From 0f9ecdedaa007b19832b6e172d808ebd29a63de3 Mon Sep 17 00:00:00 2001 From: Vikhyath Mondreti Date: Fri, 11 Sep 2026 09:47:13 -0700 Subject: [PATCH 01/15] feat(library): Why No-Code AI Agents Need Live Web Access (And How to Wire It Up) (#7765) Co-authored-by: Sim Pi Agent --- .../index.mdx | 118 ++++++++++++++++++ .../cover.jpg | Bin 0 -> 30367 bytes 2 files changed, 118 insertions(+) create mode 100644 apps/sim/content/library/why-no-code-ai-agents-need-live-web-access/index.mdx create mode 100644 apps/sim/public/library/why-no-code-ai-agents-need-live-web-access/cover.jpg diff --git a/apps/sim/content/library/why-no-code-ai-agents-need-live-web-access/index.mdx b/apps/sim/content/library/why-no-code-ai-agents-need-live-web-access/index.mdx new file mode 100644 index 00000000000..4d870a63143 --- /dev/null +++ b/apps/sim/content/library/why-no-code-ai-agents-need-live-web-access/index.mdx @@ -0,0 +1,118 @@ +--- +slug: why-no-code-ai-agents-need-live-web-access +title: 'Why No-Code AI Agents Need Live Web Access (And How to Wire It Up)' +description: 'How to pair a no-code AI agent builder with a dedicated live-web layer—TinyFish Search, Fetch, Browser, and Agent—and wire it into Sim workflows.' +date: 2026-09-11 +updated: 2026-09-11 +authors: + - andrew +readingTime: 9 +tags: [AI Agents, No-Code, Web Automation, TinyFish, Sim] +ogImage: /library/why-no-code-ai-agents-need-live-web-access/cover.jpg +canonical: https://www.sim.ai/library/why-no-code-ai-agents-need-live-web-access +draft: false +faq: + - q: "What happens when a site rate-limits or blocks a request?" + a: "Honor any Retry-After response, and use bounded exponential backoff when the site does not provide retry timing. If Fetch cannot retrieve a protected page, route the task through Browser or Agent for browser rendering and navigation. Keep a failure branch in the workflow so repeated blocks do not stall later steps." + - q: "Can I use Agent without calling Browser separately?" + a: "Yes. Agent manages multi-step navigation and extraction through its own API. Use Browser directly when you need explicit control over sessions, browser profiles, or individual page interactions." + - q: "How should I handle portal credentials in Vault?" + a: "Store credentials in Vault and reference the Vault item from the TinyFish block instead of placing secrets in prompts or workflow fields. Scope workflow and workspace access to the people and runs that need those credentials. Review your platform’s access and retention controls before using production accounts." + - q: "Do I need to migrate off my current no-code tool?" + a: "No. TinyFish provides a web access layer through an API key. You can call it from an existing builder through a native integration, an HTTP block, or custom code. The Sim integration (https://sim.ai/integrations/tinyfish) provides one working example." +--- + +## TL;DR + +- No-code AI agent builders handle prompts, branches, and integrations, but their workflows often depend on cached search results or brittle scrapers for web access. +- [TinyFish](https://www.tinyfish.ai/) supplies the missing live-web layer through Search, Fetch, Browser, and Agent. Together, these tools support browser-rendered discovery, content retrieval, protected or authenticated sites, and multi-step navigation. +- In TinyFish's published [Online-Mind2Web evaluation](https://www.tinyfish.ai/benchmarks), Agent achieved an 89.9% overall success rate. TinyFish describes the evaluation as [300 tasks across 136 live websites](https://www.tinyfish.ai/blog/mind2web). +- Sim's TinyFish integration shows how a no-code AI agent builder can connect visual workflow logic to a dedicated live-web layer. + +## The wiring problem no-code builders don't solve + +A no-code AI agent builder lets you compose workflows without writing the orchestration code. You can arrange prompts, branches, approval steps, and integrations without writing the orchestration code yourself. However, each workflow still depends on the web tools available to its underlying model. A polished visual flow cannot make a cached search result current or give a basic HTTP request an authenticated browser session. + +Cached search indexes create problems when a workflow depends on changing information. A pricing monitor may retrieve last week’s plan page, while an inventory check may report an item that has already sold out. Point-in-time scrapers can fail when a site renders content in the browser, changes its page structure, or loads data only after user interaction. + +Authenticated portals create a different failure mode. Without persistent cookies, stored credentials, and browser state, an agent sees the logged-out version of a supplier portal rather than its invoices or order records. Some portals return a normal response code with a login shell, so the workflow may continue without recognizing that extraction failed. + +Bot protection can stop retrieval before the model receives any useful content. Modern challenges inspect browser behavior and session signals that generic request tools often lack. Repeated retries rarely fix that mismatch because the site keeps rejecting the same type of client. + +Visual branches can respond to a known retrieval error, but they cannot recover data that the web tool never retrieved. A workflow may even finish successfully while working with stale search results or a logged-out page. Automations that rely on current public data or authenticated portals need a web-access layer that can retrieve that data before the workflow evaluates it. + +For a broader look at how these pieces fit together, see [AI agent orchestration frameworks explained](https://www.sim.ai/library/ai-agent-orchestration-frameworks-explained). + +## Live web access as a missing infrastructure layer + +You should provision workflow logic and live web access as separate infrastructure. A no-code builder handles decisions and application integrations. A dedicated web layer retrieves current pages through real browser sessions and converts them into usable data. + +When a builder delegates retrieval to the selected model or a basic scraper, it may work for stable public pages. It can break down when a workflow needs current data, an authenticated session, or access through bot controls. Purpose-built web infrastructure fills the capability gap without requiring each builder to operate its own browser platform. + +Separating the two layers also makes each one easier to change. You can replace a model or revise workflow logic without rebuilding browser access, and you can update browsing or extraction without moving the workflow. [TinyFish provides Search, Fetch, Browser, and Agent](https://docs.tinyfish.ai/) through one live-web platform, while the no-code builder remains responsible for orchestration and downstream actions. + +## TinyFish Search, Fetch, Browser, and Agent + +[One TinyFish API key](https://docs.tinyfish.ai/) gives a workflow four distinct ways to reach the live web. You choose the primitive based on whether the workflow needs discovery, extraction, direct browser control, or autonomous navigation. + +[Search](https://www.tinyfish.ai/search) finds current information from the live web and returns structured results. A no-code AI agent builder can pass titles, URLs, snippets, and metadata into later blocks without parsing a conventional results page. Search fits workflows that need to discover recent reviews, product listings, or newly published pages. + +[Fetch](https://www.tinyfish.ai/fetch) loads a known URL in a real browser and converts it into clean content. A workflow can send that output directly to a model for classification, summarization, or field extraction. Search and Fetch are free. Use them first for public pages that do not require interaction or authentication. + +[Browser](https://www.tinyfish.ai/browser) provides cloud browser sessions with standard CDP connections and anti-bot handling. Your workflow controls the browser when it needs to click interface elements, maintain a login, or inspect content unavailable in a basic HTTP response. Browser usage consumes TinyFish credits. + +[Agent](https://www.tinyfish.ai/agent) handles goals that require multiple browser actions and decisions. You provide the objective and desired output, and Agent navigates the site, adapts its next action, and extracts the requested data. TinyFish's published [Online-Mind2Web benchmark](https://www.tinyfish.ai/benchmarks) reports an 89.9% overall success rate. Online-Mind2Web measures multi-step tasks on live websites, making the evaluation relevant to workflows that navigate and extract data across several actions. Agent also consumes credits. + +## How pricing works: free APIs and usage credits + +According to [TinyFish pricing](https://www.tinyfish.ai/pricing), Search and Fetch consume zero credits, while Agent and Browser consume credits based on usage. TinyFish offers pay-as-you-go access as well as Starter, Pro, and custom options, so teams can choose between usage-based billing and a recurring credit allocation. + +Estimate spend by running a representative workflow against the sites you expect to access, recording its credit usage, and multiplying that amount by the scheduled run volume. Include retries and unusually long browser sessions in the estimate. Because page complexity, blocking, and task frequency affect usage, test representative workflows before setting a budget. + +## Wiring TinyFish into Sim + +Sim provides a working example of this two-layer setup. Its [TinyFish integration](https://sim.ai/integrations/tinyfish) adds live web capabilities through one workflow block. If you are new to visual agents, start with [how to create an AI agent](https://www.sim.ai/library/how-to-create-an-ai-agent) or compare the [best no-code AI agent builders](https://www.sim.ai/library/best-no-code-ai-agent-builders-2026). + +The block exposes nine tools that cover agent runs, web retrieval, Vault items, and browser profiles. Run Agent and Start Agent Run launch work, while Get Run, Cancel Run, and List Runs manage execution. Search finds current web results, and Fetch URLs retrieves page content. List Vault Items and List Browser Profiles expose the stored resources available to the workflow. + +### Adding the TinyFish block and authenticating + +Add the TinyFish block where the workflow first needs live web data. Create a TinyFish connection in Sim, paste the API key into the connection field, and save it. Run a simple Search or Fetch URLs call to confirm that Sim can authenticate and pass the returned JSON to the next block. + +Configure each TinyFish block to call one operation. Use Search for discovery and Fetch URLs for known pages. Run Agent handles work that can finish within the current execution. Longer jobs can use Start Agent Run, followed by Get Run to poll for completion. Cancel Run and List Runs provide control over active or previous jobs. + +Authenticated portal workflows should reference stored resources instead of placing credentials in prompts. Use List Vault Items to identify the stored credential resource required by the portal workflow. Use List Browser Profiles when the workflow needs a configured browser identity or session. Configure the agent run with the supported resource references, target URL, and extraction instructions. + +Map the block output into later Sim nodes after the call works in isolation. For example, a returned JSON object can feed a table step, while run status can control a branch that waits, retries, or reports an error. + +### Template: competitor pricing watch + +A weekly trigger in Sim starts the pricing check and passes each competitor URL to [TinyFish Agent](https://www.tinyfish.ai/agent). Agent navigates pricing pages, including pages that render prices with JavaScript or apply bot protection. The workflow returns each plan as a structured record with its price, billing period, included limits, and source URL. + +A storage step preserves the current records as a dated snapshot. On the next run, a comparison step loads the previous snapshot and matches plans by a stable identifier. It detects plan additions and removals, along with changes to prices or terms. Sim then posts the relevant differences to Slack with the old value, new value, and source page. + +[TinyFish Agent](https://www.tinyfish.ai/agent) reduces the workflow's dependence on fixed selectors by navigating the rendered page and extracting the requested fields. A renamed class or redesigned pricing table can stop a selector-based scraper, while Agent can navigate the rendered page and extract the requested pricing fields. Site changes can still require review, but they are less likely to break the workflow than a selector-only scraper. + +### Template: supplier portal collector + +A supplier portal collector uses [TinyFish Vault credentials](https://docs.tinyfish.ai/key-concepts/credentials) to reach invoice data that public scrapers cannot access. In Sim, configure the TinyFish block with Run Agent or Start Agent Run, then reference the Vault item containing the portal credentials. The agent opens the supplier portal in a browser session, signs in, and navigates to the outstanding invoices page. + +The extraction prompt should define a strict output schema for downstream steps. Ask the agent to return one JSON record per invoice with the invoice ID and amount, plus fields such as due date and payment status. A downstream Sim step can map those records into a table for reconciliation or approval. + +For longer portal sessions, [Start Agent Run](https://docs.tinyfish.ai/agent-api) lets Sim launch the task asynchronously. Get Run can check its status and retrieve the completed output. The asynchronous pattern lets Sim track a slow login or multi-page invoice task without holding one synchronous TinyFish call open until completion. + +### Template: review monitor + +A review monitor assigns discovery and retrieval to TinyFish, then sends the retrieved content to a model for classification. [TinyFish Search](https://www.tinyfish.ai/search) finds recent review pages and returns structured results with their URLs. The Sim workflow compares those URLs with its stored history, discards pages it has already processed, and sends each new URL to [Fetch](https://www.tinyfish.ai/fetch). Fetch converts the page into clean content so later steps do not need to parse navigation menus, ads, or raw HTML. + +A model step in Sim then classifies the retrieved review by sentiment and can extract details such as the product mentioned or the reason for a complaint. Sim can route the structured output into a table or Slack based on that classification. If Fetch cannot retrieve a page because the site requires interaction or blocks direct requests, route the URL to [TinyFish Agent](https://www.tinyfish.ai/agent) for browser-based navigation and extraction. Each TinyFish primitive handles one part of the pipeline, while Sim controls scheduling, state, and downstream actions. For more extraction patterns, see [the best AI agents for data extraction and RAG](https://www.sim.ai/library/best-ai-agents-for-data-extraction-and-rag-in-2026). + +## Pair any no-code framework with one live-web layer + +The Sim block is one working example, not a special case. Any builder that can call an API and consume structured output can pair with [TinyFish](https://docs.tinyfish.ai/) the same way, sending a query, URL, or task and getting back JSON its own nodes evaluate or store. + +You can swap the visual builder without rebuilding web access or add TinyFish to an existing workflow through a native integration, an HTTP block, or custom code. + +## Where to start + +Add a dedicated live-web layer when your workflow needs current data, authenticated sessions, or browser interaction. Try the TinyFish block in [Sim](https://sim.ai) for a visual setup, or connect a [TinyFish API key](https://docs.tinyfish.ai/) directly to your existing agent framework. Choose Search, Fetch, Browser, or Agent based on the pages your workflow must reach. diff --git a/apps/sim/public/library/why-no-code-ai-agents-need-live-web-access/cover.jpg b/apps/sim/public/library/why-no-code-ai-agents-need-live-web-access/cover.jpg new file mode 100644 index 0000000000000000000000000000000000000000..050cf7d87ce574638992f9bf51090920166bb1fa GIT binary patch literal 30367 zcmeFZbyQr>wm;aoCOE-ef(3UcxCVC!G_HZhg9UeYcXxtoaO;NPPJlq83GVVE-z)R( zdw15FyJr5H^{VBZQ>RYJr)uxo*8RNryaIR+K>S-mLPA7AeR;h?M?*t@h5H)g<%LU* zgOBs_CMTvOCVcs@(@{~;vGcLAu<}U?3rlLLYJK{Y@~0A*|JRlD0kDu^3*qbFV5k7F zSTJx{FwX-35&#SU77hjm2Jp{>hy;&-3MRZdW|?iHTUz_v}!g z=nVDAT(j~0|Fb4$q@nd3Xc(i3XgO(Zy#P(EnyNtEr0%@tD{gRs>O5G|{J#kNF9QF+L;&vRo#);Evys8JG*Hv3`+`)&iRITv3c-$I z=bBdzKh&4arVY4vg4D8+Ach3yFLlAFt|aY~bb0RT7>boPeBw~>c*(>Nl~20}xYwuU z?rdRl9@;ps6-%c80EpI7>hfzH{Cc8$UkXvU`YvecYP~}81%R?^RrCjb0DM1aRll<^ zemJzp`S?=eCBfkJ&RUJv{q5o(-*A&tpx{c3Q5FcOy@L9x?_}x?tH9bIV9*_sRN_S{Jwbt=$8}3eM#fzwpq%B@#o2q zetk2re8O6}FWOgt$@$=lOe*|}egnZ06%6mlEmspAO}Go9w}kg1GH7^9 z)~FGF0Z!A)H+4{Js@(g=k7{OPQlwmxx?yMZIO-E@xVupn)p<7DQ7qdn<|hX_NrIcV z()QGIed)Xcug+$+FnWZ% zwiaS#frEJ8v!LHYG*Nt}ini=g>SF9WnI;>FeGE2A7E#@{N~QW$45Z#R?{O$3Vx-}q zI_wv}j=w*>qDpESS0*Ke7?PL2b=04^7$~@VpM$nxufGJC%TyA!{+MJe4m!Sba22$t zlrYq&{;AppGkN{JbN;9a0mknG@2N7-LJs+Q=j&Vj{uviDxXGOA47;2O>v*of*R94Ijq6DE<3CG>6|LhT3aC~s`Ttj3d_fEEwWW-|;}zF2 zRHjg=T}u+Ja{#AF#l>9Ar9P2euv}_pGNID4P-(Qtg2E{~ebDZ}NSXfk zkHbX*0sebq5kHv9lvcD8CS|!Hs%}Oh9LhGHv;mH86#o^6zn#xG0L{oKS#yY^{Qu|8 zzvrNGJ13Je9C8wLe{wjbJQ?xE3@-52j>*vM`I3qiv z>asuih$2<%LXU7zc}Fsl-tU=1bUFaUmXkjdL=@;SYv22)%)d=AJBL3(Zs#(0E~#tQ z=4qYK?^(M>*j5v1qFf=TC9C9lLM}yLY8L&8R;hmlckKlhaMpo>B#bc`V&Zpy#S4p7 z94o1+84(GGr}R!DQoej)yke)Yy#f$DdF|_=f2B>fFS4@wEMNVOuv)>MsK&Rs;_N8S z`zg1Ye5uXXHyI(H0lmB)T|0u>2|nx1UzQ3q*j)^$L9 z67)%)T-;JoTe!&@R>YtRg0{+}l!jpbi`$9DQW;^}YWb?Ys3Ve1%+vu?V3B7>k;(_g zdx=`=^F_Q_(6A(^t5ad0I5bD@V&$rg+xMK94XU8>u26s4Iw|p#Bn6e4h~$Hl)o_m3ePUW8 zt(44Wo;ezcmb$jYn|~wwEmqgn?@r2v(Ea;lhkjo^%VP6-j8Nl|bva~#E`Y?y#k^Q9 zli7AfsK^nys;ay|$8BHt;euIc&Hm|MxfK9_lv*1PUNEP3!)CTlyNPA~Y@K_9dC zaoFr)tb4-HQ6CmbZdo#BhQ)r0mFE5HDuEkc__^EBsKUzgvBLH#E`YdmB0C(yvBH6E zQ=o-A`xvbp$_Jstk`UhH&B~b_oZI@q(KQ5vval{dWu3i!M1}pRIytTD5mwwkiLY{` zr5z+->I?cUJ{X~%PmSXQ$c=H%QlR7sISoMe5p~(Z&Wig8eQnov+6@1WdTOeV7d!oz z>}B}ZJAR0a?Kd#9T3<$P9h&|Lv@PWsAR$@Ap<9nodB?*nd2(em0K2E^ zoS=4V$oXp%_i4d)PtwV1#|!+qi&z2Bi&811tyuO)y{L;@ii6Rb2!F{B`-WEhclP$D z*k1`wORK%?a!jE|Tw4Dt%&q7{2r2&g#Va$ChVOjwb}x;}grk;Eu)C&v1Va$$-P9~x zyFRS+;ttoQmOGIlwRgm!DUuwWGvCYVpgn=8yU6B12vw7cIP98 z%?cX7l@n2t8C>HtL{199S7R&V{3U0l zRcZ>7I#`9)iT1DUQoL^8@Zn}J$)$l9p8+m%@$oflLo_@6(#uKWJ*i4pGD6^%WI|i5 z)LLOuCS_f&FX!Kd&Rycj%c^S>zGyE9V?lnd_g${yHF-Bi5p?Z@scF~p8V2PNF%lPh zu69z~6UeoPti%P3L_Q8i5noj{p@vS*OtiL@7Pl2$Z73XZh$`r~-ZG3YM>O0NTOuSO zgULNqcaC-SRSPPz1_aPguMqIOzDu7il~>2TcK8FxMQIID*oLfK4=C%1B;#n$j${+e z^C)A1&-X82z!>P9HYDsl*>=CW(9%@KoOqmgs5m|TrsP74Cql#Jvni9!jEd+9mqTP= z&0^!CZWyPvT&*?R)?4&zOcC-&yn#)-JiDaF&6NZ#O_P6EiYF;#ep~)oO}pB`#w9}m zclac225CcT#{B~#hTw&Y;G3&$@gDw~{c2vR)`!TXxfT`U-C0zx&A_-YXwFTC3D4`S zau+f`b1?JCH6yvG3dh!NPRee=QL>b|lrC0dMSxx1xqP=Aae4ygKNbXSG+wFrd5=Wy zN3}OTRyH-So!jN;Q?s45dGSQ2Xxu8Athb9*(+ROkcb3o2Pp_hIgKIU6rBD6^2f)K4 zE^`D(mK14{H)S?@yhl`w>8<_k539YW#1oD$Vw3bnp;MUd|f*wznoH zW2oO_qM~B0?&)dmF7~hEg+t;qHTVD5ynlNI&r`nV4l^k%lIfv4B8&bj8nr-c0kxqrDO81unsswY1()9#EYBT@#y zMJ;R7vobNQ%r!BKkwaTF@;U(ie&cr#JB``d`d%q8^+xFBFW!(!4TWkY$;;EoeVqQ8 zkDeoq=cr7CKsqlz`nnI#xpE z>gdiuh$myv-Q#f~?8Fz?^s{$mmgoJ??JD<&Yx5;3WoCc!Gh@qCfg@|{B!;iCKI98q z$fcnl-nrPiq`)DQrz|(Qj;mTnWEAhuja43X-&=yUkMGtqjz3gXz6tW|)J71bs3Ya5 z(!y6~xOF!mmY)}s0@E(S6h3)292Jz}i(%ZdHiB*S@c8OLzn>OUx&E|ZuTkBXpc{HI zp0vXp=3uCyfEn#@{gH5pwQP~hK(V&r{y3N0xaH6b=}Ky5K;^;L!~Gdh|K#^SDm*(# zdh-zzL%qCMd6yVt4%jrW*{n%WF2H0P3 zbo;^Qw5Vrzee=&`?Or<9y!UO%^D{FPl6(dXLqq-U$)O#>SJrrB2+si8E6-|MiBkO6 zezWcxgS*VUyBIi55C(BWJ_TeGbx23s3eq+3gY=jhxHui*iU>uy1 zyIZM@ONr=0oA&&jsBOL>C-CXny8;Cil+MF3rsy0sJcJOF^|pcYtg;%=-RBNw)LnL> z`DRo$oS2#c{Bnf4i#5WJ+KFKo(y#U1OjTwWBw-Yb+tvxVc8MClj;l{B?zjy*>c9P| zp%0t-Wis)ihBj?hZ%p_wt01XVNteMl<$T(L^bz8RUYt%()NSNdebeBbDW z#ub;mEBV@)B|8!GPfNh0$)LL5-1itM`gB9S(Qr#kcW(Euhmuaiq&U;Wi2+o@Y-oi# z?wTMi<4Yll$AfNbzfVjLsxolM0htsTRdt;gbdNSe_@iKiKA_@Y`UFsUzBM@%xipU# zsx-&RAdQt&bk5;4l%5ilTd3EsyWG9euy5HSG!j&y%fG|QRl!p!(ASTn8Q0pXi#P-x zH180LiTyNA@5FPn%_b+UoAvvhCBK3|Z$_}dfMdz^?@zledc>B5AF3J6(l~}^SOs@J z!=1ZdPlLp+L%i$+*%+w5h#ww)Mp2*-pCq|0)Naw&hVapvXEcv}OYV+Dtczf2N{2{h zL50bh8RyMMU7S<}D$(#>Ay9gn9aPlBA+}$qR!p;or}SI2)hBg6)pv_HXxm-mO~!ZvqZ&DtH@7VcMXtU;T0_vML&IL_YIs6tN1@sk@El2ud~l1G#(T>w|g5VcFVW#~tC0 z+>cFJ#4-6Mi-vI6`%Vtk9O)mg^o6^Uc6Psk2|eqTT6OYt#A~w+Kx+I;g*v4WClX8k zuC+)8uvcOGHpfIvSLA^T4q{8ITwgR3nZp%ExlJd2$udbTC!I~-+4M+4CX7=PG(1#u zd2HV_IONB-x#ILUCPS+e93#rE;Q;{!>$53MaXFx{ZGP~tgHd^@L-cJs1r9c5V=beP zY7V>KDA07qIHSzTe_V6j>-Vb=G5H2}Ei4=UgRuQtZ zyCE@s9yS)q z^^_}|ul43_2N}J`PV}UM2y{sM=QeY}2F%^DZ-o;oGk2;Q#O5&!i?UbR@U@D{K6nr` z3+v*m3o_Jv)8x}ZRT7`Ww;^>u#86GP-KWQycN7;X+t}6uxeITHlm=e`FF55b*~LmmtoCMf9OZKT@fXQ=;a@&H z?V?Ft2ca6Bw+id=Eq*?^To@jfnf1;BI5KddW#avDK{Ch^Bx`Wkw#O>$DZsa5)VXEs zlR5Qmhs0mlyG%f~_zJa4G9(2e1SM5;B9Ui5xtbG)8Q|~^m}JO|LXk=u$vpARvpMJY zC6H^CbcCFLsB$YM(T`!6RqPHKWL!<_O0N$!&_wt}G{3gA?n&W{I#;2ytffBPlMth( zlr#N#L}uN#f0fikVHM-cw&2;SJG}y*&C;1m}^ zkU{M5l}`c_vQa%wIAjWsmyu~or5cn@85;{S(GZJZrI&!USGM9 z^4dI2Z_vjSx}r|#Mm1(l$U!u$OdHC%K?|R+TS1c7Z5Ll_5GtfUK;F6#36z>7a>tu3 zBXx3uN3gl!bfe7EM&{c;SmP@GgM{MkW|8+laq!D@SH$_f1cMVLV>m zV@^;xW95TGLc7z>Ii^;|NW%_NgC@ul{)>+}p|zaG;+LtG8=J`7kg`@r7OPu2*ow*` zf-er4)uEQEankHbJ7L2OpzOq~qpY8WZxz^6VolaG<*YBJgtK!CEnhhPxMbME$JU9^ zC4R^#M9BhyoSnfKY+hgwA{=sx+PrMY1XpLH+~C0#=IC|`{3No<`iqQ5XqbAmGfXdQ z1jcHfhzg*a74M`Y_0nYtN&;L@;$}Abc;!`k(=~uQuur&P*(L zbCT*zC?n2Mn~FbkE2YYx0Vp=5K(m9+Ax`FPf*Nh)yo}b}lUzqoA}~YEr-@=b$KKd+ z$wlFwTfpu`5T5))hWl*`*Ix&iJ^#+P_WnV3?u_pqjc!P$gg0|YsLc>z>}^%l_LF&9 zns=*ol=>WI*+R^TSNhkvu_xtAG969M9tBgnc-hZsDfwfZvY6cG;gF-xJpxiFbEVgh z4+~B0rqnX_7ct;S;Q3w?vv3_S%aPb-GFa2IIs4Mt3nZybVUFvBbN8UdJI$8c~VEauzJ?7t8 zk7l7^?^83XvPv4jN)Zqs@uN&XIceYSP!$YO(lum;lM}^oJ?dmg$+lx&9QcYr!Yqpt zHR&waMt=N8DObyPY_dbXRInAtLZZ>NkE+ zP%F|qg9B|0J%JHdMtAE4JNwh9P=JVvD1DBR5_Zp2Eob8$PqYJM8NysydFbZK<7{5j zBA_1RU0glKy}}rY!?wXvp3sH}KfWy7J~L@gYV_oMwpIIH2#T#+(~5`Oi&1f?Bt51s zFtMN7o8p9Qv+#4WA8#4QEXnd?0^>q0!rb=dfo?VTa@}|4_xy6?eb-NptV~}O;FLLh z;Bl+<(3r;Mi;m~Vjzx>~tNGpf=W559WsvulQ0?PuzrE=!*D0T;ss}|W5Dq!GnB;(j zOqrR+1GwZt`D=zzU{m2*h;FY*$q~n7KXX;b zmo$QgDY=~p=df|hCe)OKs0#cHrti1e74BU89oH{%RVikQ# zADLNC3`?pmn?sYD9-|}pAwn^ia%rB8eys@;II8j$LoC_Yc>u&ZSQx*+V?6XV?Qqw? zyk&^ar8W0#IVE%K1L55zb85n|a2_Y&n5?Bj&yX*Pinw>ekU?dcbRJnm&qH?B79Rw3 zlM)%eNNYkks+^EyLa1yUZq?dI@rg~~8BhZX{unp(pdj@Pf)IrAI-0M6ay0$ra>5dO zh%=@}Z$Wzu)82M0^%a2iuIg*MN&4cSvbdI*WAEg3qRbh5X$yY5#t(#pD{+%&whZqq z+>Y10Gia$6tH-f1&=N5SHvTSrDKJE#h_>t&4G4Uo*l2LbcpTWTqHsWuWBVa~x^c9! zU;5Z)_zZY&e#In`oU>xQ;C@Brf^ihOcZzgB_GJAGa9Z$fs>pr>Rb0#v|FY^wKeupf zEUcsBFK9WOnIPQR_KB7XB-pJfwUiFxy!ice(!!S;a?J{jbi-llra6Vg3>7~y z3&ou;TT!yUQ*W;F6GiZ9bJ7a&uEwy+W3DGSQvbqz&(QxbU9KCXPt$EsIazQP84XQP zXYZ%_TE$OAabfZ^Y2wpJHPdU^Fd;#v3ZeLLdkw7AREFgR(MP;H9^8B4O2Bsi)k9Tx zj^`GfuV$P&$&~&@Rfe|EM&?DOrZ#dlJ&C5(5PJ}i0Qx_=$@`b2K;JbPqc^|s43N(M z`T^U>0J(sRO58{AIJ6*Pudkd?SEsCmR3n_HuW0H>*yVN9-PZ$a8EjiYt)8d{zTyB@ zAis9`6_HeN8m=G<)=pR-$3T6!OrZ)*loMSKp6!cSA{5V)zHnE&2nsW#p6=#_3FV99 zA(A!^i>&0G9i3$3yNZB?5`;xiOVGSIwRlW)(Tm-^ODIC#6-$5*>2X5KxFL>t23Tw; zi5`#r;uujks3N-tI{$2l#jCD!CmgG$I?#{03%e*1ozlOn{VGKO!EYdXQN_FV z!U%3^?nuPYxoT&|dZ}AI>TN#6Es`o1cm6E2{7c+8J||gu!|ptxYBK?99s}5?vCTm) z2CZzyc|yw^De=ag>oZzXNeopbrPHUnSEXjRVkZrQoUe&#SVwBSb9~_^io7uey8F+I ze{weTCK*f+9o()Yj!9{y%zgV&*&J9lj%AZ*=9?841FuN%o{pzFJtUn2mBHxzHU-xv z=lff)DD7ooEjv7U1<}j}gcpSk_l3-qSdT9~+g077ya&C|0@QloOah|jhTq=)p?C1p zkZND@)B@wMtp!__ng+Fh(2sZ@)2e>4v5C5Fmus^fq9>n*A(hp}C~I!UOxk+Kc?_Oe zjk*eckG7HWJ}07HU}bg;sv1cV1J^P|RosyZcs>kA%kATiW%I)2+GAKY+&$&p-$blG z9OTm`F$Ej))__t8K3&o?z+DA%>|1MIq`f>So}PbFulClJBLMQ)Y;DM670V6yrBsb2n)Y$wETP8IVeQq0lLz1^+-nVw_EvCC4_leY0+|y@pd&Fp4}! zP%)uKTWH0!Esy=qArjGUKyIU7i*TCbdo zdv8i=zeMR0&fdD~v5YcC{1|Yz)7U3XqQnMoMy%gt;^klP9dPvS^EkT zjfSkJgki!NCW6L5k01&@Y0Rg$fB623h;>>Vu(hjmbs19TQIV?IdGmHnon+=|wPyF2 zLH?$7qz~xr^KKO4rVMHTWssoL7=6)6vG}(0mT{Ciy#Mba`}TSfmz}AB1bYC3v`}{p zt%7aTS>uZB-LIzs>3StG&%eXy6Rd^?a!V@qHZU_`?-oflg9_5~FY$w4BVx0Pb^IkFqVj=9&vP;# zfRS7~U^=zv6Q`Jt%h0m1rW4t1&88TY31weXr|_s!cBH&TPxLkKD+YO7xAa&>69P@G zAz}AUDDS5s7lL7)qj6!!;G4of&tb-&=(d5Rua@@C>ek%cP7T%9<2PNiQM^dF_A+KM3%UTCb{tkBoqi+U`E@Q0z-%@ z|5%aIze%vhl4`>Y^V$|4v%XYKXLtQ(y7;5#{|ybgtT5f*X?a)Fa}yeVIp&FLYKoW2 zqx^~HhO^VqAP?TzDb(q`Oji)%AE-lhUO48OC({|;TbVg#)q_xdGi`e_6joYmC(SvD zsd0ma#EystAiye8>24PH%{)sWji?67)e~topm^cfl%PRn``BXm;spPi38mA8HCB#` zl_QGB?_I(Oy4a&BUP*DtBWgNrf=C$-RyOnV^3gBe6nLZa7g3wJDO0bwVVpZ=to@tx z)*jGAZ_4EDF8_pi`Qobsb6|||>QFq{cCw(RVQrlEDU9Oafc{XW3F=`SX4k8ZlBPn& z6e+cXrnE{vdF&+m%Ei9EY=i9-Ev7j->BZWf^2QqzPY7I4slZCcy2j^C1LO_% zeG!lxw4Lt?-f;iaXJ+n`Ny9Mi)Gc`%_WL)F{p4QT)gi2iYbm^*pEhwAXFd7B&i1dw2eJ=Pdg{U#WR z9sEi~x@-cP>72cWEkXqf5f(;5`&Em zHl@lH?}yr7Q$8WBHqaQcHn!aP0lkV>!7`Yw7f2Zn6RTf(%k6?7@;5_(Bn&k@GGa!d zoYXwI0!{wMKpXi_X;3~DrMlnNAq)-zxA-4Z6ts2uwY*6cJ-(Ryys?1HtpM+i_mgPM z%XG;O%G~jGwH)Zi(6KCRd5QHlC9&()s!7oUXj23&31DQjQN4atMnn9+d`z*`TJBKu zGgR~l*ht)Dvh6@ikXEvu<#a96A@|Ul9Y>F>SYaST(ly2;CSk|7=e5i=s0?ZE%H$cS zxC#>zV5Zl68%G17HSAm}M~+Sr61VsSc|-Yn8;9mHB7Ih~SL%t;>AX)Bx^w1TRvj!) zrRYNd$bb>EyYWta22@nsXi~uEkIU;FI&HDkZ~nf7Xd#96ED&1MB(&!cMr5-z$#>|= zw&jMF4)m<3i)mpGWU6wi*3tXF;__&U|Ap+zw|J->)1 zF|z4G?||D46kjijp)=4kmE)hc6VBIASwaBgSFl{CwU^BCQvcXRs6oOQS}-m;6{=tA z=vhJ>t}QO?zO{m(gOF6SknmI6SntX8-8S>ww6=ObyLzfu-MbZHnzC7q3Jc4@kdSyN z6^$r{O1fW%YW4h#UzM;Ucm6tw6pK+tHt-vWTq-0X@mJl(+spdz1n2lp;XwA}n0T$9 zKc#wDbs6PeC5cH8Wlu0b=5ZiftCK>0~AtM{#j>@Tsd4a936T;4H!BIcW zxSAE#vUB+2fY?hOSLSrU^v@^2NYM)x4k}W7(?0_gJ!aXwaAG#ESWaS;if0&?NA2*t z?3@NE-JWj`#}#TFH0O zvI?38!Jjf84O7j93Fk4(c;??Ro8}9wA0N#w5%Sq)%Kchr960oAu2%ulBGua48Hy&q z#6U@a{5Sb0p%+et!yCyOs z=`Rs?nQi9`f6a;CWEObU6d6fSrZU@6m#qnW*ME)xp%~Ja;xU_vC=$ZTUz%JKFcQ-ZbE}e;^+mDf>nMd>iX-KDn)w5ad zZ;`ai2Ai^|6#r0tOr~b&#Jh|n&wL#(WwxMafcgOWZ>HO#&wEeNGrthq{&>)&fB!Dp z4gU>#1{7KzH7=032Ewv(8-N7rqdUqnodB^5I$$iGLK893Ybcm|9! zX4#T-E!?v>RNY85P;7zGX}=6mW2EAXGSrx?`{$Qp==a8%N(i$-PCVeiUnuFTixaVwMNzB-67P<`as(E^jfF30#svpigvw z(qAUfZD+^k0-;arn9~!|h1jaaX;Jjp5;!sQ8`hFnPGiMvFUGC2XMoKuae#i3z9nRB ztV@)g?^QnYEGoFsBREQh4*{g>iAMx3?!$xmrf)fbW8vACe~PfGK-MKPYzT^_@cKpW zpmU+wJ*=x#V|;8Zq^RITC&-IynVXh{BK$F|%dNJR`DIlk_K5d*to||l8Ld3TGjsR; zeyR_8XW(G9fGwskLZR!~Q*3dO$QhPBMx_c2qP#NfiMTd=ESmTV3T(K$|y0JKc zDd#QCpHxV~Oi=H^;{T=1UJK+A~ak6BA z%j|VCv7TbRg3d`Yn-ukiQuOgUy{(+D6F-U>#yL_d73%8X2{@N=4rA1{bh1EcDzew# zABjs>UxAF;qKS(wjMK!SyO^H0L1aeDL%V%S!!PFabN(UrET~x*%Xq`tv~A7Wm@e*v zaBQMTb~4aaNzUSH=CovMg{8N`d=;EdIjF8tswQ*X_a#;^h-gf?3_|@D!k*+l^k^%_ z5{<&DHyW}ty`gAh@wIL*CT?c5YS#52K`lR7uESW-^HyzyVlI(d_ruNSSQWCS-G*cO z-h{jkZl*dqN#wnqBnz3ptt-KknEE%_@TUd&h}j+k)}CcEXp>rwodpuQ zFK(iXh0-8H|_1awxW7_y^F)O8O>O&FJ+iFDb-PTw|8ziti8IAb&CmK%_9wf1hec z-_h4V{udcT-InJK->9@7MtazJ9AD;JHmUUQzn}~jWe<(UuNH*R&)-|pmc0c%h=zGi zR%*s*4@2(Q5C1s3i)}8ds`MQN@cfE0Stm0G{cLSRfTcQayi_D@e^|nIJm~~mW)b}W zG(DXVGI9leshjfwd{Bz*+-_YE^SdN00Y`>cwpIjQGTpIzYa%~vlbd4n$v&!|7=4@k z_8CbO;fTbyt73?wQSZejlPSor6*1(rBhOY-qpEZ6A&*q{%cE_#5x}=$gzp*^NH_${ z8s>VvIi^97cr<#wVwobF(lk?MXac#4hP7Dhz60-i7Sk?IN4>b@|IYV{1NohxgpiOZ z1Os=@;Ut^`wsK2C3ALcFS4CjdZinLn=H-{Vg0CP?&S*;6=>bY5L&0kH{q91&0@@nPIitS{&ep=yw`KxVdUZS zm>tS{1Km9s&*0idn*a(6N#t;V?fCyK58Z{5j2k=h{iG!v;*8~48X|g(9gdJ;)3h45 zR;cfABPeP)c8#2})Klr|5cAwfyjWN5v~7M&CcS9@fCGcz3@|l60eqMroBNAjoK7xD zpclP=8cO(qCCbG{HB%8Hzzm9zvlMnOdPMW6k5+?lr_g1cr>CVuK4_!R6fADco|hzg z%rR3MI>KW9iN#P+P-!YeKLT71 z)^1ZZS=3Qd*S`V&7u?9zo3{K6>ejdCQ#)a>Kox!nC<`h@W+KM``g|qp+^iEFft{+f z>l97q6eq*U2aMq`fB|I+ojmYIU=ZI#*OPR~&QpWUSA}K61stwO*J|)%D&?6{Bk@Jy zRY50GZ(a`0ON3gB%_S~q7;KrfIh$8IvETiEyLF!2-wVEW9FZ-rxWN3>^y}SXC5w8q z5xwS1=qm>&@6}RU1C!3Q@P(iB{xzJzi}NYB@J}?z3%57}3+ZULmdNr41z~X$Pl<%7 zvGUqZ@$N4$y*Ff1(0ns2B&M(pPZmSV4CEUQ-G7k3Z(CFURgS7?s`j$Tt;5~jP3gRr zfE+b`1iKAW1jV(zw~Y&9?VGJ2#jaPL@{u|a&L~S_;S+J9HDwr5#5WDnSW@N^O!~V>_^hTU@=z_w%k5OiqOIAfBT&+tJ zq-wF!9;eBOUZa@6gbIJs-3DI`?AGPUG&g2&u`04!zprp~DYVg*?yHr7wz!Z3q!>q6 z^l?8}vSeHm=b4BUv%(XUGEB=qrH(-4Pj{=XLJx4g+$I_4Lw7~qYHs4@@4BZEulsvKPf%vk2HEs^DTBLAakS(=n5OT~YQ#-2fI zwmJJRHt*@Fqx~Pct{aC>*vdn=T7*?iN?FG*s-lk1o2P5rzr2K-y>t>Ei0<{Avl_F2 z{O|da*jIUUWKvv?H3mfv|G8tm1nu}n{|VZ7fn&yMjuXfr^d-PmAwI(mBY}`)s@iR0 z5jEoyU^Sm2U}x=qF&RoSn|QRBbkl&$)rdAxkR~s#BCar9Yu)CW1mqjTZY_1lE`a~r zk}*~dI98F@;#Qe^LuIGZNni>agg)v-U~`u>L$OhJ$D+}HSyMUFzav8LGjY+ZUf1Yp zWW#XnUg7QK_;)M6;fsmUOP()kls&yUZHUdw-t#^{W=0(EFbTEt z|C*ddTUvXKz9|8yMgz*N_))Tu~iC z|3ZEQA{#W8d*$8YsIx~#eGI2s`?7`LdO$hNkY<_LR6<%G5ioZEvbADXxyg=5c_TaG zF`*-s8)8-c#m6{&vOy(nh&oDI*n&MpM9od^>^;e5no5I8Rg#wTL=jsU9|U1y`^B@I z_+f@jHy*D>oIKV>46rn$fRKvY*?-8LLeog~%5^Yn#K)pxCp9fl*GXYQB&wt^en2;- zLx#|^juIKOcW~ivtpG_9A{6+O@{wQj1&M@9aK-?IW@Z)mCj#0JW!RCB*;BB;(ATO$ zjO?l+kvsAdyJ==vGvN z_!D9COAwvj{*l|r$q1%Jc3L^`1-0Fl(p1P@QFJTBn$ z>Fr!{RU)mx9#v5>ch87>+L%k-fEr5OR<7J(<#G;kFH_}QZduPWK%?g+s#fVGsul(o z77h&s0Ra&K;ZLmWOK2??JT@jJI|2@sxT>0olXHCo1&4&X#+Uend}?68x9@BpOcNV% zIp2RQ?4uC_1#aPS`4>!o`bV%Wis(zQ?XE^RF6sc)PjnsUdaf_z>~esmbWhPI)DN8C zxLy5&dajdaz`Gpso!Pi&0JFv+m253AUSmz0_stRe_sZz9ci>3X#eOlrSVaC69p0;v(nu?k7y zmB5xT-FWQ;?!fx@kq@Gi(<5JKAgKBYtFF-l&w$G+gR`xS0ZJw_l4_H}+0mV5-BZF= zpbbR{YJ?+A?bv6qLjmU*mz2x^j^fmoi39cT>p+RYg^S?pPV;o`AETN->l>#e{ti#s`GD2;rfOwnx7h^vjYh-f zz^xJ>UWA;O4BYvjqyI=|cCYTp-%z4cpsg zb&GwW7jvKC`)9ypxhHgjir#c*dFa0n!_PKoef8KXMx|uTTixXid0Z70rJ%7s`*k+X zR^ZrD8q-^H%@Q}+FQ^6q%izmJ)PZdgmuJAaJ^)U#@!fguyDPEt8d{H0Sz9-J)#M!SsCRN3fvjBbs)HXy~JoJaGi5=mEC1~xqv1}CLL$aJk6w33v zAOUBR%8>XmQ43jWBzAbWSASY#r`e24@anOo)J{LIS2x9CdczB`(Q=odl^B9D%z8%| zZ19&8PF@YaF;&UymIJ^zE1A-2c)pfG7enPn9T*$p$Ez}kvvVWjmBTVrdH-S!8r#G- zyfirUZXVacixQ}xAj#!2zW&hh-a7Tf{?3Y*6?Ip1pgr?|i?~WF+z)Z1CeWD*dClp> zg$x~w@$)3|_0*5eEsF=GZ+H{NnBNc7JFapjvZ3!+(D-3)v05`#%452sA8hYs?g>XoqzsovtoHia9J4dXJ$jGCIZhbwb!)=Ow*c;s`X&hSEGa14VFYHZ* zi-|n-9bbf=kdlGP-H(<}^VbWHis={AqjX<>4>voncuR96Quy;8c=Kk|Rxa!w@4!)T zU*b1)km{Ju;)lkeqbLE5<;>8K&#(Ir$NWyD zGPWCOiJ7e+Yx3``PKw;z4uM`>8yL7f0*5z50^3P^2TszxuyWN6W0U7ZM9_@>MpDq5 z0WLvtROt#`SHU=bk6^{0XDKwZzlF$>oJp2@g0hot3*+B2RL>3}FaC~);rx<(h(}ZP zL5?tfoK!E(VDH>CI_qLl>tJhelm~|oFDymZqO)jZXXI6#?cU7M=(??z9aEBnZ2+@1 z$0#wLiOSUpDUP(o%d zNPSJYM7>Er?pAbD5`x44_o0L~En(m^QQ@jJg@#PhP|W&`+=ue(d4^q~fgdcA*fi%F z+OM^reo;2{i0d>*zaH75#V`JRw#yx1tscWK=UM|FULhOaruKQrpJqVran$KcM|= znn6!_aIBhYH%S!TwpUQ-9Vni(=O(h15nXK2_v|qg80Cp!Z(6Qr!Sz;^l=l||{{;n; zDcd~(e@Cr+lS4D-?QeCV8Y6{{dJ7&0bx8oiD3?UutR>Y>2gN+2HOjU-U45do7sF|X{%cPH=e=Q5%J)H9Oe9hMS;wO~S;}-bZaRgYgsI-l%u0v&S6k628l+-cj5;gH z2IZxQ>W{M>oPKB;XOi~^=p%zF16qvM5w{)NsZF=6>O#sq0_<9E_VL<1nxzN(s;W8T z#6KZ(i2)1}Rk{X>0(s_rYs7WR&FHP&SvGW*wnh7XYNn&qWuf66!zdzC{fPb;cps;0 zDV5|-URGG)q4RqBQ`u4p6ZR8JkNg`9j@_eZ`-}X#ugYGR)uieJr}x9i?y8MKpQkTJ zzfCc#;enS0mfIq?h~U`bEMhS2I8O1Y>h1@ce+aP8dWq*-MlTV#l-C!?Mu1Ywd%4;- z?P3?b&egy|UcH%-kJ7L_cTg`0`J)U%Z% zwjj^ngC$j% z<{OzE{p66AM|QuMWq9#VG*O46K0#zkFZ{%nI|+tnjs83C;KwM$3nih0bm<*L5J)J7UIGZx1wwCv2uLpydRKZE zkPb@kO+dgHLbK4T6zPI~!S{K-^{#vGxWKivJpE*(!`$rvu%N9V!uxY0jNzs^nY z_#bEu#pLs{zdPIYb!s*90FPfs4S3)hhA1m^m4oH*Qn3Ea+Chln)IQW#Z~jZW9yh?!m{=Hv~UeE zSK%Br=ZE79q-!E0D&VaTZR0vOz%OX`f2OSY$M}Z--Or)y<4hT;1~16hQ{bNSs>_LI zB6OkzDy5Vt`8@sSJNvGc52+VA5pJhKlw9Q2D0Obb`lFLXefYLMWU$-e(tM>b++l|g zWzIA;`fYZvV5xY&i@|EvGa6YH6EBj2&CRFhVsog%3`OTCFd;0oEh_C6S z)Tva^SGSgNU+bCE>2R0#xswGn?(u4?l$7YGwR1A7OoHqAjL^@)v~d`zeA&0wg~ib` z`va-HPhTa;b!6`i*GP+&HK(*1UL{88W|txudEJfYt%mh}=}4iWvX3s^GP{@=VTQqc|5rKDw63o&>p|lD?(nOU}5P7E$Q= z7jUw2@7h6gj0v@d`Gizi%>Z=9lx6v^x?qHtR8MCU?Gp^Z*d$yP^vYV9knWT zYa3@WNAD7CFQStS^1e)Db()Glx$~J!BGR^0l+5T4q-~4x@cu|&9lSJ8kDkwz3u6d$ zU=Np~Qbz=G68u)xzZsW;N)YVr(+O+V*Bura-?v6g%gV-P-0b$r6XXVhbf4uaG~c2y ztliD*BA>7SoNh}adp0wVS)f1a|L2&W@Xn`o&NV#yX0};Ir=&_I^L#@p?dT~m07Pkg*yr@Sy+r(^eH1qPElhT!oK>dvz z`p@hOJJO=tbVFtu0=<}ULGm68ldBlPpdoACr)%DCm9i>u7$%T@0@IxM>=W0o#?a0W ziz|)w>v1YcbnDZzB9APP!6+mTaB`mTi@R~vdXGeqOsUupy=A?9yKz*{;bHPG*7fr( z1CHb@Y<2R^%DI8Z`#|!q3Ydr~^G6zr6X7?ftf$eC_u5Mh>u$Gpa(ChGM^WY}o^wOM zZe>J6`aWS~{R2?O)cqkB8E0blM=Rr9>_(}70Zz{v(`^|W6kEhHjge}J!91(8b4g?} zMGFfkSw{Q!``txr6ohw$gPbcrn=2}RwWzslzx6C-HJ9Sh#b8zCrnOJJZl`$)RuXAN z!!1R&haXUYw;b|k<>2=W3gNkPh|vyUs(<3 zOW(o>Y(^RDbjrVMhO%8yN&lxfo1L0F@Uss~r>Xk}s^@j5lNiq$@c#Ote>Vel;+D z*7VI_cb4iS9dZ-w2{*!SOz~EAn!;<&1%S9l;l0V|a>A0B%ZwH~tPMJ8BzS9>xqk;4 zk#mP-2|m#S-RmO8j0NYoy{pUIymz*c6%`vKVxyRzP#9$xc_xED3!&;C>kE3Fsu-0N zkQSBP`Z&QqOq&rhAWl{r?2x_%Lu_cY=aAbER!|#Icm1gL;Xcp6TY){Q%zrE4f8Vhf zzN+G2Opo``WAAgGWB=AjsRb9r32;-SKK+bg@?~4!5;i5$Ln{ z3Tl%Y(FW?DN^bM;7pB-Gu;P9&z~RAu?{va|A~gi~RhTlBdaM-Z;D}k&^{0Nw_|m3( zx`X>F+#xD(R`#bwuG?=K^@LLMWfI9sXI$oZSeQGzvyISTCJ(H1+VW;OUmJXavqtc3 z=F94bHWj+$aANj2{)Zn^p7oOVA`mT5%3pkZ{)0^kxZ>wqf!GX>=NAN!iE9$Fu563_Pd|Uc9e>4KV%=#s7a^vEr3{u{+^&IUY$UZ0O zOsj7iUwr;@g>5ZBwdkU1ohTN4k3}}sqM9fq>3{&J} z%J$(&xPGYp9GzIKm|(6pAzbu+$ZjRoq}vz_i^3iu=S!4o!R#?eV|%<2myb396U+Ba zy8=E)wR@t%R=xae>bI9=UHmfe9E3VV*6q0B#-mA=q8l2tIvuX^Zp?c#3HbgcvJ5M^GU;hI1d)Dr2&g{(uKng5b z6K&4}S<5NY^r!8b$8Fp2_hqfq33piRMwj_KMk^jfpSF932cGLv(W&4+ zrmg_eDeq17K6%@wsbq2^2&5}X;=+YmWs(#=PIV=4e*ZsW5kcZeE4w2&2+IabUorHE)79mJDNvbUvNI2FGV9x5x@>>aZ&Ji>H$pU_;Y9 zy7<+@-2V`KNWyIZRh{|%)$C5(v*vxJ1)R;)6~;?l{w<({#^zJ@E!;K<8lydh`8jQF zgCdLy#85Y||0}=j5_#cC61z*P1lX_W{XvO?vrOv_7PKx~BRN^QzG?SAGQh#;+nu^d zlZr?0wc+1TM7$+74yE-(Qc$q+ga&?(_e>cs%l<4GU>!geaq4ae=P$!UaMCDAMP>@_ zO+|SaNPNeH+0_iqcKutt+i+iupF|2_ypnrAq%L_(>n~7-N&5(Qw&jhRt_#-Cq8*6M zCyhsxz6wbW=-X!1wvtpp1*eyxN&=H=c3rH-d#3j>BwTq zd&_XS;_m(}Bi3T)glyXY&$Q~=KyoFgHNElYEZWu4k|3ZU2D@qg@qWtreo6x91_DQ-2-D}sT8tnSQrnv<#X~tS zJidRS*Kl|YBEze+W`w_bwF~5br0A+Y4@*dp{#|`XsC7YK6R!r1Yp)|M;GNhgNHrQT z=h6nRG?$h!F>G8#210*!+daF*=8^?=62XIUe{t%3Y^OZmq00#z!?5N-;#ctE}W|#SLyUM{Tmy7J~V2`M( z!UDeY(6Qw8n2*l0ar0gOsA@6HDkC}LMRK(l zb<2*?Wt6zbg;x$EwRa~18iO_aTG-a1r7A^9sb!%bmMtqPu_f;-#_c5K@_qamJ@4@B z61j!QBJuH+ERmVcrDso8XYnA(+$V=w+|9}MdtyxPqn++=S6*+^qq)@F`!L=<%ko`G zd@i>-y|DoRH&+^o3ctffJG{Y|fHWOXX$? zh{~BpNWwmR4Dk`n9;ek`!rMq%4Rl$BU|b~M)i2Kba6!>czabYlbb!iT=Lsj zTA@7cDs>vXHu4X22%aMNs(vNKuW^^V0ZV2XQGKPYENl^qxmo;Z`AJ(VwIs=e{YnZ6 zn?b(AGVf*8*q|uJDIS{~P0p=1%0^YcNcg*Bs6S@S64^+iO_L!vSzjJEe5;l%@(Q+X z5DP3Meg{nVcBstMz`(0X;}!Pv54l_uLL58y%9o#uQLD>mP9;9fwDk}7{}Rg?ts(R% zS-5cWk_5{G5$Fj4*xE0V%l~o#$3%63{`V~FebE#^_8l(xEny@|q-=>F zy6^CS;C}~wW-RR=d~mX;{C$OHa#2hA(IbaY5OzgA@i^{5wS7P3>+~b!r5m_Ua|g7> z{i!13`(ekR|2BM?GYxl&#Wm22c{_Xea{3}isDsUH`S9x)T4|Q&WeZ*)K3GgqI4wZeHTK%EicDycb+lRXvY+;pYU3rWYYTmaQKp8br@TA}Cs)uw$?VxwM^j(I#rlzjXgL z<&VlXLw)1&p8YDPS4|P2*L>)u&DdSHg6D{w&Qr#ey%OnNGAQ0)zcZ)D(ooDLB&^-6 zy;-CfkzgQRzfdEjZpZVgh&fEzmU9(BkZcsTn&Ms>vb!PUpZKDi3mZIbI@CXpXZShX zSEIhgJ}6o7fvh8ra+2)yQA#c(qTD+P>>vyUItCCG_Cvw)Z5YCLXF zGzuoel424pFUjrEyn#Mju->b^BL4u!3T<*bRXlDD&SbCf@NfD>(U-B{S&`VSGp9~2 z-FHb)v7pXGECbbje&tqZ`Qx|!H8><=bBOc(uHkb;e@Zd*Ye;!?o5HNWsf82$m;}x| z&-c&BbBeu($0e^LiW*Cu%#xIA^x{>q<0)x0PS87CTZA-!b3Ep%-&R&WD0)k*$x`v9 z(9I++$)u&cQEPNcPRnZfL>Odk(b&mzMUEFCBo|5pvaX7I^zv91-TsvCsMTQ2^Uf|% z09$G2C!_2%#bTkV@DX;WoW#D@j+yPs#X!X}zk;fwzId{pxT(xW&P=;e!X^ucKg6m-ZbpXOP|{JTws z3)?fZ0w#$@GA6*VXvn4@U2%iT2y;l5Q!c)8Bva{{l}?iu(D-2`7(iEW*!01k%T{b5 zL)ySkJkMpI)P$6bEi1|;rPP!BB`5>R4kr9>;Bt>Hyl)g*=ALw=|0kpU!8Y{DMC1k1 zbK<+bI+_VuOyG0(0C?W>*$wwQdN6ryj|HKe$qgW4lKR7JEu+oi8X`|CS=pLHh}N%9 zOfkq_gCz*!khaOe%fv^B-X_`Xd(WoCBt%G@_&_xa0l2*s?22I<9cm*jHBO+-?8V01 zX3}Qq>=5!E7@meICi&mJ~+c!_h zzAKYXsWSB$A$3S^!)(kHmyX7uWCs~n4l`QU6l5YeylP8AyW ztEPA;=u;#z&Kzby_G$ytp5lBjChA?*$x_I}yw}7f`^8VF*MSmH&OL`3eDC^`l!?$Z z6DHAZ&J0_|4$Q3O(ypSGECw~i9WSNg_GqVg5N{Ahs7c)tQI(GU4Yi~tnCp&erxK;t zpNTBdztWU^r@1OL;biX2IL5xl`|A7&BWK$~k94D&ov1`ddPS~aK9C$;HUBDM+r!Wd z7l>byRQ3+91pN#FhJx%>)m$Zd+hxU!_7`EBwkc?YZ3Cw2$T`V{@ZXi!8<1P%#@eLG z_AvC3y@}j9^WftQk`d6J@eEC;yU=+5ceL0KqG`V=LEmJNLk^w@!hFRfIrPTu=!P_0 zNIlw-bc;u|pe&P#;!R`s$ZveL)34Wo?X)k7Z@ZWXXp*YgH36iPLj?vqgQl&;UwY&= zq;^1a$Bh6!{FV}(It^=b$}+eO-kM#qo(YAx(BxYD5yVJCk`{V<*tA@n+|J75yZWdA zFi{HgRxwL}v5HJOy!`ZbfH*-K0{nf&3gvcrpv`pu@V{TAmM2gm(;8mmpQ*I1WbhdY9@KQCx|=ACrd5U@Ply zy@YLx^03foac8nLSMl!FbMHXLc`8VbF&(a)W{pv5_D^FoWd^RXp)sb6Uv$R!xCkch zR{{j~)`0gICtTtN!o0(G0qKsqnQdA^T@i*#+)0pmnsfo|ebPbz5Id!Z)Nr{~iACwd zBcV8-BVfDjk`34OSY?2{S(%%=FF=K!{c|_)6HUU{F?w4)tKQ|=V9M4arvZU6y)kYt zIdwL-g84n=(^~gj>TCU!C764h;BZ4(cX{ERP`TD7?Dq=N91`%fYI_tmSjVhiDb>S*rfjGMfT+1-rS z;e#)M2%jI9NOn`9@hzz+hnsgy+%z1v@RWKqjif=se0r*1AfxQEzTSo-`(e~BDYK2W zvv6r%0#QmN62;l-$j#yxnJCKnv^~{7bhO@BPn)(L$D%s=k97q_B8~~+_lV#3rXuAP zxX4Cau!uE9mcZy+_<;WBh`3pP5<($&Ez}*_q2!mPucJRlCaT9qO~AupEod6q)p*6B z^t77SIB@tHIqsN0x0|it9S}dnbzD=v2LbAUrjGmJ<%FX*2Y!L{%AL59!|ECI5L77~ zu0?M!v||=!F;D$T-ZIl@q5#L9`tpOlghDDZ05rX9zxo>>_fgoI`wRK(Bw3Uoli7j- zKd)`XK#dO~osHC}bTuprgvfgnYDzV}-dl+5u=@Q|I*`hhmei_*V<;mkudnX%`} zm~JdJRmaR5s8hOlI=#e{CGY?FtQ$-FpvKmGI1l5oMTxo;Y>C=2R7NoEF%a87n14$s^8?ANE?`Mjc7CRa;|VMqL(sWhMA^(6uYj* z1?tSj?p^bgQG$Di;C^#eX`>tJKY&=Z$rCQr2)5?Gs`ioDMXCu*(w9S2lf2GG(q|KU zZA?8Nhhls)c2ta2D#S1CpIRyI{QjvEelHzO6eyH1zW6gJV+A8=)3%Y5P4FqT&p$7^ z9z1mc`qaINF20U{u!T5tkJBo_lpp6sxA6>{;eHG0iedWY`_pki61;JP&T6#;XB7m- z8A{(EF#ZV2&IOZ4AAaqflaqKEke9)dS-)7<_xf%~h4IOL<>{G5edKm)h)GtQb9!CX z5~Pm=zX6TMh} zQHO2(F9}9TCdDV`!J~PHz{dkaM!GfcKs##6^^Id}Iwv|c>mc%if ziTpoW?BT-1)3O0i=P<#L?CKIi1KHTx)M3z4OhQo7&xo77p(Fzm25yY$Yi5^-D)r{p zGVn>>Q-j&Bk_vly>2=cZc}n$*EwfdB2y+w+DfNx)@&O*glFjc%eYz0(I!ZG7W5}`d zN}ir&rnnCd3KHGfAQtzD-!i(!o|jwssKc|@d?R+ z>+_aeGLlr1e6A6za$T+*hDakqy=lhd=#MR7*VW$NE=x{oKZb53&9>e93&?$-6*){I zu+A$ze)jZ$&Xqup5uP1un04_Dx*pPEGfpnY*PDIk zL}Q^@s_$NsBh1K^D@WU3r~JxEzWzwy56=(KB35^xtW6p9@G_CdkC@C<`LRT|`n=sYhIdNz5k6h`?z5h{ek@u@K?-z{ zwyy?B(E302!yL;fa5BC=bfNRl%;^+-xZ54$KJJ;Agq3fY-c~Wq8ZGTq>ZWAsS-8=F zO2u>I2e{6zm>1%N+DMQ3drD7ze(DbrDOU|M!7UAipPnC^NNV-ccD1kbR(_WB9zG|s zF#%d*uS#Rq>F~XoJ7rLf694I{!MMkeU?L!gr^VG6E*%~!U|sHPAga^*c%khfTl&lg zHRB$=*8hj&x)-GNjD^YeCD@~`{tU|Ep6-5)PAI$xci~LsK$G7eHkhWJX^|v7NS04* zlyZ{)k@s@1p6DDZZgm88=M+1#DScT;qq&0Hs>vZZU1E?FMed`dw#O6IXlp35Y6*im z9dSLsUsCHEjGg1dDEO*z{j^Y3Tr%GpQ;SKT>;qs)m8~=JKA2+1Vz_j4HJztR05GV= z(qWCcRoya=c5;?b>_m+UG3c>-ouYvca$BNwH)?GRFRL}^m5XYK-Jox=GLa#$1cZz2 zoY<1oH6>wL$gg3#Q&BNqL zj%b>GXNB{bJw@8H(k??M{W72k{Sv=OA=ShEtLZPywo<#ntha?yY%nXs$yh2?yAqI2 zDctc71Rw4IX*KCQ-V|d}A(JiP|5V)cyng|;YGcebU_m#+g){G5`7lj}_uIegc7&7c zB6Qc6zc1x7#m83Z(6wX4G;4DRYXxO5Bq^O%C8kUGX#0nKx1Oe zq6}JgefsNbL)rx0vRbM{*iku0dN}b4XYE-^c(0czYG4WRv!}8f+C28{R`_GnS9zge zG8eASa^)ZU<{I`qM={afiuzWzaeOO<{Pa~YZiROfM1JeZS(t4AyTX#B)HJyAQKa0+ z?h3=*gYq9`Z9TuQNf?aNUbt6Y7)imXRTs1n;_LzKYrp0Hli83k6PFlSmC=9xFCb8E zzz-L68DoDSCJ*~k=1r+0H4^8o1PH`4;RM<(=-eskb(L(}ReAHwcz(H?d+tJ?(=VA1 z5pRG*ouH8`DNo+ccMP%8B~C57dOVy|Xs+m2Xbu7eEZpjo^06FAiA~%{FKQPoE`i(s zeZ6)%W?ibC>bm@P%c1Xb)3EE&QP=;!7baDR88Wa&7uq!-YE`fDd1LsNEj;ndJvkEo zrrfg6zvP4=Q&YIH_1eR>uU5Yl zy~AqeE*35H+*bI0DH+4Sz-7T6Q4$3MPb zu5)$zaasFjAU)*cTmfw~URJtM;m!}<(wLMeos_~=yJamkYy3E!=~w^p>84om)r%xU zmLQ4q_`d*p9=$+t>@3jNwx+^~OCQM2SgFTu*fQf!U97y5ly7S233oNODEB-*;oOxc z?6(P}`3z<$jvj(1pYFOaII&>2g4#>+$m=jg0{UyZU*E zW_%d_Tf_iA+HoS$U-0AvBm?A={h;@jT^{`>rBIs&falE9xu)IY)>6QZ2)7COxHBzW z&2zD=f7ndg5Zic`7AZ;ERBz0}z0ip%F=ElWSAzLG{N+|g^lSZyh4fkf2Oo?Z%tVAX zx?z>swv2E!GC!3S0^}^_>yQBBJVHh((@(X(Icnpp;Zp6YH}J@TpE&>TO@?x9Sh4lr zF(J&e)EPGPd=Z5rJQaDKi`7vQn&+|SFY%RHw_n{^gjebZn)T9MemT{ap=SP4CbZXQ z44H+wC5pXn_G?3Tl_?~~8GE@DYQ*T<-oIO6Y|J1u+-tZIPI~x0Z}Q$O{kJzKJPoJQ zuD=$5SRyNze#-Dg$miXgX<>5yui2ZC$3-{%HED+>`*k~llkw6a9bWn!qkDUS+TdIZ zrMqnd^O)|3`@fkK(8y#ZGX?U>IV@~>k>s4#jTK%Q5Mo)}@qoTkXV22*ySQh}Nso+< zBkU~J8pRrsu7h7PHIut_BmqbN9~e>@kJ_U-$vUmn7v(`0?^lgmBM6SQ=NvMJaMtg0 ztg?HWmL&nHF5-k7(r&7!B}v~W$@`~86`GZIPF|b^3r=QAtD^c*LR;%_tZKDvPVs|j z6I=4FdMzDH(U> z%D`K5bc&x=+zYrLkC77WyIJB*s>g-WHbJGmz*BM$_Ved6u8ZJmH^wM=|y<ulaIvZ=lHQrJx&IM#)N4Y+Sl7l$&@=F{U-g&-Nk!{Thf_gGE4HA8>q0!8f_NKNPQ0`*=YWr*E?PGR zY~A)!H(t}XS+izONh%#BeSz>1JzwVocSpq}$B+Am3k%+%9OVN5>hY{W?1?I)JK%2Y z_>_E6{L0v(1wGzap9=rFFFtzRCio~qpBpi$PNI|>T&940zIITVGQDqt6Lt<->b(D3 z{w?u}jtiguA&4>5IUN`kggGHGNp-gBb>q%$(g-l8;P*2G1XZwHF|j+~tk-)u z2+v+M;tuMW(9-;aUFhP_gS6P=OIc>ccLYtEpbu?kz?TDqXRY>eMvFC+fB63bZr^65 i{$Fpl{(Bpu{@=R|xHvcu0Gb8=KRvL|z5eSl|9=2(pz{a- literal 0 HcmV?d00001 From a46ad1609cc7dec4ede381e94368fcc63bf08c3e Mon Sep 17 00:00:00 2001 From: Waleed Date: Fri, 11 Sep 2026 11:02:19 -0700 Subject: [PATCH 02/15] fix(consent): stop asking for consent from a policy we failed to fetch (#7766) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(consent): stop asking for consent from a policy we failed to fetch The consent banner reappears for people who have already answered it. The policy lookup is a cross-origin call to the consent instance, and that origin intermittently answers a bot challenge instead: HTTP 403, an HTML body, and `x-vercel-mitigated: challenge`. A browser fetch cannot solve a JS challenge, so the runtime substitutes a generic opt-in policy and carries on as though the lookup succeeded. Because consent records the fingerprint of the policy they were given under, the substituted policy never matches, the runtime treats it as a material policy change, clears the stored consent, and asks again — with a question the visitor's jurisdiction may not even require. The banner now renders only when the policy was actually resolved. A load that fell back asks nothing; the next load that reaches the real policy asks if it still needs to. The root cause belongs to the consent instance, which should not challenge an endpoint browsers call over XHR. Reproduced against production: consent given, cookie present, then one challenged lookup and the banner returns with the cookie deleted. Also records why the backend URL must stay cross-origin. The documented same-origin rewrite would dodge the challenge, but the instance resolves jurisdiction from the address the request arrives from, and ignores every forwarding header we could send (measured: x-forwarded-for, x-real-ip, true-client-ip, cf-connecting-ip, x-vercel-ip-country). Sim has no edge that supplies a country header, so proxying would resolve every visitor to our own region and stop asking the EU for consent entirely. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_015tTS2kSemtRPmTq9ezGRCc * fix(consent): keep the explicitly opened dialog working during a fallback The guard suppressed the whole card, including a dialog the visitor opened from the Cookie Policy or the footer control. That leaves a published promise — change your choice at any time — wired to a button that does nothing. Guard the unsolicited banner only. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_015tTS2kSemtRPmTq9ezGRCc --------- Co-authored-by: Claude Opus 5 --- .../_shell/consent/consent-banner.test.tsx | 87 +++++++++++++++++++ .../sim/app/_shell/consent/consent-banner.tsx | 21 ++++- apps/sim/lib/consent/constants.ts | 13 +++ 3 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 apps/sim/app/_shell/consent/consent-banner.test.tsx diff --git a/apps/sim/app/_shell/consent/consent-banner.test.tsx b/apps/sim/app/_shell/consent/consent-banner.test.tsx new file mode 100644 index 00000000000..76af8161697 --- /dev/null +++ b/apps/sim/app/_shell/consent/consent-banner.test.tsx @@ -0,0 +1,87 @@ +/** + * @vitest-environment jsdom + */ +import { act } from 'react' +import { createRoot, type Root } from 'react-dom/client' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' + +const { mockUseConsentManager, mockUseHeadlessConsentUI } = vi.hoisted(() => ({ + mockUseConsentManager: vi.fn(), + mockUseHeadlessConsentUI: vi.fn(), +})) + +vi.mock('@c15t/nextjs/headless', () => ({ + useConsentManager: mockUseConsentManager, + useHeadlessConsentUI: mockUseHeadlessConsentUI, +})) + +vi.mock('@/app/_shell/consent/consent-preferences', () => ({ + CONSENT_LINK_CLASS: 'link', + ConsentPreferences: () => , +})) + +import { ConsentBanner } from '@/app/_shell/consent/consent-banner' + +let root: Root | null = null + +function render(): HTMLDivElement { + ;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true + const container = document.createElement('div') + document.body.appendChild(container) + root = createRoot(container) + act(() => root?.render()) + return container +} + +function isBannerShown(container: HTMLDivElement): boolean { + return container.querySelector('section[aria-label="Cookie preferences"]') !== null +} + +beforeEach(() => { + mockUseHeadlessConsentUI.mockReturnValue({ + banner: { isVisible: true, allowedActions: ['accept', 'reject', 'customize'] }, + dialog: { isVisible: false, allowedActions: [] }, + openDialog: vi.fn(), + performAction: vi.fn(), + saveCustomPreferences: vi.fn(), + }) +}) + +afterEach(() => { + act(() => root?.unmount()) + root = null + vi.clearAllMocks() +}) + +describe('ConsentBanner', () => { + it.each(['backend', 'backend-cache-hit', 'ssr'])( + 'asks for consent when the policy came from %s', + (initDataSource) => { + mockUseConsentManager.mockReturnValue({ initDataSource }) + + expect(isBannerShown(render())).toBe(true) + } + ) + + it('still renders a dialog the visitor opened, so the published control works', () => { + mockUseHeadlessConsentUI.mockReturnValue({ + banner: { isVisible: false, allowedActions: [] }, + dialog: { isVisible: true, allowedActions: ['accept', 'reject', 'customize'] }, + openDialog: vi.fn(), + performAction: vi.fn(), + saveCustomPreferences: vi.fn(), + }) + mockUseConsentManager.mockReturnValue({ initDataSource: 'offline-fallback' }) + + expect(isBannerShown(render())).toBe(true) + }) + + it('asks nothing when the policy lookup fell back', () => { + // A bot challenge on the third-party `/init` makes the runtime substitute a + // generic opt-in policy, which would otherwise re-prompt visitors who had + // already consented under the real one. + mockUseConsentManager.mockReturnValue({ initDataSource: 'offline-fallback' }) + + expect(isBannerShown(render())).toBe(false) + }) +}) diff --git a/apps/sim/app/_shell/consent/consent-banner.tsx b/apps/sim/app/_shell/consent/consent-banner.tsx index a3878c0d02b..bd3143edb1c 100644 --- a/apps/sim/app/_shell/consent/consent-banner.tsx +++ b/apps/sim/app/_shell/consent/consent-banner.tsx @@ -1,6 +1,6 @@ 'use client' -import { useHeadlessConsentUI } from '@c15t/nextjs/headless' +import { useConsentManager, useHeadlessConsentUI } from '@c15t/nextjs/headless' import { Chip } from '@sim/emcn' import { AnimatePresence, motion, useReducedMotion } from 'framer-motion' import Link from 'next/link' @@ -29,12 +29,29 @@ const CATEGORIES_OPEN = { height: 'auto', opacity: 1 } as const * the light layer on `` through `ThemeProvider`'s forced theme, or is a * themed app page where inheriting is what should happen — the card no longer * decides for itself. + * + * Nothing is asked *unprompted* when the policy lookup failed. `/init` answers + * from a third-party origin, and when that origin refuses the request — a bot + * challenge returns `403` with an HTML body — the runtime substitutes a generic + * opt-in policy rather than surfacing the failure. Volunteering a banner from + * it asks a question the visitor's jurisdiction may not require, and asks it of + * people who already answered, because the substituted policy's fingerprint + * never matches the one their stored consent was recorded under. The next load + * that reaches the real policy asks properly if it still needs to. + * + * A dialog the visitor opened themselves still renders, fallback or not: the + * Cookie Policy promises the choice can be changed at any time, and a control + * that silently does nothing breaks that promise. A choice saved during a + * fallback is recorded against the substituted policy and will be asked for + * again once the real one resolves, which is the lesser of the two failures. */ export function ConsentBanner() { const { banner, dialog, openDialog, performAction, saveCustomPreferences } = useHeadlessConsentUI() + const { initDataSource } = useConsentManager() const prefersReducedMotion = useReducedMotion() + const isPolicyResolved = initDataSource !== 'offline-fallback' const isExpanded = dialog.isVisible const surfaceName = isExpanded ? 'dialog' : 'banner' const { allowedActions } = isExpanded ? dialog : banner @@ -42,7 +59,7 @@ export function ConsentBanner() { return ( - {(banner.isVisible || dialog.isVisible) && ( + {((isPolicyResolved && banner.isVisible) || dialog.isVisible) && ( Date: Fri, 11 Sep 2026 11:26:38 -0700 Subject: [PATCH 03/15] fix(cli): keep only the agent name from a versioned AI_AGENT declaration (#7775) * fix(cli): keep only the agent name from a versioned AI_AGENT declaration * docs(cli): say that usage reports get an approximate location from their address * fix(cli): trim only the versioned AI_AGENT shape to its name --- apps/docs/content/docs/cli/usage-data.mdx | 7 +++++++ .../src/telemetry/coding-agent.test.ts | 16 +++++++++++++++- .../sim-cli/src/telemetry/coding-agent.ts | 19 +++++++++++++++++-- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/apps/docs/content/docs/cli/usage-data.mdx b/apps/docs/content/docs/cli/usage-data.mdx index 61528c8554c..229bfa374e5 100644 --- a/apps/docs/content/docs/cli/usage-data.mdx +++ b/apps/docs/content/docs/cli/usage-data.mdx @@ -31,6 +31,13 @@ workspace ids, error messages, environment variable values, credentials, or the address of the deployment you talk to. The report leaves your machine from a separate short-lived process that is not given your API key. +## Location + +The report carries no location of its own. The analytics service derives an +approximate location (country and city) from the address the report arrived +from, the way any HTTP request exposes one, and Sim uses that only to see +which regions use the CLI. + ## Identity The first run mints a random device id and stores it in `telemetry.json` under diff --git a/packages/sim-cli/src/telemetry/coding-agent.test.ts b/packages/sim-cli/src/telemetry/coding-agent.test.ts index 583afe1e9d3..4312ab8df83 100644 --- a/packages/sim-cli/src/telemetry/coding-agent.test.ts +++ b/packages/sim-cli/src/telemetry/coding-agent.test.ts @@ -30,7 +30,21 @@ describe('detectCodingAgent', () => { }) it('lets an agent declare its own name over every vendor marker', () => { - expect(detectCodingAgent({ AI_AGENT: 'Some-Agent_2', CLAUDECODE: '1' })).toBe('some-agent_2') + expect(detectCodingAgent({ AI_AGENT: 'Some-Agent', CLAUDECODE: '1' })).toBe('some-agent') + }) + + it('keeps only the name from a declaration that carries a version and role', () => { + expect(detectCodingAgent({ AI_AGENT: 'claude-code_2-1-268_agent', CLAUDECODE: '1' })).toBe( + 'claude-code' + ) + }) + + it('keeps an underscored name that carries no version', () => { + expect(detectCodingAgent({ AI_AGENT: 'github_copilot_vscode_agent' })).toBe( + 'github_copilot_vscode_agent' + ) + expect(detectCodingAgent({ AI_AGENT: 'my_agent_2' })).toBe('my_agent') + expect(detectCodingAgent({ AI_AGENT: '_', CLAUDECODE: '1' })).toBe('_') }) it('ignores a declared name that is not a well-formed token', () => { diff --git a/packages/sim-cli/src/telemetry/coding-agent.ts b/packages/sim-cli/src/telemetry/coding-agent.ts index e0fd2c58b82..79605e9097f 100644 --- a/packages/sim-cli/src/telemetry/coding-agent.ts +++ b/packages/sim-cli/src/telemetry/coding-agent.ts @@ -59,11 +59,26 @@ const AGENT_MARKERS: readonly AgentMarker[] = [ { name: 'crush', matches: anyOf('CRUSH') }, ] -/** A name an agent declared for itself, when it is a well-formed token. */ +/** + * The shape Claude Code declares itself in: the name, its version with dots + * replaced by dashes, and a role, joined by underscores — the form the Stripe + * CLI's parser also expects. Only this shape is trimmed to its name; an + * underscore anywhere else is part of the name. + */ +const VERSIONED_DECLARATION = /^(.+?)_\d+(?:-\d+)*(?:_[a-z0-9-]+)?$/ + +/** + * A name an agent declared for itself, when it is a well-formed token. + * + * A declaration that carries a version and role (`claude-code_2-1-268_agent`) + * is reduced to its name, so a breakdown by agent does not split into one + * slice per release. Any other declaration is kept whole, underscores included. + */ function declaredAgentName(value: string | undefined): string | undefined { const trimmed = value?.trim().toLowerCase() if (!trimmed || trimmed.length > MAX_AGENT_NAME_LENGTH) return undefined - return AGENT_NAME_PATTERN.test(trimmed) ? trimmed : undefined + if (!AGENT_NAME_PATTERN.test(trimmed)) return undefined + return VERSIONED_DECLARATION.exec(trimmed)?.[1] ?? trimmed } /** From 52c68b2af746b079525f4fdc6e734548b6b630d5 Mon Sep 17 00:00:00 2001 From: Vikhyath Mondreti Date: Fri, 11 Sep 2026 11:33:17 -0700 Subject: [PATCH 04/15] fix(db): exclude pending-drop columns from inserts (#7774) * fix(db): exclude pending-drop columns from inserts * fix(audit): resolve pending-drop insert imports by scope --- apps/sim/app/api/files/uploads/finalizers.ts | 3 +- apps/sim/app/api/v1/admin/credits/route.ts | 5 +- .../api/v1/admin/users/[id]/billing/route.ts | 3 +- .../workspace-forking/lib/copy/copy-files.ts | 3 +- apps/sim/lib/admin/dashboard.ts | 4 +- apps/sim/lib/auth/anonymous.ts | 3 +- apps/sim/lib/billing/core/usage.ts | 5 +- .../lib/billing/enterprise-provisioning.ts | 4 +- apps/sim/lib/billing/organization.ts | 11 +- .../organizations/create-organization.ts | 5 +- .../lib/billing/organizations/membership.ts | 4 +- apps/sim/lib/billing/storage/tracking.ts | 5 +- apps/sim/lib/copilot/chat/fork-chat-files.ts | 3 +- ...rganization-personal-tokens.integration.ts | 4 +- .../organization-mcp-search.integration.ts | 4 +- .../seed-source-access-fixture.ts | 4 +- .../slack-search-turns.integration.ts | 4 +- apps/sim/lib/logs/execution/logger.ts | 3 +- .../workspace/workspace-file-manager.ts | 5 +- apps/sim/lib/uploads/server/metadata.ts | 7 +- packages/db/insert-columns.test.ts | 145 +++++++++++++ packages/db/insert-columns.ts | 35 ++++ packages/db/package.json | 4 + packages/db/schema.ts | 49 ++--- scripts/check-pending-drop-tables.test.ts | 157 ++++++++++++++ scripts/check-pending-drop-tables.ts | 193 ++++++++++++++++-- scripts/tsconfig.json | 3 + scripts/vitest.config.ts | 3 + 28 files changed, 613 insertions(+), 65 deletions(-) create mode 100644 packages/db/insert-columns.test.ts create mode 100644 packages/db/insert-columns.ts create mode 100644 scripts/check-pending-drop-tables.test.ts diff --git a/apps/sim/app/api/files/uploads/finalizers.ts b/apps/sim/app/api/files/uploads/finalizers.ts index bc51d3a034a..98ba94e15df 100644 --- a/apps/sim/app/api/files/uploads/finalizers.ts +++ b/apps/sim/app/api/files/uploads/finalizers.ts @@ -1,6 +1,7 @@ import { AuditAction, AuditResourceType, recordAudit } from '@sim/audit' import { type Principal, resolvePrincipalAuditAttribution } from '@sim/auth/principal' import { db } from '@sim/db' +import { withInsertColumns } from '@sim/db/insert-columns' import { type WorkspaceFileRow, workspaceFileColumns, workspaceFiles } from '@sim/db/schema' import { generateId } from '@sim/utils/id' import { eq, sql } from 'drizzle-orm' @@ -354,7 +355,7 @@ async function insertOrLoadFileMetadata( const now = new Date() const [inserted] = await db - .insert(workspaceFiles) + .insert(withInsertColumns(workspaceFiles, workspaceFileColumns)) .values({ id: generateId(), key: input.key, diff --git a/apps/sim/app/api/v1/admin/credits/route.ts b/apps/sim/app/api/v1/admin/credits/route.ts index 2c41426d1f2..da245cdc7a4 100644 --- a/apps/sim/app/api/v1/admin/credits/route.ts +++ b/apps/sim/app/api/v1/admin/credits/route.ts @@ -25,7 +25,8 @@ import { AuditAction, AuditResourceType, recordAudit } from '@sim/audit' import { db } from '@sim/db' -import { organization, subscription, user, userStats } from '@sim/db/schema' +import { withInsertColumns } from '@sim/db/insert-columns' +import { organization, subscription, user, userStats, userStatsColumns } from '@sim/db/schema' import { createLogger } from '@sim/logger' import { generateShortId } from '@sim/utils/id' import { normalizeEmail } from '@sim/utils/string' @@ -155,7 +156,7 @@ export const POST = withRouteHandler( .limit(1) if (!existingStats) { - await db.insert(userStats).values({ + await db.insert(withInsertColumns(userStats, userStatsColumns)).values({ id: generateShortId(), userId: entityId, }) diff --git a/apps/sim/app/api/v1/admin/users/[id]/billing/route.ts b/apps/sim/app/api/v1/admin/users/[id]/billing/route.ts index d3cdb3c5e9d..4ab52cb09e9 100644 --- a/apps/sim/app/api/v1/admin/users/[id]/billing/route.ts +++ b/apps/sim/app/api/v1/admin/users/[id]/billing/route.ts @@ -20,6 +20,7 @@ */ import { db } from '@sim/db' +import { withInsertColumns } from '@sim/db/insert-columns' import { member, organization, @@ -247,7 +248,7 @@ export const PATCH = withRouteHandler( if (existingStats) { await db.update(userStats).set(updateData).where(eq(userStats.userId, userId)) } else { - await db.insert(userStats).values({ + await db.insert(withInsertColumns(userStats, userStatsColumns)).values({ id: generateShortId(), userId, ...updateData, diff --git a/apps/sim/ee/workspace-forking/lib/copy/copy-files.ts b/apps/sim/ee/workspace-forking/lib/copy/copy-files.ts index e5bbfd5069a..b2fc0597106 100644 --- a/apps/sim/ee/workspace-forking/lib/copy/copy-files.ts +++ b/apps/sim/ee/workspace-forking/lib/copy/copy-files.ts @@ -1,4 +1,5 @@ import { db } from '@sim/db' +import { withInsertColumns } from '@sim/db/insert-columns' import { workspaceFileColumns, workspaceFiles } from '@sim/db/schema' import { createLogger } from '@sim/logger' import { getErrorMessage } from '@sim/utils/errors' @@ -362,7 +363,7 @@ export async function executeForkFileBlobCopies( await db.transaction(async (tx) => { assertForkCopyActive(control) const [inserted] = await tx - .insert(workspaceFiles) + .insert(withInsertColumns(workspaceFiles, workspaceFileColumns)) .values({ id: task.targetFileId, key: task.targetKey, diff --git a/apps/sim/lib/admin/dashboard.ts b/apps/sim/lib/admin/dashboard.ts index 2ae89882bfa..b66d94f6ae1 100644 --- a/apps/sim/lib/admin/dashboard.ts +++ b/apps/sim/lib/admin/dashboard.ts @@ -1,5 +1,6 @@ import { AuditAction, AuditResourceType, recordAudit } from '@sim/audit' import { db } from '@sim/db' +import { withInsertColumns } from '@sim/db/insert-columns' import { member, organization, @@ -11,6 +12,7 @@ import { usageLog, user, userStats, + userStatsColumns, workspace, } from '@sim/db/schema' import { generateId } from '@sim/utils/id' @@ -1524,7 +1526,7 @@ export async function grantDashboardUserBalance( ? null : getPerUserMinimumLimit(initialSubscription).toString() await tx - .insert(userStats) + .insert(withInsertColumns(userStats, userStatsColumns)) .values({ id: generateId(), userId, diff --git a/apps/sim/lib/auth/anonymous.ts b/apps/sim/lib/auth/anonymous.ts index c4be061bea0..465992f6ddd 100644 --- a/apps/sim/lib/auth/anonymous.ts +++ b/apps/sim/lib/auth/anonymous.ts @@ -1,4 +1,5 @@ import { db } from '@sim/db' +import { withInsertColumns } from '@sim/db/insert-columns' import * as schema from '@sim/db/schema' import { createLogger } from '@sim/logger' import { generateId } from '@sim/utils/id' @@ -37,7 +38,7 @@ export async function ensureAnonymousUserExists(): Promise { }) if (!existingStats) { - await db.insert(schema.userStats).values({ + await db.insert(withInsertColumns(schema.userStats, schema.userStatsColumns)).values({ id: generateId(), userId: ANONYMOUS_USER_ID, currentUsageLimit: '10000000000', diff --git a/apps/sim/lib/billing/core/usage.ts b/apps/sim/lib/billing/core/usage.ts index 7038083ec79..1a9ad247645 100644 --- a/apps/sim/lib/billing/core/usage.ts +++ b/apps/sim/lib/billing/core/usage.ts @@ -1,4 +1,5 @@ import { db } from '@sim/db' +import { withInsertColumns } from '@sim/db/insert-columns' import { member, organization, settings, user, userStats, userStatsColumns } from '@sim/db/schema' import { createLogger } from '@sim/logger' import { isOrgAdminRole } from '@sim/platform-authz/workspace' @@ -155,7 +156,7 @@ export async function getOrgUsageLimit( */ export async function handleNewUser(userId: string): Promise { try { - await db.insert(userStats).values({ + await db.insert(withInsertColumns(userStats, userStatsColumns)).values({ id: generateId(), userId: userId, currentUsageLimit: getFreeTierLimit().toString(), @@ -182,7 +183,7 @@ export async function handleNewUser(userId: string): Promise { */ export async function ensureUserStatsExists(userId: string): Promise { await db - .insert(userStats) + .insert(withInsertColumns(userStats, userStatsColumns)) .values({ id: generateId(), userId: userId, diff --git a/apps/sim/lib/billing/enterprise-provisioning.ts b/apps/sim/lib/billing/enterprise-provisioning.ts index 6a5f1152037..50918ed50d6 100644 --- a/apps/sim/lib/billing/enterprise-provisioning.ts +++ b/apps/sim/lib/billing/enterprise-provisioning.ts @@ -1,10 +1,12 @@ import { AuditAction, AuditResourceType, recordAudit, recordAuditOnce } from '@sim/audit' import { db } from '@sim/db' +import { withInsertColumns } from '@sim/db/insert-columns' import { invitation, invitationWorkspaceGrant, member, organization, + organizationColumns, outboxEvent, permissions, subscription, @@ -1638,7 +1640,7 @@ export async function issueEnterpriseProvisioning( if (organizationToCreate) { const now = new Date() - await tx.insert(organization).values({ + await tx.insert(withInsertColumns(organization, organizationColumns)).values({ id: organizationToCreate.id, name: organizationToCreate.name, slug: slugifyOrganizationName(organizationToCreate.name, organizationToCreate.id), diff --git a/apps/sim/lib/billing/organization.ts b/apps/sim/lib/billing/organization.ts index fc6219b250c..e1e3e3d2951 100644 --- a/apps/sim/lib/billing/organization.ts +++ b/apps/sim/lib/billing/organization.ts @@ -1,5 +1,12 @@ import { db } from '@sim/db' -import { member, organization, subscription as subscriptionTable, user } from '@sim/db/schema' +import { withInsertColumns } from '@sim/db/insert-columns' +import { + member, + organization, + organizationColumns, + subscription as subscriptionTable, + user, +} from '@sim/db/schema' import { createLogger } from '@sim/logger' import { isOrgAdminRole } from '@sim/platform-authz/workspace' import { generateId } from '@sim/utils/id' @@ -442,7 +449,7 @@ export async function ensureOrganizationForTeamSubscriptionTx( organizationId = `org_${generateId()}` const now = new Date() - await tx.insert(organization).values({ + await tx.insert(withInsertColumns(organization, organizationColumns)).values({ id: organizationId, name: userData.name || `${userData.email || 'User'}'s Team`, slug: `${userId}-team-${generateId()}` diff --git a/apps/sim/lib/billing/organizations/create-organization.ts b/apps/sim/lib/billing/organizations/create-organization.ts index 1947a333745..9fb27bffb74 100644 --- a/apps/sim/lib/billing/organizations/create-organization.ts +++ b/apps/sim/lib/billing/organizations/create-organization.ts @@ -1,5 +1,6 @@ import { db } from '@sim/db' -import { member, organization } from '@sim/db/schema' +import { withInsertColumns } from '@sim/db/insert-columns' +import { member, organization, organizationColumns } from '@sim/db/schema' import { generateId } from '@sim/utils/id' import { and, eq, ne } from 'drizzle-orm' import { acquireUserBillingIdentityLock } from '@/lib/billing/organizations/billing-identity-lock' @@ -100,7 +101,7 @@ export async function createOrganizationWithOwnerTx( throw new OrganizationSlugTakenError(slug) } - await tx.insert(organization).values({ + await tx.insert(withInsertColumns(organization, organizationColumns)).values({ id: organizationId, name, slug, diff --git a/apps/sim/lib/billing/organizations/membership.ts b/apps/sim/lib/billing/organizations/membership.ts index d4bd323b3cb..7687d32db23 100644 --- a/apps/sim/lib/billing/organizations/membership.ts +++ b/apps/sim/lib/billing/organizations/membership.ts @@ -6,6 +6,7 @@ */ import { db } from '@sim/db' +import { withInsertColumns } from '@sim/db/insert-columns' import { account, credential, @@ -18,6 +19,7 @@ import { subscription as subscriptionTable, user, userStats, + userStatsColumns, workspace, workspaceFiles, } from '@sim/db/schema' @@ -1837,7 +1839,7 @@ export async function transferOrganizationOwnership( if (oldStats) { await tx - .insert(userStats) + .insert(withInsertColumns(userStats, userStatsColumns)) .values({ id: generateId(), userId: newOwnerUserId, diff --git a/apps/sim/lib/billing/storage/tracking.ts b/apps/sim/lib/billing/storage/tracking.ts index 7ae702a94c3..7f416fe0180 100644 --- a/apps/sim/lib/billing/storage/tracking.ts +++ b/apps/sim/lib/billing/storage/tracking.ts @@ -17,7 +17,8 @@ * writes any of them or deletes a locked row. */ -import { organization, userStats, workspace } from '@sim/db/schema' +import { withInsertColumns } from '@sim/db/insert-columns' +import { organization, userStats, userStatsColumns, workspace } from '@sim/db/schema' import { createLogger } from '@sim/logger' import { generateId } from '@sim/utils/id' import { isRecordLike } from '@sim/utils/object' @@ -631,7 +632,7 @@ export async function checkAndIncrementStorageUsageInTx( if (!orgScoped) { await tx - .insert(userStats) + .insert(withInsertColumns(userStats, userStatsColumns)) .values({ id: generateId(), userId, diff --git a/apps/sim/lib/copilot/chat/fork-chat-files.ts b/apps/sim/lib/copilot/chat/fork-chat-files.ts index 719b77d867e..084bc682cf5 100644 --- a/apps/sim/lib/copilot/chat/fork-chat-files.ts +++ b/apps/sim/lib/copilot/chat/fork-chat-files.ts @@ -1,3 +1,4 @@ +import { withInsertColumns } from '@sim/db/insert-columns' import { type WorkspaceFileRow, workspaceFileColumns, workspaceFiles } from '@sim/db/schema' import { createLogger } from '@sim/logger' import { getErrorMessage } from '@sim/utils/errors' @@ -145,7 +146,7 @@ export async function planChatFileCopies(params: { // Ids and keys are generated client-side, so one multi-row insert suffices — // no per-row round trips while the fork transaction is held open. if (copyRows.length > 0) { - await tx.insert(workspaceFiles).values(copyRows) + await tx.insert(withInsertColumns(workspaceFiles, workspaceFileColumns)).values(copyRows) for (const source of rows) { const targetId = idMap.get(source.id) if (!targetId) continue diff --git a/apps/sim/lib/credentials/__integration__/organization-personal-tokens.integration.ts b/apps/sim/lib/credentials/__integration__/organization-personal-tokens.integration.ts index fb1f2ffdd7c..9a86b0f3415 100644 --- a/apps/sim/lib/credentials/__integration__/organization-personal-tokens.integration.ts +++ b/apps/sim/lib/credentials/__integration__/organization-personal-tokens.integration.ts @@ -1,11 +1,13 @@ /** Real storage, encryption, migration, and authorization; no external GitLab calls. */ import { db } from '@sim/db' +import { withInsertColumns } from '@sim/db/insert-columns' import { credential, credentialGroup, credentialGroupEnrollment, member, organization, + organizationColumns, permissions, resourcePolicy, user, @@ -95,7 +97,7 @@ describe('organization personal tokens', () => { updatedAt: now, })) ) - await db.insert(organization).values( + await db.insert(withInsertColumns(organization, organizationColumns)).values( [ids.org, ids.foreignOrg].map((id) => ({ id, name: 'Token fixture organization', diff --git a/apps/sim/lib/knowledge/__integration__/organization-mcp-search.integration.ts b/apps/sim/lib/knowledge/__integration__/organization-mcp-search.integration.ts index 8f8374ebb9f..0b7060df4c6 100644 --- a/apps/sim/lib/knowledge/__integration__/organization-mcp-search.integration.ts +++ b/apps/sim/lib/knowledge/__integration__/organization-mcp-search.integration.ts @@ -12,6 +12,7 @@ import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/ import { CallToolResultSchema } from '@modelcontextprotocol/sdk/types.js' import type { Principal } from '@sim/auth/principal' import { db } from '@sim/db' +import { withInsertColumns } from '@sim/db/insert-columns' import { apiKey, document, @@ -25,6 +26,7 @@ import { oauthClient, oauthConsent, organization, + organizationColumns, organizationSearchIntegration, rateLimitBucket, user, @@ -252,7 +254,7 @@ describe('organization Search MCP with real ingestion and current access', () => updatedAt: new Date(), })) ) - await db.insert(organization).values({ + await db.insert(withInsertColumns(organization, organizationColumns)).values({ id: otherOrganizationId, name: 'Other organization MCP fixture', slug: otherOrganizationId, diff --git a/apps/sim/lib/knowledge/__integration__/seed-source-access-fixture.ts b/apps/sim/lib/knowledge/__integration__/seed-source-access-fixture.ts index 3c0749defc0..22e90269614 100644 --- a/apps/sim/lib/knowledge/__integration__/seed-source-access-fixture.ts +++ b/apps/sim/lib/knowledge/__integration__/seed-source-access-fixture.ts @@ -1,5 +1,6 @@ import { createHash } from 'node:crypto' import { db } from '@sim/db' +import { withInsertColumns } from '@sim/db/insert-columns' import { credential, credentialGroup, @@ -11,6 +12,7 @@ import { knowledgeExternalGroup, knowledgeExternalGroupMember, organization, + organizationColumns, permissions, user, workspace, @@ -69,7 +71,7 @@ export async function seedKnowledgeAclFixture( updatedAt: now, }, ]) - await db.insert(organization).values({ + await db.insert(withInsertColumns(organization, organizationColumns)).values({ id: ids.organizationId, name: 'ACL integration organization', slug: ids.organizationId, diff --git a/apps/sim/lib/knowledge/__integration__/slack-search-turns.integration.ts b/apps/sim/lib/knowledge/__integration__/slack-search-turns.integration.ts index 740cfa9fc69..91e6301593a 100644 --- a/apps/sim/lib/knowledge/__integration__/slack-search-turns.integration.ts +++ b/apps/sim/lib/knowledge/__integration__/slack-search-turns.integration.ts @@ -1,10 +1,12 @@ /** Exercises real PostgreSQL locks and constraints using only isolated, explicitly cleaned fixtures. */ import type { OrganizationDelegatedPrincipal } from '@sim/auth/principal' import { db } from '@sim/db' +import { withInsertColumns } from '@sim/db/insert-columns' import { copilotChats, credential, organization, + organizationColumns, outboxEvent, slackSearchInstallation, slackSearchTurn, @@ -72,7 +74,7 @@ describe('durable Slack Search turns in PostgreSQL', () => { })) ) await db - .insert(organization) + .insert(withInsertColumns(organization, organizationColumns)) .values({ id: organizationId, name: 'Slack queue fixture', slug: organizationId }) await db.insert(credential).values({ id: credentialId, diff --git a/apps/sim/lib/logs/execution/logger.ts b/apps/sim/lib/logs/execution/logger.ts index 840f5804247..45d53d4764c 100644 --- a/apps/sim/lib/logs/execution/logger.ts +++ b/apps/sim/lib/logs/execution/logger.ts @@ -1,4 +1,5 @@ import { db, dbFor } from '@sim/db' +import { withInsertColumns } from '@sim/db/insert-columns' import { organization, usageLog, @@ -698,7 +699,7 @@ export class ExecutionLogger implements IExecutionLoggerService { const startTime = new Date() const [workflowLog] = await execDb - .insert(workflowExecutionLogs) + .insert(withInsertColumns(workflowExecutionLogs, workflowExecutionLogColumns)) .values({ id: generateId(), workflowId, diff --git a/apps/sim/lib/uploads/contexts/workspace/workspace-file-manager.ts b/apps/sim/lib/uploads/contexts/workspace/workspace-file-manager.ts index df414d185b1..33221719dea 100644 --- a/apps/sim/lib/uploads/contexts/workspace/workspace-file-manager.ts +++ b/apps/sim/lib/uploads/contexts/workspace/workspace-file-manager.ts @@ -5,6 +5,7 @@ import { randomBytes } from 'crypto' import { db } from '@sim/db' +import { withInsertColumns } from '@sim/db/insert-columns' import { uploadSession, type WorkspaceFileRow, @@ -266,7 +267,7 @@ async function insertWorkspaceFileMetadataInTx( metadata: WorkspaceFileMetadataInsert ): Promise { const [inserted] = await tx - .insert(workspaceFiles) + .insert(withInsertColumns(workspaceFiles, workspaceFileColumns)) .values({ ...omit(metadata, ['size']), sizeBytes: metadata.size, @@ -1056,7 +1057,7 @@ export async function trackChatUpload( await db.transaction(async (tx) => { const [inserted] = await tx - .insert(workspaceFiles) + .insert(withInsertColumns(workspaceFiles, workspaceFileColumns)) .values({ id: fileId, key: s3Key, diff --git a/apps/sim/lib/uploads/server/metadata.ts b/apps/sim/lib/uploads/server/metadata.ts index 0df26c0cf2c..f0d9661fd6d 100644 --- a/apps/sim/lib/uploads/server/metadata.ts +++ b/apps/sim/lib/uploads/server/metadata.ts @@ -1,4 +1,5 @@ import { db } from '@sim/db' +import { withInsertColumns } from '@sim/db/insert-columns' import { type WorkspaceFileRow, workspaceFileColumns, workspaceFiles } from '@sim/db/schema' import { createLogger } from '@sim/logger' import { generateId } from '@sim/utils/id' @@ -179,7 +180,7 @@ async function insertFileMetadataWithExecutor( try { const [inserted] = await executor - .insert(workspaceFiles) + .insert(withInsertColumns(workspaceFiles, workspaceFileColumns)) .values({ id: fileId, key, @@ -235,7 +236,7 @@ async function insertImmutableFileMetadataWithExecutor( } = options assertFileMetadataOrganizationOwner(options) const [inserted] = await executor - .insert(workspaceFiles) + .insert(withInsertColumns(workspaceFiles, workspaceFileColumns)) .values({ id: id || generateId(), key, @@ -316,7 +317,7 @@ export async function insertFileMetadataMany( const uniqueRows = [...uniqueRowsByKey.values()] const inserted = await db - .insert(workspaceFiles) + .insert(withInsertColumns(workspaceFiles, workspaceFileColumns)) .values( uniqueRows.map((row) => ({ id: row.id || generateId(), diff --git a/packages/db/insert-columns.test.ts b/packages/db/insert-columns.test.ts new file mode 100644 index 00000000000..88abafdd1cd --- /dev/null +++ b/packages/db/insert-columns.test.ts @@ -0,0 +1,145 @@ +import { withInsertColumns } from '@sim/db/insert-columns' +import { + organization, + organizationColumns, + userStats, + userStatsColumns, + workflowExecutionLogColumns, + workflowExecutionLogs, + workspaceFileColumns, + workspaceFiles, +} from '@sim/db/schema' +import { getTableColumns, getTableName, sql } from 'drizzle-orm' +import { getTableConfig, type PgTable, pgSchema, text } from 'drizzle-orm/pg-core' +import { drizzle } from 'drizzle-orm/pg-proxy' +import { describe, expect, expectTypeOf, it, vi } from 'vitest' + +const db = drizzle(async () => ({ rows: [] })) + +describe('withInsertColumns', () => { + it.each([ + { table: userStats, columns: userStatsColumns, retired: 'total_manual_executions' }, + { table: organization, columns: organizationColumns, retired: 'departed_member_usage' }, + { table: workflowExecutionLogs, columns: workflowExecutionLogColumns, retired: 'cost' }, + { table: workspaceFiles, columns: workspaceFileColumns, retired: 'size' }, + ])('excludes every retired column from $retired inserts and RETURNING', ({ table, columns }) => { + const originalColumns = getTableColumns(table) + const originalConfig = getTableConfig(table) + const target = withInsertColumns(table, columns) + const query = db.insert(target).values({ id: 'example' }).returning().toSQL() + const fullQuery = db.insert(table).values({ id: 'example' }).returning().toSQL() + + for (const [key, column] of Object.entries(originalColumns)) { + expect(fullQuery.sql).toContain(`"${column.name}"`) + if (key in columns) expect(query.sql).toContain(`"${column.name}"`) + else expect(query.sql).not.toContain(`"${column.name}"`) + } + expect(getTableName(target)).toBe(getTableName(table)) + expect(getTableColumns(target)).toBe(columns) + expect(getTableColumns(table)).toBe(originalColumns) + expect(getTableConfig(table)).toEqual(originalConfig) + }) + + it('retains live insert types and excludes retired fields', () => { + const target = withInsertColumns(userStats, userStatsColumns) + type Insert = typeof target.$inferInsert + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf() + expectTypeOf().toEqualTypeOf< + 'payment_failed' | 'dispute' | null | undefined + >() + expectTypeOf<'totalManualExecutions'>().not.toExtend() + expectTypeOf<'currentPeriodCost'>().not.toExtend() + }) + + it('preserves bulk values, explicit nulls, defaults, and conflict handling', () => { + const target = withInsertColumns(userStats, userStatsColumns) + const query = db + .insert(target) + .values([ + { id: 'stats-1', userId: 'user-1', currentUsageLimit: null }, + { id: 'stats-2', userId: 'user-2', currentUsageLimit: '5' }, + ]) + .onConflictDoUpdate({ + target: userStats.userId, + set: { currentUsageLimit: sql`excluded.current_usage_limit` }, + }) + .returning({ id: userStats.id }) + .toSQL() + + expect(query.params).toEqual(['stats-1', 'user-1', null, 'stats-2', 'user-2', '5']) + expect(query.sql).toContain('default') + expect(query.sql).toContain( + 'on conflict ("user_id") do update set "current_usage_limit" = excluded.current_usage_limit' + ) + expect(query.sql).toContain('returning "id"') + expect(query.sql).not.toContain('total_manual_executions') + expect( + db.insert(target).values({ id: 'stats-3', userId: 'user-3' }).onConflictDoNothing().toSQL() + .sql + ).toContain('on conflict do nothing') + }) + + it('preserves parameter encoders and RETURNING decoders', async () => { + const startedAt = new Date('2026-01-01T00:00:00Z') + const payload = { sample: true } + const execute = vi.fn(async () => ({ + rows: [['2026-01-01 00:00:00', payload, '{model-a,model-b}']], + })) + const connection = drizzle(execute) + const rows = await connection + .insert(withInsertColumns(workflowExecutionLogs, workflowExecutionLogColumns)) + .values({ + id: 'log-1', + workflowId: 'workflow-1', + workspaceId: 'workspace-1', + executionId: 'execution-1', + stateSnapshotId: 'snapshot-1', + level: 'info', + status: 'running', + trigger: 'manual', + startedAt, + executionData: payload, + modelsUsed: ['model-a', 'model-b'], + }) + .returning({ + startedAt: workflowExecutionLogs.startedAt, + executionData: workflowExecutionLogs.executionData, + modelsUsed: workflowExecutionLogs.modelsUsed, + }) + + expect(rows).toEqual([ + { startedAt, executionData: payload, modelsUsed: ['model-a', 'model-b'] }, + ]) + expect(execute).toHaveBeenCalledWith( + expect.not.stringContaining('"cost"'), + expect.arrayContaining([ + startedAt.toISOString(), + JSON.stringify(payload), + '{"model-a","model-b"}', + ]), + 'all', + expect.arrayContaining(['timestamp', 'json']) + ) + }) + + it('retains schema-qualified names and runtime defaults', () => { + const table = pgSchema('insert_test').table('records', { + id: text('id').$defaultFn(() => 'generated-id'), + retired: text('retired'), + }) + const query = db + .insert(withInsertColumns(table, { id: table.id })) + .values({}) + .toSQL() + expect(query.sql).toBe('insert into "insert_test"."records" ("id") values ($1)') + expect(query.params).toEqual(['generated-id']) + }) + + it('rejects a column from a different table', () => { + const table: PgTable = userStats + expect(() => withInsertColumns(table, { id: organization.id })).toThrow( + 'INSERT column id does not belong to the target table' + ) + }) +}) diff --git a/packages/db/insert-columns.ts b/packages/db/insert-columns.ts new file mode 100644 index 00000000000..065b47c1b1e --- /dev/null +++ b/packages/db/insert-columns.ts @@ -0,0 +1,35 @@ +import { getTableColumns } from 'drizzle-orm' +import type { PgTable } from 'drizzle-orm/pg-core' + +type InsertTable = PgTable<{ + name: TTable['_']['name'] + schema: TTable['_']['schema'] + dialect: TTable['_']['config']['dialect'] + columns: Pick +}> + +/** + * Restricts Drizzle's INSERT column list without changing the migration schema. + * Omitting a value is insufficient: Drizzle still names that column with DEFAULT. + * The table proxy substitutes the column map exposed by getTableColumns while + * retaining table metadata, column codecs, defaults, and SQL names. + * It is local to this insert and never mutates the shared table or its columns. + */ +export function withInsertColumns< + TTable extends PgTable, + TKey extends keyof TTable['_']['columns'], +>(table: TTable, columns: Pick): InsertTable { + const declaredColumns = getTableColumns(table) + for (const [name, column] of Object.entries(columns)) { + if (declaredColumns[name] !== column) { + throw new Error(`INSERT column ${name} does not belong to the target table`) + } + } + + return new Proxy(table, { + get(target, property, receiver) { + const value = Reflect.get(target, property, receiver) + return value === declaredColumns ? columns : value + }, + }) as InsertTable +} diff --git a/packages/db/package.json b/packages/db/package.json index 39a0b69a60a..8efe8c4ca32 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -17,6 +17,10 @@ "types": "./schema.ts", "default": "./schema.ts" }, + "./insert-columns": { + "types": "./insert-columns.ts", + "default": "./insert-columns.ts" + }, "./timestamps": { "types": "./timestamps.ts", "default": "./timestamps.ts" diff --git a/packages/db/schema.ts b/packages/db/schema.ts index d8d8342ebe2..cc5c149a0c7 100644 --- a/packages/db/schema.ts +++ b/packages/db/schema.ts @@ -523,12 +523,13 @@ export const workflowExecutionLogs = pgTable( * `materializeExecutionData`, which resolves the pointer. */ executionData: jsonb('execution_data').notNull().default('{}'), - // contract-pending(after #7134 is fully deployed to production): DROP COLUMN - // cost. Same procedure and argless-read lint as the user_stats marker - // (scripts/check-pending-drop-tables.ts). Script migration - // 0009_backfill_wel_residual_cost_total projects the ~23 straggler rows - // whose json still held a numeric total into cost_total before the drop; - // the contract PR must ALSO deregister that script (it reads this column). + /** + * contract-pending(after #7134 and #7774 are fully deployed): + * DROP cost. Reads and inserts use workflowExecutionLogColumns. Before the + * drop, confirm script migration 0009_backfill_wel_residual_cost_total has + * projected all residual numeric totals, then deregister it in the contract + * PR because it reads this column. + */ /** @deprecated Not written/read; cost lives in usage_log + the `cost_total` projection. */ cost: jsonb('cost'), // Faithful, write-once projection of the run's usage_log ledger sum (dollars). @@ -1247,16 +1248,16 @@ export const userStats = pgTable('user_stats', { .notNull() .references(() => user.id, { onDelete: 'cascade' }) .unique(), // One record per user - // contract-pending(after #7134 is fully deployed to production): DROP COLUMN - // the 19 @deprecated columns in this table. Their last readers/writers were - // removed by the ledger cutover (#7078/#7113) and #7134; the declarations - // remain ONLY so the app schema keeps matching the deployed database until - // the drop. Argless select()/relational reads of this table are forbidden - // meanwhile — they would put these columns back into generated SQL and break - // the old task set when the contract deploy drops them mid-cutover — enforced - // by scripts/check-pending-drop-tables.ts. The follow-up PR deletes the - // @deprecated declarations plus this marker and ships the generated DROP - // migration in the same change. + /** + * contract-pending(after #7134 and #7774 are fully deployed): + * DROP the 19 deprecated columns. Usage updates were retired by #7078/#7113; + * #7134 removed the remaining reads. Declarations stay until the contract so + * generated migrations match the deployed database. Reads use userStatsColumns; + * inserts use withInsertColumns(userStats, userStatsColumns), because omitting + * values still makes Drizzle name the columns with DEFAULT. The pending-drop + * audit enforces both. Deploy the compatibility release to every writer before + * deleting these declarations and generating the DROP migration. + */ /** @deprecated Retired usage counter; derive from usage_log. */ totalManualExecutions: integer('total_manual_executions').notNull().default(0), /** @deprecated Retired usage counter; derive from usage_log. */ @@ -1343,8 +1344,8 @@ export const userStats = pgTable('user_stats', { }) /** - * Live columns of `user_stats` — the selection every read of this table goes - * through while the contract-pending drop (see the marker inside the table) is + * Live columns of `user_stats` — the selection every read and withInsertColumns + * insert uses while the contract-pending drop (see the marker inside the table) is * outstanding, so generated SQL never names the doomed columns. Enforced by * `scripts/check-pending-drop-tables.ts`; the contract PR deletes this helper * together with the deprecated declarations. @@ -1716,10 +1717,12 @@ export const organization = pgTable('organization', { .$type>() .notNull() .default({}), - // contract-pending(after #7134 is fully deployed to production): DROP COLUMN - // departed_member_usage. The last readers/writers (v1 admin exposure, - // cycle-close resets) were removed in #7134; same procedure and argless-read - // lint as the user_stats marker (scripts/check-pending-drop-tables.ts). + /** + * contract-pending(after #7134 and #7774 are fully deployed): + * DROP departed_member_usage. Reads and inserts use organizationColumns; + * #7134 removed the v1 admin exposure and cycle-close resets. The pending-drop + * audit enforces the same read and insert constraints as user_stats. + */ /** @deprecated No readers or writers; a departed member's ledger rows stay stamped to the org's period, so nothing needs capturing. */ departedMemberUsage: decimal('departed_member_usage').notNull().default('0'), /** @@ -2260,7 +2263,7 @@ export const workspaceFiles = pgTable( */ displayName: text('display_name'), contentType: text('content_type').notNull(), - /** contract-pending(after the cutover is fully deployed and size_bytes has no NULLs): drop size, workspace_files_sync_size_columns, and the temporary dev cutover runner — all application reads and writes use size_bytes */ + /** contract-pending(after the cutover and #7774 are fully deployed and size_bytes has no NULLs): drop size, workspace_files_sync_size_columns, and the temporary dev cutover runner — all application reads and writes use size_bytes */ size: integer('size').notNull().default(0), /** Exact byte size. The deploy migration backfills existing rows before this release serves traffic. */ sizeBytes: bigint('size_bytes', { mode: 'number' }), diff --git a/scripts/check-pending-drop-tables.test.ts b/scripts/check-pending-drop-tables.test.ts new file mode 100644 index 00000000000..dbc9f8aa79b --- /dev/null +++ b/scripts/check-pending-drop-tables.test.ts @@ -0,0 +1,157 @@ +import { auditFile } from '@scripts/check-pending-drop-tables' +import { describe, expect, it } from 'vitest' + +const tables = new Map([ + ['userStats', new Set(['totalCost'])], + ['organization', new Set(['departedMemberUsage'])], +]) +const columns = new Map([ + ['userStatsColumns', 'userStats'], + ['organizationColumns', 'organization'], +]) + +function audit(source: string) { + return auditFile('insert-example.ts', source, tables, columns) +} + +describe('pending-drop INSERT audit', () => { + it.each([ + 'db.insert(userStats).values({ id: "id", userId: "user" })', + 'db.insert(userStats).values({ id: "id" }).onConflictDoNothing().returning({ id: userStats.id })', + 'const target = userStats; tx.insert(target).values({ id: "id" })', + 'db.insert(alias(userStats, "stats")).values({ id: "id" })', + ])('rejects implicit DEFAULT columns: %s', (statement) => { + const findings = audit(`import { userStats } from '@sim/db/schema'; ${statement}`) + expect(findings.some((finding) => finding.pattern.startsWith('insert()'))).toBe(true) + }) + + it.each([ + "import { userStats as stats } from '@sim/db/schema'; db.insert(stats).values({})", + "import * as schema from '@sim/db/schema'; db.insert(schema.userStats).values({})", + ])('resolves renamed and namespace table imports', (source) => { + expect(audit(source)).toHaveLength(1) + }) + + it.each([ + `import { userStats, userStatsColumns } from '@sim/db/schema'; + import { withInsertColumns } from '@sim/db/insert-columns'; + db.insert(withInsertColumns(userStats, userStatsColumns)).values({}).returning()`, + `import { userStats as stats, userStatsColumns as live } from '@sim/db/schema'; + import { withInsertColumns as project } from '@sim/db/insert-columns'; + db.insert(project(stats, live)).values({})`, + `import * as schema from '@sim/db/schema'; + import { withInsertColumns } from '@sim/db/insert-columns'; + db.insert(withInsertColumns(schema.userStats, schema.userStatsColumns)).values({})`, + ])('accepts the validated live-column map', (source) => { + expect(audit(source)).toEqual([]) + }) + + it.each(['{}', 'organizationColumns', '{ ...userStatsColumns, totalCost: userStats.totalCost }'])( + 'rejects an unverified or mismatched selection: %s', + (selection) => { + expect( + audit(` + import { userStats, userStatsColumns, organizationColumns } from '@sim/db/schema'; + import { withInsertColumns } from '@sim/db/insert-columns'; + db.insert(withInsertColumns(userStats, ${selection})).values({}); + `) + ).toHaveLength(1) + } + ) + + it('still rejects broad reads', () => { + expect( + audit(`import { userStats } from '@sim/db/schema'; db.select().from(userStats)`) + ).toHaveLength(1) + }) + + it.each([ + 'function write(userStatsColumns) { INSERT }', + 'const write = ({ userStatsColumns }) => { INSERT }', + 'function write(userStatsColumns = arbitrary) { INSERT }', + '{ const userStatsColumns = arbitrary; INSERT }', + 'function write() { INSERT; var userStatsColumns = arbitrary }', + 'try {} catch (userStatsColumns) { INSERT }', + 'for (const userStatsColumns of selections) { INSERT }', + 'const write = function userStatsColumns() { INSERT }', + ])('rejects a shadowed live-column map: %s', (scope) => { + const source = scope.replace( + 'INSERT', + 'db.insert(withInsertColumns(userStats, userStatsColumns)).values({});' + ) + expect( + audit(` + import { userStats, userStatsColumns } from '@sim/db/schema'; + import { withInsertColumns } from '@sim/db/insert-columns'; + ${source} + `) + ).toEqual([ + expect.objectContaining({ pattern: expect.stringContaining('validated live-column map') }), + ]) + }) + + it.each([ + `import { userStats, userStatsColumns as live } from '@sim/db/schema'; + function write(live) { db.insert(withInsertColumns(userStats, live)).values({}) }`, + `import { userStats } from '@sim/db/schema'; + import * as schema from '@sim/db/schema'; + function write(schema) { + db.insert(withInsertColumns(userStats, schema.userStatsColumns)).values({}) + }`, + ])('rejects shadowed renamed and namespace selections', (source) => { + expect(audit(`import { withInsertColumns } from '@sim/db/insert-columns'; ${source}`)).toEqual([ + expect.objectContaining({ pattern: expect.stringContaining('validated live-column map') }), + ]) + }) + + it.each([ + `import { withInsertColumns } from '@sim/db/insert-columns'; + function write(withInsertColumns) { + db.insert(withInsertColumns(userStats, userStatsColumns)).values({}) + }`, + `import * as inserts from '@sim/db/insert-columns'; + function write(inserts) { + db.insert(inserts.withInsertColumns(userStats, userStatsColumns)).values({}) + }`, + ])('rejects a shadowed INSERT helper', (source) => { + expect( + audit(`import { userStats, userStatsColumns } from '@sim/db/schema'; ${source}`) + ).toEqual([ + expect.objectContaining({ pattern: expect.stringContaining('imported INSERT helper') }), + ]) + }) + + it('keeps imports valid outside the shadowing scope', () => { + expect( + audit(` + import { userStats, userStatsColumns } from '@sim/db/schema'; + import { withInsertColumns } from '@sim/db/insert-columns'; + function unrelated(userStatsColumns, withInsertColumns) {} + { const userStatsColumns = arbitrary } + function write() { + db.insert(withInsertColumns(userStats, userStatsColumns)).values({}) + } + `) + ).toEqual([]) + }) + + it('accepts namespace-imported INSERT helpers', () => { + expect( + audit(` + import * as schema from '@sim/db/schema'; + import * as inserts from '@sim/db/insert-columns'; + db.insert(inserts.withInsertColumns(schema.userStats, schema.userStatsColumns)).values({}); + `) + ).toEqual([]) + }) + + it('validates namespace-imported insert helpers', () => { + expect( + audit(` + import { userStats } from '@sim/db/schema'; + import * as inserts from '@sim/db/insert-columns'; + db.insert(inserts.withInsertColumns(userStats, {})).values({}); + `) + ).toHaveLength(1) + }) +}) diff --git a/scripts/check-pending-drop-tables.ts b/scripts/check-pending-drop-tables.ts index 5a4e60f1b41..030a1a15b89 100644 --- a/scripts/check-pending-drop-tables.ts +++ b/scripts/check-pending-drop-tables.ts @@ -1,6 +1,6 @@ #!/usr/bin/env bun /** - * Fails when app code reads a pending-drop table without naming its columns. + * Fails when app code reads or inserts retired columns of a pending-drop table. * * A `contract-pending` marker inside a table in `packages/db/schema.ts` means the table * still declares columns whose physical `DROP COLUMN` is deferred until the app version @@ -10,6 +10,8 @@ * single argless read puts the doomed columns back into live SQL and would fail with * 42703 against the already-migrated database for the whole cutover window of the * contract deploy. Reads of these tables must name the columns they want. + * INSERTs must use withInsertColumns(table, liveColumns): omitted values still + * generate named DEFAULT columns. The supplied map must be a validated schema export. * * The audit derives everything from schema.ts itself and retires when the contract PR * deletes the markers: @@ -106,9 +108,8 @@ function parseSource( errorRecovery: true, plugins: [...(extname(file) === '.tsx' ? (['jsx'] as const) : []), 'typescript', 'decorators'], }) - const comments = Array.isArray(syntaxTree.comments) - ? syntaxTree.comments.filter(isCommentNode) - : [] + const detachedComments: unknown[] = syntaxTree.comments ?? [] + const comments = detachedComments.filter(isCommentNode) return { program: syntaxTree.program as unknown as SyntaxNode, comments } } @@ -245,6 +246,110 @@ function objectKeys(node: unknown): Set | null { interface TableBindings { locals: Map namespaces: Set + insertHelpers: Set + insertHelperNamespaces: Set +} + +/** Live selections already validated against the pending column declarations. */ +function readLiveColumnMaps(pendingTables: Map>): Map { + const { program } = parseSource(SCHEMA_PATH, readFileSync(SCHEMA_PATH, 'utf8')) + const selections = new Map() + const visit = (node: SyntaxNode) => { + if (node.type === 'VariableDeclarator') { + const name = propertyName(node.id) + const init = unwrap(node.init) + if (name && init?.type === 'CallExpression' && identifierName(init.callee) === 'omit') { + const columns = unwrap(Array.isArray(init.arguments) ? init.arguments[0] : undefined) + if ( + columns?.type === 'CallExpression' && + identifierName(columns.callee) === 'getTableColumns' + ) { + const table = identifierName( + Array.isArray(columns.arguments) ? columns.arguments[0] : undefined + ) + const doomed = table ? pendingTables.get(table) : undefined + if (table && doomed && sanctionedOmitMissing(init, doomed)?.length === 0) { + selections.set(name, table) + } + } + } + } + for (const child of getChildNodes(node)) visit(child) + } + visit(program) + return selections +} + +interface ImportBinding { + module: string + name: string +} + +/** + * Binds references within this file, without loading dependencies or standard + * libraries. Initialize lazily: only INSERT helpers need trusted import provenance. + * TypeScript resolves parameters, block locals, destructuring and hoisted bindings + * so a shadowed import cannot authorize an arbitrary column map or helper. + */ +function createImportResolver(file: string, source: string) { + let checker: ts.TypeChecker | undefined + const identifiers = new Map() + const resolveIdentifier = (node: SyntaxNode): ImportBinding | null => { + if (!checker) { + const filename = resolve(file) + const sourceFile = ts.createSourceFile(filename, source, ts.ScriptTarget.Latest, true) + const host: ts.CompilerHost = { + getSourceFile: (name) => (name === filename ? sourceFile : undefined), + getDefaultLibFileName: () => 'lib.d.ts', + writeFile: () => {}, + getCurrentDirectory: () => dirname(filename), + getDirectories: () => [], + fileExists: (name) => name === filename, + readFile: (name) => (name === filename ? source : undefined), + getCanonicalFileName: (name) => name, + useCaseSensitiveFileNames: () => true, + getNewLine: () => '\n', + } + checker = ts + .createProgram([filename], { noLib: true, noResolve: true }, host) + .getTypeChecker() + const index = (child: ts.Node) => { + if (ts.isIdentifier(child)) identifiers.set(child.getStart(sourceFile), child) + ts.forEachChild(child, index) + } + index(sourceFile) + } + const identifier = typeof node.start === 'number' ? identifiers.get(node.start) : undefined + const declarations = identifier + ? checker.getSymbolAtLocation(identifier)?.declarations + : undefined + if (declarations?.length !== 1) return null + const declaration = declarations[0] + if (!ts.isImportSpecifier(declaration) && !ts.isNamespaceImport(declaration)) return null + let parent: ts.Node = declaration.parent + while (!ts.isImportDeclaration(parent)) { + if (!parent.parent) return null + parent = parent.parent + } + if (!ts.isStringLiteral(parent.moduleSpecifier)) return null + return { + module: parent.moduleSpecifier.text, + name: ts.isImportSpecifier(declaration) + ? (declaration.propertyName ?? declaration.name).text + : '*', + } + } + + return (node: unknown): ImportBinding | null => { + const expression = unwrap(node) + if (expression?.type === 'Identifier') return resolveIdentifier(expression) + if (expression?.type !== 'MemberExpression' || expression.computed) return null + const object = unwrap(expression.object) + if (object?.type !== 'Identifier') return null + const binding = resolveIdentifier(object) + const member = propertyName(expression.property) + return binding?.name === '*' && member ? { module: binding.module, name: member } : null + } } /** @@ -283,7 +388,12 @@ function resolveTable( /** A module that can export the schema's table objects. */ function isSchemaModule(source: unknown): boolean { - const value = isSyntaxNode(source) && typeof source.value === 'string' ? source.value : null + const value = + typeof source === 'string' + ? source + : isSyntaxNode(source) && typeof source.value === 'string' + ? source.value + : null return value !== null && (/@sim\/db(\/|$)/.test(value) || /(^|\/)schema(\.ts)?$/.test(value)) } @@ -295,7 +405,12 @@ function collectTableBindings( program: SyntaxNode, pendingTables: Map> ): TableBindings { - const bindings: TableBindings = { locals: new Map(), namespaces: new Set() } + const bindings: TableBindings = { + locals: new Map(), + namespaces: new Set(), + insertHelpers: new Set(), + insertHelperNamespaces: new Set(), + } const visitImports = (node: SyntaxNode) => { if (node.type === 'ImportDeclaration' && isSchemaModule(node.source)) { @@ -306,10 +421,20 @@ function collectTableBindings( if (!local) continue if (specifier.type === 'ImportNamespaceSpecifier') { bindings.namespaces.add(local) + if (isSyntaxNode(node.source) && node.source.value === '@sim/db/insert-columns') { + bindings.insertHelperNamespaces.add(local) + } continue } if (specifier.type !== 'ImportSpecifier') continue const imported = propertyName(specifier.imported) + if ( + imported === 'withInsertColumns' && + isSyntaxNode(node.source) && + node.source.value === '@sim/db/insert-columns' + ) { + bindings.insertHelpers.add(local) + } if (imported && imported !== local && pendingTables.has(imported)) { bindings.locals.set(local, imported) } @@ -397,12 +522,37 @@ function checkCall( parent: SyntaxNode | null, pendingTables: Map>, bindings: TableBindings, + liveColumnMaps: Map, + resolveImport: ReturnType, report: (node: SyntaxNode, table: string, pattern: string) => void ): void { const callee = isSyntaxNode(call.callee) ? call.callee : null const args = Array.isArray(call.arguments) ? call.arguments : [] const resolveArg = (node: unknown) => resolveTable(node, pendingTables, bindings) + const isInsertHelper = + bindings.insertHelpers.has(identifierName(callee) ?? '') || + (callee?.type === 'MemberExpression' && + !callee.computed && + propertyName(callee.property) === 'withInsertColumns' && + bindings.insertHelperNamespaces.has(identifierName(callee.object) ?? '')) + if (isInsertHelper) { + const table = resolveArg(args[0]) + if (!table) return + const helper = resolveImport(callee) + const columns = resolveImport(args[1]) + if (helper?.module !== '@sim/db/insert-columns' || helper.name !== 'withInsertColumns') { + report(call, table, 'withInsertColumns() must resolve to the imported INSERT helper') + } else if ( + !columns || + !isSchemaModule(columns.module) || + liveColumnMaps.get(columns.name) !== table + ) { + report(call, table, "withInsertColumns() must use this table's validated live-column map") + } + return + } + // getTableColumns(pendingTable) — spreads every declared column unless the // doomed ones are verifiably named away on the spot. if (identifierName(callee) === 'getTableColumns') { @@ -420,6 +570,18 @@ function checkCall( if (callee?.type !== 'MemberExpression') return const method = propertyName(callee.property) + if (method === 'insert') { + const table = resolveArg(args[0]) + if (table) { + report( + call, + table, + 'insert() names every declared column, including omitted DEFAULT values; use withInsertColumns()' + ) + } + return + } + // .select()/.selectDistinct() ... .from(pendingTable) with no selection. if (method === 'from') { const table = resolveArg(args[0]) @@ -484,10 +646,11 @@ function checkCall( } } -function auditFile( +export function auditFile( file: string, source: string, - pendingTables: Map> + pendingTables: Map>, + liveColumnMaps: Map ): Violation[] { const violations: Violation[] = [] let program: SyntaxNode @@ -504,6 +667,7 @@ function auditFile( } const bindings = collectTableBindings(program, pendingTables) + const resolveImport = createImportResolver(file, source) const report = (node: SyntaxNode, table: string, pattern: string) => { violations.push({ file, line: node.loc?.start.line ?? 1, table, pattern }) @@ -511,7 +675,7 @@ function auditFile( const visit = (node: SyntaxNode, parent: SyntaxNode | null) => { if (node.type === 'CallExpression') { - checkCall(node, parent, pendingTables, bindings, report) + checkCall(node, parent, pendingTables, bindings, liveColumnMaps, resolveImport, report) } for (const child of getChildNodes(node)) visit(child, node) } @@ -562,26 +726,27 @@ function main(): void { // must keep naming every doomed column away, including ones deprecated later. const skipFiles = new Set([fileURLToPath(import.meta.url)]) const pendingTableNames = new Set(pendingTables.keys()) + const liveColumnMaps = readLiveColumnMaps(pendingTables) const violations: Violation[] = [] for (const file of SCAN_DIRS.flatMap((dir) => collectSources(dir))) { if (skipFiles.has(file) || /\.test\.(ts|tsx|mts|cts)$/.test(file)) continue const source = readFileSync(file, 'utf8') if (file !== SCHEMA_PATH && !mayReferencePendingTable(source, pendingTableNames)) continue - violations.push(...auditFile(file, source, pendingTables)) + violations.push(...auditFile(file, source, pendingTables, liveColumnMaps)) } if (violations.length === 0) { console.log( - `✓ No argless reads of pending-drop tables (${[...pendingTables.keys()].sort().join(', ')}).` + `✓ No unsafe reads or inserts of pending-drop tables (${[...pendingTables.keys()].sort().join(', ')}).` ) return } console.error( - `❌ Found ${violations.length} read(s) of pending-drop tables that select every declared column.\n` + + `❌ Found ${violations.length} unsafe read(s) or insert(s) of pending-drop tables.\n` + 'These tables carry a `contract-pending` marker in packages/db/schema.ts: deprecated\n' + - 'columns are awaiting DROP, and an argless read would re-introduce them into live SQL\n' + - 'and 42703 during the contract deploy. Name the live columns explicitly instead.\n' + 'columns are awaiting DROP, and full-table reads or inserts re-introduce them into live SQL\n' + + 'and 42703 during the contract deploy. Use the validated live-column maps.\n' ) for (const violation of violations) { console.error( diff --git a/scripts/tsconfig.json b/scripts/tsconfig.json index 486cf36a7cc..46670083b22 100644 --- a/scripts/tsconfig.json +++ b/scripts/tsconfig.json @@ -11,6 +11,9 @@ "resolveJsonModule": true, "noEmit": true, "allowImportingTsExtensions": true, + "paths": { + "@scripts/*": ["./*"] + }, "jsx": "react-jsx" }, "ts-node": { diff --git a/scripts/vitest.config.ts b/scripts/vitest.config.ts index b80735697ea..f6f9f47b36d 100644 --- a/scripts/vitest.config.ts +++ b/scripts/vitest.config.ts @@ -13,6 +13,9 @@ import { defineConfig } from 'vitest/config' * The root is pinned so `bun run test:scripts` behaves the same from any cwd. */ export default defineConfig({ + resolve: { + alias: { '@scripts': fileURLToPath(new URL('.', import.meta.url)) }, + }, test: { root: fileURLToPath(new URL('..', import.meta.url)), environment: 'node', From d0c825b0fe3e66e716a1af3436aac6e6968060e1 Mon Sep 17 00:00:00 2001 From: Waleed Date: Fri, 11 Sep 2026 11:40:48 -0700 Subject: [PATCH 05/15] feat(assistant): support image attachments (#7776) * feat(assistant): support image attachments * fix(assistant): clean up orphaned image uploads --- apps/sim/app/api/files/authorization.test.ts | 8 + apps/sim/app/api/files/authorization.ts | 2 + .../api/files/serve/[...path]/route.test.ts | 50 +++- .../app/api/files/serve/[...path]/route.ts | 17 ++ apps/sim/app/api/files/uploads/finalizers.ts | 4 + apps/sim/app/api/files/uploads/purposes.ts | 1 + apps/sim/app/api/files/uploads/route.test.ts | 43 ++++ .../components/composer/composer.test.tsx | 133 +++++++++- .../home/components/composer/composer.tsx | 124 +++++++--- .../home/organization-home.test.tsx | 94 +++++++ .../home/organization-home.tsx | 45 +++- .../components/drop-overlay/drop-overlay.tsx | 13 +- .../home/hooks/use-chat.mount-send.test.tsx | 31 +++ .../[workspaceId]/home/hooks/use-chat.ts | 4 +- .../hooks/use-file-attachments.test.tsx | 51 +++- .../user-input/hooks/use-file-attachments.ts | 32 ++- apps/sim/lib/api/contracts/upload-sessions.ts | 30 ++- .../lib/copilot/chat/assistant-images.test.ts | 104 ++++++++ apps/sim/lib/copilot/chat/assistant-images.ts | 68 +++++ apps/sim/lib/copilot/chat/payload.test.ts | 27 ++ apps/sim/lib/copilot/chat/payload.ts | 5 + apps/sim/lib/copilot/chat/post.test.ts | 138 +++++++++++ apps/sim/lib/copilot/chat/post.ts | 152 +++++++----- apps/sim/lib/core/utils/browser-storage.ts | 30 ++- apps/sim/lib/mothership/events.ts | 2 +- apps/sim/lib/uploads/client/admission.ts | 9 +- apps/sim/lib/uploads/client/session-upload.ts | 12 +- .../application.test.ts | 226 +++++++++++++++++ .../organization-assistant/application.ts | 181 ++++++++++++++ .../organization-assistant/binding.ts | 56 +++++ .../lib/uploads/shared/assistant-images.ts | 15 ++ .../upload-session/application.test.ts | 75 +++++- .../lib/uploads/upload-session/application.ts | 20 ++ .../uploads/upload-session/service.test.ts | 139 +++++++++++ .../sim/lib/uploads/upload-session/service.ts | 81 +++++- apps/sim/lib/uploads/utils/file-utils.ts | 1 + .../account-deletion-attachments.test.ts | 234 ++++++++++++++++++ apps/sim/lib/users/account-deletion.ts | 58 ++++- 38 files changed, 2162 insertions(+), 153 deletions(-) create mode 100644 apps/sim/lib/copilot/chat/assistant-images.test.ts create mode 100644 apps/sim/lib/copilot/chat/assistant-images.ts create mode 100644 apps/sim/lib/uploads/contexts/organization-assistant/application.test.ts create mode 100644 apps/sim/lib/uploads/contexts/organization-assistant/application.ts create mode 100644 apps/sim/lib/uploads/contexts/organization-assistant/binding.ts create mode 100644 apps/sim/lib/uploads/shared/assistant-images.ts create mode 100644 apps/sim/lib/users/account-deletion-attachments.test.ts diff --git a/apps/sim/app/api/files/authorization.test.ts b/apps/sim/app/api/files/authorization.test.ts index 22525582e75..a3b17bfab40 100644 --- a/apps/sim/app/api/files/authorization.test.ts +++ b/apps/sim/app/api/files/authorization.test.ts @@ -63,6 +63,14 @@ function grantAccess(cloudKey: string) { } describe('verifyKBFileAccess (binding-only)', () => { + it.each(['mothership', 'profile-pictures', 'general'] as const)( + 'refuses organization image keys through legacy %s authorization', + async (context) => { + await expect( + verifyFileAccess('assistant/org-1/user-1/upload-1/image.png', USER_ID, undefined, context) + ).resolves.toBe(false) + } + ) beforeEach(() => { vi.clearAllMocks() // Default liveness query result: one active document references the exact storage key. diff --git a/apps/sim/app/api/files/authorization.ts b/apps/sim/app/api/files/authorization.ts index 618b4e9711e..56f5d8e2cd8 100644 --- a/apps/sim/app/api/files/authorization.ts +++ b/apps/sim/app/api/files/authorization.ts @@ -150,6 +150,8 @@ export async function verifyFileAccess( isLocal?: boolean, options?: { requireWrite?: boolean; knowledgeAccess?: KnowledgeFileAccess } ): Promise { + /** Organization images require the Principal-aware Assistant application resolver. */ + if (cloudKey.startsWith('assistant/')) return false const requireWrite = options?.requireWrite ?? false try { const keyContext = inferContextFromKey(cloudKey) diff --git a/apps/sim/app/api/files/serve/[...path]/route.test.ts b/apps/sim/app/api/files/serve/[...path]/route.test.ts index 755861df05f..33b08a07e0c 100644 --- a/apps/sim/app/api/files/serve/[...path]/route.test.ts +++ b/apps/sim/app/api/files/serve/[...path]/route.test.ts @@ -3,7 +3,12 @@ * * @vitest-environment node */ -import { hybridAuthMockFns, storageServiceMock, storageServiceMockFns } from '@sim/testing' +import { + authMockFns, + hybridAuthMockFns, + storageServiceMock, + storageServiceMockFns, +} from '@sim/testing' import { NextRequest } from 'next/server' import { beforeEach, describe, expect, it, vi } from 'vitest' import { MAX_BUFFERED_TRANSFER_BYTES } from '@/lib/uploads/shared/types' @@ -34,6 +39,7 @@ const { mockCreateErrorResponse, FileNotFoundError, serveLogger, + mockReadOrganizationAssistantImage, } = vi.hoisted(() => { class FileNotFoundErrorClass extends Error { constructor(message: string) { @@ -43,6 +49,7 @@ const { } return { serveLogger: { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() }, + mockReadOrganizationAssistantImage: vi.fn(), mockVerifyFileAccess: vi.fn(), mockReadFile: vi.fn(), mockIsUsingCloudStorage: vi.fn(), @@ -62,6 +69,10 @@ const { } }) +vi.mock('@/lib/uploads/contexts/organization-assistant/application', () => ({ + readOrganizationAssistantImage: mockReadOrganizationAssistantImage, +})) + vi.mock('fs/promises', () => ({ readFile: mockReadFile, access: vi.fn().mockResolvedValue(undefined), @@ -204,6 +215,43 @@ describe('File Serve API Route', () => { }) }) + it('serves private Assistant images through session authorization and disables caching', async () => { + authMockFns.mockGetSession.mockResolvedValue({ + user: { id: 'user-1' }, + session: { id: 'session-1' }, + }) + const key = 'assistant/org-1/user-1/upload-1/image.png' + mockReadOrganizationAssistantImage.mockResolvedValue({ + name: 'image.png', + contentType: 'image/webp', + buffer: Buffer.from('decoded-image'), + }) + const response = await GET(new NextRequest(`http://localhost/api/files/serve/${key}`), { + params: Promise.resolve({ path: key.split('/') }), + }) + expect(response.status).toBe(200) + expect(mockReadOrganizationAssistantImage).toHaveBeenCalledWith({ + principal: { kind: 'session', userId: 'user-1', sessionId: 'session-1' }, + key, + signal: expect.any(AbortSignal), + }) + expect(mockCreateFileResponse).toHaveBeenCalledWith( + expect.objectContaining({ cacheControl: 'private, no-store', contentType: 'image/webp' }) + ) + expect(mockVerifyFileAccess).not.toHaveBeenCalled() + expect(hybridAuthMockFns.mockCheckSessionOrInternalAuth).not.toHaveBeenCalled() + }) + + it('requires a real session for private Assistant images even when legacy auth succeeds', async () => { + authMockFns.mockGetSession.mockResolvedValue(null) + const key = 'assistant/org-1/user-1/upload-1/image.png' + const response = await GET(new NextRequest(`http://localhost/api/files/serve/${key}`), { + params: Promise.resolve({ path: key.split('/') }), + }) + expect(response.status).toBe(401) + expect(mockReadOrganizationAssistantImage).not.toHaveBeenCalled() + }) + it('bounds the local read rather than trusting the stored size', async () => { await GET(new NextRequest('http://localhost:3000/api/files/serve/workspace/ws/test-file.txt'), { params: Promise.resolve({ path: ['workspace', 'ws', 'test-file.txt'] }), diff --git a/apps/sim/app/api/files/serve/[...path]/route.ts b/apps/sim/app/api/files/serve/[...path]/route.ts index ffb8845aeff..6ccd6e7eb6e 100644 --- a/apps/sim/app/api/files/serve/[...path]/route.ts +++ b/apps/sim/app/api/files/serve/[...path]/route.ts @@ -7,6 +7,7 @@ import { fileServeParamsSchema, fileServeQuerySchema } from '@/lib/api/contracts import { concealCrossTenantResourceError, InternalUnauthenticatedError, + internalSessionAuth, } from '@/lib/api/server/routes' import { AuthType, checkSessionOrInternalAuth } from '@/lib/auth/hybrid' import { resolveServableDocBytes } from '@/lib/copilot/tools/server/files/doc-compile' @@ -16,6 +17,7 @@ import { assertKnownSizeWithinLimit, isPayloadSizeLimitError } from '@/lib/core/ import { withRouteHandler } from '@/lib/core/utils/with-route-handler' import { CopilotFiles, isUsingCloudStorage } from '@/lib/uploads' import type { StorageContext } from '@/lib/uploads/config' +import { readOrganizationAssistantImage } from '@/lib/uploads/contexts/organization-assistant/application' import { parseWorkspaceFileKey } from '@/lib/uploads/contexts/workspace/workspace-file-manager' import { downloadFile } from '@/lib/uploads/core/storage-service' import { resolveServableImageBytes } from '@/lib/uploads/server/image-derivative' @@ -218,6 +220,21 @@ export const GET = withRouteHandler( const isCloudPath = isS3Path || isBlobPath || isGcsPath const cloudKey = isCloudPath ? path.slice(1).join('/') : fullPath + if (cloudKey.startsWith('assistant/')) { + const principal = await internalSessionAuth.authenticate() + const image = await readOrganizationAssistantImage({ + principal, + key: cloudKey, + signal: request.signal, + }) + return createFileResponse({ + buffer: image.buffer, + filename: image.name, + contentType: image.contentType, + cacheControl: 'private, no-store', + }) + } + const isPublicByKeyPrefix = cloudKey.startsWith('profile-pictures/') || cloudKey.startsWith('og-images/') || diff --git a/apps/sim/app/api/files/uploads/finalizers.ts b/apps/sim/app/api/files/uploads/finalizers.ts index 98ba94e15df..902b96b4f49 100644 --- a/apps/sim/app/api/files/uploads/finalizers.ts +++ b/apps/sim/app/api/files/uploads/finalizers.ts @@ -10,6 +10,7 @@ import type { OrchestrationRequestContext } from '@/lib/core/orchestration/types import { captureServerEvent } from '@/lib/posthog/server' import { notifyWorkspaceFilesChanged } from '@/lib/realtime/notify' import { getServeStoragePrefix } from '@/lib/uploads/config' +import { finalizeOrganizationAssistantAttachment } from '@/lib/uploads/contexts/organization-assistant/application' import { getWorkspaceFile, registerUploadedWorkspaceFile, @@ -108,6 +109,9 @@ export async function finalizeUploadPurpose({ case 'workspace_logo': return finalizeWorkspaceLogo(session, actor, request) case 'mothership_attachment': + if (session.workspaceId === null) { + return { value: await finalizeOrganizationAssistantAttachment(principal, session) } + } return finalizeMothershipAttachment(session) case 'execution_attachment': return finalizeExecutionAttachment(session) diff --git a/apps/sim/app/api/files/uploads/purposes.ts b/apps/sim/app/api/files/uploads/purposes.ts index dddddf82663..41e50569af9 100644 --- a/apps/sim/app/api/files/uploads/purposes.ts +++ b/apps/sim/app/api/files/uploads/purposes.ts @@ -78,6 +78,7 @@ export async function createPurposeUploadSession( localOrigin, }) case 'mothership_attachment': + if (!body.workspaceId) throw new UploadSessionError('validation', 'workspaceId is required') await requireWorkspacePermission(userId, body.workspaceId, 'write') return createUploadSession({ purpose: body.purpose, diff --git a/apps/sim/app/api/files/uploads/route.test.ts b/apps/sim/app/api/files/uploads/route.test.ts index f36e29862d1..4dc5aab2175 100644 --- a/apps/sim/app/api/files/uploads/route.test.ts +++ b/apps/sim/app/api/files/uploads/route.test.ts @@ -234,6 +234,49 @@ describe('/api/files/uploads', () => { ) }) + it.each([ + { organizationId: 'org-1', contentType: 'application/pdf', size: 100 }, + { organizationId: 'org-1', contentType: 'image/svg+xml', size: 100 }, + { organizationId: 'org-1', contentType: 'image/png', size: 5 * 1024 * 1024 + 1 }, + { organizationId: 'org-1', workspaceId: 'ws-1', contentType: 'image/png', size: 100 }, + ])('rejects unsupported organization attachments before application loading', async (body) => { + const response = await createUpload( + new NextRequest('http://localhost/api/files/uploads', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ purpose: 'mothership_attachment', name: 'image.png', ...body }), + }) + ) + expect(response.status).toBe(400) + expect(mockCreateInternalPurposeUploadSession).not.toHaveBeenCalled() + }) + + it('creates organization image attachments through the same upload lifecycle', async () => { + mockCreateInternalPurposeUploadSession.mockResolvedValue({ + ...session({ purpose: 'mothership_attachment', storageContext: 'mothership' }), + transfer: { method: 'put', url: 'https://storage.example/upload', headers: {} }, + }) + const response = await createUpload( + new NextRequest('http://localhost/api/files/uploads', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + purpose: 'mothership_attachment', + organizationId: 'org-1', + name: 'image.png', + contentType: 'image/png', + size: 100, + }), + }) + ) + expect(response.status).toBe(201) + expect(mockCreateInternalPurposeUploadSession).toHaveBeenCalledWith( + expect.objectContaining({ kind: 'session', userId: 'user-1' }), + expect.objectContaining({ purpose: 'mothership_attachment', organizationId: 'org-1' }), + expect.anything() + ) + }) + it('rejects mothership attachments above the 5 GiB direct-to-storage limit', async () => { const request = new NextRequest('http://localhost/api/files/uploads', { method: 'POST', diff --git a/apps/sim/app/o/[organizationId]/home/components/composer/composer.test.tsx b/apps/sim/app/o/[organizationId]/home/components/composer/composer.test.tsx index b8e873529b2..65ee1653466 100644 --- a/apps/sim/app/o/[organizationId]/home/components/composer/composer.test.tsx +++ b/apps/sim/app/o/[organizationId]/home/components/composer/composer.test.tsx @@ -9,9 +9,11 @@ const mocks = vi.hoisted(() => ({ toggleListening: vi.fn(), resetTranscript: vi.fn(), submit: vi.fn(), + upload: vi.fn(), })) vi.mock('@/hooks/use-speech-to-text', () => ({ useSpeechToText: mocks.speech })) +vi.mock('@/lib/uploads/client/session-upload', () => ({ uploadInternalFileSession: mocks.upload })) vi.mock('@/hooks/use-animated-placeholder', () => ({ useAnimatedPlaceholder: () => 'Ask Sim to' })) vi.mock('@/hooks/use-chat-input-focus', () => ({ useChatInputFocus: vi.fn() })) vi.mock('@/app/o/[organizationId]/providers/organization-provider', () => ({ @@ -19,6 +21,7 @@ vi.mock('@/app/o/[organizationId]/providers/organization-provider', () => ({ })) import { Composer } from '@/app/o/[organizationId]/home/components/composer/composer' +import { useFileAttachments } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/user-input/hooks/use-file-attachments' let root: Root let container: HTMLDivElement @@ -26,6 +29,17 @@ let container: HTMLDivElement beforeEach(() => { vi.clearAllMocks() vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true) + vi.stubGlobal( + 'URL', + class extends URL { + static createObjectURL = vi.fn(() => 'blob:image-preview') + static revokeObjectURL = vi.fn() + } + ) + mocks.upload.mockResolvedValue({ + key: 'assistant/organization-a/user-a/image-a/screenshot.png', + path: '/api/files/serve/image-a?context=mothership', + }) vi.stubGlobal( 'matchMedia', vi.fn(() => ({ @@ -50,21 +64,25 @@ afterEach(async () => { await act(async () => root.unmount()) container.remove() vi.unstubAllGlobals() + vi.restoreAllMocks() }) -async function render(isInitialView: boolean) { +async function render(isInitialView: boolean, initialValue = 'Summarize') { function Harness() { - const [value, setValue] = useState('Summarize') + const [value, setValue] = useState(initialValue) + const files = useFileAttachments({ userId: 'user-a', organizationId: 'organization-a' }) return ( { - mocks.submit(value) + mocks.submit(value, files.attachedFiles) setValue('') + files.clearAttachedFiles() }} /> ) @@ -90,7 +108,7 @@ describe('organization voice composer', () => { await act(async () => { container.querySelector('button[aria-label="Send"]')!.click() }) - expect(mocks.submit).toHaveBeenCalledWith('Summarize the release') + expect(mocks.submit).toHaveBeenCalledWith('Summarize the release', []) expect(mocks.resetTranscript).toHaveBeenCalledOnce() await act(async () => mocks.speech.mock.calls.at(-1)![0].onTranscript('Next question')) expect(container.querySelector('textarea')!.value).toBe('Next question') @@ -109,3 +127,110 @@ describe('organization voice composer', () => { expect(container.querySelector('button[aria-label="Voice input"]')).toBeNull() }) }) + +function fileList(files: File[]): FileList { + return Object.assign(files, { item: (index: number) => files[index] ?? null }) +} + +async function paste(files: File[]) { + const event = new Event('paste', { bubbles: true, cancelable: true }) + Object.defineProperty(event, 'clipboardData', { value: { files: fileList(files) } }) + await act(async () => container.querySelector('textarea')!.dispatchEvent(event)) + return event +} + +describe('organization image composer', () => { + it.each([true, false])( + 'pastes and submits an image without text (initial: %s)', + async (initial) => { + await render(initial, '') + const image = new File(['image'], 'screenshot.png', { type: 'image/png' }) + const event = await paste([image]) + expect(event.defaultPrevented).toBe(true) + expect(mocks.upload).toHaveBeenCalledWith( + expect.objectContaining({ + purpose: 'mothership_attachment', + organizationId: 'organization-a', + file: image, + }) + ) + expect(container.querySelector('img')?.getAttribute('alt')).toBe('screenshot.png') + await act(async () => + container.querySelector('button[aria-label="Send"]')!.click() + ) + expect(mocks.submit).toHaveBeenCalledWith('', [ + expect.objectContaining({ + key: 'assistant/organization-a/user-a/image-a/screenshot.png', + uploading: false, + }), + ]) + expect(container.querySelector('img')).toBeNull() + } + ) + + it('leaves ordinary text paste to the textarea', async () => { + await render(true) + expect((await paste([])).defaultPrevented).toBe(false) + expect(mocks.upload).not.toHaveBeenCalled() + }) + + it('accepts dropped images through the same upload flow', async () => { + await render(false) + const image = new File(['image'], 'dropped.png', { type: 'image/png' }) + const drop = new Event('drop', { bubbles: true, cancelable: true }) + Object.defineProperty(drop, 'dataTransfer', { value: { files: fileList([image]) } }) + await act(async () => container.querySelector('textarea')!.dispatchEvent(drop)) + expect(drop.defaultPrevented).toBe(true) + expect(mocks.upload).toHaveBeenCalledWith(expect.objectContaining({ file: image })) + expect(container.querySelector('img')?.getAttribute('alt')).toBe('dropped.png') + }) + + it('blocks Send and Enter until an image upload finishes', async () => { + let finish!: (value: { key: string; path: string }) => void + mocks.upload.mockImplementation( + () => + new Promise((resolve) => { + finish = resolve + }) + ) + await render(true) + await paste([new File(['image'], 'screenshot.png', { type: 'image/png' })]) + expect(container.querySelector('button[aria-label="Send"]')!.disabled).toBe( + true + ) + await act(async () => + container + .querySelector('textarea')! + .dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true })) + ) + expect(mocks.submit).not.toHaveBeenCalled() + await act(async () => finish({ key: 'image-key', path: '/image-path' })) + expect(container.querySelector('button[aria-label="Send"]')!.disabled).toBe( + false + ) + }) + + it('uses the picker and lets an attachment be removed before sending', async () => { + await render(true, '') + const input = container.querySelector('input[type="file"]')! + const click = vi.spyOn(input, 'click') + await act(async () => + container.querySelector('button[aria-label="Attach images"]')!.click() + ) + expect(click).toHaveBeenCalledOnce() + expect(input.accept).toContain('image/png') + Object.defineProperty(input, 'files', { + value: fileList([new File(['image'], 'screenshot.png', { type: 'image/png' })]), + }) + await act(async () => input.dispatchEvent(new Event('change', { bubbles: true }))) + await act(async () => + container + .querySelector('button[aria-label="Remove screenshot.png"]')! + .click() + ) + expect(container.querySelector('img')).toBeNull() + expect(container.querySelector('button[aria-label="Send"]')!.disabled).toBe( + true + ) + }) +}) diff --git a/apps/sim/app/o/[organizationId]/home/components/composer/composer.tsx b/apps/sim/app/o/[organizationId]/home/components/composer/composer.tsx index 1c897d4d532..891af13473a 100644 --- a/apps/sim/app/o/[organizationId]/home/components/composer/composer.tsx +++ b/apps/sim/app/o/[organizationId]/home/components/composer/composer.tsx @@ -1,11 +1,15 @@ 'use client' import { useRef } from 'react' -import { Button, cn } from '@sim/emcn' -import { ArrowUp } from '@sim/emcn/icons' +import { Button, Chip, cn, Tooltip } from '@sim/emcn' +import { ArrowUp, Plus } from '@sim/emcn/icons' +import { ASSISTANT_IMAGE_ACCEPT_ATTRIBUTE } from '@/lib/uploads/shared/assistant-images' import { useOrganizationContext } from '@/app/o/[organizationId]/providers/organization-provider' +import { AttachedFilesList } from '@/app/workspace/[workspaceId]/home/components/user-input/components/attached-files-list/attached-files-list' +import { DropOverlay } from '@/app/workspace/[workspaceId]/home/components/user-input/components/drop-overlay/drop-overlay' import { MicButton } from '@/app/workspace/[workspaceId]/home/components/user-input/components/mic-button/mic-button' import { MicrophonePermissionHelp } from '@/app/workspace/[workspaceId]/home/components/user-input/components/microphone-permission-help/microphone-permission-help' +import type { useFileAttachments } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/user-input/hooks/use-file-attachments' import { useAnimatedPlaceholder } from '@/hooks/use-animated-placeholder' import { useChatInputFocus } from '@/hooks/use-chat-input-focus' import { useVoiceInput } from '@/hooks/use-voice-input' @@ -17,6 +21,7 @@ const SEND_BUTTON_DISABLED = 'bg-[#808080] dark:bg-[#808080]' interface ComposerProps { value: string + files: ReturnType /** On the empty home the placeholder types itself and the field is taller; in a chat it is the plain footer input. */ isInitialView: boolean isSending: boolean @@ -32,6 +37,7 @@ interface ComposerProps { */ export function Composer({ value, + files, isInitialView, isSending, onChange, @@ -46,7 +52,9 @@ export function Composer({ getValue: () => value, onChange, }) - const canSubmit = value.trim().length > 0 + const canSubmit = + !files.attachedFiles.some((file) => file.uploading) && + (value.trim().length > 0 || files.attachedFiles.some((file) => file.key)) const animatedPlaceholder = useAnimatedPlaceholder(isInitialView) const placeholder = isInitialView ? animatedPlaceholder : 'Send message to Sim' @@ -58,11 +66,20 @@ export function Composer({ return (
+
onChange(event.target.value)} + onPaste={(event) => { + const pasted = event.clipboardData.files + if (!pasted.length) return + event.preventDefault() + void files.processFiles(pasted) + }} onKeyDown={(event) => { if (event.key === 'Enter' && !event.shiftKey && !event.nativeEvent.isComposing) { event.preventDefault() @@ -86,43 +109,68 @@ export function Composer({ />
-
- {voice.isSupported && ( - - )} - {isSending ? ( - - ) : ( - - )} + + + + + ) : ( + + )} +
+ + {files.isDragging && } ({ apiKeys: vi.fn(), authorizedApps: vi.fn(), fetchNextPage: vi.fn(), + upload: vi.fn(), })) vi.mock('@/lib/auth/auth-client', () => ({ useSession: () => ({ data: { user: { id: 'reader' } } }), })) +vi.mock('@/lib/uploads/client/session-upload', () => ({ uploadInternalFileSession: mocks.upload })) vi.mock('@/lib/core/utils/browser-storage', () => ({ MothershipHandoffStorage: { consume: mocks.consume }, })) @@ -46,6 +48,14 @@ let container: HTMLDivElement beforeEach(() => { vi.clearAllMocks() vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true) + vi.stubGlobal( + 'URL', + class extends URL { + static createObjectURL = vi.fn(() => 'blob:image-preview') + static revokeObjectURL = vi.fn() + } + ) + mocks.upload.mockResolvedValue({ key: 'image-key', path: '/image-path' }) mocks.context.mockReturnValue({ organization: { id: 'organization-a' }, searchAccess: { memberScoped: true }, @@ -290,6 +300,90 @@ describe('organization home', () => { await act(async () => composerProps().onSubmit()) expect(mocks.send).not.toHaveBeenCalled() }) + it('sends image-only turns with canonical attachment properties and clears the draft', async () => { + await act(async () => root.render()) + const files = [new File(['image'], 'screenshot.png', { type: 'image/png' })] + await act(async () => + composerProps().files.processFiles( + Object.assign(files, { item: (index: number) => files[index] ?? null }) + ) + ) + await act(async () => composerProps().onSubmit()) + expect(mocks.send).toHaveBeenCalledWith( + '', + [ + expect.objectContaining({ + id: expect.any(String), + key: 'image-key', + filename: 'screenshot.png', + media_type: 'image/png', + size: 5, + path: '/image-path', + }), + ], + undefined, + { requestMode: 'assistant' } + ) + expect(composerProps().files.attachedFiles).toEqual([]) + }) + + it('restores queued images when editing and includes them in the replacement turn', async () => { + mocks.renderer.mockImplementation(({ composer }: { composer: ReactNode }) => composer) + const attachments = [ + { + id: 'image-a', + key: 'image-key', + filename: 'screenshot.png', + media_type: 'image/png', + size: 5, + }, + ] + mocks.chat.mockReturnValue({ + messages: [], + sendMessage: mocks.send, + editQueuedMessage: () => ({ + id: 'queued-a', + content: 'Explain this', + fileAttachments: attachments, + }), + }) + await act(async () => root.render()) + await act(async () => mocks.renderer.mock.lastCall![0].onEditQueuedMessage('queued-a')) + expect(composerProps().files.attachedFiles[0]).toEqual( + expect.objectContaining({ + name: 'screenshot.png', + key: 'image-key', + uploading: false, + path: '/api/files/serve/image-key?context=mothership&preview=1', + }) + ) + await act(async () => composerProps().onSubmit()) + expect(mocks.send).toHaveBeenCalledWith( + 'Explain this', + [{ ...attachments[0], path: '/api/files/serve/image-key?context=mothership&preview=1' }], + undefined, + { + requestMode: 'assistant', + } + ) + }) + + it('resumes image-only handoffs without dropping their attachments', async () => { + const attachments = [ + { + id: 'image-a', + key: 'image-key', + filename: 'screenshot.png', + media_type: 'image/png', + size: 5, + }, + ] + mocks.consume.mockReturnValueOnce({ message: '', fileAttachments: attachments }) + await act(async () => root.render()) + expect(mocks.send).toHaveBeenCalledWith('', attachments, undefined, { + requestMode: 'assistant', + }) + }) it('resumes a scoped handoff with the original search filters', async () => { const assistantSearch = { documentIds: ['document-a'] } mocks.consume.mockReturnValueOnce({ message: 'Summarize', assistantSearch }) diff --git a/apps/sim/app/o/[organizationId]/home/organization-home.tsx b/apps/sim/app/o/[organizationId]/home/organization-home.tsx index 59d754b9117..34ec83488ae 100644 --- a/apps/sim/app/o/[organizationId]/home/organization-home.tsx +++ b/apps/sim/app/o/[organizationId]/home/organization-home.tsx @@ -2,6 +2,7 @@ import { useEffect, useState } from 'react' import { useSession } from '@/lib/auth/auth-client' +import { getMothershipAttachmentPreviewUrl } from '@/lib/copilot/chat/attachment-preview' import { MothershipHandoffStorage } from '@/lib/core/utils/browser-storage' import { Composer } from '@/app/o/[organizationId]/home/components/composer' import { GetStarted } from '@/app/o/[organizationId]/home/components/get-started' @@ -9,6 +10,8 @@ import { useOrganizationContext } from '@/app/o/[organizationId]/providers/organ import { SearchIntegrationConnection } from '@/app/workspace/[workspaceId]/home/components/message-content/components/special-tags/search-integration-connection' import { MothershipChat } from '@/app/workspace/[workspaceId]/home/components/mothership-chat' import { useChat } from '@/app/workspace/[workspaceId]/home/hooks/use-chat' +import type { FileAttachmentForApi } from '@/app/workspace/[workspaceId]/home/types' +import { useFileAttachments } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/user-input/hooks/use-file-attachments' import { useMarkMothershipChatRead } from '@/hooks/queries/mothership-chats' interface OrganizationHomeProps { @@ -28,6 +31,7 @@ function OrganizationHomeContent({ userName, chatId }: OrganizationHomeProps) { const { data: session } = useSession() const [draft, setDraft] = useState('') const chat = useChat({ organizationId: organization.id }, chatId) + const files = useFileAttachments({ userId: session?.user?.id, organizationId: organization.id }) const { sendMessage } = chat const { mutate: markRead } = useMarkMothershipChatRead({ organizationId: organization.id }) const firstName = userName?.split(' ')[0] ?? '' @@ -40,8 +44,8 @@ function OrganizationHomeContent({ userName, chatId }: OrganizationHomeProps) { useEffect(() => { if (chatId) return const handoff = MothershipHandoffStorage.consume({ organizationId: organization.id }) - if (handoff?.message) { - void sendMessage(handoff.message, undefined, undefined, { + if (handoff && (handoff.message || handoff.fileAttachments?.length)) { + void sendMessage(handoff.message ?? '', handoff.fileAttachments, undefined, { requestMode: 'assistant', ...(handoff.resumeUserMessageId ? { resumeUserMessageId: handoff.resumeUserMessageId } @@ -51,21 +55,34 @@ function OrganizationHomeContent({ userName, chatId }: OrganizationHomeProps) { } }, [chatId, organization.id, sendMessage]) - const send = (message: string) => { - void sendMessage(message, undefined, undefined, { requestMode: 'assistant' }) + const send = (message: string, fileAttachments?: FileAttachmentForApi[]) => { + void sendMessage(message, fileAttachments, undefined, { requestMode: 'assistant' }) } const submit = () => { const message = draft.trim() - if (!message) return + if (files.attachedFiles.some((file) => file.uploading)) return + const attachments: FileAttachmentForApi[] = files.attachedFiles + .filter((file) => file.key) + .map((file) => ({ + id: file.id, + key: file.key!, + filename: file.name, + media_type: file.type, + size: file.size, + path: file.path, + })) + if (!message && !attachments.length) return setDraft('') - send(message) + send(message, attachments.length ? attachments : undefined) + files.clearAttachedFiles() } const hasChat = Boolean(chatId || chat.messages.length) const composer = ( { const queued = chat.editQueuedMessage(id) - if (queued) setDraft(queued.content) + if (queued) { + setDraft(queued.content) + files.restoreAttachedFiles( + (queued.fileAttachments ?? []).map((file) => ({ + id: file.id, + key: file.key, + name: file.filename, + type: file.media_type, + size: file.size, + path: file.path || getMothershipAttachmentPreviewUrl(file) || '', + previewUrl: getMothershipAttachmentPreviewUrl(file), + uploading: false, + })) + ) + } return queued }} onCancelQueueEdit={chat.cancelQueueEdit} diff --git a/apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/drop-overlay/drop-overlay.tsx b/apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/drop-overlay/drop-overlay.tsx index 03993db036e..08bd1e957d5 100644 --- a/apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/drop-overlay/drop-overlay.tsx +++ b/apps/sim/app/workspace/[workspaceId]/home/components/user-input/components/drop-overlay/drop-overlay.tsx @@ -1,6 +1,7 @@ 'use client' import { memo } from 'react' +import { ImageUp } from '@sim/emcn/icons' import { AudioIcon, CsvIcon, @@ -25,13 +26,19 @@ const DROP_OVERLAY_ICONS = [ VideoIcon, ] as const -export const DropOverlay = memo(function DropOverlay() { +interface DropOverlayProps { + imagesOnly?: boolean +} + +export const DropOverlay = memo(function DropOverlay({ imagesOnly = false }: DropOverlayProps) { return (
- Drop files + + {imagesOnly ? 'Drop images' : 'Drop files'} +
- {DROP_OVERLAY_ICONS.map((Icon, i) => ( + {(imagesOnly ? [ImageUp] : DROP_OVERLAY_ICONS).map((Icon, i) => ( ))}
diff --git a/apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.mount-send.test.tsx b/apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.mount-send.test.tsx index 7ec24fb8476..875dc709b53 100644 --- a/apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.mount-send.test.tsx +++ b/apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.mount-send.test.tsx @@ -301,6 +301,37 @@ async function waitFor(predicate: () => boolean, budgetMs = 2000): Promise } describe('useChat remount send recovery', () => { + it('sends and recovers an image-only organization turn', async () => { + navigationMocks.usePathname.mockReturnValue('/o/org-1/home') + const { getResult, unmount } = renderUseChat({ organizationId: 'org-1' }) + const attachments = [ + { + id: 'image-a', + key: 'image-key', + filename: 'screenshot.png', + media_type: 'image/png', + size: 5, + }, + ] + await act(async () => { + void getResult().sendMessage('', attachments) + }) + await waitFor(() => state.postBodies.length === 1) + expect(state.postBodies[0]).toMatchObject({ + organizationId: 'org-1', + mode: 'assistant', + message: '', + fileAttachments: attachments, + }) + expect(state.postBodies[0]).not.toHaveProperty('workspaceId') + unmount() + await waitFor(() => window.localStorage.getItem('sim_mothership_handoff') !== null) + expect(MothershipHandoffStorage.consume({ organizationId: 'org-1' })).toMatchObject({ + message: '', + fileAttachments: attachments, + }) + }) + it('sends and recovers an organization turn without adding workspace scope', async () => { navigationMocks.usePathname.mockReturnValue('/o/org-1/home') const { getResult, unmount } = renderUseChat({ organizationId: 'org-1' }) diff --git a/apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts b/apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts index 6752c4cd6e3..0ac26689ac1 100644 --- a/apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts +++ b/apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts @@ -3811,7 +3811,7 @@ export function useChat( contexts?: ChatContext[], options?: StartSendMessageOptions ): Promise => { - if (!message.trim() || !scopeKey) return false + if ((!message.trim() && !fileAttachments?.length) || !scopeKey) return false const { onOptimisticSendApplied, queuedSendHandoff } = options ?? {} const pendingStop = options?.pendingStop ?? pendingStopPromiseRef.current const pendingStopStreamId = pendingStop @@ -4339,7 +4339,7 @@ export function useChat( contexts?: ChatContext[], options?: SendMessageOptions ) => { - if (!message.trim() || !scopeKey) return + if ((!message.trim() && !fileAttachments?.length) || !scopeKey) return const queueStore = useMothershipQueueStore.getState() const activeChatKey = chatKeyRef.current diff --git a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/user-input/hooks/use-file-attachments.test.tsx b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/user-input/hooks/use-file-attachments.test.tsx index 9d1a3d26d63..520c7fd8c8b 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/user-input/hooks/use-file-attachments.test.tsx +++ b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/user-input/hooks/use-file-attachments.test.tsx @@ -16,6 +16,10 @@ vi.mock('@/lib/uploads/client/session-upload', () => ({ uploadInternalFileSession: mockUploadInternalFileSession, })) +import { + ASSISTANT_IMAGE_MAX_BYTES, + ASSISTANT_IMAGE_MAX_COUNT, +} from '@/lib/uploads/shared/assistant-images' import { MAX_WORKSPACE_FILE_SIZE } from '@/lib/uploads/shared/types' import { useFileAttachments } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/user-input/hooks/use-file-attachments' @@ -24,13 +28,15 @@ interface HookHarness { unmount: () => void } -function renderFileAttachmentsHook(): HookHarness { +function renderFileAttachmentsHook( + owner: { workspaceId: string } | { organizationId: string } = { workspaceId: 'workspace-1' } +): HookHarness { ;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true const root: Root = createRoot(document.createElement('div')) let latest: ReturnType function Probe() { - latest = useFileAttachments({ userId: 'user-1', workspaceId: 'workspace-1' }) + latest = useFileAttachments({ userId: 'user-1', ...owner }) return null } @@ -115,4 +121,45 @@ describe('useFileAttachments admission', () => { unmount() }) + + it.each(['unsupported', 'oversized', 'too many'] as const)( + 'rejects %s organization images before allocating previews or sessions', + async (kind) => { + const { result, unmount } = renderFileAttachmentsHook({ organizationId: 'organization-1' }) + const files = + kind === 'unsupported' + ? [new File(['pdf'], 'document.pdf', { type: 'application/pdf' })] + : kind === 'oversized' + ? [sizedFile('large.png', ASSISTANT_IMAGE_MAX_BYTES + 1)] + : Array.from({ length: ASSISTANT_IMAGE_MAX_COUNT + 1 }, (_, index) => + sizedFile(`image-${index}.png`, 10) + ) + await act(async () => result().processFiles(asFileList(files))) + expect(mockToastError).toHaveBeenCalledOnce() + expect(createObjectUrl).not.toHaveBeenCalled() + expect(mockUploadInternalFileSession).not.toHaveBeenCalled() + expect(result().attachedFiles).toEqual([]) + unmount() + } + ) + + it('uses organization scope for images and removes a failed upload', async () => { + mockUploadInternalFileSession.mockRejectedValueOnce(new Error('Upload failed')) + const { result, unmount } = renderFileAttachmentsHook({ organizationId: 'organization-1' }) + const file = sizedFile('screenshot.png', 10) + await act(async () => result().processFiles(asFileList([file]))) + expect(mockUploadInternalFileSession).toHaveBeenCalledWith( + expect.objectContaining({ + purpose: 'mothership_attachment', + organizationId: 'organization-1', + file, + }) + ) + expect(mockUploadInternalFileSession.mock.calls[0][0]).not.toHaveProperty('workspaceId') + expect(result().attachedFiles).toEqual([]) + expect(mockToastError).toHaveBeenCalledWith('Couldn\'t upload "screenshot.png"', { + description: 'Upload failed', + }) + unmount() + }) }) diff --git a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/user-input/hooks/use-file-attachments.ts b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/user-input/hooks/use-file-attachments.ts index 13a5be86e4f..edf9c7aa24d 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/user-input/hooks/use-file-attachments.ts +++ b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/user-input/hooks/use-file-attachments.ts @@ -9,6 +9,12 @@ import { getMothershipAttachmentPreviewUrl } from '@/lib/copilot/chat/attachment import { assertMultiFileUploadAdmission } from '@/lib/uploads/client/admission' import { runWithConcurrency, WHOLE_FILE_PARALLEL_UPLOADS } from '@/lib/uploads/client/concurrency' import { uploadInternalFileSession } from '@/lib/uploads/client/session-upload' +import { + ASSISTANT_IMAGE_MAX_BYTES, + ASSISTANT_IMAGE_MAX_COUNT, + ASSISTANT_IMAGE_MAX_TOTAL_BYTES, + isAssistantImageType, +} from '@/lib/uploads/shared/assistant-images' import { MAX_WORKSPACE_FILE_SIZE } from '@/lib/uploads/shared/types' import { resolveFileType } from '@/lib/uploads/utils/file-utils' @@ -78,6 +84,7 @@ export interface MessageFileAttachment { interface UseFileAttachmentsProps { userId?: string workspaceId?: string + organizationId?: string disabled?: boolean isLoading?: boolean } @@ -90,7 +97,7 @@ interface UseFileAttachmentsProps { * @returns File attachment state and operations */ export function useFileAttachments(props: UseFileAttachmentsProps) { - const { userId, workspaceId, disabled, isLoading } = props + const { userId, workspaceId, organizationId, disabled, isLoading } = props const [attachedFiles, setAttachedFiles] = useState([]) const [dragCounter, setDragCounter] = useState(0) @@ -152,16 +159,29 @@ export function useFileAttachments(props: UseFileAttachmentsProps) { logger.error('User ID not available for file upload') return } - if (!workspaceId) { - logger.error('workspaceId required for mothership uploads') + if (!workspaceId && !organizationId) { + logger.error('Workspace or organization context required for attachments') return } if (fileList.length === 0) return try { + if ( + organizationId && + Array.from(fileList).some((file) => !isAssistantImageType(resolveFileType(file))) + ) { + toast.error('Attach PNG, JPEG, GIF, or WebP images.') + return + } assertMultiFileUploadAdmission(fileList, { existingFiles: attachedFilesRef.current, - maxFileBytes: MAX_WORKSPACE_FILE_SIZE, + maxFileBytes: organizationId ? ASSISTANT_IMAGE_MAX_BYTES : MAX_WORKSPACE_FILE_SIZE, + ...(organizationId + ? { + maxFiles: ASSISTANT_IMAGE_MAX_COUNT, + maxTotalBytes: ASSISTANT_IMAGE_MAX_TOTAL_BYTES, + } + : {}), }) } catch (error) { toast.error("Couldn't add files", { description: toError(error).message }) @@ -198,7 +218,7 @@ export function useFileAttachments(props: UseFileAttachmentsProps) { const result = await uploadInternalFileSession({ purpose: 'mothership_attachment', file, - workspaceId, + ...(organizationId ? { organizationId } : { workspaceId: workspaceId! }), signal: controller.signal, }) @@ -236,7 +256,7 @@ export function useFileAttachments(props: UseFileAttachmentsProps) { } }) }, - [userId, workspaceId, updateAttachedFiles] + [userId, workspaceId, organizationId, updateAttachedFiles] ) /** diff --git a/apps/sim/lib/api/contracts/upload-sessions.ts b/apps/sim/lib/api/contracts/upload-sessions.ts index a60749ac704..dfc5938b859 100644 --- a/apps/sim/lib/api/contracts/upload-sessions.ts +++ b/apps/sim/lib/api/contracts/upload-sessions.ts @@ -2,6 +2,7 @@ import { z } from 'zod' import { folderIdSchema, noInputSchema, + organizationIdSchema, workflowIdSchema, workspaceIdSchema, } from '@/lib/api/contracts/primitives' @@ -16,6 +17,10 @@ import { v2UploadTransferSchema, } from '@/lib/api/contracts/v2/uploads' import { executionIdSchema } from '@/lib/api/contracts/workflows' +import { + ASSISTANT_IMAGE_CONTENT_TYPES, + ASSISTANT_IMAGE_MAX_BYTES, +} from '@/lib/uploads/shared/assistant-images' import { MAX_WORKSPACE_FILE_SIZE, MAX_WORKSPACE_FORMDATA_FILE_SIZE, @@ -62,9 +67,30 @@ export const createInternalFileUploadBodySchema = z.discriminatedUnion('purpose' purpose: z.literal('mothership_attachment'), ...internalFileUploadBaseShape, size: z.number().int().min(1).max(MAX_WORKSPACE_FILE_SIZE), - workspaceId: workspaceIdSchema, + workspaceId: workspaceIdSchema.optional(), + organizationId: organizationIdSchema.optional(), }) - .strict(), + .strict() + .superRefine((body, ctx) => { + if (Boolean(body.workspaceId) === Boolean(body.organizationId)) { + ctx.addIssue({ + code: 'custom', + path: ['workspaceId'], + message: 'Provide exactly one workspaceId or organizationId', + }) + } + if ( + body.organizationId && + (body.size > ASSISTANT_IMAGE_MAX_BYTES || + !ASSISTANT_IMAGE_CONTENT_TYPES.some((type) => type === body.contentType)) + ) { + ctx.addIssue({ + code: 'custom', + path: ['contentType'], + message: 'Assistant attachments must be PNG, JPEG, GIF, or WebP images up to 5 MB', + }) + } + }), z .object({ purpose: z.literal('execution_attachment'), diff --git a/apps/sim/lib/copilot/chat/assistant-images.test.ts b/apps/sim/lib/copilot/chat/assistant-images.test.ts new file mode 100644 index 00000000000..5a11b4905de --- /dev/null +++ b/apps/sim/lib/copilot/chat/assistant-images.test.ts @@ -0,0 +1,104 @@ +/** @vitest-environment node */ +import type { SessionPrincipal } from '@sim/auth/principal' +import { beforeEach, describe, expect, it, vi } from 'vitest' +import { OrchestrationError } from '@/lib/core/orchestration/types' +import type { readOrganizationAssistantImage } from '@/lib/uploads/contexts/organization-assistant/application' +import { ASSISTANT_IMAGE_MAX_COUNT } from '@/lib/uploads/shared/assistant-images' + +const { readImage } = vi.hoisted(() => ({ + readImage: vi.fn(), +})) +vi.mock('@/lib/uploads/contexts/organization-assistant/application', () => ({ + readOrganizationAssistantImage: readImage, +})) + +import { prepareAssistantImages } from '@/lib/copilot/chat/assistant-images' +import { getMothershipAttachmentPreviewUrl } from '@/lib/copilot/chat/attachment-preview' + +const principal: SessionPrincipal = { kind: 'session', userId: 'user-1', sessionId: 'session-1' } +const key = 'assistant/org-1/user-1/upload-1/image.png' +const image = { + id: 'upload-1', + key, + name: 'image.png', + contentType: 'image/png', + size: 5, + buffer: Buffer.from('image'), +} + +describe('Assistant image preparation', () => { + beforeEach(() => { + vi.clearAllMocks() + readImage.mockResolvedValue(image) + }) + + it('uses canonical metadata and model content from the authorized reader', async () => { + const signal = new AbortController().signal + const result = await prepareAssistantImages({ + principal, + organizationId: 'org-1', + attachments: [{ key }], + signal, + }) + expect(readImage).toHaveBeenCalledWith({ principal, organizationId: 'org-1', key, signal }) + expect(result).toEqual({ + attachments: [ + { id: 'upload-1', key, filename: 'image.png', media_type: 'image/png', size: 5 }, + ], + content: [ + { + type: 'image', + filename: 'image.png', + source: { type: 'base64', media_type: 'image/png', data: 'aW1hZ2U=' }, + }, + ], + }) + expect(getMothershipAttachmentPreviewUrl(result.attachments[0])).toBe( + `/api/files/serve/${encodeURIComponent(key)}?context=mothership&preview=1` + ) + }) + + it('rejects an oversized batch before reading any image', async () => { + await expect( + prepareAssistantImages({ + principal, + organizationId: 'org-1', + attachments: Array.from({ length: ASSISTANT_IMAGE_MAX_COUNT + 1 }, () => ({ key })), + }) + ).rejects.toMatchObject({ code: 'validation' }) + expect(readImage).not.toHaveBeenCalled() + }) + + it('fails the entire turn if any image is inaccessible', async () => { + readImage.mockRejectedValueOnce(new OrchestrationError('not_found', 'Image not found')) + await expect( + prepareAssistantImages({ + principal, + organizationId: 'org-1', + attachments: [{ key }, { key: 'another-image' }], + }) + ).rejects.toMatchObject({ code: 'not_found' }) + expect(readImage).toHaveBeenCalledOnce() + }) + + it('rejects non-image content even if an upstream reader returns it', async () => { + readImage.mockResolvedValueOnce({ ...image, contentType: 'application/pdf' }) + await expect( + prepareAssistantImages({ principal, organizationId: 'org-1', attachments: [{ key }] }) + ).rejects.toMatchObject({ code: 'validation' }) + }) + + it('does not read images after the request is aborted', async () => { + const controller = new AbortController() + controller.abort() + await expect( + prepareAssistantImages({ + principal, + organizationId: 'org-1', + attachments: [{ key }], + signal: controller.signal, + }) + ).rejects.toMatchObject({ name: 'AbortError' }) + expect(readImage).not.toHaveBeenCalled() + }) +}) diff --git a/apps/sim/lib/copilot/chat/assistant-images.ts b/apps/sim/lib/copilot/chat/assistant-images.ts new file mode 100644 index 00000000000..c2f6f643743 --- /dev/null +++ b/apps/sim/lib/copilot/chat/assistant-images.ts @@ -0,0 +1,68 @@ +import type { SessionPrincipal } from '@sim/auth/principal' +import type { PersistedFileAttachment } from '@/lib/copilot/chat/persisted-message' +import { OrchestrationError } from '@/lib/core/orchestration/types' +import { readOrganizationAssistantImage } from '@/lib/uploads/contexts/organization-assistant/application' +import { + ASSISTANT_IMAGE_MAX_COUNT, + ASSISTANT_IMAGE_MAX_TOTAL_BYTES, +} from '@/lib/uploads/shared/assistant-images' +import { createFileContent, type MessageContent } from '@/lib/uploads/utils/file-utils' + +export interface AssistantImageContent extends MessageContent { + type: 'image' + filename: string +} + +interface PreparedAssistantImages { + attachments: PersistedFileAttachment[] + content: AssistantImageContent[] +} + +/** Resolves private uploads before any attachment metadata or bytes enter a chat turn. */ +export async function prepareAssistantImages({ + principal, + organizationId, + attachments, + signal, +}: { + principal: SessionPrincipal + organizationId: string + attachments: readonly { key: string }[] + signal?: AbortSignal +}): Promise { + if (attachments.length > ASSISTANT_IMAGE_MAX_COUNT) { + throw new OrchestrationError( + 'validation', + `Attach up to ${ASSISTANT_IMAGE_MAX_COUNT} images per message` + ) + } + + const prepared: PreparedAssistantImages = { attachments: [], content: [] } + let totalBytes = 0 + for (const attachment of attachments) { + signal?.throwIfAborted() + const image = await readOrganizationAssistantImage({ + principal, + organizationId, + key: attachment.key, + signal, + }) + totalBytes += image.buffer.length + if (totalBytes > ASSISTANT_IMAGE_MAX_TOTAL_BYTES) { + throw new OrchestrationError('payload_too_large', 'Attached images are too large') + } + const content = createFileContent(image.buffer, image.contentType) + if (content?.type !== 'image') { + throw new OrchestrationError('validation', 'Assistant attachments must be supported images') + } + prepared.attachments.push({ + id: image.id, + key: image.key, + filename: image.name, + media_type: image.contentType, + size: image.size, + }) + prepared.content.push({ ...content, type: 'image', filename: image.name }) + } + return prepared +} diff --git a/apps/sim/lib/copilot/chat/payload.test.ts b/apps/sim/lib/copilot/chat/payload.test.ts index 5c504effebe..93a86f0b825 100644 --- a/apps/sim/lib/copilot/chat/payload.test.ts +++ b/apps/sim/lib/copilot/chat/payload.test.ts @@ -647,6 +647,33 @@ describe('Assistant payload', () => { mockIsIntegrationDeploymentAvailable.mockReturnValue(true) mockCreateUserToolSchema.mockReturnValue({ type: 'object', properties: {} }) }) + it('sends prepared organization images as model-readable attachments without workspace tracking', async () => { + mockTrackChatUpload.mockClear() + const image = { + type: 'image' as const, + filename: 'image.png', + source: { type: 'base64' as const, media_type: 'image/png', data: 'aW1hZ2U=' }, + } + const payload = await buildCopilotRequestPayload( + { + message: '', + userId: 'user-1', + userMessageId: 'message-1', + organizationId: 'org-1', + mode: 'assistant', + model: '', + assistantImages: [image], + fileAttachments: [{ id: 'image', key: 'private-upload', size: 5 }], + }, + { selectedModel: '' } + ) + expect(payload.message).toBe('') + expect(payload.fileAttachments).toEqual([image]) + expect(payload).not.toHaveProperty('context') + expect(payload).not.toHaveProperty('workspaceId') + expect(mockTrackChatUpload).not.toHaveBeenCalled() + }) + it('forwards organization scope without workspace, integration, or desktop authority', async () => { const payload = await buildCopilotRequestPayload( { diff --git a/apps/sim/lib/copilot/chat/payload.ts b/apps/sim/lib/copilot/chat/payload.ts index ff76023488c..35a48a938a7 100644 --- a/apps/sim/lib/copilot/chat/payload.ts +++ b/apps/sim/lib/copilot/chat/payload.ts @@ -10,6 +10,7 @@ import { isAssistantIntegrationTool, } from '@/lib/copilot/assistant/tool-policy' import { getBlockVisibilityForCopilot, visibilitySignature } from '@/lib/copilot/block-visibility' +import type { AssistantImageContent } from '@/lib/copilot/chat/assistant-images' import type { VfsSnapshotV1 } from '@/lib/copilot/generated/vfs-snapshot-v1' import { type IntegrationGateConfig, @@ -52,6 +53,7 @@ interface BuildPayloadParams { */ mcpServerIds?: string[] fileAttachments?: Array<{ id: string; key: string; size: number; [key: string]: unknown }> + assistantImages?: AssistantImageContent[] commands?: string[] chatId?: string prefetch?: boolean @@ -412,6 +414,9 @@ export async function buildCopilotRequestPayload( ...(provider ? { provider } : {}), mode: transportMode, ...(isAssistant && params.assistantSearch ? { assistantSearch: params.assistantSearch } : {}), + ...(isAssistant && params.organizationId && params.assistantImages?.length + ? { fileAttachments: params.assistantImages } + : {}), messageId: userMessageId, ...(allContexts.length > 0 ? { context: allContexts } : {}), ...(chatId ? { chatId } : {}), diff --git a/apps/sim/lib/copilot/chat/post.test.ts b/apps/sim/lib/copilot/chat/post.test.ts index 6a0d6914736..a06b91590d8 100644 --- a/apps/sim/lib/copilot/chat/post.test.ts +++ b/apps/sim/lib/copilot/chat/post.test.ts @@ -40,6 +40,7 @@ const { resolveBillingAttribution, resolveOrganizationBillingAttribution, authorizeOrganizationChat, + readOrganizationAssistantImage, finalizeAssistantTurn, appendCopilotChatMessages, persistChatResources, @@ -62,6 +63,7 @@ const { resolveBillingAttribution: vi.fn(), resolveOrganizationBillingAttribution: vi.fn(), authorizeOrganizationChat: vi.fn(), + readOrganizationAssistantImage: vi.fn(), finalizeAssistantTurn: vi.fn(), appendCopilotChatMessages: vi.fn(), persistChatResources: vi.fn(), @@ -135,6 +137,10 @@ vi.mock('@/lib/copilot/chat/organization-chats', () => ({ authorizeOrganizationChat: { execute: authorizeOrganizationChat }, })) +vi.mock('@/lib/uploads/contexts/organization-assistant/application', () => ({ + readOrganizationAssistantImage, +})) + vi.mock('@/lib/credentials/application/personal-credentials', () => ({ listPersonalCredentials: { execute: listPersonal }, })) @@ -237,6 +243,14 @@ describe('handleUnifiedChatPost', () => { userId: 'user-1', role: 'member', }) + readOrganizationAssistantImage.mockResolvedValue({ + id: 'upload-1', + key: 'assistant/org-1/user-1/upload-1/image.png', + name: 'image.png', + contentType: 'image/png', + size: 5, + buffer: Buffer.from('image'), + }) getEffectiveEnvironmentSnapshot.mockResolvedValue({ personalEncrypted: { API_KEY: 'encrypted-secret' }, workspaceEncrypted: {}, @@ -341,6 +355,130 @@ describe('handleUnifiedChatPost', () => { ) }) + it.each(['Describe this image', ''])( + 'prepares organization image bytes and persists canonical metadata (message: %s)', + async (message) => { + getSession.mockResolvedValue({ user: { id: 'user-1' }, session: { id: 'session-1' } }) + dbChainMockFns.returning.mockResolvedValueOnce([{ model: null }]) + const key = 'assistant/org-1/user-1/upload-1/image.png' + const response = await handleUnifiedChatPost( + new NextRequest('http://localhost/api/mothership/chat', { + method: 'POST', + body: JSON.stringify({ + message, + organizationId: 'org-1', + mode: 'assistant', + fileAttachments: [ + { id: 'forged-id', key, filename: 'forged.txt', media_type: 'text/plain', size: 0 }, + ], + }), + }) + ) + expect(response.status).toBe(200) + expect(readOrganizationAssistantImage).toHaveBeenCalledWith({ + principal: { kind: 'session', userId: 'user-1', sessionId: 'session-1' }, + organizationId: 'org-1', + key, + signal: expect.any(AbortSignal), + }) + expect(buildCopilotRequestPayload).toHaveBeenCalledWith( + expect.objectContaining({ + message, + assistantImages: [ + { + type: 'image', + filename: 'image.png', + source: { type: 'base64', media_type: 'image/png', data: 'aW1hZ2U=' }, + }, + ], + }), + expect.anything() + ) + expect(appendCopilotChatMessages).toHaveBeenCalledWith( + 'chat-1', + [ + expect.objectContaining({ + content: message, + fileAttachments: [ + { id: 'upload-1', key, filename: 'image.png', media_type: 'image/png', size: 5 }, + ], + }), + ], + expect.anything(), + expect.anything() + ) + expect(getUserEntityPermissions).not.toHaveBeenCalled() + expect(generateWorkspaceSnapshot).not.toHaveBeenCalled() + } + ) + + it('rejects inaccessible images before creating or persisting a conversation', async () => { + getSession.mockResolvedValue({ user: { id: 'user-1' }, session: { id: 'session-1' } }) + readOrganizationAssistantImage.mockRejectedValueOnce( + new OrchestrationError('not_found', 'Image not found') + ) + const response = await handleUnifiedChatPost( + new NextRequest('http://localhost/api/mothership/chat', { + method: 'POST', + body: JSON.stringify({ + message: '', + organizationId: 'org-1', + mode: 'assistant', + fileAttachments: [ + { + id: 'image', + key: 'other-user-image', + filename: 'image.png', + media_type: 'image/png', + size: 5, + }, + ], + }), + }) + ) + expect(response.status).toBe(403) + expect(resolveOrCreateChat).not.toHaveBeenCalled() + expect(appendCopilotChatMessages).not.toHaveBeenCalled() + expect(createSSEStream).not.toHaveBeenCalled() + }) + + it('continues rejecting empty messages without organization images', async () => { + const response = await handleUnifiedChatPost( + new NextRequest('http://localhost/api/mothership/chat', { + method: 'POST', + body: JSON.stringify({ message: '', organizationId: 'org-1', mode: 'assistant' }), + }) + ) + expect(response.status).toBe(400) + expect(readOrganizationAssistantImage).not.toHaveBeenCalled() + expect(resolveOrCreateChat).not.toHaveBeenCalled() + }) + + it('keeps workspace files unavailable in workspace Assistant mode', async () => { + const response = await handleUnifiedChatPost( + new NextRequest('http://localhost/api/mothership/chat', { + method: 'POST', + body: JSON.stringify({ + message: 'Read this file', + workspaceId: 'ws-1', + mode: 'assistant', + fileAttachments: [ + { + id: 'file-1', + key: 'workspace/file.png', + filename: 'file.png', + media_type: 'image/png', + size: 5, + }, + ], + }), + }) + ) + expect(response.status).toBe(400) + expect(readOrganizationAssistantImage).not.toHaveBeenCalled() + expect(resolveOrCreateChat).not.toHaveBeenCalled() + }) + it.each([{ workspaceId: 'ws-1' }, { workflowId: 'wf-1' }, { mode: 'agent' }])( 'rejects mixed organization scope before persistence: %j', async (extra) => { diff --git a/apps/sim/lib/copilot/chat/post.ts b/apps/sim/lib/copilot/chat/post.ts index ba2f04f7afe..77b1570cb8d 100644 --- a/apps/sim/lib/copilot/chat/post.ts +++ b/apps/sim/lib/copilot/chat/post.ts @@ -19,6 +19,10 @@ import { resolveOrganizationBillingAttribution, } from '@/lib/billing/core/billing-attribution' import { chatOperations } from '@/lib/copilot/application/operations' +import { + type AssistantImageContent, + prepareAssistantImages, +} from '@/lib/copilot/chat/assistant-images' import { DESKTOP_TERMINAL_HINT_ID_MAX_LENGTH, DESKTOP_TERMINAL_HINT_TEXT_MAX_LENGTH, @@ -277,63 +281,70 @@ const ChatContextSchema = z } }) -const ChatMessageSchema = z.object({ - message: z.string().min(1, 'Message is required'), - /* Bounded because it becomes part of a Postgres key in `chatSendIdempotency`; +const ChatMessageSchema = z + .object({ + message: z.string(), + /* Bounded because it becomes part of a Postgres key in `chatSendIdempotency`; a client-supplied id longer than the btree entry limit would throw there. A generated id is 36 chars. */ - userMessageId: z.string().max(128).optional(), - chatId: z.string().optional(), - workflowId: z.string().optional(), - workspaceId: z.string().optional(), - organizationId: z.string().min(1).max(200).optional(), - workflowName: z.string().optional(), - model: z.string().optional().default(DEFAULT_MODEL), - mode: z.enum(COPILOT_REQUEST_MODES).optional().default('agent'), - assistantSearch: workspaceSearchFiltersSchema.optional(), - prefetch: z.boolean().optional(), - createNewChat: z.boolean().optional().default(false), - implicitFeedback: z.string().optional(), - fileAttachments: z.array(FileAttachmentSchema).optional(), - resourceAttachments: z - .preprocess(dropUnaddressableAttachments, z.array(ResourceAttachmentSchema)) - .optional(), - provider: z.string().optional(), - contexts: z.array(ChatContextSchema).optional(), - commands: z.array(z.string()).optional(), - userTimezone: z.string().optional(), - desktopCapabilities: z - .object({ - localFilesystem: z.boolean().optional(), - browser: z.boolean().optional(), - terminal: z.boolean().optional(), - terminals: z - .array( - z.object({ - id: z.string().max(DESKTOP_TERMINAL_HINT_ID_MAX_LENGTH), - cwd: z.string().max(DESKTOP_TERMINAL_HINT_TEXT_MAX_LENGTH).optional(), - running: z.string().max(DESKTOP_TERMINAL_HINT_TEXT_MAX_LENGTH).optional(), - interactive: z.boolean().optional(), - active: z.boolean().optional(), - }) - ) - .optional(), - browserSessions: z - .array( - z.object({ - hostname: z - .string() - .max(253) - .regex(/^[a-z0-9.-]+$/), - evidence: z.enum(['sign-in-completed', 'cookies']), - lastObservedAt: z.string().datetime(), - }) - ) - .max(20) - .optional(), - }) - .optional(), -}) + userMessageId: z.string().max(128).optional(), + chatId: z.string().optional(), + workflowId: z.string().optional(), + workspaceId: z.string().optional(), + organizationId: z.string().min(1).max(200).optional(), + workflowName: z.string().optional(), + model: z.string().optional().default(DEFAULT_MODEL), + mode: z.enum(COPILOT_REQUEST_MODES).optional().default('agent'), + assistantSearch: workspaceSearchFiltersSchema.optional(), + prefetch: z.boolean().optional(), + createNewChat: z.boolean().optional().default(false), + implicitFeedback: z.string().optional(), + fileAttachments: z.array(FileAttachmentSchema).optional(), + resourceAttachments: z + .preprocess(dropUnaddressableAttachments, z.array(ResourceAttachmentSchema)) + .optional(), + provider: z.string().optional(), + contexts: z.array(ChatContextSchema).optional(), + commands: z.array(z.string()).optional(), + userTimezone: z.string().optional(), + desktopCapabilities: z + .object({ + localFilesystem: z.boolean().optional(), + browser: z.boolean().optional(), + terminal: z.boolean().optional(), + terminals: z + .array( + z.object({ + id: z.string().max(DESKTOP_TERMINAL_HINT_ID_MAX_LENGTH), + cwd: z.string().max(DESKTOP_TERMINAL_HINT_TEXT_MAX_LENGTH).optional(), + running: z.string().max(DESKTOP_TERMINAL_HINT_TEXT_MAX_LENGTH).optional(), + interactive: z.boolean().optional(), + active: z.boolean().optional(), + }) + ) + .optional(), + browserSessions: z + .array( + z.object({ + hostname: z + .string() + .max(253) + .regex(/^[a-z0-9.-]+$/), + evidence: z.enum(['sign-in-completed', 'cookies']), + lastObservedAt: z.string().datetime(), + }) + ) + .max(20) + .optional(), + }) + .optional(), + }) + .refine( + (body) => + body.message.length > 0 || + (body.mode === 'assistant' && !!body.organizationId && !!body.fileAttachments?.length), + { message: 'Message is required', path: ['message'] } + ) type UnifiedChatRequest = z.infer type BrowserSessions = NonNullable['browserSessions'] @@ -406,6 +417,7 @@ type UnifiedChatBranch = contexts: Array<{ type: string; content: string; tag?: string; path?: string }> mcpServerIds?: string[] fileAttachments?: UnifiedChatRequest['fileAttachments'] + assistantImages?: AssistantImageContent[] userPermission?: string entitlements?: string[] userTimezone?: string @@ -1138,7 +1150,7 @@ export async function handleUnifiedChatPost(req: NextRequest) { body.mode === 'assistant' && (body.workflowId || body.workflowName || - body.fileAttachments?.length || + (body.fileAttachments?.length && !body.organizationId) || body.contexts?.length) ) { return createBadRequestResponse( @@ -1251,6 +1263,21 @@ export async function handleUnifiedChatPost(req: NextRequest) { return capabilityRefusalResponse(chatCapability) } + const assistantImages = + branch.kind === 'organization' && body.fileAttachments?.length + ? await prepareAssistantImages({ + principal: { + kind: 'session', + userId: authenticatedUserId, + sessionId: session.session.id, + }, + organizationId: branch.organizationId, + attachments: body.fileAttachments, + signal: req.signal, + }) + : undefined + const fileAttachments = assistantImages?.attachments ?? body.fileAttachments + /* Prompt content is captured only once the turn is going to run. Both calls are internally gated on OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT, but the gate is on @@ -1478,7 +1505,7 @@ export async function handleUnifiedChatPost(req: NextRequest) { chatId: actualChatId, userMessageId, message: body.message, - fileAttachments: body.fileAttachments, + fileAttachments, contexts: normalizedContexts, workspaceId, notifyWorkspaceStatus: branch.notifyWorkspaceStatus, @@ -1543,7 +1570,7 @@ export async function handleUnifiedChatPost(req: NextRequest) { contexts: turnContexts, assistantSearch: body.mode === 'assistant' ? body.assistantSearch : undefined, mcpServerIds, - fileAttachments: body.fileAttachments, + fileAttachments, userPermission: userPermission ?? undefined, entitlements, userTimezone: body.userTimezone, @@ -1572,7 +1599,8 @@ export async function handleUnifiedChatPost(req: NextRequest) { contexts: turnContexts, assistantSearch: body.mode === 'assistant' ? body.assistantSearch : undefined, mcpServerIds, - fileAttachments: body.fileAttachments, + fileAttachments, + assistantImages: assistantImages?.content, userPermission: userPermission ?? undefined, entitlements, userTimezone: body.userTimezone, @@ -1702,6 +1730,12 @@ export async function handleUnifiedChatPost(req: NextRequest) { if (applicationError?.code === 'forbidden' || applicationError?.code === 'not_found') { return NextResponse.json({ error: 'Conversation access denied' }, { status: 403 }) } + if (applicationError?.code === 'validation' || applicationError?.code === 'payload_too_large') { + return NextResponse.json( + { error: applicationError.message }, + { status: applicationError.code === 'validation' ? 400 : 413 } + ) + } if (isWorkspaceAccessDeniedError(error)) { return NextResponse.json({ error: 'Workspace access denied' }, { status: 403 }) } diff --git a/apps/sim/lib/core/utils/browser-storage.ts b/apps/sim/lib/core/utils/browser-storage.ts index 32109dcfb58..7103bfa421a 100644 --- a/apps/sim/lib/core/utils/browser-storage.ts +++ b/apps/sim/lib/core/utils/browser-storage.ts @@ -362,22 +362,27 @@ export class MothershipHandoffStorage { * accumulate — "Add to chat" can fire twice before the route swap completes, * and the second write must not drop the first. * @returns True if stored, false when the workspace is empty or the handoff - * carries neither a message nor a context. + * carries no message, context, or attachment. */ static store(handoff: MothershipHandoff, owner: MothershipHandoffOwner): boolean { const workspaceId = typeof owner === 'string' ? owner : undefined const organizationId = typeof owner === 'string' ? undefined : owner.organizationId const message = handoff.message?.trim() + const hasAttachments = Boolean(handoff.fileAttachments?.length) const contexts = handoff.contexts ?? [] - if (!(workspaceId || organizationId) || (!message && contexts.length === 0)) { + if ( + !(workspaceId || organizationId) || + (!message && !hasAttachments && contexts.length === 0) + ) { return false } return BrowserStorage.setItem(MothershipHandoffStorage.KEY, { - ...(message ? { message } : {}), - contexts: message - ? contexts - : [...MothershipHandoffStorage.pendingContexts(owner), ...contexts], + ...(message || hasAttachments ? { message: message ?? '' } : {}), + contexts: + message || hasAttachments + ? contexts + : [...MothershipHandoffStorage.pendingContexts(owner), ...contexts], ...(handoff.fileAttachments?.length ? { fileAttachments: handoff.fileAttachments } : {}), ...(handoff.resumeUserMessageId ? { resumeUserMessageId: handoff.resumeUserMessageId } : {}), ...(handoff.requestMode ? { requestMode: handoff.requestMode } : {}), @@ -398,7 +403,13 @@ export class MothershipHandoffStorage { */ private static pendingContexts(owner: MothershipHandoffOwner): ChatContext[] { const data = BrowserStorage.getItem(MothershipHandoffStorage.KEY, null) - if (!data || data.message || !MothershipHandoffStorage.belongsTo(data, owner)) return [] + if ( + !data || + data.message || + data.fileAttachments?.length || + !MothershipHandoffStorage.belongsTo(data, owner) + ) + return [] if (!data.timestamp || Date.now() - data.timestamp > MothershipHandoffStorage.MAX_AGE_MS) { return [] } @@ -433,10 +444,11 @@ export class MothershipHandoffStorage { MothershipHandoffStorage.clear() const contexts = Array.isArray(data.contexts) ? data.contexts : [] + const hasAttachments = Array.isArray(data.fileAttachments) && data.fileAttachments.length > 0 if ( !(data.workspaceId || data.organizationId) || Boolean(data.workspaceId && data.organizationId) || - (!data.message && contexts.length === 0) || + (!data.message && !hasAttachments && contexts.length === 0) || !data.timestamp || Date.now() - data.timestamp > maxAge ) { @@ -447,7 +459,7 @@ export class MothershipHandoffStorage { if (!assistantSearch.success) return null return { - ...(data.message ? { message: data.message } : {}), + ...(data.message || hasAttachments ? { message: data.message ?? '' } : {}), contexts, ...(data.requestMode === 'assistant' ? { requestMode: 'assistant' as const } : {}), ...(data.assistantSearch ? { assistantSearch: assistantSearch.data } : {}), diff --git a/apps/sim/lib/mothership/events.ts b/apps/sim/lib/mothership/events.ts index 1ee0b53150c..0d3bdd13d65 100644 --- a/apps/sim/lib/mothership/events.ts +++ b/apps/sim/lib/mothership/events.ts @@ -61,7 +61,7 @@ export function sendMothershipMessage( assistantSearch?: WorkspaceSearchFilters ): boolean { const trimmed = message.trim() - if (!trimmed) { + if (!trimmed && !fileAttachments?.length) { logger.warn('sendMothershipMessage called with empty message') return false } diff --git a/apps/sim/lib/uploads/client/admission.ts b/apps/sim/lib/uploads/client/admission.ts index 670a570a2fd..489323c1c2a 100644 --- a/apps/sim/lib/uploads/client/admission.ts +++ b/apps/sim/lib/uploads/client/admission.ts @@ -34,6 +34,7 @@ interface UploadAdmissionFile { interface MultiFileUploadAdmissionOptions { existingFiles?: ArrayLike + maxFiles?: number maxFileBytes?: number maxTotalBytes?: number } @@ -48,9 +49,13 @@ export function assertMultiFileUploadAdmission( options: MultiFileUploadAdmissionOptions = {} ): void { const existingFiles = options.existingFiles + const maxFiles = options.maxFiles ?? MULTI_FILE_UPLOAD_MAX_FILES const maxFileBytes = options.maxFileBytes ?? MULTI_FILE_UPLOAD_MAX_FILE_BYTES const maxTotalBytes = options.maxTotalBytes ?? MULTI_FILE_UPLOAD_MAX_TOTAL_FILE_EQUIVALENTS * maxFileBytes + if (!Number.isSafeInteger(maxFiles) || maxFiles < 1) { + throw new Error('Invalid upload file count limit') + } if (!Number.isSafeInteger(maxFileBytes) || maxFileBytes < 1) { throw new Error('Invalid per-file upload limit') } @@ -59,9 +64,9 @@ export function assertMultiFileUploadAdmission( } const existingCount = existingFiles?.length ?? 0 const totalCount = existingCount + files.length - if (totalCount > MULTI_FILE_UPLOAD_MAX_FILES) { + if (totalCount > maxFiles) { throw new MultiFileUploadAdmissionError( - `Select up to ${MULTI_FILE_UPLOAD_MAX_FILES} files at a time.`, + `Select up to ${maxFiles} files at a time.`, 'UPLOAD_FILE_COUNT_EXCEEDED' ) } diff --git a/apps/sim/lib/uploads/client/session-upload.ts b/apps/sim/lib/uploads/client/session-upload.ts index 55d1a7466f6..1411a7bec50 100644 --- a/apps/sim/lib/uploads/client/session-upload.ts +++ b/apps/sim/lib/uploads/client/session-upload.ts @@ -39,7 +39,8 @@ type InternalUploadContext = | { purpose: 'workspace_file'; workspaceId: string; folderId?: string | null } | { purpose: 'profile_picture' } | { purpose: 'workspace_logo'; workspaceId: string } - | { purpose: 'mothership_attachment'; workspaceId: string } + | { purpose: 'mothership_attachment'; workspaceId: string; organizationId?: never } + | { purpose: 'mothership_attachment'; organizationId: string; workspaceId?: never } | { purpose: 'execution_attachment' workspaceId: string @@ -162,12 +163,19 @@ function internalUploadBody(params: UploadInternalFileSessionParams): CreateInte case 'profile_picture': return { purpose: params.purpose, ...fileFields } case 'workspace_logo': - case 'mothership_attachment': return { purpose: params.purpose, workspaceId: params.workspaceId, ...fileFields, } + case 'mothership_attachment': + return { + purpose: params.purpose, + ...(params.organizationId + ? { organizationId: params.organizationId } + : { workspaceId: params.workspaceId }), + ...fileFields, + } case 'execution_attachment': return { purpose: params.purpose, diff --git a/apps/sim/lib/uploads/contexts/organization-assistant/application.test.ts b/apps/sim/lib/uploads/contexts/organization-assistant/application.test.ts new file mode 100644 index 00000000000..dca45cbf243 --- /dev/null +++ b/apps/sim/lib/uploads/contexts/organization-assistant/application.test.ts @@ -0,0 +1,226 @@ +/** @vitest-environment node */ +import { dbChainMockFns, resetDbChainMock } from '@sim/testing' +import sharp from 'sharp' +import { beforeAll, beforeEach, describe, expect, it, vi } from 'vitest' + +const mocks = vi.hoisted(() => ({ download: vi.fn(), config: vi.fn(), create: vi.fn() })) +vi.mock('@/lib/uploads/core/storage-service', () => ({ downloadFile: mocks.download })) +vi.mock('@/lib/uploads/upload-session/service', () => ({ createUploadSession: mocks.create })) +vi.mock('@/lib/permission-groups/resolve.server', () => ({ + getUserPermissionConfigForOrganization: mocks.config, +})) +vi.mock('@/lib/uploads/config', () => ({ getServeStoragePrefix: () => 's3' })) + +import { + authorizeOrganizationAttachmentControl, + createOrganizationAssistantAttachment, + finalizeOrganizationAssistantAttachment, + readOrganizationAssistantImage, +} from '@/lib/uploads/contexts/organization-assistant/application' +import { ASSISTANT_IMAGE_MAX_BYTES } from '@/lib/uploads/shared/assistant-images' +import type { UploadSessionRecord } from '@/lib/uploads/upload-session/service' + +const principal = { kind: 'session', userId: 'user-1', sessionId: 'session-1' } as const +const key = 'assistant/org-1/user-1/upload-1/image.png' +const session: UploadSessionRecord = { + id: 'upload-1', + purpose: 'mothership_attachment', + workspaceId: null, + userId: 'user-1', + metadata: { + organizationAttachment: { organizationId: 'org-1', userId: 'user-1', sessionId: 'session-1' }, + }, + finalKey: key, + storageKey: key, + fileName: 'image.png', + contentType: 'image/png', + fileSize: 100, + storageContext: 'mothership', + storageProvider: 's3', + status: 'completed', + method: 'put', + knowledgeBaseId: null, + workflowId: null, + executionId: null, + providerUploadId: null, + providerObjectVersion: 'v1', + partSize: null, + partCount: null, + uploadToken: '', + createdAt: new Date(), + expiresAt: new Date(), + completedFileId: null, + error: null, + completedAt: new Date(), + updatedAt: new Date(), +} +let png: Buffer +beforeAll(async () => { + png = await sharp({ create: { width: 4, height: 4, channels: 3, background: '#ff0000' } }) + .png() + .toBuffer() +}) +beforeEach(() => { + vi.clearAllMocks() + resetDbChainMock() + mocks.config.mockResolvedValue(null) + mocks.download.mockResolvedValue(png) + dbChainMockFns.limit.mockResolvedValue([{ role: 'member' }]) +}) + +function read(overrides: Partial[0]> = {}) { + return readOrganizationAssistantImage({ principal, organizationId: 'org-1', key, ...overrides }) +} + +describe('private organization Assistant images', () => { + it('creates uploads as the actual current member with no workspace fallback', async () => { + await createOrganizationAssistantAttachment(principal, { + organizationId: 'org-1', + name: 'image.png', + contentType: 'image/png', + size: 100, + localOrigin: 'http://localhost', + }) + expect(mocks.create).toHaveBeenCalledWith( + expect.objectContaining({ + principal, + userId: 'user-1', + organizationId: 'org-1', + purpose: 'mothership_attachment', + }) + ) + expect(mocks.create.mock.calls[0][0]).not.toHaveProperty('workspaceId') + }) + + it('rejects removed members before creating an upload', async () => { + dbChainMockFns.limit.mockResolvedValue([]) + await expect( + createOrganizationAssistantAttachment(principal, { + organizationId: 'org-1', + name: 'image.png', + contentType: 'image/png', + size: 100, + localOrigin: 'http://localhost', + }) + ).rejects.toMatchObject({ code: 'not_found' }) + expect(mocks.create).not.toHaveBeenCalled() + }) + + it('reads canonical completed uploads after a new login and emits bounded decoded bytes', async () => { + dbChainMockFns.limit.mockResolvedValueOnce([session]) + const signal = new AbortController().signal + const image = await read({ principal: { ...principal, sessionId: 'new-session' }, signal }) + expect(image).toMatchObject({ + id: 'upload-1', + key, + name: 'image.png', + contentType: 'image/webp', + }) + expect((await sharp(image.buffer).metadata()).format).toBe('webp') + expect(mocks.download).toHaveBeenCalledWith({ + key, + context: 'mothership', + maxBytes: ASSISTANT_IMAGE_MAX_BYTES, + signal, + }) + }) + + it.each([ + { key: 'https://example.com/image.png' }, + { key: 'assistant/org-1/user-1/../image.png' }, + { principal: { kind: 'personal_api_key', userId: 'user-1', keyId: 'key-1' } as const }, + ])('rejects invalid references or non-session callers before loading', async (input) => { + await expect(read(input)).rejects.toMatchObject({ code: 'not_found' }) + expect(dbChainMockFns.limit).not.toHaveBeenCalled() + expect(mocks.download).not.toHaveBeenCalled() + }) + + it.each([ + { organizationId: 'other-org' }, + { principal: { ...principal, userId: 'other-user' } }, + { key: 'assistant/other-org/user-1/upload-1/image.png' }, + ])('rejects a mismatched asserted owner', async (input) => { + dbChainMockFns.limit.mockResolvedValueOnce([session]) + await expect(read(input)).rejects.toMatchObject({ code: 'not_found' }) + expect(mocks.download).not.toHaveBeenCalled() + }) + + it('refuses absent, incomplete, or purged records', async () => { + dbChainMockFns.limit.mockResolvedValueOnce([]) + await expect(read()).rejects.toMatchObject({ code: 'not_found' }) + expect(mocks.download).not.toHaveBeenCalled() + }) + + it('rechecks membership for every preview/model read', async () => { + dbChainMockFns.limit.mockResolvedValueOnce([session]).mockResolvedValueOnce([]) + await expect(read()).rejects.toMatchObject({ code: 'not_found' }) + expect(mocks.download).not.toHaveBeenCalled() + }) + + it('rejects missing immutable scope metadata', async () => { + dbChainMockFns.limit.mockResolvedValueOnce([{ ...session, metadata: {} }]) + await expect(read()).rejects.toMatchObject({ code: 'not_found' }) + expect(mocks.download).not.toHaveBeenCalled() + }) + + it('refuses metadata above the byte cap without downloading', async () => { + dbChainMockFns.limit.mockResolvedValueOnce([ + { ...session, fileSize: ASSISTANT_IMAGE_MAX_BYTES + 1 }, + ]) + await expect(read()).rejects.toMatchObject({ code: 'payload_too_large' }) + expect(mocks.download).not.toHaveBeenCalled() + }) + + it.each([ + '', + '', + ])('rejects active content with a forged image MIME', async (content) => { + dbChainMockFns.limit.mockResolvedValueOnce([session]) + mocks.download.mockResolvedValue(Buffer.from(content)) + await expect(read()).rejects.toMatchObject({ code: 'validation' }) + }) + + it('propagates storage infrastructure failures unchanged', async () => { + const error = new Error('storage unavailable') + dbChainMockFns.limit.mockResolvedValueOnce([session]) + mocks.download.mockRejectedValue(error) + await expect(read()).rejects.toBe(error) + }) + + it('rejects compressed images above the 25 megapixel decode budget', async () => { + const largePng = await sharp({ + create: { width: 5001, height: 5000, channels: 3, background: '#000' }, + }) + .png() + .toBuffer() + expect(largePng.length).toBeLessThan(ASSISTANT_IMAGE_MAX_BYTES) + dbChainMockFns.limit.mockResolvedValueOnce([session]) + mocks.download.mockResolvedValue(largePng) + await expect(read()).rejects.toMatchObject({ code: 'validation', cause: expect.any(Error) }) + }) + + it('binds upload controls to the exact creating session', async () => { + await expect( + authorizeOrganizationAttachmentControl({ ...principal, sessionId: 'other-session' }, session) + ).rejects.toMatchObject({ code: 'not_found' }) + expect(dbChainMockFns.limit).not.toHaveBeenCalled() + }) + + it('reauthorizes finalization after decoding before returning an attachment', async () => { + dbChainMockFns.limit.mockResolvedValueOnce([{ role: 'member' }]).mockResolvedValueOnce([]) + await expect(finalizeOrganizationAssistantAttachment(principal, session)).rejects.toMatchObject( + { code: 'not_found' } + ) + expect(mocks.download).toHaveBeenCalledTimes(1) + }) + + it('returns the same durable metadata on completion replay', async () => { + const first = await finalizeOrganizationAssistantAttachment(principal, session) + const second = await finalizeOrganizationAssistantAttachment(principal, session) + expect(second).toEqual(first) + expect(first).toMatchObject({ + key, + path: `/api/files/serve/s3/${encodeURIComponent(key)}?context=mothership`, + }) + }) +}) diff --git a/apps/sim/lib/uploads/contexts/organization-assistant/application.ts b/apps/sim/lib/uploads/contexts/organization-assistant/application.ts new file mode 100644 index 00000000000..ea894123634 --- /dev/null +++ b/apps/sim/lib/uploads/contexts/organization-assistant/application.ts @@ -0,0 +1,181 @@ +import type { Principal } from '@sim/auth/principal' +import { db } from '@sim/db' +import { uploadSession } from '@sim/db/schema' +import { and, eq, isNull } from 'drizzle-orm' +import sharp from 'sharp' +import { authorizeOrganizationOperation } from '@/lib/core/application/organization-authorization' +import { defineOrganizationOperation } from '@/lib/core/application/organization-operation' +import { OrchestrationError } from '@/lib/core/orchestration/types' +import { getServeStoragePrefix } from '@/lib/uploads/config' +import { + assertOrganizationAttachmentControlBinding, + organizationAttachmentBinding, +} from '@/lib/uploads/contexts/organization-assistant/binding' +import { downloadFile } from '@/lib/uploads/core/storage-service' +import { + ASSISTANT_IMAGE_MAX_BYTES, + isAssistantImageType, +} from '@/lib/uploads/shared/assistant-images' +import { createUploadSession, type UploadSessionRecord } from '@/lib/uploads/upload-session/service' + +const organizationAttachmentOperation = defineOrganizationOperation({ + id: 'organization.assistant.attachments.use', + minimumRole: 'member', + principalKinds: ['session'], + capability: 'copilot.use', +}) + +const MAX_ASSISTANT_IMAGE_PIXELS = 25_000_000 + +export interface CreateOrganizationAssistantAttachmentInput { + organizationId: string + name: string + contentType: string + size: number + localOrigin: string +} + +export async function createOrganizationAssistantAttachment( + principal: Principal, + input: CreateOrganizationAssistantAttachmentInput +) { + const context = await authorizeOrganizationOperation( + principal, + organizationAttachmentOperation, + input + ) + return createUploadSession({ + purpose: 'mothership_attachment', + principal, + organizationId: context.organizationId, + userId: context.userId, + fileName: input.name, + contentType: input.contentType, + fileSize: input.size, + localOrigin: input.localOrigin, + }) +} + +export async function authorizeOrganizationAttachmentControl( + principal: Principal, + session: UploadSessionRecord +): Promise { + const binding = assertOrganizationAttachmentControlBinding(session, principal) + await authorizeOrganizationOperation(principal, organizationAttachmentOperation, binding) +} + +/** A bounded decode removes active content, metadata, and animation before preview or model use. */ +async function readImageBytes(key: string, contentType: string, signal?: AbortSignal) { + if (!isAssistantImageType(contentType)) + throw new OrchestrationError('validation', 'Unsupported image type') + const buffer = await downloadFile({ + key, + context: 'mothership', + maxBytes: ASSISTANT_IMAGE_MAX_BYTES, + signal, + }) + try { + const image = sharp(buffer, { limitInputPixels: MAX_ASSISTANT_IMAGE_PIXELS, pages: 1 }) + const metadata = await image.metadata() + if (!metadata.format || !['jpeg', 'png', 'gif', 'webp'].includes(metadata.format)) { + throw new OrchestrationError( + 'validation', + 'Attachment must contain a PNG, JPEG, GIF, or WebP image' + ) + } + const normalized = await image + .rotate() + .resize(1568, 1568, { fit: 'inside', withoutEnlargement: true }) + .webp({ quality: 85 }) + .toBuffer() + if (normalized.length > ASSISTANT_IMAGE_MAX_BYTES) + throw new OrchestrationError('payload_too_large', 'Image exceeds the 5 MB limit') + return normalized + } catch (cause) { + if (cause instanceof OrchestrationError) throw cause + const error = new OrchestrationError('validation', 'Attachment is not a valid supported image') + error.cause = cause + throw error + } +} + +export async function finalizeOrganizationAssistantAttachment( + principal: Principal, + session: UploadSessionRecord +) { + await authorizeOrganizationAttachmentControl(principal, session) + await readImageBytes(session.finalKey, session.contentType) + await authorizeOrganizationAttachmentControl(principal, session) + return { + path: `/api/files/serve/${getServeStoragePrefix()}/${encodeURIComponent(session.finalKey)}?context=mothership`, + key: session.finalKey, + name: session.fileName, + size: session.fileSize, + type: session.contentType, + } +} + +/** Resolves only completed images owned by the current user and their current organization. */ +export async function readOrganizationAssistantImage(input: { + principal: Principal + organizationId?: string + key: string + signal?: AbortSignal +}) { + if (input.principal.kind !== 'session') + throw new OrchestrationError('not_found', 'Attachment not found') + const keyParts = input.key.split('/') + if ( + keyParts.length !== 5 || + keyParts[0] !== 'assistant' || + keyParts.some((part) => !part || part === '.' || part === '..') + ) { + throw new OrchestrationError('not_found', 'Attachment not found') + } + const [session] = await db + .select({ + id: uploadSession.id, + purpose: uploadSession.purpose, + workspaceId: uploadSession.workspaceId, + userId: uploadSession.userId, + metadata: uploadSession.metadata, + fileName: uploadSession.fileName, + contentType: uploadSession.contentType, + fileSize: uploadSession.fileSize, + finalKey: uploadSession.finalKey, + }) + .from(uploadSession) + .where( + and( + eq(uploadSession.id, keyParts[3]), + eq(uploadSession.finalKey, input.key), + eq(uploadSession.userId, input.principal.userId), + eq(uploadSession.purpose, 'mothership_attachment'), + eq(uploadSession.status, 'completed'), + isNull(uploadSession.workspaceId) + ) + ) + .limit(1) + if (!session) throw new OrchestrationError('not_found', 'Attachment not found') + const binding = organizationAttachmentBinding(session) + if ( + session.userId !== input.principal.userId || + keyParts[1] !== binding.organizationId || + keyParts[2] !== binding.userId || + (input.organizationId && input.organizationId !== binding.organizationId) + ) { + throw new OrchestrationError('not_found', 'Attachment not found') + } + await authorizeOrganizationOperation(input.principal, organizationAttachmentOperation, binding) + if (session.fileSize > ASSISTANT_IMAGE_MAX_BYTES) + throw new OrchestrationError('payload_too_large', 'Image exceeds the 5 MB limit') + const buffer = await readImageBytes(session.finalKey, session.contentType, input.signal) + return { + id: session.id, + key: session.finalKey, + name: session.fileName, + size: buffer.length, + contentType: 'image/webp', + buffer, + } +} diff --git a/apps/sim/lib/uploads/contexts/organization-assistant/binding.ts b/apps/sim/lib/uploads/contexts/organization-assistant/binding.ts new file mode 100644 index 00000000000..df2743c533c --- /dev/null +++ b/apps/sim/lib/uploads/contexts/organization-assistant/binding.ts @@ -0,0 +1,56 @@ +import type { Principal } from '@sim/auth/principal' +import { isRecordLike } from '@sim/utils/object' +import { OrchestrationError } from '@/lib/core/orchestration/types' + +export interface OrganizationAttachmentBinding { + organizationId: string + userId: string + sessionId: string +} + +interface OrganizationAttachmentSession { + purpose: string + workspaceId: string | null + userId: string + metadata: Record +} + +/** Organization attachments remain private to their uploader across new login sessions. */ +export function organizationAttachmentBinding( + session: OrganizationAttachmentSession +): OrganizationAttachmentBinding { + const binding = session.metadata.organizationAttachment + if ( + session.purpose !== 'mothership_attachment' || + session.workspaceId !== null || + !isRecordLike(binding) || + typeof binding.organizationId !== 'string' || + !binding.organizationId || + binding.userId !== session.userId || + typeof binding.sessionId !== 'string' || + !binding.sessionId + ) { + throw new OrchestrationError('not_found', 'Attachment not found') + } + return { + organizationId: binding.organizationId, + userId: session.userId, + sessionId: binding.sessionId, + } +} + +/** A byte-transfer token cannot replace the session that initiated the upload. */ +export function assertOrganizationAttachmentControlBinding( + session: OrganizationAttachmentSession, + principal: Principal +): OrganizationAttachmentBinding { + const binding = organizationAttachmentBinding(session) + if ( + principal.kind !== 'session' || + principal.userId !== binding.userId || + principal.sessionId !== binding.sessionId + ) { + throw new OrchestrationError('not_found', 'Upload session not found') + } + return binding +} diff --git a/apps/sim/lib/uploads/shared/assistant-images.ts b/apps/sim/lib/uploads/shared/assistant-images.ts new file mode 100644 index 00000000000..deae05e9a5d --- /dev/null +++ b/apps/sim/lib/uploads/shared/assistant-images.ts @@ -0,0 +1,15 @@ +/** Inline image limits shared by Assistant upload, preview, and model preparation. */ +export const ASSISTANT_IMAGE_MAX_BYTES = 5 * 1024 * 1024 +export const ASSISTANT_IMAGE_MAX_COUNT = 5 +export const ASSISTANT_IMAGE_MAX_TOTAL_BYTES = ASSISTANT_IMAGE_MAX_BYTES * ASSISTANT_IMAGE_MAX_COUNT +export const ASSISTANT_IMAGE_CONTENT_TYPES = [ + 'image/jpeg', + 'image/png', + 'image/gif', + 'image/webp', +] as const +export const ASSISTANT_IMAGE_ACCEPT_ATTRIBUTE = ASSISTANT_IMAGE_CONTENT_TYPES.join(',') + +export function isAssistantImageType(contentType: string): boolean { + return ASSISTANT_IMAGE_CONTENT_TYPES.some((type) => type === contentType) +} diff --git a/apps/sim/lib/uploads/upload-session/application.test.ts b/apps/sim/lib/uploads/upload-session/application.test.ts index 70ae6b01c61..52f9cd31ea6 100644 --- a/apps/sim/lib/uploads/upload-session/application.test.ts +++ b/apps/sim/lib/uploads/upload-session/application.test.ts @@ -12,6 +12,12 @@ const mocks = vi.hoisted(() => ({ getPrincipalSession: vi.fn(), reauthorizeWorkspacePurpose: vi.fn(), getWorkspaceFile: vi.fn(), + authorizeOrganizationAttachment: vi.fn(), +})) + +vi.mock('@/lib/uploads/contexts/organization-assistant/application', () => ({ + authorizeOrganizationAttachmentControl: mocks.authorizeOrganizationAttachment, + createOrganizationAssistantAttachment: vi.fn(), })) vi.mock('@/lib/uploads/contexts/workspace', () => ({ @@ -43,7 +49,9 @@ vi.mock('@/app/api/files/uploads/purposes', () => ({ })) import { + abortInternalUploadSession, completeInternalUploadSession, + issueInternalUploadPartUrls, readWorkspaceUploadSession, } from '@/lib/uploads/upload-session/application' import type { UploadSessionRecord } from '@/lib/uploads/upload-session/service' @@ -58,6 +66,7 @@ const actor = { id: 'user-1', name: 'Ada', email: 'ada@example.com' } describe('upload session application', () => { beforeEach(() => { vi.clearAllMocks() + mocks.authorizeOrganizationAttachment.mockResolvedValue(undefined) const session = workspaceUploadSession() mocks.getOwnedSession.mockResolvedValue(session) mocks.finalizePurpose.mockResolvedValue({ @@ -91,6 +100,48 @@ describe('upload session application', () => { ) }) + it.each(['complete', 'abort', 'parts'] as const)( + 'rechecks organization membership before the %s control leg', + async (control) => { + const session = { + ...workspaceUploadSession(), + purpose: 'mothership_attachment' as const, + workspaceId: null, + } + mocks.getOwnedSession.mockResolvedValue(session) + const request = new NextRequest('http://localhost/api/files/uploads/upload-1/complete', { + headers: { host: 'localhost' }, + }) + const input = { uploadId: 'upload-1', uploadToken: 'upload-token', partNumbers: [1] } + if (control === 'complete') await completeInternalUploadSession(principal, input, request) + else if (control === 'abort') await abortInternalUploadSession(principal, input) + else await issueInternalUploadPartUrls(principal, input, request) + expect(mocks.assertAuthBinding).toHaveBeenCalledWith(session, principal) + expect(mocks.authorizeOrganizationAttachment).toHaveBeenCalledWith(principal, session) + expect(mocks.reauthorizeWorkspacePurpose).not.toHaveBeenCalled() + } + ) + + it('does not finalize when organization access is revoked after the session is claimed', async () => { + const session = { + ...workspaceUploadSession(), + purpose: 'mothership_attachment' as const, + workspaceId: null, + } + mocks.getOwnedSession.mockResolvedValue(session) + mocks.authorizeOrganizationAttachment + .mockResolvedValueOnce(undefined) + .mockRejectedValueOnce(new Error('Organization not found')) + await expect( + completeInternalUploadSession( + principal, + { uploadId: 'upload-1', uploadToken: 'upload-token' }, + new NextRequest('http://localhost/api/files/uploads/upload-1/complete') + ) + ).rejects.toThrow('Organization not found') + expect(mocks.finalizePurpose).not.toHaveBeenCalled() + }) + /** * The read is a control leg, so it re-authorizes the caller's present * workspace permission rather than trusting the session lookup alone. @@ -119,7 +170,11 @@ describe('upload session application', () => { * had created. */ it('returns the registered file once the session has completed', async () => { - const completed = { ...workspaceUploadSession(), status: 'completed' as const, completedFileId: 'file-1' } + const completed = { + ...workspaceUploadSession(), + status: 'completed' as const, + completedFileId: 'file-1', + } mocks.getOwnedSession.mockResolvedValue(completed) mocks.getPrincipalSession.mockResolvedValue(completed) mocks.getWorkspaceFile.mockResolvedValue({ id: 'file-1', name: 'file.txt' }) @@ -154,7 +209,11 @@ describe('upload session application', () => { * there was nothing. A failed read is not the same answer as no file. */ it('surfaces a failed file read instead of reporting the upload fileless', async () => { - const completed = { ...workspaceUploadSession(), status: 'completed' as const, completedFileId: 'file-1' } + const completed = { + ...workspaceUploadSession(), + status: 'completed' as const, + completedFileId: 'file-1', + } mocks.getOwnedSession.mockResolvedValue(completed) mocks.getPrincipalSession.mockResolvedValue(completed) mocks.getWorkspaceFile.mockRejectedValue(new Error('connection terminated')) @@ -169,7 +228,11 @@ describe('upload session application', () => { }) it('reads the completed file with throwOnError so a fault cannot read as absence', async () => { - const completed = { ...workspaceUploadSession(), status: 'completed' as const, completedFileId: 'file-1' } + const completed = { + ...workspaceUploadSession(), + status: 'completed' as const, + completedFileId: 'file-1', + } mocks.getOwnedSession.mockResolvedValue(completed) mocks.getPrincipalSession.mockResolvedValue(completed) mocks.getWorkspaceFile.mockResolvedValue({ id: 'file-1', name: 'file.txt' }) @@ -187,7 +250,11 @@ describe('upload session application', () => { /** A completed session whose file was since deleted has nothing to address. */ it('answers null when the completed file is gone', async () => { - const gone = { ...workspaceUploadSession(), status: 'completed' as const, completedFileId: 'file-1' } + const gone = { + ...workspaceUploadSession(), + status: 'completed' as const, + completedFileId: 'file-1', + } mocks.getOwnedSession.mockResolvedValue(gone) mocks.getPrincipalSession.mockResolvedValue(gone) mocks.getWorkspaceFile.mockResolvedValue(null) diff --git a/apps/sim/lib/uploads/upload-session/application.ts b/apps/sim/lib/uploads/upload-session/application.ts index 61929b1dd77..b7060d8d7b1 100644 --- a/apps/sim/lib/uploads/upload-session/application.ts +++ b/apps/sim/lib/uploads/upload-session/application.ts @@ -3,6 +3,10 @@ import type { CreateInternalFileUploadBody } from '@/lib/api/contracts/upload-se import type { OrchestrationRequestContext } from '@/lib/core/orchestration/types' import { OrchestrationError } from '@/lib/core/orchestration/types' import { loadActiveFolderPathIndex, resolveFolderPathFromIndex } from '@/lib/folders/queries' +import { + authorizeOrganizationAttachmentControl, + createOrganizationAssistantAttachment, +} from '@/lib/uploads/contexts/organization-assistant/application' import { getWorkspaceFile, type WorkspaceFileRecord } from '@/lib/uploads/contexts/workspace' import { abortUploadSession, @@ -82,6 +86,13 @@ export async function createInternalPurposeUploadSession( body: CreateInternalFileUploadBody, request: OrchestrationRequestContext ): Promise>> { + if (body.purpose === 'mothership_attachment' && body.organizationId) { + return createOrganizationAssistantAttachment(principal, { + ...body, + organizationId: body.organizationId, + localOrigin: requestOrigin(request), + }) + } return createPurposeUploadSession(principal, body, requestOrigin(request)) } @@ -97,6 +108,9 @@ export async function loadAuthorizedInternalUploadSession( userId: principalUserId(principal), }) if (session.purpose === 'workspace_file') assertUploadSessionAuthBinding(session, principal) + if (session.purpose === 'mothership_attachment' && session.workspaceId === null) { + assertUploadSessionAuthBinding(session, principal) + } return session } @@ -108,6 +122,8 @@ export async function issueInternalUploadPartUrls( const session = await loadAuthorizedInternalUploadSession(principal, input) if (session.purpose === 'workspace_file') { await reauthorizeWorkspaceUploadPurpose(principal, session, fileOperations.uploadParts) + } else if (session.purpose === 'mothership_attachment' && session.workspaceId === null) { + await authorizeOrganizationAttachmentControl(principal, session) } else { await reauthorizeUploadPurpose(principalUserId(principal), session) } @@ -127,6 +143,8 @@ export async function abortInternalUploadSession( const session = await loadAuthorizedInternalUploadSession(principal, input) if (session.purpose === 'workspace_file') { await reauthorizeWorkspaceUploadPurpose(principal, session, fileOperations.uploadCancel) + } else if (session.purpose === 'mothership_attachment' && session.workspaceId === null) { + await authorizeOrganizationAttachmentControl(principal, session) } else { await reauthorizeUploadPurpose(principalUserId(principal), session) } @@ -146,6 +164,8 @@ export async function completeInternalUploadSession( const authorize = async (claimed: UploadSessionRecord) => { if (claimed.purpose === 'workspace_file') { await reauthorizeWorkspaceUploadPurpose(principal, claimed, fileOperations.uploadComplete) + } else if (claimed.purpose === 'mothership_attachment' && claimed.workspaceId === null) { + await authorizeOrganizationAttachmentControl(principal, claimed) } else { await reauthorizeUploadPurpose(principalUserId(principal), claimed) } diff --git a/apps/sim/lib/uploads/upload-session/service.test.ts b/apps/sim/lib/uploads/upload-session/service.test.ts index 558b1fca924..d1712db1f66 100644 --- a/apps/sim/lib/uploads/upload-session/service.test.ts +++ b/apps/sim/lib/uploads/upload-session/service.test.ts @@ -153,6 +153,64 @@ describe('upload sessions', () => { }) }) + it('binds organization images to the creating session and stores them without a workspace', async () => { + dbChainMockFns.returning.mockResolvedValueOnce([ + uploadRow({ + purpose: 'mothership_attachment', + workspaceId: null, + storageContext: 'mothership', + finalKey: 'assistant/org-1/user-1/upload-1/image.png', + contentType: 'image/png', + }), + ]) + await createUploadSession({ + id: 'upload-1', + userId: 'user-1', + purpose: 'mothership_attachment', + organizationId: 'org-1', + principal: { kind: 'session', userId: 'user-1', sessionId: 'session-1' }, + fileName: 'image.png', + contentType: 'image/png', + fileSize: 100, + metadata: { organizationAttachment: { organizationId: 'forged' } }, + }) + expect(dbChainMockFns.values).toHaveBeenCalledWith( + expect.objectContaining({ + workspaceId: null, + finalKey: 'assistant/org-1/user-1/upload-1/image.png', + metadata: { + organizationAttachment: { + organizationId: 'org-1', + userId: 'user-1', + sessionId: 'session-1', + }, + }, + }) + ) + expect(mockCreatePutTransfer).toHaveBeenCalledWith( + expect.objectContaining({ context: 'mothership', fileSize: 100 }) + ) + }) + + it.each([ + { contentType: 'text/html', fileSize: 100 }, + { contentType: 'image/png', fileSize: 5 * 1024 * 1024 + 1 }, + ])('rejects invalid organization images before storage initialization', async (file) => { + await expect( + createUploadSession({ + id: 'upload-1', + userId: 'user-1', + purpose: 'mothership_attachment', + organizationId: 'org-1', + principal: { kind: 'session', userId: 'user-1', sessionId: 'session-1' }, + fileName: 'image.png', + ...file, + }) + ).rejects.toThrow('Assistant attachments must be') + expect(mockCreatePutTransfer).not.toHaveBeenCalled() + expect(dbChainMockFns.values).not.toHaveBeenCalled() + }) + // Local storage stores an object's metadata sidecar beside it, under the // object's own name, so the whole key + suffix must fit one path component. // Three purposes built their key by hand and admitted a 255-character name @@ -1031,6 +1089,87 @@ describe('upload sessions', () => { expect.objectContaining({ key: FINAL_KEY, version: 'version-1' }) ) }) + + it('reclaims a completed Assistant image left behind by account deletion', async () => { + const image = uploadRow({ + purpose: 'mothership_attachment', + workspaceId: null, + storageContext: 'mothership', + finalKey: 'assistant/org-1/user-1/upload-1/image.png', + status: 'completed', + completedAt: new Date(Date.now() - 8 * 24 * 60 * 60 * 1000), + }) + queueTableRows(schemaMock.uploadSession, []) + queueTableRows(schemaMock.uploadSession, [image]) + mockHeadObject.mockResolvedValue(providerObject(sessionRecord(image), 'version-1')) + dbChainMockFns.returning + .mockResolvedValueOnce([image]) + .mockResolvedValueOnce([{ id: image.id }]) + + await expect(cleanupExpiredUploadSessions()).resolves.toEqual({ + expired: 0, + failed: 0, + purged: 1, + }) + expect(mockDeleteObjectVersion).toHaveBeenCalledWith({ + provider: 's3', + key: image.finalKey, + context: 'mothership', + version: 'version-1', + }) + expect(mockDeleteObjectVersion.mock.invocationCallOrder[0]).toBeLessThan( + dbChainMockFns.delete.mock.invocationCallOrder[0] + ) + }) + + it('retains orphan image ownership records when object deletion fails so cleanup can retry', async () => { + const image = uploadRow({ + purpose: 'mothership_attachment', + workspaceId: null, + storageContext: 'mothership', + status: 'completed', + completedAt: new Date(Date.now() - 8 * 24 * 60 * 60 * 1000), + }) + queueTableRows(schemaMock.uploadSession, []) + queueTableRows(schemaMock.uploadSession, [image]) + mockHeadObject.mockResolvedValue(providerObject(sessionRecord(image), 'version-1')) + mockDeleteObjectVersion.mockRejectedValueOnce(new Error('Storage unavailable')) + dbChainMockFns.returning.mockResolvedValueOnce([image]) + + await expect(cleanupExpiredUploadSessions()).resolves.toEqual({ + expired: 0, + failed: 1, + purged: 0, + }) + expect(dbChainMockFns.delete).not.toHaveBeenCalled() + expect(dbChainMockFns.set).toHaveBeenLastCalledWith( + expect.objectContaining({ + processingLeaseId: null, + processingLeaseExpiresAt: null, + error: 'Storage unavailable', + }) + ) + }) + + it('purges completed workspace attachment sessions without deleting their registered objects', async () => { + const attachment = uploadRow({ + purpose: 'mothership_attachment', + status: 'completed', + completedAt: new Date(Date.now() - 8 * 24 * 60 * 60 * 1000), + }) + queueTableRows(schemaMock.uploadSession, []) + queueTableRows(schemaMock.uploadSession, [attachment]) + dbChainMockFns.returning + .mockResolvedValueOnce([attachment]) + .mockResolvedValueOnce([{ id: attachment.id }]) + + await expect(cleanupExpiredUploadSessions()).resolves.toEqual({ + expired: 0, + failed: 0, + purged: 1, + }) + expect(mockDeleteObjectVersion).not.toHaveBeenCalled() + }) }) async function createWorkspaceUpload(fileSize: number) { diff --git a/apps/sim/lib/uploads/upload-session/service.ts b/apps/sim/lib/uploads/upload-session/service.ts index 2c9aed76a7c..5838abd8c74 100644 --- a/apps/sim/lib/uploads/upload-session/service.ts +++ b/apps/sim/lib/uploads/upload-session/service.ts @@ -5,13 +5,13 @@ import { requirePrincipalSubjectUserId, } from '@sim/auth/principal' import { db, dbFor } from '@sim/db' -import { uploadSession } from '@sim/db/schema' +import { organization, uploadSession, user } from '@sim/db/schema' import { safeCompare } from '@sim/security/compare' import { sha256Hex } from '@sim/security/hash' import { generateSecureToken } from '@sim/security/tokens' import { getErrorMessage } from '@sim/utils/errors' import { generateId } from '@sim/utils/id' -import { and, asc, eq, inArray, isNull, lt, or } from 'drizzle-orm' +import { and, asc, eq, inArray, isNull, lt, or, sql } from 'drizzle-orm' import { checkStorageQuotaForBillingContext, resolveStorageBillingContext, @@ -19,8 +19,13 @@ import { import { OrchestrationError } from '@/lib/core/orchestration/types' import { generateUniqueExecutionFileKey } from '@/lib/uploads/contexts/execution/utils' import { generateKnowledgeBaseFileKey } from '@/lib/uploads/contexts/knowledge-base/knowledge-base-file-manager' +import { assertOrganizationAttachmentControlBinding } from '@/lib/uploads/contexts/organization-assistant/binding' import { generateWorkspaceFileKey } from '@/lib/uploads/contexts/workspace' import { buildStorageKeySegment } from '@/lib/uploads/core/storage-key' +import { + ASSISTANT_IMAGE_MAX_BYTES, + isAssistantImageType, +} from '@/lib/uploads/shared/assistant-images' import { MAX_KNOWLEDGE_DOCUMENT_FILE_SIZE, MAX_WORKSPACE_FILE_SIZE, @@ -190,6 +195,12 @@ export type CreateUploadSessionParams = CreateUploadSessionBaseParams & } | { purpose: 'profile_picture'; workspaceId?: null } | { purpose: 'workspace_logo' | 'mothership_attachment'; workspaceId: string } + | { + purpose: 'mothership_attachment' + organizationId: string + principal: Principal + workspaceId?: never + } | { purpose: 'execution_attachment' workspaceId: string @@ -206,8 +217,21 @@ export async function createUploadSession( validateFile(params) const id = params.id ?? generateId() const uploadToken = generateSecureToken(32) - const workspaceId = params.purpose === 'profile_picture' ? null : params.workspaceId + const workspaceId = params.purpose === 'profile_picture' ? null : (params.workspaceId ?? null) const metadata = { ...(params.metadata ?? {}) } + if (params.purpose === 'mothership_attachment' && 'organizationId' in params) { + if (params.principal.kind !== 'session' || params.principal.userId !== params.userId) { + throw new UploadSessionError( + 'forbidden', + 'Organization attachments require the uploading session' + ) + } + metadata.organizationAttachment = { + organizationId: params.organizationId, + userId: params.userId, + sessionId: params.principal.sessionId, + } + } if (params.purpose === 'workspace_file' || params.purpose === 'knowledge_document') { if (!workspaceId) throw new Error(`${params.purpose} upload is missing workspaceId`) if (!params.principal) { @@ -500,6 +524,10 @@ export function assertUploadSessionAuthBinding( session: UploadSessionRecord, principal: Principal ): void { + if (session.purpose === 'mothership_attachment' && session.workspaceId === null) { + assertOrganizationAttachmentControlBinding(session, principal) + return + } if (!isPrincipalBoundUploadPurpose(session.purpose)) return const candidate = session.metadata.authBinding if (candidate === undefined) { @@ -913,6 +941,17 @@ export async function cleanupExpiredUploadSessions(): Promise<{ .where( and( inArray(uploadSession.status, ['completed', 'aborted', 'expired']), + /** Keep private images while both their uploader and organization exist. */ + sql`NOT ( + ${uploadSession.status} = 'completed' + AND ${uploadSession.purpose} = 'mothership_attachment' + AND ${uploadSession.workspaceId} IS NULL + AND EXISTS (SELECT 1 FROM ${user} WHERE ${user.id} = ${uploadSession.userId}) + AND EXISTS ( + SELECT 1 FROM ${organization} + WHERE ${organization.id} = ${uploadSession.metadata}->'organizationAttachment'->>'organizationId' + ) + )`, lt(uploadSession.completedAt, terminalCutoff), or( isNull(uploadSession.processingLeaseId), @@ -934,7 +973,11 @@ export async function cleanupExpiredUploadSessions(): Promise<{ candidate.status, cleanupDb ) - if (claimed.status === 'aborted' || claimed.status === 'expired') { + if ( + claimed.status === 'aborted' || + claimed.status === 'expired' || + (claimed.purpose === 'mothership_attachment' && claimed.workspaceId === null) + ) { await deleteOwnedFinalObject(claimed) } else if (claimed.status !== 'completed') { throw new Error(`Invalid terminal upload status ${claimed.status}`) @@ -1202,7 +1245,24 @@ function validateFile(params: CreateUploadSessionParams): void { if (params.fileSize > maximum) { throw new UploadSessionError('validation', `File size exceeds maximum of ${maximum} bytes`) } - if (params.purpose !== 'profile_picture' && !params.workspaceId.trim()) { + const organizationAttachment = + params.purpose === 'mothership_attachment' && 'organizationId' in params + if ( + organizationAttachment && + (!params.organizationId.trim() || + params.fileSize > ASSISTANT_IMAGE_MAX_BYTES || + !isAssistantImageType(params.contentType)) + ) { + throw new UploadSessionError( + 'validation', + 'Assistant attachments must be PNG, JPEG, GIF, or WebP images up to 5 MB' + ) + } + if ( + params.purpose !== 'profile_picture' && + !organizationAttachment && + !params.workspaceId?.trim() + ) { throw new UploadSessionError('validation', 'workspaceId must not be empty') } if (params.purpose === 'knowledge_document' && !params.knowledgeBaseId.trim()) { @@ -1231,7 +1291,10 @@ function requiresStorageQuota(purpose: UploadSessionPurpose): boolean { function isPrincipalBoundUploadPurpose(purpose: UploadSessionPurpose): boolean { return ( - purpose === 'workspace_file' || purpose === 'knowledge_document' || purpose === 'table_import' + purpose === 'workspace_file' || + purpose === 'knowledge_document' || + purpose === 'table_import' || + purpose === 'mothership_attachment' ) } @@ -1266,6 +1329,12 @@ function resolveUploadStorage( finalKey: `workspace-logos/${params.workspaceId}/${buildStorageKeySegment(`${id}-`, params.fileName)}`, } case 'mothership_attachment': + if ('organizationId' in params) { + return { + storageContext: 'mothership', + finalKey: `assistant/${params.organizationId}/${params.userId}/${id}/${buildStorageKeySegment('', params.fileName)}`, + } + } return { storageContext: 'mothership', finalKey: generateWorkspaceFileKey(params.workspaceId, params.fileName), diff --git a/apps/sim/lib/uploads/utils/file-utils.ts b/apps/sim/lib/uploads/utils/file-utils.ts index b00ac1ab7ee..a06539b5611 100644 --- a/apps/sim/lib/uploads/utils/file-utils.ts +++ b/apps/sim/lib/uploads/utils/file-utils.ts @@ -801,6 +801,7 @@ export function tryInferContextFromKey(key: string): StorageContext | null { if (key.startsWith('copilot/')) return 'copilot' if (key.startsWith('execution/')) return 'execution' if (key.startsWith('workspace/')) return 'workspace' + if (key.startsWith('assistant/')) return 'mothership' if (key.startsWith('profile-pictures/')) return 'profile-pictures' if (key.startsWith('og-images/')) return 'og-images' if (key.startsWith('workspace-logos/')) return 'workspace-logos' diff --git a/apps/sim/lib/users/account-deletion-attachments.test.ts b/apps/sim/lib/users/account-deletion-attachments.test.ts new file mode 100644 index 00000000000..5b99873ead4 --- /dev/null +++ b/apps/sim/lib/users/account-deletion-attachments.test.ts @@ -0,0 +1,234 @@ +/** + * @vitest-environment node + */ +import { + dbChainMockFns, + hasMockCondition, + queueTableRows, + resetDbChainMock, + schemaMock, +} from '@sim/testing' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' + +const mocks = vi.hoisted(() => ({ + isSoleOwnerOfPaidOrganization: vi.fn(), + getPersonalSubscription: vi.fn(), + isUsingCloudStorage: vi.fn(), + deleteFiles: vi.fn(), +})) + +vi.mock('@/lib/billing/organizations/membership', () => ({ + isSoleOwnerOfPaidOrganization: mocks.isSoleOwnerOfPaidOrganization, +})) +vi.mock('@/lib/billing/core/plan', () => ({ + getHighestPriorityPersonalSubscription: mocks.getPersonalSubscription, +})) +vi.mock('@/lib/uploads', () => ({ + isUsingCloudStorage: mocks.isUsingCloudStorage, + StorageService: { deleteFiles: mocks.deleteFiles }, +})) +vi.mock('@/lib/workspaces/utils', () => ({ + reassignBilledAccountForUser: vi.fn(async () => ({ unresolved: [] })), + reassignOwnedWorkspacesForUser: vi.fn(async () => ({ unresolved: [] })), +})) +vi.mock('@/lib/table/events', () => ({ appendTableEvent: vi.fn() })) +vi.mock('@/lib/table/rows/executions', () => ({ + cancelPendingMarkersForGovernedSubject: vi.fn(async () => []), +})) + +import { deleteUserAccount } from '@/lib/users/account-deletion' + +const IMAGE_KEY = 'assistant/org-1/user-1/upload-1/photo.png' +const FAILED_IMAGE_KEY = 'assistant/org-2/user-1/upload-2/photo.png' +const NOW = new Date('2026-09-11T12:00:00Z') + +function imageDeletionFilter() { + return dbChainMockFns.where.mock.calls + .map(([condition]) => condition) + .find((condition) => + hasMockCondition( + condition, + (node) => node.type === 'inArray' && node.column === schemaMock.uploadSession.finalKey + ) + ) +} + +describe('account deletion of private organization Assistant images', () => { + beforeEach(() => { + vi.clearAllMocks() + resetDbChainMock() + vi.useFakeTimers() + vi.setSystemTime(NOW) + mocks.isSoleOwnerOfPaidOrganization.mockResolvedValue({ isBlocker: false }) + mocks.getPersonalSubscription.mockResolvedValue(null) + mocks.isUsingCloudStorage.mockReturnValue(true) + mocks.deleteFiles.mockResolvedValue({ deleted: 1, failed: [] }) + }) + + afterEach(() => { + vi.useRealTimers() + }) + + it.each([true, false])( + 'purges image objects and ownership records after deleting an account without workspaces (cloud: %s)', + async (cloudStorage) => { + mocks.isUsingCloudStorage.mockReturnValue(cloudStorage) + queueTableRows(schemaMock.uploadSession, [{ id: 'upload-1', key: IMAGE_KEY }]) + + const plan = await deleteUserAccount('user-1') + + expect(plan.workspacesToDelete).toEqual([]) + expect(mocks.deleteFiles).toHaveBeenCalledWith([IMAGE_KEY], 'mothership') + expect(dbChainMockFns.delete).toHaveBeenCalledWith(schemaMock.uploadSession) + const userDeleteIndex = dbChainMockFns.delete.mock.calls.findIndex( + ([table]) => table === schemaMock.user + ) + const imageDeleteIndex = dbChainMockFns.delete.mock.calls.findIndex( + ([table]) => table === schemaMock.uploadSession + ) + expect(dbChainMockFns.delete.mock.invocationCallOrder[userDeleteIndex]).toBeLessThan( + mocks.deleteFiles.mock.invocationCallOrder[0] + ) + expect(mocks.deleteFiles.mock.invocationCallOrder[0]).toBeLessThan( + dbChainMockFns.delete.mock.invocationCallOrder[imageDeleteIndex] + ) + } + ) + + it('scopes both collection and ownership deletion to this uploader’s completed organization images', async () => { + queueTableRows(schemaMock.uploadSession, [{ id: 'upload-1', key: IMAGE_KEY }]) + + await deleteUserAccount('user-1') + + const imageFilters = dbChainMockFns.where.mock.calls + .map(([condition]) => condition) + .filter((condition) => + hasMockCondition(condition, (node) => node.left === schemaMock.uploadSession.userId) + ) + expect(imageFilters).toHaveLength(2) + for (const filter of imageFilters) { + for (const [column, value] of [ + [schemaMock.uploadSession.userId, 'user-1'], + [schemaMock.uploadSession.purpose, 'mothership_attachment'], + [schemaMock.uploadSession.status, 'completed'], + ]) { + expect( + hasMockCondition( + filter, + (node) => node.type === 'eq' && node.left === column && node.right === value + ) + ).toBe(true) + } + expect( + hasMockCondition( + filter, + (node) => node.type === 'isNull' && node.column === schemaMock.uploadSession.workspaceId + ) + ).toBe(true) + } + }) + + it('retains ownership while an issued upload URL could recreate a purged object', async () => { + queueTableRows(schemaMock.uploadSession, [{ id: 'upload-1', key: IMAGE_KEY }]) + + await deleteUserAccount('user-1') + + expect( + hasMockCondition( + imageDeletionFilter(), + (node) => + node.type === 'lte' && + node.left === schemaMock.uploadSession.expiresAt && + node.right instanceof Date && + node.right.getTime() === NOW.getTime() + ) + ).toBe(true) + }) + + it('retains failed objects’ ownership records for the upload-session sweep', async () => { + queueTableRows(schemaMock.uploadSession, [ + { id: 'upload-1', key: IMAGE_KEY }, + { id: 'upload-2', key: FAILED_IMAGE_KEY }, + ]) + mocks.deleteFiles.mockResolvedValue({ + deleted: 1, + failed: [{ key: FAILED_IMAGE_KEY, error: 'Storage unavailable' }], + }) + + await deleteUserAccount('user-1') + + expect( + hasMockCondition( + imageDeletionFilter(), + (node) => + node.type === 'inArray' && + node.column === schemaMock.uploadSession.finalKey && + Array.isArray(node.values) && + node.values.length === 1 && + node.values[0] === IMAGE_KEY + ) + ).toBe(true) + }) + + it.each(['batch', 'object'])( + 'keeps ownership records when all %s deletions fail', + async (failure) => { + queueTableRows(schemaMock.uploadSession, [{ id: 'upload-1', key: IMAGE_KEY }]) + if (failure === 'batch') { + mocks.deleteFiles.mockRejectedValueOnce(new Error('Storage unavailable')) + } else { + mocks.deleteFiles.mockResolvedValueOnce({ + deleted: 0, + failed: [{ key: IMAGE_KEY, error: 'Storage unavailable' }], + }) + } + + await expect(deleteUserAccount('user-1')).resolves.toMatchObject({ blockers: [] }) + + expect(dbChainMockFns.delete).not.toHaveBeenCalledWith(schemaMock.uploadSession) + } + ) + + it('does not purge images or ownership records if account deletion rolls back', async () => { + queueTableRows(schemaMock.uploadSession, [{ id: 'upload-1', key: IMAGE_KEY }]) + dbChainMockFns.transaction.mockRejectedValueOnce(new Error('Transaction rolled back')) + + await expect(deleteUserAccount('user-1')).rejects.toThrow('Transaction rolled back') + + expect(mocks.deleteFiles).not.toHaveBeenCalled() + expect(dbChainMockFns.delete).not.toHaveBeenCalledWith(schemaMock.uploadSession) + }) + + it('leaves storage untouched when deletion is blocked for an active account', async () => { + mocks.getPersonalSubscription.mockResolvedValueOnce({ plan: 'pro' }) + + await expect(deleteUserAccount('user-1')).rejects.toMatchObject({ code: 'conflict' }) + + expect(dbChainMockFns.from).not.toHaveBeenCalledWith(schemaMock.uploadSession) + expect(mocks.deleteFiles).not.toHaveBeenCalled() + }) + + it('collects and purges image keys in bounded pages', async () => { + const firstPage = Array.from({ length: 1000 }, (_, index) => ({ + id: `upload-${String(index).padStart(4, '0')}`, + key: `assistant/org-1/user-1/upload-${index}/photo.png`, + })) + queueTableRows(schemaMock.uploadSession, firstPage) + queueTableRows(schemaMock.uploadSession, [{ id: 'upload-1000', key: IMAGE_KEY }]) + + await deleteUserAccount('user-1') + + expect(mocks.deleteFiles.mock.calls.map(([keys]) => keys.length)).toEqual([1000, 1]) + expect( + dbChainMockFns.where.mock.calls.some(([condition]) => + hasMockCondition( + condition, + (node) => + node.type === 'gt' && + node.left === schemaMock.uploadSession.id && + node.right === firstPage[999].id + ) + ) + ).toBe(true) + }) +}) diff --git a/apps/sim/lib/users/account-deletion.ts b/apps/sim/lib/users/account-deletion.ts index 447beba1b30..1b81d20988c 100644 --- a/apps/sim/lib/users/account-deletion.ts +++ b/apps/sim/lib/users/account-deletion.ts @@ -7,6 +7,7 @@ import { organization, permissions, tableRunDispatches, + uploadSession, user, workspaceFile, workspaceFiles, @@ -14,7 +15,7 @@ import { } from '@sim/db/schema' import { createLogger } from '@sim/logger' import { formatQuotedNameList } from '@sim/utils/string' -import { and, eq, gt, inArray, isNotNull, ne, notExists, or, sql } from 'drizzle-orm' +import { and, eq, gt, inArray, isNotNull, isNull, lte, ne, notExists, or, sql } from 'drizzle-orm' import type { AccountDeletionBlocker, AccountDeletionPlan, @@ -415,7 +416,7 @@ export function extractProfilePictureKey(image: string | null): string | null { } /** - * Collects every stored object held by workspaces that go with the account. + * Collects the account's private images and stored objects in workspaces that go with it. * * This has to run *before* the rows are deleted: they disappear with the * workspace through `ON DELETE CASCADE`, and the retention sweep that normally @@ -429,6 +430,27 @@ async function collectAccountStorageKeys( workspaceIds: string[] ): Promise { const batches: StorageKeyBatch[] = [] + + await collectPages( + (afterId) => + db + .select({ id: uploadSession.id, key: uploadSession.finalKey }) + .from(uploadSession) + .where( + and( + eq(uploadSession.userId, userId), + eq(uploadSession.purpose, 'mothership_attachment'), + isNull(uploadSession.workspaceId), + eq(uploadSession.status, 'completed'), + gt(uploadSession.id, afterId) + ) + ) + .orderBy(uploadSession.id) + .limit(STORAGE_PAGE_SIZE), + batches, + () => 'mothership' + ) + if (!isUsingCloudStorage()) return batches const [profile] = await db @@ -497,7 +519,7 @@ async function collectAccountStorageKeys( * failure for work that cannot be undone. An orphaned object is recoverable from * the log; a deletion the caller believes failed is not. */ -async function purgeStorageObjects(batches: StorageKeyBatch[]): Promise { +async function purgeStorageObjects(userId: string, batches: StorageKeyBatch[]): Promise { for (const { context, keys } of batches) { if (keys.length === 0) continue try { @@ -509,8 +531,34 @@ async function purgeStorageObjects(batches: StorageKeyBatch[]): Promise { error, }) } + + if (context === 'mothership') { + const failedKeys = new Set(failed.map(({ key }) => key)) + const deletedImageKeys = keys.filter( + (key) => key.startsWith('assistant/') && !failedKeys.has(key) + ) + if (deletedImageKeys.length > 0) { + /** + * Keep ownership records while a signed PUT can recreate the object. + * The upload-session sweep retries these and failed object deletions + * after the deleted uploader and transfer expiry are confirmed. + */ + await db + .delete(uploadSession) + .where( + and( + eq(uploadSession.userId, userId), + eq(uploadSession.purpose, 'mothership_attachment'), + isNull(uploadSession.workspaceId), + eq(uploadSession.status, 'completed'), + lte(uploadSession.expiresAt, new Date()), + inArray(uploadSession.finalKey, deletedImageKeys) + ) + ) + } + } } catch (error) { - logger.error('Storage batch deletion failed during account deletion', { context, error }) + logger.error('Storage cleanup failed during account deletion', { context, error }) } } } @@ -743,7 +791,7 @@ export async function deleteUserAccount(userId: string): Promise Date: Fri, 11 Sep 2026 11:47:23 -0700 Subject: [PATCH 06/15] fix(slack): read shared app credentials from the environment (#7773) * fix(slack): read shared app credentials from the environment * fix(slack): retain custom app credential constraints * chore(slack): rename shared app environment module --- apps/sim/.env.example | 5 +- apps/sim/lib/core/config/env.ts | 3 + .../provider-configuration.test.ts | 57 +- .../provider-configuration.ts | 7 +- .../slack-managed-users.test.ts | 65 + .../credential-groups/slack-managed-users.ts | 53 +- .../application/slack-search/installations.ts | 14 +- .../application/slack-search/setup.test.ts | 61 +- .../application/slack-search/setup.ts | 95 +- .../slack-search/app-configuration.test.ts | 108 + .../sim/lib/slack-search/app-configuration.ts | 30 + apps/sim/lib/slack-search/manifest.test.ts | 41 +- apps/sim/lib/slack-search/manifest.ts | 40 +- apps/sim/lib/slack-search/oauth-state.test.ts | 8 + apps/sim/lib/slack-search/oauth-state.ts | 56 +- apps/sim/lib/slack-search/shared-app-env.ts | 24 + apps/sim/lib/slack-search/shared-app.test.ts | 43 +- apps/sim/lib/slack-search/shared-app.ts | 19 +- .../scripts/register-platform-slack-app.ts | 17 +- .../migrations/0340_slack_shared_app_env.sql | 4 + .../db/migrations/meta/0340_snapshot.json | 26301 ++++++++++++++++ packages/db/migrations/meta/_journal.json | 7 + packages/db/schema.ts | 11 +- 23 files changed, 26938 insertions(+), 131 deletions(-) create mode 100644 apps/sim/lib/slack-search/app-configuration.test.ts create mode 100644 apps/sim/lib/slack-search/shared-app-env.ts create mode 100644 packages/db/migrations/0340_slack_shared_app_env.sql create mode 100644 packages/db/migrations/meta/0340_snapshot.json diff --git a/apps/sim/.env.example b/apps/sim/.env.example index 5b8106a17b7..c8b8583d103 100644 --- a/apps/sim/.env.example +++ b/apps/sim/.env.example @@ -254,6 +254,9 @@ CRON_SECRET=your_cron_secret # Use `openssl rand -hex 32` to generate. Authentic # MISTRAL_OCR_QUOTA_GROUPS={"<64-character lowercase key fingerprint>":"organization-id"} # Official Sim Search Slack app (optional; requires existing Search access) -# Register the company app with bun scripts/register-platform-slack-app.ts --search. +# Supply these through the deployment environment (for example, ECS Secrets Manager injection). # SLACK_SEARCH_APP_ID= +# SLACK_SEARCH_CLIENT_ID= +# SLACK_SEARCH_CLIENT_SECRET= +# SLACK_SEARCH_SIGNING_SECRET= # SLACK_SEARCH_SHARED_APP=false # Off-production fallback for the global slack-search-shared-app flag diff --git a/apps/sim/lib/core/config/env.ts b/apps/sim/lib/core/config/env.ts index a7bee9c48b4..efece380bdb 100644 --- a/apps/sim/lib/core/config/env.ts +++ b/apps/sim/lib/core/config/env.ts @@ -548,6 +548,9 @@ export const env = createEnv({ DROPBOX_CLIENT_SECRET: z.string().optional(), // Dropbox OAuth client secret SLACK_CLIENT_ID: z.string().optional(), // Slack OAuth client ID SLACK_SEARCH_APP_ID: z.string().optional(), + SLACK_SEARCH_CLIENT_ID: z.string().optional(), + SLACK_SEARCH_CLIENT_SECRET: z.string().optional(), + SLACK_SEARCH_SIGNING_SECRET: z.string().optional(), SLACK_SEARCH_SHARED_APP: z.boolean().optional(), SLACK_CLIENT_SECRET: z.string().optional(), // Slack OAuth client secret SLACK_SIGNING_SECRET: z.string().optional(), // Official Sim Slack app signing secret (verifies inbound events for the native OAuth trigger) diff --git a/apps/sim/lib/credential-groups/provider-configuration.test.ts b/apps/sim/lib/credential-groups/provider-configuration.test.ts index 603d360acba..bd833a7f285 100644 --- a/apps/sim/lib/credential-groups/provider-configuration.test.ts +++ b/apps/sim/lib/credential-groups/provider-configuration.test.ts @@ -2,6 +2,18 @@ import { dbChainMockFns, resetDbChainMock } from '@sim/testing' import { beforeEach, describe, expect, it, vi } from 'vitest' +const shared = vi.hoisted(() => ({ + env: { + SLACK_SEARCH_APP_ID: '', + SLACK_SEARCH_CLIENT_ID: 'environment-client', + SLACK_SEARCH_CLIENT_SECRET: 'environment-secret', + SLACK_SEARCH_SIGNING_SECRET: 'environment-signing', + }, + flag: vi.fn(), +})) +vi.mock('@/lib/core/config/env', () => ({ env: shared.env })) +vi.mock('@/lib/core/config/feature-flags', () => ({ isFeatureEnabled: shared.flag })) + vi.mock('@/lib/core/security/encryption', () => ({ encryptSecret: async (value: string) => ({ encrypted: `encrypted:${value}` }), decryptSecret: async (value: string) => ({ decrypted: value.replace(/^encrypted:/, '') }), @@ -26,6 +38,8 @@ const configuration = { } beforeEach(() => { resetDbChainMock() + shared.env.SLACK_SEARCH_APP_ID = '' + shared.flag.mockResolvedValue(true) }) describe('organization Slack app references', () => { @@ -36,7 +50,12 @@ describe('organization Slack app references', () => { dbChainMockFns.limit .mockResolvedValueOnce([{ encryptedProviderConfiguration }]) .mockResolvedValueOnce([ - { id: 'A1', clientId: 'client-1', encryptedClientSecret: 'encrypted:current-secret' }, + { + id: 'A1', + clientId: 'client-1', + encryptedClientSecret: 'encrypted:current-secret', + encryptedSigningSecret: 'encrypted:signing', + }, ]) expect( await getSlackCredentialGroupConfiguration({ @@ -50,6 +69,42 @@ describe('organization Slack app references', () => { clientSecret: 'current-secret', }) }) + it.each([true, false])( + 'resolves environment credentials only for an active shared installation (active=%s)', + async (active) => { + shared.env.SLACK_SEARCH_APP_ID = 'A1' + dbChainMockFns.limit + .mockResolvedValueOnce([ + { + encryptedProviderConfiguration: + await encryptCredentialGroupProviderConfiguration(configuration), + }, + ]) + .mockResolvedValueOnce([ + { + id: 'A1', + kind: 'shared', + organizationId: null, + clientId: null, + encryptedClientSecret: null, + encryptedSigningSecret: null, + }, + ]) + .mockResolvedValueOnce(active ? [{ id: 'installation' }] : []) + const result = getSlackCredentialGroupConfiguration({ + organizationId: 'org-1', + credentialGroupId: 'group-1', + }) + if (active) + await expect(result).resolves.toMatchObject({ + clientId: 'environment-client', + clientSecret: 'environment-secret', + appId: 'A1', + teamId: 'T1', + }) + else await expect(result).rejects.toThrow('disabled or removed') + } + ) it('fails when the referenced app is absent from the owning organization', async () => { dbChainMockFns.limit .mockResolvedValueOnce([ diff --git a/apps/sim/lib/credential-groups/provider-configuration.ts b/apps/sim/lib/credential-groups/provider-configuration.ts index 13249edb58c..fd4bde8c0d5 100644 --- a/apps/sim/lib/credential-groups/provider-configuration.ts +++ b/apps/sim/lib/credential-groups/provider-configuration.ts @@ -6,6 +6,7 @@ import { resourceScopeFromOwner } from '@/lib/core/resource-scope' import { resourceScopeCondition } from '@/lib/core/resource-scope.server' import { decryptSecret, encryptSecret } from '@/lib/core/security/encryption' import type { DbOrTx } from '@/lib/db/types' +import { resolveSlackAppCredentials } from '@/lib/slack-search/app-configuration' import { requireSlackSearchAppAvailable } from '@/lib/slack-search/shared-app' const CREDENTIAL_GROUP_PROVIDER_CONFIGURATION_TYPE = @@ -173,12 +174,12 @@ async function resolveSlackConfiguration( .limit(1) if (!installation) throw new Error('The shared Slack installation is disabled or removed') } - const { decrypted: clientSecret } = await decryptSecret(app.encryptedClientSecret) + const resolved = await resolveSlackAppCredentials(app) return { appId: app.id, teamId: configuration.teamId, - clientId: app.clientId, - clientSecret, + clientId: resolved.clientId, + clientSecret: resolved.clientSecret, scopes: configuration.scopes, verifiedAt: configuration.verifiedAt, } diff --git a/apps/sim/lib/credential-groups/slack-managed-users.test.ts b/apps/sim/lib/credential-groups/slack-managed-users.test.ts index b24795083aa..3e32054c599 100644 --- a/apps/sim/lib/credential-groups/slack-managed-users.test.ts +++ b/apps/sim/lib/credential-groups/slack-managed-users.test.ts @@ -24,6 +24,18 @@ const { attempts, redis } = vi.hoisted(() => { } }) +const shared = vi.hoisted(() => ({ + env: { + SLACK_SEARCH_APP_ID: '', + SLACK_SEARCH_CLIENT_ID: 'environment-client', + SLACK_SEARCH_CLIENT_SECRET: 'environment-secret', + SLACK_SEARCH_SIGNING_SECRET: 'environment-signing', + }, + flag: vi.fn(), +})) +vi.mock('@/lib/core/config/env', () => ({ env: shared.env })) +vi.mock('@/lib/core/config/feature-flags', () => ({ isFeatureEnabled: shared.flag })) + vi.mock('@/lib/core/config/redis', () => ({ getRedisClient: () => redis })) vi.mock('@/lib/core/security/encryption', () => ({ encryptSecret: vi.fn(async (value: string) => ({ @@ -70,6 +82,9 @@ describe('Slack managed-user authorization', () => { vi.clearAllMocks() resetDbChainMock() attempts.clear() + shared.env.SLACK_SEARCH_APP_ID = '' + shared.env.SLACK_SEARCH_CLIENT_SECRET = 'environment-secret' + shared.flag.mockResolvedValue(true) }) afterEach(() => { @@ -84,6 +99,7 @@ describe('Slack managed-user authorization', () => { app: { id: 'A123', clientId: 'client-1', + encryptedSigningSecret: `encrypted:${Buffer.from('signing-secret').toString('base64')}`, encryptedClientSecret: `encrypted:${Buffer.from('private-client-secret').toString('base64')}`, revision: 'app-revision', }, @@ -125,6 +141,54 @@ describe('Slack managed-user authorization', () => { await expect(loadSlackManagedUsersAttempt(created.state)).rejects.toThrow('malformed') }) + it.each(['rotation', 'disabled', 'success'] as const)( + 'keeps shared setup state secret-free and rechecks configuration on %s', + async (outcome) => { + shared.env.SLACK_SEARCH_APP_ID = 'ASHARED' + dbChainMockFns.limit + .mockResolvedValueOnce([{ id: 'group-1', updatedAt: new Date(1), options: [] }]) + .mockResolvedValueOnce([ + { + app: { + id: 'ASHARED', + kind: 'shared', + organizationId: null, + clientId: null, + encryptedClientSecret: null, + encryptedSigningSecret: null, + revision: 'old-revision', + }, + teamId: 'T123', + }, + ]) + const created = await createSlackManagedUsersAttempt({ + organizationId: 'org-1', + userId: 'user-1', + credentialGroupId: 'group-1', + appId: 'ASHARED', + teamId: 'T123', + }) + const stored = JSON.parse([...attempts.values()][0]) + expect(stored).toMatchObject({ credentialSource: 'environment', expectedAppId: 'ASHARED' }) + expect(stored).not.toHaveProperty('encryptedClientSecret') + expect(JSON.stringify(stored)).not.toContain('environment-secret') + if (outcome === 'rotation') { + shared.env.SLACK_SEARCH_CLIENT_SECRET = 'rotated' + await expect(consumeSlackManagedUsersAttempt(created.state)).rejects.toThrow('changed') + } else if (outcome === 'disabled') { + shared.flag.mockResolvedValue(false) + await expect(consumeSlackManagedUsersAttempt(created.state)).rejects.toThrow('unavailable') + } else { + await expect(consumeSlackManagedUsersAttempt(created.state)).resolves.toMatchObject({ + clientId: 'environment-client', + clientSecret: 'environment-secret', + organizationId: 'org-1', + }) + await expect(consumeSlackManagedUsersAttempt(created.state)).resolves.toBeNull() + } + } + ) + it('binds the bot token to Slack app and workspace identities', async () => { const fetchMock = vi .fn() @@ -202,6 +266,7 @@ describe('Slack managed-user authorization', () => { const app = { id: 'A123', clientId: 'client-1', + encryptedSigningSecret: `encrypted:${Buffer.from('signing-secret').toString('base64')}`, encryptedClientSecret: `encrypted:${Buffer.from('client-secret').toString('base64')}`, revision: 'app-revision', } diff --git a/apps/sim/lib/credential-groups/slack-managed-users.ts b/apps/sim/lib/credential-groups/slack-managed-users.ts index 5b2863c9d7a..5bd4b689c59 100644 --- a/apps/sim/lib/credential-groups/slack-managed-users.ts +++ b/apps/sim/lib/credential-groups/slack-managed-users.ts @@ -29,7 +29,9 @@ import { } from '@/lib/credential-groups/slack-managed-user-scopes' import type { DbOrTx } from '@/lib/db/types' import { SLACK_CUSTOM_BOT_PROVIDER_ID, SLACK_CUSTOM_BOT_SECRET_TYPE } from '@/lib/oauth/types' +import { resolveSlackAppCredentials } from '@/lib/slack-search/app-configuration' import { requireSlackSearchAppAvailable } from '@/lib/slack-search/shared-app' +import { getSharedSlackSearchAppConfiguration } from '@/lib/slack-search/shared-app-env' const logger = createLogger('SlackManagedUsers') const SLACK_MANAGED_USERS_ATTEMPT_TTL_MS = 10 * 60 * 1000 @@ -54,7 +56,7 @@ interface SlackCustomBotSecret { metadata?: Record } -interface StoredSlackManagedUsersAttempt { +type StoredSlackManagedUsersAttempt = { appRevision?: string version: typeof SLACK_MANAGED_USERS_ATTEMPT_VERSION workspaceId?: string @@ -67,11 +69,13 @@ interface StoredSlackManagedUsersAttempt { expectedAppId: string expectedTeamId: string clientId: string - encryptedClientSecret: string redirectUri: string requiredScopes: string[] createdAt: number -} +} & ( + | { credentialSource: 'environment'; encryptedClientSecret?: never } + | { credentialSource?: undefined; encryptedClientSecret: string } +) export interface SlackManagedUsersAttempt { appRevision?: string @@ -162,7 +166,11 @@ function isStoredAttempt(value: unknown): value is StoredSlackManagedUsersAttemp typeof candidate.expectedAppId === 'string' && typeof candidate.expectedTeamId === 'string' && typeof candidate.clientId === 'string' && - typeof candidate.encryptedClientSecret === 'string' && + (candidate.credentialSource === 'environment' + ? typeof candidate.organizationId === 'string' && + candidate.encryptedClientSecret === undefined + : candidate.credentialSource === undefined && + typeof candidate.encryptedClientSecret === 'string') && typeof candidate.redirectUri === 'string' && Array.isArray(candidate.requiredScopes) && candidate.requiredScopes.length > 0 && @@ -518,10 +526,11 @@ export async function createSlackManagedUsersAttempt(params: { 'invalid_response' ) await requireSlackSearchAppAvailable(configured.app.id) + const app = await resolveSlackAppCredentials(configured.app) identity = { appId: configured.app.id, teamId: configured.teamId } - clientId = configured.app.clientId - clientSecret = (await decryptSecret(configured.app.encryptedClientSecret)).decrypted - appRevision = configured.app.revision + clientId = app.clientId + clientSecret = app.clientSecret + appRevision = app.revision requiredScopes = resolveSlackManagedUserScopes( existingOption ? existingOption.requiredScopes : SLACK_SEARCH_USER_SCOPES ) @@ -545,7 +554,8 @@ export async function createSlackManagedUsersAttempt(params: { const redis = requireRedis() const state = generateId() const redirectUri = getSlackManagedUsersRedirectUri() - const encryptedClientSecret = await encryptSecret(clientSecret) + const sharedApp = + scope.kind === 'organization' ? getSharedSlackSearchAppConfiguration(identity.appId) : null const attempt: StoredSlackManagedUsersAttempt = { version: SLACK_MANAGED_USERS_ATTEMPT_VERSION, ...resourceScopeFields(scope), @@ -559,7 +569,9 @@ export async function createSlackManagedUsersAttempt(params: { expectedTeamId: identity.teamId, clientId, ...(appRevision ? { appRevision } : {}), - encryptedClientSecret: encryptedClientSecret.encrypted, + ...(sharedApp + ? { credentialSource: 'environment' as const } + : { encryptedClientSecret: (await encryptSecret(clientSecret)).encrypted }), requiredScopes, redirectUri, createdAt: Date.now(), @@ -606,7 +618,19 @@ async function parseSlackManagedUsersAttempt( const parsed: unknown = JSON.parse(raw) if (!isStoredAttempt(parsed)) throw new Error('Slack managed-user state is malformed') if (Date.now() - parsed.createdAt > SLACK_MANAGED_USERS_ATTEMPT_TTL_MS) return null - const clientSecret = await decryptSecret(parsed.encryptedClientSecret) + let clientSecret: string + if (parsed.credentialSource === 'environment') { + const app = getSharedSlackSearchAppConfiguration(parsed.expectedAppId) + if (!app || app.revision !== parsed.appRevision || app.clientId !== parsed.clientId) + throw new SlackManagedUsersError( + 'The shared Slack app changed. Start again.', + 'invalid_state' + ) + await requireSlackSearchAppAvailable(app.id) + clientSecret = app.clientSecret + } else { + clientSecret = (await decryptSecret(parsed.encryptedClientSecret)).decrypted + } return { ...resourceScopeFields(resourceScopeFromOwner(parsed)), userId: parsed.userId, @@ -622,7 +646,7 @@ async function parseSlackManagedUsersAttempt( expectedTeamId: parsed.expectedTeamId, clientId: parsed.clientId, ...(parsed.appRevision ? { appRevision: parsed.appRevision } : {}), - clientSecret: clientSecret.decrypted, + clientSecret, redirectUri: parsed.redirectUri, requiredScopes: parsed.requiredScopes, createdAt: parsed.createdAt, @@ -706,11 +730,12 @@ export async function exchangeAndConfigureSlackManagedUsers(params: { .limit(1) .for('update') if (app?.kind === 'shared') await requireSlackSearchAppAvailable(app.id) + const resolved = app ? await resolveSlackAppCredentials(app) : null if ( - !app || + !resolved || !params.attempt.appRevision || - app.revision !== params.attempt.appRevision || - app.clientId !== params.attempt.clientId + resolved.revision !== params.attempt.appRevision || + resolved.clientId !== params.attempt.clientId ) throw new SlackManagedUsersError( 'The Slack app changed during authorization. Start again.', diff --git a/apps/sim/lib/knowledge/application/slack-search/installations.ts b/apps/sim/lib/knowledge/application/slack-search/installations.ts index cd53db31d22..801be121a54 100644 --- a/apps/sim/lib/knowledge/application/slack-search/installations.ts +++ b/apps/sim/lib/knowledge/application/slack-search/installations.ts @@ -15,7 +15,10 @@ import { resolveKnowledgeOrganizationContext } from '@/lib/knowledge/application import { knowledgeOperations } from '@/lib/knowledge/application/operations' import { loadSlackSearchCredential } from '@/lib/knowledge/application/slack-search/repository' import { SLACK_CUSTOM_BOT_PROVIDER_ID } from '@/lib/oauth/types' -import { slackBotCredentialVersion } from '@/lib/slack-search/app-configuration' +import { + resolveSlackAppCredentials, + slackBotCredentialVersion, +} from '@/lib/slack-search/app-configuration' import { SLACK_SHARED_SEARCH_BOT_SCOPES } from '@/lib/slack-search/constants' import { readSharedSlackSearchApp, @@ -85,12 +88,15 @@ export const listSlackSearchInstallations = defineAuthorizedKnowledgeUseCase({ sharedAppAvailable: Boolean(sharedApp), installations: installations.map(({ credentialVersion, ...installation }) => { const bot = bots.find((bot) => bot.id === installation.credentialId) + const shared = installation.appKind === 'shared' + const appRevision = shared ? sharedApp?.revision : bot?.appRevision return { ...installation, appKind: installation.appKind ?? 'custom', needsValidation: + (shared && sharedApp?.id !== installation.appId) || !bot?.encryptedKey || - slackBotCredentialVersion(bot.encryptedKey, bot.appRevision ?? undefined) !== + slackBotCredentialVersion(bot.encryptedKey, appRevision ?? undefined) !== credentialVersion, } }), @@ -154,10 +160,12 @@ export const configureSlackSearchInstallation = defineAuthorizedKnowledgeUseCase if (input.enabled && current.slackAppId) await requireSlackSearchAppAvailable(current.slackAppId) if (current.slackAppId && !app) throw new Error('Slack app configuration is missing') + const appRevision = + app && secret ? (await resolveSlackAppCredentials(app)).revision : undefined if ( secret && (!current.encryptedServiceAccountKey || - slackBotCredentialVersion(current.encryptedServiceAccountKey, app?.revision) !== + slackBotCredentialVersion(current.encryptedServiceAccountKey, appRevision) !== secret.version) ) throw new OrchestrationError('conflict', 'The bot credential changed. Validate it again.') diff --git a/apps/sim/lib/knowledge/application/slack-search/setup.test.ts b/apps/sim/lib/knowledge/application/slack-search/setup.test.ts index 2f197b744b9..214f5f3a290 100644 --- a/apps/sim/lib/knowledge/application/slack-search/setup.test.ts +++ b/apps/sim/lib/knowledge/application/slack-search/setup.test.ts @@ -122,6 +122,7 @@ beforeEach(() => { values: m.values, set: m.set, onConflictDoUpdate: vi.fn(), + onConflictDoNothing: vi.fn(), returning: vi.fn().mockResolvedValue([{ id: 'credential1' }]), } for (const method of [ @@ -131,6 +132,7 @@ beforeEach(() => { txQuery.values, txQuery.set, txQuery.onConflictDoUpdate, + txQuery.onConflictDoNothing, ]) method.mockReturnValue(txQuery) const tx = { @@ -299,7 +301,15 @@ it('rejects a shared-app callback if the global configuration was disabled or ro }) describe('shared app completion', () => { - const sharedApp = { id: 'A1', revision: 'shared-revision', kind: 'shared', organizationId: null } + const sharedApp = { + id: 'A1', + revision: 'shared-revision', + kind: 'shared', + organizationId: null, + clientId: 'client', + clientSecret: 'environment-secret', + signingSecret: 'environment-signing', + } beforeEach(() => { m.shared.mockResolvedValue(sharedApp) m.consume.mockResolvedValue({ @@ -308,9 +318,27 @@ describe('shared app completion', () => { }) }) - it('commits the personal app configuration, bot credential and installation in one transaction', async () => { + it('starts shared OAuth without storing deployment secrets in the attempt', async () => { + const result = await startSlackSearchSetup.execute({ + principal, + input: { + organizationId: 'org1', + mode: 'shared', + name: 'Sim Search', + description: 'Search with sources', + }, + }) + expect(new URL(result.authorizationUrl).searchParams.get('client_id')).toBe('client') + const stored = m.store.mock.calls[0][0] + expect(stored.sharedApp).toEqual({ id: 'A1', revision: 'shared-revision' }) + expect(stored).not.toHaveProperty('encryptedClientSecret') + expect(stored).not.toHaveProperty('encryptedSigningSecret') + expect(JSON.stringify(stored)).not.toContain('environment-secret') + }) + + it('creates shared identity without app secrets and installs atomically without registration', async () => { m.rows - .mockResolvedValueOnce([sharedApp]) + .mockResolvedValueOnce([]) .mockResolvedValueOnce([]) .mockResolvedValueOnce([]) .mockResolvedValueOnce([ @@ -350,16 +378,27 @@ describe('shared app completion', () => { }) expect(configuration.slack).not.toHaveProperty('clientSecret') const rows = m.values.mock.calls.map(([value]) => value) - expect(rows).toHaveLength(2) - expect(rows[0]).toMatchObject({ + expect(rows).toHaveLength(3) + expect(rows[0]).toEqual({ + id: 'A1', + kind: 'shared', + organizationId: null, + revision: 'shared-revision', + }) + expect(m.exchange).toHaveBeenCalledWith( + expect.objectContaining({ clientSecret: 'environment-secret' }) + ) + expect(JSON.stringify(rows)).not.toContain('environment-secret') + expect(JSON.stringify(rows)).not.toContain('environment-signing') + expect(rows[1]).toMatchObject({ organizationId: 'org1', workspaceId: null, type: 'service_account', slackAppId: 'A1', }) - expect(rows[1]).toMatchObject({ + expect(rows[2]).toMatchObject({ organizationId: 'org1', - credentialId: rows[0].id, + credentialId: rows[1].id, slackAppId: 'A1', appId: 'A1', teamId: 'T1', @@ -382,13 +421,7 @@ describe('shared app completion', () => { }) it('revokes an unused shared grant after a database write fails', async () => { - m.rows - .mockResolvedValueOnce([sharedApp]) - .mockResolvedValueOnce([]) - .mockResolvedValueOnce([]) - .mockResolvedValueOnce([ - { id: 'accounts', options: [], encryptedProviderConfiguration: null }, - ]) + m.rows.mockResolvedValueOnce([sharedApp]).mockResolvedValueOnce([]).mockResolvedValueOnce([]) m.values.mockImplementationOnce(() => { throw new Error('write failed') }) diff --git a/apps/sim/lib/knowledge/application/slack-search/setup.ts b/apps/sim/lib/knowledge/application/slack-search/setup.ts index 4a6c46d2da5..b2e259a2a65 100644 --- a/apps/sim/lib/knowledge/application/slack-search/setup.ts +++ b/apps/sim/lib/knowledge/application/slack-search/setup.ts @@ -138,7 +138,8 @@ export const startSlackSearchSetup = defineAuthorizedKnowledgeUseCase({ ) if (savedApp?.kind === 'custom' && savedApp.organizationId !== context.organizationId) throw new OrchestrationError('forbidden', 'Slack app ownership changed') - const app = shared ? await readSharedSlackSearchApp() : savedApp + const sharedApp = shared ? await readSharedSlackSearchApp() : null + const app = shared ? sharedApp : savedApp if (shared && (!app || input.clientId || input.clientSecret || input.signingSecret)) throw new OrchestrationError( 'validation', @@ -150,20 +151,29 @@ export const startSlackSearchSetup = defineAuthorizedKnowledgeUseCase({ 'Remove the previous Slack source configuration before switching apps; members must reconnect' ) const clientId = input.clientId ?? app?.clientId - const encryptedClientSecret = input.clientSecret - ? (await encryptSecret(input.clientSecret)).encrypted - : app?.encryptedClientSecret - const encryptedSigningSecret = input.signingSecret - ? (await encryptSecret(input.signingSecret)).encrypted - : app?.encryptedSigningSecret - if (!clientId || !encryptedClientSecret || !encryptedSigningSecret) - throw new OrchestrationError( - 'validation', - 'Client ID, Client Secret, and Signing Secret are required for a new Slack app' - ) + if (!clientId) throw new OrchestrationError('validation', 'Slack Client ID is required') + let appCredentials: + | { sharedApp: { id: string; revision: string } } + | { encryptedClientSecret: string; encryptedSigningSecret: string } + if (sharedApp) { + appCredentials = { sharedApp: { id: sharedApp.id, revision: sharedApp.revision } } + } else { + const encryptedClientSecret = input.clientSecret + ? (await encryptSecret(input.clientSecret)).encrypted + : savedApp?.encryptedClientSecret + const encryptedSigningSecret = input.signingSecret + ? (await encryptSecret(input.signingSecret)).encrypted + : savedApp?.encryptedSigningSecret + if (!encryptedClientSecret || !encryptedSigningSecret) + throw new OrchestrationError( + 'validation', + 'Client ID, Client Secret, and Signing Secret are required for a new Slack app' + ) + appCredentials = { encryptedClientSecret, encryptedSigningSecret } + } const redirectUri = new URL(SLACK_SEARCH_CALLBACK_PATH, origin).href const state = await storeSlackSearchOAuthAttempt({ - ...(shared && app ? { sharedApp: { id: app.id, revision: app.revision } } : {}), + ...appCredentials, userId: principal.userId, sessionId: principal.sessionId, organizationId: context.organizationId, @@ -171,8 +181,6 @@ export const startSlackSearchSetup = defineAuthorizedKnowledgeUseCase({ description: input.description, ...(member.app ? { memberApp: member.app } : {}), clientId, - encryptedClientSecret, - encryptedSigningSecret, redirectUri, createdAt: Date.now(), ...(installation @@ -256,15 +264,22 @@ export const completeSlackSearchSetup = defineAuthorizedKnowledgeUseCase({ ) await requireOrganizationSearchAvailable(context.organizationId) const { attempt } = context + let clientSecret: string if (attempt.sharedApp) { const app = await readSharedSlackSearchApp() - if (app?.id !== attempt.sharedApp.id || app.revision !== attempt.sharedApp.revision) + if ( + app?.id !== attempt.sharedApp.id || + app.revision !== attempt.sharedApp.revision || + app.clientId !== attempt.clientId + ) throw new OrchestrationError( 'conflict', 'Shared Slack app configuration changed. Start again.' ) + clientSecret = app.clientSecret + } else { + clientSecret = (await decryptSecret(attempt.encryptedClientSecret)).decrypted } - const { decrypted: clientSecret } = await decryptSecret(attempt.encryptedClientSecret) const grant = await exchangeSlackBotAuthorization({ clientId: attempt.clientId, clientSecret, @@ -345,10 +360,7 @@ export const completeSlackSearchSetup = defineAuthorizedKnowledgeUseCase({ .limit(1) if ( attempt.sharedApp - ? !existingApp || - existingApp.kind !== 'shared' || - existingApp.organizationId !== null || - existingApp.revision !== attempt.sharedApp.revision + ? existingApp && (existingApp.kind !== 'shared' || existingApp.organizationId !== null) : existingApp && (existingApp.kind !== 'custom' || existingApp.organizationId !== context.organizationId) @@ -358,6 +370,7 @@ export const completeSlackSearchSetup = defineAuthorizedKnowledgeUseCase({ 'This Slack app belongs to another installation owner' ) if ( + !attempt.sharedApp && attempt.installation?.appRevision && existingApp?.revision !== attempt.installation.appRevision ) @@ -413,6 +426,12 @@ export const completeSlackSearchSetup = defineAuthorizedKnowledgeUseCase({ 'This Slack workspace already has an active Search installation' ) if (attempt.sharedApp) { + const currentApp = await readSharedSlackSearchApp() + if ( + currentApp?.id !== attempt.sharedApp.id || + currentApp.revision !== attempt.sharedApp.revision + ) + throw new OrchestrationError('conflict', 'Shared Slack app configuration changed') /** A concurrent failed setup may have revoked an uncommitted grant while we waited. */ const current = await verifySlackSearchBot( grant.access_token, @@ -430,21 +449,33 @@ export const completeSlackSearchSetup = defineAuthorizedKnowledgeUseCase({ ) } const appRevision = attempt.sharedApp?.revision ?? generateId() - const appValues = { - id: identity.appId, - kind: 'custom' as const, - organizationId: context.organizationId, - clientId: attempt.clientId, - encryptedClientSecret: attempt.encryptedClientSecret, - encryptedSigningSecret: attempt.encryptedSigningSecret, - revision: appRevision, - updatedAt: new Date(), - } - if (!attempt.sharedApp) + if (attempt.sharedApp) { + /** The row supplies foreign-key identity only; shared secrets remain in the environment. */ + await tx + .insert(slackApp) + .values({ + id: identity.appId, + kind: 'shared', + organizationId: null, + revision: appRevision, + }) + .onConflictDoNothing() + } else { + const appValues = { + id: identity.appId, + kind: 'custom' as const, + organizationId: context.organizationId, + clientId: attempt.clientId, + encryptedClientSecret: attempt.encryptedClientSecret, + encryptedSigningSecret: attempt.encryptedSigningSecret, + revision: appRevision, + updatedAt: new Date(), + } await tx .insert(slackApp) .values(appValues) .onConflictDoUpdate({ target: slackApp.id, set: appValues }) + } await adoptOrganizationSlackMemberApp( tx, context.organizationId, diff --git a/apps/sim/lib/slack-search/app-configuration.test.ts b/apps/sim/lib/slack-search/app-configuration.test.ts new file mode 100644 index 00000000000..bde6f6a6a71 --- /dev/null +++ b/apps/sim/lib/slack-search/app-configuration.test.ts @@ -0,0 +1,108 @@ +/** @vitest-environment node */ +import { db } from '@sim/db' +import { slackApp } from '@sim/db/schema' +import { queueTableRows, resetDbChainMock } from '@sim/testing' +import { beforeEach, describe, expect, it, vi } from 'vitest' + +const m = vi.hoisted(() => ({ + env: { + SLACK_SEARCH_APP_ID: 'ASHARED', + SLACK_SEARCH_CLIENT_ID: '123.456', + SLACK_SEARCH_CLIENT_SECRET: 'environment-client-secret', + SLACK_SEARCH_SIGNING_SECRET: 'environment-signing-secret', + }, + decrypt: vi.fn(async (value: string) => ({ decrypted: value.replace('encrypted:', '') })), +})) +vi.mock('@/lib/core/config/env', () => ({ env: m.env })) +vi.mock('@/lib/core/security/encryption', () => ({ decryptSecret: m.decrypt })) + +import { + loadSlackAppConfiguration, + resolveSlackAppCredentials, + slackBotCredentialVersion, +} from '@/lib/slack-search/app-configuration' +import { getSharedSlackSearchAppConfiguration } from '@/lib/slack-search/shared-app-env' + +const stored = { + id: 'ASHARED', + kind: 'shared' as const, + organizationId: null, + clientId: 'old-client', + encryptedClientSecret: 'encrypted:old-client-secret', + encryptedSigningSecret: 'encrypted:old-signing-secret', + revision: 'old-revision', + createdAt: new Date(0), + updatedAt: new Date(0), +} +const credentialKeys = [ + 'SLACK_SEARCH_CLIENT_ID', + 'SLACK_SEARCH_CLIENT_SECRET', + 'SLACK_SEARCH_SIGNING_SECRET', +] as const + +beforeEach(() => { + vi.clearAllMocks() + resetDbChainMock() + Object.assign(m.env, { + SLACK_SEARCH_APP_ID: 'ASHARED', + SLACK_SEARCH_CLIENT_ID: '123.456', + SLACK_SEARCH_CLIENT_SECRET: 'environment-client-secret', + SLACK_SEARCH_SIGNING_SECRET: 'environment-signing-secret', + }) +}) + +describe('deployment-owned Slack app configuration', () => { + it('authenticates shared ingress without a database registration', async () => { + await expect(loadSlackAppConfiguration('ASHARED')).resolves.toMatchObject({ + signingSecret: 'environment-signing-secret', + app: { id: 'ASHARED', kind: 'shared', organizationId: null }, + }) + expect(db.select).not.toHaveBeenCalled() + expect(m.decrypt).not.toHaveBeenCalled() + }) + + it('ignores previously registered credentials for the configured company app', async () => { + await expect(resolveSlackAppCredentials(stored)).resolves.toMatchObject({ + clientId: '123.456', + clientSecret: 'environment-client-secret', + }) + expect(m.decrypt).not.toHaveBeenCalled() + }) + + it.each(credentialKeys)('does not use stored secrets when %s is missing', async (key) => { + m.env[key] = '' + queueTableRows(slackApp, [stored]) + await expect(loadSlackAppConfiguration('ASHARED')).rejects.toThrow('Configure SLACK_SEARCH') + await expect(resolveSlackAppCredentials(stored)).rejects.toThrow('Configure SLACK_SEARCH') + expect(m.decrypt).not.toHaveBeenCalled() + }) + + it.each(credentialKeys)('invalidates queued work when %s rotates', (key) => { + const previous = getSharedSlackSearchAppConfiguration()?.revision + expect(getSharedSlackSearchAppConfiguration()?.revision).toBe(previous) + m.env[key] = 'rotated' + const current = getSharedSlackSearchAppConfiguration()?.revision + expect(current).not.toBe(previous) + expect(slackBotCredentialVersion('token', current)).not.toBe( + slackBotCredentialVersion('token', previous) + ) + }) + + it('preserves custom ingress when shared credentials are incomplete', async () => { + m.env.SLACK_SEARCH_CLIENT_SECRET = '' + queueTableRows(slackApp, [{ ...stored, id: 'ACUSTOM', kind: 'custom', organizationId: 'org' }]) + await expect(loadSlackAppConfiguration('ACUSTOM')).resolves.toMatchObject({ + signingSecret: 'old-signing-secret', + }) + }) + + it('rejects company identity colliding with a custom app owner', async () => { + await expect( + resolveSlackAppCredentials({ ...stored, kind: 'custom', organizationId: 'org' }) + ).rejects.toThrow('belongs to a custom installation') + }) + + it('never assigns the shared signing key to an unknown app', async () => { + await expect(loadSlackAppConfiguration('AUNKNOWN')).resolves.toBeNull() + }) +}) diff --git a/apps/sim/lib/slack-search/app-configuration.ts b/apps/sim/lib/slack-search/app-configuration.ts index 197d1f3010c..83171eb9ab0 100644 --- a/apps/sim/lib/slack-search/app-configuration.ts +++ b/apps/sim/lib/slack-search/app-configuration.ts @@ -3,11 +3,41 @@ import { slackApp } from '@sim/db/schema' import { sha256Hex } from '@sim/security/hash' import { eq } from 'drizzle-orm' import { decryptSecret } from '@/lib/core/security/encryption' +import { getSharedSlackSearchAppConfiguration } from '@/lib/slack-search/shared-app-env' + +/** Shared credentials always come from the deployment, even for previously registered apps. */ +export async function resolveSlackAppCredentials(app: typeof slackApp.$inferSelect) { + const shared = getSharedSlackSearchAppConfiguration(app.id) + if (shared?.id === app.id) { + if (app.kind !== 'shared' || app.organizationId !== null) + throw new Error('The configured shared Slack app belongs to a custom installation') + return shared + } + if (!app.clientId || !app.encryptedClientSecret || !app.encryptedSigningSecret) + throw new Error('Slack app credentials are missing') + const [client, signing] = await Promise.all([ + decryptSecret(app.encryptedClientSecret), + decryptSecret(app.encryptedSigningSecret), + ]) + if (!client.decrypted || !signing.decrypted) throw new Error('Slack app credentials are empty') + return { + id: app.id, + kind: app.kind, + organizationId: app.organizationId, + clientId: app.clientId, + clientSecret: client.decrypted, + signingSecret: signing.decrypted, + revision: app.revision, + } +} /** Authentication lookup only: an app ID selects a key, never grants organization access. */ export async function loadSlackAppConfiguration(appId: string) { + const shared = getSharedSlackSearchAppConfiguration(appId) + if (shared?.id === appId) return { app: shared, signingSecret: shared.signingSecret } const [app] = await db.select().from(slackApp).where(eq(slackApp.id, appId)).limit(1) if (!app) return null + if (!app.encryptedSigningSecret) throw new Error('Slack app signing secret is missing') const { decrypted: signingSecret } = await decryptSecret(app.encryptedSigningSecret) if (!signingSecret) throw new Error('Slack app signing secret is empty') return { app, signingSecret } diff --git a/apps/sim/lib/slack-search/manifest.test.ts b/apps/sim/lib/slack-search/manifest.test.ts index 12c578edd47..6f434da4f74 100644 --- a/apps/sim/lib/slack-search/manifest.test.ts +++ b/apps/sim/lib/slack-search/manifest.test.ts @@ -92,7 +92,7 @@ describe('Search app manifest', () => { }) }) -it('official app uses the existing personal indexing grants with bot commands', () => { +it('official app declares expanded permissions without subscribing to member message events', () => { const manifest = createSharedSlackSearchManifest('https://www.sim.ai') expect(manifest.oauth_config.scopes.user).toEqual([ 'channels:history', @@ -105,9 +105,44 @@ it('official app uses the existing personal indexing grants with bot commands', 'mpim:read', 'users:read', 'users:read.email', + 'canvases:read', + 'canvases:write', + 'chat:write', + 'files:read', + 'search:read.files', + 'search:read.im', + 'search:read.mpim', + 'search:read.private', + 'search:read.public', + 'search:read.users', + 'team:read', + 'usergroups:read', + ]) + expect(manifest.oauth_config.scopes.bot).toEqual([ + 'assistant:write', + 'chat:write', + 'im:history', + 'im:write', + 'app_mentions:read', + 'users:read', + 'users:read.email', + 'commands', + 'channels:history', + 'channels:manage', + 'channels:read', + 'channels:write.invites', + 'chat:write.public', + 'groups:history', + 'groups:read', + 'groups:write', + 'groups:write.invites', + 'links:read', + 'links:write', + 'mpim:history', + 'mpim:read', + 'mpim:write', + 'reactions:write', ]) - expect(manifest.oauth_config.scopes.bot).toContain('commands') - expect(manifest.oauth_config.scopes.bot).not.toContain('groups:history') expect(manifest.features.slash_commands.map((command) => command.command)).toEqual([ '/query', '/connect', diff --git a/apps/sim/lib/slack-search/manifest.ts b/apps/sim/lib/slack-search/manifest.ts index cadeba498c0..f8135416f95 100644 --- a/apps/sim/lib/slack-search/manifest.ts +++ b/apps/sim/lib/slack-search/manifest.ts @@ -62,7 +62,10 @@ export function createSlackSearchManifest( } } -/** The official app combines personal source indexing with bot conversations and commands. */ +/** + * Declares the company app's permissions, including planned capabilities. + * Runtime OAuth validation continues to require only scopes used by implemented features. + */ export function createSharedSlackSearchManifest(origin: string) { const manifest = createSlackSearchManifest( SLACK_SEARCH_DEFAULT_NAME, @@ -94,8 +97,39 @@ export function createSharedSlackSearchManifest(origin: string) { oauth_config: { ...manifest.oauth_config, scopes: { - bot: [...SLACK_SHARED_SEARCH_BOT_SCOPES], - user: [...SLACK_SEARCH_USER_SCOPES], + bot: [ + ...SLACK_SHARED_SEARCH_BOT_SCOPES, + 'channels:history', + 'channels:manage', + 'channels:read', + 'channels:write.invites', + 'chat:write.public', + 'groups:history', + 'groups:read', + 'groups:write', + 'groups:write.invites', + 'links:read', + 'links:write', + 'mpim:history', + 'mpim:read', + 'mpim:write', + 'reactions:write', + ], + user: [ + ...SLACK_SEARCH_USER_SCOPES, + 'canvases:read', + 'canvases:write', + 'chat:write', + 'files:read', + 'search:read.files', + 'search:read.im', + 'search:read.mpim', + 'search:read.private', + 'search:read.public', + 'search:read.users', + 'team:read', + 'usergroups:read', + ], }, }, settings: { diff --git a/apps/sim/lib/slack-search/oauth-state.test.ts b/apps/sim/lib/slack-search/oauth-state.test.ts index 74f85cf2c95..3bf69859e8f 100644 --- a/apps/sim/lib/slack-search/oauth-state.test.ts +++ b/apps/sim/lib/slack-search/oauth-state.test.ts @@ -35,6 +35,14 @@ describe('Slack OAuth state', () => { expect(JSON.parse(value)).toEqual(attempt) expect([expiryMode, ttl, condition]).toEqual(['EX', 600, 'NX']) }) + it('stores only shared identity and revision without app secrets', async () => { + const { encryptedClientSecret, encryptedSigningSecret, ...common } = attempt + const shared = { ...common, sharedApp: { id: 'ASHARED', revision: 'env-revision' } } + await storeSlackSearchOAuthAttempt(shared) + expect(JSON.parse(redis.set.mock.calls[0][1])).toEqual(shared) + redis.eval.mockResolvedValueOnce(JSON.stringify(shared)) + await expect(consumeSlackSearchOAuthAttempt('state', principal)).resolves.toEqual(shared) + }) it('consumes only for the initiating admin session and rejects replay', async () => { redis.eval.mockResolvedValueOnce(JSON.stringify(attempt)) expect(await consumeSlackSearchOAuthAttempt('state', principal)).toEqual(attempt) diff --git a/apps/sim/lib/slack-search/oauth-state.ts b/apps/sim/lib/slack-search/oauth-state.ts index a1257f0582b..7074500722e 100644 --- a/apps/sim/lib/slack-search/oauth-state.ts +++ b/apps/sim/lib/slack-search/oauth-state.ts @@ -6,30 +6,38 @@ import { getRedisClient } from '@/lib/core/config/redis' import { OrchestrationError } from '@/lib/core/orchestration/types' const TTL_SECONDS = 600 -const attemptSchema = z.object({ - userId: z.string().min(1), - sessionId: z.string().min(1), - organizationId: z.string().min(1), - name: z.string().min(1), - description: z.string().min(1), - sharedApp: z.object({ id: z.string().min(1), revision: z.string().min(1) }).optional(), - memberApp: z.object({ appId: z.string().min(1), teamId: z.string().min(1) }).optional(), - clientId: z.string().min(1), - encryptedClientSecret: z.string().min(1), - encryptedSigningSecret: z.string().min(1), - redirectUri: z.string().url(), - createdAt: z.number(), - installation: z - .object({ - id: z.string(), - revision: z.string(), - credentialId: z.string(), - appId: z.string(), - teamId: z.string(), - appRevision: z.string().optional(), - }) - .optional(), -}) +const attemptSchema = z + .object({ + userId: z.string().min(1), + sessionId: z.string().min(1), + organizationId: z.string().min(1), + name: z.string().min(1), + description: z.string().min(1), + memberApp: z.object({ appId: z.string().min(1), teamId: z.string().min(1) }).optional(), + clientId: z.string().min(1), + redirectUri: z.string().url(), + createdAt: z.number(), + installation: z + .object({ + id: z.string(), + revision: z.string(), + credentialId: z.string(), + appId: z.string(), + teamId: z.string(), + appRevision: z.string().optional(), + }) + .optional(), + }) + .and( + z.union([ + z.object({ sharedApp: z.object({ id: z.string().min(1), revision: z.string().min(1) }) }), + z.object({ + sharedApp: z.undefined().optional(), + encryptedClientSecret: z.string().min(1), + encryptedSigningSecret: z.string().min(1), + }), + ]) + ) export type SlackSearchOAuthAttempt = z.infer const CONSUME = ` local value = redis.call('GET', KEYS[1]) diff --git a/apps/sim/lib/slack-search/shared-app-env.ts b/apps/sim/lib/slack-search/shared-app-env.ts new file mode 100644 index 00000000000..c1bebbcb1b3 --- /dev/null +++ b/apps/sim/lib/slack-search/shared-app-env.ts @@ -0,0 +1,24 @@ +import { sha256Hex } from '@sim/security/hash' +import { env } from '@/lib/core/config/env' + +/** Deployment-owned credentials; callers apply Search availability separately. */ +export function getSharedSlackSearchAppConfiguration(appId?: string) { + const id = env.SLACK_SEARCH_APP_ID + if (!id || (appId !== undefined && appId !== id)) return null + const clientId = env.SLACK_SEARCH_CLIENT_ID + const clientSecret = env.SLACK_SEARCH_CLIENT_SECRET + const signingSecret = env.SLACK_SEARCH_SIGNING_SECRET + if (!/^A[A-Z0-9]{1,199}$/.test(id) || !clientId || !clientSecret || !signingSecret) + throw new Error( + 'Configure SLACK_SEARCH_APP_ID, SLACK_SEARCH_CLIENT_ID, SLACK_SEARCH_CLIENT_SECRET, and SLACK_SEARCH_SIGNING_SECRET for the shared Slack app' + ) + return { + id, + kind: 'shared' as const, + organizationId: null, + clientId, + clientSecret, + signingSecret, + revision: sha256Hex(JSON.stringify([id, clientId, clientSecret, signingSecret])), + } +} diff --git a/apps/sim/lib/slack-search/shared-app.test.ts b/apps/sim/lib/slack-search/shared-app.test.ts index ce541a84e61..9bce83397a7 100644 --- a/apps/sim/lib/slack-search/shared-app.test.ts +++ b/apps/sim/lib/slack-search/shared-app.test.ts @@ -1,9 +1,18 @@ /** @vitest-environment node */ +import { db } from '@sim/db' import { slackApp, slackSearchInstallation } from '@sim/db/schema' import { queueTableRows, resetDbChainMock } from '@sim/testing' import { beforeEach, describe, expect, it, vi } from 'vitest' -const m = vi.hoisted(() => ({ flag: vi.fn(), env: { SLACK_SEARCH_APP_ID: 'A1' } })) +const m = vi.hoisted(() => ({ + flag: vi.fn(), + env: { + SLACK_SEARCH_APP_ID: 'A1', + SLACK_SEARCH_CLIENT_ID: 'client', + SLACK_SEARCH_CLIENT_SECRET: 'secret', + SLACK_SEARCH_SIGNING_SECRET: 'signing', + }, +})) vi.mock('@/lib/core/config/env', () => ({ env: m.env })) vi.mock('@/lib/core/config/feature-flags', () => ({ isFeatureEnabled: m.flag })) @@ -16,7 +25,12 @@ import { beforeEach(() => { vi.clearAllMocks() resetDbChainMock() - m.env.SLACK_SEARCH_APP_ID = 'A1' + Object.assign(m.env, { + SLACK_SEARCH_APP_ID: 'A1', + SLACK_SEARCH_CLIENT_ID: 'client', + SLACK_SEARCH_CLIENT_SECRET: 'secret', + SLACK_SEARCH_SIGNING_SECRET: 'signing', + }) m.flag.mockResolvedValue(true) }) describe('shared Slack rollout', () => { @@ -25,15 +39,22 @@ describe('shared Slack rollout', () => { if (flag) m.env.SLACK_SEARCH_APP_ID = '' await expect(readSharedSlackSearchApp()).resolves.toBeNull() }) - it.each( - [ - [], - [{ id: 'A1', kind: 'custom', organizationId: 'org' }], - [{ id: 'A1', kind: 'shared', organizationId: 'org' }], - ].map((rows) => ({ rows })) - )('fails closed for invalid registration %#', async ({ rows }) => { - queueTableRows(slackApp, rows) - await expect(readSharedSlackSearchApp()).rejects.toThrow('not registered') + it.each([ + 'SLACK_SEARCH_CLIENT_ID', + 'SLACK_SEARCH_CLIENT_SECRET', + 'SLACK_SEARCH_SIGNING_SECRET', + ] as const)('fails closed without %s', async (key) => { + m.env[key] = '' + await expect(readSharedSlackSearchApp()).rejects.toThrow('Configure SLACK_SEARCH_APP_ID') + }) + it('uses deployment credentials without requiring a registered database row', async () => { + await expect(readSharedSlackSearchApp()).resolves.toMatchObject({ + id: 'A1', + clientId: 'client', + clientSecret: 'secret', + signingSecret: 'signing', + }) + expect(db.select).not.toHaveBeenCalled() }) it('preserves custom bot handling while the shared flag is off', async () => { m.flag.mockResolvedValue(false) diff --git a/apps/sim/lib/slack-search/shared-app.ts b/apps/sim/lib/slack-search/shared-app.ts index 8b87c0e2c22..9431b4565ab 100644 --- a/apps/sim/lib/slack-search/shared-app.ts +++ b/apps/sim/lib/slack-search/shared-app.ts @@ -1,25 +1,24 @@ import { db } from '@sim/db' import { slackApp, slackSearchInstallation } from '@sim/db/schema' import { and, eq } from 'drizzle-orm' -import { env } from '@/lib/core/config/env' import { isFeatureEnabled } from '@/lib/core/config/feature-flags' import { OrchestrationError } from '@/lib/core/orchestration/types' +import { getSharedSlackSearchAppConfiguration } from '@/lib/slack-search/shared-app-env' /** Called only inside authorized installation/member operations; never returns secrets to a surface. */ export async function readSharedSlackSearchApp() { - if (!(await isFeatureEnabled('slack-search-shared-app')) || !env.SLACK_SEARCH_APP_ID) return null - const [app] = await db - .select() - .from(slackApp) - .where(eq(slackApp.id, env.SLACK_SEARCH_APP_ID)) - .limit(1) - if (!app || app.kind !== 'shared' || app.organizationId !== null) - throw new Error('The configured shared Slack Search app is not registered') - return app + if (!(await isFeatureEnabled('slack-search-shared-app'))) return null + return getSharedSlackSearchAppConfiguration() } /** Existing custom bots remain independent of the shared-app rollout. */ export async function requireSlackSearchAppAvailable(appId: string) { + const shared = getSharedSlackSearchAppConfiguration(appId) + if (shared?.id === appId) { + if (!(await readSharedSlackSearchApp())) + throw new OrchestrationError('forbidden', 'The shared Slack Search app is unavailable') + return + } const [app] = await db .select({ kind: slackApp.kind }) .from(slackApp) diff --git a/apps/sim/scripts/register-platform-slack-app.ts b/apps/sim/scripts/register-platform-slack-app.ts index 5e0376cbb09..185a7b9aa8a 100644 --- a/apps/sim/scripts/register-platform-slack-app.ts +++ b/apps/sim/scripts/register-platform-slack-app.ts @@ -10,17 +10,16 @@ const logger = createLogger('RegisterPlatformSlackApp') /** Explicit deployment preparation; never chooses an app identity from an unauthenticated event. */ async function main() { const appId = process.argv[2] - const searchApp = process.argv.includes('--search') - const clientId = searchApp ? process.env.SLACK_SEARCH_CLIENT_ID : process.env.SLACK_CLIENT_ID - const clientSecret = searchApp - ? process.env.SLACK_SEARCH_CLIENT_SECRET - : process.env.SLACK_CLIENT_SECRET - const signingSecret = searchApp - ? process.env.SLACK_SEARCH_SIGNING_SECRET - : process.env.SLACK_SIGNING_SECRET + if (process.argv.includes('--search')) + throw new Error( + 'Slack Search reads its app credentials directly from SLACK_SEARCH_* environment variables' + ) + const clientId = process.env.SLACK_CLIENT_ID + const clientSecret = process.env.SLACK_CLIENT_SECRET + const signingSecret = process.env.SLACK_SIGNING_SECRET if (!appId || !/^A[A-Z0-9]+$/.test(appId) || !clientId || !clientSecret || !signingSecret) throw new Error( - 'Supply a verified app ID and client/signing secrets. With --search use SLACK_SEARCH_CLIENT_ID, SLACK_SEARCH_CLIENT_SECRET, SLACK_SEARCH_SIGNING_SECRET; otherwise use SLACK_CLIENT_ID, SLACK_CLIENT_SECRET, SLACK_SIGNING_SECRET.' + 'Supply a verified app ID, SLACK_CLIENT_ID, SLACK_CLIENT_SECRET, and SLACK_SIGNING_SECRET.' ) const [client, signing] = await Promise.all([ encryptSecret(clientSecret), diff --git a/packages/db/migrations/0340_slack_shared_app_env.sql b/packages/db/migrations/0340_slack_shared_app_env.sql new file mode 100644 index 00000000000..0dc3df98e1d --- /dev/null +++ b/packages/db/migrations/0340_slack_shared_app_env.sql @@ -0,0 +1,4 @@ +ALTER TABLE "slack_app" ALTER COLUMN "client_id" DROP NOT NULL;--> statement-breakpoint +ALTER TABLE "slack_app" ALTER COLUMN "encrypted_client_secret" DROP NOT NULL;--> statement-breakpoint +ALTER TABLE "slack_app" ALTER COLUMN "encrypted_signing_secret" DROP NOT NULL;--> statement-breakpoint +ALTER TABLE "slack_app" ADD CONSTRAINT "slack_app_custom_credentials_check" CHECK ("slack_app"."kind" = 'shared' OR ("slack_app"."client_id" IS NOT NULL AND "slack_app"."encrypted_client_secret" IS NOT NULL AND "slack_app"."encrypted_signing_secret" IS NOT NULL)) NOT VALID; diff --git a/packages/db/migrations/meta/0340_snapshot.json b/packages/db/migrations/meta/0340_snapshot.json new file mode 100644 index 00000000000..d661144ddcb --- /dev/null +++ b/packages/db/migrations/meta/0340_snapshot.json @@ -0,0 +1,26301 @@ +{ + "id": "ae1f15e2-2725-434a-a1ac-9ea8a857868d", + "prevId": "1bdee29d-c55a-4de9-a0a3-03a6c6aa68aa", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.academy_certificate": { + "name": "academy_certificate", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "course_id": { + "name": "course_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "academy_cert_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "issued_at": { + "name": "issued_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "certificate_number": { + "name": "certificate_number", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "academy_certificate_user_id_idx": { + "name": "academy_certificate_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "academy_certificate_course_id_idx": { + "name": "academy_certificate_course_id_idx", + "columns": [ + { + "expression": "course_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "academy_certificate_user_course_unique": { + "name": "academy_certificate_user_course_unique", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "course_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "academy_certificate_status_idx": { + "name": "academy_certificate_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "academy_certificate_user_id_user_id_fk": { + "name": "academy_certificate_user_id_user_id_fk", + "tableFrom": "academy_certificate", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "academy_certificate_certificate_number_unique": { + "name": "academy_certificate_certificate_number_unique", + "nullsNotDistinct": false, + "columns": ["certificate_number"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.account": { + "name": "account", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "account_id": { + "name": "account_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "id_token": { + "name": "id_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "access_token_expires_at": { + "name": "access_token_expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "refresh_token_expires_at": { + "name": "refresh_token_expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "oauth_config": { + "name": "oauth_config", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "account_user_id_idx": { + "name": "account_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_account_on_account_id_provider_id": { + "name": "idx_account_on_account_id_provider_id", + "columns": [ + { + "expression": "account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "account_user_id_user_id_fk": { + "name": "account_user_id_user_id_fk", + "tableFrom": "account", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.api_key": { + "name": "api_key", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "key": { + "name": "key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "key_hash": { + "name": "key_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'personal'" + }, + "last_used": { + "name": "last_used", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "api_key_workspace_type_idx": { + "name": "api_key_workspace_type_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "api_key_user_type_idx": { + "name": "api_key_user_type_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "api_key_key_hash_idx": { + "name": "api_key_key_hash_idx", + "columns": [ + { + "expression": "key_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "api_key_user_id_user_id_fk": { + "name": "api_key_user_id_user_id_fk", + "tableFrom": "api_key", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "api_key_workspace_id_workspace_id_fk": { + "name": "api_key_workspace_id_workspace_id_fk", + "tableFrom": "api_key", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "api_key_created_by_user_id_fk": { + "name": "api_key_created_by_user_id_fk", + "tableFrom": "api_key", + "tableTo": "user", + "columnsFrom": ["created_by"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "api_key_key_unique": { + "name": "api_key_key_unique", + "nullsNotDistinct": false, + "columns": ["key"] + } + }, + "policies": {}, + "checkConstraints": { + "workspace_type_check": { + "name": "workspace_type_check", + "value": "(type = 'workspace' AND workspace_id IS NOT NULL) OR (type = 'personal' AND workspace_id IS NULL)" + } + }, + "isRLSEnabled": false + }, + "public.async_jobs": { + "name": "async_jobs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "started_at": { + "name": "started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "run_at": { + "name": "run_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "max_attempts": { + "name": "max_attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 3 + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "output": { + "name": "output", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "async_jobs_status_started_at_idx": { + "name": "async_jobs_status_started_at_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "started_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "async_jobs_status_completed_at_idx": { + "name": "async_jobs_status_completed_at_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "completed_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "async_jobs_schedule_pending_run_at_idx": { + "name": "async_jobs_schedule_pending_run_at_idx", + "columns": [ + { + "expression": "run_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"async_jobs\".\"type\" = 'schedule-execution' AND \"async_jobs\".\"status\" = 'pending'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "async_jobs_schedule_processing_started_at_idx": { + "name": "async_jobs_schedule_processing_started_at_idx", + "columns": [ + { + "expression": "started_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"async_jobs\".\"type\" = 'schedule-execution' AND \"async_jobs\".\"status\" = 'processing'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "async_jobs_schedule_unreconciled_terminal_idx": { + "name": "async_jobs_schedule_unreconciled_terminal_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"async_jobs\".\"type\" = 'schedule-execution' AND \"async_jobs\".\"status\" IN ('completed', 'failed', 'cancelled') AND COALESCE(\"async_jobs\".\"metadata\" ->> 'scheduleReconciled', 'false') <> 'true'", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.audit_log": { + "name": "audit_log", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "actor_id": { + "name": "actor_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "resource_type": { + "name": "resource_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "resource_id": { + "name": "resource_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "actor_name": { + "name": "actor_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "actor_email": { + "name": "actor_email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "resource_name": { + "name": "resource_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'" + }, + "ip_address": { + "name": "ip_address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_agent": { + "name": "user_agent", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "audit_log_workspace_created_idx": { + "name": "audit_log_workspace_created_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "audit_log_workspace_created_at_id_idx": { + "name": "audit_log_workspace_created_at_id_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "date_trunc('milliseconds', \"created_at\")", + "asc": true, + "isExpression": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "audit_log_actor_created_idx": { + "name": "audit_log_actor_created_idx", + "columns": [ + { + "expression": "actor_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "audit_log_resource_idx": { + "name": "audit_log_resource_idx", + "columns": [ + { + "expression": "resource_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "resource_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "audit_log_action_idx": { + "name": "audit_log_action_idx", + "columns": [ + { + "expression": "action", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "audit_log_workspace_id_workspace_id_fk": { + "name": "audit_log_workspace_id_workspace_id_fk", + "tableFrom": "audit_log", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "audit_log_actor_id_user_id_fk": { + "name": "audit_log_actor_id_user_id_fk", + "tableFrom": "audit_log", + "tableTo": "user", + "columnsFrom": ["actor_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.background_work_status": { + "name": "background_work_status", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "kind": { + "name": "kind", + "type": "background_work_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "background_work_status_value", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "started_at": { + "name": "started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "background_work_status_workspace_status_idx": { + "name": "background_work_status_workspace_status_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "background_work_status_workflow_status_idx": { + "name": "background_work_status_workflow_status_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "background_work_status_meta_child_ws_idx": { + "name": "background_work_status_meta_child_ws_idx", + "columns": [ + { + "expression": "(\"metadata\" ->> 'childWorkspaceId')", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "background_work_status_meta_other_ws_idx": { + "name": "background_work_status_meta_other_ws_idx", + "columns": [ + { + "expression": "(\"metadata\" ->> 'otherWorkspaceId')", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "background_work_status_workspace_id_workspace_id_fk": { + "name": "background_work_status_workspace_id_workspace_id_fk", + "tableFrom": "background_work_status", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "background_work_status_workflow_id_workflow_id_fk": { + "name": "background_work_status_workflow_id_workflow_id_fk", + "tableFrom": "background_work_status", + "tableTo": "workflow", + "columnsFrom": ["workflow_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.chat": { + "name": "chat", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "identifier": { + "name": "identifier", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "customizations": { + "name": "customizations", + "type": "json", + "primaryKey": false, + "notNull": false, + "default": "'{}'" + }, + "auth_type": { + "name": "auth_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'public'" + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "allowed_emails": { + "name": "allowed_emails", + "type": "json", + "primaryKey": false, + "notNull": false, + "default": "'[]'" + }, + "output_configs": { + "name": "output_configs", + "type": "json", + "primaryKey": false, + "notNull": false, + "default": "'[]'" + }, + "include_thinking": { + "name": "include_thinking", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "include_tool_calls": { + "name": "include_tool_calls", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "identifier_idx": { + "name": "identifier_idx", + "columns": [ + { + "expression": "identifier", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"chat\".\"archived_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "chat_archived_at_partial_idx": { + "name": "chat_archived_at_partial_idx", + "columns": [ + { + "expression": "archived_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"chat\".\"archived_at\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_chat_on_workflow_id_archived_at": { + "name": "idx_chat_on_workflow_id_archived_at", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "archived_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "chat_workflow_id_workflow_id_fk": { + "name": "chat_workflow_id_workflow_id_fk", + "tableFrom": "chat", + "tableTo": "workflow", + "columnsFrom": ["workflow_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "chat_user_id_user_id_fk": { + "name": "chat_user_id_user_id_fk", + "tableFrom": "chat", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.copilot_async_tool_calls": { + "name": "copilot_async_tool_calls", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "run_id": { + "name": "run_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "checkpoint_id": { + "name": "checkpoint_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "tool_call_id": { + "name": "tool_call_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tool_name": { + "name": "tool_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "args": { + "name": "args", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'" + }, + "status": { + "name": "status", + "type": "copilot_async_tool_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "result": { + "name": "result", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "permission_decision": { + "name": "permission_decision", + "type": "copilot_tool_permission_decision", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "permission_decided_at": { + "name": "permission_decided_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "claimed_at": { + "name": "claimed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "claimed_by": { + "name": "claimed_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "copilot_async_tool_calls_run_id_idx": { + "name": "copilot_async_tool_calls_run_id_idx", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_async_tool_calls_checkpoint_id_idx": { + "name": "copilot_async_tool_calls_checkpoint_id_idx", + "columns": [ + { + "expression": "checkpoint_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_async_tool_calls_status_idx": { + "name": "copilot_async_tool_calls_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_async_tool_calls_run_status_idx": { + "name": "copilot_async_tool_calls_run_status_idx", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_async_tool_calls_tool_call_id_unique": { + "name": "copilot_async_tool_calls_tool_call_id_unique", + "columns": [ + { + "expression": "tool_call_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "copilot_async_tool_calls_run_id_copilot_runs_id_fk": { + "name": "copilot_async_tool_calls_run_id_copilot_runs_id_fk", + "tableFrom": "copilot_async_tool_calls", + "tableTo": "copilot_runs", + "columnsFrom": ["run_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "copilot_async_tool_calls_checkpoint_id_copilot_run_checkpoints_id_fk": { + "name": "copilot_async_tool_calls_checkpoint_id_copilot_run_checkpoints_id_fk", + "tableFrom": "copilot_async_tool_calls", + "tableTo": "copilot_run_checkpoints", + "columnsFrom": ["checkpoint_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.copilot_chats": { + "name": "copilot_chats", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "type": { + "name": "type", + "type": "chat_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'copilot'" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "model": { + "name": "model", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'claude-3-7-sonnet-latest'" + }, + "conversation_id": { + "name": "conversation_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "external_conversation_key": { + "name": "external_conversation_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "external_conversation_metadata": { + "name": "external_conversation_metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "preview_yaml": { + "name": "preview_yaml", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "plan_artifact": { + "name": "plan_artifact", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "config": { + "name": "config", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "resources": { + "name": "resources", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'" + }, + "auto_allowed_tools": { + "name": "auto_allowed_tools", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'" + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "pinned": { + "name": "pinned", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "copilot_chats_organization_id_idx": { + "name": "copilot_chats_organization_id_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_chats_external_conversation_unique": { + "name": "copilot_chats_external_conversation_unique", + "columns": [ + { + "expression": "external_conversation_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"copilot_chats\".\"external_conversation_key\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_chats_user_org_created_idx": { + "name": "copilot_chats_user_org_created_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_chats_user_id_idx": { + "name": "copilot_chats_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_chats_workflow_id_idx": { + "name": "copilot_chats_workflow_id_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_chats_user_workflow_idx": { + "name": "copilot_chats_user_workflow_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_chats_user_workspace_idx": { + "name": "copilot_chats_user_workspace_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_chats_created_at_idx": { + "name": "copilot_chats_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_chats_updated_at_idx": { + "name": "copilot_chats_updated_at_idx", + "columns": [ + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_chats_workspace_created_at_id_idx": { + "name": "copilot_chats_workspace_created_at_id_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "date_trunc('milliseconds', \"created_at\")", + "asc": true, + "isExpression": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_chats_user_workspace_deleted_partial_idx": { + "name": "copilot_chats_user_workspace_deleted_partial_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"copilot_chats\".\"deleted_at\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "copilot_chats_user_id_user_id_fk": { + "name": "copilot_chats_user_id_user_id_fk", + "tableFrom": "copilot_chats", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "copilot_chats_workflow_id_workflow_id_fk": { + "name": "copilot_chats_workflow_id_workflow_id_fk", + "tableFrom": "copilot_chats", + "tableTo": "workflow", + "columnsFrom": ["workflow_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "copilot_chats_workspace_id_workspace_id_fk": { + "name": "copilot_chats_workspace_id_workspace_id_fk", + "tableFrom": "copilot_chats", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "copilot_chats_organization_id_organization_id_fk": { + "name": "copilot_chats_organization_id_organization_id_fk", + "tableFrom": "copilot_chats", + "tableTo": "organization", + "columnsFrom": ["organization_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "copilot_chats_owner_check": { + "name": "copilot_chats_owner_check", + "value": "num_nonnulls(\"copilot_chats\".\"workspace_id\", \"copilot_chats\".\"organization_id\") <= 1" + }, + "copilot_chats_organization_workflow_check": { + "name": "copilot_chats_organization_workflow_check", + "value": "\"copilot_chats\".\"organization_id\" IS NULL OR \"copilot_chats\".\"workflow_id\" IS NULL" + } + }, + "isRLSEnabled": false + }, + "public.copilot_feedback": { + "name": "copilot_feedback", + "schema": "", + "columns": { + "feedback_id": { + "name": "feedback_id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "chat_id": { + "name": "chat_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_query": { + "name": "user_query", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "agent_response": { + "name": "agent_response", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "is_positive": { + "name": "is_positive", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "feedback": { + "name": "feedback", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "workflow_yaml": { + "name": "workflow_yaml", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "copilot_feedback_user_id_idx": { + "name": "copilot_feedback_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_feedback_chat_id_idx": { + "name": "copilot_feedback_chat_id_idx", + "columns": [ + { + "expression": "chat_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_feedback_user_chat_idx": { + "name": "copilot_feedback_user_chat_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "chat_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_feedback_is_positive_idx": { + "name": "copilot_feedback_is_positive_idx", + "columns": [ + { + "expression": "is_positive", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_feedback_created_at_idx": { + "name": "copilot_feedback_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "copilot_feedback_user_id_user_id_fk": { + "name": "copilot_feedback_user_id_user_id_fk", + "tableFrom": "copilot_feedback", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "copilot_feedback_chat_id_copilot_chats_id_fk": { + "name": "copilot_feedback_chat_id_copilot_chats_id_fk", + "tableFrom": "copilot_feedback", + "tableTo": "copilot_chats", + "columnsFrom": ["chat_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.copilot_messages": { + "name": "copilot_messages", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "chat_id": { + "name": "chat_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "message_id": { + "name": "message_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "content": { + "name": "content", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "stream_id": { + "name": "stream_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "parent_message_id": { + "name": "parent_message_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "model": { + "name": "model", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tokens_in": { + "name": "tokens_in", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "tokens_out": { + "name": "tokens_out", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "seq": { + "name": "seq", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "copilot_messages_chat_message_unique": { + "name": "copilot_messages_chat_message_unique", + "columns": [ + { + "expression": "chat_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "message_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_messages_chat_created_at_idx": { + "name": "copilot_messages_chat_created_at_idx", + "columns": [ + { + "expression": "chat_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"copilot_messages\".\"deleted_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_messages_chat_seq_idx": { + "name": "copilot_messages_chat_seq_idx", + "columns": [ + { + "expression": "chat_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "seq", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"copilot_messages\".\"deleted_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_messages_chat_stream_idx": { + "name": "copilot_messages_chat_stream_idx", + "columns": [ + { + "expression": "chat_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "stream_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"copilot_messages\".\"stream_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_messages_user_created_at_idx": { + "name": "copilot_messages_user_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "chat_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "message_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"copilot_messages\".\"role\" = 'user' AND \"copilot_messages\".\"deleted_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "copilot_messages_chat_id_copilot_chats_id_fk": { + "name": "copilot_messages_chat_id_copilot_chats_id_fk", + "tableFrom": "copilot_messages", + "tableTo": "copilot_chats", + "columnsFrom": ["chat_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.copilot_run_checkpoints": { + "name": "copilot_run_checkpoints", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "run_id": { + "name": "run_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "pending_tool_call_id": { + "name": "pending_tool_call_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "conversation_snapshot": { + "name": "conversation_snapshot", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'" + }, + "agent_state": { + "name": "agent_state", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'" + }, + "provider_request": { + "name": "provider_request", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "copilot_run_checkpoints_run_id_idx": { + "name": "copilot_run_checkpoints_run_id_idx", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_run_checkpoints_pending_tool_call_id_idx": { + "name": "copilot_run_checkpoints_pending_tool_call_id_idx", + "columns": [ + { + "expression": "pending_tool_call_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_run_checkpoints_run_pending_tool_unique": { + "name": "copilot_run_checkpoints_run_pending_tool_unique", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "pending_tool_call_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "copilot_run_checkpoints_run_id_copilot_runs_id_fk": { + "name": "copilot_run_checkpoints_run_id_copilot_runs_id_fk", + "tableFrom": "copilot_run_checkpoints", + "tableTo": "copilot_runs", + "columnsFrom": ["run_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.copilot_runs": { + "name": "copilot_runs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "execution_id": { + "name": "execution_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "parent_run_id": { + "name": "parent_run_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "chat_id": { + "name": "chat_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "stream_id": { + "name": "stream_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "agent": { + "name": "agent", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "model": { + "name": "model", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "copilot_run_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "request_context": { + "name": "request_context", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'" + }, + "started_at": { + "name": "started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "copilot_runs_execution_id_idx": { + "name": "copilot_runs_execution_id_idx", + "columns": [ + { + "expression": "execution_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_runs_parent_run_id_idx": { + "name": "copilot_runs_parent_run_id_idx", + "columns": [ + { + "expression": "parent_run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_runs_chat_id_idx": { + "name": "copilot_runs_chat_id_idx", + "columns": [ + { + "expression": "chat_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_runs_user_id_idx": { + "name": "copilot_runs_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_runs_workflow_id_idx": { + "name": "copilot_runs_workflow_id_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_runs_workspace_id_idx": { + "name": "copilot_runs_workspace_id_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_runs_status_idx": { + "name": "copilot_runs_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_runs_chat_execution_idx": { + "name": "copilot_runs_chat_execution_idx", + "columns": [ + { + "expression": "chat_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "execution_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_runs_execution_started_at_idx": { + "name": "copilot_runs_execution_started_at_idx", + "columns": [ + { + "expression": "execution_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "started_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_runs_workspace_completed_at_id_idx": { + "name": "copilot_runs_workspace_completed_at_id_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "date_trunc('milliseconds', \"completed_at\")", + "asc": true, + "isExpression": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_runs_stream_id_unique": { + "name": "copilot_runs_stream_id_unique", + "columns": [ + { + "expression": "stream_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "copilot_runs_chat_id_copilot_chats_id_fk": { + "name": "copilot_runs_chat_id_copilot_chats_id_fk", + "tableFrom": "copilot_runs", + "tableTo": "copilot_chats", + "columnsFrom": ["chat_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "copilot_runs_user_id_user_id_fk": { + "name": "copilot_runs_user_id_user_id_fk", + "tableFrom": "copilot_runs", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "copilot_runs_workflow_id_workflow_id_fk": { + "name": "copilot_runs_workflow_id_workflow_id_fk", + "tableFrom": "copilot_runs", + "tableTo": "workflow", + "columnsFrom": ["workflow_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "copilot_runs_workspace_id_workspace_id_fk": { + "name": "copilot_runs_workspace_id_workspace_id_fk", + "tableFrom": "copilot_runs", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.copilot_workflow_read_hashes": { + "name": "copilot_workflow_read_hashes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "chat_id": { + "name": "chat_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "hash": { + "name": "hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "copilot_workflow_read_hashes_chat_id_idx": { + "name": "copilot_workflow_read_hashes_chat_id_idx", + "columns": [ + { + "expression": "chat_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_workflow_read_hashes_workflow_id_idx": { + "name": "copilot_workflow_read_hashes_workflow_id_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "copilot_workflow_read_hashes_chat_workflow_unique": { + "name": "copilot_workflow_read_hashes_chat_workflow_unique", + "columns": [ + { + "expression": "chat_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "copilot_workflow_read_hashes_chat_id_copilot_chats_id_fk": { + "name": "copilot_workflow_read_hashes_chat_id_copilot_chats_id_fk", + "tableFrom": "copilot_workflow_read_hashes", + "tableTo": "copilot_chats", + "columnsFrom": ["chat_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "copilot_workflow_read_hashes_workflow_id_workflow_id_fk": { + "name": "copilot_workflow_read_hashes_workflow_id_workflow_id_fk", + "tableFrom": "copilot_workflow_read_hashes", + "tableTo": "workflow", + "columnsFrom": ["workflow_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.credential": { + "name": "credential", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "slack_app_id": { + "name": "slack_app_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "type": { + "name": "type", + "type": "credential_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "display_name": { + "name": "display_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "unredacted": { + "name": "unredacted", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "account_id": { + "name": "account_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "env_key": { + "name": "env_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "env_owner_user_id": { + "name": "env_owner_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "encrypted_service_account_key": { + "name": "encrypted_service_account_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "encrypted_personal_token": { + "name": "encrypted_personal_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "authorization_app_id": { + "name": "authorization_app_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "credential_group_enrollment_id": { + "name": "credential_group_enrollment_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "credential_group_option_id": { + "name": "credential_group_option_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "mcp_server_id": { + "name": "mcp_server_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "mcp_oauth_config_version": { + "name": "mcp_oauth_config_version", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "managed_oauth_scope_version": { + "name": "managed_oauth_scope_version", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "provider_subject_id": { + "name": "provider_subject_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "provider_tenant_id": { + "name": "provider_tenant_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "managed_oauth_status": { + "name": "managed_oauth_status", + "type": "managed_oauth_credential_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "granted_scopes": { + "name": "granted_scopes", + "type": "text[]", + "primaryKey": false, + "notNull": false + }, + "provider_metadata": { + "name": "provider_metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "encrypted_oauth_token_set": { + "name": "encrypted_oauth_token_set", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "mcp_tools": { + "name": "mcp_tools", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "mcp_tools_refreshed_at": { + "name": "mcp_tools_refreshed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "granted_at": { + "name": "granted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "revoked_at": { + "name": "revoked_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "access_token_expires_at": { + "name": "access_token_expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "refresh_token_expires_at": { + "name": "refresh_token_expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_refreshed_at": { + "name": "last_refreshed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "credential_organization_id_idx": { + "name": "credential_organization_id_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "credential_organization_account_unique": { + "name": "credential_organization_account_unique", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"credential\".\"account_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "credential_org_personal_token_unique": { + "name": "credential_org_personal_token_unique", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_by", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider_tenant_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider_subject_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"credential\".\"type\" = 'personal_token'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "credential_workspace_id_idx": { + "name": "credential_workspace_id_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "credential_type_idx": { + "name": "credential_type_idx", + "columns": [ + { + "expression": "type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "credential_provider_id_idx": { + "name": "credential_provider_id_idx", + "columns": [ + { + "expression": "provider_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "credential_account_id_idx": { + "name": "credential_account_id_idx", + "columns": [ + { + "expression": "account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "credential_env_owner_user_id_idx": { + "name": "credential_env_owner_user_id_idx", + "columns": [ + { + "expression": "env_owner_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "credential_group_enrollment_idx": { + "name": "credential_group_enrollment_idx", + "columns": [ + { + "expression": "credential_group_enrollment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "credential_mcp_server_idx": { + "name": "credential_mcp_server_idx", + "columns": [ + { + "expression": "mcp_server_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "credential_group_option_unique": { + "name": "credential_group_option_unique", + "columns": [ + { + "expression": "credential_group_enrollment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "credential_group_option_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"credential\".\"type\" = 'managed_oauth'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "credential_managed_mcp_enrollment_server_unique": { + "name": "credential_managed_mcp_enrollment_server_unique", + "columns": [ + { + "expression": "credential_group_enrollment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "mcp_server_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"credential\".\"type\" = 'managed_mcp'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "credential_workspace_account_unique": { + "name": "credential_workspace_account_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "account_id IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "credential_workspace_env_unique": { + "name": "credential_workspace_env_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "env_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "type = 'env_workspace'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "credential_workspace_personal_env_unique": { + "name": "credential_workspace_personal_env_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "env_key", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "env_owner_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "type = 'env_personal'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "credential_personal_token_identity_unique": { + "name": "credential_personal_token_identity_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_by", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider_tenant_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider_subject_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "type = 'personal_token'", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "credential_workspace_id_workspace_id_fk": { + "name": "credential_workspace_id_workspace_id_fk", + "tableFrom": "credential", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "credential_organization_id_organization_id_fk": { + "name": "credential_organization_id_organization_id_fk", + "tableFrom": "credential", + "tableTo": "organization", + "columnsFrom": ["organization_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "credential_slack_app_id_slack_app_id_fk": { + "name": "credential_slack_app_id_slack_app_id_fk", + "tableFrom": "credential", + "tableTo": "slack_app", + "columnsFrom": ["slack_app_id"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + }, + "credential_account_id_account_id_fk": { + "name": "credential_account_id_account_id_fk", + "tableFrom": "credential", + "tableTo": "account", + "columnsFrom": ["account_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "credential_env_owner_user_id_user_id_fk": { + "name": "credential_env_owner_user_id_user_id_fk", + "tableFrom": "credential", + "tableTo": "user", + "columnsFrom": ["env_owner_user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "credential_credential_group_enrollment_id_credential_group_enrollment_id_fk": { + "name": "credential_credential_group_enrollment_id_credential_group_enrollment_id_fk", + "tableFrom": "credential", + "tableTo": "credential_group_enrollment", + "columnsFrom": ["credential_group_enrollment_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "credential_mcp_server_id_mcp_servers_id_fk": { + "name": "credential_mcp_server_id_mcp_servers_id_fk", + "tableFrom": "credential", + "tableTo": "mcp_servers", + "columnsFrom": ["mcp_server_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "credential_created_by_user_id_fk": { + "name": "credential_created_by_user_id_fk", + "tableFrom": "credential", + "tableTo": "user", + "columnsFrom": ["created_by"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "credential_owner_check": { + "name": "credential_owner_check", + "value": "num_nonnulls(\"credential\".\"workspace_id\", \"credential\".\"organization_id\") = 1" + }, + "credential_organization_type_check": { + "name": "credential_organization_type_check", + "value": "\"credential\".\"organization_id\" IS NULL OR \"credential\".\"type\" IN ('oauth', 'managed_oauth', 'managed_mcp', 'service_account', 'personal_token')" + }, + "credential_personal_token_source_check": { + "name": "credential_personal_token_source_check", + "value": "(type::text <> 'personal_token') OR (\n created_by IS NOT NULL\n AND provider_id IS NOT NULL\n AND provider_id = 'gitlab'\n AND provider_subject_id IS NOT NULL\n AND provider_tenant_id IS NOT NULL\n AND encrypted_personal_token IS NOT NULL\n AND granted_scopes IS NOT NULL\n AND cardinality(granted_scopes) > 0\n AND account_id IS NULL\n AND env_key IS NULL\n AND env_owner_user_id IS NULL\n AND authorization_app_id IS NULL\n AND encrypted_oauth_token_set IS NULL\n AND encrypted_service_account_key IS NULL\n AND unredacted = false\n )" + }, + "credential_oauth_source_check": { + "name": "credential_oauth_source_check", + "value": "(type <> 'oauth') OR (account_id IS NOT NULL AND provider_id IS NOT NULL)" + }, + "credential_managed_oauth_source_check": { + "name": "credential_managed_oauth_source_check", + "value": "(type::text <> 'managed_oauth') OR (\n account_id IS NULL\n AND provider_id IS NOT NULL\n AND authorization_app_id IS NOT NULL\n AND provider_subject_id IS NOT NULL\n AND managed_oauth_status IS NOT NULL\n AND granted_scopes IS NOT NULL\n AND encrypted_oauth_token_set IS NOT NULL\n AND granted_at IS NOT NULL\n )" + }, + "credential_managed_oauth_group_binding_check": { + "name": "credential_managed_oauth_group_binding_check", + "value": "(type::text <> 'managed_oauth') OR (\n credential_group_enrollment_id IS NOT NULL\n AND credential_group_option_id IS NOT NULL\n AND managed_oauth_scope_version IS NOT NULL\n AND managed_oauth_scope_version > 0\n )" + }, + "credential_managed_mcp_source_check": { + "name": "credential_managed_mcp_source_check", + "value": "(type::text <> 'managed_mcp') OR (\n id LIKE 'mcp-cg-%'\n AND account_id IS NULL\n AND provider_id IS NULL\n AND authorization_app_id IS NULL\n AND credential_group_enrollment_id IS NOT NULL\n AND credential_group_option_id IS NULL\n AND mcp_server_id IS NOT NULL\n AND managed_oauth_status IS NOT NULL\n AND (managed_oauth_status <> 'active' OR (\n encrypted_oauth_token_set IS NOT NULL\n AND mcp_tools IS NOT NULL\n ))\n AND granted_at IS NOT NULL\n AND managed_oauth_scope_version IS NULL\n AND provider_subject_id IS NULL\n AND provider_tenant_id IS NULL\n AND granted_scopes IS NULL\n AND provider_metadata IS NULL\n AND created_by IS NULL\n AND env_key IS NULL\n AND env_owner_user_id IS NULL\n AND encrypted_service_account_key IS NULL\n AND unredacted = false\n )" + }, + "credential_creator_source_check": { + "name": "credential_creator_source_check", + "value": "(type::text = 'managed_mcp') OR created_by IS NOT NULL" + }, + "credential_workspace_env_source_check": { + "name": "credential_workspace_env_source_check", + "value": "(type <> 'env_workspace') OR (env_key IS NOT NULL AND env_owner_user_id IS NULL)" + }, + "credential_personal_env_source_check": { + "name": "credential_personal_env_source_check", + "value": "(type <> 'env_personal') OR (env_key IS NOT NULL AND env_owner_user_id IS NOT NULL)" + } + }, + "isRLSEnabled": false + }, + "public.credential_group": { + "name": "credential_group", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "public_id": { + "name": "public_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "options": { + "name": "options", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "encrypted_provider_configuration": { + "name": "encrypted_provider_configuration", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "credential_group_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "credential_group_organization_id_idx": { + "name": "credential_group_organization_id_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "credential_group_organization_unique": { + "name": "credential_group_organization_unique", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "credential_group_public_id_unique": { + "name": "credential_group_public_id_unique", + "columns": [ + { + "expression": "public_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "credential_group_workspace_unique": { + "name": "credential_group_workspace_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "credential_group_workspace_id_workspace_id_fk": { + "name": "credential_group_workspace_id_workspace_id_fk", + "tableFrom": "credential_group", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "credential_group_organization_id_organization_id_fk": { + "name": "credential_group_organization_id_organization_id_fk", + "tableFrom": "credential_group", + "tableTo": "organization", + "columnsFrom": ["organization_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "credential_group_created_by_user_id_fk": { + "name": "credential_group_created_by_user_id_fk", + "tableFrom": "credential_group", + "tableTo": "user", + "columnsFrom": ["created_by"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "credential_group_owner_check": { + "name": "credential_group_owner_check", + "value": "num_nonnulls(\"credential_group\".\"workspace_id\", \"credential_group\".\"organization_id\") = 1" + } + }, + "isRLSEnabled": false + }, + "public.credential_group_enrollment": { + "name": "credential_group_enrollment", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "credential_group_id": { + "name": "credential_group_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "credential_group_enrollment_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'invited'" + }, + "invitation_token_hash": { + "name": "invitation_token_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "invitation_expires_at": { + "name": "invitation_expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "invited_at": { + "name": "invited_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "sent_at": { + "name": "sent_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "revoked_at": { + "name": "revoked_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_delivery_error": { + "name": "last_delivery_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "credential_group_enrollment_group_user_unique": { + "name": "credential_group_enrollment_group_user_unique", + "columns": [ + { + "expression": "credential_group_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"credential_group_enrollment\".\"user_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "credential_group_enrollment_user_id_idx": { + "name": "credential_group_enrollment_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "credential_group_enrollment_group_email_unique": { + "name": "credential_group_enrollment_group_email_unique", + "columns": [ + { + "expression": "credential_group_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "email", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "credential_group_enrollment_invitation_token_hash_unique": { + "name": "credential_group_enrollment_invitation_token_hash_unique", + "columns": [ + { + "expression": "invitation_token_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "credential_group_enrollment_group_status_idx": { + "name": "credential_group_enrollment_group_status_idx", + "columns": [ + { + "expression": "credential_group_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "credential_group_enrollment_group_invited_at_id_idx": { + "name": "credential_group_enrollment_group_invited_at_id_idx", + "columns": [ + { + "expression": "credential_group_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "invited_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "credential_group_enrollment_credential_group_id_credential_group_id_fk": { + "name": "credential_group_enrollment_credential_group_id_credential_group_id_fk", + "tableFrom": "credential_group_enrollment", + "tableTo": "credential_group", + "columnsFrom": ["credential_group_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "credential_group_enrollment_user_id_user_id_fk": { + "name": "credential_group_enrollment_user_id_user_id_fk", + "tableFrom": "credential_group_enrollment", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "credential_group_enrollment_created_by_user_id_fk": { + "name": "credential_group_enrollment_created_by_user_id_fk", + "tableFrom": "credential_group_enrollment", + "tableTo": "user", + "columnsFrom": ["created_by"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "credential_group_enrollment_normalized_email_check": { + "name": "credential_group_enrollment_normalized_email_check", + "value": "\"credential_group_enrollment\".\"email\" = lower(btrim(\"credential_group_enrollment\".\"email\")) AND length(\"credential_group_enrollment\".\"email\") BETWEEN 3 AND 320" + }, + "credential_group_enrollment_invitation_token_hash_length_check": { + "name": "credential_group_enrollment_invitation_token_hash_length_check", + "value": "length(\"credential_group_enrollment\".\"invitation_token_hash\") = 64" + } + }, + "isRLSEnabled": false + }, + "public.credential_member": { + "name": "credential_member", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "credential_id": { + "name": "credential_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "credential_member_role", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'member'" + }, + "status": { + "name": "status", + "type": "credential_member_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "joined_at": { + "name": "joined_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "invited_by": { + "name": "invited_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "credential_member_user_id_idx": { + "name": "credential_member_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "credential_member_role_idx": { + "name": "credential_member_role_idx", + "columns": [ + { + "expression": "role", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "credential_member_status_idx": { + "name": "credential_member_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "credential_member_unique": { + "name": "credential_member_unique", + "columns": [ + { + "expression": "credential_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "credential_member_credential_id_credential_id_fk": { + "name": "credential_member_credential_id_credential_id_fk", + "tableFrom": "credential_member", + "tableTo": "credential", + "columnsFrom": ["credential_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "credential_member_user_id_user_id_fk": { + "name": "credential_member_user_id_user_id_fk", + "tableFrom": "credential_member", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "credential_member_invited_by_user_id_fk": { + "name": "credential_member_invited_by_user_id_fk", + "tableFrom": "credential_member", + "tableTo": "user", + "columnsFrom": ["invited_by"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.custom_block": { + "name": "custom_block", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "icon_url": { + "name": "icon_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "inputs": { + "name": "inputs", + "type": "json", + "primaryKey": false, + "notNull": false + }, + "outputs": { + "name": "outputs", + "type": "json", + "primaryKey": false, + "notNull": false + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "trace_child_runs": { + "name": "trace_child_runs", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "custom_block_organization_id_idx": { + "name": "custom_block_organization_id_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "custom_block_workflow_id_idx": { + "name": "custom_block_workflow_id_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "custom_block_organization_type_unique": { + "name": "custom_block_organization_type_unique", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "custom_block_organization_id_organization_id_fk": { + "name": "custom_block_organization_id_organization_id_fk", + "tableFrom": "custom_block", + "tableTo": "organization", + "columnsFrom": ["organization_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "custom_block_workflow_id_workflow_id_fk": { + "name": "custom_block_workflow_id_workflow_id_fk", + "tableFrom": "custom_block", + "tableTo": "workflow", + "columnsFrom": ["workflow_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "custom_block_created_by_user_id_fk": { + "name": "custom_block_created_by_user_id_fk", + "tableFrom": "custom_block", + "tableTo": "user", + "columnsFrom": ["created_by"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.custom_tools": { + "name": "custom_tools", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "schema": { + "name": "schema", + "type": "json", + "primaryKey": false, + "notNull": true + }, + "code": { + "name": "code", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "custom_tools_workspace_id_idx": { + "name": "custom_tools_workspace_id_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "custom_tools_workspace_title_unique": { + "name": "custom_tools_workspace_title_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "title", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "custom_tools_workspace_id_workspace_id_fk": { + "name": "custom_tools_workspace_id_workspace_id_fk", + "tableFrom": "custom_tools", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "custom_tools_user_id_user_id_fk": { + "name": "custom_tools_user_id_user_id_fk", + "tableFrom": "custom_tools", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.data_drain_runs": { + "name": "data_drain_runs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "drain_id": { + "name": "drain_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "data_drain_run_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "trigger": { + "name": "trigger", + "type": "data_drain_run_trigger", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "started_at": { + "name": "started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "finished_at": { + "name": "finished_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "rows_exported": { + "name": "rows_exported", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "bytes_written": { + "name": "bytes_written", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "cursor_before": { + "name": "cursor_before", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "cursor_after": { + "name": "cursor_after", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "locators": { + "name": "locators", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + } + }, + "indexes": { + "data_drain_runs_drain_started_idx": { + "name": "data_drain_runs_drain_started_idx", + "columns": [ + { + "expression": "drain_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "started_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "data_drain_runs_drain_id_data_drains_id_fk": { + "name": "data_drain_runs_drain_id_data_drains_id_fk", + "tableFrom": "data_drain_runs", + "tableTo": "data_drains", + "columnsFrom": ["drain_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.data_drains": { + "name": "data_drains", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "data_drain_source", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "destination_type": { + "name": "destination_type", + "type": "data_drain_destination", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "destination_config": { + "name": "destination_config", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "destination_credentials": { + "name": "destination_credentials", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "schedule_cadence": { + "name": "schedule_cadence", + "type": "data_drain_cadence", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "cursor": { + "name": "cursor", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "last_run_at": { + "name": "last_run_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_success_at": { + "name": "last_success_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "data_drains_org_idx": { + "name": "data_drains_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "data_drains_due_idx": { + "name": "data_drains_due_idx", + "columns": [ + { + "expression": "enabled", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "last_run_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "data_drains_org_name_unique": { + "name": "data_drains_org_name_unique", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "data_drains_organization_id_organization_id_fk": { + "name": "data_drains_organization_id_organization_id_fk", + "tableFrom": "data_drains", + "tableTo": "organization", + "columnsFrom": ["organization_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "data_drains_created_by_user_id_fk": { + "name": "data_drains_created_by_user_id_fk", + "tableFrom": "data_drains", + "tableTo": "user", + "columnsFrom": ["created_by"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.docs_embeddings": { + "name": "docs_embeddings", + "schema": "", + "columns": { + "chunk_id": { + "name": "chunk_id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "chunk_text": { + "name": "chunk_text", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_document": { + "name": "source_document", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_link": { + "name": "source_link", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "header_text": { + "name": "header_text", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "header_level": { + "name": "header_level", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "token_count": { + "name": "token_count", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "embedding": { + "name": "embedding", + "type": "vector(1536)", + "primaryKey": false, + "notNull": true + }, + "embedding_model": { + "name": "embedding_model", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'text-embedding-3-small'" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'" + }, + "chunk_text_tsv": { + "name": "chunk_text_tsv", + "type": "tsvector", + "primaryKey": false, + "notNull": false, + "generated": { + "as": "to_tsvector('english', \"docs_embeddings\".\"chunk_text\")", + "type": "stored" + } + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "docs_emb_source_document_idx": { + "name": "docs_emb_source_document_idx", + "columns": [ + { + "expression": "source_document", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "docs_emb_header_level_idx": { + "name": "docs_emb_header_level_idx", + "columns": [ + { + "expression": "header_level", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "docs_emb_source_header_idx": { + "name": "docs_emb_source_header_idx", + "columns": [ + { + "expression": "source_document", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "header_level", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "docs_emb_model_idx": { + "name": "docs_emb_model_idx", + "columns": [ + { + "expression": "embedding_model", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "docs_emb_created_at_idx": { + "name": "docs_emb_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "docs_embedding_vector_hnsw_idx": { + "name": "docs_embedding_vector_hnsw_idx", + "columns": [ + { + "expression": "embedding", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "vector_cosine_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "hnsw", + "with": { + "m": 16, + "ef_construction": 64 + } + }, + "docs_emb_metadata_gin_idx": { + "name": "docs_emb_metadata_gin_idx", + "columns": [ + { + "expression": "metadata", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "gin", + "with": {} + }, + "docs_emb_chunk_text_fts_idx": { + "name": "docs_emb_chunk_text_fts_idx", + "columns": [ + { + "expression": "chunk_text_tsv", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "gin", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "docs_embedding_not_null_check": { + "name": "docs_embedding_not_null_check", + "value": "\"embedding\" IS NOT NULL" + }, + "docs_header_level_check": { + "name": "docs_header_level_check", + "value": "\"header_level\" >= 1 AND \"header_level\" <= 6" + } + }, + "isRLSEnabled": false + }, + "public.document": { + "name": "document", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "knowledge_base_id": { + "name": "knowledge_base_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "filename": { + "name": "filename", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "file_url": { + "name": "file_url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "storage_key": { + "name": "storage_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "mime_type": { + "name": "mime_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "chunk_count": { + "name": "chunk_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "token_count": { + "name": "token_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "character_count": { + "name": "character_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "processing_status": { + "name": "processing_status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "processing_attempts": { + "name": "processing_attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "processing_queued_at": { + "name": "processing_queued_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "processing_queue_token": { + "name": "processing_queue_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "processing_started_at": { + "name": "processing_started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "processing_deferred_until": { + "name": "processing_deferred_until", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "processing_completed_at": { + "name": "processing_completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "processing_error": { + "name": "processing_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "processing_recovery_after": { + "name": "processing_recovery_after", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "user_excluded": { + "name": "user_excluded", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "tag1": { + "name": "tag1", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tag2": { + "name": "tag2", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tag3": { + "name": "tag3", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tag4": { + "name": "tag4", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tag5": { + "name": "tag5", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tag6": { + "name": "tag6", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tag7": { + "name": "tag7", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "number1": { + "name": "number1", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "number2": { + "name": "number2", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "number3": { + "name": "number3", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "number4": { + "name": "number4", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "number5": { + "name": "number5", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "date1": { + "name": "date1", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "date2": { + "name": "date2", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "boolean1": { + "name": "boolean1", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "boolean2": { + "name": "boolean2", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "boolean3": { + "name": "boolean3", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "connector_id": { + "name": "connector_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "external_id": { + "name": "external_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "content_hash": { + "name": "content_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "source_url": { + "name": "source_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "secret_provenance_version": { + "name": "secret_provenance_version", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "uploaded_by": { + "name": "uploaded_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "acl": { + "name": "acl", + "type": "text[]", + "primaryKey": false, + "notNull": true, + "default": "'{ws}'::text[]" + }, + "acl_requirements": { + "name": "acl_requirements", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "acl_verified_at": { + "name": "acl_verified_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "source_modified_at": { + "name": "source_modified_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "source_seen_at": { + "name": "source_seen_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "uploaded_at": { + "name": "uploaded_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "doc_kb_id_idx": { + "name": "doc_kb_id_idx", + "columns": [ + { + "expression": "knowledge_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_acl_gin_idx": { + "name": "doc_acl_gin_idx", + "columns": [ + { + "expression": "acl", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "array_ops" + } + ], + "isUnique": false, + "where": "\"document\".\"deleted_at\" IS NULL", + "concurrently": false, + "method": "gin", + "with": {} + }, + "doc_filename_idx": { + "name": "doc_filename_idx", + "columns": [ + { + "expression": "filename", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_processing_status_idx": { + "name": "doc_processing_status_idx", + "columns": [ + { + "expression": "knowledge_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "processing_status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_processing_recovery_idx": { + "name": "doc_processing_recovery_idx", + "columns": [ + { + "expression": "uploaded_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"document\".\"processing_status\" IN ('pending', 'processing', 'failed') AND \"document\".\"connector_id\" IS NOT NULL AND \"document\".\"content_hash\" IS NOT NULL AND \"document\".\"storage_key\" IS NOT NULL AND \"document\".\"user_excluded\" = false AND \"document\".\"archived_at\" IS NULL AND \"document\".\"deleted_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_connector_external_id_idx": { + "name": "doc_connector_external_id_idx", + "columns": [ + { + "expression": "connector_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "external_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"document\".\"deleted_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_connector_source_lookup_idx": { + "name": "doc_connector_source_lookup_idx", + "columns": [ + { + "expression": "connector_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "external_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_connector_reconciliation_idx": { + "name": "doc_connector_reconciliation_idx", + "columns": [ + { + "expression": "connector_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "COALESCE(\"source_seen_at\", '-infinity'::timestamp)", + "asc": true, + "isExpression": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"document\".\"user_excluded\" = false AND \"document\".\"archived_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_active_kb_token_count_idx": { + "name": "doc_active_kb_token_count_idx", + "columns": [ + { + "expression": "knowledge_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "token_count", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"document\".\"user_excluded\" = false AND \"document\".\"archived_at\" IS NULL AND \"document\".\"deleted_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_storage_key_idx": { + "name": "doc_storage_key_idx", + "columns": [ + { + "expression": "storage_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"document\".\"storage_key\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_archived_at_partial_idx": { + "name": "doc_archived_at_partial_idx", + "columns": [ + { + "expression": "archived_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"document\".\"archived_at\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_deleted_at_partial_idx": { + "name": "doc_deleted_at_partial_idx", + "columns": [ + { + "expression": "deleted_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"document\".\"deleted_at\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_kb_tag1_lower_idx": { + "name": "doc_kb_tag1_lower_idx", + "columns": [ + { + "expression": "knowledge_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lower(\"tag1\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_kb_tag2_lower_idx": { + "name": "doc_kb_tag2_lower_idx", + "columns": [ + { + "expression": "knowledge_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lower(\"tag2\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_kb_tag3_lower_idx": { + "name": "doc_kb_tag3_lower_idx", + "columns": [ + { + "expression": "knowledge_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lower(\"tag3\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_kb_tag4_lower_idx": { + "name": "doc_kb_tag4_lower_idx", + "columns": [ + { + "expression": "knowledge_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lower(\"tag4\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_kb_tag5_lower_idx": { + "name": "doc_kb_tag5_lower_idx", + "columns": [ + { + "expression": "knowledge_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lower(\"tag5\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_kb_tag6_lower_idx": { + "name": "doc_kb_tag6_lower_idx", + "columns": [ + { + "expression": "knowledge_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lower(\"tag6\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_kb_tag7_lower_idx": { + "name": "doc_kb_tag7_lower_idx", + "columns": [ + { + "expression": "knowledge_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lower(\"tag7\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_number1_idx": { + "name": "doc_number1_idx", + "columns": [ + { + "expression": "number1", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_number2_idx": { + "name": "doc_number2_idx", + "columns": [ + { + "expression": "number2", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_number3_idx": { + "name": "doc_number3_idx", + "columns": [ + { + "expression": "number3", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_number4_idx": { + "name": "doc_number4_idx", + "columns": [ + { + "expression": "number4", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_number5_idx": { + "name": "doc_number5_idx", + "columns": [ + { + "expression": "number5", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_date1_idx": { + "name": "doc_date1_idx", + "columns": [ + { + "expression": "date1", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_date2_idx": { + "name": "doc_date2_idx", + "columns": [ + { + "expression": "date2", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_boolean1_idx": { + "name": "doc_boolean1_idx", + "columns": [ + { + "expression": "boolean1", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_boolean2_idx": { + "name": "doc_boolean2_idx", + "columns": [ + { + "expression": "boolean2", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_boolean3_idx": { + "name": "doc_boolean3_idx", + "columns": [ + { + "expression": "boolean3", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "document_knowledge_base_id_knowledge_base_id_fk": { + "name": "document_knowledge_base_id_knowledge_base_id_fk", + "tableFrom": "document", + "tableTo": "knowledge_base", + "columnsFrom": ["knowledge_base_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "document_connector_id_knowledge_connector_id_fk": { + "name": "document_connector_id_knowledge_connector_id_fk", + "tableFrom": "document", + "tableTo": "knowledge_connector", + "columnsFrom": ["connector_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "document_uploaded_by_user_id_fk": { + "name": "document_uploaded_by_user_id_fk", + "tableFrom": "document", + "tableTo": "user", + "columnsFrom": ["uploaded_by"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "doc_acl_token_shape_check": { + "name": "doc_acl_token_shape_check", + "value": "array_position(\"document\".\"acl\", NULL) IS NULL AND (cardinality(\"document\".\"acl\") = 0 OR (cardinality(\"document\".\"acl\") = array_length(string_to_array(array_to_string(\"document\".\"acl\", E'\\n'), E'\\n'), 1) AND array_to_string(\"document\".\"acl\", E'\\n') ~ '^((ws|pub|link|u:[^\\nA-Z]+@[^\\nA-Z]+|[gs]:[^\\n:]+:[^\\n:]+:[^\\n]+)(\\n(ws|pub|link|u:[^\\nA-Z]+@[^\\nA-Z]+|[gs]:[^\\n:]+:[^\\n:]+:[^\\n]+))*)$'))" + } + }, + "isRLSEnabled": false + }, + "public.document_secret_provenance": { + "name": "document_secret_provenance", + "schema": "", + "columns": { + "document_id": { + "name": "document_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "source_hash": { + "name": "source_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "entries": { + "name": "entries", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "document_secret_provenance_document_id_document_id_fk": { + "name": "document_secret_provenance_document_id_document_id_fk", + "tableFrom": "document_secret_provenance", + "tableTo": "document", + "columnsFrom": ["document_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "document_secret_provenance_status_check": { + "name": "document_secret_provenance_status_check", + "value": "\"document_secret_provenance\".\"status\" IN ('exact', 'unknown')" + } + }, + "isRLSEnabled": false + }, + "public.embedding": { + "name": "embedding", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "knowledge_base_id": { + "name": "knowledge_base_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "document_id": { + "name": "document_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "chunk_index": { + "name": "chunk_index", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "chunk_hash": { + "name": "chunk_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "secret_provenance_version": { + "name": "secret_provenance_version", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "content_length": { + "name": "content_length", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "token_count": { + "name": "token_count", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "embedding": { + "name": "embedding", + "type": "vector(1536)", + "primaryKey": false, + "notNull": false + }, + "embedding_384": { + "name": "embedding_384", + "type": "vector(384)", + "primaryKey": false, + "notNull": false + }, + "embedding_768": { + "name": "embedding_768", + "type": "vector(768)", + "primaryKey": false, + "notNull": false + }, + "embedding_1024": { + "name": "embedding_1024", + "type": "vector(1024)", + "primaryKey": false, + "notNull": false + }, + "embedding_3072": { + "name": "embedding_3072", + "type": "vector(3072)", + "primaryKey": false, + "notNull": false + }, + "embedding_model": { + "name": "embedding_model", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'text-embedding-3-small'" + }, + "start_offset": { + "name": "start_offset", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "end_offset": { + "name": "end_offset", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "tag1": { + "name": "tag1", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tag2": { + "name": "tag2", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tag3": { + "name": "tag3", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tag4": { + "name": "tag4", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tag5": { + "name": "tag5", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tag6": { + "name": "tag6", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tag7": { + "name": "tag7", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "number1": { + "name": "number1", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "number2": { + "name": "number2", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "number3": { + "name": "number3", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "number4": { + "name": "number4", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "number5": { + "name": "number5", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "date1": { + "name": "date1", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "date2": { + "name": "date2", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "boolean1": { + "name": "boolean1", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "boolean2": { + "name": "boolean2", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "boolean3": { + "name": "boolean3", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "content_tsv": { + "name": "content_tsv", + "type": "tsvector", + "primaryKey": false, + "notNull": false, + "generated": { + "as": "to_tsvector('english', \"embedding\".\"content\")", + "type": "stored" + } + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "emb_kb_id_idx": { + "name": "emb_kb_id_idx", + "columns": [ + { + "expression": "knowledge_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "emb_doc_id_idx": { + "name": "emb_doc_id_idx", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "emb_doc_chunk_idx": { + "name": "emb_doc_chunk_idx", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "chunk_index", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "emb_kb_model_idx": { + "name": "emb_kb_model_idx", + "columns": [ + { + "expression": "knowledge_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "embedding_model", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "emb_kb_enabled_idx": { + "name": "emb_kb_enabled_idx", + "columns": [ + { + "expression": "knowledge_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "enabled", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "emb_doc_enabled_idx": { + "name": "emb_doc_enabled_idx", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "enabled", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "embedding_vector_hnsw_idx": { + "name": "embedding_vector_hnsw_idx", + "columns": [ + { + "expression": "embedding", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "vector_cosine_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "hnsw", + "with": { + "m": 16, + "ef_construction": 64 + } + }, + "embedding_384_vector_hnsw_idx": { + "name": "embedding_384_vector_hnsw_idx", + "columns": [ + { + "expression": "embedding_384", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "vector_cosine_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "hnsw", + "with": { + "m": 16, + "ef_construction": 64 + } + }, + "embedding_768_vector_hnsw_idx": { + "name": "embedding_768_vector_hnsw_idx", + "columns": [ + { + "expression": "embedding_768", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "vector_cosine_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "hnsw", + "with": { + "m": 16, + "ef_construction": 64 + } + }, + "embedding_1024_vector_hnsw_idx": { + "name": "embedding_1024_vector_hnsw_idx", + "columns": [ + { + "expression": "embedding_1024", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "vector_cosine_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "hnsw", + "with": { + "m": 16, + "ef_construction": 64 + } + }, + "embedding_3072_vector_hnsw_idx": { + "name": "embedding_3072_vector_hnsw_idx", + "columns": [ + { + "expression": "(\"embedding_3072\"::halfvec(3072)) halfvec_cosine_ops", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "hnsw", + "with": { + "m": 16, + "ef_construction": 64 + } + }, + "emb_kb_tag1_lower_idx": { + "name": "emb_kb_tag1_lower_idx", + "columns": [ + { + "expression": "knowledge_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lower(\"tag1\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "emb_kb_tag2_lower_idx": { + "name": "emb_kb_tag2_lower_idx", + "columns": [ + { + "expression": "knowledge_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lower(\"tag2\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "emb_kb_tag3_lower_idx": { + "name": "emb_kb_tag3_lower_idx", + "columns": [ + { + "expression": "knowledge_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lower(\"tag3\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "emb_kb_tag4_lower_idx": { + "name": "emb_kb_tag4_lower_idx", + "columns": [ + { + "expression": "knowledge_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lower(\"tag4\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "emb_kb_tag5_lower_idx": { + "name": "emb_kb_tag5_lower_idx", + "columns": [ + { + "expression": "knowledge_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lower(\"tag5\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "emb_kb_tag6_lower_idx": { + "name": "emb_kb_tag6_lower_idx", + "columns": [ + { + "expression": "knowledge_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lower(\"tag6\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "emb_kb_tag7_lower_idx": { + "name": "emb_kb_tag7_lower_idx", + "columns": [ + { + "expression": "knowledge_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lower(\"tag7\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "emb_number1_idx": { + "name": "emb_number1_idx", + "columns": [ + { + "expression": "number1", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "emb_number2_idx": { + "name": "emb_number2_idx", + "columns": [ + { + "expression": "number2", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "emb_number3_idx": { + "name": "emb_number3_idx", + "columns": [ + { + "expression": "number3", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "emb_number4_idx": { + "name": "emb_number4_idx", + "columns": [ + { + "expression": "number4", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "emb_number5_idx": { + "name": "emb_number5_idx", + "columns": [ + { + "expression": "number5", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "emb_date1_idx": { + "name": "emb_date1_idx", + "columns": [ + { + "expression": "date1", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "emb_date2_idx": { + "name": "emb_date2_idx", + "columns": [ + { + "expression": "date2", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "emb_boolean1_idx": { + "name": "emb_boolean1_idx", + "columns": [ + { + "expression": "boolean1", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "emb_boolean2_idx": { + "name": "emb_boolean2_idx", + "columns": [ + { + "expression": "boolean2", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "emb_boolean3_idx": { + "name": "emb_boolean3_idx", + "columns": [ + { + "expression": "boolean3", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "emb_content_fts_idx": { + "name": "emb_content_fts_idx", + "columns": [ + { + "expression": "content_tsv", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "gin", + "with": {} + } + }, + "foreignKeys": { + "embedding_knowledge_base_id_knowledge_base_id_fk": { + "name": "embedding_knowledge_base_id_knowledge_base_id_fk", + "tableFrom": "embedding", + "tableTo": "knowledge_base", + "columnsFrom": ["knowledge_base_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "embedding_document_id_document_id_fk": { + "name": "embedding_document_id_document_id_fk", + "tableFrom": "embedding", + "tableTo": "document", + "columnsFrom": ["document_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "embedding_width_check": { + "name": "embedding_width_check", + "value": "num_nonnulls(\"embedding\", \"embedding_384\", \"embedding_768\", \"embedding_1024\", \"embedding_3072\") = 1" + } + }, + "isRLSEnabled": false + }, + "public.embedding_secret_provenance": { + "name": "embedding_secret_provenance", + "schema": "", + "columns": { + "embedding_id": { + "name": "embedding_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "content_hash": { + "name": "content_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "entries": { + "name": "entries", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "embedding_secret_provenance_embedding_id_embedding_id_fk": { + "name": "embedding_secret_provenance_embedding_id_embedding_id_fk", + "tableFrom": "embedding_secret_provenance", + "tableTo": "embedding", + "columnsFrom": ["embedding_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "embedding_secret_provenance_status_check": { + "name": "embedding_secret_provenance_status_check", + "value": "\"embedding_secret_provenance\".\"status\" IN ('exact', 'unknown')" + } + }, + "isRLSEnabled": false + }, + "public.environment": { + "name": "environment", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "variables": { + "name": "variables", + "type": "json", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "environment_user_id_user_id_fk": { + "name": "environment_user_id_user_id_fk", + "tableFrom": "environment", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "environment_user_id_unique": { + "name": "environment_user_id_unique", + "nullsNotDistinct": false, + "columns": ["user_id"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.execution_large_value_dependencies": { + "name": "execution_large_value_dependencies", + "schema": "", + "columns": { + "parent_key": { + "name": "parent_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "child_key": { + "name": "child_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "execution_large_value_dependencies_workspace_parent_key_idx": { + "name": "execution_large_value_dependencies_workspace_parent_key_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "parent_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "execution_large_value_dependencies_workspace_child_key_idx": { + "name": "execution_large_value_dependencies_workspace_child_key_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "child_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "execution_large_value_dependencies_workspace_id_workspace_id_fk": { + "name": "execution_large_value_dependencies_workspace_id_workspace_id_fk", + "tableFrom": "execution_large_value_dependencies", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "execution_large_value_dependencies_parent_key_child_key_pk": { + "name": "execution_large_value_dependencies_parent_key_child_key_pk", + "columns": ["parent_key", "child_key"] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.execution_large_value_references": { + "name": "execution_large_value_references", + "schema": "", + "columns": { + "key": { + "name": "key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "execution_id": { + "name": "execution_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "execution_large_value_reference_source", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "execution_large_value_references_workspace_execution_source_idx": { + "name": "execution_large_value_references_workspace_execution_source_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "execution_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "source", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "execution_large_value_references_workflow_id_idx": { + "name": "execution_large_value_references_workflow_id_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "execution_large_value_references_workspace_id_workspace_id_fk": { + "name": "execution_large_value_references_workspace_id_workspace_id_fk", + "tableFrom": "execution_large_value_references", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "execution_large_value_references_workflow_id_workflow_id_fk": { + "name": "execution_large_value_references_workflow_id_workflow_id_fk", + "tableFrom": "execution_large_value_references", + "tableTo": "workflow", + "columnsFrom": ["workflow_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "execution_large_value_references_key_execution_id_source_pk": { + "name": "execution_large_value_references_key_execution_id_source_pk", + "columns": ["key", "execution_id", "source"] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.execution_large_values": { + "name": "execution_large_values", + "schema": "", + "columns": { + "key": { + "name": "key", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "owner_execution_id": { + "name": "owner_execution_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "size": { + "name": "size", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "execution_large_values_owner_execution_id_idx": { + "name": "execution_large_values_owner_execution_id_idx", + "columns": [ + { + "expression": "owner_execution_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "execution_large_values_cleanup_idx": { + "name": "execution_large_values_cleanup_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"execution_large_values\".\"deleted_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "execution_large_values_tombstone_cleanup_idx": { + "name": "execution_large_values_tombstone_cleanup_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "deleted_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"execution_large_values\".\"deleted_at\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "execution_large_values_workflow_id_idx": { + "name": "execution_large_values_workflow_id_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "execution_large_values_workspace_id_workspace_id_fk": { + "name": "execution_large_values_workspace_id_workspace_id_fk", + "tableFrom": "execution_large_values", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "execution_large_values_workflow_id_workflow_id_fk": { + "name": "execution_large_values_workflow_id_workflow_id_fk", + "tableFrom": "execution_large_values", + "tableTo": "workflow", + "columnsFrom": ["workflow_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.folder": { + "name": "folder", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "resource_type": { + "name": "resource_type", + "type": "folder_resource_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "parent_id": { + "name": "parent_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "locked": { + "name": "locked", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "folder_user_idx": { + "name": "folder_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "folder_workspace_resource_parent_idx": { + "name": "folder_workspace_resource_parent_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "resource_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "folder_parent_sort_idx": { + "name": "folder_parent_sort_idx", + "columns": [ + { + "expression": "parent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sort_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "folder_deleted_at_idx": { + "name": "folder_deleted_at_idx", + "columns": [ + { + "expression": "deleted_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "folder_workspace_deleted_partial_idx": { + "name": "folder_workspace_deleted_partial_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "deleted_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"folder\".\"deleted_at\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "folder_workspace_resource_parent_name_active_unique": { + "name": "folder_workspace_resource_parent_name_active_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "resource_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "coalesce(\"parent_id\", '')", + "asc": true, + "isExpression": true, + "nulls": "last" + }, + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"folder\".\"deleted_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "folder_user_id_user_id_fk": { + "name": "folder_user_id_user_id_fk", + "tableFrom": "folder", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "folder_workspace_id_workspace_id_fk": { + "name": "folder_workspace_id_workspace_id_fk", + "tableFrom": "folder", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "folder_parent_id_folder_id_fk": { + "name": "folder_parent_id_folder_id_fk", + "tableFrom": "folder", + "tableTo": "folder", + "columnsFrom": ["parent_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.idempotency_key": { + "name": "idempotency_key", + "schema": "", + "columns": { + "key": { + "name": "key", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "result": { + "name": "result", + "type": "json", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idempotency_key_created_at_idx": { + "name": "idempotency_key_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.invitation": { + "name": "invitation", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "invitation_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'organization'" + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "inviter_id": { + "name": "inviter_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "membership_intent": { + "name": "membership_intent", + "type": "invitation_membership_intent", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'internal'" + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "invitation_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "invitation_email_idx": { + "name": "invitation_email_idx", + "columns": [ + { + "expression": "email", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "invitation_organization_id_idx": { + "name": "invitation_organization_id_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "invitation_status_idx": { + "name": "invitation_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "invitation_pending_email_org_unique": { + "name": "invitation_pending_email_org_unique", + "columns": [ + { + "expression": "email", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"invitation\".\"status\" = 'pending' AND \"invitation\".\"organization_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "invitation_inviter_id_user_id_fk": { + "name": "invitation_inviter_id_user_id_fk", + "tableFrom": "invitation", + "tableTo": "user", + "columnsFrom": ["inviter_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "invitation_organization_id_organization_id_fk": { + "name": "invitation_organization_id_organization_id_fk", + "tableFrom": "invitation", + "tableTo": "organization", + "columnsFrom": ["organization_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "invitation_token_unique": { + "name": "invitation_token_unique", + "nullsNotDistinct": false, + "columns": ["token"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.invitation_workspace_grant": { + "name": "invitation_workspace_grant", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "invitation_id": { + "name": "invitation_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "permission": { + "name": "permission", + "type": "permission_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "invitation_workspace_grant_unique": { + "name": "invitation_workspace_grant_unique", + "columns": [ + { + "expression": "invitation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "invitation_workspace_grant_workspace_id_idx": { + "name": "invitation_workspace_grant_workspace_id_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "invitation_workspace_grant_invitation_id_invitation_id_fk": { + "name": "invitation_workspace_grant_invitation_id_invitation_id_fk", + "tableFrom": "invitation_workspace_grant", + "tableTo": "invitation", + "columnsFrom": ["invitation_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "invitation_workspace_grant_workspace_id_workspace_id_fk": { + "name": "invitation_workspace_grant_workspace_id_workspace_id_fk", + "tableFrom": "invitation_workspace_grant", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.job_execution_logs": { + "name": "job_execution_logs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "schedule_id": { + "name": "schedule_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "execution_id": { + "name": "execution_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "level": { + "name": "level", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'running'" + }, + "trigger": { + "name": "trigger", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "started_at": { + "name": "started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "ended_at": { + "name": "ended_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "total_duration_ms": { + "name": "total_duration_ms", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "execution_data": { + "name": "execution_data", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'" + }, + "cost": { + "name": "cost", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "job_execution_logs_schedule_id_idx": { + "name": "job_execution_logs_schedule_id_idx", + "columns": [ + { + "expression": "schedule_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "job_execution_logs_workspace_started_at_idx": { + "name": "job_execution_logs_workspace_started_at_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "started_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "job_execution_logs_workspace_ended_at_id_idx": { + "name": "job_execution_logs_workspace_ended_at_id_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "date_trunc('milliseconds', \"ended_at\")", + "asc": true, + "isExpression": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "job_execution_logs_execution_id_unique": { + "name": "job_execution_logs_execution_id_unique", + "columns": [ + { + "expression": "execution_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "job_execution_logs_trigger_idx": { + "name": "job_execution_logs_trigger_idx", + "columns": [ + { + "expression": "trigger", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "job_execution_logs_schedule_id_workflow_schedule_id_fk": { + "name": "job_execution_logs_schedule_id_workflow_schedule_id_fk", + "tableFrom": "job_execution_logs", + "tableTo": "workflow_schedule", + "columnsFrom": ["schedule_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "job_execution_logs_workspace_id_workspace_id_fk": { + "name": "job_execution_logs_workspace_id_workspace_id_fk", + "tableFrom": "job_execution_logs", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.knowledge_base": { + "name": "knowledge_base", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "folder_id": { + "name": "folder_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_search_index": { + "name": "is_search_index", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "token_count": { + "name": "token_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "embedding_model": { + "name": "embedding_model", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'text-embedding-3-small'" + }, + "embedding_dimension": { + "name": "embedding_dimension", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1536 + }, + "chunking_config": { + "name": "chunking_config", + "type": "json", + "primaryKey": false, + "notNull": true, + "default": "'{\"maxSize\": 1024, \"minSize\": 1, \"overlap\": 200}'" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "kb_organization_id_idx": { + "name": "kb_organization_id_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "kb_organization_search_index_unique": { + "name": "kb_organization_search_index_unique", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"knowledge_base\".\"is_search_index\" = true AND \"knowledge_base\".\"deleted_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "kb_organization_name_active_unique": { + "name": "kb_organization_name_active_unique", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"knowledge_base\".\"deleted_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "kb_user_id_idx": { + "name": "kb_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "kb_workspace_id_idx": { + "name": "kb_workspace_id_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "kb_user_workspace_idx": { + "name": "kb_user_workspace_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "kb_folder_id_idx": { + "name": "kb_folder_id_idx", + "columns": [ + { + "expression": "folder_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "kb_deleted_at_idx": { + "name": "kb_deleted_at_idx", + "columns": [ + { + "expression": "deleted_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "kb_workspace_deleted_partial_idx": { + "name": "kb_workspace_deleted_partial_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "deleted_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"knowledge_base\".\"deleted_at\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "kb_workspace_name_active_unique": { + "name": "kb_workspace_name_active_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"knowledge_base\".\"deleted_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "kb_workspace_search_index_unique": { + "name": "kb_workspace_search_index_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"knowledge_base\".\"is_search_index\" = true AND \"knowledge_base\".\"deleted_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "knowledge_base_user_id_user_id_fk": { + "name": "knowledge_base_user_id_user_id_fk", + "tableFrom": "knowledge_base", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "knowledge_base_workspace_id_workspace_id_fk": { + "name": "knowledge_base_workspace_id_workspace_id_fk", + "tableFrom": "knowledge_base", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "knowledge_base_organization_id_organization_id_fk": { + "name": "knowledge_base_organization_id_organization_id_fk", + "tableFrom": "knowledge_base", + "tableTo": "organization", + "columnsFrom": ["organization_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "knowledge_base_folder_id_folder_id_fk": { + "name": "knowledge_base_folder_id_folder_id_fk", + "tableFrom": "knowledge_base", + "tableTo": "folder", + "columnsFrom": ["folder_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "kb_owner_check": { + "name": "kb_owner_check", + "value": "num_nonnulls(\"knowledge_base\".\"workspace_id\", \"knowledge_base\".\"organization_id\") = 1" + }, + "kb_organization_search_index_check": { + "name": "kb_organization_search_index_check", + "value": "\"knowledge_base\".\"organization_id\" IS NULL OR \"knowledge_base\".\"is_search_index\"" + }, + "kb_organization_folder_check": { + "name": "kb_organization_folder_check", + "value": "\"knowledge_base\".\"organization_id\" IS NULL OR \"knowledge_base\".\"folder_id\" IS NULL" + } + }, + "isRLSEnabled": false + }, + "public.knowledge_base_tag_definitions": { + "name": "knowledge_base_tag_definitions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "knowledge_base_id": { + "name": "knowledge_base_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tag_slot": { + "name": "tag_slot", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "display_name": { + "name": "display_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "field_type": { + "name": "field_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'text'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "kb_tag_definitions_kb_slot_idx": { + "name": "kb_tag_definitions_kb_slot_idx", + "columns": [ + { + "expression": "knowledge_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "tag_slot", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "kb_tag_definitions_kb_display_name_idx": { + "name": "kb_tag_definitions_kb_display_name_idx", + "columns": [ + { + "expression": "knowledge_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "display_name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "kb_tag_definitions_kb_id_idx": { + "name": "kb_tag_definitions_kb_id_idx", + "columns": [ + { + "expression": "knowledge_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "knowledge_base_tag_definitions_knowledge_base_id_knowledge_base_id_fk": { + "name": "knowledge_base_tag_definitions_knowledge_base_id_knowledge_base_id_fk", + "tableFrom": "knowledge_base_tag_definitions", + "tableTo": "knowledge_base", + "columnsFrom": ["knowledge_base_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.knowledge_connector": { + "name": "knowledge_connector", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "knowledge_base_id": { + "name": "knowledge_base_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "connector_type": { + "name": "connector_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "credential_id": { + "name": "credential_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "encrypted_api_key": { + "name": "encrypted_api_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "source_config": { + "name": "source_config", + "type": "json", + "primaryKey": false, + "notNull": true + }, + "sync_mode": { + "name": "sync_mode", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'full'" + }, + "sync_interval_minutes": { + "name": "sync_interval_minutes", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1440 + }, + "access_mode": { + "name": "access_mode", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'workspace'" + }, + "credential_group_id": { + "name": "credential_group_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "credential_group_option_id": { + "name": "credential_group_option_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "member_sync_status": { + "name": "member_sync_status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'idle'" + }, + "member_sync_lock_token": { + "name": "member_sync_lock_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "member_sync_lock_lease_at": { + "name": "member_sync_lock_lease_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "next_member_sync_at": { + "name": "next_member_sync_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_member_sync_at": { + "name": "last_member_sync_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_member_sync_error": { + "name": "last_member_sync_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "member_sync_consecutive_failures": { + "name": "member_sync_consecutive_failures", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "access_rewrite_pending": { + "name": "access_rewrite_pending", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "last_sync_at": { + "name": "last_sync_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_sync_error": { + "name": "last_sync_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "last_sync_doc_count": { + "name": "last_sync_doc_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "listing_checkpoint": { + "name": "listing_checkpoint", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "directory_checkpoint": { + "name": "directory_checkpoint", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "next_sync_at": { + "name": "next_sync_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "next_directory_sync_at": { + "name": "next_directory_sync_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "consecutive_failures": { + "name": "consecutive_failures", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "sync_lock_token": { + "name": "sync_lock_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sync_lock_lease_at": { + "name": "sync_lock_lease_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "kc_knowledge_base_id_idx": { + "name": "kc_knowledge_base_id_idx", + "columns": [ + { + "expression": "knowledge_base_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "kc_status_next_sync_idx": { + "name": "kc_status_next_sync_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "next_sync_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "kc_archived_at_partial_idx": { + "name": "kc_archived_at_partial_idx", + "columns": [ + { + "expression": "archived_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"knowledge_connector\".\"archived_at\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "kc_deleted_at_partial_idx": { + "name": "kc_deleted_at_partial_idx", + "columns": [ + { + "expression": "deleted_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"knowledge_connector\".\"deleted_at\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "kc_member_sync_due_idx": { + "name": "kc_member_sync_due_idx", + "columns": [ + { + "expression": "member_sync_status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "next_member_sync_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"knowledge_connector\".\"access_mode\" = 'members' AND \"knowledge_connector\".\"deleted_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "kc_directory_sync_due_idx": { + "name": "kc_directory_sync_due_idx", + "columns": [ + { + "expression": "next_directory_sync_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"knowledge_connector\".\"access_mode\" = 'admin' AND \"knowledge_connector\".\"deleted_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "knowledge_connector_knowledge_base_id_knowledge_base_id_fk": { + "name": "knowledge_connector_knowledge_base_id_knowledge_base_id_fk", + "tableFrom": "knowledge_connector", + "tableTo": "knowledge_base", + "columnsFrom": ["knowledge_base_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "knowledge_connector_credential_group_id_credential_group_id_fk": { + "name": "knowledge_connector_credential_group_id_credential_group_id_fk", + "tableFrom": "knowledge_connector", + "tableTo": "credential_group", + "columnsFrom": ["credential_group_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "kc_access_mode_check": { + "name": "kc_access_mode_check", + "value": "\"knowledge_connector\".\"access_mode\" IN ('workspace', 'members', 'admin')" + }, + "kc_member_sync_status_check": { + "name": "kc_member_sync_status_check", + "value": "\"knowledge_connector\".\"member_sync_status\" IN ('idle', 'pending', 'running', 'error', 'disabled')" + }, + "kc_sync_lock_exclusive_check": { + "name": "kc_sync_lock_exclusive_check", + "value": "NOT (\"knowledge_connector\".\"sync_lock_token\" IS NOT NULL AND \"knowledge_connector\".\"member_sync_lock_token\" IS NOT NULL)" + } + }, + "isRLSEnabled": false + }, + "public.knowledge_connector_member": { + "name": "knowledge_connector_member", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "connector_id": { + "name": "connector_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "credential_id": { + "name": "credential_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "subject_token": { + "name": "subject_token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "consecutive_failures": { + "name": "consecutive_failures", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "next_attempt_at": { + "name": "next_attempt_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_started_at": { + "name": "last_started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_complete_listing_at": { + "name": "last_complete_listing_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_listed_count": { + "name": "last_listed_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "member_synced_through": { + "name": "member_synced_through", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "change_cursor": { + "name": "change_cursor", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "listing_checkpoint": { + "name": "listing_checkpoint", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "suspended_at": { + "name": "suspended_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "kcm_organization_id_idx": { + "name": "kcm_organization_id_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "kcm_connector_credential_unique": { + "name": "kcm_connector_credential_unique", + "columns": [ + { + "expression": "connector_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "credential_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "kcm_connector_queue_idx": { + "name": "kcm_connector_queue_idx", + "columns": [ + { + "expression": "connector_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "next_attempt_at", + "isExpression": false, + "asc": true, + "nulls": "first" + }, + { + "expression": "last_started_at", + "isExpression": false, + "asc": true, + "nulls": "first" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "kcm_credential_idx": { + "name": "kcm_credential_idx", + "columns": [ + { + "expression": "credential_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "knowledge_connector_member_workspace_id_workspace_id_fk": { + "name": "knowledge_connector_member_workspace_id_workspace_id_fk", + "tableFrom": "knowledge_connector_member", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "knowledge_connector_member_organization_id_organization_id_fk": { + "name": "knowledge_connector_member_organization_id_organization_id_fk", + "tableFrom": "knowledge_connector_member", + "tableTo": "organization", + "columnsFrom": ["organization_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "knowledge_connector_member_connector_id_knowledge_connector_id_fk": { + "name": "knowledge_connector_member_connector_id_knowledge_connector_id_fk", + "tableFrom": "knowledge_connector_member", + "tableTo": "knowledge_connector", + "columnsFrom": ["connector_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "knowledge_connector_member_credential_id_credential_id_fk": { + "name": "knowledge_connector_member_credential_id_credential_id_fk", + "tableFrom": "knowledge_connector_member", + "tableTo": "credential", + "columnsFrom": ["credential_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "kcm_owner_check": { + "name": "kcm_owner_check", + "value": "num_nonnulls(\"knowledge_connector_member\".\"workspace_id\", \"knowledge_connector_member\".\"organization_id\") = 1" + }, + "kcm_status_check": { + "name": "kcm_status_check", + "value": "\"knowledge_connector_member\".\"status\" IN ('active', 'suspended', 'disabled')" + }, + "kcm_subject_token_shape_check": { + "name": "kcm_subject_token_shape_check", + "value": "\"knowledge_connector_member\".\"subject_token\" ~ '^s:[^:]+:[^:]+:.+$'" + } + }, + "isRLSEnabled": false + }, + "public.knowledge_connector_member_sync_log": { + "name": "knowledge_connector_member_sync_log", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "connector_id": { + "name": "connector_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "started_at": { + "name": "started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "members_claimed": { + "name": "members_claimed", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "members_completed": { + "name": "members_completed", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "members_incomplete": { + "name": "members_incomplete", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "members_failed": { + "name": "members_failed", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "docs_listed": { + "name": "docs_listed", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "docs_added": { + "name": "docs_added", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "docs_updated": { + "name": "docs_updated", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "docs_unchanged": { + "name": "docs_unchanged", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "docs_hydrated_once": { + "name": "docs_hydrated_once", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "observations_added": { + "name": "observations_added", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "observations_removed": { + "name": "observations_removed", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "docs_tombstoned": { + "name": "docs_tombstoned", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "docs_resurrected": { + "name": "docs_resurrected", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "docs_purged": { + "name": "docs_purged", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "credentials_audited": { + "name": "credentials_audited", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "kcmsl_connector_started_at_idx": { + "name": "kcmsl_connector_started_at_idx", + "columns": [ + { + "expression": "connector_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "\"started_at\" DESC", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "kcmsl_started_at_partial_idx": { + "name": "kcmsl_started_at_partial_idx", + "columns": [ + { + "expression": "started_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"knowledge_connector_member_sync_log\".\"status\" = 'started'", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "knowledge_connector_member_sync_log_connector_id_knowledge_connector_id_fk": { + "name": "knowledge_connector_member_sync_log_connector_id_knowledge_connector_id_fk", + "tableFrom": "knowledge_connector_member_sync_log", + "tableTo": "knowledge_connector", + "columnsFrom": ["connector_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "kcmsl_status_check": { + "name": "kcmsl_status_check", + "value": "\"knowledge_connector_member_sync_log\".\"status\" IN ('started', 'partial', 'completed', 'failed')" + } + }, + "isRLSEnabled": false + }, + "public.knowledge_connector_permission_grant": { + "name": "knowledge_connector_permission_grant", + "schema": "", + "columns": { + "connector_id": { + "name": "connector_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "group_key": { + "name": "group_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "subject_token": { + "name": "subject_token", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "kcpg_subject_idx": { + "name": "kcpg_subject_idx", + "columns": [ + { + "expression": "subject_token", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "connector_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "group_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "kcpg_snapshot_fk": { + "name": "kcpg_snapshot_fk", + "tableFrom": "knowledge_connector_permission_grant", + "tableTo": "knowledge_connector_permission_snapshot", + "columnsFrom": ["connector_id"], + "columnsTo": ["connector_id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "kcpg_pk": { + "name": "kcpg_pk", + "columns": ["connector_id", "group_key", "subject_token"] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "kcpg_group_check": { + "name": "kcpg_group_check", + "value": "length(\"knowledge_connector_permission_grant\".\"group_key\") BETWEEN 1 AND 255" + }, + "kcpg_subject_check": { + "name": "kcpg_subject_check", + "value": "\"knowledge_connector_permission_grant\".\"subject_token\" ~ '^u:[^[:space:]A-Z]+@[^[:space:]A-Z]+$'" + } + }, + "isRLSEnabled": false + }, + "public.knowledge_connector_permission_snapshot": { + "name": "knowledge_connector_permission_snapshot", + "schema": "", + "columns": { + "connector_id": { + "name": "connector_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "revision": { + "name": "revision", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "kcps_connector_fk": { + "name": "kcps_connector_fk", + "tableFrom": "knowledge_connector_permission_snapshot", + "tableTo": "knowledge_connector", + "columnsFrom": ["connector_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "kcps_revision_check": { + "name": "kcps_revision_check", + "value": "\"knowledge_connector_permission_snapshot\".\"revision\" > 0" + } + }, + "isRLSEnabled": false + }, + "public.knowledge_connector_sync_log": { + "name": "knowledge_connector_sync_log", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "connector_id": { + "name": "connector_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "started_at": { + "name": "started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "docs_added": { + "name": "docs_added", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "docs_updated": { + "name": "docs_updated", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "docs_deleted": { + "name": "docs_deleted", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "docs_unchanged": { + "name": "docs_unchanged", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "docs_skipped": { + "name": "docs_skipped", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "docs_failed": { + "name": "docs_failed", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "listed_count": { + "name": "listed_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "kcsl_connector_started_at_idx": { + "name": "kcsl_connector_started_at_idx", + "columns": [ + { + "expression": "connector_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "\"started_at\" DESC", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "kcsl_started_at_partial_idx": { + "name": "kcsl_started_at_partial_idx", + "columns": [ + { + "expression": "started_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"knowledge_connector_sync_log\".\"status\" = 'started'", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "knowledge_connector_sync_log_connector_id_knowledge_connector_id_fk": { + "name": "knowledge_connector_sync_log_connector_id_knowledge_connector_id_fk", + "tableFrom": "knowledge_connector_sync_log", + "tableTo": "knowledge_connector", + "columnsFrom": ["connector_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.knowledge_document_observation": { + "name": "knowledge_document_observation", + "schema": "", + "columns": { + "document_id": { + "name": "document_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "member_id": { + "name": "member_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "run_id": { + "name": "run_id", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "kdo_member_idx": { + "name": "kdo_member_idx", + "columns": [ + { + "expression": "member_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "knowledge_document_observation_document_id_document_id_fk": { + "name": "knowledge_document_observation_document_id_document_id_fk", + "tableFrom": "knowledge_document_observation", + "tableTo": "document", + "columnsFrom": ["document_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "knowledge_document_observation_member_id_knowledge_connector_member_id_fk": { + "name": "knowledge_document_observation_member_id_knowledge_connector_member_id_fk", + "tableFrom": "knowledge_document_observation", + "tableTo": "knowledge_connector_member", + "columnsFrom": ["member_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "knowledge_document_observation_document_id_member_id_pk": { + "name": "knowledge_document_observation_document_id_member_id_pk", + "columns": ["document_id", "member_id"] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.knowledge_external_directory": { + "name": "knowledge_external_directory", + "schema": "", + "columns": { + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tenant_id": { + "name": "tenant_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "sync_lock_token": { + "name": "sync_lock_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sync_lock_lease_at": { + "name": "sync_lock_lease_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_started_at": { + "name": "last_started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_complete_sync_at": { + "name": "last_complete_sync_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "ked_organization_id_idx": { + "name": "ked_organization_id_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "ked_workspace_identity_unique": { + "name": "ked_workspace_identity_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "tenant_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "ked_organization_identity_unique": { + "name": "ked_organization_identity_unique", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "tenant_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "knowledge_external_directory_workspace_id_workspace_id_fk": { + "name": "knowledge_external_directory_workspace_id_workspace_id_fk", + "tableFrom": "knowledge_external_directory", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "knowledge_external_directory_organization_id_organization_id_fk": { + "name": "knowledge_external_directory_organization_id_organization_id_fk", + "tableFrom": "knowledge_external_directory", + "tableTo": "organization", + "columnsFrom": ["organization_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "ked_owner_check": { + "name": "ked_owner_check", + "value": "num_nonnulls(\"knowledge_external_directory\".\"workspace_id\", \"knowledge_external_directory\".\"organization_id\") = 1" + } + }, + "isRLSEnabled": false + }, + "public.knowledge_external_group": { + "name": "knowledge_external_group", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tenant_id": { + "name": "tenant_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "external_group_id": { + "name": "external_group_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "last_synced_at": { + "name": "last_synced_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "keg_organization_id_idx": { + "name": "keg_organization_id_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "keg_organization_identity_unique": { + "name": "keg_organization_identity_unique", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "tenant_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "external_group_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "keg_organization_synced_idx": { + "name": "keg_organization_synced_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "last_synced_at", + "isExpression": false, + "asc": true, + "nulls": "first" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "keg_identity_unique": { + "name": "keg_identity_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "tenant_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "external_group_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "keg_workspace_synced_idx": { + "name": "keg_workspace_synced_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "last_synced_at", + "isExpression": false, + "asc": true, + "nulls": "first" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "knowledge_external_group_organization_id_organization_id_fk": { + "name": "knowledge_external_group_organization_id_organization_id_fk", + "tableFrom": "knowledge_external_group", + "tableTo": "organization", + "columnsFrom": ["organization_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "keg_workspace_fk": { + "name": "keg_workspace_fk", + "tableFrom": "knowledge_external_group", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "keg_owner_check": { + "name": "keg_owner_check", + "value": "num_nonnulls(\"knowledge_external_group\".\"workspace_id\", \"knowledge_external_group\".\"organization_id\") = 1" + } + }, + "isRLSEnabled": false + }, + "public.knowledge_external_group_member": { + "name": "knowledge_external_group_member", + "schema": "", + "columns": { + "group_id": { + "name": "group_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "subject_token": { + "name": "subject_token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "kegm_subject_token_idx": { + "name": "kegm_subject_token_idx", + "columns": [ + { + "expression": "subject_token", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "kegm_group_fk": { + "name": "kegm_group_fk", + "tableFrom": "knowledge_external_group_member", + "tableTo": "knowledge_external_group", + "columnsFrom": ["group_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "knowledge_external_group_member_group_id_subject_token_pk": { + "name": "knowledge_external_group_member_group_id_subject_token_pk", + "columns": ["group_id", "subject_token"] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.mcp_server_oauth": { + "name": "mcp_server_oauth", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "mcp_server_id": { + "name": "mcp_server_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "client_information": { + "name": "client_information", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tokens": { + "name": "tokens", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "code_verifier": { + "name": "code_verifier", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "state": { + "name": "state", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "state_created_at": { + "name": "state_created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_refreshed_at": { + "name": "last_refreshed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "mcp_server_oauth_server_unique": { + "name": "mcp_server_oauth_server_unique", + "columns": [ + { + "expression": "mcp_server_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "mcp_server_oauth_state_idx": { + "name": "mcp_server_oauth_state_idx", + "columns": [ + { + "expression": "state", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "mcp_server_oauth_mcp_server_id_mcp_servers_id_fk": { + "name": "mcp_server_oauth_mcp_server_id_mcp_servers_id_fk", + "tableFrom": "mcp_server_oauth", + "tableTo": "mcp_servers", + "columnsFrom": ["mcp_server_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "mcp_server_oauth_user_id_user_id_fk": { + "name": "mcp_server_oauth_user_id_user_id_fk", + "tableFrom": "mcp_server_oauth", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "mcp_server_oauth_workspace_id_workspace_id_fk": { + "name": "mcp_server_oauth_workspace_id_workspace_id_fk", + "tableFrom": "mcp_server_oauth", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "mcp_server_oauth_organization_id_organization_id_fk": { + "name": "mcp_server_oauth_organization_id_organization_id_fk", + "tableFrom": "mcp_server_oauth", + "tableTo": "organization", + "columnsFrom": ["organization_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "mcp_server_oauth_owner_check": { + "name": "mcp_server_oauth_owner_check", + "value": "num_nonnulls(\"mcp_server_oauth\".\"workspace_id\", \"mcp_server_oauth\".\"organization_id\") = 1" + } + }, + "isRLSEnabled": false + }, + "public.mcp_servers": { + "name": "mcp_servers", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "credential_group_id": { + "name": "credential_group_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "managed_connector_id": { + "name": "managed_connector_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "oauth_config_version": { + "name": "oauth_config_version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "transport": { + "name": "transport", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "auth_type": { + "name": "auth_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'headers'" + }, + "oauth_client_id": { + "name": "oauth_client_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "oauth_client_secret": { + "name": "oauth_client_secret", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "headers": { + "name": "headers", + "type": "json", + "primaryKey": false, + "notNull": false, + "default": "'{}'" + }, + "timeout": { + "name": "timeout", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 30000 + }, + "retries": { + "name": "retries", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 3 + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "last_connected": { + "name": "last_connected", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "connection_status": { + "name": "connection_status", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'disconnected'" + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status_config": { + "name": "status_config", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'" + }, + "tool_count": { + "name": "tool_count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "last_tools_refresh": { + "name": "last_tools_refresh", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "total_requests": { + "name": "total_requests", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "last_used": { + "name": "last_used", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "mcp_servers_organization_id_idx": { + "name": "mcp_servers_organization_id_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "mcp_servers_workspace_enabled_idx": { + "name": "mcp_servers_workspace_enabled_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "enabled", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "mcp_servers_credential_group_idx": { + "name": "mcp_servers_credential_group_idx", + "columns": [ + { + "expression": "credential_group_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "mcp_servers_credential_group_managed_connector_unique": { + "name": "mcp_servers_credential_group_managed_connector_unique", + "columns": [ + { + "expression": "credential_group_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "managed_connector_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"mcp_servers\".\"credential_group_id\" IS NOT NULL AND \"mcp_servers\".\"managed_connector_id\" IS NOT NULL AND \"mcp_servers\".\"deleted_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "mcp_servers_workspace_deleted_partial_idx": { + "name": "mcp_servers_workspace_deleted_partial_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "deleted_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"mcp_servers\".\"deleted_at\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "mcp_servers_workspace_id_workspace_id_fk": { + "name": "mcp_servers_workspace_id_workspace_id_fk", + "tableFrom": "mcp_servers", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "mcp_servers_organization_id_organization_id_fk": { + "name": "mcp_servers_organization_id_organization_id_fk", + "tableFrom": "mcp_servers", + "tableTo": "organization", + "columnsFrom": ["organization_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "mcp_servers_credential_group_id_credential_group_id_fk": { + "name": "mcp_servers_credential_group_id_credential_group_id_fk", + "tableFrom": "mcp_servers", + "tableTo": "credential_group", + "columnsFrom": ["credential_group_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "mcp_servers_created_by_user_id_fk": { + "name": "mcp_servers_created_by_user_id_fk", + "tableFrom": "mcp_servers", + "tableTo": "user", + "columnsFrom": ["created_by"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "mcp_servers_owner_check": { + "name": "mcp_servers_owner_check", + "value": "num_nonnulls(\"mcp_servers\".\"workspace_id\", \"mcp_servers\".\"organization_id\") = 1" + }, + "mcp_servers_organization_managed_check": { + "name": "mcp_servers_organization_managed_check", + "value": "\"mcp_servers\".\"organization_id\" IS NULL OR \"mcp_servers\".\"credential_group_id\" IS NOT NULL" + }, + "mcp_servers_credential_group_managed_connector_check": { + "name": "mcp_servers_credential_group_managed_connector_check", + "value": "\"mcp_servers\".\"credential_group_id\" IS NULL OR \"mcp_servers\".\"managed_connector_id\" IS NOT NULL" + }, + "mcp_servers_managed_connector_oauth_check": { + "name": "mcp_servers_managed_connector_oauth_check", + "value": "\"mcp_servers\".\"managed_connector_id\" IS NULL OR \"mcp_servers\".\"auth_type\" = 'oauth'" + } + }, + "isRLSEnabled": false + }, + "public.member": { + "name": "member", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "member_user_id_unique": { + "name": "member_user_id_unique", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "member_organization_id_idx": { + "name": "member_organization_id_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "member_user_id_user_id_fk": { + "name": "member_user_id_user_id_fk", + "tableFrom": "member", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "member_organization_id_organization_id_fk": { + "name": "member_organization_id_organization_id_fk", + "tableFrom": "member", + "tableTo": "organization", + "columnsFrom": ["organization_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.memory": { + "name": "memory", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "key": { + "name": "key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "secret_provenance_version": { + "name": "secret_provenance_version", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "memory_key_idx": { + "name": "memory_key_idx", + "columns": [ + { + "expression": "key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "memory_workspace_idx": { + "name": "memory_workspace_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "memory_workspace_key_idx": { + "name": "memory_workspace_key_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "memory_workspace_deleted_partial_idx": { + "name": "memory_workspace_deleted_partial_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "deleted_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"memory\".\"deleted_at\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "memory_workspace_id_workspace_id_fk": { + "name": "memory_workspace_id_workspace_id_fk", + "tableFrom": "memory", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.memory_secret_provenance": { + "name": "memory_secret_provenance", + "schema": "", + "columns": { + "memory_id": { + "name": "memory_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "content_hash": { + "name": "content_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "entries": { + "name": "entries", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "memory_secret_provenance_memory_id_memory_id_fk": { + "name": "memory_secret_provenance_memory_id_memory_id_fk", + "tableFrom": "memory_secret_provenance", + "tableTo": "memory", + "columnsFrom": ["memory_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "memory_secret_provenance_status_check": { + "name": "memory_secret_provenance_status_check", + "value": "\"memory_secret_provenance\".\"status\" IN ('exact', 'unknown')" + } + }, + "isRLSEnabled": false + }, + "public.mothership_inbox_allowed_sender": { + "name": "mothership_inbox_allowed_sender", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "added_by": { + "name": "added_by", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "inbox_sender_ws_email_idx": { + "name": "inbox_sender_ws_email_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "email", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "mothership_inbox_allowed_sender_workspace_id_workspace_id_fk": { + "name": "mothership_inbox_allowed_sender_workspace_id_workspace_id_fk", + "tableFrom": "mothership_inbox_allowed_sender", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "mothership_inbox_allowed_sender_added_by_user_id_fk": { + "name": "mothership_inbox_allowed_sender_added_by_user_id_fk", + "tableFrom": "mothership_inbox_allowed_sender", + "tableTo": "user", + "columnsFrom": ["added_by"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.mothership_inbox_task": { + "name": "mothership_inbox_task", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "from_email": { + "name": "from_email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "from_name": { + "name": "from_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "subject": { + "name": "subject", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "body_preview": { + "name": "body_preview", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "body_text": { + "name": "body_text", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "body_html": { + "name": "body_html", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "email_message_id": { + "name": "email_message_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "in_reply_to": { + "name": "in_reply_to", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "response_message_id": { + "name": "response_message_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "agentmail_message_id": { + "name": "agentmail_message_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'received'" + }, + "chat_id": { + "name": "chat_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "trigger_job_id": { + "name": "trigger_job_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "result_summary": { + "name": "result_summary", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "rejection_reason": { + "name": "rejection_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "has_attachments": { + "name": "has_attachments", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "cc_recipients": { + "name": "cc_recipients", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "processing_started_at": { + "name": "processing_started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "inbox_task_ws_created_at_idx": { + "name": "inbox_task_ws_created_at_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "inbox_task_ws_status_idx": { + "name": "inbox_task_ws_status_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "inbox_task_response_msg_id_idx": { + "name": "inbox_task_response_msg_id_idx", + "columns": [ + { + "expression": "response_message_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "inbox_task_email_msg_id_idx": { + "name": "inbox_task_email_msg_id_idx", + "columns": [ + { + "expression": "email_message_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "mothership_inbox_task_workspace_id_workspace_id_fk": { + "name": "mothership_inbox_task_workspace_id_workspace_id_fk", + "tableFrom": "mothership_inbox_task", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "mothership_inbox_task_chat_id_copilot_chats_id_fk": { + "name": "mothership_inbox_task_chat_id_copilot_chats_id_fk", + "tableFrom": "mothership_inbox_task", + "tableTo": "copilot_chats", + "columnsFrom": ["chat_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.mothership_inbox_webhook": { + "name": "mothership_inbox_webhook", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "webhook_id": { + "name": "webhook_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "secret": { + "name": "secret", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "mothership_inbox_webhook_workspace_id_workspace_id_fk": { + "name": "mothership_inbox_webhook_workspace_id_workspace_id_fk", + "tableFrom": "mothership_inbox_webhook", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "mothership_inbox_webhook_workspace_id_unique": { + "name": "mothership_inbox_webhook_workspace_id_unique", + "nullsNotDistinct": false, + "columns": ["workspace_id"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.mothership_settings": { + "name": "mothership_settings", + "schema": "", + "columns": { + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "mcp_tool_refs": { + "name": "mcp_tool_refs", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "custom_tool_refs": { + "name": "custom_tool_refs", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "skill_refs": { + "name": "skill_refs", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "mothership_settings_workspace_id_workspace_id_fk": { + "name": "mothership_settings_workspace_id_workspace_id_fk", + "tableFrom": "mothership_settings", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.oauth_access_token": { + "name": "oauth_access_token", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "client_id": { + "name": "client_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "session_id": { + "name": "session_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "reference_id": { + "name": "reference_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "refresh_id": { + "name": "refresh_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "scopes": { + "name": "scopes", + "type": "text[]", + "primaryKey": false, + "notNull": true + }, + "resource": { + "name": "resource", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "oauth_access_token_client_id_idx": { + "name": "oauth_access_token_client_id_idx", + "columns": [ + { + "expression": "client_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "oauth_access_token_session_id_idx": { + "name": "oauth_access_token_session_id_idx", + "columns": [ + { + "expression": "session_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "oauth_access_token_refresh_id_idx": { + "name": "oauth_access_token_refresh_id_idx", + "columns": [ + { + "expression": "refresh_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "oauth_access_token_user_client_idx": { + "name": "oauth_access_token_user_client_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "client_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "oauth_access_token_expires_at_idx": { + "name": "oauth_access_token_expires_at_idx", + "columns": [ + { + "expression": "expires_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "oauth_access_token_client_id_oauth_client_client_id_fk": { + "name": "oauth_access_token_client_id_oauth_client_client_id_fk", + "tableFrom": "oauth_access_token", + "tableTo": "oauth_client", + "columnsFrom": ["client_id"], + "columnsTo": ["client_id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "oauth_access_token_session_id_session_id_fk": { + "name": "oauth_access_token_session_id_session_id_fk", + "tableFrom": "oauth_access_token", + "tableTo": "session", + "columnsFrom": ["session_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "oauth_access_token_user_id_user_id_fk": { + "name": "oauth_access_token_user_id_user_id_fk", + "tableFrom": "oauth_access_token", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "oauth_access_token_refresh_id_oauth_refresh_token_id_fk": { + "name": "oauth_access_token_refresh_id_oauth_refresh_token_id_fk", + "tableFrom": "oauth_access_token", + "tableTo": "oauth_refresh_token", + "columnsFrom": ["refresh_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "oauth_access_token_token_unique": { + "name": "oauth_access_token_token_unique", + "nullsNotDistinct": false, + "columns": ["token"] + } + }, + "policies": {}, + "checkConstraints": { + "oauth_access_token_search_resource_check": { + "name": "oauth_access_token_search_resource_check", + "value": "NOT ('search:read' = ANY(\"oauth_access_token\".\"scopes\")) OR \"oauth_access_token\".\"resource\" IS NOT NULL" + } + }, + "isRLSEnabled": false + }, + "public.oauth_client": { + "name": "oauth_client", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "client_id": { + "name": "client_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "client_secret": { + "name": "client_secret", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "disabled": { + "name": "disabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "skip_consent": { + "name": "skip_consent", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "enable_end_session": { + "name": "enable_end_session", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "subject_type": { + "name": "subject_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "scopes": { + "name": "scopes", + "type": "text[]", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "uri": { + "name": "uri", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "contacts": { + "name": "contacts", + "type": "text[]", + "primaryKey": false, + "notNull": false + }, + "tos": { + "name": "tos", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "policy": { + "name": "policy", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "software_id": { + "name": "software_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "software_version": { + "name": "software_version", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "software_statement": { + "name": "software_statement", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "redirect_uris": { + "name": "redirect_uris", + "type": "text[]", + "primaryKey": false, + "notNull": true + }, + "post_logout_redirect_uris": { + "name": "post_logout_redirect_uris", + "type": "text[]", + "primaryKey": false, + "notNull": false + }, + "token_endpoint_auth_method": { + "name": "token_endpoint_auth_method", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "grant_types": { + "name": "grant_types", + "type": "text[]", + "primaryKey": false, + "notNull": false + }, + "response_types": { + "name": "response_types", + "type": "text[]", + "primaryKey": false, + "notNull": false + }, + "public": { + "name": "public", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "require_pkce": { + "name": "require_pkce", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "reference_id": { + "name": "reference_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "oauth_client_user_id_idx": { + "name": "oauth_client_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "oauth_client_user_id_user_id_fk": { + "name": "oauth_client_user_id_user_id_fk", + "tableFrom": "oauth_client", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "oauth_client_client_id_unique": { + "name": "oauth_client_client_id_unique", + "nullsNotDistinct": false, + "columns": ["client_id"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.oauth_consent": { + "name": "oauth_consent", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "client_id": { + "name": "client_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "reference_id": { + "name": "reference_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "scopes": { + "name": "scopes", + "type": "text[]", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "oauth_consent_client_id_idx": { + "name": "oauth_consent_client_id_idx", + "columns": [ + { + "expression": "client_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "oauth_consent_client_id_oauth_client_client_id_fk": { + "name": "oauth_consent_client_id_oauth_client_client_id_fk", + "tableFrom": "oauth_consent", + "tableTo": "oauth_client", + "columnsFrom": ["client_id"], + "columnsTo": ["client_id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "oauth_consent_user_id_user_id_fk": { + "name": "oauth_consent_user_id_user_id_fk", + "tableFrom": "oauth_consent", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "oauth_consent_user_client_reference_unique": { + "name": "oauth_consent_user_client_reference_unique", + "nullsNotDistinct": true, + "columns": ["user_id", "client_id", "reference_id"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.oauth_refresh_token": { + "name": "oauth_refresh_token", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "client_id": { + "name": "client_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "session_id": { + "name": "session_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "reference_id": { + "name": "reference_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "revoked": { + "name": "revoked", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "auth_time": { + "name": "auth_time", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "scopes": { + "name": "scopes", + "type": "text[]", + "primaryKey": false, + "notNull": true + }, + "resource": { + "name": "resource", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "family_id": { + "name": "family_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "generation": { + "name": "generation", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "oauth_refresh_token_client_id_idx": { + "name": "oauth_refresh_token_client_id_idx", + "columns": [ + { + "expression": "client_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "oauth_refresh_token_session_id_idx": { + "name": "oauth_refresh_token_session_id_idx", + "columns": [ + { + "expression": "session_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "oauth_refresh_token_user_client_idx": { + "name": "oauth_refresh_token_user_client_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "client_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "oauth_refresh_token_expires_at_idx": { + "name": "oauth_refresh_token_expires_at_idx", + "columns": [ + { + "expression": "expires_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "oauth_refresh_token_client_id_oauth_client_client_id_fk": { + "name": "oauth_refresh_token_client_id_oauth_client_client_id_fk", + "tableFrom": "oauth_refresh_token", + "tableTo": "oauth_client", + "columnsFrom": ["client_id"], + "columnsTo": ["client_id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "oauth_refresh_token_session_id_session_id_fk": { + "name": "oauth_refresh_token_session_id_session_id_fk", + "tableFrom": "oauth_refresh_token", + "tableTo": "session", + "columnsFrom": ["session_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "oauth_refresh_token_user_id_user_id_fk": { + "name": "oauth_refresh_token_user_id_user_id_fk", + "tableFrom": "oauth_refresh_token", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "oauth_refresh_token_family_id_oauth_token_family_id_fk": { + "name": "oauth_refresh_token_family_id_oauth_token_family_id_fk", + "tableFrom": "oauth_refresh_token", + "tableTo": "oauth_token_family", + "columnsFrom": ["family_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "oauth_refresh_token_token_unique": { + "name": "oauth_refresh_token_token_unique", + "nullsNotDistinct": false, + "columns": ["token"] + }, + "oauth_refresh_token_family_generation_unique": { + "name": "oauth_refresh_token_family_generation_unique", + "nullsNotDistinct": false, + "columns": ["family_id", "generation"] + } + }, + "policies": {}, + "checkConstraints": { + "oauth_refresh_token_generation_check": { + "name": "oauth_refresh_token_generation_check", + "value": "\"oauth_refresh_token\".\"generation\" BETWEEN 0 AND 1000" + }, + "oauth_refresh_token_search_resource_check": { + "name": "oauth_refresh_token_search_resource_check", + "value": "NOT ('search:read' = ANY(\"oauth_refresh_token\".\"scopes\")) OR \"oauth_refresh_token\".\"resource\" IS NOT NULL" + } + }, + "isRLSEnabled": false + }, + "public.oauth_token_family": { + "name": "oauth_token_family", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "client_id": { + "name": "client_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "session_id": { + "name": "session_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "reference_id": { + "name": "reference_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "consent_id": { + "name": "consent_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "current_generation": { + "name": "current_generation", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "oauth_token_family_client_id_idx": { + "name": "oauth_token_family_client_id_idx", + "columns": [ + { + "expression": "client_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "oauth_token_family_session_id_idx": { + "name": "oauth_token_family_session_id_idx", + "columns": [ + { + "expression": "session_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "oauth_token_family_user_client_idx": { + "name": "oauth_token_family_user_client_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "client_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "oauth_token_family_consent_id_idx": { + "name": "oauth_token_family_consent_id_idx", + "columns": [ + { + "expression": "consent_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "oauth_token_family_expires_at_idx": { + "name": "oauth_token_family_expires_at_idx", + "columns": [ + { + "expression": "expires_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "oauth_token_family_client_id_oauth_client_client_id_fk": { + "name": "oauth_token_family_client_id_oauth_client_client_id_fk", + "tableFrom": "oauth_token_family", + "tableTo": "oauth_client", + "columnsFrom": ["client_id"], + "columnsTo": ["client_id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "oauth_token_family_session_id_session_id_fk": { + "name": "oauth_token_family_session_id_session_id_fk", + "tableFrom": "oauth_token_family", + "tableTo": "session", + "columnsFrom": ["session_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "oauth_token_family_user_id_user_id_fk": { + "name": "oauth_token_family_user_id_user_id_fk", + "tableFrom": "oauth_token_family", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "oauth_token_family_consent_id_oauth_consent_id_fk": { + "name": "oauth_token_family_consent_id_oauth_consent_id_fk", + "tableFrom": "oauth_token_family", + "tableTo": "oauth_consent", + "columnsFrom": ["consent_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "oauth_token_family_generation_check": { + "name": "oauth_token_family_generation_check", + "value": "\"oauth_token_family\".\"current_generation\" BETWEEN 0 AND 1000" + } + }, + "isRLSEnabled": false + }, + "public.organization": { + "name": "organization", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "logo": { + "name": "logo", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "json", + "primaryKey": false, + "notNull": false + }, + "session_policy_settings": { + "name": "session_policy_settings", + "type": "json", + "primaryKey": false, + "notNull": false + }, + "security_policy_version": { + "name": "security_policy_version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "whitelabel_settings": { + "name": "whitelabel_settings", + "type": "json", + "primaryKey": false, + "notNull": false + }, + "data_retention_settings": { + "name": "data_retention_settings", + "type": "json", + "primaryKey": false, + "notNull": false + }, + "org_usage_limit": { + "name": "org_usage_limit", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "storage_used_bytes": { + "name": "storage_used_bytes", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "limit_notifications": { + "name": "limit_notifications", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "departed_member_usage": { + "name": "departed_member_usage", + "type": "numeric", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "credit_balance": { + "name": "credit_balance", + "type": "numeric", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.organization_byok_keys": { + "name": "organization_byok_keys", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "encrypted_api_key": { + "name": "encrypted_api_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "organization_byok_organization_provider_idx": { + "name": "organization_byok_organization_provider_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "organization_byok_keys_organization_id_organization_id_fk": { + "name": "organization_byok_keys_organization_id_organization_id_fk", + "tableFrom": "organization_byok_keys", + "tableTo": "organization", + "columnsFrom": ["organization_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "organization_byok_keys_created_by_user_id_fk": { + "name": "organization_byok_keys_created_by_user_id_fk", + "tableFrom": "organization_byok_keys", + "tableTo": "user", + "columnsFrom": ["created_by"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.organization_member_usage_limit": { + "name": "organization_member_usage_limit", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "usage_limit": { + "name": "usage_limit", + "type": "numeric", + "primaryKey": false, + "notNull": true + }, + "set_by": { + "name": "set_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "org_member_usage_limit_org_user_unique": { + "name": "org_member_usage_limit_org_user_unique", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "org_member_usage_limit_organization_id_idx": { + "name": "org_member_usage_limit_organization_id_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "organization_member_usage_limit_organization_id_organization_id_fk": { + "name": "organization_member_usage_limit_organization_id_organization_id_fk", + "tableFrom": "organization_member_usage_limit", + "tableTo": "organization", + "columnsFrom": ["organization_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "organization_member_usage_limit_user_id_user_id_fk": { + "name": "organization_member_usage_limit_user_id_user_id_fk", + "tableFrom": "organization_member_usage_limit", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "organization_member_usage_limit_set_by_user_id_fk": { + "name": "organization_member_usage_limit_set_by_user_id_fk", + "tableFrom": "organization_member_usage_limit", + "tableTo": "user", + "columnsFrom": ["set_by"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.organization_search_integration": { + "name": "organization_search_integration", + "schema": "", + "columns": { + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "connector_type": { + "name": "connector_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "approved": { + "name": "approved", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "organization_search_integration_organization_id_organization_id_fk": { + "name": "organization_search_integration_organization_id_organization_id_fk", + "tableFrom": "organization_search_integration", + "tableTo": "organization", + "columnsFrom": ["organization_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "organization_search_integration_organization_id_connector_type_pk": { + "name": "organization_search_integration_organization_id_connector_type_pk", + "columns": ["organization_id", "connector_type"] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.organization_search_invocation": { + "name": "organization_search_invocation", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "surface": { + "name": "surface", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_types": { + "name": "source_types", + "type": "text[]", + "primaryKey": false, + "notNull": true + }, + "result_count": { + "name": "result_count", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "organization_search_invocation_org_created_idx": { + "name": "organization_search_invocation_org_created_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "organization_search_invocation_user_idx": { + "name": "organization_search_invocation_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "organization_search_invocation_organization_id_organization_id_fk": { + "name": "organization_search_invocation_organization_id_organization_id_fk", + "tableFrom": "organization_search_invocation", + "tableTo": "organization", + "columnsFrom": ["organization_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "organization_search_invocation_user_id_user_id_fk": { + "name": "organization_search_invocation_user_id_user_id_fk", + "tableFrom": "organization_search_invocation", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "organization_search_invocation_result_count_bounds": { + "name": "organization_search_invocation_result_count_bounds", + "value": "\"organization_search_invocation\".\"result_count\" BETWEEN 0 AND 100" + }, + "organization_search_invocation_source_types_bounds": { + "name": "organization_search_invocation_source_types_bounds", + "value": "cardinality(\"organization_search_invocation\".\"source_types\") <= 100" + } + }, + "isRLSEnabled": false + }, + "public.outbox_event": { + "name": "outbox_event", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "event_type": { + "name": "event_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "payload": { + "name": "payload", + "type": "json", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "max_attempts": { + "name": "max_attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 10 + }, + "available_at": { + "name": "available_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "locked_at": { + "name": "locked_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "processed_at": { + "name": "processed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "outbox_event_status_available_idx": { + "name": "outbox_event_status_available_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "available_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "outbox_event_pending_type_available_idx": { + "name": "outbox_event_pending_type_available_idx", + "columns": [ + { + "expression": "event_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "available_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"outbox_event\".\"status\" = 'pending'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "outbox_event_locked_at_idx": { + "name": "outbox_event_locked_at_idx", + "columns": [ + { + "expression": "locked_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "outbox_event_type_created_idx": { + "name": "outbox_event_type_created_idx", + "columns": [ + { + "expression": "event_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.paused_executions": { + "name": "paused_executions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "execution_id": { + "name": "execution_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "execution_snapshot": { + "name": "execution_snapshot", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "pause_points": { + "name": "pause_points", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "total_pause_count": { + "name": "total_pause_count", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "resumed_count": { + "name": "resumed_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "automatic_resume_retry_count": { + "name": "automatic_resume_retry_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'paused'" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "paused_at": { + "name": "paused_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "next_resume_at": { + "name": "next_resume_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "paused_executions_workflow_id_idx": { + "name": "paused_executions_workflow_id_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "paused_executions_status_idx": { + "name": "paused_executions_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "paused_executions_execution_id_unique": { + "name": "paused_executions_execution_id_unique", + "columns": [ + { + "expression": "execution_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "paused_executions_next_resume_at_idx": { + "name": "paused_executions_next_resume_at_idx", + "columns": [ + { + "expression": "next_resume_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "status = 'paused' AND next_resume_at IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "paused_executions_workflow_id_workflow_id_fk": { + "name": "paused_executions_workflow_id_workflow_id_fk", + "tableFrom": "paused_executions", + "tableTo": "workflow", + "columnsFrom": ["workflow_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pending_credential_draft": { + "name": "pending_credential_draft", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "display_name": { + "name": "display_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "credential_id": { + "name": "credential_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "oauth_config": { + "name": "oauth_config", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "pending_draft_organization_id_idx": { + "name": "pending_draft_organization_id_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pending_draft_user_provider_org": { + "name": "pending_draft_user_provider_org", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pending_draft_user_provider_ws": { + "name": "pending_draft_user_provider_ws", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pending_credential_draft_user_id_user_id_fk": { + "name": "pending_credential_draft_user_id_user_id_fk", + "tableFrom": "pending_credential_draft", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pending_credential_draft_workspace_id_workspace_id_fk": { + "name": "pending_credential_draft_workspace_id_workspace_id_fk", + "tableFrom": "pending_credential_draft", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pending_credential_draft_organization_id_organization_id_fk": { + "name": "pending_credential_draft_organization_id_organization_id_fk", + "tableFrom": "pending_credential_draft", + "tableTo": "organization", + "columnsFrom": ["organization_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pending_credential_draft_credential_id_credential_id_fk": { + "name": "pending_credential_draft_credential_id_credential_id_fk", + "tableFrom": "pending_credential_draft", + "tableTo": "credential", + "columnsFrom": ["credential_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "pending_draft_owner_check": { + "name": "pending_draft_owner_check", + "value": "num_nonnulls(\"pending_credential_draft\".\"workspace_id\", \"pending_credential_draft\".\"organization_id\") = 1" + } + }, + "isRLSEnabled": false + }, + "public.permission_group": { + "name": "permission_group", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "config": { + "name": "config", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'" + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "is_default": { + "name": "is_default", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "membership_mode": { + "name": "membership_mode", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'inherit'" + } + }, + "indexes": { + "permission_group_created_by_idx": { + "name": "permission_group_created_by_idx", + "columns": [ + { + "expression": "created_by", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "permission_group_organization_name_unique": { + "name": "permission_group_organization_name_unique", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "permission_group_organization_default_unique": { + "name": "permission_group_organization_default_unique", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "is_default = true", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "permission_group_organization_id_organization_id_fk": { + "name": "permission_group_organization_id_organization_id_fk", + "tableFrom": "permission_group", + "tableTo": "organization", + "columnsFrom": ["organization_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "permission_group_created_by_user_id_fk": { + "name": "permission_group_created_by_user_id_fk", + "tableFrom": "permission_group", + "tableTo": "user", + "columnsFrom": ["created_by"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.permission_group_member": { + "name": "permission_group_member", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "permission_group_id": { + "name": "permission_group_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "assigned_by": { + "name": "assigned_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "assigned_at": { + "name": "assigned_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "permission_group_member_group_id_idx": { + "name": "permission_group_member_group_id_idx", + "columns": [ + { + "expression": "permission_group_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "permission_group_member_group_user_unique": { + "name": "permission_group_member_group_user_unique", + "columns": [ + { + "expression": "permission_group_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "permission_group_member_organization_user_idx": { + "name": "permission_group_member_organization_user_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "permission_group_member_permission_group_id_permission_group_id_fk": { + "name": "permission_group_member_permission_group_id_permission_group_id_fk", + "tableFrom": "permission_group_member", + "tableTo": "permission_group", + "columnsFrom": ["permission_group_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "permission_group_member_organization_id_organization_id_fk": { + "name": "permission_group_member_organization_id_organization_id_fk", + "tableFrom": "permission_group_member", + "tableTo": "organization", + "columnsFrom": ["organization_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "permission_group_member_user_id_user_id_fk": { + "name": "permission_group_member_user_id_user_id_fk", + "tableFrom": "permission_group_member", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "permission_group_member_assigned_by_user_id_fk": { + "name": "permission_group_member_assigned_by_user_id_fk", + "tableFrom": "permission_group_member", + "tableTo": "user", + "columnsFrom": ["assigned_by"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.permission_group_workspace": { + "name": "permission_group_workspace", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "permission_group_id": { + "name": "permission_group_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "permission_group_workspace_workspace_id_idx": { + "name": "permission_group_workspace_workspace_id_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "permission_group_workspace_group_workspace_unique": { + "name": "permission_group_workspace_group_workspace_unique", + "columns": [ + { + "expression": "permission_group_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "permission_group_workspace_permission_group_id_permission_group_id_fk": { + "name": "permission_group_workspace_permission_group_id_permission_group_id_fk", + "tableFrom": "permission_group_workspace", + "tableTo": "permission_group", + "columnsFrom": ["permission_group_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "permission_group_workspace_workspace_id_workspace_id_fk": { + "name": "permission_group_workspace_workspace_id_workspace_id_fk", + "tableFrom": "permission_group_workspace", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "permission_group_workspace_organization_id_organization_id_fk": { + "name": "permission_group_workspace_organization_id_organization_id_fk", + "tableFrom": "permission_group_workspace", + "tableTo": "organization", + "columnsFrom": ["organization_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.permissions": { + "name": "permissions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "entity_type": { + "name": "entity_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "entity_id": { + "name": "entity_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "permission_type": { + "name": "permission_type", + "type": "permission_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "permissions_user_id_idx": { + "name": "permissions_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "permissions_entity_idx": { + "name": "permissions_entity_idx", + "columns": [ + { + "expression": "entity_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "entity_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "permissions_user_entity_type_idx": { + "name": "permissions_user_entity_type_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "entity_type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "permissions_user_entity_permission_idx": { + "name": "permissions_user_entity_permission_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "entity_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "permission_type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "permissions_unique_constraint": { + "name": "permissions_unique_constraint", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "entity_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "entity_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "permissions_user_id_user_id_fk": { + "name": "permissions_user_id_user_id_fk", + "tableFrom": "permissions", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pinned_item": { + "name": "pinned_item", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "resource_type": { + "name": "resource_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "resource_id": { + "name": "resource_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "pinned_at": { + "name": "pinned_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "pinned_item_user_workspace_idx": { + "name": "pinned_item_user_workspace_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pinned_item_resource_idx": { + "name": "pinned_item_resource_idx", + "columns": [ + { + "expression": "resource_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "resource_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "pinned_item_user_resource_unique": { + "name": "pinned_item_user_resource_unique", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "resource_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "resource_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pinned_item_user_id_user_id_fk": { + "name": "pinned_item_user_id_user_id_fk", + "tableFrom": "pinned_item", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pinned_item_workspace_id_workspace_id_fk": { + "name": "pinned_item_workspace_id_workspace_id_fk", + "tableFrom": "pinned_item", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.public_share": { + "name": "public_share", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "resource_type": { + "name": "resource_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "resource_id": { + "name": "resource_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "auth_type": { + "name": "auth_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'public'" + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "allowed_emails": { + "name": "allowed_emails", + "type": "json", + "primaryKey": false, + "notNull": false, + "default": "'[]'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "public_share_token_unique": { + "name": "public_share_token_unique", + "columns": [ + { + "expression": "token", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "public_share_resource_unique": { + "name": "public_share_resource_unique", + "columns": [ + { + "expression": "resource_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "resource_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "public_share_resource_id_idx": { + "name": "public_share_resource_id_idx", + "columns": [ + { + "expression": "resource_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "public_share_workspace_id_idx": { + "name": "public_share_workspace_id_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "public_share_workspace_id_workspace_id_fk": { + "name": "public_share_workspace_id_workspace_id_fk", + "tableFrom": "public_share", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "public_share_created_by_user_id_fk": { + "name": "public_share_created_by_user_id_fk", + "tableFrom": "public_share", + "tableTo": "user", + "columnsFrom": ["created_by"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.rate_limit_bucket": { + "name": "rate_limit_bucket", + "schema": "", + "columns": { + "key": { + "name": "key", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "tokens": { + "name": "tokens", + "type": "numeric", + "primaryKey": false, + "notNull": true + }, + "last_refill_at": { + "name": "last_refill_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "blocked_until": { + "name": "blocked_until", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "capacity_state": { + "name": "capacity_state", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.resource_policy": { + "name": "resource_policy", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "resource_type": { + "name": "resource_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "resource_id": { + "name": "resource_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "revision": { + "name": "revision", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "document": { + "name": "document", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "updated_by": { + "name": "updated_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "resource_policy_organization_id_idx": { + "name": "resource_policy_organization_id_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "resource_policy_resource_unique": { + "name": "resource_policy_resource_unique", + "columns": [ + { + "expression": "resource_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "resource_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "resource_policy_workspace_id_idx": { + "name": "resource_policy_workspace_id_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "resource_policy_workspace_id_workspace_id_fk": { + "name": "resource_policy_workspace_id_workspace_id_fk", + "tableFrom": "resource_policy", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "resource_policy_organization_id_organization_id_fk": { + "name": "resource_policy_organization_id_organization_id_fk", + "tableFrom": "resource_policy", + "tableTo": "organization", + "columnsFrom": ["organization_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "resource_policy_created_by_user_id_fk": { + "name": "resource_policy_created_by_user_id_fk", + "tableFrom": "resource_policy", + "tableTo": "user", + "columnsFrom": ["created_by"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "resource_policy_updated_by_user_id_fk": { + "name": "resource_policy_updated_by_user_id_fk", + "tableFrom": "resource_policy", + "tableTo": "user", + "columnsFrom": ["updated_by"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "resource_policy_owner_check": { + "name": "resource_policy_owner_check", + "value": "num_nonnulls(\"resource_policy\".\"workspace_id\", \"resource_policy\".\"organization_id\") = 1" + } + }, + "isRLSEnabled": false + }, + "public.resume_queue": { + "name": "resume_queue", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "paused_execution_id": { + "name": "paused_execution_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "parent_execution_id": { + "name": "parent_execution_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "new_execution_id": { + "name": "new_execution_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "context_id": { + "name": "context_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "resume_input": { + "name": "resume_input", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "queued_at": { + "name": "queued_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "claimed_at": { + "name": "claimed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "failure_reason": { + "name": "failure_reason", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "resume_queue_parent_status_idx": { + "name": "resume_queue_parent_status_idx", + "columns": [ + { + "expression": "parent_execution_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "queued_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "resume_queue_new_execution_idx": { + "name": "resume_queue_new_execution_idx", + "columns": [ + { + "expression": "new_execution_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "resume_queue_paused_execution_id_paused_executions_id_fk": { + "name": "resume_queue_paused_execution_id_paused_executions_id_fk", + "tableFrom": "resume_queue", + "tableTo": "paused_executions", + "columnsFrom": ["paused_execution_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.sandbox_image": { + "name": "sandbox_image", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "spec_hash": { + "name": "spec_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "spec": { + "name": "spec", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "sandbox_image_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "image_ref": { + "name": "image_ref", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "provider_image_id": { + "name": "provider_image_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "build_id": { + "name": "build_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "materialization_generation": { + "name": "materialization_generation", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "error_code": { + "name": "error_code", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "error_detail": { + "name": "error_detail", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "last_used_at": { + "name": "last_used_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "sandbox_image_provider_spec_unique": { + "name": "sandbox_image_provider_spec_unique", + "columns": [ + { + "expression": "provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "spec_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "sandbox_image_status_idx": { + "name": "sandbox_image_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "sandbox_image_last_used_idx": { + "name": "sandbox_image_last_used_idx", + "columns": [ + { + "expression": "last_used_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.scim_connection": { + "name": "scim_connection", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "settings": { + "name": "settings", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "last_request_at": { + "name": "last_request_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "reconcile_lock_token": { + "name": "reconcile_lock_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "reconcile_lease_at": { + "name": "reconcile_lease_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "reconciled_at": { + "name": "reconciled_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "scim_connection_organization_unique": { + "name": "scim_connection_organization_unique", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "scim_connection_reconcile_due_idx": { + "name": "scim_connection_reconcile_due_idx", + "columns": [ + { + "expression": "reconciled_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "scim_connection_organization_id_organization_id_fk": { + "name": "scim_connection_organization_id_organization_id_fk", + "tableFrom": "scim_connection", + "tableTo": "organization", + "columnsFrom": ["organization_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "scim_connection_created_by_user_id_fk": { + "name": "scim_connection_created_by_user_id_fk", + "tableFrom": "scim_connection", + "tableTo": "user", + "columnsFrom": ["created_by"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.scim_credential": { + "name": "scim_credential", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "connection_id": { + "name": "connection_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "token_hash": { + "name": "token_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "token_prefix": { + "name": "token_prefix", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "scopes": { + "name": "scopes", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "revoked_at": { + "name": "revoked_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "revoked_by": { + "name": "revoked_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "last_used_at": { + "name": "last_used_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "scim_credential_token_hash_unique": { + "name": "scim_credential_token_hash_unique", + "columns": [ + { + "expression": "token_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "scim_credential_connection_idx": { + "name": "scim_credential_connection_idx", + "columns": [ + { + "expression": "connection_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "scim_credential_connection_id_scim_connection_id_fk": { + "name": "scim_credential_connection_id_scim_connection_id_fk", + "tableFrom": "scim_credential", + "tableTo": "scim_connection", + "columnsFrom": ["connection_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "scim_credential_revoked_by_user_id_fk": { + "name": "scim_credential_revoked_by_user_id_fk", + "tableFrom": "scim_credential", + "tableTo": "user", + "columnsFrom": ["revoked_by"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "scim_credential_created_by_user_id_fk": { + "name": "scim_credential_created_by_user_id_fk", + "tableFrom": "scim_credential", + "tableTo": "user", + "columnsFrom": ["created_by"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.scim_group": { + "name": "scim_group", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "connection_id": { + "name": "connection_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "external_id": { + "name": "external_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "display_name": { + "name": "display_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "display_name_key": { + "name": "display_name_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "order_key": { + "name": "order_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "scim_group_connection_display_name_unique": { + "name": "scim_group_connection_display_name_unique", + "columns": [ + { + "expression": "connection_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "display_name_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "scim_group_connection_external_id_unique": { + "name": "scim_group_connection_external_id_unique", + "columns": [ + { + "expression": "connection_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "external_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "external_id is not null", + "concurrently": false, + "method": "btree", + "with": {} + }, + "scim_group_connection_order_idx": { + "name": "scim_group_connection_order_idx", + "columns": [ + { + "expression": "connection_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "order_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "scim_group_connection_id_scim_connection_id_fk": { + "name": "scim_group_connection_id_scim_connection_id_fk", + "tableFrom": "scim_group", + "tableTo": "scim_connection", + "columnsFrom": ["connection_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.scim_group_mapping": { + "name": "scim_group_mapping", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "group_id": { + "name": "group_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "target_kind": { + "name": "target_kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "permission_group_id": { + "name": "permission_group_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "permission_type": { + "name": "permission_type", + "type": "permission_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'manual'" + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "scim_group_mapping_group_idx": { + "name": "scim_group_mapping_group_idx", + "columns": [ + { + "expression": "group_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "scim_group_mapping_permission_group_idx": { + "name": "scim_group_mapping_permission_group_idx", + "columns": [ + { + "expression": "permission_group_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "scim_group_mapping_workspace_idx": { + "name": "scim_group_mapping_workspace_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "scim_group_mapping_group_target_unique": { + "name": "scim_group_mapping_group_target_unique", + "columns": [ + { + "expression": "group_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "target_kind", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "coalesce(\"permission_group_id\", \"workspace_id\", \"role\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "scim_group_mapping_group_id_scim_group_id_fk": { + "name": "scim_group_mapping_group_id_scim_group_id_fk", + "tableFrom": "scim_group_mapping", + "tableTo": "scim_group", + "columnsFrom": ["group_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "scim_group_mapping_permission_group_id_permission_group_id_fk": { + "name": "scim_group_mapping_permission_group_id_permission_group_id_fk", + "tableFrom": "scim_group_mapping", + "tableTo": "permission_group", + "columnsFrom": ["permission_group_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "scim_group_mapping_workspace_id_workspace_id_fk": { + "name": "scim_group_mapping_workspace_id_workspace_id_fk", + "tableFrom": "scim_group_mapping", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "scim_group_mapping_created_by_user_id_fk": { + "name": "scim_group_mapping_created_by_user_id_fk", + "tableFrom": "scim_group_mapping", + "tableTo": "user", + "columnsFrom": ["created_by"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "scim_group_mapping_target_shape": { + "name": "scim_group_mapping_target_shape", + "value": "(\n (\"scim_group_mapping\".\"target_kind\" = 'permission_group' AND \"scim_group_mapping\".\"permission_group_id\" IS NOT NULL AND \"scim_group_mapping\".\"workspace_id\" IS NULL AND \"scim_group_mapping\".\"permission_type\" IS NULL AND \"scim_group_mapping\".\"role\" IS NULL)\n OR (\"scim_group_mapping\".\"target_kind\" = 'workspace' AND \"scim_group_mapping\".\"workspace_id\" IS NOT NULL AND \"scim_group_mapping\".\"permission_type\" IS NOT NULL AND \"scim_group_mapping\".\"permission_group_id\" IS NULL AND \"scim_group_mapping\".\"role\" IS NULL)\n OR (\"scim_group_mapping\".\"target_kind\" = 'org_role' AND \"scim_group_mapping\".\"role\" IS NOT NULL AND \"scim_group_mapping\".\"permission_group_id\" IS NULL AND \"scim_group_mapping\".\"workspace_id\" IS NULL AND \"scim_group_mapping\".\"permission_type\" IS NULL)\n )" + } + }, + "isRLSEnabled": false + }, + "public.scim_group_member": { + "name": "scim_group_member", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "group_id": { + "name": "group_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "scim_user_id": { + "name": "scim_user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "scim_group_member_group_user_unique": { + "name": "scim_group_member_group_user_unique", + "columns": [ + { + "expression": "group_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "scim_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "scim_group_member_scim_user_idx": { + "name": "scim_group_member_scim_user_idx", + "columns": [ + { + "expression": "scim_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "scim_group_member_group_id_scim_group_id_fk": { + "name": "scim_group_member_group_id_scim_group_id_fk", + "tableFrom": "scim_group_member", + "tableTo": "scim_group", + "columnsFrom": ["group_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "scim_group_member_scim_user_id_scim_user_id_fk": { + "name": "scim_group_member_scim_user_id_scim_user_id_fk", + "tableFrom": "scim_group_member", + "tableTo": "scim_user", + "columnsFrom": ["scim_user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.scim_projection_grant": { + "name": "scim_projection_grant", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "connection_id": { + "name": "connection_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "scim_user_id": { + "name": "scim_user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "target_kind": { + "name": "target_kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "target_id": { + "name": "target_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "permission_type": { + "name": "permission_type", + "type": "permission_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "baseline_permission": { + "name": "baseline_permission", + "type": "permission_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "origin": { + "name": "origin", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'directory'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "scim_projection_grant_user_target_unique": { + "name": "scim_projection_grant_user_target_unique", + "columns": [ + { + "expression": "scim_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "target_kind", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "target_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "scim_projection_grant_connection_idx": { + "name": "scim_projection_grant_connection_idx", + "columns": [ + { + "expression": "connection_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "scim_projection_grant_connection_id_scim_connection_id_fk": { + "name": "scim_projection_grant_connection_id_scim_connection_id_fk", + "tableFrom": "scim_projection_grant", + "tableTo": "scim_connection", + "columnsFrom": ["connection_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "scim_projection_grant_scim_user_id_scim_user_id_fk": { + "name": "scim_projection_grant_scim_user_id_scim_user_id_fk", + "tableFrom": "scim_projection_grant", + "tableTo": "scim_user", + "columnsFrom": ["scim_user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.scim_request_log": { + "name": "scim_request_log", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "connection_id": { + "name": "connection_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "credential_id": { + "name": "credential_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "method": { + "name": "method", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "path": { + "name": "path", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "scim_type": { + "name": "scim_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "detail": { + "name": "detail", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_agent": { + "name": "user_agent", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "duration_ms": { + "name": "duration_ms", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "scim_request_log_connection_created_idx": { + "name": "scim_request_log_connection_created_idx", + "columns": [ + { + "expression": "connection_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "scim_request_log_connection_id_scim_connection_id_fk": { + "name": "scim_request_log_connection_id_scim_connection_id_fk", + "tableFrom": "scim_request_log", + "tableTo": "scim_connection", + "columnsFrom": ["connection_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.scim_user": { + "name": "scim_user", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "connection_id": { + "name": "connection_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "external_id": { + "name": "external_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_name": { + "name": "user_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "active": { + "name": "active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "attributes": { + "name": "attributes", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "order_key": { + "name": "order_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "scim_user_connection_user_unique": { + "name": "scim_user_connection_user_unique", + "columns": [ + { + "expression": "connection_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "scim_user_connection_user_name_unique": { + "name": "scim_user_connection_user_name_unique", + "columns": [ + { + "expression": "connection_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "scim_user_connection_external_id_unique": { + "name": "scim_user_connection_external_id_unique", + "columns": [ + { + "expression": "connection_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "external_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "external_id is not null", + "concurrently": false, + "method": "btree", + "with": {} + }, + "scim_user_connection_order_idx": { + "name": "scim_user_connection_order_idx", + "columns": [ + { + "expression": "connection_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "order_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "scim_user_user_idx": { + "name": "scim_user_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "scim_user_connection_id_scim_connection_id_fk": { + "name": "scim_user_connection_id_scim_connection_id_fk", + "tableFrom": "scim_user", + "tableTo": "scim_connection", + "columnsFrom": ["connection_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "scim_user_user_id_user_id_fk": { + "name": "scim_user_user_id_user_id_fk", + "tableFrom": "scim_user", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.scim_user_tombstone": { + "name": "scim_user_tombstone", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "connection_id": { + "name": "connection_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "external_id": { + "name": "external_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "scim_user_tombstone_connection_external_id_unique": { + "name": "scim_user_tombstone_connection_external_id_unique", + "columns": [ + { + "expression": "connection_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "external_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "scim_user_tombstone_user_idx": { + "name": "scim_user_tombstone_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "scim_user_tombstone_connection_id_scim_connection_id_fk": { + "name": "scim_user_tombstone_connection_id_scim_connection_id_fk", + "tableFrom": "scim_user_tombstone", + "tableTo": "scim_connection", + "columnsFrom": ["connection_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "scim_user_tombstone_user_id_user_id_fk": { + "name": "scim_user_tombstone_user_id_user_id_fk", + "tableFrom": "scim_user_tombstone", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.secret_usage": { + "name": "secret_usage", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "secret_name": { + "name": "secret_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "secret_scope": { + "name": "secret_scope", + "type": "secret_usage_scope", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "secret_owner_user_id": { + "name": "secret_owner_user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "source": { + "name": "source", + "type": "secret_usage_source", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "actor_user_id": { + "name": "actor_user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "usage_date": { + "name": "usage_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "use_count": { + "name": "use_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "last_used_at": { + "name": "last_used_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "last_execution_id": { + "name": "last_execution_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "last_trigger": { + "name": "last_trigger", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "secret_usage_bucket_unique": { + "name": "secret_usage_bucket_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "secret_name", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "secret_scope", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "secret_owner_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "source", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "actor_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "usage_date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "secret_usage_secret_recent_idx": { + "name": "secret_usage_secret_recent_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "secret_name", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "secret_scope", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "secret_owner_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "last_used_at", + "isExpression": false, + "asc": false, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "secret_usage_workspace_id_workspace_id_fk": { + "name": "secret_usage_workspace_id_workspace_id_fk", + "tableFrom": "secret_usage", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.session": { + "name": "session", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "ip_address": { + "name": "ip_address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_agent": { + "name": "user_agent", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "active_organization_id": { + "name": "active_organization_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "impersonated_by": { + "name": "impersonated_by", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "session_user_id_idx": { + "name": "session_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "session_user_id_user_id_fk": { + "name": "session_user_id_user_id_fk", + "tableFrom": "session", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "session_active_organization_id_organization_id_fk": { + "name": "session_active_organization_id_organization_id_fk", + "tableFrom": "session", + "tableTo": "organization", + "columnsFrom": ["active_organization_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "session_token_unique": { + "name": "session_token_unique", + "nullsNotDistinct": false, + "columns": ["token"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.settings": { + "name": "settings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "theme": { + "name": "theme", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'system'" + }, + "auto_connect": { + "name": "auto_connect", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "telemetry_enabled": { + "name": "telemetry_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "email_preferences": { + "name": "email_preferences", + "type": "json", + "primaryKey": false, + "notNull": true, + "default": "'{}'" + }, + "billing_usage_notifications_enabled": { + "name": "billing_usage_notifications_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "show_training_controls": { + "name": "show_training_controls", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "super_user_mode_enabled": { + "name": "super_user_mode_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "mothership_environment": { + "name": "mothership_environment", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'default'" + }, + "error_notifications_enabled": { + "name": "error_notifications_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "snap_to_grid_size": { + "name": "snap_to_grid_size", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "show_action_bar": { + "name": "show_action_bar", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "auto_focus_on_click": { + "name": "auto_focus_on_click", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "timezone": { + "name": "timezone", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "copilot_enabled_models": { + "name": "copilot_enabled_models", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'" + }, + "copilot_auto_allowed_tools": { + "name": "copilot_auto_allowed_tools", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'" + }, + "last_active_workspace_id": { + "name": "last_active_workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "settings_user_id_user_id_fk": { + "name": "settings_user_id_user_id_fk", + "tableFrom": "settings", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "settings_user_id_unique": { + "name": "settings_user_id_unique", + "nullsNotDistinct": false, + "columns": ["user_id"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.sim_trigger_state": { + "name": "sim_trigger_state", + "schema": "", + "columns": { + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "block_id": { + "name": "block_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "scope_key": { + "name": "scope_key", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "last_fired_at": { + "name": "last_fired_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "sim_trigger_state_workflow_id_workflow_id_fk": { + "name": "sim_trigger_state_workflow_id_workflow_id_fk", + "tableFrom": "sim_trigger_state", + "tableTo": "workflow", + "columnsFrom": ["workflow_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "sim_trigger_state_workflow_id_block_id_scope_key_pk": { + "name": "sim_trigger_state_workflow_id_block_id_scope_key_pk", + "columns": ["workflow_id", "block_id", "scope_key"] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.skill": { + "name": "skill", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "skill_workspace_name_unique": { + "name": "skill_workspace_name_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "skill_workspace_id_workspace_id_fk": { + "name": "skill_workspace_id_workspace_id_fk", + "tableFrom": "skill", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "skill_user_id_user_id_fk": { + "name": "skill_user_id_user_id_fk", + "tableFrom": "skill", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.skill_member": { + "name": "skill_member", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "skill_id": { + "name": "skill_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "invited_by": { + "name": "invited_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "skill_member_user_id_idx": { + "name": "skill_member_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "skill_member_unique": { + "name": "skill_member_unique", + "columns": [ + { + "expression": "skill_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "skill_member_skill_id_skill_id_fk": { + "name": "skill_member_skill_id_skill_id_fk", + "tableFrom": "skill_member", + "tableTo": "skill", + "columnsFrom": ["skill_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "skill_member_user_id_user_id_fk": { + "name": "skill_member_user_id_user_id_fk", + "tableFrom": "skill_member", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "skill_member_invited_by_user_id_fk": { + "name": "skill_member_invited_by_user_id_fk", + "tableFrom": "skill_member", + "tableTo": "user", + "columnsFrom": ["invited_by"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.slack_app": { + "name": "slack_app", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "client_id": { + "name": "client_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "encrypted_client_secret": { + "name": "encrypted_client_secret", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "encrypted_signing_secret": { + "name": "encrypted_signing_secret", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "revision": { + "name": "revision", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "slack_app_organization_id_organization_id_fk": { + "name": "slack_app_organization_id_organization_id_fk", + "tableFrom": "slack_app", + "tableTo": "organization", + "columnsFrom": ["organization_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "slack_app_owner_check": { + "name": "slack_app_owner_check", + "value": "(\"slack_app\".\"kind\" = 'custom' AND \"slack_app\".\"organization_id\" IS NOT NULL) OR (\"slack_app\".\"kind\" = 'shared' AND \"slack_app\".\"organization_id\" IS NULL)" + }, + "slack_app_custom_credentials_check": { + "name": "slack_app_custom_credentials_check", + "value": "\"slack_app\".\"kind\" = 'shared' OR (\"slack_app\".\"client_id\" IS NOT NULL AND \"slack_app\".\"encrypted_client_secret\" IS NOT NULL AND \"slack_app\".\"encrypted_signing_secret\" IS NOT NULL)" + } + }, + "isRLSEnabled": false + }, + "public.slack_search_installation": { + "name": "slack_search_installation", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "credential_id": { + "name": "credential_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "app_id": { + "name": "app_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "slack_app_id": { + "name": "slack_app_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "team_id": { + "name": "team_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "team_name": { + "name": "team_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "bot_user_id": { + "name": "bot_user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "enterprise_id": { + "name": "enterprise_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "credential_version": { + "name": "credential_version", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "revision": { + "name": "revision", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "last_outcome": { + "name": "last_outcome", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "last_event_at": { + "name": "last_event_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "slack_search_installation_organization_idx": { + "name": "slack_search_installation_organization_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "slack_search_installation_credential_unique": { + "name": "slack_search_installation_credential_unique", + "columns": [ + { + "expression": "credential_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "slack_search_installation_app_team_unique": { + "name": "slack_search_installation_app_team_unique", + "columns": [ + { + "expression": "app_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "team_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "slack_search_installation_active_team_unique": { + "name": "slack_search_installation_active_team_unique", + "columns": [ + { + "expression": "team_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"slack_search_installation\".\"enabled\" = true", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "slack_search_installation_organization_id_organization_id_fk": { + "name": "slack_search_installation_organization_id_organization_id_fk", + "tableFrom": "slack_search_installation", + "tableTo": "organization", + "columnsFrom": ["organization_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "slack_search_installation_credential_id_credential_id_fk": { + "name": "slack_search_installation_credential_id_credential_id_fk", + "tableFrom": "slack_search_installation", + "tableTo": "credential", + "columnsFrom": ["credential_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "slack_search_installation_slack_app_id_slack_app_id_fk": { + "name": "slack_search_installation_slack_app_id_slack_app_id_fk", + "tableFrom": "slack_search_installation", + "tableTo": "slack_app", + "columnsFrom": ["slack_app_id"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.slack_search_turn": { + "name": "slack_search_turn", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "ordinal": { + "name": "ordinal", + "type": "integer", + "primaryKey": false, + "notNull": true, + "identity": { + "type": "always", + "name": "slack_search_turn_ordinal_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "installation_id": { + "name": "installation_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "conversation_key": { + "name": "conversation_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "event_id": { + "name": "event_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "lease_id": { + "name": "lease_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "lease_expires_at": { + "name": "lease_expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "outcome": { + "name": "outcome", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "slack_search_turn_event_unique": { + "name": "slack_search_turn_event_unique", + "columns": [ + { + "expression": "installation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "event_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "slack_search_turn_pending_idx": { + "name": "slack_search_turn_pending_idx", + "columns": [ + { + "expression": "installation_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "slack_search_turn_thread_idx": { + "name": "slack_search_turn_thread_idx", + "columns": [ + { + "expression": "conversation_key", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "slack_search_turn_active_thread_unique": { + "name": "slack_search_turn_active_thread_unique", + "columns": [ + { + "expression": "conversation_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"slack_search_turn\".\"status\" = 'running'", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "slack_search_turn_installation_id_slack_search_installation_id_fk": { + "name": "slack_search_turn_installation_id_slack_search_installation_id_fk", + "tableFrom": "slack_search_turn", + "tableTo": "slack_search_installation", + "columnsFrom": ["installation_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.sso_domain": { + "name": "sso_domain", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "domain": { + "name": "domain", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "verification_token": { + "name": "verification_token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "verified_at": { + "name": "verified_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "sso_domain_organization_id_idx": { + "name": "sso_domain_organization_id_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "sso_domain_domain_idx": { + "name": "sso_domain_domain_idx", + "columns": [ + { + "expression": "domain", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "sso_domain_org_domain_unique": { + "name": "sso_domain_org_domain_unique", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "domain", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "sso_domain_verified_unique": { + "name": "sso_domain_verified_unique", + "columns": [ + { + "expression": "domain", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "status = 'verified'", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sso_domain_organization_id_organization_id_fk": { + "name": "sso_domain_organization_id_organization_id_fk", + "tableFrom": "sso_domain", + "tableTo": "organization", + "columnsFrom": ["organization_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "sso_domain_created_by_user_id_fk": { + "name": "sso_domain_created_by_user_id_fk", + "tableFrom": "sso_domain", + "tableTo": "user", + "columnsFrom": ["created_by"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.sso_provider": { + "name": "sso_provider", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "issuer": { + "name": "issuer", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "domain": { + "name": "domain", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "oidc_config": { + "name": "oidc_config", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "saml_config": { + "name": "saml_config", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "domain_verified": { + "name": "domain_verified", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "jit_provisioning_enabled": { + "name": "jit_provisioning_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + } + }, + "indexes": { + "sso_provider_provider_id_unique": { + "name": "sso_provider_provider_id_unique", + "columns": [ + { + "expression": "provider_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "sso_provider_org_domain_unique": { + "name": "sso_provider_org_domain_unique", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "lower(regexp_replace(btrim(\"domain\"), '^\\*\\.', ''))", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"sso_provider\".\"organization_id\" is not null", + "concurrently": false, + "method": "btree", + "with": {} + }, + "sso_provider_domain_idx": { + "name": "sso_provider_domain_idx", + "columns": [ + { + "expression": "domain", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "sso_provider_user_id_idx": { + "name": "sso_provider_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "sso_provider_organization_id_idx": { + "name": "sso_provider_organization_id_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sso_provider_user_id_user_id_fk": { + "name": "sso_provider_user_id_user_id_fk", + "tableFrom": "sso_provider", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "sso_provider_organization_id_organization_id_fk": { + "name": "sso_provider_organization_id_organization_id_fk", + "tableFrom": "sso_provider", + "tableTo": "organization", + "columnsFrom": ["organization_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.subscription": { + "name": "subscription", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "plan": { + "name": "plan", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "reference_id": { + "name": "reference_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "stripe_customer_id": { + "name": "stripe_customer_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "stripe_subscription_id": { + "name": "stripe_subscription_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "period_start": { + "name": "period_start", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "period_end": { + "name": "period_end", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "cancel_at_period_end": { + "name": "cancel_at_period_end", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "cancel_at": { + "name": "cancel_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "canceled_at": { + "name": "canceled_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "ended_at": { + "name": "ended_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "seats": { + "name": "seats", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "trial_start": { + "name": "trial_start", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "trial_end": { + "name": "trial_end", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "billing_interval": { + "name": "billing_interval", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "stripe_schedule_id": { + "name": "stripe_schedule_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "json", + "primaryKey": false, + "notNull": false + }, + "last_closed_period_start": { + "name": "last_closed_period_start", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "subscription_reference_status_idx": { + "name": "subscription_reference_status_idx", + "columns": [ + { + "expression": "reference_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "subscription_cycle_close_lagging_idx": { + "name": "subscription_cycle_close_lagging_idx", + "columns": [ + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"subscription\".\"status\" in ('active', 'past_due') and \"subscription\".\"period_start\" is not null and (\"subscription\".\"last_closed_period_start\" is null or \"subscription\".\"last_closed_period_start\" < \"subscription\".\"period_start\")", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "check_enterprise_metadata": { + "name": "check_enterprise_metadata", + "value": "plan != 'enterprise' OR metadata IS NOT NULL" + } + }, + "isRLSEnabled": false + }, + "public.table_jobs": { + "name": "table_jobs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "table_id": { + "name": "table_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'running'" + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "rows_processed": { + "name": "rows_processed", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "started_at": { + "name": "started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "table_jobs_one_active_per_table": { + "name": "table_jobs_one_active_per_table", + "columns": [ + { + "expression": "table_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"table_jobs\".\"status\" = 'running' AND \"table_jobs\".\"type\" <> 'export'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "table_jobs_watchdog_idx": { + "name": "table_jobs_watchdog_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "table_jobs_table_started_idx": { + "name": "table_jobs_table_started_idx", + "columns": [ + { + "expression": "table_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "started_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "table_jobs_table_id_user_table_definitions_id_fk": { + "name": "table_jobs_table_id_user_table_definitions_id_fk", + "tableFrom": "table_jobs", + "tableTo": "user_table_definitions", + "columnsFrom": ["table_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "table_jobs_workspace_id_workspace_id_fk": { + "name": "table_jobs_workspace_id_workspace_id_fk", + "tableFrom": "table_jobs", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.table_row_executions": { + "name": "table_row_executions", + "schema": "", + "columns": { + "table_id": { + "name": "table_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "row_id": { + "name": "row_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "group_id": { + "name": "group_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "execution_id": { + "name": "execution_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "job_id": { + "name": "job_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "running_block_ids": { + "name": "running_block_ids", + "type": "text[]", + "primaryKey": false, + "notNull": true, + "default": "'{}'::text[]" + }, + "block_errors": { + "name": "block_errors", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "cancelled_at": { + "name": "cancelled_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "capability_governed_user_id": { + "name": "capability_governed_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "enrichment_details": { + "name": "enrichment_details", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "table_row_executions_table_status_idx": { + "name": "table_row_executions_table_status_idx", + "columns": [ + { + "expression": "table_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"table_row_executions\".\"status\" IN ('queued', 'running', 'pending')", + "concurrently": false, + "method": "btree", + "with": {} + }, + "table_row_executions_execution_id_idx": { + "name": "table_row_executions_execution_id_idx", + "columns": [ + { + "expression": "execution_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"table_row_executions\".\"execution_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "table_row_executions_table_group_idx": { + "name": "table_row_executions_table_group_idx", + "columns": [ + { + "expression": "table_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "group_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "table_row_executions_table_id_user_table_definitions_id_fk": { + "name": "table_row_executions_table_id_user_table_definitions_id_fk", + "tableFrom": "table_row_executions", + "tableTo": "user_table_definitions", + "columnsFrom": ["table_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "table_row_executions_row_id_user_table_rows_id_fk": { + "name": "table_row_executions_row_id_user_table_rows_id_fk", + "tableFrom": "table_row_executions", + "tableTo": "user_table_rows", + "columnsFrom": ["row_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "table_row_executions_capability_governed_user_id_user_id_fk": { + "name": "table_row_executions_capability_governed_user_id_user_id_fk", + "tableFrom": "table_row_executions", + "tableTo": "user", + "columnsFrom": ["capability_governed_user_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "table_row_executions_row_id_group_id_pk": { + "name": "table_row_executions_row_id_group_id_pk", + "columns": ["row_id", "group_id"] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.table_run_dispatches": { + "name": "table_run_dispatches", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "table_id": { + "name": "table_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "request_id": { + "name": "request_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "mode": { + "name": "mode", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "scope": { + "name": "scope", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "cursor": { + "name": "cursor", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "limit": { + "name": "limit", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "processed_count": { + "name": "processed_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "is_manual_run": { + "name": "is_manual_run", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "triggered_by_user_id": { + "name": "triggered_by_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "capability_governed_user_id": { + "name": "capability_governed_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "requested_at": { + "name": "requested_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "heartbeat_at": { + "name": "heartbeat_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "cancelled_at": { + "name": "cancelled_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "table_run_dispatches_active_idx": { + "name": "table_run_dispatches_active_idx", + "columns": [ + { + "expression": "table_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "table_run_dispatches_watchdog_idx": { + "name": "table_run_dispatches_watchdog_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "requested_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "table_run_dispatches_governed_active_idx": { + "name": "table_run_dispatches_governed_active_idx", + "columns": [ + { + "expression": "capability_governed_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"table_run_dispatches\".\"status\" IN ('pending', 'dispatching')", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "table_run_dispatches_table_id_user_table_definitions_id_fk": { + "name": "table_run_dispatches_table_id_user_table_definitions_id_fk", + "tableFrom": "table_run_dispatches", + "tableTo": "user_table_definitions", + "columnsFrom": ["table_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "table_run_dispatches_workspace_id_workspace_id_fk": { + "name": "table_run_dispatches_workspace_id_workspace_id_fk", + "tableFrom": "table_run_dispatches", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "table_run_dispatches_triggered_by_user_id_user_id_fk": { + "name": "table_run_dispatches_triggered_by_user_id_user_id_fk", + "tableFrom": "table_run_dispatches", + "tableTo": "user", + "columnsFrom": ["triggered_by_user_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "table_run_dispatches_capability_governed_user_id_user_id_fk": { + "name": "table_run_dispatches_capability_governed_user_id_user_id_fk", + "tableFrom": "table_run_dispatches", + "tableTo": "user", + "columnsFrom": ["capability_governed_user_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.table_views": { + "name": "table_views", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "table_id": { + "name": "table_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "config": { + "name": "config", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'" + }, + "is_default": { + "name": "is_default", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "table_views_table_created_idx": { + "name": "table_views_table_created_idx", + "columns": [ + { + "expression": "table_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "table_views_workspace_created_idx": { + "name": "table_views_workspace_created_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "table_views_table_default_unique": { + "name": "table_views_table_default_unique", + "columns": [ + { + "expression": "table_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "is_default = true", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "table_views_table_id_user_table_definitions_id_fk": { + "name": "table_views_table_id_user_table_definitions_id_fk", + "tableFrom": "table_views", + "tableTo": "user_table_definitions", + "columnsFrom": ["table_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "table_views_workspace_id_workspace_id_fk": { + "name": "table_views_workspace_id_workspace_id_fk", + "tableFrom": "table_views", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "table_views_created_by_user_id_fk": { + "name": "table_views_created_by_user_id_fk", + "tableFrom": "table_views", + "tableTo": "user", + "columnsFrom": ["created_by"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.upload_session": { + "name": "upload_session", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "token_hash": { + "name": "token_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "knowledge_base_id": { + "name": "knowledge_base_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "execution_id": { + "name": "execution_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "purpose": { + "name": "purpose", + "type": "upload_session_purpose", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "method": { + "name": "method", + "type": "upload_session_method", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "storage_context": { + "name": "storage_context", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "final_key": { + "name": "final_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "storage_provider": { + "name": "storage_provider", + "type": "upload_session_provider", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "provider_upload_id": { + "name": "provider_upload_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "provider_object_version": { + "name": "provider_object_version", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "file_name": { + "name": "file_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "content_type": { + "name": "content_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "file_size": { + "name": "file_size", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "part_size": { + "name": "part_size", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "part_count": { + "name": "part_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "upload_session_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'uploading'" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "processing_lease_id": { + "name": "processing_lease_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "processing_lease_expires_at": { + "name": "processing_lease_expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "completed_file_id": { + "name": "completed_file_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "upload_session_token_hash_unique": { + "name": "upload_session_token_hash_unique", + "columns": [ + { + "expression": "token_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "upload_session_final_key_unique": { + "name": "upload_session_final_key_unique", + "columns": [ + { + "expression": "final_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "upload_session_status_expires_at_idx": { + "name": "upload_session_status_expires_at_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "expires_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.usage_log": { + "name": "usage_log", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "category": { + "name": "category", + "type": "usage_log_category", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "usage_log_source", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "cost": { + "name": "cost", + "type": "numeric", + "primaryKey": false, + "notNull": true + }, + "event_key": { + "name": "event_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "billing_entity_type": { + "name": "billing_entity_type", + "type": "billing_entity_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "billing_entity_id": { + "name": "billing_entity_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "billing_period_start": { + "name": "billing_period_start", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "billing_period_end": { + "name": "billing_period_end", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "execution_id": { + "name": "execution_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "usage_log_user_created_at_idx": { + "name": "usage_log_user_created_at_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "usage_log_source_idx": { + "name": "usage_log_source_idx", + "columns": [ + { + "expression": "source", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "usage_log_workspace_id_idx": { + "name": "usage_log_workspace_id_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "usage_log_workflow_id_idx": { + "name": "usage_log_workflow_id_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "usage_log_event_key_unique": { + "name": "usage_log_event_key_unique", + "columns": [ + { + "expression": "event_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"usage_log\".\"event_key\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "usage_log_billing_entity_period_idx": { + "name": "usage_log_billing_entity_period_idx", + "columns": [ + { + "expression": "billing_entity_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "billing_entity_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "billing_period_start", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "billing_period_end", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"usage_log\".\"billing_entity_type\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "usage_log_billing_period_cost_idx": { + "name": "usage_log_billing_period_cost_idx", + "columns": [ + { + "expression": "billing_entity_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "billing_entity_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "billing_period_start", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "billing_period_end", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "source", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "cost", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"usage_log\".\"billing_entity_type\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "usage_log_billing_entity_created_at_cost_idx": { + "name": "usage_log_billing_entity_created_at_cost_idx", + "columns": [ + { + "expression": "billing_entity_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "billing_entity_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "source", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "cost", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"usage_log\".\"billing_entity_type\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "usage_log_workspace_created_at_idx": { + "name": "usage_log_workspace_created_at_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "usage_log_execution_id_idx": { + "name": "usage_log_execution_id_idx", + "columns": [ + { + "expression": "execution_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "usage_log_user_id_user_id_fk": { + "name": "usage_log_user_id_user_id_fk", + "tableFrom": "usage_log", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "usage_log_workspace_id_workspace_id_fk": { + "name": "usage_log_workspace_id_workspace_id_fk", + "tableFrom": "usage_log", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "usage_log_workflow_id_workflow_id_fk": { + "name": "usage_log_workflow_id_workflow_id_fk", + "tableFrom": "usage_log", + "tableTo": "workflow", + "columnsFrom": ["workflow_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "usage_log_billing_scope_all_or_none": { + "name": "usage_log_billing_scope_all_or_none", + "value": "(\n (\"usage_log\".\"billing_entity_type\" IS NULL AND \"usage_log\".\"billing_entity_id\" IS NULL AND \"usage_log\".\"billing_period_start\" IS NULL AND \"usage_log\".\"billing_period_end\" IS NULL)\n OR\n (\"usage_log\".\"billing_entity_type\" IS NOT NULL AND \"usage_log\".\"billing_entity_id\" IS NOT NULL AND \"usage_log\".\"billing_period_start\" IS NOT NULL AND \"usage_log\".\"billing_period_end\" IS NOT NULL AND \"usage_log\".\"billing_period_start\" < \"usage_log\".\"billing_period_end\")\n )" + } + }, + "isRLSEnabled": false + }, + "public.user": { + "name": "user", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "normalized_email": { + "name": "normalized_email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "email_verified": { + "name": "email_verified", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "stripe_customer_id": { + "name": "stripe_customer_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'user'" + }, + "banned": { + "name": "banned", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "ban_reason": { + "name": "ban_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "ban_expires": { + "name": "ban_expires", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "suspended_at": { + "name": "suspended_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "suspension_source": { + "name": "suspension_source", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "user_email_lower_idx": { + "name": "user_email_lower_idx", + "columns": [ + { + "expression": "lower(btrim(\"email\"))", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "user_email_unique": { + "name": "user_email_unique", + "nullsNotDistinct": false, + "columns": ["email"] + }, + "user_normalized_email_unique": { + "name": "user_normalized_email_unique", + "nullsNotDistinct": false, + "columns": ["normalized_email"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user_stats": { + "name": "user_stats", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "total_manual_executions": { + "name": "total_manual_executions", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "total_api_calls": { + "name": "total_api_calls", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "total_webhook_triggers": { + "name": "total_webhook_triggers", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "total_scheduled_executions": { + "name": "total_scheduled_executions", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "total_chat_executions": { + "name": "total_chat_executions", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "total_mcp_executions": { + "name": "total_mcp_executions", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "total_tokens_used": { + "name": "total_tokens_used", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "total_cost": { + "name": "total_cost", + "type": "numeric", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "current_usage_limit": { + "name": "current_usage_limit", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": "'5'" + }, + "usage_limit_updated_at": { + "name": "usage_limit_updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "current_period_cost": { + "name": "current_period_cost", + "type": "numeric", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "last_period_cost": { + "name": "last_period_cost", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": "'0'" + }, + "billed_overage_this_period": { + "name": "billed_overage_this_period", + "type": "numeric", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "pro_period_cost_snapshot": { + "name": "pro_period_cost_snapshot", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": "'0'" + }, + "pro_period_cost_snapshot_at": { + "name": "pro_period_cost_snapshot_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "credit_balance": { + "name": "credit_balance", + "type": "numeric", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "total_copilot_cost": { + "name": "total_copilot_cost", + "type": "numeric", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "current_period_copilot_cost": { + "name": "current_period_copilot_cost", + "type": "numeric", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "last_period_copilot_cost": { + "name": "last_period_copilot_cost", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": "'0'" + }, + "total_copilot_tokens": { + "name": "total_copilot_tokens", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "total_copilot_calls": { + "name": "total_copilot_calls", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "total_mcp_copilot_calls": { + "name": "total_mcp_copilot_calls", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "total_mcp_copilot_cost": { + "name": "total_mcp_copilot_cost", + "type": "numeric", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "current_period_mcp_copilot_cost": { + "name": "current_period_mcp_copilot_cost", + "type": "numeric", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "storage_used_bytes": { + "name": "storage_used_bytes", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "last_active": { + "name": "last_active", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "billing_blocked": { + "name": "billing_blocked", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "billing_blocked_reason": { + "name": "billing_blocked_reason", + "type": "billing_blocked_reason", + "typeSchema": "public", + "primaryKey": false, + "notNull": false + }, + "limit_notifications": { + "name": "limit_notifications", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + } + }, + "indexes": {}, + "foreignKeys": { + "user_stats_user_id_user_id_fk": { + "name": "user_stats_user_id_user_id_fk", + "tableFrom": "user_stats", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "user_stats_user_id_unique": { + "name": "user_stats_user_id_unique", + "nullsNotDistinct": false, + "columns": ["user_id"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user_table_definitions": { + "name": "user_table_definitions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "folder_id": { + "name": "folder_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "schema": { + "name": "schema", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "max_rows": { + "name": "max_rows", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 10000 + }, + "row_count": { + "name": "row_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "rows_version": { + "name": "rows_version", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "schema_locked": { + "name": "schema_locked", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "insert_locked": { + "name": "insert_locked", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "update_locked": { + "name": "update_locked", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "delete_locked": { + "name": "delete_locked", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "user_table_def_workspace_id_idx": { + "name": "user_table_def_workspace_id_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "user_table_def_folder_id_idx": { + "name": "user_table_def_folder_id_idx", + "columns": [ + { + "expression": "folder_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "user_table_def_workspace_name_unique": { + "name": "user_table_def_workspace_name_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"user_table_definitions\".\"archived_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "user_table_def_archived_at_idx": { + "name": "user_table_def_archived_at_idx", + "columns": [ + { + "expression": "archived_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "user_table_def_workspace_archived_partial_idx": { + "name": "user_table_def_workspace_archived_partial_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "archived_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"user_table_definitions\".\"archived_at\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "user_table_definitions_workspace_id_workspace_id_fk": { + "name": "user_table_definitions_workspace_id_workspace_id_fk", + "tableFrom": "user_table_definitions", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "user_table_definitions_folder_id_folder_id_fk": { + "name": "user_table_definitions_folder_id_folder_id_fk", + "tableFrom": "user_table_definitions", + "tableTo": "folder", + "columnsFrom": ["folder_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "user_table_definitions_created_by_user_id_fk": { + "name": "user_table_definitions_created_by_user_id_fk", + "tableFrom": "user_table_definitions", + "tableTo": "user", + "columnsFrom": ["created_by"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user_table_row_secret_provenance": { + "name": "user_table_row_secret_provenance", + "schema": "", + "columns": { + "row_id": { + "name": "row_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "content_updated_at": { + "name": "content_updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "entries": { + "name": "entries", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "user_table_row_secret_provenance_row_id_user_table_rows_id_fk": { + "name": "user_table_row_secret_provenance_row_id_user_table_rows_id_fk", + "tableFrom": "user_table_row_secret_provenance", + "tableTo": "user_table_rows", + "columnsFrom": ["row_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "user_table_row_secret_provenance_status_check": { + "name": "user_table_row_secret_provenance_status_check", + "value": "\"user_table_row_secret_provenance\".\"status\" IN ('exact', 'unknown')" + } + }, + "isRLSEnabled": false + }, + "public.user_table_rows": { + "name": "user_table_rows", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "table_id": { + "name": "table_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "order_key": { + "name": "order_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "secret_provenance_version": { + "name": "secret_provenance_version", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "user_table_rows_tenant_data_gin_idx": { + "name": "user_table_rows_tenant_data_gin_idx", + "columns": [ + { + "expression": "table_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "\"data\" jsonb_path_ops", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "gin", + "with": {} + }, + "user_table_rows_workspace_table_idx": { + "name": "user_table_rows_workspace_table_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "table_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "user_table_rows_table_position_idx": { + "name": "user_table_rows_table_position_idx", + "columns": [ + { + "expression": "table_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "position", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "user_table_rows_table_order_key_idx": { + "name": "user_table_rows_table_order_key_idx", + "columns": [ + { + "expression": "table_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "order_key", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "user_table_rows_table_created_id_idx": { + "name": "user_table_rows_table_created_id_idx", + "columns": [ + { + "expression": "table_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "user_table_rows_table_id_id_idx": { + "name": "user_table_rows_table_id_id_idx", + "columns": [ + { + "expression": "table_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "user_table_rows_table_id_user_table_definitions_id_fk": { + "name": "user_table_rows_table_id_user_table_definitions_id_fk", + "tableFrom": "user_table_rows", + "tableTo": "user_table_definitions", + "columnsFrom": ["table_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "user_table_rows_workspace_id_workspace_id_fk": { + "name": "user_table_rows_workspace_id_workspace_id_fk", + "tableFrom": "user_table_rows", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "user_table_rows_created_by_user_id_fk": { + "name": "user_table_rows_created_by_user_id_fk", + "tableFrom": "user_table_rows", + "tableTo": "user", + "columnsFrom": ["created_by"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.verification": { + "name": "verification", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "identifier": { + "name": "identifier", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "verification_identifier_idx": { + "name": "verification_identifier_idx", + "columns": [ + { + "expression": "identifier", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "verification_expires_at_idx": { + "name": "verification_expires_at_idx", + "columns": [ + { + "expression": "expires_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.waitlist": { + "name": "waitlist", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "waitlist_email_unique": { + "name": "waitlist_email_unique", + "nullsNotDistinct": false, + "columns": ["email"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.webhook": { + "name": "webhook", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "deployment_version_id": { + "name": "deployment_version_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "registration_status": { + "name": "registration_status", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "registration_generation": { + "name": "registration_generation", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "config_fingerprint": { + "name": "config_fingerprint", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "prepared_at": { + "name": "prepared_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "block_id": { + "name": "block_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "path": { + "name": "path", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "routing_key": { + "name": "routing_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "provider_config": { + "name": "provider_config", + "type": "json", + "primaryKey": false, + "notNull": false + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "failed_count": { + "name": "failed_count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "last_failed_at": { + "name": "last_failed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "path_deployment_unique": { + "name": "path_deployment_unique", + "columns": [ + { + "expression": "path", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "deployment_version_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"webhook\".\"archived_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "webhook_workflow_deployment_idx": { + "name": "webhook_workflow_deployment_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "deployment_version_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "webhook_routing_key_active_idx": { + "name": "webhook_routing_key_active_idx", + "columns": [ + { + "expression": "routing_key", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"webhook\".\"archived_at\" IS NULL AND \"webhook\".\"routing_key\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "webhook_archived_at_partial_idx": { + "name": "webhook_archived_at_partial_idx", + "columns": [ + { + "expression": "archived_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"webhook\".\"archived_at\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_webhook_on_provider_is_active_workflow_id_deploym_bdeed5468": { + "name": "idx_webhook_on_provider_is_active_workflow_id_deploym_bdeed5468", + "columns": [ + { + "expression": "provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "is_active", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "deployment_version_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_webhook_on_workflow_id_block_id_updated_at_desc": { + "name": "idx_webhook_on_workflow_id_block_id_updated_at_desc", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "block_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "updated_at", + "isExpression": false, + "asc": false, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "webhook_active_registration_unique": { + "name": "webhook_active_registration_unique", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "block_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"webhook\".\"registration_status\" = 'active' AND \"webhook\".\"block_id\" IS NOT NULL AND \"webhook\".\"archived_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "webhook_candidate_registration_unique": { + "name": "webhook_candidate_registration_unique", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "block_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"webhook\".\"registration_status\" = 'candidate' AND \"webhook\".\"block_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "webhook_registration_status_generation_idx": { + "name": "webhook_registration_status_generation_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "registration_status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "registration_generation", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "webhook_workflow_id_workflow_id_fk": { + "name": "webhook_workflow_id_workflow_id_fk", + "tableFrom": "webhook", + "tableTo": "workflow", + "columnsFrom": ["workflow_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "webhook_deployment_version_id_workflow_deployment_version_id_fk": { + "name": "webhook_deployment_version_id_workflow_deployment_version_id_fk", + "tableFrom": "webhook", + "tableTo": "workflow_deployment_version", + "columnsFrom": ["deployment_version_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "webhook_registration_status_check": { + "name": "webhook_registration_status_check", + "value": "\"webhook\".\"registration_status\" IS NULL OR \"webhook\".\"registration_status\" IN ('active', 'candidate', 'retired', 'orphaned')" + }, + "webhook_registration_generation_check": { + "name": "webhook_registration_generation_check", + "value": "\"webhook\".\"registration_generation\" IS NULL OR \"webhook\".\"registration_generation\" >= 0" + } + }, + "isRLSEnabled": false + }, + "public.webhook_path_claim": { + "name": "webhook_path_claim", + "schema": "", + "columns": { + "path": { + "name": "path", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "generation": { + "name": "generation", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "webhook_path_claim_workflow_idx": { + "name": "webhook_path_claim_workflow_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "webhook_path_claim_workflow_id_workflow_id_fk": { + "name": "webhook_path_claim_workflow_id_workflow_id_fk", + "tableFrom": "webhook_path_claim", + "tableTo": "workflow", + "columnsFrom": ["workflow_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "webhook_path_claim_generation_check": { + "name": "webhook_path_claim_generation_check", + "value": "\"webhook_path_claim\".\"generation\" >= 0" + } + }, + "isRLSEnabled": false + }, + "public.workflow": { + "name": "workflow", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "folder_id": { + "name": "folder_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "last_synced": { + "name": "last_synced", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "is_deployed": { + "name": "is_deployed", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "deployed_at": { + "name": "deployed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "is_public_api": { + "name": "is_public_api", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "locked": { + "name": "locked", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "fork_sync_excluded": { + "name": "fork_sync_excluded", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "run_count": { + "name": "run_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "last_run_at": { + "name": "last_run_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "variables": { + "name": "variables", + "type": "json", + "primaryKey": false, + "notNull": false, + "default": "'{}'" + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "workflow_user_id_idx": { + "name": "workflow_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_workspace_id_idx": { + "name": "workflow_workspace_id_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_user_workspace_idx": { + "name": "workflow_user_workspace_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_workspace_folder_name_active_unique": { + "name": "workflow_workspace_folder_name_active_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "coalesce(\"folder_id\", '')", + "asc": true, + "isExpression": true, + "nulls": "last" + }, + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"workflow\".\"archived_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_folder_sort_idx": { + "name": "workflow_folder_sort_idx", + "columns": [ + { + "expression": "folder_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sort_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_active_workspace_sort_idx": { + "name": "workflow_active_workspace_sort_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sort_order", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"workflow\".\"archived_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_archived_at_idx": { + "name": "workflow_archived_at_idx", + "columns": [ + { + "expression": "archived_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_workspace_archived_partial_idx": { + "name": "workflow_workspace_archived_partial_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "archived_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"workflow\".\"archived_at\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "workflow_user_id_user_id_fk": { + "name": "workflow_user_id_user_id_fk", + "tableFrom": "workflow", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workflow_workspace_id_workspace_id_fk": { + "name": "workflow_workspace_id_workspace_id_fk", + "tableFrom": "workflow", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workflow_folder_id_folder_id_fk": { + "name": "workflow_folder_id_folder_id_fk", + "tableFrom": "workflow", + "tableTo": "folder", + "columnsFrom": ["folder_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workflow_blocks": { + "name": "workflow_blocks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "position_x": { + "name": "position_x", + "type": "numeric", + "primaryKey": false, + "notNull": true + }, + "position_y": { + "name": "position_y", + "type": "numeric", + "primaryKey": false, + "notNull": true + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "horizontal_handles": { + "name": "horizontal_handles", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "is_wide": { + "name": "is_wide", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "advanced_mode": { + "name": "advanced_mode", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "trigger_mode": { + "name": "trigger_mode", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "error_enabled": { + "name": "error_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "retry": { + "name": "retry", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "locked": { + "name": "locked", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "height": { + "name": "height", + "type": "numeric", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "sub_blocks": { + "name": "sub_blocks", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'" + }, + "outputs": { + "name": "outputs", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'" + }, + "data": { + "name": "data", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "workflow_blocks_workflow_id_idx": { + "name": "workflow_blocks_workflow_id_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_blocks_type_idx": { + "name": "workflow_blocks_type_idx", + "columns": [ + { + "expression": "type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "workflow_blocks_workflow_id_workflow_id_fk": { + "name": "workflow_blocks_workflow_id_workflow_id_fk", + "tableFrom": "workflow_blocks", + "tableTo": "workflow", + "columnsFrom": ["workflow_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workflow_checkpoints": { + "name": "workflow_checkpoints", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "chat_id": { + "name": "chat_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "message_id": { + "name": "message_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "workflow_state": { + "name": "workflow_state", + "type": "json", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "workflow_checkpoints_user_id_idx": { + "name": "workflow_checkpoints_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_checkpoints_workflow_id_idx": { + "name": "workflow_checkpoints_workflow_id_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_checkpoints_chat_id_idx": { + "name": "workflow_checkpoints_chat_id_idx", + "columns": [ + { + "expression": "chat_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_checkpoints_message_id_idx": { + "name": "workflow_checkpoints_message_id_idx", + "columns": [ + { + "expression": "message_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_checkpoints_user_workflow_idx": { + "name": "workflow_checkpoints_user_workflow_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_checkpoints_workflow_chat_idx": { + "name": "workflow_checkpoints_workflow_chat_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "chat_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_checkpoints_created_at_idx": { + "name": "workflow_checkpoints_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_checkpoints_chat_created_at_idx": { + "name": "workflow_checkpoints_chat_created_at_idx", + "columns": [ + { + "expression": "chat_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "workflow_checkpoints_user_id_user_id_fk": { + "name": "workflow_checkpoints_user_id_user_id_fk", + "tableFrom": "workflow_checkpoints", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workflow_checkpoints_workflow_id_workflow_id_fk": { + "name": "workflow_checkpoints_workflow_id_workflow_id_fk", + "tableFrom": "workflow_checkpoints", + "tableTo": "workflow", + "columnsFrom": ["workflow_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workflow_checkpoints_chat_id_copilot_chats_id_fk": { + "name": "workflow_checkpoints_chat_id_copilot_chats_id_fk", + "tableFrom": "workflow_checkpoints", + "tableTo": "copilot_chats", + "columnsFrom": ["chat_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workflow_deployment_operation": { + "name": "workflow_deployment_operation", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "deployment_version_id": { + "name": "deployment_version_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "previous_active_version_id": { + "name": "previous_active_version_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "protocol_version": { + "name": "protocol_version", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "generation": { + "name": "generation", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'preparing'" + }, + "component_readiness": { + "name": "component_readiness", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "error_code": { + "name": "error_code", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "idempotency_key": { + "name": "idempotency_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "request_hash": { + "name": "request_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "actor_id": { + "name": "actor_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "workflow_deployment_operation_workflow_generation_unique": { + "name": "workflow_deployment_operation_workflow_generation_unique", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "generation", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_deployment_operation_workflow_idempotency_unique": { + "name": "workflow_deployment_operation_workflow_idempotency_unique", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "idempotency_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"workflow_deployment_operation\".\"idempotency_key\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_deployment_operation_workflow_in_flight_unique": { + "name": "workflow_deployment_operation_workflow_in_flight_unique", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"workflow_deployment_operation\".\"status\" IN ('preparing', 'activating')", + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_deployment_operation_workflow_status_idx": { + "name": "workflow_deployment_operation_workflow_status_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_deployment_operation_deployment_version_idx": { + "name": "workflow_deployment_operation_deployment_version_idx", + "columns": [ + { + "expression": "deployment_version_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_deployment_operation_workflow_version_generation_idx": { + "name": "workflow_deployment_operation_workflow_version_generation_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "deployment_version_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "generation", + "isExpression": false, + "asc": false, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "workflow_deployment_operation_workflow_id_workflow_id_fk": { + "name": "workflow_deployment_operation_workflow_id_workflow_id_fk", + "tableFrom": "workflow_deployment_operation", + "tableTo": "workflow", + "columnsFrom": ["workflow_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workflow_deployment_operation_deployment_version_id_workflow_deployment_version_id_fk": { + "name": "workflow_deployment_operation_deployment_version_id_workflow_deployment_version_id_fk", + "tableFrom": "workflow_deployment_operation", + "tableTo": "workflow_deployment_version", + "columnsFrom": ["deployment_version_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workflow_deployment_operation_previous_active_version_id_workflow_deployment_version_id_fk": { + "name": "workflow_deployment_operation_previous_active_version_id_workflow_deployment_version_id_fk", + "tableFrom": "workflow_deployment_operation", + "tableTo": "workflow_deployment_version", + "columnsFrom": ["previous_active_version_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "workflow_deployment_operation_action_check": { + "name": "workflow_deployment_operation_action_check", + "value": "\"workflow_deployment_operation\".\"action\" IN ('deploy', 'activate')" + }, + "workflow_deployment_operation_status_check": { + "name": "workflow_deployment_operation_status_check", + "value": "\"workflow_deployment_operation\".\"status\" IN ('preparing', 'activating', 'active', 'failed', 'superseded')" + }, + "workflow_deployment_operation_generation_check": { + "name": "workflow_deployment_operation_generation_check", + "value": "\"workflow_deployment_operation\".\"generation\" > 0" + }, + "workflow_deployment_operation_protocol_version_check": { + "name": "workflow_deployment_operation_protocol_version_check", + "value": "\"workflow_deployment_operation\".\"protocol_version\" > 0" + } + }, + "isRLSEnabled": false + }, + "public.workflow_deployment_version": { + "name": "workflow_deployment_version", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "state": { + "name": "state", + "type": "json", + "primaryKey": false, + "notNull": true + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "workflow_deployment_version_workflow_version_unique": { + "name": "workflow_deployment_version_workflow_version_unique", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "version", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_deployment_version_workflow_active_idx": { + "name": "workflow_deployment_version_workflow_active_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "is_active", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_deployment_version_created_at_idx": { + "name": "workflow_deployment_version_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "workflow_deployment_version_workflow_id_workflow_id_fk": { + "name": "workflow_deployment_version_workflow_id_workflow_id_fk", + "tableFrom": "workflow_deployment_version", + "tableTo": "workflow", + "columnsFrom": ["workflow_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workflow_edges": { + "name": "workflow_edges", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_block_id": { + "name": "source_block_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "target_block_id": { + "name": "target_block_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_handle": { + "name": "source_handle", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "target_handle": { + "name": "target_handle", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "workflow_edges_workflow_id_idx": { + "name": "workflow_edges_workflow_id_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_edges_workflow_source_idx": { + "name": "workflow_edges_workflow_source_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "source_block_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_edges_workflow_target_idx": { + "name": "workflow_edges_workflow_target_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "target_block_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "workflow_edges_workflow_id_workflow_id_fk": { + "name": "workflow_edges_workflow_id_workflow_id_fk", + "tableFrom": "workflow_edges", + "tableTo": "workflow", + "columnsFrom": ["workflow_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workflow_edges_source_block_id_workflow_blocks_id_fk": { + "name": "workflow_edges_source_block_id_workflow_blocks_id_fk", + "tableFrom": "workflow_edges", + "tableTo": "workflow_blocks", + "columnsFrom": ["source_block_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workflow_edges_target_block_id_workflow_blocks_id_fk": { + "name": "workflow_edges_target_block_id_workflow_blocks_id_fk", + "tableFrom": "workflow_edges", + "tableTo": "workflow_blocks", + "columnsFrom": ["target_block_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workflow_execution_logs": { + "name": "workflow_execution_logs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "execution_id": { + "name": "execution_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "state_snapshot_id": { + "name": "state_snapshot_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "deployment_version_id": { + "name": "deployment_version_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "level": { + "name": "level", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'running'" + }, + "trigger": { + "name": "trigger", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "started_at": { + "name": "started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "execution_deadline_at": { + "name": "execution_deadline_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "ended_at": { + "name": "ended_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "total_duration_ms": { + "name": "total_duration_ms", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "execution_data": { + "name": "execution_data", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'" + }, + "cost": { + "name": "cost", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "cost_total": { + "name": "cost_total", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "models_used": { + "name": "models_used", + "type": "text[]", + "primaryKey": false, + "notNull": false + }, + "files": { + "name": "files", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "workflow_execution_logs_workflow_id_idx": { + "name": "workflow_execution_logs_workflow_id_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_execution_logs_state_snapshot_id_idx": { + "name": "workflow_execution_logs_state_snapshot_id_idx", + "columns": [ + { + "expression": "state_snapshot_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_execution_logs_deployment_version_id_idx": { + "name": "workflow_execution_logs_deployment_version_id_idx", + "columns": [ + { + "expression": "deployment_version_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_execution_logs_trigger_idx": { + "name": "workflow_execution_logs_trigger_idx", + "columns": [ + { + "expression": "trigger", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_execution_logs_level_idx": { + "name": "workflow_execution_logs_level_idx", + "columns": [ + { + "expression": "level", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_execution_logs_started_at_idx": { + "name": "workflow_execution_logs_started_at_idx", + "columns": [ + { + "expression": "started_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_execution_logs_execution_id_unique": { + "name": "workflow_execution_logs_execution_id_unique", + "columns": [ + { + "expression": "execution_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_execution_logs_workflow_started_at_idx": { + "name": "workflow_execution_logs_workflow_started_at_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "started_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_execution_logs_workspace_started_at_idx": { + "name": "workflow_execution_logs_workspace_started_at_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "started_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_execution_logs_workspace_started_at_id_desc_idx": { + "name": "workflow_execution_logs_workspace_started_at_id_desc_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "\"started_at\" DESC NULLS LAST", + "asc": true, + "isExpression": true, + "nulls": "last" + }, + { + "expression": "\"id\" DESC", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_execution_logs_workspace_cost_total_idx": { + "name": "workflow_execution_logs_workspace_cost_total_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "cost_total", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_execution_logs_models_used_idx": { + "name": "workflow_execution_logs_models_used_idx", + "columns": [ + { + "expression": "models_used", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "gin", + "with": {} + }, + "workflow_execution_logs_workspace_ended_at_id_idx": { + "name": "workflow_execution_logs_workspace_ended_at_id_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "date_trunc('milliseconds', \"ended_at\")", + "asc": true, + "isExpression": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_execution_logs_running_started_at_idx": { + "name": "workflow_execution_logs_running_started_at_idx", + "columns": [ + { + "expression": "started_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "status = 'running'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_execution_logs_running_deadline_idx": { + "name": "workflow_execution_logs_running_deadline_idx", + "columns": [ + { + "expression": "execution_deadline_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"workflow_execution_logs\".\"status\" = 'running' AND \"workflow_execution_logs\".\"execution_deadline_at\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_execution_logs_redacting_started_at_idx": { + "name": "workflow_execution_logs_redacting_started_at_idx", + "columns": [ + { + "expression": "started_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "status = 'redacting'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_execution_logs_redacting_deadline_idx": { + "name": "workflow_execution_logs_redacting_deadline_idx", + "columns": [ + { + "expression": "execution_deadline_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"workflow_execution_logs\".\"status\" = 'redacting' AND \"workflow_execution_logs\".\"execution_deadline_at\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_execution_logs_completed_ended_at_idx": { + "name": "workflow_execution_logs_completed_ended_at_idx", + "columns": [ + { + "expression": "ended_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "execution_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"workflow_execution_logs\".\"status\" = 'completed' AND \"workflow_execution_logs\".\"level\" = 'info' AND \"workflow_execution_logs\".\"ended_at\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "workflow_execution_logs_workflow_id_workflow_id_fk": { + "name": "workflow_execution_logs_workflow_id_workflow_id_fk", + "tableFrom": "workflow_execution_logs", + "tableTo": "workflow", + "columnsFrom": ["workflow_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "workflow_execution_logs_workspace_id_workspace_id_fk": { + "name": "workflow_execution_logs_workspace_id_workspace_id_fk", + "tableFrom": "workflow_execution_logs", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workflow_execution_logs_state_snapshot_id_workflow_execution_snapshots_id_fk": { + "name": "workflow_execution_logs_state_snapshot_id_workflow_execution_snapshots_id_fk", + "tableFrom": "workflow_execution_logs", + "tableTo": "workflow_execution_snapshots", + "columnsFrom": ["state_snapshot_id"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + }, + "workflow_execution_logs_deployment_version_id_workflow_deployment_version_id_fk": { + "name": "workflow_execution_logs_deployment_version_id_workflow_deployment_version_id_fk", + "tableFrom": "workflow_execution_logs", + "tableTo": "workflow_deployment_version", + "columnsFrom": ["deployment_version_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workflow_execution_snapshots": { + "name": "workflow_execution_snapshots", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "state_hash": { + "name": "state_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "state_data": { + "name": "state_data", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "workflow_snapshots_workflow_id_idx": { + "name": "workflow_snapshots_workflow_id_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_snapshots_hash_idx": { + "name": "workflow_snapshots_hash_idx", + "columns": [ + { + "expression": "state_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_snapshots_workflow_hash_idx": { + "name": "workflow_snapshots_workflow_hash_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "state_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_snapshots_created_at_idx": { + "name": "workflow_snapshots_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "workflow_execution_snapshots_workflow_id_workflow_id_fk": { + "name": "workflow_execution_snapshots_workflow_id_workflow_id_fk", + "tableFrom": "workflow_execution_snapshots", + "tableTo": "workflow", + "columnsFrom": ["workflow_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workflow_mcp_server": { + "name": "workflow_mcp_server", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_public": { + "name": "is_public", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "workflow_mcp_server_workspace_id_idx": { + "name": "workflow_mcp_server_workspace_id_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_mcp_server_created_by_idx": { + "name": "workflow_mcp_server_created_by_idx", + "columns": [ + { + "expression": "created_by", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_mcp_server_deleted_at_idx": { + "name": "workflow_mcp_server_deleted_at_idx", + "columns": [ + { + "expression": "deleted_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_mcp_server_workspace_deleted_partial_idx": { + "name": "workflow_mcp_server_workspace_deleted_partial_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "deleted_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"workflow_mcp_server\".\"deleted_at\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "workflow_mcp_server_workspace_id_workspace_id_fk": { + "name": "workflow_mcp_server_workspace_id_workspace_id_fk", + "tableFrom": "workflow_mcp_server", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workflow_mcp_server_created_by_user_id_fk": { + "name": "workflow_mcp_server_created_by_user_id_fk", + "tableFrom": "workflow_mcp_server", + "tableTo": "user", + "columnsFrom": ["created_by"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workflow_mcp_tool": { + "name": "workflow_mcp_tool", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "server_id": { + "name": "server_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tool_name": { + "name": "tool_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tool_description": { + "name": "tool_description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "parameter_schema": { + "name": "parameter_schema", + "type": "json", + "primaryKey": false, + "notNull": true, + "default": "'{}'" + }, + "parameter_description_overrides": { + "name": "parameter_description_overrides", + "type": "json", + "primaryKey": false, + "notNull": true, + "default": "'{}'::json" + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "workflow_mcp_tool_server_id_idx": { + "name": "workflow_mcp_tool_server_id_idx", + "columns": [ + { + "expression": "server_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_mcp_tool_workflow_id_idx": { + "name": "workflow_mcp_tool_workflow_id_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_mcp_tool_server_workflow_unique": { + "name": "workflow_mcp_tool_server_workflow_unique", + "columns": [ + { + "expression": "server_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"workflow_mcp_tool\".\"archived_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_mcp_tool_archived_at_partial_idx": { + "name": "workflow_mcp_tool_archived_at_partial_idx", + "columns": [ + { + "expression": "archived_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"workflow_mcp_tool\".\"archived_at\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "workflow_mcp_tool_server_id_workflow_mcp_server_id_fk": { + "name": "workflow_mcp_tool_server_id_workflow_mcp_server_id_fk", + "tableFrom": "workflow_mcp_tool", + "tableTo": "workflow_mcp_server", + "columnsFrom": ["server_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workflow_mcp_tool_workflow_id_workflow_id_fk": { + "name": "workflow_mcp_tool_workflow_id_workflow_id_fk", + "tableFrom": "workflow_mcp_tool", + "tableTo": "workflow", + "columnsFrom": ["workflow_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workflow_schedule": { + "name": "workflow_schedule", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "deployment_version_id": { + "name": "deployment_version_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "deployment_operation_id": { + "name": "deployment_operation_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "block_id": { + "name": "block_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "cron_expression": { + "name": "cron_expression", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "next_run_at": { + "name": "next_run_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_ran_at": { + "name": "last_ran_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_queued_at": { + "name": "last_queued_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "trigger_type": { + "name": "trigger_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "timezone": { + "name": "timezone", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'UTC'" + }, + "failed_count": { + "name": "failed_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "infra_retry_count": { + "name": "infra_retry_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "last_failed_at": { + "name": "last_failed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "source_type": { + "name": "source_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'workflow'" + }, + "job_title": { + "name": "job_title", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "prompt": { + "name": "prompt", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "lifecycle": { + "name": "lifecycle", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'persistent'" + }, + "success_condition": { + "name": "success_condition", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "max_runs": { + "name": "max_runs", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "run_count": { + "name": "run_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "source_chat_id": { + "name": "source_chat_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "source_task_name": { + "name": "source_task_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "source_user_id": { + "name": "source_user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "source_workspace_id": { + "name": "source_workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "secret_scope": { + "name": "secret_scope", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'all'" + }, + "mounted_secrets": { + "name": "mounted_secrets", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "job_history": { + "name": "job_history", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "contexts": { + "name": "contexts", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "excluded_dates": { + "name": "excluded_dates", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "ends_at": { + "name": "ends_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "workflow_schedule_workflow_block_deployment_unique": { + "name": "workflow_schedule_workflow_block_deployment_unique", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "block_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "deployment_version_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"workflow_schedule\".\"archived_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_schedule_workflow_deployment_idx": { + "name": "workflow_schedule_workflow_deployment_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "deployment_version_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_schedule_archived_at_partial_idx": { + "name": "workflow_schedule_archived_at_partial_idx", + "columns": [ + { + "expression": "archived_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"workflow_schedule\".\"archived_at\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_workflow_schedule_on_source_workspace_id_source_t_c07f3bba6": { + "name": "idx_workflow_schedule_on_source_workspace_id_source_t_c07f3bba6", + "columns": [ + { + "expression": "source_workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "source_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "archived_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_schedule_due_workflow_idx": { + "name": "workflow_schedule_due_workflow_idx", + "columns": [ + { + "expression": "next_run_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "last_queued_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "deployment_version_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"workflow_schedule\".\"archived_at\" IS NULL AND \"workflow_schedule\".\"status\" NOT IN ('disabled', 'completed') AND (\"workflow_schedule\".\"source_type\" = 'workflow' OR \"workflow_schedule\".\"source_type\" IS NULL)", + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_schedule_due_job_idx": { + "name": "workflow_schedule_due_job_idx", + "columns": [ + { + "expression": "next_run_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "last_queued_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"workflow_schedule\".\"archived_at\" IS NULL AND \"workflow_schedule\".\"status\" NOT IN ('disabled', 'completed') AND \"workflow_schedule\".\"source_type\" = 'job'", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "workflow_schedule_workflow_id_workflow_id_fk": { + "name": "workflow_schedule_workflow_id_workflow_id_fk", + "tableFrom": "workflow_schedule", + "tableTo": "workflow", + "columnsFrom": ["workflow_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workflow_schedule_deployment_version_id_workflow_deployment_version_id_fk": { + "name": "workflow_schedule_deployment_version_id_workflow_deployment_version_id_fk", + "tableFrom": "workflow_schedule", + "tableTo": "workflow_deployment_version", + "columnsFrom": ["deployment_version_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workflow_schedule_deployment_operation_id_workflow_deployment_operation_id_fk": { + "name": "workflow_schedule_deployment_operation_id_workflow_deployment_operation_id_fk", + "tableFrom": "workflow_schedule", + "tableTo": "workflow_deployment_operation", + "columnsFrom": ["deployment_operation_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "workflow_schedule_source_user_id_user_id_fk": { + "name": "workflow_schedule_source_user_id_user_id_fk", + "tableFrom": "workflow_schedule", + "tableTo": "user", + "columnsFrom": ["source_user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workflow_schedule_source_workspace_id_workspace_id_fk": { + "name": "workflow_schedule_source_workspace_id_workspace_id_fk", + "tableFrom": "workflow_schedule", + "tableTo": "workspace", + "columnsFrom": ["source_workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workflow_subflows": { + "name": "workflow_subflows", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workflow_id": { + "name": "workflow_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "config": { + "name": "config", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "workflow_subflows_workflow_id_idx": { + "name": "workflow_subflows_workflow_id_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workflow_subflows_workflow_type_idx": { + "name": "workflow_subflows_workflow_type_idx", + "columns": [ + { + "expression": "workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "workflow_subflows_workflow_id_workflow_id_fk": { + "name": "workflow_subflows_workflow_id_workflow_id_fk", + "tableFrom": "workflow_subflows", + "tableTo": "workflow", + "columnsFrom": ["workflow_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workspace": { + "name": "workspace", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'#33C482'" + }, + "logo_url": { + "name": "logo_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "owner_id": { + "name": "owner_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "workspace_mode": { + "name": "workspace_mode", + "type": "workspace_mode", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'grandfathered_shared'" + }, + "billed_account_user_id": { + "name": "billed_account_user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "storage_used_bytes": { + "name": "storage_used_bytes", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "allow_personal_api_keys": { + "name": "allow_personal_api_keys", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "inbox_enabled": { + "name": "inbox_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "inbox_address": { + "name": "inbox_address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "inbox_provider_id": { + "name": "inbox_provider_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "inbox_secret_scope": { + "name": "inbox_secret_scope", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'all'" + }, + "inbox_mounted_secrets": { + "name": "inbox_mounted_secrets", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "organization_assigned_at": { + "name": "organization_assigned_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "forked_from_workspace_id": { + "name": "forked_from_workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "workspace_owner_id_idx": { + "name": "workspace_owner_id_idx", + "columns": [ + { + "expression": "owner_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_organization_id_idx": { + "name": "workspace_organization_id_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_mode_idx": { + "name": "workspace_mode_idx", + "columns": [ + { + "expression": "workspace_mode", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_forked_from_workspace_id_idx": { + "name": "workspace_forked_from_workspace_id_idx", + "columns": [ + { + "expression": "forked_from_workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_inbox_provider_id_idx": { + "name": "workspace_inbox_provider_id_idx", + "columns": [ + { + "expression": "inbox_provider_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"workspace\".\"inbox_provider_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "workspace_owner_id_user_id_fk": { + "name": "workspace_owner_id_user_id_fk", + "tableFrom": "workspace", + "tableTo": "user", + "columnsFrom": ["owner_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workspace_organization_id_organization_id_fk": { + "name": "workspace_organization_id_organization_id_fk", + "tableFrom": "workspace", + "tableTo": "organization", + "columnsFrom": ["organization_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "workspace_billed_account_user_id_user_id_fk": { + "name": "workspace_billed_account_user_id_user_id_fk", + "tableFrom": "workspace", + "tableTo": "user", + "columnsFrom": ["billed_account_user_id"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + }, + "workspace_forked_from_workspace_id_workspace_id_fk": { + "name": "workspace_forked_from_workspace_id_workspace_id_fk", + "tableFrom": "workspace", + "tableTo": "workspace", + "columnsFrom": ["forked_from_workspace_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "workspace_storage_used_bytes_non_negative": { + "name": "workspace_storage_used_bytes_non_negative", + "value": "\"workspace\".\"storage_used_bytes\" >= 0" + } + }, + "isRLSEnabled": false + }, + "public.workspace_byok_keys": { + "name": "workspace_byok_keys", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "encrypted_api_key": { + "name": "encrypted_api_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "workspace_byok_workspace_provider_idx": { + "name": "workspace_byok_workspace_provider_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "workspace_byok_keys_workspace_id_workspace_id_fk": { + "name": "workspace_byok_keys_workspace_id_workspace_id_fk", + "tableFrom": "workspace_byok_keys", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workspace_byok_keys_created_by_user_id_fk": { + "name": "workspace_byok_keys_created_by_user_id_fk", + "tableFrom": "workspace_byok_keys", + "tableTo": "user", + "columnsFrom": ["created_by"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workspace_environment": { + "name": "workspace_environment", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "variables": { + "name": "variables", + "type": "json", + "primaryKey": false, + "notNull": true, + "default": "'{}'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "workspace_environment_workspace_unique": { + "name": "workspace_environment_workspace_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "workspace_environment_workspace_id_workspace_id_fk": { + "name": "workspace_environment_workspace_id_workspace_id_fk", + "tableFrom": "workspace_environment", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workspace_file": { + "name": "workspace_file", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "key": { + "name": "key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "size": { + "name": "size", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "uploaded_by": { + "name": "uploaded_by", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "uploaded_at": { + "name": "uploaded_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "workspace_file_workspace_id_idx": { + "name": "workspace_file_workspace_id_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_file_deleted_at_idx": { + "name": "workspace_file_deleted_at_idx", + "columns": [ + { + "expression": "deleted_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_file_workspace_deleted_partial_idx": { + "name": "workspace_file_workspace_deleted_partial_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "deleted_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"workspace_file\".\"deleted_at\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "workspace_file_workspace_id_workspace_id_fk": { + "name": "workspace_file_workspace_id_workspace_id_fk", + "tableFrom": "workspace_file", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workspace_file_uploaded_by_user_id_fk": { + "name": "workspace_file_uploaded_by_user_id_fk", + "tableFrom": "workspace_file", + "tableTo": "user", + "columnsFrom": ["uploaded_by"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "workspace_file_key_unique": { + "name": "workspace_file_key_unique", + "nullsNotDistinct": false, + "columns": ["key"] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workspace_file_collab_state": { + "name": "workspace_file_collab_state", + "schema": "", + "columns": { + "file_id": { + "name": "file_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "doc_state": { + "name": "doc_state", + "type": "bytea", + "primaryKey": false, + "notNull": true + }, + "source_hash": { + "name": "source_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "workspace_file_collab_state_file_id_workspace_files_id_fk": { + "name": "workspace_file_collab_state_file_id_workspace_files_id_fk", + "tableFrom": "workspace_file_collab_state", + "tableTo": "workspace_files", + "columnsFrom": ["file_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workspace_file_search_backfill": { + "name": "workspace_file_search_backfill", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "after_workspace_id": { + "name": "after_workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "after_file_id": { + "name": "after_file_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workspace_file_search_dispatch_queue": { + "name": "workspace_file_search_dispatch_queue", + "schema": "", + "columns": { + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "enqueued_at": { + "name": "enqueued_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "last_dispatched_at": { + "name": "last_dispatched_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "workspace_file_search_dispatch_queue_schedule_idx": { + "name": "workspace_file_search_dispatch_queue_schedule_idx", + "columns": [ + { + "expression": "last_dispatched_at", + "isExpression": false, + "asc": true, + "nulls": "first" + }, + { + "expression": "enqueued_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "workspace_file_search_queue_workspace_fk": { + "name": "workspace_file_search_queue_workspace_fk", + "tableFrom": "workspace_file_search_dispatch_queue", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workspace_file_search_index": { + "name": "workspace_file_search_index", + "schema": "", + "columns": { + "file_id": { + "name": "file_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_content_updated_at": { + "name": "source_content_updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "workspace_file_search_index_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "partial": { + "name": "partial", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "failure_reason": { + "name": "failure_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "line_count": { + "name": "line_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "indexed_bytes": { + "name": "indexed_bytes", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "dispatched_at": { + "name": "dispatched_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "workspace_file_search_index_workspace_status_idx": { + "name": "workspace_file_search_index_workspace_status_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "source_content_updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_file_search_index_pending_dispatch_idx": { + "name": "workspace_file_search_index_pending_dispatch_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "file_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "source_content_updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"workspace_file_search_index\".\"status\" = 'pending' AND \"workspace_file_search_index\".\"dispatched_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_file_search_index_active_dispatch_idx": { + "name": "workspace_file_search_index_active_dispatch_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "dispatched_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"workspace_file_search_index\".\"status\" = 'pending' AND \"workspace_file_search_index\".\"dispatched_at\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "workspace_file_search_index_file_fk": { + "name": "workspace_file_search_index_file_fk", + "tableFrom": "workspace_file_search_index", + "tableTo": "workspace_files", + "columnsFrom": ["file_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workspace_file_search_index_workspace_fk": { + "name": "workspace_file_search_index_workspace_fk", + "tableFrom": "workspace_file_search_index", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "workspace_file_search_index_pk": { + "name": "workspace_file_search_index_pk", + "columns": ["file_id", "source_content_updated_at"] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workspace_file_search_segment": { + "name": "workspace_file_search_segment", + "schema": "", + "columns": { + "file_id": { + "name": "file_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_content_updated_at": { + "name": "source_content_updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "line_number": { + "name": "line_number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "segment_number": { + "name": "segment_number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "segment_start": { + "name": "segment_start", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "line_length": { + "name": "line_length", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "workspace_file_search_segment_workspace_revision_idx": { + "name": "workspace_file_search_segment_workspace_revision_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "file_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "source_content_updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_file_search_segment_workspace_content_trgm_idx": { + "name": "workspace_file_search_segment_workspace_content_trgm_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "text_ops" + }, + { + "expression": "content", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "gin_trgm_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "gin", + "with": {} + } + }, + "foreignKeys": { + "workspace_file_search_segment_file_fk": { + "name": "workspace_file_search_segment_file_fk", + "tableFrom": "workspace_file_search_segment", + "tableTo": "workspace_files", + "columnsFrom": ["file_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workspace_file_search_segment_workspace_fk": { + "name": "workspace_file_search_segment_workspace_fk", + "tableFrom": "workspace_file_search_segment", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "workspace_file_search_segment_pk": { + "name": "workspace_file_search_segment_pk", + "columns": ["file_id", "source_content_updated_at", "line_number", "segment_number"] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workspace_file_secret_provenance": { + "name": "workspace_file_secret_provenance", + "schema": "", + "columns": { + "file_id": { + "name": "file_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "content_updated_at": { + "name": "content_updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "entries": { + "name": "entries", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "workspace_file_secret_provenance_file_id_workspace_files_id_fk": { + "name": "workspace_file_secret_provenance_file_id_workspace_files_id_fk", + "tableFrom": "workspace_file_secret_provenance", + "tableTo": "workspace_files", + "columnsFrom": ["file_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "workspace_file_secret_provenance_status_check": { + "name": "workspace_file_secret_provenance_status_check", + "value": "\"workspace_file_secret_provenance\".\"status\" IN ('exact', 'unknown', 'unrecorded')" + } + }, + "isRLSEnabled": false + }, + "public.workspace_files": { + "name": "workspace_files", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "key": { + "name": "key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "organization_id": { + "name": "organization_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "folder_id": { + "name": "folder_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "context": { + "name": "context", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "chat_id": { + "name": "chat_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "message_id": { + "name": "message_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "original_name": { + "name": "original_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "display_name": { + "name": "display_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "content_type": { + "name": "content_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "size": { + "name": "size", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "size_bytes": { + "name": "size_bytes", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "width": { + "name": "width", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "height": { + "name": "height", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "uploaded_at": { + "name": "uploaded_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "content_updated_at": { + "name": "content_updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "secret_provenance_version": { + "name": "secret_provenance_version", + "type": "integer", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "workspace_files_key_active_unique": { + "name": "workspace_files_key_active_unique", + "columns": [ + { + "expression": "key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"workspace_files\".\"deleted_at\" IS NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_files_workspace_folder_name_active_unique": { + "name": "workspace_files_workspace_folder_name_active_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "coalesce(\"folder_id\", '')", + "asc": true, + "isExpression": true, + "nulls": "last" + }, + { + "expression": "original_name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"workspace_files\".\"deleted_at\" IS NULL AND \"workspace_files\".\"context\" = 'workspace' AND \"workspace_files\".\"workspace_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_files_chat_display_name_unique": { + "name": "workspace_files_chat_display_name_unique", + "columns": [ + { + "expression": "chat_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "display_name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"workspace_files\".\"context\" = 'mothership' AND \"workspace_files\".\"chat_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_files_organization_id_idx": { + "name": "workspace_files_organization_id_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_files_key_idx": { + "name": "workspace_files_key_idx", + "columns": [ + { + "expression": "key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_files_user_id_idx": { + "name": "workspace_files_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_files_workspace_id_idx": { + "name": "workspace_files_workspace_id_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_files_folder_id_idx": { + "name": "workspace_files_folder_id_idx", + "columns": [ + { + "expression": "folder_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_files_context_idx": { + "name": "workspace_files_context_idx", + "columns": [ + { + "expression": "context", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_files_chat_id_idx": { + "name": "workspace_files_chat_id_idx", + "columns": [ + { + "expression": "chat_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_files_deleted_at_idx": { + "name": "workspace_files_deleted_at_idx", + "columns": [ + { + "expression": "deleted_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_files_workspace_deleted_partial_idx": { + "name": "workspace_files_workspace_deleted_partial_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "deleted_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"workspace_files\".\"deleted_at\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "workspace_files_user_id_user_id_fk": { + "name": "workspace_files_user_id_user_id_fk", + "tableFrom": "workspace_files", + "tableTo": "user", + "columnsFrom": ["user_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workspace_files_workspace_id_workspace_id_fk": { + "name": "workspace_files_workspace_id_workspace_id_fk", + "tableFrom": "workspace_files", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workspace_files_organization_id_organization_id_fk": { + "name": "workspace_files_organization_id_organization_id_fk", + "tableFrom": "workspace_files", + "tableTo": "organization", + "columnsFrom": ["organization_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workspace_files_folder_id_folder_id_fk": { + "name": "workspace_files_folder_id_folder_id_fk", + "tableFrom": "workspace_files", + "tableTo": "folder", + "columnsFrom": ["folder_id"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + }, + "workspace_files_chat_id_copilot_chats_id_fk": { + "name": "workspace_files_chat_id_copilot_chats_id_fk", + "tableFrom": "workspace_files", + "tableTo": "copilot_chats", + "columnsFrom": ["chat_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "workspace_files_organization_binding_check": { + "name": "workspace_files_organization_binding_check", + "value": "\"workspace_files\".\"organization_id\" IS NULL OR (\"workspace_files\".\"workspace_id\" IS NULL AND \"workspace_files\".\"context\" = 'knowledge-base' AND \"workspace_files\".\"folder_id\" IS NULL AND \"workspace_files\".\"chat_id\" IS NULL)" + } + }, + "isRLSEnabled": false + }, + "public.workspace_fork_block_map": { + "name": "workspace_fork_block_map", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "child_workspace_id": { + "name": "child_workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "parent_workflow_id": { + "name": "parent_workflow_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "parent_block_id": { + "name": "parent_block_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "child_workflow_id": { + "name": "child_workflow_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "child_block_id": { + "name": "child_block_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "workspace_fork_block_map_child_ws_parent_unique": { + "name": "workspace_fork_block_map_child_ws_parent_unique", + "columns": [ + { + "expression": "child_workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "parent_block_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_fork_block_map_child_ws_child_unique": { + "name": "workspace_fork_block_map_child_ws_child_unique", + "columns": [ + { + "expression": "child_workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "child_block_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_fork_block_map_child_ws_parent_wf_idx": { + "name": "workspace_fork_block_map_child_ws_parent_wf_idx", + "columns": [ + { + "expression": "child_workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "parent_workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_fork_block_map_child_ws_child_wf_idx": { + "name": "workspace_fork_block_map_child_ws_child_wf_idx", + "columns": [ + { + "expression": "child_workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "child_workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "workspace_fork_block_map_child_workspace_id_workspace_id_fk": { + "name": "workspace_fork_block_map_child_workspace_id_workspace_id_fk", + "tableFrom": "workspace_fork_block_map", + "tableTo": "workspace", + "columnsFrom": ["child_workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workspace_fork_dependent_value": { + "name": "workspace_fork_dependent_value", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "child_workspace_id": { + "name": "child_workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "target_workflow_id": { + "name": "target_workflow_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "target_block_id": { + "name": "target_block_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "sub_block_key": { + "name": "sub_block_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "workspace_fork_dependent_value_child_ws_wf_idx": { + "name": "workspace_fork_dependent_value_child_ws_wf_idx", + "columns": [ + { + "expression": "child_workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "target_workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_fork_dependent_value_field_unique": { + "name": "workspace_fork_dependent_value_field_unique", + "columns": [ + { + "expression": "child_workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "target_workflow_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "target_block_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sub_block_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "workspace_fork_dependent_value_child_workspace_id_workspace_id_fk": { + "name": "workspace_fork_dependent_value_child_workspace_id_workspace_id_fk", + "tableFrom": "workspace_fork_dependent_value", + "tableTo": "workspace", + "columnsFrom": ["child_workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workspace_fork_promote_run": { + "name": "workspace_fork_promote_run", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "child_workspace_id": { + "name": "child_workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_workspace_id": { + "name": "source_workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "target_workspace_id": { + "name": "target_workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "direction": { + "name": "direction", + "type": "workspace_fork_promote_direction", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "snapshot": { + "name": "snapshot", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "workspace_fork_promote_run_child_ws_target_unique": { + "name": "workspace_fork_promote_run_child_ws_target_unique", + "columns": [ + { + "expression": "child_workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "target_workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_fork_promote_run_target_ws_idx": { + "name": "workspace_fork_promote_run_target_ws_idx", + "columns": [ + { + "expression": "target_workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "workspace_fork_promote_run_child_workspace_id_workspace_id_fk": { + "name": "workspace_fork_promote_run_child_workspace_id_workspace_id_fk", + "tableFrom": "workspace_fork_promote_run", + "tableTo": "workspace", + "columnsFrom": ["child_workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workspace_fork_promote_run_created_by_user_id_fk": { + "name": "workspace_fork_promote_run_created_by_user_id_fk", + "tableFrom": "workspace_fork_promote_run", + "tableTo": "user", + "columnsFrom": ["created_by"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workspace_fork_resource_map": { + "name": "workspace_fork_resource_map", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "child_workspace_id": { + "name": "child_workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "resource_type": { + "name": "resource_type", + "type": "workspace_fork_resource_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "parent_resource_id": { + "name": "parent_resource_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "child_resource_id": { + "name": "child_resource_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "workspace_fork_resource_map_child_ws_idx": { + "name": "workspace_fork_resource_map_child_ws_idx", + "columns": [ + { + "expression": "child_workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_fork_resource_map_child_ws_type_idx": { + "name": "workspace_fork_resource_map_child_ws_type_idx", + "columns": [ + { + "expression": "child_workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "resource_type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_fork_resource_map_child_type_parent_unique": { + "name": "workspace_fork_resource_map_child_type_parent_unique", + "columns": [ + { + "expression": "child_workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "resource_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "parent_resource_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "workspace_fork_resource_map_child_workspace_id_workspace_id_fk": { + "name": "workspace_fork_resource_map_child_workspace_id_workspace_id_fk", + "tableFrom": "workspace_fork_resource_map", + "tableTo": "workspace", + "columnsFrom": ["child_workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workspace_fork_resource_map_created_by_user_id_fk": { + "name": "workspace_fork_resource_map_created_by_user_id_fk", + "tableFrom": "workspace_fork_resource_map", + "tableTo": "user", + "columnsFrom": ["created_by"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workspace_operation_receipt": { + "name": "workspace_operation_receipt", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "request_id": { + "name": "request_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "request_hash": { + "name": "request_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "report": { + "name": "report", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "workspace_operation_receipt_request_unique": { + "name": "workspace_operation_receipt_request_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "request_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_operation_receipt_workspace_created_idx": { + "name": "workspace_operation_receipt_workspace_created_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "workspace_operation_receipt_workspace_id_workspace_id_fk": { + "name": "workspace_operation_receipt_workspace_id_workspace_id_fk", + "tableFrom": "workspace_operation_receipt", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.workspace_sandbox": { + "name": "workspace_sandbox", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "language": { + "name": "language", + "type": "sandbox_language", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "dependencies": { + "name": "dependencies", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "cli_tools": { + "name": "cli_tools", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "system_packages": { + "name": "system_packages", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "spec_hash": { + "name": "spec_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "workspace_sandbox_workspace_name_unique": { + "name": "workspace_sandbox_workspace_name_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_sandbox_workspace_idx": { + "name": "workspace_sandbox_workspace_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_sandbox_spec_hash_idx": { + "name": "workspace_sandbox_spec_hash_idx", + "columns": [ + { + "expression": "spec_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "workspace_sandbox_workspace_id_workspace_id_fk": { + "name": "workspace_sandbox_workspace_id_workspace_id_fk", + "tableFrom": "workspace_sandbox", + "tableTo": "workspace", + "columnsFrom": ["workspace_id"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "workspace_sandbox_created_by_user_id_fk": { + "name": "workspace_sandbox_created_by_user_id_fk", + "tableFrom": "workspace_sandbox", + "tableTo": "user", + "columnsFrom": ["created_by"], + "columnsTo": ["id"], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.academy_cert_status": { + "name": "academy_cert_status", + "schema": "public", + "values": ["active", "revoked", "expired"] + }, + "public.background_work_kind": { + "name": "background_work_kind", + "schema": "public", + "values": ["deployment_side_effects", "fork_content_copy", "fork_sync", "fork_rollback"] + }, + "public.background_work_status_value": { + "name": "background_work_status_value", + "schema": "public", + "values": ["pending", "processing", "completed", "completed_with_warnings", "failed"] + }, + "public.billing_blocked_reason": { + "name": "billing_blocked_reason", + "schema": "public", + "values": ["payment_failed", "dispute"] + }, + "public.billing_entity_type": { + "name": "billing_entity_type", + "schema": "public", + "values": ["user", "organization"] + }, + "public.chat_type": { + "name": "chat_type", + "schema": "public", + "values": ["mothership", "copilot"] + }, + "public.copilot_async_tool_status": { + "name": "copilot_async_tool_status", + "schema": "public", + "values": ["pending", "running", "completed", "failed", "cancelled", "delivered"] + }, + "public.copilot_run_status": { + "name": "copilot_run_status", + "schema": "public", + "values": ["active", "paused_waiting_for_tool", "resuming", "complete", "error", "cancelled"] + }, + "public.copilot_tool_permission_decision": { + "name": "copilot_tool_permission_decision", + "schema": "public", + "values": ["allow", "allow_chat", "always_allow", "skip"] + }, + "public.credential_group_enrollment_status": { + "name": "credential_group_enrollment_status", + "schema": "public", + "values": ["invited", "delivery_failed", "in_progress", "completed", "revoked"] + }, + "public.credential_group_status": { + "name": "credential_group_status", + "schema": "public", + "values": ["active", "disabled"] + }, + "public.credential_member_role": { + "name": "credential_member_role", + "schema": "public", + "values": ["admin", "member"] + }, + "public.credential_member_status": { + "name": "credential_member_status", + "schema": "public", + "values": ["active", "pending", "revoked"] + }, + "public.credential_type": { + "name": "credential_type", + "schema": "public", + "values": [ + "oauth", + "managed_oauth", + "managed_mcp", + "env_workspace", + "env_personal", + "service_account", + "personal_token" + ] + }, + "public.data_drain_cadence": { + "name": "data_drain_cadence", + "schema": "public", + "values": ["hourly", "daily"] + }, + "public.data_drain_destination": { + "name": "data_drain_destination", + "schema": "public", + "values": ["s3", "gcs", "azure_blob", "datadog", "bigquery", "snowflake", "webhook"] + }, + "public.data_drain_run_status": { + "name": "data_drain_run_status", + "schema": "public", + "values": ["running", "success", "failed"] + }, + "public.data_drain_run_trigger": { + "name": "data_drain_run_trigger", + "schema": "public", + "values": ["cron", "manual"] + }, + "public.data_drain_source": { + "name": "data_drain_source", + "schema": "public", + "values": ["workflow_logs", "job_logs", "audit_logs", "copilot_chats", "copilot_runs"] + }, + "public.execution_large_value_reference_source": { + "name": "execution_large_value_reference_source", + "schema": "public", + "values": ["execution_log", "paused_snapshot"] + }, + "public.folder_resource_type": { + "name": "folder_resource_type", + "schema": "public", + "values": ["workflow", "file", "knowledge_base", "table"] + }, + "public.invitation_kind": { + "name": "invitation_kind", + "schema": "public", + "values": ["organization", "workspace"] + }, + "public.invitation_membership_intent": { + "name": "invitation_membership_intent", + "schema": "public", + "values": ["internal", "external"] + }, + "public.invitation_status": { + "name": "invitation_status", + "schema": "public", + "values": ["pending", "accepted", "rejected", "cancelled", "expired"] + }, + "public.managed_oauth_credential_status": { + "name": "managed_oauth_credential_status", + "schema": "public", + "values": ["active", "needs_reauth", "revoked"] + }, + "public.permission_type": { + "name": "permission_type", + "schema": "public", + "values": ["admin", "write", "read"] + }, + "public.sandbox_image_status": { + "name": "sandbox_image_status", + "schema": "public", + "values": ["pending", "building", "ready", "failed"] + }, + "public.sandbox_language": { + "name": "sandbox_language", + "schema": "public", + "values": ["javascript", "python"] + }, + "public.secret_usage_scope": { + "name": "secret_usage_scope", + "schema": "public", + "values": ["workspace", "personal"] + }, + "public.secret_usage_source": { + "name": "secret_usage_source", + "schema": "public", + "values": ["workflow", "copilot", "mcp"] + }, + "public.upload_session_method": { + "name": "upload_session_method", + "schema": "public", + "values": ["put", "multipart"] + }, + "public.upload_session_provider": { + "name": "upload_session_provider", + "schema": "public", + "values": ["local", "s3", "blob", "gcs"] + }, + "public.upload_session_purpose": { + "name": "upload_session_purpose", + "schema": "public", + "values": [ + "workspace_file", + "table_import", + "knowledge_document", + "profile_picture", + "workspace_logo", + "mothership_attachment", + "execution_attachment" + ] + }, + "public.upload_session_status": { + "name": "upload_session_status", + "schema": "public", + "values": [ + "uploading", + "completing", + "finalizing", + "completed", + "aborting", + "aborted", + "failed", + "expired" + ] + }, + "public.usage_log_category": { + "name": "usage_log_category", + "schema": "public", + "values": ["model", "fixed", "tool", "model_unbilled"] + }, + "public.usage_log_source": { + "name": "usage_log_source", + "schema": "public", + "values": [ + "workflow", + "wand", + "copilot", + "workspace-chat", + "mcp_copilot", + "mothership_block", + "knowledge-base", + "voice-input", + "enrichment", + "voice-output", + "api-tool" + ] + }, + "public.workspace_file_search_index_status": { + "name": "workspace_file_search_index_status", + "schema": "public", + "values": ["pending", "ready", "skipped", "failed"] + }, + "public.workspace_fork_promote_direction": { + "name": "workspace_fork_promote_direction", + "schema": "public", + "values": ["push", "pull"] + }, + "public.workspace_fork_resource_type": { + "name": "workspace_fork_resource_type", + "schema": "public", + "values": [ + "workflow", + "oauth_credential", + "service_account_credential", + "env_var", + "table", + "knowledge_base", + "knowledge_document", + "file", + "file_folder", + "mcp_server", + "workflow_mcp_server", + "custom_block", + "custom_tool", + "skill", + "sandbox" + ] + }, + "public.workspace_mode": { + "name": "workspace_mode", + "schema": "public", + "values": ["personal", "organization", "grandfathered_shared"] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} diff --git a/packages/db/migrations/meta/_journal.json b/packages/db/migrations/meta/_journal.json index de9faaffd08..40fae367dcc 100644 --- a/packages/db/migrations/meta/_journal.json +++ b/packages/db/migrations/meta/_journal.json @@ -2374,6 +2374,13 @@ "when": 1789084655493, "tag": "0339_connector_permissions", "breakpoints": true + }, + { + "idx": 340, + "version": "7", + "when": 1789150173739, + "tag": "0340_slack_shared_app_env", + "breakpoints": true } ] } diff --git a/packages/db/schema.ts b/packages/db/schema.ts index cc5c149a0c7..b2c4ba60015 100644 --- a/packages/db/schema.ts +++ b/packages/db/schema.ts @@ -4969,9 +4969,10 @@ export const slackApp = pgTable( onDelete: 'cascade', }), kind: text('kind').$type<'custom' | 'shared'>().notNull(), - clientId: text('client_id').notNull(), - encryptedClientSecret: text('encrypted_client_secret').notNull(), - encryptedSigningSecret: text('encrypted_signing_secret').notNull(), + /** Custom app credentials; company app credentials come from the deployment environment. */ + clientId: text('client_id'), + encryptedClientSecret: text('encrypted_client_secret'), + encryptedSigningSecret: text('encrypted_signing_secret'), revision: text('revision').notNull(), createdAt: timestamp('created_at').notNull().defaultNow(), updatedAt: timestamp('updated_at').notNull().defaultNow(), @@ -4981,6 +4982,10 @@ export const slackApp = pgTable( 'slack_app_owner_check', sql`(${table.kind} = 'custom' AND ${table.organizationId} IS NOT NULL) OR (${table.kind} = 'shared' AND ${table.organizationId} IS NULL)` ), + customCredentialsCheck: check( + 'slack_app_custom_credentials_check', + sql`${table.kind} = 'shared' OR (${table.clientId} IS NOT NULL AND ${table.encryptedClientSecret} IS NOT NULL AND ${table.encryptedSigningSecret} IS NOT NULL)` + ), }) ) From 938d1bc4b01407f20b0a4e75b931f3be4bed7a96 Mon Sep 17 00:00:00 2001 From: Waleed Date: Fri, 11 Sep 2026 11:59:17 -0700 Subject: [PATCH 07/15] fix(sidebar): align organization and workspace navigation (#7777) * fix(sidebar): align organization and workspace navigation * fix(settings): classify recently deleted in workspace move impact * fix(tests): isolate organization layout event subscriptions --- .../app/api/copilot/chat/stop/route.test.ts | 48 ++-- apps/sim/app/api/copilot/chat/stop/route.ts | 7 +- .../chats/[chatId]/fork/route.test.ts | 14 +- .../mothership/chats/[chatId]/fork/route.ts | 10 +- .../chats/[chatId]/restore/route.test.ts | 14 +- .../chats/[chatId]/restore/route.ts | 8 +- .../mothership/chats/[chatId]/route.test.ts | 69 ++++- .../api/mothership/chats/[chatId]/route.ts | 22 +- .../api/mothership/chats/read/route.test.ts | 19 ++ .../app/api/mothership/chats/read/route.ts | 7 +- .../app/api/mothership/events/route.test.ts | 201 ++++++++++++++ apps/sim/app/api/mothership/events/route.ts | 59 +++- .../chats-section/chats-section.test.tsx | 137 +++++++++- .../chats-section/chats-section.tsx | 12 +- .../organization-sidebar/components/index.ts | 1 - .../organization-footer.test.tsx | 130 +++++++++ .../organization-footer.tsx | 10 +- .../workspaces-rail-flyout/index.ts | 1 - .../workspaces-rail-flyout.test.tsx | 97 ------- .../workspaces-rail-flyout.tsx | 35 --- .../workspace-list.test.tsx | 116 ++++++++ .../workspaces-section/workspace-list.tsx | 256 ++++++++++++++++++ .../workspaces-section.test.tsx | 159 ++++++++++- .../workspaces-section/workspaces-section.tsx | 150 +++++----- .../hooks/use-organization-chat-actions.ts | 32 +++ .../use-organization-workspaces.test.tsx | 123 +++++++++ .../hooks/use-organization-workspaces.ts | 20 +- .../organization-sidebar.tsx | 1 - .../app/o/[organizationId]/layout.test.tsx | 11 + apps/sim/app/o/[organizationId]/layout.tsx | 3 +- .../providers/organization-provider.tsx | 12 +- .../settings/[section]/settings.tsx | 9 + .../organization-recently-deleted.test.tsx | 178 ++++++++++++ .../organization-recently-deleted.tsx | 84 ++++++ .../settings/navigation.test.ts | 13 +- .../sidebar-footer/sidebar-footer.tsx | 2 +- .../workspace-header/workspace-header.tsx | 71 ++--- .../hooks/use-flyout-inline-rename.test.tsx | 109 ++++++++ .../sidebar/hooks/use-flyout-inline-rename.ts | 27 +- .../sidebar/hooks/use-workspace-management.ts | 24 +- .../w/components/sidebar/sidebar.tsx | 2 +- .../components/settings/navigation.test.ts | 19 ++ apps/sim/components/settings/navigation.ts | 16 +- .../workspace-context-menu.test.tsx | 114 ++++++++ .../workspaces/workspace-context-menu.tsx | 47 ++++ .../hooks/queries/mothership-chats.test.ts | 60 +++- apps/sim/hooks/queries/mothership-chats.ts | 25 +- ...-mothership-chat-events-lifecycle.test.tsx | 115 ++++++++ .../hooks/use-mothership-chat-events.test.ts | 28 ++ apps/sim/hooks/use-mothership-chat-events.ts | 59 ++-- apps/sim/hooks/use-workspace-order.ts | 22 ++ .../sim/lib/api/contracts/mothership-chats.ts | 6 +- apps/sim/lib/copilot/chat-status.test.ts | 54 ++++ apps/sim/lib/copilot/chat-status.ts | 26 +- .../copilot/chat/organization-chats.test.ts | 75 ++++- .../lib/copilot/chat/organization-chats.ts | 23 ++ apps/sim/lib/copilot/chat/post.test.ts | 58 +++- apps/sim/lib/copilot/chat/post.ts | 125 ++++++--- .../copilot/request/lifecycle/start.test.ts | 2 +- .../lib/copilot/request/lifecycle/start.ts | 10 +- apps/sim/lib/core/utils/browser-storage.ts | 34 ++- apps/sim/lib/events/sse-endpoint.ts | 248 ++++++++++------- .../lib/organizations/settings-access.test.ts | 11 + .../workspaces/admin-move-source-impact.ts | 6 +- apps/sim/lib/workspaces/constants.ts | 2 + apps/sim/lib/workspaces/utils.test.ts | 32 ++- apps/sim/lib/workspaces/utils.ts | 4 +- 67 files changed, 2912 insertions(+), 612 deletions(-) create mode 100644 apps/sim/app/api/mothership/events/route.test.ts create mode 100644 apps/sim/app/o/[organizationId]/components/organization-sidebar/components/organization-footer/organization-footer.test.tsx delete mode 100644 apps/sim/app/o/[organizationId]/components/organization-sidebar/components/workspaces-rail-flyout/index.ts delete mode 100644 apps/sim/app/o/[organizationId]/components/organization-sidebar/components/workspaces-rail-flyout/workspaces-rail-flyout.test.tsx delete mode 100644 apps/sim/app/o/[organizationId]/components/organization-sidebar/components/workspaces-rail-flyout/workspaces-rail-flyout.tsx create mode 100644 apps/sim/app/o/[organizationId]/components/organization-sidebar/components/workspaces-section/workspace-list.test.tsx create mode 100644 apps/sim/app/o/[organizationId]/components/organization-sidebar/components/workspaces-section/workspace-list.tsx create mode 100644 apps/sim/app/o/[organizationId]/components/organization-sidebar/hooks/use-organization-workspaces.test.tsx create mode 100644 apps/sim/app/o/[organizationId]/settings/components/organization-recently-deleted.test.tsx create mode 100644 apps/sim/app/o/[organizationId]/settings/components/organization-recently-deleted.tsx create mode 100644 apps/sim/app/workspace/[workspaceId]/w/components/sidebar/hooks/use-flyout-inline-rename.test.tsx create mode 100644 apps/sim/components/workspaces/workspace-context-menu.test.tsx create mode 100644 apps/sim/components/workspaces/workspace-context-menu.tsx create mode 100644 apps/sim/hooks/use-mothership-chat-events-lifecycle.test.tsx create mode 100644 apps/sim/hooks/use-workspace-order.ts create mode 100644 apps/sim/lib/copilot/chat-status.test.ts create mode 100644 apps/sim/lib/workspaces/constants.ts diff --git a/apps/sim/app/api/copilot/chat/stop/route.test.ts b/apps/sim/app/api/copilot/chat/stop/route.test.ts index ccee5a1bde7..182606b3ab3 100644 --- a/apps/sim/app/api/copilot/chat/stop/route.test.ts +++ b/apps/sim/app/api/copilot/chat/stop/route.test.ts @@ -21,9 +21,7 @@ vi.mock('@/lib/copilot/chat/messages-store', () => ({ })) vi.mock('@/lib/copilot/chat-status', () => ({ - chatPubSub: { - publishStatusChanged: mockPublishStatusChanged, - }, + publishChatStatusChanged: mockPublishStatusChanged, })) import { POST } from '@/app/api/copilot/chat/stop/route' @@ -59,7 +57,7 @@ describe('copilot chat stop route', () => { user: { id: 'user-1' }, session: { id: 'session-1' }, }) - mockGetAccessibleChat.mockResolvedValue({ id: 'chat-1' }) + mockGetAccessibleChat.mockResolvedValue({ id: 'chat-1', workspaceId: 'ws-1', userId: 'user-1' }) }) it('does not persist stopped content after organization access is removed', async () => { @@ -120,12 +118,14 @@ describe('copilot chat stop route', () => { contentBlocks: [{ type: 'complete', status: 'cancelled' }], }) - expect(mockPublishStatusChanged).toHaveBeenCalledWith({ - workspaceId: 'ws-1', - chatId: 'chat-1', - type: 'completed', - streamId: 'stream-1', - }) + expect(mockPublishStatusChanged).toHaveBeenCalledWith( + expect.objectContaining({ workspaceId: 'ws-1' }), + { + chatId: 'chat-1', + type: 'completed', + streamId: 'stream-1', + } + ) }) it('appends a stopped assistant message if the stream marker was already cleared', async () => { @@ -145,12 +145,14 @@ describe('copilot chat stop route', () => { const [, appended] = mockAppendCopilotChatMessages.mock.calls[0] expect(appended[0]).toMatchObject({ role: 'assistant', content: 'partial' }) - expect(mockPublishStatusChanged).toHaveBeenCalledWith({ - workspaceId: 'ws-1', - chatId: 'chat-1', - type: 'completed', - streamId: 'stream-1', - }) + expect(mockPublishStatusChanged).toHaveBeenCalledWith( + expect.objectContaining({ workspaceId: 'ws-1' }), + { + chatId: 'chat-1', + type: 'completed', + streamId: 'stream-1', + } + ) }) it('republishes completed status when the assistant was already persisted', async () => { @@ -167,11 +169,13 @@ describe('copilot chat stop route', () => { expect(await response.json()).toEqual({ success: true }) expect(mockAppendCopilotChatMessages).not.toHaveBeenCalled() expect(dbChainMockFns.set).not.toHaveBeenCalled() - expect(mockPublishStatusChanged).toHaveBeenCalledWith({ - workspaceId: 'ws-1', - chatId: 'chat-1', - type: 'completed', - streamId: 'stream-1', - }) + expect(mockPublishStatusChanged).toHaveBeenCalledWith( + expect.objectContaining({ workspaceId: 'ws-1' }), + { + chatId: 'chat-1', + type: 'completed', + streamId: 'stream-1', + } + ) }) }) diff --git a/apps/sim/app/api/copilot/chat/stop/route.ts b/apps/sim/app/api/copilot/chat/stop/route.ts index ef02d470844..29cf8900229 100644 --- a/apps/sim/app/api/copilot/chat/stop/route.ts +++ b/apps/sim/app/api/copilot/chat/stop/route.ts @@ -11,7 +11,7 @@ import { withStoppedContentBlock, } from '@/lib/copilot/chat/persisted-message' import { finalizeAssistantTurn } from '@/lib/copilot/chat/terminal-state' -import { chatPubSub } from '@/lib/copilot/chat-status' +import { publishChatStatusChanged } from '@/lib/copilot/chat-status' import { CopilotChatFinalizeOutcome, CopilotStopOutcome, @@ -87,9 +87,8 @@ export const POST = withRouteHandler((req: NextRequest) => const shouldPublishCompleted = result.updated || result.outcome === CopilotChatFinalizeOutcome.AssistantAlreadyPersisted - if (shouldPublishCompleted && result.workspaceId) { - chatPubSub?.publishStatusChanged({ - workspaceId: result.workspaceId, + if (shouldPublishCompleted) { + publishChatStatusChanged(chat, { chatId, type: 'completed', streamId, diff --git a/apps/sim/app/api/mothership/chats/[chatId]/fork/route.test.ts b/apps/sim/app/api/mothership/chats/[chatId]/fork/route.test.ts index 4e806387e8c..a3e687bdf27 100644 --- a/apps/sim/app/api/mothership/chats/[chatId]/fork/route.test.ts +++ b/apps/sim/app/api/mothership/chats/[chatId]/fork/route.test.ts @@ -65,7 +65,7 @@ vi.mock('@/lib/copilot/chat/messages-store', () => ({ })) vi.mock('@/lib/copilot/chat-status', () => ({ - chatPubSub: { publishStatusChanged: mockPublishStatusChanged }, + publishChatStatusChanged: mockPublishStatusChanged, })) vi.mock('@/lib/copilot/request/go/fetch', () => ({ @@ -291,11 +291,13 @@ describe('POST /api/mothership/chats/[chatId]/fork', () => { userId: 'user-1', }) - expect(mockPublishStatusChanged).toHaveBeenCalledWith({ - workspaceId: 'ws-1', - chatId: body.id, - type: 'created', - }) + expect(mockPublishStatusChanged).toHaveBeenCalledWith( + expect.objectContaining({ workspaceId: 'ws-1' }), + { + chatId: body.id, + type: 'created', + } + ) expect(mockCaptureServerEvent).toHaveBeenCalledWith( 'user-1', 'task_forked', diff --git a/apps/sim/app/api/mothership/chats/[chatId]/fork/route.ts b/apps/sim/app/api/mothership/chats/[chatId]/fork/route.ts index 740456f750b..0bd87841838 100644 --- a/apps/sim/app/api/mothership/chats/[chatId]/fork/route.ts +++ b/apps/sim/app/api/mothership/chats/[chatId]/fork/route.ts @@ -19,7 +19,7 @@ import { rewriteMessageFileRefs, rewriteResourceFileRefs, } from '@/lib/copilot/chat/rewrite-file-references' -import { chatPubSub } from '@/lib/copilot/chat-status' +import { publishChatStatusChanged } from '@/lib/copilot/chat-status' import { fetchGo } from '@/lib/copilot/request/go/fetch' import { authenticateCopilotRequestSessionOnly, @@ -267,13 +267,7 @@ export const POST = withRouteHandler( logger.warn('Failed to fork copilot-service conversation, skipping', { err }) } - if (newChat.workspaceId) { - chatPubSub?.publishStatusChanged({ - workspaceId: newChat.workspaceId, - chatId: newId, - type: 'created', - }) - } + publishChatStatusChanged({ ...parent, userId }, { chatId: newId, type: 'created' }) captureServerEvent( userId, diff --git a/apps/sim/app/api/mothership/chats/[chatId]/restore/route.test.ts b/apps/sim/app/api/mothership/chats/[chatId]/restore/route.test.ts index ee9438038b8..adfe941a4e0 100644 --- a/apps/sim/app/api/mothership/chats/[chatId]/restore/route.test.ts +++ b/apps/sim/app/api/mothership/chats/[chatId]/restore/route.test.ts @@ -26,7 +26,7 @@ vi.mock('@/lib/workspaces/permissions/utils', () => ({ })) vi.mock('@/lib/copilot/chat-status', () => ({ - chatPubSub: { publishStatusChanged: mockPublishStatusChanged }, + publishChatStatusChanged: mockPublishStatusChanged, })) vi.mock('@/lib/posthog/server', () => ({ @@ -101,11 +101,13 @@ describe('POST /api/mothership/chats/[chatId]/restore', () => { updatedAt: expect.any(Date), lastSeenAt: expect.any(Date), }) - expect(mockPublishStatusChanged).toHaveBeenCalledWith({ - workspaceId: 'workspace-1', - chatId: 'chat-1', - type: 'created', - }) + expect(mockPublishStatusChanged).toHaveBeenCalledWith( + expect.objectContaining({ workspaceId: 'workspace-1' }), + { + chatId: 'chat-1', + type: 'created', + } + ) }) it('returns 404 when the chat is restored concurrently before the update lands', async () => { diff --git a/apps/sim/app/api/mothership/chats/[chatId]/restore/route.ts b/apps/sim/app/api/mothership/chats/[chatId]/restore/route.ts index b98f6824e1f..ed1b9d84c24 100644 --- a/apps/sim/app/api/mothership/chats/[chatId]/restore/route.ts +++ b/apps/sim/app/api/mothership/chats/[chatId]/restore/route.ts @@ -6,7 +6,7 @@ import { type NextRequest, NextResponse } from 'next/server' import { restoreMothershipChatContract } from '@/lib/api/contracts/mothership-chats' import { parseRequest } from '@/lib/api/server' import { authorizeOrganizationChat } from '@/lib/copilot/chat/organization-chats' -import { chatPubSub } from '@/lib/copilot/chat-status' +import { publishChatStatusChanged } from '@/lib/copilot/chat-status' import { authenticateCopilotRequestSessionOnly, createForbiddenResponse, @@ -95,12 +95,8 @@ export const POST = withRouteHandler( return NextResponse.json({ success: false, error: 'Chat not found' }, { status: 404 }) } + publishChatStatusChanged({ ...restoredChat, userId }, { chatId, type: 'created' }) if (restoredChat.workspaceId) { - chatPubSub?.publishStatusChanged({ - workspaceId: restoredChat.workspaceId, - chatId, - type: 'created', - }) captureServerEvent( userId, 'task_restored', diff --git a/apps/sim/app/api/mothership/chats/[chatId]/route.test.ts b/apps/sim/app/api/mothership/chats/[chatId]/route.test.ts index d0f2a64c00e..ae07dee5be7 100644 --- a/apps/sim/app/api/mothership/chats/[chatId]/route.test.ts +++ b/apps/sim/app/api/mothership/chats/[chatId]/route.test.ts @@ -59,7 +59,7 @@ vi.mock('@/lib/copilot/chat/persisted-message', () => ({ })) vi.mock('@/lib/copilot/chat-status', () => ({ - chatPubSub: { publishStatusChanged: vi.fn() }, + publishChatStatusChanged: vi.fn(), })) vi.mock('@/lib/billing/storage', () => ({ @@ -71,7 +71,8 @@ vi.mock('@/lib/posthog/server', () => ({ captureServerEvent: vi.fn(), })) -import { DELETE, GET } from '@/app/api/mothership/chats/[chatId]/route' +import { publishChatStatusChanged } from '@/lib/copilot/chat-status' +import { DELETE, GET, PATCH } from '@/app/api/mothership/chats/[chatId]/route' function makeContext(chatId: string) { return { params: Promise.resolve({ chatId }) } @@ -307,3 +308,67 @@ describe('DELETE /api/mothership/chats/[chatId]', () => { expect(mockDecrementStorageUsageForBillingContextInTx).not.toHaveBeenCalled() }) }) + +describe('organization chat mutations publish private owner updates', () => { + beforeEach(() => { + vi.clearAllMocks() + resetDbChainMock() + copilotHttpMockFns.mockAuthenticateCopilotRequestSessionOnly.mockResolvedValue({ + userId: 'user-1', + isAuthenticated: true, + principal: { kind: 'session', userId: 'user-1', sessionId: 'session-1' }, + }) + mockGetAccessibleCopilotChat.mockResolvedValue({ + id: 'chat-1', + type: 'mothership', + organizationId: 'org-1', + userId: 'user-1', + }) + dbChainMockFns.returning.mockResolvedValue([ + { id: 'chat-1', workspaceId: null, organizationId: 'org-1' }, + ]) + }) + + it.each([{ title: 'New title' }, { pinned: true }, { isUnread: true }, { isUnread: false }])( + 'publishes after updating %j', + async (body) => { + const response = await PATCH( + new NextRequest('http://localhost/api/mothership/chats/chat-1', { + method: 'PATCH', + body: JSON.stringify(body), + }), + makeContext('chat-1') + ) + expect(response.status).toBe(200) + expect(publishChatStatusChanged).toHaveBeenCalledWith( + expect.objectContaining({ organizationId: 'org-1', userId: 'user-1' }), + { chatId: 'chat-1', type: 'title' in body ? 'renamed' : 'updated' } + ) + } + ) + + it('publishes deletion under the same owner', async () => { + const response = await DELETE( + new NextRequest('http://localhost/api/mothership/chats/chat-1', { method: 'DELETE' }), + makeContext('chat-1') + ) + expect(response.status).toBe(200) + expect(publishChatStatusChanged).toHaveBeenCalledWith( + expect.objectContaining({ organizationId: 'org-1', userId: 'user-1' }), + { chatId: 'chat-1', type: 'deleted' } + ) + }) + + it('does not publish if a concurrent deletion leaves no updated row', async () => { + dbChainMockFns.returning.mockResolvedValueOnce([]) + const response = await PATCH( + new NextRequest('http://localhost/api/mothership/chats/chat-1', { + method: 'PATCH', + body: JSON.stringify({ pinned: true }), + }), + makeContext('chat-1') + ) + expect(response.status).toBe(404) + expect(publishChatStatusChanged).not.toHaveBeenCalled() + }) +}) diff --git a/apps/sim/app/api/mothership/chats/[chatId]/route.ts b/apps/sim/app/api/mothership/chats/[chatId]/route.ts index 6d321e169f3..e8e6eccbf8c 100644 --- a/apps/sim/app/api/mothership/chats/[chatId]/route.ts +++ b/apps/sim/app/api/mothership/chats/[chatId]/route.ts @@ -18,7 +18,7 @@ import { } from '@/lib/copilot/chat/lifecycle' import { normalizeMessage } from '@/lib/copilot/chat/persisted-message' import { reconcileChatStreamMarkers } from '@/lib/copilot/chat/stream-liveness' -import { chatPubSub } from '@/lib/copilot/chat-status' +import { publishChatStatusChanged } from '@/lib/copilot/chat-status' import { authenticateCopilotRequestSessionOnly, createInternalServerErrorResponse, @@ -199,19 +199,22 @@ export const PATCH = withRouteHandler( .returning({ id: copilotChats.id, workspaceId: copilotChats.workspaceId, + organizationId: copilotChats.organizationId, }) if (!updatedChat) { return NextResponse.json({ success: false, error: 'Chat not found' }, { status: 404 }) } + publishChatStatusChanged( + { ...updatedChat, userId }, + { + chatId, + type: title !== undefined ? 'renamed' : 'updated', + } + ) if (updatedChat.workspaceId) { if (title !== undefined) { - chatPubSub?.publishStatusChanged({ - workspaceId: updatedChat.workspaceId, - chatId, - type: 'renamed', - }) captureServerEvent( userId, 'task_renamed', @@ -281,18 +284,15 @@ export const DELETE = withRouteHandler( ) .returning({ workspaceId: copilotChats.workspaceId, + organizationId: copilotChats.organizationId, }) if (!deletedChat) { return NextResponse.json({ success: false, error: 'Chat not found' }, { status: 404 }) } + publishChatStatusChanged({ ...deletedChat, userId }, { chatId, type: 'deleted' }) if (deletedChat.workspaceId) { - chatPubSub?.publishStatusChanged({ - workspaceId: deletedChat.workspaceId, - chatId, - type: 'deleted', - }) captureServerEvent( userId, 'task_deleted', diff --git a/apps/sim/app/api/mothership/chats/read/route.test.ts b/apps/sim/app/api/mothership/chats/read/route.test.ts index 5a67be8f8a6..b69926d7cf8 100644 --- a/apps/sim/app/api/mothership/chats/read/route.test.ts +++ b/apps/sim/app/api/mothership/chats/read/route.test.ts @@ -17,6 +17,9 @@ vi.mock('@/lib/copilot/chat/lifecycle', () => ({ getAccessibleCopilotChatAuth: mockGetAccessibleChat, })) +vi.mock('@/lib/copilot/chat-status', () => ({ publishChatStatusChanged: vi.fn() })) + +import { publishChatStatusChanged } from '@/lib/copilot/chat-status' import { POST } from '@/app/api/mothership/chats/read/route' function createRequest() { @@ -67,6 +70,22 @@ describe('POST /api/mothership/chats/read', () => { ) }) + it('broadcasts only a changed read marker, avoiding read/refetch loops', async () => { + mockGetAccessibleChat.mockResolvedValue({ + id: 'chat-1', + type: 'mothership', + organizationId: 'org-1', + userId: 'user-1', + }) + dbChainMockFns.returning.mockResolvedValueOnce([{ id: 'chat-1' }]).mockResolvedValueOnce([]) + await POST(createRequest()) + await POST(createRequest()) + expect(publishChatStatusChanged).toHaveBeenCalledExactlyOnceWith( + expect.objectContaining({ organizationId: 'org-1', userId: 'user-1' }), + { chatId: 'chat-1', type: 'updated' } + ) + }) + it('does not update a chat the caller can no longer access', async () => { mockGetAccessibleChat.mockResolvedValueOnce(null) const res = await POST(createRequest()) diff --git a/apps/sim/app/api/mothership/chats/read/route.ts b/apps/sim/app/api/mothership/chats/read/route.ts index 1c2cc149f72..8eaf98e955c 100644 --- a/apps/sim/app/api/mothership/chats/read/route.ts +++ b/apps/sim/app/api/mothership/chats/read/route.ts @@ -6,6 +6,7 @@ import { type NextRequest, NextResponse } from 'next/server' import { markMothershipChatReadContract } from '@/lib/api/contracts/mothership-chats' import { parseRequest } from '@/lib/api/server' import { getAccessibleCopilotChatAuth } from '@/lib/copilot/chat/lifecycle' +import { publishChatStatusChanged } from '@/lib/copilot/chat-status' import { authenticateCopilotRequestSessionOnly, createInternalServerErrorResponse, @@ -28,7 +29,7 @@ export const POST = withRouteHandler(async (request: NextRequest) => { const chat = await getAccessibleCopilotChatAuth(chatId, userId, { principal }) if (!chat) return NextResponse.json({ success: true }) - await db + const [updatedChat] = await db .update(copilotChats) .set({ lastSeenAt: sql`GREATEST(${copilotChats.updatedAt}, NOW())` }) .where( @@ -38,6 +39,10 @@ export const POST = withRouteHandler(async (request: NextRequest) => { or(isNull(copilotChats.lastSeenAt), lt(copilotChats.lastSeenAt, copilotChats.updatedAt)) ) ) + .returning({ id: copilotChats.id }) + if (updatedChat && chat.type === 'mothership') { + publishChatStatusChanged(chat, { chatId, type: 'updated' }) + } return NextResponse.json({ success: true }) } catch (error) { diff --git a/apps/sim/app/api/mothership/events/route.test.ts b/apps/sim/app/api/mothership/events/route.test.ts new file mode 100644 index 00000000000..e4113c188a5 --- /dev/null +++ b/apps/sim/app/api/mothership/events/route.test.ts @@ -0,0 +1,201 @@ +/** @vitest-environment node */ +import { + authMockFns, + permissionsMock, + permissionsMockFns, + resetEnvFlagsMock, + setEnvFlags, +} from '@sim/testing' +import { NextRequest } from 'next/server' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import type { ChatStatusEvent } from '@/lib/copilot/chat-status' +import { OrchestrationError } from '@/lib/core/orchestration/types' +import { HEARTBEAT_INTERVAL_MS } from '@/lib/events/sse-endpoint' +import { PermissionGroupCapabilityError } from '@/lib/permission-groups/capability-error' + +const { authorize, subscribe, unsubscribe } = vi.hoisted(() => ({ + authorize: vi.fn(), + subscribe: vi.fn(), + unsubscribe: vi.fn(), +})) +vi.mock('@/lib/copilot/chat/organization-chats', () => ({ + authorizeOrganizationChatEvents: { execute: authorize }, +})) +vi.mock('@/lib/copilot/chat-status', () => ({ chatPubSub: { onStatusChanged: subscribe } })) +vi.mock('@/lib/workspaces/permissions/utils', () => permissionsMock) + +import { GET } from '@/app/api/mothership/events/route' + +function request(query: string, signal?: AbortSignal) { + return new NextRequest(`http://localhost/api/mothership/events?${query}`, { signal }) +} + +function emit(event: ChatStatusEvent) { + const handler = subscribe.mock.calls[0][0] as (event: ChatStatusEvent) => void + handler(event) +} + +async function collect(body: ReadableStream, chunks: string[]) { + const reader = body.getReader() + const decoder = new TextDecoder() + while (true) { + const { done, value } = await reader.read() + if (done) return + chunks.push(decoder.decode(value)) + } +} + +describe('Mothership owner-scoped event stream', () => { + beforeEach(() => { + vi.clearAllMocks() + vi.useFakeTimers() + setEnvFlags({ isChatEnabled: true }) + authMockFns.mockGetSession.mockResolvedValue({ + user: { id: 'user-1' }, + session: { id: 'session-1' }, + }) + permissionsMockFns.mockGetUserEntityPermissions.mockResolvedValue('read') + authorize.mockResolvedValue({ organizationId: 'org-1', userId: 'user-1', role: 'member' }) + subscribe.mockReturnValue(unsubscribe) + }) + afterEach(() => { + vi.useRealTimers() + resetEnvFlagsMock() + }) + + it('authenticates before validating scope', async () => { + authMockFns.mockGetSession.mockResolvedValue(null) + const response = await GET(request('organizationId=org-1&workspaceId=ws-1')) + expect(response.status).toBe(401) + expect(authorize).not.toHaveBeenCalled() + expect(subscribe).not.toHaveBeenCalled() + }) + + it.each(['', 'workspaceId=', 'organizationId=', 'organizationId=org-1&workspaceId=ws-1'])( + 'refuses absent, empty, or mixed owners: %s', + async (query) => { + expect((await GET(request(query))).status).toBe(400) + expect(subscribe).not.toHaveBeenCalled() + } + ) + + it('requires chat availability', async () => { + setEnvFlags({ isChatEnabled: false }) + expect((await GET(request('organizationId=org-1'))).status).toBe(404) + expect(subscribe).not.toHaveBeenCalled() + }) + + it('refuses a non-member or disabled organization before subscribing', async () => { + authorize.mockRejectedValue(new OrchestrationError('forbidden', 'Search is not enabled')) + expect((await GET(request('organizationId=org-1'))).status).toBe(403) + expect(subscribe).not.toHaveBeenCalled() + }) + + it('maps a permission group capability refusal to 403', async () => { + authorize.mockRejectedValueOnce( + new PermissionGroupCapabilityError( + 'copilot.use', + 'PERMISSION_GROUP_CAPABILITY_BLOCKED', + 'Chat is disabled' + ) + ) + expect((await GET(request('organizationId=org-1'))).status).toBe(403) + expect(subscribe).not.toHaveBeenCalled() + }) + + it('exposes only the current user’s organization events, without owner metadata', async () => { + const abort = new AbortController() + const response = await GET(request('organizationId=org-1', abort.signal)) + expect(response.status).toBe(200) + const chunks: string[] = [] + const collected = collect(response.body!, chunks) + emit({ + organizationId: 'org-1', + userId: 'other-user', + chatId: 'hidden-user-chat', + type: 'created', + }) + emit({ organizationId: 'org-2', userId: 'user-1', chatId: 'hidden-org-chat', type: 'created' }) + emit({ workspaceId: 'ws-1', chatId: 'hidden-workspace-chat', type: 'created' }) + emit({ + organizationId: 'org-1', + userId: 'user-1', + chatId: 'visible-chat', + type: 'completed', + streamId: 'stream-1', + }) + await vi.advanceTimersByTimeAsync(0) + abort.abort() + await collected + expect(chunks).toHaveLength(1) + expect(chunks[0]).toContain('visible-chat') + expect(chunks[0]).toContain('stream-1') + expect(chunks[0]).not.toMatch(/hidden|userId|organizationId|workspaceId/) + expect(authorize).toHaveBeenCalledTimes(2) + expect(authorize).toHaveBeenLastCalledWith({ + principal: { kind: 'session', sessionId: 'session-1', userId: 'user-1' }, + input: { organizationId: 'org-1' }, + }) + expect(unsubscribe).toHaveBeenCalledTimes(1) + }) + + it('drops a pending event and closes immediately when current authorization fails', async () => { + const response = await GET(request('organizationId=org-1')) + const chunks: string[] = [] + const collected = collect(response.body!, chunks) + authorize.mockRejectedValueOnce(new OrchestrationError('not_found', 'Organization not found')) + emit({ organizationId: 'org-1', userId: 'user-1', chatId: 'revoked-chat', type: 'renamed' }) + await collected + expect(chunks).toEqual([]) + expect(unsubscribe).toHaveBeenCalledTimes(1) + }) + + it('rechecks membership and rollout while idle and releases a revoked connection', async () => { + const response = await GET(request('organizationId=org-1')) + const chunks: string[] = [] + const collected = collect(response.body!, chunks) + authorize.mockRejectedValueOnce(new OrchestrationError('forbidden', 'Search is disabled')) + await vi.advanceTimersByTimeAsync(HEARTBEAT_INTERVAL_MS) + await collected + expect(chunks).toEqual([]) + expect(unsubscribe).toHaveBeenCalledTimes(1) + }) + + it('bounds publications waiting on slow authorization and reconciles through reconnect', async () => { + const response = await GET(request('organizationId=org-1')) + const chunks: string[] = [] + const collected = collect(response.body!, chunks) + let authorizeDone: (() => void) | undefined + authorize.mockReturnValueOnce( + new Promise((resolve) => { + authorizeDone = resolve + }) + ) + for (let index = 0; index < 17; index += 1) { + emit({ organizationId: 'org-1', userId: 'user-1', chatId: `chat-${index}`, type: 'updated' }) + } + await collected + expect(unsubscribe).toHaveBeenCalledTimes(1) + expect(authorize).toHaveBeenCalledTimes(2) + authorizeDone?.() + await vi.advanceTimersByTimeAsync(0) + expect(chunks).toEqual([]) + }) + + it('preserves workspace status events and excludes organization events', async () => { + const abort = new AbortController() + const response = await GET(request('workspaceId=ws-1', abort.signal)) + const chunks: string[] = [] + const collected = collect(response.body!, chunks) + emit({ organizationId: 'org-1', userId: 'user-1', chatId: 'org-chat', type: 'created' }) + emit({ workspaceId: 'ws-2', chatId: 'other-workspace-chat', type: 'created' }) + emit({ workspaceId: 'ws-1', chatId: 'workspace-chat', type: 'renamed' }) + abort.abort() + await collected + expect(chunks).toHaveLength(1) + expect(chunks[0]).toContain('workspace-chat') + expect(chunks[0]).not.toMatch(/org-chat|other-workspace-chat/) + expect(authorize).not.toHaveBeenCalled() + expect(authMockFns.mockGetSession).toHaveBeenCalledTimes(1) + }) +}) diff --git a/apps/sim/app/api/mothership/events/route.ts b/apps/sim/app/api/mothership/events/route.ts index c942c825665..c39f4068fc8 100644 --- a/apps/sim/app/api/mothership/events/route.ts +++ b/apps/sim/app/api/mothership/events/route.ts @@ -7,16 +7,25 @@ * Auth is handled via session cookies (EventSource sends cookies automatically). */ +import { createLogger } from '@sim/logger' import type { NextRequest } from 'next/server' import { mothershipEventsQuerySchema } from '@/lib/api/contracts/mothership-chats' import { validationErrorResponse } from '@/lib/api/server' +import { + InternalUnauthenticatedError, + internalSessionAuth, +} from '@/lib/api/server/routes/internal-json-route' +import { authorizeOrganizationChatEvents } from '@/lib/copilot/chat/organization-chats' import { chatPubSub } from '@/lib/copilot/chat-status' import { isChatEnabled } from '@/lib/core/config/env-flags' +import { asOrchestrationError } from '@/lib/core/orchestration/types' import { withRouteHandler } from '@/lib/core/utils/with-route-handler' -import { createWorkspaceSSE } from '@/lib/events/sse-endpoint' +import { createSSEStream, createWorkspaceSSE } from '@/lib/events/sse-endpoint' export const dynamic = 'force-dynamic' +const logger = createLogger('MothershipEvents') + const mothershipEventsHandler = createWorkspaceSSE({ label: 'mothership-events', subscriptions: [ @@ -37,14 +46,50 @@ const mothershipEventsHandler = createWorkspaceSSE({ ], }) -export const GET = withRouteHandler((request: NextRequest) => { +export const GET = withRouteHandler(async (request: NextRequest) => { // Closes streams held by tabs that were open when Chat was turned off; the // client hook already declines to open new ones. if (!isChatEnabled) return new Response(null, { status: 404 }) - const validation = mothershipEventsQuerySchema.safeParse( - Object.fromEntries(request.nextUrl.searchParams.entries()) - ) - if (!validation.success) return validationErrorResponse(validation.error) - return mothershipEventsHandler(request) + try { + const principal = await internalSessionAuth.authenticate() + const validation = mothershipEventsQuerySchema.safeParse( + Object.fromEntries(request.nextUrl.searchParams.entries()) + ) + if (!validation.success) return validationErrorResponse(validation.error) + const { organizationId } = validation.data + if (!organizationId) return mothershipEventsHandler(request, principal) + + const revalidate = async () => { + await authorizeOrganizationChatEvents.execute({ principal, input: { organizationId } }) + } + await revalidate() + return createSSEStream(request, { + label: 'mothership-organization-events', + revalidate, + subscriptions: [ + { + subscribe: (send) => + chatPubSub?.onStatusChanged((event) => { + if (event.organizationId !== organizationId || event.userId !== principal.userId) + return + send('task_status', { + chatId: event.chatId, + type: event.type, + ...(event.streamId ? { streamId: event.streamId } : {}), + timestamp: Date.now(), + }) + }) ?? (() => {}), + }, + ], + }) + } catch (error) { + const code = asOrchestrationError(error)?.code + if (code === 'not_found' || code === 'forbidden') + return new Response('Organization access denied', { status: 403 }) + if (error instanceof InternalUnauthenticatedError) + return new Response('Unauthorized', { status: 401 }) + logger.error('Failed to subscribe to organization chats', error) + return new Response('Unable to subscribe to chats', { status: 500 }) + } }) diff --git a/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/chats-section/chats-section.test.tsx b/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/chats-section/chats-section.test.tsx index e68e55f599c..8e7d8d53d0d 100644 --- a/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/chats-section/chats-section.test.tsx +++ b/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/chats-section/chats-section.test.tsx @@ -2,6 +2,8 @@ * @vitest-environment jsdom */ import { act } from 'react' +import { ToastProvider } from '@sim/emcn' +import { sleep } from '@sim/utils/helpers' import { QueryClient, QueryClientProvider } from '@tanstack/react-query' import { createRoot, type Root } from 'react-dom/client' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' @@ -9,6 +11,12 @@ import type { OrganizationChat } from '@/app/o/[organizationId]/components/organ const hoverState = vi.hoisted(() => ({ isOpen: false })) const mockRequestJson = vi.hoisted(() => vi.fn()) +const mockPush = vi.hoisted(() => vi.fn()) + +vi.mock('next/navigation', () => ({ + useRouter: () => ({ push: mockPush }), + usePathname: () => window.location.pathname, +})) vi.mock('@/lib/api/client/request', () => ({ requestJson: mockRequestJson })) @@ -64,7 +72,8 @@ beforeEach(() => { } ) vi.clearAllMocks() - mockRequestJson.mockResolvedValue({ success: true }) + mockRequestJson.mockReset().mockResolvedValue({ success: true }) + window.history.replaceState(null, '', '/o/org-1/home') hoverState.isOpen = false queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } }) prefetchQuery = vi.spyOn(queryClient, 'prefetchQuery').mockResolvedValue() @@ -84,14 +93,16 @@ async function render(props: Partial[0]> = {}) { await act(async () => { root.render( - + + + ) }) @@ -239,6 +250,114 @@ describe('ChatsSection', () => { expect(prefetchQuery).not.toHaveBeenCalled() }) + async function openDelete(isCollapsed = false) { + hoverState.isOpen = isCollapsed + await render({ isCollapsed }) + const options = document.body.querySelector('[aria-label="Chat options"]')! + await act(async () => options.click()) + const action = Array.from( + document.body.querySelectorAll('[role="menuitem"]') + ).find((item) => item.textContent === 'Delete')! + expect(action).toBeDefined() + await act(async () => action.click()) + expect(document.body.querySelector('[role="dialog"]')?.textContent).toContain('Chat 1') + expect(mockRequestJson).not.toHaveBeenCalled() + } + + function modalButton(label: string) { + return Array.from( + document.body.querySelectorAll('[role="dialog"] button') + ).find((button) => button.textContent === label)! + } + + it.each([false, true])( + 'cancels deletion without a request with collapsed=%s', + async (isCollapsed) => { + await openDelete(isCollapsed) + await act(async () => modalButton('Cancel').click()) + expect(document.body.querySelector('[role="dialog"]')).toBeNull() + expect(mockRequestJson).not.toHaveBeenCalled() + expect(mockPush).not.toHaveBeenCalled() + } + ) + + it.each([false, true])( + 'deletes through the shared contract with collapsed=%s', + async (isCollapsed) => { + const invalidate = vi.spyOn(queryClient, 'invalidateQueries') + await openDelete(isCollapsed) + await act(async () => modalButton('Delete').click()) + expect(mockRequestJson).toHaveBeenCalledWith(expect.objectContaining({ method: 'DELETE' }), { + params: { chatId: 'chat-1' }, + }) + expect(invalidate).toHaveBeenCalledWith({ + queryKey: mothershipChatKeys.organizationLists('org-1'), + }) + expect(invalidate).not.toHaveBeenCalledWith({ + queryKey: mothershipChatKeys.workspaceLists('org-1'), + }) + expect(document.body.querySelector('[role="dialog"]')).toBeNull() + expect(mockPush).not.toHaveBeenCalled() + } + ) + + it('cancels delete confirmation with Escape without changing chats', async () => { + await openDelete() + await act(async () => { + document.body + .querySelector('[role="dialog"]')! + .dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true })) + }) + expect(document.body.querySelector('[role="dialog"]')).toBeNull() + expect(mockRequestJson).not.toHaveBeenCalled() + expect(mockPush).not.toHaveBeenCalled() + }) + + it('returns home when the deleted chat is still open', async () => { + await openDelete() + window.history.replaceState(null, '', CHATS[0].href) + await act(async () => modalButton('Delete').click()) + expect(mockPush).toHaveBeenCalledWith('/o/org-1/home') + }) + + it('keeps confirmation pending and does not override navigation after a slow delete', async () => { + const pending = Promise.withResolvers<{ success: boolean }>() + await openDelete() + mockRequestJson.mockReturnValueOnce(pending.promise) + window.history.replaceState(null, '', CHATS[0].href) + await act(async () => modalButton('Delete').click()) + await act(async () => sleep(1)) + expect(modalButton('Deleting...').disabled).toBe(true) + expect(modalButton('Cancel').disabled).toBe(true) + await act(async () => { + document.body + .querySelector('[role="dialog"]')! + .dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true })) + }) + expect(document.body.querySelector('[role="dialog"]')).not.toBeNull() + expect(mockPush).not.toHaveBeenCalled() + window.history.replaceState(null, '', CHATS[1].href) + await act(async () => pending.resolve({ success: true })) + expect(mockPush).not.toHaveBeenCalled() + expect(document.body.querySelector('[role="dialog"]')).toBeNull() + }) + + it('keeps the chat and confirmation available for retry after a failed delete', async () => { + await openDelete() + mockRequestJson.mockRejectedValueOnce(new Error('Delete rejected')) + window.history.replaceState(null, '', CHATS[0].href) + const key = mothershipChatKeys.detail('chat-1') + queryClient.setQueryData(key, { id: 'chat-1', messages: ['Preserved'] }) + await act(async () => modalButton('Delete').click()) + expect(mockPush).not.toHaveBeenCalled() + expect(document.body.querySelector('[role="dialog"]')).not.toBeNull() + expect(modalButton('Delete').disabled).toBe(false) + expect(queryClient.getQueryData(key)).toEqual({ id: 'chat-1', messages: ['Preserved'] }) + await act(async () => modalButton('Delete').click()) + expect(mockPush).toHaveBeenCalledWith('/o/org-1/home') + expect(document.body.querySelector('[role="dialog"]')).toBeNull() + }) + it('shows the empty state when there are no chats', async () => { await render({ chats: [] }) expect(container.textContent).toContain('No chats yet') diff --git a/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/chats-section/chats-section.tsx b/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/chats-section/chats-section.tsx index df2b36b4aa9..dbd855226ef 100644 --- a/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/chats-section/chats-section.tsx +++ b/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/chats-section/chats-section.tsx @@ -19,6 +19,7 @@ import { SidebarSection, } from '@/app/workspace/[workspaceId]/w/components/sidebar/components' import { ContextMenu } from '@/app/workspace/[workspaceId]/w/components/sidebar/components/workflow-list/components/context-menu/context-menu' +import { DeleteModal } from '@/app/workspace/[workspaceId]/w/components/sidebar/components/workflow-list/components/delete-modal/delete-modal' import { SIDEBAR_ITEM_GAP_CLASS, SIDEBAR_SECTION_GAP_CLASS, @@ -233,9 +234,18 @@ export function ChatsSection({ isPinned={Boolean(selectedChat?.isPinned)} showMarkAsRead={Boolean(selectedChat?.isUnread)} showMarkAsUnread={Boolean(selectedChat) && !selectedChat?.isUnread} - showDelete={false} + onDelete={actions.startDelete} + showDelete={Boolean(selectedChat)} showDuplicate={false} /> + ) } diff --git a/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/index.ts b/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/index.ts index 525cf120d1d..c7f48483337 100644 --- a/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/index.ts +++ b/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/index.ts @@ -1,5 +1,4 @@ export { ChatsSection } from './chats-section' export { OrganizationFooter } from './organization-footer' export { OrganizationHeader } from './organization-header' -export { WorkspacesRailFlyout } from './workspaces-rail-flyout' export { WorkspacesSection } from './workspaces-section' diff --git a/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/organization-footer/organization-footer.test.tsx b/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/organization-footer/organization-footer.test.tsx new file mode 100644 index 00000000000..8a39e94a9fe --- /dev/null +++ b/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/organization-footer/organization-footer.test.tsx @@ -0,0 +1,130 @@ +/** + * @vitest-environment jsdom + */ +import { act, type ComponentProps } from 'react' +import { createRoot, type Root } from 'react-dom/client' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' + +const { mockNavigate, mockPush } = vi.hoisted(() => ({ + mockNavigate: vi.fn(), + mockPush: vi.fn(), +})) + +vi.mock('next/navigation', () => ({ + useRouter: () => ({ push: mockPush }), +})) +vi.mock('next/link', () => ({ + default: ({ + onNavigate, + ...props + }: ComponentProps<'a'> & { onNavigate?: (event: { preventDefault: () => void }) => void }) => ( + { + event.preventDefault() + let prevented = false + onNavigate?.({ + preventDefault: () => { + prevented = true + }, + }) + if (!prevented) mockNavigate(props.href) + }} + /> + ), +})) +vi.mock('@/lib/desktop', () => ({ getDesktopUpdates: () => null })) +vi.mock('@/hooks/use-desktop-update-state', () => ({ + useDesktopUpdateState: () => ({ status: 'idle' }), +})) +vi.mock('@/hooks/queries/user-profile', () => ({ + useUserProfile: () => ({ data: { id: 'user-1', name: 'Ada', email: 'ada@example.com' } }), +})) +vi.mock('@/app/o/[organizationId]/providers/organization-provider', () => ({ + useOrganizationContext: () => ({ organization: { id: 'org-1' } }), +})) +vi.mock('@/app/workspace/[workspaceId]/w/components/sidebar/components', () => ({ + SidebarTooltip: ({ children }: { children: React.ReactNode }) => children, +})) +vi.mock('@/components/icons', () => ({ SlackIcon: () => })) + +import { OrganizationFooter } from '@/app/o/[organizationId]/components/organization-sidebar/components/organization-footer/organization-footer' +import { useSettingsDirtyStore } from '@/stores/settings/dirty/store' + +let container: HTMLDivElement +let root: Root + +beforeEach(() => { + vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true) + vi.clearAllMocks() + useSettingsDirtyStore.getState().reset() + container = document.createElement('div') + document.body.appendChild(container) + root = createRoot(container) +}) + +afterEach(async () => { + await act(async () => root.unmount()) + container.remove() + useSettingsDirtyStore.getState().reset() + vi.unstubAllGlobals() +}) + +async function selectSettings() { + await act(async () => { + root.render( + {}} + onJoinSlack={() => {}} + /> + ) + }) + const trigger = container.querySelector('[data-item-id="profile"]') + if (!trigger) throw new Error('Profile menu is missing') + await act(async () => { + trigger.dispatchEvent(new MouseEvent('pointerdown', { bubbles: true, button: 0 })) + }) + const link = document.querySelector('a[href="/o/org-1/settings/general"]') + if (!link) throw new Error('Settings link is missing') + await act(async () => link.click()) +} + +describe('OrganizationFooter settings navigation', () => { + it('navigates immediately when settings are clean', async () => { + await selectSettings() + expect(mockNavigate).toHaveBeenCalledWith('/o/org-1/settings/general') + expect(useSettingsDirtyStore.getState().pendingLeave).toBeNull() + }) + + it('waits for discard confirmation before leaving a dirty form', async () => { + useSettingsDirtyStore.getState().setDirty(true) + await selectSettings() + expect(mockNavigate).not.toHaveBeenCalled() + expect(mockPush).not.toHaveBeenCalled() + expect(useSettingsDirtyStore.getState().pendingLeave).not.toBeNull() + + act(() => useSettingsDirtyStore.getState().confirmLeave()) + expect(mockPush).toHaveBeenCalledWith('/o/org-1/settings/general') + }) + + it('keeps the draft when leaving is cancelled', async () => { + useSettingsDirtyStore.getState().setDirty(true) + await selectSettings() + act(() => useSettingsDirtyStore.getState().cancelLeave()) + expect(mockNavigate).not.toHaveBeenCalled() + expect(mockPush).not.toHaveBeenCalled() + expect(useSettingsDirtyStore.getState().isDirty).toBe(true) + }) + + it('blocks navigation while saving without queuing a later redirect', async () => { + useSettingsDirtyStore.getState().setNavigationBlocked(true) + await selectSettings() + expect(mockNavigate).not.toHaveBeenCalled() + expect(mockPush).not.toHaveBeenCalled() + expect(useSettingsDirtyStore.getState().pendingLeave).toBeNull() + }) +}) diff --git a/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/organization-footer/organization-footer.tsx b/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/organization-footer/organization-footer.tsx index 3abcc00a6f2..ecc37a12e01 100644 --- a/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/organization-footer/organization-footer.tsx +++ b/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/organization-footer/organization-footer.tsx @@ -17,8 +17,8 @@ import { Skeleton, } from '@sim/emcn' import { BookOpen, Download, HelpCircle, Settings } from '@sim/emcn/icons' -import Link from 'next/link' import { SlackIcon } from '@/components/icons' +import { SettingsGuardedLink } from '@/components/settings/settings-guarded-link' import { getDesktopUpdates } from '@/lib/desktop' import { organizationRoutes } from '@/lib/navigation/paths' import { getUserColor } from '@/lib/workspaces/colors' @@ -166,10 +166,12 @@ export function OrganizationFooter({ - + - + @@ -233,7 +235,7 @@ export function OrganizationFooter({ {/* Expanded, claims the row's free width so the help button lands hard right. `flex` makes the inline-flex chip a flex item, so the wrapper is exactly the chip's 30px rather than a line box padded by the strut's half-leading. */} -
{profileMenu}
+
{profileMenu}
{helpMenu}
) diff --git a/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/workspaces-rail-flyout/index.ts b/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/workspaces-rail-flyout/index.ts deleted file mode 100644 index fe0024ab47c..00000000000 --- a/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/workspaces-rail-flyout/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { WorkspacesRailFlyout } from './workspaces-rail-flyout' diff --git a/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/workspaces-rail-flyout/workspaces-rail-flyout.test.tsx b/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/workspaces-rail-flyout/workspaces-rail-flyout.test.tsx deleted file mode 100644 index b6729ecbf07..00000000000 --- a/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/workspaces-rail-flyout/workspaces-rail-flyout.test.tsx +++ /dev/null @@ -1,97 +0,0 @@ -/** - * @vitest-environment jsdom - */ -import { act } from 'react' -import { createRoot, type Root } from 'react-dom/client' -import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' - -const workspacesState = vi.hoisted(() => ({ - workspaces: [] as { id: string; name: string }[], - isLoading: false, -})) - -vi.mock('next/link', () => ({ - default: ({ href, children, ...props }: { href: string; children: React.ReactNode }) => ( - - {children} - - ), -})) -vi.mock('@/app/o/[organizationId]/components/organization-sidebar/hooks', () => ({ - useOrganizationWorkspaces: () => workspacesState, -})) -vi.mock( - '@/app/workspace/[workspaceId]/w/components/sidebar/components/collapsed-sidebar-menu', - () => ({ - CollapsedResourceFlyout: ({ - entries, - isLoading, - emptyLabel, - }: { - entries: { id: string; name: string; href: string }[] - isLoading: boolean - emptyLabel: string - }) => - isLoading ? ( - Loading... - ) : entries.length === 0 ? ( - {emptyLabel} - ) : ( - entries.map((entry) => ( - - {entry.name} - - )) - ), - }) -) - -import { WorkspacesRailFlyout } from '@/app/o/[organizationId]/components/organization-sidebar/components/workspaces-rail-flyout/workspaces-rail-flyout' - -let container: HTMLDivElement -let root: Root - -beforeEach(() => { - ;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true - workspacesState.workspaces = [] - workspacesState.isLoading = false - container = document.createElement('div') - document.body.appendChild(container) - root = createRoot(container) -}) - -afterEach(async () => { - await act(async () => root.unmount()) - container.remove() -}) - -async function render() { - await act(async () => { - root.render() - }) -} - -describe('WorkspacesRailFlyout', () => { - it('lists every workspace as a link into it', async () => { - workspacesState.workspaces = [ - { id: 'ws-1', name: 'Design' }, - { id: 'ws-2', name: 'Ops' }, - ] - await render() - - const links = Array.from(container.querySelectorAll('a')).map((a) => a.getAttribute('href')) - expect(links).toEqual(['/workspace/ws-1', '/workspace/ws-2']) - expect(container.textContent).toContain('Design') - }) - - it('shows the empty label when the organization has no workspaces', async () => { - await render() - expect(container.textContent).toContain('No workspaces yet') - }) - - it('shows the loading row while the list resolves', async () => { - workspacesState.isLoading = true - await render() - expect(container.textContent).toContain('Loading...') - }) -}) diff --git a/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/workspaces-rail-flyout/workspaces-rail-flyout.tsx b/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/workspaces-rail-flyout/workspaces-rail-flyout.tsx deleted file mode 100644 index b36e478cf14..00000000000 --- a/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/workspaces-rail-flyout/workspaces-rail-flyout.tsx +++ /dev/null @@ -1,35 +0,0 @@ -'use client' - -import { useOrganizationWorkspaces } from '@/app/o/[organizationId]/components/organization-sidebar/hooks' -import type { FlyoutEntry } from '@/app/workspace/[workspaceId]/components/folders' -import { CollapsedResourceFlyout } from '@/app/workspace/[workspaceId]/w/components/sidebar/components/collapsed-sidebar-menu' - -interface WorkspacesRailFlyoutProps { - organizationId: string -} - -/** - * Rail flyout body for the Workspaces tab: a jump list of the organization's - * workspaces, one row each, the way the workspace sidebar's Tables and Files tabs - * list theirs. Mounts only while the rail menu is open, so the workspace query - * runs only when someone hovers the chip. - */ -export function WorkspacesRailFlyout({ organizationId }: WorkspacesRailFlyoutProps) { - const { workspaces, isLoading } = useOrganizationWorkspaces(organizationId) - - const entries: FlyoutEntry[] = workspaces.map((workspace) => ({ - kind: 'item', - id: workspace.id, - name: workspace.name, - pinned: false, - href: `/workspace/${workspace.id}`, - })) - - return ( - - ) -} diff --git a/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/workspaces-section/workspace-list.test.tsx b/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/workspaces-section/workspace-list.test.tsx new file mode 100644 index 00000000000..30c9f787fd9 --- /dev/null +++ b/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/workspaces-section/workspace-list.test.tsx @@ -0,0 +1,116 @@ +/** + * @vitest-environment jsdom + */ +import { act } from 'react' +import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from '@sim/emcn' +import { createRoot, type Root } from 'react-dom/client' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' + +const workspacesState = vi.hoisted(() => ({ + workspaces: [] as { id: string; name: string }[], + isLoading: false, + pinnedWorkspaceIds: new Set(), +})) + +vi.mock('next/link', () => ({ + default: ({ + href, + children, + onNavigate: _onNavigate, + ...props + }: { + href: string + children: React.ReactNode + onNavigate?: () => void + }) => ( + + {children} + + ), +})) +vi.mock( + '@/app/o/[organizationId]/components/organization-sidebar/hooks/use-organization-workspaces', + () => ({ + useOrganizationWorkspaces: () => workspacesState, + }) +) + +vi.mock('next/navigation', () => ({ + usePathname: () => '/o/org-1/home', + useRouter: () => ({ push: vi.fn() }), +})) +vi.mock('@/hooks/queries/workspace', () => ({ + useUpdateWorkspace: () => ({ mutateAsync: vi.fn() }), + useToggleWorkspacePin: () => ({ mutate: vi.fn() }), +})) + +import { WorkspaceList } from '@/app/o/[organizationId]/components/organization-sidebar/components/workspaces-section/workspace-list' + +let container: HTMLDivElement +let root: Root + +beforeEach(() => { + ;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true + workspacesState.workspaces = [] + workspacesState.isLoading = false + container = document.createElement('div') + document.body.appendChild(container) + root = createRoot(container) +}) + +afterEach(async () => { + await act(async () => root.unmount()) + container.remove() +}) + +async function render() { + await act(async () => { + root.render( + + Workspaces + + + + + ) + }) +} + +describe('WorkspaceList rail view', () => { + it('lists every workspace as a link into it', async () => { + workspacesState.workspaces = [ + { id: 'ws-1', name: 'Design' }, + { id: 'ws-2', name: 'Ops' }, + ] + await render() + + const links = Array.from(document.querySelectorAll('a')).map((a) => a.getAttribute('href')) + expect(links).toEqual(['/workspace/ws-1', '/workspace/ws-2']) + expect(document.body.textContent).toContain('Design') + }) + + it('shows the empty label when the organization has no workspaces', async () => { + await render() + expect(document.body.textContent).toContain('No workspaces yet') + }) + + it('shows the loading row while the list resolves', async () => { + workspacesState.isLoading = true + await render() + expect(document.body.textContent).toContain('Loading...') + }) +}) diff --git a/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/workspaces-section/workspace-list.tsx b/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/workspaces-section/workspace-list.tsx new file mode 100644 index 00000000000..efb0d956cf1 --- /dev/null +++ b/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/workspaces-section/workspace-list.tsx @@ -0,0 +1,256 @@ +'use client' + +import { useEffect, useState } from 'react' +import { + ChipInput, + chipVariants, + cn, + DropdownMenuItem, + DropdownMenuItemAction, + Loader, + OverflowText, + toast, +} from '@sim/emcn' +import { MoreHorizontal, Pin, Search } from '@sim/emcn/icons' +import { getErrorMessage } from '@sim/utils/errors' +import { IdentityTile } from '@/components/identity-tile/identity-tile' +import { SettingsGuardedLink } from '@/components/settings/settings-guarded-link' +import { WorkspaceContextMenu } from '@/components/workspaces/workspace-context-menu' +import { WORKSPACE_SEARCH_THRESHOLD } from '@/lib/workspaces/constants' +import { getWorkspaceInitial } from '@/lib/workspaces/initials' +import { useOrganizationWorkspaces } from '@/app/o/[organizationId]/components/organization-sidebar/hooks/use-organization-workspaces' +import { useFlyoutInlineRename } from '@/app/workspace/[workspaceId]/w/components/sidebar/hooks/use-flyout-inline-rename' +import type { useHoverMenu } from '@/app/workspace/[workspaceId]/w/components/sidebar/hooks/use-hover-menu' +import { useToggleWorkspacePin, useUpdateWorkspace } from '@/hooks/queries/workspace' +import { useContextMenu } from '@/hooks/use-context-menu' + +const PAGE_SIZE = 5 + +interface WorkspaceListProps { + organizationId: string + pathname?: string | null + /** The rail flyout uses the same actions and ordering as the expanded list. */ + flyout?: ReturnType +} + +export function WorkspaceList({ organizationId, pathname, flyout }: WorkspaceListProps) { + const { workspaces, pinnedWorkspaceIds, isLoading } = useOrganizationWorkspaces(organizationId) + const { mutate: togglePin } = useToggleWorkspacePin() + const { mutateAsync: updateWorkspace } = useUpdateWorkspace() + const menu = useContextMenu() + const [selectedId, setSelectedId] = useState(null) + const [search, setSearch] = useState('') + const [visibleCount, setVisibleCount] = useState(PAGE_SIZE) + const selectedWorkspace = workspaces.find((workspace) => workspace.id === selectedId) + const rename = useFlyoutInlineRename({ + itemType: 'workspace', + onSave: async (workspaceId, name) => { + try { + await updateWorkspace({ workspaceId, name }) + } catch (error) { + toast.error(getErrorMessage(error, 'Failed to rename workspace')) + throw error + } + }, + }) + const lockFlyout = flyout?.setLocked + + useEffect(() => { + lockFlyout?.(menu.isOpen || rename.editingId !== null) + return () => lockFlyout?.(false) + }, [lockFlyout, menu.isOpen, rename.editingId]) + + const showSearch = workspaces.length >= WORKSPACE_SEARCH_THRESHOLD + const query = showSearch ? search.trim().toLowerCase() : '' + const filteredWorkspaces = query + ? workspaces.filter((workspace) => workspace.name.toLowerCase().includes(query)) + : workspaces + const visibleWorkspaces = + flyout || query ? filteredWorkspaces : filteredWorkspaces.slice(0, visibleCount) + const hasMore = workspaces.length > visibleCount + + const openMenu = (event: React.MouseEvent, workspaceId: string) => { + setSelectedId(workspaceId) + flyout?.setLocked(true) + menu.preventDismiss() + menu.handleContextMenu(event) + } + + return ( + <> + {showSearch && ( + setSearch(event.target.value)} + onKeyDown={(event) => event.stopPropagation()} + className='mb-1.5' + /> + )} + {isLoading && flyout && ( + + + Loading... + + )} + {!isLoading && filteredWorkspaces.length === 0 && ( +
+ {query ? 'No matching workspaces' : 'No workspaces yet'} +
+ )} + {visibleWorkspaces.map((workspace) => { + const href = `/workspace/${workspace.id}` + const isActive = pathname === href || Boolean(pathname?.startsWith(`${href}/`)) + const isMenuOpen = menu.isOpen && selectedId === workspace.id + const isPinned = pinnedWorkspaceIds.has(workspace.id) + const label = ( + <> + + + + ) + const onMoreClick = (event: React.MouseEvent) => { + event.preventDefault() + event.stopPropagation() + if (isMenuOpen) { + menu.closeMenu() + return + } + setSelectedId(workspace.id) + flyout?.setLocked(true) + const rect = event.currentTarget.getBoundingClientRect() + menu.openMenuAt({ x: rect.right, y: rect.top }) + } + + if (rename.editingId === workspace.id) { + return ( + rename.setValue(event.target.value)} + onKeyDown={(event) => { + event.stopPropagation() + rename.handleKeyDown(event) + }} + onBlur={() => void rename.saveRename()} + disabled={rename.isSaving} + maxLength={100} + /> + ) + } + + if (flyout) { + return ( + { + if (menu.isOpen || rename.editingId) event.preventDefault() + }} + action={ + menu.preventDismiss()} + onClick={onMoreClick} + > + + + } + > + openMenu(event, workspace.id)} + > + {label} + {isPinned && } + + + ) + } + + return ( + openMenu(event, workspace.id)} + > + {label} +
+ {isPinned && ( + + )} + +
+
+ ) + })} + {!flyout && !query && workspaces.length > PAGE_SIZE && ( + + )} + { + if (selectedWorkspace) + window.open(`/workspace/${selectedWorkspace.id}`, '_blank', 'noopener,noreferrer') + }} + onRename={() => { + if (selectedWorkspace?.permissions === 'admin') rename.startRename(selectedWorkspace) + }} + isPinned={Boolean(selectedId && pinnedWorkspaceIds.has(selectedId))} + onTogglePin={() => { + if (selectedWorkspace) { + togglePin( + { + workspaceId: selectedWorkspace.id, + pinned: !pinnedWorkspaceIds.has(selectedWorkspace.id), + }, + { onError: (error) => toast.error(error.message) } + ) + } + }} + /> + + ) +} diff --git a/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/workspaces-section/workspaces-section.test.tsx b/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/workspaces-section/workspaces-section.test.tsx index 7505e56a100..4fa737cb46c 100644 --- a/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/workspaces-section/workspaces-section.test.tsx +++ b/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/workspaces-section/workspaces-section.test.tsx @@ -7,18 +7,34 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' const state = vi.hoisted(() => ({ isOpen: false, - workspaces: [] as { id: string; name: string; logoUrl: null }[], + workspaces: [] as { id: string; name: string; logoUrl: null; permissions: string }[], + pins: new Set(), + canCreate: true, + createOrganizationId: 'org-1', + mockCreate: vi.fn(), + mockRename: vi.fn(), + mockPin: vi.fn(), + mockPush: vi.fn(), isLoading: false, })) vi.mock('next/link', () => ({ - default: ({ href, children, ...props }: { href: string; children: React.ReactNode }) => ( + default: ({ + href, + children, + onNavigate: _onNavigate, + ...props + }: { + href: string + children: React.ReactNode + onNavigate?: () => void + }) => ( {children} ), })) -vi.mock('@/app/workspace/[workspaceId]/w/components/sidebar/hooks', () => ({ +vi.mock('@/app/workspace/[workspaceId]/w/components/sidebar/hooks/use-hover-menu', () => ({ useHoverMenu: () => ({ isOpen: state.isOpen, open: vi.fn(), @@ -28,8 +44,32 @@ vi.mock('@/app/workspace/[workspaceId]/w/components/sidebar/hooks', () => ({ contentProps: { onMouseEnter: vi.fn(), onMouseLeave: vi.fn(), onCloseAutoFocus: vi.fn() }, }), })) -vi.mock('@/app/o/[organizationId]/components/organization-sidebar/hooks', () => ({ - useOrganizationWorkspaces: () => ({ workspaces: state.workspaces, isLoading: state.isLoading }), +vi.mock( + '@/app/o/[organizationId]/components/organization-sidebar/hooks/use-organization-workspaces', + () => ({ + useOrganizationWorkspaces: () => ({ + workspaces: state.workspaces, + pinnedWorkspaceIds: state.pins, + isLoading: state.isLoading, + }), + }) +) + +vi.mock('next/navigation', () => ({ + usePathname: () => '/o/org-1/home', + useRouter: () => ({ push: state.mockPush }), +})) +vi.mock('@/hooks/queries/workspace', () => ({ + useUpdateWorkspace: () => ({ mutateAsync: state.mockRename }), + useToggleWorkspacePin: () => ({ mutate: state.mockPin }), + useCreateWorkspace: () => ({ mutateAsync: state.mockCreate, isPending: false }), + useWorkspaceCreationPolicy: () => ({ + data: { + canCreate: state.canCreate, + organizationId: state.createOrganizationId, + reason: 'Workspace limit reached', + }, + }), })) import { WorkspacesSection } from '@/app/o/[organizationId]/components/organization-sidebar/components/workspaces-section/workspaces-section' @@ -47,12 +87,19 @@ beforeEach(() => { disconnect() {} } ) + vi.clearAllMocks() + state.canCreate = true + state.createOrganizationId = 'org-1' + state.pins.clear() + state.mockCreate.mockResolvedValue({ id: 'ws-new' }) + state.mockRename.mockResolvedValue({}) state.isOpen = false state.isLoading = false state.workspaces = Array.from({ length: 8 }, (_, index) => ({ id: `ws-${index + 1}`, name: `Workspace ${index + 1}`, logoUrl: null, + permissions: 'admin', })) container = document.createElement('div') document.body.appendChild(container) @@ -68,13 +115,7 @@ afterEach(async () => { async function render(props: Partial[0]> = {}) { await act(async () => { root.render( - {}} - {...props} - /> + ) }) } @@ -136,4 +177,98 @@ describe('WorkspacesSection', () => { await render({ isCollapsed: true }) expect(container.querySelector('[aria-label="Workspaces"]')).not.toBeNull() }) + it('searches all workspaces, including those beyond the first page', async () => { + await render() + await act(async () => typeInto(container.querySelector('input')!, 'Workspace 8')) + expect(rows()).toHaveLength(1) + expect(rows()[0].textContent).toContain('Workspace 8') + expect(pager()).toBeUndefined() + await act(async () => typeInto(container.querySelector('input')!, '')) + expect(rows()).toHaveLength(5) + }) + + it('uses the shared pin mutation and permission-aware rename action', async () => { + await render() + await act(async () => + container.querySelector('[aria-label="Options for Workspace 1"]')?.click() + ) + const pin = Array.from(document.querySelectorAll('[role="menuitem"]')).find( + (item) => item.textContent === 'Pin' + ) + expect(pin).toBeDefined() + await act(async () => pin?.click()) + expect(state.mockPin).toHaveBeenCalledWith( + { workspaceId: 'ws-1', pinned: true }, + expect.any(Object) + ) + await act(async () => + container.querySelector('[aria-label="Options for Workspace 1"]')?.click() + ) + const rename = Array.from(document.querySelectorAll('[role="menuitem"]')).find( + (item) => item.textContent === 'Rename' + ) + await act(async () => rename?.click()) + const input = container.querySelector( + '[aria-label="Rename workspace Workspace 1"]' + )! + expect(input).not.toBeNull() + await act(async () => typeInto(input, 'Renamed workspace')) + await act(async () => + input.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true })) + ) + expect(state.mockRename).toHaveBeenCalledWith({ + workspaceId: 'ws-1', + name: 'Renamed workspace', + }) + }) + + it('prevents a read-only viewer from renaming while retaining pinning', async () => { + state.workspaces[0].permissions = 'read' + await render() + await act(async () => + container.querySelector('[aria-label="Options for Workspace 1"]')?.click() + ) + const rename = Array.from(document.querySelectorAll('[role="menuitem"]')).find( + (item) => item.textContent === 'Rename' + ) + expect(rename?.getAttribute('aria-disabled')).toBe('true') + await act(async () => rename?.click()) + expect(container.querySelector('[aria-label="Rename workspace Workspace 1"]')).toBeNull() + expect(state.mockRename).not.toHaveBeenCalled() + }) + + it('creates in the current organization through the existing modal and mutation', async () => { + await render() + await act(async () => + container.querySelector('[aria-label="New workspace"]')?.click() + ) + const input = document.querySelector('input[placeholder="Workspace name"]')! + expect(input).not.toBeNull() + await act(async () => typeInto(input, 'New team workspace')) + const create = Array.from(document.querySelectorAll('button')).find( + (button) => button.textContent === 'Create' + ) + await act(async () => create?.click()) + expect(state.mockCreate).toHaveBeenCalledWith({ name: 'New team workspace' }) + expect(state.mockPush).toHaveBeenCalledWith('/workspace/ws-new') + }) + + it.each([false, true])( + 'respects creation policy and never creates in a different organization (allowed=%s)', + async (allowed) => { + state.canCreate = allowed + state.createOrganizationId = allowed ? 'another-org' : 'org-1' + await render() + const create = container.querySelector('[aria-label="New workspace"]')! + expect(create.disabled).toBe(true) + await act(async () => create.click()) + expect(document.querySelector('input[placeholder="Workspace name"]')).toBeNull() + expect(state.mockCreate).not.toHaveBeenCalled() + } + ) }) + +function typeInto(input: HTMLInputElement, value: string) { + Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set?.call(input, value) + input.dispatchEvent(new Event('input', { bubbles: true })) +} diff --git a/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/workspaces-section/workspaces-section.tsx b/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/workspaces-section/workspaces-section.tsx index 5e64b48fa75..8c11625e2a2 100644 --- a/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/workspaces-section/workspaces-section.tsx +++ b/apps/sim/app/o/[organizationId]/components/organization-sidebar/components/workspaces-section/workspaces-section.tsx @@ -1,98 +1,104 @@ 'use client' import { useState } from 'react' -import { chipVariants, cn, OverflowText } from '@sim/emcn' -import { Workspaces } from '@sim/emcn/icons' -import Link from 'next/link' -import { IdentityTile } from '@/components/identity-tile/identity-tile' -import { getWorkspaceInitial } from '@/lib/workspaces/initials' -import { WorkspacesRailFlyout } from '@/app/o/[organizationId]/components/organization-sidebar/components/workspaces-rail-flyout' -import { useOrganizationWorkspaces } from '@/app/o/[organizationId]/components/organization-sidebar/hooks' +import { Button, cn, Tooltip } from '@sim/emcn' +import { Plus, Workspaces } from '@sim/emcn/icons' +import { useRouter } from 'next/navigation' +import { WorkspaceList } from '@/app/o/[organizationId]/components/organization-sidebar/components/workspaces-section/workspace-list' import { CollapsedSidebarMenu, SidebarSection, } from '@/app/workspace/[workspaceId]/w/components/sidebar/components' +import { CreateWorkspaceModal } from '@/app/workspace/[workspaceId]/w/components/sidebar/components/workspace-header/components/create-workspace-modal/create-workspace-modal' import { SIDEBAR_ITEM_GAP_CLASS } from '@/app/workspace/[workspaceId]/w/components/sidebar/constants' -import { useHoverMenu } from '@/app/workspace/[workspaceId]/w/components/sidebar/hooks' - -/** Rows shown at first, and added per "See more" — the workspace sidebar's Chats paging. */ -const PAGE_SIZE = 5 +import { useHoverMenu } from '@/app/workspace/[workspaceId]/w/components/sidebar/hooks/use-hover-menu' +import { useCreateWorkspace, useWorkspaceCreationPolicy } from '@/hooks/queries/workspace' +import { useSettingsDirtyStore } from '@/stores/settings/dirty/store' interface WorkspacesSectionProps { organizationId: string isCollapsed: boolean pathname: string | null - onContextMenu: (e: React.MouseEvent, href: string) => void } -/** - * The organization's workspaces the viewer belongs to: the first section of the - * scroll region, so it carries no section gap — the divider padding above it is - * the whole distance, exactly as the workspace sidebar spaces its own Chats. - * Expanded, five rail chips and a muted "See more" that pages the rest in, the way - * the workspace sidebar pages its Chats; collapsed, a hover flyout off the rail glyph. - */ export function WorkspacesSection({ organizationId, isCollapsed, pathname, - onContextMenu, }: WorkspacesSectionProps) { + const router = useRouter() const hover = useHoverMenu() - const { workspaces, isLoading } = useOrganizationWorkspaces(organizationId) - const [visibleCount, setVisibleCount] = useState(PAGE_SIZE) - const hasMore = workspaces.length > visibleCount + const [isCreateOpen, setIsCreateOpen] = useState(false) + const { data: creationPolicy } = useWorkspaceCreationPolicy() + const { mutateAsync: createWorkspace, isPending: isCreating } = useCreateWorkspace() + const canCreate = creationPolicy?.canCreate && creationPolicy.organizationId === organizationId + const createDisabledReason = creationPolicy?.reason ?? 'Workspace creation is unavailable.' + + const openCreate = () => { + if (!canCreate || isCreating) return + useSettingsDirtyStore.getState().requestLeave(() => { + hover.close() + setIsCreateOpen(true) + }) + } return ( - - {isCollapsed ? ( -
- } - hover={hover} - ariaLabel='Workspaces' - > - - -
- ) : ( -
- {!isLoading && workspaces.length === 0 && ( -
- No workspaces yet -
- )} - {workspaces.slice(0, visibleCount).map((workspace) => { - const href = `/workspace/${workspace.id}` - return ( - onContextMenu(e, href)} - > - - - - ) - })} - {workspaces.length > PAGE_SIZE && ( - + + + {canCreate ? 'New workspace' : createDisabledReason} + + + ) + } + > + {isCollapsed ? ( +
+ } + hover={hover} + ariaLabel='Workspaces' + primaryAction={ + canCreate ? { label: 'New workspace', onSelect: openCreate } : undefined + } > - {hasMore ? 'See more' : 'See less'} - - )} -
- )} - + + +
+ ) : ( +
+ +
+ )} +
+ { + if (!canCreate) throw new Error(createDisabledReason) + const workspace = await createWorkspace({ name }) + setIsCreateOpen(false) + router.push(`/workspace/${workspace.id}`) + }} + /> + ) } diff --git a/apps/sim/app/o/[organizationId]/components/organization-sidebar/hooks/use-organization-chat-actions.ts b/apps/sim/app/o/[organizationId]/components/organization-sidebar/hooks/use-organization-chat-actions.ts index 9ba5070470c..1ad28686c39 100644 --- a/apps/sim/app/o/[organizationId]/components/organization-sidebar/hooks/use-organization-chat-actions.ts +++ b/apps/sim/app/o/[organizationId]/components/organization-sidebar/hooks/use-organization-chat-actions.ts @@ -1,10 +1,13 @@ import { useCallback, useEffect, useState } from 'react' import { toast } from '@sim/emcn' import { getErrorMessage } from '@sim/utils/errors' +import { useRouter } from 'next/navigation' +import { organizationRoutes } from '@/lib/navigation/paths' import type { OrganizationChat } from '@/app/o/[organizationId]/components/organization-sidebar/hooks/use-organization-chats' import { useFlyoutInlineRename } from '@/app/workspace/[workspaceId]/w/components/sidebar/hooks/use-flyout-inline-rename' import { useHoverMenu } from '@/app/workspace/[workspaceId]/w/components/sidebar/hooks/use-hover-menu' import { + useDeleteMothershipChat, useMarkMothershipChatRead, useMarkMothershipChatUnread, useRenameMothershipChat, @@ -21,7 +24,9 @@ export function useOrganizationChatActions({ organizationId, chats, }: UseOrganizationChatActionsProps) { + const router = useRouter() const owner = { organizationId } + const { mutate: deleteChat, isPending: isDeleting } = useDeleteMothershipChat(owner) const { mutateAsync: renameChat } = useRenameMothershipChat(owner) const { mutate: pinChat } = useSetMothershipChatPinned(owner) const { mutate: readChat } = useMarkMothershipChatRead(owner) @@ -29,6 +34,7 @@ export function useOrganizationChatActions({ const menu = useContextMenu() const hover = useHoverMenu() const [selectedChatId, setSelectedChatId] = useState(null) + const [chatToDelete, setChatToDelete] = useState(null) const selectedChat = chats.find((chat) => chat.id === selectedChatId) const rename = useFlyoutInlineRename({ itemType: 'chat', @@ -80,6 +86,27 @@ export function useOrganizationChatActions({ const chatHref = selectedChat?.href const chatPinned = selectedChat?.isPinned + const startDelete = useCallback(() => { + if (selectedChat) setChatToDelete(selectedChat) + }, [selectedChat]) + + const cancelDelete = useCallback(() => { + if (!isDeleting) setChatToDelete(null) + }, [isDeleting]) + + const confirmDelete = useCallback(() => { + if (!chatToDelete || isDeleting) return + deleteChat(chatToDelete.id, { + onSuccess: () => { + setChatToDelete(null) + if (window.location.pathname === chatToDelete.href) { + router.push(organizationRoutes(organizationId).home) + } + }, + onError: (error) => toast.error(error.message), + }) + }, [chatToDelete, deleteChat, isDeleting, organizationId, router]) + const startRename = useCallback(() => { if (chatId && chatName !== undefined) rename.startRename({ id: chatId, name: chatName }) }, [chatId, chatName, rename.startRename]) @@ -119,6 +146,11 @@ export function useOrganizationChatActions({ onMorePointerDown, onMoreClick, startRename, + chatToDelete, + isDeleting, + startDelete, + cancelDelete, + confirmDelete, togglePin, markRead, markUnread, diff --git a/apps/sim/app/o/[organizationId]/components/organization-sidebar/hooks/use-organization-workspaces.test.tsx b/apps/sim/app/o/[organizationId]/components/organization-sidebar/hooks/use-organization-workspaces.test.tsx new file mode 100644 index 00000000000..6e639163a73 --- /dev/null +++ b/apps/sim/app/o/[organizationId]/components/organization-sidebar/hooks/use-organization-workspaces.test.tsx @@ -0,0 +1,123 @@ +/** + * @vitest-environment jsdom + */ +import { act } from 'react' +import { createRoot, hydrateRoot, type Root } from 'react-dom/client' +import { renderToString } from 'react-dom/server' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { STORAGE_KEYS, WorkspaceRecencyStorage } from '@/lib/core/utils/browser-storage' + +const { mockUseWorkspacesQuery, pins } = vi.hoisted(() => ({ + pins: { current: new Set() }, + mockUseWorkspacesQuery: vi.fn(), +})) + +vi.mock('@/hooks/queries/workspace', () => ({ + useWorkspacesQuery: mockUseWorkspacesQuery, + EMPTY_PINNED_WORKSPACE_IDS: new Set(), + usePinnedWorkspaceIds: () => ({ data: pins.current }), +})) + +import { useOrganizationWorkspaces } from '@/app/o/[organizationId]/components/organization-sidebar/hooks/use-organization-workspaces' + +function Harness() { + const { workspaces } = useOrganizationWorkspaces('org-1') + return ( +
    + {workspaces.map((workspace) => ( +
  • {workspace.id}
  • + ))} +
+ ) +} + +let container: HTMLDivElement +let root: Root | undefined + +beforeEach(() => { + vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true) + localStorage.clear() + pins.current = new Set() + mockUseWorkspacesQuery.mockReturnValue({ + data: [ + { id: 'newest', organizationId: 'org-1' }, + { id: 'other-org', organizationId: 'org-2' }, + { id: 'older', organizationId: 'org-1' }, + { id: 'oldest', organizationId: 'org-1' }, + ], + isLoading: false, + }) + container = document.createElement('div') + document.body.appendChild(container) +}) + +afterEach(async () => { + if (root) await act(async () => root?.unmount()) + root = undefined + container.remove() + localStorage.clear() + vi.unstubAllGlobals() +}) + +function workspaceIds() { + return Array.from(container.querySelectorAll('li'), (item) => item.textContent) +} + +describe('useOrganizationWorkspaces', () => { + it('hydrates the prefetched order before applying visit history without changing the query cache', async () => { + localStorage.setItem( + STORAGE_KEYS.WORKSPACE_RECENCY, + JSON.stringify({ oldest: 100, older: 200, 'other-org': 300 }) + ) + container.innerHTML = renderToString() + expect(workspaceIds()).toEqual(['newest', 'older', 'oldest']) + + const onRecoverableError = vi.fn() + await act(async () => { + root = hydrateRoot(container, , { onRecoverableError }) + }) + + expect(onRecoverableError).not.toHaveBeenCalled() + expect(workspaceIds()).toEqual(['older', 'oldest', 'newest']) + expect(mockUseWorkspacesQuery().data.map(({ id }: { id: string }) => id)).toEqual([ + 'newest', + 'other-org', + 'older', + 'oldest', + ]) + }) + + it('preserves creation-date order when the browser has no visit history', async () => { + await act(async () => { + root = createRoot(container) + root.render() + }) + + expect(workspaceIds()).toEqual(['newest', 'older', 'oldest']) + }) + it('keeps pins first and reacts to visits without mutating the query cache', async () => { + pins.current = new Set(['oldest']) + await act(async () => { + root = createRoot(container) + root.render() + }) + expect(workspaceIds()).toEqual(['oldest', 'newest', 'older']) + await act(async () => WorkspaceRecencyStorage.touch('older')) + expect(workspaceIds()).toEqual(['oldest', 'older', 'newest']) + pins.current = new Set() + await act(async () => root?.render()) + expect(workspaceIds()).toEqual(['older', 'newest', 'oldest']) + }) + + it('follows visit history changed by another tab', async () => { + await act(async () => { + root = createRoot(container) + root.render() + }) + await act(async () => { + localStorage.setItem(STORAGE_KEYS.WORKSPACE_RECENCY, JSON.stringify({ oldest: 300 })) + window.dispatchEvent(new StorageEvent('storage', { key: STORAGE_KEYS.WORKSPACE_RECENCY })) + }) + expect(workspaceIds()).toEqual(['oldest', 'newest', 'older']) + }) +}) diff --git a/apps/sim/app/o/[organizationId]/components/organization-sidebar/hooks/use-organization-workspaces.ts b/apps/sim/app/o/[organizationId]/components/organization-sidebar/hooks/use-organization-workspaces.ts index 6c54a696a36..761fddcd7c4 100644 --- a/apps/sim/app/o/[organizationId]/components/organization-sidebar/hooks/use-organization-workspaces.ts +++ b/apps/sim/app/o/[organizationId]/components/organization-sidebar/hooks/use-organization-workspaces.ts @@ -1,4 +1,9 @@ -import { useWorkspacesQuery } from '@/hooks/queries/workspace' +import { + EMPTY_PINNED_WORKSPACE_IDS, + usePinnedWorkspaceIds, + useWorkspacesQuery, +} from '@/hooks/queries/workspace' +import { useWorkspaceOrder } from '@/hooks/use-workspace-order' /** * The organization's workspaces the viewer belongs to, for the sidebar's @@ -7,8 +12,15 @@ import { useWorkspacesQuery } from '@/hooks/queries/workspace' */ export function useOrganizationWorkspaces(organizationId: string) { const { data = [], isLoading } = useWorkspacesQuery() + const { data: pinnedWorkspaceIds = EMPTY_PINNED_WORKSPACE_IDS } = usePinnedWorkspaceIds() + const orderedWorkspaces = useWorkspaceOrder(data, pinnedWorkspaceIds) + const workspaces = orderedWorkspaces.filter( + (workspace) => workspace.organizationId === organizationId + ) - const workspaces = data.filter((workspace) => workspace.organizationId === organizationId) - - return { workspaces, isLoading } + return { + workspaces, + pinnedWorkspaceIds, + isLoading, + } } diff --git a/apps/sim/app/o/[organizationId]/components/organization-sidebar/organization-sidebar.tsx b/apps/sim/app/o/[organizationId]/components/organization-sidebar/organization-sidebar.tsx index 126004e808d..18f7895a002 100644 --- a/apps/sim/app/o/[organizationId]/components/organization-sidebar/organization-sidebar.tsx +++ b/apps/sim/app/o/[organizationId]/components/organization-sidebar/organization-sidebar.tsx @@ -262,7 +262,6 @@ export const OrganizationSidebar = memo(function OrganizationSidebar() { organizationId={organization.id} isCollapsed={isCollapsed} pathname={pathname} - onContextMenu={handleHrefContextMenu} /> {searchAccess.memberScoped && ( ({ mockGetOrganizationSurfaceContext: vi.fn(), mockWorkspaceChrome: vi.fn(({ children }: { children: ReactNode }) => children), mockPrefetchOrganizationSidebar: vi.fn(async () => undefined), mockUseSession: vi.fn(), + mockUseMothershipChatEvents: vi.fn(), +})) + +vi.mock('@/hooks/use-mothership-chat-events', () => ({ + useMothershipChatEvents: mockUseMothershipChatEvents, })) vi.mock('@/lib/auth/auth-client', () => ({ useSession: mockUseSession })) @@ -118,6 +125,10 @@ describe('OrganizationLayout', () => { 'active-org' ) expect(html).toContain('Organization child') + expect(mockUseMothershipChatEvents).toHaveBeenCalledWith( + { organizationId: 'org-1' }, + isChatEnabled + ) expect(html).not.toContain('Stop impersonating') expect(mockWorkspaceChrome).toHaveBeenCalledWith( expect.objectContaining({ initialSidebarCollapsed: true }), diff --git a/apps/sim/app/o/[organizationId]/layout.tsx b/apps/sim/app/o/[organizationId]/layout.tsx index fb4b66e85bd..41628908ca4 100644 --- a/apps/sim/app/o/[organizationId]/layout.tsx +++ b/apps/sim/app/o/[organizationId]/layout.tsx @@ -3,6 +3,7 @@ import { cookies } from 'next/headers' import { redirect } from 'next/navigation' import { getSession } from '@/lib/auth' import { getActiveOrganizationId } from '@/lib/auth/session-response' +import { isChatEnabled } from '@/lib/core/config/env-flags' import { organizationRoutes, WORKSPACE_SETTINGS_PATH } from '@/lib/navigation/paths' import { getOrganizationSurfaceContext } from '@/lib/organizations/surface' import { getQueryClient } from '@/app/_shell/providers/get-query-client' @@ -61,7 +62,7 @@ export default async function OrganizationLayout({ return ( - +
diff --git a/apps/sim/app/o/[organizationId]/providers/organization-provider.tsx b/apps/sim/app/o/[organizationId]/providers/organization-provider.tsx index 849ee65ffba..af1f23d4260 100644 --- a/apps/sim/app/o/[organizationId]/providers/organization-provider.tsx +++ b/apps/sim/app/o/[organizationId]/providers/organization-provider.tsx @@ -2,12 +2,14 @@ import { createContext, type ReactNode, useContext } from 'react' import type { OrganizationSurfaceContext } from '@/lib/organizations/surface' +import { useMothershipChatEvents } from '@/hooks/use-mothership-chat-events' const OrganizationContextValue = createContext(null) interface OrganizationProviderProps { children: ReactNode context: OrganizationSurfaceContext + chatEnabled: boolean } /** @@ -15,7 +17,15 @@ interface OrganizationProviderProps { * organization surface. The layout resolves both on the server, so the first paint * already knows the organization's name and logo. */ -export function OrganizationProvider({ children, context }: OrganizationProviderProps) { +export function OrganizationProvider({ + children, + context, + chatEnabled, +}: OrganizationProviderProps) { + useMothershipChatEvents( + context.searchAccess.memberScoped ? { organizationId: context.organization.id } : undefined, + chatEnabled + ) return ( {children} diff --git a/apps/sim/app/o/[organizationId]/settings/[section]/settings.tsx b/apps/sim/app/o/[organizationId]/settings/[section]/settings.tsx index f924714adc4..f5adfa63f19 100644 --- a/apps/sim/app/o/[organizationId]/settings/[section]/settings.tsx +++ b/apps/sim/app/o/[organizationId]/settings/[section]/settings.tsx @@ -9,6 +9,12 @@ import { import { SettingsSectionProvider } from '@/components/settings/settings-panel' import { useOrganizationContext } from '@/app/o/[organizationId]/providers/organization-provider' +const OrganizationRecentlyDeleted = dynamic(() => + import('@/app/o/[organizationId]/settings/components/organization-recently-deleted').then( + (m) => m.OrganizationRecentlyDeleted + ) +) + const OrganizationIntegrationsSettings = dynamic(() => import( '@/app/o/[organizationId]/settings/components/integrations/organization-integrations-settings' @@ -78,6 +84,9 @@ export function OrganizationSettings({ section }: OrganizationSettingsProps) { return ( + {section === 'recently-deleted' && ( + + )} {section === 'integrations' && } {section === 'connected-accounts' && ( diff --git a/apps/sim/app/o/[organizationId]/settings/components/organization-recently-deleted.test.tsx b/apps/sim/app/o/[organizationId]/settings/components/organization-recently-deleted.test.tsx new file mode 100644 index 00000000000..06bdd5ddafd --- /dev/null +++ b/apps/sim/app/o/[organizationId]/settings/components/organization-recently-deleted.test.tsx @@ -0,0 +1,178 @@ +/** @vitest-environment jsdom */ +import { act, type ReactNode } from 'react' +import { ToastProvider } from '@sim/emcn' +import { sleep } from '@sim/utils/helpers' +import { QueryClient, QueryClientProvider } from '@tanstack/react-query' +import { NuqsTestingAdapter } from 'nuqs/adapters/testing' +import { createRoot, type Root } from 'react-dom/client' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import type { SettingsHeaderSearch } from '@/components/settings/settings-header' + +const mocks = vi.hoisted(() => ({ request: vi.fn(), push: vi.fn() })) +vi.mock('@/lib/api/client/request', () => ({ requestJson: mocks.request })) +vi.mock('next/navigation', () => ({ + useRouter: () => ({ push: mocks.push }), + usePathname: () => '/o/org-1/settings/recently-deleted', +})) +vi.mock('@/components/settings/settings-panel', () => ({ + SettingsPanel: ({ children, search }: { children: ReactNode; search: SettingsHeaderSearch }) => ( + <> + search.onChange(event.target.value)} + /> + {children} + + ), +})) + +import { OrganizationRecentlyDeleted } from '@/app/o/[organizationId]/settings/components/organization-recently-deleted' +import { type MothershipChatMetadata, mothershipChatKeys } from '@/hooks/queries/mothership-chats' + +const CHATS: MothershipChatMetadata[] = [ + { + id: 'chat-1', + name: 'Older chat', + updatedAt: new Date('2026-09-10'), + deletedAt: new Date('2026-09-10'), + isActive: false, + isUnread: false, + isPinned: false, + }, + { + id: 'chat-2', + name: 'Recent chat', + updatedAt: new Date('2026-09-11'), + deletedAt: new Date('2026-09-11'), + isActive: false, + isUnread: false, + isPinned: false, + }, +] +const ARCHIVED_KEY = mothershipChatKeys.organizationList('org-1', 'archived') +let container: HTMLDivElement +let root: Root +let queryClient: QueryClient + +beforeEach(() => { + vi.clearAllMocks() + mocks.request.mockReset().mockResolvedValue({ success: true }) + vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true) + vi.stubGlobal( + 'ResizeObserver', + class { + observe() {} + unobserve() {} + disconnect() {} + } + ) + queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } }) + queryClient.setQueryData(ARCHIVED_KEY, CHATS) + container = document.createElement('div') + document.body.appendChild(container) + root = createRoot(container) +}) + +afterEach(async () => { + await act(async () => root.unmount()) + container.remove() + queryClient.clear() + vi.unstubAllGlobals() +}) + +async function render(search = '') { + await act(async () => { + root.render( + + + + + + + + ) + }) +} + +function button(label: string) { + return Array.from(container.querySelectorAll('button')).find( + (button) => button.textContent === label + )! +} + +describe('OrganizationRecentlyDeleted', () => { + it('shows only this organization’s archived chats, newest deletion first', async () => { + queryClient.setQueryData(mothershipChatKeys.list('workspace-1', 'archived'), [ + { ...CHATS[0], name: 'Workspace chat' }, + ]) + await render() + const text = container.textContent ?? '' + expect(text.indexOf('Recent chat')).toBeLessThan(text.indexOf('Older chat')) + expect(text).not.toContain('Workspace chat') + expect(mocks.request).not.toHaveBeenCalled() + }) + + it('fetches the organization’s archived list when it is not cached', async () => { + queryClient.removeQueries({ queryKey: ARCHIVED_KEY }) + mocks.request.mockResolvedValueOnce({ data: [] }) + await render() + expect(mocks.request).toHaveBeenCalledWith( + expect.objectContaining({ method: 'GET' }), + expect.objectContaining({ + query: { organizationId: 'org-1', scope: 'archived' }, + signal: expect.any(AbortSignal), + }) + ) + }) + + it('filters through the shared settings search parameter', async () => { + await render('?search=recent') + expect(container.textContent).toContain('Recent chat') + expect(container.textContent).not.toContain('Older chat') + }) + + it('restores through the shared mutation and follows the authoritative archived list', async () => { + const invalidate = vi.spyOn(queryClient, 'invalidateQueries').mockResolvedValue() + await render() + await act(async () => button('Restore').click()) + expect(mocks.request).toHaveBeenCalledWith(expect.objectContaining({ method: 'POST' }), { + params: { chatId: 'chat-2' }, + }) + expect(invalidate).toHaveBeenCalledExactlyOnceWith({ + queryKey: mothershipChatKeys.organizationLists('org-1'), + }) + await act(async () => { + queryClient.setQueryData(ARCHIVED_KEY, [CHATS[0]]) + await sleep(1) + }) + expect(container.textContent).not.toContain('Recent chat') + await act(async () => { + queryClient.setQueryData(ARCHIVED_KEY, CHATS) + await sleep(1) + }) + expect(container.textContent).toContain('Recent chat') + expect(button('Restore').disabled).toBe(false) + expect(container.textContent).not.toContain('Restored') + }) + + it('disables repeat restoration while pending and leaves failures retryable', async () => { + vi.spyOn(queryClient, 'invalidateQueries').mockResolvedValue() + const pending = Promise.withResolvers<{ success: boolean }>() + mocks.request.mockReturnValueOnce(pending.promise) + await render() + await act(async () => button('Restore').click()) + await act(async () => sleep(1)) + expect(button('Restoring...').disabled).toBe(true) + await act(async () => button('Restoring...').click()) + expect(mocks.request).toHaveBeenCalledTimes(1) + await act(async () => { + pending.reject(new Error('Restore failed')) + await sleep(1) + }) + expect(button('Restore').disabled).toBe(false) + expect(button('View')).toBeUndefined() + expect(mocks.push).not.toHaveBeenCalled() + expect(queryClient.getQueryData(ARCHIVED_KEY)).toEqual(CHATS) + }) +}) diff --git a/apps/sim/app/o/[organizationId]/settings/components/organization-recently-deleted.tsx b/apps/sim/app/o/[organizationId]/settings/components/organization-recently-deleted.tsx new file mode 100644 index 00000000000..4976f123e40 --- /dev/null +++ b/apps/sim/app/o/[organizationId]/settings/components/organization-recently-deleted.tsx @@ -0,0 +1,84 @@ +'use client' + +import { Chip, toast } from '@sim/emcn' +import { Task } from '@sim/emcn/icons' +import { formatDate } from '@sim/utils/formatting' +import { SettingsPanel } from '@/components/settings/settings-panel' +import { SettingsEmptyState } from '@/app/workspace/[workspaceId]/settings/components/settings-empty-state' +import { + RESOURCE_LIST_STACK, + SettingsResourceRow, +} from '@/app/workspace/[workspaceId]/settings/components/settings-resource-row' +import { useSettingsSearch } from '@/app/workspace/[workspaceId]/settings/components/use-settings-search' +import { + type MothershipChatMetadata, + useOrganizationMothershipChats, + useRestoreMothershipChat, +} from '@/hooks/queries/mothership-chats' + +interface DeletedChatRowProps { + organizationId: string + chat: MothershipChatMetadata +} + +function DeletedChatRow({ organizationId, chat }: DeletedChatRowProps) { + const { mutate: restoreChat, isPending } = useRestoreMothershipChat({ organizationId }) + return ( + } + title={chat.name} + description={chat.deletedAt ? `Deleted ${formatDate(chat.deletedAt)}` : undefined} + trailing={ + restoreChat(chat.id, { onError: (error) => toast.error(error.message) })} + > + {isPending ? 'Restoring...' : 'Restore'} + + } + /> + ) +} + +interface OrganizationRecentlyDeletedProps { + organizationId: string +} + +export function OrganizationRecentlyDeleted({ organizationId }: OrganizationRecentlyDeletedProps) { + const [search, setSearch] = useSettingsSearch() + const { + data: chats = [], + isLoading, + error, + } = useOrganizationMothershipChats(organizationId, 'archived') + const searchTerm = search.trim().toLowerCase() + const filtered = chats + .filter((chat) => chat.name.toLowerCase().includes(searchTerm)) + .sort( + (a, b) => + (b.deletedAt?.getTime() ?? 0) - (a.deletedAt?.getTime() ?? 0) || + a.name.localeCompare(b.name) || + a.id.localeCompare(b.id) + ) + + return ( + + {error ? ( + {error.message} + ) : isLoading ? null : filtered.length === 0 ? ( + + {searchTerm && chats.length > 0 ? 'No chats match your search' : 'No deleted chats'} + + ) : ( +
+ {filtered.map((chat) => ( + + ))} +
+ )} +
+ ) +} diff --git a/apps/sim/app/o/[organizationId]/settings/navigation.test.ts b/apps/sim/app/o/[organizationId]/settings/navigation.test.ts index 2e7e3279110..36c23895f8c 100644 --- a/apps/sim/app/o/[organizationId]/settings/navigation.test.ts +++ b/apps/sim/app/o/[organizationId]/settings/navigation.test.ts @@ -28,7 +28,7 @@ describe('organization settings navigation', () => { it('exposes MCP setup and the read-only roster to an ordinary organization member', () => { expect( organizationSettingsNavigation(false, enterprise, available).map(({ id }) => id) - ).toEqual(['members', 'search-mcp']) + ).toEqual(['members', 'recently-deleted', 'search-mcp']) }) it('uses Sources for administration when Search is available', () => { @@ -49,7 +49,7 @@ describe('organization settings navigation', () => { { ...enterprise, hasEnterprisePlan: false }, available ).map(({ id }) => id) - ).toEqual(['billing', 'members', 'search-mcp']) + ).toEqual(['billing', 'members', 'recently-deleted', 'search-mcp']) }) it('honors individual self-hosted feature flags and hides billing when disabled', () => { @@ -64,7 +64,7 @@ describe('organization settings navigation', () => { }, available ).map(({ id }) => id) - ).toEqual(['members', 'sso', 'integrations', 'search-mcp', 'search-slack']) + ).toEqual(['members', 'recently-deleted', 'sso', 'integrations', 'search-mcp', 'search-slack']) }) it('normalizes old section names and does not expose unsupported routes', () => { @@ -88,6 +88,7 @@ describe('organization settings navigation', () => { 'organization:connected-accounts', 'organization:usage', 'organization:whitelabeling', + 'organization:recently-deleted', 'governance:audit-logs', 'governance:access-control', 'governance:sso', @@ -103,7 +104,7 @@ describe('organization settings navigation', () => { it('hosts the account General section ahead of the organization sections', () => { expect( organizationSurfaceSettingsNavigation(false, enterprise, available).map(({ id }) => id) - ).toEqual(['general', 'members', 'search-mcp']) + ).toEqual(['general', 'members', 'recently-deleted', 'search-mcp']) expect(ORGANIZATION_SETTINGS_GROUPS.map(({ key }) => key)).toEqual([ 'account', 'organization', @@ -123,6 +124,10 @@ describe('organization settings navigation', () => { section: 'billing', }) expect(resolveOrganizationSurfaceSection('skills')).toBeNull() + expect(resolveOrganizationSurfaceSection('recently-deleted')).toEqual({ + plane: 'organization', + section: 'recently-deleted', + }) }) it('hides gated sections while preserving ordinary organization navigation', () => { const sections = organizationSurfaceSettingsNavigation(true, enterprise, { diff --git a/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/sidebar-footer/sidebar-footer.tsx b/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/sidebar-footer/sidebar-footer.tsx index 3187bccd6fe..6963d707b56 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/sidebar-footer/sidebar-footer.tsx +++ b/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/sidebar-footer/sidebar-footer.tsx @@ -394,7 +394,7 @@ export function SidebarFooter({ exactly the chip's 30px instead of a line box padded by the strut's half-leading, which would deepen the bar below the chip. Collapsed, it stretches to the rail on its own and the chip fills it. */} -
{profileMenu}
+
{profileMenu}
{helpMenu}
) diff --git a/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workspace-header/workspace-header.tsx b/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workspace-header/workspace-header.tsx index f6d35471dfb..c39d0ba9090 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workspace-header/workspace-header.tsx +++ b/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workspace-header/workspace-header.tsx @@ -29,11 +29,12 @@ import { createLogger } from '@sim/logger' import { getErrorMessage } from '@sim/utils/errors' import { useQueryClient } from '@tanstack/react-query' import { IdentityTile } from '@/components/identity-tile/identity-tile' +import { WorkspaceContextMenu } from '@/components/workspaces/workspace-context-menu' import { useDeploymentShape } from '@/lib/core/config/deployment-shape' +import { WORKSPACE_SEARCH_THRESHOLD } from '@/lib/workspaces/constants' import { getWorkspaceInitial } from '@/lib/workspaces/initials' import { InviteModal } from '@/app/workspace/[workspaceId]/components/invite-modal' import { useWorkspacePermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider' -import { ContextMenu } from '@/app/workspace/[workspaceId]/w/components/sidebar/components/workflow-list/components/context-menu/context-menu' import { DeleteModal } from '@/app/workspace/[workspaceId]/w/components/sidebar/components/workflow-list/components/delete-modal/delete-modal' import { CreateWorkspaceModal } from '@/app/workspace/[workspaceId]/w/components/sidebar/components/workspace-header/components/create-workspace-modal/create-workspace-modal' import { ViewInvitationsMenuItem } from '@/app/workspace/[workspaceId]/w/components/sidebar/components/workspace-header/components/pending-invitations/view-invitations-menu-item' @@ -50,20 +51,6 @@ import { useSettingsNavigation } from '@/hooks/use-settings-navigation' const logger = createLogger('WorkspaceHeader') -/** - * Show the search input once the workspace list reaches this count, and size the - * list viewport to exactly this many rows — so the sixth workspace is the one that - * both fills the viewport and brings in search. - * - * The viewport's `max-h-[200px]` is derived from it: 6 rows at `chipGeometryClass`'s - * 30px plus the 2px `gap-0.5` between them (6 * 30 + 5 * 2), plus the list's own - * `pt-1.5 pb-1` (6 + 4) — the gaps to the search field and the rule, carried as - * the scroll box's padding so rows scroll through them under the edge fade. - * Tailwind arbitrary values must be statically analyzable, so the arithmetic - * cannot live in the class — change them together. - */ -const WORKSPACE_SEARCH_THRESHOLD = 6 - interface DisabledReasonTooltipProps { reason: string | null children: ReactElement @@ -847,44 +834,22 @@ function WorkspaceHeaderImpl({ )} - {(() => { - const capturedPermissions = capturedWorkspaceRef.current?.permissions - const contextCanAdmin = capturedPermissions === 'admin' - const capturedWorkspace = workspaces.find((w) => w.id === capturedWorkspaceRef.current?.id) - const isOwner = capturedWorkspace && sessionUserId === capturedWorkspace.ownerId - /** - * An organization admin holds this workspace through their org role, not - * a permission row, so there is nothing to give up and the removal - * endpoint refuses it. `permissions === 'admin'` cannot tell them apart - * from an explicit workspace admin, who may leave. This menu has no - * tooltip affordance to explain a greyed row, so the entry is withheld - * rather than shown dead. - */ - const canLeave = !isOwner && !capturedWorkspace?.isOrgAdmin && !!onLeaveWorkspace - - return ( - - ) - })()} + workspace.id === menuOpenWorkspaceId)} + workspaceCount={workspaces.length} + sessionUserId={sessionUserId} + isOpen={isContextMenuOpen} + position={contextMenuPosition} + menuRef={contextMenuRef} + onClose={closeContextMenu} + onRename={handleRenameAction} + renameInputRef={renameInputRef} + onDelete={handleDeleteAction} + onLeave={handleLeaveAction} + onTogglePin={handleTogglePinAction} + onUploadLogo={handleUploadLogoAction} + isPinned={Boolean(menuOpenWorkspaceId && pinnedWorkspaceIds.has(menuOpenWorkspaceId))} + /> { + vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true) + container = document.createElement('div') + document.body.appendChild(container) + root = createRoot(container) +}) +afterEach(() => { + act(() => root.unmount()) + container.remove() + vi.unstubAllGlobals() +}) + +function renderRenameHook(onSave: (id: string, name: string) => Promise) { + const result = {} as { current: ReturnType } + function Harness() { + result.current = useFlyoutInlineRename({ itemType: 'workspace', onSave }) + return null + } + act(() => root.render()) + return { result } +} + +function deferred() { + let resolve!: () => void + let reject!: (reason: Error) => void + const promise = new Promise((done, fail) => { + resolve = done + reject = fail + }) + return { promise, resolve, reject } +} + +describe('useFlyoutInlineRename', () => { + it.each(['success', 'failure'] as const)( + 'keeps a newer rename intact when an older save finishes with %s', + async (outcome) => { + const oldSave = deferred() + const newSave = deferred() + const onSave = vi + .fn() + .mockReturnValueOnce(oldSave.promise) + .mockReturnValueOnce(newSave.promise) + const { result } = renderRenameHook(onSave) + act(() => result.current.startRename({ id: 'old', name: 'Old name' })) + act(() => result.current.setValue('Old renamed')) + let firstSave!: Promise + act(() => { + firstSave = result.current.saveRename() + }) + act(() => result.current.startRename({ id: 'new', name: 'New name' })) + act(() => result.current.setValue('New renamed')) + let secondSave!: Promise + act(() => { + secondSave = result.current.saveRename() + }) + await act(async () => { + if (outcome === 'success') oldSave.resolve() + else oldSave.reject(new Error('Save failed')) + await firstSave + }) + expect(result.current.editingId).toBe('new') + expect(result.current.value).toBe('New renamed') + expect(result.current.isSaving).toBe(true) + await act(async () => { + newSave.resolve() + await secondSave + }) + expect(result.current.editingId).toBeNull() + expect(result.current.isSaving).toBe(false) + } + ) + + it('allows retry after failure and prevents Enter plus blur from saving twice', async () => { + const pending = deferred() + const onSave = vi.fn().mockReturnValueOnce(pending.promise).mockResolvedValue(undefined) + const { result } = renderRenameHook(onSave) + act(() => result.current.startRename({ id: 'workspace', name: 'Original' })) + act(() => result.current.setValue('Renamed')) + let save!: Promise + act(() => { + save = result.current.saveRename() + void result.current.saveRename() + }) + expect(onSave).toHaveBeenCalledTimes(1) + await act(async () => { + pending.reject(new Error('Save failed')) + await save + }) + expect(result.current.editingId).toBe('workspace') + expect(result.current.value).toBe('Original') + expect(result.current.isSaving).toBe(false) + act(() => result.current.setValue('Retry')) + await act(async () => { + await result.current.saveRename() + }) + expect(onSave).toHaveBeenLastCalledWith('workspace', 'Retry') + expect(result.current.editingId).toBeNull() + }) +}) diff --git a/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/hooks/use-flyout-inline-rename.ts b/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/hooks/use-flyout-inline-rename.ts index a492918d789..f96613b173d 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/hooks/use-flyout-inline-rename.ts +++ b/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/hooks/use-flyout-inline-rename.ts @@ -20,6 +20,7 @@ export function useFlyoutInlineRename({ itemType, onSave }: UseFlyoutInlineRenam const inputRef = useRef(null) const cancelRequestedRef = useRef(false) const isSavingRef = useRef(false) + const activeTargetRef = useRef(null) useEffect(() => { if (editingTarget && inputRef.current) { @@ -29,13 +30,20 @@ export function useFlyoutInlineRename({ itemType, onSave }: UseFlyoutInlineRenam }, [editingTarget]) const startRename = useCallback((target: RenameTarget) => { + const nextTarget = { ...target } + activeTargetRef.current = nextTarget cancelRequestedRef.current = false - setEditingTarget(target) + isSavingRef.current = false + setIsSaving(false) + setEditingTarget(nextTarget) setValue(target.name) }, []) const cancelRename = useCallback(() => { + activeTargetRef.current = null cancelRequestedRef.current = true + isSavingRef.current = false + setIsSaving(false) setEditingTarget(null) }, []) @@ -45,21 +53,24 @@ export function useFlyoutInlineRename({ itemType, onSave }: UseFlyoutInlineRenam return } - if (!editingTarget || isSavingRef.current) { + if (!editingTarget || activeTargetRef.current !== editingTarget || isSavingRef.current) { return } const trimmedValue = value.trim() if (!trimmedValue || trimmedValue === editingTarget.name) { + activeTargetRef.current = null setEditingTarget(null) return } isSavingRef.current = true setIsSaving(true) + let saved = false try { await onSave(editingTarget.id, trimmedValue) - setEditingTarget(null) + saved = true + if (activeTargetRef.current === editingTarget) setEditingTarget(null) } catch (error) { logger.error(`Failed to rename ${itemType}:`, { error, @@ -67,10 +78,14 @@ export function useFlyoutInlineRename({ itemType, onSave }: UseFlyoutInlineRenam oldName: editingTarget.name, newName: trimmedValue, }) - setValue(editingTarget.name) + if (activeTargetRef.current === editingTarget) setValue(editingTarget.name) } finally { - isSavingRef.current = false - setIsSaving(false) + /** A late save must not clear a newer row's rename session or pending state. */ + if (activeTargetRef.current === editingTarget) { + isSavingRef.current = false + setIsSaving(false) + if (saved) activeTargetRef.current = null + } } }, [editingTarget, itemType, onSave, value]) diff --git a/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/hooks/use-workspace-management.ts b/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/hooks/use-workspace-management.ts index 8a821c0243a..2b60f17bb2c 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/hooks/use-workspace-management.ts +++ b/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/hooks/use-workspace-management.ts @@ -1,4 +1,4 @@ -import { useCallback, useEffect, useMemo, useRef, useState } from 'react' +import { useCallback, useEffect, useMemo, useRef } from 'react' import { createLogger } from '@sim/logger' import { usePathname, useRouter } from 'next/navigation' import { requestJson } from '@/lib/api/client/request' @@ -16,6 +16,7 @@ import { useWorkspacesQuery, type Workspace, } from '@/hooks/queries/workspace' +import { useWorkspaceOrder } from '@/hooks/use-workspace-order' import { useWorkflowRegistry } from '@/stores/workflows/registry/store' const logger = createLogger('useWorkspaceManagement') @@ -96,8 +97,6 @@ export function useWorkspaceManagement({ workspacesRef.current = workspaces routerRef.current = router - const [recencySortKey, setRecencySortKey] = useState(0) - useEffect(() => { return () => { if (syncTimerRef.current) clearTimeout(syncTimerRef.current) @@ -112,7 +111,6 @@ export function useWorkspaceManagement({ if (validIds.length > 0) { WorkspaceRecencyStorage.prune(new Set(validIds)) } - setRecencySortKey((k) => k + 1) if (syncTimerRef.current) clearTimeout(syncTimerRef.current) syncTimerRef.current = setTimeout(() => { @@ -122,23 +120,7 @@ export function useWorkspaceManagement({ }, 1000) }, []) - /** - * Pinned workspaces float to the top, recency ordering them within each group. - * Matches `resource-sort.ts`: pinning is a user-declared priority layered over - * the list's own sort, not a competing sort key. - */ - const sortedWorkspaces = useMemo(() => { - const byRecency = WorkspaceRecencyStorage.sortByRecency(workspaces) - if (pinnedWorkspaceIds.size === 0) return byRecency - const pinned: Workspace[] = [] - const unpinned: Workspace[] = [] - for (const workspace of byRecency) { - if (pinnedWorkspaceIds.has(workspace.id)) pinned.push(workspace) - else unpinned.push(workspace) - } - return [...pinned, ...unpinned] - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [workspaces, recencySortKey, pinnedWorkspaceIds]) + const sortedWorkspaces = useWorkspaceOrder(workspaces, pinnedWorkspaceIds) const toggleWorkspacePin = useCallback( (workspaceId: string) => { diff --git a/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/sidebar.tsx b/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/sidebar.tsx index 36b376cba74..35fab1b09f7 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/sidebar.tsx +++ b/apps/sim/app/workspace/[workspaceId]/w/components/sidebar/sidebar.tsx @@ -830,7 +830,7 @@ export const Sidebar = memo(function Sidebar() { { enabled: chatEnabled } ) - useMothershipChatEvents(workspaceId) + useMothershipChatEvents(workspaceId, chatEnabled) /** * Stays empty when Chat is disabled, which also drops the command palette's diff --git a/apps/sim/components/settings/navigation.test.ts b/apps/sim/components/settings/navigation.test.ts index 37ded7d6390..7e29f8ca48c 100644 --- a/apps/sim/components/settings/navigation.test.ts +++ b/apps/sim/components/settings/navigation.test.ts @@ -470,6 +470,24 @@ describe('settings navigation boundaries', () => { ).toBe('manage') }) + it('allows members to recover their own organization chats without changing workspace settings ownership', () => { + expect( + resolveOrganizationSectionAccess({ + section: 'recently-deleted', + isTargetOrganizationMember: true, + isTargetOrganizationAdmin: false, + }) + ).toBe('view') + expect( + resolveOrganizationSectionAccess({ + section: 'recently-deleted', + isTargetOrganizationMember: false, + isTargetOrganizationAdmin: false, + }) + ).toBe('unavailable') + expect(ORGANIZATION_PLANE_UNIFIED_SECTIONS.has('recently-deleted')).toBe(false) + }) + it('gates organization control-plane sections by the target organization plan', () => { const hostedFree = { billingEnabled: true, @@ -478,6 +496,7 @@ describe('settings navigation boundaries', () => { selfHosted: {}, } expect(isOrganizationSettingsSectionAvailable('members', hostedFree)).toBe(true) + expect(isOrganizationSettingsSectionAvailable('recently-deleted', hostedFree)).toBe(true) expect(isOrganizationSettingsSectionAvailable('billing', hostedFree)).toBe(true) expect(isOrganizationSettingsSectionAvailable('sso', hostedFree)).toBe(false) expect( diff --git a/apps/sim/components/settings/navigation.ts b/apps/sim/components/settings/navigation.ts index d935ce3e92b..2665b09e256 100644 --- a/apps/sim/components/settings/navigation.ts +++ b/apps/sim/components/settings/navigation.ts @@ -44,6 +44,7 @@ export type AccountSettingsSection = 'general' | 'billing' | 'api-keys' | 'admin export type SelfHostSettingsSection = 'general' | 'billing' | 'chat-keys' export type OrganizationSettingsSection = + | 'recently-deleted' | 'integrations' | 'connected-accounts' | 'search-mcp' @@ -900,6 +901,7 @@ const ORGANIZATION_SECTION_GROUPS: Record { const group = ORGANIZATION_SECTION_GROUPS[id] + if (id === 'recently-deleted') { + return { + id, + label: 'Recently deleted', + description: 'Restore your deleted chats.', + icon: Trash, + group, + } + } if (id === 'connected-accounts') { return { id, @@ -1011,7 +1022,7 @@ export function resolveOrganizationSectionAccess({ isTargetOrganizationAdmin, }: ResolveOrganizationSectionAccessOptions): OrganizationSectionAccess { if (!isTargetOrganizationMember) return 'unavailable' - if (section === 'search-mcp') return 'view' + if (section === 'search-mcp' || section === 'recently-deleted') return 'view' if (section === 'members') return isTargetOrganizationAdmin ? 'manage' : 'view' return isTargetOrganizationAdmin ? 'manage' : 'unavailable' } @@ -1054,7 +1065,8 @@ export function isOrganizationSettingsSectionAvailable( section: OrganizationSettingsSection, features: OrganizationSettingsFeatures ): boolean { - if (section === 'members' || section === 'search-mcp') return true + if (section === 'members' || section === 'search-mcp' || section === 'recently-deleted') + return true if (section === 'billing') return features.billingEnabled /* Sim Search itself is enterprise on the hosted product; self-hosted gates it by flag, not by section. */ if (section === 'integrations' || section === 'search-slack') diff --git a/apps/sim/components/workspaces/workspace-context-menu.test.tsx b/apps/sim/components/workspaces/workspace-context-menu.test.tsx new file mode 100644 index 00000000000..db5cb098883 --- /dev/null +++ b/apps/sim/components/workspaces/workspace-context-menu.test.tsx @@ -0,0 +1,114 @@ +/** + * @vitest-environment jsdom + */ +import { act, createRef } from 'react' +import { createRoot, type Root } from 'react-dom/client' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { WorkspaceContextMenu } from '@/components/workspaces/workspace-context-menu' +import type { Workspace } from '@/lib/api/contracts/workspaces' + +const workspace: Workspace = { + id: 'workspace', + name: 'Workspace', + organizationId: 'org', + workspaceMode: 'organization', + ownerId: 'owner', + permissions: 'admin', +} + +let container: HTMLDivElement +let root: Root +beforeEach(() => { + vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true) + container = document.createElement('div') + document.body.appendChild(container) + root = createRoot(container) +}) +afterEach(() => { + act(() => root.unmount()) + container.remove() + vi.unstubAllGlobals() +}) +function menuItem(name: string) { + return Array.from(document.querySelectorAll('[role="menuitem"]')).find( + (item) => item.textContent === name + ) +} + +function showMenu( + overrides: Partial = {}, + sessionUserId = 'member', + workspaceCount = 2 +) { + act(() => + root.render( + ()} + onClose={vi.fn()} + onTogglePin={vi.fn()} + onRename={vi.fn()} + onDelete={vi.fn()} + onLeave={vi.fn()} + onUploadLogo={vi.fn()} + /> + ) + ) +} + +describe('WorkspaceContextMenu', () => { + it.each(['read', 'write'] as const)( + 'keeps personal pinning available for %s access but disables admin actions', + (permissions) => { + showMenu({ permissions }) + expect(menuItem('Pin')).not.toHaveAttribute('aria-disabled', 'true') + expect(menuItem('Rename')).toHaveAttribute('aria-disabled', 'true') + expect(menuItem('Delete')).toHaveAttribute('aria-disabled', 'true') + expect(menuItem('Upload logo')).toHaveAttribute('aria-disabled', 'true') + } + ) + + it('allows an explicit admin to rename and leave', () => { + showMenu() + expect(menuItem('Rename')).not.toHaveAttribute('aria-disabled', 'true') + expect(menuItem('Leave')).toBeDefined() + }) + + it('does not offer leaving access inherited from the organization role', () => { + showMenu({ isOrgAdmin: true }) + expect(menuItem('Leave')).toBeUndefined() + expect(menuItem('Rename')).not.toHaveAttribute('aria-disabled', 'true') + }) + + it('does not offer leaving the owned workspace or deleting the final workspace', () => { + showMenu({}, 'owner', 1) + expect(menuItem('Leave')).toBeUndefined() + expect(menuItem('Delete')).toHaveAttribute('aria-disabled', 'true') + }) + + it('omits unavailable actions even when the viewer has admin permissions', () => { + act(() => + root.render( + ()} + onClose={vi.fn()} + onRename={vi.fn()} + onTogglePin={vi.fn()} + /> + ) + ) + expect(menuItem('Upload logo')).toBeUndefined() + expect(menuItem('Leave')).toBeUndefined() + expect(menuItem('Delete')).toBeUndefined() + expect(menuItem('Rename')).toBeDefined() + }) +}) diff --git a/apps/sim/components/workspaces/workspace-context-menu.tsx b/apps/sim/components/workspaces/workspace-context-menu.tsx new file mode 100644 index 00000000000..9b1bb88ce77 --- /dev/null +++ b/apps/sim/components/workspaces/workspace-context-menu.tsx @@ -0,0 +1,47 @@ +'use client' + +import type { ComponentProps } from 'react' +import type { Workspace } from '@/lib/api/contracts/workspaces' +import { ContextMenu } from '@/app/workspace/[workspaceId]/w/components/sidebar/components/workflow-list/components/context-menu/context-menu' + +interface WorkspaceContextMenuProps + extends Omit< + ComponentProps, + | 'disableRename' + | 'disableDelete' + | 'disableUploadLogo' + | 'showLeave' + | 'showUploadLogo' + | 'showPin' + | 'showRename' + > { + workspace?: Workspace | null + workspaceCount: number + sessionUserId?: string +} + +/** Uses the same workspace role policy in the switcher and organization sidebar. */ +export function WorkspaceContextMenu({ + workspace, + workspaceCount, + sessionUserId, + ...props +}: WorkspaceContextMenuProps) { + const canAdmin = workspace?.permissions === 'admin' + const canLeave = Boolean( + workspace && sessionUserId && sessionUserId !== workspace.ownerId && !workspace.isOrgAdmin + ) + + return ( + + ) +} diff --git a/apps/sim/hooks/queries/mothership-chats.test.ts b/apps/sim/hooks/queries/mothership-chats.test.ts index 755367b1040..1953cc79fbc 100644 --- a/apps/sim/hooks/queries/mothership-chats.test.ts +++ b/apps/sim/hooks/queries/mothership-chats.test.ts @@ -2,10 +2,12 @@ * @vitest-environment node */ +import { sleep } from '@sim/utils/helpers' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import type { MothershipResource } from '@/lib/copilot/resources/types' -const { queryClient, suspendBrowserScope, suspendTerminalScope } = vi.hoisted(() => ({ +const { queryClient, suspendBrowserScope, suspendTerminalScope, clearChat } = vi.hoisted(() => ({ + clearChat: vi.fn(), queryClient: { cancelQueries: vi.fn().mockResolvedValue(undefined), invalidateQueries: vi.fn().mockResolvedValue(undefined), @@ -17,6 +19,10 @@ const { queryClient, suspendBrowserScope, suspendTerminalScope } = vi.hoisted(() suspendTerminalScope: vi.fn(async () => true), })) +vi.mock('@/stores/mothership-queue/store', () => ({ + useMothershipQueueStore: { getState: () => ({ clearChat }) }, +})) + vi.mock('@tanstack/react-query', () => ({ keepPreviousData: {}, queryOptions: (options: unknown) => options, @@ -232,10 +238,16 @@ describe('tasks query boundary parsing', () => { mutation.onSettled(undefined, new Error('delete failed'), 'chat-failed') expect(suspendBrowserScope).not.toHaveBeenCalled() expect(suspendTerminalScope).not.toHaveBeenCalled() + expect(clearChat).not.toHaveBeenCalled() + expect(queryClient.removeQueries).not.toHaveBeenCalled() await mutation.onSuccess(undefined, 'chat-deleted') expect(suspendBrowserScope).toHaveBeenCalledWith('chat-deleted') expect(suspendTerminalScope).toHaveBeenCalledWith('chat-deleted') + expect(clearChat).toHaveBeenCalledWith('chat-deleted') + expect(queryClient.removeQueries).toHaveBeenCalledWith({ + queryKey: ['mothership-chats', 'detail', 'chat-deleted'], + }) }) it('suspends every native resource group after a successful bulk delete', async () => { @@ -254,6 +266,44 @@ describe('tasks query boundary parsing', () => { expect(suspendTerminalScope).toHaveBeenCalledWith('chat-b') }) + it('waits for slower successful deletions before reconciling a failed batch', async () => { + const pending = Promise.withResolvers() + const mutation = useDeleteMothershipChats({ organizationId: 'org-1' }) as unknown as { + mutationFn: (chatIds: string[]) => Promise + onSettled: () => void + } + vi.mocked(fetch) + .mockResolvedValueOnce(new Response('delete failed', { status: 500 })) + .mockReturnValueOnce(pending.promise) + const result = mutation.mutationFn(['chat-failed', 'chat-slow']) + const reconciled = vi.fn() + const observed = result.then( + () => { + mutation.onSettled() + reconciled() + }, + () => { + mutation.onSettled() + reconciled() + } + ) + await sleep(1) + expect(fetch).toHaveBeenCalledTimes(2) + expect(reconciled).not.toHaveBeenCalled() + expect(queryClient.invalidateQueries).not.toHaveBeenCalled() + expect(clearChat).not.toHaveBeenCalled() + pending.resolve(jsonResponse({ success: true })) + await observed + await expect(result).rejects.toThrow() + expect(queryClient.invalidateQueries).toHaveBeenCalledExactlyOnceWith({ + queryKey: ['mothership-chats', 'list', 'organization', 'org-1'], + }) + expect(clearChat).toHaveBeenCalledExactlyOnceWith('chat-slow') + expect(queryClient.removeQueries).toHaveBeenCalledExactlyOnceWith({ + queryKey: ['mothership-chats', 'detail', 'chat-slow'], + }) + }) + it('suspends each successful bulk delete even when a sibling delete fails', async () => { const mutation = useDeleteMothershipChats('workspace-1') as unknown as { mutationFn: (chatIds: string[]) => Promise @@ -268,5 +318,13 @@ describe('tasks query boundary parsing', () => { expect(suspendTerminalScope).toHaveBeenCalledWith('chat-a') expect(suspendBrowserScope).not.toHaveBeenCalledWith('chat-b') expect(suspendTerminalScope).not.toHaveBeenCalledWith('chat-b') + expect(clearChat).toHaveBeenCalledWith('chat-a') + expect(clearChat).not.toHaveBeenCalledWith('chat-b') + expect(queryClient.removeQueries).toHaveBeenCalledWith({ + queryKey: ['mothership-chats', 'detail', 'chat-a'], + }) + expect(queryClient.removeQueries).not.toHaveBeenCalledWith({ + queryKey: ['mothership-chats', 'detail', 'chat-b'], + }) }) }) diff --git a/apps/sim/hooks/queries/mothership-chats.ts b/apps/sim/hooks/queries/mothership-chats.ts index dcaadc0f2ee..f076f468bce 100644 --- a/apps/sim/hooks/queries/mothership-chats.ts +++ b/apps/sim/hooks/queries/mothership-chats.ts @@ -273,7 +273,6 @@ export function useOrganizationMothershipChats( return data.data.map(mapChat) }, staleTime: MOTHERSHIP_CHAT_LIST_STALE_TIME, - refetchInterval: (query) => (query.state.data?.some((chat) => chat.isActive) ? 5_000 : false), }) } @@ -337,12 +336,12 @@ export function useDeleteMothershipChat(owner?: MothershipChatOwner) { mutationFn: deleteChat, onSuccess: async (_data, chatId) => { await suspendDesktopChatScopes(chatId) - }, - onSettled: (_data, _error, chatId) => { - queryClient.invalidateQueries({ queryKey: mothershipChatKeys.ownerLists(owner) }) queryClient.removeQueries({ queryKey: mothershipChatKeys.detail(chatId) }) useMothershipQueueStore.getState().clearChat(chatId) }, + onSettled: () => { + queryClient.invalidateQueries({ queryKey: mothershipChatKeys.ownerLists(owner) }) + }, }) } @@ -374,24 +373,20 @@ export function useDeleteMothershipChats(owner?: MothershipChatOwner) { const queryClient = useQueryClient() return useMutation({ mutationFn: async (chatIds: string[]) => { - // Couple each successful DELETE to its own native suspension. If one - // sibling request fails, Promise.all rejects but the independently - // successful tasks still stop their pages and PTYs instead of being - // stranded live behind the aggregate onSuccess callback. - await Promise.all( + /** Reconcile only after every request settles, while cleaning up only deleted chats. */ + const results = await Promise.allSettled( chatIds.map(async (chatId) => { await deleteChat(chatId) await suspendDesktopChatScopes(chatId) + queryClient.removeQueries({ queryKey: mothershipChatKeys.detail(chatId) }) + useMothershipQueueStore.getState().clearChat(chatId) }) ) + const failed = results.find((result) => result.status === 'rejected') + if (failed) throw failed.reason }, - onSettled: (_data, _error, chatIds) => { + onSettled: () => { queryClient.invalidateQueries({ queryKey: mothershipChatKeys.ownerLists(owner) }) - const queueStore = useMothershipQueueStore.getState() - for (const chatId of chatIds) { - queryClient.removeQueries({ queryKey: mothershipChatKeys.detail(chatId) }) - queueStore.clearChat(chatId) - } }, }) } diff --git a/apps/sim/hooks/use-mothership-chat-events-lifecycle.test.tsx b/apps/sim/hooks/use-mothership-chat-events-lifecycle.test.tsx new file mode 100644 index 00000000000..bcf078e3583 --- /dev/null +++ b/apps/sim/hooks/use-mothership-chat-events-lifecycle.test.tsx @@ -0,0 +1,115 @@ +/** @vitest-environment jsdom */ + +import { act } from 'react' +import { QueryClient, QueryClientProvider } from '@tanstack/react-query' +import { createRoot } from 'react-dom/client' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import type { MothershipChatOwner } from '@/hooks/queries/mothership-chats' +import { mothershipChatKeys } from '@/hooks/queries/mothership-chats' + +const { connect, close, deployment } = vi.hoisted(() => ({ + connect: vi.fn(), + close: vi.fn(), + deployment: { chatEnabled: true }, +})) +vi.mock('@/lib/events/rotating-event-source', () => ({ createRotatingEventSource: connect })) + +import { useMothershipChatEvents } from '@/hooks/use-mothership-chat-events' + +function EventSubscriber({ owner }: { owner: MothershipChatOwner | undefined }) { + useMothershipChatEvents(owner, deployment.chatEnabled) + return null +} + +function renderEvents(owner: MothershipChatOwner | undefined) { + const client = new QueryClient({ defaultOptions: { queries: { retry: false } } }) + const invalidate = vi.spyOn(client, 'invalidateQueries') + const container = document.createElement('div') + document.body.appendChild(container) + const root = createRoot(container) + const rerender = ({ owner }: { owner: MothershipChatOwner | undefined }) => { + act(() => + root.render( + + + + ) + ) + } + rerender({ owner }) + return { + invalidate, + client, + rerender, + unmount: () => { + act(() => root.unmount()) + container.remove() + }, + } +} + +describe('chat event subscription lifecycle', () => { + beforeEach(() => { + vi.clearAllMocks() + vi.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true) + deployment.chatEnabled = true + connect.mockReturnValue({ close }) + }) + afterEach(() => { + vi.restoreAllMocks() + vi.unstubAllGlobals() + }) + + it('subscribes once for a stable organization, including new owner objects on rerender', () => { + const view = renderEvents({ organizationId: 'org-lifecycle-1' }) + expect(connect).toHaveBeenCalledWith( + expect.objectContaining({ url: '/api/mothership/events?organizationId=org-lifecycle-1' }) + ) + view.rerender({ owner: { organizationId: 'org-lifecycle-1' } }) + expect(connect).toHaveBeenCalledTimes(1) + view.unmount() + expect(close).toHaveBeenCalledTimes(1) + view.client.clear() + }) + + it('reconciles missed changes on reconnect while leaving seamless rotation alone', () => { + const view = renderEvents({ organizationId: 'org-lifecycle-2' }) + const connection = connect.mock.calls[0][0] + act(() => connection.onOpen('initial')) + expect(view.invalidate).not.toHaveBeenCalled() + act(() => connection.onOpen('rotation')) + expect(view.invalidate).not.toHaveBeenCalled() + act(() => connection.onOpen('reconnect')) + expect(view.invalidate).toHaveBeenCalledExactlyOnceWith({ + queryKey: mothershipChatKeys.organizationLists('org-lifecycle-2'), + }) + view.unmount() + view.client.clear() + }) + + it('closes the old scope and reconciles when returning to a previously visited organization', () => { + const view = renderEvents({ organizationId: 'org-lifecycle-3' }) + view.rerender({ owner: 'ws-lifecycle-3' }) + expect(close).toHaveBeenCalledTimes(1) + expect(connect).toHaveBeenLastCalledWith( + expect.objectContaining({ url: '/api/mothership/events?workspaceId=ws-lifecycle-3' }) + ) + view.rerender({ owner: { organizationId: 'org-lifecycle-3' } }) + act(() => connect.mock.calls[2][0].onOpen('initial')) + expect(view.invalidate).toHaveBeenCalledExactlyOnceWith({ + queryKey: mothershipChatKeys.organizationLists('org-lifecycle-3'), + }) + view.unmount() + view.client.clear() + }) + + it('does not subscribe without an owner or when chat is disabled', () => { + const view = renderEvents(undefined) + expect(connect).not.toHaveBeenCalled() + deployment.chatEnabled = false + view.rerender({ owner: { organizationId: 'org-disabled' } }) + expect(connect).not.toHaveBeenCalled() + view.unmount() + view.client.clear() + }) +}) diff --git a/apps/sim/hooks/use-mothership-chat-events.test.ts b/apps/sim/hooks/use-mothership-chat-events.test.ts index fb01186b06c..4ccfdf50148 100644 --- a/apps/sim/hooks/use-mothership-chat-events.test.ts +++ b/apps/sim/hooks/use-mothership-chat-events.test.ts @@ -415,6 +415,27 @@ describe('handleMothershipChatStatusEvent', () => { expect(queryClient.removeQueries).not.toHaveBeenCalled() }) + it.each(['created', 'updated', 'renamed', 'started', 'completed', 'deleted'])( + 'invalidates only organization lists for organization %s events', + (type) => { + handleMothershipChatStatusEvent( + queryClient, + { organizationId: 'org-1' }, + { chatId: 'chat-1', type } + ) + expect(queryClient.invalidateQueries).toHaveBeenCalledWith({ + queryKey: mothershipChatKeys.organizationLists('org-1'), + }) + expect(queryClient.invalidateQueries).not.toHaveBeenCalledWith({ + queryKey: mothershipChatKeys.workspaceLists('org-1'), + }) + if (type === 'deleted') + expect(queryClient.removeQueries).toHaveBeenCalledWith({ + queryKey: mothershipChatKeys.detail('chat-1'), + }) + } + ) + it('does not invalidate when task event payload is invalid', () => { handleMothershipChatStatusEvent(queryClient, 'ws-1', '{') @@ -441,6 +462,13 @@ describe('resyncMothershipChatCaches', () => { }) }) + it('reconciles active and archived organization lists after reconnect', () => { + resyncMothershipChatCaches(queryClient, { organizationId: 'org-1' }) + expect(queryClient.invalidateQueries).toHaveBeenCalledExactlyOnceWith({ + queryKey: mothershipChatKeys.organizationLists('org-1'), + }) + }) + it('leaves chat details untouched so a mounted stream cannot be refetched mid-turn', () => { resyncMothershipChatCaches(queryClient, 'ws-1') diff --git a/apps/sim/hooks/use-mothership-chat-events.ts b/apps/sim/hooks/use-mothership-chat-events.ts index 2d1a9d91717..6d2a17ecda0 100644 --- a/apps/sim/hooks/use-mothership-chat-events.ts +++ b/apps/sim/hooks/use-mothership-chat-events.ts @@ -3,17 +3,27 @@ import { createLogger } from '@sim/logger' import type { QueryClient } from '@tanstack/react-query' import { useQueryClient } from '@tanstack/react-query' import { getLiveAssistantMessageId } from '@/lib/copilot/chat/effective-transcript' -import { useDeploymentShape } from '@/lib/core/config/deployment-shape' import { suspendDesktopChatScopes } from '@/lib/desktop/chat-scope' import { createRotatingEventSource } from '@/lib/events/rotating-event-source' -import { type MothershipChatHistory, mothershipChatKeys } from '@/hooks/queries/mothership-chats' +import { + type MothershipChatHistory, + type MothershipChatOwner, + mothershipChatKeys, +} from '@/hooks/queries/mothership-chats' const logger = createLogger('MothershipChatEvents') -/** Workspaces this process has subscribed to before, so a re-subscribe can be told from a first one. */ +/** Owner scopes this process subscribed to, so returning to a scope reconciles missed events. */ const everSubscribed = new Set() -const CHAT_STATUS_TYPES = ['started', 'completed', 'created', 'deleted', 'renamed'] as const +const CHAT_STATUS_TYPES = [ + 'started', + 'completed', + 'created', + 'deleted', + 'renamed', + 'updated', +] as const type ChatStatusEventType = (typeof CHAT_STATUS_TYPES)[number] const CHAT_STATUS_TYPE_SET = new Set(CHAT_STATUS_TYPES) @@ -98,7 +108,7 @@ function parseChatStatusEventPayload(data: unknown): ChatStatusEventPayload | nu export function handleMothershipChatStatusEvent( queryClient: Pick, - workspaceId: string, + owner: MothershipChatOwner, data: unknown ): void { const payload = parseChatStatusEventPayload(data) @@ -107,9 +117,8 @@ export function handleMothershipChatStatusEvent( return } - // workspaceLists covers both the active and archived (Recently Deleted) - // lists: delete/restore events move chats between the two scopes. - queryClient.invalidateQueries({ queryKey: mothershipChatKeys.workspaceLists(workspaceId) }) + /** Delete and restore move chats between active and archived owner lists. */ + queryClient.invalidateQueries({ queryKey: mothershipChatKeys.ownerLists(owner) }) if (!payload.chatId) return if (payload.type === 'deleted') { // A task may be deleted from another window, browser, or device. Stop its @@ -149,9 +158,9 @@ export function handleMothershipChatStatusEvent( */ export function resyncMothershipChatCaches( queryClient: Pick, - workspaceId: string + owner: MothershipChatOwner ): void { - queryClient.invalidateQueries({ queryKey: mothershipChatKeys.workspaceLists(workspaceId) }) + queryClient.invalidateQueries({ queryKey: mothershipChatKeys.ownerLists(owner) }) } /** @@ -162,38 +171,46 @@ export function resyncMothershipChatCaches( * without the guard every session would hold an open connection to an endpoint * that cannot serve it. */ -export function useMothershipChatEvents(workspaceId: string | undefined) { +export function useMothershipChatEvents( + owner: MothershipChatOwner | undefined, + chatEnabled: boolean +) { const queryClient = useQueryClient() - const { chatEnabled } = useDeploymentShape() + const workspaceId = typeof owner === 'string' ? owner : undefined + const organizationId = typeof owner === 'object' ? owner.organizationId : undefined useEffect(() => { - if (!workspaceId || !chatEnabled) return - - const isResubscribe = everSubscribed.has(workspaceId) - everSubscribed.add(workspaceId) + if ((!workspaceId && !organizationId) || !chatEnabled) return + + const eventOwner = organizationId ? { organizationId } : workspaceId! + const ownerParam = organizationId + ? `organizationId=${encodeURIComponent(organizationId)}` + : `workspaceId=${encodeURIComponent(workspaceId!)}` + const isResubscribe = everSubscribed.has(ownerParam) + everSubscribed.add(ownerParam) const connection = createRotatingEventSource({ - url: `/api/mothership/events?workspaceId=${encodeURIComponent(workspaceId)}`, + url: `/api/mothership/events?${ownerParam}`, events: { task_status: (event) => { handleMothershipChatStatusEvent( queryClient, - workspaceId, + eventOwner, event instanceof MessageEvent ? event.data : undefined ) }, }, onOpen: (reason) => { if (reason === 'reconnect' || (reason === 'initial' && isResubscribe)) { - resyncMothershipChatCaches(queryClient, workspaceId) + resyncMothershipChatCaches(queryClient, eventOwner) } }, onError: () => { - logger.warn(`SSE connection error for workspace ${workspaceId}`) + logger.warn('Chat status SSE connection error') }, }) return () => { connection.close() } - }, [workspaceId, queryClient, chatEnabled]) + }, [workspaceId, organizationId, queryClient, chatEnabled]) } diff --git a/apps/sim/hooks/use-workspace-order.ts b/apps/sim/hooks/use-workspace-order.ts new file mode 100644 index 00000000000..6d3438607ec --- /dev/null +++ b/apps/sim/hooks/use-workspace-order.ts @@ -0,0 +1,22 @@ +'use client' + +import { useMemo, useSyncExternalStore } from 'react' +import { WorkspaceRecencyStorage } from '@/lib/core/utils/browser-storage' +import type { Workspace } from '@/hooks/queries/workspace' + +const serverSnapshot = () => null + +/** Layers the viewer's pins and visit history over the server's newest-first list. */ +export function useWorkspaceOrder(workspaces: Workspace[], pinnedIds: ReadonlySet) { + const recencySnapshot = useSyncExternalStore( + WorkspaceRecencyStorage.subscribe, + WorkspaceRecencyStorage.getSnapshot, + serverSnapshot + ) + return useMemo(() => { + const byRecency = recencySnapshot + ? WorkspaceRecencyStorage.sortByRecency(workspaces) + : workspaces + return [...byRecency].sort((a, b) => Number(pinnedIds.has(b.id)) - Number(pinnedIds.has(a.id))) + }, [workspaces, pinnedIds, recencySnapshot]) +} diff --git a/apps/sim/lib/api/contracts/mothership-chats.ts b/apps/sim/lib/api/contracts/mothership-chats.ts index 8320cb26be5..4c48e8b37b3 100644 --- a/apps/sim/lib/api/contracts/mothership-chats.ts +++ b/apps/sim/lib/api/contracts/mothership-chats.ts @@ -139,11 +139,7 @@ export const mothershipExecuteBodySchema = z.object({ }) export type MothershipExecuteBody = z.input -export const mothershipEventsQuerySchema = z - .object({ - workspaceId: z.string().optional(), - }) - .passthrough() +export const mothershipEventsQuerySchema = mothershipChatOwnerSchema export const mothershipChatGetQuerySchema = z .object({ diff --git a/apps/sim/lib/copilot/chat-status.test.ts b/apps/sim/lib/copilot/chat-status.test.ts new file mode 100644 index 00000000000..1d559dc966a --- /dev/null +++ b/apps/sim/lib/copilot/chat-status.test.ts @@ -0,0 +1,54 @@ +/** @vitest-environment node */ +import { beforeEach, describe, expect, it, vi } from 'vitest' + +const { publish } = vi.hoisted(() => ({ publish: vi.fn() })) +vi.mock('@/lib/events/pubsub', () => ({ + createPubSubChannel: () => ({ publish, subscribe: vi.fn(), dispose: vi.fn() }), +})) + +import { publishChatStatusChanged } from '@/lib/copilot/chat-status' + +describe('chat status ownership', () => { + beforeEach(() => vi.clearAllMocks()) + + it('preserves the workspace event shape', () => { + publishChatStatusChanged( + { workspaceId: 'ws-1', userId: 'user-1' }, + { chatId: 'chat-1', type: 'renamed' } + ) + expect(publish).toHaveBeenCalledWith({ workspaceId: 'ws-1', chatId: 'chat-1', type: 'renamed' }) + }) + + it.each(['created', 'updated', 'renamed', 'deleted', 'started', 'completed'] as const)( + 'binds %s events to the organization and private chat owner', + (type) => { + publishChatStatusChanged( + { organizationId: 'org-1', userId: 'user-1' }, + { chatId: 'chat-1', type } + ) + expect(publish).toHaveBeenCalledWith({ + organizationId: 'org-1', + userId: 'user-1', + chatId: 'chat-1', + type, + }) + } + ) + + it('does not broadcast an organization event without its private owner', () => { + expect(() => + publishChatStatusChanged({ organizationId: 'org-1' }, { chatId: 'chat-1', type: 'created' }) + ).toThrow('Invalid organization chat owner') + expect(publish).not.toHaveBeenCalled() + }) + + it('refuses ambiguous workspace and organization ownership', () => { + expect(() => + publishChatStatusChanged( + { workspaceId: 'ws-1', organizationId: 'org-1', userId: 'user-1' }, + { chatId: 'chat-1', type: 'created' } + ) + ).toThrow('Invalid organization chat owner') + expect(publish).not.toHaveBeenCalled() + }) +}) diff --git a/apps/sim/lib/copilot/chat-status.ts b/apps/sim/lib/copilot/chat-status.ts index 221eb20ac9f..3fb5edf163c 100644 --- a/apps/sim/lib/copilot/chat-status.ts +++ b/apps/sim/lib/copilot/chat-status.ts @@ -11,10 +11,13 @@ import { createPubSubChannel, type PubSubChannel } from '@/lib/events/pubsub' -interface ChatStatusEvent { - workspaceId: string +export type ChatStatusOwner = + | { workspaceId: string; organizationId?: never; userId?: never } + | { organizationId: string; userId: string; workspaceId?: never } + +export type ChatStatusEvent = ChatStatusOwner & { chatId: string - type: 'started' | 'completed' | 'created' | 'deleted' | 'renamed' + type: 'started' | 'completed' | 'created' | 'deleted' | 'renamed' | 'updated' streamId?: string } @@ -40,3 +43,20 @@ export const chatPubSub = channel dispose: () => channel.dispose(), } : null + +/** Projects canonical chat ownership into the same status channel for both surfaces. */ +export function publishChatStatusChanged( + chat: { workspaceId?: string | null; organizationId?: string | null; userId?: string | null }, + event: Pick +): void { + if (chat.organizationId) { + if (!chat.userId || chat.workspaceId) throw new Error('Invalid organization chat owner') + chatPubSub?.publishStatusChanged({ + organizationId: chat.organizationId, + userId: chat.userId, + ...event, + }) + } else if (chat.workspaceId) { + chatPubSub?.publishStatusChanged({ workspaceId: chat.workspaceId, ...event }) + } +} diff --git a/apps/sim/lib/copilot/chat/organization-chats.test.ts b/apps/sim/lib/copilot/chat/organization-chats.test.ts index 72194d9cec4..f5540d89d0e 100644 --- a/apps/sim/lib/copilot/chat/organization-chats.test.ts +++ b/apps/sim/lib/copilot/chat/organization-chats.test.ts @@ -2,10 +2,22 @@ import { dbChainMockFns, resetDbChainMock } from '@sim/testing' import { beforeEach, describe, expect, it, vi } from 'vitest' import { createTrustedOrganizationCopilotPrincipal } from '@/lib/copilot/auth/application-delegation' -import { authorizeOrganizationChatDelegation } from '@/lib/copilot/chat/organization-chats' +import { + authorizeOrganizationChatDelegation, + authorizeOrganizationChatEvents, + createOrganizationChat, +} from '@/lib/copilot/chat/organization-chats' import { OrchestrationError } from '@/lib/core/orchestration/types' -const { authorize } = vi.hoisted(() => ({ authorize: vi.fn() })) +const { authorize, requireSearch, publish } = vi.hoisted(() => ({ + authorize: vi.fn(), + requireSearch: vi.fn(), + publish: vi.fn(), +})) +vi.mock('@/lib/knowledge/access/availability', () => ({ + requireOrganizationSearchAvailable: requireSearch, +})) +vi.mock('@/lib/copilot/chat-status', () => ({ publishChatStatusChanged: publish })) vi.mock('@/lib/core/application/organization-authorization', () => ({ authorizeOrganizationOperation: authorize, })) @@ -64,3 +76,62 @@ describe('private organization chat delegation', () => { expect(authorize).not.toHaveBeenCalled() }) }) + +describe('organization chat events application boundary', () => { + const principal = { kind: 'session', userId: 'member-1', sessionId: 'session-1' } as const + beforeEach(() => { + vi.clearAllMocks() + resetDbChainMock() + authorize.mockResolvedValue({ userId: 'member-1', organizationId: 'org-1', role: 'member' }) + requireSearch.mockResolvedValue(undefined) + }) + + it('authorizes current membership before reading the feature rollout', async () => { + await authorizeOrganizationChatEvents.execute({ principal, input: { organizationId: 'org-1' } }) + expect(authorize).toHaveBeenCalledWith( + principal, + expect.objectContaining({ + id: 'organization.chats.subscribe', + principalKinds: ['session'], + minimumRole: 'member', + capability: 'copilot.use', + }), + { organizationId: 'org-1' } + ) + expect(requireSearch).toHaveBeenCalledWith('org-1') + expect(authorize.mock.invocationCallOrder[0]).toBeLessThan( + requireSearch.mock.invocationCallOrder[0] + ) + }) + + it('does not examine rollout state for a non-member', async () => { + authorize.mockRejectedValueOnce(new OrchestrationError('not_found', 'Organization not found')) + await expect( + authorizeOrganizationChatEvents.execute({ principal, input: { organizationId: 'org-1' } }) + ).rejects.toThrow('Organization not found') + expect(requireSearch).not.toHaveBeenCalled() + }) + + it('propagates rollout revocation and infrastructure failures', async () => { + requireSearch.mockRejectedValueOnce(new OrchestrationError('forbidden', 'Search is disabled')) + await expect( + authorizeOrganizationChatEvents.execute({ principal, input: { organizationId: 'org-1' } }) + ).rejects.toThrow('Search is disabled') + authorize.mockRejectedValueOnce(new Error('database unavailable')) + await expect( + authorizeOrganizationChatEvents.execute({ principal, input: { organizationId: 'org-1' } }) + ).rejects.toThrow('database unavailable') + }) + + it('publishes newly created chats only after persistence and under the canonical owner', async () => { + dbChainMockFns.returning.mockResolvedValueOnce([{ id: 'new-chat' }]) + await createOrganizationChat.execute({ principal, input: { organizationId: 'org-1' } }) + expect(publish).toHaveBeenCalledWith( + { organizationId: 'org-1', userId: 'member-1', role: 'member' }, + { chatId: 'new-chat', type: 'created' } + ) + expect(dbChainMockFns.returning.mock.invocationCallOrder[0]).toBeLessThan( + publish.mock.invocationCallOrder[0] + ) + }) +}) diff --git a/apps/sim/lib/copilot/chat/organization-chats.ts b/apps/sim/lib/copilot/chat/organization-chats.ts index 4cb3d7dcb3c..242f3ab68c8 100644 --- a/apps/sim/lib/copilot/chat/organization-chats.ts +++ b/apps/sim/lib/copilot/chat/organization-chats.ts @@ -4,12 +4,20 @@ import { copilotChats } from '@sim/db/schema' import { and, eq, isNull } from 'drizzle-orm' import type { MothershipChatScope } from '@/lib/api/contracts/mothership-chats' import { listMothershipChats } from '@/lib/copilot/chat/list-mothership-chats' +import { publishChatStatusChanged } from '@/lib/copilot/chat-status' import { MOTHERSHIP_CHAT_DEFAULT_MODEL } from '@/lib/copilot/constants' import { authorizeOrganizationOperation } from '@/lib/core/application/organization-authorization' import { defineOrganizationOperation } from '@/lib/core/application/organization-operation' import { OrchestrationError } from '@/lib/core/orchestration/types' +import { requireOrganizationSearchAvailable } from '@/lib/knowledge/access/availability' export const organizationChatOperations = { + subscribe: defineOrganizationOperation({ + id: 'organization.chats.subscribe', + minimumRole: 'member', + principalKinds: ['session'], + capability: 'copilot.use', + }), read: defineOrganizationOperation({ id: 'organization.chats.read', minimumRole: 'member', @@ -42,6 +50,20 @@ export const authorizeOrganizationChat = { }, } +/** Revalidates the organization surface's rollout and private-chat membership for live updates. */ +export const authorizeOrganizationChatEvents = { + operation: organizationChatOperations.subscribe, + async execute({ principal, input }: { principal: Principal; input: OrganizationChatInput }) { + const context = await authorizeOrganizationOperation( + principal, + organizationChatOperations.subscribe, + input + ) + await requireOrganizationSearchAvailable(context.organizationId) + return context + }, +} + export const listOrganizationChats = { operation: organizationChatOperations.list, async execute({ @@ -83,6 +105,7 @@ export const createOrganizationChat = { }) .returning({ id: copilotChats.id }) if (!chat) throw new Error('Failed to create organization conversation') + publishChatStatusChanged(context, { chatId: chat.id, type: 'created' }) return chat }, } diff --git a/apps/sim/lib/copilot/chat/post.test.ts b/apps/sim/lib/copilot/chat/post.test.ts index a06b91590d8..e2a2e6fcd68 100644 --- a/apps/sim/lib/copilot/chat/post.test.ts +++ b/apps/sim/lib/copilot/chat/post.test.ts @@ -198,9 +198,7 @@ vi.mock('@/lib/copilot/resources/persistence', () => ({ vi.mock('@/lib/permission-groups/config-scope.server', () => permissionGroupScopeMock) vi.mock('@/lib/copilot/chat-status', () => ({ - chatPubSub: { - publishStatusChanged: mockPublishStatusChanged, - }, + publishChatStatusChanged: mockPublishStatusChanged, })) import { chatOperations } from '@/lib/copilot/application/operations' @@ -479,6 +477,46 @@ describe('handleUnifiedChatPost', () => { expect(resolveOrCreateChat).not.toHaveBeenCalled() }) + it('broadcasts organization turn start, completion, and failure under its private owner', async () => { + getSession.mockResolvedValue({ user: { id: 'user-1' }, session: { id: 'session-1' } }) + dbChainMockFns.returning.mockResolvedValueOnce([{ model: 'mothership' }]) + const response = await handleUnifiedChatPost( + new NextRequest('http://localhost/api/mothership/chat', { + method: 'POST', + body: JSON.stringify({ + message: 'Find the policy', + organizationId: 'org-1', + mode: 'assistant', + }), + }) + ) + expect(response.status).toBe(200) + const args = createSSEStream.mock.calls[0][0] + const owner = { organizationId: 'org-1', userId: 'user-1', workspaceId: undefined } + expect(mockPublishStatusChanged).toHaveBeenCalledWith(owner, { + chatId: 'chat-1', + type: 'started', + streamId: args.streamId, + }) + await args.orchestrateOptions.onComplete({ + success: true, + content: 'Answer', + contentBlocks: [], + toolCalls: [], + }) + expect(mockPublishStatusChanged).toHaveBeenLastCalledWith(owner, { + chatId: 'chat-1', + type: 'completed', + streamId: args.streamId, + }) + await args.orchestrateOptions.onError(new Error('provider failed')) + expect(mockPublishStatusChanged).toHaveBeenLastCalledWith(owner, { + chatId: 'chat-1', + type: 'completed', + streamId: args.streamId, + }) + }) + it.each([{ workspaceId: 'ws-1' }, { workflowId: 'wf-1' }, { mode: 'agent' }])( 'rejects mixed organization scope before persistence: %j', async (extra) => { @@ -1207,12 +1245,14 @@ describe('handleUnifiedChatPost', () => { requestId: 'request-1', }) - expect(mockPublishStatusChanged).toHaveBeenCalledWith({ - workspaceId: 'ws-1', - chatId: 'chat-1', - type: 'completed', - streamId: streamArgs?.streamId, - }) + expect(mockPublishStatusChanged).toHaveBeenCalledWith( + expect.objectContaining({ workspaceId: 'ws-1' }), + { + chatId: 'chat-1', + type: 'completed', + streamId: streamArgs?.streamId, + } + ) }) it('rejects requests that have neither workflow nor workspace attachment', async () => { diff --git a/apps/sim/lib/copilot/chat/post.ts b/apps/sim/lib/copilot/chat/post.ts index 77b1570cb8d..282393fa1cd 100644 --- a/apps/sim/lib/copilot/chat/post.ts +++ b/apps/sim/lib/copilot/chat/post.ts @@ -48,7 +48,7 @@ import { } from '@/lib/copilot/chat/selection-context' import { finalizeAssistantTurn } from '@/lib/copilot/chat/terminal-state' import { generateWorkspaceSnapshot } from '@/lib/copilot/chat/workspace-context' -import { chatPubSub } from '@/lib/copilot/chat-status' +import { publishChatStatusChanged } from '@/lib/copilot/chat-status' import { COPILOT_REQUEST_MODES } from '@/lib/copilot/constants' import { computeWorkspaceEntitlements } from '@/lib/copilot/entitlements' import { prepareCopilotEnvironmentContext } from '@/lib/copilot/environment-context' @@ -362,7 +362,7 @@ type UnifiedChatBranch = goRoute: '/api/copilot' titleModel: string titleProvider?: string - notifyWorkspaceStatus: false + notifyChatStatus: false buildPayload: (params: { message: string userId: string @@ -408,7 +408,7 @@ type UnifiedChatBranch = goRoute: '/api/mothership' titleModel: string titleProvider?: undefined - notifyWorkspaceStatus: boolean + notifyChatStatus: boolean buildPayload: (params: { message: string userId: string @@ -578,7 +578,9 @@ async function persistUserMessage(params: { fileAttachments?: UnifiedChatRequest['fileAttachments'] contexts?: UnifiedChatRequest['contexts'] workspaceId?: string - notifyWorkspaceStatus: boolean + notifyChatStatus: boolean + organizationId?: string + userId?: string requestMode?: 'assistant' | 'agent' /** * Root context for the mothership request. When present the persist @@ -597,7 +599,9 @@ async function persistUserMessage(params: { fileAttachments, contexts, workspaceId, - notifyWorkspaceStatus, + organizationId, + userId, + notifyChatStatus, parentOtelContext, } = params if (!chatId) return @@ -649,13 +653,15 @@ async function persistUserMessage(params: { updated ? CopilotChatPersistOutcome.Appended : CopilotChatPersistOutcome.ChatNotFound ) - if (notifyWorkspaceStatus && updated && workspaceId) { - chatPubSub?.publishStatusChanged({ - workspaceId, - chatId, - type: 'started', - streamId: userMessageId, - }) + if (notifyChatStatus && updated) { + publishChatStatusChanged( + { workspaceId, organizationId, userId }, + { + chatId, + type: 'started', + streamId: userMessageId, + } + ) } }, parentOtelContext @@ -724,7 +730,9 @@ function buildOnComplete(params: { userMessageId: string requestId: string workspaceId?: string - notifyWorkspaceStatus: boolean + notifyChatStatus: boolean + organizationId?: string + userId?: string requestMode?: 'assistant' | 'agent' /** * Root agent span for this request. When present, the final @@ -740,7 +748,16 @@ function buildOnComplete(params: { }) => void } }) { - const { chatId, userMessageId, requestId, workspaceId, notifyWorkspaceStatus, otelRoot } = params + const { + chatId, + userMessageId, + requestId, + workspaceId, + organizationId, + userId, + notifyChatStatus, + otelRoot, + } = params return async (result: OrchestratorResult) => { if (otelRoot && result.success) { @@ -770,13 +787,15 @@ function buildOnComplete(params: { finalization.updated || finalization.outcome === CopilotChatFinalizeOutcome.AssistantAlreadyPersisted - if (notifyWorkspaceStatus && workspaceId && shouldPublishCompletion) { - chatPubSub?.publishStatusChanged({ - workspaceId, - chatId, - type: 'completed', - streamId: userMessageId, - }) + if (notifyChatStatus && shouldPublishCompletion) { + publishChatStatusChanged( + { workspaceId, organizationId, userId }, + { + chatId, + type: 'completed', + streamId: userMessageId, + } + ) } return } @@ -796,13 +815,15 @@ function buildOnComplete(params: { ...(result.success ? {} : { streamMarkerPolicy: 'active-or-cleared' as const }), }) - if (notifyWorkspaceStatus && workspaceId) { - chatPubSub?.publishStatusChanged({ - workspaceId, - chatId, - type: 'completed', - streamId: userMessageId, - }) + if (notifyChatStatus) { + publishChatStatusChanged( + { workspaceId, organizationId, userId }, + { + chatId, + type: 'completed', + streamId: userMessageId, + } + ) } } catch (error) { logger.error(`[${requestId}] Failed to persist chat messages`, { @@ -818,10 +839,20 @@ function buildOnError(params: { userMessageId: string requestId: string workspaceId?: string - notifyWorkspaceStatus: boolean + notifyChatStatus: boolean + organizationId?: string + userId?: string requestMode?: 'assistant' | 'agent' }) { - const { chatId, userMessageId, requestId, workspaceId, notifyWorkspaceStatus } = params + const { + chatId, + userMessageId, + requestId, + workspaceId, + organizationId, + userId, + notifyChatStatus, + } = params return async (_error: Error, result?: OrchestratorResult) => { if (!chatId) return @@ -843,13 +874,15 @@ function buildOnError(params: { streamMarkerPolicy: 'active-or-cleared', }) - if (notifyWorkspaceStatus && workspaceId) { - chatPubSub?.publishStatusChanged({ - workspaceId, - chatId, - type: 'completed', - streamId: userMessageId, - }) + if (notifyChatStatus) { + publishChatStatusChanged( + { workspaceId, organizationId, userId }, + { + chatId, + type: 'completed', + streamId: userMessageId, + } + ) } } catch (error) { logger.error(`[${requestId}] Failed to finalize errored chat stream`, { @@ -898,7 +931,7 @@ async function resolveBranch(params: { effectiveModel: DEFAULT_MODEL, goRoute: '/api/mothership', titleModel: DEFAULT_MODEL, - notifyWorkspaceStatus: false, + notifyChatStatus: true, buildPayload: async (payloadParams) => buildCopilotRequestPayload( { @@ -948,7 +981,7 @@ async function resolveBranch(params: { goRoute: '/api/copilot', titleModel: selectedModel, titleProvider: provider, - notifyWorkspaceStatus: false, + notifyChatStatus: false, buildPayload: async (payloadParams) => buildCopilotRequestPayload( { @@ -1017,7 +1050,7 @@ async function resolveBranch(params: { effectiveModel: DEFAULT_MODEL, goRoute: '/api/mothership', titleModel: DEFAULT_MODEL, - notifyWorkspaceStatus: true, + notifyChatStatus: true, buildPayload: async (payloadParams) => buildCopilotRequestPayload( { @@ -1508,7 +1541,9 @@ export async function handleUnifiedChatPost(req: NextRequest) { fileAttachments, contexts: normalizedContexts, workspaceId, - notifyWorkspaceStatus: branch.notifyWorkspaceStatus, + notifyChatStatus: branch.notifyChatStatus, + organizationId: branch.kind === 'organization' ? branch.organizationId : undefined, + userId: authenticatedUserId, requestMode: body.mode === 'assistant' ? 'assistant' : 'agent', parentOtelContext: activeOtelRoot.context, }) @@ -1658,7 +1693,9 @@ export async function handleUnifiedChatPost(req: NextRequest) { userMessageId, requestId, workspaceId, - notifyWorkspaceStatus: branch.notifyWorkspaceStatus, + notifyChatStatus: branch.notifyChatStatus, + organizationId: branch.kind === 'organization' ? branch.organizationId : undefined, + userId: authenticatedUserId, requestMode: body.mode === 'assistant' ? 'assistant' : 'agent', otelRoot, }), @@ -1667,7 +1704,9 @@ export async function handleUnifiedChatPost(req: NextRequest) { userMessageId, requestId, workspaceId, - notifyWorkspaceStatus: branch.notifyWorkspaceStatus, + notifyChatStatus: branch.notifyChatStatus, + organizationId: branch.kind === 'organization' ? branch.organizationId : undefined, + userId: authenticatedUserId, requestMode: body.mode === 'assistant' ? 'assistant' : 'agent', }), }, diff --git a/apps/sim/lib/copilot/request/lifecycle/start.test.ts b/apps/sim/lib/copilot/request/lifecycle/start.test.ts index e50486707e6..e02f5c2d8ce 100644 --- a/apps/sim/lib/copilot/request/lifecycle/start.test.ts +++ b/apps/sim/lib/copilot/request/lifecycle/start.test.ts @@ -119,7 +119,7 @@ vi.mock('@/lib/copilot/request/session/sse', () => ({ })) vi.mock('@/lib/copilot/chat-status', () => ({ - chatPubSub: null, + publishChatStatusChanged: vi.fn(), })) vi.mock('@/lib/copilot/request/go/fetch', () => ({ diff --git a/apps/sim/lib/copilot/request/lifecycle/start.ts b/apps/sim/lib/copilot/request/lifecycle/start.ts index b5ee96d37a6..43ccf62da93 100644 --- a/apps/sim/lib/copilot/request/lifecycle/start.ts +++ b/apps/sim/lib/copilot/request/lifecycle/start.ts @@ -12,7 +12,7 @@ import { resolveOrganizationBillingAttribution, } from '@/lib/billing/core/billing-attribution' import { createRunSegment } from '@/lib/copilot/async-runs/repository' -import { chatPubSub } from '@/lib/copilot/chat-status' +import { publishChatStatusChanged } from '@/lib/copilot/chat-status' import { MothershipStreamV1EventType, MothershipStreamV1SessionKind, @@ -512,13 +512,7 @@ function fireTitleGeneration(params: { type: MothershipStreamV1EventType.session, payload: { kind: MothershipStreamV1SessionKind.title, title }, }) - if (workspaceId) { - chatPubSub?.publishStatusChanged({ - workspaceId, - chatId, - type: 'renamed', - }) - } + publishChatStatusChanged({ workspaceId, organizationId, userId }, { chatId, type: 'renamed' }) }) .catch((error) => { logger.error(`[${requestId}] Title generation failed:`, error) diff --git a/apps/sim/lib/core/utils/browser-storage.ts b/apps/sim/lib/core/utils/browser-storage.ts index 7103bfa421a..fd5c46fde9a 100644 --- a/apps/sim/lib/core/utils/browser-storage.ts +++ b/apps/sim/lib/core/utils/browser-storage.ts @@ -117,11 +117,39 @@ export const STORAGE_KEYS = { export class WorkspaceRecencyStorage { private static readonly KEY = STORAGE_KEYS.WORKSPACE_RECENCY + private static readonly CHANGE_EVENT = 'workspace-recency-changed' + + static subscribe(onChange: () => void): () => void { + const onStorage = (event: StorageEvent) => { + if (event.key === WorkspaceRecencyStorage.KEY || event.key === null) onChange() + } + window.addEventListener('storage', onStorage) + window.addEventListener(WorkspaceRecencyStorage.CHANGE_EVENT, onChange) + return () => { + window.removeEventListener('storage', onStorage) + window.removeEventListener(WorkspaceRecencyStorage.CHANGE_EVENT, onChange) + } + } + + /** A stable snapshot lets both sidebars follow visits without render-time writes. */ + static getSnapshot(): string | null { + try { + return window.localStorage.getItem(WorkspaceRecencyStorage.KEY) + } catch { + return null + } + } + + private static save(map: Record): void { + if (BrowserStorage.setItem(WorkspaceRecencyStorage.KEY, map)) { + window.dispatchEvent(new Event(WorkspaceRecencyStorage.CHANGE_EVENT)) + } + } static touch(workspaceId: string): void { const map = WorkspaceRecencyStorage.getAll() map[workspaceId] = Date.now() - BrowserStorage.setItem(WorkspaceRecencyStorage.KEY, map) + WorkspaceRecencyStorage.save(map) } static getAll(): Record { @@ -139,7 +167,7 @@ export class WorkspaceRecencyStorage { static remove(workspaceId: string): void { const map = WorkspaceRecencyStorage.getAll() delete map[workspaceId] - BrowserStorage.setItem(WorkspaceRecencyStorage.KEY, map) + WorkspaceRecencyStorage.save(map) } /** @@ -156,7 +184,7 @@ export class WorkspaceRecencyStorage { } } if (pruned) { - BrowserStorage.setItem(WorkspaceRecencyStorage.KEY, map) + WorkspaceRecencyStorage.save(map) } } diff --git a/apps/sim/lib/events/sse-endpoint.ts b/apps/sim/lib/events/sse-endpoint.ts index 63a0111c8d6..9f110e58f08 100644 --- a/apps/sim/lib/events/sse-endpoint.ts +++ b/apps/sim/lib/events/sse-endpoint.ts @@ -5,6 +5,7 @@ * and streams Server-Sent Events with heartbeats and cleanup. */ +import type { SessionPrincipal } from '@sim/auth/principal' import { createLogger } from '@sim/logger' import { getErrorMessage } from '@sim/utils/errors' import { randomFloat } from '@sim/utils/random' @@ -58,11 +59,12 @@ export const ROTATION_GRACE_MS = 30_000 export const MAX_UNDRAINED_CHUNKS = 16 export function createWorkspaceSSE(config: WorkspaceSSEConfig) { - const logger = createLogger(`${config.label}-SSE`) - - return async function GET(request: NextRequest): Promise { - const session = await getSession() - if (!session?.user?.id) { + return async function GET( + request: NextRequest, + authenticatedPrincipal?: SessionPrincipal + ): Promise { + const userId = authenticatedPrincipal?.userId ?? (await getSession())?.user?.id + if (!userId) { return new Response('Unauthorized', { status: 401 }) } @@ -72,115 +74,171 @@ export function createWorkspaceSSE(config: WorkspaceSSEConfig) { return new Response('Missing workspaceId query parameter', { status: 400 }) } - const permissions = await getUserEntityPermissions(session.user.id, 'workspace', workspaceId) + const permissions = await getUserEntityPermissions(userId, 'workspace', workspaceId) if (!permissions) { return new Response('Access denied to workspace', { status: 403 }) } - const teardowns: Array<() => void> = [] - let cleaned = false + return createSSEStream(request, { + label: `${config.label}:workspace:${workspaceId}`, + subscriptions: config.subscriptions.map((subscription) => ({ + subscribe: (send) => subscription.subscribe(workspaceId, send), + })), + }) + } +} + +interface SSEStreamConfig { + label: string + subscriptions: Array<{ + subscribe(send: (eventName: string, data: Record) => void): () => void + }> + /** Rechecks a long-lived authorization before each publication and on heartbeats. */ + revalidate?: () => Promise +} - const cleanup = (reason: string) => { - if (cleaned) return - cleaned = true - for (const teardown of teardowns.splice(0)) { - try { - teardown() - } catch (error) { - logger.warn(`SSE teardown failed for workspace ${workspaceId}`, { - reason, - error: getErrorMessage(error), - }) - } +/** Shared SSE transport; callers authorize their scope before opening the stream. */ +export function createSSEStream(request: NextRequest, config: SSEStreamConfig): Response { + const logger = createLogger(`${config.label}-SSE`) + const teardowns: Array<() => void> = [] + let cleaned = false + + const cleanup = (reason: string) => { + if (cleaned) return + cleaned = true + for (const teardown of teardowns.splice(0)) { + try { + teardown() + } catch (error) { + logger.warn(`SSE teardown failed for ${config.label}`, { + reason, + error: getErrorMessage(error), + }) } - logger.info(`SSE connection closed for workspace ${workspaceId}`, { reason }) } + logger.info(`SSE connection closed for ${config.label}`, { reason }) + } - const stream = new ReadableStream({ - start(controller) { - const close = (reason: string) => { - cleanup(reason) - try { - controller.close() - } catch { - // Already closed - } + const stream = new ReadableStream({ + start(controller) { + const close = (reason: string) => { + cleanup(reason) + try { + controller.close() + } catch { + // Already closed } + } - const enqueue = (payload: string): boolean => { - if (cleaned) return false - try { - controller.enqueue(encoder.encode(payload)) - return true - } catch { - close('errored') - return false - } + const enqueue = (payload: string): boolean => { + if (cleaned) return false + try { + controller.enqueue(encoder.encode(payload)) + return true + } catch { + close('errored') + return false } + } - const send = (eventName: string, data: Record) => { - enqueue(`event: ${eventName}\ndata: ${JSON.stringify(data)}\n\n`) + let authorization: Promise | undefined + const revalidate = (): Promise => { + if (!config.revalidate) return Promise.resolve() + authorization ??= config.revalidate().finally(() => { + authorization = undefined + }) + return authorization + } + let pendingEvents = 0 + const send = (eventName: string, data: Record) => { + if (cleaned) return + const payload = `event: ${eventName}\ndata: ${JSON.stringify(data)}\n\n` + if (!config.revalidate) { + enqueue(payload) + return } - - try { - for (const subscription of config.subscriptions) { - teardowns.push(subscription.subscribe(workspaceId, send)) + if (pendingEvents >= MAX_UNDRAINED_CHUNKS) { + close('authorization_backpressure') + return + } + pendingEvents += 1 + void revalidate().then( + () => { + pendingEvents -= 1 + enqueue(payload) + }, + () => { + pendingEvents -= 1 + close('authorization_lost') } + ) + } - const rotationDeadline = - Date.now() + MAX_CONNECTION_MS + randomFloat() * MAX_CONNECTION_JITTER_MS - let rotationStartedAt: number | null = null + try { + for (const subscription of config.subscriptions) { + teardowns.push(subscription.subscribe(send)) + } - const heartbeat = setInterval(() => { - if (cleaned) { - clearInterval(heartbeat) - return - } + const rotationDeadline = + Date.now() + MAX_CONNECTION_MS + randomFloat() * MAX_CONNECTION_JITTER_MS + let rotationStartedAt: number | null = null - const now = Date.now() - if (rotationStartedAt !== null && now - rotationStartedAt >= ROTATION_GRACE_MS) { - close('rotated') - return - } - if (rotationStartedAt === null && now >= rotationDeadline) { - if (enqueue('event: rotate\ndata: {}\n\n')) { - rotationStartedAt = now - } - return - } + const heartbeat = setInterval(() => { + if (cleaned) { + clearInterval(heartbeat) + return + } - const desiredSize = controller.desiredSize - if (desiredSize !== null && desiredSize <= -MAX_UNDRAINED_CHUNKS) { - close('unread') - return + const now = Date.now() + if (rotationStartedAt !== null && now - rotationStartedAt >= ROTATION_GRACE_MS) { + close('rotated') + return + } + if (rotationStartedAt === null && now >= rotationDeadline) { + if (enqueue('event: rotate\ndata: {}\n\n')) { + rotationStartedAt = now } + return + } + + const desiredSize = controller.desiredSize + if (desiredSize !== null && desiredSize <= -MAX_UNDRAINED_CHUNKS) { + close('unread') + return + } + if (config.revalidate) { + void revalidate().then( + () => enqueue(': heartbeat\n\n'), + () => close('authorization_lost') + ) + } else { enqueue(': heartbeat\n\n') - }, HEARTBEAT_INTERVAL_MS) - teardowns.push(() => clearInterval(heartbeat)) - - const listenerScope = new AbortController() - request.signal.addEventListener('abort', () => close('aborted'), { - once: true, - signal: listenerScope.signal, - }) - teardowns.push(() => listenerScope.abort()) - - logger.info(`SSE connection opened for workspace ${workspaceId}`) - } catch (error) { - cleanup('setup_failed') - logger.error(`Failed to open SSE connection for workspace ${workspaceId}`, { - error: getErrorMessage(error), - }) - try { - controller.error(error) - } catch {} - } - }, - cancel() { - cleanup('cancelled') - }, - }) + } + }, HEARTBEAT_INTERVAL_MS) + teardowns.push(() => clearInterval(heartbeat)) + + const listenerScope = new AbortController() + request.signal.addEventListener('abort', () => close('aborted'), { + once: true, + signal: listenerScope.signal, + }) + teardowns.push(() => listenerScope.abort()) + + logger.info(`SSE connection opened for ${config.label}`) + } catch (error) { + cleanup('setup_failed') + logger.error(`Failed to open SSE connection for ${config.label}`, { + error: getErrorMessage(error), + }) + try { + controller.error(error) + } catch {} + } + }, + cancel() { + cleanup('cancelled') + }, + }) - return new Response(stream, { headers: SSE_HEADERS }) - } + return new Response(stream, { headers: SSE_HEADERS }) } diff --git a/apps/sim/lib/organizations/settings-access.test.ts b/apps/sim/lib/organizations/settings-access.test.ts index b7564da047b..acd91c2d60f 100644 --- a/apps/sim/lib/organizations/settings-access.test.ts +++ b/apps/sim/lib/organizations/settings-access.test.ts @@ -46,6 +46,17 @@ describe('organization settings access', () => { }) }) + it('allows recovery only for current members of the target organization', async () => { + queueTableRows(member, [{ role: 'member' }]) + await expect( + canOpenOrganizationSettingsSection('organization-route', 'viewer', 'recently-deleted') + ).resolves.toBe(true) + queueTableRows(member, []) + await expect( + canOpenOrganizationSettingsSection('organization-route', 'viewer', 'recently-deleted') + ).resolves.toBe(false) + }) + it('fails closed when a stored membership has a non-canonical role', async () => { queueTableRows(member, [{ role: 'billing-owner' }]) diff --git a/apps/sim/lib/workspaces/admin-move-source-impact.ts b/apps/sim/lib/workspaces/admin-move-source-impact.ts index 2674334b9a6..687f89ec9ac 100644 --- a/apps/sim/lib/workspaces/admin-move-source-impact.ts +++ b/apps/sim/lib/workspaces/admin-move-source-impact.ts @@ -49,12 +49,12 @@ import { getCustomBlockUsageCounts } from '@/lib/workflows/custom-blocks/operati * failure mode a downgrade disclosure cannot have. Now adding a section to * that union fails the build here until somebody decides whether it is gated. * - * The gating mirrors `isOrganizationSettingsSectionAvailable`: on hosted every - * section except `members` and `billing` resolves to `hasEnterprisePlan`. The - * type is imported type-only so this domain module stays free of the settings + * The gating mirrors `isOrganizationSettingsSectionAvailable`. The type is + * imported type-only so this domain module stays free of the settings * navigation module's React and icon imports. */ const ENTERPRISE_GATED_SECTION_LABELS: Record = { + 'recently-deleted': null, integrations: 'Sim Search source setup', 'search-mcp': null, 'search-slack': 'Sim Search in Slack', diff --git a/apps/sim/lib/workspaces/constants.ts b/apps/sim/lib/workspaces/constants.ts new file mode 100644 index 00000000000..7a3247a6149 --- /dev/null +++ b/apps/sim/lib/workspaces/constants.ts @@ -0,0 +1,2 @@ +/** Search becomes available when the workspace menu exceeds five entries. */ +export const WORKSPACE_SEARCH_THRESHOLD = 6 diff --git a/apps/sim/lib/workspaces/utils.test.ts b/apps/sim/lib/workspaces/utils.test.ts index 2f2474c785b..f0d240c0d9a 100644 --- a/apps/sim/lib/workspaces/utils.test.ts +++ b/apps/sim/lib/workspaces/utils.test.ts @@ -278,7 +278,13 @@ describe('listAccessibleWorkspaceRowsForUser', () => { }) it('elevates an org admin to admin on an org workspace where they hold a lower explicit grant', async () => { - const orgWorkspace = { id: 'ws-1', name: 'Shared', ownerId: 'owner-x', organizationId: 'org-1' } + const orgWorkspace = { + id: 'ws-1', + name: 'Shared', + ownerId: 'owner-x', + organizationId: 'org-1', + createdAt: new Date('2026-01-01'), + } dbChainMockFns.select .mockReturnValueOnce(createMockChain([{ workspace: orgWorkspace, permissionType: 'write' }])) @@ -292,12 +298,19 @@ describe('listAccessibleWorkspaceRowsForUser', () => { it('keeps a lower explicit grant on a workspace owned by a different organization', async () => { const externalWorkspace = { + createdAt: new Date('2026-02-01'), id: 'ws-ext', name: 'External', ownerId: 'owner-y', organizationId: 'org-2', } - const orgWorkspace = { id: 'ws-1', name: 'Shared', ownerId: 'owner-x', organizationId: 'org-1' } + const orgWorkspace = { + id: 'ws-1', + name: 'Shared', + ownerId: 'owner-x', + organizationId: 'org-1', + createdAt: new Date('2026-01-01'), + } dbChainMockFns.select .mockReturnValueOnce( @@ -325,4 +338,19 @@ describe('listAccessibleWorkspaceRowsForUser', () => { expect(rows).toEqual([{ workspace: ownWorkspace, permissionType: 'admin', viaOrgAdmin: false }]) }) + it('globally orders combined explicit and derived access by newest creation date', async () => { + const explicit = { id: 'ws-explicit', createdAt: new Date('2026-01-01') } + const derived = { id: 'ws-derived', createdAt: new Date('2026-02-01') } + dbChainMockFns.select + .mockReturnValueOnce(createMockChain([{ workspace: explicit, permissionType: 'write' }])) + .mockReturnValueOnce(createMockChain([{ organizationId: 'org-1', role: 'admin' }])) + .mockReturnValueOnce(createMockChain([explicit, derived])) + + const rows = await listAccessibleWorkspaceRowsForUser('user-1', 'active') + expect(rows.map(({ workspace }) => workspace.id)).toEqual(['ws-derived', 'ws-explicit']) + expect(rows).toEqual([ + { workspace: derived, permissionType: 'admin', viaOrgAdmin: true }, + { workspace: explicit, permissionType: 'admin', viaOrgAdmin: true }, + ]) + }) }) diff --git a/apps/sim/lib/workspaces/utils.ts b/apps/sim/lib/workspaces/utils.ts index 760dcb9b1ce..e225516d12e 100644 --- a/apps/sim/lib/workspaces/utils.ts +++ b/apps/sim/lib/workspaces/utils.ts @@ -150,7 +150,9 @@ export async function listAccessibleWorkspaceRowsForUser( .filter((ws) => !seen.has(ws.id)) .map((ws) => ({ workspace: ws, permissionType: 'admin' as const, viaOrgAdmin: true })) - return [...elevatedExplicit, ...derived] + return [...elevatedExplicit, ...derived].sort( + (a, b) => b.workspace.createdAt.getTime() - a.workspace.createdAt.getTime() + ) } export async function listUserWorkspaces(userId: string, scope: WorkspaceScope = 'active') { From 333be5f2ee00483e2ac1a5cdce52fad86d3f4730 Mon Sep 17 00:00:00 2001 From: Vikhyath Mondreti Date: Fri, 11 Sep 2026 12:06:55 -0700 Subject: [PATCH 08/15] feat(library): What to Look for in an AI Workflow Automation Platform: Buyer's Checklist (#7780) Co-authored-by: Sim Pi Agent --- .../index.mdx | 134 ++++++++++++++++++ .../cover.jpg | Bin 0 -> 31092 bytes 2 files changed, 134 insertions(+) create mode 100644 apps/sim/content/library/ai-workflow-automation-platform-buyers-checklist/index.mdx create mode 100644 apps/sim/public/library/ai-workflow-automation-platform-buyers-checklist/cover.jpg diff --git a/apps/sim/content/library/ai-workflow-automation-platform-buyers-checklist/index.mdx b/apps/sim/content/library/ai-workflow-automation-platform-buyers-checklist/index.mdx new file mode 100644 index 00000000000..5ec2b8b9a33 --- /dev/null +++ b/apps/sim/content/library/ai-workflow-automation-platform-buyers-checklist/index.mdx @@ -0,0 +1,134 @@ +--- +slug: ai-workflow-automation-platform-buyers-checklist +title: 'What to Look for in an AI Workflow Automation Platform: Buyer''s Checklist' +description: 'A six-criteria buyer''s checklist for evaluating AI workflow automation platforms, covering agent support, orchestration, model flexibility, integrations, governance, and pricing.' +date: 2026-09-11 +updated: 2026-09-11 +authors: + - andrew +readingTime: 9 +tags: [AI Agents, Workflow Automation, Enterprise AI, Sim] +ogImage: /library/ai-workflow-automation-platform-buyers-checklist/cover.jpg +canonical: https://www.sim.ai/library/ai-workflow-automation-platform-buyers-checklist +draft: false +faq: + - q: "Is an AI agent platform the same as workflow automation software?" + a: "The categories overlap. Workflow automation software primarily executes predefined steps, while an AI agent platform lets models choose tools and actions based on context. Some products, including Sim, support both structured workflows and tool-using agents." + - q: "Do I need BYOK support, or is hosted model access enough?" + a: "Hosted access works when the platform offers suitable models, predictable limits, and acceptable data handling. Bring your own key becomes useful when you need direct provider billing, specific model access, or greater control over credentials." + - q: "What is the difference between self-hosted and cloud-hosted governance?" + a: "Cloud hosting places infrastructure maintenance and security operations with the vendor. Self-hosting gives you more control over data location, networking, and model access, but you must manage updates, scaling, monitoring, and hardening. Enterprise controls such as SSO and audit logs may still require a paid license." + - q: "How do credit-based and task-based pricing compare at high volume?" + a: "Task-based plans usually charge for each successful action, so workflows with many actions consume more quota. Credit-based plans may assign different costs to AI calls, enrichment, and other nodes. You should price several representative workflows rather than compare headline monthly allowances." + - q: "Can I switch platforms later without rebuilding everything?" + a: "Most migrations require some rebuilding because platforms define triggers, branches, credentials, and data mappings differently. Standard APIs, webhooks, MCP tools, portable prompts, and external data stores can reduce the work. Before buying, ask whether you can export workflow definitions, logs, and stored data." +--- + +## TL;DR + +- **AI agent support.** Can agents reason, use tools, access context, and complete tasks with limited supervision? +- **Multi-step orchestration.** Can workflows branch, loop, run parallel steps, and pause for human approval? +- **Model flexibility.** Can you change or bring your own language model without rebuilding workflows? +- **Integration depth.** Does each connector support the actions you need, with API, webhook, or MCP fallbacks? +- **Security and governance.** Can you control access, audit activity, manage data retention, and meet compliance requirements? +- **Pricing model.** Can you predict costs as tasks, model usage, and workflow volume increase? + +The comparison table evaluates Sim, Zapier, n8n, Make, and Gumloop against these six criteria. + +## Why the buying criteria have changed + +Workflow automation software once centered on predictable trigger-action sequences. An event in one app started a fixed action in another. AI agents add reasoning, tool selection, context, and variable execution paths, so buyers now need to assess how a platform controls decisions as well as how it connects applications. + +Established automation vendors have expanded accordingly. Zapier now combines structured Zaps with [goal-driven Agents](https://zapier.com/agents). n8n documents [LangChain-based AI components](https://docs.n8n.io/build/integrate-ai/langchain-in-n8n) for models, memory, tools, and retrieval. Connector count alone does not show how well a product can build and operate agent workflows. + +Use the six criteria in this guide to weight each platform against your deployment requirements. Agent execution and orchestration determine what workflows can do, while model choice and integration depth determine technical fit. Governance controls establish whether you can deploy those workflows under your security requirements, and pricing determines whether production volume fits your budget. For broader market context, see the guides to [AI agent platforms](https://www.sim.ai/library/best-ai-agent-platforms-2026) and [AI automation tools](https://www.sim.ai/library/best-ai-automation-tools-2026). + +## AI agent support: can the platform run autonomous, tool-using agents? + +AI agent support requires a reasoning loop that lets a model choose and call tools until it completes a goal. The agent should also retain relevant context during the run and retrieve stored knowledge when needed. A workflow that sends one prompt to an LLM and passes the response onward provides an AI step, but it does not let an agent choose and use tools in a reasoning loop. + +Sim provides an Agent block within its workflow builder. Each [Sim Agent block](https://docs.sim.ai/workflows/blocks/agent) reasons with a selected model and can act through connected tools. Sim also supports [MCP tools](https://docs.sim.ai/agents/mcp) for services without a built-in integration. Knowledge bases give agents retrievable information, while Sim Tables store structured information that later workflow runs can read and update. + +Platforms package these capabilities differently. Zapier offers [Agents](https://zapier.com/agents) that can use company knowledge and act across connected apps. n8n lets builders configure the agent, LLM, memory, and other components through its [LangChain integration](https://docs.n8n.io/build/integrate-ai/langchain-in-n8n). Its [Call n8n Workflow Tool](https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.toolworkflow) lets an agent invoke another workflow and retrieve its output, supporting delegated tasks. + +Gumloop documents [tool-using, context-aware Agents](https://docs.gumloop.com/core-concepts/agents) that choose actions based on a goal. Make describes [AI Agents](https://www.make.com/en/ai-agents) that orchestrate processes across its app catalog while exposing reasoning and tool use. These differences make a live test more useful than a feature label. + +Ask each vendor to run an agent against a realistic support request. The agent should consult your knowledge base, call a customer-record tool, and pause before making a consequential update. Then inspect whether the platform records its tool calls and preserves enough context to explain the decision. + +## Multi-step and multi-app orchestration: how workflows branch, loop, and hand off + +Orchestration depth measures how well workflow automation software handles changing paths and repeated work. A capable platform can route records based on conditions, process independent steps in parallel, and iterate over collections. It should also delegate reusable work to sub-workflows and pause for human approval before consequential actions. The guide to [AI agent orchestration frameworks](https://www.sim.ai/library/ai-agent-orchestration-frameworks-explained) explains these patterns in more depth. + +Sim provides Condition and Router blocks for branching, while Parallel and Loop blocks handle concurrent work and iteration. The Sim Workflow Block delegates a task to another workflow. Its [Human in the Loop block](https://docs.sim.ai/workflows/blocks/human-in-the-loop) can pause a run until a reviewer responds and notify a reviewer. The workflow resumes after the reviewer approves, rejects, or supplies requested input. + +Deployment options determine whether you can reuse the same workflow in different contexts. Sim can expose a workflow through an API or a chat interface. You can also [deploy it as an MCP server](https://docs.sim.ai/workflows/deployment/mcp), which lets compatible AI clients call the workflow as a tool. + +Other platforms organize complex work differently. n8n can expose another workflow to an agent through its Workflow Tool, and it documents [modular sub-workflows](https://docs.n8n.io/build/flow-logic/break-workflows-into-smaller-parts). Zapier provides [Paths for conditional branches](https://help.zapier.com/hc/en-us/articles/8496288555917-Add-branching-logic-to-Zap-workflows-with-Paths) plus [Looping and Sub-Zaps](https://help.zapier.com/hc/en-us/sections/16075022072077-Sub-Zap-Looping). Make uses [routers](https://help.make.com/router), [iterators](https://help.make.com/iterator), and [aggregators](https://help.make.com/aggregator) to route and combine data. Gumloop offers [reusable subflows](https://docs.gumloop.com/core-concepts/subflows) and conditional routing. + +During a vendor demo, ask the platform to build one realistic process with an exception path, a loop over multiple records, and an approval that may sit pending for several days. Then inspect how the platform retries failed branches, preserves state during the pause, and traces delegated work. A two-action demo cannot reveal those limits. + +## Model flexibility: locked into one LLM vendor or free to choose? + +Model flexibility lets you choose an LLM for each agent or workflow node, then replace the provider without rebuilding the surrounding logic. A flexible platform may also support bring your own key, or BYOK, so you can use direct provider billing or an existing provider agreement. + +Sim connects to major model providers and separates hosted access from BYOK. Confirm the models, included credits, workflow charges, and plan limits on [Sim's pricing page](https://www.sim.ai/pricing) before estimating production costs. Enterprise deployments can also use self-hosted infrastructure. The [BYOK and multi-model guide](https://www.sim.ai/library/byok-multi-model-ai-agent-builder) covers the architectural tradeoffs. + +Competing platforms expose model choice differently. n8n's configurable language-model components include provider-specific nodes such as its [Anthropic Chat Model](https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.lmchatanthropic) and [Ollama Chat Model](https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.lmchatollama). Gumloop documents [model selection and presets](https://docs.gumloop.com/core-concepts/ai_models), while its [pricing page](https://www.gumloop.com/pricing) identifies BYOK as a plan feature. Make's [AI Agent credit documentation](https://help.make.com/credit-usage-for-ai-agents) distinguishes its own provider from custom provider connections on paid plans. + +During a vendor demo, replace the model inside an existing agent and reconnect nothing else. Then confirm which providers, keys, and local deployment options your intended plan includes. + +## Integration depth: raw connector count versus usable depth per app + +Integration depth measures whether a connector supports the operations your workflow needs. A platform may list an app but expose only a few triggers and actions. Check support for the specific records, events, searches, and updates in your workflow. For any missing operation, confirm that the platform provides a workable fallback through a webhook, a generic API request, or a Model Context Protocol tool. + +Published directory totals change frequently. Zapier's [pricing page](https://zapier.com/pricing) describes access to thousands of apps, while Make's [pricing page](https://www.make.com/en/pricing) lists more than 3,000 apps. Sim's current [pricing page](https://www.sim.ai/pricing) describes more than 1,000 integrations, and Sim supports MCP tools for services without native coverage. Rather than compare these changing totals with estimates from secondary reviews, inspect each vendor's live directory and test the operations you require. + +Your evaluation should use a sample workflow rather than the directory total. Ask each vendor to build the same flow with your actual apps, including one uncommon action and one unsupported service. A smaller catalog may still meet your requirements if its connectors expose the operations you need and an API or MCP tool covers the unsupported service in your test. The [Zapier alternatives guide](https://www.sim.ai/library/best-zapier-alternatives) provides another way to frame this comparison. + +## Security and governance: what enterprise buyers actually need to check + +Verify the platform's identity controls, permissions, audit records, data handling, compliance evidence, and deployment options before approval. + +- **Identity management.** Confirm that SSO centralizes sign-in and SCIM automatically provisions or removes users through your identity provider. +- **Access control.** Check whether role-based access control can restrict specific models, integrations, credentials, and administrative actions. +- **Auditability.** Require searchable audit logs for configuration changes, user activity, and workflow runs. Confirm how long the vendor retains those records. +- **Data control.** Ask where prompts, outputs, credentials, and logs reside. Review retention settings, deletion procedures, and export options. +- **Compliance.** Request current certification reports or trust-center documents for standards such as SOC 2 Type II and ISO 27001. A logo on a sales page provides limited evidence. +- **Deployment.** Determine whether self-hosting or an on-premises option covers the full product. Some vendors reserve identity and access controls for paid enterprise licenses. + +[Sim Enterprise documentation](https://docs.sim.ai/platform/enterprise) describes permission groups, SSO, audit logs, usage tracking, data retention, and data drains. Sim separately documents [SCIM provisioning](https://docs.sim.ai/platform/enterprise/scim) and [self-hosted Enterprise configuration](https://docs.sim.ai/platform/enterprise/self-hosted). Request the applicable reports and confirm that their scope covers the Sim services you plan to use. + +Compare vendors at the plan level because security controls and deployment options may be limited to specific editions. n8n documents [SAML availability](https://docs.n8n.io/administer/manage-users-and-access/verify-user-identity/use-saml) and [role-based permissions](https://docs.n8n.io/administer/manage-users-and-access/set-permissions-and-roles-rbac), including plan restrictions. Zapier documents [SAML SSO](https://help.zapier.com/hc/en-us/articles/8496279747085-Set-up-single-sign-on-with-SAML) on Team and Enterprise plans. Gumloop documents [Enterprise SSO, SAML, and SCIM](https://docs.gumloop.com/enterprise-features/sso_saml_scim) as well as [audit logging](https://docs.gumloop.com/enterprise-features/audit_logging). Ask each vendor to confirm current scope in writing. + +## Pricing model: task, operation, or credit — and what that means at scale + +Pricing units determine which workflow patterns become expensive, so compare the cost of a complete production run rather than the advertised monthly fee. Under task-based pricing, successful actions consume part of your allowance. Zapier's [pricing documentation](https://zapier.com/pricing) explains its task allowance and usage model. + +Credit-based pricing requires closer inspection because different nodes may consume different amounts. Make's [pricing page](https://www.make.com/en/pricing) says each module action in a scenario generally counts as one credit, while its AI documentation explains additional model-related usage. Gumloop's [credit documentation](https://docs.gumloop.com/core-concepts/credits) says agent costs vary with the model, tools, and run length. + +Self-hosting may reduce variable platform charges, but it adds infrastructure and operating costs. n8n prices its hosted and self-hosted offerings around workflow execution allowances; its [current pricing page](https://n8n.io/pricing/) explains that executions include unlimited steps. You still need to account for servers, monitoring, upgrades, backups, and staff time when operating a deployment yourself. + +Sim calculates usage from a base run charge, billable model usage, and hosted tool usage, as detailed in its [cost calculation documentation](https://docs.sim.ai/platform/costs). Verify current allowances and plan features on [Sim's pricing page](https://www.sim.ai/pricing). For every vendor, price a representative workflow with expected records, loops, retries, and AI-node choices. + +## Comparison table: Sim vs. Zapier vs. n8n vs. Make vs. Gumloop + +The table compares the five platforms across the six buying criteria. Plan availability and pricing can change, so verify each entry with the linked vendor documentation. + +| Criterion | [Sim](https://docs.sim.ai/introduction) | [Zapier](https://zapier.com/agents) | [n8n](https://docs.n8n.io/build/integrate-ai/langchain-in-n8n) | [Make](https://www.make.com/en/ai-agents) | [Gumloop](https://docs.gumloop.com/core-concepts/agents) | +| --- | --- | --- | --- | --- | --- | +| AI agents | [Native tool-using Agent blocks](https://docs.sim.ai/workflows/blocks/agent) | [Separate Agents product alongside Zaps](https://zapier.com/agents) | [Configurable LangChain agents, models, tools, and memory](https://docs.n8n.io/build/integrate-ai/langchain-in-n8n) | [AI Agents with visible reasoning and tool use](https://www.make.com/en/ai-agents) | [Tool-using, context-aware Agents](https://docs.gumloop.com/core-concepts/agents) | +| Orchestration | [Human review](https://docs.sim.ai/workflows/blocks/human-in-the-loop) plus branches, loops, and parallel runs | [Paths](https://help.zapier.com/hc/en-us/articles/8496288555917-Add-branching-logic-to-Zap-workflows-with-Paths), Looping, and Sub-Zaps | [Modular sub-workflows](https://docs.n8n.io/build/flow-logic/break-workflows-into-smaller-parts) plus flow-control nodes | [Routers](https://help.make.com/router), iterators, and aggregators | [Reusable subflows](https://docs.gumloop.com/core-concepts/subflows) and routing | +| Models | Multiple hosted providers and BYOK options | Model availability varies by Zapier product | [Multiple provider-specific model nodes](https://docs.n8n.io/build/integrate-ai/langchain-in-n8n) | [Make provider plus custom providers on eligible plans](https://help.make.com/credit-usage-for-ai-agents) | [Model catalog and presets](https://docs.gumloop.com/core-concepts/ai_models), with BYOK listed in pricing | +| Integrations | [1,000+ listed on the current pricing page](https://www.sim.ai/pricing), with MCP fallback | [Thousands listed on the current pricing page](https://zapier.com/pricing) | Connector coverage should be tested against the required operations | [3,000+ listed on the current pricing page](https://www.make.com/en/pricing) | Connector coverage should be tested against the required operations | +| Governance | [Permission groups, SSO, audit logs, and retention](https://docs.sim.ai/platform/enterprise), plus self-hosting options | [SAML SSO on eligible plans](https://help.zapier.com/hc/en-us/articles/8496279747085-Set-up-single-sign-on-with-SAML) | [Plan-dependent SSO](https://docs.n8n.io/administer/manage-users-and-access/verify-user-identity/use-saml) and RBAC, with self-hosting options | Verify plan-specific controls with the vendor | [Enterprise SSO and SCIM](https://docs.gumloop.com/enterprise-features/sso_saml_scim), model controls, and audit logs | +| Pricing | [Credits based on runs, model usage, and hosted tools](https://docs.sim.ai/platform/costs) | [Task-based allowances](https://zapier.com/pricing) | [Workflow execution allowances](https://n8n.io/pricing/) | [Credits based on module and AI usage](https://www.make.com/en/pricing) | [Variable credits based on models, tools, and run length](https://docs.gumloop.com/core-concepts/credits) | + +## Matching the checklist to your buying scenario + +If you are evaluating a platform's technical architecture, prioritize agent support and orchestration depth, then verify model flexibility against your provider and deployment requirements. During a demo, ask each vendor to build an agent that selects tools, switches models, handles a failed step, and pauses for human approval. + +If you own the operating process, start with integration depth and orchestration because those criteria determine whether the workflow can perform the required actions. Test a real process that crosses your core applications, then calculate its cost at the expected monthly volume. A large connector catalog offers little value if the required connectors lack the actions your process needs. + +If you approve enterprise software, verify security and governance before assessing integration coverage and pricing predictability. Ask vendors to demonstrate access controls, audit records, retention settings, and deployment options rather than accepting a security summary. + +Sim is a strong candidate when your evaluation prioritizes tool-using agents, model choice, and the documented enterprise governance controls above. Use the six criteria as rows in a vendor scorecard, weight them for your buying scenario, and require vendors to prove each score during the same demo workflow. diff --git a/apps/sim/public/library/ai-workflow-automation-platform-buyers-checklist/cover.jpg b/apps/sim/public/library/ai-workflow-automation-platform-buyers-checklist/cover.jpg new file mode 100644 index 0000000000000000000000000000000000000000..efe0522fc5e4e82529f791c3721732bd1c395709 GIT binary patch literal 31092 zcmeFZbyQs4vM<`W2MG?r-Q8V-ySoQ>2oNMdumHi`0>QO$cL~ysy9G!CK?1=EcAM<) z+h^~4-gsl|_wHYJoYi!%)pN}?rDj#ls$W&}wDhzJkOm>A^%wyvvPYtE;P*1WVF1DwqAgaZcSB~K}vT)^A#_sP-6k4;*_Fu zF6|Y4sJ4dp`Ab`+63g6F7bS>Z=|Ag6W=Nz}u05cHnIw;y2>?TstUGwZl$=7$DC_5z zO531iM2j~gvOYs!ZEv#>I$q5J1c|c#r=4JjjpZ3r=|2xl?($r+YB^j^I*a1mwP5-L z@zYymk#GOeka>kI2$MtpqeuRy^8Zlae<<*OHwBQ=moNTbX9#1ojGa{8BUoAxSL|x7 zvD;GMS8>Ph#(2zS&qjRK&!`%<#}>;K0sv5*#Y|1+XiG_X!cUiPYaxFsK|dC!(rA5L*&gkC z;(D3H*(a&?{=V~khMS!7{7{KG$_n;uub{r_Kb<0A7g}$WbpF|Jippe$RgZclX{jYI z^Sj?CoDHw7Sy2@J3 zB~Rvo&zs`1!jQx7#^3&xAh2CEH3!J`Zd41=jm1LrxgT*bci33pUPOp!m=J*j32oHV z*HKkjP@e##%QB5V?{ytrn7n>C%#2qf&u__Z08mwrzJMT~^;Qs+!hmz>ZHJ=w_z6V1p^I1I@$LzL7KOXnOy?JOcz$YZUMhCaH7YCZsx_>8pke%qB3z}H$BXq+ zDwhZ?OFCxtv*70E$tB#YF6Qx#*iNu-=l=LUv?D}6xIB_EvC|@O!qwR&gTe%vo4$n1 zBNMCzIgsB5J5ar4nkZzlz~q{uAX^#@^K^lkA2&USw$m13H7$GVE{WXkks z{~*-Z`Gx*K-D1iz7^5XhjV2;yVJYghJ@M5<%}e5AL|0wU3-2CglPyui_z(L`buI7e zMZq4qAZAThT|1>uf>&nm!M^kM_Sq6J5|g}|MH`=bn5nie&o3AZhMQHDBw?$5<5bfE z-`q#l)V!i^JArGoEUtNB-^qN)vkr@`z4Qbqet&=*-t%qmMMMSt7tAsFQ~iJAg@5IX z|Ku96b*YKO%_1{S>>FW;mVAe}1OR|x(ctJK0U&0ll3BdXh88>@7>w->S0R5c|NbCW zd7t+8^}n4Fd@b!!#S8svZusX-%B8aMVs}>ulNOqF$Q;`dOPZz0m0#-tD? zh&{B}^pHgxvR%fM-V3H%+5kpYMEo~F_A09i?c!>1>(!%N8pq2=XEQj^VsXrcPZ#Sw zVy_$VWzAlpE;y-rH}Q373EYbtnkB!zf50TAw*57OgU|Q+-zM?=MO<87cqvOnb92uz zsYw(fm@sp&CtQ)trd$odwXjjHhRd!3&9itFb2`k+)oNsWB<8+q(IiV7Qi!#(@mr@2 z)W68(kfrS)QLnhTixc$GnhzDg^Xoyp(Wz$>@IEFm~P>J#32_2dJV=SgmxA>lew zlHkTvS_+f!4D&J92@t3sZ4n}Uf+Kv`lq<7~JRjLyIjU*-wBxg_A~9 z2ww{Q>+>!4Pxek!!+S4M_qg_x`u33a_`ER12$b=^R)ap&>a2w3wwBMlI`6Fi3Mm4m zCsLNM`I|4Vq?(lJ_y-Q>)cs)o87`!DqR~R#XfmYv3PsurL)W?T)2PA@_17w8qsR0f z0PaKWB%=0D-XxdGXqUQd{ghWXo?V~y4P>qw>kkUW{ipTHWtFyZ&W1}|95Qa3e~`3l z<3A8P(N5pOXkFL|URXdt>(rp3ExOpz7&Z6OHGF4_x-c^G^p7jj2n3`cSw*uV%5w|NRYR%p&PML@ zpDp!BLaH>te#U%`9I_P9Bn~zH7Y9Yg)ffh8*8RpWdUJr5>VZrqq-iN1)ioJ9&n;PlRVh6@TCt^Ws*Kl=ZSkeCOxstEjhorc$$% zlDDmt;!pvO{XqP-u|!pqZ^5i>N97`xGKxz`4(VoBjXS0;ImHilMTK2PIL06nHZk{Q>~oj)IS3_Vr0K$`MW_f({6cw1uH#lyrFg^-j#L?3+4|XN}CHyB8NrzW^5F{Fz}VL zwb^P+p`61v5=_{koZiyUM3HIrz&sKvf!9+k{g&a*(Wo#7s;MGNiB#B{%Tjb(A3|Ko z#idG`9W3ct7EC_Kzub?a#Az2?EtKj=A?fE*NKjd((DR|73a>`a4rk*rVmb&4z#Fxq z)~HvIU!U8W>aHg0)UlkC|3X3NrQJ>FKVFrS6g%T(!)D0IvPMM^sNS&swtUw*1>S+w zaBMipEI)}2ah*Cf92Qd4ge0e`fVe_DFbV|M8PMR35Nn?aM=Hbj> z#8$%Mh?<YG=Sfw}HES?TTaU~+J zZ9m?Z?#uxH+h-9QLYj}x>|c&UUU^~FCmA78F(kNP32}q*Wxllp1p1izzMoRu1B3XR4&0sq4lWyh#H4LMg_6JRBCJy(G9qJ1J%6P1y+C zAMd;<{E3QQSI;kG30=#Usahwdi}#yz8265X=LNT?JuSq6eNrGwPpM(~BH7rpOFZ5N zE#mR|#5VM@pDXA(>nM}C=;{j}oY`5KW`;}99T#G{Uemh2JMXi6W0khdw)->nGpHsQ zQl=A~!_d%nQg}PnV)F~-E$plA@GQbTX+K=rlSu-1It2P3LM1O!C2aRP9k(-tP%(b& zN}W{T|K{|YEE1gPa`fiu9(3Q97~Un=W6{o)u6m~x?35ebL08)?mzcq+8MszqvKlle3vc?rW-C zsbac;X9xinekrUEpAw)1D|U~4H8MFZ1)|@y3DmpzlrVPx043PAXFw5>;P(sqHnSy3 zQ=Km68o_h>w>Bw(ho2G{?=(|+O)zy=2Bf=5FSn+Jk|G;+Z>@5Ea}&mnKZ-#u*G-8a z(jT`04|t-}`vAQKk-a5b3MjTt4*&IhGi{x zz@3Rwk^cHL?Ozz#v`Zx8AM-=m{rdQ~=l6cl4aJo3;l$U^u2mjzO=nCH+mRe?OD%0lR}@(NF)q^#9m5I4DBMiv@s%g@u8GL4rkqhvJA( z-wGZU0R|C(gvE=Cjq?(Zn}?5p0-r-dR-KZH#+=$Mgtiw7AtFO-!XN{l07sP=8*_1! zjOvEFyNxPPe@eJk?#Vdzn1*xh@$!9?dB_f5>gf2oO@M!MaTMI+ zowp)d9Wv5`c-8KZii#2`yzz|4=@TGm=dDANO#9rNni*jaa;_*JQqD(ljzVA>r-l`p zAtWche^#=iDWu7Gj|Z<)A^~j_$0w~ho4Xzhqk042N6B23Q(;N3d+m{!sO>#|c>PIw zCwlNzEgj;<=X!GbS5`gO>*+Rl0`-94(ZD?8Ltt@b7QY7lSM!dBQ{_Wp`DJ9BZ1!Yc!QCt6MjvPzFn^>oju~LBwU?z)60iU4<&HJe zs1s?;{AVvmCqU0p2SfQ#0^Fn0(YfKm2UQl*`}SglC3v{G1ADEu zh=IE*pZ2llu_C<5P!K0y8$7o(2OC7Q*s3?F9mbAn46AJkG86xHGV@=jdH z_hIMpq5i0_6kh`Kmc0SwXox3J=lKL+e*1;f22FOq+2;o}$9A9;dD{~p?s~I37(TB> zE6cwxB%3|AVYl+;!PWc$+vkA(D#+{PZsg(Gt{X&E)Z6pDdy=>MjrMlmivzNV`NX~t*=n0^)Y2IrcW>MZ~o+@OyiE-AsXQy`Pv@MLPK|6%TUAT_gWjDD6-l!dQVWpc<)x2Za|1!_UEjNY*W1f zW6*e4Zz?{Ws?hF;@Q)UvV4BT+ob!b?5KA~KDUI6R&+ioFMU*8we$K{r*NPgkHjHM@ zs>`IIdV*ljoISOBkB-|Gj24mr{Shfn<)T~mOZ-oA&0Woq^xQPhoI^b%%`N5Z?w{kZ zZL#vj^?k0CIKg47$(LR#cY=zWHRY1A=Ps`Erfo;Nt(#R}YS{cb_z&22S>BA^2gK$J z>+M{bB;E0fr_QMz-OoM&sB0cNO21=xmi8FV-pc)^JO1*P@(Cc>b@SSty;JM@h$f+& zm6l9nX0g<;loI)cK)86uLZbF63%8KJEF-){^@H3Kz~X1L;tgFkCcYFBgOiw@cDCSg z*KMok>vJekku`ezDN4T5RkE;)qV&Y+_b&?;v?|+YGziApuPox!ZQ))ZK3uG8aiv%g zDXMYPliFv#QMe~wAO_FhJfu5{w(ZK$YK~4a2F#SLR2`zBtLRE?Z&|<0K|)dW&8}3& zv8ZBpCN@aaZK%`KPx?K)C`>g(&|F01PcVk~%6-yvE_~QHkpZ{0CD~!vq@~4J4Pu%x zB1|)?+7VZp32{~gk7f^r2buk>C*7^qI5KlENbEoSsDy(+_tPB=XpAiq7klu$1y1#GhA< za|w|98CaSZu16L+*~e}#fT4u+n7&P}*-N_v}1?;)t5 z=2?4N1xrrBEp~sQtBsiv;w$mytASmg8typQp7ob$FMDclZ5lrANYq^`ufMx<4RRs< zqX7GV+W$5hP$OmzhTU-7b9J4W=8x4XKRm`Z%9T`Gg?}}iv{~8_($LVdzkfs@uT{R! zG;Q>URhz0MeRN(fu>EMP3Uz}S;GHmkDP<{BVa~Op-4N6=t5;jKnh2TaYG0=cjoN8B zEQ9U#L1pk`nwgMI4f$q^$nQVL+->lK_d^I|o5E5ELP|?C($G|lZ+> zpWU4JE%J^(TY)Jf5eJ2MXlM?@r$x({P#QmLNGFP(uoQm#WWNGN!_wVd#UtLKTF|hb7*z{o50=R(74_9p(Fq?on$d1#MDD;~DJT2tUSz1? zTWlsQPGYh0(ahzvzIWuaww%~#)LX0wfvcW#pUxlG%S)ba_Z}n7Eu}U6g+8Ole5nbl z0FDwkT$-tjM2C13pQeuuwGPO@8dFvlnN-7SO*ARG?geHd$t3nMtqjz0nG-}>IEMoFSwxP803*Sm2$J-#GU(D%|Py+<0F^KkU{+8 zkw=q9-Dj;uW4$nul^*i?qj=8nwIn3KpE2VSn~#ss#9 z5bicndlY11RNHgf?KlZLn1?W^UkBSf0kWI+)Vjd~*^xVGqUrGzt<+>r?t`w*obmaA zxsgXrYfOhWoEX(-OKo5P=wUV^MFr&8r|bE=C}V`%dOG@(w4|zB@qVR`f+lzT9hjfY zaX;540t_pBp8&DE8wO7P^D!9ZV)o5s%^A|^{5||Ho(+gCAKV9T-Vpb3VORrF*}T}& z-qOT#hGF*<>$4e!g|yVT_bfCeb_Mjm$lN>69qxn1>&H&mn{qJE$4uCt#sFk_*2wYRFc}s+IuJsdp&|2~=Y?=IMQym+yzMacx;r`&Yz-2$ zS`wELZ8j6O13xc7Ab6^2K9LYtzos4`G(K9NaD)vfDVJvDt6%k7Ca^cs(c!J+?m>@j z{td*}=LK(wRciC=9c8Z9Wpg{x^3#HoGJD7`k(PgXWn(J1{(yi^Km%Fwx#TyFI-(fK z73YK#4Y8JO##EsWJK6m~d3$stJYODoDaP}h%|0#rC>_lm*Wa#+{TW$LrGQwG@gnP% zl1&6k?zrio=uf8(%-F6y@V?j>COX$@xoQ3?G~SY|>}{#@ z%BP)=yC1)79j?GhRMjCAN;pBOk6^dV-k_ECCLV;SMeUG_uiQZVxQ9T1L8;WmD z;wZVpdiB}de%67$o2itJbC$ed#V&|ZREubk zRV<{=#me2X)C{Efiw;Mz<(1@}(4)Fvd+qYGByIZDUCg^_GFHeN8EAx18&d-AT$ z3+1Cea^Tt!WAt65I*@E;NAi3U5**ut)OcG~ zF)p26p4DGGBzcb=F!Y&{4Q4!DD0N^VzW$YB?uz#+i4X7CN+qvBuw1jL$5`E*56U

Ds()NmQp+Qu`g?}LP#ZBFKTGPkXFS0Kd;=G8IzR9aD+2q^GlMY(N2RI3xy2^-r zThX~G&XM}4+o3s6rw{r0rMU4+ufgoeVw!u1gWg^m=a?v`!);$=K$2j>C}}Xf>G=)S zbv|^6kH}ryhR#c`)Mp{PSxqUsV|H_{eJnd44+xHw2toJ-)yCTcqP1QSr&2y#v7#Up zJ5n=^9uZ)?hW)`j7`+Kp2&{DYT2--P@+|{~c2pi`*ov8zY+xau!Qqmiu?mcI>`|Uq z>23Z5fH(d1=Cx9Y2V|o&ZjJMo@l4G^UJ%x$q9BAtX4Wc%_H+&Yhmx@Bq!QM7f_Yabft!Yuna$^tCv>| zhElzAZD(p`&>NlrYc)o?i%HbZ0V@%40Jw%vrDn(~b(^ys8sR3{?%J}yvL0y*cmKE) zXGX165=!x8rvaXRMr=McQa9)OScU)LPz_VbE6!H-+ zN;Xm`bn~}fX^hN6U_IIsfIZ;cZTI~y(L+bqbPA#4B4L#Mpym7z)|3v}uuG&9=G)>& ziP{Ta_U(G$@NLen0oc>{`{9O8D|!OM@ate|izOGWHb3u+4*8=Yi*)glH7C;QDwveY zWmil)W1K7B6O!HcTgy)XL16izy%R#bqss3wp)Y)0cy{)@nHY*F2RzYn&dj6XY zl4{#aJPU6Jlo&CihJC7o1g~tA6!#t%fk&08^aB>Y)2>`G6WvKclbV%3M57@l&k7SM z!w$FvJ20wtUJ;}SZiXc)ZmmbGv6Zk#RB%L$pK>}hpo4!=@Bj(s>G_KHb3NCe+&iw) z3>=tY(qtStXcP&o)qP6>0MIva4{EQ@UQLw@Dh5rPGL^mNIwqt>*Q1Y!-G zwIhES4A0l@nw|i9iO5jl2$|z$c$%}2mDb0675>8%DN?2si z4Ah6rDP>J}VjkwL)aMZ0>(dlY4=%qYveX|eRCds(IW>F&q}>y}YXM#n%NA$g3bSHE zqWZZ8fzk320{CQ#!MR$eM=%=SOTqKC+omV@&U#3{@SgybIaUH-Zrc)#I(JjAhaNw> zx$$EQnru74iD)*bCNoB7jh#{uG`<*W0QKe2{h+>_qQMW8-wyiOP&XJ=c88GfP%TUT zjaNEC1Pc1#IKeWjo+CBQtH4P9U?Ej)eUS+(EsIyWUe`66TmlszVFIS4m4KYU^7t+Aovo5I$g0Qv&EJQU=a7CWz7W*Wo3 z?uu1>vhm4Dh|o1>4N-=J?r`6t6H;UcCOaG^;wOq2?3S4v)5^1=!<;=X`_6Pdxa0&< z(yb4Ok<3h6hd^GK$%IN#5v-42*GEf{Yd%)*2AS<19)RE zfQBG7b62`^?9Q#ulTfkd`~gGHtbWU_L=dj3O~BeZBa^)xFcU(rBAmOTg8 z1=B8;Hz@CT);vtE4lyMa-^o~ID!}x&3FsA8B&;1iI18d-Ct1>S{)j{q>)P)P7AZ)Ek)k#*^ zlc-A>TzR>1Pa{aUs~KyhAXm&)6wZFoXKy$`4`Pb8WIyLqq=ar^t_dG(8e%?`7N=p@ zvKcMhFXPZ>UOarw&<`Dlkw8Z~hOgvRDzHioAFXs8hoX1`)njIyS{sw2`koS}N9RF7 zQaUmgy5UDhc&exj?aXoB6WAP#;j0K{W2`S4z0gq1s~5+;?gML9AgJ?<5gvYcRk~CY zjVMgxXycMJ#hMe`kJ9h7c63m37zR`9eJHy{@rh~yzk~8S$HBJ0#7#8JyI~DN`g!=X z3Au?AKIy70m{OBAF-qFflR03=dLKLi?6_lkyD6+gUG_k_Vd$ML3YOsnG3?}5zv+QuCSrse=95$JW8Qe0zctiFo?->vU>7Ai& ztm=KoH~w)l-FVz-C)kzGgS^8RH!j+;G|W!{=26}w@Z7!Lq8#l0r8*1+%AT#lRj>Q^ zHC}foECS;c>hOZc{LSNx{cYJs{G#23cxg1aATrGx|2)^nS1y{jF?m;i@lN)m=ef5# zh*%(XuSK*yjBx8aEr?xkxVM&HZDi#k-PCe5SNvBE)MaYaTGSJ&wIyWcjvX&4{qd%c zF|3=7{Q8aROnrPv+j#Mfk9x7%}`0UQ?)4G4Oxx-UOHxfb5nCM$ije8)>QE4 zU*z?DRbaG! zs-}K~NKp_zuL6+F6|>JjU+Kepz6{tMQYrx{?9HSbSBCErzw|U9R)wX%j(3NB=N?%d zKo)i}6(_L7XQtf{fL(`E9Iw7LG-RAJ!jzRdUWt(Sm!X-Kb(t$6XWMj#nPyZn>}Mal z4IUwyLPK9@CG`w;l66L~s(6$%T6MS&9nXdC61gpx9>NI3!v*))9hig1&EiNuGZTIX zefhEq+WX6Gcy`>OcqVDhaeI)&qEO&<8tDO=OjKoR+$%3uXFOGV?S;h=LfxA>4A!dB zF*8gp=nnS3$xa#59%8L4@%U*?oATgsyEu}I4a~m7>*f->Y^atD8n5Ma2It=_29G*1 z{wB!=e51-7qm*=$wCP3m3{>0FuUZf+r{CXC9`R-JTi|63Phmx zpl%=}!0UnCKF{CedK~k;Deh;}FPq*v=9InEgpn)1dv?9qSmPb}$T>^YGuIrEQ-S(J z&e^HT79TLW)=~_@(YT2<1-;F_G6%SPR3?~s$;+>%nG&uU=~~~|tiiphEw$VE(Iz!M z^D82A%SW04ETCP7ekTzCm0@54!}|wQq?#$7)n8CDusgZ~3IoLJ`K*gmIR4S(t~$le zSbQ|ALM$H&kFCtdknG3*c7j&-?fLklP&`Jreu@; z7F%Oo)O9!p`Ioj`Nh~1KA2z0hAb}-5lQ7GZq|xtePN%>;SCvi(4^tcdTInpT=2-BRi^i6HzOiE7?~lfH7`2 zN}QdLu<7&i;~mo7~)9!6zw$RW*xO?dMB5E|lWj7t(B+7sfT&S2Am%dGl(L zmC>Y{U6{lhoj#N(VjN@Hfuh~ntYl52Un}KHldpT$waVw`Rq2NEG7ZfAfT*v`we2`} z1Y{CZ=zc~T`i(hSm1bN$0V*7~Wbq7H_G38uCbJaXH5p_h$C<)eKfG@qQFA}BV}>iO zzXm4HPcO`l2z?;;0V&b_yA2OUNNcP}`Y&yL}< zPOGutnJ3vZOO4TWD_OkzY@i?A5#cD;mi@7MQ9~`og@1)H#Sk+U!8u^R& z@P!o-G_VREj7&v-M(%|-MpU%A+Tu1B@852O7QM?PU0Q7`Fmc@EsF-0rs8fPtuFNj$ zBAkLa;s4>n;kMduWpbadcI2o73Uvm73m$TV8AR6g9OFzcE9JqjxblWecTHQaow|J{ zp|UTGd7uIX`eaU%Pr4Z>3_=Fx6cUdZ0)+l*2@LKmcB2_k^+sA|8Dj8;9l?151j_B0 z*uDmIwyXz^E-(7jZUmw#R`xqTLMWX5>P+r06Y^7hdgy{!&suzMKOU5?Y&ukz=Y%C) zA{>p2qnH*XZw!-EH_I)F}%=Uj-LREam)N40sJE@8nwM= zo4;5Is2RYVIRV~qqtNXfnuu_6itjK-=Li&8qKtB{zMkdk6_oTm9~_%>{%CoNR0PpI zJQqet-tF^IqyXIL1rsd;qF2pVC}q6+Vgh^9PCf{DEc(>QdEnF^Af&fEl(}x@6e0Dx zHDYIw@;w1gl{MT&Gr6_jff_DR3G>|ARzSlQs|K|M!-3d7txL>5tYSHW3R*Jlz9E&d zZtLG%3iH}@yK(w%Iu-Nb*L=|NV`agI8i??EIOAs;u{#W7JBD8TNCp^+5i>cF)Fx8D zdEYIZ$C@s9Ec$6^zGfIG!xu>77E;M2sk&$JX_qMZ`l>`Qc@nF>LNc)v;%6wo<+@woau3`f04pAl#BG2z2gBUKCLsgF| zZfo8v^aUP1-I}+$3T#Wyf^tKZz}<%!r}H7D0rxV{W21h~scDY9p>~%$$D>lSu@PPE zW1Pcq8Wv-OCgR(SiXZu{ED=Tiy!E}A@*uG>A3W^7=T@HM3BJ#Aoq{h_-hlSuL8AKm z@6dSa{77H_^{p*#`;}iYy;UoazZ}8i=V0%AFhw|J#D{zyZKb&#y6IvJ?Jpr zwgO()`-UF7(Mn%KS)Kp@tyAgVaL$nyb&(`v1-dHzP-s3e($PEcXP_0Sg&s2~inH1U zF*7_hpXELkYMs8AbSVtB+pWAsaCNTefm|yO3&A~(c9=0=cbljm5{A<#^kY@4;x&y` zMy_PnG|pXu(wY+)V}i@@Iy+V?ohu2ouyQ^#fSF0q+2GtaJ6*G0soTLV6LifCdX)6S zLdmm7RJrlJ6&6Wnjltl`in)(U)wy=#glGuV%so50v+RhuKF409H>MK-Y4V2*bH-W` zHlSk~-;{!&ITJlbpwV(}{|UjWHEP8Hbnf5pjrvbg<%kf(9F7B4wrwaud@rn$UrV8B z4dpGQZZ}GXk7`uwYFl!X{Yf!+NOBE9W_}&QQnjFc$btaifXn?0`L9`p=A=O5g>j|) zsfzw@u^c&c2+?5G%FxCM2P&L#Rqe1tznQq-Ri6JHR0!65&K0on4$wZMCZ{d^mLS75 z_+j<$ZF&a@r+{Gh@FG0+pw+mccp3EbL@z~ z+y*7UH&LYIKhAR=#60s$!R`_eZ(T%_yW!iS8-}3OTtQ|ol@Q)98*qX*&U&3`fpNMk z9ola*4fo`&W5Afr-%E76EZ@y+#^_;_-t{yt=<3_hX#u7B#m@dY6}uo%_e$-~W#{rv z#-_mzkNdf*Q~LG=;j;hw>~vG{j58GJq=6?;&DA5B|n5?r^g z)@Avb4>Bg%^0ASkr*au}tgXQ?r*30%wXD5KBt>fjnU|yY!X@t!ZXe*gmUFsPYY?H? zGg#H&h%uzE9}9@7^Zq(6@0Lh;5%UC4&^n+6CAI4`AAiiU?Zy4YwEG93=0k&&&(Sko zXCqHoxRM{n+Oa+Cy!#Uxw<)gILHmBJb0WwLi3^FLj;DF)p^HYQGPynh`DwqCae3h` zwi?J&&3tNZB^d9Xqwb+qOS~p@=T7?p@jE-Q(rQm*X;yP@po{N*0ToWbIt+ zf0O*5EMn#qqxp$rxT6(i(&5T@^-Ip1)d7KF&m1c>DQSbZN`F@54iIGq-&4jv&F}oO zU+wBy4gWDDY~1X?fnr=k^MXU#p*Yobu4$x>Pl$38H}8r>;Rdles_b5ym0lBO*T+XH_Z90 z`#_H11>XbA<;Alw(7aFk>D79f2(8{fBJe$Ov(GXV2uzHqz^XkRFD=6Dh*#$;4clA!6sSFY=om?m3p0ZcJYPm5LLH5BUsdXs)F2Rb08&=7*D5vYF zDn?;Pz^GYE3z~%p^JlJqfLs+><#&5DrfJ0nmXZ&{#^?iUV%{r)N;qTl`=wX^I`%(i z&TpDqWC`~{i;3r1CTnPs86@JDSE=eJJ&aKj6TP>o)fh9q(pBL3mBTvP4WyQ8JfNf0}Bg} ziUfxWj|c~V1Hiz-0kGk5uqZi!2rsE5H8iy>-0La0v_0M@ewIq=$ED_$P`9)SP4456 zHgE6@D=eCxaSPd|;rTnO8ATkL)%;UC8W(kt>N~o=7m(*YIi~_(In!VK2DiX2n{uLM z-qL>SF;_%-Wc~MKH>%BNWoXAfpf({`!>eB0%4S{R}a;q_6dMRoJk`MObo-!n2rynJ7@^m zWZFU(1}=RbdNe!yVJ(qlhrl}R;y=6{{G-bFY&&a^lG*wdt3?qodDf|6o7-b}PEr{U zcSFJK%L#9P)a2AO9yx~!w{-M}wofD57-$5hh8G-jvX(Zo+$0rkfJKeY-MB>hxQq)x zZ&ti+)XO1>kn9&}aCxnK#zihh{L>Da(6Hzoix8n!#`i3dS&mh5J`H^o10z#gN>AU| zLDRY!nYHDJO*qYTy?HcXo9;pKV>jimc<8@z;0T)4^()Q1H^`U<#iY5B#zk=@r|4PH zmk46Os0Ykf=)}us$4ae)8N)c^fa9rAZtDxML?p{;z1U38uwK*mq8`V2lT3I~;Cy|* z>*6u!LX5>Q_}Lb&rbC6{&FMZlEFbrhB{e@Lyhzo+XU66KKVD2gjvrz#}OxXlvn!QGAg*Wjq4;w6?QbTOa%DqQZ{@okq63)M7B1 zZOy9+0(CQ&so)ts&>Z;}&6!`u-a!%9Y9{~&&P1o`yG{eR#pczpY0Zf>ALTU*q`B^K znAy^QRI2^GZxGS?okXKTRm^9OmN}j2f&rQyem|2;bvJ>)L2*Q}7W}0o5jP_G3<$fU zU!`1(Zv#e4;!3tE(UrDMJxdb)U}?ilS~h`}gp8zL&%#ODxaXbE?Y2oEV_JE zo!+2?Ns2X!k2-~!fPa(6MVYbVo`oSjeuuBw$hzgx5de(lJ{w4OsxX@Ft$L5AYWdy2 z|1w;^wOG3R+>HOmM6Sws^WAI%|0}v?e(|!`UxOJ{99|1!Se8&sF+_D{?76tRUsA)F=`aHEQ;kbS0MZN0L4fv+QTizu)k)qwb1#wr3ykkW}eL z2PeBOO15FcyAs|CVbUR|iqWU|PJQ3nwtcky9&^B+@#aX&_r`4G9`D}lYIXWR7J@hT z5ei+Rm8~}V%mjTtW^7$_%6{Osx)sLks+7Z_OWl@BT$bjvCE$sv-~+IT4-HxlfSAAb z8L*&bpI0j|qY!fLAPa{)*fh26Sf3K7C37QhNPi36lQtQ%N!~P(S8Jd@V{#~1xxIF|W!PN4`9+6}(7?uDE zyv+s%kG2tQyLH!AHHEhkk#8tp&nvN&dLXHBl;`9n4QA!;g&oUNf-0{SmesNZak;Y0 zD+pHqfW2szMJ;=r2-mj56Z0Qg;&HRtj$jDRzw5M0Z@OB!WFDb9^0KUAuhhWnZ|z4fL*^D&%`u+Z-Dz-l(YzXOp64Fh zbL_ykayi#8|IB*$T==8OErL#)k#-tlt7Wq<#Oh7M^WE$x>aYss!yX;bQ%+t;&=4~0 zjndn|-ibJ^Or#Hsynrm^AJ-x8OkW@YFix&RtuL6fqk?ozITG-MpEo4yj~0nCeb;~| zLC8Tf+MIf>Bg2Ft=fP&QjtKO8?QbwzWj&pj>cLR1Rb~kQlHC-!o6cm%`Hc2RVth>W zqi%R*WlSG$=L4f-8<6DqO5`RQz(S_$t@;gRwqKw$wgEPd8IS4#et*l@9H0-wJy%Oz z&$~WqD^k>$rIUcQl$S*#Vw5{|E7u|Ntr=GjQFh@epG8DY9)6FfHx-1 zvc3#ao=vXi_rKELm^JpXW9}0?0ATEpcsIIRp3|aWsiJ%nB{t`>ND=fynDJbmDne^5 z5Vm+xYqAk;st}m`I@oWtN_#pH9Ixjs;N^iwzoh+m?GvkAmzMgTvrWp|R}aOC3^&zK zhO5C=qftLAvmh*sVU+xBTocdxc4;gJE4Eirq*mFTf#1(RyGC@OB6i$NPITTeTj?LQk zBG#Mi^o_xekKC&Rr#DGdIgnE~3<}yc_kuc2bx*VfRQ<57*bgo-h_mh$twJa)yq#q< zR=*tHTfEKmtZ;zZmp&T6cpbOES^sG3=;}<>0W1IhF9tV9w|-}kvhYNHB508{T`M2f zm?V-a9_{G6%r_fru74F%<;zaD*fE07%%Z)@03CMk`%VT$cZ@zP>Un z%IMp7=uXL@OB$&mB?V^ahCxAK2x)0SM7kMZ=ul~?A%>EcZWNFX>5!BX5yU&_|2+4e zbMJFM&HG`$@9e!-?6rPtt-YReCQyL=k>XxsZsy56u7RBg)Zqz|+sPpO&e=+a$2YyM z*oGE)Ti_#!iSPf#$1|@~N6^vJ$BfNSd-A+f)}WBB0MBB?BM}9rw8#Vk*THlUq0%vy zt6)*g@Q3c~Q)`IcOB>hJnOE9p=+`W7##@Kiz>44Q*PuqYnhl2YGjkJ$dpJcGQv@`q z!oK1z&?Iy7P0hX%!O+!mt=sy??H$OUSs3euH`+_Q@65J>C`TP1*)aM=hio(5Mq+ZM z*$6PY;(>9y%?gxt{i%U@a8Knht7qbUSup}SliG^4>*lz_zh>n3y=U>dU=rmx)~l)_ z4(88dK26Gy`MtlHVWkW!P-R&%t<&6+!B3#N*kWI04wfE+iRdg#r;x>t}IC z-CVut2gaU5p{RQlBmPuUAKgLW2?QJPw?Hm@0{xnhyyYCytVDIp{#N^C#dJ;pp0s$R z#pdX@XdXqz*lGQ!FzY83OKD-ru5z*DpyNxfnJ4+A*O?0LIPPE05si10U4Y z_$>W;(dCoJvsa#&V2uNgb>0vYK&W)r#KBP8tPS^pew8$_>*__VbXv}GN6W)8F@KZD zQnoAcRH4B)PJaL+vrk}YEJxYSF?6G^0JX>YK4Q4feWbx){Z~DTHRRx}iAB`atV?TI zXn9<+b}(jvi)LcOs~9ypyd$p9zfF;^CfODu5-gLZOMd>U3@7AX)9?7p1LERA7(vHR#u5x%dC!JbzBspXKGX8|6RKGO6)g22z{W9H-m}sLfYjW8JEsU z*OvG|Jga$0==3+8{_}u)g(&T56pB`1xM8pHzHmUlt9&iYlMK&5Hys|k4md$mU8rZ;10 zvB_0kV@-4s)u-;LZiVE?(gJ+Borx(+;fcBThfJud`4@(1U>ym|ud{YkUH)9lpZfGa zD{DRS%77JaHiU-WzZoYk#d?kKKmP+j+ma_ii_gJjw5g^Bf;(yhJ*htn@BJ*D)2OEH zje~Qa3j>x%w=ZgWED{G&O8y!SFR_f8yjd^H*b~3y*;)FLFKG9Qa9TzmSDQSPw~VW) zHZhmEnL>cizoSKpd_i~D8j_gMczdxo5XrHAz`tPVk*9vYlTg~jvt;`hTM<8}i*f21 zg|7eVQ+3&=3O9+5P%^Sq%a6|eg2}?Lo+1tV4_8TBB!P0zGDp5Eg4e5FY1~_Vzulf~ z$vZKZ2wt#Vv8X+&UJGh!k%?;syEr#mESMuRqj)o2@p0y20Ym)ZPtLQ`)mPqNA>_07 z!&VL0Jn2g9X_y2HQPhhPdp|NSfBhv>eGaF?r-5eG{n>OiuM<#YYFJG;C$L-llEnJ{ zb!35e$LO%?H)Lk&(9M3OcYx?~(A>~9ol}B6(a|B5ka|t^X}+;MtMjBUfhn$2*e9 zP48X7Y~eSs+C|=%z_d-vHjLY;tfu$PPZn0=D4^z6a>G$4CfyicP;2n0^n6G5G|U={ zJb1VfUEXPYc5OVf7-(vk+z51;EiR;R0D zPIeUi98*W`TTT*oCv~g05}(F$;X@xrE`Tf6(4-?CP5~+tQ4UANKNx zTsu9Dhe8 z=kkmhN}qZT1*Oe6tcH6W*b!@~Bz8u%ApQ{%U{-3mpvW^{f!;&T$p!yGe>|B4yJ|=6 z{#M(SdO#dp%BXRltInKo&-M z8Os4>qWf$w=?q82&RCT{np9x=@WG=Ct*FvzcyVqkpN>69-8}#o9*RCkONi_9qphclW*0e|%OOu?C8=vC*OT`6#niCXoqQDcpjBOyLj$y_Xs8Y5-F<|;y1Zvr{n(5e&*#$u4P-(e>={SG?=L*oPv*Vn#81__?&XmKqer6|27hFraB-YTDfOrmw%9>rJ?t0*| zHPk2+di{o5X(puFIdz>ps^kd9k;)|pRaGf7uNBV_E6sE-Malift$Ap*?Jy4oc6r!T za+HVYaQ9X%a$gE%v8emsvJQ-xogklREY0zn zO&I7L0YjX2CfnVGQNPj}Y|!HAz-YcFkis(~n+PdQA%8O(k2g_i4&3<4*E*(A>H139 zMgGhn!Wh68Vg;yv46&f?ON~X-K@StMK{zAH9E;95dOLGGs?CR+tT>WZT}lWTxv%v> zf-!^SZjlRASo!QCLu_`f!H#<3$++f~fr^gt58aB*bh=3(wf(+oJN$_U&S5#nXu{YT z0Y~+7P)GOQiQQv3(Sh(Tkx7;6b5OMGx%Y3U5rNt4M`xx~InCI!n2U6o7)&+%v( zDsIa3Z`I&kw0KI>jA(Chdu5^Bp~%#dTC&i`o4BMoqCf1@q`e>Vwrv+r-P@GG?nyn5m{Ff{H~UibetWbQihrna2j#%7!*Z+YV>AHJyq-Gr^n`c_pr^T{AuU;j4T=d!j%mIy4cBt zjRssm-R?_1>Oq40;rY#Tbem_7;r%fiF%MiOh4q8(ne&Hn<^b+%^nxk9TQSTzbA2jX z-m8-z*jn{`GbnP9sH@SFzu%;x5Q<_E=BK5~b0wVR=yhZT2&q@yi`*!Car(7MhvD{w zce{ZhOs6zfXtci*`D#Gp`{=F zt7y9Z04(@y;kYwsN;h^th-ap~}4>4m)|zi9=d%i(IlHhg}m&JWd2YQk<36ucRWabghGS2kCOoR%G7 z+p#%k!fXo_O1k_WXIG9hUn1(98a=g30 z;01@9p0@R-F~R*t1H5u)l%N=*;d-;05RZd8^rRbt6`e~sgF43 zdI4jNgz!Eg13|>ih}!UR--qxwZ}Fzo(%LNbmeq#u6Mo%4)d?H@BAMo3!HR2tYmsZI zIEUfsY%}Qjf_19CWy?)aZfa4}wztaT7_P1DaKhi08{qWqN7k$UcGOK=;hjg)a<~N| zY9enqEqi!g40XkZP6_>3Oj9rARJsz|w_|msy0U@0^}iX2#6u9~N~$9{Cl?)6ISIQp zsejNa=Y6SfGVs^GSL0oxR6@cSOaG*4w*LKw@)n~oGwuZkWXEb-f4m?yY+SW8IqDp7 zudGjf2oFJbL5T>KC7|X9v*%Rs=3$q5YT!Y=5;k;K$RbJ{y#g&<_9)Odn>Ks}vM^l{;_fqIV=z|V-1wY_Rs@y?DWDVm{t-sAv{HuMS5 z>ae*}PbCD5PG*^B7&;Ty7`6Q*aikeYfm*}|_Vfm;?dW?}7WjA@I!`hE-BFu}<#9(e z%(4{Z9?<8renvt`BTIo--agDr|4OyoAVDI*o(Ws8cJKrLxLSdN0~{KyB!B9u%^~yA0ZR@O$+5h62z%;Ns+57KJI;Np?HZJ3p;H}I&vijCF({<-uQq30ydku<;6_^=AV18YesJ7SMe#0k(t7b0?Ag$L}<8Xt_*~-}{zNcVF zUpl_7fRsk(-5ui-a|0H!#}jjnzxFh@K#e?^)d60HH1@DjG#bDv^+p*_z_*+!R$PrL zgGh>j~_Izl)yCz}0CCEGxf zGw>M+iU&9C;QdGDwb+(Ea=7&=w{{9>fG9P?moU#OT5&CYQxYMK?@nH}Fjf|GYu8ljGbsA9lzC%BR!}vfN%R;3LNW>T0 z+sOr;UpLs0_o1Z$5^#N=5aDiDs&>)kFl|)Y0S3Oe6sdLzV*m0wD{koMeV5vj&D^^P z;81C(T4*Q9PDi0Bdah7&3e)wAhbkAqoMh7kopliCj?XCgVQ;b2*??UNwl4^yWrTm0 zePhCfFYsEB#pamw_JKP1(A?&(_28(Z{GuSu+^?)1G-0(7RPo4wy|+Wi?S)>eIA?WR zTmA)=%SlViy9-Gwe?hV>7QCr?A=F3U%IQVy0!o^h)j?Jz{P$U&IfaedDwA5HKrO~u zyRXR1bWg~ct329@kj9wh2l&Q?*_=@EUXiK?zq6M$)wN;r<^Kr&XFW_TOkiF1!(;Qv zFbcECZ{9cn7x0Jh+8v-^-jSoX&gX^0T^{L7z4nhev)&tXH@&q_A9|?K)925r{|E5P zZu3@+{zI7B!Kk_%=Xf2b;>V7K#qo#nqR{JOm;;XsiM`fx0ezVi4Eavq&VC) zT>14G;ZAqQ$$v0mFxsWNi#-(H`Sq~YJw-%bt4L`$?-)n$r`HTPHaqVAac@5Ib$+r@ z5&E1IL0GW40!DRhQXj@_I{g@YxS?A=vJE;++L zx+6PlO0p`fX~d=VA%m}RbIvmTNvoFvUjqAV*kqUX^z+QJh@)<;1uf!z=Bj?*(MUa6 z{1IokD<3`$i%f`tIbRB9wbYI!oU*FYU9AAWK!GQANc8edGUUGry13Aii4W7RmxGlq z4fXX~A10EkQO#hyqx?~AqPAMT2XPE0eR_qRdeh=|3|}=K#zPeU08ST$^DD?GIKIAy zz(P3HqVV5 zC{|ec<{Q44iEXAV1%ef4L=3Lr%#YVK5lef3<@^u_{rT&r5ojQP)mOv9st$b%zYk1U zDFV`DZIPMSSz4Ue3jZ27}fwHXZ2mdD+I>wC2o36E?{nKGF_}5BqD>O3Skfb!KKU=ndatUOt|Cg|iPw5xf zta=ezalmXm{lnrMo!>KITl6(HkZO_Vw*87gODEZ*MeeigAGzHMjzkZD7J;){gtX7x zE7tp`_XdCkKY1EM%Kcmdch8B$^F~)b*L^E^*ei%4l$iIG(=broLHmuprg$o!C##GM z`3hbl?iW*qTeCY44%i@m;3o9T9GJe&MeFW%_|1O40!Zw&H(4FGZkX}#%i0n%5-Eq} zNBpGj&ZvY|>XpL(*a~b?>W}x-dbtm>-Syl3avy`-U6g)lCi5AbvLrD945(=oQp%36 zU(y_72^4lZDLl$^?$v-?8Yc6Y4-w&9MmGG~wKP_N1S~#zNiy6kx45LSC=lBLI23PG z(JPk$Oo_)eYfW75BOROv!(vmuYCP&)*YSD&^;)@jc%}}k66#H%zg7SPwd8Z}X^Wu{ z@Z~BmN%@xj52?FP1O^j6;t;+td>{bWUEiB26&_*CI?{(qauIo<3TPC)dUvw=R3-)^ zN8cA{LGt@0KU8v%)$cg|2lFUI18jGY!o*bEFh9!T zJR*Uv(Oo97{)=6*L`(K+@dMWa7~Y5=IReWkLc+4>{4IGNos01B>LHOGAeMIBUY#tm z;r6`Gf=(1Ms#fD9z=8OY1>D)}4voqoV~nS@63WXl{V&Ou5UgY<->@znhD1SS2Yl2r zGpEeNk{Lu{5rY|&hji6&U-%gdVu*q>OGWAg8SJ8P|)xG#? z_4qJoM(!nGeWuVzmBv`#N*uNckLBCa!=Hv`Bn^f@tZ?6$BM@|&Ja~4nqNI8?Sz#p#q)4GevprMDP>l3 z$ydz~DS1XeKcC~sJwBk3t{5Al1R(51gNk-~od6=QUs6Lhl#tI!Jhj`%C&S5U(ohT- z9|foDsDB~^)Xn)obTH#r>;SF)4-WH>hC1#iYhmHgslZkf2~&p{HjQACzIxRFXEk7! zu16J>4-*-AV4rh1aV4|!1KK3UVbh}B&;z{ts#E)`&fyJS0*F5V_qzwAA zAD-VUu#YFe+SVhOhF-;hNn8qZz*6i@%FkQ))O->_nS0z~G!yX%`tJDhyaY%C?CB$R z9JXK}mkYndc%kSknkHk{Wtxv5er=fpe+k|rs$=W~b(eHLUF`~*$&5s<*a(0*P;a<1 zl(a^vY^!JG;MX31#1PZ?lM_Q4@@_=r!!?`=7GY7yCq?}q@ICt^@%NfFSPod%4#A*y zQ{dZIB<={J(ORz0qoxFL-kd>8*-`1L*(NhPD#+L^9Xr~GDKGDMX_AEEV+}^O5u8Iv}hKu=MwJzO2O~n!(+tfbY;m{L|$4WXG@6OSRrY$2Xb|r^NFBU zfpOYtI&q)`VL1WJ7r-CkzA{C%Hqpt~xkT;_p%i~o2kgqzd6vGJ8(hT^mu{Gd0@q{8iss8W3@K$*tO&y-h^3|}PFpCr3D4LTvoo|MZFsh&gf$oM)MmSo7?HDku zgT6n5ZZIA;nGgx1FX%d_%CufWUlz1oBO-H_IrQkFU2_=okip641StHC8~BM7rdm5g z$Yo~9Yc+6zO*+BDrqknzbN9h7oyQPEaV_7}Ii>GaZLJZ$Jzst}zA6FNfm@Yon;ls` z3gxTdCLPKGFgIu9!G0D`=KGl4lLKyR>nFU|ZAEz*tQw!F_8dTtT*qm=l0y;md? zYi!Uc49f99*sJWxg=;xQhmLq)xbYR)ci<3krR|-S?3na0!TJVXa%g@_m_4F_{b%+X zPnb70r-48XycUdn(8gzw%+^wqN8L5T=VNaA)S|o9`d1V>!~}-rw3E(%Fs&c>sD>x* zsdE7DXKmtcn_-FF@I$_7aNZgVGRoDxLvD{}?t<#|9c#skVvk-N+ex&$xa_^=ajq6x zv#6O69iZEJxRXcf1tqE$8(xWU#){-<6)uu;%rS_RG?Bxocen2mXMD!Ap3!K*NShlI zV<^ewJQvW=b=$$&)92CN`}HcIf~a>hj;n5`qxL0^QvW=?r~S}}j{YVwZs3*I$$aJa zVexz78!jHdbNyy8ahQnBK0I!c(>U+#Wl1sWs@!Lr8d(>&mO2uzxj23DpmP@2cEeKW zwJfNEUR7-_%V@qfsg$f8N*zsQKg!rR+3oftttb1C2tHEwf4(GbJ*YgK+@2WZI=e!N5IqS?3IHW<26(m zlbV|k&ACY!Dga8~@O0~5b6BXqD$#E0>kV#~;Cue`!xqKX$*8!yj+>CF=E=2Zu5Znf zj#<3F*UlV9N7t7^yaA7;XNyBF=|^&)t~ZuI$maq3h7eiN*e;LVBmG4B6y61CxchUO zMD_{=rdN4yJ4(NVZ!C{DGumqvT5W^6%)~Iwe(rAp0$Rw|ix@O=)X*yx5N5i9TaDV( z$8WRnr9G9TH8FJecGo_Y75sS{b~G6;^URhYN1D^yiMlHyrFau{1#n`GH0P{LVwfx5 zKV0Xq%)!VX(dgc%bha^PA*?<|1AiIW~?_9)QVF69$vwH2{+3!hn$V3ds z)k4v-gYIPDQ6H8j?-SaC?&2_mpSP3Dks0{K0EuX7sh$1D*yW0d{^G1e;VMFb;5SJ7 zVaWGk=g^;-wEC$d*@xqWJXQbr9*p~JJr~U>g17YA)>7|yN-xeWf;Uv@pzy5#(b^-zL7BNZ&5rw@b=1hANFgI`&}vN*7{>vh!kgw?LhpBNe@TzUxJ1uCz1 zXNsFW{iC`8@p=E`Qw0sViT5goBYDT$-+_*O1T z3;6HHIBk1(ii&Mu!%rPg?IclLm4!@{F*c@zMoUjo9y?lQneFgs6iwNr^2rX4662;( z1p`_Px;Kn%V0JNQ)P#V|nrh=GKp0|r_8ma9&)~W`9 zxjIc!5|Jk1*e2hX*x=v{eo3;Y2Bxj!MbS>{n?I;JaEV)Yg4pvB@Pu#wGyQ#QXuguen#}En-ZCsg|+6ZV?x_UC2+2#*Upo zi20E)e|eBO+o*u>zDwM*XnP;AoP2U;a7w<);=D}JA9o8m1s}aH2W~zzdcC*rw=~mlQ1n zJq88a8OSg4u^=Ri25$@t<02bj&J6sSw&?warsaE3Y5n-d>O{@v&j}mtM@5RU<5CnX z1;12BLQ_M2NzxO12VsX%R=czkQp@V9mg{p42g`<74d{v=+heUm%EG@ts8ZgtJ!X#)NyaW4{ia1I6KNpbRYq8F`!;HU`@qQT%|5r4 z{-m~h9@#j`{5h5JnwM>wuVvmj(CbS4h*EWzThHk(uWyC*Ey{lo+GpAi_*Gzz6m&oTPnz_ z(3Gj&2hDT}nPPQk4)h5>;Jq;NX3jY`;gjm_M9qiD(q+4k-P;n70QMHaBncm3I#V-- ztPf(M(#xby=VNc67 zJg-Zjg}|9Oj1MCA94KHBF`PM5CSxgzS4S0ed&(e+BKU%v14vRQz(V5F(>4MqV8I`wD|*AXp+4>2)Z_+e8f5hEB{1AXhMb2)lK@ z$fhG^A9R`!-9xwZvDzX1!81zJl{!(!i_IL$e=|6J`@J2_*-2s*CmxmubLP2<7GH6P zWgs)S@$~M|RO<97R_`*TSxlmMx#>PqFCtqHOCw!6^k7Dg%q3@UyTw}mxh9$j%DZQ! z)|0rkJWxVflTgLik7eN7;%+tNY9IM?%a9MzE&}8fV~FwE`JV_&B_|X^J$=IRZet}4 z*XUXGTL%vg0_MI3Z-@wu>K>I1BUbo*BotA)*MQ9`h|_I(}yC*6N^Cf&QGTF>Qvo+!*N)Eypef#fh5Y`afr4) zl|a7aXLiKU1*t^G_Zx6 z6(1JO`HvJ;MIDC4YJTjFg>F7PLf#Cmoe_zekNeyI2SydKW&L&RNRELIf^`iqD{HY2 z;u~-Cv+mCgfXz%6kY-;vov|{=6`G-Y^*ngF`1I|(u(OF^C`(RA| zfKKOpXP7NVSN3|b(FUVBg^kq{Yid4r5@aucCk30(m;tFXbBAgs8bIgCdiCmh58&vW z;j2uwXfjV8edW(F=uT3DEg8xSk~RWQ_oqTAR>XA{v6#vomW;|h1d3GYX54&5j;JHe zbzoGYo{TBy;(xhkL04JV1Gmv@9EW`%Dk*`ds)PS)8TCX&4=*;5w-@`NeUQnNzz2!% z`7ZNwr0WA3PhZK+D=rNCR#M`FSYzz~1c{}$a=0b%)U!xzqak??SbyXyb2|H*`eYG% zx$X2Z;UU^4(z^e~QIn_KipZcqp4_2r47;Po{xaiUxb)-6vWiO&I?xH3gm5f{r6p zXvT6N$Yo_0iXb}zp6YvrSYu0S@!?6>tcM%Ywd2jzW;S}S6szW@$~i?jaPIfUy{?;b zU63ojBm@6F#ERQI+0>Z&3k3-jaxzIZ$qt+u9x5JE3=YbtKIuPK4vCsmnih_HjrW`DwcGK%qFA7AFfKdr^)#i@grV`-)JBR-_XQFqWgelhT?%4W8=g0-~ zWlvG^n`Z69m&AYhM8$52=bjomt`yG$9T)KB0sc5Quys*N5qLJEm%h015)I#dn~zD@ zS6qiL?Ue#&PmMlF55Eyj? zq!RTJT(h(-|B`*SVp0DtWQfnakClN8U0@Mul`+k}|L6p1K4JNsW=qn9&(XCm-t&4- zG7cYKU=!N3tD#pKOKs!=aKaiVtZn=d1w(y%8m9NqO`;->iBR*N6`&bJAB%xh@sa&` zPN-L&2f)n({BzgAust8v4qZuh8*p@jj_=e z_p?TFI5{eOuNS}()>3(~UUVb4tS9~~^U&lNw*+CDCxTh{%vUB&i8CAPG*m&7`KtiS zv4!f{-DVbzF~%B4c~seWyR|Sy<|b`s5^THq{QOU{(?5kvt{= zcOHNed;8ms(ozFSG&!q$FnjBO(FJTIRDxw$k=;EiTHiJD28}E^FkD~C(kqyCKf1(G zE0v)F$k8DV>qNt#4r!6yPVB7ekT&5fA8Y=-uqCt?`zq08Cipok|=`NImuNy~y;VPBOmFI&mDJseqkQlg456HeN z;tiTm(zST9S}eHNq#O~d8t>{`?*=PX5%*B~CWYuuHp!A!j?QCntOrVQAYNAGN6p;5 zrb*bT3)jDw^-x2quOp*)jbt*BC#G~i-8-IHI z&;$^M1{VB+LIM0lREmd#Auk;C{%-2Obv|N1)YOJSp-Q-`;ne?avkFP>i7aSfYOBNq zHXD)rn?H4zpT|+2#dK&S$7D3d)h|Y-2(QTr-mm<4*x>h4(=URGuAi+yeW9P`&8Zdn zrv^(TMnOqmr7x-9j)iFcbjlx&NOL=-wlLN6h~( DMoeY= literal 0 HcmV?d00001 From e21b9a6c37d808c95415de90b58f887264f54711 Mon Sep 17 00:00:00 2001 From: Vikhyath Mondreti Date: Fri, 11 Sep 2026 12:09:27 -0700 Subject: [PATCH 09/15] fix(provenance): preserve execution files across durable surfaces (#7778) * fix(provenance): preserve execution files across durable surfaces * fix(provenance): preserve storage identity and consumer admission --- .../payloads/file-secret-provenance.test.ts | 124 +++++ .../payloads/file-secret-provenance.ts | 61 +++ .../payloads/materialization.server.test.ts | 33 +- .../payloads/materialization.server.ts | 45 +- .../application/execute-function.test.ts | 25 + .../application/execute-function.ts | 6 + .../execute-request.test.ts | 510 +++++++++++++++++- .../lib/function-execution/execute-request.ts | 217 ++++++-- .../function-execution/sandbox-mounts.test.ts | 89 +++ .../lib/function-execution/sandbox-mounts.ts | 50 +- .../lib/internal/file/execute-tool.test.ts | 6 +- apps/sim/lib/internal/file/execute-tool.ts | 1 + .../file/operations.provenance.test.ts | 104 +++- apps/sim/lib/internal/file/operations.test.ts | 245 ++++++++- apps/sim/lib/internal/file/operations.ts | 246 ++++++--- apps/sim/lib/internal/file/parser.test.ts | 378 ++++++++++++- apps/sim/lib/internal/file/parser.ts | 182 ++++++- .../sim/lib/internal/function/execute.test.ts | 6 + apps/sim/lib/internal/function/execute.ts | 3 + ...xecution-archive-provenance.integration.ts | 491 +++++++++++++++++ .../document-processing-source.test.ts | 136 +++++ apps/sim/lib/knowledge/documents/service.ts | 60 ++- .../workspace-source-provenance.test.ts | 132 +++++ .../execution/execution-file-manager.test.ts | 105 +++- .../execution/execution-file-manager.ts | 68 ++- .../workspace-file-secret-provenance.test.ts | 164 +++++- .../workspace-file-secret-provenance.ts | 79 ++- apps/sim/lib/uploads/server/metadata.ts | 23 +- .../uploads/utils/file-utils.server.test.ts | 52 +- .../lib/uploads/utils/file-utils.server.ts | 18 +- .../page-document.server.test.ts | 76 ++- .../workspace-files/page-document.server.ts | 74 ++- apps/sim/tools/file/parser.test.ts | 13 +- apps/sim/tools/file/parser.ts | 2 + apps/sim/tools/index.test.ts | 60 +++ 35 files changed, 3639 insertions(+), 245 deletions(-) create mode 100644 apps/sim/lib/execution/payloads/file-secret-provenance.test.ts create mode 100644 apps/sim/lib/execution/payloads/file-secret-provenance.ts create mode 100644 apps/sim/lib/knowledge/__integration__/execution-archive-provenance.integration.ts diff --git a/apps/sim/lib/execution/payloads/file-secret-provenance.test.ts b/apps/sim/lib/execution/payloads/file-secret-provenance.test.ts new file mode 100644 index 00000000000..0afa418d05b --- /dev/null +++ b/apps/sim/lib/execution/payloads/file-secret-provenance.test.ts @@ -0,0 +1,124 @@ +/** @vitest-environment node */ +import { beforeEach, describe, expect, it, vi } from 'vitest' + +const { metadata, readWorkspaceFile } = vi.hoisted(() => ({ + metadata: vi.fn(), + readWorkspaceFile: vi.fn(), +})) + +vi.mock('@/lib/uploads/server/metadata', () => ({ getFileMetadataByKey: metadata })) +vi.mock('@/lib/workspace-files/application/read-workspace-file-content-by-key', () => ({ + readWorkspaceFileRecordByKey: { execute: readWorkspaceFile }, +})) + +import { resolveStoredFileProvenanceSource } from '@/lib/execution/payloads/file-secret-provenance' + +const context = { + principal: { kind: 'session', userId: 'reader', sessionId: 'session' } as const, + workspaceId: 'workspace-1', + workflowId: 'workflow-1', + executionId: 'execution-1', +} +const file = { + key: 'execution/workspace-1/workflow-1/execution-1/unique/archive.zip', + context: 'execution' as const, +} +const revision = new Date('2026-09-11T00:00:00.000Z') +const record = { + id: 'canonical-file', + key: file.key, + context: 'execution', + workspaceId: context.workspaceId, + userId: 'writer', + contentUpdatedAt: revision, +} + +describe('stored file provenance source', () => { + beforeEach(() => { + vi.clearAllMocks() + metadata.mockResolvedValue(record) + readWorkspaceFile.mockResolvedValue({ file: {} }) + }) + + it('uses the canonical execution file identity and revision', async () => { + expect(await resolveStoredFileProvenanceSource(file, context)).toEqual({ + identity: { + fileId: record.id, + key: record.key, + context: 'execution', + contentUpdatedAt: revision, + }, + ownerUserId: 'writer', + }) + expect(metadata).toHaveBeenCalledWith(file.key, undefined, { includeDeleted: true }) + }) + + it.each([ + { workspaceId: 'foreign-workspace' }, + { workflowId: 'foreign-workflow' }, + { executionId: 'foreign-execution' }, + ])('refuses an out-of-scope file before metadata lookup: %j', async (scope) => { + await expect(resolveStoredFileProvenanceSource(file, { ...context, ...scope })).rejects.toThrow( + 'File not found' + ) + expect(metadata).not.toHaveBeenCalled() + }) + + it('accepts a causally inherited file key in the same workflow', async () => { + await expect( + resolveStoredFileProvenanceSource(file, { + ...context, + executionId: 'resumed-execution', + fileKeys: [file.key], + }) + ).resolves.toMatchObject({ identity: { fileId: 'canonical-file' } }) + }) + + it('does not let a file key allowlist cross workspaces', async () => { + await expect( + resolveStoredFileProvenanceSource(file, { + ...context, + workspaceId: 'foreign-workspace', + fileKeys: [file.key], + }) + ).rejects.toThrow('File not found') + expect(metadata).not.toHaveBeenCalled() + }) + + it('rejects a forged context before metadata lookup', async () => { + await expect( + resolveStoredFileProvenanceSource({ ...file, context: 'workspace' }, context) + ).rejects.toThrow('File context does not match its storage key') + expect(metadata).not.toHaveBeenCalled() + }) + + it.each([ + { workspaceId: 'foreign-workspace' }, + { context: 'workspace' }, + { context: 'knowledge-base' }, + ])('rejects mismatched canonical metadata: %j', async (changes) => { + metadata.mockResolvedValue({ ...record, ...changes }) + await expect(resolveStoredFileProvenanceSource(file, context)).rejects.toThrow('File not found') + }) + + it('preserves a missing legacy record as absence', async () => { + metadata.mockResolvedValue(null) + await expect(resolveStoredFileProvenanceSource(file, context)).resolves.toBeUndefined() + }) + + it('does not turn metadata lookup failures into legacy absence', async () => { + metadata.mockRejectedValue(new Error('database unavailable')) + await expect(resolveStoredFileProvenanceSource(file, context)).rejects.toThrow( + 'database unavailable' + ) + }) + + it('requires the workspace file use case before resolving a workspace source', async () => { + const workspaceFile = { key: 'workspace/workspace-1/file.txt', context: 'workspace' as const } + readWorkspaceFile.mockRejectedValue(new Error('Workspace access denied')) + await expect(resolveStoredFileProvenanceSource(workspaceFile, context)).rejects.toThrow( + 'Workspace access denied' + ) + expect(metadata).not.toHaveBeenCalled() + }) +}) diff --git a/apps/sim/lib/execution/payloads/file-secret-provenance.ts b/apps/sim/lib/execution/payloads/file-secret-provenance.ts new file mode 100644 index 00000000000..1af18b999b3 --- /dev/null +++ b/apps/sim/lib/execution/payloads/file-secret-provenance.ts @@ -0,0 +1,61 @@ +import type { Principal } from '@sim/auth/principal' +import { OrchestrationError } from '@/lib/core/orchestration/types' +import { + assertUserFileContentAccess, + ExecutionFileAccessError, + type ExecutionMaterializationContext, +} from '@/lib/execution/payloads/materialization.server' +import type { WorkspaceFileSecretProvenanceIdentity } from '@/lib/uploads/contexts/workspace/workspace-file-secret-provenance' +import { getFileMetadataByKey } from '@/lib/uploads/server/metadata' +import { inferContextFromKey } from '@/lib/uploads/utils/file-utils' +import type { UserFile } from '@/executor/types' + +export interface StoredFileProvenanceSource { + identity: WorkspaceFileSecretProvenanceIdentity + ownerUserId: string +} + +/** + * Binds an authorized stored-file read to its canonical content revision. Execution callers pass + * the same trusted run capability used to read the bytes; a file object's id is never an identity. + * Files predating metadata registration retain the caller's existing absence policy. + */ +export async function resolveStoredFileProvenanceSource( + file: Pick, + context: ExecutionMaterializationContext & { principal: Principal; workspaceId: string } +): Promise { + if (!file.key) return undefined + try { + await assertUserFileContentAccess(file, context) + } catch (error) { + if (error instanceof ExecutionFileAccessError) { + throw new OrchestrationError('not_found', 'File not found') + } + throw error + } + const storageContext = inferContextFromKey(file.key) + if (storageContext !== 'workspace' && storageContext !== 'execution') return undefined + + const metadata = await getFileMetadataByKey(file.key, undefined, { includeDeleted: true }) + if (!metadata) return undefined + if ( + (metadata.context !== 'workspace' && + metadata.context !== 'mothership' && + metadata.context !== 'execution') || + metadata.workspaceId !== context.workspaceId || + (storageContext === 'execution' + ? metadata.context !== 'execution' + : metadata.context !== 'workspace' && metadata.context !== 'mothership') + ) { + throw new OrchestrationError('not_found', 'File not found') + } + return { + identity: { + fileId: metadata.id, + key: metadata.key, + context: metadata.context, + contentUpdatedAt: metadata.contentUpdatedAt, + }, + ownerUserId: metadata.userId, + } +} diff --git a/apps/sim/lib/execution/payloads/materialization.server.test.ts b/apps/sim/lib/execution/payloads/materialization.server.test.ts index cdcdcd225d3..c7208738e04 100644 --- a/apps/sim/lib/execution/payloads/materialization.server.test.ts +++ b/apps/sim/lib/execution/payloads/materialization.server.test.ts @@ -1,6 +1,7 @@ /** * @vitest-environment node */ +import { resetDbChainMock } from '@sim/testing' import { beforeEach, describe, expect, it, vi } from 'vitest' const { mockDownloadServableFileFromStorage, mockReadWorkspaceFileByKey, mockVerifyFileAccess } = @@ -22,7 +23,10 @@ vi.mock('@/lib/workspace-files/application/read-workspace-file-content-by-key', readWorkspaceFileRecordByKey: { execute: mockReadWorkspaceFileByKey }, })) -import { readUserFileContent } from '@/lib/execution/payloads/materialization.server' +import { + readUserFileContent, + readUserFileContentWithContributors, +} from '@/lib/execution/payloads/materialization.server' import type { UserFile } from '@/executor/types' const PDF_SOURCE = Buffer.from('from reportlab.pdfgen import canvas') @@ -40,6 +44,7 @@ const generatedPdf: UserFile = { describe('readUserFileContent', () => { beforeEach(() => { vi.clearAllMocks() + resetDbChainMock() generatedPdf.size = PDF_SOURCE.length mockVerifyFileAccess.mockResolvedValue(true) mockReadWorkspaceFileByKey.mockResolvedValue({ file: { id: 'file-1' } }) @@ -49,6 +54,32 @@ describe('readUserFileContent', () => { }) }) + it('returns rendered contributor identities for the consuming boundary to classify', async () => { + const identity = { + fileId: 'image', + key: 'workspace/workspace-1/image.png', + context: 'workspace' as const, + contentUpdatedAt: new Date('2026-01-01T00:00:00Z'), + } + const html = '' + mockDownloadServableFileFromStorage.mockResolvedValue({ + buffer: Buffer.from(html), + contentType: 'text/html', + contributingFiles: [identity], + }) + + await expect( + readUserFileContentWithContributors( + { ...generatedPdf, name: 'page', type: 'text/x-sim-page' }, + { userId: 'user-1', encoding: 'text' } + ) + ).resolves.toEqual({ + content: html, + contributingFiles: [identity], + renderedContributingFiles: [identity], + }) + }) + it('returns the compiled artifact instead of the stored generation source', async () => { const content = await readUserFileContent(generatedPdf, { userId: 'user-1', diff --git a/apps/sim/lib/execution/payloads/materialization.server.ts b/apps/sim/lib/execution/payloads/materialization.server.ts index c5eafdedc6b..b919b3ca20b 100644 --- a/apps/sim/lib/execution/payloads/materialization.server.ts +++ b/apps/sim/lib/execution/payloads/materialization.server.ts @@ -63,6 +63,8 @@ export interface ReadUserFileContentOptions extends ExecutionMaterializationCont export interface ReadUserFileContentResult { content: string contributingFiles?: readonly WorkspaceFileSecretProvenanceIdentity[] + /** Subset transformed by the renderer; consumers apply their own admission policy. */ + renderedContributingFiles?: readonly WorkspaceFileSecretProvenanceIdentity[] } function getLogger(options: ExecutionMaterializationContext): Logger { @@ -215,10 +217,17 @@ function getExecutionKeyParts(key: string): } } +export class ExecutionFileAccessError extends Error { + constructor() { + super('File is not available in this execution.') + this.name = 'ExecutionFileAccessError' + } +} + function assertExecutionFileScope(key: string, options: ExecutionMaterializationContext): void { const parts = getExecutionKeyParts(key) if (!parts) { - throw new Error('File is not available in this execution.') + throw new ExecutionFileAccessError() } const allowedExecutionIds = new Set([ @@ -232,11 +241,11 @@ function assertExecutionFileScope(key: string, options: ExecutionMaterialization options.workflowId === parts.workflowId if (options.workspaceId && parts.workspaceId !== options.workspaceId) { - throw new Error('File is not available in this execution.') + throw new ExecutionFileAccessError() } if (options.workflowId && parts.workflowId !== options.workflowId) { - throw new Error('File is not available in this execution.') + throw new ExecutionFileAccessError() } if (allowedFileKeys.has(key)) { @@ -247,7 +256,7 @@ function assertExecutionFileScope(key: string, options: ExecutionMaterialization !options.executionId || (!allowedExecutionIds.has(parts.executionId) && !workflowScopeAllowed) ) { - throw new Error('File is not available in this execution.') + throw new ExecutionFileAccessError() } } @@ -344,7 +353,26 @@ export async function readUserFileContentWithContributors( throw new Error('Expected a file object with metadata.') } - await assertUserFileContentAccess(file, options) + let sourceIdentity: WorkspaceFileSecretProvenanceIdentity | undefined + const storageContext = file.key ? inferContextFromKey(file.key) : undefined + if ( + (storageContext === 'execution' || storageContext === 'workspace') && + options.principal && + options.workspaceId + ) { + const { resolveStoredFileProvenanceSource } = await import( + '@/lib/execution/payloads/file-secret-provenance' + ) + sourceIdentity = ( + await resolveStoredFileProvenanceSource(file, { + ...options, + principal: options.principal, + workspaceId: options.workspaceId, + }) + )?.identity + } else { + await assertUserFileContentAccess(file, options) + } const maxSourceBytes = options.maxSourceBytes ?? MAX_FUNCTION_FILE_BYTES if (Number.isFinite(file.size) && file.size > maxSourceBytes) { @@ -357,6 +385,7 @@ export async function readUserFileContentWithContributors( let buffer: Buffer | null = null let contributingFiles: readonly WorkspaceFileSecretProvenanceIdentity[] | undefined + let renderedContributingFiles: readonly WorkspaceFileSecretProvenanceIdentity[] | undefined const log = getLogger(options) const requestId = options.requestId ?? 'unknown' @@ -365,7 +394,10 @@ export async function readUserFileContentWithContributors( maxBytes: maxSourceBytes, }) buffer = servable.buffer - contributingFiles = servable.contributingFiles + renderedContributingFiles = servable.contributingFiles + contributingFiles = sourceIdentity + ? [sourceIdentity, ...(servable.contributingFiles ?? [])] + : servable.contributingFiles } catch (error) { if (isPayloadSizeLimitError(error)) { if (isGeneratedDocumentSourceType(file.type) && error.observedBytes !== undefined) { @@ -402,6 +434,7 @@ export async function readUserFileContentWithContributors( return { content: options.encoding === 'base64' ? bufferToBase64(selected) : selected.toString('utf8'), ...(contributingFiles && contributingFiles.length > 0 ? { contributingFiles } : {}), + ...(renderedContributingFiles?.length ? { renderedContributingFiles } : {}), } } diff --git a/apps/sim/lib/function-execution/application/execute-function.test.ts b/apps/sim/lib/function-execution/application/execute-function.test.ts index 156ee2d7542..4f4fa7542d0 100644 --- a/apps/sim/lib/function-execution/application/execute-function.test.ts +++ b/apps/sim/lib/function-execution/application/execute-function.test.ts @@ -26,6 +26,7 @@ vi.mock('@sim/platform-authz/workspace', () => ({ import { FUNCTION_EXECUTION_DELEGATION_AUDIENCE } from '@/lib/function-execution/application/authorization' import { executeFunction } from '@/lib/function-execution/application/execute-function' +import { ResolvedSecretTraceRegistry } from '@/executor/utils/resolved-secret-trace-registry' const principal: WorkflowExecutionDelegatedPrincipal = { kind: 'delegated', @@ -154,4 +155,28 @@ describe('executeFunction', () => { expect(mocks.loadWorkspace).not.toHaveBeenCalled() expect(mocks.executeRequest).not.toHaveBeenCalled() }) + + it('passes trusted registry state outside the parsed Function wire body', async () => { + const registry = new ResolvedSecretTraceRegistry([], { + userId: 'workspace-owner', + workspaceId: 'workspace-1', + }) + await executeFunction.execute({ + principal, + input: { + workspaceId: 'workspace-1', + body: { + code: 'return 1', + workspaceId: 'workspace-1', + workflowId: 'workflow-1', + executionId: 'execution-1', + }, + headers: new Headers(), + resolvedSecretTraceRegistry: registry, + }, + }) + + expect(mocks.executeRequest.mock.calls[0][2].resolvedSecretTraceRegistry).toBe(registry) + expect(mocks.executeRequest.mock.calls[0][1]).not.toHaveProperty('resolvedSecretTraceRegistry') + }) }) diff --git a/apps/sim/lib/function-execution/application/execute-function.ts b/apps/sim/lib/function-execution/application/execute-function.ts index 66b73058abe..c5a8e2998c4 100644 --- a/apps/sim/lib/function-execution/application/execute-function.ts +++ b/apps/sim/lib/function-execution/application/execute-function.ts @@ -5,6 +5,7 @@ import { OrchestrationError } from '@/lib/core/orchestration/types' import { functionExecutionDelegationPolicy } from '@/lib/function-execution/application/authorization' import { functionExecutionOperations } from '@/lib/function-execution/application/operations' import { resolveActiveWorkspaceApplicationContext } from '@/lib/workspaces/application/workspace-context' +import type { ResolvedSecretTraceRegistry } from '@/executor/utils/resolved-secret-trace-registry' export interface ExecuteFunctionInput { workspaceId: string @@ -12,6 +13,8 @@ export interface ExecuteFunctionInput { headers: Headers signal?: AbortSignal sandboxProfile?: 'mothership' + /** Trusted in-process provenance state; never accepted from the Function request body. */ + resolvedSecretTraceRegistry?: ResolvedSecretTraceRegistry } /** @@ -57,6 +60,9 @@ export const executeFunction = defineAuthorizedWorkspaceUseCase({ { attributedUserId, principal, + ...(input.resolvedSecretTraceRegistry + ? { resolvedSecretTraceRegistry: input.resolvedSecretTraceRegistry } + : {}), ...(subject?.kind === 'sim_user' ? { fileAccessUserId: subject.userId } : {}), ...(input.sandboxProfile ? { sandboxProfile: input.sandboxProfile } : {}), } diff --git a/apps/sim/lib/function-execution/execute-request.test.ts b/apps/sim/lib/function-execution/execute-request.test.ts index 4b821c084cb..36ceb0a0e59 100644 --- a/apps/sim/lib/function-execution/execute-request.test.ts +++ b/apps/sim/lib/function-execution/execute-request.test.ts @@ -6,11 +6,14 @@ import { readFileSync } from 'node:fs' import { resolve } from 'node:path' import { createMockRequest, + dbChainMockFns, envFlagsMock, hybridAuthMockFns, + resetDbChainMock, resetEnvFlagsMock, workflowsUtilsMock, } from '@sim/testing' +import JSZip from 'jszip' import { NextRequest } from 'next/server' import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest' import { functionExecuteBodySchema } from '@/lib/api/contracts' @@ -42,6 +45,9 @@ const { mockUploadFile, mockValidateWorkspaceFileWriteTarget, mockWriteWorkspaceFileByPath, + mockUploadExecutionFile, + mockMountContributors, + mockRenderedMountContributors, } = vi.hoisted(() => ({ mockExecuteInSandbox: vi.fn(), mockExecuteInIsolatedVM: vi.fn(), @@ -60,6 +66,9 @@ const { mockUploadFile: vi.fn(), mockValidateWorkspaceFileWriteTarget: vi.fn(), mockWriteWorkspaceFileByPath: vi.fn(), + mockUploadExecutionFile: vi.fn(), + mockMountContributors: vi.fn(), + mockRenderedMountContributors: vi.fn(), })) vi.mock('@/lib/core/security/encryption', () => ({ @@ -146,6 +155,10 @@ vi.mock('@/lib/uploads', () => ({ }, })) +vi.mock('@/lib/uploads/contexts/execution/execution-file-manager', () => ({ + uploadExecutionFile: mockUploadExecutionFile, +})) + vi.mock('@/lib/workflows/utils', () => workflowsUtilsMock) /** @@ -162,6 +175,8 @@ vi.mock('@/lib/function-execution/sandbox-mounts', () => ({ }: { planned: Array<{ userFile: { name: string }; mountPath: string }> }) => ({ + contributingFiles: mockMountContributors(), + renderedContributingFiles: mockRenderedMountContributors(), sandboxFiles: planned.map(({ mountPath }) => ({ type: 'url' as const, path: mountPath, @@ -180,9 +195,14 @@ import { validateExternalUrl } from '@/lib/core/security/input-validation' import { clearLargeValueCacheForTests } from '@/lib/execution/payloads/cache' import { isLargeArrayManifest } from '@/lib/execution/payloads/large-array-manifest-metadata' import { isLargeValueRef } from '@/lib/execution/payloads/large-value-ref' +import * as fileMaterialization from '@/lib/execution/payloads/materialization.server' import { executeFunctionRequest } from '@/lib/function-execution/execute-request' +import { ResolvedSecretTraceRegistry } from '@/executor/utils/resolved-secret-trace-registry' -async function POST(request: NextRequest): Promise { +async function POST( + request: NextRequest, + resolvedSecretTraceRegistry?: ResolvedSecretTraceRegistry +): Promise { const auth = await hybridAuthMockFns.mockCheckInternalAuth(request) if (!auth.success || !auth.userId) { return Response.json({ error: auth.error || 'Unauthorized' }, { status: 401 }) @@ -204,6 +224,7 @@ async function POST(request: NextRequest): Promise { return executeFunctionRequest({ headers: request.headers, signal: request.signal }, parsed.data, { attributedUserId: auth.userId, + resolvedSecretTraceRegistry, principal: { kind: 'delegated', serviceId: 'executor', @@ -247,6 +268,18 @@ const MOUNT_REF = { describe('Function execution request', () => { beforeEach(() => { vi.clearAllMocks() + resetDbChainMock() + mockMountContributors.mockReturnValue(undefined) + mockRenderedMountContributors.mockReturnValue(undefined) + mockUploadExecutionFile.mockImplementation(async (context, buffer, name, type) => ({ + id: 'execution-file-1', + key: `execution/${context.workspaceId}/${context.workflowId}/${context.executionId}/file/${name}`, + context: 'execution', + name, + type, + size: buffer.length, + url: 'https://presigned.example/output', + })) envFlagsMock.isRemoteSandboxEnabled = false envFlagsMock.isMothershipSandboxEnabled = false @@ -1792,6 +1825,375 @@ describe('Function execution request', () => { expect(data.error).toContain('21 files') }) + it.each([ + { name: 'report.zip', secret: undefined, expectedStatus: 'exact' }, + { name: 'report.zip', secret: 'super-secret-value', expectedStatus: 'unknown' }, + { name: 'report.txt', secret: 'super-secret-value', expectedStatus: 'unknown' }, + ])( + 'preserves binary provenance for harvested $name with secret=$secret', + async ({ name, secret, expectedStatus }) => { + envFlagsMock.isRemoteSandboxEnabled = true + const zip = new JSZip() + zip.file('report.txt', secret ?? 'ordinary report') + const buffer = await zip.generateAsync({ type: 'nodebuffer', compression: 'DEFLATE' }) + expect(buffer.includes('super-secret-value')).toBe(false) + mockExecuteInSandbox.mockResolvedValueOnce({ + result: null, + stdout: '', + sandboxId: 'sbx', + collectedFiles: [ + { + relativePath: name, + path: `/tmp/sim/outputs/${name}`, + contentBase64: buffer.toString('base64'), + byteLength: buffer.length, + }, + ], + }) + + const response = await POST( + createMockRequest('POST', { + code: secret ? 'token = {{MY_SECRET}}' : 'x = 1', + language: 'python', + workspaceId: 'workspace-1', + workflowId: 'workflow-1', + executionId: 'execution-1', + ...(secret ? { envVars: { MY_SECRET: secret } } : {}), + }) + ) + + expect(response.status).toBe(200) + expect(mockUploadExecutionFile).toHaveBeenCalledWith( + expect.any(Object), + buffer, + name, + expect.any(String), + 'user-123', + expectedStatus === 'exact' ? { status: 'exact', entries: [] } : { status: 'unknown' } + ) + const data = await response.json() + expect(data.output.files[0]).not.toHaveProperty('secretProvenance') + } + ) + + it('keeps text-looking bytes opaque when their declared format is an archive', async () => { + envFlagsMock.isRemoteSandboxEnabled = true + const buffer = Buffer.from('ASCII archive placeholder') + mockExecuteInSandbox.mockResolvedValueOnce({ + result: null, + stdout: '', + sandboxId: 'sbx', + collectedFiles: [ + { + relativePath: 'report.zip', + path: '/tmp/sim/outputs/report.zip', + contentBase64: buffer.toString('base64'), + byteLength: buffer.length, + }, + ], + }) + const response = await POST( + createMockRequest('POST', { + code: 'token = {{MY_SECRET}}', + language: 'python', + workspaceId: 'workspace-1', + workflowId: 'workflow-1', + executionId: 'execution-1', + envVars: { MY_SECRET: 'super-secret-value' }, + }) + ) + expect(response.status).toBe(200) + expect(mockUploadExecutionFile.mock.calls[0][5]).toEqual({ status: 'unknown' }) + }) + + it('refuses an unknown tracked execution mount before running code', async () => { + envFlagsMock.isRemoteSandboxEnabled = true + const updatedAt = new Date('2026-01-01T00:00:00Z') + mockMountContributors.mockReturnValue([ + { + fileId: 'execution-file-1', + key: 'execution/workspace-1/workflow-1/execution-1/a/input.zip', + context: 'execution', + contentUpdatedAt: updatedAt, + }, + ]) + dbChainMockFns.limit.mockResolvedValue([ + { + fileContentUpdatedAt: updatedAt, + secretProvenanceVersion: 1, + provenanceContentUpdatedAt: updatedAt, + status: 'unknown', + entries: [], + }, + ]) + + const response = await POST( + createMockRequest('POST', { + code: 'x = 1', + language: 'python', + workspaceId: 'workspace-1', + workflowId: 'workflow-1', + executionId: 'execution-1', + }) + ) + expect(response.status).toBe(400) + expect((await response.json()).error).toContain('File secret provenance is unavailable') + expect(mockExecuteInSandbox).not.toHaveBeenCalled() + expect(mockUploadExecutionFile).not.toHaveBeenCalled() + }) + + it('imports exact mount secrets into the trusted result registry and binary export classifier', async () => { + envFlagsMock.isRemoteSandboxEnabled = true + const updatedAt = new Date('2026-01-01T00:00:00Z') + const registry = new ResolvedSecretTraceRegistry([], { + userId: 'user-123', + workspaceId: 'workspace-1', + }) + const completePending = registry.beginPendingActivation() + mockMountContributors.mockReturnValue([ + { + fileId: 'execution-file-1', + key: 'execution/workspace-1/workflow-1/execution-1/a/input.txt', + context: 'execution', + contentUpdatedAt: updatedAt, + }, + ]) + dbChainMockFns.limit.mockResolvedValue([ + { + fileContentUpdatedAt: updatedAt, + secretProvenanceVersion: 1, + provenanceContentUpdatedAt: updatedAt, + status: 'exact', + entries: [ + { + name: 'API_KEY', + encryptedValue: 'encrypted:mounted-secret', + sourceUserId: 'user-123', + sourceWorkspaceId: 'workspace-1', + }, + ], + }, + ]) + const zip = new JSZip() + zip.file('result.txt', 'mounted-secret') + const buffer = await zip.generateAsync({ type: 'nodebuffer', compression: 'DEFLATE' }) + mockExecuteInSandbox.mockResolvedValueOnce({ + result: 'mounted-secret', + stdout: '', + sandboxId: 'sbx', + collectedFiles: [ + { + relativePath: 'result.zip', + path: '/tmp/sim/outputs/result.zip', + contentBase64: buffer.toString('base64'), + byteLength: buffer.length, + }, + ], + }) + const response = await POST( + createMockRequest('POST', { + code: 'x = 1', + language: 'python', + workspaceId: 'workspace-1', + workflowId: 'workflow-1', + executionId: 'execution-1', + }), + registry + ) + completePending() + expect(response.status).toBe(200) + expect(registry.exportProvenance().entries).toEqual([ + expect.objectContaining({ encryptedValue: 'encrypted:mounted-secret' }), + ]) + expect(mockUploadExecutionFile.mock.calls[0][5]).toEqual({ status: 'unknown' }) + }) + + it.each([ + { input: 'contextVariables', archive: true, unredacted: false }, + { input: 'params', archive: true, unredacted: false }, + { input: 'contextVariables', archive: false, unredacted: false }, + { input: 'contextVariables', archive: true, unredacted: true }, + ] as const)( + 'classifies secret-bearing $input with archive=$archive and unredacted=$unredacted', + async ({ input, archive, unredacted }) => { + envFlagsMock.isRemoteSandboxEnabled = true + const plaintext = 'table-input-secret-value' + const registry = new ResolvedSecretTraceRegistry( + [ + { + name: 'API_KEY', + plaintext, + encryptedValue: plaintext, + scope: 'workspace', + ...(unredacted ? { unredacted: true as const } : {}), + }, + ], + { userId: 'user-123', workspaceId: 'workspace-1' } + ) + registry.recordResolvedAtInputPath('API_KEY', plaintext, [input, 'token']) + const zip = new JSZip() + zip.file('report.txt', plaintext) + const buffer = archive + ? await zip.generateAsync({ type: 'nodebuffer', compression: 'DEFLATE' }) + : Buffer.from(plaintext) + const name = archive ? 'report.zip' : 'report.txt' + mockExecuteInSandbox.mockResolvedValueOnce({ + result: null, + stdout: '', + sandboxId: 'sbx', + collectedFiles: [ + { + relativePath: name, + path: `/tmp/sim/outputs/${name}`, + contentBase64: buffer.toString('base64'), + byteLength: buffer.length, + }, + ], + }) + + const response = await POST( + createMockRequest('POST', { + code: input === 'params' ? "x = params['token']" : 'x = token', + language: 'python', + workspaceId: 'workspace-1', + workflowId: 'workflow-1', + executionId: 'execution-1', + [input]: { token: plaintext }, + }), + registry + ) + + expect(response.status).toBe(archive || unredacted ? 200 : 400) + if (archive) { + expect(mockUploadExecutionFile.mock.calls[0][5]).toEqual( + unredacted ? { status: 'exact', entries: [] } : { status: 'unknown' } + ) + } else { + expect(mockUploadExecutionFile).not.toHaveBeenCalled() + } + } + ) + + it.each([ + { reason: 'source-provenance-incomplete', status: 200 }, + { reason: 'entry-decrypt-failed', status: 400 }, + ] as const)( + 'distinguishes historical absence from provenance faults: $reason', + async ({ reason, status }) => { + envFlagsMock.isRemoteSandboxEnabled = true + const registry = new ResolvedSecretTraceRegistry([], { + userId: 'user-123', + workspaceId: 'workspace-1', + }) + registry.markIncomplete(reason) + const contentUpdatedAt = new Date('2026-01-01T00:00:00Z') + mockMountContributors.mockReturnValue([ + { + fileId: 'legacy-file', + key: 'execution/workspace-1/workflow-1/execution-1/a/input.txt', + context: 'execution', + contentUpdatedAt, + }, + ]) + dbChainMockFns.limit.mockResolvedValue([ + { + fileContentUpdatedAt: contentUpdatedAt, + secretProvenanceVersion: null, + provenanceContentUpdatedAt: null, + status: null, + entries: null, + }, + ]) + const buffer = Buffer.from('ordinary file') + mockExecuteInSandbox.mockResolvedValueOnce({ + result: null, + stdout: '', + sandboxId: 'sbx', + collectedFiles: [ + { + relativePath: 'report.zip', + path: '/tmp/sim/outputs/report.zip', + contentBase64: buffer.toString('base64'), + byteLength: buffer.length, + }, + ], + }) + const response = await POST( + createMockRequest('POST', { + code: 'x = 1', + language: 'python', + workspaceId: 'workspace-1', + workflowId: 'workflow-1', + executionId: 'execution-1', + }), + registry + ) + expect(response.status).toBe(status) + if (status === 200) + expect(mockUploadExecutionFile.mock.calls[0][5]).toEqual({ status: 'unrecorded' }) + else expect(mockUploadExecutionFile).not.toHaveBeenCalled() + } + ) + + it('does not taint a secret-free mounted file with unrelated secrets from an earlier block', async () => { + envFlagsMock.isRemoteSandboxEnabled = true + const updatedAt = new Date('2026-01-01T00:00:00Z') + const scope = { userId: 'user-123', workspaceId: 'workspace-1' } + const registry = new ResolvedSecretTraceRegistry([], scope) + await registry.importProvenance( + { + version: 1, + complete: true, + scope, + entries: [{ name: 'OTHER_SECRET', encryptedValue: 'unrelated-secret-value' }], + }, + { trusted: true } + ) + mockMountContributors.mockReturnValue([ + { + fileId: 'execution-file-1', + key: 'execution/workspace-1/workflow-1/execution-1/a/input.txt', + context: 'execution', + contentUpdatedAt: updatedAt, + }, + ]) + dbChainMockFns.limit.mockResolvedValue([ + { + fileContentUpdatedAt: updatedAt, + secretProvenanceVersion: 1, + provenanceContentUpdatedAt: updatedAt, + status: 'exact', + entries: [], + }, + ]) + const buffer = Buffer.from('archive without secret inputs') + mockExecuteInSandbox.mockResolvedValueOnce({ + result: null, + stdout: '', + sandboxId: 'sbx', + collectedFiles: [ + { + relativePath: 'result.zip', + path: '/tmp/sim/outputs/result.zip', + contentBase64: buffer.toString('base64'), + byteLength: buffer.length, + }, + ], + }) + const response = await POST( + createMockRequest('POST', { + code: 'x = 1', + language: 'python', + workspaceId: 'workspace-1', + workflowId: 'workflow-1', + executionId: 'execution-1', + }), + registry + ) + expect(response.status).toBe(200) + expect(mockUploadExecutionFile.mock.calls[0][5]).toEqual({ status: 'exact', entries: [] }) + }) + it('scans a harvested plaintext secret even under a binary file name', async () => { envFlagsMock.isRemoteSandboxEnabled = true mockExecuteInSandbox.mockResolvedValueOnce({ @@ -2479,6 +2881,112 @@ describe('Function execution request', () => { expect(data.success).toBe(true) expect(options?.brokers).toHaveProperty('sim.values.readArray') }) + + it.each([ + { status: 'exact', version: 1, secret: true, safe: false }, + { status: 'unknown', version: 1, secret: false, safe: false }, + { status: 'exact', version: 1, secret: false, safe: true }, + { status: null, version: null, secret: false, safe: true }, + ])( + 'applies rendered asset policy at Function admission while retaining legacy compatibility: %j', + async ({ status, version, secret, safe }) => { + const contentUpdatedAt = new Date('2026-01-01T00:00:00Z') + const identity = { + fileId: 'image-1', + key: 'workspace/workspace-1/image.png', + context: 'workspace' as const, + contentUpdatedAt, + } + const materialized = { + content: '', + contributingFiles: [identity], + renderedContributingFiles: [identity], + } + const read = vi + .spyOn(fileMaterialization, 'readUserFileContentWithContributors') + .mockResolvedValue(materialized) + dbChainMockFns.limit.mockResolvedValue([ + { + fileContentUpdatedAt: contentUpdatedAt, + provenanceContentUpdatedAt: contentUpdatedAt, + secretProvenanceVersion: version, + status, + entries: secret + ? [{ name: 'TOKEN', encryptedValue: 'ciphertext', sourceUserId: 'user-1' }] + : [], + }, + ]) + mockExecuteInIsolatedVM.mockImplementationOnce(async (_input, options) => ({ + result: await options.brokers['sim.files.readText']({ file: MOUNT_REF.file }), + stdout: '', + })) + const request = { + code: 'return 1', + language: 'javascript', + workspaceId: 'workspace-1', + workflowId: 'workflow-1', + executionId: 'execution-1', + } + try { + const brokerResponse = await POST(createMockRequest('POST', request)) + const brokerBody = await brokerResponse.json() + expect(brokerBody.success).toBe(safe) + if (!safe) expect(JSON.stringify(brokerBody)).not.toContain(materialized.content) + + mockMountContributors.mockReturnValue([identity]) + mockRenderedMountContributors.mockReturnValue([identity]) + const mountResponse = await POST(createMockRequest('POST', request)) + expect(mountResponse.status).toBe(safe ? 200 : 400) + expect((await mountResponse.json()).success).toBe(safe) + } finally { + read.mockRestore() + } + } + ) + + it('refuses unknown execution provenance returned by the runtime file broker', async () => { + const contentUpdatedAt = new Date('2026-01-01T00:00:00Z') + vi.spyOn(fileMaterialization, 'readUserFileContentWithContributors').mockResolvedValueOnce({ + content: 'private file content', + contributingFiles: [ + { + fileId: 'execution-file-1', + key: 'execution/workspace-1/workflow-1/execution-1/a/input.txt', + context: 'execution', + contentUpdatedAt, + }, + ], + }) + dbChainMockFns.limit.mockResolvedValue([ + { + fileContentUpdatedAt: contentUpdatedAt, + secretProvenanceVersion: 1, + provenanceContentUpdatedAt: contentUpdatedAt, + status: 'unknown', + entries: [], + }, + ]) + mockExecuteInIsolatedVM.mockImplementationOnce(async (_input, options) => ({ + result: await options.brokers['sim.files.readText']({ file: MOUNT_REF.file }), + stdout: '', + })) + + const response = await POST( + createMockRequest('POST', { + code: 'return 1', + language: 'javascript', + workspaceId: 'workspace-1', + workflowId: 'workflow-1', + executionId: 'execution-1', + }) + ) + + expect(response.status).toBe(500) + const data = await response.json() + expect(data.success).toBe(false) + expect(data.error).toContain('File secret provenance is unavailable') + expect(JSON.stringify(data)).not.toContain('private file content') + }) }) describe('Template Variable Resolution', () => { diff --git a/apps/sim/lib/function-execution/execute-request.ts b/apps/sim/lib/function-execution/execute-request.ts index 1392221fbd0..020b7b32f9d 100644 --- a/apps/sim/lib/function-execution/execute-request.ts +++ b/apps/sim/lib/function-execution/execute-request.ts @@ -55,7 +55,7 @@ import { MAX_INLINE_MATERIALIZATION_BYTES, } from '@/lib/execution/payloads/limits' import { - readUserFileContent, + readUserFileContentWithContributors, unavailableLargeValueError, } from '@/lib/execution/payloads/materialization.server' import { @@ -93,9 +93,13 @@ import { isExecutionResourceLimitError } from '@/lib/execution/resource-errors' import { planUserFileMounts, resolveUserFileMounts } from '@/lib/function-execution/sandbox-mounts' import { uploadExecutionFile } from '@/lib/uploads/contexts/execution/execution-file-manager' import { + createWorkspaceFileSecretProvenanceFromRegistry, EXACT_EMPTY_WORKSPACE_FILE_SECRET_PROVENANCE, + importWorkspaceFileSecretProvenanceForRuntime, + isOpaqueWorkspaceFileEgressSafe, mergeWorkspaceFileSecretProvenance, type WorkspaceFileSecretProvenance, + type WorkspaceFileSecretProvenanceIdentity, } from '@/lib/uploads/contexts/workspace/workspace-file-secret-provenance' import { deleteFiles } from '@/lib/uploads/core/storage-service' import { getFileExtension, getMimeTypeFromExtension } from '@/lib/uploads/utils/file-utils' @@ -117,7 +121,12 @@ import { scanResolvedSecretString, } from '@/executor/utils/resolved-secret-content-projection' import { isNonIdentifyingSecretLiteral } from '@/executor/utils/resolved-secret-match-policy' -import type { ResolvedSecretTraceProvenanceV1 } from '@/executor/utils/resolved-secret-trace-registry' +import type { + ResolvedSecretTraceProvenanceV1, + ResolvedSecretTraceRegistry, +} from '@/executor/utils/resolved-secret-trace-registry' + +const TEXT_OUTPUT_MIME_TYPES = new Set(Object.values(FORMAT_TO_CONTENT_TYPE)) const logger = createLogger('FunctionExecuteAPI') @@ -1014,6 +1023,74 @@ interface FunctionRouteExecutionContext { */ unredactedSecretNames: Set mountedFileSecretProvenanceScanner?: MountedFileSecretProvenanceScanner + runtimeFileSecretProvenanceScanner?: MountedFileSecretProvenanceScanner + runtimeFileSecretTraceRegistry?: ResolvedSecretTraceRegistry + runtimeInputProvenanceUnrecorded?: boolean + resolvedSecretTraceRegistry?: ResolvedSecretTraceRegistry +} + +/** Keeps bound file provenance in both ordinary Function results and exported artifact bytes. */ +async function importRuntimeFileContributors( + context: FunctionRouteExecutionContext, + identities: readonly WorkspaceFileSecretProvenanceIdentity[] | undefined, + renderedIdentities: readonly WorkspaceFileSecretProvenanceIdentity[] = [] +): Promise { + if (!identities?.length && renderedIdentities.length === 0) return + if (!context.workspaceId) throw new Error('File provenance requires a workspace') + /** Sim-rendered assets can encode literals before user code runs; raw files retain runtime lineage. */ + for (const identity of renderedIdentities) { + if (!(await isOpaqueWorkspaceFileEgressSafe(context.workspaceId, identity))) { + throw new Error('File secret provenance is unavailable for Function execution') + } + } + if (!context.runtimeInputProvenanceUnrecorded) { + context.runtimeFileSecretTraceRegistry ??= + context.resolvedSecretTraceRegistry?.forkForInputPaths([]) + } + for (const identity of identities ?? []) { + const imported = await importWorkspaceFileSecretProvenanceForRuntime({ + workspaceId: context.workspaceId, + identity, + registry: context.runtimeFileSecretTraceRegistry, + actorUserId: context.fileAccessUserId, + }) + if (!imported) throw new Error('File secret provenance is unavailable for Function execution') + } + if (context.runtimeFileSecretTraceRegistry && context.resolvedSecretTraceRegistry) { + context.resolvedSecretTraceRegistry.mergeToolCallRegistry( + context.runtimeFileSecretTraceRegistry + ) + } +} + +/** Includes only lineage carried by the values this Function receives, including deferred refs. */ +async function importRuntimeInputProvenance( + context: FunctionRouteExecutionContext, + inputs: { + code: string + params: Record + contextVariables: Record + } +): Promise { + const registry = context.resolvedSecretTraceRegistry + if (!registry) return + const valueProvenance = registry.exportCommittedProvenanceForValue(inputs) + if (!valueProvenance.complete && context.workspaceId) { + const decision = await createWorkspaceFileSecretProvenanceFromRegistry(registry, inputs, { + userId: context.attributedUserId, + workspaceId: context.workspaceId, + }) + if (decision.safe && decision.provenance.status === 'unrecorded') { + context.runtimeInputProvenanceUnrecorded = true + return + } + } + const inputRegistry = registry.forkForInputPaths(Object.keys(inputs).map((key) => [key])) + await inputRegistry.importProvenance(valueProvenance, { + trusted: true, + origin: 'function.runtimeInputs', + }) + context.runtimeFileSecretTraceRegistry = inputRegistry } type ResolvedSecretNamesMetadataType = @@ -1117,7 +1194,7 @@ function createFunctionRuntimeBrokers( const readFile = async (args: unknown, encoding: 'base64' | 'text', chunked = false) => { const fileArgs = getBrokerFileArgs(args) - return readUserFileContent(fileArgs.file, { + const materialized = await readUserFileContentWithContributors(fileArgs.file, { ...base, encoding, maxBytes: fileArgs.maxBytes, @@ -1125,6 +1202,12 @@ function createFunctionRuntimeBrokers( offset: chunked ? fileArgs.offset : undefined, length: chunked ? fileArgs.length : undefined, }) + await importRuntimeFileContributors( + context, + materialized.contributingFiles, + materialized.renderedContributingFiles + ) + return materialized.content } return { @@ -1256,7 +1339,10 @@ function countProtectedOutputSecretNames(context: FunctionRouteExecutionContext) */ function hasSecretMaterialInScope(context: FunctionRouteExecutionContext): boolean { if (countProtectedOutputSecretNames(context) > 0) return true - return context.mountedFileSecretProvenanceScanner?.hasSecrets ?? false + return Boolean( + context.mountedFileSecretProvenanceScanner?.hasSecrets || + context.runtimeFileSecretProvenanceScanner?.hasSecrets + ) } /** @@ -1274,15 +1360,34 @@ async function getOutputFileSecretProvenance( context: FunctionRouteExecutionContext, scope: { userId: string; workspaceId: string } ): Promise { + /** Runtime reads have settled before export; a broker cannot replace this with an older snapshot. */ + if (context.runtimeFileSecretTraceRegistry && !context.runtimeFileSecretProvenanceScanner) { + const provenance = context.runtimeFileSecretTraceRegistry.exportProvenance() + context.runtimeFileSecretProvenanceScanner = + await createMountedFileSecretProvenanceScanner(provenance) + if (!context.runtimeFileSecretProvenanceScanner && provenance.entries.length > 0) { + context.runtimeFileSecretProvenanceScanner = { + hasSecrets: true, + scan: () => ({ status: 'unknown' }), + } + } + } if (isBinary) { return hasSecretMaterialInScope(context) ? { status: 'unknown' } - : EXACT_EMPTY_WORKSPACE_FILE_SECRET_PROVENANCE - } - const mountedFileProvenance = context.mountedFileSecretProvenanceScanner?.scan(buffer) ?? { - status: 'exact' as const, - entries: [], + : context.runtimeInputProvenanceUnrecorded + ? { status: 'unrecorded' } + : EXACT_EMPTY_WORKSPACE_FILE_SECRET_PROVENANCE } + const mountedFileProvenance = mergeWorkspaceFileSecretProvenance( + context.mountedFileSecretProvenanceScanner?.scan(buffer) ?? + EXACT_EMPTY_WORKSPACE_FILE_SECRET_PROVENANCE, + context.runtimeFileSecretProvenanceScanner?.scan(buffer) ?? + EXACT_EMPTY_WORKSPACE_FILE_SECRET_PROVENANCE, + context.runtimeInputProvenanceUnrecorded + ? { status: 'unrecorded' } + : EXACT_EMPTY_WORKSPACE_FILE_SECRET_PROVENANCE + ) if (countProtectedOutputSecretNames(context) === 0) { return mountedFileProvenance } @@ -1531,12 +1636,11 @@ async function maybeExportSandboxFileToWorkspace(args: { const fileName = normalizeOutputWorkspaceFileName(outputPath) - const TEXT_MIMES = new Set(Object.values(FORMAT_TO_CONTENT_TYPE)) const resolvedMimeType = outputMimeType || FORMAT_TO_CONTENT_TYPE[resolveOutputFormat(fileName, outputFormat)] || 'application/octet-stream' - const isBinary = !TEXT_MIMES.has(resolvedMimeType) + const isBinary = !TEXT_OUTPUT_MIME_TYPES.has(resolvedMimeType) const outputBytes = Buffer.byteLength(exportedFileContent, isBinary ? 'base64' : 'utf-8') if (outputBytes > MAX_SANDBOX_OUTPUT_BYTES) { return exportFailure( @@ -1711,7 +1815,7 @@ async function maybeExportSandboxFilesToWorkspace(args: { file.mimeType || FORMAT_TO_CONTENT_TYPE[resolveOutputFormat(fileName, file.format)] || 'application/octet-stream' - const isBinary = !new Set(Object.values(FORMAT_TO_CONTENT_TYPE)).has(resolvedMimeType) + const isBinary = !TEXT_OUTPUT_MIME_TYPES.has(resolvedMimeType) const size = Buffer.byteLength(content, isBinary ? 'base64' : 'utf-8') totalOutputBytes += size if (totalOutputBytes > MAX_SANDBOX_OUTPUT_BYTES) { @@ -1926,16 +2030,6 @@ function collectedFileName(relativePath: string): string { return sanitizeFileName(relativePath.split('/').filter(Boolean).join('-')) || 'file' } -/** - * Persists files harvested from the sandbox output directory as platform file - * objects, so any downstream tool that accepts a file can consume them. - * - * Uploaded here, one at a time, rather than handed to the declarative - * file-output pipeline as bytes: that path would carry the whole export budget - * as base64 through `JSON.stringify`, a response buffer, and a re-parse, so - * several multiples of the payload would be live at once for a value that is a - * couple of hundred bytes per file once stored. - */ /** * Removes files already uploaded when a later one in the same harvest is refused. * @@ -1959,6 +2053,7 @@ async function discardUploadedExecutionFiles(files: readonly UserFile[]): Promis } } +/** Uploads harvested files sequentially, retaining their private provenance beside stored bytes. */ async function collectExecutionOutputFiles(args: { routeContext: FunctionRouteExecutionContext authUserId: string @@ -2001,38 +2096,41 @@ async function collectExecutionOutputFiles(args: { const name = collectedFileName(collected.relativePath) const mimeType = getMimeTypeFromExtension(getFileExtension(name)) - // Scanned unconditionally — never gated on whether the bytes look textual. - // Both a filename check and a UTF-8 round-trip were trivially defeated: name - // the file `.png`, or append one invalid byte, and a plaintext secret sailed - // past. A lossy UTF-8 decode preserves ASCII runs, so a literal secret is - // findable in any buffer, textual or not. - // - // What stays out of reach is a secret carried in transformed form — deflated - // inside a PDF, re-encoded — which no substring scan can see. That is an - // inherent limit of scanning, not a hole in the gate, and it is why these - // files are execution-scoped rather than durable workspace files. - { - const provenance = await getOutputFileSecretProvenance(buffer, false, routeContext, { - userId: args.authUserId, - workspaceId: resolvedWorkspaceId, - }) - // An execution-scoped file has nowhere to record a provenance envelope, so - // one carrying a resolved secret cannot ship under a lock the way a - // workspace file can — it is refused instead. - if (provenance.status !== 'exact' || provenance.entries.length > 0) { - await discardUploadedExecutionFiles(files) - return { - response: exportFailure( - `Sandbox output file "${name}" contains a resolved secret value and was not returned. Write the file without embedding secret values, or export it to a workspace file where its provenance can be recorded.`, - 400, - args.stdout, - args.executionTime, - args.cost - ), - } + /** Literal secrets must be refused regardless of the export's name or encoding. */ + const scannedProvenance = await getOutputFileSecretProvenance(buffer, false, routeContext, { + userId: args.authUserId, + workspaceId: resolvedWorkspaceId, + }) + if ( + scannedProvenance.status === 'unknown' || + (scannedProvenance.status === 'exact' && scannedProvenance.entries.length > 0) + ) { + await discardUploadedExecutionFiles(files) + return { + response: exportFailure( + `Sandbox output file "${name}" contains a resolved secret value and was not returned. Write the file without embedding secret values, or export it to a workspace file where its provenance can be recorded.`, + 400, + args.stdout, + args.executionTime, + args.cost + ), } } + /** + * A literal scan cannot vouch for encoded secrets in an archive or binary document. + * Persist that uncertainty so a later conversion cannot turn these bytes into a trusted + * workspace file. Both the format and bytes must be textual before a scan is sufficient. + */ + const isBinary = + !TEXT_OUTPUT_MIME_TYPES.has(mimeType) || !isUtf8(buffer) || buffer.includes(0) + const secretProvenance = isBinary + ? await getOutputFileSecretProvenance(buffer, true, routeContext, { + userId: args.authUserId, + workspaceId: resolvedWorkspaceId, + }) + : scannedProvenance + const userFile = await uploadExecutionFile( { workspaceId: resolvedWorkspaceId, @@ -2042,7 +2140,8 @@ async function collectExecutionOutputFiles(args: { buffer, name, mimeType, - args.authUserId + args.authUserId, + secretProvenance ) files.push(userFile) } @@ -2070,6 +2169,7 @@ export interface TrustedFunctionExecutionAuth { fileAccessUserId?: string principal: DelegatedPrincipal sandboxProfile?: 'mothership' + resolvedSecretTraceRegistry?: ResolvedSecretTraceRegistry } /** Executes the Function protocol after the application operation authorizes its principal. */ @@ -2284,6 +2384,7 @@ export async function executeFunctionRequest( unredactedSecretNames.filter((name) => Object.hasOwn(envVars, name)) ), mountedFileSecretProvenanceScanner, + resolvedSecretTraceRegistry: auth.resolvedSecretTraceRegistry, } const lang = isValidCodeLanguage(language) ? language : DEFAULT_CODE_LANGUAGE @@ -2377,6 +2478,11 @@ export async function executeFunctionRequest( for (const binding of compilation.bindings) { setRecordValue(contextVariables, binding.name, binding.value) } + await importRuntimeInputProvenance(routeContext, { + code: resolvedCode, + params: executionParams, + contextVariables, + }) if (lang === CodeLanguage.Shell && containsLargeValueRef(contextVariables)) { throw new Error( 'Large execution values require the JavaScript isolated-vm runtime. Select a nested field or read the value in a JavaScript function.' @@ -2479,6 +2585,11 @@ export async function executeFunctionRequest( logger, }, }) + await importRuntimeFileContributors( + routeContext, + resolvedMounts.contributingFiles, + resolvedMounts.renderedContributingFiles + ) } catch (error) { // Everything this can raise is about the files the caller named — a mount // it may not read, one over a size ceiling, a set over the aggregate. The @@ -3258,3 +3369,5 @@ export async function executeFunctionRequest( executionDeadlineController?.cleanup() } } + +import { isUtf8 } from 'node:buffer' diff --git a/apps/sim/lib/function-execution/sandbox-mounts.test.ts b/apps/sim/lib/function-execution/sandbox-mounts.test.ts index 2f49c989885..6557a35cb0d 100644 --- a/apps/sim/lib/function-execution/sandbox-mounts.test.ts +++ b/apps/sim/lib/function-execution/sandbox-mounts.test.ts @@ -14,11 +14,13 @@ const { mockGeneratePresignedDownloadUrl, mockDownloadServableFileFromStorage, mockReadWorkspaceFileRecordByKey, + mockGetFileMetadataByKey, } = vi.hoisted(() => ({ mockHasCloudStorage: vi.fn(), mockGeneratePresignedDownloadUrl: vi.fn(), mockDownloadServableFileFromStorage: vi.fn(), mockReadWorkspaceFileRecordByKey: vi.fn(), + mockGetFileMetadataByKey: vi.fn(), })) vi.mock('@/lib/uploads/core/storage-service', () => ({ @@ -34,6 +36,10 @@ vi.mock('@/lib/workspace-files/application/read-workspace-file-content-by-key', readWorkspaceFileRecordByKey: { execute: mockReadWorkspaceFileRecordByKey }, })) +vi.mock('@/lib/uploads/server/metadata', () => ({ + getFileMetadataByKey: mockGetFileMetadataByKey, +})) + import { MOUNT_URL_TTL_SECONDS, planUserFileMounts, @@ -137,6 +143,7 @@ describe('resolveUserFileMounts', () => { mockHasCloudStorage.mockReturnValue(true) mockGeneratePresignedDownloadUrl.mockResolvedValue('https://presigned.example/object') mockReadWorkspaceFileRecordByKey.mockResolvedValue({ file: { id: 'wf_1' } }) + mockGetFileMetadataByKey.mockResolvedValue(null) // Sized from the file being read: the aggregate budget counts bytes actually // buffered, so a fixed-size stub would never let the total ceiling trip. mockDownloadServableFileFromStorage.mockImplementation(async (file: UserFile) => ({ @@ -175,6 +182,88 @@ describe('resolveUserFileMounts', () => { ]) }) + it('carries canonical execution provenance through a URL mount without buffering bytes', async () => { + const file = executionFile({ id: 'untrusted-public-id' }) + const contentUpdatedAt = new Date('2026-01-01T00:00:00Z') + mockGetFileMetadataByKey.mockResolvedValue({ + id: 'canonical-file-id', + key: file.key, + context: 'execution', + workspaceId: WORKSPACE_ID, + userId: 'user-1', + contentUpdatedAt, + }) + + const result = await resolveUserFileMounts({ + planned: planUserFileMounts([file]), + context: { + ...executionContext, + principal: { kind: 'session', userId: 'user-1', sessionId: 'session-1' }, + }, + }) + + expect(result.contributingFiles).toEqual([ + { + fileId: 'canonical-file-id', + key: file.key, + context: 'execution', + contentUpdatedAt, + }, + ]) + expect(mockDownloadServableFileFromStorage).not.toHaveBeenCalled() + }) + + it('preserves contributors introduced when an inline mount renders generated source', async () => { + const contributor = { + fileId: 'image-file', + key: 'workspace/ws-1/image.png', + context: 'workspace' as const, + contentUpdatedAt: new Date('2026-01-01T00:00:00Z'), + } + mockHasCloudStorage.mockReturnValue(false) + mockDownloadServableFileFromStorage.mockResolvedValueOnce({ + buffer: Buffer.from('rendered'), + contributingFiles: [contributor], + }) + const result = await resolveUserFileMounts({ + planned: planUserFileMounts([executionFile()]), + context: executionContext, + }) + expect(result.contributingFiles).toEqual([contributor]) + expect(result.renderedContributingFiles).toEqual([contributor]) + }) + + it('retains both revisions when a file changes between two mount resolutions', async () => { + const oldFile = workspaceFile({ key: 'workspace/ws-1/old.pdf' }) + const newFile = workspaceFile({ key: 'workspace/ws-1/new.pdf' }) + const revisions = [new Date('2026-01-01T00:00:00Z'), new Date('2026-01-01T00:01:00Z')] + for (const [index, file] of [oldFile, newFile].entries()) { + mockGetFileMetadataByKey.mockResolvedValueOnce({ + id: 'canonical-file-id', + key: file.key, + context: 'workspace', + workspaceId: WORKSPACE_ID, + userId: 'user-1', + contentUpdatedAt: revisions[index], + }) + } + const result = await resolveUserFileMounts({ + planned: planUserFileMounts([oldFile, newFile]), + context: { + ...executionContext, + principal: { kind: 'session', userId: 'user-1', sessionId: 'session-1' }, + }, + }) + expect(result.contributingFiles).toEqual( + [oldFile, newFile].map((file, index) => ({ + fileId: 'canonical-file-id', + key: file.key, + context: 'workspace', + contentUpdatedAt: revisions[index], + })) + ) + }) + it('buffers bytes inline when there is no cloud storage to presign from', async () => { mockHasCloudStorage.mockReturnValue(false) diff --git a/apps/sim/lib/function-execution/sandbox-mounts.ts b/apps/sim/lib/function-execution/sandbox-mounts.ts index cbad1fa2859..8ba9069dcef 100644 --- a/apps/sim/lib/function-execution/sandbox-mounts.ts +++ b/apps/sim/lib/function-execution/sandbox-mounts.ts @@ -1,4 +1,5 @@ import { createLogger } from '@sim/logger' +import { resolveStoredFileProvenanceSource } from '@/lib/execution/payloads/file-secret-provenance' import { assertUserFileContentAccess, type ExecutionMaterializationContext, @@ -7,6 +8,7 @@ import { import { MAX_SANDBOX_URL_MOUNT_BYTES } from '@/lib/execution/remote-sandbox/output-limits' import { SANDBOX_INPUT_DIR } from '@/lib/execution/remote-sandbox/sandbox-paths' import type { SandboxFile } from '@/lib/execution/remote-sandbox/types' +import type { WorkspaceFileSecretProvenanceIdentity } from '@/lib/uploads/contexts/workspace/workspace-file-secret-provenance' import { buildStorageKeySegment } from '@/lib/uploads/core/storage-key' import { generatePresignedDownloadUrl, hasCloudStorage } from '@/lib/uploads/core/storage-service' import type { StorageContext } from '@/lib/uploads/shared/types' @@ -270,14 +272,39 @@ export function planUserFileMounts( export async function resolveUserFileMounts(args: { planned: readonly PlannedUserFileMount[] context: ExecutionMaterializationContext -}): Promise<{ sandboxFiles: SandboxFile[]; manifest: SandboxMountManifestEntry[] }> { +}): Promise<{ + sandboxFiles: SandboxFile[] + manifest: SandboxMountManifestEntry[] + contributingFiles?: readonly WorkspaceFileSecretProvenanceIdentity[] + renderedContributingFiles?: readonly WorkspaceFileSecretProvenanceIdentity[] +}> { const sandboxFiles: SandboxFile[] = [] const manifest: SandboxMountManifestEntry[] = [] const budget = createSandboxMountBudget() + const contributingFiles = new Map() + const renderedContributingFiles = new Map() + const addContributor = (identity: WorkspaceFileSecretProvenanceIdentity, rendered = false) => { + const revision = JSON.stringify([ + identity.fileId, + identity.key, + identity.context, + identity.contentUpdatedAt?.getTime(), + ]) + contributingFiles.set(revision, identity) + if (rendered) renderedContributingFiles.set(revision, identity) + } for (const { userFile, mountPath } of args.planned) { const storageContext = resolveTrustedFileContext(userFile.key, userFile.context) await assertUserFileContentAccess(userFile, args.context) + if (args.context.principal && args.context.workspaceId) { + const source = await resolveStoredFileProvenanceSource(userFile, { + ...args.context, + principal: args.context.principal, + workspaceId: args.context.workspaceId, + }) + if (source) addContributor(source.identity) + } await pushSandboxFileMount( sandboxFiles, @@ -291,12 +318,22 @@ export async function resolveUserFileMounts(args: { // Base64 regardless of content type: the payload is reproduced exactly // for any byte sequence, and picking utf8 for a mistyped binary would // substitute U+FFFD and hand the code a corrupted file. - const { content } = await readUserFileContentWithContributors(userFile, { + const { + content, + contributingFiles: contributors, + renderedContributingFiles, + } = await readUserFileContentWithContributors(userFile, { ...args.context, encoding: 'base64', maxBytes, maxSourceBytes: maxBytes, }) + for (const contributor of contributors ?? []) { + addContributor(contributor) + } + for (const contributor of renderedContributingFiles ?? []) { + addContributor(contributor, true) + } return { content, encoding: 'base64' as const, @@ -321,5 +358,12 @@ export async function resolveUserFileMounts(args: { urlBytes: budget.url, }) - return { sandboxFiles, manifest } + return { + sandboxFiles, + manifest, + ...(contributingFiles.size > 0 ? { contributingFiles: [...contributingFiles.values()] } : {}), + ...(renderedContributingFiles.size > 0 + ? { renderedContributingFiles: [...renderedContributingFiles.values()] } + : {}), + } } diff --git a/apps/sim/lib/internal/file/execute-tool.test.ts b/apps/sim/lib/internal/file/execute-tool.test.ts index 82853d417ac..05534d68ab1 100644 --- a/apps/sim/lib/internal/file/execute-tool.test.ts +++ b/apps/sim/lib/internal/file/execute-tool.test.ts @@ -298,8 +298,11 @@ describe('executeFileTool', () => { }) it.each(PARSER_TOOL_IDS)('dispatches %s with trusted execution scope', async (toolId) => { + const headers = new Headers({ + 'x-sim-request-private-tool-metadata': 'resolved-secret-provenance-v1', + }) const response = await executeFileTool( - request(toolId, { filePath: 'https://example.com/report.txt', fileType: '' }) + request(toolId, { filePath: 'https://example.com/report.txt', fileType: '' }, { headers }) ) expect(response.status).toBe(200) @@ -311,6 +314,7 @@ describe('executeFileTool', () => { executionId: 'execution-1', attributedUserId: 'user-1', fileAccessUserId: 'user-1', + headers, }) ) expect(mocks.executeManage).not.toHaveBeenCalled() diff --git a/apps/sim/lib/internal/file/execute-tool.ts b/apps/sim/lib/internal/file/execute-tool.ts index 4ed4dd0a2d5..5641a165781 100644 --- a/apps/sim/lib/internal/file/execute-tool.ts +++ b/apps/sim/lib/internal/file/execute-tool.ts @@ -166,6 +166,7 @@ export const executeFileTool: InternalToolOperationHandler = async (request) => fileKeys: request.context.fileKeys, allowLargeValueWorkflowScope: request.context.allowLargeValueWorkflowScope, requestId: request.requestId, + headers: request.headers, signal: request.signal, }) } else { diff --git a/apps/sim/lib/internal/file/operations.provenance.test.ts b/apps/sim/lib/internal/file/operations.provenance.test.ts index 9e129d0f1bd..e82ebb64904 100644 --- a/apps/sim/lib/internal/file/operations.provenance.test.ts +++ b/apps/sim/lib/internal/file/operations.provenance.test.ts @@ -177,7 +177,10 @@ vi.mock('@/lib/core/security/encryption', () => ({ import { fileManageBodySchema } from '@/lib/api/contracts/tools/file' import type { DbTransaction } from '@/lib/db/types' -import { executeFileManageOperation } from '@/lib/internal/file/operations' +import { + executeFileManageOperation, + getFileContentProvenance, +} from '@/lib/internal/file/operations' import { importWorkspaceFileSecretProvenanceForModelView, isOpaqueWorkspaceFileEgressSafe, @@ -395,3 +398,102 @@ describe('appended file provenance', () => { } ) }) + +describe('execution-file content provenance', () => { + const identity = { + fileId: 'execution-file', + key: 'execution/workspace-1/workflow-1/execution-1/report.txt', + context: 'execution' as const, + contentUpdatedAt: CONTENT_UPDATED_AT, + } + const principal = createWorkspaceFileDelegatedPrincipal({ + serviceId: 'executor', + subjectUserId: 'user-1', + workspaceId: 'workspace-1', + delegationId: 'test-file-content', + }) + + beforeEach(() => { + vi.clearAllMocks() + resetDbChainMock() + }) + + it.each([ + { status: 'exact', version: 1, stale: false, enforced: false, complete: true }, + { status: 'exact', version: 1, stale: false, enforced: true, complete: true }, + { status: 'unrecorded', version: 1, stale: false, enforced: false, complete: true }, + { status: 'unrecorded', version: 1, stale: false, enforced: true, complete: false }, + { status: 'unknown', version: 1, stale: false, enforced: false, complete: false }, + { status: 'unknown', version: 1, stale: false, enforced: true, complete: false }, + { status: 'unknown', version: null, stale: false, enforced: false, complete: true }, + { status: 'unknown', version: null, stale: false, enforced: true, complete: true }, + { status: 'exact', version: 1, stale: true, enforced: false, complete: false }, + { status: 'exact', version: 1, stale: true, enforced: true, complete: false }, + ])( + 'reads $status version=$version stale=$stale with enforcement=$enforced', + async ({ status, version, stale, enforced, complete }) => { + mockEnforced.mockReturnValue(enforced) + queueTableRows(workspaceFiles, [ + { + ...joinedRow(status), + secretProvenanceVersion: version, + ...(stale ? { provenanceContentUpdatedAt: new Date(0) } : {}), + }, + ]) + + const provenance = await getFileContentProvenance(principal, 'workspace-1', [ + { identity, ownerUserId: 'user-1' }, + ]) + + expect(provenance).toMatchObject({ version: 1, complete, entries: [] }) + } + ) + + it('retains exact secret-bearing execution lineage for downstream text projections', async () => { + mockEnforced.mockReturnValue(true) + queueTableRows(workspaceFiles, [ + joinedRow('exact', [ + { + name: 'TOKEN', + encryptedValue: 'synthetic-ciphertext', + sourceUserId: 'user-1', + sourceWorkspaceId: 'workspace-1', + }, + ]), + ]) + + const provenance = await getFileContentProvenance(principal, 'workspace-1', [ + { identity, ownerUserId: 'user-1' }, + ]) + const registry = new ResolvedSecretTraceRegistry([], SCOPE) + expect(provenance.complete).toBe(true) + expect(await registry.importProvenance(provenance, { trusted: true })).toBe(true) + expect(projectResolvedSecretModelContent(`parsed: ${SECRET}`, registry)).toEqual({ + safe: true, + value: 'parsed: {{TOKEN}}', + }) + }) + + it.each([ + { sourceUserId: 'other-user', sourceWorkspaceId: 'workspace-1' }, + { sourceUserId: 'user-1', sourceWorkspaceId: 'other-workspace' }, + ])('anonymizes names from a different source scope: %j', async (sourceScope) => { + queueTableRows(workspaceFiles, [ + joinedRow('exact', [ + { name: 'PRIVATE_SOURCE_NAME', encryptedValue: 'synthetic-ciphertext', ...sourceScope }, + ]), + ]) + + const provenance = await getFileContentProvenance(principal, 'workspace-1', [ + { identity, ownerUserId: 'user-1' }, + ]) + + expect(provenance).toEqual({ + version: 1, + complete: true, + entries: [{ encryptedValue: 'synthetic-ciphertext' }], + scope: SCOPE, + }) + expect(JSON.stringify(provenance)).not.toContain('PRIVATE_SOURCE_NAME') + }) +}) diff --git a/apps/sim/lib/internal/file/operations.test.ts b/apps/sim/lib/internal/file/operations.test.ts index 2516a1873a7..3cffe984456 100644 --- a/apps/sim/lib/internal/file/operations.test.ts +++ b/apps/sim/lib/internal/file/operations.test.ts @@ -128,6 +128,8 @@ vi.mock('@/lib/uploads/contexts/workspace', () => ({ getWorkspaceFileByName: (...args: unknown[]) => mockGetWorkspaceFileByName(...args), getWorkspaceFile: (...args: unknown[]) => mockGetWorkspaceFile(...args), loadActiveWorkspaceContext: (...args: unknown[]) => mockLoadActiveWorkspaceContext(...args), + loadActiveWorkspaceFileContext: (...args: unknown[]) => + mockLoadActiveWorkspaceFileContext(...args), updateWorkspaceFileContent: (...args: unknown[]) => mockUpdateWorkspaceFileContent(...args), uploadWorkspaceFile: (...args: unknown[]) => mockUploadWorkspaceFile(...args), })) @@ -1068,13 +1070,30 @@ describe('file manage operations', () => { ? { status: 'exact', entries: [ - { name: 'TOKEN', encryptedValue: 'encrypted-token' }, - { name: 'ALPHA', encryptedValue: 'encrypted-alpha' }, + { + name: 'TOKEN', + encryptedValue: 'encrypted-token', + sourceUserId: 'user-1', + sourceWorkspaceId: 'workspace-1', + }, + { + name: 'ALPHA', + encryptedValue: 'encrypted-alpha', + sourceUserId: 'user-1', + sourceWorkspaceId: 'workspace-1', + }, ], } : { status: 'exact', - entries: [{ name: 'TOKEN', encryptedValue: 'encrypted-token' }], + entries: [ + { + name: 'TOKEN', + encryptedValue: 'encrypted-token', + sourceUserId: 'user-1', + sourceWorkspaceId: 'workspace-1', + }, + ], } ) @@ -1115,6 +1134,215 @@ describe('file manage operations', () => { ) }) + describe('rendered file contributors', () => { + const contributor = { + fileId: 'image', + key: 'workspace/workspace-1/image.txt', + context: 'workspace' as const, + contentUpdatedAt: CONTENT_UPDATED_AT, + } + const secretEntries = [ + { + name: 'IMAGE_TOKEN', + encryptedValue: 'encrypted-image-token', + sourceUserId: 'user-1', + sourceWorkspaceId: 'workspace-1', + }, + ] + + beforeEach(() => { + mockResolveWorkspaceFileReference.mockResolvedValue(workspaceFile('document')) + mockGetFileMetadataByKey.mockResolvedValue({ + id: contributor.fileId, + key: contributor.key, + context: contributor.context, + workspaceId: 'workspace-1', + userId: 'user-1', + contentUpdatedAt: CONTENT_UPDATED_AT, + }) + mockDownloadServableFileFromStorage.mockResolvedValue({ + buffer: Buffer.from('rendered image content'), + contentType: 'text/plain', + contributingFiles: [contributor], + }) + }) + + function renderedRequest(operation: 'write' | 'compress' | 'content') { + return createMockRequest( + 'POST', + { + operation, + workspaceId: 'workspace-1', + ...(operation === 'write' + ? { + fileName: 'copy.txt', + fileInput: { + id: 'document', + name: 'document.txt', + key: 'workspace/workspace-1/document.txt', + url: '/api/files/serve/document', + context: 'workspace', + size: 1, + type: 'text/plain', + }, + } + : { fileId: 'document' }), + }, + PRIVATE_REQUEST_HEADER + ) + } + + it.each(['write', 'compress', 'content'] as const)( + '%s keeps transformed secret-bearing assets unknown even when the source is exact-empty', + async (operation) => { + mockGetBoundWorkspaceFileSecretProvenance.mockImplementation( + async (_workspaceId: string, identity: { fileId: string }) => ({ + status: 'exact', + entries: identity.fileId === contributor.fileId ? secretEntries : [], + }) + ) + + mockDownloadServableFileFromStorage.mockResolvedValueOnce({ + buffer: Buffer.from(''), + contentType: 'text/html', + contributingFiles: [contributor], + }) + const response = await POST(renderedRequest(operation)) + + expect(response.status, await response.clone().text()).toBe(200) + if (operation === 'content') { + await expect(response.json()).resolves.toMatchObject({ + __resolvedSecretTraceProvenance: { + complete: false, + entries: [], + }, + }) + } else { + expect(mockUploadWorkspaceFile.mock.calls[0]?.[5]).toMatchObject({ + secretProvenance: { status: 'unknown' }, + }) + } + expect(mockDownloadServableFileFromStorage).toHaveBeenCalledWith( + expect.anything(), + 'request-1', + expect.anything(), + expect.objectContaining({ + filePrincipal: expect.objectContaining({ subjectUserId: 'user-1' }), + signal: expect.any(AbortSignal), + }) + ) + expect(mockGetBoundWorkspaceFileSecretProvenance).toHaveBeenCalledWith( + 'workspace-1', + contributor + ) + } + ) + + it.each(['write', 'compress', 'content'] as const)( + '%s preserves unknown rendered-asset provenance', + async (operation) => { + mockGetBoundWorkspaceFileSecretProvenance.mockImplementation( + async (_workspaceId: string, identity: { fileId: string }) => + identity.fileId === contributor.fileId + ? { status: 'unknown' } + : { status: 'exact', entries: [] } + ) + + const response = await POST(renderedRequest(operation)) + + expect(response.status, await response.clone().text()).toBe(200) + if (operation === 'content') { + await expect(response.json()).resolves.toMatchObject({ + __resolvedSecretTraceProvenance: { complete: false, entries: [] }, + }) + } else { + expect(mockUploadWorkspaceFile.mock.calls[0]?.[5]).toMatchObject({ + secretProvenance: { status: 'unknown' }, + }) + } + } + ) + + it.each(['write', 'compress', 'content'] as const)( + '%s does not replace an older rendered revision with a safe revision of the same file', + async (operation) => { + const oldRevision = new Date(CONTENT_UPDATED_AT.getTime() - 1_000) + mockDownloadServableFileFromStorage.mockResolvedValue({ + buffer: Buffer.from('both old and new image bytes'), + contentType: 'text/plain', + contributingFiles: [{ ...contributor, contentUpdatedAt: oldRevision }, contributor], + }) + mockGetBoundWorkspaceFileSecretProvenance.mockImplementation( + async (_workspaceId: string, identity: { contentUpdatedAt?: Date }) => + identity.contentUpdatedAt?.getTime() === oldRevision.getTime() + ? { status: 'unknown' } + : { status: 'exact', entries: [] } + ) + + const response = await POST(renderedRequest(operation)) + + expect(response.status, await response.clone().text()).toBe(200) + expect(mockGetBoundWorkspaceFileSecretProvenance).toHaveBeenCalledWith('workspace-1', { + ...contributor, + contentUpdatedAt: oldRevision, + }) + if (operation === 'content') { + await expect(response.json()).resolves.toMatchObject({ + __resolvedSecretTraceProvenance: { complete: false, entries: [] }, + }) + } else { + expect(mockUploadWorkspaceFile.mock.calls[0]?.[5]).toMatchObject({ + secretProvenance: { status: 'unknown' }, + }) + } + } + ) + + it.each(['write', 'compress'] as const)( + '%s retains the secret owner guard for rendered contributors', + async (operation) => { + mockGetFileMetadataByKey.mockResolvedValue({ + id: contributor.fileId, + key: contributor.key, + context: contributor.context, + workspaceId: 'workspace-1', + userId: 'other-user', + contentUpdatedAt: CONTENT_UPDATED_AT, + }) + mockGetBoundWorkspaceFileSecretProvenance.mockImplementation( + async (_workspaceId: string, identity: { fileId: string }) => ({ + status: 'exact', + entries: identity.fileId === contributor.fileId ? secretEntries : [], + }) + ) + + const response = await POST(renderedRequest(operation)) + + expect(response.status, await response.clone().text()).toBe(200) + expect(mockUploadWorkspaceFile.mock.calls[0]?.[5]).toMatchObject({ + secretProvenance: { status: 'unknown' }, + }) + } + ) + + it('refuses a rendered contributor whose canonical scope differs', async () => { + mockGetFileMetadataByKey.mockResolvedValue({ + id: contributor.fileId, + key: contributor.key, + context: contributor.context, + workspaceId: 'other-workspace', + userId: 'user-1', + contentUpdatedAt: CONTENT_UPDATED_AT, + }) + mockGetBoundWorkspaceFileSecretProvenance.mockResolvedValue({ status: 'exact', entries: [] }) + + const response = await POST(renderedRequest('write')) + + expect(response.status).toBe(404) + expect(mockUploadWorkspaceFile).not.toHaveBeenCalled() + }) + }) + it('pins resolved file-input provenance to the captured content revision', async () => { mockResolveWorkspaceFileReference.mockResolvedValue(workspaceFile('file-1')) mockGetBoundWorkspaceFileSecretProvenance.mockResolvedValue({ @@ -1870,7 +2098,14 @@ describe('file manage operations', () => { ) mockGetBoundWorkspaceFileSecretProvenance.mockResolvedValue({ status: 'exact', - entries: [{ name: 'TOKEN', encryptedValue: 'encrypted-token' }], + entries: [ + { + name: 'TOKEN', + encryptedValue: 'encrypted-token', + sourceUserId: 'user-1', + sourceWorkspaceId: 'workspace-1', + }, + ], }) const response = await POST( @@ -1885,7 +2120,7 @@ describe('file manage operations', () => { expect(body.__resolvedSecretTraceProvenance).toEqual({ version: 1, complete: true, - entries: [{ name: 'TOKEN', encryptedValue: 'encrypted-token' }], + entries: [{ encryptedValue: 'encrypted-token' }], }) }) diff --git a/apps/sim/lib/internal/file/operations.ts b/apps/sim/lib/internal/file/operations.ts index 9907e9103c0..5e84bdcac74 100644 --- a/apps/sim/lib/internal/file/operations.ts +++ b/apps/sim/lib/internal/file/operations.ts @@ -19,6 +19,7 @@ import { inspectPrivateSecretProvenanceRequest, isPrivateSecretProvenanceBundleV1, } from '@/lib/execution/model-input-provenance' +import { resolveStoredFileProvenanceSource } from '@/lib/execution/payloads/file-secret-provenance' import { assertUserFileContentAccess } from '@/lib/execution/payloads/materialization.server' import { PRIVATE_TOOL_METADATA_RESPONSE_HEADER, @@ -44,6 +45,8 @@ import type { WorkspaceFileRecord, } from '@/lib/uploads/contexts/workspace/workspace-file-manager' import { + getBoundWorkspaceFileSecretProvenance, + mayReadUnrecordedWorkspaceFile, mergeWorkspaceFileSecretProvenance, type WorkspaceFileSecretProvenance, type WorkspaceFileSecretProvenanceIdentity, @@ -198,11 +201,10 @@ const fileInputToUserFile = (fileInput: unknown) => { ? record.fileId.trim() : '' - // Objects with ids are resolved through workspace metadata. This fallback is for - // picker/upload values that only carry storage fields. - if (id) return null - const key = typeof record.key === 'string' ? record.key.trim() : '' + /** Execution ids are not workspace file ids; their storage key carries the run scope. */ + if (id && (!key || tryInferContextFromKey(key) !== 'execution')) return null + const path = typeof record.path === 'string' ? record.path.trim() : '' const url = typeof record.url === 'string' ? record.url.trim() : '' const fileUrl = @@ -217,7 +219,7 @@ const fileInputToUserFile = (fileInput: unknown) => { if (key && !context) return null return { - id: key || fileUrl, + id: id || key || fileUrl, name: typeof record.name === 'string' && record.name.trim() ? record.name.trim() : 'workspace-file', url: fileUrl ? ensureAbsoluteUrl(fileUrl) : '', @@ -284,6 +286,12 @@ const extractFileIdsFromInput = (fileInput: unknown): string[] => { if (typeof input === 'string') return normalizeFileIdList(input) if (input && typeof input === 'object') { const record = input as Record + if ( + typeof record.key === 'string' && + tryInferContextFromKey(record.key.trim()) === 'execution' + ) { + return [] + } if (typeof record.id === 'string') return normalizeFileIdList(record.id) if (typeof record.fileId === 'string') return normalizeFileIdList(record.fileId) } @@ -424,15 +432,23 @@ function sliceTextLines( interface ExtractedFileText { text: string truncated: boolean + contributingFiles?: readonly WorkspaceFileSecretProvenanceIdentity[] } const extractUserFileTextContent = async ( userFile: UserFile, - requestId: string + context: FileManageOperationContext ): Promise => { - const { buffer } = await downloadServableFileFromStorage(userFile, requestId, logger, { - maxBytes: MAX_GET_CONTENT_FILE_BYTES, - }) + const { buffer, contributingFiles } = await downloadServableFileFromStorage( + userFile, + context.requestId, + logger, + { + maxBytes: MAX_GET_CONTENT_FILE_BYTES, + filePrincipal: context.principal, + signal: context.signal, + } + ) const extension = getFileExtension(userFile.name) if (extension && isSupportedFileType(extension)) { @@ -442,7 +458,11 @@ const extractUserFileTextContent = async ( /** Scraped or placeholder output is a failure, not the file's content. */ throw new Error(result.metadata.warning ?? 'Parser returned degraded output') } - return { text: result.content ?? '', truncated: result.metadata?.truncated === true } + return { + text: result.content ?? '', + truncated: result.metadata?.truncated === true, + contributingFiles, + } } catch (error) { logger.warn('Falling back to raw text after parser failure', { name: userFile.name, @@ -452,16 +472,19 @@ const extractUserFileTextContent = async ( } if (isLikelyTextBuffer(buffer)) { - return { text: buffer.toString('utf-8'), truncated: false } + return { text: buffer.toString('utf-8'), truncated: false, contributingFiles } } return { text: `[Binary file: ${userFile.name} (${userFile.type || 'application/octet-stream'}, ${buffer.length} bytes). Cannot extract text content.]`, truncated: false, + contributingFiles, } } export interface FileContentProvenanceSource { + /** Rendering may encode these bytes; original secret literals cannot describe the transformed value. */ + opaque?: boolean identity?: WorkspaceFileSecretProvenanceIdentity ownerUserId?: string } @@ -471,10 +494,17 @@ interface FileContentSource extends FileContentProvenanceSource { } async function bindSelectedContentFile( - principal: Principal, - workspaceId: string, + context: FileManageOperationContext, file: UserFile ): Promise { + const { principal, workspaceId } = context + if (file.key && tryInferContextFromKey(file.key) === 'execution') { + const source = await resolveStoredFileProvenanceSource(file, { + ...context, + userId: context.fileAccessUserId, + }) + return { file, ...source } + } if (!file.key || file.context !== 'workspace') return { file } let metadata: Awaited> @@ -503,6 +533,67 @@ async function bindSelectedContentFile( } } +async function bindSelectedContentFiles( + context: FileManageOperationContext, + files: readonly UserFile[] +): Promise { + const sources: FileContentSource[] = [] + for (const file of files) { + context.signal?.throwIfAborted() + sources.push(await bindSelectedContentFile(context, file)) + } + return sources +} + +/** Preserves the renderer's consumed revision while checking each contributor's current scope. */ +async function bindRenderedContentSources( + context: FileManageOperationContext, + identities: readonly WorkspaceFileSecretProvenanceIdentity[] = [] +): Promise { + const sources: FileContentProvenanceSource[] = [] + for (const identity of identities) { + context.signal?.throwIfAborted() + const canonical = await resolveStoredFileProvenanceSource( + { + key: identity.key, + context: identity.context === 'mothership' ? 'workspace' : identity.context, + }, + { ...context, userId: context.fileAccessUserId } + ) + const matches = + canonical && + canonical.identity.fileId === identity.fileId && + canonical.identity.key === identity.key && + canonical.identity.context === identity.context + sources.push({ + identity, + opaque: true, + ...(matches ? { ownerUserId: canonical.ownerUserId } : {}), + }) + } + return sources +} + +/** Execution identities have already passed the same run capability that authorized their bytes. */ +async function readFileSourceSecretProvenance( + principal: Principal, + workspaceId: string, + identity: WorkspaceFileSecretProvenanceIdentity +): Promise { + if (identity.context === 'execution' || identity.context === 'mothership') { + return getBoundWorkspaceFileSecretProvenance(workspaceId, identity) + } + const { provenance } = await readWorkspaceFileSecretProvenance.execute({ + principal, + input: { + fileId: identity.fileId, + assertedWorkspaceId: workspaceId, + expectedContentUpdatedAt: identity.contentUpdatedAt, + }, + }) + return provenance +} + export async function getFileContentProvenance( principal: Principal, workspaceId: string, @@ -527,27 +618,25 @@ export async function getFileContentProvenance( accumulator.markIncomplete('file-source-unidentified') continue } - const { provenance } = await readWorkspaceFileSecretProvenance.execute({ - principal, - input: { - fileId: source.identity.fileId, - assertedWorkspaceId: workspaceId, - expectedContentUpdatedAt: source.identity.contentUpdatedAt, - }, - }) + const provenance = await readFileSourceSecretProvenance(principal, workspaceId, source.identity) signal?.throwIfAborted() - /** - * `unrecorded` is a more specific `unknown`, and this accumulator has not opted into the - * workspace file surface's policy, so it latches exactly as it did before. - */ - if (provenance.status !== 'exact') { + if (provenance.status === 'unrecorded' && mayReadUnrecordedWorkspaceFile(workspaceId)) continue + if (provenance.status !== 'exact' || (source.opaque && provenance.entries.length > 0)) { accumulator.markIncomplete('workspace-file-provenance-unknown') continue } accumulator.record({ version: 1, complete: true, - entries: [...provenance.entries], + entries: provenance.entries.map((entry) => ({ + encryptedValue: entry.encryptedValue, + ...(entry.name && + scope && + entry.sourceUserId === scope.userId && + entry.sourceWorkspaceId === scope.workspaceId + ? { name: entry.name } + : {}), + })), ...(scope ? { scope } : {}), }) } @@ -678,25 +767,27 @@ async function deriveWorkspaceFileSecretProvenance(options: { principal: Principal workspaceId: string targetOwnerUserId: string - sources: readonly FileContentSource[] + sources: readonly FileContentProvenanceSource[] }): Promise { - const provenances: WorkspaceFileSecretProvenance[] = [] + let combined: WorkspaceFileSecretProvenance = { status: 'exact', entries: [] } for (const source of options.sources) { if (!source.identity || !source.ownerUserId) return { status: 'unknown' } - const { provenance } = await readWorkspaceFileSecretProvenance.execute({ - principal: options.principal, - input: { fileId: source.identity.fileId, assertedWorkspaceId: options.workspaceId }, - }) + const provenance = await readFileSourceSecretProvenance( + options.principal, + options.workspaceId, + source.identity + ) if ( provenance.status === 'exact' && provenance.entries.length > 0 && - source.ownerUserId !== options.targetOwnerUserId + (source.opaque || source.ownerUserId !== options.targetOwnerUserId) ) { return { status: 'unknown' } } - provenances.push(provenance) + combined = mergeWorkspaceFileSecretProvenance(combined, provenance) + if (combined.status === 'unknown') return combined } - return mergeWorkspaceFileSecretProvenance(...provenances) + return combined } export function fileContentJsonResponse( @@ -1097,10 +1188,9 @@ export async function executeFileManageOperation( }, ] }) - const selectedSources = await Promise.all( - selectedInputFiles.map((file) => bindSelectedContentFile(principal, workspaceId, file)) - ) + const selectedSources = await bindSelectedContentFiles(context, selectedInputFiles) const sources = canonicalSources.concat(selectedSources) + const provenanceSources: FileContentProvenanceSource[] = [...sources] const contents: string[] = [] const lineRanges: FileContentLineRange[] = [] @@ -1119,7 +1209,14 @@ export async function executeFileManageOperation( }) } - const extracted = await extractUserFileTextContent(source.file, requestId) + const extracted = await extractUserFileTextContent(source.file, context) + if (includePrivateContentProvenance) { + const renderedSources = await bindRenderedContentSources( + context, + extracted.contributingFiles + ) + for (const renderedSource of renderedSources) provenanceSources.push(renderedSource) + } const { text: content, range } = sliceTextLines( extracted.text, body.offset, @@ -1144,7 +1241,7 @@ export async function executeFileManageOperation( logger.info('File content extracted', { count: contents.length }) const provenance = includePrivateContentProvenance - ? await getFileContentProvenance(principal, workspaceId, sources, signal) + ? await getFileContentProvenance(principal, workspaceId, provenanceSources, signal) : undefined return contentResponse( @@ -1186,8 +1283,8 @@ export async function executeFileManageOperation( * "safe" state — and a file the platform had locked as secret-derived * would be readable again under its new id. * - * A source with no workspace row resolves to `unknown` rather than empty, - * because nothing durable records what went into it. + * Workspace and execution files carry their canonical sidecars across the copy. + * An unidentified source cannot establish exact provenance. */ let inputProvenance: WorkspaceFileSecretProvenance | undefined if (fileInput !== undefined && fileInput !== null) { @@ -1220,12 +1317,7 @@ export async function executeFileManageOperation( const denied = await assertOperationFileAccess(sourceFile, context) if (denied) return denied - inputProvenance = await deriveWorkspaceFileSecretProvenance({ - principal, - workspaceId, - targetOwnerUserId: userId, - sources: [await bindSelectedContentFile(principal, workspaceId, sourceFile)], - }) + const source = await bindSelectedContentFile(context, sourceFile) const downloaded = await downloadServableFileFromStorage(sourceFile, requestId, logger, { maxBytes: MAX_WRITE_FILE_INPUT_BYTES, @@ -1235,6 +1327,15 @@ export async function executeFileManageOperation( // already-published artifact and throws when there is none. filePrincipal: principal, }) + inputProvenance = await deriveWorkspaceFileSecretProvenance({ + principal, + workspaceId, + targetOwnerUserId: userId, + sources: [ + source, + ...(await bindRenderedContentSources(context, downloaded.contributingFiles)), + ], + }) sourceEncoding = 'base64' sourceContent = downloaded.buffer.toString('base64') sourceName = fileName?.trim() || sourceFile.name @@ -1735,16 +1836,19 @@ export async function executeFileManageOperation( return [ { file: userFile, - identity: { fileId: file.id, key: file.key, context: 'workspace' }, + identity: { + fileId: file.id, + key: file.key, + context: 'workspace', + contentUpdatedAt: file.contentUpdatedAt ?? undefined, + }, ownerUserId: file.uploadedBy, }, ] }) - const selectedArchiveSources = await Promise.all( - selectedInputFiles.map((file) => bindSelectedContentFile(principal, workspaceId, file)) - ) + const selectedArchiveSources = await bindSelectedContentFiles(context, selectedInputFiles) const archiveSources = canonicalArchiveSources.concat(selectedArchiveSources) - const archiveProvenance = await deriveWorkspaceFileSecretProvenance({ + let archiveProvenance = await deriveWorkspaceFileSecretProvenance({ principal, workspaceId, targetOwnerUserId: userId, @@ -1775,9 +1879,26 @@ export async function executeFileManageOperation( // the archive must carry the servable bytes instead of the raw source text. // A still-compiling artifact throws, and the handler's catch turns that into // the shared 409 via `docNotReadyResponse`. - const { buffer } = await downloadServableFileFromStorage(userFile, requestId, logger, { - maxBytes: MAX_COMPRESS_FILE_BYTES, - }) + const { buffer, contributingFiles } = await downloadServableFileFromStorage( + userFile, + requestId, + logger, + { + maxBytes: MAX_COMPRESS_FILE_BYTES, + filePrincipal: principal, + signal, + } + ) + const renderedSources = await bindRenderedContentSources(context, contributingFiles) + archiveProvenance = mergeWorkspaceFileSecretProvenance( + archiveProvenance, + await deriveWorkspaceFileSecretProvenance({ + principal, + workspaceId, + targetOwnerUserId: userId, + sources: renderedSources, + }) + ) totalBytes += buffer.length if (totalBytes > MAX_COMPRESS_TOTAL_BYTES) { return Response.json( @@ -1905,14 +2026,17 @@ export async function executeFileManageOperation( return [ { file: userFile, - identity: { fileId: file.id, key: file.key, context: 'workspace' }, + identity: { + fileId: file.id, + key: file.key, + context: 'workspace', + contentUpdatedAt: file.contentUpdatedAt ?? undefined, + }, ownerUserId: file.uploadedBy, }, ] }) - const selectedArchiveSource = await Promise.all( - selectedInputFiles.map((file) => bindSelectedContentFile(principal, workspaceId, file)) - ) + const selectedArchiveSource = await bindSelectedContentFiles(context, selectedInputFiles) const archiveSource = canonicalArchiveSource.concat(selectedArchiveSource)[0] if (!archiveSource?.identity) { const denied = await assertOperationFileAccess(archive, context) diff --git a/apps/sim/lib/internal/file/parser.test.ts b/apps/sim/lib/internal/file/parser.test.ts index 9df0f56b89f..c3018aeef8c 100644 --- a/apps/sim/lib/internal/file/parser.test.ts +++ b/apps/sim/lib/internal/file/parser.test.ts @@ -37,6 +37,11 @@ const { mockUploadExecutionFile, mockUploadWorkspaceFile, mockReadWorkspaceFileNameByKey, + mockResolveProvenanceSource, + mockGetBoundProvenance, + mockGetFileContentProvenance, + storageConfig, + mockGetBlobContainerClient, } = vi.hoisted(() => { // eslint-disable-next-line @typescript-eslint/no-require-imports const actualPath = require('path') as typeof import('path') @@ -80,9 +85,40 @@ const { }) ), mockReadWorkspaceFileNameByKey: vi.fn(), + mockResolveProvenanceSource: vi.fn(), + mockGetBoundProvenance: vi.fn(), + mockGetFileContentProvenance: vi.fn(), + storageConfig: { + provider: 's3', + bucket: 'sim-execution-files', + containerName: 'execution-files', + }, + mockGetBlobContainerClient: vi.fn(), } }) +vi.mock('@/lib/execution/payloads/file-secret-provenance', () => ({ + resolveStoredFileProvenanceSource: mockResolveProvenanceSource, +})) + +vi.mock('@/lib/uploads/contexts/workspace/workspace-file-secret-provenance', () => ({ + getBoundWorkspaceFileSecretProvenance: mockGetBoundProvenance, +})) + +vi.mock('@/lib/internal/file/operations', () => ({ + getFileContentProvenance: mockGetFileContentProvenance, + fileContentJsonResponse: ( + body: Record, + includePrivate: boolean, + init?: ResponseInit, + provenance?: unknown + ) => + Response.json( + includePrivate ? { ...body, __resolvedSecretTraceProvenance: provenance } : body, + init + ), +})) + vi.mock('@/lib/execution/payloads/materialization.server', () => ({ assertUserFileContentAccess: async (file: { key: string }) => { if (!(await mockVerifyFileAccess(file.key))) throw new Error('File not found') @@ -95,6 +131,24 @@ vi.mock('@/lib/uploads', () => ({ StorageService: storageServiceMock, })) +vi.mock('@/lib/uploads/config', () => ({ + getStorageConfig: () => storageConfig, + S3_CONFIG: {}, + get USE_S3_STORAGE() { + return storageConfig.provider === 's3' + }, + get USE_BLOB_STORAGE() { + return storageConfig.provider === 'blob' + }, + get USE_GCS_STORAGE() { + return storageConfig.provider === 'gcs' + }, +})) + +vi.mock('@/lib/uploads/providers/blob/client', () => ({ + getBlobServiceClient: async () => ({ getContainerClient: mockGetBlobContainerClient }), +})) + vi.mock('@/lib/file-parsers', () => ({ isSupportedFileType: mockIsSupportedFileType, parseBuffer: mockParseBuffer, @@ -186,6 +240,7 @@ async function POST(request: NextRequest): Promise { executionId: parsed.data.executionId || 'execution-id', attributedUserId: 'test-user-id', fileAccessUserId: 'test-user-id', + headers: request.headers, signal: request.signal, }) } @@ -233,6 +288,8 @@ describe('file parser operation', () => { beforeEach(() => { vi.clearAllMocks() + storageConfig.provider = 's3' + mockGetBlobContainerClient.mockReset() setupFileApiMocks({ authenticated: true, }) @@ -254,6 +311,9 @@ describe('file parser operation', () => { }) mockUploadWorkspaceFile.mockClear() mockReadWorkspaceFileNameByKey.mockResolvedValue({ name: null }) + mockResolveProvenanceSource.mockResolvedValue(undefined) + mockGetBoundProvenance.mockResolvedValue({ status: 'exact', entries: [] }) + mockGetFileContentProvenance.mockResolvedValue({ version: 1, complete: true, entries: [] }) mockParseBuffer.mockResolvedValue({ content: 'parsed buffer content', metadata: { pageCount: 1 }, @@ -278,6 +338,321 @@ describe('file parser operation', () => { expect(data).toHaveProperty('error', 'No file path provided') }) + it('exports negotiated canonical execution-file lineage without changing public content', async () => { + const source = { + identity: { + fileId: 'canonical-file', + key: 'execution/workspace-id/workflow-id/execution-id/report.txt', + context: 'execution', + contentUpdatedAt: new Date('2026-09-10T00:00:00Z'), + }, + ownerUserId: 'test-user-id', + } + mockResolveProvenanceSource.mockResolvedValue(source) + const lineage = { + version: 1, + complete: true, + scope: { userId: 'test-user-id', workspaceId: 'workspace-id' }, + entries: [{ name: 'SECRET', encryptedValue: 'encrypted-value' }], + } + mockGetFileContentProvenance.mockResolvedValue(lineage) + + const response = await POST( + createMockRequest( + 'POST', + { filePath: source.identity.key }, + { 'x-sim-request-private-tool-metadata': 'resolved-secret-provenance-v1' } + ) + ) + const body = await response.json() + + expect(body.output.content).toBe('parsed buffer content') + expect(body.__resolvedSecretTraceProvenance).toEqual(lineage) + expect(body).not.toHaveProperty('provenanceSource') + expect(body.output).not.toHaveProperty('provenanceSource') + expect(mockGetFileContentProvenance).toHaveBeenCalledWith( + expect.any(Object), + 'workspace-id', + [source], + expect.any(AbortSignal) + ) + expect(mockUploadExecutionFile).not.toHaveBeenCalled() + }) + + it('keeps private canonical provenance out of unnegotiated parser responses', async () => { + mockResolveProvenanceSource.mockResolvedValue({ + identity: { fileId: 'canonical-file', key: 'workspace/report.txt', context: 'workspace' }, + ownerUserId: 'test-user-id', + }) + const response = await POST(createMockRequest('POST', { filePath: 'workspace/report.txt' })) + const body = await response.json() + + expect(body.output.content).toBe('parsed buffer content') + expect(body).not.toHaveProperty('__resolvedSecretTraceProvenance') + expect(body).not.toHaveProperty('provenanceSource') + expect(mockGetFileContentProvenance).not.toHaveBeenCalled() + }) + + it.each([ + { ownerUserId: 'test-user-id', expectedStatus: 'exact' }, + { ownerUserId: 'other-user', expectedStatus: 'unknown' }, + ])('preserves safe copy provenance for $ownerUserId', async ({ ownerUserId, expectedStatus }) => { + const source = { + identity: { fileId: 'canonical-file', key: 'workspace/report.txt', context: 'workspace' }, + ownerUserId, + } + const entries = [{ name: 'SECRET', encryptedValue: 'encrypted-value' }] + mockResolveProvenanceSource.mockResolvedValue(source) + mockGetBoundProvenance.mockResolvedValue({ status: 'exact', entries }) + + await POST(createMockRequest('POST', { filePath: source.identity.key })) + + expect(mockGetBoundProvenance).toHaveBeenCalledWith('workspace-id', source.identity) + expect(mockUploadExecutionFile).toHaveBeenCalledWith( + expect.any(Object), + expect.any(Buffer), + 'report.txt', + 'text/plain', + 'test-user-id', + expectedStatus === 'exact' ? { status: 'exact', entries } : { status: 'unknown' } + ) + }) + + it('keeps tracked unknown sources in the private response instead of treating them as legacy', async () => { + const source = { + identity: { fileId: 'canonical-file', key: 'workspace/report.txt', context: 'workspace' }, + ownerUserId: 'test-user-id', + } + mockResolveProvenanceSource.mockResolvedValue(source) + mockGetBoundProvenance.mockResolvedValue({ status: 'unknown' }) + mockGetFileContentProvenance.mockResolvedValue({ version: 1, complete: false, entries: [] }) + + const response = await POST( + createMockRequest( + 'POST', + { filePath: source.identity.key }, + { 'x-sim-request-private-tool-metadata': 'resolved-secret-provenance-v1' } + ) + ) + + expect((await response.json()).__resolvedSecretTraceProvenance.complete).toBe(false) + expect(mockGetFileContentProvenance).toHaveBeenCalledWith( + expect.any(Object), + 'workspace-id', + [source], + expect.any(AbortSignal) + ) + expect(mockUploadExecutionFile.mock.calls[0][5]).toEqual({ status: 'unknown' }) + }) + + it('preserves missing historical metadata as absence on copied files', async () => { + const response = await POST( + createMockRequest( + 'POST', + { filePath: 'workspace/legacy.txt' }, + { 'x-sim-request-private-tool-metadata': 'resolved-secret-provenance-v1' } + ) + ) + + expect((await response.json()).success).toBe(true) + expect(mockGetBoundProvenance).not.toHaveBeenCalled() + expect(mockUploadExecutionFile.mock.calls[0][5]).toEqual({ status: 'unrecorded' }) + expect(mockGetFileContentProvenance).toHaveBeenCalledWith( + expect.any(Object), + 'workspace-id', + [], + expect.any(AbortSignal) + ) + }) + + it('does not return content when canonical provenance resolution rejects the file scope', async () => { + mockResolveProvenanceSource.mockRejectedValue(new Error('File not found')) + const response = await POST(createMockRequest('POST', { filePath: 'workspace/other.txt' })) + + expect((await response.json()).success).toBe(false) + expect(storageServiceMockFns.mockDownloadFile).not.toHaveBeenCalled() + expect(mockUploadExecutionFile).not.toHaveBeenCalled() + }) + + it('reads owned presigned URLs through canonical authorized storage', async () => { + const key = 'execution/workspace-id/workflow-id/execution-id/report.txt' + const source = { + identity: { fileId: 'canonical-file', key, context: 'execution' }, + ownerUserId: 'test-user-id', + } + mockResolveProvenanceSource.mockResolvedValue(source) + const response = await POST( + createMockRequest( + 'POST', + { filePath: `https://sim-execution-files.s3.us-east-1.amazonaws.com/${key}?signature=old` }, + { 'x-sim-request-private-tool-metadata': 'resolved-secret-provenance-v1' } + ) + ) + + expect((await response.json()).success).toBe(true) + expect(mockResolveProvenanceSource).toHaveBeenCalledWith( + { key, context: 'execution' }, + expect.objectContaining({ workspaceId: 'workspace-id', executionId: 'execution-id' }) + ) + expect(storageServiceMockFns.mockDownloadFile).toHaveBeenCalledWith({ + key, + context: 'execution', + maxBytes: 100 * 1024 * 1024, + }) + expect(inputValidationMockFns.mockSecureFetchWithPinnedIP).not.toHaveBeenCalled() + }) + + it.each([ + 'https://exampleaccount.blob.core.windows.net/execution-files', + 'https://exampleaccount.blob.core.usgovcloudapi.net/execution-files', + 'https://storage.example.test/account/execution-files', + ])( + 'recognizes the configured Azure container endpoint without a separate account name: %s', + async (containerUrl) => { + storageConfig.provider = 'blob' + mockGetBlobContainerClient.mockReturnValue({ url: containerUrl }) + const key = 'execution/workspace-id/workflow-id/execution-id/report.txt' + const source = { + identity: { fileId: 'canonical-file', key, context: 'execution' }, + ownerUserId: 'test-user-id', + } + mockResolveProvenanceSource.mockResolvedValue(source) + mockGetBoundProvenance.mockResolvedValue({ status: 'unknown' }) + + const response = await POST( + createMockRequest('POST', { + filePath: `${containerUrl}/${key}?sig=placeholder`, + }) + ) + + expect((await response.json()).success).toBe(true) + expect(mockGetBlobContainerClient).toHaveBeenCalledWith('execution-files') + expect(mockResolveProvenanceSource).toHaveBeenCalledWith( + { key, context: 'execution' }, + expect.objectContaining({ workspaceId: 'workspace-id' }) + ) + expect(mockGetBoundProvenance).toHaveBeenCalledWith('workspace-id', source.identity) + expect(mockUploadExecutionFile).not.toHaveBeenCalled() + expect(storageServiceMockFns.mockDownloadFile).toHaveBeenCalledWith({ + key, + context: 'execution', + maxBytes: 100 * 1024 * 1024, + }) + expect(inputValidationMockFns.mockSecureFetchWithPinnedIP).not.toHaveBeenCalled() + } + ) + + it.each([ + 'https://exampleaccount.blob.core.windows.net.attacker.test/execution-files', + 'https://exampleaccount.blob.core.windows.net/execution-files-other', + ])( + 'does not attribute another Azure origin or container to owned storage: %s', + async (containerUrl) => { + storageConfig.provider = 'blob' + mockGetBlobContainerClient.mockReturnValue({ + url: 'https://exampleaccount.blob.core.windows.net/execution-files', + }) + inputValidationMockFns.mockSecureFetchWithPinnedIP.mockResolvedValue( + new Response('external content', { headers: { 'content-type': 'text/plain' } }) + ) + await POST(createMockRequest('POST', { filePath: `${containerUrl}/report.txt` })) + + expect(mockResolveProvenanceSource).not.toHaveBeenCalled() + expect(storageServiceMockFns.mockDownloadFile).not.toHaveBeenCalled() + } + ) + + it('does not attribute an external hostname prefix to canonical storage provenance', async () => { + inputValidationMockFns.mockSecureFetchWithPinnedIP.mockResolvedValue( + new Response('external content', { headers: { 'content-type': 'text/plain' } }) + ) + await POST( + createMockRequest('POST', { + filePath: + 'https://sim-execution-files.s3.us-east-1.amazonaws.com.attacker.test/execution/workspace-id/workflow-id/execution-id/report.txt', + }) + ) + + expect(mockResolveProvenanceSource).not.toHaveBeenCalled() + expect(storageServiceMockFns.mockDownloadFile).not.toHaveBeenCalled() + }) + + it('retains only returned contributors when the multi-file output budget stops parsing', async () => { + const first = { + identity: { fileId: 'first', key: 'workspace/first.txt', context: 'workspace' }, + ownerUserId: 'test-user-id', + } + const second = { + identity: { fileId: 'second', key: 'workspace/second.txt', context: 'workspace' }, + ownerUserId: 'test-user-id', + } + mockResolveProvenanceSource.mockResolvedValueOnce(first).mockResolvedValueOnce(second) + mockParseBuffer + .mockResolvedValueOnce({ content: 'a'.repeat(3 * 1024 * 1024) }) + .mockResolvedValueOnce({ content: 'b'.repeat(3 * 1024 * 1024) }) + const response = await POST( + createMockRequest( + 'POST', + { filePath: ['workspace/first.txt', 'workspace/second.txt', 'workspace/third.txt'] }, + { 'x-sim-request-private-tool-metadata': 'resolved-secret-provenance-v1' } + ) + ) + const body = await response.json() + + expect(body.success).toBe(true) + expect(body.results).toHaveLength(1) + expect(body.error).toContain('too large') + expect(mockResolveProvenanceSource).toHaveBeenCalledTimes(2) + expect(mockGetFileContentProvenance).toHaveBeenCalledWith( + expect.any(Object), + 'workspace-id', + [first], + expect.any(AbortSignal) + ) + }) + + it.each([{ filePath: 'workspace/failed.txt' }, { filePath: ['workspace/failed.txt'] }])( + 'keeps failed parser provenance out of the public payload for %j', + async ({ filePath }) => { + mockResolveProvenanceSource.mockResolvedValue({ + identity: { fileId: 'private-source', key: 'workspace/failed.txt', context: 'workspace' }, + ownerUserId: 'private-owner', + }) + mockGetBoundProvenance.mockResolvedValue({ + status: 'exact', + entries: [{ name: 'SECRET', encryptedValue: 'private-ciphertext' }], + }) + mockParseBuffer.mockResolvedValue({ + content: 'discarded parser output', + metadata: { degraded: true, warning: 'Unable to parse format' }, + }) + + const response = await POST( + createMockRequest( + 'POST', + { filePath }, + { 'x-sim-request-private-tool-metadata': 'resolved-secret-provenance-v1' } + ) + ) + const body = await response.json() + const serialized = JSON.stringify(body) + + expect(Array.isArray(filePath) ? body.results[0].success : body.success).toBe(false) + for (const privateValue of [ + 'provenanceSource', + 'private-source', + 'private-owner', + 'private-ciphertext', + 'discarded parser output', + ]) { + expect(serialized).not.toContain(privateValue) + } + for (const call of mockGetFileContentProvenance.mock.calls) { + expect(call[2]).toEqual([]) + } + } + ) + it('should accept and process a local file', async () => { setupFileApiMocks({ cloudEnabled: false, @@ -458,7 +833,8 @@ describe('file parser operation', () => { parsedBuffer, 'report.pdf', 'application/pdf', - 'test-user-id' + 'test-user-id', + { status: 'unrecorded' } ) }) diff --git a/apps/sim/lib/internal/file/parser.ts b/apps/sim/lib/internal/file/parser.ts index 3318736429b..19f24e02ef7 100644 --- a/apps/sim/lib/internal/file/parser.ts +++ b/apps/sim/lib/internal/file/parser.ts @@ -7,6 +7,7 @@ import type { Principal } from '@sim/auth/principal' import { createLogger } from '@sim/logger' import { getErrorMessage } from '@sim/utils/errors' import { generateShortId } from '@sim/utils/id' +import { omit } from '@sim/utils/object' import binaryExtensionsList from 'binary-extensions' import type { ContractBody } from '@/lib/api/contracts' import type { fileParseContract } from '@/lib/api/contracts/storage-transfer' @@ -16,18 +17,32 @@ import { isPayloadSizeLimitError, readNodeStreamToBufferWithLimit, } from '@/lib/core/utils/stream-limits' +import { resolveStoredFileProvenanceSource } from '@/lib/execution/payloads/file-secret-provenance' import { assertUserFileContentAccess, type ExecutionMaterializationContext, } from '@/lib/execution/payloads/materialization.server' +import { + RESOLVED_SECRET_PROVENANCE_METADATA_V1, + requestsPrivateToolMetadata, +} from '@/lib/execution/private-tool-metadata' import { isSupportedFileType, parseBuffer } from '@/lib/file-parsers' import { isFileParserError } from '@/lib/file-parsers/errors' +import { + type FileContentProvenanceSource, + fileContentJsonResponse, + getFileContentProvenance, +} from '@/lib/internal/file/operations' import { isUsingCloudStorage, StorageService } from '@/lib/uploads' import { uploadExecutionFile } from '@/lib/uploads/contexts/execution' import { ExternalUrlValidationError, fetchExternalUrlToWorkspace, } from '@/lib/uploads/contexts/workspace' +import { + getBoundWorkspaceFileSecretProvenance, + type WorkspaceFileSecretProvenance, +} from '@/lib/uploads/contexts/workspace/workspace-file-secret-provenance' import { UPLOAD_DIR_SERVER } from '@/lib/uploads/core/setup.server' import { isWorkspaceScopedContext } from '@/lib/uploads/shared/types' import { @@ -74,6 +89,7 @@ export interface FileParserOperationContext { fileKeys?: string[] allowLargeValueWorkflowScope?: boolean requestId?: string + headers?: Headers signal?: AbortSignal } @@ -91,6 +107,8 @@ interface ParseResult { originalName?: string // Original filename from database (for workspace files) viewerUrl?: string | null // Viewer URL for the file if available userFile?: UserFile // UserFile object for the raw file + /** Canonical lineage used only when presenting the private tool response. */ + provenanceSource?: FileContentProvenanceSource metadata?: { fileType: string size: number @@ -103,6 +121,32 @@ function getContentBytes(content: unknown): number { return typeof content === 'string' ? Buffer.byteLength(content, 'utf8') : 0 } +/** Keeps stored source lineage on byte-for-byte copies, including legacy absence. */ +async function resolveParserFileProvenance( + file: Pick, + access: FileReadAccessContext, + targetOwnerUserId: string +): Promise<{ + source?: FileContentProvenanceSource + copyProvenance: WorkspaceFileSecretProvenance +}> { + const source = await resolveStoredFileProvenanceSource(file, access) + if (!source) return { copyProvenance: { status: 'unrecorded' } } + const provenance = await getBoundWorkspaceFileSecretProvenance( + access.workspaceId, + source.identity + ) + return { + source, + copyProvenance: + provenance.status === 'exact' && + provenance.entries.length > 0 && + source.ownerUserId !== targetOwnerUserId + ? { status: 'unknown' } + : provenance, + } +} + export async function executeFileParserOperation( input: FileParserOperationInput, context: FileParserOperationContext @@ -122,6 +166,24 @@ export async function executeFileParserOperation( return Response.json({ success: false, error: 'Execution access denied' }, { status: 403 }) } const { attributedUserId, workspaceId } = context + const sources: FileContentProvenanceSource[] = [] + const includePrivateProvenance = Boolean( + context.headers && + requestsPrivateToolMetadata(context.headers, RESOLVED_SECRET_PROVENANCE_METADATA_V1) + ) + const contentResponse = async (body: Record, init?: ResponseInit) => + fileContentJsonResponse( + body, + includePrivateProvenance, + init, + includePrivateProvenance + ? await getFileContentProvenance(context.principal, workspaceId, sources, context.signal) + : undefined + ) + const partialResponse = async (results: unknown[]) => { + const response = parsedOutputTooLargeResponse(results) + return contentResponse(await response.json(), { status: response.status }) + } const fileReadAccess: FileReadAccessContext = { principal: context.principal, workspaceId, @@ -168,7 +230,7 @@ export async function executeFileParserOperation( const remainingOutputBytes = MAX_MULTI_FILE_PARSE_OUTPUT_BYTES - totalOutputBytes if (remainingOutputBytes <= 0) { - return parsedOutputTooLargeResponse(results) + return await partialResponse(results) } const result = await parseFileSingle( @@ -191,8 +253,9 @@ export async function executeFileParserOperation( if (result.success) { totalOutputBytes += getContentBytes(result.content) if (totalOutputBytes > MAX_MULTI_FILE_PARSE_OUTPUT_BYTES) { - return parsedOutputTooLargeResponse(results) + return await partialResponse(results) } + if (result.provenanceSource) sources.push(result.provenanceSource) const displayName = result.originalName || extractCleanFilename(result.filePath) || 'unknown' @@ -213,13 +276,13 @@ export async function executeFileParserOperation( } if (result.error?.startsWith('Parsed file output is too large')) { - return parsedOutputTooLargeResponse(results) + return await partialResponse(results) } - results.push(result) + results.push(omit(result, ['provenanceSource'])) } - return Response.json({ + return await contentResponse({ success: true, results, }) @@ -242,8 +305,9 @@ export async function executeFileParserOperation( } if (result.success) { + if (result.provenanceSource) sources.push(result.provenanceSource) const displayName = result.originalName || extractCleanFilename(result.filePath) || 'unknown' - return Response.json({ + return await contentResponse({ success: true, output: { content: result.content, @@ -258,7 +322,7 @@ export async function executeFileParserOperation( }) } - return Response.json(result) + return Response.json(omit(result, ['provenanceSource'])) } catch (error) { logger.error('Error in file parse API:', error) return Response.json( @@ -337,6 +401,7 @@ async function parseFileSingle( fileType, workspaceId, attributedUserId, + fileReadAccess, executionContext, headers, signal, @@ -498,15 +563,15 @@ function validateFilePath(filePath: string): { isValid: boolean; error?: string * so keying a cache by filename returns stale bytes. `fetchExternalUrlToWorkspace` * delegates to `uploadWorkspaceFile`, which suffix-disambiguates collisions on save. * - * Workspace save is skipped when the URL already points at our execution-files - * bucket (re-uploading our own bytes is wasteful and would generate `image (1).png` - * style aliases for files we already own). + * URLs for our execution-files storage resolve through the authorized canonical + * read path, keeping stored provenance bound to the same bytes the parser reads. */ async function handleExternalUrl( url: string, fileType: string, workspaceId: string, userId: string, + fileReadAccess: FileReadAccessContext, executionContext?: ExecutionContext, headers?: Record, signal?: AbortSignal, @@ -516,36 +581,81 @@ async function handleExternalUrl( try { logger.info('Fetching external URL:', url) - const { getStorageConfig, USE_S3_STORAGE, USE_BLOB_STORAGE, USE_GCS_STORAGE } = await import( - '@/lib/uploads/config' - ) + const { getStorageConfig, S3_CONFIG, USE_S3_STORAGE, USE_BLOB_STORAGE, USE_GCS_STORAGE } = + await import('@/lib/uploads/config') const executionConfig = getStorageConfig('execution') - let isExecutionFile = false + let executionFileKey: string | undefined try { const parsedUrl = new URL(url) if (USE_S3_STORAGE && executionConfig.bucket) { - const bucketInHost = parsedUrl.hostname.startsWith(executionConfig.bucket) - const bucketInPath = parsedUrl.pathname.startsWith(`/${executionConfig.bucket}/`) - isExecutionFile = bucketInHost || bucketInPath + const endpointHost = S3_CONFIG.endpoint ? new URL(S3_CONFIG.endpoint).host : undefined + const bucketHostPrefix = `${executionConfig.bucket}.` + const storageHost = parsedUrl.host.startsWith(bucketHostPrefix) + ? parsedUrl.host.slice(bucketHostPrefix.length) + : parsedUrl.host + const matchesStorageHost = endpointHost + ? storageHost === endpointHost + : /^s3(?:[.-][a-z0-9-]+)?\.amazonaws\.com$/.test(storageHost) + const bucketInHost = matchesStorageHost && parsedUrl.host.startsWith(bucketHostPrefix) + const bucketInPath = + matchesStorageHost && parsedUrl.pathname.startsWith(`/${executionConfig.bucket}/`) + if (bucketInHost || bucketInPath) { + executionFileKey = decodeURIComponent( + bucketInHost + ? parsedUrl.pathname.slice(1) + : parsedUrl.pathname.slice(executionConfig.bucket.length + 2) + ) + } } else if (USE_BLOB_STORAGE && executionConfig.containerName) { - isExecutionFile = url.includes(`/${executionConfig.containerName}/`) + const { getBlobServiceClient } = await import('@/lib/uploads/providers/blob/client') + const client = await getBlobServiceClient() + const containerUrl = new URL(client.getContainerClient(executionConfig.containerName).url) + const prefix = `${containerUrl.pathname.replace(/\/$/, '')}/` + if (parsedUrl.origin === containerUrl.origin && parsedUrl.pathname.startsWith(prefix)) { + executionFileKey = decodeURIComponent(parsedUrl.pathname.slice(prefix.length)) + } } else if (USE_GCS_STORAGE && executionConfig.bucket) { - const bucketInHost = parsedUrl.hostname.startsWith(`${executionConfig.bucket}.`) - const bucketInPath = parsedUrl.pathname.startsWith(`/${executionConfig.bucket}/`) - isExecutionFile = bucketInHost || bucketInPath + const bucketInHost = + parsedUrl.hostname === `${executionConfig.bucket}.storage.googleapis.com` + const bucketInPath = + parsedUrl.hostname === 'storage.googleapis.com' && + parsedUrl.pathname.startsWith(`/${executionConfig.bucket}/`) + if (bucketInHost || bucketInPath) { + executionFileKey = decodeURIComponent( + bucketInHost + ? parsedUrl.pathname.slice(1) + : parsedUrl.pathname.slice(executionConfig.bucket.length + 2) + ) + } } } catch (error) { logger.warn('Failed to parse URL for execution file check:', error) - isExecutionFile = false + executionFileKey = undefined + } + + /** Read owned storage through its authorized, canonical bytes and provenance together. */ + if (executionFileKey) { + return handleCloudFile( + executionFileKey, + fileType, + userId, + fileReadAccess, + fileReadAccess.principal, + workspaceId, + executionContext, + signal, + maxDownloadBytes, + maxParsedOutputBytes + ) } const { filename, buffer, mimeType } = await fetchExternalUrlToWorkspace({ url, userId, workspaceId: workspaceId || undefined, - saveToWorkspace: Boolean(workspaceId) && !isExecutionFile, + saveToWorkspace: Boolean(workspaceId), headers, signal, maxDownloadBytes, @@ -558,7 +668,9 @@ async function handleExternalUrl( let userFile: UserFile | undefined if (executionContext) { try { - userFile = await uploadExecutionFile(executionContext, buffer, filename, mimeType, userId) + userFile = await uploadExecutionFile(executionContext, buffer, filename, mimeType, userId, { + status: 'unrecorded', + }) logger.info(`Stored file in execution storage: ${filename}`, { key: userFile.key }) } catch (uploadError) { logger.warn('Failed to store file in execution storage:', uploadError) @@ -672,6 +784,12 @@ async function handleCloudFile( } } + const sourceProvenance = await resolveParserFileProvenance( + { key: cloudKey, context }, + fileReadAccess, + attributedUserId + ) + let originalFilename: string | undefined // Not filtered to `context = 'workspace'`: a chat attachment carries the same key // prefix and has an `originalName` worth recovering too, and without it the parse @@ -745,7 +863,8 @@ async function handleCloudFile( fileBuffer, filename, mimeType, - attributedUserId + attributedUserId, + sourceProvenance.copyProvenance ) logger.info(`Copied file to execution storage: ${filename}`, { key: userFile.key }) } catch (uploadError) { @@ -803,6 +922,9 @@ async function handleCloudFile( if (userFile) { parseResult.userFile = userFile } + if (parseResult.success && sourceProvenance.source) { + parseResult.provenanceSource = sourceProvenance.source + } signal?.throwIfAborted() @@ -873,6 +995,12 @@ async function handleLocalFile( } } + const sourceProvenance = await resolveParserFileProvenance( + { key: storageKey, context }, + fileReadAccess, + attributedUserId + ) + const fullPath = path.join(UPLOAD_DIR_SERVER, storageKey) logger.info('Processing local file:', fullPath) @@ -916,7 +1044,8 @@ async function handleLocalFile( fileBuffer, filename, mimeType, - attributedUserId + attributedUserId, + sourceProvenance.copyProvenance ) logger.info(`Stored local file in execution storage: ${filename}`, { key: userFile.key }) } catch (uploadError) { @@ -930,6 +1059,7 @@ async function handleLocalFile( content, filePath, userFile, + provenanceSource: sourceProvenance.source, metadata: { fileType: mimeType, size: fileBuffer.length, diff --git a/apps/sim/lib/internal/function/execute.test.ts b/apps/sim/lib/internal/function/execute.test.ts index a5ed37edef3..676a24ecd0b 100644 --- a/apps/sim/lib/internal/function/execute.test.ts +++ b/apps/sim/lib/internal/function/execute.test.ts @@ -18,6 +18,7 @@ vi.mock('@/lib/function-execution/application/execute-function', () => ({ import { FUNCTION_EXECUTION_DELEGATION_AUDIENCE } from '@/lib/function-execution/application/authorization' import { executeFunctionTool } from '@/lib/internal/function/execute' +import { ResolvedSecretTraceRegistry } from '@/executor/utils/resolved-secret-trace-registry' describe('executeFunctionTool', () => { beforeEach(() => { @@ -59,6 +60,10 @@ describe('executeFunctionTool', () => { executionId: 'execution-1', userId: 'workspace-owner', executorDelegationOrigin: origin, + resolvedSecretTraceRegistry: new ResolvedSecretTraceRegistry([], { + userId: 'workspace-owner', + workspaceId: 'workspace-1', + }), } const headers = new Headers() @@ -92,6 +97,7 @@ describe('executeFunctionTool', () => { userId: undefined, }), headers, + resolvedSecretTraceRegistry: context.resolvedSecretTraceRegistry, }), }) }) diff --git a/apps/sim/lib/internal/function/execute.ts b/apps/sim/lib/internal/function/execute.ts index 4d68ba712a4..291dddd4fa1 100644 --- a/apps/sim/lib/internal/function/execute.ts +++ b/apps/sim/lib/internal/function/execute.ts @@ -71,6 +71,9 @@ export async function executeFunctionTool(input: ExecuteFunctionToolInput): Prom workspaceId: context.workspaceId, body: trustedBody, headers, + ...(context.resolvedSecretTraceRegistry + ? { resolvedSecretTraceRegistry: context.resolvedSecretTraceRegistry } + : {}), ...(signal ? { signal } : {}), ...(sandboxProfile ? { sandboxProfile } : {}), }, diff --git a/apps/sim/lib/knowledge/__integration__/execution-archive-provenance.integration.ts b/apps/sim/lib/knowledge/__integration__/execution-archive-provenance.integration.ts new file mode 100644 index 00000000000..6cbe10aeed6 --- /dev/null +++ b/apps/sim/lib/knowledge/__integration__/execution-archive-provenance.integration.ts @@ -0,0 +1,491 @@ +/** Real execution-file storage, ZIP extraction, durable provenance, table import, and KB indexing. */ +import { mkdtempSync } from 'node:fs' +import { rm } from 'node:fs/promises' +import { tmpdir } from 'node:os' +import path from 'node:path' +import type { DelegatedPrincipal } from '@sim/auth/principal' +import { db } from '@sim/db' +import { withInsertColumns } from '@sim/db/insert-columns' +import { + document, + documentSecretProvenance, + knowledgeBase, + organization, + outboxEvent, + user, + userTableRowSecretProvenance, + userTableRows, + workspace, + workspaceFileColumns, + workspaceFiles, +} from '@sim/db/schema' +import { generateId } from '@sim/utils/id' +import { eq, inArray, sql } from 'drizzle-orm' +import JSZip from 'jszip' +import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest' + +const fixtureStorage = vi.hoisted(() => ({ root: '' })) +vi.mock('@/lib/uploads/core/setup.server', () => ({ + get UPLOAD_DIR_SERVER() { + return fixtureStorage.root + }, +})) +vi.mock('@/lib/embeddings', async () => ({ + ...(await import('@/lib/embeddings/client')), + assertKnowledgeEmbeddingCapacity: async () => {}, + embedKnowledge: async (texts: string[]) => ({ + embeddings: texts.map(() => [1, ...Array(1535).fill(0)]), + totalTokens: texts.length, + billableTokens: 0, + isBYOK: true, + modelName: 'text-embedding-3-small', + pricingId: 'text-embedding-3-small', + }), +})) + +import { fileManageDecompressBodySchema } from '@/lib/api/contracts/tools/file' +import { processOutboxEventById } from '@/lib/core/outbox/service' +import { encryptSecret } from '@/lib/core/security/encryption' +import { isUserFile } from '@/lib/core/utils/user-file' +import { executeFileManageOperation } from '@/lib/internal/file/operations' +import { + createKnowledgeAclFixtureIds, + seedKnowledgeAclFixture, +} from '@/lib/knowledge/__integration__/seed-source-access-fixture' +import { addWorkspaceFilesToKnowledgeBase } from '@/lib/knowledge/application/add-workspace-files' +import { listKnowledgeChunks } from '@/lib/knowledge/application/chunks' +import { searchKnowledge } from '@/lib/knowledge/application/search' +import { KNOWLEDGE_DOCUMENT_PROCESSING_OUTBOX_EVENT } from '@/lib/knowledge/documents/processing-outbox-event' +import { knowledgeDocumentProcessingOutboxHandlers } from '@/lib/knowledge/documents/processing-outbox-handler' +import { createSingleDocument } from '@/lib/knowledge/documents/service' +import { loadKnowledgeDocumentSecretRegistry } from '@/lib/knowledge/secret-provenance' +import { createTableFromWorkspaceFile } from '@/lib/table/application/workspace-file-imports' +import { uploadExecutionFile } from '@/lib/uploads/contexts/execution/execution-file-manager' +import { + deleteWorkspaceFile, + getWorkspaceFile, +} from '@/lib/uploads/contexts/workspace/workspace-file-manager' +import { + filterModelSafeWorkspaceFileAttachments, + getBoundWorkspaceFileSecretProvenance, + isModelSafeWorkspaceFileKey, + isOpaqueWorkspaceFileEgressSafe, + type WorkspaceFileSecretProvenance, +} from '@/lib/uploads/contexts/workspace/workspace-file-secret-provenance' +import { deleteFile, downloadFile } from '@/lib/uploads/core/storage-service' +import { createWorkspaceFileDelegatedPrincipal } from '@/lib/workspace-files/application/delegated-principal' +import type { UserFile } from '@/executor/types' + +const fixtures: ReturnType[] = [] +const trackedEventIds: string[] = [] +const REPORT_TEXT = + 'Orion archive import retains verified source bytes through every durable surface.' +const REPORT_CSV = `name,description\nOrion,${REPORT_TEXT}\n` +const FIXTURE_SECRET = 'fixture-resolved-secret-not-a-live-key' + +async function seed() { + const ids = createKnowledgeAclFixtureIds() + fixtures.push(ids) + await seedKnowledgeAclFixture(ids) + return { ...ids, workflowId: generateId(), executionId: generateId() } +} + +type Fixture = Awaited> + +function sessionPrincipal(ids: Fixture) { + return { kind: 'session', userId: ids.aliceId, sessionId: 'fixture-session' } as const +} + +function tablePrincipal(ids: Fixture): DelegatedPrincipal { + const issuedAt = new Date() + return { + kind: 'delegated', + serviceId: 'copilot', + subjectUserId: ids.aliceId, + workspaceId: ids.workspaceId, + delegationId: generateId(), + audience: 'sim:tables', + issuedAt, + expiresAt: new Date(issuedAt.getTime() + 5 * 60_000), + } +} + +async function uploadArchive( + ids: Fixture, + provenance?: WorkspaceFileSecretProvenance, + content = REPORT_CSV +) { + const zip = new JSZip() + zip.file('report.csv', content) + return uploadExecutionFile( + ids, + await zip.generateAsync({ type: 'nodebuffer', compression: 'DEFLATE' }), + 'report.zip', + 'application/zip', + ids.aliceId, + provenance + ) +} + +async function decompress(ids: Fixture, archive: UserFile, executionId = ids.executionId) { + return executeFileManageOperation( + fileManageDecompressBodySchema.parse({ + operation: 'decompress', + workspaceId: ids.workspaceId, + fileInput: archive, + }), + { + principal: createWorkspaceFileDelegatedPrincipal({ + serviceId: 'executor', + subjectUserId: ids.aliceId, + workspaceId: ids.workspaceId, + delegationId: generateId(), + executionId, + }), + workspaceId: ids.workspaceId, + attributedUserId: ids.aliceId, + fileAccessUserId: ids.aliceId, + workflowId: ids.workflowId, + executionId, + headers: new Headers(), + requestId: generateId(), + } + ) +} + +async function extract(ids: Fixture, archive: UserFile) { + const response = await decompress(ids, archive) + const body = await response.json() + expect(response.status, JSON.stringify(body)).toBe(200) + expect(body.success).toBe(true) + const candidates: unknown = body.data?.files + if (!Array.isArray(candidates) || !candidates.every(isUserFile)) { + throw new Error('Archive extraction returned invalid file metadata') + } + expect(candidates).toHaveLength(1) + const child = candidates[0] + const record = await getWorkspaceFile(ids.workspaceId, child.id) + if (!record) throw new Error('Extracted file has no canonical workspace record') + const identity = { + fileId: record.id, + key: record.key, + context: 'workspace' as const, + contentUpdatedAt: record.contentUpdatedAt ?? undefined, + } + return { child, record, identity, publicMetadata: JSON.stringify({ archive, body }) } +} + +async function assertBlockedConsumers(ids: Fixture, source: Awaited>) { + expect(await isOpaqueWorkspaceFileEgressSafe(ids.workspaceId, source.identity)).toBe(false) + const imported = await addWorkspaceFilesToKnowledgeBase.execute({ + principal: sessionPrincipal(ids), + input: { knowledgeBaseId: ids.knowledgeBaseId, fileReferences: [source.child.id] }, + }) + expect(imported).toMatchObject({ added: [], failed: [source.child.id] }) + await expect( + createTableFromWorkspaceFile.execute({ + principal: tablePrincipal(ids), + input: { workspaceId: ids.workspaceId, fileReference: source.child.id }, + }) + ).rejects.toThrow('cannot be verified as free of resolved secrets') +} + +beforeAll(() => { + fixtureStorage.root = mkdtempSync(path.join(tmpdir(), 'sim-execution-archive-provenance-')) +}) +afterAll(async () => { + if (trackedEventIds.length) { + await db.delete(outboxEvent).where(inArray(outboxEvent.id, trackedEventIds)) + } + for (const ids of fixtures) { + await db.delete(knowledgeBase).where(eq(knowledgeBase.id, ids.knowledgeBaseId)) + await db.delete(workspace).where(eq(workspace.id, ids.workspaceId)) + await db.delete(organization).where(eq(organization.id, ids.organizationId)) + await db.delete(user).where(inArray(user.id, [ids.aliceId, ids.bobId])) + } + await rm(fixtureStorage.root, { recursive: true, force: true }) + await db.$client.end() +}) + +describe('execution archive durable provenance', () => { + it('carries exact-empty lineage through extraction, table rows, and delayed KB indexing/search', async () => { + const ids = await seed() + const archive = await uploadArchive(ids, { status: 'exact', entries: [] }) + const [storedArchive] = await db + .select({ + secretProvenanceVersion: workspaceFiles.secretProvenanceVersion, + context: workspaceFiles.context, + }) + .from(workspaceFiles) + .where(eq(workspaceFiles.key, archive.key)) + expect(storedArchive.secretProvenanceVersion).toBe(1) + expect(storedArchive.context).toBe('execution') + const source = await extract(ids, archive) + expect(await getBoundWorkspaceFileSecretProvenance(ids.workspaceId, source.identity)).toEqual({ + status: 'exact', + entries: [], + }) + expect(await isOpaqueWorkspaceFileEgressSafe(ids.workspaceId, source.identity)).toBe(true) + expect((await downloadFile({ key: source.child.key, context: 'workspace' })).toString()).toBe( + REPORT_CSV + ) + + const table = await createTableFromWorkspaceFile.execute({ + principal: tablePrincipal(ids), + input: { workspaceId: ids.workspaceId, fileReference: source.child.id }, + }) + expect(table.kind).toBe('inline') + if (table.kind !== 'inline') throw new Error('Small CSV did not use the inline import path') + expect(table.insertedCount).toBe(1) + const rows = await db + .select({ + data: userTableRows.data, + updatedAt: userTableRows.updatedAt, + version: userTableRows.secretProvenanceVersion, + contentUpdatedAt: userTableRowSecretProvenance.contentUpdatedAt, + status: userTableRowSecretProvenance.status, + entries: userTableRowSecretProvenance.entries, + }) + .from(userTableRows) + .leftJoin( + userTableRowSecretProvenance, + eq(userTableRowSecretProvenance.rowId, userTableRows.id) + ) + .where(eq(userTableRows.tableId, table.table.id)) + expect(rows).toHaveLength(1) + const nameColumn = table.table.schema.columns.find((column) => column.name === 'name') + const descriptionColumn = table.table.schema.columns.find( + (column) => column.name === 'description' + ) + if (!nameColumn?.id || !descriptionColumn?.id) { + throw new Error('Imported table lost its canonical source columns') + } + expect(rows[0]).toMatchObject({ + data: { [nameColumn.id]: 'Orion', [descriptionColumn.id]: REPORT_TEXT }, + version: 1, + status: 'exact', + entries: [], + }) + expect(rows[0].contentUpdatedAt).toEqual(rows[0].updatedAt) + + const imported = await addWorkspaceFilesToKnowledgeBase.execute({ + principal: sessionPrincipal(ids), + input: { knowledgeBaseId: ids.knowledgeBaseId, fileReferences: [source.child.id] }, + }) + expect(imported.failed).toEqual([]) + expect(imported.added).toHaveLength(1) + const documentId = imported.added[0].documentId + const [admitted] = await db.select().from(document).where(eq(document.id, documentId)) + expect(admitted.secretProvenanceVersion).toBe(1) + expect(admitted.storageKey).toMatch(/^kb\//) + const events = await db + .select() + .from(outboxEvent) + .where(sql`${outboxEvent.payload}::jsonb ->> 'documentId' = ${documentId}`) + trackedEventIds.push(...events.map((event) => event.id)) + const dispatch = events.find( + (event) => event.eventType === KNOWLEDGE_DOCUMENT_PROCESSING_OUTBOX_EVENT + ) + if (!dispatch) throw new Error('Knowledge import did not atomically admit processing') + await deleteWorkspaceFile(ids.workspaceId, source.child.id) + await deleteFile({ key: source.child.key, context: 'workspace' }) + await deleteFile({ key: archive.key, context: 'execution' }) + await processOutboxEventById(dispatch.id, knowledgeDocumentProcessingOutboxHandlers) + const [indexed] = await db.select().from(document).where(eq(document.id, documentId)) + expect(indexed.processingStatus, indexed.processingError ?? undefined).toBe('completed') + const chunks = await listKnowledgeChunks.execute({ + principal: sessionPrincipal(ids), + input: { knowledgeBaseId: ids.knowledgeBaseId, documentId }, + }) + expect(chunks.chunks.map((chunk) => chunk.content).join('\n')).toContain(REPORT_TEXT) + const search = await searchKnowledge.execute({ + principal: sessionPrincipal(ids), + input: { + workspaceId: ids.workspaceId, + knowledgeBaseIds: [ids.knowledgeBaseId], + query: 'Orion', + searchMode: 'hybrid', + topK: 10, + }, + }) + expect(search.results.map((entry) => entry.documentId)).toContain(documentId) + }) + + it('keeps an explicitly unknown execution source unavailable to model, KB, and table consumers', async () => { + const ids = await seed() + const archive = await uploadArchive(ids, { status: 'unknown' }) + const source = await extract(ids, archive) + expect(await getBoundWorkspaceFileSecretProvenance(ids.workspaceId, source.identity)).toEqual({ + status: 'unknown', + }) + await assertBlockedConsumers(ids, source) + }) + + it('does not infer safe extracted bytes from a secret-bearing archive or expose private metadata', async () => { + const ids = await seed() + const { encrypted } = await encryptSecret(FIXTURE_SECRET) + const archive = await uploadArchive( + ids, + { + status: 'exact', + entries: [ + { + name: 'FIXTURE_SECRET', + encryptedValue: encrypted, + sourceUserId: ids.aliceId, + sourceWorkspaceId: ids.workspaceId, + }, + ], + }, + `name,description\nOrion,${FIXTURE_SECRET}\n` + ) + const source = await extract(ids, archive) + expect(source.publicMetadata).not.toContain(FIXTURE_SECRET) + expect(source.publicMetadata).not.toContain(encrypted) + expect(source.publicMetadata).not.toContain('encryptedValue') + expect(await getBoundWorkspaceFileSecretProvenance(ids.workspaceId, source.identity)).toEqual({ + status: 'unknown', + }) + await assertBlockedConsumers(ids, source) + }) + + it('preserves compatibility for execution files created before provenance stamping', async () => { + const ids = await seed() + const archive = await uploadArchive(ids) + const [storedArchive] = await db + .select({ + secretProvenanceVersion: workspaceFiles.secretProvenanceVersion, + context: workspaceFiles.context, + }) + .from(workspaceFiles) + .where(eq(workspaceFiles.key, archive.key)) + expect(storedArchive.secretProvenanceVersion).toBeNull() + const source = await extract(ids, archive) + expect(await isOpaqueWorkspaceFileEgressSafe(ids.workspaceId, source.identity)).toBe(true) + const imported = await createTableFromWorkspaceFile.execute({ + principal: tablePrincipal(ids), + input: { workspaceId: ids.workspaceId, fileReference: source.child.id }, + }) + expect(imported.kind).toBe('inline') + }) + + it.each([false, true])( + 'refuses tracked unknown execution attachments with historical metadata (archivedOnly=%s)', + async (archivedOnly) => { + const ids = await seed() + const file = await uploadExecutionFile( + ids, + Buffer.from(REPORT_CSV), + 'report.csv', + 'text/csv', + ids.aliceId, + { status: 'unknown' } + ) + if (archivedOnly) { + await db + .update(workspaceFiles) + .set({ deletedAt: new Date() }) + .where(eq(workspaceFiles.key, file.key)) + } else { + await db.insert(withInsertColumns(workspaceFiles, workspaceFileColumns)).values({ + id: generateId(), + key: file.key, + userId: ids.aliceId, + workspaceId: ids.workspaceId, + context: 'execution', + originalName: 'historical-report.csv', + contentType: file.type, + sizeBytes: file.size, + deletedAt: new Date(), + contentUpdatedAt: new Date(Date.now() + 60_000), + secretProvenanceVersion: null, + }) + } + + expect( + await filterModelSafeWorkspaceFileAttachments([file], { workspaceId: ids.workspaceId }) + ).toEqual([]) + expect(await isModelSafeWorkspaceFileKey(file.key, { workspaceId: ids.workspaceId })).toBe( + false + ) + } + ) + + it.each([ + { status: 'exact', deleted: false }, + { status: 'unknown', deleted: false }, + { status: 'exact', deleted: true }, + { status: 'unknown', deleted: true }, + ] as const)( + 'binds $status execution bytes into KB admission despite URL-only classification (deleted=$deleted)', + async ({ status, deleted }) => { + const ids = await seed() + const file = await uploadExecutionFile( + ids, + Buffer.from(REPORT_CSV), + 'report.csv', + 'text/csv', + ids.aliceId, + status === 'exact' ? { status, entries: [] } : { status } + ) + if (deleted) { + await db + .update(workspaceFiles) + .set({ deletedAt: new Date() }) + .where(eq(workspaceFiles.key, file.key)) + } + const admitted = await createSingleDocument( + { + filename: file.name, + fileUrl: `/api/files/serve/${encodeURIComponent(file.key)}?context=workspace`, + fileSize: file.size, + mimeType: file.type, + }, + ids.knowledgeBaseId, + generateId(), + ids.aliceId, + undefined, + { + filename: { status: 'exact', entries: [] }, + content: { status: 'exact', entries: [] }, + tags: [], + } + ) + const [stored] = await db + .select({ + version: document.secretProvenanceVersion, + status: documentSecretProvenance.status, + }) + .from(document) + .leftJoin(documentSecretProvenance, eq(documentSecretProvenance.documentId, document.id)) + .where(eq(document.id, admitted.id)) + expect(stored).toEqual({ version: 1, status }) + const registry = loadKnowledgeDocumentSecretRegistry(admitted.id, { + userId: ids.aliceId, + workspaceId: ids.workspaceId, + }) + if (status === 'exact') { + await expect(registry).resolves.toMatchObject({ + tracked: true, + provenance: { status: 'exact', entries: [] }, + }) + } else { + await expect(registry).rejects.toThrow( + 'Knowledge document secret provenance is unavailable' + ) + } + } + ) + + it('refuses another execution before extracting any workspace files', async () => { + const ids = await seed() + const archive = await uploadArchive(ids, { status: 'exact', entries: [] }) + const response = await decompress(ids, archive, generateId()) + expect(response.status).toBe(404) + const files = await db + .select({ context: workspaceFiles.context }) + .from(workspaceFiles) + .where(eq(workspaceFiles.workspaceId, ids.workspaceId)) + expect(files).toEqual([{ context: 'execution' }]) + }) +}) diff --git a/apps/sim/lib/knowledge/documents/document-processing-source.test.ts b/apps/sim/lib/knowledge/documents/document-processing-source.test.ts index 5b36cbdf3c2..24b77c321fa 100644 --- a/apps/sim/lib/knowledge/documents/document-processing-source.test.ts +++ b/apps/sim/lib/knowledge/documents/document-processing-source.test.ts @@ -420,6 +420,142 @@ describe('knowledge document processing source', () => { expect(mockGenerateEmbeddings).not.toHaveBeenCalled() }) + describe('execution source provenance', () => { + const executionKey = 'execution/workspace-1/workflow-1/run-1/source.pdf' + const executionUrl = `/api/files/serve/${encodeURIComponent(executionKey)}?context=workspace` + const executionBinding = { + ...SOURCE_BINDING, + key: executionKey, + context: 'execution', + secretProvenanceVersion: 1, + } + + beforeEach(() => { + dbChainMockFns.limit + .mockReset() + .mockResolvedValueOnce([{ ...PERSISTED_CONTEXT, fileUrl: executionUrl }]) + .mockResolvedValueOnce([{ ...PERSISTED_PROVENANCE_ROW, fileUrl: executionUrl }]) + .mockResolvedValueOnce([{ id: 'document-1' }]) + mockGetFileMetadataByKeys.mockImplementation(async (_keys: string[], context: string) => + context === 'execution' ? [executionBinding] : [] + ) + }) + + function process() { + return processDocumentAsync( + 'knowledge-base-1', + 'document-1', + { + filename: 'untrusted-queued-name.txt', + fileUrl: 'https://example.com/untrusted-queued-url.txt', + fileSize: 1, + mimeType: 'text/plain', + }, + {}, + BILLING_ATTRIBUTION + ) + } + + it('loads persisted execution lineage before parsing, ignoring the URL context label', async () => { + await process() + + expect(mockGetFileMetadataByKeys).toHaveBeenCalledWith( + [executionKey], + 'execution', + expect.anything(), + { includeDeleted: true } + ) + expect(mockGetBoundWorkspaceFileSecretProvenanceByMetadata).toHaveBeenCalledWith( + expect.anything(), + [executionBinding] + ) + expect(mockProcessDocument).toHaveBeenCalledWith( + executionUrl, + PERSISTED_CONTEXT.filename, + PERSISTED_CONTEXT.mimeType, + 1024, + 200, + 100, + expect.objectContaining({ userId: BILLING_ATTRIBUTION.actorUserId }), + PERSISTED_CONTEXT.workspaceId, + undefined, + undefined + ) + }) + + it.each(['unknown', 'missing'])( + 'refuses tracked execution sources with %s sidecars before parsing', + async (kind) => { + mockGetBoundWorkspaceFileSecretProvenanceByMetadata.mockResolvedValue( + new Map(kind === 'unknown' ? [[executionBinding.id, { status: 'unknown' }]] : []) + ) + + await expect(process()).rejects.toThrow( + 'Knowledge document secret provenance is unavailable' + ) + + expect(mockProcessDocument).not.toHaveBeenCalled() + expect(mockGenerateEmbeddings).not.toHaveBeenCalled() + } + ) + + it('refuses a soft-deleted tracked execution source before parsing', async () => { + const deletedBinding = { ...executionBinding, deletedAt: CONTENT_UPDATED_AT } + mockGetFileMetadataByKeys.mockImplementation( + async ( + _keys: string[], + context: string, + _executor: unknown, + options?: { includeDeleted?: boolean } + ) => (context === 'execution' && options?.includeDeleted ? [deletedBinding] : []) + ) + mockGetBoundWorkspaceFileSecretProvenanceByMetadata.mockResolvedValue( + new Map([[executionBinding.id, { status: 'unknown' }]]) + ) + + await expect(process()).rejects.toThrow('Knowledge document secret provenance is unavailable') + + expect(mockProcessDocument).not.toHaveBeenCalled() + expect(mockGenerateEmbeddings).not.toHaveBeenCalled() + }) + + it('preserves legacy null-marker behavior for a soft-deleted execution source', async () => { + mockGetFileMetadataByKeys.mockResolvedValue([ + { ...executionBinding, deletedAt: CONTENT_UPDATED_AT, secretProvenanceVersion: null }, + ]) + + await process() + + expect(mockGetBoundWorkspaceFileSecretProvenanceByMetadata).not.toHaveBeenCalled() + expect(mockProcessDocument).toHaveBeenCalled() + }) + + it.each(['missing', 'untracked'])( + 'retains legacy %s execution source behavior', + async (kind) => { + mockGetFileMetadataByKeys.mockResolvedValue( + kind === 'missing' ? [] : [{ ...executionBinding, secretProvenanceVersion: null }] + ) + + await process() + + expect(mockGetBoundWorkspaceFileSecretProvenanceByMetadata).not.toHaveBeenCalled() + expect(mockProcessDocument).toHaveBeenCalled() + } + ) + + it('refuses a source whose execution metadata belongs to another workspace', async () => { + mockGetFileMetadataByKeys.mockResolvedValue([ + { ...executionBinding, workspaceId: 'other-workspace' }, + ]) + + await expect(process()).rejects.toThrow('Document file is not owned by this knowledge base') + + expect(mockProcessDocument).not.toHaveBeenCalled() + expect(mockGenerateEmbeddings).not.toHaveBeenCalled() + }) + }) + it('takes over an existing processing attempt', async () => { dbChainMockFns.limit .mockReset() diff --git a/apps/sim/lib/knowledge/documents/service.ts b/apps/sim/lib/knowledge/documents/service.ts index d3dea4c4ecc..65eb4b14f95 100644 --- a/apps/sim/lib/knowledge/documents/service.ts +++ b/apps/sim/lib/knowledge/documents/service.ts @@ -184,7 +184,7 @@ const logger = createLogger('DocumentService') /** * Thrown when a knowledge-base document's `fileUrl` references an internal - * knowledge-base storage object not owned by the target knowledge base's workspace. + * knowledge-base or execution object not owned by the target knowledge base's workspace. * Routes map this to a 403. * * Deliberately carries no `details.code`. It belongs to the cross-tenant class @@ -214,12 +214,15 @@ function getKnowledgeBaseStorageKeys(fileUrls: readonly string[]): string[] { ] } -function getWorkspaceSourceStorageKeys(fileUrls: readonly string[]): string[] { +function getSourceStorageKeys( + fileUrls: readonly string[], + context: 'workspace' | 'execution' +): string[] { return [ ...new Set( fileUrls .map((url) => getKnowledgeBaseStorageKey(url)) - .filter((key): key is string => typeof key === 'string' && key.startsWith('workspace/')) + .filter((key): key is string => typeof key === 'string' && key.startsWith(`${context}/`)) ), ] } @@ -238,18 +241,39 @@ async function loadKnowledgeBaseFileBindings( return new Map(bindings.map((binding) => [binding.key, binding])) } -async function loadWorkspaceSourceFileBindings( +/** Execution metadata without a provenance marker predates stamping and remains a legacy source. */ +async function loadSourceFileBindings( fileUrls: readonly string[], + workspaceId: string | null, executor: DbExecutor = db ): Promise> { - const keys = getWorkspaceSourceStorageKeys(fileUrls) - if (keys.length === 0) return new Map() + const workspaceKeys = getSourceStorageKeys(fileUrls, 'workspace') + const executionKeys = getSourceStorageKeys(fileUrls, 'execution') + const workspaceBindings = + workspaceKeys.length > 0 + ? await getFileMetadataByKeys(workspaceKeys, 'workspace', executor) + : [] + const mothershipBindings = + workspaceKeys.length > 0 + ? await getFileMetadataByKeys(workspaceKeys, 'mothership', executor) + : [] + const executionBindings = + executionKeys.length > 0 + ? await getFileMetadataByKeys(executionKeys, 'execution', executor, { includeDeleted: true }) + : [] - const workspaceBindings = await getFileMetadataByKeys(keys, 'workspace', executor) - const mothershipBindings = await getFileMetadataByKeys(keys, 'mothership', executor) + for (const binding of executionBindings) { + if (!workspaceId || binding.workspaceId !== workspaceId) { + throw new KnowledgeBaseFileOwnershipError(binding.key) + } + } return new Map( - [...workspaceBindings, ...mothershipBindings].map((binding) => [binding.key, binding]) + [ + ...workspaceBindings, + ...mothershipBindings, + ...executionBindings.filter((binding) => binding.secretProvenanceVersion !== null), + ].map((binding) => [binding.key, binding]) ) } @@ -281,13 +305,14 @@ async function assertKnowledgeBaseFileUrlsOwnership( return bindingByKey } -async function loadCurrentWorkspaceSourceFileSecretProvenance(options: { +async function loadCurrentSourceFileSecretProvenance(options: { fileUrl: string + workspaceId: string | null }): Promise { const storageKey = getKnowledgeBaseStorageKey(options.fileUrl) - if (!storageKey?.startsWith('workspace/')) return undefined + if (!storageKey) return undefined - const bindingByKey = await loadWorkspaceSourceFileBindings([options.fileUrl]) + const bindingByKey = await loadSourceFileBindings([options.fileUrl], options.workspaceId) const binding = bindingByKey.get(storageKey) if (!binding) return undefined @@ -388,7 +413,7 @@ interface DocumentTagData { type TagDefinition = typeof knowledgeBaseTagDefinitions.$inferSelect type TagDefinitionsByName = Map -type DbExecutor = Pick +type DbExecutor = Pick async function loadTagDefinitions( knowledgeBaseId: string, @@ -1638,8 +1663,9 @@ export async function processDocumentAsync( let embeddingModelName = kbEmbeddingModel let embeddingPricingId = kbEmbeddingModel - const currentSourceFileProvenance = await loadCurrentWorkspaceSourceFileSecretProvenance({ + const currentSourceFileProvenance = await loadCurrentSourceFileSecretProvenance({ fileUrl: persistedDocData.fileUrl, + workspaceId: ctx.workspaceId, }) const documentSecretContext = await loadKnowledgeDocumentSecretRegistry( documentId, @@ -2287,8 +2313,9 @@ export async function createDocumentRecords( requestId, tx ) - const sourceBindingByKey = await loadWorkspaceSourceFileBindings( + const sourceBindingByKey = await loadSourceFileBindings( resolvedDocuments.map((docData) => docData.fileUrl), + admission.workspaceId, tx ) const trackedBindings = [ @@ -2961,8 +2988,9 @@ export async function createSingleDocument( requestId, tx ) - const sourceBindingByKey = await loadWorkspaceSourceFileBindings( + const sourceBindingByKey = await loadSourceFileBindings( [resolvedDocumentData.fileUrl], + admission.workspaceId, tx ) const storageKey = getKnowledgeBaseStorageKey(resolvedDocumentData.fileUrl) diff --git a/apps/sim/lib/knowledge/documents/workspace-source-provenance.test.ts b/apps/sim/lib/knowledge/documents/workspace-source-provenance.test.ts index ecbc5e5f543..4c860c16817 100644 --- a/apps/sim/lib/knowledge/documents/workspace-source-provenance.test.ts +++ b/apps/sim/lib/knowledge/documents/workspace-source-provenance.test.ts @@ -3,6 +3,7 @@ */ import { dbChainMockFns, resetDbChainMock } from '@sim/testing' import { beforeEach, describe, expect, it, vi } from 'vitest' +import type { WorkspaceFileSecretProvenance } from '@/lib/uploads/contexts/workspace/workspace-file-secret-provenance' const { mockCheckStorageQuotaForBillingContext, @@ -282,6 +283,137 @@ describe('knowledge workspace source provenance', () => { expect(findDocumentProvenanceWrite()).toBeUndefined() }) + describe('execution file sources', () => { + const executionKey = `execution/${WORKSPACE_ID}/workflow-1/run-1/source.pdf` + const executionUrl = `/api/files/serve/${encodeURIComponent(executionKey)}?context=workspace` + const executionBinding = { + ...SOURCE_BINDING, + id: 'execution-source-1', + key: executionKey, + context: 'execution', + } + const documentInput = { + filename: 'source.pdf', + fileUrl: executionUrl, + fileSize: 512, + mimeType: 'application/pdf', + } + + beforeEach(() => { + mockGetFileMetadataByKeys.mockImplementation(async (_keys: string[], context: string) => + context === 'execution' ? [executionBinding] : [] + ) + }) + + for (const mode of ['single', 'bulk'] as const) { + async function create() { + if (mode === 'single') { + await createSingleDocument(documentInput, KNOWLEDGE_BASE_ID, 'request-1', SOURCE_USER_ID) + } else { + await createDocumentRecords( + [documentInput], + KNOWLEDGE_BASE_ID, + 'request-1', + SOURCE_USER_ID + ) + } + } + + it.each([ + { status: 'exact', entries: [] }, + { + status: 'exact', + entries: [{ name: 'EXPORT_SECRET', encryptedValue: 'encrypted-export-secret' }], + }, + { status: 'unknown' }, + ] satisfies WorkspaceFileSecretProvenance[])( + `binds canonical execution byte provenance during ${mode} admission: %j`, + async (provenance) => { + mockGetBoundWorkspaceFileSecretProvenanceByMetadata.mockResolvedValue( + new Map([[executionBinding.id, provenance]]) + ) + + await create() + + expect(mockGetFileMetadataByKeys).toHaveBeenCalledWith( + [executionKey], + 'execution', + expect.anything(), + { includeDeleted: true } + ) + expect(mockGetBoundWorkspaceFileSecretProvenanceByMetadata).toHaveBeenCalledWith( + expect.anything(), + [executionBinding] + ) + expect(findDocumentProvenanceWrite()).toEqual( + expect.objectContaining({ + status: provenance.status, + entries: + provenance.status === 'exact' + ? provenance.entries.map((entry) => + expect.objectContaining({ + ...entry, + sourceUserId: SOURCE_USER_ID, + sourceWorkspaceId: WORKSPACE_ID, + sourceValueHash: expect.any(String), + }) + ) + : [], + }) + ) + } + ) + + it(`preserves soft-deleted execution taint during ${mode} admission`, async () => { + const deletedBinding = { ...executionBinding, deletedAt: CONTENT_UPDATED_AT } + mockGetFileMetadataByKeys.mockImplementation( + async ( + _keys: string[], + context: string, + _executor: unknown, + options?: { includeDeleted?: boolean } + ) => (context === 'execution' && options?.includeDeleted ? [deletedBinding] : []) + ) + mockGetBoundWorkspaceFileSecretProvenanceByMetadata.mockResolvedValue( + new Map([[executionBinding.id, { status: 'unknown' }]]) + ) + + await create() + + expect(findDocumentProvenanceWrite()).toMatchObject({ status: 'unknown', entries: [] }) + }) + + it.each(['missing', 'untracked'])( + `preserves legacy %s execution sources during ${mode} admission`, + async (kind) => { + mockGetFileMetadataByKeys.mockResolvedValue( + kind === 'missing' ? [] : [{ ...executionBinding, secretProvenanceVersion: null }] + ) + + await create() + + expect(mockGetBoundWorkspaceFileSecretProvenanceByMetadata).toHaveBeenCalledWith( + expect.anything(), + [] + ) + expect(findDocumentProvenanceWrite()).toBeUndefined() + } + ) + + it(`refuses another workspace's execution source before ${mode} admission`, async () => { + mockGetFileMetadataByKeys.mockResolvedValue([ + { ...executionBinding, workspaceId: 'other-workspace' }, + ]) + + await expect(create()).rejects.toThrow('Document file is not owned by this knowledge base') + + expect(mockGetBoundWorkspaceFileSecretProvenanceByMetadata).not.toHaveBeenCalled() + expect(findDocumentProvenanceWrite()).toBeUndefined() + expect(mockIncrementStorageUsageForBillingContextInTx).not.toHaveBeenCalled() + }) + } + }) + it('never deletes a referenced workspace source as knowledge-base storage', async () => { await deleteDocumentStorageFiles( [{ id: 'document-1', fileUrl: SOURCE_URL, workspaceId: WORKSPACE_ID }], diff --git a/apps/sim/lib/uploads/contexts/execution/execution-file-manager.test.ts b/apps/sim/lib/uploads/contexts/execution/execution-file-manager.test.ts index 4f0c5d007c5..1d108c60d37 100644 --- a/apps/sim/lib/uploads/contexts/execution/execution-file-manager.test.ts +++ b/apps/sim/lib/uploads/contexts/execution/execution-file-manager.test.ts @@ -4,9 +4,10 @@ import { dbChainMockFns, resetDbChainMock } from '@sim/testing' import { beforeEach, describe, expect, it, vi } from 'vitest' -const { mockUploadToS3, mockGetPresignedUrlWithConfig } = vi.hoisted(() => ({ +const { mockUploadToS3, mockGetPresignedUrlWithConfig, mockDeleteFromS3 } = vi.hoisted(() => ({ mockUploadToS3: vi.fn(), mockGetPresignedUrlWithConfig: vi.fn(), + mockDeleteFromS3: vi.fn(), })) vi.mock('@/lib/uploads/config', () => ({ @@ -19,6 +20,7 @@ vi.mock('@/lib/uploads/config', () => ({ vi.mock('@/lib/uploads/providers/s3/client', () => ({ uploadToS3: mockUploadToS3, getPresignedUrlWithConfig: mockGetPresignedUrlWithConfig, + deleteFromS3: mockDeleteFromS3, })) import { uploadExecutionFile } from '@/lib/uploads/contexts/execution/execution-file-manager' @@ -41,6 +43,7 @@ describe('uploadExecutionFile key allocation', () => { type: contentType, })) mockGetPresignedUrlWithConfig.mockResolvedValue('https://example.com/download') + mockDeleteFromS3.mockResolvedValue(undefined) dbChainMockFns.limit.mockResolvedValue([]) dbChainMockFns.returning.mockResolvedValue([{ id: 'file-1' }]) }) @@ -64,4 +67,104 @@ describe('uploadExecutionFile key allocation', () => { expect(first.key).not.toBe(second.key) expect(dbChainMockFns.insert).toHaveBeenCalledTimes(2) }) + + it('commits tracked provenance with the canonical file before returning its URL', async () => { + const contentUpdatedAt = new Date('2026-01-01T00:00:00Z') + dbChainMockFns.returning.mockImplementation(async () => { + const values = dbChainMockFns.values.mock.calls.at(-1)?.[0] + return [{ ...values, id: values?.id ?? values?.fileId, contentUpdatedAt }] + }) + const file = await uploadExecutionFile( + context, + Buffer.from('archive'), + 'report.zip', + 'application/zip', + 'user-1', + { status: 'exact', entries: [] } + ) + + expect(dbChainMockFns.transaction).toHaveBeenCalledTimes(1) + expect(dbChainMockFns.values).toHaveBeenNthCalledWith( + 1, + expect.objectContaining({ id: file.id, key: file.key, context: 'execution' }) + ) + expect(dbChainMockFns.values).toHaveBeenNthCalledWith( + 2, + expect.objectContaining({ fileId: file.id, contentUpdatedAt, status: 'exact', entries: [] }) + ) + expect(dbChainMockFns.set).toHaveBeenCalledWith({ secretProvenanceVersion: 1 }) + expect(dbChainMockFns.set.mock.invocationCallOrder[0]).toBeLessThan( + mockGetPresignedUrlWithConfig.mock.invocationCallOrder[0] + ) + expect(file).not.toHaveProperty('secretProvenance') + }) + + it('removes uploaded bytes when their provenance cannot be committed', async () => { + const failure = new Error('Provenance commit failed') + dbChainMockFns.returning + .mockResolvedValueOnce([ + { + id: 'recorded-file', + contentUpdatedAt: new Date('2026-01-01T00:00:00Z'), + }, + ]) + .mockRejectedValueOnce(failure) + + await expect( + uploadExecutionFile( + context, + Buffer.from('archive'), + 'report.zip', + 'application/zip', + 'user-1', + { status: 'unknown' } + ) + ).rejects.toThrow('Provenance commit failed') + + expect(mockDeleteFromS3).toHaveBeenCalledWith( + mockUploadToS3.mock.calls[0][1], + expect.any(Object), + undefined + ) + expect(mockGetPresignedUrlWithConfig).not.toHaveBeenCalled() + }) + + it('rejects tracked uploads without an owner before writing bytes', async () => { + await expect( + uploadExecutionFile( + context, + Buffer.from('archive'), + 'report.zip', + 'application/zip', + undefined, + { + status: 'exact', + entries: [], + } + ) + ).rejects.toThrow('requires an owner and workspace') + expect(mockUploadToS3).not.toHaveBeenCalled() + }) + + it('cleans both committed metadata and bytes when its download URL cannot be issued', async () => { + const contentUpdatedAt = new Date('2026-01-01T00:00:00Z') + dbChainMockFns.returning.mockImplementation(async () => { + const values = dbChainMockFns.values.mock.calls.at(-1)?.[0] + return [{ ...values, id: values?.id ?? values?.fileId, contentUpdatedAt }] + }) + mockGetPresignedUrlWithConfig.mockRejectedValueOnce(new Error('Signing failed')) + + await expect( + uploadExecutionFile( + context, + Buffer.from('archive'), + 'report.zip', + 'application/zip', + 'user-1', + { status: 'unknown' } + ) + ).rejects.toThrow('Signing failed') + expect(mockDeleteFromS3).toHaveBeenCalledTimes(1) + expect(dbChainMockFns.set).toHaveBeenCalledWith({ deletedAt: expect.any(Date) }) + }) }) diff --git a/apps/sim/lib/uploads/contexts/execution/execution-file-manager.ts b/apps/sim/lib/uploads/contexts/execution/execution-file-manager.ts index d4f4bea9cb9..b9bb85213b7 100644 --- a/apps/sim/lib/uploads/contexts/execution/execution-file-manager.ts +++ b/apps/sim/lib/uploads/contexts/execution/execution-file-manager.ts @@ -1,5 +1,7 @@ +import { db } from '@sim/db' import { createLogger } from '@sim/logger' import { getErrorMessage } from '@sim/utils/errors' +import { generateId } from '@sim/utils/id' import { isPayloadSizeLimitError } from '@/lib/core/utils/stream-limits' import { isUserFileWithMetadata } from '@/lib/core/utils/user-file' import type { ExecutionContext } from '@/lib/uploads/contexts/execution/utils' @@ -7,6 +9,15 @@ import { generateFileId, generateUniqueExecutionFileKey, } from '@/lib/uploads/contexts/execution/utils' +import { + initializeWorkspaceFileSecretProvenanceInTx, + type WorkspaceFileSecretProvenance, +} from '@/lib/uploads/contexts/workspace/workspace-file-secret-provenance' +import { + deleteFileMetadataByIdentity, + type FileMetadataRecord, + insertImmutableFileMetadata, +} from '@/lib/uploads/server/metadata' import type { UserFile } from '@/executor/types' const logger = createLogger('ExecutionFileStorage') @@ -69,8 +80,12 @@ export async function uploadExecutionFile( fileBuffer: Buffer, fileName: string, contentType: string, - userId?: string + userId?: string, + secretProvenance?: WorkspaceFileSecretProvenance ): Promise { + if (secretProvenance && (!userId || !context.workspaceId)) { + throw new Error('Execution file provenance requires an owner and workspace') + } logger.info(`Uploading execution file: ${fileName} for execution ${context.executionId}`) logger.debug(`File upload context:`, { workspaceId: context.workspaceId, @@ -82,7 +97,7 @@ export async function uploadExecutionFile( }) const storageKey = generateUniqueExecutionFileKey(context, fileName) - const fileId = generateFileId() + const fileId = secretProvenance ? generateId() : generateFileId() logger.info(`Generated storage key: "${storageKey}" for file: ${fileName}`) @@ -97,8 +112,10 @@ export async function uploadExecutionFile( metadata.userId = userId } + const StorageService = await getStorageService() + let uploadedKey: string | undefined + let recordedFile: FileMetadataRecord | undefined try { - const StorageService = await getStorageService() const fileInfo = await StorageService.uploadFile({ file: fileBuffer, fileName: storageKey, @@ -107,7 +124,34 @@ export async function uploadExecutionFile( preserveKey: true, // Don't add timestamp prefix customKey: storageKey, // Use exact execution-scoped key metadata, // Pass metadata for cloud storage and database tracking + ...(secretProvenance ? { persistMetadata: false } : {}), }) + uploadedKey = fileInfo.key + + if (secretProvenance && userId) { + recordedFile = await db.transaction(async (tx) => { + const record = await insertImmutableFileMetadata( + { + id: fileId, + key: fileInfo.key, + userId, + workspaceId: context.workspaceId, + context: 'execution', + originalName: fileName, + contentType, + size: fileBuffer.length, + }, + tx + ) + await initializeWorkspaceFileSecretProvenanceInTx( + tx, + record.id, + record.contentUpdatedAt, + secretProvenance + ) + return record + }) + } const presignedUrl = await StorageService.generatePresignedDownloadUrl( fileInfo.key, @@ -130,6 +174,24 @@ export async function uploadExecutionFile( }) return userFile } catch (error) { + if (secretProvenance && uploadedKey) { + try { + await StorageService.deleteFile({ key: uploadedKey, context: 'execution' }) + if (recordedFile) { + await deleteFileMetadataByIdentity({ + id: recordedFile.id, + key: recordedFile.key, + context: 'execution', + contentUpdatedAt: recordedFile.contentUpdatedAt, + }) + } + } catch (cleanupError) { + logger.warn('Could not remove an unreturned execution file', { + key: uploadedKey, + error: getErrorMessage(cleanupError), + }) + } + } logger.error(`Failed to upload execution file ${fileName}:`, error) throw new Error(`Failed to upload file: ${getErrorMessage(error, 'Unknown error')}`) } diff --git a/apps/sim/lib/uploads/contexts/workspace/workspace-file-secret-provenance.test.ts b/apps/sim/lib/uploads/contexts/workspace/workspace-file-secret-provenance.test.ts index a1b84a68099..b6bdbd17523 100644 --- a/apps/sim/lib/uploads/contexts/workspace/workspace-file-secret-provenance.test.ts +++ b/apps/sim/lib/uploads/contexts/workspace/workspace-file-secret-provenance.test.ts @@ -21,11 +21,16 @@ vi.mock('@/lib/execution/durable-secret-provenance-enforcement', () => ({ })) import type { DbTransaction } from '@/lib/db/types' +import { + PROVENANCE_MAX_ENTRIES, + PROVENANCE_MAX_SERIALIZED_BYTES, +} from '@/lib/execution/provenance-limits' import { areModelSafeWorkspaceFileKeys, copyWorkspaceFileSecretProvenanceInTx, createWorkspaceFileSecretProvenanceFromRegistry, filterModelSafeWorkspaceFileAttachments, + getBoundWorkspaceFileSecretProvenance, importWorkspaceFileSecretProvenanceForModelView, importWorkspaceFileSecretProvenanceForRuntime, initializeWorkspaceFileSecretProvenanceInTx, @@ -39,6 +44,64 @@ import type { ResolvedSecretTraceRegistry } from '@/executor/utils/resolved-secr const CONTENT_UPDATED_AT = new Date('2026-08-04T00:00:00.000Z') +describe('execution file sidecars at model boundaries', () => { + beforeEach(() => { + vi.clearAllMocks() + resetDbChainMock() + }) + + it.each([ + { status: 'exact', version: 1, stale: false, entries: [], safe: true }, + { status: 'unknown', version: 1, stale: false, entries: [], safe: false }, + { status: 'exact', version: 1, stale: true, entries: [], safe: false }, + { status: null, version: 1, stale: false, entries: null, safe: false }, + { status: 'unknown', version: null, stale: true, entries: [], safe: true }, + { + status: 'exact', + version: 1, + stale: false, + entries: [{ name: 'KEY', encryptedValue: 'ciphertext', sourceUserId: 'writer' }], + safe: false, + }, + ])( + 'classifies execution bytes consistently: %j', + async ({ status, version, stale, entries, safe }) => { + const key = 'execution/workspace-1/workflow-1/execution-1/file.zip' + const row = { + key, + workspaceId: 'workspace-1', + context: 'execution', + fileContentUpdatedAt: CONTENT_UPDATED_AT, + secretProvenanceVersion: version, + provenanceContentUpdatedAt: stale ? new Date(0) : CONTENT_UPDATED_AT, + status, + entries, + } + for (const enforced of [false, true]) { + mockIsEnforced.mockReturnValue(enforced) + queueTableRows(workspaceFiles, [row]) + expect(await isModelSafeWorkspaceFileKey(key, { workspaceId: 'workspace-1' })).toBe(safe) + queueTableRows(workspaceFiles, [row]) + expect( + await filterModelSafeWorkspaceFileAttachments([{ id: 'invented-id', key }], { + workspaceId: 'workspace-1', + }) + ).toEqual(safe ? [{ id: 'invented-id', key }] : []) + queueTableRows(workspaceFiles, [row]) + const bound = await getBoundWorkspaceFileSecretProvenance('workspace-1', { + fileId: 'canonical-id', + key, + context: 'execution', + contentUpdatedAt: CONTENT_UPDATED_AT, + }) + expect(bound.status).toBe( + version === null || (status === 'exact' && !stale) ? 'exact' : 'unknown' + ) + } + } + ) +}) + describe('workspace file secret provenance', () => { beforeEach(() => { vi.clearAllMocks() @@ -256,7 +319,11 @@ describe('workspace file secret provenance', () => { left: 'workspaceFiles.contentUpdatedAt', right: new Date(CONTENT_UPDATED_AT.getTime() + 1), }, - { type: 'inArray', column: 'workspaceFiles.context', values: ['workspace', 'mothership'] }, + { + type: 'inArray', + column: 'workspaceFiles.context', + values: ['workspace', 'mothership', 'execution'], + }, { type: 'or', conditions: [ @@ -436,7 +503,6 @@ describe('workspace file secret provenance', () => { */ { id: 'unrecorded-id', key: 'unrecorded-key' }, { id: 'pre-marker-sidecar-id', key: 'pre-marker-sidecar-key' }, - { id: 'synthetic-execution-id', key: 'untracked-context-key' }, { id: 'legacy-id', key: 'legacy-key' }, { id: 'inline-file' }, ]) @@ -996,14 +1062,20 @@ describe('workspace file secret provenance', () => { it('merges exact byte contributors and propagates unknown classifications', () => { expect( mergeWorkspaceFileSecretProvenance( - { status: 'exact', entries: [{ name: 'A', encryptedValue: 'encrypted-a' }] }, - { status: 'exact', entries: [{ name: 'B', encryptedValue: 'encrypted-b' }] } + { + status: 'exact', + entries: [{ name: 'A', encryptedValue: 'encrypted-a', sourceUserId: 'user-1' }], + }, + { + status: 'exact', + entries: [{ name: 'B', encryptedValue: 'encrypted-b', sourceUserId: 'user-1' }], + } ) ).toEqual({ status: 'exact', entries: [ - { name: 'A', encryptedValue: 'encrypted-a' }, - { name: 'B', encryptedValue: 'encrypted-b' }, + { name: 'A', encryptedValue: 'encrypted-a', sourceUserId: 'user-1' }, + { name: 'B', encryptedValue: 'encrypted-b', sourceUserId: 'user-1' }, ], }) expect( @@ -1011,6 +1083,86 @@ describe('workspace file secret provenance', () => { ).toEqual({ status: 'unknown' }) }) + it('deduplicates only identical scoped entries across repeated contributors', () => { + const base = { + sourceUserId: 'user-1', + sourceWorkspaceId: 'workspace-1', + name: 'TOKEN', + encryptedValue: 'ciphertext', + } + const entries = [ + base, + { ...base, sourceUserId: 'user-2' }, + { ...base, sourceWorkspaceId: 'workspace-2' }, + { ...base, name: 'OTHER_TOKEN' }, + { sourceUserId: base.sourceUserId, encryptedValue: base.encryptedValue }, + { ...base, encryptedValue: 'different-ciphertext' }, + ] + const contributors = Array.from({ length: 1_000 }, () => ({ + status: 'exact' as const, + entries, + })) + + expect(mergeWorkspaceFileSecretProvenance(...contributors)).toEqual({ + status: 'exact', + entries, + }) + }) + + it('counts distinct merged entries at the actual entry boundary and refuses overflow', () => { + const entries = Array.from({ length: PROVENANCE_MAX_ENTRIES }, (_, index) => ({ + sourceUserId: 'user-1', + encryptedValue: `ciphertext-${index}`, + })) + const full = { status: 'exact' as const, entries } + expect(mergeWorkspaceFileSecretProvenance(full, full)).toEqual(full) + expect( + mergeWorkspaceFileSecretProvenance(full, { + status: 'exact', + entries: [{ sourceUserId: 'user-1', encryptedValue: 'one-more-secret' }], + }) + ).toEqual({ status: 'unknown' }) + }) + + it('deduplicates before charging the actual byte boundary and refuses a larger union', () => { + const sourceUserId = 'user-1' + const name = 'TOKEN' + const overhead = Buffer.byteLength(sourceUserId + name, 'utf8') + const entry = { + sourceUserId, + name, + encryptedValue: 'x'.repeat(PROVENANCE_MAX_SERIALIZED_BYTES - overhead), + } + const full = { status: 'exact' as const, entries: [entry] } + expect(mergeWorkspaceFileSecretProvenance(full, full)).toEqual(full) + expect( + mergeWorkspaceFileSecretProvenance(full, { + status: 'exact', + entries: [{ sourceUserId, encryptedValue: 'one-more-secret' }], + }) + ).toEqual({ status: 'unknown' }) + expect( + mergeWorkspaceFileSecretProvenance({ + status: 'exact', + entries: [{ ...entry, encryptedValue: `${entry.encryptedValue}é` }], + }) + ).toEqual({ status: 'unknown' }) + }) + + it('stops reading entries once the merged envelope cannot be represented', () => { + const entries = [ + { sourceUserId: 'user-1', encryptedValue: 'x'.repeat(PROVENANCE_MAX_SERIALIZED_BYTES) }, + ] + Object.defineProperty(entries, 1, { + get: () => { + throw new Error('overflow must stop the merge') + }, + }) + expect(mergeWorkspaceFileSecretProvenance({ status: 'exact', entries })).toEqual({ + status: 'unknown', + }) + }) + it('does not discard known secret entries when another contributor is unrecorded', () => { const known = { status: 'exact' as const, diff --git a/apps/sim/lib/uploads/contexts/workspace/workspace-file-secret-provenance.ts b/apps/sim/lib/uploads/contexts/workspace/workspace-file-secret-provenance.ts index e89f258199e..88d1b89f889 100644 --- a/apps/sim/lib/uploads/contexts/workspace/workspace-file-secret-provenance.ts +++ b/apps/sim/lib/uploads/contexts/workspace/workspace-file-secret-provenance.ts @@ -5,7 +5,7 @@ import { workspaceFileSecretProvenance, workspaceFiles, } from '@sim/db/schema' -import { and, eq, gte, inArray, isNull, lt, or } from 'drizzle-orm' +import { and, desc, eq, gte, inArray, isNull, lt, or, sql } from 'drizzle-orm' import { encryptSecret } from '@/lib/core/security/encryption' import type { DbTransaction } from '@/lib/db/types' import { @@ -81,7 +81,7 @@ interface WorkspaceFileAttachmentIdentity { export interface WorkspaceFileSecretProvenanceIdentity { fileId: string key: string - context: 'workspace' | 'mothership' + context: 'workspace' | 'mothership' | 'execution' contentUpdatedAt?: Date } @@ -138,12 +138,35 @@ export function mergeWorkspaceFileSecretProvenance( : { status: 'unrecorded' } } - return { - status: 'exact', - entries: provenances.flatMap((provenance) => - provenance.status === 'exact' ? provenance.entries : [] - ), + const entries = new Map() + let bytes = 0 + for (const provenance of provenances) { + if (provenance.status !== 'exact') continue + for (const entry of provenance.entries) { + if ( + !entry.encryptedValue || + !entry.sourceUserId || + (entry.name !== undefined && entry.name.length === 0) + ) { + return { status: 'unknown' } + } + const entryBytes = exactEntryByteSize(entry) + if (entryBytes > PROVENANCE_MAX_SERIALIZED_BYTES) return { status: 'unknown' } + const key = JSON.stringify([ + entry.sourceUserId, + entry.sourceWorkspaceId ?? '', + entry.name ?? '', + entry.encryptedValue, + ]) + if (entries.has(key)) continue + bytes += entryBytes + if (entries.size >= PROVENANCE_MAX_ENTRIES || bytes > PROVENANCE_MAX_SERIALIZED_BYTES) { + return { status: 'unknown' } + } + entries.set(key, entry) + } } + return { status: 'exact', entries: [...entries.values()] } } function compareStrings(left: string, right: string): number { @@ -422,7 +445,7 @@ async function markWorkspaceFileSecretProvenanceTrackedInTx( eq(workspaceFiles.id, fileId), gte(workspaceFiles.contentUpdatedAt, contentUpdatedAt), lt(workspaceFiles.contentUpdatedAt, nextContentMillisecond), - inArray(workspaceFiles.context, ['workspace', 'mothership']), + inArray(workspaceFiles.context, ['workspace', 'mothership', 'execution']), or( isNull(workspaceFiles.secretProvenanceVersion), eq(workspaceFiles.secretProvenanceVersion, 1) @@ -859,7 +882,7 @@ export async function getBoundWorkspaceFileSecretProvenanceByMetadata( * absence this covers. Closing the surface again is a matter of naming it in * `DURABLE_SECRET_PROVENANCE_ENFORCED_SURFACES`. */ -function mayReadUnrecordedWorkspaceFile( +export function mayReadUnrecordedWorkspaceFile( workspaceId: string | undefined, count = 1, actorUserId?: string @@ -1017,7 +1040,8 @@ export async function importWorkspaceFileSecretProvenanceForRuntime(args: { /** * Removes model attachments whose canonical workspace-file record is tainted or unknown. * Missing legacy records remain compatible; persisted records are classified by their unique - * active storage-key binding and private provenance row. Attachment ids are deliberately ignored: + * storage-key binding (active first, newest archived execution revision otherwise) and private + * provenance row. Attachment ids are deliberately ignored: * older persisted workflows omit them and file normalization may synthesize a runtime-only id. * This classification is not file authorization; callers still enforce storage access before * reading bytes or issuing a provider URL. @@ -1051,7 +1075,13 @@ export async function filterModelSafeWorkspaceFileAttachments< if (typeof attachment.key !== 'string' || attachment.key.length === 0) return true const row = rowByKey.get(attachment.key) if (!row) return true - if (row.context !== 'workspace' && row.context !== 'mothership') return true + if ( + row.context !== 'workspace' && + row.context !== 'mothership' && + row.context !== 'execution' + ) { + return true + } const classification = classifyModelSafeWorkspaceFileRow(row, options.workspaceId) if (classification === 'safe') return true if (classification === 'unsafe') { @@ -1098,7 +1128,7 @@ async function loadModelSafeWorkspaceFileRows( keys: readonly string[] ): Promise { return db - .select({ + .selectDistinctOn([workspaceFiles.key], { key: workspaceFiles.key, workspaceId: workspaceFiles.workspaceId, context: workspaceFiles.context, @@ -1113,7 +1143,18 @@ async function loadModelSafeWorkspaceFileRows( workspaceFileSecretProvenance, eq(workspaceFileSecretProvenance.fileId, workspaceFiles.id) ) - .where(and(inArray(workspaceFiles.key, [...keys]), isNull(workspaceFiles.deletedAt))) + .where( + and( + inArray(workspaceFiles.key, [...keys]), + or(isNull(workspaceFiles.deletedAt), eq(workspaceFiles.context, 'execution')) + ) + ) + .orderBy( + workspaceFiles.key, + sql`${workspaceFiles.deletedAt} IS NULL DESC`, + desc(workspaceFiles.contentUpdatedAt), + workspaceFiles.id + ) } /** @@ -1131,8 +1172,8 @@ export async function isModelSafeWorkspaceFileKey( /** * Batch variant for server-authorized storage keys crossing the same model boundary. Missing keys - * and non-workspace contexts retain their legacy/raw behavior; canonical workspace and mothership - * rows are accepted only when every current content version has exact-empty provenance. + * retain their legacy behavior; tracked workspace, mothership, and execution files must satisfy + * the same classification before their bytes leave private storage. */ export async function areModelSafeWorkspaceFileKeys( keys: readonly string[], @@ -1148,7 +1189,13 @@ export async function areModelSafeWorkspaceFileKeys( let unrecorded = 0 for (const row of rows) { - if (row.context !== 'workspace' && row.context !== 'mothership') continue + if ( + row.context !== 'workspace' && + row.context !== 'mothership' && + row.context !== 'execution' + ) { + continue + } const classification = classifyModelSafeWorkspaceFileRow(row, options.workspaceId) if (classification === 'unsafe') { return refuseWorkspaceFileProvenance( diff --git a/apps/sim/lib/uploads/server/metadata.ts b/apps/sim/lib/uploads/server/metadata.ts index f0d9661fd6d..97ab3565e38 100644 --- a/apps/sim/lib/uploads/server/metadata.ts +++ b/apps/sim/lib/uploads/server/metadata.ts @@ -3,7 +3,7 @@ import { withInsertColumns } from '@sim/db/insert-columns' import { type WorkspaceFileRow, workspaceFileColumns, workspaceFiles } from '@sim/db/schema' import { createLogger } from '@sim/logger' import { generateId } from '@sim/utils/id' -import { and, eq, inArray, isNotNull, isNull, sql } from 'drizzle-orm' +import { and, desc, eq, inArray, isNotNull, isNull, sql } from 'drizzle-orm' import type { DbOrTx, DbTransaction } from '@/lib/db/types' import { getWorkspaceFileSize, @@ -424,18 +424,31 @@ export async function resolveStoredFileContext(key: string): Promise = db, - options?: { lock?: 'share' } + executor: Pick = db, + options?: { lock?: 'share'; includeDeleted?: false } | { lock?: never; includeDeleted: true } ): Promise { if (keys.length === 0) { return [] } + if (options?.includeDeleted) { + return executor + .selectDistinctOn([workspaceFiles.key], workspaceFileColumns) + .from(workspaceFiles) + .where(and(inArray(workspaceFiles.key, keys), eq(workspaceFiles.context, context))) + .orderBy( + workspaceFiles.key, + sql`${workspaceFiles.deletedAt} IS NULL DESC`, + desc(workspaceFiles.contentUpdatedAt), + workspaceFiles.id + ) + } const query = executor .select(workspaceFileColumns) .from(workspaceFiles) diff --git a/apps/sim/lib/uploads/utils/file-utils.server.test.ts b/apps/sim/lib/uploads/utils/file-utils.server.test.ts index 91670aeeb25..f3463527fa8 100644 --- a/apps/sim/lib/uploads/utils/file-utils.server.test.ts +++ b/apps/sim/lib/uploads/utils/file-utils.server.test.ts @@ -3,13 +3,13 @@ */ import { beforeEach, describe, expect, it, vi } from 'vitest' -const { mockDownloadFile, mockParseWorkspaceFileKey, mockResolveServableDocBytes } = vi.hoisted( - () => ({ +const { mockDownloadFile, mockParseWorkspaceFileKey, mockResolveServableDocBytes, mockRenderPage } = + vi.hoisted(() => ({ mockDownloadFile: vi.fn(), mockParseWorkspaceFileKey: vi.fn(), mockResolveServableDocBytes: vi.fn(), - }) -) + mockRenderPage: vi.fn(), + })) vi.mock('@/lib/uploads/core/storage-service', () => ({ downloadFile: mockDownloadFile, @@ -28,6 +28,10 @@ vi.mock('@/lib/copilot/tools/server/files/doc-compile', () => ({ resolveServableDocBytes: mockResolveServableDocBytes, })) +vi.mock('@/lib/workspace-files/page-document.server', () => ({ + renderSimPageDocumentWithContributors: mockRenderPage, +})) + vi.mock('@/app/api/files/authorization', () => ({ verifyFileAccess: vi.fn(), })) @@ -220,3 +224,43 @@ describe('downloadServableFilesWithinBudget', () => { expect(mockDownloadFile).toHaveBeenCalledTimes(1) }) }) + +describe('servable page provenance', () => { + it('preserves the inlined image identity for execution-stored pages', async () => { + const workspaceId = '2f1d8c3e-5b6a-4c7d-8e9f-0a1b2c3d4e5f' + const contributor = { + fileId: 'image-file', + key: `workspace/${workspaceId}/image.png`, + context: 'workspace' as const, + contentUpdatedAt: new Date('2026-01-01T00:00:00Z'), + } + mockParseWorkspaceFileKey.mockReturnValue(null) + mockDownloadFile.mockResolvedValue(Buffer.from('---\ntitle: Example\n---\nPage body')) + mockRenderPage.mockResolvedValue({ + html: 'rendered image', + contributingFiles: [contributor], + }) + + const rendered = await downloadServableFileFromStorage( + { + id: 'page-file', + name: 'page.html', + key: `execution/${workspaceId}/3f2e9d4c-6a7b-4d8e-9f0a-1b2c3d4e5f6a/4a3b2c1d-7e8f-4a9b-8c0d-1e2f3a4b5c6d/page.html`, + url: '', + type: 'text/x-sim-page', + size: 100, + context: 'execution', + }, + 'request', + createLogger('test'), + { maxBytes: 1024 } + ) + + expect(mockRenderPage).toHaveBeenCalledWith(expect.any(String), { workspaceId }) + expect(rendered).toEqual({ + buffer: Buffer.from('rendered image'), + contentType: 'text/html', + contributingFiles: [contributor], + }) + }) +}) diff --git a/apps/sim/lib/uploads/utils/file-utils.server.ts b/apps/sim/lib/uploads/utils/file-utils.server.ts index b78bff2b00b..625dcddc262 100644 --- a/apps/sim/lib/uploads/utils/file-utils.server.ts +++ b/apps/sim/lib/uploads/utils/file-utils.server.ts @@ -36,7 +36,7 @@ import { resolveTrustedFileContext, } from '@/lib/uploads/utils/file-utils' import { isSimPageSource, SIM_PAGE_CONTENT_TYPE } from '@/lib/workspace-files/page-compile' -import { renderSimPageDocumentWithAssets } from '@/lib/workspace-files/page-document.server' +import { renderSimPageDocumentWithContributors } from '@/lib/workspace-files/page-document.server' import { type KnowledgeFileAccess, verifyFileAccess } from '@/app/api/files/authorization' import type { UserFile } from '@/executor/types' @@ -461,16 +461,20 @@ export async function downloadServableFileFromStorage( const text = buffer.toString('utf8') if (isSimPageSource(text)) { const workspaceId = userFile.key - ? (parseWorkspaceFileKey(userFile.key) ?? undefined) + ? (parseWorkspaceFileKey(userFile.key) ?? + extractWorkspaceIdFromExecutionKey(userFile.key) ?? + undefined) : undefined - const rendered = Buffer.from( - await renderSimPageDocumentWithAssets(text, { workspaceId }), - 'utf8' - ) + const page = await renderSimPageDocumentWithContributors(text, { workspaceId }) + const rendered = Buffer.from(page.html, 'utf8') // Rendering inlines referenced assets, so a source well under the ceiling can // resolve to a document well over it. assertKnownSizeWithinLimit(rendered.length, options.maxBytes, 'servable page render') - return { buffer: rendered, contentType: 'text/html' } + return { + buffer: rendered, + contentType: 'text/html', + contributingFiles: page.contributingFiles, + } } } diff --git a/apps/sim/lib/workspace-files/page-document.server.test.ts b/apps/sim/lib/workspace-files/page-document.server.test.ts index 14375b70a16..5eba3bbd766 100644 --- a/apps/sim/lib/workspace-files/page-document.server.test.ts +++ b/apps/sim/lib/workspace-files/page-document.server.test.ts @@ -21,7 +21,10 @@ vi.mock('@/lib/workspace-files/page-document', () => ({ renderSimPageDocument: mockRenderSimPageDocument, })) -import { renderSimPageDocumentWithAssets } from '@/lib/workspace-files/page-document.server' +import { + renderSimPageDocumentWithAssets, + renderSimPageDocumentWithContributors, +} from '@/lib/workspace-files/page-document.server' const WORKSPACE_ID = 'ws-1' const MB = 1024 * 1024 @@ -35,6 +38,7 @@ function imageRecord(id: string, size: number) { contentType: 'image/png', size, sizeBytes: size, + contentUpdatedAt: new Date('2026-01-01T00:00:00Z'), } } @@ -119,3 +123,73 @@ describe('renderSimPageDocumentWithAssets memory bounds', () => { expect(html).toContain('src="/api/files/view/theirs"') }) }) + +describe('rendered page contributors', () => { + beforeEach(() => { + vi.clearAllMocks() + }) + + it('reports only the canonical revisions whose bytes were embedded', async () => { + mockRenderSimPageDocument.mockReturnValue( + documentReferencing(['mine', 'failed', 'foreign', 'missing', 'mine']) + ) + const record = imageRecord('mine', 5) + mockGetFileMetadataById.mockImplementation(async (id: string) => { + if (id === 'missing') return null + if (id === 'foreign') return { ...imageRecord(id, 5), workspaceId: 'other-workspace' } + return id === 'mine' ? record : imageRecord(id, 5) + }) + mockDownloadFile.mockImplementation(async ({ key }: { key: string }) => { + if (key.includes('failed')) throw new Error('unavailable') + return Buffer.from('image') + }) + + const rendered = await renderSimPageDocumentWithContributors('source', { + workspaceId: WORKSPACE_ID, + }) + + expect(rendered.contributingFiles).toEqual([ + { + fileId: record.id, + key: record.key, + context: 'workspace', + contentUpdatedAt: record.contentUpdatedAt, + }, + ]) + expect(rendered.html).toContain('data:image/png;base64,aW1hZ2U=') + expect(rendered.html).toContain('/api/files/view/failed') + expect(rendered.html).toContain('/api/files/view/foreign') + expect(mockGetFileMetadataById).toHaveBeenCalledTimes(4) + }) + + it('bounds metadata reads for missing images', async () => { + mockRenderSimPageDocument.mockReturnValue( + documentReferencing(Array.from({ length: 300 }, (_, i) => `missing-${i}`)) + ) + mockGetFileMetadataById.mockResolvedValue(null) + + const rendered = await renderSimPageDocumentWithContributors('source', { + workspaceId: WORKSPACE_ID, + }) + + expect(mockGetFileMetadataById).toHaveBeenCalledTimes(256) + expect(mockDownloadFile).not.toHaveBeenCalled() + expect(rendered.contributingFiles).toEqual([]) + }) + + it('charges repeated image occurrences against the rendered byte budget', async () => { + const source = documentReferencing(Array(12).fill('image')) + mockRenderSimPageDocument.mockReturnValue(source) + mockGetFileMetadataById.mockResolvedValue(imageRecord('image', 8 * MB)) + mockDownloadFile.mockResolvedValue(Buffer.alloc(8 * MB)) + + const rendered = await renderSimPageDocumentWithContributors('source', { + workspaceId: WORKSPACE_ID, + }) + + expect(mockDownloadFile).toHaveBeenCalledTimes(1) + expect(rendered.html.length).toBeLessThanOrEqual(source.length + Math.ceil((32 * MB * 4) / 3)) + expect(rendered.html).toContain('/api/files/view/image') + expect(rendered.contributingFiles).toHaveLength(1) + }) +}) diff --git a/apps/sim/lib/workspace-files/page-document.server.ts b/apps/sim/lib/workspace-files/page-document.server.ts index 4c4954e33dc..7abcdfa74d4 100644 --- a/apps/sim/lib/workspace-files/page-document.server.ts +++ b/apps/sim/lib/workspace-files/page-document.server.ts @@ -1,3 +1,4 @@ +import type { WorkspaceFileSecretProvenanceIdentity } from '@/lib/uploads/contexts/workspace/workspace-file-secret-provenance' import { downloadFile } from '@/lib/uploads/core/storage-service' import { getFileMetadataById } from '@/lib/uploads/server/metadata' import { renderSimPageDocument } from '@/lib/workspace-files/page-document' @@ -12,6 +13,9 @@ const MAX_INLINE_IMAGE_BYTES = 8 * 1024 * 1024 */ const MAX_INLINE_TOTAL_BYTES = 32 * 1024 * 1024 +/** Bounds metadata reads even when the page references many missing or empty images. */ +const MAX_INLINE_IMAGE_REFERENCES = 256 + const IMAGE_SRC = /src="[^"]*\/api\/files\/view\/([^"]+)"/g /** @@ -27,30 +31,32 @@ export async function renderSimPageDocumentWithAssets( source: string, options: { workspaceId?: string } ): Promise { - const documentHtml = renderSimPageDocument(source, options) - const ids = [...new Set([...documentHtml.matchAll(IMAGE_SRC)].map((match) => match[1]))] - if (ids.length === 0 || !options.workspaceId) return documentHtml + return (await renderSimPageDocumentWithContributors(source, options)).html +} - const candidates = await Promise.all( - ids.map(async (id) => { - const record = await getFileMetadataById(id).catch(() => null) - if (!record || record.context !== 'workspace' || record.workspaceId !== options.workspaceId) - return null - return { id, record } - }) - ) +/** Servable page bytes and the exact stored image revisions actually embedded in them. */ +export async function renderSimPageDocumentWithContributors( + source: string, + options: { workspaceId?: string } +): Promise<{ html: string; contributingFiles: readonly WorkspaceFileSecretProvenanceIdentity[] }> { + const documentHtml = renderSimPageDocument(source, options) + if (!options.workspaceId) return { html: documentHtml, contributingFiles: [] } - // One image at a time, charged against the budget by what each download actually - // delivered. Fetching them concurrently made the peak the sum of every image rather - // than the largest one, and the ceiling on the finished document could only observe - // that after the fact. Each download is given whatever the budget has left, so an - // image that does not fit is refused by the read itself instead of after it lands. - const inlined = new Map() + const visited = new Set() + const inlined = new Map< + string, + { dataUri: string; identity: WorkspaceFileSecretProvenanceIdentity } + >() let remaining = MAX_INLINE_TOTAL_BYTES - for (const candidate of candidates) { - if (!candidate) continue - if (remaining === 0) break - const { id, record } = candidate + for (const match of documentHtml.matchAll(IMAGE_SRC)) { + const id = match[1] + if (visited.has(id)) continue + if (remaining === 0 || visited.size >= MAX_INLINE_IMAGE_REFERENCES) break + visited.add(id) + const record = await getFileMetadataById(id).catch(() => null) + if (!record || record.context !== 'workspace' || record.workspaceId !== options.workspaceId) { + continue + } try { const bytes = await downloadFile({ key: record.key, @@ -61,14 +67,28 @@ export async function renderSimPageDocumentWithAssets( const mime = record.contentType?.startsWith('image/') ? record.contentType : 'application/octet-stream' - inlined.set(id, `data:${mime};base64,${bytes.toString('base64')}`) + inlined.set(id, { + dataUri: `data:${mime};base64,${bytes.toString('base64')}`, + identity: { + fileId: record.id, + key: record.key, + context: 'workspace', + contentUpdatedAt: record.contentUpdatedAt, + }, + }) } catch { - // A missing, unreadable or too-large image keeps its URL reference. + /** A missing, unreadable or too-large image keeps its URL reference. */ } } - if (inlined.size === 0) return documentHtml - return documentHtml.replace(IMAGE_SRC, (match, id: string) => { - const dataUri = inlined.get(id) - return dataUri ? `src="${dataUri}"` : match + /** Charge each occurrence: repeating one image must not multiply the rendered byte budget. */ + let remainingEncodedBytes = Math.ceil((MAX_INLINE_TOTAL_BYTES * 4) / 3) + const contributors = new Map() + const html = documentHtml.replace(IMAGE_SRC, (match, id: string) => { + const image = inlined.get(id) + if (!image || image.dataUri.length > remainingEncodedBytes) return match + remainingEncodedBytes -= image.dataUri.length + contributors.set(id, image.identity) + return `src="${image.dataUri}"` }) + return { html, contributingFiles: [...contributors.values()] } } diff --git a/apps/sim/tools/file/parser.test.ts b/apps/sim/tools/file/parser.test.ts index 8a0e3e1ac91..18f794e0228 100644 --- a/apps/sim/tools/file/parser.test.ts +++ b/apps/sim/tools/file/parser.test.ts @@ -2,9 +2,20 @@ * @vitest-environment node */ import { describe, expect, it } from 'vitest' -import { fileFetchTool, fileParserTool, fileParserV3Tool } from '@/tools/file/parser' +import { + fileFetchTool, + fileParserTool, + fileParserV2Tool, + fileParserV3Tool, +} from '@/tools/file/parser' describe('fileParserTool', () => { + it.each([fileFetchTool, fileParserTool, fileParserV2Tool, fileParserV3Tool])( + '$id negotiates stored source provenance before exposing parsed content', + (tool) => { + expect(tool.operation.secretProvenance?.response).toEqual({ incomplete: 'reject' }) + } + ) it('maps the public File Fetch URL to the internal parser path', () => { expect( fileFetchTool.operation.input({ diff --git a/apps/sim/tools/file/parser.ts b/apps/sim/tools/file/parser.ts index fb4d8cf869f..a17a1c9a03c 100644 --- a/apps/sim/tools/file/parser.ts +++ b/apps/sim/tools/file/parser.ts @@ -197,6 +197,7 @@ export const fileParserTool: InternalToolConfig { logger.info('Request parameters received by tool body:', params) @@ -384,6 +385,7 @@ export const fileFetchTool: InternalToolConfig fileParserTool.operation.input({ ...params, diff --git a/apps/sim/tools/index.test.ts b/apps/sim/tools/index.test.ts index 1cb84748caa..7a84d491bef 100644 --- a/apps/sim/tools/index.test.ts +++ b/apps/sim/tools/index.test.ts @@ -1562,6 +1562,66 @@ describe('executeTool Function', () => { ]) }) + it.each([true, false])( + 'carries File Fetch lineage into later durable values when complete=%s', + async (complete) => { + const scope = { userId: 'user-1', workspaceId: 'workspace-1' } + const registry = new ResolvedSecretTraceRegistry([], scope) + const entry = { name: 'API_KEY', encryptedValue: 'encrypted-value' } + encryptionMockFns.mockDecryptSecret.mockResolvedValue({ decrypted: 'secret-value' }) + mockExecuteInternalToolOperation.mockResolvedValueOnce( + Response.json( + { + success: true, + output: { + content: 'secret-value', + name: 'report.txt', + fileType: 'text/plain', + size: 12, + binary: false, + }, + __resolvedSecretTraceProvenance: { + version: 1, + complete, + entries: complete ? [entry] : [], + scope, + }, + }, + { headers: { 'x-sim-private-tool-metadata': 'resolved-secret-provenance-v1' } } + ) + ) + + const result = await executeTool( + 'file_fetch', + { fileUrl: '/api/files/serve/execution/workspace-1/workflow-1/execution-1/report.txt' }, + { + executionContext: createToolExecutionContext(scope), + resolvedSecretTraceRegistry: registry, + } + ) + + expect(result).toMatchObject({ + success: true, + output: { combinedContent: 'secret-value' }, + }) + expect(JSON.stringify(result)).not.toContain('__resolvedSecretTraceProvenance') + expect( + mockExecuteInternalToolOperation.mock.calls[0]?.[0].headers.get( + 'x-sim-request-private-tool-metadata' + ) + ).toBe('resolved-secret-provenance-v1') + for (const durableValue of [ + { 'column-id': 'secret-value' }, + { role: 'assistant', content: 'secret-value' }, + ]) { + expect(registry.exportCommittedProvenanceForValue(durableValue)).toMatchObject({ + complete, + entries: complete ? [entry] : [], + }) + } + } + ) + it.each([ { name: 'table propagate policy', From 2217f716f1753dddafc04d68c897922dfe794b5f Mon Sep 17 00:00:00 2001 From: Vikhyath Mondreti Date: Fri, 11 Sep 2026 12:54:41 -0700 Subject: [PATCH 10/15] fix(tools): persist large file outputs before response limits (#7781) * fix(tools): persist large file outputs before response limits * fix(tools): cover late attachments and simplify file outputs --- .agents/skills/add-block/SKILL.md | 6 + .agents/skills/add-tools/SKILL.md | 32 ++ .agents/skills/validate-integration/SKILL.md | 15 + apps/docs/components/ui/icon-mapping.ts | 9 + apps/docs/content/docs/integrations/box.mdx | 3 +- .../content/docs/integrations/dropbox.mdx | 5 +- apps/docs/content/docs/integrations/dub.mdx | 3 +- .../content/docs/integrations/jupyter.mdx | 14 +- .../docs/integrations/microsoft_dataverse.mdx | 9 +- .../docs/content/docs/integrations/quiver.mdx | 33 +- .../content/docs/integrations/servicenow.mdx | 43 +- apps/docs/content/docs/integrations/sftp.mdx | 9 +- apps/docs/content/docs/integrations/ssh.mdx | 7 +- .../blocks/binary-download-versioning.test.ts | 100 ++++ apps/sim/blocks/blocks/box.ts | 29 +- apps/sim/blocks/blocks/dropbox.ts | 29 +- apps/sim/blocks/blocks/dub.ts | 29 +- apps/sim/blocks/blocks/jupyter.test.ts | 35 ++ apps/sim/blocks/blocks/jupyter.ts | 35 +- apps/sim/blocks/blocks/microsoft_dataverse.ts | 44 +- apps/sim/blocks/blocks/quiver.test.ts | 34 ++ apps/sim/blocks/blocks/quiver.ts | 43 +- apps/sim/blocks/blocks/servicenow.ts | 33 +- apps/sim/blocks/blocks/sftp.test.ts | 59 ++ apps/sim/blocks/blocks/sftp.ts | 55 +- apps/sim/blocks/blocks/ssh.test.ts | 39 ++ apps/sim/blocks/blocks/ssh.ts | 50 +- apps/sim/blocks/registry-maps.ts | 29 +- .../utils/file-tool-processor.aliases.test.ts | 107 ++++ .../utils/file-tool-processor.context.test.ts | 167 ++++++ .../utils/file-tool-processor.test.ts | 22 + .../sim/executor/utils/file-tool-processor.ts | 378 ++++++------- apps/sim/lib/integrations/icon-mapping.ts | 17 +- .../lib/internal/agiloft/execute-tool.test.ts | 27 +- apps/sim/lib/internal/agiloft/execute-tool.ts | 10 +- .../lib/internal/agiloft/operations.test.ts | 26 +- apps/sim/lib/internal/agiloft/operations.ts | 21 +- .../lib/internal/cursor/execute-tool.test.ts | 30 +- apps/sim/lib/internal/cursor/execute-tool.ts | 25 +- .../lib/internal/cursor/operations.test.ts | 47 +- apps/sim/lib/internal/cursor/operations.ts | 56 +- apps/sim/lib/internal/discord/execute-tool.ts | 12 +- .../lib/internal/discord/operations.test.ts | 45 +- apps/sim/lib/internal/discord/operations.ts | 10 +- .../google-drive/execute-tool.test.ts | 20 +- .../lib/internal/google-drive/execute-tool.ts | 10 +- .../internal/google-drive/operations.test.ts | 26 +- .../lib/internal/google-drive/operations.ts | 37 +- .../google-vault/execute-tool.test.ts | 33 +- .../lib/internal/google-vault/execute-tool.ts | 15 +- .../internal/google-vault/operations.test.ts | 22 +- .../lib/internal/google-vault/operations.ts | 9 +- apps/sim/lib/internal/jupyter/client.test.ts | 53 +- apps/sim/lib/internal/jupyter/client.ts | 30 +- .../lib/internal/jupyter/execute-tool.test.ts | 58 +- apps/sim/lib/internal/jupyter/execute-tool.ts | 44 +- .../lib/internal/jupyter/get-content.test.ts | 179 ++++++ .../lib/internal/jupyter/operations.test.ts | 1 + apps/sim/lib/internal/jupyter/operations.ts | 118 +++- .../microsoft-teams/execute-tool.test.ts | 28 +- .../internal/microsoft-teams/execute-tool.ts | 16 +- .../microsoft-teams/operations.test.ts | 48 ++ .../internal/microsoft-teams/operations.ts | 39 +- .../microsoft-word/execute-tool.test.ts | 27 +- .../internal/microsoft-word/execute-tool.ts | 14 +- .../microsoft-word/operations.test.ts | 36 +- .../lib/internal/microsoft-word/operations.ts | 16 +- .../internal/onedrive/execute-tool.test.ts | 11 +- .../sim/lib/internal/onedrive/execute-tool.ts | 17 +- .../lib/internal/onedrive/operations.test.ts | 41 +- apps/sim/lib/internal/onedrive/operations.ts | 25 +- .../lib/internal/onepassword/execute-tool.ts | 10 +- .../internal/onepassword/operations.test.ts | 62 ++- .../lib/internal/onepassword/operations.ts | 30 +- apps/sim/lib/internal/outlook/client.test.ts | 90 ++- apps/sim/lib/internal/outlook/client.ts | 42 +- .../lib/internal/outlook/execute-tool.test.ts | 65 ++- apps/sim/lib/internal/outlook/execute-tool.ts | 34 +- .../internal/outlook/get-attachment-input.ts | 10 + .../lib/internal/outlook/operations.test.ts | 191 +++++++ apps/sim/lib/internal/outlook/operations.ts | 63 ++- .../lib/internal/pipedrive/execute-tool.ts | 12 +- .../lib/internal/pipedrive/operations.test.ts | 84 +++ apps/sim/lib/internal/pipedrive/operations.ts | 33 +- .../lib/internal/quiver/execute-tool.test.ts | 45 +- apps/sim/lib/internal/quiver/execute-tool.ts | 18 +- .../lib/internal/quiver/operations.test.ts | 103 +++- apps/sim/lib/internal/quiver/operations.ts | 100 ++-- .../lib/internal/sftp/execute-tool.test.ts | 34 +- apps/sim/lib/internal/sftp/execute-tool.ts | 17 +- apps/sim/lib/internal/sftp/operations.test.ts | 74 +++ apps/sim/lib/internal/sftp/operations.ts | 47 +- apps/sim/lib/internal/sftp/schema.ts | 8 + .../internal/sharepoint/execute-tool.test.ts | 28 +- .../lib/internal/sharepoint/execute-tool.ts | 12 +- .../internal/sharepoint/operations.test.ts | 33 +- .../sim/lib/internal/sharepoint/operations.ts | 19 +- apps/sim/lib/internal/slack/execute-tool.ts | 10 +- .../sim/lib/internal/slack/operations.test.ts | 44 +- apps/sim/lib/internal/slack/operations.ts | 38 +- .../sim/lib/internal/ssh/execute-tool.test.ts | 29 +- apps/sim/lib/internal/ssh/execute-tool.ts | 17 +- apps/sim/lib/internal/ssh/operations.test.ts | 76 ++- apps/sim/lib/internal/ssh/operations.ts | 41 +- .../internal/telegram/execute-tool.test.ts | 11 +- .../sim/lib/internal/telegram/execute-tool.ts | 21 +- .../lib/internal/telegram/operations.test.ts | 32 +- apps/sim/lib/internal/telegram/operations.ts | 19 +- .../file-result.server.test.ts | 527 ++++++++++++++++++ .../tool-operations/file-result.server.ts | 185 ++++++ .../internal/tool-operations/file-result.ts | 45 ++ .../tool-operations/registry.server.ts | 22 +- .../tool-operations/response-limits.ts | 2 + .../sim/lib/internal/tool-operations/types.ts | 7 +- .../lib/internal/twilio-voice/execute-tool.ts | 21 +- .../internal/twilio-voice/operations.test.ts | 32 +- .../lib/internal/twilio-voice/operations.ts | 52 +- apps/sim/lib/internal/vanta/execute-tool.ts | 12 +- .../sim/lib/internal/vanta/operations.test.ts | 35 +- apps/sim/lib/internal/vanta/operations.ts | 17 +- .../internal/zoho-desk/execute-tool.test.ts | 34 +- .../lib/internal/zoho-desk/execute-tool.ts | 23 +- .../lib/internal/zoho-desk/operations.test.ts | 146 +++++ apps/sim/lib/internal/zoho-desk/operations.ts | 45 +- apps/sim/lib/internal/zoom/execute-tool.ts | 21 +- apps/sim/lib/internal/zoom/operations.test.ts | 44 +- apps/sim/lib/internal/zoom/operations.ts | 78 ++- .../block-successors.generated.ts | 9 + .../copilot/copilot-file-manager.test.ts | 56 ++ .../contexts/copilot/copilot-file-manager.ts | 8 +- .../execution/execution-file-manager.test.ts | 34 ++ .../execution/execution-file-manager.ts | 8 +- .../core/storage-service.local.test.ts | 38 +- .../lib/uploads/core/storage-service.test.ts | 100 ++++ apps/sim/lib/uploads/core/storage-service.ts | 34 +- apps/sim/lib/uploads/shared/types.ts | 2 + .../utils/attachment-download-budget.test.ts | 61 ++ .../utils/attachment-download-budget.ts | 70 +++ .../lib/uploads/utils/stored-file-metadata.ts | 33 ++ .../tools/agiloft/retrieve_attachment.test.ts | 23 + apps/sim/tools/agiloft/retrieve_attachment.ts | 7 +- apps/sim/tools/agiloft/types.ts | 10 +- apps/sim/tools/binary-downloads.test.ts | 235 ++++++++ apps/sim/tools/box/download_file.ts | 100 ++-- apps/sim/tools/box/index.ts | 2 +- apps/sim/tools/box/types.ts | 7 + .../tools/cursor/download_artifact.test.ts | 33 ++ apps/sim/tools/cursor/types.ts | 8 +- apps/sim/tools/daytona/download_file.ts | 3 +- apps/sim/tools/dropbox/download.ts | 132 +++-- apps/sim/tools/dropbox/index.ts | 3 +- apps/sim/tools/dropbox/types.ts | 7 + apps/sim/tools/dub/get_qr_code.ts | 86 ++- apps/sim/tools/dub/index.ts | 3 +- apps/sim/tools/dub/types.ts | 7 + .../file-message-operation-security.test.ts | 24 +- apps/sim/tools/generated/tool-ids.ts | 2 +- apps/sim/tools/generated/tool-metadata.ts | 2 +- apps/sim/tools/generated/tool-outputs.ts | 2 +- apps/sim/tools/gmail/read.test.ts | 112 ++++ apps/sim/tools/gmail/read.ts | 81 ++- apps/sim/tools/gmail/types.ts | 2 +- apps/sim/tools/gmail/utils.ts | 73 ++- apps/sim/tools/google_drive/export.ts | 8 +- apps/sim/tools/google_drive/types.ts | 7 +- apps/sim/tools/index.test.ts | 309 ++++++++++ apps/sim/tools/index.ts | 107 +++- .../tools/jira/attachment-downloads.test.ts | 99 ++++ apps/sim/tools/jira/get_attachments.ts | 44 +- apps/sim/tools/jira/retrieve.ts | 74 ++- apps/sim/tools/jira/types.ts | 4 +- apps/sim/tools/jira/utils.ts | 24 +- .../tools/jupyter/content-transforms.test.ts | 47 +- apps/sim/tools/jupyter/get_content.ts | 42 +- apps/sim/tools/jupyter/index.ts | 2 +- apps/sim/tools/jupyter/types.ts | 13 + .../microsoft_dataverse/download_file.ts | 117 ++-- apps/sim/tools/microsoft_dataverse/index.ts | 5 +- apps/sim/tools/microsoft_dataverse/types.ts | 8 + .../attachment-downloads.test.ts | 119 ++++ .../sim/tools/microsoft_teams/read_channel.ts | 142 ++--- apps/sim/tools/microsoft_teams/read_chat.ts | 89 +-- apps/sim/tools/microsoft_teams/types.ts | 16 +- apps/sim/tools/microsoft_teams/utils.ts | 241 ++++---- .../tools/onepassword/get_item_file.test.ts | 26 + apps/sim/tools/onepassword/get_item_file.ts | 7 +- apps/sim/tools/outlook/get_attachment.test.ts | 30 + apps/sim/tools/outlook/get_attachment.ts | 82 +-- apps/sim/tools/outlook/read.test.ts | 103 ++++ apps/sim/tools/outlook/read.ts | 192 ++++--- apps/sim/tools/outlook/types.ts | 4 +- apps/sim/tools/persona/print_inquiry_pdf.ts | 3 +- apps/sim/tools/persona/types.ts | 2 +- apps/sim/tools/quiver/image_to_svg.ts | 24 +- apps/sim/tools/quiver/index.ts | 4 +- apps/sim/tools/quiver/operation.test.ts | 39 +- apps/sim/tools/quiver/outputs.ts | 16 + apps/sim/tools/quiver/text_to_svg.ts | 26 +- apps/sim/tools/quiver/types.ts | 7 + apps/sim/tools/registry.ts | 26 +- apps/sim/tools/s3/get_object.ts | 3 +- .../tools/servicenow/download_attachment.ts | 98 ++-- apps/sim/tools/servicenow/index.ts | 6 +- apps/sim/tools/servicenow/types.ts | 7 + apps/sim/tools/sftp/download.test.ts | 67 +++ apps/sim/tools/sftp/download.ts | 52 +- apps/sim/tools/sftp/index.ts | 2 +- apps/sim/tools/sftp/types.ts | 8 + apps/sim/tools/ssh/download_file.test.ts | 47 ++ apps/sim/tools/ssh/download_file.ts | 36 +- apps/sim/tools/ssh/index.ts | 3 +- apps/sim/tools/ssh/types.ts | 8 + apps/sim/tools/supabase/storage_download.ts | 5 +- apps/sim/tools/types.ts | 8 +- apps/sim/tools/vanta/types.ts | 10 +- .../deployment-config/src/integrations.json | 20 +- scripts/generate-docs.test.ts | 149 +++++ scripts/generate-docs.ts | 213 +++++-- 218 files changed, 8225 insertions(+), 1796 deletions(-) create mode 100644 apps/sim/blocks/blocks/binary-download-versioning.test.ts create mode 100644 apps/sim/blocks/blocks/jupyter.test.ts create mode 100644 apps/sim/blocks/blocks/quiver.test.ts create mode 100644 apps/sim/blocks/blocks/sftp.test.ts create mode 100644 apps/sim/blocks/blocks/ssh.test.ts create mode 100644 apps/sim/executor/utils/file-tool-processor.aliases.test.ts create mode 100644 apps/sim/executor/utils/file-tool-processor.context.test.ts create mode 100644 apps/sim/lib/internal/jupyter/get-content.test.ts create mode 100644 apps/sim/lib/internal/outlook/get-attachment-input.ts create mode 100644 apps/sim/lib/internal/pipedrive/operations.test.ts create mode 100644 apps/sim/lib/internal/tool-operations/file-result.server.test.ts create mode 100644 apps/sim/lib/internal/tool-operations/file-result.server.ts create mode 100644 apps/sim/lib/internal/tool-operations/file-result.ts create mode 100644 apps/sim/lib/internal/tool-operations/response-limits.ts create mode 100644 apps/sim/lib/internal/zoho-desk/operations.test.ts create mode 100644 apps/sim/lib/uploads/contexts/copilot/copilot-file-manager.test.ts create mode 100644 apps/sim/lib/uploads/utils/attachment-download-budget.test.ts create mode 100644 apps/sim/lib/uploads/utils/attachment-download-budget.ts create mode 100644 apps/sim/lib/uploads/utils/stored-file-metadata.ts create mode 100644 apps/sim/tools/agiloft/retrieve_attachment.test.ts create mode 100644 apps/sim/tools/binary-downloads.test.ts create mode 100644 apps/sim/tools/cursor/download_artifact.test.ts create mode 100644 apps/sim/tools/gmail/read.test.ts create mode 100644 apps/sim/tools/jira/attachment-downloads.test.ts create mode 100644 apps/sim/tools/microsoft_teams/attachment-downloads.test.ts create mode 100644 apps/sim/tools/onepassword/get_item_file.test.ts create mode 100644 apps/sim/tools/outlook/get_attachment.test.ts create mode 100644 apps/sim/tools/outlook/read.test.ts create mode 100644 apps/sim/tools/quiver/outputs.ts create mode 100644 apps/sim/tools/sftp/download.test.ts create mode 100644 apps/sim/tools/ssh/download_file.test.ts diff --git a/.agents/skills/add-block/SKILL.md b/.agents/skills/add-block/SKILL.md index 60778644da4..2361233e08a 100644 --- a/.agents/skills/add-block/SKILL.md +++ b/.agents/skills/add-block/SKILL.md @@ -927,6 +927,11 @@ bun run apps/sim/scripts/check-canvas-sentences.ts --block={service} ## Generated artifacts +When adding or changing `sunset.replacedBy`, run `bun run generate:block-successors` and commit +`apps/sim/lib/permission-groups/block-successors.generated.ts`. Authorization uses this generated +map to resolve legacy and current block IDs consistently without importing the executable registry. +Verify it with `bun run check:block-successors`. + Adding a block on its own needs no **tool metadata** regeneration — a block references existing tool IDs through `tools.access` and does not change any tool's shape. @@ -969,6 +974,7 @@ changes. - [ ] Tools.config.tool returns correct tool ID (snake_case) - [ ] Outputs match tool outputs - [ ] Block + meta registered in registry-maps.ts (`BLOCK_REGISTRY` / `BLOCK_META_REGISTRY`) +- [ ] If `sunset.replacedBy` changed: regenerated and committed the block successor map; `bun run check:block-successors` passes - [ ] If any tool was added, changed or removed alongside the block: ran `bun run tool-metadata:generate` and committed the artifacts - [ ] Ran `bun run scripts/generate-docs.ts`, reviewed the generated diff, and committed the integration catalog changes - [ ] `bun run integration-catalog:check` passes diff --git a/.agents/skills/add-tools/SKILL.md b/.agents/skills/add-tools/SKILL.md index e0f68e70c34..85d34b491cd 100644 --- a/.agents/skills/add-tools/SKILL.md +++ b/.agents/skills/add-tools/SKILL.md @@ -264,6 +264,38 @@ stale/missing sidecars, and scope isolation. ## Critical Rules for Outputs +### File Downloads and Generated Files + +Internal operations return `createInternalToolFileResult` / `createInternalToolFilesResult` from +`lib/internal/tool-operations/file-result.ts` with bounded Buffers and a callback that places the +stored descriptors in the response. Their handlers preserve this result through dispatch, using +`InternalToolOperationHandler`. Do not serialize file bytes as base64 +JSON: the executor's 10 MiB response cap runs before ordinary file postprocessing or large-value +externalization. The shared executor stores files using trusted run or Copilot ownership. + +External endpoints that return raw binary files explicitly declare `request.responseType: 'binary'` +and return `output.file` with `{ name, mimeType, data: buffer, size }` from `transformResponse`. +The executor applies the bounded file-transfer budget and persists the descriptor. This opt-in is +for raw binary responses, not provider JSON containing base64 or tools that fetch attachments later. +Keep provider-specific limits and bounded reads; a file declaration is not permission to enlarge +arbitrary JSON responses. + +Attachment readers that download files inside `transformResponse` need their own bounded reads: +the first response cap does not cover subsequent fetches. Accept `ToolResponseContext` as the third +transform argument, forward its `signal`, and share one `AttachmentDownloadBudget` across sequential +downloads. Prefer raw provider endpoints over base64 metadata. Return the same file object in the +declared `file` / `file[]` output and nested message associations; `FileToolProcessor` stores it once +and replaces every alias with the same `UserFile` in both workflow and Copilot execution. + +Preserve stored `UserFile` fields (`id`, `key`, `url`, `context`, `type`, `name`, `size`) in transforms; +rebuilding the old `{ name, mimeType, data, size }` shape discards the reference. File outputs do not +need duplicate inline text/base64 aliases; the file system handles content materialization. When +an existing tool explicitly exposes content aliases in its contract, preserve its legacy version and +use the existing block/tool version pattern for a file-only output. Test a file over 10 MiB through +executor admission, single persistence, trusted ownership, and the unchanged JSON cap. Avoid adding +top-level filename, size, MIME type, URL, or success fields that merely repeat the canonical file or +tool result; keep additional provider fields only when they convey distinct information. + ### Output Types - `'string'`, `'number'`, `'boolean'` - Primitives - `'json'` - Complex objects (use this, NOT 'object') diff --git a/.agents/skills/validate-integration/SKILL.md b/.agents/skills/validate-integration/SKILL.md index 308df1d6691..a32df2b8bb3 100644 --- a/.agents/skills/validate-integration/SKILL.md +++ b/.agents/skills/validate-integration/SKILL.md @@ -345,6 +345,21 @@ If any tool lists, searches, exports, imports, downloads, uploads, paginates, ba - [ ] List/search tools expose API limits and do not auto-fetch every page into memory - [ ] Transform logic does not build unbounded arrays, maps, sets, or `Promise.all` fan-outs - [ ] File and HTTP body reads use explicit byte caps or existing stream-limit helpers +- [ ] Internal file results reach `createInternalToolFileResult` / `createInternalToolFilesResult` + before JSON serialization; external raw downloads explicitly use `request.responseType: 'binary'` + and return a buffered `output.file`. Provider base64 JSON needs separate handling +- [ ] Transforms retain stored `UserFile` identity/access fields, and tests cover a >10 MiB file + crossing executor admission without another upload. New file outputs contain references only, + without inline content aliases; preserve legacy versions when removing existing inline fields +- [ ] Scan every file-producing path, including attachment fetches inside `transformResponse`, URL + descriptors, export operations, and old/new block versions; checking download-named tools alone + misses late reads that occur after the first response admission +- [ ] Late attachment reads share a per-call byte budget, bound actual streamed bytes independently + of provider size metadata, and forward `ToolResponseContext.signal` through every fetch/read +- [ ] Both workflow and Copilot tests produce compact `UserFile` outputs; nested message attachment + aliases reference the same stored files, with no duplicate upload or raw bytes left behind +- [ ] New output contracts omit redundant copies of file name, MIME type, size, URL, and success; + retained provider metadata has a distinct purpose, and types match the stored-file runtime shape - [ ] Large result payloads are summarized, paginated, referenced, or capped rather than raw-dumped - [ ] Pagination and download tests cover caps, early stop behavior, or partial-result preservation when relevant diff --git a/apps/docs/components/ui/icon-mapping.ts b/apps/docs/components/ui/icon-mapping.ts index 51431ca589b..6178ca24e12 100644 --- a/apps/docs/components/ui/icon-mapping.ts +++ b/apps/docs/components/ui/icon-mapping.ts @@ -339,6 +339,7 @@ export const blockTypeToIconMap: Record = { azure_devops: AzureIcon, bitbucket: BitbucketIcon, box: BoxCompanyIcon, + box_v2: BoxCompanyIcon, brandfetch: BrandfetchIcon, brex: BrexIcon, brightdata: BrightDataIcon, @@ -380,9 +381,11 @@ export const blockTypeToIconMap: Record = { docusign: DocuSignIcon, downdetector: DowndetectorIcon, dropbox: DropboxIcon, + dropbox_v2: DropboxIcon, dropcontact: DropcontactIcon, dspy: DsPyIcon, dub: DubIcon, + dub_v2: DubIcon, duckduckgo: DuckDuckGoIcon, dynamodb: DynamoDBIcon, dynatrace: DynatraceIcon, @@ -475,6 +478,7 @@ export const blockTypeToIconMap: Record = { jotform: JotformIcon, jsm: JiraServiceManagementIcon, jupyter: JupyterIcon, + jupyter_v2: JupyterIcon, kalshi: KalshiIcon, kalshi_v2: KalshiIcon, ketch: KetchIcon, @@ -506,6 +510,7 @@ export const blockTypeToIconMap: Record = { memory: BrainIcon, microsoft_ad: AzureIcon, microsoft_dataverse: MicrosoftDataverseIcon, + microsoft_dataverse_v2: MicrosoftDataverseIcon, microsoft_dynamics_365: MicrosoftDataverseIcon, microsoft_excel: MicrosoftExcelIcon, microsoft_excel_v2: MicrosoftExcelIcon, @@ -557,6 +562,7 @@ export const blockTypeToIconMap: Record = { quartr: QuartrIcon, quickbooks: QuickBooksIcon, quiver: QuiverIcon, + quiver_v2: QuiverIcon, rabbitmq: RabbitmqIcon, railway: RailwayIcon, rb2b: RB2BIcon, @@ -588,8 +594,10 @@ export const blockTypeToIconMap: Record = { sentry: SentryIcon, serper: SerperIcon, servicenow: ServiceNowIcon, + servicenow_v2: ServiceNowIcon, ses: SESIcon, sftp: SftpIcon, + sftp_v2: SftpIcon, sharepoint: MicrosoftSharepointIcon, sharepoint_v2: MicrosoftSharepointIcon, shopify: ShopifyIcon, @@ -607,6 +615,7 @@ export const blockTypeToIconMap: Record = { sqs: SQSIcon, square: SquareIcon, ssh: SshIcon, + ssh_v2: SshIcon, ssm: SSMIcon, stagehand: StagehandIcon, start_trigger: StartIcon, diff --git a/apps/docs/content/docs/integrations/box.mdx b/apps/docs/content/docs/integrations/box.mdx index db628a6699d..f165d7f9058 100644 --- a/apps/docs/content/docs/integrations/box.mdx +++ b/apps/docs/content/docs/integrations/box.mdx @@ -6,7 +6,7 @@ description: Manage files, folders, and e-signatures with Box import { BlockInfoCard } from "@/components/ui/block-info-card" @@ -63,7 +63,6 @@ Download a file from Box | Parameter | Type | Description | | --------- | ---- | ----------- | | `file` | file | Downloaded file stored in execution files | -| `content` | string | Base64 encoded file content | ### Box Get File Info diff --git a/apps/docs/content/docs/integrations/dropbox.mdx b/apps/docs/content/docs/integrations/dropbox.mdx index 27b95131829..ebd17a220a4 100644 --- a/apps/docs/content/docs/integrations/dropbox.mdx +++ b/apps/docs/content/docs/integrations/dropbox.mdx @@ -6,7 +6,7 @@ description: Upload, download, share, and manage files in Dropbox import { BlockInfoCard } from "@/components/ui/block-info-card" @@ -66,7 +66,7 @@ Upload a file to Dropbox ### Dropbox Download File -Download a file from Dropbox with metadata and content +Download a file from Dropbox with metadata #### Input @@ -81,7 +81,6 @@ Download a file from Dropbox with metadata and content | `file` | file | Downloaded file stored in execution files | | `metadata` | json | The file metadata | | `temporaryLink` | string | Temporary link to download the file \(valid for ~4 hours\) | -| `content` | string | Base64 encoded file content \(if fetched\) | ### Dropbox List Folder diff --git a/apps/docs/content/docs/integrations/dub.mdx b/apps/docs/content/docs/integrations/dub.mdx index beb890bbf74..5ad7e6c23f1 100644 --- a/apps/docs/content/docs/integrations/dub.mdx +++ b/apps/docs/content/docs/integrations/dub.mdx @@ -6,7 +6,7 @@ description: Link management with Dub import { BlockInfoCard } from "@/components/ui/block-info-card" @@ -474,7 +474,6 @@ Generate a customizable QR code (PNG) for a short link, with control over size, | Parameter | Type | Description | | --------- | ---- | ----------- | | `file` | file | Generated QR code image stored in execution files | -| `content` | string | Base64-encoded PNG image data | ### Dub List Domains diff --git a/apps/docs/content/docs/integrations/jupyter.mdx b/apps/docs/content/docs/integrations/jupyter.mdx index ceb5266a318..2025e5fc79f 100644 --- a/apps/docs/content/docs/integrations/jupyter.mdx +++ b/apps/docs/content/docs/integrations/jupyter.mdx @@ -6,7 +6,7 @@ description: Manage files, notebooks, kernels, and sessions on a Jupyter server import { BlockInfoCard } from "@/components/ui/block-info-card" @@ -61,7 +61,7 @@ List files, notebooks, and subdirectories at a path on a Jupyter server ### Jupyter Get Content -Read a file or notebook from a Jupyter server +Download a file as a stored file, or read structured notebook and directory content #### Input @@ -75,11 +75,11 @@ Read a file or notebook from a Jupyter server | Parameter | Type | Description | | --------- | ---- | ----------- | -| `name` | string | File or notebook name | -| `path` | string | Path relative to the server root | -| `mimetype` | string | MIME type of the content | -| `text` | string | Text content, for text files and notebooks \(JSON-stringified\) | -| `file` | file | Binary content stored as a file, for base64-format content | +| `file` | file | Downloaded file | +| `text` | string | JSON-stringified notebook or directory content | +| `name` | string | Notebook or directory name | +| `path` | string | Notebook or directory path | +| `mimetype` | string | Notebook or directory MIME type | ### Jupyter Create File diff --git a/apps/docs/content/docs/integrations/microsoft_dataverse.mdx b/apps/docs/content/docs/integrations/microsoft_dataverse.mdx index 596dd1db9a7..91662cfea31 100644 --- a/apps/docs/content/docs/integrations/microsoft_dataverse.mdx +++ b/apps/docs/content/docs/integrations/microsoft_dataverse.mdx @@ -6,7 +6,7 @@ description: Manage records in Microsoft Dataverse tables import { BlockInfoCard } from "@/components/ui/block-info-card" @@ -136,7 +136,7 @@ Remove an association between two records in Microsoft Dataverse. For collection ### Download File from Microsoft Dataverse -Download a file from a file or image column on a Dataverse record. Stores the file in execution storage and returns a file reference, plus the base64 content and metadata directly. +Download a file from a Dataverse file or image column and return its stored file reference and metadata #### Input @@ -152,12 +152,7 @@ Download a file from a file or image column on a Dataverse record. Stores the fi | Parameter | Type | Description | | --------- | ---- | ----------- | | `file` | file | Downloaded file stored in execution files | -| `fileContent` | string | Base64-encoded file content | -| `fileName` | string | Name of the downloaded file | -| `fileSize` | number | File size in bytes | -| `mimeType` | string | MIME type of the file | | `fileColumn` | string | File column the file was downloaded from | -| `success` | boolean | Whether the file was downloaded successfully | ### Execute Microsoft Dataverse Action diff --git a/apps/docs/content/docs/integrations/quiver.mdx b/apps/docs/content/docs/integrations/quiver.mdx index 282ca9aca7b..43a658acd42 100644 --- a/apps/docs/content/docs/integrations/quiver.mdx +++ b/apps/docs/content/docs/integrations/quiver.mdx @@ -6,7 +6,7 @@ description: Generate and vectorize SVGs import { BlockInfoCard } from "@/components/ui/block-info-card" @@ -57,16 +57,12 @@ Generate SVG images from text prompts using QuiverAI | Parameter | Type | Description | | --------- | ---- | ----------- | -| `success` | boolean | Whether the SVG generation succeeded | -| `output` | object | Generated SVG output | -| ↳ `file` | file | First generated SVG file | -| ↳ `files` | json | All generated SVG files \(when n > 1\) | -| ↳ `svgContent` | string | Raw SVG markup content of the first result | -| ↳ `id` | string | Generation request ID | -| ↳ `usage` | json | Token usage statistics | -| ↳ `totalTokens` | number | Total tokens used | -| ↳ `inputTokens` | number | Input tokens used | -| ↳ `outputTokens` | number | Output tokens used | +| `files` | file[] | All generated SVG files | +| `id` | string | Request ID | +| `usage` | json | Token usage statistics | +| ↳ `totalTokens` | number | Total tokens used | +| ↳ `inputTokens` | number | Input tokens used | +| ↳ `outputTokens` | number | Output tokens used | ### Quiver Image to SVG @@ -90,15 +86,12 @@ Convert raster images into vector SVG format using QuiverAI | Parameter | Type | Description | | --------- | ---- | ----------- | -| `success` | boolean | Whether the vectorization succeeded | -| `output` | object | Vectorized SVG output | -| ↳ `file` | file | Generated SVG file | -| ↳ `svgContent` | string | Raw SVG markup content | -| ↳ `id` | string | Vectorization request ID | -| ↳ `usage` | json | Token usage statistics | -| ↳ `totalTokens` | number | Total tokens used | -| ↳ `inputTokens` | number | Input tokens used | -| ↳ `outputTokens` | number | Output tokens used | +| `files` | file[] | All generated SVG files | +| `id` | string | Request ID | +| `usage` | json | Token usage statistics | +| ↳ `totalTokens` | number | Total tokens used | +| ↳ `inputTokens` | number | Input tokens used | +| ↳ `outputTokens` | number | Output tokens used | ### Quiver List Models diff --git a/apps/docs/content/docs/integrations/servicenow.mdx b/apps/docs/content/docs/integrations/servicenow.mdx index 84482fba5fc..9fb36bf30f2 100644 --- a/apps/docs/content/docs/integrations/servicenow.mdx +++ b/apps/docs/content/docs/integrations/servicenow.mdx @@ -6,7 +6,7 @@ description: Create, read, update, and delete ServiceNow records import { BlockInfoCard } from "@/components/ui/block-info-card" @@ -189,7 +189,6 @@ Download an attachment file from ServiceNow by its sys_id | Parameter | Type | Description | | --------- | ---- | ----------- | | `file` | file | Downloaded attachment stored in execution files | -| `content` | string | Base64 encoded file content | ### Upload ServiceNow Attachment @@ -258,7 +257,7 @@ Create an incident in ServiceNow. Reference fields (caller, assignment group, as | `count` | number | Aggregate matching record count | | `attachments` | json | Attachment metadata list — record attachments \(sys_id, file_name, content_type, download_link\) or knowledge article attachments \(sys_id, file_name, size_bytes, state\) | | `file` | file | Downloaded attachment file | -| `content` | string | Base64-encoded downloaded file content, or the HTML body of a knowledge article | +| `content` | string | HTML body of a knowledge article | | `attachment` | json | Uploaded attachment metadata | | `tasks` | json | Change tasks belonging to a change request. Unlike the Table API operations, the Change Management API always returns every field as \{value, display_value\} regardless of the display value setting | | `items` | json | Service catalog items | @@ -306,7 +305,7 @@ Retrieve a single ServiceNow incident by number (e.g., INC0010001) or sys_id. Re | `count` | number | Aggregate matching record count | | `attachments` | json | Attachment metadata list — record attachments \(sys_id, file_name, content_type, download_link\) or knowledge article attachments \(sys_id, file_name, size_bytes, state\) | | `file` | file | Downloaded attachment file | -| `content` | string | Base64-encoded downloaded file content, or the HTML body of a knowledge article | +| `content` | string | HTML body of a knowledge article | | `attachment` | json | Uploaded attachment metadata | | `tasks` | json | Change tasks belonging to a change request. Unlike the Table API operations, the Change Management API always returns every field as \{value, display_value\} regardless of the display value setting | | `items` | json | Service catalog items | @@ -362,7 +361,7 @@ Search ServiceNow incidents by state, priority, assignment, caller, or text. All | `count` | number | Aggregate matching record count | | `attachments` | json | Attachment metadata list — record attachments \(sys_id, file_name, content_type, download_link\) or knowledge article attachments \(sys_id, file_name, size_bytes, state\) | | `file` | file | Downloaded attachment file | -| `content` | string | Base64-encoded downloaded file content, or the HTML body of a knowledge article | +| `content` | string | HTML body of a knowledge article | | `attachment` | json | Uploaded attachment metadata | | `tasks` | json | Change tasks belonging to a change request. Unlike the Table API operations, the Change Management API always returns every field as \{value, display_value\} regardless of the display value setting | | `items` | json | Service catalog items | @@ -424,7 +423,7 @@ Update fields on an existing ServiceNow incident. Only the fields you supply are | `count` | number | Aggregate matching record count | | `attachments` | json | Attachment metadata list — record attachments \(sys_id, file_name, content_type, download_link\) or knowledge article attachments \(sys_id, file_name, size_bytes, state\) | | `file` | file | Downloaded attachment file | -| `content` | string | Base64-encoded downloaded file content, or the HTML body of a knowledge article | +| `content` | string | HTML body of a knowledge article | | `attachment` | json | Uploaded attachment metadata | | `tasks` | json | Change tasks belonging to a change request. Unlike the Table API operations, the Change Management API always returns every field as \{value, display_value\} regardless of the display value setting | | `items` | json | Service catalog items | @@ -476,7 +475,7 @@ Move a ServiceNow incident to Resolved (state 6) with a resolution code and reso | `count` | number | Aggregate matching record count | | `attachments` | json | Attachment metadata list — record attachments \(sys_id, file_name, content_type, download_link\) or knowledge article attachments \(sys_id, file_name, size_bytes, state\) | | `file` | file | Downloaded attachment file | -| `content` | string | Base64-encoded downloaded file content, or the HTML body of a knowledge article | +| `content` | string | HTML body of a knowledge article | | `attachment` | json | Uploaded attachment metadata | | `tasks` | json | Change tasks belonging to a change request. Unlike the Table API operations, the Change Management API always returns every field as \{value, display_value\} regardless of the display value setting | | `items` | json | Service catalog items | @@ -528,7 +527,7 @@ Move a ServiceNow incident to Closed (state 7) with a resolution code and resolu | `count` | number | Aggregate matching record count | | `attachments` | json | Attachment metadata list — record attachments \(sys_id, file_name, content_type, download_link\) or knowledge article attachments \(sys_id, file_name, size_bytes, state\) | | `file` | file | Downloaded attachment file | -| `content` | string | Base64-encoded downloaded file content, or the HTML body of a knowledge article | +| `content` | string | HTML body of a knowledge article | | `attachment` | json | Uploaded attachment metadata | | `tasks` | json | Change tasks belonging to a change request. Unlike the Table API operations, the Change Management API always returns every field as \{value, display_value\} regardless of the display value setting | | `items` | json | Service catalog items | @@ -578,7 +577,7 @@ Append an internal work note or a customer-visible additional comment to a Servi | `count` | number | Aggregate matching record count | | `attachments` | json | Attachment metadata list — record attachments \(sys_id, file_name, content_type, download_link\) or knowledge article attachments \(sys_id, file_name, size_bytes, state\) | | `file` | file | Downloaded attachment file | -| `content` | string | Base64-encoded downloaded file content, or the HTML body of a knowledge article | +| `content` | string | HTML body of a knowledge article | | `attachment` | json | Uploaded attachment metadata | | `tasks` | json | Change tasks belonging to a change request. Unlike the Table API operations, the Change Management API always returns every field as \{value, display_value\} regardless of the display value setting | | `items` | json | Service catalog items | @@ -643,7 +642,7 @@ Create a change request in ServiceNow. Reference fields (assignment group, assig | `count` | number | Aggregate matching record count | | `attachments` | json | Attachment metadata list — record attachments \(sys_id, file_name, content_type, download_link\) or knowledge article attachments \(sys_id, file_name, size_bytes, state\) | | `file` | file | Downloaded attachment file | -| `content` | string | Base64-encoded downloaded file content, or the HTML body of a knowledge article | +| `content` | string | HTML body of a knowledge article | | `attachment` | json | Uploaded attachment metadata | | `tasks` | json | Change tasks belonging to a change request. Unlike the Table API operations, the Change Management API always returns every field as \{value, display_value\} regardless of the display value setting | | `items` | json | Service catalog items | @@ -691,7 +690,7 @@ Retrieve a single ServiceNow change request by number (e.g., CHG0030001) or sys_ | `count` | number | Aggregate matching record count | | `attachments` | json | Attachment metadata list — record attachments \(sys_id, file_name, content_type, download_link\) or knowledge article attachments \(sys_id, file_name, size_bytes, state\) | | `file` | file | Downloaded attachment file | -| `content` | string | Base64-encoded downloaded file content, or the HTML body of a knowledge article | +| `content` | string | HTML body of a knowledge article | | `attachment` | json | Uploaded attachment metadata | | `tasks` | json | Change tasks belonging to a change request. Unlike the Table API operations, the Change Management API always returns every field as \{value, display_value\} regardless of the display value setting | | `items` | json | Service catalog items | @@ -747,7 +746,7 @@ Search ServiceNow change requests by state, type, risk, assignment, or text. All | `count` | number | Aggregate matching record count | | `attachments` | json | Attachment metadata list — record attachments \(sys_id, file_name, content_type, download_link\) or knowledge article attachments \(sys_id, file_name, size_bytes, state\) | | `file` | file | Downloaded attachment file | -| `content` | string | Base64-encoded downloaded file content, or the HTML body of a knowledge article | +| `content` | string | HTML body of a knowledge article | | `attachment` | json | Uploaded attachment metadata | | `tasks` | json | Change tasks belonging to a change request. Unlike the Table API operations, the Change Management API always returns every field as \{value, display_value\} regardless of the display value setting | | `items` | json | Service catalog items | @@ -809,7 +808,7 @@ Update fields on an existing ServiceNow change request. Only the fields you supp | `count` | number | Aggregate matching record count | | `attachments` | json | Attachment metadata list — record attachments \(sys_id, file_name, content_type, download_link\) or knowledge article attachments \(sys_id, file_name, size_bytes, state\) | | `file` | file | Downloaded attachment file | -| `content` | string | Base64-encoded downloaded file content, or the HTML body of a knowledge article | +| `content` | string | HTML body of a knowledge article | | `attachment` | json | Uploaded attachment metadata | | `tasks` | json | Change tasks belonging to a change request. Unlike the Table API operations, the Change Management API always returns every field as \{value, display_value\} regardless of the display value setting | | `items` | json | Service catalog items | @@ -862,7 +861,7 @@ Move a ServiceNow change request to another state. Base-system change model stat | `count` | number | Aggregate matching record count | | `attachments` | json | Attachment metadata list — record attachments \(sys_id, file_name, content_type, download_link\) or knowledge article attachments \(sys_id, file_name, size_bytes, state\) | | `file` | file | Downloaded attachment file | -| `content` | string | Base64-encoded downloaded file content, or the HTML body of a knowledge article | +| `content` | string | HTML body of a knowledge article | | `attachment` | json | Uploaded attachment metadata | | `tasks` | json | Change tasks belonging to a change request. Unlike the Table API operations, the Change Management API always returns every field as \{value, display_value\} regardless of the display value setting | | `items` | json | Service catalog items | @@ -1040,7 +1039,7 @@ List requested items (RITMs) from the ServiceNow Requested Item [sc_req_item] ta | `count` | number | Aggregate matching record count | | `attachments` | json | Attachment metadata list — record attachments \(sys_id, file_name, content_type, download_link\) or knowledge article attachments \(sys_id, file_name, size_bytes, state\) | | `file` | file | Downloaded attachment file | -| `content` | string | Base64-encoded downloaded file content, or the HTML body of a knowledge article | +| `content` | string | HTML body of a knowledge article | | `attachment` | json | Uploaded attachment metadata | | `tasks` | json | Change tasks belonging to a change request. Unlike the Table API operations, the Change Management API always returns every field as \{value, display_value\} regardless of the display value setting | | `items` | json | Service catalog items | @@ -1088,7 +1087,7 @@ Retrieve a single ServiceNow requested item (RITM) by number (e.g., RITM0010001) | `count` | number | Aggregate matching record count | | `attachments` | json | Attachment metadata list — record attachments \(sys_id, file_name, content_type, download_link\) or knowledge article attachments \(sys_id, file_name, size_bytes, state\) | | `file` | file | Downloaded attachment file | -| `content` | string | Base64-encoded downloaded file content, or the HTML body of a knowledge article | +| `content` | string | HTML body of a knowledge article | | `attachment` | json | Uploaded attachment metadata | | `tasks` | json | Change tasks belonging to a change request. Unlike the Table API operations, the Change Management API always returns every field as \{value, display_value\} regardless of the display value setting | | `items` | json | Service catalog items | @@ -1140,7 +1139,7 @@ List approval records from the ServiceNow Approval [sysapproval_approver] table. | `count` | number | Aggregate matching record count | | `attachments` | json | Attachment metadata list — record attachments \(sys_id, file_name, content_type, download_link\) or knowledge article attachments \(sys_id, file_name, size_bytes, state\) | | `file` | file | Downloaded attachment file | -| `content` | string | Base64-encoded downloaded file content, or the HTML body of a knowledge article | +| `content` | string | HTML body of a knowledge article | | `attachment` | json | Uploaded attachment metadata | | `tasks` | json | Change tasks belonging to a change request. Unlike the Table API operations, the Change Management API always returns every field as \{value, display_value\} regardless of the display value setting | | `items` | json | Service catalog items | @@ -1190,7 +1189,7 @@ Approve or reject a ServiceNow approval record by setting its state on the Appro | `count` | number | Aggregate matching record count | | `attachments` | json | Attachment metadata list — record attachments \(sys_id, file_name, content_type, download_link\) or knowledge article attachments \(sys_id, file_name, size_bytes, state\) | | `file` | file | Downloaded attachment file | -| `content` | string | Base64-encoded downloaded file content, or the HTML body of a knowledge article | +| `content` | string | HTML body of a knowledge article | | `attachment` | json | Uploaded attachment metadata | | `tasks` | json | Change tasks belonging to a change request. Unlike the Table API operations, the Change Management API always returns every field as \{value, display_value\} regardless of the display value setting | | `items` | json | Service catalog items | @@ -1242,7 +1241,7 @@ Search the ServiceNow CMDB for configuration items. Defaults to the base cmdb_ci | `count` | number | Aggregate matching record count | | `attachments` | json | Attachment metadata list — record attachments \(sys_id, file_name, content_type, download_link\) or knowledge article attachments \(sys_id, file_name, size_bytes, state\) | | `file` | file | Downloaded attachment file | -| `content` | string | Base64-encoded downloaded file content, or the HTML body of a knowledge article | +| `content` | string | HTML body of a knowledge article | | `attachment` | json | Uploaded attachment metadata | | `tasks` | json | Change tasks belonging to a change request. Unlike the Table API operations, the Change Management API always returns every field as \{value, display_value\} regardless of the display value setting | | `items` | json | Service catalog items | @@ -1324,7 +1323,7 @@ List rows from the CI Relationship [cmdb_rel_ci] table for a configuration item. | `count` | number | Aggregate matching record count | | `attachments` | json | Attachment metadata list — record attachments \(sys_id, file_name, content_type, download_link\) or knowledge article attachments \(sys_id, file_name, size_bytes, state\) | | `file` | file | Downloaded attachment file | -| `content` | string | Base64-encoded downloaded file content, or the HTML body of a knowledge article | +| `content` | string | HTML body of a knowledge article | | `attachment` | json | Uploaded attachment metadata | | `tasks` | json | Change tasks belonging to a change request. Unlike the Table API operations, the Change Management API always returns every field as \{value, display_value\} regardless of the display value setting | | `items` | json | Service catalog items | @@ -1444,7 +1443,7 @@ Look up ServiceNow users by email, user name, or display name. Use this to resol | `count` | number | Aggregate matching record count | | `attachments` | json | Attachment metadata list — record attachments \(sys_id, file_name, content_type, download_link\) or knowledge article attachments \(sys_id, file_name, size_bytes, state\) | | `file` | file | Downloaded attachment file | -| `content` | string | Base64-encoded downloaded file content, or the HTML body of a knowledge article | +| `content` | string | HTML body of a knowledge article | | `attachment` | json | Uploaded attachment metadata | | `tasks` | json | Change tasks belonging to a change request. Unlike the Table API operations, the Change Management API always returns every field as \{value, display_value\} regardless of the display value setting | | `items` | json | Service catalog items | @@ -1495,7 +1494,7 @@ List the members of a ServiceNow group from the Group Member [sys_user_grmember] | `count` | number | Aggregate matching record count | | `attachments` | json | Attachment metadata list — record attachments \(sys_id, file_name, content_type, download_link\) or knowledge article attachments \(sys_id, file_name, size_bytes, state\) | | `file` | file | Downloaded attachment file | -| `content` | string | Base64-encoded downloaded file content, or the HTML body of a knowledge article | +| `content` | string | HTML body of a knowledge article | | `attachment` | json | Uploaded attachment metadata | | `tasks` | json | Change tasks belonging to a change request. Unlike the Table API operations, the Change Management API always returns every field as \{value, display_value\} regardless of the display value setting | | `items` | json | Service catalog items | diff --git a/apps/docs/content/docs/integrations/sftp.mdx b/apps/docs/content/docs/integrations/sftp.mdx index 60b2397b18a..a62e82ca437 100644 --- a/apps/docs/content/docs/integrations/sftp.mdx +++ b/apps/docs/content/docs/integrations/sftp.mdx @@ -6,7 +6,7 @@ description: Transfer files via SFTP (SSH File Transfer Protocol) import { BlockInfoCard } from "@/components/ui/block-info-card" @@ -77,19 +77,12 @@ Download a file from a remote SFTP server | `privateKey` | string | No | Private key for authentication \(OpenSSH format\) | | `passphrase` | string | No | Passphrase for encrypted private key | | `remotePath` | string | Yes | Path to the file on the remote server | -| `encoding` | string | No | Output encoding: utf-8 for text, base64 for binary \(default: utf-8\) | #### Output | Parameter | Type | Description | | --------- | ---- | ----------- | -| `success` | boolean | Whether the download was successful | | `file` | file | Downloaded file stored in execution files | -| `fileName` | string | Name of the downloaded file | -| `content` | string | File content \(text or base64 encoded\) | -| `size` | number | File size in bytes | -| `encoding` | string | Content encoding \(utf-8 or base64\) | -| `message` | string | Operation status message | ### SFTP List Directory diff --git a/apps/docs/content/docs/integrations/ssh.mdx b/apps/docs/content/docs/integrations/ssh.mdx index 3b6e7631df7..23e16880e0e 100644 --- a/apps/docs/content/docs/integrations/ssh.mdx +++ b/apps/docs/content/docs/integrations/ssh.mdx @@ -6,7 +6,7 @@ description: Connect to remote servers via SSH import { BlockInfoCard } from "@/components/ui/block-info-card" @@ -161,13 +161,8 @@ Download a file from a remote SSH server | Parameter | Type | Description | | --------- | ---- | ----------- | -| `downloaded` | boolean | Whether the file was downloaded successfully | | `file` | file | Downloaded file stored in execution files | -| `fileContent` | string | File content \(base64 encoded for binary files\) | -| `fileName` | string | Name of the downloaded file | | `remotePath` | string | Source path on the remote server | -| `size` | number | File size in bytes | -| `message` | string | Operation status message | ### SSH List Directory diff --git a/apps/sim/blocks/blocks/binary-download-versioning.test.ts b/apps/sim/blocks/blocks/binary-download-versioning.test.ts new file mode 100644 index 00000000000..88a5fe12b7f --- /dev/null +++ b/apps/sim/blocks/blocks/binary-download-versioning.test.ts @@ -0,0 +1,100 @@ +import { describe, expect, it } from 'vitest' +import { BoxBlock, BoxV2Block } from '@/blocks/blocks/box' +import { DropboxBlock, DropboxV2Block } from '@/blocks/blocks/dropbox' +import { DubBlock, DubV2Block } from '@/blocks/blocks/dub' +import { + MicrosoftDataverseBlock, + MicrosoftDataverseV2Block, +} from '@/blocks/blocks/microsoft_dataverse' +import { ServiceNowBlock, ServiceNowV2Block } from '@/blocks/blocks/servicenow' +import type { BlockConfig } from '@/blocks/types' + +const cases: { + legacy: BlockConfig + current: BlockConfig + operation: string + toolId: string + content: string +}[] = [ + { + legacy: BoxBlock, + current: BoxV2Block, + operation: 'download_file', + toolId: 'box_download_file', + content: 'content', + }, + { + legacy: DropboxBlock, + current: DropboxV2Block, + operation: 'dropbox_download', + toolId: 'dropbox_download', + content: 'content', + }, + { + legacy: DubBlock, + current: DubV2Block, + operation: 'get_qr_code', + toolId: 'dub_get_qr_code', + content: 'content', + }, + { + legacy: MicrosoftDataverseBlock, + current: MicrosoftDataverseV2Block, + operation: 'download_file', + toolId: 'microsoft_dataverse_download_file', + content: 'fileContent', + }, + { + legacy: ServiceNowBlock, + current: ServiceNowV2Block, + operation: 'servicenow_download_attachment', + toolId: 'servicenow_download_attachment', + content: 'content', + }, +] + +describe.each(cases)( + '$current.type download versioning', + ({ legacy, current, operation, toolId, content }) => { + it('preserves saved blocks and changes only the download tool for new blocks', () => { + expect(legacy.hideFromToolbar).toBe(true) + expect(legacy.sunset).toEqual({ status: 'legacy', replacedBy: current.type }) + expect(current.hideFromToolbar).toBe(false) + expect(current.sunset).toBeUndefined() + expect(current.subBlocks).toBe(legacy.subBlocks) + expect(current.tools.config?.params).toBe(legacy.tools.config?.params) + expect(legacy.tools.config?.tool({ operation })).toBe(toolId) + expect(current.tools.config?.tool({ operation })).toBe(`${toolId}_v2`) + expect(current.tools.access).toEqual( + legacy.tools.access.map((id) => (id === toolId ? `${id}_v2` : id)) + ) + }) + + it('removes the download content output while preserving unrelated outputs', () => { + expect(legacy.outputs).toHaveProperty(content) + if (current.type === 'servicenow_v2') { + expect(current.outputs.content).toEqual({ + type: 'string', + description: 'HTML body of a knowledge article', + }) + } else { + expect(current.outputs).not.toHaveProperty(content) + } + expect(current.outputs.file).toEqual(legacy.outputs.file) + }) + } +) + +it('keeps Dataverse upload metadata separate from canonical download files', () => { + expect(MicrosoftDataverseV2Block.outputs).not.toHaveProperty('fileSize') + expect(MicrosoftDataverseV2Block.outputs).not.toHaveProperty('mimeType') + expect(MicrosoftDataverseV2Block.outputs.fileName.condition).toEqual({ + field: 'operation', + value: 'upload_file', + }) + expect(MicrosoftDataverseV2Block.outputs.success.condition).toEqual({ + field: 'operation', + value: 'download_file', + not: true, + }) +}) diff --git a/apps/sim/blocks/blocks/box.ts b/apps/sim/blocks/blocks/box.ts index 6d3b03f157e..3b81fc5a25b 100644 --- a/apps/sim/blocks/blocks/box.ts +++ b/apps/sim/blocks/blocks/box.ts @@ -1,3 +1,4 @@ +import { omit } from '@sim/utils/object' import { BoxCompanyIcon } from '@/components/icons' import { getScopesForService } from '@/lib/oauth/utils' import type { BlockConfig, BlockMeta } from '@/blocks/types' @@ -7,9 +8,11 @@ import { normalizeFileInput } from '@/blocks/utils' /** Canonical pair for the upload payload: file picker in basic mode, file reference in advanced. */ const UPLOAD_FILE_FIELD = ['uploadFile', 'fileRef'] as const -export const BoxBlock: BlockConfig = { +export const BoxBlock = { type: 'box', - name: 'Box', + name: 'Box (Legacy)', + hideFromToolbar: true, + sunset: { status: 'legacy', replacedBy: 'box_v2' }, description: 'Manage files, folders, and e-signatures with Box', longDescription: 'Integrate Box into your workflow to manage files, folders, and e-signatures. Upload and download files, search content, create folders, send documents for e-signature, track signing status, and more.', @@ -657,6 +660,28 @@ export const BoxBlock: BlockConfig = { count: 'number', nextMarker: 'string', }, +} satisfies BlockConfig + +export const BoxV2Block: BlockConfig = { + ...BoxBlock, + type: 'box_v2', + name: 'Box', + hideFromToolbar: false, + sunset: undefined, + tools: { + ...BoxBlock.tools, + access: BoxBlock.tools.access.map((toolId) => + toolId === 'box_download_file' ? 'box_download_file_v2' : toolId + ), + config: { + ...BoxBlock.tools.config, + tool: (params) => { + const toolId = BoxBlock.tools.config.tool(params) + return toolId === 'box_download_file' ? 'box_download_file_v2' : toolId + }, + }, + }, + outputs: omit(BoxBlock.outputs, ['content']), } export const BoxBlockMeta = { diff --git a/apps/sim/blocks/blocks/dropbox.ts b/apps/sim/blocks/blocks/dropbox.ts index 3047df56821..572c47047d0 100644 --- a/apps/sim/blocks/blocks/dropbox.ts +++ b/apps/sim/blocks/blocks/dropbox.ts @@ -1,3 +1,4 @@ +import { omit } from '@sim/utils/object' import { DropboxIcon } from '@/components/icons' import { getScopesForService } from '@/lib/oauth/utils' import type { BlockConfig, BlockMeta } from '@/blocks/types' @@ -12,9 +13,11 @@ import type { DropboxResponse } from '@/tools/dropbox/types' */ const UPLOAD_FILE_FIELD = ['uploadFile', 'fileRef'] as const -export const DropboxBlock: BlockConfig = { +export const DropboxBlock = { type: 'dropbox', - name: 'Dropbox', + name: 'Dropbox (Legacy)', + hideFromToolbar: true, + sunset: { status: 'legacy', replacedBy: 'dropbox_v2' }, description: 'Upload, download, share, and manage files in Dropbox', authMode: AuthMode.OAuth, longDescription: @@ -544,6 +547,28 @@ Return ONLY the timestamp string - no explanations, no quotes, no extra text.`, // List revisions output isDeleted: { type: 'boolean', description: 'Whether the latest revision is deleted or moved' }, }, +} satisfies BlockConfig + +export const DropboxV2Block: BlockConfig = { + ...DropboxBlock, + type: 'dropbox_v2', + name: 'Dropbox', + hideFromToolbar: false, + sunset: undefined, + tools: { + ...DropboxBlock.tools, + access: DropboxBlock.tools.access.map((toolId) => + toolId === 'dropbox_download' ? 'dropbox_download_v2' : toolId + ), + config: { + ...DropboxBlock.tools.config, + tool: (params) => { + const toolId = DropboxBlock.tools.config.tool(params) + return toolId === 'dropbox_download' ? 'dropbox_download_v2' : toolId + }, + }, + }, + outputs: omit(DropboxBlock.outputs, ['content']), } export const DropboxBlockMeta = { diff --git a/apps/sim/blocks/blocks/dub.ts b/apps/sim/blocks/blocks/dub.ts index 1b2e213be6a..3361f171254 100644 --- a/apps/sim/blocks/blocks/dub.ts +++ b/apps/sim/blocks/blocks/dub.ts @@ -1,3 +1,4 @@ +import { omit } from '@sim/utils/object' import { DubIcon } from '@/components/icons' import type { BlockConfig, BlockMeta } from '@/blocks/types' import { AuthMode, IntegrationType } from '@/blocks/types' @@ -8,9 +9,11 @@ const BULK_UPDATE_TARGET_FIELD = ['bulkUpdateLinkIds', 'bulkUpdateExternalIds'] const ANALYTICS_LINK_FIELD = ['analyticsLinkId', 'analyticsExternalId'] as const const EVENTS_LINK_FIELD = ['eventsLinkId', 'eventsExternalId'] as const -export const DubBlock: BlockConfig = { +export const DubBlock = { type: 'dub', - name: 'Dub', + name: 'Dub (Legacy)', + hideFromToolbar: true, + sunset: { status: 'legacy', replacedBy: 'dub_v2' }, description: 'Link management with Dub', authMode: AuthMode.ApiKey, longDescription: @@ -1277,6 +1280,28 @@ export const DubBlock: BlockConfig = { condition: { field: 'operation', value: 'create_tag' }, }, }, +} satisfies BlockConfig + +export const DubV2Block: BlockConfig = { + ...DubBlock, + type: 'dub_v2', + name: 'Dub', + hideFromToolbar: false, + sunset: undefined, + tools: { + ...DubBlock.tools, + access: DubBlock.tools.access.map((toolId) => + toolId === 'dub_get_qr_code' ? 'dub_get_qr_code_v2' : toolId + ), + config: { + ...DubBlock.tools.config, + tool: (params) => { + const toolId = DubBlock.tools.config.tool(params) + return toolId === 'dub_get_qr_code' ? 'dub_get_qr_code_v2' : toolId + }, + }, + }, + outputs: omit(DubBlock.outputs, ['content']), } export const DubBlockMeta = { diff --git a/apps/sim/blocks/blocks/jupyter.test.ts b/apps/sim/blocks/blocks/jupyter.test.ts new file mode 100644 index 00000000000..5c5c284b7e9 --- /dev/null +++ b/apps/sim/blocks/blocks/jupyter.test.ts @@ -0,0 +1,35 @@ +import { describe, expect, it } from 'vitest' +import { JupyterBlock, JupyterV2Block } from '@/blocks/blocks/jupyter' + +describe('Jupyter block versions', () => { + it('offers v2 for new blocks and preserves the legacy block', () => { + expect(JupyterBlock.hideFromToolbar).toBe(true) + expect(JupyterBlock.sunset).toEqual({ status: 'legacy', replacedBy: 'jupyter_v2' }) + expect(JupyterV2Block.hideFromToolbar).toBe(false) + expect(JupyterV2Block.sunset).toBeUndefined() + expect(JupyterV2Block.canvasPresentation).toBe(JupyterBlock.canvasPresentation) + expect(JupyterV2Block.subBlocks).toBe(JupyterBlock.subBlocks) + }) + + it.each(JupyterBlock.tools.access)('versions only Get Content: %s', (operation) => { + const id = operation === 'jupyter_get_content' ? 'jupyter_get_content_v2' : operation + expect(JupyterBlock.tools.config.tool({ operation })).toBe(operation) + expect(JupyterV2Block.tools.config?.tool({ operation })).toBe(id) + expect(JupyterV2Block.tools.access).toContain(id) + }) + + it('preserves the path and credentials for the versioned read', () => { + expect( + JupyterV2Block.tools.config?.params?.({ + operation: 'jupyter_get_content', + serverUrl: 'https://jupyter.example.com', + token: 'token', + path: 'reports/book.xlsx', + }) + ).toEqual({ + serverUrl: 'https://jupyter.example.com', + token: 'token', + path: 'reports/book.xlsx', + }) + }) +}) diff --git a/apps/sim/blocks/blocks/jupyter.ts b/apps/sim/blocks/blocks/jupyter.ts index e251c738abc..55d6c0dd03c 100644 --- a/apps/sim/blocks/blocks/jupyter.ts +++ b/apps/sim/blocks/blocks/jupyter.ts @@ -1,7 +1,7 @@ import { JupyterIcon } from '@/components/icons' import type { BlockConfig, BlockMeta } from '@/blocks/types' import { AuthMode, IntegrationType } from '@/blocks/types' -import { normalizeFileInput } from '@/blocks/utils' +import { createVersionedToolSelector, normalizeFileInput } from '@/blocks/utils' const PATH_OPERATIONS = [ 'jupyter_list_contents', @@ -31,9 +31,11 @@ const KERNEL_ID_OPERATIONS = [ /** Both members of the `file` canonical group — advanced mode fills only `fileRef`. */ const UPLOAD_FILE_FIELD = ['uploadFile', 'fileRef'] as const -export const JupyterBlock: BlockConfig = { +export const JupyterBlock = { type: 'jupyter', - name: 'Jupyter', + name: 'Jupyter (Legacy)', + hideFromToolbar: true, + sunset: { status: 'legacy', replacedBy: 'jupyter_v2' }, description: 'Manage files, notebooks, kernels, and sessions on a Jupyter server', longDescription: 'Integrate a self-hosted Jupyter server into the workflow. Browse, read, create, upload, rename, copy, and delete files and notebooks; start, stop, restart, and interrupt kernels; and manage sessions that bind notebooks to kernels.', @@ -392,6 +394,33 @@ export const JupyterBlock: BlockConfig = { kernelId: 'string', sessionId: 'string', }, +} satisfies BlockConfig + +const selectJupyterV2Tool = createVersionedToolSelector({ + baseToolSelector: JupyterBlock.tools.config.tool, + suffix: '_v2', + fallbackToolId: 'jupyter_get_content_v2', +}) + +export const JupyterV2Block: BlockConfig = { + ...JupyterBlock, + type: 'jupyter_v2', + name: 'Jupyter', + hideFromToolbar: false, + sunset: undefined, + tools: { + ...JupyterBlock.tools, + access: JupyterBlock.tools.access.map((toolId) => + toolId === 'jupyter_get_content' ? 'jupyter_get_content_v2' : toolId + ), + config: { + ...JupyterBlock.tools.config, + tool: (params) => + params.operation === 'jupyter_get_content' + ? selectJupyterV2Tool(params) + : JupyterBlock.tools.config.tool(params), + }, + }, } export const JupyterBlockMeta = { diff --git a/apps/sim/blocks/blocks/microsoft_dataverse.ts b/apps/sim/blocks/blocks/microsoft_dataverse.ts index 2c51cfe7ad2..748859694a0 100644 --- a/apps/sim/blocks/blocks/microsoft_dataverse.ts +++ b/apps/sim/blocks/blocks/microsoft_dataverse.ts @@ -1,3 +1,4 @@ +import { omit } from '@sim/utils/object' import { MicrosoftDataverseIcon } from '@/components/icons' import { getScopesForService } from '@/lib/oauth/utils' import type { BlockConfig, BlockMeta } from '@/blocks/types' @@ -8,9 +9,11 @@ import type { DataverseResponse } from '@/tools/microsoft_dataverse/types' /** Canonical upload pair for the file column payload, basic then advanced. */ const FILE_FIELD = ['uploadFile', 'fileReference'] as const -export const MicrosoftDataverseBlock: BlockConfig = { +export const MicrosoftDataverseBlock = { type: 'microsoft_dataverse', - name: 'Microsoft Dataverse', + name: 'Microsoft Dataverse (Legacy)', + hideFromToolbar: true, + sunset: { status: 'legacy', replacedBy: 'microsoft_dataverse_v2' }, description: 'Manage records in Microsoft Dataverse tables', authMode: AuthMode.OAuth, longDescription: @@ -788,6 +791,43 @@ Return ONLY the expand expression - no $expand= prefix, no explanations.`, description: 'Full raw table metadata response (get table metadata)', }, }, +} satisfies BlockConfig + +export const MicrosoftDataverseV2Block: BlockConfig = { + ...MicrosoftDataverseBlock, + type: 'microsoft_dataverse_v2', + name: 'Microsoft Dataverse', + hideFromToolbar: false, + sunset: undefined, + tools: { + ...MicrosoftDataverseBlock.tools, + access: MicrosoftDataverseBlock.tools.access.map((toolId) => + toolId === 'microsoft_dataverse_download_file' + ? 'microsoft_dataverse_download_file_v2' + : toolId + ), + config: { + ...MicrosoftDataverseBlock.tools.config, + tool: (params) => { + const toolId = MicrosoftDataverseBlock.tools.config.tool(params) + return toolId === 'microsoft_dataverse_download_file' + ? 'microsoft_dataverse_download_file_v2' + : toolId + }, + }, + }, + outputs: { + ...omit(MicrosoftDataverseBlock.outputs, ['fileContent', 'fileSize', 'mimeType']), + fileName: { + type: 'string', + description: 'Name of the uploaded file', + condition: { field: 'operation', value: 'upload_file' }, + }, + success: { + ...MicrosoftDataverseBlock.outputs.success, + condition: { field: 'operation', value: 'download_file', not: true }, + }, + }, } export const MicrosoftDataverseBlockMeta = { diff --git a/apps/sim/blocks/blocks/quiver.test.ts b/apps/sim/blocks/blocks/quiver.test.ts new file mode 100644 index 00000000000..c1953d8dfc6 --- /dev/null +++ b/apps/sim/blocks/blocks/quiver.test.ts @@ -0,0 +1,34 @@ +import { describe, expect, it } from 'vitest' +import { QuiverBlock, QuiverV2Block } from '@/blocks/blocks/quiver' + +describe('Quiver block versions', () => { + it('keeps the legacy block executable and offers v2 for new blocks', () => { + expect(QuiverBlock.hideFromToolbar).toBe(true) + expect(QuiverBlock.sunset).toEqual({ status: 'legacy', replacedBy: 'quiver_v2' }) + expect(QuiverV2Block.name).toBe('Quiver') + expect(QuiverV2Block.hideFromToolbar).toBe(false) + expect(QuiverV2Block.sunset).toBeUndefined() + expect(QuiverV2Block.subBlocks).toBe(QuiverBlock.subBlocks) + expect(QuiverV2Block.tools.config?.params).toBe(QuiverBlock.tools.config?.params) + }) + + it.each([ + ['text_to_svg', 'quiver_text_to_svg', 'quiver_text_to_svg_v2'], + ['image_to_svg', 'quiver_image_to_svg', 'quiver_image_to_svg_v2'], + ['list_models', 'quiver_list_models', 'quiver_list_models'], + ])('routes %s to the versioned response contract', (operation, legacyId, currentId) => { + expect(QuiverBlock.tools.config?.tool({ operation })).toBe(legacyId) + expect(QuiverV2Block.tools.config?.tool({ operation })).toBe(currentId) + expect(QuiverBlock.tools.access).toContain(legacyId) + expect(QuiverV2Block.tools.access).toContain(currentId) + }) + + it('defaults to SVG generation and exposes all generated files in v2', () => { + expect(QuiverV2Block.tools.config?.tool({})).toBe('quiver_text_to_svg_v2') + expect(QuiverV2Block.outputs.files).toMatchObject({ type: 'file[]' }) + expect(QuiverBlock.outputs.files).toMatchObject({ type: 'json' }) + expect(QuiverV2Block.outputs).not.toHaveProperty('svgContent') + expect(QuiverV2Block.outputs).not.toHaveProperty('file') + expect(QuiverBlock.outputs.svgContent).toMatchObject({ type: 'string' }) + }) +}) diff --git a/apps/sim/blocks/blocks/quiver.ts b/apps/sim/blocks/blocks/quiver.ts index 879c9fa90df..c87e691642a 100644 --- a/apps/sim/blocks/blocks/quiver.ts +++ b/apps/sim/blocks/blocks/quiver.ts @@ -1,15 +1,18 @@ +import { omit } from '@sim/utils/object' import { QuiverIcon } from '@/components/icons' import type { BlockConfig, BlockMeta } from '@/blocks/types' import { AuthMode, IntegrationType } from '@/blocks/types' -import { normalizeFileInput } from '@/blocks/utils' -import type { QuiverSvgResponse } from '@/tools/quiver/types' +import { createVersionedToolSelector, normalizeFileInput } from '@/blocks/utils' +import type { QuiverSvgResponse, QuiverSvgV2Response } from '@/tools/quiver/types' const REFERENCE_IMAGES_FIELD = ['referenceFiles', 'referenceInput'] as const const IMAGE_FIELD = ['imageFile', 'imageInput'] as const -export const QuiverBlock: BlockConfig = { +export const QuiverBlock = { type: 'quiver', - name: 'Quiver', + name: 'Quiver (Legacy)', + hideFromToolbar: true, + sunset: { status: 'legacy', replacedBy: 'quiver_v2' }, description: 'Generate and vectorize SVGs', longDescription: 'Generate SVG images from text prompts or vectorize raster images into SVGs using QuiverAI. Supports reference images, style instructions, and multiple output generation.', @@ -255,6 +258,34 @@ export const QuiverBlock: BlockConfig = { description: 'List of available models (list_models operation only)', }, }, +} satisfies BlockConfig + +const selectQuiverV2Tool = createVersionedToolSelector({ + baseToolSelector: (params: Record) => + `quiver_${params.operation || 'text_to_svg'}`, + suffix: '_v2', + fallbackToolId: 'quiver_text_to_svg_v2', +}) + +export const QuiverV2Block: BlockConfig = { + ...QuiverBlock, + type: 'quiver_v2', + name: 'Quiver', + hideFromToolbar: false, + sunset: undefined, + tools: { + ...QuiverBlock.tools, + access: ['quiver_text_to_svg_v2', 'quiver_image_to_svg_v2', 'quiver_list_models'], + config: { + ...QuiverBlock.tools.config, + tool: (params: Record) => + params.operation === 'list_models' ? 'quiver_list_models' : selectQuiverV2Tool(params), + }, + }, + outputs: { + ...omit(QuiverBlock.outputs, ['file', 'svgContent']), + files: { type: 'file[]', description: 'All generated SVG files' }, + }, } export const QuiverBlockMeta = { @@ -294,13 +325,13 @@ export const QuiverBlockMeta = { name: 'generate-brand-icon', description: 'Generate a clean SVG icon from a text prompt and save it to the files store.', content: - '# Generate Brand Icon\n\nTurn a text description into a production-ready SVG icon using Quiver text-to-SVG.\n\n## Steps\n1. Collect the icon concept (for example, a product name plus a brand color and style cues).\n2. Run the text_to_svg operation with a focused prompt that names the subject, color palette, and visual style (flat, line, filled).\n3. Optionally set n greater than 1 to generate several variations to choose from.\n4. Save the returned SVG file to the files store, or pass svgContent downstream for embedding.\n\n## Output\nReport the saved file location and the request id. When multiple variations are generated, list each so the user can pick one.', + '# Generate Brand Icon\n\nTurn a text description into a production-ready SVG icon using Quiver text-to-SVG.\n\n## Steps\n1. Collect the icon concept (for example, a product name plus a brand color and style cues).\n2. Run the text_to_svg operation with a focused prompt that names the subject, color palette, and visual style (flat, line, filled).\n3. Optionally set n greater than 1 to generate several variations to choose from.\n4. Save the returned SVG file to the files store, or pass the file downstream.\n\n## Output\nReport the saved file location and the request id. When multiple variations are generated, list each so the user can pick one.', }, { name: 'vectorize-raster-image', description: 'Convert an uploaded raster image (PNG or JPG) into a clean editable SVG.', content: - '# Vectorize Raster Image\n\nConvert a bitmap logo or graphic into a scalable SVG with Quiver image-to-SVG.\n\n## Steps\n1. Accept the raster image upload and pass it as the image input.\n2. Run the image_to_svg operation, optionally setting auto_crop and a target_size to tighten the output.\n3. Inspect svgContent for fidelity; rerun with adjusted instructions if details are lost.\n4. Save the SVG file for use in presentations, exports, or the web.\n\n## Output\nReturn the vectorized SVG file and confirm dimensions. Note any visual elements that did not vectorize cleanly.', + '# Vectorize Raster Image\n\nConvert a bitmap logo or graphic into a scalable SVG with Quiver image-to-SVG.\n\n## Steps\n1. Accept the raster image upload and pass it as the image input.\n2. Run the image_to_svg operation, optionally setting auto_crop and a target_size to tighten the output.\n3. Inspect the generated SVG file for fidelity; rerun with adjusted instructions if details are lost.\n4. Save the SVG file for use in presentations, exports, or the web.\n\n## Output\nReturn the vectorized SVG file and confirm dimensions. Note any visual elements that did not vectorize cleanly.', }, { name: 'create-data-diagram', diff --git a/apps/sim/blocks/blocks/servicenow.ts b/apps/sim/blocks/blocks/servicenow.ts index 4b4eb33cac9..6ac69083260 100644 --- a/apps/sim/blocks/blocks/servicenow.ts +++ b/apps/sim/blocks/blocks/servicenow.ts @@ -162,9 +162,11 @@ const optionalChoices = (options: reado ...options, ] -export const ServiceNowBlock: BlockConfig = { +export const ServiceNowBlock = { type: 'servicenow', - name: 'ServiceNow', + name: 'ServiceNow (Legacy)', + hideFromToolbar: true, + sunset: { status: 'legacy', replacedBy: 'servicenow_v2' }, description: 'Create, read, update, and delete ServiceNow records', longDescription: 'Integrate ServiceNow into your workflow. Create, read, update, and delete records in any ServiceNow table including incidents, tasks, change requests, users, and more.', @@ -1921,6 +1923,33 @@ Output: {"state": "2", "assigned_to": "john.doe", "work_notes": "Assigned and st 'servicenow_webhook', ], }, +} satisfies BlockConfig + +export const ServiceNowV2Block: BlockConfig = { + ...ServiceNowBlock, + type: 'servicenow_v2', + name: 'ServiceNow', + hideFromToolbar: false, + sunset: undefined, + tools: { + ...ServiceNowBlock.tools, + access: ServiceNowBlock.tools.access.map((toolId) => + toolId === 'servicenow_download_attachment' ? 'servicenow_download_attachment_v2' : toolId + ), + config: { + ...ServiceNowBlock.tools.config, + tool: (params) => { + const toolId = ServiceNowBlock.tools.config.tool(params) + return toolId === 'servicenow_download_attachment' + ? 'servicenow_download_attachment_v2' + : toolId + }, + }, + }, + outputs: { + ...ServiceNowBlock.outputs, + content: { type: 'string', description: 'HTML body of a knowledge article' }, + }, } export const ServiceNowBlockMeta = { diff --git a/apps/sim/blocks/blocks/sftp.test.ts b/apps/sim/blocks/blocks/sftp.test.ts new file mode 100644 index 00000000000..6d8570a2308 --- /dev/null +++ b/apps/sim/blocks/blocks/sftp.test.ts @@ -0,0 +1,59 @@ +import { describe, expect, it } from 'vitest' +import { SftpBlock, SftpV2Block } from '@/blocks/blocks/sftp' + +describe('SFTP block versions', () => { + it('preserves legacy blocks and offers v2 for new blocks', () => { + expect(SftpBlock.hideFromToolbar).toBe(true) + expect(SftpBlock.sunset).toEqual({ status: 'legacy', replacedBy: 'sftp_v2' }) + expect(SftpV2Block.hideFromToolbar).toBe(false) + expect(SftpV2Block.sunset).toBeUndefined() + expect(SftpV2Block.name).toBe('SFTP') + expect(SftpV2Block.canvasPresentation).toBe(SftpBlock.canvasPresentation) + }) + + it.each(SftpBlock.tools.access)('versions only the download operation: %s', (operation) => { + const currentId = operation === 'sftp_download' ? 'sftp_download_v2' : operation + expect(SftpBlock.tools.config.tool({ operation })).toBe(operation) + expect(SftpV2Block.tools.config?.tool({ operation })).toBe(currentId) + expect(SftpV2Block.tools.access).toContain(currentId) + }) + + it('preserves defaults and the create-file alias', () => { + expect(SftpV2Block.tools.config?.tool({})).toBe('sftp_upload') + expect(SftpV2Block.tools.config?.tool({ operation: 'sftp_create' })).toBe('sftp_upload') + }) + + it('removes download encoding and inline content from v2', () => { + expect(SftpBlock.subBlocks.some((subBlock) => subBlock.id === 'encoding')).toBe(true) + expect(SftpV2Block.subBlocks.some((subBlock) => subBlock.id === 'encoding')).toBe(false) + expect(SftpV2Block.inputs).not.toHaveProperty('encoding') + expect(SftpV2Block.outputs).not.toHaveProperty('content') + expect(SftpV2Block.outputs).not.toHaveProperty('fileName') + expect(SftpV2Block.outputs).not.toHaveProperty('size') + for (const key of ['success', 'message']) { + expect(SftpV2Block.outputs[key].condition).toEqual({ + field: 'operation', + value: 'sftp_download', + not: true, + }) + } + expect(SftpV2Block.outputs.file.type).toBe('file') + const params = { + operation: 'sftp_download', + host: 'sftp.example.com', + port: '22', + username: 'user', + password: 'test-password', + remotePath: '/file.txt', + encoding: 'base64', + } + expect(SftpBlock.tools.config.params(params)).toHaveProperty('encoding', 'base64') + expect(SftpV2Block.tools.config?.params?.(params)).toEqual({ + host: 'sftp.example.com', + port: 22, + username: 'user', + password: 'test-password', + remotePath: '/file.txt', + }) + }) +}) diff --git a/apps/sim/blocks/blocks/sftp.ts b/apps/sim/blocks/blocks/sftp.ts index 62181bdaabb..a4132d27565 100644 --- a/apps/sim/blocks/blocks/sftp.ts +++ b/apps/sim/blocks/blocks/sftp.ts @@ -1,13 +1,16 @@ import { ClipboardList, Download, File, Search, Server, Trash, Upload } from '@sim/emcn/icons' +import { omit } from '@sim/utils/object' import { SftpIcon } from '@/components/icons' import type { BlockConfig, BlockMeta } from '@/blocks/types' import { AuthMode, IntegrationType } from '@/blocks/types' -import { normalizeFileInput } from '@/blocks/utils' +import { createVersionedToolSelector, normalizeFileInput } from '@/blocks/utils' import type { SftpUploadResult } from '@/tools/sftp/types' -export const SftpBlock: BlockConfig = { +export const SftpBlock = { type: 'sftp', - name: 'SFTP', + name: 'SFTP (Legacy)', + hideFromToolbar: true, + sunset: { status: 'legacy', replacedBy: 'sftp_v2' }, description: 'Transfer files via SFTP (SSH File Transfer Protocol)', longDescription: 'Upload, download, list, and manage files on remote servers via SFTP. Supports both password and private key authentication for secure file transfers.', @@ -332,6 +335,50 @@ export const SftpBlock: BlockConfig = { message: { type: 'string', description: 'Operation status message' }, error: { type: 'string', description: 'Error message if operation failed' }, }, +} satisfies BlockConfig + +const selectSftpV2Tool = createVersionedToolSelector({ + baseToolSelector: SftpBlock.tools.config.tool, + suffix: '_v2', + fallbackToolId: 'sftp_download_v2', +}) + +export const SftpV2Block: BlockConfig = { + ...SftpBlock, + type: 'sftp_v2', + name: 'SFTP', + hideFromToolbar: false, + sunset: undefined, + subBlocks: SftpBlock.subBlocks.filter((subBlock) => subBlock.id !== 'encoding'), + tools: { + ...SftpBlock.tools, + access: SftpBlock.tools.access.map((toolId) => + toolId === 'sftp_download' ? 'sftp_download_v2' : toolId + ), + config: { + ...SftpBlock.tools.config, + tool: (params) => + params.operation === 'sftp_download' + ? selectSftpV2Tool(params) + : SftpBlock.tools.config.tool(params), + params: (params) => { + const input: Record = SftpBlock.tools.config.params(params) + return omit(input, ['encoding']) + }, + }, + }, + inputs: omit(SftpBlock.inputs, ['encoding']), + outputs: { + ...omit(SftpBlock.outputs, ['content', 'fileName', 'size']), + success: { + ...SftpBlock.outputs.success, + condition: { field: 'operation', value: 'sftp_download', not: true }, + }, + message: { + ...SftpBlock.outputs.message, + condition: { field: 'operation', value: 'sftp_download', not: true }, + }, + }, } export const SftpBlockMeta = { @@ -416,7 +463,7 @@ export const SftpBlockMeta = { name: 'pull-remote-drop-folder', description: 'Poll a remote SFTP drop folder on a schedule and ingest any new files.', content: - '# Pull Remote Drop Folder\n\nPeriodically fetch newly arrived files from a remote SFTP directory into a workflow.\n\n## Steps\n1. Use the List Directory operation to read the remote drop folder and inspect `entries`.\n2. Filter for files newer than the last processed timestamp.\n3. For each new file, use the Download File operation and read `file`/`content`.\n4. Hand the contents to downstream blocks for parsing.\n\n## Output\nNew remote files are downloaded and their contents are available for processing each run.', + '# Pull Remote Drop Folder\n\nPeriodically fetch newly arrived files from a remote SFTP directory into a workflow.\n\n## Steps\n1. Use the List Directory operation to read the remote drop folder and inspect `entries`.\n2. Filter for files newer than the last processed timestamp.\n3. For each new file, use the Download File operation and read `file`.\n4. Pass the file to downstream blocks for parsing.\n\n## Output\nNew remote files are downloaded and available for processing each run.', }, { name: 'push-report-to-partner', diff --git a/apps/sim/blocks/blocks/ssh.test.ts b/apps/sim/blocks/blocks/ssh.test.ts new file mode 100644 index 00000000000..a49753c3c08 --- /dev/null +++ b/apps/sim/blocks/blocks/ssh.test.ts @@ -0,0 +1,39 @@ +import { describe, expect, it } from 'vitest' +import { SSHBlock, SSHV2Block } from '@/blocks/blocks/ssh' + +describe('SSH block versions', () => { + it('preserves legacy blocks and offers v2 for new blocks', () => { + expect(SSHBlock.hideFromToolbar).toBe(true) + expect(SSHBlock.sunset).toEqual({ status: 'legacy', replacedBy: 'ssh_v2' }) + expect(SSHV2Block.hideFromToolbar).toBe(false) + expect(SSHV2Block.sunset).toBeUndefined() + expect(SSHV2Block.name).toBe('SSH') + expect(SSHV2Block.subBlocks).toBe(SSHBlock.subBlocks) + expect(SSHV2Block.tools.config?.params).toBe(SSHBlock.tools.config.params) + expect(SSHV2Block.canvasPresentation).toBe(SSHBlock.canvasPresentation) + }) + + it.each(SSHBlock.tools.access)('versions only the download operation: %s', (operation) => { + const currentId = operation === 'ssh_download_file' ? 'ssh_download_file_v2' : operation + expect(SSHBlock.tools.config.tool({ operation })).toBe(operation) + expect(SSHV2Block.tools.config?.tool({ operation })).toBe(currentId) + expect(SSHV2Block.tools.access).toContain(currentId) + }) + + it('preserves the command default and explicit read-content operation', () => { + expect(SSHV2Block.tools.config?.tool({})).toBe('ssh_execute_command') + expect(SSHV2Block.outputs).not.toHaveProperty('fileContent') + expect(SSHV2Block.outputs.file.type).toBe('file') + expect(SSHV2Block.outputs.content.condition).toEqual({ + field: 'operation', + value: 'ssh_read_file_content', + }) + for (const key of ['success', 'message']) { + expect(SSHV2Block.outputs[key].condition).toEqual({ + field: 'operation', + value: 'ssh_download_file', + not: true, + }) + } + }) +}) diff --git a/apps/sim/blocks/blocks/ssh.ts b/apps/sim/blocks/blocks/ssh.ts index a991a0ea6c8..c49a3a4de0c 100644 --- a/apps/sim/blocks/blocks/ssh.ts +++ b/apps/sim/blocks/blocks/ssh.ts @@ -1,12 +1,16 @@ import { ClipboardList, Download, File, Search, Server, Wrench } from '@sim/emcn/icons' +import { omit } from '@sim/utils/object' import { SshIcon, SshTerminalIcon } from '@/components/icons' import type { BlockConfig, BlockMeta } from '@/blocks/types' import { AuthMode, IntegrationType } from '@/blocks/types' +import { createVersionedToolSelector } from '@/blocks/utils' import type { SSHResponse } from '@/tools/ssh/types' -export const SSHBlock: BlockConfig = { +export const SSHBlock = { type: 'ssh', - name: 'SSH', + name: 'SSH (Legacy)', + hideFromToolbar: true, + sunset: { status: 'legacy', replacedBy: 'ssh_v2' }, description: 'Connect to remote servers via SSH', authMode: AuthMode.ApiKey, longDescription: @@ -661,6 +665,48 @@ Examples: os: { type: 'string', description: 'Operating system' }, message: { type: 'string', description: 'Operation status message' }, }, +} satisfies BlockConfig + +const selectSshV2Tool = createVersionedToolSelector({ + baseToolSelector: SSHBlock.tools.config.tool, + suffix: '_v2', + fallbackToolId: 'ssh_download_file_v2', +}) + +export const SSHV2Block: BlockConfig = { + ...SSHBlock, + type: 'ssh_v2', + name: 'SSH', + hideFromToolbar: false, + sunset: undefined, + tools: { + ...SSHBlock.tools, + access: SSHBlock.tools.access.map((toolId) => + toolId === 'ssh_download_file' ? 'ssh_download_file_v2' : toolId + ), + config: { + ...SSHBlock.tools.config, + tool: (params) => + params.operation === 'ssh_download_file' + ? selectSshV2Tool(params) + : SSHBlock.tools.config.tool(params), + }, + }, + outputs: { + ...omit(SSHBlock.outputs, ['fileContent']), + success: { + ...SSHBlock.outputs.success, + condition: { field: 'operation', value: 'ssh_download_file', not: true }, + }, + message: { + ...SSHBlock.outputs.message, + condition: { field: 'operation', value: 'ssh_download_file', not: true }, + }, + content: { + ...SSHBlock.outputs.content, + condition: { field: 'operation', value: 'ssh_read_file_content' }, + }, + }, } export const SSHBlockMeta = { diff --git a/apps/sim/blocks/registry-maps.ts b/apps/sim/blocks/registry-maps.ts index 672ebb5e0e1..b75dc96d948 100644 --- a/apps/sim/blocks/registry-maps.ts +++ b/apps/sim/blocks/registry-maps.ts @@ -25,7 +25,7 @@ import { } from '@/blocks/blocks/azure_data_explorer' import { AzureDevOpsBlock, AzureDevOpsBlockMeta } from '@/blocks/blocks/azure_devops' import { BitbucketBlock, BitbucketBlockMeta } from '@/blocks/blocks/bitbucket' -import { BoxBlock, BoxBlockMeta } from '@/blocks/blocks/box' +import { BoxBlock, BoxBlockMeta, BoxV2Block } from '@/blocks/blocks/box' import { BrandfetchBlock, BrandfetchBlockMeta } from '@/blocks/blocks/brandfetch' import { BrexBlock, BrexBlockMeta } from '@/blocks/blocks/brex' import { BrightDataBlock, BrightDataBlockMeta } from '@/blocks/blocks/brightdata' @@ -64,10 +64,10 @@ import { DevinBlock, DevinBlockMeta } from '@/blocks/blocks/devin' import { DiscordBlock, DiscordBlockMeta } from '@/blocks/blocks/discord' import { DocuSignBlock, DocuSignBlockMeta } from '@/blocks/blocks/docusign' import { DowndetectorBlock, DowndetectorBlockMeta } from '@/blocks/blocks/downdetector' -import { DropboxBlock, DropboxBlockMeta } from '@/blocks/blocks/dropbox' +import { DropboxBlock, DropboxBlockMeta, DropboxV2Block } from '@/blocks/blocks/dropbox' import { DropcontactBlock, DropcontactBlockMeta } from '@/blocks/blocks/dropcontact' import { DSPyBlock, DSPyBlockMeta } from '@/blocks/blocks/dspy' -import { DubBlock, DubBlockMeta } from '@/blocks/blocks/dub' +import { DubBlock, DubBlockMeta, DubV2Block } from '@/blocks/blocks/dub' import { DuckDuckGoBlock, DuckDuckGoBlockMeta } from '@/blocks/blocks/duckduckgo' import { DynamoDBBlock, DynamoDBBlockMeta } from '@/blocks/blocks/dynamodb' import { DynatraceBlock, DynatraceBlockMeta } from '@/blocks/blocks/dynatrace' @@ -173,7 +173,7 @@ import { JiraServiceManagementBlockMeta, } from '@/blocks/blocks/jira_service_management' import { JotformBlock, JotformBlockMeta } from '@/blocks/blocks/jotform' -import { JupyterBlock, JupyterBlockMeta } from '@/blocks/blocks/jupyter' +import { JupyterBlock, JupyterBlockMeta, JupyterV2Block } from '@/blocks/blocks/jupyter' import { KalshiBlock, KalshiBlockMeta, @@ -209,6 +209,7 @@ import { MicrosoftAdBlock, MicrosoftAdBlockMeta } from '@/blocks/blocks/microsof import { MicrosoftDataverseBlock, MicrosoftDataverseBlockMeta, + MicrosoftDataverseV2Block, } from '@/blocks/blocks/microsoft_dataverse' import { MicrosoftDynamics365Block, @@ -272,7 +273,7 @@ import { PulseBlock, PulseBlockMeta, PulseV2Block } from '@/blocks/blocks/pulse' import { QdrantBlock, QdrantBlockMeta } from '@/blocks/blocks/qdrant' import { QuartrBlock, QuartrBlockMeta } from '@/blocks/blocks/quartr' import { QuickBooksBlock, QuickBooksBlockMeta } from '@/blocks/blocks/quickbooks' -import { QuiverBlock, QuiverBlockMeta } from '@/blocks/blocks/quiver' +import { QuiverBlock, QuiverBlockMeta, QuiverV2Block } from '@/blocks/blocks/quiver' import { RabbitmqBlock, RabbitmqBlockMeta } from '@/blocks/blocks/rabbitmq' import { RailwayBlock, RailwayBlockMeta } from '@/blocks/blocks/railway' import { RB2BBlock, RB2BBlockMeta } from '@/blocks/blocks/rb2b' @@ -301,9 +302,9 @@ import { SendblueBlock, SendblueBlockMeta } from '@/blocks/blocks/sendblue' import { SendGridBlock, SendGridBlockMeta } from '@/blocks/blocks/sendgrid' import { SentryBlock, SentryBlockMeta } from '@/blocks/blocks/sentry' import { SerperBlock, SerperBlockMeta } from '@/blocks/blocks/serper' -import { ServiceNowBlock, ServiceNowBlockMeta } from '@/blocks/blocks/servicenow' +import { ServiceNowBlock, ServiceNowBlockMeta, ServiceNowV2Block } from '@/blocks/blocks/servicenow' import { SESBlock, SESBlockMeta } from '@/blocks/blocks/ses' -import { SftpBlock, SftpBlockMeta } from '@/blocks/blocks/sftp' +import { SftpBlock, SftpBlockMeta, SftpV2Block } from '@/blocks/blocks/sftp' import { SharepointBlock, SharepointBlockMeta, SharepointV2Block } from '@/blocks/blocks/sharepoint' import { ShopifyBlock, ShopifyBlockMeta } from '@/blocks/blocks/shopify' import { SimWorkspaceEventBlock } from '@/blocks/blocks/sim_workspace_event' @@ -318,7 +319,7 @@ import { SportmonksBlock, SportmonksBlockMeta } from '@/blocks/blocks/sportmonks import { SpotifyBlock, SpotifyBlockMeta } from '@/blocks/blocks/spotify' import { SQSBlock, SQSBlockMeta } from '@/blocks/blocks/sqs' import { SquareBlock, SquareBlockMeta } from '@/blocks/blocks/square' -import { SSHBlock, SSHBlockMeta } from '@/blocks/blocks/ssh' +import { SSHBlock, SSHBlockMeta, SSHV2Block } from '@/blocks/blocks/ssh' import { SSMBlock, SSMBlockMeta } from '@/blocks/blocks/ssm' import { StagehandBlock, StagehandBlockMeta } from '@/blocks/blocks/stagehand' import { StartTriggerBlock } from '@/blocks/blocks/start_trigger' @@ -406,6 +407,7 @@ export const BLOCK_REGISTRY: Record = { azure_devops: AzureDevOpsBlock, bitbucket: BitbucketBlock, box: BoxBlock, + box_v2: BoxV2Block, brandfetch: BrandfetchBlock, brex: BrexBlock, brightdata: BrightDataBlock, @@ -447,9 +449,11 @@ export const BLOCK_REGISTRY: Record = { docusign: DocuSignBlock, downdetector: DowndetectorBlock, dropbox: DropboxBlock, + dropbox_v2: DropboxV2Block, dropcontact: DropcontactBlock, dspy: DSPyBlock, dub: DubBlock, + dub_v2: DubV2Block, duckduckgo: DuckDuckGoBlock, dynamodb: DynamoDBBlock, dynatrace: DynatraceBlock, @@ -541,6 +545,7 @@ export const BLOCK_REGISTRY: Record = { jira_service_management: JiraServiceManagementBlock, jotform: JotformBlock, jupyter: JupyterBlock, + jupyter_v2: JupyterV2Block, kalshi: KalshiBlock, kalshi_v2: KalshiV2Block, ketch: KetchBlock, @@ -572,6 +577,7 @@ export const BLOCK_REGISTRY: Record = { memory: MemoryBlock, microsoft_ad: MicrosoftAdBlock, microsoft_dataverse: MicrosoftDataverseBlock, + microsoft_dataverse_v2: MicrosoftDataverseV2Block, microsoft_dynamics_365: MicrosoftDynamics365Block, microsoft_excel: MicrosoftExcelBlock, microsoft_excel_v2: MicrosoftExcelV2Block, @@ -620,6 +626,7 @@ export const BLOCK_REGISTRY: Record = { quartr: QuartrBlock, quickbooks: QuickBooksBlock, quiver: QuiverBlock, + quiver_v2: QuiverV2Block, rabbitmq: RabbitmqBlock, railway: RailwayBlock, rb2b: RB2BBlock, @@ -651,8 +658,10 @@ export const BLOCK_REGISTRY: Record = { sentry: SentryBlock, serper: SerperBlock, servicenow: ServiceNowBlock, + servicenow_v2: ServiceNowV2Block, ses: SESBlock, sftp: SftpBlock, + sftp_v2: SftpV2Block, sharepoint: SharepointBlock, sharepoint_v2: SharepointV2Block, shopify: ShopifyBlock, @@ -670,6 +679,7 @@ export const BLOCK_REGISTRY: Record = { sqs: SQSBlock, square: SquareBlock, ssh: SSHBlock, + ssh_v2: SSHV2Block, ssm: SSMBlock, stagehand: StagehandBlock, start_trigger: StartTriggerBlock, @@ -875,6 +885,7 @@ export const BLOCK_META_REGISTRY: Record = { jira_service_management: JiraServiceManagementBlockMeta, jotform: JotformBlockMeta, jupyter: JupyterBlockMeta, + jupyter_v2: JupyterBlockMeta, kalshi: KalshiBlockMeta, kalshi_v2: KalshiV2BlockMeta, ketch: KetchBlockMeta, @@ -970,6 +981,7 @@ export const BLOCK_META_REGISTRY: Record = { servicenow: ServiceNowBlockMeta, ses: SESBlockMeta, sftp: SftpBlockMeta, + sftp_v2: SftpBlockMeta, sharepoint: SharepointBlockMeta, shopify: ShopifyBlockMeta, similarweb: SimilarwebBlockMeta, @@ -985,6 +997,7 @@ export const BLOCK_META_REGISTRY: Record = { sqs: SQSBlockMeta, square: SquareBlockMeta, ssh: SSHBlockMeta, + ssh_v2: SSHBlockMeta, ssm: SSMBlockMeta, stagehand: StagehandBlockMeta, stripe: StripeBlockMeta, diff --git a/apps/sim/executor/utils/file-tool-processor.aliases.test.ts b/apps/sim/executor/utils/file-tool-processor.aliases.test.ts new file mode 100644 index 00000000000..040c338e00c --- /dev/null +++ b/apps/sim/executor/utils/file-tool-processor.aliases.test.ts @@ -0,0 +1,107 @@ +/** + * @vitest-environment node + */ +import { describe, expect, it, vi } from 'vitest' +import type { UserFile } from '@/executor/types' +import type { ToolDefinition } from '@/tools/types' + +vi.mock('@/lib/internal/tool-operations/file-result.server', () => ({ + storeInternalToolFileResult: vi.fn(), +})) +vi.mock('@/lib/uploads/utils/file-utils.server', () => ({ downloadFileFromUrl: vi.fn() })) + +import { FileToolProcessor } from '@/executor/utils/file-tool-processor' + +const STORED_FILE: UserFile = { + id: 'file-1', + key: 'execution/file-1', + url: '/api/files/serve/execution/file-1', + name: 'notes.txt', + type: 'text/plain', + size: 5, + base64: 'aGVsbG8=', +} +const TOOL: ToolDefinition = { + id: 'alias-test', + name: 'Alias Test', + description: 'File aliases', + version: '1.0.0', + params: {}, + outputs: { file: { type: 'file', description: 'Stored file' } }, +} +const CONTEXT = { workflowId: 'workflow-1', executionId: 'execution-1', workspaceId: 'workspace-1' } + +describe('file output alias replacement', () => { + it('handles deeply nested, small JSON metadata without recursive stack growth', async () => { + const depth = 20_000 + const json = `${'{"child":'.repeat(depth)}null${'}'.repeat(depth)}` + const metadata: Record = JSON.parse(json) + const result = await FileToolProcessor.processToolOutputs( + { file: STORED_FILE, metadata }, + TOOL, + CONTEXT + ) + + expect(json.length).toBeLessThan(1024 * 1024) + expect(result.file).not.toHaveProperty('base64') + expect(result.metadata === metadata).toBe(false) + let cursor: unknown = result.metadata + let actualDepth = 0 + while (cursor && typeof cursor === 'object' && 'child' in cursor) { + actualDepth++ + cursor = cursor.child + } + expect(actualDepth).toBe(depth) + expect(cursor).toBeNull() + }) + + it('preserves cycles and shared aliases while replacing every reference to the file', async () => { + const shared = { file: STORED_FILE } + const input: Record = { + file: STORED_FILE, + messages: [shared, shared], + } + input.self = input + const result = await FileToolProcessor.processToolOutputs(input, TOOL, CONTEXT) + expect(result.self).toBe(result) + const messages = result.messages as Array<{ file: UserFile }> + expect(messages[0]).toBe(messages[1]) + expect(messages[0]?.file).toBe(result.file) + expect(result.file).not.toHaveProperty('base64') + expect(STORED_FILE.base64).toBe('aGVsbG8=') + expect(input.self).toBe(input) + }) + + it('keeps buffers, stored files, and non-plain objects as leaves', async () => { + const buffer = Buffer.alloc(12 * 1024 * 1024) + const date = new Date('2026-01-01') + const existing = { ...STORED_FILE, id: 'existing-file', base64: undefined } + const result = await FileToolProcessor.processToolOutputs( + { file: STORED_FILE, metadata: { buffer, date, existing } }, + TOOL, + CONTEXT + ) + const metadata = result.metadata as Record + expect(metadata.buffer).toBe(buffer) + expect(metadata.date).toBe(date) + expect(metadata.existing).toBe(existing) + }) + + it('preserves null prototypes and own __proto__ keys without modifying prototypes', async () => { + const metadata: Record = Object.create(null) + metadata.file = STORED_FILE + const keys = JSON.parse('{"__proto__":{"file":null}}') + keys.__proto__.file = STORED_FILE + const result = await FileToolProcessor.processToolOutputs( + { file: STORED_FILE, metadata, keys }, + TOOL, + CONTEXT + ) + expect(Object.getPrototypeOf(result.metadata)).toBeNull() + const copiedKeys = result.keys as Record + expect(Object.getPrototypeOf(copiedKeys)).toBe(Object.prototype) + expect(Object.hasOwn(copiedKeys, '__proto__')).toBe(true) + expect((copiedKeys.__proto__ as Record).file).toBe(result.file) + expect({}).not.toHaveProperty('file') + }) +}) diff --git a/apps/sim/executor/utils/file-tool-processor.context.test.ts b/apps/sim/executor/utils/file-tool-processor.context.test.ts new file mode 100644 index 00000000000..84d36d284a9 --- /dev/null +++ b/apps/sim/executor/utils/file-tool-processor.context.test.ts @@ -0,0 +1,167 @@ +/** + * @vitest-environment node + */ +import { beforeEach, describe, expect, it, vi } from 'vitest' +import type { InternalToolOperationContext } from '@/lib/internal/tool-operations/types' +import { MAX_FILE_SIZE } from '@/lib/uploads/utils/validation' +import type { UserFile } from '@/executor/types' +import type { ToolConfig } from '@/tools/types' + +const mocks = vi.hoisted(() => ({ + download: vi.fn(), + uploadExecution: vi.fn(), + uploadCopilot: vi.fn(), + deleteFile: vi.fn(), + deleteMetadata: vi.fn(), +})) + +vi.mock('@/lib/uploads/utils/file-utils.server', () => ({ downloadFileFromUrl: mocks.download })) +vi.mock('@/lib/uploads/contexts/execution', () => ({ uploadExecutionFile: mocks.uploadExecution })) +vi.mock('@/lib/uploads/contexts/copilot', () => ({ uploadCopilotFile: mocks.uploadCopilot })) +vi.mock('@/lib/uploads/core/storage-service', () => ({ deleteFile: mocks.deleteFile })) +vi.mock('@/lib/uploads/server/metadata', () => ({ deleteFileMetadata: mocks.deleteMetadata })) + +import { FileToolProcessor } from '@/executor/utils/file-tool-processor' + +const context: InternalToolOperationContext = { + workflowId: '', + userId: 'actor-1', + workspaceId: 'workspace-1', + copilotToolExecution: true, +} +const tool = { + id: 'test_attachments', + name: 'Test attachments', + description: 'Downloads message attachments', + version: '1.0.0', + params: {}, + request: { url: 'https://example.com/messages', method: 'GET' }, + outputs: { files: { type: 'file[]' } }, +} satisfies ToolConfig + +const stored: UserFile = { + id: 'file-1', + key: 'copilot/actor-1/file-1/workbook.xlsx', + name: 'workbook.xlsx', + type: 'application/octet-stream', + size: 12 * 1024 * 1024, + url: 'https://storage.example/workbook.xlsx', + context: 'copilot', +} + +describe('file output processing across trusted contexts', () => { + beforeEach(() => { + vi.resetAllMocks() + mocks.uploadCopilot.mockResolvedValue(stored) + }) + + it('stores a large late attachment once and replaces every nested alias for Copilot', async () => { + const bytes = Buffer.alloc(12 * 1024 * 1024) + const attachment = { name: 'workbook.xlsx', contentType: stored.type, data: bytes } + const input = { files: [attachment, attachment], results: [{ attachments: [attachment] }] } + + const result = await FileToolProcessor.processToolOutputs(input, tool, context) + + expect(result).toEqual({ files: [stored, stored], results: [{ attachments: [stored] }] }) + expect((result.files as UserFile[])[0]).toBe(stored) + expect(mocks.uploadCopilot).toHaveBeenCalledOnce() + expect(mocks.uploadCopilot.mock.calls[0]?.[0].buffer).toBe(bytes) + expect(mocks.uploadCopilot.mock.calls[0]?.[0].userId).toBe('actor-1') + expect(mocks.uploadExecution).not.toHaveBeenCalled() + expect(JSON.stringify(result).length).toBeLessThan(2048) + expect(input.results[0]?.attachments[0]?.data).toBe(bytes) + }) + + it('rejects an aggregate over budget before uploading any file', async () => { + const first = Buffer.alloc(1) + Object.defineProperty(first, 'length', { value: MAX_FILE_SIZE }) + await expect( + FileToolProcessor.processToolOutputs( + { + files: [ + { name: 'first.bin', data: first }, + { name: 'second.bin', data: Buffer.alloc(1) }, + ], + }, + tool, + context + ) + ).rejects.toThrow('exceeds the maximum allowed size') + expect(mocks.uploadCopilot).not.toHaveBeenCalled() + }) + + it('validates all files before creating storage objects', async () => { + await expect( + FileToolProcessor.processToolOutputs( + { + files: [ + { name: 'valid.txt', data: Buffer.from('valid') }, + { name: 'invalid.txt', data: '?' }, + ], + }, + tool, + context + ) + ).rejects.toThrow('invalid base64') + expect(mocks.uploadCopilot).not.toHaveBeenCalled() + }) + + it('passes the remaining aggregate budget and cancellation signal to URL downloads', async () => { + const controller = new AbortController() + mocks.download.mockImplementation(async () => { + controller.abort(new Error('Download cancelled')) + return Buffer.alloc(1) + }) + await expect( + FileToolProcessor.processToolOutputs( + { + files: [ + { name: 'first.txt', data: Buffer.alloc(3) }, + { name: 'second.txt', url: 'https://example.com/file' }, + ], + }, + tool, + context, + controller.signal + ) + ).rejects.toThrow('Download cancelled') + expect(mocks.download).toHaveBeenCalledWith('https://example.com/file', { + userId: 'actor-1', + maxBytes: MAX_FILE_SIZE - 3, + signal: controller.signal, + }) + expect(mocks.uploadCopilot).not.toHaveBeenCalled() + }) + + it('removes materialized base64 from existing references and their nested aliases', async () => { + const materialized = { ...stored, base64: 'c2VjcmV0' } + const result = await FileToolProcessor.processToolOutputs( + { files: [materialized], messages: [{ file: materialized }] }, + tool, + context + ) + expect(result).toEqual({ files: [stored], messages: [{ file: stored }] }) + expect(mocks.uploadCopilot).not.toHaveBeenCalled() + expect(mocks.download).not.toHaveBeenCalled() + }) + + it('rolls back an unpublished attachment if a later upload fails', async () => { + mocks.uploadCopilot + .mockResolvedValueOnce(stored) + .mockRejectedValueOnce(new Error('Storage down')) + await expect( + FileToolProcessor.processToolOutputs( + { + files: [ + { name: 'first.txt', data: Buffer.from('a') }, + { name: 'second.txt', data: Buffer.from('b') }, + ], + }, + tool, + context + ) + ).rejects.toThrow('Storage down') + expect(mocks.deleteFile).toHaveBeenCalledWith({ key: stored.key, context: 'copilot' }) + expect(mocks.deleteMetadata).toHaveBeenCalledWith(stored.key) + }) +}) diff --git a/apps/sim/executor/utils/file-tool-processor.test.ts b/apps/sim/executor/utils/file-tool-processor.test.ts index 549dbedf2a2..a32cee604bf 100644 --- a/apps/sim/executor/utils/file-tool-processor.test.ts +++ b/apps/sim/executor/utils/file-tool-processor.test.ts @@ -57,6 +57,28 @@ describe('FileToolProcessor', () => { } satisfies UserFile) }) + it('passes stored file descriptors through without downloading or uploading again', async () => { + const stored: UserFile = { + id: 'file-1', + key: 'execution/workspace-1/workflow-1/execution-1/file-1/workbook.xlsx', + name: 'workbook.xlsx', + size: 12 * 1024 * 1024, + type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + url: 'https://storage.example/workbook.xlsx', + context: 'execution', + } + + const result = await FileToolProcessor.processToolOutputs( + { file: stored }, + toolConfig, + executionContext + ) + + expect(result.file).toBe(stored) + expect(mockUploadExecutionFile).not.toHaveBeenCalled() + expect(mockDownloadFileFromUrl).not.toHaveBeenCalled() + }) + it('caps URL downloads and stores raster images using byte-derived metadata', async () => { const png = Buffer.concat([ Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]), diff --git a/apps/sim/executor/utils/file-tool-processor.ts b/apps/sim/executor/utils/file-tool-processor.ts index d66dea14763..e81a2134539 100644 --- a/apps/sim/executor/utils/file-tool-processor.ts +++ b/apps/sim/executor/utils/file-tool-processor.ts @@ -1,265 +1,219 @@ import { createLogger } from '@sim/logger' import { toError } from '@sim/utils/errors' +import { omit } from '@sim/utils/object' import { isCanonicalBase64 } from '@/lib/api/contracts/primitives' -import { isUserFile } from '@/lib/core/utils/user-file' -import { uploadExecutionFile, uploadFileFromRawData } from '@/lib/uploads/contexts/execution' +import { isUserFile, type UserFileLike } from '@/lib/core/utils/user-file' +import { + createInternalToolFilesResult, + type InternalToolFile, +} from '@/lib/internal/tool-operations/file-result' +import { storeInternalToolFileResult } from '@/lib/internal/tool-operations/file-result.server' +import type { InternalToolOperationContext } from '@/lib/internal/tool-operations/types' import { downloadFileFromUrl } from '@/lib/uploads/utils/file-utils.server' -import { MAX_FILE_SIZE, sniffImageContentType } from '@/lib/uploads/utils/validation' -import type { ExecutionContext, UserFile } from '@/executor/types' -import type { ToolDefinition, ToolFileData } from '@/tools/types' +import { MAX_FILE_SIZE } from '@/lib/uploads/utils/validation' +import type { UserFile } from '@/executor/types' +import type { ToolDefinition } from '@/tools/types' const logger = createLogger('FileToolProcessor') -const IMAGE_FILE_EXTENSIONS: Record = { - 'image/gif': 'gif', - 'image/jpeg': 'jpg', - 'image/png': 'png', - 'image/webp': 'webp', +function isRecord(value: unknown): value is Record { + return typeof value === 'object' && value !== null && !Array.isArray(value) } -/** - * Strip a base64 `data:` URI prefix, leaving the encoded payload. An empty payload is - * a legitimate zero-byte file; a payload that only looks empty after normalization is - * not, so callers compare against what this returns rather than the raw value. - */ +/** Strip a data URI prefix while preserving legitimate zero-byte payloads. */ function stripBase64DataUri(value: string): string { return /^data:[^,]*;base64,/i.test(value) ? value.slice(value.indexOf(',') + 1) : value } -/** - * Normalize a base64 payload to canonical RFC 4648 form so it can be validated: drop - * the line wrapping MIME encoders emit, translate the base64url alphabet, and restore - * the padding unpadded encoders omit. - */ +/** Normalize wrapped or unpadded base64url into canonical RFC 4648 form. */ function normalizeBase64(payload: string): string { const compact = payload.replace(/\s/g, '').replace(/-/g, '+').replace(/_/g, '/') const remainder = compact.length % 4 return remainder === 0 ? compact : compact + '='.repeat(4 - remainder) } -function assertFileSize(size: number, fileName: string): void { - if (size > MAX_FILE_SIZE) { - throw new Error(`File '${fileName}' exceeds the maximum allowed size of ${MAX_FILE_SIZE} bytes`) +function assertFileSize(size: number, name: string, remainingBytes: number): void { + if (size > remainingBytes) { + throw new Error(`File '${name}' exceeds the maximum allowed size of ${remainingBytes} bytes`) } } -function resolveStoredFileMetadata( - fileName: string, - declaredMimeType: string, - buffer: Buffer -): { fileName: string; mimeType: string } { - if (!declaredMimeType.startsWith('image/')) { - return { fileName, mimeType: declaredMimeType } - } - - const mimeType = sniffImageContentType(buffer) - if (!mimeType) { - return { - fileName: `${fileName.replace(/\.[^.]+$/, '')}.bin`, - mimeType: 'application/octet-stream', +/** Replaces aliases by identity, preserving message-to-file associations without inline bytes. */ +function replaceFileReferences( + value: unknown, + replacements: ReadonlyMap, + visited = new WeakMap() +): unknown { + type PendingCopy = + | { kind: 'array'; source: unknown[]; target: unknown[] } + | { kind: 'object'; source: object; target: Record } + const pending: PendingCopy[] = [] + + function copyOrReplace(item: unknown): unknown { + if (typeof item !== 'object' || item === null) return item + const replacement = replacements.get(item) + if (replacement) return replacement + if (isUserFile(item) || Buffer.isBuffer(item)) return item + if (visited.has(item)) return visited.get(item) + if (Array.isArray(item)) { + const target: unknown[] = [] + visited.set(item, target) + pending.push({ kind: 'array', source: item, target }) + return target } + const prototype = Object.getPrototypeOf(item) + if (prototype !== Object.prototype && prototype !== null) return item + const target: Record = Object.create(prototype) + visited.set(item, target) + pending.push({ kind: 'object', source: item, target }) + return target } - const extension = IMAGE_FILE_EXTENSIONS[mimeType] - return { - fileName: extension ? `${fileName.replace(/\.[^.]+$/, '')}.${extension}` : fileName, - mimeType, + const result = copyOrReplace(value) + while (pending.length > 0) { + const copy = pending.pop()! + if (copy.kind === 'array') { + for (const item of copy.source) copy.target.push(copyOrReplace(item)) + } else { + for (const [key, item] of Object.entries(copy.source)) { + Object.defineProperty(copy.target, key, { + value: copyOrReplace(item), + enumerable: true, + writable: true, + configurable: true, + }) + } + } } + return result } -/** - * Processes tool outputs and converts file-typed outputs to UserFile objects. - * This enables tools to return file data that gets automatically stored in the - * execution filesystem and made available as UserFile objects for workflow use. - */ +/** Stores declared file outputs once, for both workflow and Copilot callers. */ export class FileToolProcessor { - /** - * Process tool outputs and convert file-typed outputs to UserFile objects - */ static async processToolOutputs( - toolOutput: any, + toolOutput: Record, toolConfig: ToolDefinition, - executionContext: ExecutionContext - ): Promise { - if (!toolConfig.outputs) { - return toolOutput - } - - const processedOutput = { ...toolOutput } + context: InternalToolOperationContext, + signal?: AbortSignal + ): Promise> { + if (!toolConfig.outputs) return toolOutput + signal?.throwIfAborted() + const pendingFiles = new Map() + const replacements = new Map() + let remainingBytes = MAX_FILE_SIZE for (const [outputKey, outputDef] of Object.entries(toolConfig.outputs)) { - if (!FileToolProcessor.isFileOutput(outputDef.type)) { - continue - } - - const fileData = processedOutput[outputKey] - if (!fileData) { - logger.warn(`File-typed output '${outputKey}' is missing from tool result`) - continue - } - + if (outputDef.type !== 'file' && outputDef.type !== 'file[]') continue + const value = toolOutput[outputKey] + if (value === undefined || value === null) continue try { - processedOutput[outputKey] = await FileToolProcessor.processFileOutput( - fileData, - outputDef.type, - outputKey, - executionContext - ) + if (outputDef.type === 'file[]' && !Array.isArray(value)) { + throw new Error(`Output '${outputKey}' is marked as file[] but is not an array`) + } + const files = outputDef.type === 'file[]' && Array.isArray(value) ? value : [value] + for (const file of files) { + signal?.throwIfAborted() + if (!isRecord(file)) throw new Error('File output must be a file object') + if (isUserFile(file)) { + if (file.base64 !== undefined) replacements.set(file, omit(file, ['base64'])) + continue + } + if (pendingFiles.has(file)) continue + const buffered = await FileToolProcessor.readFile(file, context, remainingBytes, signal) + remainingBytes -= buffered.buffer.length + pendingFiles.set(file, buffered) + } } catch (error) { + signal?.throwIfAborted() logger.error(`Error processing file output '${outputKey}':`, error) - const errorMessage = toError(error).message - throw new Error(`Failed to process file output '${outputKey}': ${errorMessage}`) + throw new Error(`Failed to process file output '${outputKey}': ${toError(error).message}`) } } - return processedOutput - } - - /** - * Check if an output type is file-related - */ - private static isFileOutput(type: string): boolean { - return type === 'file' || type === 'file[]' - } - - /** - * Process a single file output (either single file or array of files) - */ - private static async processFileOutput( - fileData: any, - outputType: string, - outputKey: string, - executionContext: ExecutionContext - ): Promise { - if (outputType === 'file[]') { - return FileToolProcessor.processFileArray(fileData, outputKey, executionContext) - } - return FileToolProcessor.processFileData(fileData, executionContext) - } - - /** - * Process an array of files - */ - private static async processFileArray( - fileData: any, - outputKey: string, - executionContext: ExecutionContext - ): Promise { - if (!Array.isArray(fileData)) { - throw new Error(`Output '${outputKey}' is marked as file[] but is not an array`) + const originals = [...pendingFiles.keys()] + const present = (files: readonly UserFile[]) => { + originals.forEach((original, index) => { + replacements.set(original, files[index]!) + }) + if (replacements.size === 0) return toolOutput + const output = replaceFileReferences(toolOutput, replacements) + if (!isRecord(output)) throw new Error('Tool file output must be an object') + return output } - - const files: UserFile[] = [] - for (const file of fileData) { - files.push(await FileToolProcessor.processFileData(file, executionContext)) - } - return files + if (pendingFiles.size === 0) return present([]) + return storeInternalToolFileResult( + createInternalToolFilesResult([...pendingFiles.values()], present), + context, + (output) => { + if (!isRecord(output)) throw new Error('Tool file output must be an object') + return output + }, + signal + ) } - /** - * Convert various file data formats to UserFile by storing in execution filesystem. - * If the input is already a UserFile, returns it unchanged. - */ - private static async processFileData( - fileData: ToolFileData | UserFile, - context: ExecutionContext - ): Promise { - // If already a UserFile (e.g., from tools that handle their own file storage), - // return it directly without re-processing - if (isUserFile(fileData)) { - return fileData as UserFile + private static async readFile( + file: Record, + context: InternalToolOperationContext, + remainingBytes: number, + signal?: AbortSignal + ): Promise { + if (typeof file.name !== 'string' || !file.name.trim()) { + throw new Error('File output requires a filename') } - - const data = fileData as ToolFileData - try { - let buffer: Buffer | null = null - - if (Buffer.isBuffer(data.data)) { - assertFileSize(data.data.length, data.name) - buffer = data.data - } else if ( - data.data && - typeof data.data === 'object' && - 'type' in data.data && - 'data' in data.data - ) { - const serializedBuffer = data.data as { type: string; data: number[] } - if (serializedBuffer.type === 'Buffer' && Array.isArray(serializedBuffer.data)) { - assertFileSize(serializedBuffer.data.length, data.name) - buffer = Buffer.from(serializedBuffer.data) - } else { - throw new Error(`Invalid serialized buffer format for ${data.name}`) - } - } else if (typeof data.data === 'string') { - const payload = stripBase64DataUri(data.data) - const base64Data = normalizeBase64(payload) - - const paddingBytes = base64Data.endsWith('==') ? 2 : base64Data.endsWith('=') ? 1 : 0 - assertFileSize(Math.floor((base64Data.length * 3) / 4) - paddingBytes, data.name) - if (!isCanonicalBase64(base64Data) || (payload.length > 0 && base64Data.length === 0)) { - throw new Error(`File '${data.name}' has invalid base64 data`) - } - buffer = Buffer.from(base64Data, 'base64') + const name = file.name + const mimeType = + (typeof file.mimeType === 'string' && file.mimeType) || + (typeof file.contentType === 'string' && file.contentType) || + 'application/octet-stream' + let buffer: Buffer | undefined + const data = file.data + + if (Buffer.isBuffer(data)) { + assertFileSize(data.length, name, remainingBytes) + buffer = data + } else if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) { + assertFileSize(data.byteLength, name, remainingBytes) + buffer = + data instanceof ArrayBuffer + ? Buffer.from(data) + : Buffer.from(data.buffer, data.byteOffset, data.byteLength) + } else if (Array.isArray(data) || (isRecord(data) && data.type === 'Buffer')) { + const bytes = Array.isArray(data) ? data : data.data + if (!Array.isArray(bytes)) throw new Error(`Invalid serialized buffer format for ${name}`) + assertFileSize(bytes.length, name, remainingBytes) + if (!bytes.every((byte) => Number.isInteger(byte) && byte >= 0 && byte <= 255)) { + throw new Error(`Invalid serialized buffer format for ${name}`) } - - if ((!buffer || buffer.length === 0) && data.url) { - buffer = await downloadFileFromUrl(data.url, { - maxBytes: MAX_FILE_SIZE, - userId: context.userId, - }) - } - - if (buffer) { - assertFileSize(buffer.length, data.name) - const storedMetadata = resolveStoredFileMetadata(data.name, data.mimeType, buffer) - - return await uploadExecutionFile( - { - workspaceId: context.workspaceId || '', - workflowId: context.workflowId, - executionId: context.executionId || '', - }, - buffer, - storedMetadata.fileName, - storedMetadata.mimeType, - context.userId - ) - } - - if (!data.data) { - throw new Error( - `File data for '${data.name}' must have either 'data' (Buffer/base64) or 'url' property` - ) + buffer = Buffer.from(bytes) + } else if (typeof data === 'string') { + const payload = stripBase64DataUri(data) + const base64 = normalizeBase64(payload) + const padding = base64.endsWith('==') ? 2 : base64.endsWith('=') ? 1 : 0 + assertFileSize(Math.floor((base64.length * 3) / 4) - padding, name, remainingBytes) + if (!isCanonicalBase64(base64) || (payload.length > 0 && base64.length === 0)) { + throw new Error(`File '${name}' has invalid base64 data`) } + buffer = Buffer.from(base64, 'base64') + } - return uploadFileFromRawData( - { - name: data.name, - data: data.data, - mimeType: data.mimeType, - }, - { - workspaceId: context.workspaceId || '', - workflowId: context.workflowId, - executionId: context.executionId || '', - }, - context.userId - ) - } catch (error) { - logger.error(`Error processing file data for '${data.name}':`, error) - throw error + if ((!buffer || buffer.length === 0) && typeof file.url === 'string' && file.url) { + buffer = await downloadFileFromUrl(file.url, { + maxBytes: remainingBytes, + userId: context.userId, + ...(signal ? { signal } : {}), + }) + } + signal?.throwIfAborted() + if (!buffer) { + throw new Error(`File data for '${name}' must have either 'data' (Buffer/base64) or 'url'`) } + assertFileSize(buffer.length, name, remainingBytes) + return { buffer, name, mimeType } } - /** - * Check if a tool has any file-typed outputs - */ static hasFileOutputs(toolConfig: ToolDefinition): boolean { - if (!toolConfig.outputs) { - return false - } - - return Object.values(toolConfig.outputs).some( + return Object.values(toolConfig.outputs ?? {}).some( (output) => output.type === 'file' || output.type === 'file[]' ) } diff --git a/apps/sim/lib/integrations/icon-mapping.ts b/apps/sim/lib/integrations/icon-mapping.ts index a9318bcd494..bad2b73663e 100644 --- a/apps/sim/lib/integrations/icon-mapping.ts +++ b/apps/sim/lib/integrations/icon-mapping.ts @@ -301,7 +301,7 @@ export const blockTypeToIconMap: Record = { azure_data_explorer: AzureDataExplorerIcon, azure_devops: AzureIcon, bitbucket: BitbucketIcon, - box: BoxCompanyIcon, + box_v2: BoxCompanyIcon, brandfetch: BrandfetchIcon, brex: BrexIcon, brightdata: BrightDataIcon, @@ -337,10 +337,10 @@ export const blockTypeToIconMap: Record = { discord: DiscordIcon, docusign: DocuSignIcon, downdetector: DowndetectorIcon, - dropbox: DropboxIcon, + dropbox_v2: DropboxIcon, dropcontact: DropcontactIcon, dspy: DsPyIcon, - dub: DubIcon, + dub_v2: DubIcon, duckduckgo: DuckDuckGoIcon, dynamodb: DynamoDBIcon, dynatrace: DynatraceIcon, @@ -416,7 +416,7 @@ export const blockTypeToIconMap: Record = { jira_service_management: JiraServiceManagementIcon, jotform: JotformIcon, jsm: JiraServiceManagementIcon, - jupyter: JupyterIcon, + jupyter_v2: JupyterIcon, kalshi_v2: KalshiIcon, ketch: KetchIcon, knowledge: PackageSearchIcon, @@ -443,7 +443,7 @@ export const blockTypeToIconMap: Record = { mem0: Mem0Icon, memory: BrainIcon, microsoft_ad: AzureIcon, - microsoft_dataverse: MicrosoftDataverseIcon, + microsoft_dataverse_v2: MicrosoftDataverseIcon, microsoft_dynamics_365: MicrosoftDataverseIcon, microsoft_excel_v2: MicrosoftExcelIcon, microsoft_planner: MicrosoftPlannerIcon, @@ -486,7 +486,7 @@ export const blockTypeToIconMap: Record = { qdrant: QdrantIcon, quartr: QuartrIcon, quickbooks: QuickBooksIcon, - quiver: QuiverIcon, + quiver_v2: QuiverIcon, rabbitmq: RabbitmqIcon, railway: RailwayIcon, rb2b: RB2BIcon, @@ -512,8 +512,9 @@ export const blockTypeToIconMap: Record = { sentry: SentryIcon, serper: SerperIcon, servicenow: ServiceNowIcon, + servicenow_v2: ServiceNowIcon, ses: SESIcon, - sftp: SftpIcon, + sftp_v2: SftpIcon, sharepoint_v2: MicrosoftSharepointIcon, shopify: ShopifyIcon, sim_workspace_event: SimTriggerIcon, @@ -529,7 +530,7 @@ export const blockTypeToIconMap: Record = { sportmonks: SportmonksIcon, sqs: SQSIcon, square: SquareIcon, - ssh: SshIcon, + ssh_v2: SshIcon, ssm: SSMIcon, stagehand: StagehandIcon, stripe: StripeIcon, diff --git a/apps/sim/lib/internal/agiloft/execute-tool.test.ts b/apps/sim/lib/internal/agiloft/execute-tool.test.ts index d0c98cc55f8..79df94a6178 100644 --- a/apps/sim/lib/internal/agiloft/execute-tool.test.ts +++ b/apps/sim/lib/internal/agiloft/execute-tool.test.ts @@ -3,6 +3,7 @@ */ import { createExecutionContext } from '@sim/testing' import { beforeEach, describe, expect, it, vi } from 'vitest' +import { createInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' const operationMocks = vi.hoisted(() => ({ executeAgiloftAsyncStatus: vi.fn(), @@ -28,7 +29,7 @@ const operationMocks = vi.hoisted(() => ({ vi.mock('@/lib/internal/agiloft/operations', () => operationMocks) import { AgiloftOperationError } from '@/lib/internal/agiloft/errors' -import { executeAgiloftTool } from '@/lib/internal/agiloft/execute-tool' +import { executeAgiloftTool as executeAgiloftToolOperation } from '@/lib/internal/agiloft/execute-tool' import type { InternalToolOperationCall } from '@/lib/internal/tool-operations/types' const CREDENTIALS = { @@ -145,6 +146,14 @@ const TOOL_CASES = [ ], ] as const +async function executeAgiloftTool( + request: Parameters[0] +): Promise { + const result = await executeAgiloftToolOperation(request) + if (!(result instanceof Response)) throw new Error('Expected a JSON response') + return result +} + describe('executeAgiloftTool', () => { beforeEach(() => { vi.clearAllMocks() @@ -164,6 +173,22 @@ describe('executeAgiloftTool', () => { ) }) + it('forwards file bytes without serializing the file result', async () => { + const fileResult = createInternalToolFileResult( + { buffer: Buffer.from('file'), name: 'file.txt', mimeType: 'text/plain' }, + (file) => ({ success: true, output: { file } }) + ) + operationMocks.executeAgiloftRetrieveAttachment.mockResolvedValueOnce(fileResult) + expect( + await executeAgiloftToolOperation( + createRequest({ + toolId: 'agiloft_retrieve_attachment', + input: { ...BASE, recordId: '1', fieldName: 'files', position: '0' }, + }) + ) + ).toBe(fileResult) + }) + it('uses the trusted delegation origin and forwards cancellation', async () => { const controller = new AbortController() const input = { ...BASE, data: '{"name":"Contract"}' } diff --git a/apps/sim/lib/internal/agiloft/execute-tool.ts b/apps/sim/lib/internal/agiloft/execute-tool.ts index e59c8ba22ba..5d5377815cd 100644 --- a/apps/sim/lib/internal/agiloft/execute-tool.ts +++ b/apps/sim/lib/internal/agiloft/execute-tool.ts @@ -42,9 +42,11 @@ import { executeAgiloftUpdateRecord, executeAgiloftUpsertRecord, } from '@/lib/internal/agiloft/operations' +import { isInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' import type { InternalToolOperationCall, InternalToolOperationHandler, + InternalToolOperationResult, } from '@/lib/internal/tool-operations/types' function parseInput(contract: C, input: unknown) { @@ -69,7 +71,7 @@ async function executeOperation( contract: C, request: InternalToolOperationCall, operation: (input: ContractBody, context: AgiloftOperationContext) => Promise -): Promise { +): Promise { request.signal?.throwIfAborted() const parsed = parseInput(contract, request.input) if (!parsed.success) return parsed.response @@ -80,7 +82,7 @@ async function executeOperation( signal: request.signal, }) request.signal?.throwIfAborted() - return Response.json(result) + return isInternalToolFileResult(result) ? result : Response.json(result) } catch (error) { request.signal?.throwIfAborted() if (error instanceof AgiloftOperationError) { @@ -93,7 +95,9 @@ async function executeOperation( } } -export const executeAgiloftTool: InternalToolOperationHandler = async (request) => { +export const executeAgiloftTool: InternalToolOperationHandler = async ( + request +) => { switch (request.toolId) { case 'agiloft_async_status': return executeOperation(agiloftAsyncStatusContract, request, executeAgiloftAsyncStatus) diff --git a/apps/sim/lib/internal/agiloft/operations.test.ts b/apps/sim/lib/internal/agiloft/operations.test.ts index a9e373f3244..cd5709a1893 100644 --- a/apps/sim/lib/internal/agiloft/operations.test.ts +++ b/apps/sim/lib/internal/agiloft/operations.test.ts @@ -77,6 +77,17 @@ function createResponse( type ResponseTransform = (response: SecureFetchResponse) => Promise +const storedFile = { + id: 'stored-file', + name: 'stored.bin', + size: 5, + type: 'application/octet-stream', + mimeType: 'application/octet-stream', + url: '/api/files/stored', + key: 'execution/workspace/workflow/run/stored.bin', + context: 'execution', +} as const + describe('Agiloft operations', () => { beforeEach(() => { vi.clearAllMocks() @@ -163,17 +174,10 @@ describe('Agiloft operations', () => { { requestId: 'request-1', signal: controller.signal } ) - expect(result).toEqual({ - success: true, - output: { - file: { - name: 'evidence.txt', - mimeType: 'text/plain', - data: Buffer.from('hello').toString('base64'), - size: 5, - }, - }, - }) + expect(result.files).toEqual([ + { name: 'evidence.txt', mimeType: 'text/plain', buffer: Buffer.from('hello') }, + ]) + expect(result.present([storedFile])).toEqual({ success: true, output: { file: storedFile } }) expect(providerMocks.secureFetchWithPinnedIP).toHaveBeenCalledWith( expect.stringContaining('/ewws/EWRetrieve'), '203.0.113.10', diff --git a/apps/sim/lib/internal/agiloft/operations.ts b/apps/sim/lib/internal/agiloft/operations.ts index a346fd60ef8..ba25c691692 100644 --- a/apps/sim/lib/internal/agiloft/operations.ts +++ b/apps/sim/lib/internal/agiloft/operations.ts @@ -65,6 +65,10 @@ import { getLockHttpMethod, parseFieldList, } from '@/lib/internal/agiloft/urls' +import { + createInternalToolFileResult, + type InternalToolFileResult, +} from '@/lib/internal/tool-operations/file-result' import { resolveEffectiveMimeType } from '@/lib/uploads/utils/file-utils' import type { AgiloftAsyncStatusResponse, @@ -893,7 +897,7 @@ export async function executeAgiloftAttachFile( export async function executeAgiloftRetrieveAttachment( input: AgiloftRetrieveBody, context: AgiloftOperationContext -): Promise { +): Promise { let resolvedIP: string try { resolvedIP = await resolveAgiloftInstance(input.instanceUrl, context.signal) @@ -930,15 +934,8 @@ export async function executeAgiloftRetrieveAttachment( error: `Agiloft error: ${buffer.toString('utf8').slice(0, 300)}`, }) } - return { - success: true, - output: { - file: { - name: fileName, - mimeType: resolveEffectiveMimeType(contentType, fileName), - data: buffer.toString('base64'), - size: buffer.length, - }, - }, - } + return createInternalToolFileResult( + { buffer, name: fileName, mimeType: resolveEffectiveMimeType(contentType, fileName) }, + (file) => ({ success: true, output: { file } }) + ) } diff --git a/apps/sim/lib/internal/cursor/execute-tool.test.ts b/apps/sim/lib/internal/cursor/execute-tool.test.ts index a290d6a7f06..e68a9e6bf1d 100644 --- a/apps/sim/lib/internal/cursor/execute-tool.test.ts +++ b/apps/sim/lib/internal/cursor/execute-tool.test.ts @@ -3,6 +3,7 @@ */ import { createExecutionContext } from '@sim/testing' import { beforeEach, describe, expect, it, vi } from 'vitest' +import { createInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' const mocks = vi.hoisted(() => ({ downloadCursorArtifact: vi.fn() })) @@ -15,7 +16,7 @@ vi.mock('@/lib/internal/cursor/operations', () => ({ })) import { CursorOperationError } from '@/lib/internal/cursor/errors' -import { executeCursorTool } from '@/lib/internal/cursor/execute-tool' +import { executeCursorTool as executeCursorToolOperation } from '@/lib/internal/cursor/execute-tool' import type { InternalToolOperationCall } from '@/lib/internal/tool-operations/types' function request(overrides: Partial = {}): InternalToolOperationCall { @@ -29,6 +30,14 @@ function request(overrides: Partial = {}): InternalTo } } +async function executeCursorTool( + request: Parameters[0] +): Promise { + const result = await executeCursorToolOperation(request) + if (!(result instanceof Response)) throw new Error('Expected a JSON response') + return result +} + describe('executeCursorTool', () => { beforeEach(() => { vi.clearAllMocks() @@ -45,13 +54,26 @@ describe('executeCursorTool', () => { const response = await executeCursorTool(request({ toolId, signal: controller.signal })) expect(response.status).toBe(200) - expect(mocks.downloadCursorArtifact).toHaveBeenCalledWith( + const expectedArgs: unknown[] = [ { apiKey: 'cursor-key', agentId: 'agent-1', path: '/src/index.ts' }, - { requestId: 'request-1', signal: controller.signal } - ) + { requestId: 'request-1', signal: controller.signal }, + ] + if (toolId.endsWith('_v2')) expectedArgs.push('v2') + expect(mocks.downloadCursorArtifact.mock.calls[0]).toEqual(expectedArgs) } ) + it('forwards file bytes without serializing the file result', async () => { + const fileResult = createInternalToolFileResult( + { buffer: Buffer.from('file'), name: 'file.txt', mimeType: 'text/plain' }, + (file) => ({ success: true, output: { file } }) + ) + mocks.downloadCursorArtifact.mockResolvedValueOnce(fileResult) + expect( + await executeCursorToolOperation(request({ toolId: 'cursor_download_artifact_v2' })) + ).toBe(fileResult) + }) + it('rejects invalid input before provider work', async () => { const response = await executeCursorTool(request({ input: { apiKey: '' } })) diff --git a/apps/sim/lib/internal/cursor/execute-tool.ts b/apps/sim/lib/internal/cursor/execute-tool.ts index 9436106fdec..eba25730a9d 100644 --- a/apps/sim/lib/internal/cursor/execute-tool.ts +++ b/apps/sim/lib/internal/cursor/execute-tool.ts @@ -4,7 +4,11 @@ import { cursorOperationErrorMessage, downloadCursorArtifact, } from '@/lib/internal/cursor/operations' -import type { InternalToolOperationHandler } from '@/lib/internal/tool-operations/types' +import { isInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' +import type { + InternalToolOperationHandler, + InternalToolOperationResult, +} from '@/lib/internal/tool-operations/types' const inputSchema = z.object({ apiKey: z.string().min(1, 'API key is required'), @@ -12,7 +16,9 @@ const inputSchema = z.object({ path: z.string().min(1, 'Artifact path is required'), }) -export const executeCursorTool: InternalToolOperationHandler = async (request) => { +export const executeCursorTool: InternalToolOperationHandler = async ( + request +) => { request.signal?.throwIfAborted() if ( request.toolId !== 'cursor_download_artifact' && @@ -29,12 +35,15 @@ export const executeCursorTool: InternalToolOperationHandler = async (request) = } try { - return Response.json( - await downloadCursorArtifact(parsed.data, { - requestId: request.requestId, - signal: request.signal, - }) - ) + const context = { + requestId: request.requestId, + signal: request.signal, + } + const result = + request.toolId === 'cursor_download_artifact_v2' + ? await downloadCursorArtifact(parsed.data, context, 'v2') + : await downloadCursorArtifact(parsed.data, context) + return isInternalToolFileResult(result) ? result : Response.json(result) } catch (error) { request.signal?.throwIfAborted() const status = error instanceof CursorOperationError ? error.status : 500 diff --git a/apps/sim/lib/internal/cursor/operations.test.ts b/apps/sim/lib/internal/cursor/operations.test.ts index 1eff865fe46..9909d7a9bbd 100644 --- a/apps/sim/lib/internal/cursor/operations.test.ts +++ b/apps/sim/lib/internal/cursor/operations.test.ts @@ -15,6 +15,17 @@ vi.mock('@/lib/core/security/input-validation.server', () => ({ import { downloadCursorArtifact } from '@/lib/internal/cursor/operations' +const storedFile = { + id: 'stored-file', + name: 'stored.bin', + size: 5, + type: 'application/octet-stream', + mimeType: 'application/octet-stream', + url: '/api/files/stored', + key: 'execution/workspace/workflow/run/stored.bin', + context: 'execution', +} as const + describe('downloadCursorArtifact', () => { beforeEach(() => { vi.clearAllMocks() @@ -34,7 +45,8 @@ describe('downloadCursorArtifact', () => { const result = await downloadCursorArtifact( { apiKey: 'cursor-key', agentId: 'agent-1', path: '/src/index.ts' }, - { requestId: 'request-1', signal: controller.signal } + { requestId: 'request-1', signal: controller.signal }, + 'v2' ) expect(fetchMock).toHaveBeenCalledOnce() @@ -47,11 +59,34 @@ describe('downloadCursorArtifact', () => { '203.0.113.1', { profile: 'contentFetch', signal: controller.signal } ) - expect(result.output.file).toEqual({ - name: 'index.ts', - mimeType: 'text/plain', - data: Buffer.from('artifact').toString('base64'), - size: 8, + expect(result.files).toEqual([ + { name: 'index.ts', mimeType: 'text/plain', buffer: Buffer.from('artifact') }, + ]) + expect(result.present([storedFile])).toMatchObject({ + success: true, + output: { file: storedFile }, + }) + }) + + it('preserves inline file data for the legacy tool', async () => { + vi.stubGlobal( + 'fetch', + vi.fn().mockResolvedValue(Response.json({ url: 'https://download.example/artifact' })) + ) + const result = await downloadCursorArtifact( + { apiKey: 'cursor-key', agentId: 'agent-1', path: '/src/index.ts' }, + { requestId: 'request-1' } + ) + expect(result).toEqual({ + success: true, + output: { + file: { + name: 'index.ts', + mimeType: 'text/plain', + data: Buffer.from('artifact').toString('base64'), + size: 8, + }, + }, }) }) }) diff --git a/apps/sim/lib/internal/cursor/operations.ts b/apps/sim/lib/internal/cursor/operations.ts index 3365cd7969d..4ac9ba2cc81 100644 --- a/apps/sim/lib/internal/cursor/operations.ts +++ b/apps/sim/lib/internal/cursor/operations.ts @@ -9,6 +9,10 @@ import { readResponseTextWithLimit, } from '@/lib/core/utils/stream-limits' import { CursorOperationError } from '@/lib/internal/cursor/errors' +import { + createInternalToolFileResult, + type InternalToolFileResult, +} from '@/lib/internal/tool-operations/file-result' import type { DownloadArtifactParams } from '@/tools/cursor/types' const logger = createLogger('CursorOperations') @@ -25,13 +29,32 @@ export interface CursorOperationContext { signal?: AbortSignal } -export async function downloadCursorArtifact( +interface LegacyCursorArtifactResult { + success: boolean + output: { + file: { + name: string + mimeType: string + data: string + size: number + } + } +} + +export function downloadCursorArtifact( input: DownloadArtifactParams, context: CursorOperationContext -): Promise<{ - success: true - output: { file: { name: string; mimeType: string; data: string; size: number } } -}> { +): Promise +export function downloadCursorArtifact( + input: DownloadArtifactParams, + context: CursorOperationContext, + version: 'v2' +): Promise +export async function downloadCursorArtifact( + input: DownloadArtifactParams, + context: CursorOperationContext, + version: 'v1' | 'v2' = 'v1' +): Promise { context.signal?.throwIfAborted() const authHeader = `Basic ${Buffer.from(`${input.apiKey}:`).toString('base64')}` const artifactResponse = await fetch( @@ -86,15 +109,30 @@ export async function downloadCursorArtifact( const file = { name: input.path.split('/').pop() || 'artifact', mimeType: downloadResponse.headers.get('content-type') || 'application/octet-stream', - data: fileBuffer.toString('base64'), - size: fileBuffer.length, + buffer: fileBuffer, } logger.info(`[${context.requestId}] Cursor artifact downloaded`, { agentId: input.agentId, path: input.path, - size: file.size, + size: fileBuffer.length, }) - return { success: true, output: { file } } + if (version === 'v1') { + return { + success: true, + output: { + file: { + name: file.name, + mimeType: file.mimeType, + data: fileBuffer.toString('base64'), + size: fileBuffer.length, + }, + }, + } + } + return createInternalToolFileResult(file, (storedFile) => ({ + success: true, + output: { file: storedFile }, + })) } export function cursorOperationErrorMessage(error: unknown): string { diff --git a/apps/sim/lib/internal/discord/execute-tool.ts b/apps/sim/lib/internal/discord/execute-tool.ts index 023a0be5a79..a3bc4aa7fb6 100644 --- a/apps/sim/lib/internal/discord/execute-tool.ts +++ b/apps/sim/lib/internal/discord/execute-tool.ts @@ -5,7 +5,11 @@ import { DEFAULT_MAX_JSON_BODY_BYTES } from '@/lib/api/server/validation' import { DiscordOperationError } from '@/lib/internal/discord/errors' import { executeDiscordSendMessage } from '@/lib/internal/discord/operations' import { discordSendMessageInputSchema } from '@/lib/internal/discord/schema' -import type { InternalToolOperationHandler } from '@/lib/internal/tool-operations/types' +import { isInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' +import type { + InternalToolOperationHandler, + InternalToolOperationResult, +} from '@/lib/internal/tool-operations/types' const logger = createLogger('DiscordToolExecution') @@ -26,7 +30,9 @@ function inputSizeError(input: unknown): Response | null { : null } -export const executeDiscordTool: InternalToolOperationHandler = async (request) => { +export const executeDiscordTool: InternalToolOperationHandler = async ( + request +) => { request.signal?.throwIfAborted() if (request.toolId !== 'discord_send_message') { return Response.json( @@ -54,7 +60,7 @@ export const executeDiscordTool: InternalToolOperationHandler = async (request) userId, }) request.signal?.throwIfAborted() - return Response.json(result) + return isInternalToolFileResult(result) ? result : Response.json(result) } catch (error) { request.signal?.throwIfAborted() if (error instanceof DiscordOperationError) { diff --git a/apps/sim/lib/internal/discord/operations.test.ts b/apps/sim/lib/internal/discord/operations.test.ts index 6dfac7443b6..2843a8d2746 100644 --- a/apps/sim/lib/internal/discord/operations.test.ts +++ b/apps/sim/lib/internal/discord/operations.test.ts @@ -2,6 +2,7 @@ * @vitest-environment node */ import { beforeEach, describe, expect, it, vi } from 'vitest' +import { isInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' const fileMocks = vi.hoisted(() => ({ assertToolFileAccess: vi.fn(), @@ -96,25 +97,39 @@ describe('executeDiscordSendMessage', () => { return { id: 'message-1', content: 'hello' } }) - await expect( - executeDiscordSendMessage( - { - botToken: 'bot-token', - channelId: '123', - content: 'hello', - files: [{ key: 'workspace/file.txt', name: 'file.txt', size: 4 }], - }, - { - requestId: 'request-1', - signal: controller.signal, - userId: 'user-1', - } - ) - ).resolves.toMatchObject({ + const result = await executeDiscordSendMessage( + { + botToken: 'bot-token', + channelId: '123', + content: 'hello', + files: [{ key: 'workspace/file.txt', name: 'file.txt', size: 4 }], + }, + { + requestId: 'request-1', + signal: controller.signal, + userId: 'user-1', + } + ) + if (!isInternalToolFileResult(result)) throw new Error('Expected a file output') + expect(result.files).toEqual([ + { name: 'file.txt', mimeType: 'text/plain', buffer: Buffer.from('file') }, + ]) + const storedFile = { + id: 'stored', + name: 'file.txt', + size: 4, + type: 'text/plain', + mimeType: 'text/plain', + url: '/api/files/stored', + key: 'execution/file.txt', + context: 'execution' as const, + } + expect(result.present([storedFile])).toMatchObject({ success: true, output: { data: { id: 'message-1', content: 'hello' }, fileCount: 1, + files: [storedFile], message: 'hello', }, }) diff --git a/apps/sim/lib/internal/discord/operations.ts b/apps/sim/lib/internal/discord/operations.ts index 00a5d2211eb..a4571e27c66 100644 --- a/apps/sim/lib/internal/discord/operations.ts +++ b/apps/sim/lib/internal/discord/operations.ts @@ -6,6 +6,7 @@ import { isPayloadSizeLimitError } from '@/lib/core/utils/stream-limits' import { sendDiscordMessage } from '@/lib/internal/discord/client' import { DiscordOperationError } from '@/lib/internal/discord/errors' import type { DiscordSendMessageInput } from '@/lib/internal/discord/schema' +import { createInternalToolFilesResult } from '@/lib/internal/tool-operations/file-result' import { MAX_BUFFERED_TRANSFER_BYTES } from '@/lib/uploads/shared/types' import { docNotReadyMessage, isDocNotReadyError } from '@/lib/uploads/utils/doc-not-ready' import { processFilesToUserFiles } from '@/lib/uploads/utils/file-utils' @@ -92,8 +93,7 @@ export async function executeDiscordSendMessage( return { name: file.name, mimeType, - data: downloaded.buffer.toString('base64'), - size: downloaded.buffer.length, + buffer: downloaded.buffer, } }) const data = await sendDiscordMessage( @@ -103,13 +103,13 @@ export async function executeDiscordSendMessage( 'multipart', context.signal ) - return { + return createInternalToolFilesResult(files, (storedFiles) => ({ success: true, output: { message: typeof data.content === 'string' ? data.content : undefined, data, fileCount: userFiles.length, - files, + files: storedFiles, }, - } + })) } diff --git a/apps/sim/lib/internal/google-drive/execute-tool.test.ts b/apps/sim/lib/internal/google-drive/execute-tool.test.ts index 2081e5db43f..5fcc8255c29 100644 --- a/apps/sim/lib/internal/google-drive/execute-tool.test.ts +++ b/apps/sim/lib/internal/google-drive/execute-tool.test.ts @@ -3,6 +3,7 @@ */ import { createExecutionContext } from '@sim/testing' import { beforeEach, describe, expect, it, vi } from 'vitest' +import { createInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' const mocks = vi.hoisted(() => ({ download: vi.fn(), @@ -20,7 +21,7 @@ vi.mock('@/lib/internal/google-drive/operations', () => ({ import { PayloadSizeLimitError } from '@/lib/core/utils/stream-limits' import { GoogleDriveOperationError } from '@/lib/internal/google-drive/errors' -import { executeGoogleDriveTool } from '@/lib/internal/google-drive/execute-tool' +import { executeGoogleDriveTool as executeGoogleDriveToolOperation } from '@/lib/internal/google-drive/execute-tool' import type { InternalToolOperationCall } from '@/lib/internal/tool-operations/types' const INPUTS = { @@ -64,6 +65,14 @@ function request( } } +async function executeGoogleDriveTool( + request: Parameters[0] +): Promise { + const result = await executeGoogleDriveToolOperation(request) + if (!(result instanceof Response)) throw new Error('Expected a JSON response') + return result +} + describe('executeGoogleDriveTool', () => { beforeEach(() => { vi.clearAllMocks() @@ -88,6 +97,15 @@ describe('executeGoogleDriveTool', () => { } ) + it('forwards file bytes without serializing the file result', async () => { + const fileResult = createInternalToolFileResult( + { buffer: Buffer.from('file'), name: 'file.txt', mimeType: 'text/plain' }, + (file) => ({ success: true, output: { file } }) + ) + mocks.download.mockResolvedValueOnce(fileResult) + expect(await executeGoogleDriveToolOperation(request('google_drive_download'))).toBe(fileResult) + }) + it('preserves validation and provider error envelopes', async () => { const invalid = await executeGoogleDriveTool( request('google_drive_export', { input: { accessToken: 'token' } }) diff --git a/apps/sim/lib/internal/google-drive/execute-tool.ts b/apps/sim/lib/internal/google-drive/execute-tool.ts index d96ac227fdd..3d76c819c7c 100644 --- a/apps/sim/lib/internal/google-drive/execute-tool.ts +++ b/apps/sim/lib/internal/google-drive/execute-tool.ts @@ -20,9 +20,11 @@ import { executeGoogleDriveUpload, type GoogleDriveOperationContext, } from '@/lib/internal/google-drive/operations' +import { isInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' import type { InternalToolOperationCall, InternalToolOperationHandler, + InternalToolOperationResult, } from '@/lib/internal/tool-operations/types' import { MAX_BUFFERED_TRANSFER_BYTES } from '@/lib/uploads/shared/types' @@ -92,7 +94,9 @@ function unexpectedResponse(request: InternalToolOperationCall, error: unknown): return Response.json({ success: false, error: message }, { status }) } -export const executeGoogleDriveTool: InternalToolOperationHandler = async (request) => { +export const executeGoogleDriveTool: InternalToolOperationHandler< + InternalToolOperationResult +> = async (request) => { request.signal?.throwIfAborted() let serialized: string try { @@ -118,7 +122,9 @@ export const executeGoogleDriveTool: InternalToolOperationHandler = async (reque userId: request.context.userId, }) request.signal?.throwIfAborted() - return result instanceof Response ? result : Response.json(result) + return result instanceof Response || isInternalToolFileResult(result) + ? result + : Response.json(result) } catch (error) { request.signal?.throwIfAborted() if (error instanceof GoogleDriveOperationError) { diff --git a/apps/sim/lib/internal/google-drive/operations.test.ts b/apps/sim/lib/internal/google-drive/operations.test.ts index bd3046b17cb..aaab39e66fb 100644 --- a/apps/sim/lib/internal/google-drive/operations.test.ts +++ b/apps/sim/lib/internal/google-drive/operations.test.ts @@ -49,6 +49,17 @@ const context = { userId: 'user-1', } +const storedFile = { + id: 'stored-file', + name: 'stored.bin', + size: 5, + type: 'application/octet-stream', + mimeType: 'application/octet-stream', + url: '/api/files/stored', + key: 'execution/workspace/workflow/run/stored.bin', + context: 'execution', +} as const + describe('Google Drive operations', () => { beforeEach(() => { vi.clearAllMocks() @@ -82,11 +93,12 @@ describe('Google Drive operations', () => { maxResponseBytes: MAX_FILE_SIZE, signal: context.signal, }) - expect(result.output.file).toEqual({ - name: 'report.pdf', - mimeType: 'application/pdf', - data: 'AAAAAA==', - size: 4, + expect(result.files).toEqual([ + { name: 'report.pdf', mimeType: 'application/pdf', buffer: Buffer.alloc(4) }, + ]) + expect(result.present([storedFile])).toMatchObject({ + success: true, + output: { file: storedFile }, }) }) @@ -112,7 +124,9 @@ describe('Google Drive operations', () => { label: 'revisionsUrl', signal: context.signal, }) - expect(result.output.metadata.revisions).toEqual([{ id: 'rev-1' }]) + expect(result.present([storedFile])).toMatchObject({ + output: { metadata: { revisions: [{ id: 'rev-1' }] } }, + }) }) it('preserves the export byte limit and exact error', async () => { diff --git a/apps/sim/lib/internal/google-drive/operations.ts b/apps/sim/lib/internal/google-drive/operations.ts index c7d02d82f26..e07fc6b552c 100644 --- a/apps/sim/lib/internal/google-drive/operations.ts +++ b/apps/sim/lib/internal/google-drive/operations.ts @@ -17,6 +17,7 @@ import type { GoogleDriveMoveInput, GoogleDriveUploadInput, } from '@/lib/internal/google-drive/input' +import { createInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' import { MAX_FILE_SIZE } from '@/lib/uploads/utils/validation' import type { GoogleDriveFile, GoogleDriveRevision } from '@/tools/google_drive/types' import { @@ -204,18 +205,14 @@ export async function executeGoogleDriveDownload( } context.signal?.throwIfAborted() - return { - success: true, - output: { - file: { - name: input.fileName || metadata.name || 'download', - mimeType: finalMimeType, - data: fileBuffer.toString('base64'), - size: fileBuffer.length, - }, - metadata, + return createInternalToolFileResult( + { + buffer: fileBuffer, + name: input.fileName || metadata.name || 'download', + mimeType: finalMimeType, }, - } + (file) => ({ success: true, output: { file, metadata } }) + ) } export async function executeGoogleDriveExport( @@ -279,18 +276,14 @@ export async function executeGoogleDriveExport( ) } const fileBuffer = Buffer.from(arrayBuffer) - return { - success: true, - output: { - file: { - name: input.fileName || metadata.name || 'export', - mimeType: input.mimeType, - data: fileBuffer.toString('base64'), - size: fileBuffer.length, - }, - exportedMimeType: input.mimeType, + return createInternalToolFileResult( + { + buffer: fileBuffer, + name: input.fileName || metadata.name || 'export', + mimeType: input.mimeType, }, - } + (file) => ({ success: true, output: { file, exportedMimeType: input.mimeType } }) + ) } export async function executeGoogleDriveMove( diff --git a/apps/sim/lib/internal/google-vault/execute-tool.test.ts b/apps/sim/lib/internal/google-vault/execute-tool.test.ts index cebe945359a..c6f86679f64 100644 --- a/apps/sim/lib/internal/google-vault/execute-tool.test.ts +++ b/apps/sim/lib/internal/google-vault/execute-tool.test.ts @@ -3,6 +3,7 @@ */ import { createExecutionContext } from '@sim/testing' import { beforeEach, describe, expect, it, vi } from 'vitest' +import { createInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' const mocks = vi.hoisted(() => ({ downloadGoogleVaultExportFile: vi.fn() })) @@ -10,15 +11,45 @@ vi.mock('@/lib/internal/google-vault/operations', () => ({ downloadGoogleVaultExportFile: mocks.downloadGoogleVaultExportFile, })) -import { executeGoogleVaultTool } from '@/lib/internal/google-vault/execute-tool' +import { executeGoogleVaultTool as executeGoogleVaultToolOperation } from '@/lib/internal/google-vault/execute-tool' import type { InternalToolOperationCall } from '@/lib/internal/tool-operations/types' +async function executeGoogleVaultTool( + request: Parameters[0] +): Promise { + const result = await executeGoogleVaultToolOperation(request) + if (!(result instanceof Response)) throw new Error('Expected a JSON response') + return result +} + describe('executeGoogleVaultTool', () => { beforeEach(() => { vi.clearAllMocks() mocks.downloadGoogleVaultExportFile.mockResolvedValue({ success: true, output: {} }) }) + it('forwards file bytes without serializing the file result', async () => { + const fileResult = createInternalToolFileResult( + { buffer: Buffer.from('file'), name: 'file.txt', mimeType: 'text/plain' }, + (file) => ({ success: true, output: { file } }) + ) + mocks.downloadGoogleVaultExportFile.mockResolvedValueOnce(fileResult) + expect( + await executeGoogleVaultToolOperation({ + toolId: 'google_vault_download_export_file', + input: { + accessToken: 'token', + matterId: 'matter-1', + bucketName: 'bucket', + objectName: 'file.zip', + }, + headers: new Headers(), + context: createExecutionContext(), + requestId: 'request-1', + }) + ).toBe(fileResult) + }) + it('dispatches typed input and cancellation without HTTP metadata', async () => { const controller = new AbortController() const request: InternalToolOperationCall = { diff --git a/apps/sim/lib/internal/google-vault/execute-tool.ts b/apps/sim/lib/internal/google-vault/execute-tool.ts index c18a7c55327..665b423b162 100644 --- a/apps/sim/lib/internal/google-vault/execute-tool.ts +++ b/apps/sim/lib/internal/google-vault/execute-tool.ts @@ -3,7 +3,11 @@ import { z } from 'zod' import { isPayloadSizeLimitError } from '@/lib/core/utils/stream-limits' import { GoogleVaultOperationError } from '@/lib/internal/google-vault/errors' import { downloadGoogleVaultExportFile } from '@/lib/internal/google-vault/operations' -import type { InternalToolOperationHandler } from '@/lib/internal/tool-operations/types' +import { isInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' +import type { + InternalToolOperationHandler, + InternalToolOperationResult, +} from '@/lib/internal/tool-operations/types' const inputSchema = z.object({ accessToken: z.string().min(1, 'Access token is required'), @@ -13,7 +17,9 @@ const inputSchema = z.object({ fileName: z.string().optional(), }) -export const executeGoogleVaultTool: InternalToolOperationHandler = async (request) => { +export const executeGoogleVaultTool: InternalToolOperationHandler< + InternalToolOperationResult +> = async (request) => { request.signal?.throwIfAborted() if (request.toolId !== 'google_vault_download_export_file') { return Response.json( @@ -26,9 +32,8 @@ export const executeGoogleVaultTool: InternalToolOperationHandler = async (reque return Response.json({ success: false, error: 'Invalid request data' }, { status: 400 }) } try { - return Response.json( - await downloadGoogleVaultExportFile(parsed.data, { signal: request.signal }) - ) + const result = await downloadGoogleVaultExportFile(parsed.data, { signal: request.signal }) + return isInternalToolFileResult(result) ? result : Response.json(result) } catch (error) { request.signal?.throwIfAborted() const status = isPayloadSizeLimitError(error) diff --git a/apps/sim/lib/internal/google-vault/operations.test.ts b/apps/sim/lib/internal/google-vault/operations.test.ts index fb7d34b9045..03daa3b8da5 100644 --- a/apps/sim/lib/internal/google-vault/operations.test.ts +++ b/apps/sim/lib/internal/google-vault/operations.test.ts @@ -16,6 +16,17 @@ vi.mock('@/lib/core/security/input-validation.server', () => ({ import { downloadGoogleVaultExportFile } from '@/lib/internal/google-vault/operations' import { MAX_BUFFERED_TRANSFER_BYTES } from '@/lib/uploads/shared/types' +const storedFile = { + id: 'stored-file', + name: 'stored.bin', + size: 5, + type: 'application/octet-stream', + mimeType: 'application/octet-stream', + url: '/api/files/stored', + key: 'execution/workspace/workflow/run/stored.bin', + context: 'execution', +} as const + describe('downloadGoogleVaultExportFile', () => { beforeEach(() => { vi.clearAllMocks() @@ -53,11 +64,12 @@ describe('downloadGoogleVaultExportFile', () => { signal: controller.signal, } ) - expect(result.output.file).toEqual({ - name: 'vault export.zip', - mimeType: 'application/zip', - data: 'AQID', - size: 3, + expect(result.files).toEqual([ + { name: 'vault export.zip', mimeType: 'application/zip', buffer: Buffer.from([1, 2, 3]) }, + ]) + expect(result.present([storedFile])).toMatchObject({ + success: true, + output: { file: storedFile }, }) }) }) diff --git a/apps/sim/lib/internal/google-vault/operations.ts b/apps/sim/lib/internal/google-vault/operations.ts index 87683ae4b2b..045a55f4096 100644 --- a/apps/sim/lib/internal/google-vault/operations.ts +++ b/apps/sim/lib/internal/google-vault/operations.ts @@ -8,6 +8,7 @@ import { readResponseToBufferWithLimit, } from '@/lib/core/utils/stream-limits' import { GoogleVaultOperationError } from '@/lib/internal/google-vault/errors' +import { createInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' import { MAX_BUFFERED_TRANSFER_BYTES } from '@/lib/uploads/shared/types' import type { GoogleVaultDownloadExportFileParams } from '@/tools/google_vault/types' import { enhanceGoogleVaultError } from '@/tools/google_vault/utils' @@ -84,10 +85,8 @@ export async function downloadGoogleVaultExportFile( input.fileName, input.objectName ) - return { + return createInternalToolFileResult({ buffer, name, mimeType }, (file) => ({ success: true, - output: { - file: { name, mimeType, data: buffer.toString('base64'), size: buffer.length }, - }, - } + output: { file }, + })) } diff --git a/apps/sim/lib/internal/jupyter/client.test.ts b/apps/sim/lib/internal/jupyter/client.test.ts index 9f2256bf54e..d6e46c42e43 100644 --- a/apps/sim/lib/internal/jupyter/client.test.ts +++ b/apps/sim/lib/internal/jupyter/client.test.ts @@ -14,7 +14,11 @@ vi.mock('@/lib/core/security/input-validation.server', () => ({ secureFetchWithPinnedIP: securityMocks.secureFetchWithPinnedIP, })) -import { InvalidJupyterTargetError, requestJupyterApi } from '@/lib/internal/jupyter/client' +import { + InvalidJupyterTargetError, + requestJupyterApi, + requestJupyterFile, +} from '@/lib/internal/jupyter/client' describe('Jupyter client', () => { beforeEach(() => { @@ -109,4 +113,51 @@ describe('Jupyter client', () => { ).rejects.toMatchObject({ name: 'AbortError' }) expect(securityMocks.validateUrlWithDNS).not.toHaveBeenCalled() }) + + it('downloads raw bytes with token auth, the server base path, and a separate 100 MiB cap', async () => { + const controller = new AbortController() + await requestJupyterFile( + { + serverUrl: 'https://jupyter.example.com/user/alice/', + token: 'secret-token', + path: 'datasets/report #1.xlsx', + }, + controller.signal + ) + + const url = + 'https://jupyter.example.com/user/alice/files/datasets/report%20%231.xlsx?download=1' + expect(securityMocks.validateUrlWithDNS).toHaveBeenCalledWith( + url, + 'serverUrl', + 'selfHostedService' + ) + expect(securityMocks.secureFetchWithPinnedIP).toHaveBeenCalledWith(url, '192.0.2.10', { + method: 'GET', + headers: { Authorization: 'token secret-token' }, + body: undefined, + profile: 'selfHostedService', + maxRedirects: 0, + maxResponseBytes: 100 * 1024 * 1024, + signal: controller.signal, + }) + }) + + it.each(['../secret', '%2e%2e/secret', 'data/../secret'])( + 'rejects raw download traversal before DNS: %s', + async (path) => { + await expect( + requestJupyterFile({ serverUrl: 'jupyter.example.com', token: 'token', path }) + ).rejects.toMatchObject({ name: 'UnsafeJupyterPathError' }) + expect(securityMocks.validateUrlWithDNS).not.toHaveBeenCalled() + } + ) + + it('rejects a raw file target blocked by DNS policy', async () => { + securityMocks.validateUrlWithDNS.mockResolvedValue({ isValid: false, error: 'blocked' }) + await expect( + requestJupyterFile({ serverUrl: 'jupyter.example.com', token: 'token', path: 'data.csv' }) + ).rejects.toBeInstanceOf(InvalidJupyterTargetError) + expect(securityMocks.secureFetchWithPinnedIP).not.toHaveBeenCalled() + }) }) diff --git a/apps/sim/lib/internal/jupyter/client.ts b/apps/sim/lib/internal/jupyter/client.ts index 3e1b3acc3cb..06348db6b29 100644 --- a/apps/sim/lib/internal/jupyter/client.ts +++ b/apps/sim/lib/internal/jupyter/client.ts @@ -7,9 +7,11 @@ import { } from '@/lib/core/security/input-validation.server' import { buildJupyterAuthHeaders, + encodeJupyterPath, InvalidJupyterServerUrlError, normalizeJupyterServerUrl, } from '@/lib/internal/jupyter/protocol' +import { MAX_BUFFERED_TRANSFER_BYTES } from '@/lib/uploads/shared/types' export class InvalidJupyterTargetError extends Error { constructor(message: string) { @@ -30,6 +32,30 @@ export interface JupyterApiRequest { export async function requestJupyterApi( input: JupyterApiRequest, signal?: AbortSignal +): Promise { + return requestJupyter(input, `api/${input.path}`, MAX_JSON_API_RESPONSE_BYTES, signal) +} + +/** Downloads raw file bytes through Jupyter's authenticated `/files/` handler. */ +export async function requestJupyterFile( + input: Pick, + signal?: AbortSignal +): Promise { + signal?.throwIfAborted() + const path = encodeJupyterPath(input.path) + return requestJupyter( + { serverUrl: input.serverUrl, token: input.token, path: input.path, method: 'GET' }, + `files/${path}?download=1`, + MAX_BUFFERED_TRANSFER_BYTES, + signal + ) +} + +async function requestJupyter( + input: JupyterApiRequest, + route: string, + maxResponseBytes: number, + signal?: AbortSignal ): Promise { signal?.throwIfAborted() let base: string @@ -41,7 +67,7 @@ export async function requestJupyterApi( } throw error } - const url = `${base}/api/${input.path}` + const url = `${base}/${route}` const urlValidation = await validateUrlWithDNS(url, 'serverUrl', 'selfHostedService') signal?.throwIfAborted() @@ -59,7 +85,7 @@ export async function requestJupyterApi( body: hasBody ? JSON.stringify(input.body) : undefined, profile: 'selfHostedService', maxRedirects: 0, - maxResponseBytes: MAX_JSON_API_RESPONSE_BYTES, + maxResponseBytes, signal, }) } diff --git a/apps/sim/lib/internal/jupyter/execute-tool.test.ts b/apps/sim/lib/internal/jupyter/execute-tool.test.ts index e956ae7e1d5..69464995721 100644 --- a/apps/sim/lib/internal/jupyter/execute-tool.test.ts +++ b/apps/sim/lib/internal/jupyter/execute-tool.test.ts @@ -7,11 +7,14 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' const operationMocks = vi.hoisted(() => ({ executeJupyterProxy: vi.fn(), executeJupyterUpload: vi.fn(), + executeJupyterGetContent: vi.fn(), })) vi.mock('@/lib/internal/jupyter/operations', () => operationMocks) +import { PayloadSizeLimitError } from '@/lib/core/utils/stream-limits' import { executeJupyterTool, JUPYTER_PROXY_TOOL_IDS } from '@/lib/internal/jupyter/execute-tool' +import { createInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' import type { InternalToolOperationCall } from '@/lib/internal/tool-operations/types' const PROXY_BODY = { @@ -38,6 +41,12 @@ function createRequest( } } +async function executeResponse(request: InternalToolOperationCall): Promise { + const response = await executeJupyterTool(request) + if (!(response instanceof Response)) throw new Error('Expected a JSON response') + return response +} + describe('executeJupyterTool', () => { beforeEach(() => { vi.clearAllMocks() @@ -50,7 +59,7 @@ describe('executeJupyterTool', () => { }) it.each(JUPYTER_PROXY_TOOL_IDS)('recognizes proxy tool ID %s', async (toolId) => { - const response = await executeJupyterTool(createRequest({ toolId })) + const response = await executeResponse(createRequest({ toolId })) expect(response.status).toBe(200) expect(operationMocks.executeJupyterProxy).toHaveBeenCalledWith(PROXY_BODY, { @@ -60,7 +69,7 @@ describe('executeJupyterTool', () => { }) it('validates the canonical proxy contract before provider work', async () => { - const response = await executeJupyterTool(createRequest({ input: { ...PROXY_BODY, path: '' } })) + const response = await executeResponse(createRequest({ input: { ...PROXY_BODY, path: '' } })) expect(response.status).toBe(400) await expect(response.json()).resolves.toMatchObject({ @@ -79,7 +88,7 @@ describe('executeJupyterTool', () => { fileName: 'hello.txt', } - const response = await executeJupyterTool( + const response = await executeResponse( createRequest({ toolId: 'jupyter_upload_file', input, @@ -96,7 +105,7 @@ describe('executeJupyterTool', () => { }) it('fails upload closed without a trusted execution user', async () => { - const response = await executeJupyterTool( + const response = await executeResponse( createRequest({ toolId: 'jupyter_upload_file', context: { @@ -122,11 +131,50 @@ describe('executeJupyterTool', () => { }) it('returns a deterministic error for unsupported IDs', async () => { - const response = await executeJupyterTool(createRequest({ toolId: 'jupyter_unknown' })) + const response = await executeResponse(createRequest({ toolId: 'jupyter_unknown' })) expect(response.status).toBe(500) await expect(response.json()).resolves.toEqual({ error: 'Unsupported Jupyter tool: jupyter_unknown', }) }) + + it('preserves the typed v2 file result for central storage', async () => { + const result = createInternalToolFileResult( + { buffer: Buffer.from('hello'), name: 'notes.txt', mimeType: 'text/plain' }, + (file) => ({ success: true, output: { file } }) + ) + const input = { ...PROXY_BODY, path: 'notes.txt' } + const controller = new AbortController() + operationMocks.executeJupyterGetContent.mockResolvedValue(result) + expect( + await executeJupyterTool( + createRequest({ toolId: 'jupyter_get_content_v2', input, signal: controller.signal }) + ) + ).toBe(result) + expect(operationMocks.executeJupyterGetContent).toHaveBeenCalledWith(input, { + requestId: 'request-1', + signal: controller.signal, + }) + expect(operationMocks.executeJupyterProxy).not.toHaveBeenCalled() + }) + + it('rejects non-GET v2 reads before provider work', async () => { + const response = await executeResponse( + createRequest({ toolId: 'jupyter_get_content_v2', input: { ...PROXY_BODY, method: 'POST' } }) + ) + expect(response.status).toBe(400) + expect(operationMocks.executeJupyterGetContent).not.toHaveBeenCalled() + }) + + it('projects a download byte limit failure as 413', async () => { + operationMocks.executeJupyterGetContent.mockRejectedValue( + new PayloadSizeLimitError({ label: 'Jupyter file download', maxBytes: 100 * 1024 * 1024 }) + ) + const response = await executeResponse(createRequest({ toolId: 'jupyter_get_content_v2' })) + expect(response.status).toBe(413) + await expect(response.json()).resolves.toMatchObject({ + error: expect.stringContaining('Jupyter file download exceeds maximum size'), + }) + }) }) diff --git a/apps/sim/lib/internal/jupyter/execute-tool.ts b/apps/sim/lib/internal/jupyter/execute-tool.ts index 26ba77d704b..d732610cb30 100644 --- a/apps/sim/lib/internal/jupyter/execute-tool.ts +++ b/apps/sim/lib/internal/jupyter/execute-tool.ts @@ -4,9 +4,19 @@ import type { AnyApiRouteContract } from '@/lib/api/contracts' import { jupyterUploadContract } from '@/lib/api/contracts/storage-transfer' import { jupyterProxyContract } from '@/lib/api/contracts/tools/jupyter' import { DEFAULT_MAX_JSON_BODY_BYTES } from '@/lib/api/server/validation' -import { executeJupyterProxy, executeJupyterUpload } from '@/lib/internal/jupyter/operations' +import { isPayloadSizeLimitError } from '@/lib/core/utils/stream-limits' +import { InvalidJupyterTargetError } from '@/lib/internal/jupyter/client' +import { + executeJupyterGetContent, + executeJupyterProxy, + executeJupyterUpload, +} from '@/lib/internal/jupyter/operations' +import { UnsafeJupyterPathError } from '@/lib/internal/jupyter/protocol' import { parseInternalToolInput } from '@/lib/internal/tool-operations/parse-input' -import type { InternalToolOperationHandler } from '@/lib/internal/tool-operations/types' +import type { + InternalToolOperationHandler, + InternalToolOperationResult, +} from '@/lib/internal/tool-operations/types' const proxyLogger = createLogger('JupyterProxyAPI') const uploadLogger = createLogger('JupyterUploadAPI') @@ -53,15 +63,31 @@ function unexpectedErrorResponse( } /** Executes every Jupyter tool without routing through the application's HTTP listener. */ -export const executeJupyterTool: InternalToolOperationHandler = async ({ - toolId, - input, - context, - requestId, - signal, -}) => { +export const executeJupyterTool: InternalToolOperationHandler< + InternalToolOperationResult +> = async ({ toolId, input, context, requestId, signal }) => { signal?.throwIfAborted() + if (toolId === 'jupyter_get_content_v2') { + const parsed = parseJupyterBody(jupyterProxyContract, input) + if (!parsed.success) return parsed.response + if (parsed.data.method !== 'GET') { + return Response.json({ error: 'Get Content requires a GET request' }, { status: 400 }) + } + try { + return await executeJupyterGetContent(parsed.data, { requestId, signal }) + } catch (error) { + signal?.throwIfAborted() + if (error instanceof UnsafeJupyterPathError || error instanceof InvalidJupyterTargetError) { + return Response.json({ error: error.message }, { status: 400 }) + } + if (isPayloadSizeLimitError(error)) { + return Response.json({ error: error.message }, { status: 413 }) + } + return unexpectedErrorResponse('proxy', requestId, error, signal) + } + } + if (JUPYTER_PROXY_TOOL_ID_SET.has(toolId)) { const parsed = parseJupyterBody(jupyterProxyContract, input) if (!parsed.success) return parsed.response diff --git a/apps/sim/lib/internal/jupyter/get-content.test.ts b/apps/sim/lib/internal/jupyter/get-content.test.ts new file mode 100644 index 00000000000..6f73d7fd3b0 --- /dev/null +++ b/apps/sim/lib/internal/jupyter/get-content.test.ts @@ -0,0 +1,179 @@ +/** + * @vitest-environment node + */ +import { beforeEach, describe, expect, it, vi } from 'vitest' + +const clientMocks = vi.hoisted(() => ({ + InvalidJupyterTargetError: class extends Error {}, + requestJupyterApi: vi.fn(), + requestJupyterFile: vi.fn(), +})) + +vi.mock('@/lib/internal/jupyter/client', () => clientMocks) +vi.mock('@/lib/internal/jupyter/file-input', () => ({ resolveJupyterUploadFile: vi.fn() })) + +import { executeJupyterGetContent } from '@/lib/internal/jupyter/operations' +import { isInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' +import { MAX_BUFFERED_TRANSFER_BYTES } from '@/lib/uploads/shared/types' + +const INPUT = { + serverUrl: 'https://jupyter.example.com/user/alice', + token: 'token', + path: 'data/report #1.xlsx', +} +const CONTEXT = { requestId: 'request-1' } +const MIME_TYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' + +describe('Jupyter Get Content v2', () => { + beforeEach(() => vi.clearAllMocks()) + + it('downloads a 12 MiB workbook through the raw endpoint and presents only its stored file', async () => { + const controller = new AbortController() + const buffer = Buffer.alloc(12 * 1024 * 1024, 42) + clientMocks.requestJupyterApi.mockResolvedValue( + Response.json({ name: 'report #1.xlsx', type: 'file', size: buffer.length, content: null }) + ) + clientMocks.requestJupyterFile.mockResolvedValue( + new Response(buffer, { headers: { 'content-type': MIME_TYPE } }) + ) + + const result = await executeJupyterGetContent(INPUT, { ...CONTEXT, signal: controller.signal }) + expect(isInternalToolFileResult(result)).toBe(true) + if (!isInternalToolFileResult(result)) throw new Error('Expected a file result') + expect(result.files).toHaveLength(1) + expect(result.files[0]?.buffer.length).toBe(buffer.length) + expect(result.files[0]?.buffer.equals(buffer)).toBe(true) + expect(result.files[0]?.name).toBe('report #1.xlsx') + expect(result.files[0]?.mimeType).toBe(MIME_TYPE) + const file = { + id: 'file-1', + name: 'report #1.xlsx', + type: MIME_TYPE, + mimeType: MIME_TYPE, + size: buffer.length, + key: 'execution/file-1', + url: '/api/files/serve/execution/file-1', + } + expect(result.present([file])).toEqual({ success: true, output: { file } }) + expect(clientMocks.requestJupyterApi).toHaveBeenCalledExactlyOnceWith( + { ...INPUT, method: 'GET', path: 'contents/data/report%20%231.xlsx?content=0' }, + controller.signal + ) + expect(clientMocks.requestJupyterFile).toHaveBeenCalledExactlyOnceWith(INPUT, controller.signal) + }) + + it('returns text files as stored files without an inline text alias', async () => { + clientMocks.requestJupyterApi.mockResolvedValue( + Response.json({ type: 'file', name: 'notes.txt', size: 5 }) + ) + clientMocks.requestJupyterFile.mockResolvedValue( + new Response('hello', { headers: { 'content-type': 'text/plain; charset=UTF-8' } }) + ) + const result = await executeJupyterGetContent({ ...INPUT, path: 'notes.txt' }, CONTEXT) + if (!isInternalToolFileResult(result)) throw new Error('Expected a file result') + expect(result.files[0]?.buffer.toString('utf8')).toBe('hello') + expect(result.files[0]?.mimeType).toBe('text/plain') + }) + + it.each([ + { type: 'notebook', content: { cells: [{ cell_type: 'code', source: ['1 + 1'] }] } }, + { type: 'directory', content: [{ type: 'file', name: 'data.csv', path: 'docs/data.csv' }] }, + ])('preserves structured $type output without a raw file request', async ({ type, content }) => { + clientMocks.requestJupyterApi + .mockResolvedValueOnce(Response.json({ name: 'docs', path: 'docs', type, content: null })) + .mockResolvedValueOnce( + Response.json({ name: 'docs', path: 'docs', type, content, format: 'json', mimetype: null }) + ) + const response = await executeJupyterGetContent({ ...INPUT, path: 'docs' }, CONTEXT) + if (!(response instanceof Response)) throw new Error('Expected structured content') + await expect(response.json()).resolves.toEqual({ + success: true, + output: { + name: 'docs', + path: 'docs', + mimetype: null, + text: JSON.stringify(content), + file: null, + }, + }) + expect(clientMocks.requestJupyterApi).toHaveBeenNthCalledWith( + 2, + { ...INPUT, method: 'GET', path: `contents/docs?content=1&type=${type}` }, + undefined + ) + expect(clientMocks.requestJupyterFile).not.toHaveBeenCalled() + }) + + it('rejects oversized metadata before reading file bytes', async () => { + clientMocks.requestJupyterApi.mockResolvedValue( + Response.json({ type: 'file', size: MAX_BUFFERED_TRANSFER_BYTES + 1 }) + ) + const response = await executeJupyterGetContent(INPUT, CONTEXT) + if (!(response instanceof Response)) throw new Error('Expected a size error') + expect(response.status).toBe(413) + expect(clientMocks.requestJupyterFile).not.toHaveBeenCalled() + }) + + it('enforces the raw byte cap when metadata size is missing or wrong', async () => { + const cancel = vi.fn() + clientMocks.requestJupyterApi.mockResolvedValue(Response.json({ type: 'file', size: 1 })) + clientMocks.requestJupyterFile.mockResolvedValue( + new Response(new ReadableStream({ cancel }), { + headers: { 'content-length': String(MAX_BUFFERED_TRANSFER_BYTES + 1) }, + }) + ) + await expect(executeJupyterGetContent(INPUT, CONTEXT)).rejects.toMatchObject({ + name: 'PayloadSizeLimitError', + maxBytes: MAX_BUFFERED_TRANSFER_BYTES, + }) + expect(cancel).toHaveBeenCalledOnce() + }) + + it('keeps notebook JSON bounded at 10 MiB', async () => { + clientMocks.requestJupyterApi + .mockResolvedValueOnce(Response.json({ type: 'notebook' })) + .mockResolvedValueOnce( + new Response('', { headers: { 'content-length': String(10 * 1024 * 1024 + 1) } }) + ) + await expect(executeJupyterGetContent(INPUT, CONTEXT)).rejects.toMatchObject({ + name: 'PayloadSizeLimitError', + maxBytes: 10 * 1024 * 1024, + }) + expect(clientMocks.requestJupyterFile).not.toHaveBeenCalled() + }) + + it.each(['metadata', 'download'])( + 'preserves an upstream %s failure without returning a file', + async (stage) => { + const errorResponse = new Response('not found', { status: 404 }) + clientMocks.requestJupyterApi.mockResolvedValue( + stage === 'metadata' ? errorResponse : Response.json({ type: 'file' }) + ) + clientMocks.requestJupyterFile.mockResolvedValue(errorResponse) + const response = await executeJupyterGetContent(INPUT, CONTEXT) + if (!(response instanceof Response)) throw new Error('Expected an upstream error') + expect(response.status).toBe(404) + await expect(response.json()).resolves.toEqual({ error: 'Jupyter API error: 404 not found' }) + } + ) + + it('does not fetch raw bytes when cancellation arrives after metadata', async () => { + const controller = new AbortController() + clientMocks.requestJupyterApi.mockImplementation(async () => { + controller.abort(new DOMException('cancelled', 'AbortError')) + return Response.json({ type: 'file' }) + }) + await expect( + executeJupyterGetContent(INPUT, { ...CONTEXT, signal: controller.signal }) + ).rejects.toMatchObject({ name: 'AbortError' }) + expect(clientMocks.requestJupyterFile).not.toHaveBeenCalled() + }) + + it('rejects malformed metadata without requesting raw bytes', async () => { + clientMocks.requestJupyterApi.mockResolvedValue(Response.json({ type: 'unexpected' })) + const response = await executeJupyterGetContent(INPUT, CONTEXT) + if (!(response instanceof Response)) throw new Error('Expected an invalid model error') + expect(response.status).toBe(502) + expect(clientMocks.requestJupyterFile).not.toHaveBeenCalled() + }) +}) diff --git a/apps/sim/lib/internal/jupyter/operations.test.ts b/apps/sim/lib/internal/jupyter/operations.test.ts index b8a8d33ca7b..a705d1f6f38 100644 --- a/apps/sim/lib/internal/jupyter/operations.test.ts +++ b/apps/sim/lib/internal/jupyter/operations.test.ts @@ -8,6 +8,7 @@ const clientMocks = vi.hoisted(() => { return { InvalidJupyterTargetError, requestJupyterApi: vi.fn(), + requestJupyterFile: vi.fn(), } }) const fileInputMocks = vi.hoisted(() => ({ diff --git a/apps/sim/lib/internal/jupyter/operations.ts b/apps/sim/lib/internal/jupyter/operations.ts index a42129cd911..3beeef70bb3 100644 --- a/apps/sim/lib/internal/jupyter/operations.ts +++ b/apps/sim/lib/internal/jupyter/operations.ts @@ -1,7 +1,18 @@ import { createLogger } from '@sim/logger' import type { JupyterUploadBody } from '@/lib/api/contracts/storage-transfer' import type { JupyterProxyBody } from '@/lib/api/contracts/tools/jupyter' -import { InvalidJupyterTargetError, requestJupyterApi } from '@/lib/internal/jupyter/client' +import { MAX_JSON_API_RESPONSE_BYTES } from '@/lib/core/security/input-validation.server' +import { + DEFAULT_MAX_ERROR_BODY_BYTES, + readResponseJsonWithLimit, + readResponseTextWithLimit, + readResponseToBufferWithLimit, +} from '@/lib/core/utils/stream-limits' +import { + InvalidJupyterTargetError, + requestJupyterApi, + requestJupyterFile, +} from '@/lib/internal/jupyter/client' import { resolveJupyterUploadFile } from '@/lib/internal/jupyter/file-input' import { assertSafeJupyterProxyPath, @@ -9,6 +20,10 @@ import { parseJupyterContentModel, UnsafeJupyterPathError, } from '@/lib/internal/jupyter/protocol' +import { createInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' +import type { InternalToolOperationResult } from '@/lib/internal/tool-operations/types' +import { MAX_BUFFERED_TRANSFER_BYTES } from '@/lib/uploads/shared/types' +import { getFileExtension, getMimeTypeFromExtension } from '@/lib/uploads/utils/file-utils' const uploadLogger = createLogger('JupyterUploadAPI') @@ -25,6 +40,107 @@ function validationErrorResponse(error: UnsafeJupyterPathError | InvalidJupyterT return Response.json({ success: false, error: error.message }, { status: 400 }) } +/** Stores files before JSON presentation while preserving structured notebook and directory reads. */ +export async function executeJupyterGetContent( + input: Pick, + context: JupyterOperationContext +): Promise { + const { signal } = context + signal?.throwIfAborted() + const path = encodeJupyterPath(input.path) + const auth = { serverUrl: input.serverUrl, token: input.token } + const metadataResponse = await requestJupyterApi( + { ...auth, method: 'GET', path: `contents/${path}?content=0` }, + signal + ) + if (!metadataResponse.ok) return jupyterReadErrorResponse(metadataResponse, signal) + const metadata = parseJupyterContentModel( + await readResponseJsonWithLimit(metadataResponse, { + maxBytes: MAX_JSON_API_RESPONSE_BYTES, + label: 'Jupyter content metadata', + signal, + }) + ) + signal?.throwIfAborted() + if (!metadata?.type) { + return Response.json({ error: 'Jupyter returned an invalid content model' }, { status: 502 }) + } + + if (metadata.type === 'file') { + if (metadata.size !== undefined && metadata.size > MAX_BUFFERED_TRANSFER_BYTES) { + return Response.json( + { error: 'Jupyter file exceeds the 100 MB download limit' }, + { status: 413 } + ) + } + const response = await requestJupyterFile(input, signal) + if (!response.ok) return jupyterReadErrorResponse(response, signal) + const buffer = await readResponseToBufferWithLimit(response, { + maxBytes: MAX_BUFFERED_TRANSFER_BYTES, + label: 'Jupyter file download', + signal, + }) + signal?.throwIfAborted() + const name = metadata.name || input.path.split('/').filter(Boolean).at(-1) || 'file' + const mimeType = + response.headers.get('content-type')?.split(';')[0]?.trim() || + metadata.mimetype || + getMimeTypeFromExtension(getFileExtension(name)) + return createInternalToolFileResult({ buffer, name, mimeType }, (file) => ({ + success: true, + output: { file }, + })) + } + + const response = await requestJupyterApi( + { ...auth, method: 'GET', path: `contents/${path}?content=1&type=${metadata.type}` }, + signal + ) + if (!response.ok) return jupyterReadErrorResponse(response, signal) + const data = parseJupyterContentModel( + await readResponseJsonWithLimit(response, { + maxBytes: MAX_JSON_API_RESPONSE_BYTES, + label: 'Jupyter structured content', + signal, + }) + ) + signal?.throwIfAborted() + if (data?.type !== metadata.type) { + return Response.json({ error: 'Jupyter returned an invalid content model' }, { status: 502 }) + } + const text = + data.format === 'json' || typeof data.content === 'object' + ? JSON.stringify(data.content) + : typeof data.content === 'string' + ? data.content + : null + return Response.json({ + success: true, + output: { + name: data.name ?? metadata.name ?? '', + path: data.path ?? input.path, + mimetype: data.mimetype ?? null, + text, + file: null, + }, + }) +} + +async function jupyterReadErrorResponse( + response: Awaited>, + signal?: AbortSignal +): Promise { + const errorText = await readResponseTextWithLimit(response, { + maxBytes: DEFAULT_MAX_ERROR_BODY_BYTES, + label: 'Jupyter read error', + signal, + }) + return Response.json( + { error: `Jupyter API error: ${response.status} ${errorText}` }, + { status: response.status } + ) +} + /** Executes the shared Jupyter proxy contract and mirrors the upstream response verbatim. */ export async function executeJupyterProxy( input: JupyterProxyBody, diff --git a/apps/sim/lib/internal/microsoft-teams/execute-tool.test.ts b/apps/sim/lib/internal/microsoft-teams/execute-tool.test.ts index da09c978423..873618b9d72 100644 --- a/apps/sim/lib/internal/microsoft-teams/execute-tool.test.ts +++ b/apps/sim/lib/internal/microsoft-teams/execute-tool.test.ts @@ -3,6 +3,7 @@ */ import { createExecutionContext } from '@sim/testing' import { beforeEach, describe, expect, it, vi } from 'vitest' +import { createInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' const mocks = vi.hoisted(() => ({ deleteMicrosoftTeamsChatMessage: vi.fn(), @@ -16,9 +17,17 @@ vi.mock('@/lib/internal/microsoft-teams/operations', () => ({ writeMicrosoftTeamsChatMessage: mocks.writeMicrosoftTeamsChatMessage, })) -import { executeMicrosoftTeamsTool } from '@/lib/internal/microsoft-teams/execute-tool' +import { executeMicrosoftTeamsTool as executeMicrosoftTeamsToolOperation } from '@/lib/internal/microsoft-teams/execute-tool' import type { InternalToolOperationCall } from '@/lib/internal/tool-operations/types' +async function executeMicrosoftTeamsTool( + request: Parameters[0] +): Promise { + const result = await executeMicrosoftTeamsToolOperation(request) + if (!(result instanceof Response)) throw new Error('Expected a JSON response') + return result +} + describe('executeMicrosoftTeamsTool', () => { beforeEach(() => { vi.clearAllMocks() @@ -27,6 +36,23 @@ describe('executeMicrosoftTeamsTool', () => { mocks.writeMicrosoftTeamsChatMessage.mockResolvedValue({ success: true, output: {} }) }) + it('forwards file bytes without serializing the file result', async () => { + const fileResult = createInternalToolFileResult( + { buffer: Buffer.from('file'), name: 'file.txt', mimeType: 'text/plain' }, + (file) => ({ success: true, output: { file } }) + ) + mocks.writeMicrosoftTeamsChatMessage.mockResolvedValueOnce(fileResult) + expect( + await executeMicrosoftTeamsToolOperation({ + toolId: 'microsoft_teams_write_chat', + input: { accessToken: 'token', chatId: 'chat-1', content: 'hello', files: null }, + headers: new Headers(), + context: createExecutionContext(), + requestId: 'request-1', + }) + ).toBe(fileResult) + }) + it('dispatches typed input with cancellation', async () => { const controller = new AbortController() const input = { accessToken: 'token', chatId: 'chat-1', messageId: 'message-1' } diff --git a/apps/sim/lib/internal/microsoft-teams/execute-tool.ts b/apps/sim/lib/internal/microsoft-teams/execute-tool.ts index 0c371d540b9..442be760b82 100644 --- a/apps/sim/lib/internal/microsoft-teams/execute-tool.ts +++ b/apps/sim/lib/internal/microsoft-teams/execute-tool.ts @@ -12,7 +12,11 @@ import { microsoftTeamsWriteChannelInputSchema, microsoftTeamsWriteChatInputSchema, } from '@/lib/internal/microsoft-teams/schema' -import type { InternalToolOperationHandler } from '@/lib/internal/tool-operations/types' +import { isInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' +import type { + InternalToolOperationHandler, + InternalToolOperationResult, +} from '@/lib/internal/tool-operations/types' const deleteInputSchema = z.object({ accessToken: z.string().min(1, 'Access token is required'), @@ -36,7 +40,9 @@ function inputSizeError(input: unknown): Response | null { ) } -export const executeMicrosoftTeamsTool: InternalToolOperationHandler = async (request) => { +export const executeMicrosoftTeamsTool: InternalToolOperationHandler< + InternalToolOperationResult +> = async (request) => { request.signal?.throwIfAborted() const sizeError = inputSizeError(request.input) if (sizeError) return sizeError @@ -50,12 +56,14 @@ export const executeMicrosoftTeamsTool: InternalToolOperationHandler = async (re case 'microsoft_teams_write_chat': { const parsed = microsoftTeamsWriteChatInputSchema.safeParse(request.input) if (!parsed.success) return validationErrorResponse(parsed.error) - return Response.json(await writeMicrosoftTeamsChatMessage(parsed.data, context)) + const result = await writeMicrosoftTeamsChatMessage(parsed.data, context) + return isInternalToolFileResult(result) ? result : Response.json(result) } case 'microsoft_teams_write_channel': { const parsed = microsoftTeamsWriteChannelInputSchema.safeParse(request.input) if (!parsed.success) return validationErrorResponse(parsed.error) - return Response.json(await writeMicrosoftTeamsChannelMessage(parsed.data, context)) + const result = await writeMicrosoftTeamsChannelMessage(parsed.data, context) + return isInternalToolFileResult(result) ? result : Response.json(result) } case 'microsoft_teams_delete_chat_message': { const parsed = deleteInputSchema.safeParse(request.input) diff --git a/apps/sim/lib/internal/microsoft-teams/operations.test.ts b/apps/sim/lib/internal/microsoft-teams/operations.test.ts index 356c68571f7..927769c2429 100644 --- a/apps/sim/lib/internal/microsoft-teams/operations.test.ts +++ b/apps/sim/lib/internal/microsoft-teams/operations.test.ts @@ -2,6 +2,7 @@ * @vitest-environment node */ import { beforeEach, describe, expect, it, vi } from 'vitest' +import { isInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' const mocks = vi.hoisted(() => ({ assertToolFileAccess: vi.fn(), @@ -54,6 +55,7 @@ describe('deleteMicrosoftTeamsChatMessage', () => { expect(mocks.fetch.mock.calls[1][1]).toEqual( expect.objectContaining({ method: 'POST', signal: controller.signal }) ) + if (isInternalToolFileResult(result)) throw new Error('Expected a JSON result') expect(result.output).toEqual({ deleted: true, messageId: 'message-1', @@ -83,6 +85,7 @@ describe('deleteMicrosoftTeamsChatMessage', () => { expect(mocks.fetch.mock.calls[0][1]).toEqual( expect.objectContaining({ method: 'POST', signal: controller.signal }) ) + if (isInternalToolFileResult(result)) throw new Error('Expected a JSON result') expect(result.output).toEqual({ updatedContent: true, metadata: { @@ -95,6 +98,50 @@ describe('deleteMicrosoftTeamsChatMessage', () => { }) }) + it('keeps multiple valid attachments out of the message response body', async () => { + const buffer = Buffer.alloc(4 * 1024 * 1024, 1) + const sourceFiles = Array.from({ length: 3 }, (_, index) => ({ + id: `source-${index}`, + key: `workspace/file-${index}.txt`, + name: `file-${index}.txt`, + size: buffer.length, + type: 'text/plain', + })) + mocks.processFilesToUserFiles.mockReturnValue(sourceFiles) + mocks.downloadServableFileFromStorage.mockResolvedValue({ buffer, contentType: 'text/plain' }) + mocks.fetch.mockReset() + for (const file of sourceFiles) { + mocks.fetch + .mockResolvedValueOnce(Response.json({ id: file.id })) + .mockResolvedValueOnce( + Response.json({ id: file.id, webDavUrl: `https://teams.example/${file.name}` }) + ) + } + mocks.fetch.mockResolvedValueOnce(Response.json({ id: 'message-1', chatId: 'chat-1' })) + + const result = await writeMicrosoftTeamsChatMessage( + { accessToken: 'token', chatId: 'chat-1', content: 'hello', files: sourceFiles }, + { requestId: 'request-1', userId: 'user-1' } + ) + + if (!isInternalToolFileResult(result)) throw new Error('Expected a file output') + expect(result.files).toHaveLength(3) + for (const file of result.files) expect(file.buffer).toBe(buffer) + expect(mocks.downloadServableFileFromStorage).toHaveBeenCalledTimes(3) + expect(mocks.fetch).toHaveBeenCalledTimes(7) + const storedFiles = sourceFiles.map((file) => ({ + ...file, + mimeType: file.type, + url: `/api/files/${file.id}`, + context: 'execution' as const, + })) + const presented = result.present(storedFiles) + expect(presented).toMatchObject({ + output: { files: storedFiles, metadata: { attachmentCount: 3 } }, + }) + expect(Buffer.byteLength(JSON.stringify(presented))).toBeLessThan(10 * 1024) + }) + it('resolves mentions in-process while preserving the enhanced output envelope', async () => { mocks.fetch.mockReset() mocks.fetch @@ -120,6 +167,7 @@ describe('deleteMicrosoftTeamsChatMessage', () => { body: { contentType: 'html', content: 'Ada hello' }, mentions: [{ id: 0, mentionText: 'Ada' }], }) + if (isInternalToolFileResult(result)) throw new Error('Expected a JSON result') expect(result.output).toMatchObject({ updatedContent: true, metadata: { chatId: 'chat-1', attachmentCount: 0 }, diff --git a/apps/sim/lib/internal/microsoft-teams/operations.ts b/apps/sim/lib/internal/microsoft-teams/operations.ts index 4de7a0cd846..7cca5977186 100644 --- a/apps/sim/lib/internal/microsoft-teams/operations.ts +++ b/apps/sim/lib/internal/microsoft-teams/operations.ts @@ -11,6 +11,10 @@ import type { MicrosoftTeamsWriteChannelInput, MicrosoftTeamsWriteChatInput, } from '@/lib/internal/microsoft-teams/schema' +import { + createInternalToolFilesResult, + type InternalToolFile, +} from '@/lib/internal/tool-operations/file-result' import { MAX_BUFFERED_TRANSFER_BYTES } from '@/lib/uploads/shared/types' import { docNotReadyMessage, isDocNotReadyError } from '@/lib/uploads/utils/doc-not-ready' import { processFilesToUserFiles } from '@/lib/uploads/utils/file-utils' @@ -35,13 +39,6 @@ export interface MicrosoftTeamsOperationContext { userId?: string } -interface TeamsFileOutput { - name: string - mimeType: string - data: string - size: number -} - interface TeamsAttachmentRef { id: string contentType: 'reference' @@ -95,13 +92,13 @@ async function uploadFilesForMessage( rawFiles: NonNullable, client: MicrosoftTeamsClient, context: MicrosoftTeamsOperationContext -): Promise<{ attachments: TeamsAttachmentRef[]; files: TeamsFileOutput[] }> { +): Promise<{ attachments: TeamsAttachmentRef[]; files: InternalToolFile[] }> { if (rawFiles.length === 0) return { attachments: [], files: [] } if (!context.userId) throw new MicrosoftTeamsOperationError('Authentication required', 401) const requestId = context.requestId || 'microsoft-teams-operation' const userFiles = processFilesToUserFiles(rawFiles, requestId, logger) const attachments: TeamsAttachmentRef[] = [] - const files: TeamsFileOutput[] = [] + const files: InternalToolFile[] = [] let totalBytes = 0 for (const file of userFiles) { @@ -141,8 +138,7 @@ async function uploadFilesForMessage( files.push({ name: file.name, mimeType: contentType, - data: buffer.toString('base64'), - size: buffer.length, + buffer, }) let uploaded: MicrosoftTeamsGraphObject @@ -353,17 +349,20 @@ async function sendMessage(args: { 'Failed to send Teams message', args.context.signal ) - return { - success: true as const, - output: { - updatedContent: true, - metadata: { - ...args.enhancedMetadata(data), - attachmentCount: uploaded.attachments.length, - }, - files: uploaded.files, + const output = { + updatedContent: true, + metadata: { + ...args.enhancedMetadata(data), + attachmentCount: uploaded.attachments.length, }, } + if (uploaded.files.length === 0) { + return { success: true as const, output: { ...output, files: [] } } + } + return createInternalToolFilesResult(uploaded.files, (files) => ({ + success: true, + output: { ...output, files }, + })) } export async function writeMicrosoftTeamsChatMessage( diff --git a/apps/sim/lib/internal/microsoft-word/execute-tool.test.ts b/apps/sim/lib/internal/microsoft-word/execute-tool.test.ts index bee8eae27e3..f1ac631927f 100644 --- a/apps/sim/lib/internal/microsoft-word/execute-tool.test.ts +++ b/apps/sim/lib/internal/microsoft-word/execute-tool.test.ts @@ -3,6 +3,7 @@ */ import { createExecutionContext } from '@sim/testing' import { beforeEach, describe, expect, it, vi } from 'vitest' +import { createInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' const operationMocks = vi.hoisted(() => ({ executeMicrosoftWordAppend: vi.fn(), @@ -18,7 +19,7 @@ vi.mock('@/lib/internal/microsoft-word/operations', () => operationMocks) import { DEFAULT_MAX_JSON_BODY_BYTES } from '@/lib/api/server/validation' import { GraphRequestError } from '@/lib/internal/microsoft-word/client' -import { executeMicrosoftWordTool } from '@/lib/internal/microsoft-word/execute-tool' +import { executeMicrosoftWordTool as executeMicrosoftWordToolOperation } from '@/lib/internal/microsoft-word/execute-tool' import type { InternalToolOperationCall } from '@/lib/internal/tool-operations/types' const READ_INPUT = { accessToken: 'token', documentId: 'document-1' } @@ -70,6 +71,14 @@ const TOOL_CASES = [ ], ] as const +async function executeMicrosoftWordTool( + request: Parameters[0] +): Promise { + const result = await executeMicrosoftWordToolOperation(request) + if (!(result instanceof Response)) throw new Error('Expected a JSON response') + return result +} + describe('executeMicrosoftWordTool', () => { beforeEach(() => { vi.clearAllMocks() @@ -96,6 +105,22 @@ describe('executeMicrosoftWordTool', () => { }) }) + it('forwards file bytes without serializing the file result', async () => { + const fileResult = createInternalToolFileResult( + { buffer: Buffer.from('file'), name: 'file.txt', mimeType: 'text/plain' }, + (file) => ({ success: true, output: { file } }) + ) + operationMocks.executeMicrosoftWordExportPdf.mockResolvedValueOnce(fileResult) + expect( + await executeMicrosoftWordToolOperation( + createRequest({ + toolId: 'microsoft_word_export_pdf', + input: { accessToken: 'token', documentId: 'document-1' }, + }) + ) + ).toBe(fileResult) + }) + it('returns validation errors before provider work', async () => { const response = await executeMicrosoftWordTool( createRequest({ input: { accessToken: '', documentId: '' } }) diff --git a/apps/sim/lib/internal/microsoft-word/execute-tool.ts b/apps/sim/lib/internal/microsoft-word/execute-tool.ts index 9ea1b0ea7cf..b4948fc0c9c 100644 --- a/apps/sim/lib/internal/microsoft-word/execute-tool.ts +++ b/apps/sim/lib/internal/microsoft-word/execute-tool.ts @@ -24,7 +24,11 @@ import { microsoftWordReplaceTextInputSchema, microsoftWordUpdateInputSchema, } from '@/lib/internal/microsoft-word/schema' -import type { InternalToolOperationHandler } from '@/lib/internal/tool-operations/types' +import { isInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' +import type { + InternalToolOperationHandler, + InternalToolOperationResult, +} from '@/lib/internal/tool-operations/types' const logger = createLogger('MicrosoftWordToolExecution') @@ -34,7 +38,7 @@ async function executeOperation( execute: (input: z.output, context: MicrosoftWordOperationContext) => Promise, context: MicrosoftWordOperationContext, toolId: string -): Promise { +): Promise { context.signal?.throwIfAborted() let serializedInput: string try { @@ -61,7 +65,7 @@ async function executeOperation( try { const result = await execute(parsed.data, context) context.signal?.throwIfAborted() - return Response.json(result) + return isInternalToolFileResult(result) ? result : Response.json(result) } catch (error) { context.signal?.throwIfAborted() const message = getErrorMessage(error, 'Unknown error occurred') @@ -81,7 +85,9 @@ async function executeOperation( } } -export const executeMicrosoftWordTool: InternalToolOperationHandler = async (request) => { +export const executeMicrosoftWordTool: InternalToolOperationHandler< + InternalToolOperationResult +> = async (request) => { const { input, requestId, signal, toolId } = request const context: MicrosoftWordOperationContext = { requestId, signal } diff --git a/apps/sim/lib/internal/microsoft-word/operations.test.ts b/apps/sim/lib/internal/microsoft-word/operations.test.ts index 7fcc9bb4170..64add99b95d 100644 --- a/apps/sim/lib/internal/microsoft-word/operations.test.ts +++ b/apps/sim/lib/internal/microsoft-word/operations.test.ts @@ -3,6 +3,7 @@ */ import { createExecutionContext, inputValidationMock, inputValidationMockFns } from '@sim/testing' import { beforeEach, describe, expect, it, vi } from 'vitest' +import { executeMicrosoftWordExportPdf } from '@/lib/internal/microsoft-word/operations' vi.mock('@/lib/core/security/input-validation.server', () => inputValidationMock) @@ -93,7 +94,7 @@ beforeEach(() => { }) }) -function executeTool(toolId: string, input: unknown): Promise { +async function executeTool(toolId: string, input: unknown): Promise { const request: InternalToolOperationCall = { toolId, input, @@ -101,13 +102,44 @@ function executeTool(toolId: string, input: unknown): Promise { context: createExecutionContext({ workflowId: 'workflow-1' }), requestId: 'request-1', } - return executeMicrosoftWordTool(request) + const result = await executeMicrosoftWordTool(request) + if (!(result instanceof Response)) throw new Error('Expected a JSON response') + return result } function executeAppend(input: typeof baseBody): Promise { return executeTool('microsoft_word_append', input) } +describe('Microsoft Word PDF file output', () => { + it('keeps large PDFs in process for the executor to store', async () => { + const buffer = Buffer.alloc(12 * 1024 * 1024, 1) + mockSecureFetchWithPinnedIP + .mockResolvedValueOnce(itemResponse('version-1')) + .mockResolvedValueOnce(new Response(buffer)) + const result = await executeMicrosoftWordExportPdf( + { accessToken: 'token-123', documentId: 'doc-abc' }, + { requestId: 'request-1' } + ) + expect(result.files).toHaveLength(1) + expect(result.files[0]?.name).toBe('notes.pdf') + expect(result.files[0]?.mimeType).toBe('application/pdf') + expect(result.files[0]?.buffer.length).toBe(buffer.length) + expect(result.files[0]?.buffer.equals(buffer)).toBe(true) + const file = { + id: 'stored', + name: 'notes.pdf', + size: buffer.length, + type: 'application/pdf', + mimeType: 'application/pdf', + url: '/api/files/stored', + key: 'execution/notes.pdf', + context: 'execution' as const, + } + expect(result.present([file])).toEqual({ success: true, output: { file } }) + }) +}) + describe('Microsoft Word direct input validation', () => { it('rejects a whitespace-only document name before provider work', async () => { const response = await executeTool('microsoft_word_create', { diff --git a/apps/sim/lib/internal/microsoft-word/operations.ts b/apps/sim/lib/internal/microsoft-word/operations.ts index 4a3d990bf45..82999611f04 100644 --- a/apps/sim/lib/internal/microsoft-word/operations.ts +++ b/apps/sim/lib/internal/microsoft-word/operations.ts @@ -17,6 +17,7 @@ import type { MicrosoftWordReplaceTextInput, MicrosoftWordUpdateInput, } from '@/lib/internal/microsoft-word/schema' +import { createInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' import { appendParagraphsToDocx, buildDocxFromContent, @@ -322,15 +323,8 @@ export async function executeMicrosoftWordExportPdf( name, size: pdfBuffer.length, }) - return { - success: true as const, - output: { - file: { - name, - mimeType: PDF_MIME_TYPE, - data: pdfBuffer.toString('base64'), - size: pdfBuffer.length, - }, - }, - } + return createInternalToolFileResult( + { buffer: pdfBuffer, name, mimeType: PDF_MIME_TYPE }, + (file) => ({ success: true, output: { file } }) + ) } diff --git a/apps/sim/lib/internal/onedrive/execute-tool.test.ts b/apps/sim/lib/internal/onedrive/execute-tool.test.ts index ae324b007b6..4644ef711aa 100644 --- a/apps/sim/lib/internal/onedrive/execute-tool.test.ts +++ b/apps/sim/lib/internal/onedrive/execute-tool.test.ts @@ -1,8 +1,10 @@ /** * @vitest-environment node */ + import { createExecutionContext } from '@sim/testing' import { beforeEach, describe, expect, it, vi } from 'vitest' +import { createInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' const mocks = vi.hoisted(() => ({ downloadOneDriveFile: vi.fn(), @@ -17,10 +19,15 @@ vi.mock('@/lib/internal/onedrive/operations', () => ({ import { executeOneDriveTool } from '@/lib/internal/onedrive/execute-tool' import type { InternalToolOperationCall } from '@/lib/internal/tool-operations/types' +const fileResult = createInternalToolFileResult( + { buffer: Buffer.from('file'), name: 'file.pdf', mimeType: 'application/pdf' }, + (file) => ({ success: true, output: { file } }) +) + describe('executeOneDriveTool', () => { beforeEach(() => { vi.clearAllMocks() - mocks.downloadOneDriveFile.mockResolvedValue({ success: true, output: {} }) + mocks.downloadOneDriveFile.mockResolvedValue(fileResult) mocks.uploadOneDriveFile.mockResolvedValue({ success: true, output: {} }) }) @@ -35,7 +42,7 @@ describe('executeOneDriveTool', () => { signal: controller.signal, } - expect((await executeOneDriveTool(request)).status).toBe(200) + expect(await executeOneDriveTool(request)).toBe(fileResult) expect(mocks.downloadOneDriveFile).toHaveBeenCalledWith( { accessToken: 'token', fileId: 'file-1', fileName: undefined }, { signal: controller.signal } diff --git a/apps/sim/lib/internal/onedrive/execute-tool.ts b/apps/sim/lib/internal/onedrive/execute-tool.ts index a4791fd31d5..12bc5ade032 100644 --- a/apps/sim/lib/internal/onedrive/execute-tool.ts +++ b/apps/sim/lib/internal/onedrive/execute-tool.ts @@ -6,7 +6,10 @@ import { isPayloadSizeLimitError } from '@/lib/core/utils/stream-limits' import { OneDriveOperationError } from '@/lib/internal/onedrive/errors' import { downloadOneDriveFile, uploadOneDriveFile } from '@/lib/internal/onedrive/operations' import { oneDriveUploadInputSchema } from '@/lib/internal/onedrive/schema' -import type { InternalToolOperationHandler } from '@/lib/internal/tool-operations/types' +import type { + InternalToolOperationHandler, + InternalToolOperationResult, +} from '@/lib/internal/tool-operations/types' const downloadInputSchema = z.object({ accessToken: z.string().min(1, 'Access token is required'), @@ -30,7 +33,9 @@ function inputSizeError(input: unknown): Response | null { ) } -export const executeOneDriveTool: InternalToolOperationHandler = async (request) => { +export const executeOneDriveTool: InternalToolOperationHandler< + InternalToolOperationResult +> = async (request) => { request.signal?.throwIfAborted() const sizeError = inputSizeError(request.input) if (sizeError) return sizeError @@ -39,11 +44,9 @@ export const executeOneDriveTool: InternalToolOperationHandler = async (request) case 'onedrive_download': { const parsed = downloadInputSchema.safeParse(request.input) if (!parsed.success) return validationErrorResponse(parsed.error) - return Response.json( - await downloadOneDriveFile( - { ...parsed.data, fileName: parsed.data.fileName ?? undefined }, - { signal: request.signal } - ) + return await downloadOneDriveFile( + { ...parsed.data, fileName: parsed.data.fileName ?? undefined }, + { signal: request.signal } ) } case 'onedrive_upload': { diff --git a/apps/sim/lib/internal/onedrive/operations.test.ts b/apps/sim/lib/internal/onedrive/operations.test.ts index 975cd038361..db46c90a502 100644 --- a/apps/sim/lib/internal/onedrive/operations.test.ts +++ b/apps/sim/lib/internal/onedrive/operations.test.ts @@ -1,7 +1,12 @@ /** * @vitest-environment node */ -import { beforeEach, describe, expect, it, vi } from 'vitest' + +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { + isInternalToolFileResult, + type StoredToolFile, +} from '@/lib/internal/tool-operations/file-result' const mocks = vi.hoisted(() => ({ assertToolFileAccess: vi.fn(), @@ -63,12 +68,40 @@ describe('downloadOneDriveFile', () => { expect(mocks.secureFetchWithPinnedIP.mock.calls[1][2]).toEqual( expect.objectContaining({ signal: controller.signal }) ) - expect(result.output.file).toEqual({ + assert(isInternalToolFileResult(result)) + expect(result.files).toEqual([ + { + name: 'report.pdf', + mimeType: 'application/pdf', + buffer: Buffer.from([1, 2, 3]), + }, + ]) + const storedFile: StoredToolFile = { + id: 'stored-file-1', + key: 'execution/stored-file-1', + url: '/api/files/serve/stored-file-1', name: 'report.pdf', + type: 'application/pdf', mimeType: 'application/pdf', - data: 'AQID', size: 3, - }) + context: 'execution', + } + expect(result.present([storedFile])).toEqual({ success: true, output: { file: storedFile } }) + }) + + it('preserves downloads above the JSON response limit as bytes', async () => { + const buffer = Buffer.alloc(11 * 1024 * 1024, 1) + mocks.secureFetchWithPinnedIP.mockReset() + mocks.secureFetchWithPinnedIP + .mockResolvedValueOnce( + Response.json({ name: 'large.xlsx', file: { mimeType: 'application/vnd.ms-excel' } }) + ) + .mockResolvedValueOnce(new Response(buffer)) + + const result = await downloadOneDriveFile({ accessToken: 'token', fileId: 'large-file' }, {}) + + expect(result.files[0]?.buffer.equals(buffer)).toBe(true) + expect(result.files[0]).not.toHaveProperty('data') }) it('uploads plain content without an HTTP route hop and preserves text-file behavior', async () => { diff --git a/apps/sim/lib/internal/onedrive/operations.ts b/apps/sim/lib/internal/onedrive/operations.ts index c28f6002ab6..f1d5db4bf19 100644 --- a/apps/sim/lib/internal/onedrive/operations.ts +++ b/apps/sim/lib/internal/onedrive/operations.ts @@ -17,6 +17,10 @@ import { } from '@/lib/core/utils/stream-limits' import { OneDriveOperationError } from '@/lib/internal/onedrive/errors' import type { OneDriveUploadInput } from '@/lib/internal/onedrive/schema' +import { + createInternalToolFileResult, + type InternalToolFileResult, +} from '@/lib/internal/tool-operations/file-result' import { docNotReadyMessage, isDocNotReadyError } from '@/lib/uploads/utils/doc-not-ready' import { getExtensionFromMimeType, @@ -25,7 +29,7 @@ import { import { downloadServableFileFromStorage } from '@/lib/uploads/utils/file-utils.server' import { MAX_FILE_SIZE } from '@/lib/uploads/utils/validation' import { assertToolFileAccess } from '@/app/api/files/authorization' -import type { OneDriveDownloadResponse, OneDriveToolParams } from '@/tools/onedrive/types' +import type { OneDriveToolParams } from '@/tools/onedrive/types' import { normalizeExcelValues } from '@/tools/onedrive/utils' const MAX_GRAPH_JSON_BYTES = 2 * 1024 * 1024 @@ -452,7 +456,7 @@ async function graphError(response: SecureFetchResponse, fallback: string, signa export async function downloadOneDriveFile( input: OneDriveDownloadInput, context: OneDriveOperationContext -): Promise { +): Promise { context.signal?.throwIfAborted() const fileId = encodeURIComponent(input.fileId) const metadataResponse = await fetchGraph( @@ -498,15 +502,12 @@ export async function downloadOneDriveFile( label: 'OneDrive file download', signal: context.signal, }) - return { - success: true, - output: { - file: { - name: input.fileName || metadata.name || 'download', - mimeType: metadata.file?.mimeType || 'application/octet-stream', - data: buffer.toString('base64'), - size: buffer.length, - }, + return createInternalToolFileResult( + { + buffer, + name: input.fileName || metadata.name || 'download', + mimeType: metadata.file?.mimeType || 'application/octet-stream', }, - } + (file) => ({ success: true, output: { file } }) + ) } diff --git a/apps/sim/lib/internal/onepassword/execute-tool.ts b/apps/sim/lib/internal/onepassword/execute-tool.ts index 47aec72789c..4b8144709a1 100644 --- a/apps/sim/lib/internal/onepassword/execute-tool.ts +++ b/apps/sim/lib/internal/onepassword/execute-tool.ts @@ -27,10 +27,12 @@ import { executeOnePasswordUpdateItem, type OnePasswordOperationContext, } from '@/lib/internal/onepassword/operations' +import { isInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' import { parseInternalToolInput } from '@/lib/internal/tool-operations/parse-input' import type { InternalToolOperationCall, InternalToolOperationHandler, + InternalToolOperationResult, } from '@/lib/internal/tool-operations/types' const logger = createLogger('OnePasswordToolExecution') @@ -40,7 +42,7 @@ async function executeOperation( request: InternalToolOperationCall, operation: (input: ContractBody, context: OnePasswordOperationContext) => Promise, failureMessage: string -): Promise { +): Promise { request.signal?.throwIfAborted() const parsed = parseInternalToolInput(contract, request.input) if (!parsed.success) return parsed.response @@ -48,7 +50,7 @@ async function executeOperation( try { const result = await operation(parsed.data, { signal: request.signal }) request.signal?.throwIfAborted() - return Response.json(result) + return isInternalToolFileResult(result) ? result : Response.json(result) } catch (error) { request.signal?.throwIfAborted() if (error instanceof OnePasswordOperationError) { @@ -64,7 +66,9 @@ async function executeOperation( } } -export const executeOnePasswordTool: InternalToolOperationHandler = async (request) => { +export const executeOnePasswordTool: InternalToolOperationHandler< + InternalToolOperationResult +> = async (request) => { switch (request.toolId) { case 'onepassword_list_vaults': return executeOperation( diff --git a/apps/sim/lib/internal/onepassword/operations.test.ts b/apps/sim/lib/internal/onepassword/operations.test.ts index 76d7518f514..aafdf3f4dc9 100644 --- a/apps/sim/lib/internal/onepassword/operations.test.ts +++ b/apps/sim/lib/internal/onepassword/operations.test.ts @@ -1,7 +1,12 @@ /** * @vitest-environment node */ -import { beforeEach, describe, expect, it, vi } from 'vitest' + +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { + isInternalToolFileResult, + type StoredToolFile, +} from '@/lib/internal/tool-operations/file-result' const clientMocks = vi.hoisted(() => ({ connectItemToSdkItem: vi.fn(), @@ -201,20 +206,65 @@ describe('1Password operations', () => { { signal: controller.signal } ) - expect(result).toEqual({ - file: { + assert(isInternalToolFileResult(result)) + expect(result.files).toEqual([ + { name: 'secret.txt', mimeType: 'text/plain', - data: Buffer.from('hello').toString('base64'), - size: 5, + buffer: Buffer.from('hello'), }, - }) + ]) + const storedFile: StoredToolFile = { + id: 'stored-file-1', + key: 'execution/stored-file-1', + url: '/api/files/serve/stored-file-1', + name: 'secret.txt', + type: 'text/plain', + mimeType: 'text/plain', + size: 5, + context: 'execution', + } + expect(result.present([storedFile])).toEqual({ file: storedFile }) expect(clientMocks.connectRequest.mock.calls[1]?.[0]).toMatchObject({ maxResponseBytes: 5, signal: controller.signal, }) }) + it('returns SDK attachment bytes for storage with the actual byte length', async () => { + clientMocks.createOnePasswordClient.mockResolvedValue({ + items: { + get: vi.fn().mockResolvedValue({ id: 'item-1' }), + files: { read: vi.fn().mockResolvedValue(new Uint8Array([1, 2, 3])) }, + }, + }) + clientMocks.findItemFileAttributes.mockReturnValue({ + id: 'file-1', + name: 'secret.bin', + size: 3, + }) + + const result = await executeOnePasswordGetItemFile( + { ...SERVICE_CREDENTIALS, vaultId: 'vault-1', itemId: 'item-1', fileId: 'file-1' }, + {} + ) + + expect(result.files).toEqual([ + { name: 'secret.bin', mimeType: 'application/octet-stream', buffer: Buffer.from([1, 2, 3]) }, + ]) + const storedFile: StoredToolFile = { + id: 'stored-file-1', + key: 'execution/stored-file-1', + url: '/api/files/serve/stored-file-1', + name: 'secret.bin', + type: 'application/octet-stream', + mimeType: 'application/octet-stream', + size: 3, + context: 'execution', + } + expect(result.present([storedFile])).toEqual({ file: storedFile }) + }) + it('preserves the private secret value and rejects Connect mode', async () => { const resolve = vi.fn().mockResolvedValue('resolved-secret') clientMocks.createOnePasswordClient.mockResolvedValue({ secrets: { resolve } }) diff --git a/apps/sim/lib/internal/onepassword/operations.ts b/apps/sim/lib/internal/onepassword/operations.ts index 27721610f4b..d33b3ba1cb0 100644 --- a/apps/sim/lib/internal/onepassword/operations.ts +++ b/apps/sim/lib/internal/onepassword/operations.ts @@ -32,6 +32,10 @@ import { applyOnePasswordPatch, type JsonPatchOperation, } from '@/lib/internal/onepassword/json-patch' +import { + createInternalToolFileResult, + type InternalToolFileResult, +} from '@/lib/internal/tool-operations/file-result' import { MAX_FILE_SIZE } from '@/lib/uploads/utils/validation' export interface OnePasswordOperationContext { @@ -373,9 +377,7 @@ export async function executeOnePasswordResolveSecret( export async function executeOnePasswordGetItemFile( input: GetItemFileInput, context: OnePasswordOperationContext -): Promise<{ - file: { name: string; mimeType: string; data: string; size: number } -}> { +): Promise { const credentials = resolveCredentials(input) if (credentials.mode === 'service_account') { const client = await createOnePasswordClient(credentials.serviceAccountToken, context.signal) @@ -390,14 +392,10 @@ export async function executeOnePasswordGetItemFile( ) assertKnownSizeWithinLimit(content.byteLength, MAX_FILE_SIZE, '1Password item file') const buffer = Buffer.from(content.buffer, content.byteOffset, content.byteLength) - return { - file: { - name: attributes.name, - mimeType: 'application/octet-stream', - data: buffer.toString('base64'), - size: attributes.size, - }, - } + return createInternalToolFileResult( + { buffer, name: attributes.name, mimeType: 'application/octet-stream' }, + (file) => ({ file }) + ) } const metadataResponse = await connectRequest({ @@ -434,12 +432,12 @@ export async function executeOnePasswordGetItemFile( } const buffer = Buffer.from(await contentResponse.arrayBuffer()) context.signal?.throwIfAborted() - return { - file: { + return createInternalToolFileResult( + { + buffer, name: typeof metadata.name === 'string' ? metadata.name : 'attachment', mimeType: contentResponse.headers.get('content-type') || 'application/octet-stream', - data: buffer.toString('base64'), - size: typeof metadata.size === 'number' ? metadata.size : buffer.length, }, - } + (file) => ({ file }) + ) } diff --git a/apps/sim/lib/internal/outlook/client.test.ts b/apps/sim/lib/internal/outlook/client.test.ts index 1954a636768..c085bca9b04 100644 --- a/apps/sim/lib/internal/outlook/client.test.ts +++ b/apps/sim/lib/internal/outlook/client.test.ts @@ -2,7 +2,7 @@ * @vitest-environment node */ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -import { PayloadSizeLimitError } from '@/lib/core/utils/stream-limits' +import { DEFAULT_MAX_ERROR_BODY_BYTES, PayloadSizeLimitError } from '@/lib/core/utils/stream-limits' import { OutlookClient } from '@/lib/internal/outlook/client' import { OutlookOperationError } from '@/lib/internal/outlook/errors' @@ -86,6 +86,94 @@ describe('OutlookClient', () => { ) }) + it('reads raw attachments larger than 10 MiB with OAuth and cancellation', async () => { + const bytes = Buffer.alloc(12 * 1024 * 1024, 4) + fetchMock.mockResolvedValue( + new Response(bytes, { headers: { 'content-type': 'application/pdf' } }) + ) + const controller = new AbortController() + + const result = await new OutlookClient('access-token').buffer( + '/me/messages/message-1/attachments/file-1/$value', + 100 * 1024 * 1024, + 'Failed to download attachment', + controller.signal + ) + + expect(result.buffer.equals(bytes)).toBe(true) + expect(result.contentType).toBe('application/pdf') + expect(fetchMock).toHaveBeenCalledWith( + 'https://graph.microsoft.com/v1.0/me/messages/message-1/attachments/file-1/$value', + { + method: 'GET', + headers: { Authorization: 'Bearer access-token' }, + signal: controller.signal, + } + ) + }) + + it('accepts a zero-byte attachment body', async () => { + fetchMock.mockResolvedValue(new Response(new Uint8Array(0))) + + const result = await new OutlookClient('access-token').buffer( + '/attachment/$value', + 1024, + 'Failed' + ) + + expect(result.buffer.byteLength).toBe(0) + }) + + it.each(['declared', 'actual'])('enforces the %s raw-body limit', async (sizeSource) => { + fetchMock.mockResolvedValue( + new Response(new Uint8Array(1025), { + headers: { 'content-length': sizeSource === 'declared' ? '1025' : '1' }, + }) + ) + + await expect( + new OutlookClient('access-token').buffer('/attachment/$value', 1024, 'Failed') + ).rejects.toBeInstanceOf(PayloadSizeLimitError) + }) + + it('preserves raw-download Graph error messages and status', async () => { + fetchMock.mockResolvedValue( + Response.json({ error: { message: 'Access denied' } }, { status: 403 }) + ) + + await expect( + new OutlookClient('access-token').buffer('/attachment/$value', 1024, 'Failed to download') + ).rejects.toEqual(new OutlookOperationError('Access denied', 403)) + }) + + it('bounds raw-download error bodies while preserving provider status', async () => { + fetchMock.mockResolvedValue( + new Response('bad gateway', { + status: 502, + headers: { 'content-length': String(DEFAULT_MAX_ERROR_BODY_BYTES + 1) }, + }) + ) + + await expect( + new OutlookClient('access-token').buffer('/attachment/$value', 1024, 'Failed to download') + ).rejects.toEqual(new OutlookOperationError('Failed to download', 502)) + }) + + it('rejects cancelled raw downloads before fetch', async () => { + const controller = new AbortController() + controller.abort(new DOMException('cancelled', 'AbortError')) + + await expect( + new OutlookClient('access-token').buffer( + '/attachment/$value', + 1024, + 'Failed', + controller.signal + ) + ).rejects.toMatchObject({ name: 'AbortError' }) + expect(fetchMock).not.toHaveBeenCalled() + }) + it('stops before provider work when already cancelled', async () => { const controller = new AbortController() controller.abort(new DOMException('cancelled', 'AbortError')) diff --git a/apps/sim/lib/internal/outlook/client.ts b/apps/sim/lib/internal/outlook/client.ts index 7c4e70035bb..2b7a2ac7e2b 100644 --- a/apps/sim/lib/internal/outlook/client.ts +++ b/apps/sim/lib/internal/outlook/client.ts @@ -1,5 +1,9 @@ import { getErrorMessage } from '@sim/utils/errors' -import { readResponseTextWithLimit } from '@/lib/core/utils/stream-limits' +import { + DEFAULT_MAX_ERROR_BODY_BYTES, + readResponseTextWithLimit, + readResponseToBufferWithLimit, +} from '@/lib/core/utils/stream-limits' import { OutlookOperationError } from '@/lib/internal/outlook/errors' const MICROSOFT_GRAPH_BASE_URL = 'https://graph.microsoft.com/v1.0' @@ -98,4 +102,40 @@ export class OutlookClient { await response.body?.cancel() signal?.throwIfAborted() } + + async buffer( + path: string, + maxBytes: number, + fallbackError: string, + signal?: AbortSignal + ): Promise<{ buffer: Buffer; contentType: string | null }> { + signal?.throwIfAborted() + const response = await fetch(this.url(path), { + method: 'GET', + headers: { Authorization: `Bearer ${this.accessToken}` }, + signal, + }) + if (!response.ok) { + let data: OutlookJsonObject = {} + try { + data = parseJson( + await readResponseTextWithLimit(response, { + maxBytes: DEFAULT_MAX_ERROR_BODY_BYTES, + label: 'Microsoft Graph error response', + signal, + }) + ) + } catch { + signal?.throwIfAborted() + } + throw new OutlookOperationError(graphErrorMessage(data, fallbackError), response.status) + } + const buffer = await readResponseToBufferWithLimit(response, { + maxBytes, + label: 'Outlook attachment', + signal, + }) + signal?.throwIfAborted() + return { buffer, contentType: response.headers.get('content-type') } + } } diff --git a/apps/sim/lib/internal/outlook/execute-tool.test.ts b/apps/sim/lib/internal/outlook/execute-tool.test.ts index 63a032b41b4..cdeb57e9030 100644 --- a/apps/sim/lib/internal/outlook/execute-tool.test.ts +++ b/apps/sim/lib/internal/outlook/execute-tool.test.ts @@ -8,6 +8,7 @@ const operationMocks = vi.hoisted(() => ({ executeOutlookCopy: vi.fn(), executeOutlookDelete: vi.fn(), executeOutlookDraft: vi.fn(), + executeOutlookGetAttachment: vi.fn(), executeOutlookMarkRead: vi.fn(), executeOutlookMarkUnread: vi.fn(), executeOutlookMove: vi.fn(), @@ -18,9 +19,16 @@ vi.mock('@/lib/internal/outlook/operations', () => operationMocks) import { DEFAULT_MAX_JSON_BODY_BYTES } from '@/lib/api/server/validation' import { OutlookOperationError } from '@/lib/internal/outlook/errors' -import { executeOutlookTool } from '@/lib/internal/outlook/execute-tool' +import { executeOutlookTool as executeOutlookToolOperation } from '@/lib/internal/outlook/execute-tool' +import { createInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' import type { InternalToolOperationCall } from '@/lib/internal/tool-operations/types' +async function executeOutlookTool(request: InternalToolOperationCall): Promise { + const result = await executeOutlookToolOperation(request) + if (!(result instanceof Response)) throw new Error('Expected a JSON response') + return result +} + const MESSAGE_BODY = { accessToken: 'access-token', messageId: 'message-1' } const COPY_MOVE_BODY = { ...MESSAGE_BODY, destinationId: 'folder-1' } const MAIL_BODY = { @@ -51,6 +59,12 @@ const TOOL_CASES = [ ['outlook_copy', COPY_MOVE_BODY, operationMocks.executeOutlookCopy, 'provider'], ['outlook_delete', MESSAGE_BODY, operationMocks.executeOutlookDelete, 'provider'], ['outlook_draft', MAIL_BODY, operationMocks.executeOutlookDraft, 'mail'], + [ + 'outlook_get_attachment', + { ...MESSAGE_BODY, attachmentId: 'attachment-1' }, + operationMocks.executeOutlookGetAttachment, + 'provider', + ], ['outlook_mark_read', MESSAGE_BODY, operationMocks.executeOutlookMarkRead, 'provider'], ['outlook_mark_unread', MESSAGE_BODY, operationMocks.executeOutlookMarkUnread, 'provider'], ['outlook_move', COPY_MOVE_BODY, operationMocks.executeOutlookMove, 'provider'], @@ -86,6 +100,55 @@ describe('executeOutlookTool', () => { } ) + it('passes large attachment bytes to the central presenter without serializing them', async () => { + const buffer = Buffer.alloc(12 * 1024 * 1024) + const fileResult = createInternalToolFileResult( + { buffer, name: 'report.xlsx', mimeType: 'application/octet-stream' }, + (file) => ({ success: true, output: { attachments: [file] } }) + ) + operationMocks.executeOutlookGetAttachment.mockResolvedValue(fileResult) + + const result = await executeOutlookToolOperation( + createRequest({ + toolId: 'outlook_get_attachment', + input: { ...MESSAGE_BODY, attachmentId: 'attachment-1' }, + }) + ) + + expect(result).toBe(fileResult) + }) + + it('rejects invalid attachment IDs before provider work', async () => { + const response = await executeOutlookTool( + createRequest({ + toolId: 'outlook_get_attachment', + input: { ...MESSAGE_BODY, attachmentId: ' ' }, + }) + ) + + expect(response.status).toBe(400) + expect(operationMocks.executeOutlookGetAttachment).not.toHaveBeenCalled() + }) + + it('preserves attachment size errors as 413 responses', async () => { + operationMocks.executeOutlookGetAttachment.mockRejectedValue( + new OutlookOperationError('Outlook attachment exceeds the size limit', 413) + ) + + const response = await executeOutlookTool( + createRequest({ + toolId: 'outlook_get_attachment', + input: { ...MESSAGE_BODY, attachmentId: 'attachment-1' }, + }) + ) + + expect(response.status).toBe(413) + await expect(response.json()).resolves.toEqual({ + success: false, + error: 'Outlook attachment exceeds the size limit', + }) + }) + it('returns the canonical validation envelope before provider work', async () => { const response = await executeOutlookTool( createRequest({ input: { accessToken: '', messageId: '' } }) diff --git a/apps/sim/lib/internal/outlook/execute-tool.ts b/apps/sim/lib/internal/outlook/execute-tool.ts index b209433362c..6c219f184e4 100644 --- a/apps/sim/lib/internal/outlook/execute-tool.ts +++ b/apps/sim/lib/internal/outlook/execute-tool.ts @@ -11,34 +11,48 @@ import { } from '@/lib/api/contracts/tools/microsoft' import { DEFAULT_MAX_JSON_BODY_BYTES } from '@/lib/api/server/validation' import { OutlookOperationError } from '@/lib/internal/outlook/errors' +import { outlookGetAttachmentInputSchema } from '@/lib/internal/outlook/get-attachment-input' import { executeOutlookCopy, executeOutlookDelete, executeOutlookDraft, + executeOutlookGetAttachment, executeOutlookMarkRead, executeOutlookMarkUnread, executeOutlookMove, executeOutlookSend, type OutlookMailOperationContext, } from '@/lib/internal/outlook/operations' +import { isInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' +import { parseInternalOperationInput } from '@/lib/internal/tool-operations/parse-contract-input' import { parseInternalToolInput } from '@/lib/internal/tool-operations/parse-input' -import type { InternalToolOperationHandler } from '@/lib/internal/tool-operations/types' +import type { + InternalToolOperationHandler, + InternalToolOperationResult, +} from '@/lib/internal/tool-operations/types' async function executeOperation( contract: C, input: unknown, execute: (input: ContractBody) => Promise, signal?: AbortSignal -): Promise { +): Promise { signal?.throwIfAborted() const parsed = parseInternalToolInput(contract, input, { maxInputBytes: DEFAULT_MAX_JSON_BODY_BYTES, }) if (!parsed.success) return parsed.response + return executeAndPresent(() => execute(parsed.data), signal) +} + +async function executeAndPresent( + execute: () => Promise, + signal?: AbortSignal +): Promise { try { - const result = await execute(parsed.data) + const result = await execute() signal?.throwIfAborted() - return Response.json(result) + return isInternalToolFileResult(result) ? result : Response.json(result) } catch (error) { signal?.throwIfAborted() if (error instanceof OutlookOperationError) { @@ -51,14 +65,24 @@ async function executeOperation( } } -export const executeOutlookTool: InternalToolOperationHandler = async (request) => { +export const executeOutlookTool: InternalToolOperationHandler = async ( + request +) => { const { input, context, requestId, signal, toolId } = request + signal?.throwIfAborted() const mailContext: OutlookMailOperationContext = { requestId, signal, userId: context.userId, } switch (toolId) { + case 'outlook_get_attachment': { + const parsed = parseInternalOperationInput({ body: outlookGetAttachmentInputSchema }, input, { + maxInputBytes: DEFAULT_MAX_JSON_BODY_BYTES, + }) + if (!parsed.success) return parsed.response + return executeAndPresent(() => executeOutlookGetAttachment(parsed.data.body, signal), signal) + } case 'outlook_copy': return executeOperation( outlookCopyContract, diff --git a/apps/sim/lib/internal/outlook/get-attachment-input.ts b/apps/sim/lib/internal/outlook/get-attachment-input.ts new file mode 100644 index 00000000000..8e423a4a6d7 --- /dev/null +++ b/apps/sim/lib/internal/outlook/get-attachment-input.ts @@ -0,0 +1,10 @@ +import { z } from 'zod' +import { accessTokenSchema, messageIdSchema } from '@/lib/api/contracts/tools/microsoft' + +export const outlookGetAttachmentInputSchema = z.object({ + accessToken: accessTokenSchema, + messageId: messageIdSchema.trim().min(1, 'Message ID is required'), + attachmentId: z.string().trim().min(1, 'Attachment ID is required'), +}) + +export type OutlookGetAttachmentInput = z.infer diff --git a/apps/sim/lib/internal/outlook/operations.test.ts b/apps/sim/lib/internal/outlook/operations.test.ts index 2587dc1acca..e5d39b3fbc8 100644 --- a/apps/sim/lib/internal/outlook/operations.test.ts +++ b/apps/sim/lib/internal/outlook/operations.test.ts @@ -7,6 +7,7 @@ const mocks = vi.hoisted(() => ({ assertToolFileAccess: vi.fn(), downloadServableFilesWithinBudget: vi.fn(), empty: vi.fn(), + buffer: vi.fn(), json: vi.fn(), processFilesToUserFiles: vi.fn(), })) @@ -17,6 +18,10 @@ vi.mock('@/lib/internal/outlook/client', () => ({ return mocks.json(...args) } + buffer(...args: unknown[]) { + return mocks.buffer(...args) + } + empty(...args: unknown[]) { return mocks.empty(...args) } @@ -38,11 +43,17 @@ import { executeOutlookCopy, executeOutlookDelete, executeOutlookDraft, + executeOutlookGetAttachment, executeOutlookMarkRead, executeOutlookMarkUnread, executeOutlookMove, executeOutlookSend, } from '@/lib/internal/outlook/operations' +import { + isInternalToolFileResult, + type StoredToolFile, +} from '@/lib/internal/tool-operations/file-result' +import { MAX_BUFFERED_TRANSFER_BYTES } from '@/lib/uploads/shared/types' const MAIL_INPUT = { accessToken: 'access-token', @@ -81,6 +92,7 @@ describe('Outlook operations', () => { { buffer: Buffer.from('report'), contentType: 'application/pdf' }, ]) mocks.empty.mockResolvedValue(undefined) + mocks.buffer.mockResolvedValue({ buffer: Buffer.alloc(0), contentType: null }) mocks.json.mockResolvedValue({}) mocks.processFilesToUserFiles.mockReturnValue([]) }) @@ -333,3 +345,182 @@ describe('Outlook operations', () => { expect(mocks.assertToolFileAccess).not.toHaveBeenCalled() }) }) + +const ATTACHMENT_INPUT = { + accessToken: 'access-token', + messageId: ' message/1 ', + attachmentId: ' attachment/1 ', +} + +const ATTACHMENT_METADATA = { + '@odata.type': '#microsoft.graph.fileAttachment', + id: 'attachment/1', + name: 'report.xlsx', + contentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + size: 12 * 1024 * 1024, + isInline: false, + lastModifiedDateTime: '2026-09-11T10:00:00Z', +} + +describe('Outlook attachment downloads', () => { + beforeEach(() => { + vi.clearAllMocks() + mocks.json.mockResolvedValue(ATTACHMENT_METADATA) + mocks.buffer.mockResolvedValue({ buffer: Buffer.alloc(0), contentType: null }) + }) + + it('fetches metadata separately and presents a large file as a stored reference', async () => { + const buffer = Buffer.alloc(12 * 1024 * 1024, 1) + const controller = new AbortController() + mocks.buffer.mockResolvedValue({ buffer, contentType: 'application/octet-stream' }) + + const result = await executeOutlookGetAttachment(ATTACHMENT_INPUT, controller.signal) + + expect(mocks.json).toHaveBeenCalledWith( + '/me/messages/message%2F1/attachments/attachment%2F1?$select=id,name,contentType,size,isInline,lastModifiedDateTime', + { method: 'GET' }, + 'Failed to retrieve attachment', + controller.signal + ) + expect(mocks.buffer).toHaveBeenCalledWith( + '/me/messages/message%2F1/attachments/attachment%2F1/$value', + MAX_BUFFERED_TRANSFER_BYTES, + 'Failed to download attachment', + controller.signal + ) + if (!isInternalToolFileResult(result)) throw new Error('Expected a file result') + expect(result.files).toHaveLength(1) + expect(result.files[0]?.buffer).toBe(buffer) + expect(result.files[0]?.name).toBe(ATTACHMENT_METADATA.name) + expect(result.files[0]?.mimeType).toBe(ATTACHMENT_METADATA.contentType) + const stored: StoredToolFile = { + id: 'stored-1', + key: 'execution/stored-1', + name: ATTACHMENT_METADATA.name, + size: buffer.byteLength, + type: ATTACHMENT_METADATA.contentType, + mimeType: ATTACHMENT_METADATA.contentType, + url: '/api/files/serve/stored-1', + } + const body = result.present([stored]) + expect(body).toEqual({ + success: true, + output: { + message: 'Successfully retrieved attachment "report.xlsx".', + results: { + id: 'attachment/1', + name: ATTACHMENT_METADATA.name, + contentType: ATTACHMENT_METADATA.contentType, + size: buffer.byteLength, + isInline: false, + attachmentType: '#microsoft.graph.fileAttachment', + lastModifiedDateTime: ATTACHMENT_METADATA.lastModifiedDateTime, + }, + attachments: [stored], + }, + }) + expect(Buffer.byteLength(JSON.stringify(body))).toBeLessThan(2000) + expect(JSON.stringify(body)).not.toContain('contentBytes') + }) + + it('preserves zero-byte file attachments', async () => { + mocks.json.mockResolvedValue({ ...ATTACHMENT_METADATA, size: 0 }) + + const result = await executeOutlookGetAttachment(ATTACHMENT_INPUT) + + if (!isInternalToolFileResult(result)) throw new Error('Expected a file result') + expect(result.files[0]?.buffer.byteLength).toBe(0) + expect(mocks.buffer).toHaveBeenCalledOnce() + }) + + it.each(['#microsoft.graph.itemAttachment', '#microsoft.graph.referenceAttachment'])( + 'preserves %s metadata without trying to download raw content', + async (attachmentType) => { + mocks.json.mockResolvedValue({ ...ATTACHMENT_METADATA, '@odata.type': attachmentType }) + + const result = await executeOutlookGetAttachment(ATTACHMENT_INPUT) + + expect(result).toMatchObject({ + success: true, + output: { + results: { attachmentType, name: 'report.xlsx' }, + attachments: [], + }, + }) + expect(mocks.buffer).not.toHaveBeenCalled() + } + ) + + it('rejects metadata above 100 MiB before fetching file bytes', async () => { + mocks.json.mockResolvedValue({ + ...ATTACHMENT_METADATA, + size: MAX_BUFFERED_TRANSFER_BYTES + 1, + }) + + await expect(executeOutlookGetAttachment(ATTACHMENT_INPUT)).rejects.toMatchObject({ + status: 413, + }) + expect(mocks.buffer).not.toHaveBeenCalled() + }) + + it('accepts the exact metadata size limit and bounds the raw body independently', async () => { + mocks.json.mockResolvedValue({ ...ATTACHMENT_METADATA, size: MAX_BUFFERED_TRANSFER_BYTES }) + mocks.buffer.mockRejectedValue( + new PayloadSizeLimitError({ + label: 'Outlook attachment', + maxBytes: MAX_BUFFERED_TRANSFER_BYTES, + observedBytes: MAX_BUFFERED_TRANSFER_BYTES + 1, + }) + ) + + await expect(executeOutlookGetAttachment(ATTACHMENT_INPUT)).rejects.toMatchObject({ + status: 413, + }) + expect(mocks.buffer).toHaveBeenCalledOnce() + }) + + it.each(['metadata', 'download'])('preserves Graph %s errors and HTTP status', async (phase) => { + const error = new OutlookOperationError('Attachment not found', 404) + if (phase === 'metadata') mocks.json.mockRejectedValueOnce(error) + else mocks.buffer.mockRejectedValueOnce(error) + + await expect(executeOutlookGetAttachment(ATTACHMENT_INPUT)).rejects.toBe(error) + if (phase === 'metadata') expect(mocks.buffer).not.toHaveBeenCalled() + }) + + it('uses response MIME and a fallback filename when metadata omits them', async () => { + mocks.json.mockResolvedValue({ '@odata.type': '#microsoft.graph.fileAttachment' }) + mocks.buffer.mockResolvedValue({ buffer: Buffer.from('text'), contentType: 'text/plain' }) + + const result = await executeOutlookGetAttachment(ATTACHMENT_INPUT) + + if (!isInternalToolFileResult(result)) throw new Error('Expected a file result') + expect(result.files[0]?.name).toBe('attachment') + expect(result.files[0]?.mimeType).toBe('text/plain') + }) + + it('stops between metadata and raw downloads when cancelled', async () => { + const controller = new AbortController() + mocks.json.mockImplementationOnce(async () => { + controller.abort(new DOMException('cancelled', 'AbortError')) + return ATTACHMENT_METADATA + }) + + await expect( + executeOutlookGetAttachment(ATTACHMENT_INPUT, controller.signal) + ).rejects.toMatchObject({ name: 'AbortError' }) + expect(mocks.buffer).not.toHaveBeenCalled() + }) + + it('does not produce a file result if cancellation occurs during download', async () => { + const controller = new AbortController() + mocks.buffer.mockImplementationOnce(async () => { + controller.abort(new DOMException('cancelled', 'AbortError')) + return { buffer: Buffer.alloc(0), contentType: null } + }) + + await expect( + executeOutlookGetAttachment(ATTACHMENT_INPUT, controller.signal) + ).rejects.toMatchObject({ name: 'AbortError' }) + }) +}) diff --git a/apps/sim/lib/internal/outlook/operations.ts b/apps/sim/lib/internal/outlook/operations.ts index 1f6594c1f0a..972e1c4cb33 100644 --- a/apps/sim/lib/internal/outlook/operations.ts +++ b/apps/sim/lib/internal/outlook/operations.ts @@ -9,17 +9,22 @@ import type { OutlookMoveBody, OutlookSendBody, } from '@/lib/api/contracts/tools/microsoft' -import { isPayloadSizeLimitError } from '@/lib/core/utils/stream-limits' +import { assertKnownSizeWithinLimit, isPayloadSizeLimitError } from '@/lib/core/utils/stream-limits' import { OutlookClient, type OutlookJsonObject } from '@/lib/internal/outlook/client' import { OutlookOperationError } from '@/lib/internal/outlook/errors' +import type { OutlookGetAttachmentInput } from '@/lib/internal/outlook/get-attachment-input' +import { createInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' +import { MAX_BUFFERED_TRANSFER_BYTES } from '@/lib/uploads/shared/types' import { docNotReadyMessage, isDocNotReadyError } from '@/lib/uploads/utils/doc-not-ready' import { processFilesToUserFiles } from '@/lib/uploads/utils/file-utils' import { downloadServableFilesWithinBudget } from '@/lib/uploads/utils/file-utils.server' import { assertToolFileAccess } from '@/app/api/files/authorization' +import type { CleanedOutlookAttachmentMetadata } from '@/tools/outlook/types' const logger = createLogger('OutlookOperations') const OUTLOOK_SEND_ATTACHMENT_MAX_BYTES = 3 * 1024 * 1024 const OUTLOOK_DRAFT_ATTACHMENT_MAX_BYTES = 4 * 1024 * 1024 +const OUTLOOK_ATTACHMENT_METADATA_FIELDS = 'id,name,contentType,size,isInline,lastModifiedDateTime' interface OutlookMailOperationContext { requestId: string @@ -148,6 +153,62 @@ async function buildMessage( return message } +export async function executeOutlookGetAttachment( + input: OutlookGetAttachmentInput, + signal?: AbortSignal +) { + signal?.throwIfAborted() + const client = new OutlookClient(input.accessToken) + const path = `/me/messages/${encodeURIComponent(input.messageId.trim())}/attachments/${encodeURIComponent(input.attachmentId.trim())}` + try { + const data = await client.json( + `${path}?$select=${OUTLOOK_ATTACHMENT_METADATA_FIELDS}`, + { method: 'GET' }, + 'Failed to retrieve attachment', + signal + ) + signal?.throwIfAborted() + const results: CleanedOutlookAttachmentMetadata = { + id: optionalString(data, 'id') ?? input.attachmentId.trim(), + name: optionalString(data, 'name') ?? null, + contentType: optionalString(data, 'contentType') ?? null, + size: typeof data.size === 'number' ? data.size : null, + isInline: optionalBoolean(data, 'isInline') ?? null, + attachmentType: optionalString(data, '@odata.type') ?? null, + lastModifiedDateTime: optionalString(data, 'lastModifiedDateTime') ?? null, + } + const output = { + message: `Successfully retrieved attachment "${results.name ?? ''}".`, + results, + } + if (results.attachmentType !== '#microsoft.graph.fileAttachment') { + return { success: true, output: { ...output, attachments: [] } } + } + if (results.size !== null && results.size !== undefined) { + assertKnownSizeWithinLimit(results.size, MAX_BUFFERED_TRANSFER_BYTES, 'Outlook attachment') + } + const { buffer, contentType } = await client.buffer( + `${path}/$value`, + MAX_BUFFERED_TRANSFER_BYTES, + 'Failed to download attachment', + signal + ) + signal?.throwIfAborted() + return createInternalToolFileResult( + { + buffer, + name: results.name || 'attachment', + mimeType: results.contentType || contentType || 'application/octet-stream', + }, + (file) => ({ success: true, output: { ...output, attachments: [file] } }) + ) + } catch (error) { + signal?.throwIfAborted() + if (isPayloadSizeLimitError(error)) throw new OutlookOperationError(error.message, 413) + throw error + } +} + export async function executeOutlookCopy(input: OutlookCopyBody, signal?: AbortSignal) { const client = new OutlookClient(input.accessToken) const data = await client.json( diff --git a/apps/sim/lib/internal/pipedrive/execute-tool.ts b/apps/sim/lib/internal/pipedrive/execute-tool.ts index 78394ababff..ba5baf9db86 100644 --- a/apps/sim/lib/internal/pipedrive/execute-tool.ts +++ b/apps/sim/lib/internal/pipedrive/execute-tool.ts @@ -5,7 +5,11 @@ import { DEFAULT_MAX_JSON_BODY_BYTES } from '@/lib/api/server/validation' import { PipedriveOperationError } from '@/lib/internal/pipedrive/errors' import { executePipedriveGetFiles } from '@/lib/internal/pipedrive/operations' import { pipedriveGetFilesInputSchema } from '@/lib/internal/pipedrive/schema' -import type { InternalToolOperationHandler } from '@/lib/internal/tool-operations/types' +import { isInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' +import type { + InternalToolOperationHandler, + InternalToolOperationResult, +} from '@/lib/internal/tool-operations/types' const logger = createLogger('PipedriveToolExecution') @@ -26,7 +30,9 @@ function inputSizeError(input: unknown): Response | null { : null } -export const executePipedriveTool: InternalToolOperationHandler = async (request) => { +export const executePipedriveTool: InternalToolOperationHandler< + InternalToolOperationResult +> = async (request) => { request.signal?.throwIfAborted() if (request.toolId !== 'pipedrive_get_files') { return Response.json( @@ -52,7 +58,7 @@ export const executePipedriveTool: InternalToolOperationHandler = async (request signal: request.signal, }) request.signal?.throwIfAborted() - return Response.json(result) + return isInternalToolFileResult(result) ? result : Response.json(result) } catch (error) { request.signal?.throwIfAborted() if (error instanceof PipedriveOperationError) { diff --git a/apps/sim/lib/internal/pipedrive/operations.test.ts b/apps/sim/lib/internal/pipedrive/operations.test.ts new file mode 100644 index 00000000000..5b686ca2863 --- /dev/null +++ b/apps/sim/lib/internal/pipedrive/operations.test.ts @@ -0,0 +1,84 @@ +/** + * @vitest-environment node + */ +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' + +const mocks = vi.hoisted(() => ({ + downloadPipedriveFile: vi.fn(), + listPipedriveFiles: vi.fn(), +})) + +vi.mock('@/lib/internal/pipedrive/client', () => mocks) + +import { executePipedriveGetFiles } from '@/lib/internal/pipedrive/operations' +import { + isInternalToolFileResult, + type StoredToolFile, +} from '@/lib/internal/tool-operations/file-result' +import { MAX_BUFFERED_TRANSFER_BYTES } from '@/lib/uploads/shared/types' + +describe('executePipedriveGetFiles', () => { + beforeEach(() => { + vi.clearAllMocks() + mocks.listPipedriveFiles.mockResolvedValue({ + files: [{ id: 1, name: 'report.pdf', url: 'https://files.example/report.pdf' }], + hasMore: true, + nextStart: 1, + }) + }) + + it('keeps large downloads out of JSON while preserving file-list pagination', async () => { + const buffer = Buffer.alloc(11 * 1024 * 1024, 1) + mocks.downloadPipedriveFile.mockResolvedValue({ buffer, contentType: 'application/pdf' }) + const controller = new AbortController() + const input = { accessToken: 'token', downloadFiles: true } + const result = await executePipedriveGetFiles(input, { + requestId: 'request-1', + signal: controller.signal, + }) + + assert(isInternalToolFileResult(result)) + expect(result.files).toHaveLength(1) + expect(result.files[0]?.buffer).toBe(buffer) + expect(result.files[0]?.name).toBe('report.pdf') + expect(result.files[0]?.mimeType).toBe('application/pdf') + expect(mocks.downloadPipedriveFile).toHaveBeenCalledWith( + 'https://files.example/report.pdf', + input, + MAX_BUFFERED_TRANSFER_BYTES, + controller.signal + ) + const storedFile: StoredToolFile = { + id: 'stored-file-1', + key: 'execution/stored-file-1', + url: '/api/files/serve/stored-file-1', + name: 'report.pdf', + type: 'application/pdf', + mimeType: 'application/pdf', + size: buffer.length, + context: 'execution', + } + expect(result.present([storedFile])).toEqual({ + success: true, + output: { + files: [{ id: 1, name: 'report.pdf', url: 'https://files.example/report.pdf' }], + downloadedFiles: [storedFile], + total_items: 1, + has_more: true, + next_start: 1, + success: true, + }, + }) + }) + + it('returns metadata without file persistence when downloads are disabled', async () => { + const result = await executePipedriveGetFiles( + { accessToken: 'token', downloadFiles: false }, + { requestId: 'request-1' } + ) + + expect(isInternalToolFileResult(result)).toBe(false) + expect(result).toMatchObject({ success: true, output: { has_more: true, next_start: 1 } }) + expect(mocks.downloadPipedriveFile).not.toHaveBeenCalled() + }) +}) diff --git a/apps/sim/lib/internal/pipedrive/operations.ts b/apps/sim/lib/internal/pipedrive/operations.ts index 0418852eeca..068def9a162 100644 --- a/apps/sim/lib/internal/pipedrive/operations.ts +++ b/apps/sim/lib/internal/pipedrive/operations.ts @@ -1,6 +1,10 @@ import { createLogger } from '@sim/logger' import { downloadPipedriveFile, listPipedriveFiles } from '@/lib/internal/pipedrive/client' import type { PipedriveGetFilesInput } from '@/lib/internal/pipedrive/schema' +import { + createInternalToolFilesResult, + type InternalToolFile, +} from '@/lib/internal/tool-operations/file-result' import { MAX_BUFFERED_TRANSFER_BYTES } from '@/lib/uploads/shared/types' import { getFileExtension, getMimeTypeFromExtension } from '@/lib/uploads/utils/file-utils' @@ -17,12 +21,7 @@ export async function executePipedriveGetFiles( ) { context.signal?.throwIfAborted() const page = await listPipedriveFiles(input, context.signal) - const downloadedFiles: Array<{ - data: string - mimeType: string - name: string - size: number - }> = [] + const downloadedFiles: InternalToolFile[] = [] let downloadedBytes = 0 if (input.downloadFiles) { @@ -43,8 +42,7 @@ export async function executePipedriveGetFiles( downloadedFiles.push({ name, mimeType: downloaded.contentType || getMimeTypeFromExtension(extension), - data: downloaded.buffer.toString('base64'), - size: downloaded.buffer.length, + buffer: downloaded.buffer, }) } catch (error) { context.signal?.throwIfAborted() @@ -56,15 +54,16 @@ export async function executePipedriveGetFiles( } } context.signal?.throwIfAborted() - return { + const output = { + files: page.files, + total_items: page.files.length, + has_more: page.hasMore, + next_start: page.nextStart, success: true, - output: { - files: page.files, - downloadedFiles: downloadedFiles.length > 0 ? downloadedFiles : undefined, - total_items: page.files.length, - has_more: page.hasMore, - next_start: page.nextStart, - success: true, - }, } + if (downloadedFiles.length === 0) return { success: true, output } + return createInternalToolFilesResult(downloadedFiles, (files) => ({ + success: true, + output: { ...output, downloadedFiles: files }, + })) } diff --git a/apps/sim/lib/internal/quiver/execute-tool.test.ts b/apps/sim/lib/internal/quiver/execute-tool.test.ts index d89b4394be8..83c4e3bb4f8 100644 --- a/apps/sim/lib/internal/quiver/execute-tool.test.ts +++ b/apps/sim/lib/internal/quiver/execute-tool.test.ts @@ -4,6 +4,7 @@ import { createExecutionContext } from '@sim/testing' import { beforeEach, describe, expect, it, vi } from 'vitest' import { DEFAULT_MAX_JSON_BODY_BYTES } from '@/lib/api/server/validation' +import { createInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' const mocks = vi.hoisted(() => ({ executeImage: vi.fn(), @@ -16,7 +17,7 @@ vi.mock('@/lib/internal/quiver/operations', () => ({ })) import { QuiverOperationError } from '@/lib/internal/quiver/errors' -import { executeQuiverTool } from '@/lib/internal/quiver/execute-tool' +import { executeQuiverTool as executeQuiverToolOperation } from '@/lib/internal/quiver/execute-tool' import type { InternalToolOperationCall } from '@/lib/internal/tool-operations/types' function request(overrides: Partial = {}) { @@ -30,6 +31,14 @@ function request(overrides: Partial = {}) { } as InternalToolOperationCall } +async function executeQuiverTool( + request: Parameters[0] +): Promise { + const result = await executeQuiverToolOperation(request) + if (!(result instanceof Response)) throw new Error('Expected a JSON response') + return result +} + describe('executeQuiverTool', () => { beforeEach(() => { vi.clearAllMocks() @@ -47,6 +56,18 @@ describe('executeQuiverTool', () => { mocks.executeImage.mockResolvedValue(result) }) + it('forwards binary file results without serializing them', async () => { + const result = createInternalToolFileResult( + { buffer: Buffer.from('file'), name: 'file.txt', mimeType: 'text/plain' }, + (file) => ({ file }) + ) + mocks.executeText.mockResolvedValueOnce(result) + expect(await executeQuiverToolOperation(request({ toolId: 'quiver_text_to_svg_v2' }))).toBe( + result + ) + expect(mocks.executeText.mock.calls[0]?.[2]).toBe('v2') + }) + it.each([ ['quiver_text_to_svg', mocks.executeText], ['quiver_image_to_svg', mocks.executeImage], @@ -65,6 +86,28 @@ describe('executeQuiverTool', () => { ) }) + it.each([ + ['quiver_text_to_svg_v2', mocks.executeText], + ['quiver_image_to_svg_v2', mocks.executeImage], + ])('selects the stored file projection for %s', async (toolId, execute) => { + const input = + toolId === 'quiver_image_to_svg_v2' + ? { apiKey: 'secret', model: 'arrow-preview', image: 'https://example.com/image.png' } + : { apiKey: 'secret', model: 'arrow-preview', prompt: 'A compass' } + const result = createInternalToolFileResult( + { buffer: Buffer.from(''), name: 'file.svg', mimeType: 'image/svg+xml' }, + (file) => ({ success: true, output: { file, files: [file] } }) + ) + execute.mockResolvedValueOnce(result) + + expect(await executeQuiverToolOperation(request({ toolId, input }))).toBe(result) + expect(execute).toHaveBeenCalledWith( + expect.objectContaining({ apiKey: 'secret', model: 'arrow-preview' }), + expect.objectContaining({ userId: 'user-1', requestId: 'request-1' }), + 'v2' + ) + }) + it('authenticates before parsing input', async () => { const response = await executeQuiverTool( request({ input: null, context: createExecutionContext({ workflowId: 'workflow-1' }) }) diff --git a/apps/sim/lib/internal/quiver/execute-tool.ts b/apps/sim/lib/internal/quiver/execute-tool.ts index f4e4663e4d1..545023779c0 100644 --- a/apps/sim/lib/internal/quiver/execute-tool.ts +++ b/apps/sim/lib/internal/quiver/execute-tool.ts @@ -14,9 +14,11 @@ import { quiverImageToSvgInputSchema, quiverTextToSvgInputSchema, } from '@/lib/internal/quiver/schema' +import { isInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' import type { InternalToolOperationCall, InternalToolOperationHandler, + InternalToolOperationResult, } from '@/lib/internal/tool-operations/types' const logger = createLogger('QuiverToolExecution') @@ -44,7 +46,7 @@ async function executeOperation( request: InternalToolOperationCall, schema: z.ZodType, execute: (input: Input, context: QuiverOperationContext) => Promise -): Promise { +): Promise { request.signal?.throwIfAborted() const sizeError = validateInputSize(request.input) if (sizeError) return sizeError @@ -70,7 +72,7 @@ async function executeOperation( userId, }) request.signal?.throwIfAborted() - return Response.json(result) + return isInternalToolFileResult(result) ? result : Response.json(result) } catch (error) { request.signal?.throwIfAborted() if (error instanceof QuiverOperationError) { @@ -89,7 +91,9 @@ async function executeOperation( } } -export const executeQuiverTool: InternalToolOperationHandler = async (request) => { +export const executeQuiverTool: InternalToolOperationHandler = async ( + request +) => { request.signal?.throwIfAborted() if (!request.context.userId) { return Response.json({ success: false, error: 'Unauthorized' }, { status: 401 }) @@ -99,6 +103,14 @@ export const executeQuiverTool: InternalToolOperationHandler = async (request) = return executeOperation(request, quiverTextToSvgInputSchema, executeQuiverTextToSvg) case 'quiver_image_to_svg': return executeOperation(request, quiverImageToSvgInputSchema, executeQuiverImageToSvg) + case 'quiver_text_to_svg_v2': + return executeOperation(request, quiverTextToSvgInputSchema, (input, context) => + executeQuiverTextToSvg(input, context, 'v2') + ) + case 'quiver_image_to_svg_v2': + return executeOperation(request, quiverImageToSvgInputSchema, (input, context) => + executeQuiverImageToSvg(input, context, 'v2') + ) default: return Response.json( { success: false, error: `Unsupported Quiver tool: ${request.toolId}` }, diff --git a/apps/sim/lib/internal/quiver/operations.test.ts b/apps/sim/lib/internal/quiver/operations.test.ts index 65fc8133fda..ca4637f6d05 100644 --- a/apps/sim/lib/internal/quiver/operations.test.ts +++ b/apps/sim/lib/internal/quiver/operations.test.ts @@ -48,6 +48,19 @@ const context = { userId: 'user-1', } +function storedSvg(name: string) { + return { + id: name, + name, + size: 14, + type: 'image/svg+xml', + mimeType: 'image/svg+xml', + url: `/api/files/${name}`, + key: `execution/${name}`, + context: 'execution' as const, + } +} + describe('Quiver operations', () => { beforeEach(() => { vi.clearAllMocks() @@ -78,7 +91,8 @@ describe('Quiver operations', () => { n: 2, temperature: 0.5, }, - { ...context, signal: controller.signal } + { ...context, signal: controller.signal }, + 'v2' ) expect(mocks.assertToolFileAccess).toHaveBeenCalledTimes(2) @@ -110,13 +124,17 @@ describe('Quiver operations', () => { }, controller.signal ) - expect(result.output).toMatchObject({ - file: { name: 'generated-1.svg', mimeType: 'image/svg+xml' }, + expect(result.files).toHaveLength(2) + const storedFiles = [storedSvg('generated-1.svg'), storedSvg('generated-2.svg')] + const presented = result.present(storedFiles) as { output: { files: unknown[] } } + expect(presented.output.files).toBe(storedFiles) + expect(presented.output).toMatchObject({ files: [{ name: 'generated-1.svg' }, { name: 'generated-2.svg' }], - svgContent: 'one', id: 'generation-1', usage: { totalTokens: 9, inputTokens: 4, outputTokens: 5 }, }) + expect(Object.keys(presented.output).sort()).toEqual(['files', 'id', 'usage']) + expect(presented.output).not.toHaveProperty('svgContent') }) it('preserves image URL inputs without reading local files', async () => { @@ -128,7 +146,8 @@ describe('Quiver operations', () => { auto_crop: false, target_size: 512, }, - context + context, + 'v2' ) expect(mocks.assertToolFileAccess).not.toHaveBeenCalled() @@ -143,11 +162,39 @@ describe('Quiver operations', () => { }, undefined ) - expect(result.output.file.name).toBe('vectorized.svg') - expect(result.output.files).toHaveLength(1) - expect(result.output.svgContent).toBe('one') + expect(result.files[0]?.name).toBe('vectorized.svg') + expect(result.files).toHaveLength(1) + const file = storedSvg('vectorized.svg') + const presented = result.present([file]) + expect(presented).toMatchObject({ + output: { files: [file] }, + }) + expect(presented).not.toHaveProperty('output.file') + expect(presented).not.toHaveProperty('output.svgContent') }) + it.each([0, 12 * 1024 * 1024])( + 'returns only stored file references for %i bytes of SVG content', + async (size) => { + const svg = `${'x'.repeat(size)}` + mocks.requestQuiverSvg.mockResolvedValue({ data: [{ svg }] }) + const result = await executeQuiverTextToSvg( + { apiKey: 'secret', model: 'arrow-preview', prompt: 'A map' }, + context, + 'v2' + ) + expect(result.files).toHaveLength(1) + expect(result.files[0]?.buffer.length).toBe(Buffer.byteLength(svg)) + const file = storedSvg('generated.svg') + const presented = result.present([file]) + expect(presented).toEqual({ + success: true, + output: { files: [file], id: null, usage: null }, + }) + expect(JSON.stringify(presented).length).toBeLessThan(1024) + } + ) + it('authorizes stored image inputs and sends their bytes', async () => { await executeQuiverImageToSvg( { apiKey: 'secret', model: 'arrow-preview', image: rawFile }, @@ -174,6 +221,46 @@ describe('Quiver operations', () => { ) }) + it('preserves v1 inline file data and every generated SVG', async () => { + const result = await executeQuiverTextToSvg( + { apiKey: 'secret', model: 'arrow-preview', prompt: 'A compass', n: 2 }, + context + ) + const files = ['one', 'two'].map((name, index) => ({ + name: `generated-${index + 1}.svg`, + mimeType: 'image/svg+xml', + data: Buffer.from(`${name}`).toString('base64'), + size: Buffer.byteLength(`${name}`), + })) + + expect(result).toEqual({ + success: true, + output: { + file: files[0], + files, + svgContent: 'one', + id: 'generation-1', + usage: { totalTokens: 9, inputTokens: 4, outputTokens: 5 }, + }, + }) + }) + + it('preserves v1 vectorization first-file projection and inline markup', async () => { + const result = await executeQuiverImageToSvg( + { apiKey: 'secret', model: 'arrow-preview', image: 'https://images.example.com/source.png' }, + context + ) + expect(result.output.files).toHaveLength(1) + expect(result.output.file).toEqual({ + name: 'vectorized.svg', + mimeType: 'image/svg+xml', + data: Buffer.from('one').toString('base64'), + size: Buffer.byteLength('one'), + }) + expect(result.output.file).toBe(result.output.files[0]) + expect(result.output.svgContent).toBe('one') + }) + it('fails closed on incomplete private model-input provenance', async () => { const headers = new Headers({ [PRIVATE_MODEL_INPUT_PROVENANCE_HEADER]: RESOLVED_SECRET_PROVENANCE_METADATA_V1, diff --git a/apps/sim/lib/internal/quiver/operations.ts b/apps/sim/lib/internal/quiver/operations.ts index 809830b7bb1..33828b10e3f 100644 --- a/apps/sim/lib/internal/quiver/operations.ts +++ b/apps/sim/lib/internal/quiver/operations.ts @@ -4,6 +4,10 @@ import { validateOpaqueModelInputProvenance } from '@/lib/execution/model-input- import { requestQuiverSvg } from '@/lib/internal/quiver/client' import { QuiverOperationError } from '@/lib/internal/quiver/errors' import type { QuiverImageToSvgInput, QuiverTextToSvgInput } from '@/lib/internal/quiver/schema' +import { + createInternalToolFilesResult, + type InternalToolFileResult, +} from '@/lib/internal/tool-operations/file-result' import { isModelSafeWorkspaceFileKey, MODEL_UNSAFE_WORKSPACE_FILE_ERROR_MESSAGE, @@ -13,6 +17,7 @@ import type { RawFileInput } from '@/lib/uploads/utils/file-schemas' import { processFilesToUserFiles } from '@/lib/uploads/utils/file-utils' import { downloadFileFromStorage } from '@/lib/uploads/utils/file-utils.server' import { assertToolFileAccess } from '@/app/api/files/authorization' +import type { QuiverSvgResponse } from '@/tools/quiver/types' const logger = createLogger('QuiverOperations') @@ -23,32 +28,10 @@ export interface QuiverOperationContext { userId: string } -interface QuiverFile { - name: string - mimeType: 'image/svg+xml' - data: string - size: number -} - -interface QuiverUsage { - totalTokens: number - inputTokens: number - outputTokens: number -} - -export interface QuiverSvgOutput { - success: true - output: { - file: QuiverFile - files: QuiverFile[] - svgContent: string - id: string | null - usage: QuiverUsage | null - } -} - type ApiImage = { url: string } | { base64: string } +export type QuiverSvgOutput = QuiverSvgResponse & { success: true } + function fail(message: string, status: number, body?: Record): never { throw new QuiverOperationError(message, status, body) } @@ -155,8 +138,9 @@ async function resolveImage( function projectResult( result: unknown, fileName: (index: number, total: number) => string, + version: 'v1' | 'v2', firstOnly = false -): QuiverSvgOutput { +): QuiverSvgOutput | InternalToolFileResult { const root = record(result) const data = root.data if (!Array.isArray(data) || data.length === 0) { @@ -171,8 +155,7 @@ function projectResult( return { name: fileName(index, projectedData.length), mimeType: 'image/svg+xml' as const, - data: buffer.toString('base64'), - size: buffer.length, + buffer, } }) const usage = isRecordLike(root.usage) @@ -183,22 +166,49 @@ function projectResult( } : null - return { + if (version === 'v1') { + const inlineFiles = files.map(({ buffer, name, mimeType }) => ({ + name, + mimeType, + data: buffer.toString('base64'), + size: buffer.length, + })) + return { + success: true, + output: { + file: inlineFiles[0], + files: inlineFiles, + svgContent: record(data[0]).svg as string, + id: typeof root.id === 'string' ? root.id : null, + usage, + }, + } + } + + return createInternalToolFilesResult(files, (storedFiles) => ({ success: true, output: { - file: files[0], - files, - svgContent: record(data[0]).svg as string, + files: storedFiles, id: typeof root.id === 'string' ? root.id : null, usage, }, - } + })) } -export async function executeQuiverTextToSvg( +export function executeQuiverTextToSvg( input: QuiverTextToSvgInput, context: QuiverOperationContext -): Promise { +): Promise +export function executeQuiverTextToSvg( + input: QuiverTextToSvgInput, + context: QuiverOperationContext, + version: 'v2' +): Promise +export async function executeQuiverTextToSvg( + input: QuiverTextToSvgInput, + context: QuiverOperationContext, + version: 'v1' | 'v2' = 'v1' +): Promise { context.signal?.throwIfAborted() validateProvenance(input, context) const references: ApiImage[] = [] @@ -223,15 +233,27 @@ export async function executeQuiverTextToSvg( const result = await requestQuiverSvg('generations', input.apiKey, body, context.signal) context.signal?.throwIfAborted() - return projectResult(result, (index, total) => - total > 1 ? `generated-${index + 1}.svg` : 'generated.svg' + return projectResult( + result, + (index, total) => (total > 1 ? `generated-${index + 1}.svg` : 'generated.svg'), + version ) } -export async function executeQuiverImageToSvg( +export function executeQuiverImageToSvg( input: QuiverImageToSvgInput, context: QuiverOperationContext -): Promise { +): Promise +export function executeQuiverImageToSvg( + input: QuiverImageToSvgInput, + context: QuiverOperationContext, + version: 'v2' +): Promise +export async function executeQuiverImageToSvg( + input: QuiverImageToSvgInput, + context: QuiverOperationContext, + version: 'v1' | 'v2' = 'v1' +): Promise { context.signal?.throwIfAborted() validateProvenance(input, context) const image = await resolveImage(input.image, context) @@ -245,5 +267,5 @@ export async function executeQuiverImageToSvg( const result = await requestQuiverSvg('vectorizations', input.apiKey, body, context.signal) context.signal?.throwIfAborted() - return projectResult(result, () => 'vectorized.svg', true) + return projectResult(result, () => 'vectorized.svg', version, true) } diff --git a/apps/sim/lib/internal/sftp/execute-tool.test.ts b/apps/sim/lib/internal/sftp/execute-tool.test.ts index 901baba7b09..bf75f3c6194 100644 --- a/apps/sim/lib/internal/sftp/execute-tool.test.ts +++ b/apps/sim/lib/internal/sftp/execute-tool.test.ts @@ -2,6 +2,7 @@ * @vitest-environment node */ import { beforeEach, describe, expect, it, vi } from 'vitest' +import { createInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' const mocks = vi.hoisted(() => ({ executeDelete: vi.fn(), @@ -19,9 +20,9 @@ vi.mock('@/lib/internal/sftp/operations', () => ({ executeSftpUpload: mocks.executeUpload, })) -import { executeSftpTool } from '@/lib/internal/sftp/execute-tool' +import { executeSftpTool as executeSftpToolOperation } from '@/lib/internal/sftp/execute-tool' import { sftpDeleteTool } from '@/tools/sftp/delete' -import { sftpDownloadTool } from '@/tools/sftp/download' +import { sftpDownloadTool, sftpDownloadV2Tool } from '@/tools/sftp/download' import { sftpListTool } from '@/tools/sftp/list' import { sftpMkdirTool } from '@/tools/sftp/mkdir' import { sftpUploadTool } from '@/tools/sftp/upload' @@ -34,6 +35,14 @@ const baseInput = { remotePath: '/files', } +async function executeSftpTool( + request: Parameters[0] +): Promise { + const result = await executeSftpToolOperation(request) + if (!(result instanceof Response)) throw new Error('Expected a JSON response') + return result +} + describe('SFTP tool execution', () => { beforeEach(() => { vi.clearAllMocks() @@ -42,9 +51,29 @@ describe('SFTP tool execution', () => { } }) + it('forwards binary file results without serializing them', async () => { + const result = createInternalToolFileResult( + { buffer: Buffer.from('file'), name: 'file.txt', mimeType: 'text/plain' }, + (file) => ({ file }) + ) + mocks.executeDownload.mockResolvedValueOnce(result) + expect( + await executeSftpToolOperation({ + toolId: 'sftp_download_v2', + input: baseInput, + headers: new Headers(), + context: { userId: 'user-1' }, + requestId: 'request-1', + }) + ).toBe(result) + expect(mocks.executeDownload.mock.calls[0][0]).toEqual(baseInput) + expect(mocks.executeDownload.mock.calls[0][2]).toBe('v2') + }) + it.each([ ['sftp_delete', mocks.executeDelete], ['sftp_download', mocks.executeDownload], + ['sftp_download_v2', mocks.executeDownload], ['sftp_list', mocks.executeList], ['sftp_mkdir', mocks.executeMkdir], ['sftp_upload', mocks.executeUpload], @@ -81,6 +110,7 @@ describe('SFTP tool execution', () => { for (const tool of [ sftpDeleteTool, sftpDownloadTool, + sftpDownloadV2Tool, sftpListTool, sftpMkdirTool, sftpUploadTool, diff --git a/apps/sim/lib/internal/sftp/execute-tool.ts b/apps/sim/lib/internal/sftp/execute-tool.ts index 70d5b1d947b..79ed60322dd 100644 --- a/apps/sim/lib/internal/sftp/execute-tool.ts +++ b/apps/sim/lib/internal/sftp/execute-tool.ts @@ -14,6 +14,7 @@ import { import { sftpDeleteInputSchema, sftpDownloadInputSchema, + sftpDownloadV2InputSchema, sftpListInputSchema, sftpMkdirInputSchema, sftpUploadInputSchema, @@ -21,6 +22,7 @@ import { import type { InternalToolOperationCall, InternalToolOperationHandler, + InternalToolOperationResult, } from '@/lib/internal/tool-operations/types' const logger = createLogger('SftpToolExecution') @@ -28,8 +30,11 @@ const logger = createLogger('SftpToolExecution') async function executeParsed( request: InternalToolOperationCall, schema: S, - execute: (input: z.output, context: SftpOperationContext) => Promise -): Promise { + execute: ( + input: z.output, + context: SftpOperationContext + ) => Promise +): Promise { const parsed = schema.safeParse(request.input) if (!parsed.success) { return Response.json( @@ -51,7 +56,9 @@ async function executeParsed( }) } -export const executeSftpTool: InternalToolOperationHandler = async (request) => { +export const executeSftpTool: InternalToolOperationHandler = async ( + request +) => { request.signal?.throwIfAborted() let serializedInput: string try { @@ -74,6 +81,10 @@ export const executeSftpTool: InternalToolOperationHandler = async (request) => return executeParsed(request, sftpDeleteInputSchema, executeSftpDelete) case 'sftp_download': return executeParsed(request, sftpDownloadInputSchema, executeSftpDownload) + case 'sftp_download_v2': + return executeParsed(request, sftpDownloadV2InputSchema, (input, context) => + executeSftpDownload(input, context, 'v2') + ) case 'sftp_list': return executeParsed(request, sftpListInputSchema, executeSftpList) case 'sftp_mkdir': diff --git a/apps/sim/lib/internal/sftp/operations.test.ts b/apps/sim/lib/internal/sftp/operations.test.ts index eaac26e5b46..3f07be5a173 100644 --- a/apps/sim/lib/internal/sftp/operations.test.ts +++ b/apps/sim/lib/internal/sftp/operations.test.ts @@ -66,6 +66,17 @@ const connectionInput = { } const context = { userId: 'user-1', requestId: 'request-1' } +const storedFile = { + id: 'stored-file', + name: 'file.txt', + size: 5, + type: 'text/plain', + mimeType: 'text/plain', + url: '/api/files/stored', + key: 'execution/file.txt', + context: 'execution', +} as const + describe('SFTP operations', () => { beforeEach(() => { vi.clearAllMocks() @@ -128,11 +139,74 @@ describe('SFTP operations', () => { context ) + if (!(response instanceof Response)) throw new Error('Expected a JSON response') expect(response.status).toBe(413) expect(mocks.readFile).not.toHaveBeenCalled() expect(mocks.clientEnd).toHaveBeenCalledOnce() }) + it.each([5, 12 * 1024 * 1024])( + 'returns %i bytes through a stored file without inline content in v2', + async (size) => { + const buffer = Buffer.alloc(size, 1) + const sftp = { + stat: vi.fn((_path, callback) => callback(null, { size: buffer.length })), + } as unknown as SFTPWrapper + mocks.getSftp.mockResolvedValue(sftp) + mocks.readFile.mockResolvedValue(buffer) + const result = await executeSftpDownload( + { ...connectionInput, remotePath: '/file.txt' }, + context, + 'v2' + ) + if (result instanceof Response) throw new Error('Expected a file output') + expect(result.files[0]?.buffer).toBe(buffer) + expect(result.files[0]?.name).toBe('file.txt') + const file = { ...storedFile, size: buffer.length } + const presented = result.present([file]) + expect(presented).toEqual({ file }) + expect(JSON.stringify(presented)).not.toContain('"content"') + expect(JSON.stringify(presented)).not.toContain('"encoding"') + expect(mocks.clientEnd).toHaveBeenCalledOnce() + expect(mocks.readFile).toHaveBeenCalledWith( + sftp, + '/file.txt', + 50 * 1024 * 1024, + 'SFTP download', + undefined + ) + } + ) + + it.each(['base64', 'utf-8'] as const)( + 'preserves the complete v1 %s response', + async (encoding) => { + const buffer = Buffer.from('hello') + mocks.getSftp.mockResolvedValue({ + stat: vi.fn((_path, callback) => callback(null, { size: buffer.length })), + }) + mocks.readFile.mockResolvedValue(buffer) + const result = await executeSftpDownload( + { ...connectionInput, remotePath: '/file.txt', encoding }, + context + ) + expect(await result.json()).toEqual({ + success: true, + fileName: 'file.txt', + file: { + name: 'file.txt', + mimeType: 'text/plain', + data: buffer.toString('base64'), + size: 5, + }, + content: buffer.toString(encoding), + size: 5, + encoding, + message: 'Successfully downloaded file.txt', + }) + } + ) + it('authorizes every referenced Sim file before reading or uploading it', async () => { const denied = Response.json({ success: false, error: 'File not found' }, { status: 404 }) const file = { key: 'workspace/file', name: 'private.txt', size: 4 } diff --git a/apps/sim/lib/internal/sftp/operations.ts b/apps/sim/lib/internal/sftp/operations.ts index dc82c211ba4..9949f73f755 100644 --- a/apps/sim/lib/internal/sftp/operations.ts +++ b/apps/sim/lib/internal/sftp/operations.ts @@ -23,6 +23,8 @@ import type { SftpMkdirInput, SftpUploadInput, } from '@/lib/internal/sftp/schema' +import { createInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' +import type { InternalToolOperationResult } from '@/lib/internal/tool-operations/types' import { getFileExtension, getMimeTypeFromExtension, @@ -335,10 +337,20 @@ export async function executeSftpList( } } -export async function executeSftpDownload( +export function executeSftpDownload( input: SftpDownloadInput, context: SftpOperationContext -): Promise { +): Promise +export function executeSftpDownload( + input: Omit, + context: SftpOperationContext, + version: 'v2' +): Promise +export async function executeSftpDownload( + input: Omit & { encoding?: SftpDownloadInput['encoding'] }, + context: SftpOperationContext, + version: 'v1' | 'v2' = 'v1' +): Promise { if (!isPathSafe(input.remotePath)) return unsafePathResponse() try { return await withSftp(input, context, async (sftp) => { @@ -370,20 +382,25 @@ export async function executeSftpDownload( const fileName = path.basename(remotePath) const extension = getFileExtension(fileName) const mimeType = getMimeTypeFromExtension(extension) - return Response.json({ - success: true, - fileName, - file: { - name: fileName, - mimeType, - data: buffer.toString('base64'), + if (version === 'v1') { + return Response.json({ + success: true, + fileName, + file: { + name: fileName, + mimeType, + data: buffer.toString('base64'), + size: buffer.length, + }, + content: buffer.toString(input.encoding === 'base64' ? 'base64' : 'utf-8'), size: buffer.length, - }, - content: buffer.toString(input.encoding === 'base64' ? 'base64' : 'utf-8'), - size: buffer.length, - encoding: input.encoding, - message: `Successfully downloaded ${fileName}`, - }) + encoding: input.encoding, + message: `Successfully downloaded ${fileName}`, + }) + } + return createInternalToolFileResult({ buffer, name: fileName, mimeType }, (file) => ({ + file, + })) }) } catch (error) { context.signal?.throwIfAborted() diff --git a/apps/sim/lib/internal/sftp/schema.ts b/apps/sim/lib/internal/sftp/schema.ts index 6a3ab54e14d..d07447ad5be 100644 --- a/apps/sim/lib/internal/sftp/schema.ts +++ b/apps/sim/lib/internal/sftp/schema.ts @@ -52,6 +52,13 @@ export const sftpDownloadInputSchema = requireCredentials( }) ) +export const sftpDownloadV2InputSchema = requireCredentials( + z.object({ + ...connectionFields, + remotePath: z.string().min(1, 'Remote path is required'), + }) +) + export const sftpUploadInputSchema = requireCredentials( z.object({ ...connectionFields, @@ -68,4 +75,5 @@ export type SftpListInput = z.output export type SftpDeleteInput = z.output export type SftpMkdirInput = z.output export type SftpDownloadInput = z.output +export type SftpDownloadV2Input = z.output export type SftpUploadInput = z.output diff --git a/apps/sim/lib/internal/sharepoint/execute-tool.test.ts b/apps/sim/lib/internal/sharepoint/execute-tool.test.ts index d268dc14ce3..dae8f0061ce 100644 --- a/apps/sim/lib/internal/sharepoint/execute-tool.test.ts +++ b/apps/sim/lib/internal/sharepoint/execute-tool.test.ts @@ -2,6 +2,7 @@ * @vitest-environment node */ import { beforeEach, describe, expect, it, vi } from 'vitest' +import { createInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' const mocks = vi.hoisted(() => ({ download: vi.fn(), @@ -13,7 +14,7 @@ vi.mock('@/lib/internal/sharepoint/operations', () => ({ executeSharePointUploadFile: mocks.upload, })) -import { executeSharePointTool } from '@/lib/internal/sharepoint/execute-tool' +import { executeSharePointTool as executeSharePointToolOperation } from '@/lib/internal/sharepoint/execute-tool' import { downloadFileTool } from '@/tools/sharepoint/download_file' import { uploadFileTool } from '@/tools/sharepoint/upload_file' @@ -24,6 +25,14 @@ const context = { executionId: 'execution-1', } +async function executeSharePointTool( + request: Parameters[0] +): Promise { + const result = await executeSharePointToolOperation(request) + if (!(result instanceof Response)) throw new Error('Expected a JSON response') + return result +} + describe('executeSharePointTool', () => { beforeEach(() => { vi.clearAllMocks() @@ -53,6 +62,23 @@ describe('executeSharePointTool', () => { ) }) + it('forwards file bytes without serializing the file result', async () => { + const fileResult = createInternalToolFileResult( + { buffer: Buffer.from('file'), name: 'file.txt', mimeType: 'text/plain' }, + (file) => ({ success: true, output: { file } }) + ) + mocks.download.mockResolvedValueOnce(fileResult) + expect( + await executeSharePointToolOperation({ + toolId: 'sharepoint_download_file', + input: { accessToken: 'token', driveId: 'drive', itemId: 'item' }, + headers: new Headers(), + context, + requestId: 'request-1', + }) + ).toBe(fileResult) + }) + it('requires trusted execution identity before parsing tool input', async () => { const response = await executeSharePointTool({ toolId: 'sharepoint_download_file', diff --git a/apps/sim/lib/internal/sharepoint/execute-tool.ts b/apps/sim/lib/internal/sharepoint/execute-tool.ts index 8d331672e52..c25c37b97aa 100644 --- a/apps/sim/lib/internal/sharepoint/execute-tool.ts +++ b/apps/sim/lib/internal/sharepoint/execute-tool.ts @@ -14,13 +14,17 @@ import { import type { InternalToolOperationCall, InternalToolOperationHandler, + InternalToolOperationResult, } from '@/lib/internal/tool-operations/types' async function executeParsed( request: InternalToolOperationCall, schema: S, - execute: (input: z.output, context: SharePointOperationContext) => Promise -): Promise { + execute: ( + input: z.output, + context: SharePointOperationContext + ) => Promise +): Promise { let serializedInput: string try { serializedInput = JSON.stringify(request.input) ?? '' @@ -57,7 +61,9 @@ async function executeParsed( }) } -export const executeSharePointTool: InternalToolOperationHandler = async (request) => { +export const executeSharePointTool: InternalToolOperationHandler< + InternalToolOperationResult +> = async (request) => { request.signal?.throwIfAborted() if (!request.context.userId) { return Response.json({ success: false, error: 'Authentication required' }, { status: 401 }) diff --git a/apps/sim/lib/internal/sharepoint/operations.test.ts b/apps/sim/lib/internal/sharepoint/operations.test.ts index 863cb6a0f6a..42b03434e1f 100644 --- a/apps/sim/lib/internal/sharepoint/operations.test.ts +++ b/apps/sim/lib/internal/sharepoint/operations.test.ts @@ -63,6 +63,17 @@ const userFile = { type: 'application/pdf', } +const storedFile = { + id: 'stored-file', + name: 'stored.bin', + size: 5, + type: 'application/octet-stream', + mimeType: 'application/octet-stream', + url: '/api/files/stored', + key: 'execution/workspace/workflow/run/stored.bin', + context: 'execution', +} as const + describe('SharePoint operations', () => { beforeEach(() => { vi.clearAllMocks() @@ -147,13 +158,14 @@ describe('SharePoint operations', () => { expect(mocks.uploadGraph).not.toHaveBeenCalled() }) - it('preserves the inline download output contract and cancellation signal', async () => { + it('keeps a large download in process until a stored file can be presented', async () => { const controller = new AbortController() mocks.getMetadata.mockResolvedValue({ name: 'source.txt', file: { mimeType: 'text/plain' }, }) - mocks.downloadGraph.mockResolvedValue(Buffer.from('hello')) + const buffer = Buffer.alloc(12 * 1024 * 1024, 1) + mocks.downloadGraph.mockResolvedValue(buffer) const response = await executeSharePointDownloadFile( { accessToken: 'token', driveId: 'drive', itemId: 'item', fileName: 'renamed.txt' }, @@ -161,16 +173,11 @@ describe('SharePoint operations', () => { ) expect(mocks.clientConstructed).toHaveBeenCalledWith('token', controller.signal) - expect(await response.json()).toEqual({ - success: true, - output: { - file: { - name: 'renamed.txt', - mimeType: 'text/plain', - data: Buffer.from('hello').toString('base64'), - size: 5, - }, - }, - }) + if (response instanceof Response) throw new Error('Expected a file output') + expect(response.files).toHaveLength(1) + expect(response.files[0]?.name).toBe('renamed.txt') + expect(response.files[0]?.mimeType).toBe('text/plain') + expect(response.files[0]?.buffer).toBe(buffer) + expect(response.present([storedFile])).toEqual({ success: true, output: { file: storedFile } }) }) }) diff --git a/apps/sim/lib/internal/sharepoint/operations.ts b/apps/sim/lib/internal/sharepoint/operations.ts index 392185a2ee9..3782a8d689b 100644 --- a/apps/sim/lib/internal/sharepoint/operations.ts +++ b/apps/sim/lib/internal/sharepoint/operations.ts @@ -10,6 +10,8 @@ import type { SharePointDownloadFileInput, SharePointUploadFileInput, } from '@/lib/internal/sharepoint/schema' +import { createInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' +import type { InternalToolOperationResult } from '@/lib/internal/tool-operations/types' import { processFilesToUserFiles } from '@/lib/uploads/utils/file-utils' import { downloadServableFileFromStorage } from '@/lib/uploads/utils/file-utils.server' import { docNotReadyResponse } from '@/lib/uploads/utils/servable-file-response' @@ -47,7 +49,7 @@ function uploadedFile(data: SharePointUploadedItem): SharePointUploadedItem { export async function executeSharePointDownloadFile( input: SharePointDownloadFileInput, context: SharePointOperationContext -): Promise { +): Promise { context.signal?.throwIfAborted() try { const client = new SharePointClient(input.accessToken, context.signal) @@ -61,17 +63,10 @@ export async function executeSharePointDownloadFile( const mimeType = metadata.file?.mimeType || 'application/octet-stream' const buffer = await client.download(input.driveId, input.itemId) context.signal?.throwIfAborted() - return Response.json({ - success: true, - output: { - file: { - name: input.fileName || metadata.name || 'download', - mimeType, - data: buffer.toString('base64'), - size: buffer.length, - }, - }, - }) + return createInternalToolFileResult( + { buffer, name: input.fileName || metadata.name || 'download', mimeType }, + (file) => ({ success: true, output: { file } }) + ) } catch (error) { context.signal?.throwIfAborted() if (error instanceof SharePointGraphError) { diff --git a/apps/sim/lib/internal/slack/execute-tool.ts b/apps/sim/lib/internal/slack/execute-tool.ts index 81905967129..f4f4cc2b131 100644 --- a/apps/sim/lib/internal/slack/execute-tool.ts +++ b/apps/sim/lib/internal/slack/execute-tool.ts @@ -28,10 +28,12 @@ import { executeSlackGetChannelHistoryOperation } from '@/lib/internal/slack/ope import { executeSlackGetThreadRepliesOperation } from '@/lib/internal/slack/operations/get-thread-replies' import { executeSlackListConversationsOperation } from '@/lib/internal/slack/operations/list-conversations' import { executeToolOperationImplementation } from '@/lib/internal/tool-operations/execute' +import { isInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' import { parseInternalToolInput } from '@/lib/internal/tool-operations/parse-input' import type { InternalToolOperationCall, InternalToolOperationHandler, + InternalToolOperationResult, } from '@/lib/internal/tool-operations/types' import { docNotReadyResponse } from '@/lib/uploads/utils/servable-file-response' @@ -41,14 +43,14 @@ async function executeOperation( contract: C, request: InternalToolOperationCall, execute: (input: ContractBody) => Promise -): Promise { +): Promise { request.signal?.throwIfAborted() const parsed = parseInternalToolInput(contract, request.input) if (!parsed.success) return parsed.response try { const result = await execute(parsed.data) request.signal?.throwIfAborted() - return Response.json(result) + return isInternalToolFileResult(result) ? result : Response.json(result) } catch (error) { request.signal?.throwIfAborted() if (error instanceof SlackOperationError) { @@ -71,7 +73,9 @@ async function executeOperation( } } -export const executeSlackTool: InternalToolOperationHandler = async (request) => { +export const executeSlackTool: InternalToolOperationHandler = async ( + request +) => { const context: SlackOperationContext = { requestId: request.requestId, signal: request.signal, diff --git a/apps/sim/lib/internal/slack/operations.test.ts b/apps/sim/lib/internal/slack/operations.test.ts index 8f269c2f2ae..b4b76baf6be 100644 --- a/apps/sim/lib/internal/slack/operations.test.ts +++ b/apps/sim/lib/internal/slack/operations.test.ts @@ -1,7 +1,12 @@ /** * @vitest-environment node */ -import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' + +import { afterEach, assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { + isInternalToolFileResult, + type StoredToolFile, +} from '@/lib/internal/tool-operations/file-result' const mocks = vi.hoisted(() => ({ resolveFiles: vi.fn(), @@ -195,11 +200,23 @@ describe('Slack operations', () => { }), 'uploadUrl' ) - expect(result.output).toMatchObject({ - channel: 'C1', - fileCount: 1, - ts: '10', - files: [{ name: 'hello.txt', size: 5 }], + assert(isInternalToolFileResult(result)) + expect(result.files).toEqual([ + { name: 'hello.txt', mimeType: 'text/plain', buffer: Buffer.from('hello') }, + ]) + const storedFile: StoredToolFile = { + id: 'stored-file-1', + key: 'execution/stored-file-1', + url: '/api/files/serve/stored-file-1', + name: 'hello.txt', + type: 'text/plain', + mimeType: 'text/plain', + size: 5, + context: 'execution', + } + expect(result.present([storedFile])).toMatchObject({ + success: true, + output: { channel: 'C1', fileCount: 1, ts: '10', files: [storedFile] }, }) }) @@ -234,12 +251,21 @@ describe('Slack operations', () => { signal: controller.signal, } ) - expect(result.output.file).toEqual({ + assert(isInternalToolFileResult(result)) + expect(result.files).toEqual([ + { name: 'report.pdf', mimeType: 'application/pdf', buffer: Buffer.from('pdf') }, + ]) + const storedFile: StoredToolFile = { + id: 'stored-file-1', + key: 'execution/stored-file-1', + url: '/api/files/serve/stored-file-1', name: 'report.pdf', + type: 'application/pdf', mimeType: 'application/pdf', - data: Buffer.from('pdf').toString('base64'), size: 3, - }) + context: 'execution', + } + expect(result.present([storedFile])).toEqual({ success: true, output: { file: storedFile } }) }) it.each([ diff --git a/apps/sim/lib/internal/slack/operations.ts b/apps/sim/lib/internal/slack/operations.ts index a6c139d9ccf..c2d2512330b 100644 --- a/apps/sim/lib/internal/slack/operations.ts +++ b/apps/sim/lib/internal/slack/operations.ts @@ -25,8 +25,12 @@ import { } from '@/lib/internal/slack/client' import { SlackOperationError } from '@/lib/internal/slack/errors' import { forEachSlackAttachmentFile } from '@/lib/internal/slack/file-input' +import { + createInternalToolFileResult, + createInternalToolFilesResult, + type InternalToolFile, +} from '@/lib/internal/tool-operations/file-result' import { MAX_FILE_SIZE } from '@/lib/uploads/utils/validation' -import type { ToolFileData } from '@/tools/types' const logger = createLogger('SlackOperations') @@ -294,9 +298,9 @@ async function uploadSlackFiles( input: SlackSendMessageBody, channel: string, context: SlackOperationContext -): Promise<{ fileIds: string[]; files: ToolFileData[]; message?: unknown }> { +): Promise<{ fileIds: string[]; files: InternalToolFile[]; message?: unknown }> { const fileIds: string[] = [] - const files: ToolFileData[] = [] + const files: InternalToolFile[] = [] await forEachSlackAttachmentFile( input.files ?? [], @@ -344,8 +348,7 @@ async function uploadSlackFiles( files.push({ name: file.name, mimeType: file.contentType || file.type || 'application/octet-stream', - data: file.buffer.toString('base64'), - size: file.buffer.length, + buffer: file.buffer, }) } ) @@ -413,16 +416,17 @@ export async function executeSlackSendMessage( return { success: true as const, output: sentMessageOutput(data, input.text) } } - return { - success: true as const, + const { message, fileIds, files } = uploaded + return createInternalToolFilesResult(files, (storedFiles) => ({ + success: true, output: { - message: uploaded.message, - ts: record(uploaded.message).ts, + message, + ts: record(message).ts, channel, - fileCount: uploaded.fileIds.length, - files: uploaded.files, + fileCount: fileIds.length, + files: storedFiles, }, - } + })) } export async function executeSlackDownload(input: SlackDownloadBody, signal?: AbortSignal) { @@ -458,10 +462,8 @@ export async function executeSlackDownload(input: SlackDownloadBody, signal?: Ab if (!response.ok) failure(400, 'Failed to download file content') const buffer = Buffer.from(await response.arrayBuffer()) signal?.throwIfAborted() - return { - success: true as const, - output: { - file: { name, mimeType, data: buffer.toString('base64'), size: buffer.length }, - }, - } + return createInternalToolFileResult({ buffer, name, mimeType }, (file) => ({ + success: true, + output: { file }, + })) } diff --git a/apps/sim/lib/internal/ssh/execute-tool.test.ts b/apps/sim/lib/internal/ssh/execute-tool.test.ts index 7fe223caf1b..22149e60e25 100644 --- a/apps/sim/lib/internal/ssh/execute-tool.test.ts +++ b/apps/sim/lib/internal/ssh/execute-tool.test.ts @@ -3,6 +3,7 @@ */ import { createExecutionContext } from '@sim/testing' import { beforeEach, describe, expect, it, vi } from 'vitest' +import { createInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' const operationMocks = vi.hoisted(() => ({ executeSshCheckCommandExists: vi.fn(), @@ -24,7 +25,7 @@ vi.mock('@/lib/internal/ssh/operations', () => operationMocks) import { PayloadSizeLimitError } from '@/lib/core/utils/stream-limits' import { SshOperationError } from '@/lib/internal/ssh/errors' -import { executeSshTool } from '@/lib/internal/ssh/execute-tool' +import { executeSshTool as executeSshToolOperation } from '@/lib/internal/ssh/execute-tool' import type { InternalToolOperationCall } from '@/lib/internal/tool-operations/types' const CONNECTION = { @@ -40,6 +41,7 @@ const TOOL_IDS = [ 'ssh_create_directory', 'ssh_delete_file', 'ssh_download_file', + 'ssh_download_file_v2', 'ssh_execute_command', 'ssh_execute_script', 'ssh_get_system_info', @@ -67,6 +69,14 @@ function createRequest( } } +async function executeSshTool( + request: Parameters[0] +): Promise { + const result = await executeSshToolOperation(request) + if (!(result instanceof Response)) throw new Error('Expected a JSON response') + return result +} + describe('executeSshTool', () => { beforeEach(() => { vi.clearAllMocks() @@ -75,6 +85,23 @@ describe('executeSshTool', () => { } }) + it('forwards binary file results without serializing them', async () => { + const result = createInternalToolFileResult( + { buffer: Buffer.from('file'), name: 'file.txt', mimeType: 'text/plain' }, + (file) => ({ file }) + ) + operationMocks.executeSshDownloadFile.mockResolvedValueOnce(result) + expect( + await executeSshToolOperation( + createRequest({ + toolId: 'ssh_download_file_v2', + input: { ...CONNECTION, remotePath: '/file.txt' }, + }) + ) + ).toBe(result) + expect(operationMocks.executeSshDownloadFile.mock.calls[0][2]).toBe('v2') + }) + it('validates typed operation input and dispatches without reading a serialized body', async () => { const controller = new AbortController() const input = { ...CONNECTION, command: 'pwd' } diff --git a/apps/sim/lib/internal/ssh/execute-tool.ts b/apps/sim/lib/internal/ssh/execute-tool.ts index 58010742226..b1261db2d27 100644 --- a/apps/sim/lib/internal/ssh/execute-tool.ts +++ b/apps/sim/lib/internal/ssh/execute-tool.ts @@ -34,9 +34,11 @@ import { executeSshWriteFileContent, type SshOperationContext, } from '@/lib/internal/ssh/operations' +import { isInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' import type { InternalToolOperationCall, InternalToolOperationHandler, + InternalToolOperationResult, } from '@/lib/internal/tool-operations/types' const logger = createLogger('SshToolExecution') @@ -46,7 +48,7 @@ async function executeOperation( request: InternalToolOperationCall, operation: (input: ContractBody, context: SshOperationContext) => Promise, failureMessage: string -): Promise { +): Promise { request.signal?.throwIfAborted() if (!contract.body) throw new Error(`SSH contract ${contract.path} has no operation input`) const parsed = contract.body.safeParse(request.input) @@ -60,7 +62,7 @@ async function executeOperation( try { const result = await operation(parsed.data as ContractBody, { signal: request.signal }) request.signal?.throwIfAborted() - return Response.json(result) + return isInternalToolFileResult(result) ? result : Response.json(result) } catch (error) { request.signal?.throwIfAborted() if (error instanceof SshOperationError) { @@ -79,7 +81,9 @@ async function executeOperation( } } -export const executeSshTool: InternalToolOperationHandler = async (request) => { +export const executeSshTool: InternalToolOperationHandler = async ( + request +) => { switch (request.toolId) { case 'ssh_check_command_exists': return executeOperation( @@ -116,6 +120,13 @@ export const executeSshTool: InternalToolOperationHandler = async (request) => { executeSshDownloadFile, 'SSH file download failed' ) + case 'ssh_download_file_v2': + return executeOperation( + sshDownloadFileContract, + request, + (input, context) => executeSshDownloadFile(input, context, 'v2'), + 'SSH file download failed' + ) case 'ssh_execute_command': return executeOperation( sshExecuteCommandContract, diff --git a/apps/sim/lib/internal/ssh/operations.test.ts b/apps/sim/lib/internal/ssh/operations.test.ts index 5927e232ed4..99b394924b1 100644 --- a/apps/sim/lib/internal/ssh/operations.test.ts +++ b/apps/sim/lib/internal/ssh/operations.test.ts @@ -1,10 +1,12 @@ +import { Readable } from 'node:stream' /** * @vitest-environment node */ import { beforeEach, describe, expect, it, vi } from 'vitest' +import { isInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' const mocks = vi.hoisted(() => ({ - client: { destroy: vi.fn(), end: vi.fn() }, + client: { destroy: vi.fn(), end: vi.fn(), sftp: vi.fn() }, createSSHConnection: vi.fn(), executeSSHCommand: vi.fn(), })) @@ -19,7 +21,7 @@ vi.mock('@/lib/internal/ssh/client', () => ({ sanitizePath: (value: string) => value.trim(), })) -import { executeSshExecuteCommand } from '@/lib/internal/ssh/operations' +import { executeSshDownloadFile, executeSshExecuteCommand } from '@/lib/internal/ssh/operations' const INPUT = { host: 'ssh.example.com', @@ -30,6 +32,17 @@ const INPUT = { workingDirectory: "/srv/app's", } +const storedFile = { + id: 'stored-file', + name: 'file.txt', + size: 5, + type: 'text/plain', + mimeType: 'text/plain', + url: '/api/files/stored', + key: 'execution/file.txt', + context: 'execution', +} as const + describe('SSH operations', () => { beforeEach(() => { vi.clearAllMocks() @@ -58,6 +71,65 @@ describe('SSH operations', () => { expect(mocks.client.end).toHaveBeenCalledOnce() }) + it.each([5, 12 * 1024 * 1024])( + 'downloads %i bytes through a stored file without inline content in v2', + async (size) => { + const buffer = Buffer.alloc(size, 65) + const sftp = { + stat: vi.fn((_path, callback) => callback(null, { size })), + createReadStream: vi.fn(() => Readable.from([buffer])), + } + mocks.client.sftp.mockImplementation((callback) => callback(null, sftp)) + const result = await executeSshDownloadFile( + { + host: INPUT.host, + port: INPUT.port, + username: INPUT.username, + password: INPUT.password, + remotePath: '/file.txt', + }, + {}, + 'v2' + ) + if (!isInternalToolFileResult(result)) throw new Error('Expected a file output') + expect(result.files[0]?.buffer.length).toBe(size) + expect(result.files[0]?.name).toBe('file.txt') + const file = { ...storedFile, size } + const presented = result.present([file]) + expect(presented).toEqual({ + file, + remotePath: '/file.txt', + }) + expect(JSON.stringify(presented)).not.toContain('"content"') + expect(sftp.createReadStream).toHaveBeenCalledOnce() + expect(mocks.client.end).toHaveBeenCalledOnce() + } + ) + + it('preserves the complete legacy v1 download response', async () => { + const buffer = Buffer.from('hello') + const sftp = { + stat: vi.fn((_path, callback) => callback(null, { size: buffer.length })), + createReadStream: vi.fn(() => Readable.from([buffer])), + } + mocks.client.sftp.mockImplementation((callback) => callback(null, sftp)) + const result = await executeSshDownloadFile({ ...INPUT, remotePath: '/file.txt' }, {}) + expect(result).toEqual({ + downloaded: true, + file: { + name: 'file.txt', + mimeType: 'text/plain', + data: buffer.toString('base64'), + size: 5, + }, + content: buffer.toString('base64'), + fileName: 'file.txt', + remotePath: '/file.txt', + size: 5, + message: 'File downloaded successfully from /file.txt', + }) + }) + it('destroys and closes the client when cancellation wins during provider work', async () => { const controller = new AbortController() mocks.executeSSHCommand.mockImplementationOnce(async () => { diff --git a/apps/sim/lib/internal/ssh/operations.ts b/apps/sim/lib/internal/ssh/operations.ts index 0072c49f4aa..7970d848c99 100644 --- a/apps/sim/lib/internal/ssh/operations.ts +++ b/apps/sim/lib/internal/ssh/operations.ts @@ -33,6 +33,7 @@ import { sanitizePath, } from '@/lib/internal/ssh/client' import { SshOperationError } from '@/lib/internal/ssh/errors' +import { createInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' import { getFileExtension, getMimeTypeFromExtension } from '@/lib/uploads/utils/file-utils' export interface SshOperationContext { @@ -281,7 +282,8 @@ export async function executeSshDeleteFile( export async function executeSshDownloadFile( input: DownloadFileInput, - context: SshOperationContext + context: SshOperationContext, + version: 'v1' | 'v2' = 'v1' ): Promise { return withClient(input, context, async (client) => { const sftp = await getSftp(client, context.signal) @@ -307,21 +309,34 @@ export async function executeSshDownloadFile( context.signal ) const fileName = path.basename(remotePath) - const base64Content = content.toString('base64') - return { - downloaded: true, - file: { + if (version === 'v1') { + const base64Content = content.toString('base64') + return { + downloaded: true, + file: { + name: fileName, + mimeType: getMimeTypeFromExtension(getFileExtension(fileName)), + data: base64Content, + size: content.length, + }, + content: base64Content, + fileName, + remotePath, + size: content.length, + message: `File downloaded successfully from ${remotePath}`, + } + } + return createInternalToolFileResult( + { + buffer: content, name: fileName, mimeType: getMimeTypeFromExtension(getFileExtension(fileName)), - data: base64Content, - size: content.length, }, - content: base64Content, - fileName, - remotePath, - size: content.length, - message: `File downloaded successfully from ${remotePath}`, - } + (file) => ({ + file, + remotePath, + }) + ) }) } diff --git a/apps/sim/lib/internal/telegram/execute-tool.test.ts b/apps/sim/lib/internal/telegram/execute-tool.test.ts index 8dd8f96435b..a71d51157f0 100644 --- a/apps/sim/lib/internal/telegram/execute-tool.test.ts +++ b/apps/sim/lib/internal/telegram/execute-tool.test.ts @@ -1,8 +1,10 @@ /** * @vitest-environment node */ + import { createExecutionContext } from '@sim/testing' import { beforeEach, describe, expect, it, vi } from 'vitest' +import { createInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' const mocks = vi.hoisted(() => ({ sendTelegramDocument: vi.fn() })) @@ -13,10 +15,15 @@ vi.mock('@/lib/internal/telegram/operations', () => ({ import { executeTelegramTool } from '@/lib/internal/telegram/execute-tool' import type { InternalToolOperationCall } from '@/lib/internal/tool-operations/types' +const fileResult = createInternalToolFileResult( + { buffer: Buffer.from('file'), name: 'file.pdf', mimeType: 'application/pdf' }, + (file) => ({ success: true, output: { file } }) +) + describe('executeTelegramTool', () => { beforeEach(() => { vi.clearAllMocks() - mocks.sendTelegramDocument.mockResolvedValue({ success: true, output: {} }) + mocks.sendTelegramDocument.mockResolvedValue(fileResult) }) it('uses trusted user context for protected files', async () => { @@ -35,7 +42,7 @@ describe('executeTelegramTool', () => { signal: controller.signal, } - expect((await executeTelegramTool(request)).status).toBe(200) + expect(await executeTelegramTool(request)).toBe(fileResult) expect(mocks.sendTelegramDocument).toHaveBeenCalledWith(input, { userId: 'user-1', requestId: 'request-1', diff --git a/apps/sim/lib/internal/telegram/execute-tool.ts b/apps/sim/lib/internal/telegram/execute-tool.ts index ae7f4d27200..eb0f24ba471 100644 --- a/apps/sim/lib/internal/telegram/execute-tool.ts +++ b/apps/sim/lib/internal/telegram/execute-tool.ts @@ -2,7 +2,10 @@ import { getErrorMessage } from '@sim/utils/errors' import { z } from 'zod' import { TelegramOperationError } from '@/lib/internal/telegram/errors' import { sendTelegramDocument } from '@/lib/internal/telegram/operations' -import type { InternalToolOperationHandler } from '@/lib/internal/tool-operations/types' +import type { + InternalToolOperationHandler, + InternalToolOperationResult, +} from '@/lib/internal/tool-operations/types' import { RawFileInputArraySchema } from '@/lib/uploads/utils/file-schemas' import { docNotReadyResponse } from '@/lib/uploads/utils/servable-file-response' @@ -13,7 +16,9 @@ const inputSchema = z.object({ caption: z.string().optional().nullable(), }) -export const executeTelegramTool: InternalToolOperationHandler = async (request) => { +export const executeTelegramTool: InternalToolOperationHandler< + InternalToolOperationResult +> = async (request) => { request.signal?.throwIfAborted() if (request.toolId !== 'telegram_send_document') { return Response.json( @@ -30,13 +35,11 @@ export const executeTelegramTool: InternalToolOperationHandler = async (request) return Response.json({ success: false, error: 'Invalid request data' }, { status: 400 }) } try { - return Response.json( - await sendTelegramDocument(parsed.data, { - userId, - requestId: request.requestId, - signal: request.signal, - }) - ) + return await sendTelegramDocument(parsed.data, { + userId, + requestId: request.requestId, + signal: request.signal, + }) } catch (error) { request.signal?.throwIfAborted() const notReady = docNotReadyResponse(error) diff --git a/apps/sim/lib/internal/telegram/operations.test.ts b/apps/sim/lib/internal/telegram/operations.test.ts index 862acbaae0a..1ca7855cac9 100644 --- a/apps/sim/lib/internal/telegram/operations.test.ts +++ b/apps/sim/lib/internal/telegram/operations.test.ts @@ -1,7 +1,12 @@ /** * @vitest-environment node */ -import { beforeEach, describe, expect, it, vi } from 'vitest' + +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { + isInternalToolFileResult, + type StoredToolFile, +} from '@/lib/internal/tool-operations/file-result' const mocks = vi.hoisted(() => ({ assertToolFileAccess: vi.fn(), @@ -53,9 +58,28 @@ describe('sendTelegramDocument', () => { expect(mocks.fetch.mock.calls[0][1]).toEqual( expect.objectContaining({ signal: controller.signal }) ) - expect(result.output.files?.[0]).toEqual( - expect.objectContaining({ name: 'file.pdf', data: 'AQID', size: 3 }) - ) + assert(isInternalToolFileResult(result)) + expect(result.files).toEqual([ + { name: 'file.pdf', mimeType: 'application/pdf', buffer: Buffer.from([1, 2, 3]) }, + ]) + const storedFile: StoredToolFile = { + id: 'stored-file-1', + key: 'execution/stored-file-1', + url: '/api/files/serve/stored-file-1', + name: 'file.pdf', + type: 'application/pdf', + mimeType: 'application/pdf', + size: 3, + context: 'execution', + } + expect(result.present([storedFile])).toEqual({ + success: true, + output: { + message: 'Document sent successfully', + data: { message_id: 1 }, + files: [storedFile], + }, + }) }) it('fails closed before materialization when file access is denied', async () => { diff --git a/apps/sim/lib/internal/telegram/operations.ts b/apps/sim/lib/internal/telegram/operations.ts index aa18bdaf50d..b321ac86ee3 100644 --- a/apps/sim/lib/internal/telegram/operations.ts +++ b/apps/sim/lib/internal/telegram/operations.ts @@ -2,6 +2,10 @@ import { createLogger } from '@sim/logger' import { getErrorMessage } from '@sim/utils/errors' import { isPayloadSizeLimitError, readResponseJsonWithLimit } from '@/lib/core/utils/stream-limits' import { TelegramOperationError } from '@/lib/internal/telegram/errors' +import { + createInternalToolFileResult, + type InternalToolFileResult, +} from '@/lib/internal/tool-operations/file-result' import type { RawFileInput } from '@/lib/uploads/utils/file-schemas' import { processFilesToUserFiles } from '@/lib/uploads/utils/file-utils' import { downloadServableFileFromStorage } from '@/lib/uploads/utils/file-utils.server' @@ -35,7 +39,7 @@ interface TelegramApiResponse { export async function sendTelegramDocument( input: TelegramSendDocumentInput, context: TelegramOperationContext -): Promise { +): Promise { context.signal?.throwIfAborted() if (!input.files?.length) { throw new TelegramOperationError( @@ -118,19 +122,12 @@ export async function sendTelegramDocument( ) } - return { + return createInternalToolFileResult({ buffer, name: userFile.name, mimeType }, (file) => ({ success: true, output: { message: 'Document sent successfully', data: data.result, - files: [ - { - name: userFile.name, - mimeType, - data: buffer.toString('base64'), - size: buffer.length, - }, - ], + files: [file], }, - } + })) } diff --git a/apps/sim/lib/internal/tool-operations/file-result.server.test.ts b/apps/sim/lib/internal/tool-operations/file-result.server.test.ts new file mode 100644 index 00000000000..5a5dcc9c636 --- /dev/null +++ b/apps/sim/lib/internal/tool-operations/file-result.server.test.ts @@ -0,0 +1,527 @@ +/** + * @vitest-environment node + */ +import { beforeEach, describe, expect, it, vi } from 'vitest' +import { + PayloadSizeLimitError, + readResponseToBufferWithLimit, +} from '@/lib/core/utils/stream-limits' +import { + createInternalToolFileResult, + createInternalToolFilesResult, + type InternalToolFile, +} from '@/lib/internal/tool-operations/file-result' +import { MAX_TOOL_RESPONSE_BODY_BYTES } from '@/lib/internal/tool-operations/response-limits' +import type { InternalToolOperationContext } from '@/lib/internal/tool-operations/types' +import { MAX_BUFFERED_TRANSFER_BYTES } from '@/lib/uploads/shared/types' +import type { UserFile } from '@/executor/types' + +const mocks = vi.hoisted(() => ({ + uploadExecution: vi.fn(), + uploadCopilot: vi.fn(), + deleteFile: vi.fn(), + deleteMetadata: vi.fn(), +})) + +vi.mock('@/lib/uploads/contexts/execution', () => ({ + uploadExecutionFile: mocks.uploadExecution, +})) + +vi.mock('@/lib/uploads/contexts/copilot', () => ({ + uploadCopilotFile: mocks.uploadCopilot, +})) + +vi.mock('@/lib/uploads/core/storage-service', () => ({ deleteFile: mocks.deleteFile })) +vi.mock('@/lib/uploads/server/metadata', () => ({ deleteFileMetadata: mocks.deleteMetadata })) + +import { + presentInternalToolOperationResult, + storeInternalToolFileResult, +} from '@/lib/internal/tool-operations/file-result.server' + +const runContext: InternalToolOperationContext = { + workspaceId: 'workspace-1', + workflowId: 'workflow-1', + executionId: 'execution-1', + userId: 'user-1', +} + +const copilotContext: InternalToolOperationContext = { + workspaceId: 'workspace-1', + workflowId: '', + userId: 'user-1', + copilotToolExecution: true, +} + +function file(buffer = Buffer.from('workbook')): InternalToolFile { + return { + buffer, + name: 'workbook.xlsx', + mimeType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + } +} + +function storedFile( + buffer: Buffer, + name: string, + type: string, + context: 'execution' | 'copilot', + index = 1 +): UserFile { + return { + id: `file-${index}`, + key: `${context}/file-${index}/${name}`, + url: `https://storage.example/file-${index}`, + name, + size: buffer.length, + type, + context, + } +} + +describe('presentInternalToolOperationResult', () => { + beforeEach(() => { + vi.clearAllMocks() + mocks.uploadExecution.mockReset() + mocks.uploadCopilot.mockReset() + mocks.deleteFile.mockReset() + mocks.deleteMetadata.mockReset() + mocks.uploadExecution.mockImplementation( + async (_scope: unknown, buffer: Buffer, name: string, type: string) => + storedFile(buffer, name, type, 'execution', mocks.uploadExecution.mock.calls.length) + ) + mocks.uploadCopilot.mockImplementation( + async (input: { buffer: Buffer; fileName: string; contentType: string }) => + storedFile(input.buffer, input.fileName, input.contentType, 'copilot') + ) + mocks.deleteFile.mockResolvedValue(undefined) + mocks.deleteMetadata.mockResolvedValue(true) + }) + + it('passes ordinary responses through without reading or changing them', async () => { + const original = Response.json({ error: 'Provider failed' }, { status: 403 }) + const controller = new AbortController() + controller.abort() + + const result = await presentInternalToolOperationResult( + original, + { workflowId: '' }, + controller.signal + ) + + expect(result).toBe(original) + expect(original.bodyUsed).toBe(false) + expect(mocks.uploadExecution).not.toHaveBeenCalled() + expect(mocks.uploadCopilot).not.toHaveBeenCalled() + }) + + it('persists a 12 MiB workbook before serializing its descriptor and adjacent metadata', async () => { + const input = file(Buffer.alloc(12 * 1024 * 1024, 1)) + const result = createInternalToolFileResult( + input, + (stored) => ({ success: true, output: { file: stored, metadata: { sourceId: 'item-1' } } }), + { status: 201, headers: { 'x-provider-version': 'v1' } } + ) + + const response = await presentInternalToolOperationResult(result, runContext) + const body = await response.text() + + expect(body.length).toBeLessThan(1024) + expect(response.status).toBe(201) + expect(response.headers.get('x-provider-version')).toBe('v1') + expect(response.headers.get('content-type')).toBe('application/json') + expect(JSON.parse(body)).toMatchObject({ + success: true, + output: { + file: { + name: input.name, + size: input.buffer.length, + type: input.mimeType, + }, + metadata: { sourceId: 'item-1' }, + }, + }) + const [scope, buffer, name, mimeType, userId] = mocks.uploadExecution.mock.calls[0]! + expect(buffer).toBe(input.buffer) + expect({ scope, name, mimeType, userId }).toEqual({ + scope: { workspaceId: 'workspace-1', workflowId: 'workflow-1', executionId: 'execution-1' }, + name: input.name, + mimeType: input.mimeType, + userId: 'user-1', + }) + expect(mocks.uploadCopilot).not.toHaveBeenCalled() + }) + + it('stores non-run files under the authenticated Copilot user', async () => { + const input = file() + const response = await presentInternalToolOperationResult( + createInternalToolFileResult(input, (stored) => ({ file: stored, fileUrl: stored.url })), + copilotContext + ) + + expect(await response.json()).toMatchObject({ + file: { context: 'copilot' }, + fileUrl: 'https://storage.example/file-1', + }) + expect(mocks.uploadCopilot).toHaveBeenCalledWith({ + buffer: input.buffer, + fileName: input.name, + contentType: input.mimeType, + userId: 'user-1', + }) + expect(mocks.uploadExecution).not.toHaveBeenCalled() + }) + + it('replaces binary representation headers before the JSON transport size check', async () => { + const input = file(Buffer.alloc(12 * 1024 * 1024)) + const headers = new Headers({ + 'content-length': String(input.buffer.length), + 'content-encoding': 'gzip', + 'content-type': input.mimeType, + 'x-provider-version': 'v1', + }) + const response = await presentInternalToolOperationResult( + createInternalToolFileResult(input, (stored) => ({ file: stored }), { + status: 201, + statusText: 'Created', + headers, + }), + runContext + ) + + const body = await readResponseToBufferWithLimit(response, { + maxBytes: MAX_TOOL_RESPONSE_BODY_BYTES, + label: 'Tool response body', + }) + + expect(body.length).toBeLessThan(1024) + expect(JSON.parse(body.toString('utf8'))).toMatchObject({ + file: { size: input.buffer.length, context: 'execution' }, + }) + expect(response.status).toBe(201) + expect(response.statusText).toBe('Created') + expect(response.headers.get('content-type')).toBe('application/json') + expect(response.headers.get('content-length')).toBeNull() + expect(response.headers.get('content-encoding')).toBeNull() + expect(response.headers.get('x-provider-version')).toBe('v1') + expect(headers.get('content-length')).toBe(String(input.buffer.length)) + expect(mocks.uploadExecution).toHaveBeenCalledTimes(1) + expect(mocks.deleteFile).not.toHaveBeenCalled() + }) + + it('allows actorless execution artifacts without requiring a human subject', async () => { + const result = createInternalToolFileResult(file(), (stored) => ({ file: stored })) + await presentInternalToolOperationResult(result, { + ...runContext, + userId: undefined, + executorDelegationOrigin: { + workflowId: 'workflow-1', + executionId: 'execution-1', + principal: { + kind: 'system', + serviceId: 'schedule', + workspaceId: 'workspace-1', + workflowId: 'workflow-1', + }, + }, + }) + + expect(mocks.uploadExecution.mock.calls[0]?.[4]).toBeUndefined() + expect(mocks.uploadCopilot).not.toHaveBeenCalled() + }) + + it("does not make an actorless principal's compatibility owner a Copilot user", async () => { + await expect( + presentInternalToolOperationResult( + createInternalToolFileResult(file(), (stored) => ({ file: stored })), + { + ...copilotContext, + userId: 'billing-owner', + executorDelegationOrigin: { + workflowId: 'workflow-1', + principal: { + kind: 'system', + serviceId: 'schedule', + workspaceId: 'workspace-1', + workflowId: 'workflow-1', + }, + }, + } + ) + ).rejects.toThrow('human subject') + expect(mocks.uploadCopilot).not.toHaveBeenCalled() + }) + + it('uses a real principal subject and refuses a conflicting claimed owner', async () => { + const result = createInternalToolFileResult(file(), (stored) => ({ file: stored })) + const context: InternalToolOperationContext = { + ...copilotContext, + userId: undefined, + executorDelegationOrigin: { + workflowId: 'workflow-1', + principal: { kind: 'session', userId: 'actual-user', sessionId: 'session-1' }, + }, + } + await presentInternalToolOperationResult(result, context) + expect(mocks.uploadCopilot).toHaveBeenCalledWith( + expect.objectContaining({ userId: 'actual-user' }) + ) + + await expect( + presentInternalToolOperationResult(result, { ...context, userId: 'other-user' }) + ).rejects.toThrow('does not match') + expect(mocks.uploadCopilot).toHaveBeenCalledTimes(1) + }) + + it.each([ + { ...copilotContext, userId: undefined }, + { ...runContext, workspaceId: undefined }, + { ...runContext, workflowId: '' }, + ])('rejects missing storage authority before uploading: %j', async (context) => { + await expect( + presentInternalToolOperationResult( + createInternalToolFileResult(file(), (stored) => ({ file: stored })), + context + ) + ).rejects.toThrow() + expect(mocks.uploadExecution).not.toHaveBeenCalled() + expect(mocks.uploadCopilot).not.toHaveBeenCalled() + }) + + it('accepts exactly 100 MiB and rejects larger files before uploading', async () => { + const atLimit = file(Buffer.alloc(MAX_BUFFERED_TRANSFER_BYTES)) + await presentInternalToolOperationResult( + createInternalToolFileResult(atLimit, (stored) => ({ file: stored })), + runContext + ) + expect(mocks.uploadExecution).toHaveBeenCalledTimes(1) + + const oversized = file(Buffer.alloc(MAX_BUFFERED_TRANSFER_BYTES + 1)) + await expect( + presentInternalToolOperationResult( + createInternalToolFileResult(oversized, (stored) => ({ file: stored })), + runContext + ) + ).rejects.toBeInstanceOf(PayloadSizeLimitError) + expect(mocks.uploadExecution).toHaveBeenCalledTimes(1) + }) + + it('checks the aggregate buffer budget before storing the first file', async () => { + const files = [file(Buffer.alloc(60 * 1024 * 1024)), file(Buffer.alloc(41 * 1024 * 1024))] + await expect( + presentInternalToolOperationResult( + createInternalToolFilesResult(files, (stored) => ({ files: stored })), + runContext + ) + ).rejects.toMatchObject({ + maxBytes: MAX_BUFFERED_TRANSFER_BYTES, + observedBytes: 101 * 1024 * 1024, + }) + expect(mocks.uploadExecution).not.toHaveBeenCalled() + }) + + it('validates every file before any upload', async () => { + await expect( + presentInternalToolOperationResult( + createInternalToolFilesResult([file(), { ...file(), name: ' ' }], (stored) => ({ + files: stored, + })), + runContext + ) + ).rejects.toThrow('filename') + expect(mocks.uploadExecution).not.toHaveBeenCalled() + }) + + it('persists distinct files sequentially and reuses repeated file references', async () => { + const first = file() + const second = { ...file(), name: 'second.xlsx' } + let firstFinished = false + mocks.uploadExecution + .mockImplementationOnce(async () => { + await Promise.resolve() + firstFinished = true + return storedFile(first.buffer, first.name, first.mimeType, 'execution') + }) + .mockImplementationOnce(async () => { + expect(firstFinished).toBe(true) + return storedFile(second.buffer, second.name, second.mimeType, 'execution', 2) + }) + const result = createInternalToolFilesResult([first, second, first], (stored) => { + expect(stored[0]).toBe(stored[2]) + return { files: stored, echoedFile: stored[0] } + }) + + const response = await presentInternalToolOperationResult(result, runContext) + expect((await response.json()).files).toHaveLength(3) + expect(mocks.uploadExecution).toHaveBeenCalledTimes(2) + }) + + it('preserves image sniffing before returning an already stored descriptor', async () => { + const input = { buffer: Buffer.from(''), name: 'image.png', mimeType: 'image/png' } + const response = await presentInternalToolOperationResult( + createInternalToolFileResult(input, (stored) => ({ file: stored })), + runContext + ) + + expect(mocks.uploadExecution).toHaveBeenCalledWith( + expect.anything(), + input.buffer, + 'image.bin', + 'application/octet-stream', + 'user-1' + ) + expect(await response.json()).toMatchObject({ + file: { + name: 'image.bin', + type: 'application/octet-stream', + }, + }) + }) + + it('does not upload after cancellation', async () => { + const controller = new AbortController() + const error = new Error('cancelled') + controller.abort(error) + await expect( + presentInternalToolOperationResult( + createInternalToolFileResult(file(), (stored) => ({ file: stored })), + runContext, + controller.signal + ) + ).rejects.toBe(error) + expect(mocks.uploadExecution).not.toHaveBeenCalled() + }) + + it('rolls back an upload that completed after cancellation, without the aborted signal', async () => { + const controller = new AbortController() + const error = new Error('cancelled during upload') + mocks.uploadExecution.mockImplementationOnce(async () => { + controller.abort(error) + return storedFile(Buffer.from('file'), 'file.txt', 'text/plain', 'execution') + }) + + await expect( + presentInternalToolOperationResult( + createInternalToolFilesResult([file(), file()], (stored) => ({ files: stored })), + runContext, + controller.signal + ) + ).rejects.toBe(error) + expect(mocks.uploadExecution).toHaveBeenCalledTimes(1) + expect(mocks.deleteFile).toHaveBeenCalledWith({ + key: 'execution/file-1/file.txt', + context: 'execution', + }) + expect(mocks.deleteMetadata).toHaveBeenCalledWith('execution/file-1/file.txt') + }) + + it('rolls back preceding uploads when a later upload fails', async () => { + const error = new Error('Storage unavailable') + mocks.uploadExecution + .mockResolvedValueOnce( + storedFile(Buffer.from('file'), 'first.txt', 'text/plain', 'execution') + ) + .mockRejectedValueOnce(error) + await expect( + presentInternalToolOperationResult( + createInternalToolFilesResult([file(), file()], (stored) => ({ files: stored })), + runContext + ) + ).rejects.toBe(error) + expect(mocks.deleteFile).toHaveBeenCalledTimes(1) + expect(mocks.deleteMetadata).toHaveBeenCalledWith('execution/file-1/first.txt') + }) + + it.each([ + () => { + throw new Error('Presentation failed') + }, + () => ({ unsupported: 1n }), + () => undefined, + ])('rolls back Copilot files if presentation or serialization fails', async (present) => { + await expect( + presentInternalToolOperationResult( + createInternalToolFileResult(file(), present), + copilotContext + ) + ).rejects.toThrow() + expect(mocks.deleteFile).toHaveBeenCalledWith({ + key: 'copilot/file-1/workbook.xlsx', + context: 'copilot', + }) + expect(mocks.deleteMetadata).toHaveBeenCalledWith('copilot/file-1/workbook.xlsx') + }) + + it('rolls back when adjacent JSON exceeds the unchanged transport limit', async () => { + await expect( + presentInternalToolOperationResult( + createInternalToolFileResult(file(), (stored) => ({ + file: stored, + text: 'x'.repeat(MAX_TOOL_RESPONSE_BODY_BYTES), + })), + runContext + ) + ).rejects.toMatchObject({ maxBytes: MAX_TOOL_RESPONSE_BODY_BYTES }) + expect(mocks.deleteFile).toHaveBeenCalledTimes(1) + expect(mocks.deleteMetadata).toHaveBeenCalledTimes(1) + }) + + it('finalizes large binary outputs as stored file descriptors', async () => { + const buffer = Buffer.alloc(12 * 1024 * 1024) + const finalize = vi.fn((body: unknown) => body) + const output = await storeInternalToolFileResult( + createInternalToolFileResult(file(buffer), (stored) => ({ + success: true, + output: { file: stored }, + })), + copilotContext, + finalize + ) + + expect(output).toBe(finalize.mock.calls[0]?.[0]) + expect(output).toMatchObject({ + success: true, + output: { file: { context: 'copilot', size: buffer.length } }, + }) + expect(output).not.toHaveProperty('output.file.data') + expect(JSON.stringify(output).length).toBeLessThan(1024) + expect(mocks.uploadCopilot).toHaveBeenCalledTimes(1) + expect(mocks.uploadCopilot.mock.calls[0]?.[0].buffer).toBe(buffer) + expect(mocks.deleteFile).not.toHaveBeenCalled() + }) + + it('rolls back storage if the external result finalizer rejects its output', async () => { + const error = new Error('Invalid tool response') + await expect( + storeInternalToolFileResult( + createInternalToolFileResult(file(), (stored) => ({ file: stored })), + copilotContext, + () => { + throw error + } + ) + ).rejects.toBe(error) + + expect(mocks.deleteFile).toHaveBeenCalledWith({ + key: 'copilot/file-1/workbook.xlsx', + context: 'copilot', + }) + expect(mocks.deleteMetadata).toHaveBeenCalledTimes(1) + }) + + it('attempts remaining cleanup after a deletion failure and preserves the original error', async () => { + const error = new Error('Presentation failed') + mocks.deleteFile.mockRejectedValueOnce(new Error('Cleanup failed')) + await expect( + presentInternalToolOperationResult( + createInternalToolFilesResult([file(), { ...file(), name: 'second.xlsx' }], () => { + throw error + }), + runContext + ) + ).rejects.toBe(error) + expect(mocks.deleteFile).toHaveBeenCalledTimes(2) + expect(mocks.deleteMetadata).toHaveBeenCalledTimes(1) + expect(mocks.deleteMetadata).toHaveBeenCalledWith('execution/file-2/second.xlsx') + }) +}) diff --git a/apps/sim/lib/internal/tool-operations/file-result.server.ts b/apps/sim/lib/internal/tool-operations/file-result.server.ts new file mode 100644 index 00000000000..ab1b6e516d9 --- /dev/null +++ b/apps/sim/lib/internal/tool-operations/file-result.server.ts @@ -0,0 +1,185 @@ +import { PrincipalSubjectUserRequiredError, resolvePrincipalSubject } from '@sim/auth/principal' +import { createLogger } from '@sim/logger' +import { getErrorMessage } from '@sim/utils/errors' +import { omit } from '@sim/utils/object' +import { assertKnownSizeWithinLimit } from '@/lib/core/utils/stream-limits' +import type { + InternalToolFile, + InternalToolFileResult, +} from '@/lib/internal/tool-operations/file-result' +import { MAX_TOOL_RESPONSE_BODY_BYTES } from '@/lib/internal/tool-operations/response-limits' +import type { + InternalToolOperationContext, + InternalToolOperationResult, +} from '@/lib/internal/tool-operations/types' +import { uploadCopilotFile } from '@/lib/uploads/contexts/copilot' +import { uploadExecutionFile } from '@/lib/uploads/contexts/execution' +import type { ExecutionContext } from '@/lib/uploads/contexts/execution/utils' +import { deleteFile } from '@/lib/uploads/core/storage-service' +import { deleteFileMetadata } from '@/lib/uploads/server/metadata' +import { MAX_BUFFERED_TRANSFER_BYTES } from '@/lib/uploads/shared/types' +import { resolveStoredFileMetadata } from '@/lib/uploads/utils/stored-file-metadata' +import type { UserFile } from '@/executor/types' + +const logger = createLogger('InternalToolFileResult') + +type FileStorageScope = + | { kind: 'execution'; context: ExecutionContext; userId?: string } + | { kind: 'copilot'; userId: string } + +interface CreatedFile { + key: string + context: FileStorageScope['kind'] +} + +function resolveCopilotUserId(context: InternalToolOperationContext): string { + const origin = context.executorDelegationOrigin + const principal = origin?.principal + const subject = principal ? resolvePrincipalSubject(principal) : null + if (principal && subject?.kind !== 'sim_user') { + throw new PrincipalSubjectUserRequiredError(principal.kind) + } + const userId = + subject?.kind === 'sim_user' ? subject.userId : (origin?.subjectUserId ?? context.userId) + if (!userId?.trim()) throw new Error('Authentication required') + if ( + (origin?.subjectUserId !== undefined && origin.subjectUserId !== userId) || + (context.userId !== undefined && context.userId !== userId) + ) { + throw new Error('Tool file owner does not match the authenticated subject') + } + return userId +} + +function resolveFileStorageScope(context: InternalToolOperationContext): FileStorageScope { + if (context.executionId) { + if (!context.workspaceId?.trim() || !context.workflowId.trim() || !context.executionId.trim()) { + throw new Error('Execution file output requires a complete trusted execution scope') + } + return { + kind: 'execution', + context: { + workspaceId: context.workspaceId, + workflowId: context.workflowId, + executionId: context.executionId, + }, + userId: context.userId, + } + } + return { kind: 'copilot', userId: resolveCopilotUserId(context) } +} + +function validateFiles(result: InternalToolFileResult): readonly InternalToolFile[] { + const files = [...new Set(result.files)] + let totalBytes = 0 + for (const file of files) { + if ( + !Buffer.isBuffer(file.buffer) || + typeof file.name !== 'string' || + !file.name.trim() || + typeof file.mimeType !== 'string' || + !file.mimeType.trim() + ) { + throw new Error('Tool file output requires a buffer, filename, and MIME type') + } + assertKnownSizeWithinLimit(file.buffer.length, MAX_BUFFERED_TRANSFER_BYTES, 'Tool output file') + totalBytes += file.buffer.length + assertKnownSizeWithinLimit(totalBytes, MAX_BUFFERED_TRANSFER_BYTES, 'Tool output files') + } + return files +} + +/** Rollback must finish even when the operation's signal is already aborted. */ +async function rollbackCreatedFiles(files: readonly CreatedFile[]): Promise { + for (const file of files) { + try { + await deleteFile(file) + await deleteFileMetadata(file.key) + } catch (error) { + logger.error('Failed to roll back an unpublished tool output file', { + key: file.key, + context: file.context, + error: getErrorMessage(error), + }) + } + } +} + +/** Stores file results and rolls back their objects if final presentation fails. */ +export async function storeInternalToolFileResult( + result: InternalToolFileResult, + context: InternalToolOperationContext, + finalize: (body: unknown) => T, + signal?: AbortSignal +): Promise { + signal?.throwIfAborted() + const files = validateFiles(result) + const scope = resolveFileStorageScope(context) + const createdFiles: CreatedFile[] = [] + const storedFiles = new Map() + + try { + for (const file of files) { + signal?.throwIfAborted() + const metadata = resolveStoredFileMetadata(file.name, file.mimeType, file.buffer) + const storedFile = + scope.kind === 'execution' + ? await uploadExecutionFile( + scope.context, + file.buffer, + metadata.fileName, + metadata.mimeType, + scope.userId + ) + : await uploadCopilotFile({ + buffer: file.buffer, + fileName: metadata.fileName, + contentType: metadata.mimeType, + userId: scope.userId, + }) + createdFiles.push({ key: storedFile.key, context: scope.kind }) + storedFiles.set(file, 'mimeType' in storedFile ? omit(storedFile, ['mimeType']) : storedFile) + signal?.throwIfAborted() + } + const presentedFiles = result.files.map((file) => { + const storedFile = storedFiles.get(file) + if (!storedFile) throw new Error('Tool output file was not stored') + return storedFile + }) + const output = await finalize(result.present(presentedFiles)) + signal?.throwIfAborted() + return output + } catch (error) { + await rollbackCreatedFiles(createdFiles) + signal?.throwIfAborted() + throw error + } +} + +/** Stores trusted in-process file results before their small JSON envelope crosses transport. */ +export async function presentInternalToolOperationResult( + result: InternalToolOperationResult, + context: InternalToolOperationContext, + signal?: AbortSignal +): Promise { + if (result instanceof Response) return result + return storeInternalToolFileResult( + result, + context, + (presented) => { + const body = JSON.stringify(presented) + if (body === undefined) throw new TypeError('Tool file result must be JSON serializable') + assertKnownSizeWithinLimit( + Buffer.byteLength(body, 'utf8'), + MAX_TOOL_RESPONSE_BODY_BYTES, + 'Tool response body' + ) + const headers = new Headers(result.init?.headers) + headers.delete('content-length') + headers.delete('content-encoding') + headers.set('content-type', 'application/json') + return new Response(body, { ...result.init, headers }) + }, + signal + ) +} diff --git a/apps/sim/lib/internal/tool-operations/file-result.ts b/apps/sim/lib/internal/tool-operations/file-result.ts new file mode 100644 index 00000000000..42bb5167891 --- /dev/null +++ b/apps/sim/lib/internal/tool-operations/file-result.ts @@ -0,0 +1,45 @@ +import type { UserFile } from '@/executor/types' + +/** Binary output kept in process until the executor persists it. */ +export interface InternalToolFile { + buffer: Buffer + name: string + mimeType: string +} + +/** The presenter receives stored descriptors, never inline file bytes. */ +export interface InternalToolFileResult { + kind: 'file-output' + files: readonly InternalToolFile[] + present: (files: readonly UserFile[]) => unknown + init?: ResponseInit +} + +export function createInternalToolFilesResult( + files: readonly InternalToolFile[], + present: InternalToolFileResult['present'], + init?: ResponseInit +): InternalToolFileResult { + return { kind: 'file-output', files, present, ...(init ? { init } : {}) } +} + +export function createInternalToolFileResult( + file: InternalToolFile, + present: (file: UserFile) => unknown, + init?: ResponseInit +): InternalToolFileResult { + return createInternalToolFilesResult([file], (files) => present(files[0]!), init) +} + +export function isInternalToolFileResult(value: unknown): value is InternalToolFileResult { + return ( + typeof value === 'object' && + value !== null && + 'kind' in value && + value.kind === 'file-output' && + 'files' in value && + Array.isArray(value.files) && + 'present' in value && + typeof value.present === 'function' + ) +} diff --git a/apps/sim/lib/internal/tool-operations/registry.server.ts b/apps/sim/lib/internal/tool-operations/registry.server.ts index bc8fcf7b7f0..ea568ff50dd 100644 --- a/apps/sim/lib/internal/tool-operations/registry.server.ts +++ b/apps/sim/lib/internal/tool-operations/registry.server.ts @@ -1,7 +1,12 @@ -import type { InternalToolOperationHandler } from '@/lib/internal/tool-operations/types' +import type { + InternalToolOperationHandler, + InternalToolOperationResult, +} from '@/lib/internal/tool-operations/types' import { isMcpTool } from '@/executor/constants' -type InternalToolOperationHandlerLoader = () => Promise +type InternalToolOperationHandlerLoader = () => Promise< + InternalToolOperationHandler +> const STS_TOOL_IDS = [ 'sts_assume_role', @@ -456,6 +461,7 @@ const JUPYTER_TOOL_IDS = [ 'jupyter_delete_content', 'jupyter_delete_session', 'jupyter_get_content', + 'jupyter_get_content_v2', 'jupyter_interrupt_kernel', 'jupyter_list_contents', 'jupyter_list_kernels', @@ -730,6 +736,7 @@ const OUTLOOK_TOOL_IDS = [ 'outlook_copy', 'outlook_delete', 'outlook_draft', + 'outlook_get_attachment', 'outlook_mark_read', 'outlook_mark_unread', 'outlook_move', @@ -742,6 +749,7 @@ const SSH_TOOL_IDS = [ 'ssh_create_directory', 'ssh_delete_file', 'ssh_download_file', + 'ssh_download_file_v2', 'ssh_execute_command', 'ssh_execute_script', 'ssh_get_system_info', @@ -1012,6 +1020,7 @@ const CURSOR_TOOL_IDS = ['cursor_download_artifact', 'cursor_download_artifact_v const SFTP_TOOL_IDS = [ 'sftp_delete', 'sftp_download', + 'sftp_download_v2', 'sftp_list', 'sftp_mkdir', 'sftp_upload', @@ -1069,7 +1078,12 @@ const PERSONA_TOOL_IDS = ['persona_import_accounts'] as const const SHAREPOINT_TOOL_IDS = ['sharepoint_download_file', 'sharepoint_upload_file'] as const -const QUIVER_TOOL_IDS = ['quiver_text_to_svg', 'quiver_image_to_svg'] as const +const QUIVER_TOOL_IDS = [ + 'quiver_text_to_svg', + 'quiver_image_to_svg', + 'quiver_text_to_svg_v2', + 'quiver_image_to_svg_v2', +] as const const TELEGRAM_TOOL_IDS = ['telegram_send_document'] as const @@ -1787,7 +1801,7 @@ export function getRegisteredInternalToolOperationIds(): string[] { export async function getInternalToolOperationHandler( toolId: string -): Promise { +): Promise | null> { const loader = handlerLoaders.get(toolId) if (loader) return loader() if (isMcpTool(toolId)) { diff --git a/apps/sim/lib/internal/tool-operations/response-limits.ts b/apps/sim/lib/internal/tool-operations/response-limits.ts new file mode 100644 index 00000000000..fb8828b4ef1 --- /dev/null +++ b/apps/sim/lib/internal/tool-operations/response-limits.ts @@ -0,0 +1,2 @@ +/** Maximum inline tool response size; binary file outputs use stored descriptors. */ +export const MAX_TOOL_RESPONSE_BODY_BYTES = 10 * 1024 * 1024 diff --git a/apps/sim/lib/internal/tool-operations/types.ts b/apps/sim/lib/internal/tool-operations/types.ts index 2e1f52d3584..803c299741e 100644 --- a/apps/sim/lib/internal/tool-operations/types.ts +++ b/apps/sim/lib/internal/tool-operations/types.ts @@ -1,4 +1,5 @@ import type { BillingAttributionSnapshot } from '@/lib/billing/core/billing-attribution' +import type { InternalToolFileResult } from '@/lib/internal/tool-operations/file-result' import type { ExecutorDelegationOrigin } from '@/executor/types' import type { ResolvedSecretTraceRegistry } from '@/executor/utils/resolved-secret-trace-registry' import type { ToolResponse } from '@/tools/types' @@ -42,4 +43,8 @@ export interface InternalToolOperationCall { signal?: AbortSignal } -export type InternalToolOperationHandler = (request: InternalToolOperationCall) => Promise +export type InternalToolOperationResult = Response | InternalToolFileResult + +export type InternalToolOperationHandler = ( + request: InternalToolOperationCall +) => Promise diff --git a/apps/sim/lib/internal/twilio-voice/execute-tool.ts b/apps/sim/lib/internal/twilio-voice/execute-tool.ts index 8b9a555b9f4..840eedfea9a 100644 --- a/apps/sim/lib/internal/twilio-voice/execute-tool.ts +++ b/apps/sim/lib/internal/twilio-voice/execute-tool.ts @@ -1,7 +1,11 @@ import { getErrorMessage } from '@sim/utils/errors' import { z } from 'zod' import { isPayloadSizeLimitError } from '@/lib/core/utils/stream-limits' -import type { InternalToolOperationHandler } from '@/lib/internal/tool-operations/types' +import { isInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' +import type { + InternalToolOperationHandler, + InternalToolOperationResult, +} from '@/lib/internal/tool-operations/types' import { TwilioVoiceOperationError } from '@/lib/internal/twilio-voice/errors' import { getTwilioRecording } from '@/lib/internal/twilio-voice/operations' @@ -11,7 +15,9 @@ const inputSchema = z.object({ recordingSid: z.string().min(1, 'Recording SID is required'), }) -export const executeTwilioVoiceTool: InternalToolOperationHandler = async (request) => { +export const executeTwilioVoiceTool: InternalToolOperationHandler< + InternalToolOperationResult +> = async (request) => { request.signal?.throwIfAborted() if (request.toolId !== 'twilio_voice_get_recording') { return Response.json( @@ -24,12 +30,11 @@ export const executeTwilioVoiceTool: InternalToolOperationHandler = async (reque return Response.json({ success: false, error: 'Invalid request data' }, { status: 400 }) } try { - return Response.json( - await getTwilioRecording(parsed.data, { - requestId: request.requestId, - signal: request.signal, - }) - ) + const result = await getTwilioRecording(parsed.data, { + requestId: request.requestId, + signal: request.signal, + }) + return isInternalToolFileResult(result) ? result : Response.json(result) } catch (error) { request.signal?.throwIfAborted() const status = isPayloadSizeLimitError(error) diff --git a/apps/sim/lib/internal/twilio-voice/operations.test.ts b/apps/sim/lib/internal/twilio-voice/operations.test.ts index dd952e46dbb..8420edeb5cc 100644 --- a/apps/sim/lib/internal/twilio-voice/operations.test.ts +++ b/apps/sim/lib/internal/twilio-voice/operations.test.ts @@ -1,7 +1,12 @@ /** * @vitest-environment node */ -import { beforeEach, describe, expect, it, vi } from 'vitest' + +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { + isInternalToolFileResult, + type StoredToolFile, +} from '@/lib/internal/tool-operations/file-result' const mocks = vi.hoisted(() => ({ secureFetchWithPinnedIP: vi.fn(), @@ -56,12 +61,23 @@ describe('getTwilioRecording', () => { signal: controller.signal, }) ) - expect(result.output).toEqual( - expect.objectContaining({ - duration: 42, - transcriptionText: 'hello', - file: expect.objectContaining({ name: 'RE123.mp3', data: 'AQID', size: 3 }), - }) - ) + assert(isInternalToolFileResult(result)) + expect(result.files).toEqual([ + { name: 'RE123.mp3', mimeType: 'audio/mpeg', buffer: Buffer.from([1, 2, 3]) }, + ]) + const storedFile: StoredToolFile = { + id: 'stored-file-1', + key: 'execution/stored-file-1', + url: '/api/files/serve/stored-file-1', + name: 'RE123.mp3', + type: 'audio/mpeg', + mimeType: 'audio/mpeg', + size: 3, + context: 'execution', + } + expect(result.present([storedFile])).toMatchObject({ + success: true, + output: { duration: 42, transcriptionText: 'hello', file: storedFile }, + }) }) }) diff --git a/apps/sim/lib/internal/twilio-voice/operations.ts b/apps/sim/lib/internal/twilio-voice/operations.ts index 7acc77c44e8..bc551fbe692 100644 --- a/apps/sim/lib/internal/twilio-voice/operations.ts +++ b/apps/sim/lib/internal/twilio-voice/operations.ts @@ -8,10 +8,14 @@ import { readResponseJsonWithLimit, readResponseToBufferWithLimit, } from '@/lib/core/utils/stream-limits' +import { + createInternalToolFileResult, + type InternalToolFile, +} from '@/lib/internal/tool-operations/file-result' import { TwilioVoiceOperationError } from '@/lib/internal/twilio-voice/errors' import { MAX_BUFFERED_TRANSFER_BYTES } from '@/lib/uploads/shared/types' import { getExtensionFromMimeType } from '@/lib/uploads/utils/file-utils' -import type { TwilioGetRecordingOutput, TwilioGetRecordingParams } from '@/tools/twilio_voice/types' +import type { TwilioGetRecordingParams } from '@/tools/twilio_voice/types' const logger = createLogger('TwilioGetRecordingOperation') const MAX_TWILIO_JSON_BYTES = 2 * 1024 * 1024 @@ -67,7 +71,7 @@ async function fetchPinned( export async function getTwilioRecording( input: TwilioGetRecordingParams, context: TwilioVoiceOperationContext -): Promise { +) { context.signal?.throwIfAborted() if (!input.accountSid.startsWith('AC')) { throw new TwilioVoiceOperationError( @@ -131,7 +135,7 @@ export async function getTwilioRecording( logger.warn('Failed to fetch Twilio transcription', { requestId: context.requestId, error }) } - let file: TwilioGetRecordingOutput['output']['file'] + let file: InternalToolFile | undefined if (mediaUrl) { try { const response = await fetchPinned( @@ -151,8 +155,7 @@ export async function getTwilioRecording( file = { name: `${data.sid || input.recordingSid}.${getExtensionFromMimeType(mimeType) || 'dat'}`, mimeType, - data: buffer.toString('base64'), - size: buffer.length, + buffer, } } } catch (error) { @@ -164,25 +167,26 @@ export async function getTwilioRecording( } } - return { + const output = { success: true, - output: { - success: true, - recordingSid: data.sid, - callSid: data.call_sid, - duration: data.duration ? Number.parseInt(data.duration, 10) : undefined, - status: data.status, - channels: data.channels, - source: data.source, - mediaUrl, - file, - price: data.price, - priceUnit: data.price_unit, - uri: data.uri, - transcriptionText: transcription?.transcription_text, - transcriptionStatus: transcription?.status, - transcriptionPrice: transcription?.price, - transcriptionPriceUnit: transcription?.price_unit, - }, + recordingSid: data.sid, + callSid: data.call_sid, + duration: data.duration ? Number.parseInt(data.duration, 10) : undefined, + status: data.status, + channels: data.channels, + source: data.source, + mediaUrl, + price: data.price, + priceUnit: data.price_unit, + uri: data.uri, + transcriptionText: transcription?.transcription_text, + transcriptionStatus: transcription?.status, + transcriptionPrice: transcription?.price, + transcriptionPriceUnit: transcription?.price_unit, } + if (!file) return { success: true, output } + return createInternalToolFileResult(file, (storedFile) => ({ + success: true, + output: { ...output, file: storedFile }, + })) } diff --git a/apps/sim/lib/internal/vanta/execute-tool.ts b/apps/sim/lib/internal/vanta/execute-tool.ts index b510d7453ae..26181300c4b 100644 --- a/apps/sim/lib/internal/vanta/execute-tool.ts +++ b/apps/sim/lib/internal/vanta/execute-tool.ts @@ -1,5 +1,9 @@ import { getErrorMessage } from '@sim/utils/errors' -import type { InternalToolOperationHandler } from '@/lib/internal/tool-operations/types' +import { isInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' +import type { + InternalToolOperationHandler, + InternalToolOperationResult, +} from '@/lib/internal/tool-operations/types' import { VantaOperationError } from '@/lib/internal/vanta/errors' import { vantaDownloadDocumentFileInputSchema, @@ -13,7 +17,9 @@ import { import { vantaQueryBodySchema } from '@/lib/internal/vanta/schema' /** Executes the Vanta tool family without a same-origin HTTP hop. */ -export const executeVantaTool: InternalToolOperationHandler = async (request) => { +export const executeVantaTool: InternalToolOperationHandler = async ( + request +) => { request.signal?.throwIfAborted() const schema = request.toolId === 'vanta_upload_document_file' @@ -47,7 +53,7 @@ export const executeVantaTool: InternalToolOperationHandler = async (request) => context ) request.signal?.throwIfAborted() - return Response.json(result) + return isInternalToolFileResult(result) ? result : Response.json(result) } const query = vantaQueryBodySchema.parse(parsed.data) diff --git a/apps/sim/lib/internal/vanta/operations.test.ts b/apps/sim/lib/internal/vanta/operations.test.ts index 732f6561972..df66cd149cc 100644 --- a/apps/sim/lib/internal/vanta/operations.test.ts +++ b/apps/sim/lib/internal/vanta/operations.test.ts @@ -1,7 +1,12 @@ /** * @vitest-environment node */ -import { beforeEach, describe, expect, it, vi } from 'vitest' + +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' +import { + isInternalToolFileResult, + type StoredToolFile, +} from '@/lib/internal/tool-operations/file-result' const mocks = vi.hoisted(() => ({ fetchAuth: vi.fn(), @@ -98,19 +103,23 @@ describe('Vanta operations', () => { ) expect(mocks.fetchAuth.mock.calls[0]?.[2]).toEqual({ signal: context.signal }) - expect(result).toEqual({ + assert(isInternalToolFileResult(result)) + expect(result.files).toEqual([ + { name: 'report final.pdf', mimeType: 'application/pdf', buffer: Buffer.from('hello') }, + ]) + const storedFile: StoredToolFile = { + id: 'stored-file-1', + key: 'execution/stored-file-1', + url: '/api/files/serve/stored-file-1', + name: 'report final.pdf', + type: 'application/pdf', + mimeType: 'application/pdf', + size: 5, + context: 'execution', + } + expect(result.present([storedFile])).toEqual({ success: true, - output: { - file: { - name: 'report final.pdf', - mimeType: 'application/pdf', - data: Buffer.from('hello').toString('base64'), - size: 5, - }, - name: 'report final.pdf', - mimeType: 'application/pdf', - size: 5, - }, + output: { file: storedFile, name: 'report final.pdf', mimeType: 'application/pdf', size: 5 }, }) }) diff --git a/apps/sim/lib/internal/vanta/operations.ts b/apps/sim/lib/internal/vanta/operations.ts index ced9bece5cd..c649d9b53af 100644 --- a/apps/sim/lib/internal/vanta/operations.ts +++ b/apps/sim/lib/internal/vanta/operations.ts @@ -4,6 +4,10 @@ import { readResponseJsonWithLimit, readResponseToBufferWithLimit, } from '@/lib/core/utils/stream-limits' +import { + createInternalToolFileResult, + type InternalToolFileResult, +} from '@/lib/internal/tool-operations/file-result' import { fetchVantaWithAuth, getVantaBaseUrl, @@ -511,7 +515,7 @@ export async function executeVantaUploadDocumentFile( export async function executeVantaDownloadDocumentFile( input: VantaDownloadDocumentFileInput, context: VantaFileOperationContext -): Promise> { +): Promise { context.signal?.throwIfAborted() const mediaUrl = buildVantaUrl( getVantaBaseUrl(input.region), @@ -565,13 +569,8 @@ export async function executeVantaDownloadDocumentFile( const name = fileNameFromContentDisposition(response.headers.get('content-disposition')) || `vanta-document-file-${input.uploadedFileId}` - return { + return createInternalToolFileResult({ buffer, name, mimeType }, (file) => ({ success: true, - output: { - file: { name, mimeType, data: buffer.toString('base64'), size: buffer.length }, - name, - mimeType, - size: buffer.length, - }, - } + output: { file, name, mimeType, size: file.size }, + })) } diff --git a/apps/sim/lib/internal/zoho-desk/execute-tool.test.ts b/apps/sim/lib/internal/zoho-desk/execute-tool.test.ts index 907d649af75..126da373975 100644 --- a/apps/sim/lib/internal/zoho-desk/execute-tool.test.ts +++ b/apps/sim/lib/internal/zoho-desk/execute-tool.test.ts @@ -3,12 +3,14 @@ */ import { createExecutionContext } from '@sim/testing' import { beforeEach, describe, expect, it, vi } from 'vitest' +import { PayloadSizeLimitError } from '@/lib/core/utils/stream-limits' +import { createInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' +import { MAX_BUFFERED_TRANSFER_BYTES } from '@/lib/uploads/shared/types' const mocks = vi.hoisted(() => ({ getZohoDeskAttachment: vi.fn() })) vi.mock('@/lib/internal/zoho-desk/operations', () => ({ getZohoDeskAttachment: mocks.getZohoDeskAttachment, - MAX_ZOHO_DESK_ATTACHMENT_BYTES: 7 * 1024 * 1024, })) import type { InternalToolOperationCall } from '@/lib/internal/tool-operations/types' @@ -33,28 +35,46 @@ function request(overrides: Partial = {}): InternalTo describe('executeZohoDeskTool', () => { beforeEach(() => { vi.clearAllMocks() - mocks.getZohoDeskAttachment.mockResolvedValue({ - success: true, - output: { file: { name: 'file.pdf', mimeType: 'application/pdf', data: 'YQ==' } }, - }) }) it('dispatches the typed operation with cancellation', async () => { const controller = new AbortController() - const response = await executeZohoDeskTool(request({ signal: controller.signal })) + const result = createInternalToolFileResult( + { buffer: Buffer.alloc(12 * 1024 * 1024), name: 'file.pdf', mimeType: 'application/pdf' }, + (file) => ({ success: true, output: { file } }) + ) + mocks.getZohoDeskAttachment.mockResolvedValue(result) - expect(response.status).toBe(200) + expect(await executeZohoDeskTool(request({ signal: controller.signal }))).toBe(result) expect(mocks.getZohoDeskAttachment).toHaveBeenCalledWith( expect.objectContaining({ orgId: 'org-1' }), { signal: controller.signal } ) }) + it('projects the buffered file limit as 413', async () => { + mocks.getZohoDeskAttachment.mockRejectedValue( + new PayloadSizeLimitError({ + label: 'Zoho Desk attachment', + maxBytes: MAX_BUFFERED_TRANSFER_BYTES, + observedBytes: MAX_BUFFERED_TRANSFER_BYTES + 1, + }) + ) + const response = await executeZohoDeskTool(request()) + if (!(response instanceof Response)) throw new Error('Expected an error response') + expect(response.status).toBe(413) + await expect(response.json()).resolves.toEqual({ + success: false, + error: 'Attachment exceeds the 100 MB download limit', + }) + }) + it('preserves operation status', async () => { mocks.getZohoDeskAttachment.mockRejectedValue( new ZohoDeskOperationError('Invalid attachment href', 400) ) const response = await executeZohoDeskTool(request()) + if (!(response instanceof Response)) throw new Error('Expected an error response') expect(response.status).toBe(400) }) }) diff --git a/apps/sim/lib/internal/zoho-desk/execute-tool.ts b/apps/sim/lib/internal/zoho-desk/execute-tool.ts index 0af245bbe06..1a99f24ba21 100644 --- a/apps/sim/lib/internal/zoho-desk/execute-tool.ts +++ b/apps/sim/lib/internal/zoho-desk/execute-tool.ts @@ -1,12 +1,13 @@ import { getErrorMessage } from '@sim/utils/errors' import { z } from 'zod' import { isPayloadSizeLimitError } from '@/lib/core/utils/stream-limits' -import type { InternalToolOperationHandler } from '@/lib/internal/tool-operations/types' +import type { + InternalToolOperationHandler, + InternalToolOperationResult, +} from '@/lib/internal/tool-operations/types' import { ZohoDeskOperationError } from '@/lib/internal/zoho-desk/errors' -import { - getZohoDeskAttachment, - MAX_ZOHO_DESK_ATTACHMENT_BYTES, -} from '@/lib/internal/zoho-desk/operations' +import { getZohoDeskAttachment } from '@/lib/internal/zoho-desk/operations' +import { MAX_BUFFERED_TRANSFER_BYTES } from '@/lib/uploads/shared/types' const inputSchema = z.object({ accessToken: z.string().min(1), @@ -16,7 +17,9 @@ const inputSchema = z.object({ fileName: z.string().optional(), }) -export const executeZohoDeskTool: InternalToolOperationHandler = async (request) => { +export const executeZohoDeskTool: InternalToolOperationHandler< + InternalToolOperationResult +> = async (request) => { request.signal?.throwIfAborted() if (request.toolId !== 'zoho_desk_get_attachment') { return Response.json( @@ -29,18 +32,14 @@ export const executeZohoDeskTool: InternalToolOperationHandler = async (request) return Response.json({ success: false, error: 'Invalid request data' }, { status: 400 }) } try { - return Response.json( - await getZohoDeskAttachment(parsed.data, { - signal: request.signal, - }) - ) + return await getZohoDeskAttachment(parsed.data, { signal: request.signal }) } catch (error) { request.signal?.throwIfAborted() if (isPayloadSizeLimitError(error)) { return Response.json( { success: false, - error: `Attachment exceeds the ${Math.floor(MAX_ZOHO_DESK_ATTACHMENT_BYTES / (1024 * 1024))} MB download limit`, + error: `Attachment exceeds the ${Math.floor(MAX_BUFFERED_TRANSFER_BYTES / (1024 * 1024))} MB download limit`, }, { status: 413 } ) diff --git a/apps/sim/lib/internal/zoho-desk/operations.test.ts b/apps/sim/lib/internal/zoho-desk/operations.test.ts new file mode 100644 index 00000000000..5283ee5c1e6 --- /dev/null +++ b/apps/sim/lib/internal/zoho-desk/operations.test.ts @@ -0,0 +1,146 @@ +/** + * @vitest-environment node + */ +import { beforeEach, describe, expect, it, vi } from 'vitest' +import { MAX_BUFFERED_TRANSFER_BYTES } from '@/lib/uploads/shared/types' + +const mocks = vi.hoisted(() => ({ secureFetchWithValidation: vi.fn() })) + +vi.mock('@/lib/core/security/input-validation.server', () => ({ + secureFetchWithValidation: mocks.secureFetchWithValidation, +})) + +import { getZohoDeskAttachment } from '@/lib/internal/zoho-desk/operations' + +const input = { + accessToken: 'token', + orgId: 'org-1', + href: '/api/v1/tickets/1/attachments/2/content', + apiDomain: 'https://desk.zoho.eu', +} + +describe('getZohoDeskAttachment', () => { + beforeEach(() => { + vi.clearAllMocks() + }) + + it('returns a 12 MiB attachment for central storage while preserving download guards', async () => { + const buffer = Buffer.alloc(12 * 1024 * 1024, 42) + const controller = new AbortController() + mocks.secureFetchWithValidation.mockResolvedValue( + new Response(new Uint8Array(buffer), { + headers: { + 'content-type': 'application/pdf', + 'content-disposition': "attachment; filename*=UTF-8''ticket%20attachment.pdf", + }, + }) + ) + + const result = await getZohoDeskAttachment(input, { signal: controller.signal }) + + expect(mocks.secureFetchWithValidation).toHaveBeenCalledWith( + 'https://desk.zoho.eu/api/v1/tickets/1/attachments/2/content', + { + profile: 'contentFetch', + method: 'GET', + headers: { + Authorization: 'Zoho-oauthtoken token', + orgId: 'org-1', + 'Content-Type': 'application/json', + }, + timeout: 30_000, + maxResponseBytes: MAX_BUFFERED_TRANSFER_BYTES, + stripAuthOnRedirect: true, + signal: controller.signal, + } + ) + expect(result.files).toHaveLength(1) + expect(result.files[0]?.name).toBe('ticket attachment.pdf') + expect(result.files[0]?.mimeType).toBe('application/pdf') + expect(result.files[0]?.buffer.equals(buffer)).toBe(true) + const file = { + id: 'file-1', + name: 'ticket attachment.pdf', + key: 'execution/workspace/workflow/run/file.pdf', + url: '/api/files/file-1', + type: 'application/pdf', + mimeType: 'application/pdf', + size: buffer.length, + context: 'execution', + } + const presented = result.present([file]) + expect(presented).toEqual({ success: true, output: { file } }) + expect(presented).not.toHaveProperty('output.file.data') + expect(JSON.stringify(presented).length).toBeLessThan(1024) + }) + + it('rejects a declared attachment size above the buffered transfer limit', async () => { + mocks.secureFetchWithValidation.mockResolvedValue( + new Response(new Uint8Array(), { + headers: { 'content-length': String(MAX_BUFFERED_TRANSFER_BYTES + 1) }, + }) + ) + + await expect(getZohoDeskAttachment(input, {})).rejects.toMatchObject({ + maxBytes: MAX_BUFFERED_TRANSFER_BYTES, + observedBytes: MAX_BUFFERED_TRANSFER_BYTES + 1, + }) + }) + + it('rejects an oversized stream even without a content-length header', async () => { + const body = new ReadableStream({ + start(controller) { + controller.enqueue(new Uint8Array(MAX_BUFFERED_TRANSFER_BYTES + 1)) + controller.close() + }, + }) + mocks.secureFetchWithValidation.mockResolvedValue(new Response(body)) + + await expect(getZohoDeskAttachment(input, {})).rejects.toMatchObject({ + maxBytes: MAX_BUFFERED_TRANSFER_BYTES, + observedBytes: MAX_BUFFERED_TRANSFER_BYTES + 1, + }) + }) + + it('retains filename overrides and the binary MIME fallback for empty files', async () => { + mocks.secureFetchWithValidation.mockResolvedValue(new Response(new Uint8Array())) + + const result = await getZohoDeskAttachment({ ...input, fileName: ' empty.bin ' }, {}) + + expect(result.files[0]?.name).toBe('empty.bin') + expect(result.files[0]?.mimeType).toBe('application/octet-stream') + expect(result.files[0]?.buffer.length).toBe(0) + }) + + it.each(['https://desk.zoho.com.attacker.example/attachment', 'http://desk.zoho.com/attachment'])( + 'rejects untrusted attachment URL %s before sending credentials', + async (href) => { + await expect(getZohoDeskAttachment({ ...input, href }, {})).rejects.toMatchObject({ + status: 400, + }) + expect(mocks.secureFetchWithValidation).not.toHaveBeenCalled() + } + ) + + it.each([ + [403, 403], + [500, 502], + [204, 502], + ])('preserves provider HTTP %i as operation status %i', async (status, expectedStatus) => { + mocks.secureFetchWithValidation.mockResolvedValue(new Response(null, { status })) + + await expect(getZohoDeskAttachment(input, {})).rejects.toMatchObject({ + status: expectedStatus, + }) + }) + + it('does not start a download after cancellation', async () => { + const controller = new AbortController() + controller.abort(new Error('Execution cancelled')) + + await expect(getZohoDeskAttachment(input, { signal: controller.signal })).rejects.toThrow( + 'Execution cancelled' + ) + expect(mocks.secureFetchWithValidation).not.toHaveBeenCalled() + }) +}) diff --git a/apps/sim/lib/internal/zoho-desk/operations.ts b/apps/sim/lib/internal/zoho-desk/operations.ts index 8cb3f45a30e..c225cb87ea0 100644 --- a/apps/sim/lib/internal/zoho-desk/operations.ts +++ b/apps/sim/lib/internal/zoho-desk/operations.ts @@ -1,5 +1,11 @@ import { secureFetchWithValidation } from '@/lib/core/security/input-validation.server' +import { readResponseToBufferWithLimit } from '@/lib/core/utils/stream-limits' +import { + createInternalToolFileResult, + type InternalToolFileResult, +} from '@/lib/internal/tool-operations/file-result' import { ZohoDeskOperationError } from '@/lib/internal/zoho-desk/errors' +import { MAX_BUFFERED_TRANSFER_BYTES } from '@/lib/uploads/shared/types' import { isZohoHost } from '@/tools/zoho_desk/host-allowlist' import type { ZohoDeskGetAttachmentParams } from '@/tools/zoho_desk/types' import { @@ -9,8 +15,6 @@ import { resolveZohoAttachmentUrl, } from '@/tools/zoho_desk/utils' -export const MAX_ZOHO_DESK_ATTACHMENT_BYTES = 7 * 1024 * 1024 - export interface ZohoDeskOperationContext { signal?: AbortSignal } @@ -18,10 +22,7 @@ export interface ZohoDeskOperationContext { export async function getZohoDeskAttachment( input: ZohoDeskGetAttachmentParams, context: ZohoDeskOperationContext -): Promise<{ - success: true - output: { file: { data: string; mimeType: string; name: string } } -}> { +): Promise { context.signal?.throwIfAborted() let downloadUrl: URL try { @@ -41,7 +42,7 @@ export async function getZohoDeskAttachment( method: 'GET', headers: buildZohoDeskHeaders({ accessToken: input.accessToken, orgId: input.orgId }), timeout: 30_000, - maxResponseBytes: MAX_ZOHO_DESK_ATTACHMENT_BYTES, + maxResponseBytes: MAX_BUFFERED_TRANSFER_BYTES, stripAuthOnRedirect: true, signal: context.signal, }) @@ -57,20 +58,22 @@ export async function getZohoDeskAttachment( 502 ) } - const buffer = Buffer.from(await response.arrayBuffer()) + const buffer = await readResponseToBufferWithLimit(response, { + maxBytes: MAX_BUFFERED_TRANSFER_BYTES, + label: 'Zoho Desk attachment', + signal: context.signal, + }) context.signal?.throwIfAborted() - return { - success: true, - output: { - file: { - data: buffer.toString('base64'), - mimeType: response.headers.get('content-type') || 'application/octet-stream', - name: deriveAttachmentName( - input.fileName, - response.headers.get('content-disposition'), - downloadUrl.pathname - ), - }, + return createInternalToolFileResult( + { + buffer, + mimeType: response.headers.get('content-type') || 'application/octet-stream', + name: deriveAttachmentName( + input.fileName, + response.headers.get('content-disposition'), + downloadUrl.pathname + ), }, - } + (file) => ({ success: true, output: { file } }) + ) } diff --git a/apps/sim/lib/internal/zoom/execute-tool.ts b/apps/sim/lib/internal/zoom/execute-tool.ts index 803acb22ac3..49e56cc9a72 100644 --- a/apps/sim/lib/internal/zoom/execute-tool.ts +++ b/apps/sim/lib/internal/zoom/execute-tool.ts @@ -1,6 +1,10 @@ import { getErrorMessage } from '@sim/utils/errors' import { z } from 'zod' -import type { InternalToolOperationHandler } from '@/lib/internal/tool-operations/types' +import { isInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' +import type { + InternalToolOperationHandler, + InternalToolOperationResult, +} from '@/lib/internal/tool-operations/types' import { ZoomOperationError } from '@/lib/internal/zoom/errors' import { getZoomMeetingRecordings } from '@/lib/internal/zoom/operations' @@ -12,7 +16,9 @@ const inputSchema = z.object({ downloadFiles: z.boolean().default(false), }) -export const executeZoomTool: InternalToolOperationHandler = async (request) => { +export const executeZoomTool: InternalToolOperationHandler = async ( + request +) => { request.signal?.throwIfAborted() if (request.toolId !== 'zoom_get_meeting_recordings') { return Response.json( @@ -25,12 +31,11 @@ export const executeZoomTool: InternalToolOperationHandler = async (request) => return Response.json({ success: false, error: 'Invalid request data' }, { status: 400 }) } try { - return Response.json( - await getZoomMeetingRecordings(parsed.data, { - requestId: request.requestId, - signal: request.signal, - }) - ) + const result = await getZoomMeetingRecordings(parsed.data, { + requestId: request.requestId, + signal: request.signal, + }) + return isInternalToolFileResult(result) ? result : Response.json(result) } catch (error) { request.signal?.throwIfAborted() if (error instanceof ZoomOperationError) { diff --git a/apps/sim/lib/internal/zoom/operations.test.ts b/apps/sim/lib/internal/zoom/operations.test.ts index d21429d74d8..f56d9a69a94 100644 --- a/apps/sim/lib/internal/zoom/operations.test.ts +++ b/apps/sim/lib/internal/zoom/operations.test.ts @@ -1,7 +1,7 @@ /** * @vitest-environment node */ -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' import { PayloadSizeLimitError } from '@/lib/core/utils/stream-limits' const mocks = vi.hoisted(() => ({ @@ -16,6 +16,10 @@ vi.mock('@/lib/core/security/input-validation.server', () => ({ vi.mock('@/lib/uploads/shared/types', () => ({ MAX_BUFFERED_TRANSFER_BYTES: 5 })) +import { + isInternalToolFileResult, + type StoredToolFile, +} from '@/lib/internal/tool-operations/file-result' import { getZoomMeetingRecordings } from '@/lib/internal/zoom/operations' describe('getZoomMeetingRecordings', () => { @@ -24,6 +28,44 @@ describe('getZoomMeetingRecordings', () => { mocks.validateUrlWithDNS.mockResolvedValue({ isValid: true, resolvedIP: '203.0.113.1' }) }) + it('returns stored recording references with the original recording metadata', async () => { + mocks.secureFetchWithPinnedIP + .mockResolvedValueOnce( + Response.json({ + id: 'meeting-1', + recording_files: [{ id: 'one', download_url: 'https://files.example/one' }], + }) + ) + .mockResolvedValueOnce(new Response('one', { headers: { 'content-type': 'video/mp4' } })) + + const result = await getZoomMeetingRecordings( + { accessToken: 'token', meetingId: 'meeting-1', downloadFiles: true }, + { requestId: 'request-1' } + ) + + assert(isInternalToolFileResult(result)) + expect(result.files).toEqual([ + { name: 'zoom-recording-one.mp4', mimeType: 'video/mp4', buffer: Buffer.from('one') }, + ]) + const storedFile: StoredToolFile = { + id: 'stored-file-1', + key: 'execution/stored-file-1', + url: '/api/files/serve/stored-file-1', + name: 'zoom-recording-one.mp4', + type: 'video/mp4', + mimeType: 'video/mp4', + size: 3, + context: 'execution', + } + expect(result.present([storedFile])).toMatchObject({ + success: true, + output: { + recording: { id: 'meeting-1', recording_files: [{ id: 'one' }] }, + files: [storedFile], + }, + }) + }) + it('downloads sequentially and rejects cumulative recording bytes', async () => { mocks.secureFetchWithPinnedIP .mockResolvedValueOnce( diff --git a/apps/sim/lib/internal/zoom/operations.ts b/apps/sim/lib/internal/zoom/operations.ts index 1860b06e667..72be9339db7 100644 --- a/apps/sim/lib/internal/zoom/operations.ts +++ b/apps/sim/lib/internal/zoom/operations.ts @@ -4,6 +4,10 @@ import { validateUrlWithDNS, } from '@/lib/core/security/input-validation.server' import { isPayloadSizeLimitError } from '@/lib/core/utils/stream-limits' +import { + createInternalToolFilesResult, + type InternalToolFile, +} from '@/lib/internal/tool-operations/file-result' import { ZoomOperationError } from '@/lib/internal/zoom/errors' import { MAX_BUFFERED_TRANSFER_BYTES } from '@/lib/uploads/shared/types' import { getExtensionFromMimeType } from '@/lib/uploads/utils/file-utils' @@ -52,13 +56,7 @@ export interface ZoomOperationContext { export async function getZoomMeetingRecordings( input: ZoomGetMeetingRecordingsParams, context: ZoomOperationContext -): Promise<{ - success: true - output: { - recording: ZoomRecordingsResponse & { recording_files: ZoomRecordingFile[] } - files?: Array<{ name: string; mimeType: string; data: string; size: number }> - } -}> { +) { context.signal?.throwIfAborted() const query = new URLSearchParams() if (input.includeFolderItems != null) { @@ -87,7 +85,7 @@ export async function getZoomMeetingRecordings( throw new ZoomOperationError(errorData.message || `Zoom API error: ${response.status}`, 400) } const data = (await response.json()) as ZoomRecordingsResponse - const files: Array<{ name: string; mimeType: string; data: string; size: number }> = [] + const files: InternalToolFile[] = [] let bufferedBytes = 0 if (input.downloadFiles && Array.isArray(data.recording_files)) { @@ -134,8 +132,7 @@ export async function getZoomMeetingRecordings( files.push({ name: `zoom-recording-${file.id || file.recording_start || Date.now()}.${extension}`, mimeType, - data: buffer.toString('base64'), - size: buffer.length, + buffer, }) } catch (error) { context.signal?.throwIfAborted() @@ -153,36 +150,35 @@ export async function getZoomMeetingRecordings( } } - return { - success: true, - output: { - recording: { - uuid: data.uuid, - id: data.id, - account_id: data.account_id, - host_id: data.host_id, - topic: data.topic, - type: data.type, - start_time: data.start_time, - duration: data.duration, - total_size: data.total_size, - recording_count: data.recording_count, - share_url: data.share_url, - recording_files: (data.recording_files || []).map((file) => ({ - id: file.id, - meeting_id: file.meeting_id, - recording_start: file.recording_start, - recording_end: file.recording_end, - file_type: file.file_type, - file_extension: file.file_extension, - file_size: file.file_size, - play_url: file.play_url, - download_url: file.download_url, - status: file.status, - recording_type: file.recording_type, - })), - }, - files: files.length > 0 ? files : undefined, - }, + const recording = { + uuid: data.uuid, + id: data.id, + account_id: data.account_id, + host_id: data.host_id, + topic: data.topic, + type: data.type, + start_time: data.start_time, + duration: data.duration, + total_size: data.total_size, + recording_count: data.recording_count, + share_url: data.share_url, + recording_files: (data.recording_files || []).map((file) => ({ + id: file.id, + meeting_id: file.meeting_id, + recording_start: file.recording_start, + recording_end: file.recording_end, + file_type: file.file_type, + file_extension: file.file_extension, + file_size: file.file_size, + play_url: file.play_url, + download_url: file.download_url, + status: file.status, + recording_type: file.recording_type, + })), } + if (files.length === 0) return { success: true, output: { recording } } + return createInternalToolFilesResult(files, (storedFiles) => ({ + success: true, + output: { recording, files: storedFiles }, + })) } diff --git a/apps/sim/lib/permission-groups/block-successors.generated.ts b/apps/sim/lib/permission-groups/block-successors.generated.ts index d4f7c30c858..6892fa1b402 100644 --- a/apps/sim/lib/permission-groups/block-successors.generated.ts +++ b/apps/sim/lib/permission-groups/block-successors.generated.ts @@ -9,9 +9,12 @@ */ export const BLOCK_ACCESS_SUCCESSORS: Record = { api_trigger: 'start_trigger', + box: 'box_v2', chat_trigger: 'start_trigger', confluence: 'confluence_v2', cursor: 'cursor_v2', + dropbox: 'dropbox_v2', + dub: 'dub_v2', extend: 'extend_v2', file: 'file_v5', file_v2: 'file_v5', @@ -28,20 +31,26 @@ export const BLOCK_ACCESS_SUCCESSORS: Record = { image_generator: 'image_generator_v2', input_trigger: 'start_trigger', intercom: 'intercom_v2', + jupyter: 'jupyter_v2', kalshi: 'kalshi_v2', linear: 'linear_v2', logs: 'logs_v2', manual_trigger: 'start_trigger', + microsoft_dataverse: 'microsoft_dataverse_v2', microsoft_excel: 'microsoft_excel_v2', mistral_parse: 'mistral_parse_v3', mistral_parse_v2: 'mistral_parse_v3', notion: 'notion_v2', openai: 'embeddings', pulse: 'pulse_v2', + quiver: 'quiver_v2', reducto: 'reducto_v2', router: 'router_v2', + servicenow: 'servicenow_v2', + sftp: 'sftp_v2', sharepoint: 'sharepoint_v2', slack: 'slack_v2', + ssh: 'ssh_v2', starter: 'start_trigger', stt: 'stt_v2', table: 'table_v2', diff --git a/apps/sim/lib/uploads/contexts/copilot/copilot-file-manager.test.ts b/apps/sim/lib/uploads/contexts/copilot/copilot-file-manager.test.ts new file mode 100644 index 00000000000..538bde91cae --- /dev/null +++ b/apps/sim/lib/uploads/contexts/copilot/copilot-file-manager.test.ts @@ -0,0 +1,56 @@ +/** @vitest-environment node */ +import { beforeEach, describe, expect, it, vi } from 'vitest' + +const { mockUploadFile } = vi.hoisted(() => ({ mockUploadFile: vi.fn() })) + +vi.mock('@/lib/uploads/core/storage-service', () => ({ + uploadFile: mockUploadFile, + downloadFile: vi.fn(), +})) +vi.mock('@/lib/core/utils/urls', () => ({ getBaseUrl: () => 'https://sim.example' })) + +import { uploadCopilotFile } from '@/lib/uploads/contexts/copilot/copilot-file-manager' +import type { UploadFileOptions } from '@/lib/uploads/shared/types' + +describe('Copilot output key allocation', () => { + beforeEach(() => { + vi.clearAllMocks() + mockUploadFile.mockImplementation(async (options: UploadFileOptions) => ({ + key: options.customKey, + path: `/api/files/serve/${encodeURIComponent(options.customKey!)}`, + name: options.customKey, + type: options.contentType, + size: options.file.length, + })) + }) + + it('gives concurrent same-named files unique owned keys and preserves their display names', async () => { + const upload = (userId: string) => + uploadCopilotFile({ + buffer: Buffer.from(userId), + fileName: 'report.xlsx', + contentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + userId, + }) + const [first, second] = await Promise.all([upload('user-1'), upload('user-2')]) + + expect(first.key).not.toBe(second.key) + expect(first.key).toMatch(/^copilot\/[0-9a-f-]+\/report\.xlsx$/) + for (const stored of [first, second]) { + expect(stored.name).toBe('report.xlsx') + expect(stored.context).toBe('copilot') + expect(stored.url).toBe( + `https://sim.example/api/files/serve/${encodeURIComponent(stored.key)}` + ) + } + for (const [options] of mockUploadFile.mock.calls) { + expect(options.preserveKey).toBe(true) + expect(options.cleanupOnMetadataFailure).toBe(true) + expect(options.fileName).toBe('report.xlsx') + expect(options.metadata.originalName).toBe('report.xlsx') + expect(options.context).toBe('copilot') + } + expect(mockUploadFile.mock.calls[0][0].metadata.userId).toBe('user-1') + expect(mockUploadFile.mock.calls[1][0].metadata.userId).toBe('user-2') + }) +}) diff --git a/apps/sim/lib/uploads/contexts/copilot/copilot-file-manager.ts b/apps/sim/lib/uploads/contexts/copilot/copilot-file-manager.ts index 9f182f09eb3..c6f537a099a 100644 --- a/apps/sim/lib/uploads/contexts/copilot/copilot-file-manager.ts +++ b/apps/sim/lib/uploads/contexts/copilot/copilot-file-manager.ts @@ -1,5 +1,7 @@ import { createLogger } from '@sim/logger' +import { generateId } from '@sim/utils/id' import { getBaseUrl } from '@/lib/core/utils/urls' +import { buildStorageKeySegment } from '@/lib/uploads/core/storage-key' import { downloadFile, uploadFile } from '@/lib/uploads/core/storage-service' const logger = createLogger('CopilotFileManager') @@ -52,11 +54,15 @@ export async function uploadCopilotFile(options: { contentType: string userId: string }): Promise { + const storageKey = `copilot/${generateId()}/${buildStorageKeySegment('', options.fileName)}` const fileInfo = await uploadFile({ file: options.buffer, fileName: options.fileName, contentType: options.contentType, context: 'copilot', + customKey: storageKey, + preserveKey: true, + cleanupOnMetadataFailure: true, metadata: { userId: options.userId, originalName: options.fileName, @@ -77,7 +83,7 @@ export async function uploadCopilotFile(options: { id: fileInfo.key, key: fileInfo.key, context: 'copilot', - name: fileInfo.name, + name: options.fileName, url, size: fileInfo.size, type: fileInfo.type, diff --git a/apps/sim/lib/uploads/contexts/execution/execution-file-manager.test.ts b/apps/sim/lib/uploads/contexts/execution/execution-file-manager.test.ts index 1d108c60d37..9e4a6b0f7b8 100644 --- a/apps/sim/lib/uploads/contexts/execution/execution-file-manager.test.ts +++ b/apps/sim/lib/uploads/contexts/execution/execution-file-manager.test.ts @@ -167,4 +167,38 @@ describe('uploadExecutionFile key allocation', () => { expect(mockDeleteFromS3).toHaveBeenCalledTimes(1) expect(dbChainMockFns.set).toHaveBeenCalledWith({ deletedAt: expect.any(Date) }) }) + + it('removes the uploaded object and metadata when creating its download URL fails', async () => { + mockGetPresignedUrlWithConfig.mockRejectedValueOnce(new Error('Presigning failed')) + + await expect( + uploadExecutionFile(context, Buffer.from('file'), 'file.txt', 'text/plain', 'user-1') + ).rejects.toThrow('Presigning failed') + + expect(mockDeleteFromS3.mock.calls[0]?.[0]).toBe(mockUploadToS3.mock.calls[0]?.[1]) + expect(dbChainMockFns.update).toHaveBeenCalledTimes(1) + }) + + it('removes its unique object when metadata insertion fails before uploadFile returns', async () => { + dbChainMockFns.returning.mockRejectedValueOnce(new Error('Metadata persistence failed')) + + await expect( + uploadExecutionFile(context, Buffer.from('file'), 'file.txt', 'text/plain', 'user-1') + ).rejects.toThrow('Metadata persistence failed') + + expect(mockDeleteFromS3.mock.calls[0]?.[0]).toBe(mockUploadToS3.mock.calls[0]?.[1]) + expect(mockDeleteFromS3).toHaveBeenCalledOnce() + expect(mockGetPresignedUrlWithConfig).not.toHaveBeenCalled() + }) + + it('keeps the original upload error if cleanup also fails', async () => { + mockGetPresignedUrlWithConfig.mockRejectedValueOnce(new Error('Presigning failed')) + mockDeleteFromS3.mockRejectedValueOnce(new Error('Deletion failed')) + + await expect( + uploadExecutionFile(context, Buffer.from('file'), 'file.txt', 'text/plain', 'user-1') + ).rejects.toThrow('Presigning failed') + + expect(mockDeleteFromS3).toHaveBeenCalledTimes(1) + }) }) diff --git a/apps/sim/lib/uploads/contexts/execution/execution-file-manager.ts b/apps/sim/lib/uploads/contexts/execution/execution-file-manager.ts index b9bb85213b7..8cef00a6767 100644 --- a/apps/sim/lib/uploads/contexts/execution/execution-file-manager.ts +++ b/apps/sim/lib/uploads/contexts/execution/execution-file-manager.ts @@ -14,6 +14,7 @@ import { type WorkspaceFileSecretProvenance, } from '@/lib/uploads/contexts/workspace/workspace-file-secret-provenance' import { + deleteFileMetadata, deleteFileMetadataByIdentity, type FileMetadataRecord, insertImmutableFileMetadata, @@ -123,6 +124,7 @@ export async function uploadExecutionFile( context: 'execution', preserveKey: true, // Don't add timestamp prefix customKey: storageKey, // Use exact execution-scoped key + cleanupOnMetadataFailure: true, metadata, // Pass metadata for cloud storage and database tracking ...(secretProvenance ? { persistMetadata: false } : {}), }) @@ -174,7 +176,7 @@ export async function uploadExecutionFile( }) return userFile } catch (error) { - if (secretProvenance && uploadedKey) { + if (uploadedKey) { try { await StorageService.deleteFile({ key: uploadedKey, context: 'execution' }) if (recordedFile) { @@ -184,9 +186,11 @@ export async function uploadExecutionFile( context: 'execution', contentUpdatedAt: recordedFile.contentUpdatedAt, }) + } else if (!secretProvenance) { + await deleteFileMetadata(uploadedKey) } } catch (cleanupError) { - logger.warn('Could not remove an unreturned execution file', { + logger.error('Failed to clean up an unpublished execution file', { key: uploadedKey, error: getErrorMessage(cleanupError), }) diff --git a/apps/sim/lib/uploads/core/storage-service.local.test.ts b/apps/sim/lib/uploads/core/storage-service.local.test.ts index 230d16086b1..49c9e59a78d 100644 --- a/apps/sim/lib/uploads/core/storage-service.local.test.ts +++ b/apps/sim/lib/uploads/core/storage-service.local.test.ts @@ -6,10 +6,13 @@ import { join } from 'node:path' import { resetDbChainMock } from '@sim/testing' import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest' -const { testDirectory, mockInsertMetadata } = vi.hoisted(() => ({ - testDirectory: `/tmp/sim-knowledge-upload-compensation-${process.pid}`, - mockInsertMetadata: vi.fn(), -})) +const { testDirectory, mockInsertMetadata, mockInsertFileMetadata, mockDeleteFileMetadata } = + vi.hoisted(() => ({ + testDirectory: `/tmp/sim-knowledge-upload-compensation-${process.pid}`, + mockInsertMetadata: vi.fn(), + mockInsertFileMetadata: vi.fn(), + mockDeleteFileMetadata: vi.fn(), + })) vi.mock('@/lib/uploads/core/setup.server', () => ({ UPLOAD_DIR_SERVER: testDirectory })) vi.mock('@/lib/uploads/config', () => ({ @@ -19,7 +22,8 @@ vi.mock('@/lib/uploads/config', () => ({ getStorageConfig: () => ({}), })) vi.mock('@/lib/uploads/server/metadata', () => ({ - insertFileMetadata: vi.fn(), + insertFileMetadata: mockInsertFileMetadata, + deleteFileMetadata: mockDeleteFileMetadata, insertImmutableFileMetadata: mockInsertMetadata, })) @@ -63,6 +67,8 @@ describe('local cache upload compensation', () => { vi.clearAllMocks() resetDbChainMock() mockInsertMetadata.mockReset().mockResolvedValue({ id: 'file-1' }) + mockInsertFileMetadata.mockReset().mockResolvedValue({ id: 'file-1' }) + mockDeleteFileMetadata.mockReset().mockResolvedValue(undefined) await rm(testDirectory, { recursive: true, force: true }) await mkdir(testDirectory, { recursive: true }) }) @@ -118,6 +124,28 @@ describe('local cache upload compensation', () => { ).rejects.toMatchObject({ code: 'ENOENT' }) }) + it.each(['execution', 'copilot'] as const)( + 'removes owned new local %s uploads if metadata persistence fails', + async (context) => { + const key = `${context}/unique-id/file.txt` + mockInsertFileMetadata.mockRejectedValueOnce(ORIGINAL_ERROR) + await expect( + uploadFile({ + file: Buffer.from('hello'), + fileName: 'file.txt', + customKey: key, + preserveKey: true, + cleanupOnMetadataFailure: true, + context, + contentType: 'text/plain', + metadata: { userId: 'user-1' }, + }) + ).rejects.toBe(ORIGINAL_ERROR) + await expect(stat(join(testDirectory, key))).rejects.toMatchObject({ code: 'ENOENT' }) + expect(mockDeleteFileMetadata).toHaveBeenCalledExactlyOnceWith(key) + } + ) + it('does not replace or delete a preexisting object', async () => { await writeOtherAttempt() diff --git a/apps/sim/lib/uploads/core/storage-service.test.ts b/apps/sim/lib/uploads/core/storage-service.test.ts index fe307baf115..43af9e525ac 100644 --- a/apps/sim/lib/uploads/core/storage-service.test.ts +++ b/apps/sim/lib/uploads/core/storage-service.test.ts @@ -11,6 +11,7 @@ const { mockUploadToS3, mockDeleteFromS3, mockInsertFileMetadata, + mockDeleteFileMetadata, mockInsertImmutableFileMetadata, mockCleanupUnboundKnowledgeUpload, mockGetSignedUrl, @@ -26,6 +27,7 @@ const { mockUploadToS3: vi.fn(), mockDeleteFromS3: vi.fn(), mockInsertFileMetadata: vi.fn(), + mockDeleteFileMetadata: vi.fn(), mockInsertImmutableFileMetadata: vi.fn(), mockCleanupUnboundKnowledgeUpload: vi.fn(), mockGetSignedUrl: vi.fn(), @@ -63,6 +65,7 @@ vi.mock('@/lib/uploads/providers/s3/client', () => ({ vi.mock('@/lib/uploads/server/metadata', () => ({ insertFileMetadata: mockInsertFileMetadata, + deleteFileMetadata: mockDeleteFileMetadata, insertImmutableFileMetadata: mockInsertImmutableFileMetadata, })) @@ -87,6 +90,8 @@ describe('createMultipartUpload', () => { mockAbort.mockResolvedValue(undefined) mockUploadToS3.mockResolvedValue({ key: 'k', path: 'p', name: 'k', size: 0, type: 'text/csv' }) mockInsertFileMetadata.mockResolvedValue({ id: 'file-1' }) + mockDeleteFileMetadata.mockResolvedValue(undefined) + mockDeleteFromS3.mockResolvedValue(undefined) mockInsertImmutableFileMetadata.mockResolvedValue({ id: 'file-1' }) mockCleanupUnboundKnowledgeUpload.mockResolvedValue(undefined) mockGetSignedUrl.mockResolvedValue('https://s3.example/create-only') @@ -252,6 +257,101 @@ describe('createMultipartUpload', () => { expect(mockCleanupUnboundKnowledgeUpload).not.toHaveBeenCalled() }) + it.each(['execution', 'copilot'] as const)( + 'removes an owned new %s object if metadata persistence fails, even after cancellation', + async (context) => { + const key = `${context}/new-file-id/file.txt` + const failure = new Error('metadata unavailable') + const controller = new AbortController() + mockUploadToS3.mockResolvedValueOnce({ key }) + mockInsertFileMetadata.mockImplementationOnce(async () => { + controller.abort(new Error('cancelled')) + throw failure + }) + + await expect( + uploadFile({ + file: Buffer.from('hello'), + fileName: 'file.txt', + customKey: key, + preserveKey: true, + cleanupOnMetadataFailure: true, + contentType: 'text/plain', + context, + metadata: { userId: 'user-1', workspaceId: 'workspace-1' }, + signal: controller.signal, + }) + ).rejects.toBe(failure) + + expect(mockDeleteFromS3).toHaveBeenCalledExactlyOnceWith( + key, + { bucket: 'b', region: 'r' }, + undefined + ) + expect(mockDeleteFileMetadata).toHaveBeenCalledExactlyOnceWith(key) + } + ) + + it('preserves the metadata error when cleanup of an owned object also fails', async () => { + const failure = new Error('metadata unavailable') + mockInsertFileMetadata.mockRejectedValueOnce(failure) + mockDeleteFromS3.mockRejectedValueOnce(new Error('storage unavailable')) + + await expect( + uploadFile({ + file: Buffer.from('hello'), + fileName: 'file.txt', + customKey: 'execution/new-file-id/file.txt', + preserveKey: true, + cleanupOnMetadataFailure: true, + contentType: 'text/plain', + context: 'execution', + metadata: { workspaceId: 'workspace-1' }, + }) + ).rejects.toBe(failure) + expect(mockDeleteFromS3).toHaveBeenCalledOnce() + expect(mockDeleteFileMetadata).not.toHaveBeenCalled() + }) + + it.each(['workspace', 'execution', 'copilot'] as const)( + 'leaves existing %s replacement keys untouched without explicit new-key ownership', + async (context) => { + const failure = new Error('metadata unavailable') + mockInsertFileMetadata.mockRejectedValueOnce(failure) + await expect( + uploadFile({ + file: Buffer.from('hello'), + fileName: 'existing.txt', + customKey: `${context}/existing.txt`, + preserveKey: true, + contentType: 'text/plain', + context, + metadata: { userId: 'user-1', workspaceId: 'workspace-1' }, + }) + ).rejects.toBe(failure) + expect(mockDeleteFromS3).not.toHaveBeenCalled() + expect(mockDeleteFileMetadata).not.toHaveBeenCalled() + } + ) + + it.each([ + { context: 'workspace', customKey: 'workspace/file.txt', preserveKey: true }, + { context: 'execution', customKey: undefined, preserveKey: true }, + { context: 'copilot', customKey: 'copilot/file.txt', preserveKey: false }, + ] as const)('rejects cleanup without an explicitly owned ephemeral key: %j', async (scope) => { + await expect( + uploadFile({ + ...scope, + file: Buffer.from('hello'), + fileName: 'file.txt', + contentType: 'text/plain', + cleanupOnMetadataFailure: true, + metadata: { userId: 'user-1' }, + }) + ).rejects.toThrow('newly allocated execution or Copilot key') + expect(mockUploadToS3).not.toHaveBeenCalled() + }) + it('takes the single-shot PutObject path for a payload smaller than one part', async () => { const handle = await createMultipartUpload({ key: 'k', diff --git a/apps/sim/lib/uploads/core/storage-service.ts b/apps/sim/lib/uploads/core/storage-service.ts index dfd2edc83c1..ee67df9704a 100644 --- a/apps/sim/lib/uploads/core/storage-service.ts +++ b/apps/sim/lib/uploads/core/storage-service.ts @@ -98,7 +98,8 @@ async function insertFileMetadataHelper( fileName: string, contentType: string, fileSize: number, - uploadId?: string + uploadId?: string, + cleanupOnMetadataFailure = false ): Promise { const { insertFileMetadata, insertImmutableFileMetadata } = await import( '@/lib/uploads/server/metadata' @@ -131,6 +132,18 @@ async function insertFileMetadataHelper( error: cleanupError, }) } + } else if (cleanupOnMetadataFailure) { + try { + await deleteFile({ key, context }) + const { deleteFileMetadata } = await import('@/lib/uploads/server/metadata') + await deleteFileMetadata(key) + } catch (cleanupError) { + logger.error('Failed to clean up an unpublished tool output upload', { + key, + context, + error: getErrorMessage(cleanupError), + }) + } } throw error } @@ -149,6 +162,7 @@ export async function uploadFile(options: UploadFileOptions): Promise customKey, metadata, persistMetadata = true, + cleanupOnMetadataFailure = false, createOnlyUploadId, signal, } = options @@ -156,6 +170,12 @@ export async function uploadFile(options: UploadFileOptions): Promise if (createOnlyUploadId && (context !== 'knowledge-base' || !metadata)) { throw new Error('Reserved create-only uploads require knowledge-base ownership metadata') } + if ( + cleanupOnMetadataFailure && + ((context !== 'execution' && context !== 'copilot') || !preserveKey || !customKey) + ) { + throw new Error('Upload cleanup requires a newly allocated execution or Copilot key') + } logger.info(`Uploading file to ${context} storage: ${fileName}`) @@ -190,7 +210,8 @@ export async function uploadFile(options: UploadFileOptions): Promise fileName, contentType, file.length, - uploadId + uploadId, + cleanupOnMetadataFailure ) } @@ -219,7 +240,8 @@ export async function uploadFile(options: UploadFileOptions): Promise fileName, contentType, file.length, - uploadId + uploadId, + cleanupOnMetadataFailure ) } @@ -248,7 +270,8 @@ export async function uploadFile(options: UploadFileOptions): Promise fileName, contentType, file.length, - uploadId + uploadId, + cleanupOnMetadataFailure ) } @@ -295,7 +318,8 @@ export async function uploadFile(options: UploadFileOptions): Promise fileName, contentType, file.length, - uploadId + uploadId, + cleanupOnMetadataFailure ) } diff --git a/apps/sim/lib/uploads/shared/types.ts b/apps/sim/lib/uploads/shared/types.ts index f8d58b86e0f..9d846f1c0d2 100644 --- a/apps/sim/lib/uploads/shared/types.ts +++ b/apps/sim/lib/uploads/shared/types.ts @@ -127,6 +127,8 @@ export interface UploadFileOptions { * Disable when a caller finalizes metadata in its own database transaction. */ persistMetadata?: boolean + /** Only for newly allocated, unique execution or Copilot keys; never enable for replacements. */ + cleanupOnMetadataFailure?: boolean /** Internal create-only upload identity when metadata and cleanup were reserved before writing bytes. */ createOnlyUploadId?: string signal?: AbortSignal diff --git a/apps/sim/lib/uploads/utils/attachment-download-budget.test.ts b/apps/sim/lib/uploads/utils/attachment-download-budget.test.ts new file mode 100644 index 00000000000..c68fa225e6c --- /dev/null +++ b/apps/sim/lib/uploads/utils/attachment-download-budget.test.ts @@ -0,0 +1,61 @@ +/** + * @vitest-environment node + */ +import { describe, expect, it } from 'vitest' +import { PayloadSizeLimitError } from '@/lib/core/utils/stream-limits' +import { MAX_BUFFERED_TRANSFER_BYTES } from '@/lib/uploads/shared/types' +import { + AttachmentDownloadBudget, + readAttachmentJson, +} from '@/lib/uploads/utils/attachment-download-budget' + +describe('AttachmentDownloadBudget', () => { + it('defaults to the shared 100 MiB transfer bound', () => { + expect(new AttachmentDownloadBudget().remainingBytes).toBe(MAX_BUFFERED_TRANSFER_BYTES) + }) + + it('shares the remaining bytes across downloads and accepts the exact boundary', async () => { + const budget = new AttachmentDownloadBudget({ maxBytes: 6 }) + await budget.read(new Response('abc'), 'attachments') + await budget.read(new Response('def'), 'attachments') + expect(budget.remainingBytes).toBe(0) + await expect(budget.read(new Response('g'), 'attachments')).rejects.toBeInstanceOf( + PayloadSizeLimitError + ) + expect(budget.remainingBytes).toBe(0) + }) + + it('enforces actual bytes even with a false content-length', async () => { + const budget = new AttachmentDownloadBudget({ maxBytes: 3 }) + await expect( + budget.read(new Response('four', { headers: { 'content-length': '1' } }), 'attachments') + ).rejects.toBeInstanceOf(PayloadSizeLimitError) + }) + + it('accepts zero-byte files at the exact aggregate boundary', async () => { + const budget = new AttachmentDownloadBudget({ maxBytes: 0 }) + expect((await budget.read(new Response(''), 'attachments')).byteLength).toBe(0) + }) + + it('propagates cancellation while reading a body', async () => { + const controller = new AbortController() + const budget = new AttachmentDownloadBudget({ signal: controller.signal }) + const stream = new ReadableStream({ + pull() { + controller.abort(new DOMException('cancelled', 'AbortError')) + }, + }) + await expect(budget.read(new Response(stream), 'attachments')).rejects.toMatchObject({ + name: 'AbortError', + }) + }) + + it('keeps metadata responses bounded separately from file content', async () => { + await expect( + readAttachmentJson( + new Response('{}', { headers: { 'content-length': String(10 * 1024 * 1024 + 1) } }), + 'metadata' + ) + ).rejects.toBeInstanceOf(PayloadSizeLimitError) + }) +}) diff --git a/apps/sim/lib/uploads/utils/attachment-download-budget.ts b/apps/sim/lib/uploads/utils/attachment-download-budget.ts new file mode 100644 index 00000000000..15cdb5520bb --- /dev/null +++ b/apps/sim/lib/uploads/utils/attachment-download-budget.ts @@ -0,0 +1,70 @@ +import { + assertKnownSizeWithinLimit, + DEFAULT_MAX_ERROR_BODY_BYTES, + isPayloadSizeLimitError, + readResponseTextWithLimit, + readResponseToBufferWithLimit, +} from '@/lib/core/utils/stream-limits' +import { MAX_BUFFERED_TRANSFER_BYTES } from '@/lib/uploads/shared/types' + +const MAX_ATTACHMENT_METADATA_BYTES = 10 * 1024 * 1024 + +/** A shared byte budget for sequential attachment downloads in one tool call. */ +export class AttachmentDownloadBudget { + private downloadedBytes = 0 + readonly signal?: AbortSignal + private readonly maxBytes: number + + constructor(options: { signal?: AbortSignal; maxBytes?: number } = {}) { + this.signal = options.signal + this.maxBytes = options.maxBytes ?? MAX_BUFFERED_TRANSFER_BYTES + } + + get remainingBytes(): number { + return this.maxBytes - this.downloadedBytes + } + + assertSize(size: number, label: string, maxFileBytes = this.maxBytes): void { + this.signal?.throwIfAborted() + assertKnownSizeWithinLimit(size, Math.min(this.remainingBytes, maxFileBytes), label) + } + + consume(buffer: Buffer, label: string): Buffer { + this.assertSize(buffer.byteLength, label) + this.downloadedBytes += buffer.byteLength + return buffer + } + + async read(response: Response, label: string, maxFileBytes = this.maxBytes): Promise { + this.signal?.throwIfAborted() + const buffer = await readResponseToBufferWithLimit(response, { + maxBytes: Math.min(this.remainingBytes, maxFileBytes), + label, + signal: this.signal, + }) + return this.consume(buffer, label) + } +} + +/** Provider metadata and error bodies remain bounded independently of file content. */ +export async function readAttachmentJson( + response: Response, + label: string, + signal?: AbortSignal, + maxBytes = MAX_ATTACHMENT_METADATA_BYTES +): Promise { + signal?.throwIfAborted() + const text = await readResponseTextWithLimit(response, { + maxBytes: response.ok ? maxBytes : DEFAULT_MAX_ERROR_BODY_BYTES, + label, + signal, + }) + signal?.throwIfAborted() + return JSON.parse(text) as T +} + +/** Partial attachment failures may be skipped, but cancellation and byte limits must stop the call. */ +export function rethrowAttachmentDownloadError(error: unknown, signal?: AbortSignal): void { + signal?.throwIfAborted() + if (isPayloadSizeLimitError(error)) throw error +} diff --git a/apps/sim/lib/uploads/utils/stored-file-metadata.ts b/apps/sim/lib/uploads/utils/stored-file-metadata.ts new file mode 100644 index 00000000000..d1cee88a972 --- /dev/null +++ b/apps/sim/lib/uploads/utils/stored-file-metadata.ts @@ -0,0 +1,33 @@ +import { sniffImageContentType } from '@/lib/uploads/utils/validation' + +const IMAGE_FILE_EXTENSIONS: Record = { + 'image/gif': 'gif', + 'image/jpeg': 'jpg', + 'image/png': 'png', + 'image/webp': 'webp', +} + +/** Derives stored image metadata from its bytes rather than trusting a provider's MIME type. */ +export function resolveStoredFileMetadata( + fileName: string, + declaredMimeType: string, + buffer: Buffer +): { fileName: string; mimeType: string } { + if (!declaredMimeType.startsWith('image/')) { + return { fileName, mimeType: declaredMimeType } + } + + const mimeType = sniffImageContentType(buffer) + if (!mimeType) { + return { + fileName: `${fileName.replace(/\.[^.]+$/, '')}.bin`, + mimeType: 'application/octet-stream', + } + } + + const extension = IMAGE_FILE_EXTENSIONS[mimeType] + return { + fileName: extension ? `${fileName.replace(/\.[^.]+$/, '')}.${extension}` : fileName, + mimeType, + } +} diff --git a/apps/sim/tools/agiloft/retrieve_attachment.test.ts b/apps/sim/tools/agiloft/retrieve_attachment.test.ts new file mode 100644 index 00000000000..611f53b8abc --- /dev/null +++ b/apps/sim/tools/agiloft/retrieve_attachment.test.ts @@ -0,0 +1,23 @@ +/** @vitest-environment node */ +import { describe, expect, it } from 'vitest' +import { agiloftRetrieveAttachmentTool } from '@/tools/agiloft/retrieve_attachment' + +describe('Agiloft attachment file output', () => { + it('preserves the canonical stored file descriptor without requiring inline data', async () => { + const file = { + id: 'stored-file', + name: 'attachment.pdf', + size: 12 * 1024 * 1024, + type: 'application/pdf', + url: '/api/files/stored', + key: 'execution/attachment.pdf', + context: 'execution', + } + const result = await agiloftRetrieveAttachmentTool.transformResponse!( + Response.json({ success: true, output: { file } }) + ) + expect(result).toEqual({ success: true, output: { file } }) + expect(result.output.file).not.toHaveProperty('data') + expect(result.output.file).not.toHaveProperty('mimeType') + }) +}) diff --git a/apps/sim/tools/agiloft/retrieve_attachment.ts b/apps/sim/tools/agiloft/retrieve_attachment.ts index ad2b2ab1953..b7f02e0f87f 100644 --- a/apps/sim/tools/agiloft/retrieve_attachment.ts +++ b/apps/sim/tools/agiloft/retrieve_attachment.ts @@ -93,12 +93,7 @@ export const agiloftRetrieveAttachmentTool: InternalToolConfig< return { success: true, output: { - file: { - name: data.output.file.name, - mimeType: data.output.file.mimeType, - data: data.output.file.data, - size: data.output.file.size, - }, + file: data.output.file, }, } }, diff --git a/apps/sim/tools/agiloft/types.ts b/apps/sim/tools/agiloft/types.ts index f21eb5c265c..2ef86af87e6 100644 --- a/apps/sim/tools/agiloft/types.ts +++ b/apps/sim/tools/agiloft/types.ts @@ -1,4 +1,5 @@ -import type { ToolResponse } from '@/tools/types' +import type { UserFile } from '@/executor/types' +import type { ToolFileData, ToolResponse } from '@/tools/types' /** * Connection and credentials. `table` is optional here because EWLogin is @@ -149,12 +150,7 @@ export interface AgiloftRetrieveAttachmentParams extends AgiloftBaseParams { export interface AgiloftRetrieveAttachmentResponse extends ToolResponse { output: { - file: { - name: string - mimeType: string - data: string - size: number - } + file: UserFile | ToolFileData } } diff --git a/apps/sim/tools/binary-downloads.test.ts b/apps/sim/tools/binary-downloads.test.ts new file mode 100644 index 00000000000..d08f4a94893 --- /dev/null +++ b/apps/sim/tools/binary-downloads.test.ts @@ -0,0 +1,235 @@ +/** @vitest-environment node */ +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { boxDownloadFileTool, boxDownloadFileV2Tool } from '@/tools/box/download_file' +import { daytonaDownloadFileTool } from '@/tools/daytona/download_file' +import { dropboxDownloadTool, dropboxDownloadV2Tool } from '@/tools/dropbox/download' +import { getQrCodeTool, getQrCodeV2Tool } from '@/tools/dub/get_qr_code' +import { + dataverseDownloadFileTool, + dataverseDownloadFileV2Tool, +} from '@/tools/microsoft_dataverse/download_file' +import { personaPrintInquiryPdfTool } from '@/tools/persona/print_inquiry_pdf' +import { s3GetObjectTool } from '@/tools/s3/get_object' +import { + downloadAttachmentTool, + downloadAttachmentV2Tool, +} from '@/tools/servicenow/download_attachment' +import { storageDownloadTool } from '@/tools/supabase/storage_download' + +interface BinaryResult { + success: boolean + output: Record +} + +interface DownloadCase { + tool: { id: string; request: { responseType?: 'binary' }; outputs?: Record } + transform: (response: Response) => Promise + name: string + mimeType?: string + outputKeys?: string[] + checkMetadata?: (output: Record, size: number) => void +} + +const DOWNLOAD_CASES: DownloadCase[] = [ + { + tool: boxDownloadFileV2Tool, + transform: (response) => boxDownloadFileV2Tool.transformResponse!(response), + name: 'download.pdf', + outputKeys: ['file'], + }, + { + tool: dropboxDownloadV2Tool, + transform: (response) => + dropboxDownloadV2Tool.transformResponse!(response, { path: '/download.pdf' }), + name: 'download.pdf', + outputKeys: ['file', 'metadata', 'temporaryLink'], + checkMetadata: (output, size) => { + expect(output.metadata).toEqual({ id: 'file-1', name: 'download.pdf', size }) + expect(output.temporaryLink).toBeUndefined() + }, + }, + { + tool: s3GetObjectTool, + transform: (response) => + s3GetObjectTool.transformResponse!(response, { + accessKeyId: 'test-access-key', + secretAccessKey: 'test-secret-key', + bucketName: 'test-bucket', + region: 'us-east-1', + objectKey: 'folder/download.pdf', + }), + name: 'download.pdf', + checkMetadata: (output, size) => { + expect(output.metadata).toEqual({ + fileType: 'application/pdf', + size, + name: 'download.pdf', + lastModified: 'Fri, 11 Sep 2026 12:00:00 GMT', + }) + expect(output.url).toMatch( + /^https:\/\/test-bucket\.s3\.us-east-1\.amazonaws\.com\/folder\/download\.pdf\?/ + ) + }, + }, + { + tool: storageDownloadTool, + transform: (response) => + storageDownloadTool.transformResponse!(response, { + projectId: 'project-1', + apiKey: 'test-key', + bucket: 'documents', + path: 'folder/original.pdf', + fileName: 'renamed.pdf', + }), + name: 'renamed.pdf', + }, + { + tool: daytonaDownloadFileTool, + transform: (response) => + daytonaDownloadFileTool.transformResponse!(response, { + apiKey: 'test-key', + sandboxId: 'sandbox-1', + filePath: '/workspace/download.pdf', + }), + name: 'download.pdf', + checkMetadata: (output, size) => { + expect(output.name).toBe('download.pdf') + expect(output.mimeType).toBe('application/pdf') + expect(output.size).toBe(size) + }, + }, + { + tool: dataverseDownloadFileV2Tool, + transform: (response) => + dataverseDownloadFileV2Tool.transformResponse!(response, { + accessToken: 'test-token', + environmentUrl: 'https://test.crm.dynamics.com', + entitySetName: 'accounts', + recordId: 'record-1', + fileColumn: 'cr_document', + }), + name: 'download.pdf', + outputKeys: ['file', 'fileColumn'], + checkMetadata: (output) => { + expect(output.fileColumn).toBe('cr_document') + }, + }, + { + tool: personaPrintInquiryPdfTool, + transform: (response) => + personaPrintInquiryPdfTool.transformResponse!(response, { + apiKey: 'test-key', + inquiryId: 'inq_test', + }), + name: 'inq_test.pdf', + }, + { + tool: downloadAttachmentV2Tool, + transform: (response) => downloadAttachmentV2Tool.transformResponse!(response), + name: 'download.pdf', + outputKeys: ['file'], + }, + { + tool: getQrCodeV2Tool, + transform: (response) => getQrCodeV2Tool.transformResponse!(response), + name: 'qrcode.png', + mimeType: 'image/png', + outputKeys: ['file'], + }, +] + +function binaryResponse(buffer: Buffer, mimeType = 'application/pdf'): Response { + return new Response(buffer, { + headers: { + 'content-type': mimeType, + 'content-length': String(buffer.length), + 'content-disposition': 'attachment; filename="download.pdf"', + 'last-modified': 'Fri, 11 Sep 2026 12:00:00 GMT', + 'dropbox-api-result': JSON.stringify({ + id: 'file-1', + name: 'download.pdf', + size: buffer.length, + }), + 'x-ms-file-name': 'download.pdf', + 'x-ms-file-size': String(buffer.length), + }, + }) +} + +function expectBinaryFile(result: BinaryResult, buffer: Buffer, provider: DownloadCase): void { + expect(result.success).toBe(true) + const file = result.output.file as { + name: unknown + mimeType: unknown + size: unknown + data: unknown + } + expect(file.name).toBe(provider.name) + expect(file.mimeType).toBe(provider.mimeType ?? 'application/pdf') + expect(file.size).toBe(buffer.length) + expect(Buffer.isBuffer(file.data)).toBe(true) + if (!Buffer.isBuffer(file.data)) throw new Error('Expected raw file bytes') + expect(file.data.length).toBe(buffer.length) + expect(file.data.equals(buffer)).toBe(true) + expect(result.output).not.toHaveProperty('content') + expect(result.output).not.toHaveProperty('fileContent') + if (provider.outputKeys) { + expect(Object.keys(result.output).sort()).toEqual(provider.outputKeys) + } + provider.checkMetadata?.(result.output, buffer.length) +} + +beforeEach(() => { + vi.stubGlobal('fetch', vi.fn()) +}) + +afterEach(() => { + expect(fetch).not.toHaveBeenCalled() + vi.unstubAllGlobals() +}) + +describe.each(DOWNLOAD_CASES)('$tool.id binary download', (provider) => { + it('opts into the bounded binary transfer budget', () => { + expect(provider.tool.request.responseType).toBe('binary') + expect(provider.tool.outputs).not.toHaveProperty('content') + expect(provider.tool.outputs).not.toHaveProperty('fileContent') + if (provider.outputKeys) { + expect(Object.keys(provider.tool.outputs!).sort()).toEqual(provider.outputKeys) + } + }) + + it('returns raw bytes and file metadata above the former 10 MiB cap', async () => { + const buffer = Buffer.alloc(11 * 1024 * 1024, 65) + const result = await provider.transform(binaryResponse(buffer, provider.mimeType)) + expectBinaryFile(result, buffer, provider) + }) + + it('returns small downloads without inline content', async () => { + const buffer = Buffer.from('small file contents') + const result = await provider.transform(binaryResponse(buffer, provider.mimeType)) + expectBinaryFile(result, buffer, provider) + }) +}) + +const LEGACY_DOWNLOAD_CASES = [ + { tool: boxDownloadFileTool, content: 'content' }, + { tool: dropboxDownloadTool, content: 'content' }, + { tool: getQrCodeTool, content: 'content' }, + { tool: dataverseDownloadFileTool, content: 'fileContent' }, + { tool: downloadAttachmentTool, content: 'content' }, +] as const + +describe.each(LEGACY_DOWNLOAD_CASES)( + '$tool.id legacy download compatibility', + ({ tool, content }) => { + it('retains the original response budget and inline base64 contract', async () => { + expect(tool.request).not.toHaveProperty('responseType') + const buffer = Buffer.from('saved workflow content') + const result = await tool.transformResponse(binaryResponse(buffer)) + expect(result.success).toBe(true) + expect(result.output).toHaveProperty(content, buffer.toString('base64')) + expect(result.output.file?.data).toBe(buffer.toString('base64')) + expect(tool.outputs).toHaveProperty(content) + }) + } +) diff --git a/apps/sim/tools/box/download_file.ts b/apps/sim/tools/box/download_file.ts index 24366105742..20ea1ffdf46 100644 --- a/apps/sim/tools/box/download_file.ts +++ b/apps/sim/tools/box/download_file.ts @@ -1,7 +1,50 @@ -import type { ToolConfig } from '@/tools/types' -import type { BoxDownloadFileParams, BoxDownloadFileResponse } from './types' +import { omit } from '@sim/utils/object' +import type { + BoxDownloadFileParams, + BoxDownloadFileResponse, + BoxDownloadFileV2Response, +} from '@/tools/box/types' +import type { ToolConfig, ToolFileData } from '@/tools/types' -export const boxDownloadFileTool: ToolConfig = { +async function transformDownloadResponse(response: Response) { + if (response.status === 202) { + const retryAfter = response.headers.get('retry-after') || 'a few' + throw new Error(`File is not yet ready for download. Retry after ${retryAfter} seconds.`) + } + + if (!response.ok) { + const errorText = await response.text() + throw new Error(errorText || `Failed to download file: ${response.status}`) + } + + const contentType = response.headers.get('content-type') || 'application/octet-stream' + const contentDisposition = response.headers.get('content-disposition') + let fileName = 'download' + + if (contentDisposition) { + const match = contentDisposition.match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/) + if (match?.[1]) { + fileName = match[1].replace(/['"]/g, '') + } + } + + const arrayBuffer = await response.arrayBuffer() + const buffer = Buffer.from(arrayBuffer) + + return { + success: true, + output: { + file: { + name: fileName, + mimeType: contentType, + data: buffer, + size: buffer.length, + }, + }, + } +} + +export const boxDownloadFileTool = { id: 'box_download_file', name: 'Box Download File', description: 'Download a file from Box', @@ -36,40 +79,15 @@ export const boxDownloadFileTool: ToolConfig { - if (response.status === 202) { - const retryAfter = response.headers.get('retry-after') || 'a few' - throw new Error(`File is not yet ready for download. Retry after ${retryAfter} seconds.`) - } - - if (!response.ok) { - const errorText = await response.text() - throw new Error(errorText || `Failed to download file: ${response.status}`) - } - - const contentType = response.headers.get('content-type') || 'application/octet-stream' - const contentDisposition = response.headers.get('content-disposition') - let fileName = 'download' - - if (contentDisposition) { - const match = contentDisposition.match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/) - if (match?.[1]) { - fileName = match[1].replace(/['"]/g, '') - } - } - - const arrayBuffer = await response.arrayBuffer() - const buffer = Buffer.from(arrayBuffer) - + const result = await transformDownloadResponse(response) + const file = result.output.file + const content = file.data.toString('base64') return { - success: true, + ...result, output: { - file: { - name: fileName, - mimeType: contentType, - data: buffer.toString('base64'), - size: buffer.length, - }, - content: buffer.toString('base64'), + ...result.output, + file: { ...file, data: content }, + content, }, } }, @@ -84,4 +102,16 @@ export const boxDownloadFileTool: ToolConfig + +export const boxDownloadFileV2Tool: ToolConfig< + BoxDownloadFileParams, + BoxDownloadFileV2Response +> = { + ...boxDownloadFileTool, + id: 'box_download_file_v2', + version: '2.0.0', + request: { ...boxDownloadFileTool.request, responseType: 'binary' }, + transformResponse: transformDownloadResponse, + outputs: omit(boxDownloadFileTool.outputs, ['content']), } diff --git a/apps/sim/tools/box/index.ts b/apps/sim/tools/box/index.ts index 2e3b748fb42..a9bd6e3cbf5 100644 --- a/apps/sim/tools/box/index.ts +++ b/apps/sim/tools/box/index.ts @@ -2,7 +2,7 @@ export { boxCopyFileTool } from '@/tools/box/copy_file' export { boxCreateFolderTool } from '@/tools/box/create_folder' export { boxDeleteFileTool } from '@/tools/box/delete_file' export { boxDeleteFolderTool } from '@/tools/box/delete_folder' -export { boxDownloadFileTool } from '@/tools/box/download_file' +export { boxDownloadFileTool, boxDownloadFileV2Tool } from '@/tools/box/download_file' export { boxGetFileInfoTool } from '@/tools/box/get_file_info' export { boxListFolderItemsTool } from '@/tools/box/list_folder_items' export { boxSearchTool } from '@/tools/box/search' diff --git a/apps/sim/tools/box/types.ts b/apps/sim/tools/box/types.ts index 07368f79984..c5463b3089c 100644 --- a/apps/sim/tools/box/types.ts +++ b/apps/sim/tools/box/types.ts @@ -1,3 +1,4 @@ +import type { UserFile } from '@/executor/types' import type { OutputProperty, ToolResponse } from '@/tools/types' export interface BoxUploadFileParams { @@ -95,6 +96,12 @@ export interface BoxDownloadFileResponse extends ToolResponse { } } +export interface BoxDownloadFileV2Response extends ToolResponse { + output: Omit & { + file: File + } +} + export interface BoxFileInfoResponse extends ToolResponse { output: { id: string diff --git a/apps/sim/tools/cursor/download_artifact.test.ts b/apps/sim/tools/cursor/download_artifact.test.ts new file mode 100644 index 00000000000..dc32b3f1953 --- /dev/null +++ b/apps/sim/tools/cursor/download_artifact.test.ts @@ -0,0 +1,33 @@ +/** @vitest-environment node */ +import { describe, expect, it } from 'vitest' +import { downloadArtifactTool, downloadArtifactV2Tool } from '@/tools/cursor/download_artifact' + +describe('Cursor artifact output versions', () => { + it('preserves legacy inline metadata', async () => { + const file = { name: 'index.ts', mimeType: 'text/plain', data: 'YQ==', size: 1 } + const result = await downloadArtifactTool.transformResponse!( + Response.json({ success: true, output: { file } }) + ) + expect(result).toEqual({ + success: true, + output: { content: 'Downloaded artifact: index.ts', metadata: file }, + }) + }) + + it('preserves only the canonical stored file in v2', async () => { + const file = { + id: 'stored-file', + name: 'index.ts', + size: 12 * 1024 * 1024, + type: 'text/plain', + url: '/api/files/stored', + key: 'execution/index.ts', + context: 'execution', + } + const result = await downloadArtifactV2Tool.transformResponse!( + Response.json({ success: true, output: { file } }) + ) + expect(result).toEqual({ success: true, output: { file } }) + expect(Object.keys(downloadArtifactV2Tool.outputs!)).toEqual(['file']) + }) +}) diff --git a/apps/sim/tools/cursor/types.ts b/apps/sim/tools/cursor/types.ts index 2dfcf38fa20..31159e509bd 100644 --- a/apps/sim/tools/cursor/types.ts +++ b/apps/sim/tools/cursor/types.ts @@ -1,3 +1,4 @@ +import type { UserFile } from '@/executor/types' import type { ToolResponse } from '@/tools/types' interface BaseCursorParams { @@ -218,12 +219,7 @@ export interface DownloadArtifactResponse extends ToolResponse { export interface DownloadArtifactV2Response extends ToolResponse { output: { - file: { - name: string - mimeType: string - data: string - size: number - } + file: UserFile } } diff --git a/apps/sim/tools/daytona/download_file.ts b/apps/sim/tools/daytona/download_file.ts index 201bd6fa5af..1b2c5402840 100644 --- a/apps/sim/tools/daytona/download_file.ts +++ b/apps/sim/tools/daytona/download_file.ts @@ -40,6 +40,7 @@ export const daytonaDownloadFileTool: ToolConfig< }, request: { + responseType: 'binary', url: (params) => daytonaToolboxUrl( params.sandboxId, @@ -75,7 +76,7 @@ export const daytonaDownloadFileTool: ToolConfig< file: { name: fileName, mimeType, - data: buffer.toString('base64'), + data: buffer, size: buffer.length, }, name: fileName, diff --git a/apps/sim/tools/dropbox/download.ts b/apps/sim/tools/dropbox/download.ts index 011e1a64a83..dbd57e8894c 100644 --- a/apps/sim/tools/dropbox/download.ts +++ b/apps/sim/tools/dropbox/download.ts @@ -1,8 +1,66 @@ +import { omit } from '@sim/utils/object' import { httpHeaderSafeJson } from '@/lib/core/utils/validation' -import type { DropboxDownloadParams, DropboxDownloadResponse } from '@/tools/dropbox/types' -import type { ToolConfig } from '@/tools/types' +import type { + DropboxDownloadParams, + DropboxDownloadResponse, + DropboxDownloadV2Response, +} from '@/tools/dropbox/types' +import type { ToolConfig, ToolFileData } from '@/tools/types' -export const dropboxDownloadTool: ToolConfig = { +async function transformDownloadResponse(response: Response, params?: DropboxDownloadParams) { + if (!response.ok) { + const errorText = await response.text() + return { + success: false, + error: errorText || 'Failed to download file', + output: {}, + } + } + + const apiResultHeader = + response.headers.get('dropbox-api-result') || response.headers.get('Dropbox-API-Result') + const metadata = apiResultHeader ? JSON.parse(apiResultHeader) : undefined + const contentType = response.headers.get('content-type') || 'application/octet-stream' + const arrayBuffer = await response.arrayBuffer() + const buffer = Buffer.from(arrayBuffer) + const resolvedName = metadata?.name || params?.path?.split('/').pop() || 'download' + + let temporaryLink: string | undefined + if (params?.accessToken) { + try { + const linkResponse = await fetch('https://api.dropboxapi.com/2/files/get_temporary_link', { + method: 'POST', + headers: { + Authorization: `Bearer ${params.accessToken}`, + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ path: params.path.trim() }), + }) + if (linkResponse.ok) { + const linkData = await linkResponse.json() + temporaryLink = linkData.link + } + } catch { + temporaryLink = undefined + } + } + + return { + success: true, + output: { + file: { + name: resolvedName, + mimeType: contentType, + data: buffer, + size: buffer.length, + }, + metadata, + temporaryLink, + }, + } +} + +export const dropboxDownloadTool = { id: 'dropbox_download', name: 'Dropbox Download File', description: 'Download a file from Dropbox with metadata and content', @@ -38,55 +96,16 @@ export const dropboxDownloadTool: ToolConfig { - if (!response.ok) { - const errorText = await response.text() - return { - success: false, - error: errorText || 'Failed to download file', - output: {}, - } - } - - const apiResultHeader = - response.headers.get('dropbox-api-result') || response.headers.get('Dropbox-API-Result') - const metadata = apiResultHeader ? JSON.parse(apiResultHeader) : undefined - const contentType = response.headers.get('content-type') || 'application/octet-stream' - const arrayBuffer = await response.arrayBuffer() - const buffer = Buffer.from(arrayBuffer) - const resolvedName = metadata?.name || params?.path?.split('/').pop() || 'download' - - let temporaryLink: string | undefined - if (params?.accessToken) { - try { - const linkResponse = await fetch('https://api.dropboxapi.com/2/files/get_temporary_link', { - method: 'POST', - headers: { - Authorization: `Bearer ${params.accessToken}`, - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ path: params.path.trim() }), - }) - if (linkResponse.ok) { - const linkData = await linkResponse.json() - temporaryLink = linkData.link - } - } catch { - temporaryLink = undefined - } - } - + const result = await transformDownloadResponse(response, params) + if (!result.success || !result.output.file) return result + const file = result.output.file + const content = file.data.toString('base64') return { - success: true, + ...result, output: { - file: { - name: resolvedName, - mimeType: contentType, - data: buffer.toString('base64'), - size: buffer.length, - }, - content: buffer.toString('base64'), - metadata, - temporaryLink, + ...result.output, + file: { ...file, data: content }, + content, }, } }, @@ -109,4 +128,17 @@ export const dropboxDownloadTool: ToolConfig + +export const dropboxDownloadV2Tool: ToolConfig< + DropboxDownloadParams, + DropboxDownloadV2Response +> = { + ...dropboxDownloadTool, + id: 'dropbox_download_v2', + description: 'Download a file from Dropbox with metadata', + version: '2.0.0', + request: { ...dropboxDownloadTool.request, responseType: 'binary' }, + transformResponse: transformDownloadResponse, + outputs: omit(dropboxDownloadTool.outputs, ['content']), } diff --git a/apps/sim/tools/dropbox/index.ts b/apps/sim/tools/dropbox/index.ts index c113cc121af..6e9dc450113 100644 --- a/apps/sim/tools/dropbox/index.ts +++ b/apps/sim/tools/dropbox/index.ts @@ -2,7 +2,7 @@ import { dropboxCopyTool } from '@/tools/dropbox/copy' import { dropboxCreateFolderTool } from '@/tools/dropbox/create_folder' import { dropboxCreateSharedLinkTool } from '@/tools/dropbox/create_shared_link' import { dropboxDeleteTool } from '@/tools/dropbox/delete' -import { dropboxDownloadTool } from '@/tools/dropbox/download' +import { dropboxDownloadTool, dropboxDownloadV2Tool } from '@/tools/dropbox/download' import { dropboxGetMetadataTool } from '@/tools/dropbox/get_metadata' import { dropboxListFolderTool } from '@/tools/dropbox/list_folder' import { dropboxListRevisionsTool } from '@/tools/dropbox/list_revisions' @@ -18,6 +18,7 @@ export { dropboxCreateSharedLinkTool, dropboxDeleteTool, dropboxDownloadTool, + dropboxDownloadV2Tool, dropboxGetMetadataTool, dropboxListFolderTool, dropboxListRevisionsTool, diff --git a/apps/sim/tools/dropbox/types.ts b/apps/sim/tools/dropbox/types.ts index bfb5cf1c8ae..05c9594b9a4 100644 --- a/apps/sim/tools/dropbox/types.ts +++ b/apps/sim/tools/dropbox/types.ts @@ -1,4 +1,5 @@ import type { UserFileLike } from '@/lib/core/utils/user-file' +import type { UserFile } from '@/executor/types' import type { ToolFileData, ToolResponse } from '@/tools/types' interface DropboxFileMetadata { @@ -93,6 +94,12 @@ export interface DropboxDownloadResponse extends ToolResponse { } } +export interface DropboxDownloadV2Response extends ToolResponse { + output: Omit & { + file?: File + } +} + export interface DropboxListFolderParams extends DropboxBaseParams { path: string recursive?: boolean diff --git a/apps/sim/tools/dub/get_qr_code.ts b/apps/sim/tools/dub/get_qr_code.ts index 443ca643e38..24bf57d60a1 100644 --- a/apps/sim/tools/dub/get_qr_code.ts +++ b/apps/sim/tools/dub/get_qr_code.ts @@ -1,7 +1,42 @@ -import type { DubGetQrCodeParams, DubGetQrCodeResponse } from '@/tools/dub/types' -import type { ToolConfig } from '@/tools/types' +import { omit } from '@sim/utils/object' +import type { + DubGetQrCodeParams, + DubGetQrCodeResponse, + DubGetQrCodeV2Response, +} from '@/tools/dub/types' +import type { ToolConfig, ToolFileData } from '@/tools/types' -export const getQrCodeTool: ToolConfig = { +async function transformDownloadResponse(response: Response) { + if (!response.ok) { + const errorText = await response.text() + let message = errorText || `Failed to generate QR code: ${response.status}` + try { + const parsed = JSON.parse(errorText) + message = parsed.error?.message || parsed.error || message + } catch { + /** Non-JSON error body; use the raw text. */ + } + throw new Error(message) + } + + const arrayBuffer = await response.arrayBuffer() + const buffer = Buffer.from(arrayBuffer) + const mimeType = response.headers.get('content-type') || 'image/png' + + return { + success: true, + output: { + file: { + name: 'qrcode.png', + mimeType, + data: buffer, + size: buffer.length, + }, + }, + } +} + +export const getQrCodeTool = { id: 'dub_get_qr_code', name: 'Dub Get QR Code', description: @@ -85,33 +120,16 @@ export const getQrCodeTool: ToolConfig }), }, - transformResponse: async (response: Response) => { - if (!response.ok) { - const errorText = await response.text() - let message = errorText || `Failed to generate QR code: ${response.status}` - try { - const parsed = JSON.parse(errorText) - message = parsed.error?.message || parsed.error || message - } catch { - // Non-JSON error body; use the raw text - } - throw new Error(message) - } - - const arrayBuffer = await response.arrayBuffer() - const buffer = Buffer.from(arrayBuffer) - const mimeType = response.headers.get('content-type') || 'image/png' - + transformResponse: async (response) => { + const result = await transformDownloadResponse(response) + const file = result.output.file + const content = file.data.toString('base64') return { - success: true, + ...result, output: { - file: { - name: 'qrcode.png', - mimeType, - data: buffer.toString('base64'), - size: buffer.length, - }, - content: buffer.toString('base64'), + ...result.output, + file: { ...file, data: content }, + content, }, } }, @@ -126,4 +144,16 @@ export const getQrCodeTool: ToolConfig description: 'Base64-encoded PNG image data', }, }, +} satisfies ToolConfig + +export const getQrCodeV2Tool: ToolConfig< + DubGetQrCodeParams, + DubGetQrCodeV2Response +> = { + ...getQrCodeTool, + id: 'dub_get_qr_code_v2', + version: '2.0.0', + request: { ...getQrCodeTool.request, responseType: 'binary' }, + transformResponse: transformDownloadResponse, + outputs: omit(getQrCodeTool.outputs, ['content']), } diff --git a/apps/sim/tools/dub/index.ts b/apps/sim/tools/dub/index.ts index 09030412b92..7b7b957873f 100644 --- a/apps/sim/tools/dub/index.ts +++ b/apps/sim/tools/dub/index.ts @@ -8,7 +8,7 @@ import { getAnalyticsTool } from '@/tools/dub/get_analytics' import { getEventsTool } from '@/tools/dub/get_events' import { getLinkTool } from '@/tools/dub/get_link' import { getLinksCountTool } from '@/tools/dub/get_links_count' -import { getQrCodeTool } from '@/tools/dub/get_qr_code' +import { getQrCodeTool, getQrCodeV2Tool } from '@/tools/dub/get_qr_code' import { listDomainsTool } from '@/tools/dub/list_domains' import { listFoldersTool } from '@/tools/dub/list_folders' import { listLinksTool } from '@/tools/dub/list_links' @@ -29,6 +29,7 @@ export const dubBulkCreateLinksTool = bulkCreateLinksTool export const dubBulkUpdateLinksTool = bulkUpdateLinksTool export const dubBulkDeleteLinksTool = bulkDeleteLinksTool export const dubGetQrCodeTool = getQrCodeTool +export const dubGetQrCodeV2Tool = getQrCodeV2Tool export const dubListDomainsTool = listDomainsTool export const dubListTagsTool = listTagsTool export const dubCreateTagTool = createTagTool diff --git a/apps/sim/tools/dub/types.ts b/apps/sim/tools/dub/types.ts index 6270a26f3f8..9fea3443f39 100644 --- a/apps/sim/tools/dub/types.ts +++ b/apps/sim/tools/dub/types.ts @@ -1,3 +1,4 @@ +import type { UserFile } from '@/executor/types' import type { ToolResponse } from '@/tools/types' interface DubBaseParams { @@ -303,6 +304,12 @@ export interface DubGetQrCodeResponse extends ToolResponse { } } +export interface DubGetQrCodeV2Response extends ToolResponse { + output: Omit & { + file: File + } +} + export interface DubListDomainsResponse extends ToolResponse { output: { domains: Record[] diff --git a/apps/sim/tools/file-message-operation-security.test.ts b/apps/sim/tools/file-message-operation-security.test.ts index 7015ce8ce55..5dfd134da78 100644 --- a/apps/sim/tools/file-message-operation-security.test.ts +++ b/apps/sim/tools/file-message-operation-security.test.ts @@ -1,7 +1,7 @@ /** * @vitest-environment node */ -import { beforeEach, describe, expect, it, vi } from 'vitest' +import { assert, beforeEach, describe, expect, it, vi } from 'vitest' const mocks = vi.hoisted(() => ({ assertToolFileAccess: vi.fn(), @@ -68,6 +68,7 @@ import { executeDataverseUploadFile } from '@/lib/internal/microsoft-dataverse/o import { executePipedriveGetFiles } from '@/lib/internal/pipedrive/operations' import type { ServiceNowOperationError } from '@/lib/internal/servicenow/errors' import { executeServiceNowUploadAttachment } from '@/lib/internal/servicenow/operations' +import { isInternalToolFileResult } from '@/lib/internal/tool-operations/file-result' import { MAX_BUFFERED_TRANSFER_BYTES } from '@/lib/uploads/shared/types' const FILE = { @@ -248,6 +249,25 @@ describe('file and message operation security', () => { MAX_BUFFERED_TRANSFER_BYTES, MAX_BUFFERED_TRANSFER_BYTES - 3, ]) - expect(result.output.downloadedFiles).toHaveLength(2) + assert(isInternalToolFileResult(result)) + expect(result.files).toEqual([ + { name: 'one.txt', mimeType: 'text/plain', buffer: Buffer.from('abc') }, + { name: 'two.txt', mimeType: 'text/plain', buffer: Buffer.from('defg') }, + ]) + const storedFiles = [ + { ...FILE, name: 'one.txt', mimeType: 'text/plain' }, + { + ...FILE, + id: 'file-2', + key: 'execution/file-2', + name: 'two.txt', + size: 4, + mimeType: 'text/plain', + }, + ] + expect(result.present(storedFiles)).toMatchObject({ + success: true, + output: { downloadedFiles: storedFiles, has_more: true, next_start: 2 }, + }) }) }) diff --git a/apps/sim/tools/generated/tool-ids.ts b/apps/sim/tools/generated/tool-ids.ts index ca9a23f2d24..67aa132eb1a 100644 --- a/apps/sim/tools/generated/tool-ids.ts +++ b/apps/sim/tools/generated/tool-ids.ts @@ -3,7 +3,7 @@ /** Every registered tool id, including versioned variants. */ const toolIds: string[] = JSON.parse( - '["a2a_cancel_task","a2a_get_agent_card","a2a_get_task","a2a_send_message","affinity_batch_update_entity_fields","affinity_batch_update_list_entry_fields","affinity_create_list","affinity_create_list_field_dropdown_option","affinity_create_merge","affinity_create_note","affinity_create_reminder","affinity_delete_list_field_dropdown_option","affinity_delete_note","affinity_get_company","affinity_get_current_user","affinity_get_entity_field_value","affinity_get_list","affinity_get_list_entry","affinity_get_list_entry_field","affinity_get_list_field_dropdown_option","affinity_get_merge","affinity_get_merge_task","affinity_get_note","affinity_get_opportunity","affinity_get_person","affinity_get_saved_view","affinity_get_transcript","affinity_get_user","affinity_list_calls","affinity_list_chat_messages","affinity_list_companies","affinity_list_coworker_connections","affinity_list_emails","affinity_list_entity_field_values","affinity_list_entity_list_entries","affinity_list_entity_lists","affinity_list_entity_notes","affinity_list_entity_relationships","affinity_list_field_dropdown_options","affinity_list_field_metadata","affinity_list_field_value_changes","affinity_list_investor_executive_connections","affinity_list_list_entries","affinity_list_list_entry_field_value_changes","affinity_list_list_entry_fields","affinity_list_list_field_dropdown_options","affinity_list_list_fields","affinity_list_lists","affinity_list_meetings","affinity_list_merge_tasks","affinity_list_merges","affinity_list_note_attached_companies","affinity_list_note_attached_opportunities","affinity_list_note_attached_persons","affinity_list_note_replies","affinity_list_notes","affinity_list_opportunities","affinity_list_persons","affinity_list_reminders","affinity_list_saved_view_entries","affinity_list_saved_views","affinity_list_transcript_fragments","affinity_list_transcripts","affinity_list_users","affinity_search_companies","affinity_search_files","affinity_search_list_entries","affinity_search_notes","affinity_search_persons","affinity_semantic_search","affinity_update_entity_field_value","affinity_update_list_entry_field","affinity_update_list_field_dropdown_option","affinity_update_note","agentmail_create_draft","agentmail_create_inbox","agentmail_delete_draft","agentmail_delete_inbox","agentmail_delete_thread","agentmail_forward_message","agentmail_get_draft","agentmail_get_inbox","agentmail_get_message","agentmail_get_thread","agentmail_list_drafts","agentmail_list_inboxes","agentmail_list_messages","agentmail_list_threads","agentmail_reply_message","agentmail_send_draft","agentmail_send_message","agentmail_update_draft","agentmail_update_inbox","agentmail_update_message","agentmail_update_thread","agentphone_create_call","agentphone_create_contact","agentphone_create_number","agentphone_delete_contact","agentphone_get_call","agentphone_get_call_transcript","agentphone_get_contact","agentphone_get_conversation","agentphone_get_conversation_messages","agentphone_get_number_messages","agentphone_get_usage","agentphone_get_usage_daily","agentphone_get_usage_monthly","agentphone_list_calls","agentphone_list_contacts","agentphone_list_conversations","agentphone_list_numbers","agentphone_react_to_message","agentphone_release_number","agentphone_send_message","agentphone_update_contact","agentphone_update_conversation","agiloft_async_status","agiloft_attach_file","agiloft_attachment_info","agiloft_create_record","agiloft_delete_record","agiloft_get_choice_line_id","agiloft_list_tables","agiloft_lock_record","agiloft_nlp_search","agiloft_read_record","agiloft_remove_attachment","agiloft_retrieve_attachment","agiloft_run_action_button","agiloft_saved_search","agiloft_search_records","agiloft_select_records","agiloft_update_record","agiloft_upsert_record","ahrefs_anchors","ahrefs_backlinks","ahrefs_backlinks_stats","ahrefs_batch_analysis","ahrefs_broken_backlinks","ahrefs_domain_rating","ahrefs_domain_rating_history","ahrefs_keyword_overview","ahrefs_keywords_history","ahrefs_metrics","ahrefs_metrics_history","ahrefs_organic_competitors","ahrefs_organic_keywords","ahrefs_paid_pages","ahrefs_rank_tracker_competitors_overview","ahrefs_rank_tracker_competitors_stats","ahrefs_rank_tracker_overview","ahrefs_rank_tracker_serp_overview","ahrefs_refdomains_history","ahrefs_referring_domains","ahrefs_related_terms","ahrefs_site_audit_page_explorer","ahrefs_top_pages","airtable_create_records","airtable_delete_records","airtable_get_base_schema","airtable_get_record","airtable_list_bases","airtable_list_records","airtable_list_tables","airtable_update_multiple_records","airtable_update_record","airtable_upsert_records","airweave_search","algolia_add_record","algolia_batch_operations","algolia_browse_records","algolia_clear_records","algolia_copy_move_index","algolia_delete_by_filter","algolia_delete_index","algolia_delete_record","algolia_get_record","algolia_get_records","algolia_get_settings","algolia_get_task_status","algolia_list_indices","algolia_partial_update_record","algolia_search","algolia_update_settings","amplitude_event_segmentation","amplitude_funnels","amplitude_get_active_users","amplitude_get_revenue","amplitude_group_identify","amplitude_identify_user","amplitude_list_events","amplitude_realtime_active_users","amplitude_retention","amplitude_send_event","amplitude_user_activity","amplitude_user_profile","amplitude_user_search","apify_get_dataset_items","apify_get_run","apify_run_actor_async","apify_run_actor_sync","apify_run_task","apollo_account_bulk_create","apollo_account_bulk_update","apollo_account_create","apollo_account_search","apollo_account_update","apollo_contact_bulk_create","apollo_contact_bulk_update","apollo_contact_create","apollo_contact_search","apollo_contact_update","apollo_email_accounts","apollo_opportunity_create","apollo_opportunity_get","apollo_opportunity_search","apollo_opportunity_update","apollo_organization_bulk_enrich","apollo_organization_enrich","apollo_organization_search","apollo_people_bulk_enrich","apollo_people_enrich","apollo_people_search","apollo_sequence_add_contacts","apollo_sequence_search","apollo_task_create","apollo_task_search","appconfig_create_application","appconfig_create_configuration_profile","appconfig_create_environment","appconfig_create_hosted_configuration_version","appconfig_delete_application","appconfig_delete_configuration_profile","appconfig_delete_environment","appconfig_delete_hosted_configuration_version","appconfig_get_application","appconfig_get_configuration","appconfig_get_configuration_profile","appconfig_get_deployment","appconfig_get_environment","appconfig_get_hosted_configuration_version","appconfig_list_applications","appconfig_list_configuration_profiles","appconfig_list_deployment_strategies","appconfig_list_deployments","appconfig_list_environments","appconfig_list_hosted_configuration_versions","appconfig_start_deployment","appconfig_stop_deployment","appconfig_update_application","appconfig_update_configuration_profile","appconfig_update_environment","arxiv_get_author_papers","arxiv_get_paper","arxiv_search","asana_add_comment","asana_add_followers","asana_create_project","asana_create_section","asana_create_subtask","asana_create_task","asana_delete_task","asana_get_project","asana_get_projects","asana_get_task","asana_list_sections","asana_list_workspaces","asana_search_tasks","asana_update_task","ashby_add_candidate_tag","ashby_anonymize_candidate","ashby_change_application_source","ashby_change_application_stage","ashby_create_application","ashby_create_candidate","ashby_create_note","ashby_delete_application","ashby_get_application","ashby_get_candidate","ashby_get_job","ashby_get_job_posting","ashby_get_offer","ashby_get_opening","ashby_list_application_feedback","ashby_list_application_history","ashby_list_applications","ashby_list_archive_reasons","ashby_list_candidate_tags","ashby_list_candidates","ashby_list_custom_fields","ashby_list_departments","ashby_list_interview_plans","ashby_list_interview_stages","ashby_list_interviews","ashby_list_job_postings","ashby_list_jobs","ashby_list_locations","ashby_list_notes","ashby_list_offers","ashby_list_openings","ashby_list_sources","ashby_list_users","ashby_remove_candidate_tag","ashby_search_candidates","ashby_search_jobs","ashby_search_openings","ashby_search_users","ashby_set_custom_field_value","ashby_set_custom_field_values","ashby_transfer_application","ashby_update_candidate","ashby_upload_candidate_file","ashby_upload_resume","athena_batch_get_named_query","athena_batch_get_prepared_statement","athena_batch_get_query_execution","athena_create_named_query","athena_create_prepared_statement","athena_delete_named_query","athena_delete_prepared_statement","athena_get_data_catalog","athena_get_database","athena_get_named_query","athena_get_prepared_statement","athena_get_query_execution","athena_get_query_results","athena_get_query_runtime_statistics","athena_get_table_metadata","athena_get_work_group","athena_list_data_catalogs","athena_list_databases","athena_list_named_queries","athena_list_prepared_statements","athena_list_query_executions","athena_list_table_metadata","athena_list_work_groups","athena_start_query","athena_stop_query","athena_update_named_query","athena_update_prepared_statement","attio_assert_record","attio_create_attribute","attio_create_comment","attio_create_list","attio_create_list_entry","attio_create_note","attio_create_object","attio_create_record","attio_create_task","attio_create_webhook","attio_delete_comment","attio_delete_list_entry","attio_delete_note","attio_delete_record","attio_delete_task","attio_delete_webhook","attio_get_attribute","attio_get_comment","attio_get_list","attio_get_list_entry","attio_get_member","attio_get_note","attio_get_object","attio_get_record","attio_get_task","attio_get_thread","attio_get_webhook","attio_list_attributes","attio_list_lists","attio_list_members","attio_list_notes","attio_list_objects","attio_list_records","attio_list_tasks","attio_list_threads","attio_list_webhooks","attio_query_list_entries","attio_search_records","attio_update_attribute","attio_update_list","attio_update_list_entry","attio_update_object","attio_update_record","attio_update_task","attio_update_webhook","azure_data_explorer_create_table","azure_data_explorer_drop_table","azure_data_explorer_ingest_from_query","azure_data_explorer_ingest_inline","azure_data_explorer_list_databases","azure_data_explorer_list_functions","azure_data_explorer_list_tables","azure_data_explorer_management","azure_data_explorer_query","azure_data_explorer_show_database_schema","azure_data_explorer_show_ingestion_failures","azure_data_explorer_show_operations","azure_data_explorer_show_table_details","azure_data_explorer_show_table_schema","azure_devops_add_comment","azure_devops_create_work_item","azure_devops_get_build_log","azure_devops_get_build_timeline","azure_devops_get_comments","azure_devops_get_pipeline","azure_devops_get_pipeline_run","azure_devops_get_work_item","azure_devops_get_work_items_batch","azure_devops_get_work_items_between_builds","azure_devops_list_build_logs","azure_devops_list_builds","azure_devops_list_pipeline_runs","azure_devops_list_pipelines","azure_devops_query_work_items","azure_devops_update_work_item","bitbucket_approve_pull_request","bitbucket_create_branch","bitbucket_create_pull_request","bitbucket_create_pull_request_comment","bitbucket_decline_pull_request","bitbucket_delete_branch","bitbucket_get_commit","bitbucket_get_file","bitbucket_get_file_metadata","bitbucket_get_pipeline","bitbucket_get_pipeline_step_log","bitbucket_get_pull_request","bitbucket_get_pull_request_diff","bitbucket_get_pull_request_diffstat","bitbucket_get_pull_request_merge_task_status","bitbucket_get_repository","bitbucket_list_branches","bitbucket_list_commits","bitbucket_list_directory","bitbucket_list_pipeline_steps","bitbucket_list_pipelines","bitbucket_list_pull_request_comments","bitbucket_list_pull_request_commit_statuses","bitbucket_list_pull_requests","bitbucket_list_repositories","bitbucket_list_workspaces","bitbucket_merge_pull_request","bitbucket_request_pull_request_changes","bitbucket_stop_pipeline","bitbucket_trigger_pipeline","box_copy_file","box_create_folder","box_delete_file","box_delete_folder","box_download_file","box_get_file_info","box_list_folder_items","box_search","box_sign_cancel_request","box_sign_create_request","box_sign_get_request","box_sign_list_requests","box_sign_resend_request","box_update_file","box_upload_file","brandfetch_get_brand","brandfetch_search","brex_archive_budget","brex_create_budget","brex_create_spend_limit","brex_create_transfer","brex_create_vendor","brex_get_budget","brex_get_cash_account","brex_get_company","brex_get_current_user","brex_get_expense","brex_get_spend_limit","brex_get_transfer","brex_get_user","brex_get_vendor","brex_list_budgets","brex_list_card_accounts","brex_list_card_statements","brex_list_card_transactions","brex_list_cards","brex_list_cash_accounts","brex_list_cash_statements","brex_list_cash_transactions","brex_list_departments","brex_list_expenses","brex_list_locations","brex_list_spend_limits","brex_list_titles","brex_list_transfers","brex_list_users","brex_list_vendors","brex_match_receipt","brex_update_expense","brex_update_vendor","brex_upload_receipt","brightdata_cancel_snapshot","brightdata_discover","brightdata_download_snapshot","brightdata_scrape_dataset","brightdata_scrape_url","brightdata_serp_search","brightdata_snapshot_status","brightdata_sync_scrape","browser_use_run_task","buffer_create_idea","buffer_create_post","buffer_delete_post","buffer_edit_post","buffer_get_account","buffer_get_channels","buffer_get_idea_groups","buffer_get_ideas","buffer_get_post","buffer_get_posts","calcom_cancel_booking","calcom_confirm_booking","calcom_create_booking","calcom_create_event_type","calcom_create_schedule","calcom_decline_booking","calcom_delete_event_type","calcom_delete_schedule","calcom_get_booking","calcom_get_default_schedule","calcom_get_event_type","calcom_get_schedule","calcom_get_slots","calcom_list_bookings","calcom_list_event_types","calcom_list_schedules","calcom_reschedule_booking","calcom_update_event_type","calcom_update_schedule","calendly_cancel_event","calendly_create_event_invitee","calendly_create_invitee_no_show","calendly_create_scheduling_link","calendly_create_webhook","calendly_delete_invitee_no_show","calendly_delete_webhook","calendly_get_current_user","calendly_get_event_invitee","calendly_get_event_type","calendly_get_scheduled_event","calendly_get_user","calendly_list_event_invitees","calendly_list_event_type_available_times","calendly_list_event_types","calendly_list_organization_memberships","calendly_list_routing_form_submissions","calendly_list_routing_forms","calendly_list_scheduled_events","calendly_list_user_availability_schedules","calendly_list_user_busy_times","calendly_list_webhooks","cbinsights_chat","cbinsights_get_commercial_maturity_history","cbinsights_get_exit_probability_history","cbinsights_get_mosaic_history","cbinsights_get_org_business_relationships","cbinsights_get_org_funding_window","cbinsights_get_org_fundings","cbinsights_get_org_investments","cbinsights_get_org_management_and_board","cbinsights_get_org_outlook","cbinsights_get_org_portfolio_exits","cbinsights_get_org_revenue","cbinsights_get_scouting_report","cbinsights_get_strategy_map","cbinsights_list_business_relationships","cbinsights_list_funding_window","cbinsights_list_fundings","cbinsights_list_investments","cbinsights_list_management_and_board","cbinsights_list_outlook","cbinsights_list_portfolio_exits","cbinsights_list_revenue","cbinsights_lookup_organizations","cbinsights_rag","cbinsights_search_firmographics","circleback_add_tag_to_meetings","circleback_create_tag","circleback_delete_action_item","circleback_delete_meeting","circleback_delete_tag","circleback_get_company","circleback_get_meeting","circleback_get_person","circleback_get_transcript","circleback_list_action_items","circleback_list_calendar_events","circleback_list_companies","circleback_list_meetings","circleback_list_people","circleback_list_tags","circleback_remove_tag_from_meetings","circleback_search_meetings","circleback_update_action_item","circleback_update_meeting","circleback_update_tag","clay_populate","clerk_add_organization_member","clerk_ban_user","clerk_create_actor_token","clerk_create_allowlist_identifier","clerk_create_blocklist_identifier","clerk_create_organization","clerk_create_organization_invitation","clerk_create_user","clerk_delete_allowlist_identifier","clerk_delete_blocklist_identifier","clerk_delete_organization","clerk_delete_user","clerk_get_jwt_template","clerk_get_organization","clerk_get_session","clerk_get_user","clerk_get_user_oauth_token","clerk_list_allowlist_identifiers","clerk_list_blocklist_identifiers","clerk_list_jwt_templates","clerk_list_organization_invitations","clerk_list_organization_memberships","clerk_list_organizations","clerk_list_sessions","clerk_list_users","clerk_lock_user","clerk_remove_organization_member","clerk_revoke_actor_token","clerk_revoke_session","clerk_unban_user","clerk_unlock_user","clerk_update_organization","clerk_update_organization_membership","clerk_update_user","clickhouse_count_rows","clickhouse_create_database","clickhouse_create_table","clickhouse_delete","clickhouse_describe_table","clickhouse_drop_database","clickhouse_drop_partition","clickhouse_drop_table","clickhouse_execute","clickhouse_insert","clickhouse_insert_rows","clickhouse_introspect","clickhouse_kill_query","clickhouse_list_clusters","clickhouse_list_databases","clickhouse_list_mutations","clickhouse_list_partitions","clickhouse_list_running_queries","clickhouse_list_tables","clickhouse_optimize_table","clickhouse_query","clickhouse_rename_table","clickhouse_show_create_table","clickhouse_table_stats","clickhouse_truncate_table","clickhouse_update","clickup_add_tag_to_task","clickup_create_checklist","clickup_create_checklist_item","clickup_create_comment","clickup_create_folder","clickup_create_list","clickup_create_task","clickup_create_time_entry","clickup_delete_checklist","clickup_delete_checklist_item","clickup_delete_comment","clickup_delete_task","clickup_delete_time_entry","clickup_get_comments","clickup_get_custom_fields","clickup_get_folders","clickup_get_list_members","clickup_get_lists","clickup_get_running_timer","clickup_get_space_tags","clickup_get_spaces","clickup_get_task","clickup_get_task_members","clickup_get_tasks","clickup_get_time_entries","clickup_get_workspaces","clickup_remove_custom_field_value","clickup_remove_tag_from_task","clickup_search_tasks","clickup_set_custom_field_value","clickup_start_timer","clickup_stop_timer","clickup_update_checklist","clickup_update_checklist_item","clickup_update_comment","clickup_update_task","clickup_update_time_entry","clickup_upload_attachment","cloudflare_create_access_application","cloudflare_create_access_policy","cloudflare_create_access_service_token","cloudflare_create_dns_record","cloudflare_create_r2_bucket","cloudflare_create_rate_limit_rule","cloudflare_create_ruleset","cloudflare_create_ruleset_rule","cloudflare_create_zone","cloudflare_delete_access_application","cloudflare_delete_access_policy","cloudflare_delete_dns_record","cloudflare_delete_r2_bucket","cloudflare_delete_ruleset_rule","cloudflare_delete_zone","cloudflare_dns_analytics","cloudflare_get_access_application","cloudflare_get_r2_bucket","cloudflare_get_ruleset","cloudflare_get_ruleset_entrypoint","cloudflare_get_tunnel","cloudflare_get_tunnel_configuration","cloudflare_get_worker_script_settings","cloudflare_get_zone","cloudflare_get_zone_settings","cloudflare_list_access_applications","cloudflare_list_access_groups","cloudflare_list_access_identity_providers","cloudflare_list_access_policies","cloudflare_list_access_service_tokens","cloudflare_list_certificates","cloudflare_list_dns_records","cloudflare_list_managed_ruleset_overrides","cloudflare_list_r2_buckets","cloudflare_list_rate_limit_rules","cloudflare_list_rulesets","cloudflare_list_tunnels","cloudflare_list_worker_routes","cloudflare_list_worker_scripts","cloudflare_list_zones","cloudflare_purge_cache","cloudflare_revoke_access_service_token","cloudflare_update_access_application","cloudflare_update_access_policy","cloudflare_update_dns_record","cloudflare_update_rate_limit_rule","cloudflare_update_ruleset_rule","cloudflare_update_zone_setting","cloudformation_cancel_update_stack","cloudformation_create_change_set","cloudformation_create_stack","cloudformation_delete_stack","cloudformation_describe_change_set","cloudformation_describe_stack_drift_detection_status","cloudformation_describe_stack_events","cloudformation_describe_stacks","cloudformation_detect_stack_drift","cloudformation_execute_change_set","cloudformation_get_template","cloudformation_get_template_summary","cloudformation_list_stack_resources","cloudformation_update_stack","cloudformation_validate_template","cloudtrail_cancel_query","cloudtrail_describe_query","cloudtrail_describe_trails","cloudtrail_get_event_data_store","cloudtrail_get_event_selectors","cloudtrail_get_insight_selectors","cloudtrail_get_query_results","cloudtrail_get_trail","cloudtrail_get_trail_status","cloudtrail_list_event_data_stores","cloudtrail_list_tags","cloudtrail_list_trails","cloudtrail_lookup_events","cloudtrail_start_query","cloudwatch_describe_alarm_history","cloudwatch_describe_alarms","cloudwatch_describe_log_groups","cloudwatch_describe_log_streams","cloudwatch_filter_log_events","cloudwatch_get_log_events","cloudwatch_get_metric_statistics","cloudwatch_list_metrics","cloudwatch_mute_alarm","cloudwatch_put_log_group_retention","cloudwatch_put_metric_data","cloudwatch_query_logs","cloudwatch_unmute_alarm","codepipeline_disable_stage_transition","codepipeline_enable_stage_transition","codepipeline_get_pipeline","codepipeline_get_pipeline_execution","codepipeline_get_pipeline_state","codepipeline_list_action_executions","codepipeline_list_pipeline_executions","codepipeline_list_pipelines","codepipeline_put_approval_result","codepipeline_retry_stage_execution","codepipeline_start_execution","codepipeline_stop_execution","confluence_add_label","confluence_create_blogpost","confluence_create_comment","confluence_create_page","confluence_create_page_property","confluence_create_space","confluence_create_space_property","confluence_delete_attachment","confluence_delete_blogpost","confluence_delete_comment","confluence_delete_label","confluence_delete_page","confluence_delete_page_property","confluence_delete_space","confluence_delete_space_property","confluence_get_blogpost","confluence_get_page_ancestors","confluence_get_page_children","confluence_get_page_descendants","confluence_get_page_version","confluence_get_pages_by_label","confluence_get_space","confluence_get_task","confluence_get_user","confluence_list_attachments","confluence_list_blogposts","confluence_list_blogposts_in_space","confluence_list_comments","confluence_list_labels","confluence_list_page_properties","confluence_list_page_versions","confluence_list_pages_in_space","confluence_list_space_labels","confluence_list_space_permissions","confluence_list_space_properties","confluence_list_spaces","confluence_list_tasks","confluence_retrieve","confluence_search","confluence_search_in_space","confluence_update","confluence_update_blogpost","confluence_update_comment","confluence_update_space","confluence_update_task","confluence_upload_attachment","context_dev_classify_naics","context_dev_classify_sic","context_dev_crawl","context_dev_extract","context_dev_extract_product","context_dev_extract_products","context_dev_get_brand","context_dev_get_brand_by_email","context_dev_get_brand_by_name","context_dev_get_brand_by_ticker","context_dev_identify_transaction","context_dev_map","context_dev_scrape_fonts","context_dev_scrape_html","context_dev_scrape_images","context_dev_scrape_markdown","context_dev_scrape_styleguide","context_dev_screenshot","context_dev_search","convex_action","convex_document_deltas","convex_list_documents","convex_list_tables","convex_mutation","convex_query","convex_run_function","crowdstrike_create_indicators","crowdstrike_delete_indicators","crowdstrike_delete_rtr_session","crowdstrike_execute_rtr_command","crowdstrike_get_alert_details","crowdstrike_get_case_details","crowdstrike_get_host_group_details","crowdstrike_get_indicator_details","crowdstrike_get_rtr_command_status","crowdstrike_get_sensor_aggregates","crowdstrike_get_sensor_details","crowdstrike_get_vulnerability_details","crowdstrike_init_rtr_session","crowdstrike_perform_host_action","crowdstrike_perform_host_group_action","crowdstrike_query_alerts","crowdstrike_query_cases","crowdstrike_query_host_groups","crowdstrike_query_indicators","crowdstrike_query_sensors","crowdstrike_query_vulnerabilities","crowdstrike_update_alerts","crowdstrike_update_indicators","crunchbase_autocomplete","crunchbase_get_acquisition","crunchbase_get_entity","crunchbase_get_entity_card","crunchbase_get_fields_metadata","crunchbase_get_funding_round","crunchbase_get_organization","crunchbase_get_person","crunchbase_list_deleted_entities","crunchbase_search_acquisitions","crunchbase_search_entities","crunchbase_search_funding_rounds","crunchbase_search_organizations","crunchbase_search_people","cursor_add_followup","cursor_add_followup_v2","cursor_delete_agent","cursor_delete_agent_v2","cursor_download_artifact","cursor_download_artifact_v2","cursor_get_agent","cursor_get_agent_v2","cursor_get_api_key_info","cursor_get_api_key_info_v2","cursor_get_conversation","cursor_get_conversation_v2","cursor_launch_agent","cursor_launch_agent_v2","cursor_list_agents","cursor_list_agents_v2","cursor_list_artifacts","cursor_list_artifacts_v2","cursor_list_models","cursor_list_models_v2","cursor_list_repositories","cursor_list_repositories_v2","cursor_stop_agent","cursor_stop_agent_v2","dagster_delete_run","dagster_get_asset","dagster_get_run","dagster_get_run_logs","dagster_launch_run","dagster_list_assets","dagster_list_jobs","dagster_list_runs","dagster_list_schedules","dagster_list_sensors","dagster_materialize_assets","dagster_reexecute_run","dagster_report_asset_materialization","dagster_start_schedule","dagster_start_sensor","dagster_stop_schedule","dagster_stop_sensor","dagster_terminate_run","dagster_wipe_asset","databricks_cancel_run","databricks_execute_sql","databricks_get_cluster","databricks_get_job","databricks_get_run","databricks_get_run_output","databricks_get_statement","databricks_list_clusters","databricks_list_jobs","databricks_list_runs","databricks_list_warehouses","databricks_run_job","datadog_add_incident_todo","datadog_cancel_downtime","datadog_create_dashboard","datadog_create_downtime","datadog_create_event","datadog_create_incident","datadog_create_monitor","datadog_create_slo","datadog_delete_dashboard","datadog_delete_slo","datadog_get_browser_synthetics_results","datadog_get_dashboard","datadog_get_incident","datadog_get_monitor","datadog_get_security_signal","datadog_get_slo","datadog_get_slo_history","datadog_get_synthetics_results","datadog_get_synthetics_test","datadog_list_dashboards","datadog_list_downtimes","datadog_list_incidents","datadog_list_monitors","datadog_list_security_rules","datadog_list_security_signals","datadog_list_services","datadog_list_slos","datadog_list_synthetics_tests","datadog_mute_monitor","datadog_query_logs","datadog_query_timeseries","datadog_search_spans","datadog_send_logs","datadog_submit_metrics","datadog_trigger_synthetics_tests","datadog_unmute_monitor","datadog_update_incident","datadog_update_security_signal_assignee","datadog_update_security_signal_state","datadog_update_slo","datadog_update_synthetics_status","datagma_enrich_company","datagma_enrich_person","datagma_find_email","datagma_find_phone","datagma_get_credits","daytona_create_sandbox","daytona_delete_sandbox","daytona_download_file","daytona_execute_command","daytona_get_sandbox","daytona_git_clone","daytona_list_files","daytona_list_sandboxes","daytona_run_code","daytona_start_sandbox","daytona_stop_sandbox","daytona_upload_file","deployed_block_executor","deployments_deploy","deployments_get_version","deployments_list_versions","deployments_promote","deployments_undeploy","devin_append_session_tags","devin_archive_session","devin_create_session","devin_get_session","devin_get_session_tags","devin_list_session_attachments","devin_list_session_messages","devin_list_sessions","devin_replace_session_tags","devin_send_message","devin_terminate_session","discord_add_reaction","discord_archive_thread","discord_assign_role","discord_ban_member","discord_bulk_delete_messages","discord_create_channel","discord_create_invite","discord_create_role","discord_create_thread","discord_create_webhook","discord_delete_channel","discord_delete_invite","discord_delete_message","discord_delete_role","discord_delete_webhook","discord_edit_message","discord_execute_webhook","discord_get_channel","discord_get_invite","discord_get_member","discord_get_messages","discord_get_pinned_messages","discord_get_server","discord_get_user","discord_get_webhook","discord_join_thread","discord_kick_member","discord_leave_thread","discord_list_channels","discord_list_roles","discord_pin_message","discord_remove_reaction","discord_remove_role","discord_send_message","discord_unban_member","discord_unpin_message","discord_update_channel","discord_update_member","discord_update_role","docusign_create_from_template","docusign_download_document","docusign_get_envelope","docusign_list_envelopes","docusign_list_recipients","docusign_list_templates","docusign_send_envelope","docusign_void_envelope","downdetector_get_company","downdetector_get_company_attribution","downdetector_get_company_baseline","downdetector_get_company_events","downdetector_get_company_incidents","downdetector_get_company_indicators","downdetector_get_company_last_15","downdetector_get_company_status","downdetector_get_provider","downdetector_get_reports","downdetector_get_site_companies","downdetector_list_categories","downdetector_list_incidents","downdetector_list_sites","downdetector_search_companies","dropbox_copy","dropbox_create_folder","dropbox_create_shared_link","dropbox_delete","dropbox_download","dropbox_get_metadata","dropbox_list_folder","dropbox_list_revisions","dropbox_list_shared_links","dropbox_move","dropbox_restore","dropbox_search","dropbox_upload","dropcontact_enrich_contact","dspy_chain_of_thought","dspy_predict","dspy_react","dub_bulk_create_links","dub_bulk_delete_links","dub_bulk_update_links","dub_create_link","dub_create_tag","dub_delete_link","dub_get_analytics","dub_get_events","dub_get_link","dub_get_links_count","dub_get_qr_code","dub_list_domains","dub_list_folders","dub_list_links","dub_list_tags","dub_update_link","dub_upsert_link","duckduckgo_search","dynamodb_delete","dynamodb_get","dynamodb_introspect","dynamodb_put","dynamodb_query","dynamodb_scan","dynamodb_update","dynatrace_add_problem_comment","dynatrace_add_tags","dynatrace_close_problem","dynatrace_create_settings_object","dynatrace_create_slo","dynatrace_delete_problem_comment","dynatrace_delete_settings_object","dynatrace_delete_slo","dynatrace_delete_tag","dynatrace_execute_synthetic_monitors","dynatrace_get_attack","dynatrace_get_audit_logs","dynatrace_get_entity","dynatrace_get_event","dynatrace_get_metric","dynatrace_get_problem","dynatrace_get_problem_comment","dynatrace_get_security_problem","dynatrace_get_settings_object","dynatrace_get_slo","dynatrace_get_synthetic_batch","dynatrace_ingest_event","dynatrace_ingest_logs","dynatrace_ingest_metrics","dynatrace_list_attacks","dynatrace_list_entities","dynatrace_list_entity_types","dynatrace_list_events","dynatrace_list_metrics","dynatrace_list_problem_comments","dynatrace_list_problems","dynatrace_list_remediation_items","dynatrace_list_security_problems","dynatrace_list_settings_objects","dynatrace_list_settings_schemas","dynatrace_list_slos","dynatrace_list_synthetic_monitors","dynatrace_list_tags","dynatrace_mute_security_problem","dynatrace_mute_security_problems","dynatrace_query_metrics","dynatrace_search_logs","dynatrace_unmute_security_problem","dynatrace_unmute_security_problems","dynatrace_update_problem_comment","dynatrace_update_settings_object","dynatrace_update_slo","elasticsearch_bulk","elasticsearch_cluster_health","elasticsearch_cluster_stats","elasticsearch_count","elasticsearch_create_index","elasticsearch_delete_document","elasticsearch_delete_index","elasticsearch_get_document","elasticsearch_get_index","elasticsearch_index_document","elasticsearch_list_indices","elasticsearch_search","elasticsearch_update_document","elevenlabs_audio_isolation","elevenlabs_edit_voice_settings","elevenlabs_get_user","elevenlabs_get_voice","elevenlabs_get_voice_settings","elevenlabs_list_models","elevenlabs_list_voices","elevenlabs_sound_effects","elevenlabs_speech_to_speech","elevenlabs_tts","emailbison_attach_leads_to_campaign","emailbison_attach_tags_to_leads","emailbison_create_campaign","emailbison_create_lead","emailbison_create_tag","emailbison_get_lead","emailbison_list_campaigns","emailbison_list_leads","emailbison_list_replies","emailbison_list_tags","emailbison_update_campaign","emailbison_update_campaign_status","emailbison_update_lead","embeddings_cohere","embeddings_gemini","embeddings_mistral","embeddings_ollama","embeddings_openai","embeddings_openrouter","enrich_check_credits","enrich_company_funding","enrich_company_lookup","enrich_company_revenue","enrich_disposable_email_check","enrich_email_to_ip","enrich_email_to_person_lite","enrich_email_to_phone","enrich_email_to_profile","enrich_find_email","enrich_get_post_details","enrich_ip_to_company","enrich_linkedin_profile","enrich_linkedin_to_personal_email","enrich_linkedin_to_work_email","enrich_phone_finder","enrich_reverse_hash_lookup","enrich_sales_pointer_people","enrich_search_company","enrich_search_company_activities","enrich_search_company_employees","enrich_search_jobs","enrich_search_logo","enrich_search_people","enrich_search_people_activities","enrich_search_post_comments","enrich_search_post_comments_by_url","enrich_search_post_reactions","enrich_search_post_reactions_by_url","enrich_search_posts","enrich_search_similar_companies","enrich_verify_email","enrichment_run","enrow_find_email","enrow_verify_email","exa_agent","exa_answer","exa_find_similar_links","exa_get_contents","exa_search","extend_parser","extend_parser_v2","fathom_get_summary","fathom_get_transcript","fathom_list_meeting_types","fathom_list_meetings","fathom_list_team_members","fathom_list_teams","file_append","file_compress","file_create_folder","file_decompress","file_delete_folder","file_edit","file_fetch","file_get","file_get_content","file_list","file_manage_sharing","file_move","file_parser","file_parser_v2","file_parser_v3","file_read","file_restore_folder","file_search","file_update_folder","file_write","findymail_find_email_from_linkedin","findymail_find_email_from_name","findymail_find_emails_by_domain","findymail_find_employees","findymail_find_phone","findymail_get_company","findymail_get_credits","findymail_lookup_technologies","findymail_reverse_email_lookup","findymail_search_technologies","findymail_verify_email","firecrawl_agent","firecrawl_batch_scrape","firecrawl_batch_scrape_status","firecrawl_cancel_crawl","firecrawl_crawl","firecrawl_crawl_status","firecrawl_credit_usage","firecrawl_extract","firecrawl_extract_status","firecrawl_map","firecrawl_parse","firecrawl_scrape","firecrawl_search","fireflies_add_to_live_meeting","fireflies_create_bite","fireflies_delete_transcript","fireflies_get_transcript","fireflies_get_user","fireflies_list_bites","fireflies_list_contacts","fireflies_list_transcripts","fireflies_list_users","fireflies_upload_audio","flint_create_task","flint_generate_pages","flint_get_task","function_execute","gamma_check_status","gamma_generate","gamma_generate_from_template","gamma_list_folders","gamma_list_themes","github_add_assignees","github_add_assignees_v2","github_add_labels","github_add_labels_v2","github_cancel_workflow_run","github_cancel_workflow_run_v2","github_check_star","github_check_star_v2","github_close_issue","github_close_issue_v2","github_close_pr","github_close_pr_v2","github_comment","github_comment_v2","github_compare_commits","github_compare_commits_v2","github_create_branch","github_create_branch_v2","github_create_comment_reaction","github_create_comment_reaction_v2","github_create_file","github_create_file_v2","github_create_gist","github_create_gist_v2","github_create_issue","github_create_issue_reaction","github_create_issue_reaction_v2","github_create_issue_v2","github_create_milestone","github_create_milestone_v2","github_create_pr","github_create_pr_review","github_create_pr_review_v2","github_create_pr_v2","github_create_project","github_create_project_v2","github_create_release","github_create_release_v2","github_delete_branch","github_delete_branch_v2","github_delete_comment","github_delete_comment_reaction","github_delete_comment_reaction_v2","github_delete_comment_v2","github_delete_file","github_delete_file_v2","github_delete_gist","github_delete_gist_v2","github_delete_issue_reaction","github_delete_issue_reaction_v2","github_delete_milestone","github_delete_milestone_v2","github_delete_project","github_delete_project_v2","github_delete_release","github_delete_release_v2","github_fork_gist","github_fork_gist_v2","github_fork_repo","github_fork_repo_v2","github_get_branch","github_get_branch_protection","github_get_branch_protection_v2","github_get_branch_v2","github_get_commit","github_get_commit_v2","github_get_file_content","github_get_file_content_v2","github_get_gist","github_get_gist_v2","github_get_issue","github_get_issue_v2","github_get_latest_release","github_get_latest_release_v2","github_get_milestone","github_get_milestone_v2","github_get_pr_files","github_get_pr_files_v2","github_get_project","github_get_project_v2","github_get_readme","github_get_readme_v2","github_get_release","github_get_release_v2","github_get_tree","github_get_tree_v2","github_get_workflow","github_get_workflow_run","github_get_workflow_run_v2","github_get_workflow_v2","github_issue_comment","github_issue_comment_v2","github_job_logs","github_latest_commit","github_latest_commit_v2","github_list_branches","github_list_branches_v2","github_list_commits","github_list_commits_v2","github_list_forks","github_list_forks_v2","github_list_gists","github_list_gists_v2","github_list_issue_comments","github_list_issue_comments_v2","github_list_issues","github_list_issues_v2","github_list_milestones","github_list_milestones_v2","github_list_pr_comments","github_list_pr_comments_v2","github_list_projects","github_list_projects_v2","github_list_prs","github_list_prs_v2","github_list_releases","github_list_releases_v2","github_list_review_threads","github_list_stargazers","github_list_stargazers_v2","github_list_tags","github_list_tags_v2","github_list_workflow_runs","github_list_workflow_runs_v2","github_list_workflows","github_list_workflows_v2","github_merge_pr","github_merge_pr_v2","github_pr","github_pr_v2","github_remove_label","github_remove_label_v2","github_reply_review_thread","github_repo_info","github_repo_info_v2","github_request_reviewers","github_request_reviewers_v2","github_rerun_workflow","github_rerun_workflow_v2","github_resolve_review_thread","github_search_code","github_search_code_v2","github_search_commits","github_search_commits_v2","github_search_issues","github_search_issues_v2","github_search_repos","github_search_repos_v2","github_search_users","github_search_users_v2","github_star_gist","github_star_gist_v2","github_star_repo","github_star_repo_v2","github_status_check_rollup","github_trigger_workflow","github_trigger_workflow_v2","github_unstar_gist","github_unstar_gist_v2","github_unstar_repo","github_unstar_repo_v2","github_update_branch_protection","github_update_branch_protection_v2","github_update_comment","github_update_comment_v2","github_update_file","github_update_file_v2","github_update_gist","github_update_gist_v2","github_update_issue","github_update_issue_v2","github_update_milestone","github_update_milestone_v2","github_update_pr","github_update_pr_v2","github_update_project","github_update_project_v2","github_update_release","github_update_release_v2","gitlab_activate_user","gitlab_add_member","gitlab_add_saml_group_link","gitlab_approve_access_request","gitlab_approve_merge_request","gitlab_approve_user","gitlab_ban_user","gitlab_block_user","gitlab_cancel_pipeline","gitlab_compare_branches","gitlab_create_branch","gitlab_create_file","gitlab_create_issue","gitlab_create_issue_note","gitlab_create_merge_request","gitlab_create_merge_request_note","gitlab_create_pipeline","gitlab_create_release","gitlab_create_user","gitlab_deactivate_user","gitlab_delete_branch","gitlab_delete_issue","gitlab_delete_saml_group_link","gitlab_delete_user","gitlab_delete_user_identity","gitlab_deny_access_request","gitlab_get_file","gitlab_get_group","gitlab_get_issue","gitlab_get_job_log","gitlab_get_merge_request","gitlab_get_merge_request_changes","gitlab_get_pipeline","gitlab_get_project","gitlab_invite_member","gitlab_list_access_requests","gitlab_list_branches","gitlab_list_commits","gitlab_list_groups","gitlab_list_invitations","gitlab_list_issues","gitlab_list_members","gitlab_list_merge_requests","gitlab_list_pipeline_jobs","gitlab_list_pipelines","gitlab_list_projects","gitlab_list_releases","gitlab_list_repository_tree","gitlab_list_saml_group_links","gitlab_list_user_memberships","gitlab_merge_merge_request","gitlab_play_job","gitlab_reject_user","gitlab_remove_member","gitlab_retry_pipeline","gitlab_revoke_invitation","gitlab_search_users","gitlab_unban_user","gitlab_unblock_user","gitlab_update_file","gitlab_update_invitation","gitlab_update_issue","gitlab_update_member","gitlab_update_merge_request","gitlab_update_user","gmail_add_label","gmail_add_label_v2","gmail_archive","gmail_archive_v2","gmail_create_label_v2","gmail_delete","gmail_delete_draft_v2","gmail_delete_label_v2","gmail_delete_v2","gmail_draft","gmail_draft_v2","gmail_edit_draft_v2","gmail_get_draft_v2","gmail_get_thread_v2","gmail_list_drafts_v2","gmail_list_labels_v2","gmail_list_threads_v2","gmail_mark_read","gmail_mark_read_v2","gmail_mark_unread","gmail_mark_unread_v2","gmail_move","gmail_move_v2","gmail_read","gmail_read_v2","gmail_remove_label","gmail_remove_label_v2","gmail_search","gmail_search_v2","gmail_send","gmail_send_v2","gmail_trash_thread_v2","gmail_unarchive","gmail_unarchive_v2","gmail_untrash_thread_v2","gmail_update_label_v2","gong_aggregate_activity","gong_aggregate_by_period","gong_answered_scorecards","gong_ask_anything","gong_assign_flow_prospects","gong_create_call","gong_day_by_day_activity","gong_get_brief","gong_get_call","gong_get_call_transcript","gong_get_coaching","gong_get_extensive_calls","gong_get_folder_content","gong_get_logs","gong_get_prospect_flows","gong_get_user","gong_interaction_stats","gong_list_calls","gong_list_flows","gong_list_library_folders","gong_list_scorecards","gong_list_trackers","gong_list_users","gong_list_workspaces","gong_lookup_email","gong_lookup_phone","gong_purge_email_address","gong_purge_phone_number","gong_unassign_flow_prospects","google_ads_ad_performance","google_ads_campaign_performance","google_ads_list_ad_groups","google_ads_list_campaigns","google_ads_list_customers","google_ads_search","google_appsheet_add_rows","google_appsheet_delete_rows","google_appsheet_edit_rows","google_appsheet_find_rows","google_bigquery_create_dataset","google_bigquery_create_table","google_bigquery_delete_dataset","google_bigquery_delete_table","google_bigquery_get_query_results","google_bigquery_get_table","google_bigquery_insert_rows","google_bigquery_list_datasets","google_bigquery_list_table_data","google_bigquery_list_tables","google_bigquery_query","google_books_volume_details","google_books_volume_search","google_calendar_create","google_calendar_create_calendar","google_calendar_create_calendar_v2","google_calendar_create_v2","google_calendar_delete","google_calendar_delete_calendar","google_calendar_delete_calendar_v2","google_calendar_delete_v2","google_calendar_freebusy","google_calendar_freebusy_v2","google_calendar_get","google_calendar_get_v2","google_calendar_instances","google_calendar_instances_v2","google_calendar_invite","google_calendar_invite_v2","google_calendar_list","google_calendar_list_acl","google_calendar_list_acl_v2","google_calendar_list_calendars","google_calendar_list_calendars_v2","google_calendar_list_v2","google_calendar_move","google_calendar_move_v2","google_calendar_quick_add","google_calendar_quick_add_v2","google_calendar_share_calendar","google_calendar_share_calendar_v2","google_calendar_unshare_calendar","google_calendar_unshare_calendar_v2","google_calendar_update","google_calendar_update_acl","google_calendar_update_acl_v2","google_calendar_update_calendar","google_calendar_update_calendar_v2","google_calendar_update_v2","google_contacts_create","google_contacts_delete","google_contacts_get","google_contacts_list","google_contacts_search","google_contacts_update","google_docs_create","google_docs_create_named_range","google_docs_create_paragraph_bullets","google_docs_delete_content_range","google_docs_delete_named_range","google_docs_delete_paragraph_bullets","google_docs_insert_image","google_docs_insert_page_break","google_docs_insert_table","google_docs_insert_text","google_docs_read","google_docs_replace_text","google_docs_update_paragraph_style","google_docs_update_text_style","google_docs_write","google_drive_copy","google_drive_create_comment","google_drive_create_folder","google_drive_delete","google_drive_delete_comment","google_drive_download","google_drive_export","google_drive_get_about","google_drive_get_content","google_drive_get_file","google_drive_get_revision","google_drive_list","google_drive_list_comments","google_drive_list_permissions","google_drive_list_revisions","google_drive_move","google_drive_search","google_drive_share","google_drive_trash","google_drive_unshare","google_drive_untrash","google_drive_update","google_drive_upload","google_forms_batch_update","google_forms_create_form","google_forms_create_watch","google_forms_delete_watch","google_forms_get_form","google_forms_get_responses","google_forms_list_watches","google_forms_renew_watch","google_forms_set_publish_settings","google_groups_add_alias","google_groups_add_member","google_groups_create_group","google_groups_delete_group","google_groups_get_group","google_groups_get_member","google_groups_get_settings","google_groups_has_member","google_groups_list_aliases","google_groups_list_groups","google_groups_list_members","google_groups_remove_alias","google_groups_remove_member","google_groups_update_group","google_groups_update_member","google_groups_update_settings","google_maps_air_quality","google_maps_directions","google_maps_distance_matrix","google_maps_elevation","google_maps_geocode","google_maps_geolocate","google_maps_place_details","google_maps_places_nearby","google_maps_places_search","google_maps_pollen","google_maps_reverse_geocode","google_maps_snap_to_roads","google_maps_solar","google_maps_speed_limits","google_maps_timezone","google_maps_validate_address","google_meet_create_space","google_meet_end_conference","google_meet_get_conference_record","google_meet_get_space","google_meet_list_conference_records","google_meet_list_participants","google_pagespeed_analyze","google_search","google_sheets_append","google_sheets_append_v2","google_sheets_batch_clear_v2","google_sheets_batch_get_v2","google_sheets_batch_update_v2","google_sheets_clear_v2","google_sheets_copy_sheet_v2","google_sheets_create_spreadsheet_v2","google_sheets_delete_rows_v2","google_sheets_delete_sheet_v2","google_sheets_delete_spreadsheet_v2","google_sheets_get_spreadsheet_v2","google_sheets_read","google_sheets_read_v2","google_sheets_update","google_sheets_update_v2","google_sheets_write","google_sheets_write_v2","google_slides_add_image","google_slides_add_slide","google_slides_batch_update","google_slides_copy_presentation","google_slides_create","google_slides_create_line","google_slides_create_paragraph_bullets","google_slides_create_shape","google_slides_create_sheets_chart","google_slides_create_table","google_slides_create_video","google_slides_delete_object","google_slides_delete_paragraph_bullets","google_slides_delete_table_column","google_slides_delete_table_row","google_slides_delete_text","google_slides_duplicate_object","google_slides_export_presentation","google_slides_get_page","google_slides_get_thumbnail","google_slides_group_objects","google_slides_insert_table_columns","google_slides_insert_table_rows","google_slides_insert_text","google_slides_merge_table_cells","google_slides_read","google_slides_refresh_sheets_chart","google_slides_replace_all_shapes_with_image","google_slides_replace_all_shapes_with_sheets_chart","google_slides_replace_all_text","google_slides_replace_image","google_slides_reroute_line","google_slides_ungroup_objects","google_slides_unmerge_table_cells","google_slides_update_image_properties","google_slides_update_line_category","google_slides_update_line_properties","google_slides_update_page_element_alt_text","google_slides_update_page_element_transform","google_slides_update_page_elements_z_order","google_slides_update_page_properties","google_slides_update_paragraph_style","google_slides_update_shape_properties","google_slides_update_slide_properties","google_slides_update_slides_position","google_slides_update_table_border_properties","google_slides_update_table_cell_properties","google_slides_update_table_column_properties","google_slides_update_table_row_properties","google_slides_update_text_style","google_slides_update_video_properties","google_slides_write","google_tasks_create","google_tasks_delete","google_tasks_get","google_tasks_list","google_tasks_list_task_lists","google_tasks_update","google_translate_detect","google_translate_text","google_vault_add_held_accounts","google_vault_add_matters_permissions","google_vault_close_matters","google_vault_create_matters","google_vault_create_matters_export","google_vault_create_matters_holds","google_vault_create_saved_query","google_vault_delete_matters","google_vault_delete_matters_export","google_vault_delete_matters_holds","google_vault_delete_saved_query","google_vault_download_export_file","google_vault_list_matters","google_vault_list_matters_export","google_vault_list_matters_holds","google_vault_list_saved_queries","google_vault_remove_held_accounts","google_vault_remove_matters_permissions","google_vault_reopen_matters","google_vault_undelete_matters","google_vault_update_matters","google_vault_update_matters_holds","grafana_check_data_source_health","grafana_create_alert_rule","grafana_create_annotation","grafana_create_contact_point","grafana_create_dashboard","grafana_create_folder","grafana_delete_alert_rule","grafana_delete_annotation","grafana_delete_contact_point","grafana_delete_dashboard","grafana_delete_folder","grafana_get_alert_rule","grafana_get_alert_rule_group","grafana_get_dashboard","grafana_get_data_source","grafana_get_folder","grafana_get_health","grafana_list_alert_rules","grafana_list_annotations","grafana_list_contact_points","grafana_list_dashboards","grafana_list_data_sources","grafana_list_folders","grafana_move_folder","grafana_query_data_source","grafana_update_alert_rule","grafana_update_annotation","grafana_update_contact_point","grafana_update_dashboard","grafana_update_folder","grain_create_hook","grain_create_hook_v2","grain_delete_hook","grain_delete_hook_v2","grain_get_recording","grain_get_transcript","grain_list_hooks","grain_list_hooks_v2","grain_list_meeting_types","grain_list_recordings","grain_list_teams","grain_list_views","granola_create_webhook_endpoint","granola_delete_webhook_endpoint","granola_get_note","granola_get_transcript","granola_list_audit_events","granola_list_folders","granola_list_notes","granola_list_webhook_endpoints","granola_update_webhook_endpoint","greenhouse_get_application","greenhouse_get_candidate","greenhouse_get_job","greenhouse_get_user","greenhouse_list_applications","greenhouse_list_candidates","greenhouse_list_departments","greenhouse_list_job_stages","greenhouse_list_jobs","greenhouse_list_offices","greenhouse_list_users","greptile_index_repo","greptile_query","greptile_search","greptile_status","guardrails_validate","harmonic_batch_get_people","harmonic_clear_people_saved_search_net_new_results","harmonic_enrich_person","harmonic_get_company_employees","harmonic_get_email_enrichment_job","harmonic_get_email_enrichment_usage","harmonic_get_enrichment_status","harmonic_get_people_saved_search_net_new_results","harmonic_get_people_saved_search_results","harmonic_get_person","harmonic_list_people_saved_searches","harmonic_search_people_scout","harmonic_submit_email_enrichment_job","hex_cancel_run","hex_create_collection","hex_create_group","hex_deactivate_user","hex_delete_group","hex_get_collection","hex_get_data_connection","hex_get_group","hex_get_project","hex_get_project_runs","hex_get_queried_tables","hex_get_run_status","hex_list_collections","hex_list_data_connections","hex_list_groups","hex_list_projects","hex_list_users","hex_run_project","hex_update_collection","hex_update_group","hex_update_project","http_request","hubspot_add_list_memberships","hubspot_create_appointment","hubspot_create_association","hubspot_create_company","hubspot_create_contact","hubspot_create_deal","hubspot_create_email","hubspot_create_line_item","hubspot_create_list","hubspot_create_note","hubspot_create_ticket","hubspot_delete_association","hubspot_delete_company","hubspot_delete_contact","hubspot_delete_deal","hubspot_delete_line_item","hubspot_delete_ticket","hubspot_get_appointment","hubspot_get_association_labels","hubspot_get_cart","hubspot_get_company","hubspot_get_contact","hubspot_get_deal","hubspot_get_email","hubspot_get_line_item","hubspot_get_list","hubspot_get_list_memberships","hubspot_get_marketing_event","hubspot_get_note","hubspot_get_properties","hubspot_get_quote","hubspot_get_ticket","hubspot_get_users","hubspot_list_appointments","hubspot_list_associations","hubspot_list_carts","hubspot_list_companies","hubspot_list_contacts","hubspot_list_deals","hubspot_list_emails","hubspot_list_line_items","hubspot_list_lists","hubspot_list_marketing_events","hubspot_list_notes","hubspot_list_owners","hubspot_list_quotes","hubspot_list_tickets","hubspot_remove_list_memberships","hubspot_search_companies","hubspot_search_contacts","hubspot_search_deals","hubspot_search_emails","hubspot_search_line_items","hubspot_search_notes","hubspot_search_quotes","hubspot_search_tickets","hubspot_update_appointment","hubspot_update_company","hubspot_update_contact","hubspot_update_deal","hubspot_update_line_item","hubspot_update_ticket","huggingface_chat","hunter_companies_find","hunter_discover","hunter_domain_search","hunter_email_count","hunter_email_finder","hunter_email_verifier","iam_add_user_to_group","iam_attach_role_policy","iam_attach_user_policy","iam_create_access_key","iam_create_role","iam_create_user","iam_delete_access_key","iam_delete_role","iam_delete_user","iam_detach_role_policy","iam_detach_user_policy","iam_get_policy","iam_get_role","iam_get_user","iam_list_access_keys","iam_list_attached_role_policies","iam_list_attached_user_policies","iam_list_groups","iam_list_policies","iam_list_roles","iam_list_users","iam_remove_user_from_group","iam_simulate_principal_policy","iam_update_access_key","icypeas_find_email","icypeas_verify_email","identity_center_check_assignment_deletion_status","identity_center_check_assignment_status","identity_center_create_account_assignment","identity_center_delete_account_assignment","identity_center_describe_account","identity_center_describe_group","identity_center_describe_user","identity_center_get_group","identity_center_get_user","identity_center_list_account_assignments","identity_center_list_accounts","identity_center_list_assignments_for_account","identity_center_list_group_memberships","identity_center_list_groups","identity_center_list_instances","identity_center_list_permission_sets","image_generate","incidentio_actions_create","incidentio_actions_list","incidentio_actions_show","incidentio_actions_update","incidentio_alert_events_create","incidentio_alerts_list","incidentio_alerts_resolve","incidentio_alerts_show","incidentio_catalog_entries_list","incidentio_catalog_types_list","incidentio_custom_fields_create","incidentio_custom_fields_delete","incidentio_custom_fields_list","incidentio_custom_fields_show","incidentio_custom_fields_update","incidentio_escalation_paths_create","incidentio_escalation_paths_delete","incidentio_escalation_paths_list","incidentio_escalation_paths_show","incidentio_escalation_paths_update","incidentio_escalations_cancel","incidentio_escalations_create","incidentio_escalations_list","incidentio_escalations_show","incidentio_follow_ups_create","incidentio_follow_ups_list","incidentio_follow_ups_show","incidentio_follow_ups_update","incidentio_incident_alerts_list","incidentio_incident_memberships_create","incidentio_incident_memberships_revoke","incidentio_incident_participants_list","incidentio_incident_roles_create","incidentio_incident_roles_delete","incidentio_incident_roles_list","incidentio_incident_roles_show","incidentio_incident_roles_update","incidentio_incident_statuses_list","incidentio_incident_timestamps_list","incidentio_incident_timestamps_show","incidentio_incident_types_list","incidentio_incident_updates_list","incidentio_incidents_create","incidentio_incidents_list","incidentio_incidents_show","incidentio_incidents_update","incidentio_on_call_now","incidentio_schedule_entries_list","incidentio_schedule_overrides_create","incidentio_schedule_overrides_list","incidentio_schedules_create","incidentio_schedules_delete","incidentio_schedules_list","incidentio_schedules_show","incidentio_schedules_update","incidentio_severities_list","incidentio_teams_list","incidentio_teams_show","incidentio_users_list","incidentio_users_show","incidentio_workflows_create","incidentio_workflows_delete","incidentio_workflows_list","incidentio_workflows_show","incidentio_workflows_update","infisical_create_secret","infisical_delete_secret","infisical_get_secret","infisical_list_secrets","infisical_update_secret","instagram_delete_comment","instagram_download_media","instagram_get_account_insights","instagram_get_container_status","instagram_get_conversation_messages","instagram_get_media","instagram_get_media_insights","instagram_get_message","instagram_get_profile","instagram_get_publishing_limit","instagram_hide_comment","instagram_list_comments","instagram_list_conversations","instagram_list_media","instagram_list_stories","instagram_private_reply","instagram_publish_carousel","instagram_publish_image","instagram_publish_reel","instagram_publish_story","instagram_publish_video","instagram_reply_to_comment","instagram_send_text_message","instagram_set_comments_enabled","instantly_activate_campaign","instantly_create_campaign","instantly_create_lead","instantly_create_lead_list","instantly_delete_campaign","instantly_delete_leads","instantly_get_lead","instantly_list_campaigns","instantly_list_emails","instantly_list_lead_lists","instantly_list_leads","instantly_patch_campaign","instantly_patch_lead","instantly_pause_campaign","instantly_reply_to_email","instantly_update_lead_interest_status","intercom_assign_conversation_v2","intercom_attach_contact_to_company_v2","intercom_close_conversation_v2","intercom_create_company","intercom_create_company_v2","intercom_create_contact","intercom_create_contact_v2","intercom_create_event_v2","intercom_create_message","intercom_create_message_v2","intercom_create_note_v2","intercom_create_tag_v2","intercom_create_ticket","intercom_create_ticket_v2","intercom_delete_contact","intercom_delete_contact_v2","intercom_detach_contact_from_company_v2","intercom_get_company","intercom_get_company_v2","intercom_get_contact","intercom_get_contact_v2","intercom_get_conversation","intercom_get_conversation_v2","intercom_get_ticket","intercom_get_ticket_v2","intercom_list_admins_v2","intercom_list_companies","intercom_list_companies_v2","intercom_list_contacts","intercom_list_contacts_v2","intercom_list_conversations","intercom_list_conversations_v2","intercom_list_tags_v2","intercom_open_conversation_v2","intercom_reply_conversation","intercom_reply_conversation_v2","intercom_search_contacts","intercom_search_contacts_v2","intercom_search_conversations","intercom_search_conversations_v2","intercom_snooze_conversation_v2","intercom_tag_contact_v2","intercom_tag_conversation_v2","intercom_untag_contact_v2","intercom_update_contact","intercom_update_contact_v2","intercom_update_ticket_v2","jina_read_url","jina_search","jira_add_attachment","jira_add_comment","jira_add_watcher","jira_add_worklog","jira_assign_issue","jira_bulk_read","jira_create_issue_link","jira_delete_attachment","jira_delete_comment","jira_delete_issue","jira_delete_issue_link","jira_delete_worklog","jira_get_attachments","jira_get_comments","jira_get_fields","jira_get_project","jira_get_transitions","jira_get_users","jira_get_worklogs","jira_list_issue_types","jira_list_projects","jira_remove_watcher","jira_retrieve","jira_search_issues","jira_search_users","jira_transition_issue","jira_update","jira_update_comment","jira_update_worklog","jira_write","jotform_add_label_resources","jotform_clone_form","jotform_create_form","jotform_create_label","jotform_create_question","jotform_create_questions","jotform_create_report","jotform_create_submission","jotform_create_submissions","jotform_create_webhook","jotform_delete_form","jotform_delete_label","jotform_delete_question","jotform_delete_report","jotform_delete_submission","jotform_delete_webhook","jotform_get_form","jotform_get_form_properties","jotform_get_history","jotform_get_label","jotform_get_question","jotform_get_report","jotform_get_settings","jotform_get_submission","jotform_get_usage","jotform_get_user","jotform_list_form_files","jotform_list_form_reports","jotform_list_form_submissions","jotform_list_forms","jotform_list_label_resources","jotform_list_labels","jotform_list_questions","jotform_list_reports","jotform_list_submissions","jotform_list_subusers","jotform_list_webhooks","jotform_remove_label_resources","jotform_update_form_properties","jotform_update_label","jotform_update_question","jotform_update_settings","jotform_update_submission","jsm_add_comment","jsm_add_customer","jsm_add_organization","jsm_add_participants","jsm_answer_approval","jsm_attach_form","jsm_copy_forms","jsm_create_object","jsm_create_organization","jsm_create_request","jsm_delete_form","jsm_delete_object","jsm_externalise_form","jsm_get_approvals","jsm_get_comments","jsm_get_customers","jsm_get_form","jsm_get_form_answers","jsm_get_form_structure","jsm_get_form_templates","jsm_get_issue_forms","jsm_get_object","jsm_get_object_schema","jsm_get_object_type_attributes","jsm_get_organizations","jsm_get_participants","jsm_get_queues","jsm_get_request","jsm_get_request_type_fields","jsm_get_request_types","jsm_get_requests","jsm_get_service_desks","jsm_get_sla","jsm_get_transitions","jsm_internalise_form","jsm_list_object_schemas","jsm_list_object_types","jsm_reopen_form","jsm_save_form_answers","jsm_search_objects_aql","jsm_submit_form","jsm_transition_request","jsm_update_object","jupyter_copy_content","jupyter_create_file","jupyter_create_session","jupyter_delete_content","jupyter_delete_session","jupyter_get_content","jupyter_interrupt_kernel","jupyter_list_contents","jupyter_list_kernels","jupyter_list_kernelspecs","jupyter_list_sessions","jupyter_rename_content","jupyter_restart_kernel","jupyter_start_kernel","jupyter_stop_kernel","jupyter_upload_file","kalshi_amend_order","kalshi_amend_order_v2","kalshi_cancel_order","kalshi_cancel_order_v2","kalshi_create_order","kalshi_create_order_v2","kalshi_get_balance","kalshi_get_balance_v2","kalshi_get_candlesticks","kalshi_get_candlesticks_v2","kalshi_get_event","kalshi_get_event_candlesticks","kalshi_get_event_candlesticks_v2","kalshi_get_event_v2","kalshi_get_events","kalshi_get_events_v2","kalshi_get_exchange_announcements","kalshi_get_exchange_announcements_v2","kalshi_get_exchange_schedule","kalshi_get_exchange_schedule_v2","kalshi_get_exchange_status","kalshi_get_exchange_status_v2","kalshi_get_fills","kalshi_get_fills_v2","kalshi_get_market","kalshi_get_market_v2","kalshi_get_markets","kalshi_get_markets_v2","kalshi_get_order","kalshi_get_order_v2","kalshi_get_orderbook","kalshi_get_orderbook_v2","kalshi_get_orders","kalshi_get_orders_v2","kalshi_get_positions","kalshi_get_positions_v2","kalshi_get_series_by_ticker","kalshi_get_series_by_ticker_v2","kalshi_get_series_list","kalshi_get_series_list_v2","kalshi_get_settlements","kalshi_get_settlements_v2","kalshi_get_trades","kalshi_get_trades_v2","ketch_get_consent","ketch_get_subscriptions","ketch_invoke_right","ketch_set_consent","ketch_set_subscriptions","knowledge_create_document","knowledge_delete_chunk","knowledge_delete_document","knowledge_get_connector","knowledge_get_document","knowledge_list_chunks","knowledge_list_connectors","knowledge_list_documents","knowledge_list_tags","knowledge_search","knowledge_trigger_sync","knowledge_update_chunk","knowledge_upload_chunk","knowledge_upsert_document","lambda_add_permission","lambda_create_alias","lambda_create_event_source_mapping","lambda_create_function","lambda_create_function_url_config","lambda_delete_alias","lambda_delete_event_source_mapping","lambda_delete_function","lambda_delete_function_concurrency","lambda_delete_function_event_invoke_config","lambda_delete_function_url_config","lambda_delete_provisioned_concurrency_config","lambda_get_account_settings","lambda_get_alias","lambda_get_event_source_mapping","lambda_get_function","lambda_get_function_concurrency","lambda_get_function_configuration","lambda_get_function_event_invoke_config","lambda_get_function_recursion_config","lambda_get_function_url_config","lambda_get_layer_version","lambda_get_policy","lambda_get_provisioned_concurrency_config","lambda_get_runtime_management_config","lambda_invoke","lambda_list_aliases","lambda_list_event_source_mappings","lambda_list_function_event_invoke_configs","lambda_list_function_url_configs","lambda_list_functions","lambda_list_layer_versions","lambda_list_layers","lambda_list_provisioned_concurrency_configs","lambda_list_tags","lambda_list_versions_by_function","lambda_publish_version","lambda_put_function_concurrency","lambda_put_function_event_invoke_config","lambda_put_function_recursion_config","lambda_put_provisioned_concurrency_config","lambda_put_runtime_management_config","lambda_remove_permission","lambda_tag_resource","lambda_untag_resource","lambda_update_alias","lambda_update_event_source_mapping","lambda_update_function_code","lambda_update_function_configuration","lambda_update_function_url_config","langsmith_create_feedback","langsmith_create_run","langsmith_create_runs_batch","langsmith_get_run","langsmith_update_run","latex_compile","latex_get_package","latex_list_fonts","latex_search_packages","launchdarkly_create_flag","launchdarkly_delete_flag","launchdarkly_get_audit_log","launchdarkly_get_flag","launchdarkly_get_flag_status","launchdarkly_list_environments","launchdarkly_list_flags","launchdarkly_list_members","launchdarkly_list_projects","launchdarkly_list_segments","launchdarkly_toggle_flag","launchdarkly_update_flag","leadmagic_company_search","leadmagic_email_to_profile","leadmagic_find_email","leadmagic_find_mobile","leadmagic_get_credits","leadmagic_profile_search","leadmagic_profile_to_email","leadmagic_role_finder","leadmagic_validate_email","lemlist_get_activities","lemlist_get_lead","lemlist_send_email","linear_add_label_to_issue","linear_add_label_to_project","linear_archive_issue","linear_archive_label","linear_archive_project","linear_create_attachment","linear_create_comment","linear_create_customer","linear_create_customer_request","linear_create_customer_status","linear_create_customer_tier","linear_create_cycle","linear_create_favorite","linear_create_issue","linear_create_issue_relation","linear_create_label","linear_create_project","linear_create_project_label","linear_create_project_milestone","linear_create_project_status","linear_create_project_update","linear_create_workflow_state","linear_delete_attachment","linear_delete_comment","linear_delete_customer","linear_delete_customer_status","linear_delete_customer_tier","linear_delete_issue","linear_delete_issue_relation","linear_delete_project","linear_delete_project_label","linear_delete_project_milestone","linear_delete_project_status","linear_get_active_cycle","linear_get_customer","linear_get_cycle","linear_get_issue","linear_get_project","linear_get_viewer","linear_list_attachments","linear_list_comments","linear_list_customer_requests","linear_list_customer_statuses","linear_list_customer_tiers","linear_list_customers","linear_list_cycles","linear_list_favorites","linear_list_issue_relations","linear_list_labels","linear_list_notifications","linear_list_project_labels","linear_list_project_milestones","linear_list_project_statuses","linear_list_project_updates","linear_list_projects","linear_list_teams","linear_list_users","linear_list_workflow_states","linear_merge_customers","linear_read_issues","linear_remove_label_from_issue","linear_remove_label_from_project","linear_search_issues","linear_unarchive_issue","linear_update_attachment","linear_update_comment","linear_update_customer","linear_update_customer_request","linear_update_customer_status","linear_update_customer_tier","linear_update_issue","linear_update_label","linear_update_notification","linear_update_project","linear_update_project_label","linear_update_project_milestone","linear_update_project_status","linear_update_workflow_state","linkedin_get_profile","linkedin_share_post","linkup_search","linq_add_participant","linq_check_imessage","linq_check_rcs","linq_create_attachment","linq_create_chat","linq_create_contact_card","linq_create_webhook_subscription","linq_delete_attachment","linq_delete_message","linq_delete_webhook_subscription","linq_edit_message","linq_get_attachment","linq_get_chat","linq_get_contact_card","linq_get_message","linq_get_webhook_subscription","linq_leave_chat","linq_list_chats","linq_list_messages","linq_list_phone_numbers","linq_list_thread","linq_list_webhook_events","linq_list_webhook_subscriptions","linq_mark_chat_read","linq_react_to_message","linq_remove_participant","linq_send_message","linq_send_voice_memo","linq_share_contact_card","linq_start_typing","linq_stop_typing","linq_update_chat","linq_update_contact_card","linq_update_webhook_subscription","llm_chat","logfire_get_token_info","logfire_get_trace","logfire_query","logfire_search_records","logrocket_create_release","logrocket_get_audit_logs","logrocket_get_highlights","logrocket_identify_user","logrocket_list_exported_sessions","logrocket_request_highlights","logs_get","logs_get_execution","logs_get_run_details","logs_query","logs_query_runs","loops_check_contact_suppression","loops_create_contact","loops_create_contact_property","loops_delete_contact","loops_find_contact","loops_get_transactional_email","loops_list_contact_properties","loops_list_mailing_lists","loops_list_transactional_emails","loops_remove_contact_suppression","loops_send_event","loops_send_transactional_email","loops_update_contact","luma_add_guests","luma_cancel_event","luma_create_event","luma_get_event","luma_get_guest","luma_get_guests","luma_list_events","luma_lookup_event","luma_send_invites","luma_update_event","luma_update_guest_status","mailchimp_add_member","mailchimp_add_member_tags","mailchimp_add_or_update_member","mailchimp_add_segment_member","mailchimp_add_subscriber_to_automation","mailchimp_archive_member","mailchimp_create_audience","mailchimp_create_batch_operation","mailchimp_create_campaign","mailchimp_create_interest","mailchimp_create_interest_category","mailchimp_create_landing_page","mailchimp_create_merge_field","mailchimp_create_segment","mailchimp_create_template","mailchimp_delete_audience","mailchimp_delete_batch_operation","mailchimp_delete_campaign","mailchimp_delete_interest","mailchimp_delete_interest_category","mailchimp_delete_landing_page","mailchimp_delete_member","mailchimp_delete_merge_field","mailchimp_delete_segment","mailchimp_delete_template","mailchimp_get_audience","mailchimp_get_audiences","mailchimp_get_automation","mailchimp_get_automations","mailchimp_get_batch_operation","mailchimp_get_batch_operations","mailchimp_get_campaign","mailchimp_get_campaign_content","mailchimp_get_campaign_report","mailchimp_get_campaign_reports","mailchimp_get_campaigns","mailchimp_get_interest","mailchimp_get_interest_categories","mailchimp_get_interest_category","mailchimp_get_interests","mailchimp_get_landing_page","mailchimp_get_landing_pages","mailchimp_get_member","mailchimp_get_member_tags","mailchimp_get_members","mailchimp_get_merge_field","mailchimp_get_merge_fields","mailchimp_get_segment","mailchimp_get_segment_members","mailchimp_get_segments","mailchimp_get_template","mailchimp_get_templates","mailchimp_pause_automation","mailchimp_publish_landing_page","mailchimp_remove_member_tags","mailchimp_remove_segment_member","mailchimp_replicate_campaign","mailchimp_schedule_campaign","mailchimp_send_campaign","mailchimp_set_campaign_content","mailchimp_start_automation","mailchimp_unarchive_member","mailchimp_unpublish_landing_page","mailchimp_unschedule_campaign","mailchimp_update_audience","mailchimp_update_campaign","mailchimp_update_interest","mailchimp_update_interest_category","mailchimp_update_landing_page","mailchimp_update_member","mailchimp_update_merge_field","mailchimp_update_segment","mailchimp_update_template","mailgun_add_list_member","mailgun_create_mailing_list","mailgun_get_domain","mailgun_get_mailing_list","mailgun_get_message","mailgun_list_domains","mailgun_list_messages","mailgun_send_message","managed_agent_archive_session","managed_agent_create_session","managed_agent_delete_session","managed_agent_get_session","managed_agent_interrupt_session","managed_agent_list_events","managed_agent_respond_custom_tool","managed_agent_respond_tool_confirmation","managed_agent_run_session","managed_agent_send_message","managed_agent_update_session","manageengine_sdp_add_change_note","manageengine_sdp_add_problem_note","manageengine_sdp_add_request_note","manageengine_sdp_create_asset","manageengine_sdp_create_change","manageengine_sdp_create_problem","manageengine_sdp_create_request","manageengine_sdp_create_solution","manageengine_sdp_delete_asset","manageengine_sdp_delete_change","manageengine_sdp_delete_problem","manageengine_sdp_delete_request","manageengine_sdp_delete_solution","manageengine_sdp_get_asset","manageengine_sdp_get_change","manageengine_sdp_get_problem","manageengine_sdp_get_request","manageengine_sdp_get_solution","manageengine_sdp_list_assets","manageengine_sdp_list_change_notes","manageengine_sdp_list_changes","manageengine_sdp_list_problem_notes","manageengine_sdp_list_problems","manageengine_sdp_list_request_notes","manageengine_sdp_list_requests","manageengine_sdp_list_solutions","manageengine_sdp_update_asset","manageengine_sdp_update_change","manageengine_sdp_update_problem","manageengine_sdp_update_request","manageengine_sdp_update_solution","mcp_list_operations","mcp_run_operation","mem0_add_memories","mem0_get_memories","mem0_search_memories","memory_add","memory_delete","memory_get","memory_get_all","microsoft_ad_add_directory_role_member","microsoft_ad_add_group_member","microsoft_ad_add_user_app_role_assignment","microsoft_ad_assign_license","microsoft_ad_create_group","microsoft_ad_create_user","microsoft_ad_delete_group","microsoft_ad_delete_user","microsoft_ad_get_conditional_access_policy","microsoft_ad_get_device","microsoft_ad_get_group","microsoft_ad_get_user","microsoft_ad_list_authentication_methods","microsoft_ad_list_conditional_access_policies","microsoft_ad_list_devices","microsoft_ad_list_directory_audits","microsoft_ad_list_directory_role_members","microsoft_ad_list_directory_roles","microsoft_ad_list_group_members","microsoft_ad_list_groups","microsoft_ad_list_service_principal_app_role_assignments","microsoft_ad_list_service_principals","microsoft_ad_list_sign_ins","microsoft_ad_list_subscribed_skus","microsoft_ad_list_user_app_role_assignments","microsoft_ad_list_user_devices","microsoft_ad_list_user_licenses","microsoft_ad_list_users","microsoft_ad_remove_directory_role_member","microsoft_ad_remove_group_member","microsoft_ad_remove_user_app_role_assignment","microsoft_ad_reset_password","microsoft_ad_revoke_sign_in_sessions","microsoft_ad_set_password","microsoft_ad_update_group","microsoft_ad_update_user","microsoft_dataverse_associate","microsoft_dataverse_create_multiple","microsoft_dataverse_create_record","microsoft_dataverse_delete_record","microsoft_dataverse_disassociate","microsoft_dataverse_download_file","microsoft_dataverse_execute_action","microsoft_dataverse_execute_function","microsoft_dataverse_fetchxml_query","microsoft_dataverse_get_entity_metadata","microsoft_dataverse_get_record","microsoft_dataverse_list_records","microsoft_dataverse_search","microsoft_dataverse_update_multiple","microsoft_dataverse_update_record","microsoft_dataverse_upload_file","microsoft_dataverse_upsert_record","microsoft_dataverse_whoami","microsoft_dynamics_365_close_case","microsoft_dynamics_365_close_opportunity","microsoft_dynamics_365_create_record","microsoft_dynamics_365_get_record","microsoft_dynamics_365_list_records","microsoft_dynamics_365_qualify_lead","microsoft_dynamics_365_search_records","microsoft_dynamics_365_update_record","microsoft_excel_clear_range","microsoft_excel_create_table","microsoft_excel_delete_worksheet","microsoft_excel_format_range","microsoft_excel_read","microsoft_excel_read_v2","microsoft_excel_sort_range","microsoft_excel_table_add","microsoft_excel_worksheet_add","microsoft_excel_write","microsoft_excel_write_v2","microsoft_planner_create_bucket","microsoft_planner_create_plan","microsoft_planner_create_task","microsoft_planner_delete_bucket","microsoft_planner_delete_plan","microsoft_planner_delete_task","microsoft_planner_get_plan_details","microsoft_planner_get_task_details","microsoft_planner_list_buckets","microsoft_planner_list_plans","microsoft_planner_read_bucket","microsoft_planner_read_plan","microsoft_planner_read_task","microsoft_planner_update_bucket","microsoft_planner_update_plan","microsoft_planner_update_plan_details","microsoft_planner_update_task","microsoft_planner_update_task_details","microsoft_teams_delete_channel_message","microsoft_teams_delete_chat_message","microsoft_teams_get_message","microsoft_teams_list_channel_members","microsoft_teams_list_channels","microsoft_teams_list_chat_members","microsoft_teams_list_chats","microsoft_teams_list_team_members","microsoft_teams_list_teams","microsoft_teams_read_channel","microsoft_teams_read_chat","microsoft_teams_reply_to_message","microsoft_teams_set_reaction","microsoft_teams_unset_reaction","microsoft_teams_update_channel_message","microsoft_teams_update_chat_message","microsoft_teams_write_channel","microsoft_teams_write_chat","microsoft_word_append","microsoft_word_create","microsoft_word_create_from_template","microsoft_word_export_pdf","microsoft_word_list","microsoft_word_read","microsoft_word_replace_text","microsoft_word_update","millionverifier_get_credits","millionverifier_verify_email","mintlify_create_agent_job","mintlify_create_assistant_message","mintlify_detect_ai_prose","mintlify_get_agent_job","mintlify_get_assistant_caller_stats","mintlify_get_assistant_conversations","mintlify_get_feedback","mintlify_get_feedback_by_page","mintlify_get_page_content","mintlify_get_searches","mintlify_get_update_status","mintlify_get_views","mintlify_get_visitors","mintlify_search","mintlify_send_agent_message","mintlify_trigger_automation","mintlify_trigger_preview","mintlify_trigger_update","mistral_parser","mistral_parser_v2","mistral_parser_v3","modal_call_function","modal_chat_completion","modal_list_models","monday_archive_item","monday_change_column_value","monday_create_board","monday_create_column","monday_create_group","monday_create_item","monday_create_subitem","monday_create_update","monday_delete_item","monday_duplicate_item","monday_get_board","monday_get_groups","monday_get_item","monday_get_items","monday_list_boards","monday_move_item_to_group","monday_search_items","monday_update_item","mongodb_delete","mongodb_execute","mongodb_insert","mongodb_introspect","mongodb_query","mongodb_update","mssql_delete","mssql_execute","mssql_insert","mssql_introspect","mssql_query","mssql_update","mysql_delete","mysql_execute","mysql_insert","mysql_introspect","mysql_query","mysql_update","neo4j_create","neo4j_delete","neo4j_execute","neo4j_introspect","neo4j_merge","neo4j_query","neo4j_update","netsuite_attach_record","netsuite_batch_create_records","netsuite_batch_delete_records","netsuite_batch_get_records","netsuite_batch_update_records","netsuite_batch_upsert_records","netsuite_create_record","netsuite_delete_record","netsuite_detach_record","netsuite_execute_action","netsuite_execute_dataset","netsuite_execute_suiteql","netsuite_get_async_result","netsuite_get_async_status","netsuite_get_governance_limits","netsuite_get_record","netsuite_get_record_form","netsuite_get_record_metadata","netsuite_get_select_options","netsuite_get_server_time","netsuite_get_subresource","netsuite_list_datasets","netsuite_list_record_types","netsuite_list_records","netsuite_transform_record","netsuite_update_record","netsuite_upsert_record","neverbounce_get_credits","neverbounce_verify_email","new_relic_create_deployment_event","new_relic_get_entity","new_relic_nrql_query","new_relic_search_entities","notion_add_database_row","notion_add_database_row_v2","notion_append_blocks","notion_append_blocks_v2","notion_create_comment","notion_create_comment_v2","notion_create_database","notion_create_database_v2","notion_create_page","notion_create_page_v2","notion_delete_block","notion_delete_block_v2","notion_list_comments","notion_list_comments_v2","notion_list_users","notion_list_users_v2","notion_query_database","notion_query_database_v2","notion_read","notion_read_database","notion_read_database_v2","notion_read_v2","notion_retrieve_block","notion_retrieve_block_children","notion_retrieve_block_children_v2","notion_retrieve_block_v2","notion_retrieve_user","notion_retrieve_user_v2","notion_search","notion_search_v2","notion_update_block","notion_update_block_v2","notion_update_page","notion_update_page_v2","notion_write","notion_write_v2","obsidian_append_active","obsidian_append_note","obsidian_append_periodic_note","obsidian_create_note","obsidian_delete_note","obsidian_execute_command","obsidian_get_active","obsidian_get_note","obsidian_get_periodic_note","obsidian_list_commands","obsidian_list_files","obsidian_open_file","obsidian_patch_active","obsidian_patch_note","obsidian_search","okta_activate_group_rule","okta_activate_user","okta_add_user_to_group","okta_assign_group_to_app","okta_assign_user_role","okta_assign_user_to_app","okta_clear_user_sessions","okta_create_group","okta_create_group_rule","okta_create_user","okta_deactivate_group_rule","okta_deactivate_user","okta_delete_group","okta_delete_group_rule","okta_delete_user","okta_enroll_factor","okta_get_app","okta_get_factor","okta_get_group","okta_get_group_rule","okta_get_logs","okta_get_session","okta_get_user","okta_list_app_groups","okta_list_app_users","okta_list_apps","okta_list_factors","okta_list_group_members","okta_list_group_rules","okta_list_groups","okta_list_user_roles","okta_list_users","okta_remove_group_from_app","okta_remove_user_from_app","okta_remove_user_from_group","okta_remove_user_role","okta_reset_all_factors","okta_reset_factor","okta_reset_password","okta_revoke_session","okta_suspend_user","okta_unsuspend_user","okta_update_group","okta_update_user","onedrive_copy","onedrive_create_folder","onedrive_create_share_link","onedrive_delete","onedrive_download","onedrive_get_drive_info","onedrive_get_item","onedrive_list","onedrive_move","onedrive_search","onedrive_upload","onepassword_create_item","onepassword_delete_item","onepassword_get_item","onepassword_get_item_file","onepassword_get_vault","onepassword_list_items","onepassword_list_vaults","onepassword_replace_item","onepassword_resolve_secret","onepassword_update_item","openai_embeddings","openai_image","outlook_calendar_create_event","outlook_calendar_delete_event","outlook_calendar_get_event","outlook_calendar_list_events","outlook_calendar_respond","outlook_calendar_update_event","outlook_copy","outlook_create_folder","outlook_delete","outlook_draft","outlook_forward","outlook_get_attachment","outlook_list_attachments","outlook_list_folders","outlook_mark_read","outlook_mark_unread","outlook_move","outlook_read","outlook_reply","outlook_reply_all","outlook_search","outlook_send","outlook_update_message","pagerduty_add_note","pagerduty_create_incident","pagerduty_get_incident","pagerduty_get_service","pagerduty_list_escalation_policies","pagerduty_list_incident_alerts","pagerduty_list_incidents","pagerduty_list_oncalls","pagerduty_list_schedules","pagerduty_list_services","pagerduty_list_users","pagerduty_merge_incidents","pagerduty_send_event","pagerduty_snooze_incident","pagerduty_update_incident","parallel_deep_research","parallel_extract","parallel_search","pdl_autocomplete","pdl_bulk_company_enrich","pdl_bulk_person_enrich","pdl_clean_company","pdl_clean_location","pdl_clean_school","pdl_company_enrich","pdl_company_search","pdl_person_enrich","pdl_person_identify","pdl_person_search","perplexity_chat","perplexity_search","persona_approve_inquiry","persona_create_account","persona_create_inquiry","persona_create_report","persona_decline_inquiry","persona_expire_inquiry","persona_generate_inquiry_link","persona_get_account","persona_get_case","persona_get_document","persona_get_inquiry","persona_get_report","persona_get_verification","persona_import_accounts","persona_list_accounts","persona_list_cases","persona_list_inquiries","persona_list_inquiry_templates","persona_list_reports","persona_mark_inquiry_for_review","persona_print_inquiry_pdf","persona_redact_account","persona_redact_inquiry","persona_resume_inquiry","persona_update_account","persona_update_inquiry","pinecone_delete_vectors","pinecone_describe_index","pinecone_describe_index_stats","pinecone_fetch","pinecone_generate_embeddings","pinecone_list_indexes","pinecone_list_vector_ids","pinecone_search_text","pinecone_search_vector","pinecone_update_vector","pinecone_upsert_text","pipedrive_create_activity","pipedrive_create_deal","pipedrive_create_lead","pipedrive_create_project","pipedrive_delete_lead","pipedrive_get_activities","pipedrive_get_all_deals","pipedrive_get_deal","pipedrive_get_files","pipedrive_get_leads","pipedrive_get_mail_messages","pipedrive_get_mail_thread","pipedrive_get_pipeline_deals","pipedrive_get_pipelines","pipedrive_get_projects","pipedrive_update_activity","pipedrive_update_deal","pipedrive_update_lead","pitchbook_company_active_investors","pitchbook_company_bio","pitchbook_company_deal_service_providers","pitchbook_company_deals","pitchbook_company_financials","pitchbook_company_general_service_providers","pitchbook_company_industries","pitchbook_company_investors","pitchbook_company_most_recent_debt_financing","pitchbook_company_most_recent_financials","pitchbook_company_most_recent_financing","pitchbook_company_search","pitchbook_company_similar_companies","pitchbook_company_social_analytics","pitchbook_company_updates","pitchbook_company_vc_exit_predictions","pitchbook_contracts_history","pitchbook_cost_of_calls","pitchbook_credit_history","pitchbook_credit_news","pitchbook_credit_news_bulk","pitchbook_credit_news_most_recent","pitchbook_credit_news_search","pitchbook_deal_bio","pitchbook_deal_cap_table_history","pitchbook_deal_debt_lenders","pitchbook_deal_detailed","pitchbook_deal_investors","pitchbook_deal_multiples","pitchbook_deal_search","pitchbook_deal_service_providers","pitchbook_deal_stock_info","pitchbook_deal_tranche_info","pitchbook_deal_updates","pitchbook_deal_valuation","pitchbook_entity_affiliates","pitchbook_entity_locations","pitchbook_entity_news","pitchbook_entity_people","pitchbook_entity_updates","pitchbook_fund_active_investments","pitchbook_fund_benchmark","pitchbook_fund_bio","pitchbook_fund_cash_flows","pitchbook_fund_commitments","pitchbook_fund_investment_preferences","pitchbook_fund_investments","pitchbook_fund_performance","pitchbook_fund_search","pitchbook_fund_team","pitchbook_fund_updates","pitchbook_investor_active_investments","pitchbook_investor_bio","pitchbook_investor_board_seats","pitchbook_investor_deal_service_providers","pitchbook_investor_funds","pitchbook_investor_general_service_providers","pitchbook_investor_investments","pitchbook_investor_last_closed_fund","pitchbook_investor_preferences","pitchbook_investor_search","pitchbook_investor_updates","pitchbook_limited_partner_actual_allocations","pitchbook_limited_partner_bio","pitchbook_limited_partner_commitment_aggregates","pitchbook_limited_partner_commitment_preferences","pitchbook_limited_partner_commitments_detailed","pitchbook_limited_partner_search","pitchbook_limited_partner_service_providers","pitchbook_limited_partner_target_allocations","pitchbook_limited_partner_updates","pitchbook_lookup_table_structure","pitchbook_lookup_tables","pitchbook_patent_detailed","pitchbook_patent_search","pitchbook_people_search","pitchbook_person_bio","pitchbook_person_contact","pitchbook_person_education_work","pitchbook_sandbox_entities","pitchbook_search","pitchbook_service_provider_bio","pitchbook_service_provider_search","pitchbook_service_provider_updates","pitchbook_serviced_companies","pitchbook_serviced_deals","pitchbook_serviced_funds","pitchbook_serviced_investors","pitchbook_serviced_limited_partners","pitchbook_shared_search","pitchbook_usage_report","polymarket_get_activity","polymarket_get_event","polymarket_get_events","polymarket_get_holders","polymarket_get_last_trade_price","polymarket_get_leaderboard","polymarket_get_market","polymarket_get_markets","polymarket_get_midpoint","polymarket_get_orderbook","polymarket_get_positions","polymarket_get_price","polymarket_get_price_history","polymarket_get_series","polymarket_get_series_by_id","polymarket_get_spread","polymarket_get_tags","polymarket_get_tick_size","polymarket_get_trades","polymarket_search","postgresql_delete","postgresql_execute","postgresql_insert","postgresql_introspect","postgresql_query","postgresql_update","posthog_batch_events","posthog_capture_event","posthog_create_annotation","posthog_create_cohort","posthog_create_dashboard","posthog_create_experiment","posthog_create_feature_flag","posthog_create_insight","posthog_create_survey","posthog_delete_feature_flag","posthog_delete_person","posthog_delete_survey","posthog_evaluate_flags","posthog_get_cohort","posthog_get_dashboard","posthog_get_event_definition","posthog_get_experiment","posthog_get_feature_flag","posthog_get_insight","posthog_get_organization","posthog_get_person","posthog_get_project","posthog_get_property_definition","posthog_get_session_recording","posthog_get_survey","posthog_list_actions","posthog_list_annotations","posthog_list_cohorts","posthog_list_dashboards","posthog_list_event_definitions","posthog_list_experiments","posthog_list_feature_flags","posthog_list_insights","posthog_list_organizations","posthog_list_persons","posthog_list_projects","posthog_list_property_definitions","posthog_list_recording_playlists","posthog_list_session_recordings","posthog_list_surveys","posthog_query","posthog_update_cohort","posthog_update_event_definition","posthog_update_experiment","posthog_update_feature_flag","posthog_update_insight","posthog_update_property_definition","posthog_update_survey","profound_bot_logs","profound_bots_report","profound_category_assets","profound_category_personas","profound_category_prompts","profound_category_tags","profound_category_topics","profound_citation_prompts","profound_citations_report","profound_list_assets","profound_list_categories","profound_list_domains","profound_list_models","profound_list_optimizations","profound_list_personas","profound_list_regions","profound_optimization_analysis","profound_prompt_answers","profound_prompt_volume","profound_query_fanouts","profound_raw_logs","profound_referrals_report","profound_sentiment_report","profound_visibility_report","prospeo_account_information","prospeo_bulk_enrich_company","prospeo_bulk_enrich_person","prospeo_enrich_company","prospeo_enrich_person","prospeo_search_company","prospeo_search_person","prospeo_search_suggestions","pulse_parser","pulse_parser_v2","qdrant_fetch_points","qdrant_search_vector","qdrant_upsert_points","quartr_get_audio","quartr_get_company","quartr_get_event","quartr_get_event_summary","quartr_get_report","quartr_get_slide_deck","quartr_get_transcript","quartr_list_audio","quartr_list_companies","quartr_list_document_types","quartr_list_documents","quartr_list_event_types","quartr_list_events","quartr_list_live_events","quartr_list_reports","quartr_list_slide_decks","quartr_list_transcripts","quickbooks_add_attachment","quickbooks_create_bill","quickbooks_create_bill_payment","quickbooks_create_credit_memo","quickbooks_create_customer","quickbooks_create_customer_payment","quickbooks_create_deposit","quickbooks_create_employee","quickbooks_create_estimate","quickbooks_create_invoice","quickbooks_create_item","quickbooks_create_journal_entry","quickbooks_create_purchase","quickbooks_create_purchase_order","quickbooks_create_refund_receipt","quickbooks_create_sales_receipt","quickbooks_create_vendor","quickbooks_create_vendor_credit","quickbooks_download_attachment","quickbooks_download_transaction_pdf","quickbooks_email_transaction","quickbooks_get_company_info","quickbooks_read_accounting_transactions","quickbooks_read_attachments","quickbooks_read_master_data","quickbooks_read_purchasing_transactions","quickbooks_read_sales_transactions","quickbooks_run_financial_report","quickbooks_update_bill","quickbooks_update_bill_payment","quickbooks_update_credit_memo","quickbooks_update_customer","quickbooks_update_customer_payment","quickbooks_update_deposit","quickbooks_update_employee","quickbooks_update_estimate","quickbooks_update_invoice","quickbooks_update_item","quickbooks_update_journal_entry","quickbooks_update_purchase","quickbooks_update_purchase_order","quickbooks_update_refund_receipt","quickbooks_update_sales_receipt","quickbooks_update_vendor","quickbooks_update_vendor_credit","quickbooks_void_bill_payment","quickbooks_void_customer_payment","quickbooks_void_invoice","quickbooks_void_sales_receipt","quiver_image_to_svg","quiver_list_models","quiver_text_to_svg","rabbitmq_create_binding","rabbitmq_create_exchange","rabbitmq_create_policy","rabbitmq_create_queue","rabbitmq_delete_binding","rabbitmq_delete_exchange","rabbitmq_delete_policy","rabbitmq_delete_queue","rabbitmq_get_exchange","rabbitmq_get_messages","rabbitmq_get_overview","rabbitmq_get_queue","rabbitmq_health_check","rabbitmq_list_bindings","rabbitmq_list_channels","rabbitmq_list_connections","rabbitmq_list_consumers","rabbitmq_list_exchange_bindings","rabbitmq_list_exchanges","rabbitmq_list_nodes","rabbitmq_list_policies","rabbitmq_list_queues","rabbitmq_list_vhosts","rabbitmq_publish_message","rabbitmq_purge_queue","railway_create_environment","railway_create_project","railway_create_service","railway_delete_environment","railway_delete_project","railway_delete_service","railway_delete_variable","railway_deploy_service","railway_get_deployment","railway_get_deployment_logs","railway_get_project","railway_list_deployments","railway_list_project_members","railway_list_projects","railway_list_variables","railway_restart_deployment","railway_rollback_deployment","railway_transfer_project","railway_update_project","railway_upsert_variable","rb2b_credit_check","rb2b_email_to_activity","rb2b_hem_to_best_linkedin","rb2b_hem_to_business_profile","rb2b_hem_to_linkedin","rb2b_hem_to_maid","rb2b_ip_to_company","rb2b_ip_to_hem","rb2b_ip_to_maid","rb2b_linkedin_slug_search","rb2b_linkedin_to_best_personal_email","rb2b_linkedin_to_business_profile","rb2b_linkedin_to_hashed_emails","rb2b_linkedin_to_mobile_phone","rb2b_linkedin_to_personal_email","rds_delete","rds_execute","rds_insert","rds_introspect","rds_query","rds_update","reddit_delete","reddit_edit","reddit_get_comments","reddit_get_controversial","reddit_get_info","reddit_get_me","reddit_get_messages","reddit_get_posts","reddit_get_saved","reddit_get_subreddit_info","reddit_get_subreddit_rules","reddit_get_user","reddit_get_user_comments","reddit_get_user_posts","reddit_hide","reddit_hot_posts","reddit_list_my_subreddits","reddit_lock","reddit_mark_all_read","reddit_mark_read","reddit_marknsfw","reddit_mod_approve","reddit_mod_distinguish","reddit_mod_remove","reddit_mod_sticky","reddit_reply","reddit_report","reddit_save","reddit_search","reddit_search_subreddits","reddit_send_message","reddit_submit_post","reddit_subscribe","reddit_unhide","reddit_unlock","reddit_unmarknsfw","reddit_unsave","reddit_vote","redis_command","redis_delete","redis_exists","redis_expire","redis_get","redis_hdel","redis_hget","redis_hgetall","redis_hset","redis_incr","redis_incrby","redis_keys","redis_llen","redis_lpop","redis_lpush","redis_lrange","redis_persist","redis_rpop","redis_rpush","redis_set","redis_setnx","redis_ttl","reducto_parser","reducto_parser_v2","resend_cancel_email","resend_create_audience","resend_create_broadcast","resend_create_contact","resend_delete_audience","resend_delete_contact","resend_get_audience","resend_get_broadcast","resend_get_contact","resend_get_email","resend_list_audiences","resend_list_contacts","resend_list_domains","resend_send","resend_send_broadcast","resend_update_contact","revenuecat_create_purchase","revenuecat_defer_google_subscription","revenuecat_delete_customer","revenuecat_get_customer","revenuecat_grant_entitlement","revenuecat_list_offerings","revenuecat_refund_google_subscription","revenuecat_revoke_entitlement","revenuecat_revoke_google_subscription","revenuecat_update_subscriber_attributes","rippling_bulk_create_custom_object_records","rippling_bulk_delete_custom_object_records","rippling_bulk_update_custom_object_records","rippling_create_business_partner","rippling_create_business_partner_group","rippling_create_custom_app","rippling_create_custom_object","rippling_create_custom_object_field","rippling_create_custom_object_record","rippling_create_custom_page","rippling_create_custom_setting","rippling_create_department","rippling_create_draft_hires","rippling_create_object_category","rippling_create_title","rippling_create_work_location","rippling_delete_business_partner","rippling_delete_business_partner_group","rippling_delete_custom_app","rippling_delete_custom_object","rippling_delete_custom_object_field","rippling_delete_custom_object_record","rippling_delete_custom_page","rippling_delete_custom_setting","rippling_delete_object_category","rippling_delete_title","rippling_delete_work_location","rippling_get_business_partner","rippling_get_business_partner_group","rippling_get_current_user","rippling_get_custom_app","rippling_get_custom_object","rippling_get_custom_object_field","rippling_get_custom_object_record","rippling_get_custom_object_record_by_external_id","rippling_get_custom_page","rippling_get_custom_setting","rippling_get_department","rippling_get_employment_type","rippling_get_job_function","rippling_get_object_category","rippling_get_report_run","rippling_get_supergroup","rippling_get_team","rippling_get_title","rippling_get_user","rippling_get_work_location","rippling_get_worker","rippling_list_business_partner_groups","rippling_list_business_partners","rippling_list_companies","rippling_list_custom_apps","rippling_list_custom_fields","rippling_list_custom_object_fields","rippling_list_custom_object_records","rippling_list_custom_objects","rippling_list_custom_pages","rippling_list_custom_settings","rippling_list_departments","rippling_list_employment_types","rippling_list_entitlements","rippling_list_job_functions","rippling_list_object_categories","rippling_list_supergroup_exclusion_members","rippling_list_supergroup_inclusion_members","rippling_list_supergroup_members","rippling_list_supergroups","rippling_list_teams","rippling_list_titles","rippling_list_users","rippling_list_work_locations","rippling_list_workers","rippling_query_custom_object_records","rippling_trigger_report_run","rippling_update_custom_app","rippling_update_custom_object","rippling_update_custom_object_field","rippling_update_custom_object_record","rippling_update_custom_page","rippling_update_custom_setting","rippling_update_department","rippling_update_object_category","rippling_update_supergroup_exclusion_members","rippling_update_supergroup_inclusion_members","rippling_update_title","rippling_update_work_location","rocketlane_add_field_option","rocketlane_add_project_members","rocketlane_add_task_assignees","rocketlane_add_task_dependencies","rocketlane_add_task_followers","rocketlane_archive_project","rocketlane_assign_placeholders","rocketlane_create_field","rocketlane_create_phase","rocketlane_create_project","rocketlane_create_space","rocketlane_create_space_document","rocketlane_create_task","rocketlane_create_time_entry","rocketlane_create_time_off","rocketlane_delete_field","rocketlane_delete_phase","rocketlane_delete_project","rocketlane_delete_space","rocketlane_delete_space_document","rocketlane_delete_task","rocketlane_delete_time_entry","rocketlane_delete_time_off","rocketlane_get_field","rocketlane_get_invoice","rocketlane_get_invoice_line_items","rocketlane_get_invoice_payments","rocketlane_get_phase","rocketlane_get_project","rocketlane_get_space","rocketlane_get_space_document","rocketlane_get_task","rocketlane_get_time_entry","rocketlane_get_time_off","rocketlane_get_user","rocketlane_import_template","rocketlane_list_fields","rocketlane_list_invoices","rocketlane_list_phases","rocketlane_list_placeholders","rocketlane_list_projects","rocketlane_list_resource_allocations","rocketlane_list_space_documents","rocketlane_list_spaces","rocketlane_list_tasks","rocketlane_list_time_entries","rocketlane_list_time_entry_categories","rocketlane_list_time_offs","rocketlane_list_users","rocketlane_move_task_to_phase","rocketlane_remove_project_members","rocketlane_remove_task_assignees","rocketlane_remove_task_dependencies","rocketlane_remove_task_followers","rocketlane_search_time_entries","rocketlane_unassign_placeholders","rocketlane_update_field","rocketlane_update_field_option","rocketlane_update_phase","rocketlane_update_project","rocketlane_update_space","rocketlane_update_space_document","rocketlane_update_task","rocketlane_update_time_entry","rootly_acknowledge_alert","rootly_add_incident_event","rootly_add_subscribers","rootly_assign_incident_role","rootly_create_action_item","rootly_create_alert","rootly_create_incident","rootly_create_status_page_event","rootly_delete_action_item","rootly_delete_incident","rootly_escalate_alert","rootly_get_alert","rootly_get_incident","rootly_list_action_items","rootly_list_alerts","rootly_list_causes","rootly_list_environments","rootly_list_escalation_policies","rootly_list_functionalities","rootly_list_incident_events","rootly_list_incident_roles","rootly_list_incident_types","rootly_list_incidents","rootly_list_on_calls","rootly_list_playbooks","rootly_list_retrospectives","rootly_list_schedules","rootly_list_services","rootly_list_severities","rootly_list_teams","rootly_list_users","rootly_mitigate_incident","rootly_remove_subscribers","rootly_resolve_alert","rootly_resolve_incident","rootly_run_workflow","rootly_snooze_alert","rootly_unassign_incident_role","rootly_update_action_item","rootly_update_alert","rootly_update_incident","s3_copy_object","s3_create_bucket","s3_delete_bucket","s3_delete_object","s3_delete_objects","s3_get_object","s3_head_object","s3_list_buckets","s3_list_objects","s3_presigned_url","s3_put_object","sailpoint_approve_access_request","sailpoint_cancel_access_request","sailpoint_decide_certification_review_items","sailpoint_get_access_profile","sailpoint_get_access_profile_entitlements","sailpoint_get_access_request_config","sailpoint_get_access_request_status","sailpoint_get_account","sailpoint_get_account_activity","sailpoint_get_account_entitlements","sailpoint_get_account_selections","sailpoint_get_campaign","sailpoint_get_certification","sailpoint_get_entitlement","sailpoint_get_entitlement_request_config","sailpoint_get_identity","sailpoint_get_role","sailpoint_get_role_entitlements","sailpoint_get_source","sailpoint_get_task_status","sailpoint_list_access_profiles","sailpoint_list_account_activities","sailpoint_list_accounts","sailpoint_list_campaigns","sailpoint_list_certification_review_items","sailpoint_list_certifications","sailpoint_list_entitlements","sailpoint_list_identities","sailpoint_list_identity_entitlements","sailpoint_list_pending_access_request_approvals","sailpoint_list_roles","sailpoint_list_sources","sailpoint_load_accounts","sailpoint_load_entitlements","sailpoint_reject_access_request","sailpoint_request_access","sailpoint_search","sailpoint_search_aggregate","sailpoint_search_count","sailpoint_sign_off_certification","salesforce_create_account","salesforce_create_case","salesforce_create_contact","salesforce_create_custom_field","salesforce_create_custom_object","salesforce_create_lead","salesforce_create_opportunity","salesforce_create_task","salesforce_delete_account","salesforce_delete_case","salesforce_delete_contact","salesforce_delete_custom_field","salesforce_delete_lead","salesforce_delete_opportunity","salesforce_delete_task","salesforce_describe_object","salesforce_get_accounts","salesforce_get_cases","salesforce_get_contacts","salesforce_get_dashboard","salesforce_get_leads","salesforce_get_opportunities","salesforce_get_report","salesforce_get_tasks","salesforce_list_dashboards","salesforce_list_objects","salesforce_list_report_types","salesforce_list_reports","salesforce_query","salesforce_query_more","salesforce_refresh_dashboard","salesforce_run_report","salesforce_tooling_query","salesforce_update_account","salesforce_update_case","salesforce_update_contact","salesforce_update_custom_field","salesforce_update_lead","salesforce_update_opportunity","salesforce_update_task","sap_concur_approve_expense_report","sap_concur_associate_attendees","sap_concur_create_cash_advance","sap_concur_create_expected_expense","sap_concur_create_expense_report","sap_concur_create_list_item","sap_concur_create_purchase_request","sap_concur_create_quick_expense","sap_concur_create_quick_expense_with_image","sap_concur_create_report_comment","sap_concur_create_travel_request","sap_concur_create_user","sap_concur_delete_expected_expense","sap_concur_delete_expense","sap_concur_delete_expense_report","sap_concur_delete_list_item","sap_concur_delete_travel_request","sap_concur_delete_user","sap_concur_get_allocation","sap_concur_get_budget","sap_concur_get_cash_advance","sap_concur_get_expected_expense","sap_concur_get_expense","sap_concur_get_expense_report","sap_concur_get_itemizations","sap_concur_get_itinerary","sap_concur_get_list","sap_concur_get_list_item","sap_concur_get_purchase_request","sap_concur_get_receipt","sap_concur_get_receipt_status","sap_concur_get_request_cash_advance","sap_concur_get_travel_profile","sap_concur_get_travel_request","sap_concur_get_user","sap_concur_issue_cash_advance","sap_concur_list_allocations","sap_concur_list_attendee_associations","sap_concur_list_budget_categories","sap_concur_list_budgets","sap_concur_list_exceptions","sap_concur_list_expected_expenses","sap_concur_list_expense_reports","sap_concur_list_expenses","sap_concur_list_itineraries","sap_concur_list_list_items","sap_concur_list_lists","sap_concur_list_receipts","sap_concur_list_report_comments","sap_concur_list_reports_to_approve","sap_concur_list_travel_profiles_summary","sap_concur_list_travel_request_comments","sap_concur_list_travel_requests","sap_concur_list_users","sap_concur_move_travel_request","sap_concur_recall_expense_report","sap_concur_remove_all_attendees","sap_concur_search_locations","sap_concur_search_users","sap_concur_send_back_expense_report","sap_concur_submit_expense_report","sap_concur_update_allocation","sap_concur_update_expected_expense","sap_concur_update_expense","sap_concur_update_expense_report","sap_concur_update_list_item","sap_concur_update_travel_request","sap_concur_update_user","sap_concur_upload_exchange_rates","sap_concur_upload_receipt_image","sap_s4hana_create_business_partner","sap_s4hana_create_purchase_order","sap_s4hana_create_purchase_requisition","sap_s4hana_create_sales_order","sap_s4hana_delete_sales_order","sap_s4hana_get_billing_document","sap_s4hana_get_business_partner","sap_s4hana_get_customer","sap_s4hana_get_inbound_delivery","sap_s4hana_get_material_document","sap_s4hana_get_outbound_delivery","sap_s4hana_get_product","sap_s4hana_get_purchase_order","sap_s4hana_get_purchase_requisition","sap_s4hana_get_sales_order","sap_s4hana_get_supplier","sap_s4hana_get_supplier_invoice","sap_s4hana_list_billing_documents","sap_s4hana_list_business_partners","sap_s4hana_list_customers","sap_s4hana_list_inbound_deliveries","sap_s4hana_list_material_documents","sap_s4hana_list_material_stock","sap_s4hana_list_outbound_deliveries","sap_s4hana_list_products","sap_s4hana_list_purchase_orders","sap_s4hana_list_purchase_requisitions","sap_s4hana_list_sales_orders","sap_s4hana_list_supplier_invoices","sap_s4hana_list_suppliers","sap_s4hana_odata_query","sap_s4hana_update_business_partner","sap_s4hana_update_customer","sap_s4hana_update_product","sap_s4hana_update_purchase_order","sap_s4hana_update_purchase_requisition","sap_s4hana_update_sales_order","sap_s4hana_update_supplier","search_tool","secrets_manager_create_secret","secrets_manager_delete_secret","secrets_manager_describe_secret","secrets_manager_get_secret","secrets_manager_list_secrets","secrets_manager_restore_secret","secrets_manager_rotate_secret","secrets_manager_tag_resource","secrets_manager_untag_resource","secrets_manager_update_secret","semrush_backlinks","semrush_backlinks_anchors","semrush_backlinks_competitors","semrush_backlinks_geo_distribution","semrush_backlinks_indexed_pages","semrush_backlinks_overview","semrush_backlinks_tld_distribution","semrush_batch_keyword_overview","semrush_broad_match_keywords","semrush_domain_ad_copies","semrush_domain_ad_history","semrush_domain_organic_competitors","semrush_domain_organic_keywords","semrush_domain_overview","semrush_domain_overview_all","semrush_domain_overview_history","semrush_domain_paid_competitors","semrush_domain_paid_keywords","semrush_domain_pla_copies","semrush_domain_pla_keywords","semrush_domain_vs_domain","semrush_keyword_ad_history","semrush_keyword_difficulty","semrush_keyword_overview","semrush_keyword_overview_all","semrush_keyword_questions","semrush_organic_results","semrush_paid_results","semrush_referring_domains","semrush_referring_ips","semrush_related_keywords","semrush_subdomain_ad_copies","semrush_subdomain_organic_keywords","semrush_subdomain_overview","semrush_subdomain_overview_all","semrush_subdomain_overview_history","semrush_subdomain_paid_keywords","semrush_top_domains","semrush_url_organic_keywords","semrush_url_overview","semrush_url_overview_all","semrush_url_overview_history","semrush_url_paid_keywords","semrush_winners_and_losers","sendblue_evaluate_service","sendblue_get_message","sendblue_send_group_message","sendblue_send_message","sendblue_send_typing_indicator","sendgrid_add_contact","sendgrid_add_contacts_to_list","sendgrid_create_list","sendgrid_create_template","sendgrid_create_template_version","sendgrid_delete_contacts","sendgrid_delete_list","sendgrid_delete_template","sendgrid_get_contact","sendgrid_get_list","sendgrid_get_template","sendgrid_list_all_lists","sendgrid_list_templates","sendgrid_remove_contacts_from_list","sendgrid_search_contacts","sendgrid_send_mail","sentry_events_get","sentry_events_list","sentry_issues_get","sentry_issues_list","sentry_issues_update","sentry_projects_create","sentry_projects_get","sentry_projects_list","sentry_projects_update","sentry_releases_create","sentry_releases_deploy","sentry_releases_list","sentry_teams_list","serper_search","servicenow_add_incident_comment","servicenow_aggregate","servicenow_close_incident","servicenow_create_change_request","servicenow_create_incident","servicenow_create_record","servicenow_delete_record","servicenow_download_attachment","servicenow_find_user","servicenow_get_change_next_states","servicenow_get_change_request","servicenow_get_ci","servicenow_get_incident","servicenow_get_knowledge_article","servicenow_get_requested_item","servicenow_list_approvals","servicenow_list_attachments","servicenow_list_catalog_items","servicenow_list_change_requests","servicenow_list_change_tasks","servicenow_list_ci_relationships","servicenow_list_group_members","servicenow_list_incidents","servicenow_list_requested_items","servicenow_order_catalog_item","servicenow_read_record","servicenow_resolve_incident","servicenow_search_cis","servicenow_search_knowledge","servicenow_update_approval","servicenow_update_change_request","servicenow_update_change_state","servicenow_update_incident","servicenow_update_record","servicenow_upload_attachment","ses_create_configuration_set","ses_create_email_identity","ses_create_template","ses_delete_email_identity","ses_delete_suppressed_destination","ses_delete_template","ses_get_account","ses_get_email_identity","ses_get_suppressed_destination","ses_get_template","ses_list_identities","ses_list_suppressed_destinations","ses_list_templates","ses_put_suppressed_destination","ses_send_bulk_email","ses_send_custom_verification_email","ses_send_email","ses_send_templated_email","ses_update_template","sftp_delete","sftp_download","sftp_list","sftp_mkdir","sftp_upload","sharepoint_add_list_items","sharepoint_create_list","sharepoint_create_page","sharepoint_delete_file","sharepoint_delete_list_item","sharepoint_delete_page","sharepoint_download_file","sharepoint_get_drive_item","sharepoint_get_list","sharepoint_get_list_item","sharepoint_list_sites","sharepoint_publish_page","sharepoint_read_page","sharepoint_update_list","sharepoint_update_page","sharepoint_upload_file","shopify_adjust_inventory","shopify_cancel_order","shopify_create_customer","shopify_create_fulfillment","shopify_create_product","shopify_delete_customer","shopify_delete_product","shopify_get_collection","shopify_get_customer","shopify_get_inventory_level","shopify_get_order","shopify_get_product","shopify_list_collections","shopify_list_customers","shopify_list_inventory_items","shopify_list_locations","shopify_list_orders","shopify_list_products","shopify_update_customer","shopify_update_order","shopify_update_product","similarweb_bounce_rate","similarweb_page_views","similarweb_pages_per_visit","similarweb_traffic_visits","similarweb_visit_duration","similarweb_website_overview","sixtyfour_enrich_company","sixtyfour_enrich_lead","sixtyfour_find_email","sixtyfour_find_phone","slack_add_reaction","slack_archive_conversation","slack_canvas","slack_create_channel_canvas","slack_create_conversation","slack_delete_canvas","slack_delete_message","slack_delete_scheduled_message","slack_download","slack_edit_canvas","slack_ephemeral_message","slack_get_canvas","slack_get_channel_history","slack_get_channel_info","slack_get_message","slack_get_permalink","slack_get_thread","slack_get_thread_replies","slack_get_user","slack_get_user_presence","slack_invite_to_conversation","slack_list_canvases","slack_list_channels","slack_list_members","slack_list_scheduled_messages","slack_list_users","slack_lookup_canvas_sections","slack_message","slack_message_reader","slack_open_view","slack_publish_view","slack_push_view","slack_remove_reaction","slack_rename_agent_session_v2","slack_rename_conversation","slack_schedule_message","slack_set_agent_session_status_v2","slack_set_conversation_purpose","slack_set_conversation_topic","slack_set_status","slack_set_suggested_prompts","slack_set_suggested_prompts_v2","slack_set_title","slack_update_message","slack_update_view","smartlead_add_email_accounts_to_campaign","smartlead_add_leads_to_campaign","smartlead_create_campaign","smartlead_create_lead_list","smartlead_delete_campaign","smartlead_delete_campaign_webhook","smartlead_delete_lead_from_campaign","smartlead_delete_lead_list","smartlead_duplicate_campaign","smartlead_export_campaign_leads","smartlead_get_campaign","smartlead_get_campaign_analytics","smartlead_get_campaign_analytics_by_date","smartlead_get_campaign_lead_statistics","smartlead_get_campaign_mailbox_statistics","smartlead_get_campaign_sequences","smartlead_get_campaign_statistics","smartlead_get_campaign_top_level_analytics_by_date","smartlead_get_campaign_webhook_summary","smartlead_get_lead_by_email","smartlead_get_lead_by_id","smartlead_get_lead_list","smartlead_get_lead_message_history","smartlead_list_campaign_email_accounts","smartlead_list_campaign_leads","smartlead_list_campaign_webhooks","smartlead_list_campaigns","smartlead_list_clients","smartlead_list_email_accounts","smartlead_list_inbox_replies","smartlead_list_lead_activities","smartlead_list_lead_categories","smartlead_list_lead_lists","smartlead_mark_lead_complete","smartlead_pause_lead","smartlead_remove_email_accounts_from_campaign","smartlead_resume_lead","smartlead_save_campaign_sequences","smartlead_unsubscribe_lead_from_campaign","smartlead_unsubscribe_lead_globally","smartlead_update_campaign_schedule","smartlead_update_campaign_settings","smartlead_update_campaign_status","smartlead_update_lead","smartlead_update_lead_category","smartlead_update_lead_list","smartlead_upsert_campaign_webhook","sms_send","smtp_send_mail","snowflake_alter_warehouse","snowflake_call_procedure","snowflake_cancel_statement","snowflake_cancel_task_run","snowflake_delete_rows","snowflake_execute_sql","snowflake_get_statement","snowflake_get_task","snowflake_get_task_run","snowflake_get_task_run_output","snowflake_get_warehouse","snowflake_insert_rows","snowflake_introspect_schema","snowflake_list_copy_history","snowflake_list_databases","snowflake_list_query_history","snowflake_list_schemas","snowflake_list_tables","snowflake_list_task_runs","snowflake_list_tasks","snowflake_list_warehouses","snowflake_load_data","snowflake_resume_task","snowflake_resume_warehouse","snowflake_run_task","snowflake_suspend_task","snowflake_suspend_warehouse","snowflake_unload_data","snowflake_update_rows","snowflake_upsert_rows","splunk_cancel_search_job","splunk_create_search_job","splunk_dispatch_saved_search","splunk_get_fired_alerts","splunk_get_saved_search","splunk_get_search_job","splunk_get_search_results","splunk_list_apps","splunk_list_fired_alerts","splunk_list_indexes","splunk_list_saved_searches","splunk_run_search","sportmonks_core_get_cities","sportmonks_core_get_city","sportmonks_core_get_continent","sportmonks_core_get_continents","sportmonks_core_get_countries","sportmonks_core_get_country","sportmonks_core_get_entity_filters","sportmonks_core_get_my_usage","sportmonks_core_get_region","sportmonks_core_get_regions","sportmonks_core_get_timezones","sportmonks_core_get_type","sportmonks_core_get_type_by_entity","sportmonks_core_get_types","sportmonks_core_search_cities","sportmonks_core_search_countries","sportmonks_core_search_regions","sportmonks_football_expected_by_player","sportmonks_football_expected_by_team","sportmonks_football_get_all_commentaries","sportmonks_football_get_all_fixtures","sportmonks_football_get_all_players","sportmonks_football_get_all_rivals","sportmonks_football_get_all_teams","sportmonks_football_get_all_transfer_rumours","sportmonks_football_get_all_transfers","sportmonks_football_get_brackets_by_season","sportmonks_football_get_coach","sportmonks_football_get_coaches","sportmonks_football_get_coaches_by_country","sportmonks_football_get_commentaries_by_fixture","sportmonks_football_get_current_leagues_by_team","sportmonks_football_get_expected_lineups_by_player","sportmonks_football_get_expected_lineups_by_team","sportmonks_football_get_extended_team_squad","sportmonks_football_get_fixture","sportmonks_football_get_fixtures_by_date","sportmonks_football_get_fixtures_by_date_range","sportmonks_football_get_fixtures_by_date_range_for_team","sportmonks_football_get_fixtures_by_ids","sportmonks_football_get_grouped_standings_by_round","sportmonks_football_get_head_to_head","sportmonks_football_get_inplay_livescores","sportmonks_football_get_latest_coaches","sportmonks_football_get_latest_fixtures","sportmonks_football_get_latest_livescores","sportmonks_football_get_latest_players","sportmonks_football_get_latest_totw","sportmonks_football_get_latest_transfers","sportmonks_football_get_league","sportmonks_football_get_leagues","sportmonks_football_get_leagues_by_country","sportmonks_football_get_leagues_by_date","sportmonks_football_get_leagues_by_team","sportmonks_football_get_live_leagues","sportmonks_football_get_live_probabilities","sportmonks_football_get_live_probabilities_by_fixture","sportmonks_football_get_live_standings_by_league","sportmonks_football_get_livescores","sportmonks_football_get_match_facts","sportmonks_football_get_match_facts_by_date_range","sportmonks_football_get_match_facts_by_fixture","sportmonks_football_get_match_facts_by_league","sportmonks_football_get_past_fixtures_by_tv_station","sportmonks_football_get_player","sportmonks_football_get_players_by_country","sportmonks_football_get_postmatch_news","sportmonks_football_get_postmatch_news_by_season","sportmonks_football_get_predictability_by_league","sportmonks_football_get_prematch_news","sportmonks_football_get_prematch_news_by_season","sportmonks_football_get_prematch_news_upcoming","sportmonks_football_get_probabilities","sportmonks_football_get_probabilities_by_fixture","sportmonks_football_get_referee","sportmonks_football_get_referees","sportmonks_football_get_referees_by_country","sportmonks_football_get_referees_by_season","sportmonks_football_get_rivals_by_team","sportmonks_football_get_round","sportmonks_football_get_round_statistics","sportmonks_football_get_rounds","sportmonks_football_get_rounds_by_season","sportmonks_football_get_schedules_by_season","sportmonks_football_get_schedules_by_season_and_team","sportmonks_football_get_schedules_by_team","sportmonks_football_get_season","sportmonks_football_get_seasons","sportmonks_football_get_seasons_by_team","sportmonks_football_get_stage","sportmonks_football_get_stage_statistics","sportmonks_football_get_stages","sportmonks_football_get_stages_by_season","sportmonks_football_get_standing_corrections_by_season","sportmonks_football_get_standings","sportmonks_football_get_standings_by_round","sportmonks_football_get_standings_by_season","sportmonks_football_get_state","sportmonks_football_get_states","sportmonks_football_get_team","sportmonks_football_get_team_rankings","sportmonks_football_get_team_rankings_by_date","sportmonks_football_get_team_rankings_by_team","sportmonks_football_get_team_squad","sportmonks_football_get_team_squad_by_season","sportmonks_football_get_teams_by_country","sportmonks_football_get_teams_by_season","sportmonks_football_get_topscorers_by_season","sportmonks_football_get_topscorers_by_stage","sportmonks_football_get_totw","sportmonks_football_get_totw_by_round","sportmonks_football_get_transfer","sportmonks_football_get_transfer_rumour","sportmonks_football_get_transfer_rumours_between_dates","sportmonks_football_get_transfer_rumours_by_player","sportmonks_football_get_transfer_rumours_by_team","sportmonks_football_get_transfers_between_dates","sportmonks_football_get_transfers_by_player","sportmonks_football_get_transfers_by_team","sportmonks_football_get_tv_station","sportmonks_football_get_tv_stations","sportmonks_football_get_tv_stations_by_fixture","sportmonks_football_get_upcoming_fixtures_by_market","sportmonks_football_get_upcoming_fixtures_by_tv_station","sportmonks_football_get_value_bets","sportmonks_football_get_value_bets_by_fixture","sportmonks_football_get_venue","sportmonks_football_get_venues","sportmonks_football_get_venues_by_season","sportmonks_football_search_coaches","sportmonks_football_search_fixtures","sportmonks_football_search_leagues","sportmonks_football_search_players","sportmonks_football_search_referees","sportmonks_football_search_rounds","sportmonks_football_search_seasons","sportmonks_football_search_stages","sportmonks_football_search_teams","sportmonks_football_search_venues","sportmonks_motorsport_get_all_fixtures","sportmonks_motorsport_get_current_leagues_by_team","sportmonks_motorsport_get_driver","sportmonks_motorsport_get_driver_standings","sportmonks_motorsport_get_driver_standings_by_season","sportmonks_motorsport_get_drivers","sportmonks_motorsport_get_drivers_by_country","sportmonks_motorsport_get_drivers_by_season","sportmonks_motorsport_get_fixture","sportmonks_motorsport_get_fixtures_by_date","sportmonks_motorsport_get_fixtures_by_date_range","sportmonks_motorsport_get_fixtures_by_ids","sportmonks_motorsport_get_laps_by_fixture","sportmonks_motorsport_get_laps_by_fixture_and_driver","sportmonks_motorsport_get_laps_by_fixture_and_lap","sportmonks_motorsport_get_latest_laps_by_fixture","sportmonks_motorsport_get_latest_pitstops_by_fixture","sportmonks_motorsport_get_latest_stints_by_fixture","sportmonks_motorsport_get_latest_updated_drivers","sportmonks_motorsport_get_latest_updated_fixtures","sportmonks_motorsport_get_league","sportmonks_motorsport_get_leagues","sportmonks_motorsport_get_leagues_by_country","sportmonks_motorsport_get_leagues_by_date","sportmonks_motorsport_get_leagues_by_live","sportmonks_motorsport_get_leagues_by_team","sportmonks_motorsport_get_livescores","sportmonks_motorsport_get_pitstops_by_fixture","sportmonks_motorsport_get_pitstops_by_fixture_and_driver","sportmonks_motorsport_get_pitstops_by_fixture_and_lap","sportmonks_motorsport_get_race_results_by_season_and_driver","sportmonks_motorsport_get_race_results_by_season_and_team","sportmonks_motorsport_get_schedules_by_season","sportmonks_motorsport_get_season","sportmonks_motorsport_get_seasons","sportmonks_motorsport_get_stage","sportmonks_motorsport_get_stages","sportmonks_motorsport_get_stages_by_season","sportmonks_motorsport_get_state","sportmonks_motorsport_get_states","sportmonks_motorsport_get_stints_by_fixture","sportmonks_motorsport_get_stints_by_fixture_and_driver","sportmonks_motorsport_get_stints_by_fixture_and_stint","sportmonks_motorsport_get_team","sportmonks_motorsport_get_team_standings","sportmonks_motorsport_get_team_standings_by_season","sportmonks_motorsport_get_teams","sportmonks_motorsport_get_teams_by_country","sportmonks_motorsport_get_teams_by_season","sportmonks_motorsport_get_venue","sportmonks_motorsport_get_venues","sportmonks_motorsport_get_venues_by_season","sportmonks_motorsport_search_drivers","sportmonks_motorsport_search_leagues","sportmonks_motorsport_search_stages","sportmonks_motorsport_search_teams","sportmonks_motorsport_search_venues","sportmonks_odds_get_all_historical_odds","sportmonks_odds_get_all_inplay_odds","sportmonks_odds_get_all_pre_match_odds","sportmonks_odds_get_all_premium_odds","sportmonks_odds_get_bookmaker","sportmonks_odds_get_bookmaker_event_ids_by_fixture","sportmonks_odds_get_bookmakers","sportmonks_odds_get_bookmakers_by_fixture","sportmonks_odds_get_inplay_odds_by_fixture","sportmonks_odds_get_inplay_odds_by_fixture_and_bookmaker","sportmonks_odds_get_inplay_odds_by_fixture_and_market","sportmonks_odds_get_last_updated_inplay_odds","sportmonks_odds_get_last_updated_pre_match_odds","sportmonks_odds_get_market","sportmonks_odds_get_markets","sportmonks_odds_get_pre_match_odds_by_fixture","sportmonks_odds_get_pre_match_odds_by_fixture_and_bookmaker","sportmonks_odds_get_pre_match_odds_by_fixture_and_market","sportmonks_odds_get_premium_odds_by_fixture","sportmonks_odds_get_premium_odds_by_fixture_and_bookmaker","sportmonks_odds_get_premium_odds_by_fixture_and_market","sportmonks_odds_get_updated_historical_odds_between","sportmonks_odds_get_updated_premium_odds_between","sportmonks_odds_search_bookmakers","sportmonks_odds_search_markets","spotify_add_playlist_cover","spotify_add_to_queue","spotify_add_tracks_to_playlist","spotify_check_following","spotify_check_playlist_followers","spotify_check_saved_albums","spotify_check_saved_audiobooks","spotify_check_saved_episodes","spotify_check_saved_shows","spotify_check_saved_tracks","spotify_create_playlist","spotify_follow_artists","spotify_follow_playlist","spotify_get_album","spotify_get_album_tracks","spotify_get_albums","spotify_get_artist","spotify_get_artist_albums","spotify_get_artist_top_tracks","spotify_get_artists","spotify_get_audiobook","spotify_get_audiobook_chapters","spotify_get_audiobooks","spotify_get_categories","spotify_get_current_user","spotify_get_currently_playing","spotify_get_devices","spotify_get_episode","spotify_get_episodes","spotify_get_followed_artists","spotify_get_markets","spotify_get_new_releases","spotify_get_playback_state","spotify_get_playlist","spotify_get_playlist_cover","spotify_get_playlist_tracks","spotify_get_queue","spotify_get_recently_played","spotify_get_saved_albums","spotify_get_saved_audiobooks","spotify_get_saved_episodes","spotify_get_saved_shows","spotify_get_saved_tracks","spotify_get_show","spotify_get_show_episodes","spotify_get_shows","spotify_get_top_artists","spotify_get_top_tracks","spotify_get_track","spotify_get_tracks","spotify_get_user_playlists","spotify_get_user_profile","spotify_pause","spotify_play","spotify_remove_saved_albums","spotify_remove_saved_audiobooks","spotify_remove_saved_episodes","spotify_remove_saved_shows","spotify_remove_saved_tracks","spotify_remove_tracks_from_playlist","spotify_reorder_playlist_items","spotify_replace_playlist_items","spotify_save_albums","spotify_save_audiobooks","spotify_save_episodes","spotify_save_shows","spotify_save_tracks","spotify_search","spotify_seek","spotify_set_repeat","spotify_set_shuffle","spotify_set_volume","spotify_skip_next","spotify_skip_previous","spotify_transfer_playback","spotify_unfollow_artists","spotify_unfollow_playlist","spotify_update_playlist","sqs_cancel_message_move_task","sqs_change_message_visibility","sqs_change_message_visibility_batch","sqs_create_queue","sqs_delete_message","sqs_delete_message_batch","sqs_delete_queue","sqs_get_queue_attributes","sqs_get_queue_url","sqs_list_dead_letter_source_queues","sqs_list_message_move_tasks","sqs_list_queue_tags","sqs_list_queues","sqs_purge_queue","sqs_receive_message","sqs_send","sqs_send_message_batch","sqs_set_queue_attributes","sqs_start_message_move_task","sqs_tag_queue","sqs_untag_queue","square_batch_retrieve_inventory_counts","square_cancel_invoice","square_cancel_payment","square_complete_payment","square_create_catalog_image","square_create_customer","square_create_invoice","square_create_order","square_create_payment","square_delete_catalog_object","square_delete_customer","square_delete_invoice","square_get_catalog_object","square_get_customer","square_get_invoice","square_get_location","square_get_order","square_get_payment","square_get_refund","square_list_catalog","square_list_customers","square_list_invoices","square_list_locations","square_list_payments","square_list_refunds","square_pay_order","square_publish_invoice","square_refund_payment","square_search_catalog_objects","square_search_customers","square_search_invoices","square_search_orders","square_update_customer","square_upsert_catalog_object","ssh_check_command_exists","ssh_check_file_exists","ssh_create_directory","ssh_delete_file","ssh_download_file","ssh_execute_command","ssh_execute_script","ssh_get_system_info","ssh_list_directory","ssh_move_rename","ssh_read_file_content","ssh_upload_file","ssh_write_file_content","ssm_cancel_command","ssm_delete_parameter","ssm_describe_automation_executions","ssm_describe_instance_information","ssm_describe_instance_patch_states","ssm_describe_instance_patches","ssm_describe_parameters","ssm_get_automation_execution","ssm_get_command_invocation","ssm_get_document","ssm_get_parameter","ssm_get_parameters","ssm_get_parameters_by_path","ssm_list_command_invocations","ssm_list_commands","ssm_list_compliance_items","ssm_list_compliance_summaries","ssm_list_documents","ssm_put_parameter","ssm_send_command","ssm_start_automation_execution","ssm_stop_automation_execution","stagehand_agent","stagehand_extract","stripe_cancel_payment_intent","stripe_cancel_subscription","stripe_capture_charge","stripe_capture_payment_intent","stripe_confirm_payment_intent","stripe_create_charge","stripe_create_customer","stripe_create_invoice","stripe_create_payment_intent","stripe_create_price","stripe_create_product","stripe_create_subscription","stripe_delete_customer","stripe_delete_invoice","stripe_delete_product","stripe_finalize_invoice","stripe_list_charges","stripe_list_customers","stripe_list_events","stripe_list_invoices","stripe_list_payment_intents","stripe_list_prices","stripe_list_products","stripe_list_subscriptions","stripe_pay_invoice","stripe_resume_subscription","stripe_retrieve_charge","stripe_retrieve_customer","stripe_retrieve_event","stripe_retrieve_invoice","stripe_retrieve_payment_intent","stripe_retrieve_price","stripe_retrieve_product","stripe_retrieve_subscription","stripe_search_charges","stripe_search_customers","stripe_search_invoices","stripe_search_payment_intents","stripe_search_prices","stripe_search_products","stripe_search_subscriptions","stripe_send_invoice","stripe_update_charge","stripe_update_customer","stripe_update_invoice","stripe_update_payment_intent","stripe_update_price","stripe_update_product","stripe_update_subscription","stripe_void_invoice","sts_assume_role","sts_assume_role_with_saml","sts_assume_role_with_web_identity","sts_get_access_key_info","sts_get_caller_identity","sts_get_session_token","stt_assemblyai","stt_assemblyai_v2","stt_deepgram","stt_deepgram_v2","stt_elevenlabs","stt_elevenlabs_v2","stt_gemini","stt_gemini_v2","stt_whisper","stt_whisper_v2","supabase_count","supabase_delete","supabase_get_row","supabase_insert","supabase_introspect","supabase_invoke_function","supabase_query","supabase_rpc","supabase_storage_copy","supabase_storage_create_bucket","supabase_storage_create_signed_upload_url","supabase_storage_create_signed_url","supabase_storage_delete","supabase_storage_delete_bucket","supabase_storage_download","supabase_storage_empty_bucket","supabase_storage_get_public_url","supabase_storage_list","supabase_storage_list_buckets","supabase_storage_move","supabase_storage_update_bucket","supabase_storage_upload","supabase_text_search","supabase_update","supabase_upsert","supabase_vector_search","table_batch_insert_rows","table_create","table_delete_row","table_delete_rows_by_filter","table_get_row","table_get_schema","table_insert_row","table_list","table_query_rows","table_query_rows_v2","table_update_row","table_update_rows_by_filter","table_upsert_row","tailscale_authorize_device","tailscale_create_auth_key","tailscale_delete_auth_key","tailscale_delete_device","tailscale_delete_user","tailscale_expire_device_key","tailscale_get_acl","tailscale_get_auth_key","tailscale_get_device","tailscale_get_device_routes","tailscale_get_dns_preferences","tailscale_get_dns_searchpaths","tailscale_list_auth_keys","tailscale_list_devices","tailscale_list_dns_nameservers","tailscale_list_users","tailscale_set_acl","tailscale_set_device_routes","tailscale_set_device_tags","tailscale_set_dns_nameservers","tailscale_set_dns_preferences","tailscale_set_dns_searchpaths","tailscale_suspend_user","tailscale_update_device_key","tavily_crawl","tavily_extract","tavily_map","tavily_search","telegram_copy_message","telegram_delete_message","telegram_edit_message_text","telegram_forward_message","telegram_get_chat","telegram_get_chat_member","telegram_message","telegram_pin_message","telegram_send_animation","telegram_send_audio","telegram_send_chat_action","telegram_send_contact","telegram_send_document","telegram_send_location","telegram_send_photo","telegram_send_poll","telegram_send_video","telegram_set_message_reaction","telegram_unpin_message","temporal_cancel_workflow","temporal_count_workflows","temporal_create_schedule","temporal_delete_schedule","temporal_describe_schedule","temporal_describe_task_queue","temporal_describe_workflow","temporal_get_workflow_history","temporal_list_schedules","temporal_list_workflows","temporal_pause_schedule","temporal_query_workflow","temporal_reset_workflow","temporal_signal_with_start","temporal_signal_workflow","temporal_start_workflow","temporal_terminate_workflow","temporal_trigger_schedule","temporal_unpause_schedule","temporal_update_workflow","textract_analyze_expense","textract_analyze_id","textract_parser","textract_parser_v2","thinking_tool","thrive_add_audience_managers","thrive_add_audience_members","thrive_add_user_tags","thrive_create_assignment","thrive_create_audience","thrive_create_completion","thrive_create_user","thrive_delete_assignment","thrive_delete_audience","thrive_delete_user","thrive_get_activity","thrive_get_assignment","thrive_get_audience","thrive_get_completion","thrive_get_content","thrive_get_cpd_category","thrive_get_cpd_entry","thrive_get_cpd_requirement","thrive_get_enrolment","thrive_get_skill_levels","thrive_get_tag","thrive_get_user_by_id","thrive_get_user_by_ref","thrive_list_assignments","thrive_list_audience_managers","thrive_list_audience_members","thrive_list_audiences","thrive_list_completions","thrive_list_enrolments","thrive_list_tags","thrive_query_activities","thrive_query_content","thrive_query_cpd_categories","thrive_query_cpd_entries","thrive_query_cpd_requirements","thrive_query_cpd_user_summaries","thrive_remove_audience_manager","thrive_remove_audience_member","thrive_remove_user_tags","thrive_replace_audience_managers","thrive_replace_audience_members","thrive_search_users","thrive_suspend_user","thrive_update_assignment","thrive_update_audience","thrive_update_user","thrive_update_user_skills","tiktok_get_post_status","tiktok_get_user","tiktok_list_videos","tiktok_query_videos","tiktok_upload_video_draft","tinybird_append_datasource","tinybird_delete_datasource_rows","tinybird_events","tinybird_get_job","tinybird_query","tinybird_query_pipe","tinybird_truncate_datasource","tinyfish_cancel_run","tinyfish_fetch","tinyfish_get_run","tinyfish_list_profiles","tinyfish_list_runs","tinyfish_list_vault_items","tinyfish_run","tinyfish_run_async","tinyfish_search","trello_add_checklist","trello_add_checklist_item","trello_add_comment","trello_add_label","trello_add_member","trello_create_board","trello_create_card","trello_create_list","trello_delete_card","trello_get_actions","trello_get_board","trello_get_card","trello_list_cards","trello_list_lists","trello_list_members","trello_remove_label","trello_remove_member","trello_search","trello_update_card","trello_update_checklist_item","trello_update_list","trigger_dev_activate_schedule","trigger_dev_add_run_tags","trigger_dev_batch_trigger_task","trigger_dev_cancel_run","trigger_dev_complete_waitpoint_token","trigger_dev_create_env_var","trigger_dev_create_schedule","trigger_dev_create_waitpoint_token","trigger_dev_deactivate_schedule","trigger_dev_delete_env_var","trigger_dev_delete_schedule","trigger_dev_execute_query","trigger_dev_get_batch","trigger_dev_get_batch_results","trigger_dev_get_deployment","trigger_dev_get_env_var","trigger_dev_get_latest_deployment","trigger_dev_get_query_schema","trigger_dev_get_queue","trigger_dev_get_run","trigger_dev_get_run_events","trigger_dev_get_run_result","trigger_dev_get_run_trace","trigger_dev_get_schedule","trigger_dev_get_waitpoint_token","trigger_dev_import_env_vars","trigger_dev_list_deployments","trigger_dev_list_env_vars","trigger_dev_list_queues","trigger_dev_list_runs","trigger_dev_list_schedules","trigger_dev_list_timezones","trigger_dev_list_waitpoint_tokens","trigger_dev_override_queue_concurrency","trigger_dev_pause_queue","trigger_dev_promote_deployment","trigger_dev_replay_run","trigger_dev_reschedule_run","trigger_dev_reset_queue_concurrency","trigger_dev_resume_queue","trigger_dev_trigger_task","trigger_dev_update_env_var","trigger_dev_update_run_metadata","trigger_dev_update_schedule","tts_azure","tts_cartesia","tts_deepgram","tts_elevenlabs","tts_google","tts_openai","tts_playht","twilio_send_sms","twilio_voice_get_recording","twilio_voice_list_calls","twilio_voice_make_call","typeform_create_form","typeform_delete_form","typeform_files","typeform_get_form","typeform_insights","typeform_list_forms","typeform_responses","typeform_update_form","upstash_redis_command","upstash_redis_delete","upstash_redis_exists","upstash_redis_expire","upstash_redis_get","upstash_redis_hget","upstash_redis_hgetall","upstash_redis_hset","upstash_redis_incr","upstash_redis_incrby","upstash_redis_keys","upstash_redis_lpush","upstash_redis_lrange","upstash_redis_set","upstash_redis_setnx","upstash_redis_ttl","uptimerobot_create_alert_contact","uptimerobot_create_maintenance_window","uptimerobot_create_monitor","uptimerobot_create_psp","uptimerobot_delete_alert_contact","uptimerobot_delete_maintenance_window","uptimerobot_delete_monitor","uptimerobot_delete_psp","uptimerobot_get_account","uptimerobot_get_alert_contact","uptimerobot_get_incident","uptimerobot_get_maintenance_window","uptimerobot_get_monitor","uptimerobot_get_psp","uptimerobot_list_alert_contacts","uptimerobot_list_incidents","uptimerobot_list_maintenance_windows","uptimerobot_list_monitors","uptimerobot_list_psps","uptimerobot_pause_monitor","uptimerobot_start_monitor","uptimerobot_update_maintenance_window","uptimerobot_update_monitor","uptimerobot_update_psp","vanta_download_document_file","vanta_get_control","vanta_get_document","vanta_get_framework","vanta_get_person","vanta_get_policy","vanta_get_risk_scenario","vanta_get_test","vanta_get_vendor","vanta_get_vulnerable_asset","vanta_list_control_documents","vanta_list_control_tests","vanta_list_controls","vanta_list_document_uploads","vanta_list_documents","vanta_list_framework_controls","vanta_list_frameworks","vanta_list_monitored_computers","vanta_list_people","vanta_list_policies","vanta_list_risk_scenarios","vanta_list_test_entities","vanta_list_tests","vanta_list_vendors","vanta_list_vulnerabilities","vanta_list_vulnerability_remediations","vanta_list_vulnerable_assets","vanta_submit_document","vanta_upload_document_file","vercel_add_domain","vercel_add_project_domain","vercel_cancel_deployment","vercel_create_alias","vercel_create_check","vercel_create_deployment","vercel_create_dns_record","vercel_create_edge_config","vercel_create_env_var","vercel_create_project","vercel_create_webhook","vercel_delete_alias","vercel_delete_deployment","vercel_delete_dns_record","vercel_delete_domain","vercel_delete_edge_config","vercel_delete_env_var","vercel_delete_project","vercel_delete_webhook","vercel_get_alias","vercel_get_check","vercel_get_deployment","vercel_get_deployment_events","vercel_get_domain","vercel_get_domain_config","vercel_get_edge_config","vercel_get_edge_config_items","vercel_get_env_vars","vercel_get_project","vercel_get_team","vercel_get_user","vercel_get_webhook","vercel_list_aliases","vercel_list_checks","vercel_list_deployment_files","vercel_list_deployments","vercel_list_dns_records","vercel_list_domains","vercel_list_edge_configs","vercel_list_project_domains","vercel_list_projects","vercel_list_team_members","vercel_list_teams","vercel_list_webhooks","vercel_pause_project","vercel_promote_deployment","vercel_remove_project_domain","vercel_rerequest_check","vercel_unpause_project","vercel_update_check","vercel_update_dns_record","vercel_update_edge_config_items","vercel_update_env_var","vercel_update_project","vercel_update_project_domain","vercel_verify_project_domain","video_falai","video_luma","video_minimax","video_runway","video_veo","vision_tool","vision_tool_v2","wealthbox_read_contact","wealthbox_read_note","wealthbox_read_task","wealthbox_write_contact","wealthbox_write_note","wealthbox_write_task","webflow_create_item","webflow_delete_item","webflow_get_item","webflow_list_items","webflow_update_item","webhook_request","whatsapp_get_media","whatsapp_mark_read","whatsapp_send_interactive","whatsapp_send_media","whatsapp_send_message","whatsapp_send_reaction","whatsapp_send_template","whatsapp_upload_media","wikipedia_content","wikipedia_random","wikipedia_search","wikipedia_summary","windchill_check_in_document","windchill_check_in_documents","windchill_check_out_document","windchill_check_out_documents","windchill_create_document","windchill_create_documents","windchill_delete_document","windchill_delete_documents","windchill_download_attachment","windchill_download_primary_content","windchill_get_document","windchill_get_document_structure","windchill_get_primary_content","windchill_get_valid_state_transitions","windchill_list_attachments","windchill_list_documents","windchill_revise_document","windchill_revise_documents","windchill_set_lifecycle_state","windchill_undo_check_out_document","windchill_undo_check_out_documents","windchill_update_common_properties","windchill_update_document","windchill_update_document_security_labels","windchill_update_documents","windchill_upload_attachments","windchill_upload_primary_content","wiza_company_enrichment","wiza_get_credits","wiza_individual_reveal","wiza_prospect_search","wordpress_create_category","wordpress_create_comment","wordpress_create_page","wordpress_create_post","wordpress_create_tag","wordpress_delete_category","wordpress_delete_comment","wordpress_delete_media","wordpress_delete_page","wordpress_delete_post","wordpress_delete_tag","wordpress_get_category","wordpress_get_current_user","wordpress_get_media","wordpress_get_page","wordpress_get_post","wordpress_get_tag","wordpress_get_user","wordpress_list_categories","wordpress_list_comments","wordpress_list_media","wordpress_list_pages","wordpress_list_posts","wordpress_list_tags","wordpress_list_users","wordpress_search_content","wordpress_update_category","wordpress_update_comment","wordpress_update_page","wordpress_update_post","wordpress_update_tag","wordpress_upload_media","workday_assign_onboarding","workday_change_job","workday_create_prehire","workday_get_compensation","workday_get_organizations","workday_get_worker","workday_hire_employee","workday_list_workers","workday_terminate_worker","workday_update_worker","workflow_executor","x_create_bookmark","x_create_tweet","x_delete_bookmark","x_delete_tweet","x_get_blocking","x_get_bookmarks","x_get_followers","x_get_following","x_get_liked_tweets","x_get_liking_users","x_get_me","x_get_personalized_trends","x_get_quote_tweets","x_get_retweeted_by","x_get_trends_by_woeid","x_get_tweets_by_ids","x_get_usage","x_get_user_mentions","x_get_user_timeline","x_get_user_tweets","x_hide_reply","x_manage_block","x_manage_follow","x_manage_like","x_manage_mute","x_manage_retweet","x_read","x_search","x_search_tweets","x_search_users","x_user","x_write","youtube_channel_info","youtube_channel_playlists","youtube_channel_videos","youtube_comments","youtube_playlist_items","youtube_search","youtube_trending","youtube_video_categories","youtube_video_details","zendesk_autocomplete_organizations","zendesk_create_organization","zendesk_create_organizations_bulk","zendesk_create_ticket","zendesk_create_tickets_bulk","zendesk_create_user","zendesk_create_users_bulk","zendesk_delete_organization","zendesk_delete_ticket","zendesk_delete_user","zendesk_get_current_user","zendesk_get_organization","zendesk_get_organizations","zendesk_get_ticket","zendesk_get_tickets","zendesk_get_user","zendesk_get_users","zendesk_merge_tickets","zendesk_search","zendesk_search_count","zendesk_search_users","zendesk_update_organization","zendesk_update_ticket","zendesk_update_tickets_bulk","zendesk_update_user","zendesk_update_users_bulk","zep_add_messages","zep_add_user","zep_create_thread","zep_delete_thread","zep_get_context","zep_get_messages","zep_get_threads","zep_get_user","zep_get_user_threads","zerobounce_get_credits","zerobounce_verify_email","zoho_desk_add_comment","zoho_desk_get_attachment","zoho_desk_get_contact","zoho_desk_get_thread","zoho_desk_get_ticket","zoho_desk_list_comments","zoho_desk_list_organizations","zoho_desk_list_threads","zoho_desk_list_tickets","zoho_desk_update_ticket","zoom_create_meeting","zoom_delete_meeting","zoom_delete_recording","zoom_get_meeting","zoom_get_meeting_invitation","zoom_get_meeting_recordings","zoom_list_meetings","zoom_list_past_participants","zoom_list_recordings","zoom_update_meeting","zoominfo_enrich_companies","zoominfo_enrich_contacts","zoominfo_search_companies","zoominfo_search_contacts","zoominfo_search_intent","zoominfo_search_news"]' + '["a2a_cancel_task","a2a_get_agent_card","a2a_get_task","a2a_send_message","affinity_batch_update_entity_fields","affinity_batch_update_list_entry_fields","affinity_create_list","affinity_create_list_field_dropdown_option","affinity_create_merge","affinity_create_note","affinity_create_reminder","affinity_delete_list_field_dropdown_option","affinity_delete_note","affinity_get_company","affinity_get_current_user","affinity_get_entity_field_value","affinity_get_list","affinity_get_list_entry","affinity_get_list_entry_field","affinity_get_list_field_dropdown_option","affinity_get_merge","affinity_get_merge_task","affinity_get_note","affinity_get_opportunity","affinity_get_person","affinity_get_saved_view","affinity_get_transcript","affinity_get_user","affinity_list_calls","affinity_list_chat_messages","affinity_list_companies","affinity_list_coworker_connections","affinity_list_emails","affinity_list_entity_field_values","affinity_list_entity_list_entries","affinity_list_entity_lists","affinity_list_entity_notes","affinity_list_entity_relationships","affinity_list_field_dropdown_options","affinity_list_field_metadata","affinity_list_field_value_changes","affinity_list_investor_executive_connections","affinity_list_list_entries","affinity_list_list_entry_field_value_changes","affinity_list_list_entry_fields","affinity_list_list_field_dropdown_options","affinity_list_list_fields","affinity_list_lists","affinity_list_meetings","affinity_list_merge_tasks","affinity_list_merges","affinity_list_note_attached_companies","affinity_list_note_attached_opportunities","affinity_list_note_attached_persons","affinity_list_note_replies","affinity_list_notes","affinity_list_opportunities","affinity_list_persons","affinity_list_reminders","affinity_list_saved_view_entries","affinity_list_saved_views","affinity_list_transcript_fragments","affinity_list_transcripts","affinity_list_users","affinity_search_companies","affinity_search_files","affinity_search_list_entries","affinity_search_notes","affinity_search_persons","affinity_semantic_search","affinity_update_entity_field_value","affinity_update_list_entry_field","affinity_update_list_field_dropdown_option","affinity_update_note","agentmail_create_draft","agentmail_create_inbox","agentmail_delete_draft","agentmail_delete_inbox","agentmail_delete_thread","agentmail_forward_message","agentmail_get_draft","agentmail_get_inbox","agentmail_get_message","agentmail_get_thread","agentmail_list_drafts","agentmail_list_inboxes","agentmail_list_messages","agentmail_list_threads","agentmail_reply_message","agentmail_send_draft","agentmail_send_message","agentmail_update_draft","agentmail_update_inbox","agentmail_update_message","agentmail_update_thread","agentphone_create_call","agentphone_create_contact","agentphone_create_number","agentphone_delete_contact","agentphone_get_call","agentphone_get_call_transcript","agentphone_get_contact","agentphone_get_conversation","agentphone_get_conversation_messages","agentphone_get_number_messages","agentphone_get_usage","agentphone_get_usage_daily","agentphone_get_usage_monthly","agentphone_list_calls","agentphone_list_contacts","agentphone_list_conversations","agentphone_list_numbers","agentphone_react_to_message","agentphone_release_number","agentphone_send_message","agentphone_update_contact","agentphone_update_conversation","agiloft_async_status","agiloft_attach_file","agiloft_attachment_info","agiloft_create_record","agiloft_delete_record","agiloft_get_choice_line_id","agiloft_list_tables","agiloft_lock_record","agiloft_nlp_search","agiloft_read_record","agiloft_remove_attachment","agiloft_retrieve_attachment","agiloft_run_action_button","agiloft_saved_search","agiloft_search_records","agiloft_select_records","agiloft_update_record","agiloft_upsert_record","ahrefs_anchors","ahrefs_backlinks","ahrefs_backlinks_stats","ahrefs_batch_analysis","ahrefs_broken_backlinks","ahrefs_domain_rating","ahrefs_domain_rating_history","ahrefs_keyword_overview","ahrefs_keywords_history","ahrefs_metrics","ahrefs_metrics_history","ahrefs_organic_competitors","ahrefs_organic_keywords","ahrefs_paid_pages","ahrefs_rank_tracker_competitors_overview","ahrefs_rank_tracker_competitors_stats","ahrefs_rank_tracker_overview","ahrefs_rank_tracker_serp_overview","ahrefs_refdomains_history","ahrefs_referring_domains","ahrefs_related_terms","ahrefs_site_audit_page_explorer","ahrefs_top_pages","airtable_create_records","airtable_delete_records","airtable_get_base_schema","airtable_get_record","airtable_list_bases","airtable_list_records","airtable_list_tables","airtable_update_multiple_records","airtable_update_record","airtable_upsert_records","airweave_search","algolia_add_record","algolia_batch_operations","algolia_browse_records","algolia_clear_records","algolia_copy_move_index","algolia_delete_by_filter","algolia_delete_index","algolia_delete_record","algolia_get_record","algolia_get_records","algolia_get_settings","algolia_get_task_status","algolia_list_indices","algolia_partial_update_record","algolia_search","algolia_update_settings","amplitude_event_segmentation","amplitude_funnels","amplitude_get_active_users","amplitude_get_revenue","amplitude_group_identify","amplitude_identify_user","amplitude_list_events","amplitude_realtime_active_users","amplitude_retention","amplitude_send_event","amplitude_user_activity","amplitude_user_profile","amplitude_user_search","apify_get_dataset_items","apify_get_run","apify_run_actor_async","apify_run_actor_sync","apify_run_task","apollo_account_bulk_create","apollo_account_bulk_update","apollo_account_create","apollo_account_search","apollo_account_update","apollo_contact_bulk_create","apollo_contact_bulk_update","apollo_contact_create","apollo_contact_search","apollo_contact_update","apollo_email_accounts","apollo_opportunity_create","apollo_opportunity_get","apollo_opportunity_search","apollo_opportunity_update","apollo_organization_bulk_enrich","apollo_organization_enrich","apollo_organization_search","apollo_people_bulk_enrich","apollo_people_enrich","apollo_people_search","apollo_sequence_add_contacts","apollo_sequence_search","apollo_task_create","apollo_task_search","appconfig_create_application","appconfig_create_configuration_profile","appconfig_create_environment","appconfig_create_hosted_configuration_version","appconfig_delete_application","appconfig_delete_configuration_profile","appconfig_delete_environment","appconfig_delete_hosted_configuration_version","appconfig_get_application","appconfig_get_configuration","appconfig_get_configuration_profile","appconfig_get_deployment","appconfig_get_environment","appconfig_get_hosted_configuration_version","appconfig_list_applications","appconfig_list_configuration_profiles","appconfig_list_deployment_strategies","appconfig_list_deployments","appconfig_list_environments","appconfig_list_hosted_configuration_versions","appconfig_start_deployment","appconfig_stop_deployment","appconfig_update_application","appconfig_update_configuration_profile","appconfig_update_environment","arxiv_get_author_papers","arxiv_get_paper","arxiv_search","asana_add_comment","asana_add_followers","asana_create_project","asana_create_section","asana_create_subtask","asana_create_task","asana_delete_task","asana_get_project","asana_get_projects","asana_get_task","asana_list_sections","asana_list_workspaces","asana_search_tasks","asana_update_task","ashby_add_candidate_tag","ashby_anonymize_candidate","ashby_change_application_source","ashby_change_application_stage","ashby_create_application","ashby_create_candidate","ashby_create_note","ashby_delete_application","ashby_get_application","ashby_get_candidate","ashby_get_job","ashby_get_job_posting","ashby_get_offer","ashby_get_opening","ashby_list_application_feedback","ashby_list_application_history","ashby_list_applications","ashby_list_archive_reasons","ashby_list_candidate_tags","ashby_list_candidates","ashby_list_custom_fields","ashby_list_departments","ashby_list_interview_plans","ashby_list_interview_stages","ashby_list_interviews","ashby_list_job_postings","ashby_list_jobs","ashby_list_locations","ashby_list_notes","ashby_list_offers","ashby_list_openings","ashby_list_sources","ashby_list_users","ashby_remove_candidate_tag","ashby_search_candidates","ashby_search_jobs","ashby_search_openings","ashby_search_users","ashby_set_custom_field_value","ashby_set_custom_field_values","ashby_transfer_application","ashby_update_candidate","ashby_upload_candidate_file","ashby_upload_resume","athena_batch_get_named_query","athena_batch_get_prepared_statement","athena_batch_get_query_execution","athena_create_named_query","athena_create_prepared_statement","athena_delete_named_query","athena_delete_prepared_statement","athena_get_data_catalog","athena_get_database","athena_get_named_query","athena_get_prepared_statement","athena_get_query_execution","athena_get_query_results","athena_get_query_runtime_statistics","athena_get_table_metadata","athena_get_work_group","athena_list_data_catalogs","athena_list_databases","athena_list_named_queries","athena_list_prepared_statements","athena_list_query_executions","athena_list_table_metadata","athena_list_work_groups","athena_start_query","athena_stop_query","athena_update_named_query","athena_update_prepared_statement","attio_assert_record","attio_create_attribute","attio_create_comment","attio_create_list","attio_create_list_entry","attio_create_note","attio_create_object","attio_create_record","attio_create_task","attio_create_webhook","attio_delete_comment","attio_delete_list_entry","attio_delete_note","attio_delete_record","attio_delete_task","attio_delete_webhook","attio_get_attribute","attio_get_comment","attio_get_list","attio_get_list_entry","attio_get_member","attio_get_note","attio_get_object","attio_get_record","attio_get_task","attio_get_thread","attio_get_webhook","attio_list_attributes","attio_list_lists","attio_list_members","attio_list_notes","attio_list_objects","attio_list_records","attio_list_tasks","attio_list_threads","attio_list_webhooks","attio_query_list_entries","attio_search_records","attio_update_attribute","attio_update_list","attio_update_list_entry","attio_update_object","attio_update_record","attio_update_task","attio_update_webhook","azure_data_explorer_create_table","azure_data_explorer_drop_table","azure_data_explorer_ingest_from_query","azure_data_explorer_ingest_inline","azure_data_explorer_list_databases","azure_data_explorer_list_functions","azure_data_explorer_list_tables","azure_data_explorer_management","azure_data_explorer_query","azure_data_explorer_show_database_schema","azure_data_explorer_show_ingestion_failures","azure_data_explorer_show_operations","azure_data_explorer_show_table_details","azure_data_explorer_show_table_schema","azure_devops_add_comment","azure_devops_create_work_item","azure_devops_get_build_log","azure_devops_get_build_timeline","azure_devops_get_comments","azure_devops_get_pipeline","azure_devops_get_pipeline_run","azure_devops_get_work_item","azure_devops_get_work_items_batch","azure_devops_get_work_items_between_builds","azure_devops_list_build_logs","azure_devops_list_builds","azure_devops_list_pipeline_runs","azure_devops_list_pipelines","azure_devops_query_work_items","azure_devops_update_work_item","bitbucket_approve_pull_request","bitbucket_create_branch","bitbucket_create_pull_request","bitbucket_create_pull_request_comment","bitbucket_decline_pull_request","bitbucket_delete_branch","bitbucket_get_commit","bitbucket_get_file","bitbucket_get_file_metadata","bitbucket_get_pipeline","bitbucket_get_pipeline_step_log","bitbucket_get_pull_request","bitbucket_get_pull_request_diff","bitbucket_get_pull_request_diffstat","bitbucket_get_pull_request_merge_task_status","bitbucket_get_repository","bitbucket_list_branches","bitbucket_list_commits","bitbucket_list_directory","bitbucket_list_pipeline_steps","bitbucket_list_pipelines","bitbucket_list_pull_request_comments","bitbucket_list_pull_request_commit_statuses","bitbucket_list_pull_requests","bitbucket_list_repositories","bitbucket_list_workspaces","bitbucket_merge_pull_request","bitbucket_request_pull_request_changes","bitbucket_stop_pipeline","bitbucket_trigger_pipeline","box_copy_file","box_create_folder","box_delete_file","box_delete_folder","box_download_file","box_download_file_v2","box_get_file_info","box_list_folder_items","box_search","box_sign_cancel_request","box_sign_create_request","box_sign_get_request","box_sign_list_requests","box_sign_resend_request","box_update_file","box_upload_file","brandfetch_get_brand","brandfetch_search","brex_archive_budget","brex_create_budget","brex_create_spend_limit","brex_create_transfer","brex_create_vendor","brex_get_budget","brex_get_cash_account","brex_get_company","brex_get_current_user","brex_get_expense","brex_get_spend_limit","brex_get_transfer","brex_get_user","brex_get_vendor","brex_list_budgets","brex_list_card_accounts","brex_list_card_statements","brex_list_card_transactions","brex_list_cards","brex_list_cash_accounts","brex_list_cash_statements","brex_list_cash_transactions","brex_list_departments","brex_list_expenses","brex_list_locations","brex_list_spend_limits","brex_list_titles","brex_list_transfers","brex_list_users","brex_list_vendors","brex_match_receipt","brex_update_expense","brex_update_vendor","brex_upload_receipt","brightdata_cancel_snapshot","brightdata_discover","brightdata_download_snapshot","brightdata_scrape_dataset","brightdata_scrape_url","brightdata_serp_search","brightdata_snapshot_status","brightdata_sync_scrape","browser_use_run_task","buffer_create_idea","buffer_create_post","buffer_delete_post","buffer_edit_post","buffer_get_account","buffer_get_channels","buffer_get_idea_groups","buffer_get_ideas","buffer_get_post","buffer_get_posts","calcom_cancel_booking","calcom_confirm_booking","calcom_create_booking","calcom_create_event_type","calcom_create_schedule","calcom_decline_booking","calcom_delete_event_type","calcom_delete_schedule","calcom_get_booking","calcom_get_default_schedule","calcom_get_event_type","calcom_get_schedule","calcom_get_slots","calcom_list_bookings","calcom_list_event_types","calcom_list_schedules","calcom_reschedule_booking","calcom_update_event_type","calcom_update_schedule","calendly_cancel_event","calendly_create_event_invitee","calendly_create_invitee_no_show","calendly_create_scheduling_link","calendly_create_webhook","calendly_delete_invitee_no_show","calendly_delete_webhook","calendly_get_current_user","calendly_get_event_invitee","calendly_get_event_type","calendly_get_scheduled_event","calendly_get_user","calendly_list_event_invitees","calendly_list_event_type_available_times","calendly_list_event_types","calendly_list_organization_memberships","calendly_list_routing_form_submissions","calendly_list_routing_forms","calendly_list_scheduled_events","calendly_list_user_availability_schedules","calendly_list_user_busy_times","calendly_list_webhooks","cbinsights_chat","cbinsights_get_commercial_maturity_history","cbinsights_get_exit_probability_history","cbinsights_get_mosaic_history","cbinsights_get_org_business_relationships","cbinsights_get_org_funding_window","cbinsights_get_org_fundings","cbinsights_get_org_investments","cbinsights_get_org_management_and_board","cbinsights_get_org_outlook","cbinsights_get_org_portfolio_exits","cbinsights_get_org_revenue","cbinsights_get_scouting_report","cbinsights_get_strategy_map","cbinsights_list_business_relationships","cbinsights_list_funding_window","cbinsights_list_fundings","cbinsights_list_investments","cbinsights_list_management_and_board","cbinsights_list_outlook","cbinsights_list_portfolio_exits","cbinsights_list_revenue","cbinsights_lookup_organizations","cbinsights_rag","cbinsights_search_firmographics","circleback_add_tag_to_meetings","circleback_create_tag","circleback_delete_action_item","circleback_delete_meeting","circleback_delete_tag","circleback_get_company","circleback_get_meeting","circleback_get_person","circleback_get_transcript","circleback_list_action_items","circleback_list_calendar_events","circleback_list_companies","circleback_list_meetings","circleback_list_people","circleback_list_tags","circleback_remove_tag_from_meetings","circleback_search_meetings","circleback_update_action_item","circleback_update_meeting","circleback_update_tag","clay_populate","clerk_add_organization_member","clerk_ban_user","clerk_create_actor_token","clerk_create_allowlist_identifier","clerk_create_blocklist_identifier","clerk_create_organization","clerk_create_organization_invitation","clerk_create_user","clerk_delete_allowlist_identifier","clerk_delete_blocklist_identifier","clerk_delete_organization","clerk_delete_user","clerk_get_jwt_template","clerk_get_organization","clerk_get_session","clerk_get_user","clerk_get_user_oauth_token","clerk_list_allowlist_identifiers","clerk_list_blocklist_identifiers","clerk_list_jwt_templates","clerk_list_organization_invitations","clerk_list_organization_memberships","clerk_list_organizations","clerk_list_sessions","clerk_list_users","clerk_lock_user","clerk_remove_organization_member","clerk_revoke_actor_token","clerk_revoke_session","clerk_unban_user","clerk_unlock_user","clerk_update_organization","clerk_update_organization_membership","clerk_update_user","clickhouse_count_rows","clickhouse_create_database","clickhouse_create_table","clickhouse_delete","clickhouse_describe_table","clickhouse_drop_database","clickhouse_drop_partition","clickhouse_drop_table","clickhouse_execute","clickhouse_insert","clickhouse_insert_rows","clickhouse_introspect","clickhouse_kill_query","clickhouse_list_clusters","clickhouse_list_databases","clickhouse_list_mutations","clickhouse_list_partitions","clickhouse_list_running_queries","clickhouse_list_tables","clickhouse_optimize_table","clickhouse_query","clickhouse_rename_table","clickhouse_show_create_table","clickhouse_table_stats","clickhouse_truncate_table","clickhouse_update","clickup_add_tag_to_task","clickup_create_checklist","clickup_create_checklist_item","clickup_create_comment","clickup_create_folder","clickup_create_list","clickup_create_task","clickup_create_time_entry","clickup_delete_checklist","clickup_delete_checklist_item","clickup_delete_comment","clickup_delete_task","clickup_delete_time_entry","clickup_get_comments","clickup_get_custom_fields","clickup_get_folders","clickup_get_list_members","clickup_get_lists","clickup_get_running_timer","clickup_get_space_tags","clickup_get_spaces","clickup_get_task","clickup_get_task_members","clickup_get_tasks","clickup_get_time_entries","clickup_get_workspaces","clickup_remove_custom_field_value","clickup_remove_tag_from_task","clickup_search_tasks","clickup_set_custom_field_value","clickup_start_timer","clickup_stop_timer","clickup_update_checklist","clickup_update_checklist_item","clickup_update_comment","clickup_update_task","clickup_update_time_entry","clickup_upload_attachment","cloudflare_create_access_application","cloudflare_create_access_policy","cloudflare_create_access_service_token","cloudflare_create_dns_record","cloudflare_create_r2_bucket","cloudflare_create_rate_limit_rule","cloudflare_create_ruleset","cloudflare_create_ruleset_rule","cloudflare_create_zone","cloudflare_delete_access_application","cloudflare_delete_access_policy","cloudflare_delete_dns_record","cloudflare_delete_r2_bucket","cloudflare_delete_ruleset_rule","cloudflare_delete_zone","cloudflare_dns_analytics","cloudflare_get_access_application","cloudflare_get_r2_bucket","cloudflare_get_ruleset","cloudflare_get_ruleset_entrypoint","cloudflare_get_tunnel","cloudflare_get_tunnel_configuration","cloudflare_get_worker_script_settings","cloudflare_get_zone","cloudflare_get_zone_settings","cloudflare_list_access_applications","cloudflare_list_access_groups","cloudflare_list_access_identity_providers","cloudflare_list_access_policies","cloudflare_list_access_service_tokens","cloudflare_list_certificates","cloudflare_list_dns_records","cloudflare_list_managed_ruleset_overrides","cloudflare_list_r2_buckets","cloudflare_list_rate_limit_rules","cloudflare_list_rulesets","cloudflare_list_tunnels","cloudflare_list_worker_routes","cloudflare_list_worker_scripts","cloudflare_list_zones","cloudflare_purge_cache","cloudflare_revoke_access_service_token","cloudflare_update_access_application","cloudflare_update_access_policy","cloudflare_update_dns_record","cloudflare_update_rate_limit_rule","cloudflare_update_ruleset_rule","cloudflare_update_zone_setting","cloudformation_cancel_update_stack","cloudformation_create_change_set","cloudformation_create_stack","cloudformation_delete_stack","cloudformation_describe_change_set","cloudformation_describe_stack_drift_detection_status","cloudformation_describe_stack_events","cloudformation_describe_stacks","cloudformation_detect_stack_drift","cloudformation_execute_change_set","cloudformation_get_template","cloudformation_get_template_summary","cloudformation_list_stack_resources","cloudformation_update_stack","cloudformation_validate_template","cloudtrail_cancel_query","cloudtrail_describe_query","cloudtrail_describe_trails","cloudtrail_get_event_data_store","cloudtrail_get_event_selectors","cloudtrail_get_insight_selectors","cloudtrail_get_query_results","cloudtrail_get_trail","cloudtrail_get_trail_status","cloudtrail_list_event_data_stores","cloudtrail_list_tags","cloudtrail_list_trails","cloudtrail_lookup_events","cloudtrail_start_query","cloudwatch_describe_alarm_history","cloudwatch_describe_alarms","cloudwatch_describe_log_groups","cloudwatch_describe_log_streams","cloudwatch_filter_log_events","cloudwatch_get_log_events","cloudwatch_get_metric_statistics","cloudwatch_list_metrics","cloudwatch_mute_alarm","cloudwatch_put_log_group_retention","cloudwatch_put_metric_data","cloudwatch_query_logs","cloudwatch_unmute_alarm","codepipeline_disable_stage_transition","codepipeline_enable_stage_transition","codepipeline_get_pipeline","codepipeline_get_pipeline_execution","codepipeline_get_pipeline_state","codepipeline_list_action_executions","codepipeline_list_pipeline_executions","codepipeline_list_pipelines","codepipeline_put_approval_result","codepipeline_retry_stage_execution","codepipeline_start_execution","codepipeline_stop_execution","confluence_add_label","confluence_create_blogpost","confluence_create_comment","confluence_create_page","confluence_create_page_property","confluence_create_space","confluence_create_space_property","confluence_delete_attachment","confluence_delete_blogpost","confluence_delete_comment","confluence_delete_label","confluence_delete_page","confluence_delete_page_property","confluence_delete_space","confluence_delete_space_property","confluence_get_blogpost","confluence_get_page_ancestors","confluence_get_page_children","confluence_get_page_descendants","confluence_get_page_version","confluence_get_pages_by_label","confluence_get_space","confluence_get_task","confluence_get_user","confluence_list_attachments","confluence_list_blogposts","confluence_list_blogposts_in_space","confluence_list_comments","confluence_list_labels","confluence_list_page_properties","confluence_list_page_versions","confluence_list_pages_in_space","confluence_list_space_labels","confluence_list_space_permissions","confluence_list_space_properties","confluence_list_spaces","confluence_list_tasks","confluence_retrieve","confluence_search","confluence_search_in_space","confluence_update","confluence_update_blogpost","confluence_update_comment","confluence_update_space","confluence_update_task","confluence_upload_attachment","context_dev_classify_naics","context_dev_classify_sic","context_dev_crawl","context_dev_extract","context_dev_extract_product","context_dev_extract_products","context_dev_get_brand","context_dev_get_brand_by_email","context_dev_get_brand_by_name","context_dev_get_brand_by_ticker","context_dev_identify_transaction","context_dev_map","context_dev_scrape_fonts","context_dev_scrape_html","context_dev_scrape_images","context_dev_scrape_markdown","context_dev_scrape_styleguide","context_dev_screenshot","context_dev_search","convex_action","convex_document_deltas","convex_list_documents","convex_list_tables","convex_mutation","convex_query","convex_run_function","crowdstrike_create_indicators","crowdstrike_delete_indicators","crowdstrike_delete_rtr_session","crowdstrike_execute_rtr_command","crowdstrike_get_alert_details","crowdstrike_get_case_details","crowdstrike_get_host_group_details","crowdstrike_get_indicator_details","crowdstrike_get_rtr_command_status","crowdstrike_get_sensor_aggregates","crowdstrike_get_sensor_details","crowdstrike_get_vulnerability_details","crowdstrike_init_rtr_session","crowdstrike_perform_host_action","crowdstrike_perform_host_group_action","crowdstrike_query_alerts","crowdstrike_query_cases","crowdstrike_query_host_groups","crowdstrike_query_indicators","crowdstrike_query_sensors","crowdstrike_query_vulnerabilities","crowdstrike_update_alerts","crowdstrike_update_indicators","crunchbase_autocomplete","crunchbase_get_acquisition","crunchbase_get_entity","crunchbase_get_entity_card","crunchbase_get_fields_metadata","crunchbase_get_funding_round","crunchbase_get_organization","crunchbase_get_person","crunchbase_list_deleted_entities","crunchbase_search_acquisitions","crunchbase_search_entities","crunchbase_search_funding_rounds","crunchbase_search_organizations","crunchbase_search_people","cursor_add_followup","cursor_add_followup_v2","cursor_delete_agent","cursor_delete_agent_v2","cursor_download_artifact","cursor_download_artifact_v2","cursor_get_agent","cursor_get_agent_v2","cursor_get_api_key_info","cursor_get_api_key_info_v2","cursor_get_conversation","cursor_get_conversation_v2","cursor_launch_agent","cursor_launch_agent_v2","cursor_list_agents","cursor_list_agents_v2","cursor_list_artifacts","cursor_list_artifacts_v2","cursor_list_models","cursor_list_models_v2","cursor_list_repositories","cursor_list_repositories_v2","cursor_stop_agent","cursor_stop_agent_v2","dagster_delete_run","dagster_get_asset","dagster_get_run","dagster_get_run_logs","dagster_launch_run","dagster_list_assets","dagster_list_jobs","dagster_list_runs","dagster_list_schedules","dagster_list_sensors","dagster_materialize_assets","dagster_reexecute_run","dagster_report_asset_materialization","dagster_start_schedule","dagster_start_sensor","dagster_stop_schedule","dagster_stop_sensor","dagster_terminate_run","dagster_wipe_asset","databricks_cancel_run","databricks_execute_sql","databricks_get_cluster","databricks_get_job","databricks_get_run","databricks_get_run_output","databricks_get_statement","databricks_list_clusters","databricks_list_jobs","databricks_list_runs","databricks_list_warehouses","databricks_run_job","datadog_add_incident_todo","datadog_cancel_downtime","datadog_create_dashboard","datadog_create_downtime","datadog_create_event","datadog_create_incident","datadog_create_monitor","datadog_create_slo","datadog_delete_dashboard","datadog_delete_slo","datadog_get_browser_synthetics_results","datadog_get_dashboard","datadog_get_incident","datadog_get_monitor","datadog_get_security_signal","datadog_get_slo","datadog_get_slo_history","datadog_get_synthetics_results","datadog_get_synthetics_test","datadog_list_dashboards","datadog_list_downtimes","datadog_list_incidents","datadog_list_monitors","datadog_list_security_rules","datadog_list_security_signals","datadog_list_services","datadog_list_slos","datadog_list_synthetics_tests","datadog_mute_monitor","datadog_query_logs","datadog_query_timeseries","datadog_search_spans","datadog_send_logs","datadog_submit_metrics","datadog_trigger_synthetics_tests","datadog_unmute_monitor","datadog_update_incident","datadog_update_security_signal_assignee","datadog_update_security_signal_state","datadog_update_slo","datadog_update_synthetics_status","datagma_enrich_company","datagma_enrich_person","datagma_find_email","datagma_find_phone","datagma_get_credits","daytona_create_sandbox","daytona_delete_sandbox","daytona_download_file","daytona_execute_command","daytona_get_sandbox","daytona_git_clone","daytona_list_files","daytona_list_sandboxes","daytona_run_code","daytona_start_sandbox","daytona_stop_sandbox","daytona_upload_file","deployed_block_executor","deployments_deploy","deployments_get_version","deployments_list_versions","deployments_promote","deployments_undeploy","devin_append_session_tags","devin_archive_session","devin_create_session","devin_get_session","devin_get_session_tags","devin_list_session_attachments","devin_list_session_messages","devin_list_sessions","devin_replace_session_tags","devin_send_message","devin_terminate_session","discord_add_reaction","discord_archive_thread","discord_assign_role","discord_ban_member","discord_bulk_delete_messages","discord_create_channel","discord_create_invite","discord_create_role","discord_create_thread","discord_create_webhook","discord_delete_channel","discord_delete_invite","discord_delete_message","discord_delete_role","discord_delete_webhook","discord_edit_message","discord_execute_webhook","discord_get_channel","discord_get_invite","discord_get_member","discord_get_messages","discord_get_pinned_messages","discord_get_server","discord_get_user","discord_get_webhook","discord_join_thread","discord_kick_member","discord_leave_thread","discord_list_channels","discord_list_roles","discord_pin_message","discord_remove_reaction","discord_remove_role","discord_send_message","discord_unban_member","discord_unpin_message","discord_update_channel","discord_update_member","discord_update_role","docusign_create_from_template","docusign_download_document","docusign_get_envelope","docusign_list_envelopes","docusign_list_recipients","docusign_list_templates","docusign_send_envelope","docusign_void_envelope","downdetector_get_company","downdetector_get_company_attribution","downdetector_get_company_baseline","downdetector_get_company_events","downdetector_get_company_incidents","downdetector_get_company_indicators","downdetector_get_company_last_15","downdetector_get_company_status","downdetector_get_provider","downdetector_get_reports","downdetector_get_site_companies","downdetector_list_categories","downdetector_list_incidents","downdetector_list_sites","downdetector_search_companies","dropbox_copy","dropbox_create_folder","dropbox_create_shared_link","dropbox_delete","dropbox_download","dropbox_download_v2","dropbox_get_metadata","dropbox_list_folder","dropbox_list_revisions","dropbox_list_shared_links","dropbox_move","dropbox_restore","dropbox_search","dropbox_upload","dropcontact_enrich_contact","dspy_chain_of_thought","dspy_predict","dspy_react","dub_bulk_create_links","dub_bulk_delete_links","dub_bulk_update_links","dub_create_link","dub_create_tag","dub_delete_link","dub_get_analytics","dub_get_events","dub_get_link","dub_get_links_count","dub_get_qr_code","dub_get_qr_code_v2","dub_list_domains","dub_list_folders","dub_list_links","dub_list_tags","dub_update_link","dub_upsert_link","duckduckgo_search","dynamodb_delete","dynamodb_get","dynamodb_introspect","dynamodb_put","dynamodb_query","dynamodb_scan","dynamodb_update","dynatrace_add_problem_comment","dynatrace_add_tags","dynatrace_close_problem","dynatrace_create_settings_object","dynatrace_create_slo","dynatrace_delete_problem_comment","dynatrace_delete_settings_object","dynatrace_delete_slo","dynatrace_delete_tag","dynatrace_execute_synthetic_monitors","dynatrace_get_attack","dynatrace_get_audit_logs","dynatrace_get_entity","dynatrace_get_event","dynatrace_get_metric","dynatrace_get_problem","dynatrace_get_problem_comment","dynatrace_get_security_problem","dynatrace_get_settings_object","dynatrace_get_slo","dynatrace_get_synthetic_batch","dynatrace_ingest_event","dynatrace_ingest_logs","dynatrace_ingest_metrics","dynatrace_list_attacks","dynatrace_list_entities","dynatrace_list_entity_types","dynatrace_list_events","dynatrace_list_metrics","dynatrace_list_problem_comments","dynatrace_list_problems","dynatrace_list_remediation_items","dynatrace_list_security_problems","dynatrace_list_settings_objects","dynatrace_list_settings_schemas","dynatrace_list_slos","dynatrace_list_synthetic_monitors","dynatrace_list_tags","dynatrace_mute_security_problem","dynatrace_mute_security_problems","dynatrace_query_metrics","dynatrace_search_logs","dynatrace_unmute_security_problem","dynatrace_unmute_security_problems","dynatrace_update_problem_comment","dynatrace_update_settings_object","dynatrace_update_slo","elasticsearch_bulk","elasticsearch_cluster_health","elasticsearch_cluster_stats","elasticsearch_count","elasticsearch_create_index","elasticsearch_delete_document","elasticsearch_delete_index","elasticsearch_get_document","elasticsearch_get_index","elasticsearch_index_document","elasticsearch_list_indices","elasticsearch_search","elasticsearch_update_document","elevenlabs_audio_isolation","elevenlabs_edit_voice_settings","elevenlabs_get_user","elevenlabs_get_voice","elevenlabs_get_voice_settings","elevenlabs_list_models","elevenlabs_list_voices","elevenlabs_sound_effects","elevenlabs_speech_to_speech","elevenlabs_tts","emailbison_attach_leads_to_campaign","emailbison_attach_tags_to_leads","emailbison_create_campaign","emailbison_create_lead","emailbison_create_tag","emailbison_get_lead","emailbison_list_campaigns","emailbison_list_leads","emailbison_list_replies","emailbison_list_tags","emailbison_update_campaign","emailbison_update_campaign_status","emailbison_update_lead","embeddings_cohere","embeddings_gemini","embeddings_mistral","embeddings_ollama","embeddings_openai","embeddings_openrouter","enrich_check_credits","enrich_company_funding","enrich_company_lookup","enrich_company_revenue","enrich_disposable_email_check","enrich_email_to_ip","enrich_email_to_person_lite","enrich_email_to_phone","enrich_email_to_profile","enrich_find_email","enrich_get_post_details","enrich_ip_to_company","enrich_linkedin_profile","enrich_linkedin_to_personal_email","enrich_linkedin_to_work_email","enrich_phone_finder","enrich_reverse_hash_lookup","enrich_sales_pointer_people","enrich_search_company","enrich_search_company_activities","enrich_search_company_employees","enrich_search_jobs","enrich_search_logo","enrich_search_people","enrich_search_people_activities","enrich_search_post_comments","enrich_search_post_comments_by_url","enrich_search_post_reactions","enrich_search_post_reactions_by_url","enrich_search_posts","enrich_search_similar_companies","enrich_verify_email","enrichment_run","enrow_find_email","enrow_verify_email","exa_agent","exa_answer","exa_find_similar_links","exa_get_contents","exa_search","extend_parser","extend_parser_v2","fathom_get_summary","fathom_get_transcript","fathom_list_meeting_types","fathom_list_meetings","fathom_list_team_members","fathom_list_teams","file_append","file_compress","file_create_folder","file_decompress","file_delete_folder","file_edit","file_fetch","file_get","file_get_content","file_list","file_manage_sharing","file_move","file_parser","file_parser_v2","file_parser_v3","file_read","file_restore_folder","file_search","file_update_folder","file_write","findymail_find_email_from_linkedin","findymail_find_email_from_name","findymail_find_emails_by_domain","findymail_find_employees","findymail_find_phone","findymail_get_company","findymail_get_credits","findymail_lookup_technologies","findymail_reverse_email_lookup","findymail_search_technologies","findymail_verify_email","firecrawl_agent","firecrawl_batch_scrape","firecrawl_batch_scrape_status","firecrawl_cancel_crawl","firecrawl_crawl","firecrawl_crawl_status","firecrawl_credit_usage","firecrawl_extract","firecrawl_extract_status","firecrawl_map","firecrawl_parse","firecrawl_scrape","firecrawl_search","fireflies_add_to_live_meeting","fireflies_create_bite","fireflies_delete_transcript","fireflies_get_transcript","fireflies_get_user","fireflies_list_bites","fireflies_list_contacts","fireflies_list_transcripts","fireflies_list_users","fireflies_upload_audio","flint_create_task","flint_generate_pages","flint_get_task","function_execute","gamma_check_status","gamma_generate","gamma_generate_from_template","gamma_list_folders","gamma_list_themes","github_add_assignees","github_add_assignees_v2","github_add_labels","github_add_labels_v2","github_cancel_workflow_run","github_cancel_workflow_run_v2","github_check_star","github_check_star_v2","github_close_issue","github_close_issue_v2","github_close_pr","github_close_pr_v2","github_comment","github_comment_v2","github_compare_commits","github_compare_commits_v2","github_create_branch","github_create_branch_v2","github_create_comment_reaction","github_create_comment_reaction_v2","github_create_file","github_create_file_v2","github_create_gist","github_create_gist_v2","github_create_issue","github_create_issue_reaction","github_create_issue_reaction_v2","github_create_issue_v2","github_create_milestone","github_create_milestone_v2","github_create_pr","github_create_pr_review","github_create_pr_review_v2","github_create_pr_v2","github_create_project","github_create_project_v2","github_create_release","github_create_release_v2","github_delete_branch","github_delete_branch_v2","github_delete_comment","github_delete_comment_reaction","github_delete_comment_reaction_v2","github_delete_comment_v2","github_delete_file","github_delete_file_v2","github_delete_gist","github_delete_gist_v2","github_delete_issue_reaction","github_delete_issue_reaction_v2","github_delete_milestone","github_delete_milestone_v2","github_delete_project","github_delete_project_v2","github_delete_release","github_delete_release_v2","github_fork_gist","github_fork_gist_v2","github_fork_repo","github_fork_repo_v2","github_get_branch","github_get_branch_protection","github_get_branch_protection_v2","github_get_branch_v2","github_get_commit","github_get_commit_v2","github_get_file_content","github_get_file_content_v2","github_get_gist","github_get_gist_v2","github_get_issue","github_get_issue_v2","github_get_latest_release","github_get_latest_release_v2","github_get_milestone","github_get_milestone_v2","github_get_pr_files","github_get_pr_files_v2","github_get_project","github_get_project_v2","github_get_readme","github_get_readme_v2","github_get_release","github_get_release_v2","github_get_tree","github_get_tree_v2","github_get_workflow","github_get_workflow_run","github_get_workflow_run_v2","github_get_workflow_v2","github_issue_comment","github_issue_comment_v2","github_job_logs","github_latest_commit","github_latest_commit_v2","github_list_branches","github_list_branches_v2","github_list_commits","github_list_commits_v2","github_list_forks","github_list_forks_v2","github_list_gists","github_list_gists_v2","github_list_issue_comments","github_list_issue_comments_v2","github_list_issues","github_list_issues_v2","github_list_milestones","github_list_milestones_v2","github_list_pr_comments","github_list_pr_comments_v2","github_list_projects","github_list_projects_v2","github_list_prs","github_list_prs_v2","github_list_releases","github_list_releases_v2","github_list_review_threads","github_list_stargazers","github_list_stargazers_v2","github_list_tags","github_list_tags_v2","github_list_workflow_runs","github_list_workflow_runs_v2","github_list_workflows","github_list_workflows_v2","github_merge_pr","github_merge_pr_v2","github_pr","github_pr_v2","github_remove_label","github_remove_label_v2","github_reply_review_thread","github_repo_info","github_repo_info_v2","github_request_reviewers","github_request_reviewers_v2","github_rerun_workflow","github_rerun_workflow_v2","github_resolve_review_thread","github_search_code","github_search_code_v2","github_search_commits","github_search_commits_v2","github_search_issues","github_search_issues_v2","github_search_repos","github_search_repos_v2","github_search_users","github_search_users_v2","github_star_gist","github_star_gist_v2","github_star_repo","github_star_repo_v2","github_status_check_rollup","github_trigger_workflow","github_trigger_workflow_v2","github_unstar_gist","github_unstar_gist_v2","github_unstar_repo","github_unstar_repo_v2","github_update_branch_protection","github_update_branch_protection_v2","github_update_comment","github_update_comment_v2","github_update_file","github_update_file_v2","github_update_gist","github_update_gist_v2","github_update_issue","github_update_issue_v2","github_update_milestone","github_update_milestone_v2","github_update_pr","github_update_pr_v2","github_update_project","github_update_project_v2","github_update_release","github_update_release_v2","gitlab_activate_user","gitlab_add_member","gitlab_add_saml_group_link","gitlab_approve_access_request","gitlab_approve_merge_request","gitlab_approve_user","gitlab_ban_user","gitlab_block_user","gitlab_cancel_pipeline","gitlab_compare_branches","gitlab_create_branch","gitlab_create_file","gitlab_create_issue","gitlab_create_issue_note","gitlab_create_merge_request","gitlab_create_merge_request_note","gitlab_create_pipeline","gitlab_create_release","gitlab_create_user","gitlab_deactivate_user","gitlab_delete_branch","gitlab_delete_issue","gitlab_delete_saml_group_link","gitlab_delete_user","gitlab_delete_user_identity","gitlab_deny_access_request","gitlab_get_file","gitlab_get_group","gitlab_get_issue","gitlab_get_job_log","gitlab_get_merge_request","gitlab_get_merge_request_changes","gitlab_get_pipeline","gitlab_get_project","gitlab_invite_member","gitlab_list_access_requests","gitlab_list_branches","gitlab_list_commits","gitlab_list_groups","gitlab_list_invitations","gitlab_list_issues","gitlab_list_members","gitlab_list_merge_requests","gitlab_list_pipeline_jobs","gitlab_list_pipelines","gitlab_list_projects","gitlab_list_releases","gitlab_list_repository_tree","gitlab_list_saml_group_links","gitlab_list_user_memberships","gitlab_merge_merge_request","gitlab_play_job","gitlab_reject_user","gitlab_remove_member","gitlab_retry_pipeline","gitlab_revoke_invitation","gitlab_search_users","gitlab_unban_user","gitlab_unblock_user","gitlab_update_file","gitlab_update_invitation","gitlab_update_issue","gitlab_update_member","gitlab_update_merge_request","gitlab_update_user","gmail_add_label","gmail_add_label_v2","gmail_archive","gmail_archive_v2","gmail_create_label_v2","gmail_delete","gmail_delete_draft_v2","gmail_delete_label_v2","gmail_delete_v2","gmail_draft","gmail_draft_v2","gmail_edit_draft_v2","gmail_get_draft_v2","gmail_get_thread_v2","gmail_list_drafts_v2","gmail_list_labels_v2","gmail_list_threads_v2","gmail_mark_read","gmail_mark_read_v2","gmail_mark_unread","gmail_mark_unread_v2","gmail_move","gmail_move_v2","gmail_read","gmail_read_v2","gmail_remove_label","gmail_remove_label_v2","gmail_search","gmail_search_v2","gmail_send","gmail_send_v2","gmail_trash_thread_v2","gmail_unarchive","gmail_unarchive_v2","gmail_untrash_thread_v2","gmail_update_label_v2","gong_aggregate_activity","gong_aggregate_by_period","gong_answered_scorecards","gong_ask_anything","gong_assign_flow_prospects","gong_create_call","gong_day_by_day_activity","gong_get_brief","gong_get_call","gong_get_call_transcript","gong_get_coaching","gong_get_extensive_calls","gong_get_folder_content","gong_get_logs","gong_get_prospect_flows","gong_get_user","gong_interaction_stats","gong_list_calls","gong_list_flows","gong_list_library_folders","gong_list_scorecards","gong_list_trackers","gong_list_users","gong_list_workspaces","gong_lookup_email","gong_lookup_phone","gong_purge_email_address","gong_purge_phone_number","gong_unassign_flow_prospects","google_ads_ad_performance","google_ads_campaign_performance","google_ads_list_ad_groups","google_ads_list_campaigns","google_ads_list_customers","google_ads_search","google_appsheet_add_rows","google_appsheet_delete_rows","google_appsheet_edit_rows","google_appsheet_find_rows","google_bigquery_create_dataset","google_bigquery_create_table","google_bigquery_delete_dataset","google_bigquery_delete_table","google_bigquery_get_query_results","google_bigquery_get_table","google_bigquery_insert_rows","google_bigquery_list_datasets","google_bigquery_list_table_data","google_bigquery_list_tables","google_bigquery_query","google_books_volume_details","google_books_volume_search","google_calendar_create","google_calendar_create_calendar","google_calendar_create_calendar_v2","google_calendar_create_v2","google_calendar_delete","google_calendar_delete_calendar","google_calendar_delete_calendar_v2","google_calendar_delete_v2","google_calendar_freebusy","google_calendar_freebusy_v2","google_calendar_get","google_calendar_get_v2","google_calendar_instances","google_calendar_instances_v2","google_calendar_invite","google_calendar_invite_v2","google_calendar_list","google_calendar_list_acl","google_calendar_list_acl_v2","google_calendar_list_calendars","google_calendar_list_calendars_v2","google_calendar_list_v2","google_calendar_move","google_calendar_move_v2","google_calendar_quick_add","google_calendar_quick_add_v2","google_calendar_share_calendar","google_calendar_share_calendar_v2","google_calendar_unshare_calendar","google_calendar_unshare_calendar_v2","google_calendar_update","google_calendar_update_acl","google_calendar_update_acl_v2","google_calendar_update_calendar","google_calendar_update_calendar_v2","google_calendar_update_v2","google_contacts_create","google_contacts_delete","google_contacts_get","google_contacts_list","google_contacts_search","google_contacts_update","google_docs_create","google_docs_create_named_range","google_docs_create_paragraph_bullets","google_docs_delete_content_range","google_docs_delete_named_range","google_docs_delete_paragraph_bullets","google_docs_insert_image","google_docs_insert_page_break","google_docs_insert_table","google_docs_insert_text","google_docs_read","google_docs_replace_text","google_docs_update_paragraph_style","google_docs_update_text_style","google_docs_write","google_drive_copy","google_drive_create_comment","google_drive_create_folder","google_drive_delete","google_drive_delete_comment","google_drive_download","google_drive_export","google_drive_get_about","google_drive_get_content","google_drive_get_file","google_drive_get_revision","google_drive_list","google_drive_list_comments","google_drive_list_permissions","google_drive_list_revisions","google_drive_move","google_drive_search","google_drive_share","google_drive_trash","google_drive_unshare","google_drive_untrash","google_drive_update","google_drive_upload","google_forms_batch_update","google_forms_create_form","google_forms_create_watch","google_forms_delete_watch","google_forms_get_form","google_forms_get_responses","google_forms_list_watches","google_forms_renew_watch","google_forms_set_publish_settings","google_groups_add_alias","google_groups_add_member","google_groups_create_group","google_groups_delete_group","google_groups_get_group","google_groups_get_member","google_groups_get_settings","google_groups_has_member","google_groups_list_aliases","google_groups_list_groups","google_groups_list_members","google_groups_remove_alias","google_groups_remove_member","google_groups_update_group","google_groups_update_member","google_groups_update_settings","google_maps_air_quality","google_maps_directions","google_maps_distance_matrix","google_maps_elevation","google_maps_geocode","google_maps_geolocate","google_maps_place_details","google_maps_places_nearby","google_maps_places_search","google_maps_pollen","google_maps_reverse_geocode","google_maps_snap_to_roads","google_maps_solar","google_maps_speed_limits","google_maps_timezone","google_maps_validate_address","google_meet_create_space","google_meet_end_conference","google_meet_get_conference_record","google_meet_get_space","google_meet_list_conference_records","google_meet_list_participants","google_pagespeed_analyze","google_search","google_sheets_append","google_sheets_append_v2","google_sheets_batch_clear_v2","google_sheets_batch_get_v2","google_sheets_batch_update_v2","google_sheets_clear_v2","google_sheets_copy_sheet_v2","google_sheets_create_spreadsheet_v2","google_sheets_delete_rows_v2","google_sheets_delete_sheet_v2","google_sheets_delete_spreadsheet_v2","google_sheets_get_spreadsheet_v2","google_sheets_read","google_sheets_read_v2","google_sheets_update","google_sheets_update_v2","google_sheets_write","google_sheets_write_v2","google_slides_add_image","google_slides_add_slide","google_slides_batch_update","google_slides_copy_presentation","google_slides_create","google_slides_create_line","google_slides_create_paragraph_bullets","google_slides_create_shape","google_slides_create_sheets_chart","google_slides_create_table","google_slides_create_video","google_slides_delete_object","google_slides_delete_paragraph_bullets","google_slides_delete_table_column","google_slides_delete_table_row","google_slides_delete_text","google_slides_duplicate_object","google_slides_export_presentation","google_slides_get_page","google_slides_get_thumbnail","google_slides_group_objects","google_slides_insert_table_columns","google_slides_insert_table_rows","google_slides_insert_text","google_slides_merge_table_cells","google_slides_read","google_slides_refresh_sheets_chart","google_slides_replace_all_shapes_with_image","google_slides_replace_all_shapes_with_sheets_chart","google_slides_replace_all_text","google_slides_replace_image","google_slides_reroute_line","google_slides_ungroup_objects","google_slides_unmerge_table_cells","google_slides_update_image_properties","google_slides_update_line_category","google_slides_update_line_properties","google_slides_update_page_element_alt_text","google_slides_update_page_element_transform","google_slides_update_page_elements_z_order","google_slides_update_page_properties","google_slides_update_paragraph_style","google_slides_update_shape_properties","google_slides_update_slide_properties","google_slides_update_slides_position","google_slides_update_table_border_properties","google_slides_update_table_cell_properties","google_slides_update_table_column_properties","google_slides_update_table_row_properties","google_slides_update_text_style","google_slides_update_video_properties","google_slides_write","google_tasks_create","google_tasks_delete","google_tasks_get","google_tasks_list","google_tasks_list_task_lists","google_tasks_update","google_translate_detect","google_translate_text","google_vault_add_held_accounts","google_vault_add_matters_permissions","google_vault_close_matters","google_vault_create_matters","google_vault_create_matters_export","google_vault_create_matters_holds","google_vault_create_saved_query","google_vault_delete_matters","google_vault_delete_matters_export","google_vault_delete_matters_holds","google_vault_delete_saved_query","google_vault_download_export_file","google_vault_list_matters","google_vault_list_matters_export","google_vault_list_matters_holds","google_vault_list_saved_queries","google_vault_remove_held_accounts","google_vault_remove_matters_permissions","google_vault_reopen_matters","google_vault_undelete_matters","google_vault_update_matters","google_vault_update_matters_holds","grafana_check_data_source_health","grafana_create_alert_rule","grafana_create_annotation","grafana_create_contact_point","grafana_create_dashboard","grafana_create_folder","grafana_delete_alert_rule","grafana_delete_annotation","grafana_delete_contact_point","grafana_delete_dashboard","grafana_delete_folder","grafana_get_alert_rule","grafana_get_alert_rule_group","grafana_get_dashboard","grafana_get_data_source","grafana_get_folder","grafana_get_health","grafana_list_alert_rules","grafana_list_annotations","grafana_list_contact_points","grafana_list_dashboards","grafana_list_data_sources","grafana_list_folders","grafana_move_folder","grafana_query_data_source","grafana_update_alert_rule","grafana_update_annotation","grafana_update_contact_point","grafana_update_dashboard","grafana_update_folder","grain_create_hook","grain_create_hook_v2","grain_delete_hook","grain_delete_hook_v2","grain_get_recording","grain_get_transcript","grain_list_hooks","grain_list_hooks_v2","grain_list_meeting_types","grain_list_recordings","grain_list_teams","grain_list_views","granola_create_webhook_endpoint","granola_delete_webhook_endpoint","granola_get_note","granola_get_transcript","granola_list_audit_events","granola_list_folders","granola_list_notes","granola_list_webhook_endpoints","granola_update_webhook_endpoint","greenhouse_get_application","greenhouse_get_candidate","greenhouse_get_job","greenhouse_get_user","greenhouse_list_applications","greenhouse_list_candidates","greenhouse_list_departments","greenhouse_list_job_stages","greenhouse_list_jobs","greenhouse_list_offices","greenhouse_list_users","greptile_index_repo","greptile_query","greptile_search","greptile_status","guardrails_validate","harmonic_batch_get_people","harmonic_clear_people_saved_search_net_new_results","harmonic_enrich_person","harmonic_get_company_employees","harmonic_get_email_enrichment_job","harmonic_get_email_enrichment_usage","harmonic_get_enrichment_status","harmonic_get_people_saved_search_net_new_results","harmonic_get_people_saved_search_results","harmonic_get_person","harmonic_list_people_saved_searches","harmonic_search_people_scout","harmonic_submit_email_enrichment_job","hex_cancel_run","hex_create_collection","hex_create_group","hex_deactivate_user","hex_delete_group","hex_get_collection","hex_get_data_connection","hex_get_group","hex_get_project","hex_get_project_runs","hex_get_queried_tables","hex_get_run_status","hex_list_collections","hex_list_data_connections","hex_list_groups","hex_list_projects","hex_list_users","hex_run_project","hex_update_collection","hex_update_group","hex_update_project","http_request","hubspot_add_list_memberships","hubspot_create_appointment","hubspot_create_association","hubspot_create_company","hubspot_create_contact","hubspot_create_deal","hubspot_create_email","hubspot_create_line_item","hubspot_create_list","hubspot_create_note","hubspot_create_ticket","hubspot_delete_association","hubspot_delete_company","hubspot_delete_contact","hubspot_delete_deal","hubspot_delete_line_item","hubspot_delete_ticket","hubspot_get_appointment","hubspot_get_association_labels","hubspot_get_cart","hubspot_get_company","hubspot_get_contact","hubspot_get_deal","hubspot_get_email","hubspot_get_line_item","hubspot_get_list","hubspot_get_list_memberships","hubspot_get_marketing_event","hubspot_get_note","hubspot_get_properties","hubspot_get_quote","hubspot_get_ticket","hubspot_get_users","hubspot_list_appointments","hubspot_list_associations","hubspot_list_carts","hubspot_list_companies","hubspot_list_contacts","hubspot_list_deals","hubspot_list_emails","hubspot_list_line_items","hubspot_list_lists","hubspot_list_marketing_events","hubspot_list_notes","hubspot_list_owners","hubspot_list_quotes","hubspot_list_tickets","hubspot_remove_list_memberships","hubspot_search_companies","hubspot_search_contacts","hubspot_search_deals","hubspot_search_emails","hubspot_search_line_items","hubspot_search_notes","hubspot_search_quotes","hubspot_search_tickets","hubspot_update_appointment","hubspot_update_company","hubspot_update_contact","hubspot_update_deal","hubspot_update_line_item","hubspot_update_ticket","huggingface_chat","hunter_companies_find","hunter_discover","hunter_domain_search","hunter_email_count","hunter_email_finder","hunter_email_verifier","iam_add_user_to_group","iam_attach_role_policy","iam_attach_user_policy","iam_create_access_key","iam_create_role","iam_create_user","iam_delete_access_key","iam_delete_role","iam_delete_user","iam_detach_role_policy","iam_detach_user_policy","iam_get_policy","iam_get_role","iam_get_user","iam_list_access_keys","iam_list_attached_role_policies","iam_list_attached_user_policies","iam_list_groups","iam_list_policies","iam_list_roles","iam_list_users","iam_remove_user_from_group","iam_simulate_principal_policy","iam_update_access_key","icypeas_find_email","icypeas_verify_email","identity_center_check_assignment_deletion_status","identity_center_check_assignment_status","identity_center_create_account_assignment","identity_center_delete_account_assignment","identity_center_describe_account","identity_center_describe_group","identity_center_describe_user","identity_center_get_group","identity_center_get_user","identity_center_list_account_assignments","identity_center_list_accounts","identity_center_list_assignments_for_account","identity_center_list_group_memberships","identity_center_list_groups","identity_center_list_instances","identity_center_list_permission_sets","image_generate","incidentio_actions_create","incidentio_actions_list","incidentio_actions_show","incidentio_actions_update","incidentio_alert_events_create","incidentio_alerts_list","incidentio_alerts_resolve","incidentio_alerts_show","incidentio_catalog_entries_list","incidentio_catalog_types_list","incidentio_custom_fields_create","incidentio_custom_fields_delete","incidentio_custom_fields_list","incidentio_custom_fields_show","incidentio_custom_fields_update","incidentio_escalation_paths_create","incidentio_escalation_paths_delete","incidentio_escalation_paths_list","incidentio_escalation_paths_show","incidentio_escalation_paths_update","incidentio_escalations_cancel","incidentio_escalations_create","incidentio_escalations_list","incidentio_escalations_show","incidentio_follow_ups_create","incidentio_follow_ups_list","incidentio_follow_ups_show","incidentio_follow_ups_update","incidentio_incident_alerts_list","incidentio_incident_memberships_create","incidentio_incident_memberships_revoke","incidentio_incident_participants_list","incidentio_incident_roles_create","incidentio_incident_roles_delete","incidentio_incident_roles_list","incidentio_incident_roles_show","incidentio_incident_roles_update","incidentio_incident_statuses_list","incidentio_incident_timestamps_list","incidentio_incident_timestamps_show","incidentio_incident_types_list","incidentio_incident_updates_list","incidentio_incidents_create","incidentio_incidents_list","incidentio_incidents_show","incidentio_incidents_update","incidentio_on_call_now","incidentio_schedule_entries_list","incidentio_schedule_overrides_create","incidentio_schedule_overrides_list","incidentio_schedules_create","incidentio_schedules_delete","incidentio_schedules_list","incidentio_schedules_show","incidentio_schedules_update","incidentio_severities_list","incidentio_teams_list","incidentio_teams_show","incidentio_users_list","incidentio_users_show","incidentio_workflows_create","incidentio_workflows_delete","incidentio_workflows_list","incidentio_workflows_show","incidentio_workflows_update","infisical_create_secret","infisical_delete_secret","infisical_get_secret","infisical_list_secrets","infisical_update_secret","instagram_delete_comment","instagram_download_media","instagram_get_account_insights","instagram_get_container_status","instagram_get_conversation_messages","instagram_get_media","instagram_get_media_insights","instagram_get_message","instagram_get_profile","instagram_get_publishing_limit","instagram_hide_comment","instagram_list_comments","instagram_list_conversations","instagram_list_media","instagram_list_stories","instagram_private_reply","instagram_publish_carousel","instagram_publish_image","instagram_publish_reel","instagram_publish_story","instagram_publish_video","instagram_reply_to_comment","instagram_send_text_message","instagram_set_comments_enabled","instantly_activate_campaign","instantly_create_campaign","instantly_create_lead","instantly_create_lead_list","instantly_delete_campaign","instantly_delete_leads","instantly_get_lead","instantly_list_campaigns","instantly_list_emails","instantly_list_lead_lists","instantly_list_leads","instantly_patch_campaign","instantly_patch_lead","instantly_pause_campaign","instantly_reply_to_email","instantly_update_lead_interest_status","intercom_assign_conversation_v2","intercom_attach_contact_to_company_v2","intercom_close_conversation_v2","intercom_create_company","intercom_create_company_v2","intercom_create_contact","intercom_create_contact_v2","intercom_create_event_v2","intercom_create_message","intercom_create_message_v2","intercom_create_note_v2","intercom_create_tag_v2","intercom_create_ticket","intercom_create_ticket_v2","intercom_delete_contact","intercom_delete_contact_v2","intercom_detach_contact_from_company_v2","intercom_get_company","intercom_get_company_v2","intercom_get_contact","intercom_get_contact_v2","intercom_get_conversation","intercom_get_conversation_v2","intercom_get_ticket","intercom_get_ticket_v2","intercom_list_admins_v2","intercom_list_companies","intercom_list_companies_v2","intercom_list_contacts","intercom_list_contacts_v2","intercom_list_conversations","intercom_list_conversations_v2","intercom_list_tags_v2","intercom_open_conversation_v2","intercom_reply_conversation","intercom_reply_conversation_v2","intercom_search_contacts","intercom_search_contacts_v2","intercom_search_conversations","intercom_search_conversations_v2","intercom_snooze_conversation_v2","intercom_tag_contact_v2","intercom_tag_conversation_v2","intercom_untag_contact_v2","intercom_update_contact","intercom_update_contact_v2","intercom_update_ticket_v2","jina_read_url","jina_search","jira_add_attachment","jira_add_comment","jira_add_watcher","jira_add_worklog","jira_assign_issue","jira_bulk_read","jira_create_issue_link","jira_delete_attachment","jira_delete_comment","jira_delete_issue","jira_delete_issue_link","jira_delete_worklog","jira_get_attachments","jira_get_comments","jira_get_fields","jira_get_project","jira_get_transitions","jira_get_users","jira_get_worklogs","jira_list_issue_types","jira_list_projects","jira_remove_watcher","jira_retrieve","jira_search_issues","jira_search_users","jira_transition_issue","jira_update","jira_update_comment","jira_update_worklog","jira_write","jotform_add_label_resources","jotform_clone_form","jotform_create_form","jotform_create_label","jotform_create_question","jotform_create_questions","jotform_create_report","jotform_create_submission","jotform_create_submissions","jotform_create_webhook","jotform_delete_form","jotform_delete_label","jotform_delete_question","jotform_delete_report","jotform_delete_submission","jotform_delete_webhook","jotform_get_form","jotform_get_form_properties","jotform_get_history","jotform_get_label","jotform_get_question","jotform_get_report","jotform_get_settings","jotform_get_submission","jotform_get_usage","jotform_get_user","jotform_list_form_files","jotform_list_form_reports","jotform_list_form_submissions","jotform_list_forms","jotform_list_label_resources","jotform_list_labels","jotform_list_questions","jotform_list_reports","jotform_list_submissions","jotform_list_subusers","jotform_list_webhooks","jotform_remove_label_resources","jotform_update_form_properties","jotform_update_label","jotform_update_question","jotform_update_settings","jotform_update_submission","jsm_add_comment","jsm_add_customer","jsm_add_organization","jsm_add_participants","jsm_answer_approval","jsm_attach_form","jsm_copy_forms","jsm_create_object","jsm_create_organization","jsm_create_request","jsm_delete_form","jsm_delete_object","jsm_externalise_form","jsm_get_approvals","jsm_get_comments","jsm_get_customers","jsm_get_form","jsm_get_form_answers","jsm_get_form_structure","jsm_get_form_templates","jsm_get_issue_forms","jsm_get_object","jsm_get_object_schema","jsm_get_object_type_attributes","jsm_get_organizations","jsm_get_participants","jsm_get_queues","jsm_get_request","jsm_get_request_type_fields","jsm_get_request_types","jsm_get_requests","jsm_get_service_desks","jsm_get_sla","jsm_get_transitions","jsm_internalise_form","jsm_list_object_schemas","jsm_list_object_types","jsm_reopen_form","jsm_save_form_answers","jsm_search_objects_aql","jsm_submit_form","jsm_transition_request","jsm_update_object","jupyter_copy_content","jupyter_create_file","jupyter_create_session","jupyter_delete_content","jupyter_delete_session","jupyter_get_content","jupyter_get_content_v2","jupyter_interrupt_kernel","jupyter_list_contents","jupyter_list_kernels","jupyter_list_kernelspecs","jupyter_list_sessions","jupyter_rename_content","jupyter_restart_kernel","jupyter_start_kernel","jupyter_stop_kernel","jupyter_upload_file","kalshi_amend_order","kalshi_amend_order_v2","kalshi_cancel_order","kalshi_cancel_order_v2","kalshi_create_order","kalshi_create_order_v2","kalshi_get_balance","kalshi_get_balance_v2","kalshi_get_candlesticks","kalshi_get_candlesticks_v2","kalshi_get_event","kalshi_get_event_candlesticks","kalshi_get_event_candlesticks_v2","kalshi_get_event_v2","kalshi_get_events","kalshi_get_events_v2","kalshi_get_exchange_announcements","kalshi_get_exchange_announcements_v2","kalshi_get_exchange_schedule","kalshi_get_exchange_schedule_v2","kalshi_get_exchange_status","kalshi_get_exchange_status_v2","kalshi_get_fills","kalshi_get_fills_v2","kalshi_get_market","kalshi_get_market_v2","kalshi_get_markets","kalshi_get_markets_v2","kalshi_get_order","kalshi_get_order_v2","kalshi_get_orderbook","kalshi_get_orderbook_v2","kalshi_get_orders","kalshi_get_orders_v2","kalshi_get_positions","kalshi_get_positions_v2","kalshi_get_series_by_ticker","kalshi_get_series_by_ticker_v2","kalshi_get_series_list","kalshi_get_series_list_v2","kalshi_get_settlements","kalshi_get_settlements_v2","kalshi_get_trades","kalshi_get_trades_v2","ketch_get_consent","ketch_get_subscriptions","ketch_invoke_right","ketch_set_consent","ketch_set_subscriptions","knowledge_create_document","knowledge_delete_chunk","knowledge_delete_document","knowledge_get_connector","knowledge_get_document","knowledge_list_chunks","knowledge_list_connectors","knowledge_list_documents","knowledge_list_tags","knowledge_search","knowledge_trigger_sync","knowledge_update_chunk","knowledge_upload_chunk","knowledge_upsert_document","lambda_add_permission","lambda_create_alias","lambda_create_event_source_mapping","lambda_create_function","lambda_create_function_url_config","lambda_delete_alias","lambda_delete_event_source_mapping","lambda_delete_function","lambda_delete_function_concurrency","lambda_delete_function_event_invoke_config","lambda_delete_function_url_config","lambda_delete_provisioned_concurrency_config","lambda_get_account_settings","lambda_get_alias","lambda_get_event_source_mapping","lambda_get_function","lambda_get_function_concurrency","lambda_get_function_configuration","lambda_get_function_event_invoke_config","lambda_get_function_recursion_config","lambda_get_function_url_config","lambda_get_layer_version","lambda_get_policy","lambda_get_provisioned_concurrency_config","lambda_get_runtime_management_config","lambda_invoke","lambda_list_aliases","lambda_list_event_source_mappings","lambda_list_function_event_invoke_configs","lambda_list_function_url_configs","lambda_list_functions","lambda_list_layer_versions","lambda_list_layers","lambda_list_provisioned_concurrency_configs","lambda_list_tags","lambda_list_versions_by_function","lambda_publish_version","lambda_put_function_concurrency","lambda_put_function_event_invoke_config","lambda_put_function_recursion_config","lambda_put_provisioned_concurrency_config","lambda_put_runtime_management_config","lambda_remove_permission","lambda_tag_resource","lambda_untag_resource","lambda_update_alias","lambda_update_event_source_mapping","lambda_update_function_code","lambda_update_function_configuration","lambda_update_function_url_config","langsmith_create_feedback","langsmith_create_run","langsmith_create_runs_batch","langsmith_get_run","langsmith_update_run","latex_compile","latex_get_package","latex_list_fonts","latex_search_packages","launchdarkly_create_flag","launchdarkly_delete_flag","launchdarkly_get_audit_log","launchdarkly_get_flag","launchdarkly_get_flag_status","launchdarkly_list_environments","launchdarkly_list_flags","launchdarkly_list_members","launchdarkly_list_projects","launchdarkly_list_segments","launchdarkly_toggle_flag","launchdarkly_update_flag","leadmagic_company_search","leadmagic_email_to_profile","leadmagic_find_email","leadmagic_find_mobile","leadmagic_get_credits","leadmagic_profile_search","leadmagic_profile_to_email","leadmagic_role_finder","leadmagic_validate_email","lemlist_get_activities","lemlist_get_lead","lemlist_send_email","linear_add_label_to_issue","linear_add_label_to_project","linear_archive_issue","linear_archive_label","linear_archive_project","linear_create_attachment","linear_create_comment","linear_create_customer","linear_create_customer_request","linear_create_customer_status","linear_create_customer_tier","linear_create_cycle","linear_create_favorite","linear_create_issue","linear_create_issue_relation","linear_create_label","linear_create_project","linear_create_project_label","linear_create_project_milestone","linear_create_project_status","linear_create_project_update","linear_create_workflow_state","linear_delete_attachment","linear_delete_comment","linear_delete_customer","linear_delete_customer_status","linear_delete_customer_tier","linear_delete_issue","linear_delete_issue_relation","linear_delete_project","linear_delete_project_label","linear_delete_project_milestone","linear_delete_project_status","linear_get_active_cycle","linear_get_customer","linear_get_cycle","linear_get_issue","linear_get_project","linear_get_viewer","linear_list_attachments","linear_list_comments","linear_list_customer_requests","linear_list_customer_statuses","linear_list_customer_tiers","linear_list_customers","linear_list_cycles","linear_list_favorites","linear_list_issue_relations","linear_list_labels","linear_list_notifications","linear_list_project_labels","linear_list_project_milestones","linear_list_project_statuses","linear_list_project_updates","linear_list_projects","linear_list_teams","linear_list_users","linear_list_workflow_states","linear_merge_customers","linear_read_issues","linear_remove_label_from_issue","linear_remove_label_from_project","linear_search_issues","linear_unarchive_issue","linear_update_attachment","linear_update_comment","linear_update_customer","linear_update_customer_request","linear_update_customer_status","linear_update_customer_tier","linear_update_issue","linear_update_label","linear_update_notification","linear_update_project","linear_update_project_label","linear_update_project_milestone","linear_update_project_status","linear_update_workflow_state","linkedin_get_profile","linkedin_share_post","linkup_search","linq_add_participant","linq_check_imessage","linq_check_rcs","linq_create_attachment","linq_create_chat","linq_create_contact_card","linq_create_webhook_subscription","linq_delete_attachment","linq_delete_message","linq_delete_webhook_subscription","linq_edit_message","linq_get_attachment","linq_get_chat","linq_get_contact_card","linq_get_message","linq_get_webhook_subscription","linq_leave_chat","linq_list_chats","linq_list_messages","linq_list_phone_numbers","linq_list_thread","linq_list_webhook_events","linq_list_webhook_subscriptions","linq_mark_chat_read","linq_react_to_message","linq_remove_participant","linq_send_message","linq_send_voice_memo","linq_share_contact_card","linq_start_typing","linq_stop_typing","linq_update_chat","linq_update_contact_card","linq_update_webhook_subscription","llm_chat","logfire_get_token_info","logfire_get_trace","logfire_query","logfire_search_records","logrocket_create_release","logrocket_get_audit_logs","logrocket_get_highlights","logrocket_identify_user","logrocket_list_exported_sessions","logrocket_request_highlights","logs_get","logs_get_execution","logs_get_run_details","logs_query","logs_query_runs","loops_check_contact_suppression","loops_create_contact","loops_create_contact_property","loops_delete_contact","loops_find_contact","loops_get_transactional_email","loops_list_contact_properties","loops_list_mailing_lists","loops_list_transactional_emails","loops_remove_contact_suppression","loops_send_event","loops_send_transactional_email","loops_update_contact","luma_add_guests","luma_cancel_event","luma_create_event","luma_get_event","luma_get_guest","luma_get_guests","luma_list_events","luma_lookup_event","luma_send_invites","luma_update_event","luma_update_guest_status","mailchimp_add_member","mailchimp_add_member_tags","mailchimp_add_or_update_member","mailchimp_add_segment_member","mailchimp_add_subscriber_to_automation","mailchimp_archive_member","mailchimp_create_audience","mailchimp_create_batch_operation","mailchimp_create_campaign","mailchimp_create_interest","mailchimp_create_interest_category","mailchimp_create_landing_page","mailchimp_create_merge_field","mailchimp_create_segment","mailchimp_create_template","mailchimp_delete_audience","mailchimp_delete_batch_operation","mailchimp_delete_campaign","mailchimp_delete_interest","mailchimp_delete_interest_category","mailchimp_delete_landing_page","mailchimp_delete_member","mailchimp_delete_merge_field","mailchimp_delete_segment","mailchimp_delete_template","mailchimp_get_audience","mailchimp_get_audiences","mailchimp_get_automation","mailchimp_get_automations","mailchimp_get_batch_operation","mailchimp_get_batch_operations","mailchimp_get_campaign","mailchimp_get_campaign_content","mailchimp_get_campaign_report","mailchimp_get_campaign_reports","mailchimp_get_campaigns","mailchimp_get_interest","mailchimp_get_interest_categories","mailchimp_get_interest_category","mailchimp_get_interests","mailchimp_get_landing_page","mailchimp_get_landing_pages","mailchimp_get_member","mailchimp_get_member_tags","mailchimp_get_members","mailchimp_get_merge_field","mailchimp_get_merge_fields","mailchimp_get_segment","mailchimp_get_segment_members","mailchimp_get_segments","mailchimp_get_template","mailchimp_get_templates","mailchimp_pause_automation","mailchimp_publish_landing_page","mailchimp_remove_member_tags","mailchimp_remove_segment_member","mailchimp_replicate_campaign","mailchimp_schedule_campaign","mailchimp_send_campaign","mailchimp_set_campaign_content","mailchimp_start_automation","mailchimp_unarchive_member","mailchimp_unpublish_landing_page","mailchimp_unschedule_campaign","mailchimp_update_audience","mailchimp_update_campaign","mailchimp_update_interest","mailchimp_update_interest_category","mailchimp_update_landing_page","mailchimp_update_member","mailchimp_update_merge_field","mailchimp_update_segment","mailchimp_update_template","mailgun_add_list_member","mailgun_create_mailing_list","mailgun_get_domain","mailgun_get_mailing_list","mailgun_get_message","mailgun_list_domains","mailgun_list_messages","mailgun_send_message","managed_agent_archive_session","managed_agent_create_session","managed_agent_delete_session","managed_agent_get_session","managed_agent_interrupt_session","managed_agent_list_events","managed_agent_respond_custom_tool","managed_agent_respond_tool_confirmation","managed_agent_run_session","managed_agent_send_message","managed_agent_update_session","manageengine_sdp_add_change_note","manageengine_sdp_add_problem_note","manageengine_sdp_add_request_note","manageengine_sdp_create_asset","manageengine_sdp_create_change","manageengine_sdp_create_problem","manageengine_sdp_create_request","manageengine_sdp_create_solution","manageengine_sdp_delete_asset","manageengine_sdp_delete_change","manageengine_sdp_delete_problem","manageengine_sdp_delete_request","manageengine_sdp_delete_solution","manageengine_sdp_get_asset","manageengine_sdp_get_change","manageengine_sdp_get_problem","manageengine_sdp_get_request","manageengine_sdp_get_solution","manageengine_sdp_list_assets","manageengine_sdp_list_change_notes","manageengine_sdp_list_changes","manageengine_sdp_list_problem_notes","manageengine_sdp_list_problems","manageengine_sdp_list_request_notes","manageengine_sdp_list_requests","manageengine_sdp_list_solutions","manageengine_sdp_update_asset","manageengine_sdp_update_change","manageengine_sdp_update_problem","manageengine_sdp_update_request","manageengine_sdp_update_solution","mcp_list_operations","mcp_run_operation","mem0_add_memories","mem0_get_memories","mem0_search_memories","memory_add","memory_delete","memory_get","memory_get_all","microsoft_ad_add_directory_role_member","microsoft_ad_add_group_member","microsoft_ad_add_user_app_role_assignment","microsoft_ad_assign_license","microsoft_ad_create_group","microsoft_ad_create_user","microsoft_ad_delete_group","microsoft_ad_delete_user","microsoft_ad_get_conditional_access_policy","microsoft_ad_get_device","microsoft_ad_get_group","microsoft_ad_get_user","microsoft_ad_list_authentication_methods","microsoft_ad_list_conditional_access_policies","microsoft_ad_list_devices","microsoft_ad_list_directory_audits","microsoft_ad_list_directory_role_members","microsoft_ad_list_directory_roles","microsoft_ad_list_group_members","microsoft_ad_list_groups","microsoft_ad_list_service_principal_app_role_assignments","microsoft_ad_list_service_principals","microsoft_ad_list_sign_ins","microsoft_ad_list_subscribed_skus","microsoft_ad_list_user_app_role_assignments","microsoft_ad_list_user_devices","microsoft_ad_list_user_licenses","microsoft_ad_list_users","microsoft_ad_remove_directory_role_member","microsoft_ad_remove_group_member","microsoft_ad_remove_user_app_role_assignment","microsoft_ad_reset_password","microsoft_ad_revoke_sign_in_sessions","microsoft_ad_set_password","microsoft_ad_update_group","microsoft_ad_update_user","microsoft_dataverse_associate","microsoft_dataverse_create_multiple","microsoft_dataverse_create_record","microsoft_dataverse_delete_record","microsoft_dataverse_disassociate","microsoft_dataverse_download_file","microsoft_dataverse_download_file_v2","microsoft_dataverse_execute_action","microsoft_dataverse_execute_function","microsoft_dataverse_fetchxml_query","microsoft_dataverse_get_entity_metadata","microsoft_dataverse_get_record","microsoft_dataverse_list_records","microsoft_dataverse_search","microsoft_dataverse_update_multiple","microsoft_dataverse_update_record","microsoft_dataverse_upload_file","microsoft_dataverse_upsert_record","microsoft_dataverse_whoami","microsoft_dynamics_365_close_case","microsoft_dynamics_365_close_opportunity","microsoft_dynamics_365_create_record","microsoft_dynamics_365_get_record","microsoft_dynamics_365_list_records","microsoft_dynamics_365_qualify_lead","microsoft_dynamics_365_search_records","microsoft_dynamics_365_update_record","microsoft_excel_clear_range","microsoft_excel_create_table","microsoft_excel_delete_worksheet","microsoft_excel_format_range","microsoft_excel_read","microsoft_excel_read_v2","microsoft_excel_sort_range","microsoft_excel_table_add","microsoft_excel_worksheet_add","microsoft_excel_write","microsoft_excel_write_v2","microsoft_planner_create_bucket","microsoft_planner_create_plan","microsoft_planner_create_task","microsoft_planner_delete_bucket","microsoft_planner_delete_plan","microsoft_planner_delete_task","microsoft_planner_get_plan_details","microsoft_planner_get_task_details","microsoft_planner_list_buckets","microsoft_planner_list_plans","microsoft_planner_read_bucket","microsoft_planner_read_plan","microsoft_planner_read_task","microsoft_planner_update_bucket","microsoft_planner_update_plan","microsoft_planner_update_plan_details","microsoft_planner_update_task","microsoft_planner_update_task_details","microsoft_teams_delete_channel_message","microsoft_teams_delete_chat_message","microsoft_teams_get_message","microsoft_teams_list_channel_members","microsoft_teams_list_channels","microsoft_teams_list_chat_members","microsoft_teams_list_chats","microsoft_teams_list_team_members","microsoft_teams_list_teams","microsoft_teams_read_channel","microsoft_teams_read_chat","microsoft_teams_reply_to_message","microsoft_teams_set_reaction","microsoft_teams_unset_reaction","microsoft_teams_update_channel_message","microsoft_teams_update_chat_message","microsoft_teams_write_channel","microsoft_teams_write_chat","microsoft_word_append","microsoft_word_create","microsoft_word_create_from_template","microsoft_word_export_pdf","microsoft_word_list","microsoft_word_read","microsoft_word_replace_text","microsoft_word_update","millionverifier_get_credits","millionverifier_verify_email","mintlify_create_agent_job","mintlify_create_assistant_message","mintlify_detect_ai_prose","mintlify_get_agent_job","mintlify_get_assistant_caller_stats","mintlify_get_assistant_conversations","mintlify_get_feedback","mintlify_get_feedback_by_page","mintlify_get_page_content","mintlify_get_searches","mintlify_get_update_status","mintlify_get_views","mintlify_get_visitors","mintlify_search","mintlify_send_agent_message","mintlify_trigger_automation","mintlify_trigger_preview","mintlify_trigger_update","mistral_parser","mistral_parser_v2","mistral_parser_v3","modal_call_function","modal_chat_completion","modal_list_models","monday_archive_item","monday_change_column_value","monday_create_board","monday_create_column","monday_create_group","monday_create_item","monday_create_subitem","monday_create_update","monday_delete_item","monday_duplicate_item","monday_get_board","monday_get_groups","monday_get_item","monday_get_items","monday_list_boards","monday_move_item_to_group","monday_search_items","monday_update_item","mongodb_delete","mongodb_execute","mongodb_insert","mongodb_introspect","mongodb_query","mongodb_update","mssql_delete","mssql_execute","mssql_insert","mssql_introspect","mssql_query","mssql_update","mysql_delete","mysql_execute","mysql_insert","mysql_introspect","mysql_query","mysql_update","neo4j_create","neo4j_delete","neo4j_execute","neo4j_introspect","neo4j_merge","neo4j_query","neo4j_update","netsuite_attach_record","netsuite_batch_create_records","netsuite_batch_delete_records","netsuite_batch_get_records","netsuite_batch_update_records","netsuite_batch_upsert_records","netsuite_create_record","netsuite_delete_record","netsuite_detach_record","netsuite_execute_action","netsuite_execute_dataset","netsuite_execute_suiteql","netsuite_get_async_result","netsuite_get_async_status","netsuite_get_governance_limits","netsuite_get_record","netsuite_get_record_form","netsuite_get_record_metadata","netsuite_get_select_options","netsuite_get_server_time","netsuite_get_subresource","netsuite_list_datasets","netsuite_list_record_types","netsuite_list_records","netsuite_transform_record","netsuite_update_record","netsuite_upsert_record","neverbounce_get_credits","neverbounce_verify_email","new_relic_create_deployment_event","new_relic_get_entity","new_relic_nrql_query","new_relic_search_entities","notion_add_database_row","notion_add_database_row_v2","notion_append_blocks","notion_append_blocks_v2","notion_create_comment","notion_create_comment_v2","notion_create_database","notion_create_database_v2","notion_create_page","notion_create_page_v2","notion_delete_block","notion_delete_block_v2","notion_list_comments","notion_list_comments_v2","notion_list_users","notion_list_users_v2","notion_query_database","notion_query_database_v2","notion_read","notion_read_database","notion_read_database_v2","notion_read_v2","notion_retrieve_block","notion_retrieve_block_children","notion_retrieve_block_children_v2","notion_retrieve_block_v2","notion_retrieve_user","notion_retrieve_user_v2","notion_search","notion_search_v2","notion_update_block","notion_update_block_v2","notion_update_page","notion_update_page_v2","notion_write","notion_write_v2","obsidian_append_active","obsidian_append_note","obsidian_append_periodic_note","obsidian_create_note","obsidian_delete_note","obsidian_execute_command","obsidian_get_active","obsidian_get_note","obsidian_get_periodic_note","obsidian_list_commands","obsidian_list_files","obsidian_open_file","obsidian_patch_active","obsidian_patch_note","obsidian_search","okta_activate_group_rule","okta_activate_user","okta_add_user_to_group","okta_assign_group_to_app","okta_assign_user_role","okta_assign_user_to_app","okta_clear_user_sessions","okta_create_group","okta_create_group_rule","okta_create_user","okta_deactivate_group_rule","okta_deactivate_user","okta_delete_group","okta_delete_group_rule","okta_delete_user","okta_enroll_factor","okta_get_app","okta_get_factor","okta_get_group","okta_get_group_rule","okta_get_logs","okta_get_session","okta_get_user","okta_list_app_groups","okta_list_app_users","okta_list_apps","okta_list_factors","okta_list_group_members","okta_list_group_rules","okta_list_groups","okta_list_user_roles","okta_list_users","okta_remove_group_from_app","okta_remove_user_from_app","okta_remove_user_from_group","okta_remove_user_role","okta_reset_all_factors","okta_reset_factor","okta_reset_password","okta_revoke_session","okta_suspend_user","okta_unsuspend_user","okta_update_group","okta_update_user","onedrive_copy","onedrive_create_folder","onedrive_create_share_link","onedrive_delete","onedrive_download","onedrive_get_drive_info","onedrive_get_item","onedrive_list","onedrive_move","onedrive_search","onedrive_upload","onepassword_create_item","onepassword_delete_item","onepassword_get_item","onepassword_get_item_file","onepassword_get_vault","onepassword_list_items","onepassword_list_vaults","onepassword_replace_item","onepassword_resolve_secret","onepassword_update_item","openai_embeddings","openai_image","outlook_calendar_create_event","outlook_calendar_delete_event","outlook_calendar_get_event","outlook_calendar_list_events","outlook_calendar_respond","outlook_calendar_update_event","outlook_copy","outlook_create_folder","outlook_delete","outlook_draft","outlook_forward","outlook_get_attachment","outlook_list_attachments","outlook_list_folders","outlook_mark_read","outlook_mark_unread","outlook_move","outlook_read","outlook_reply","outlook_reply_all","outlook_search","outlook_send","outlook_update_message","pagerduty_add_note","pagerduty_create_incident","pagerduty_get_incident","pagerduty_get_service","pagerduty_list_escalation_policies","pagerduty_list_incident_alerts","pagerduty_list_incidents","pagerduty_list_oncalls","pagerduty_list_schedules","pagerduty_list_services","pagerduty_list_users","pagerduty_merge_incidents","pagerduty_send_event","pagerduty_snooze_incident","pagerduty_update_incident","parallel_deep_research","parallel_extract","parallel_search","pdl_autocomplete","pdl_bulk_company_enrich","pdl_bulk_person_enrich","pdl_clean_company","pdl_clean_location","pdl_clean_school","pdl_company_enrich","pdl_company_search","pdl_person_enrich","pdl_person_identify","pdl_person_search","perplexity_chat","perplexity_search","persona_approve_inquiry","persona_create_account","persona_create_inquiry","persona_create_report","persona_decline_inquiry","persona_expire_inquiry","persona_generate_inquiry_link","persona_get_account","persona_get_case","persona_get_document","persona_get_inquiry","persona_get_report","persona_get_verification","persona_import_accounts","persona_list_accounts","persona_list_cases","persona_list_inquiries","persona_list_inquiry_templates","persona_list_reports","persona_mark_inquiry_for_review","persona_print_inquiry_pdf","persona_redact_account","persona_redact_inquiry","persona_resume_inquiry","persona_update_account","persona_update_inquiry","pinecone_delete_vectors","pinecone_describe_index","pinecone_describe_index_stats","pinecone_fetch","pinecone_generate_embeddings","pinecone_list_indexes","pinecone_list_vector_ids","pinecone_search_text","pinecone_search_vector","pinecone_update_vector","pinecone_upsert_text","pipedrive_create_activity","pipedrive_create_deal","pipedrive_create_lead","pipedrive_create_project","pipedrive_delete_lead","pipedrive_get_activities","pipedrive_get_all_deals","pipedrive_get_deal","pipedrive_get_files","pipedrive_get_leads","pipedrive_get_mail_messages","pipedrive_get_mail_thread","pipedrive_get_pipeline_deals","pipedrive_get_pipelines","pipedrive_get_projects","pipedrive_update_activity","pipedrive_update_deal","pipedrive_update_lead","pitchbook_company_active_investors","pitchbook_company_bio","pitchbook_company_deal_service_providers","pitchbook_company_deals","pitchbook_company_financials","pitchbook_company_general_service_providers","pitchbook_company_industries","pitchbook_company_investors","pitchbook_company_most_recent_debt_financing","pitchbook_company_most_recent_financials","pitchbook_company_most_recent_financing","pitchbook_company_search","pitchbook_company_similar_companies","pitchbook_company_social_analytics","pitchbook_company_updates","pitchbook_company_vc_exit_predictions","pitchbook_contracts_history","pitchbook_cost_of_calls","pitchbook_credit_history","pitchbook_credit_news","pitchbook_credit_news_bulk","pitchbook_credit_news_most_recent","pitchbook_credit_news_search","pitchbook_deal_bio","pitchbook_deal_cap_table_history","pitchbook_deal_debt_lenders","pitchbook_deal_detailed","pitchbook_deal_investors","pitchbook_deal_multiples","pitchbook_deal_search","pitchbook_deal_service_providers","pitchbook_deal_stock_info","pitchbook_deal_tranche_info","pitchbook_deal_updates","pitchbook_deal_valuation","pitchbook_entity_affiliates","pitchbook_entity_locations","pitchbook_entity_news","pitchbook_entity_people","pitchbook_entity_updates","pitchbook_fund_active_investments","pitchbook_fund_benchmark","pitchbook_fund_bio","pitchbook_fund_cash_flows","pitchbook_fund_commitments","pitchbook_fund_investment_preferences","pitchbook_fund_investments","pitchbook_fund_performance","pitchbook_fund_search","pitchbook_fund_team","pitchbook_fund_updates","pitchbook_investor_active_investments","pitchbook_investor_bio","pitchbook_investor_board_seats","pitchbook_investor_deal_service_providers","pitchbook_investor_funds","pitchbook_investor_general_service_providers","pitchbook_investor_investments","pitchbook_investor_last_closed_fund","pitchbook_investor_preferences","pitchbook_investor_search","pitchbook_investor_updates","pitchbook_limited_partner_actual_allocations","pitchbook_limited_partner_bio","pitchbook_limited_partner_commitment_aggregates","pitchbook_limited_partner_commitment_preferences","pitchbook_limited_partner_commitments_detailed","pitchbook_limited_partner_search","pitchbook_limited_partner_service_providers","pitchbook_limited_partner_target_allocations","pitchbook_limited_partner_updates","pitchbook_lookup_table_structure","pitchbook_lookup_tables","pitchbook_patent_detailed","pitchbook_patent_search","pitchbook_people_search","pitchbook_person_bio","pitchbook_person_contact","pitchbook_person_education_work","pitchbook_sandbox_entities","pitchbook_search","pitchbook_service_provider_bio","pitchbook_service_provider_search","pitchbook_service_provider_updates","pitchbook_serviced_companies","pitchbook_serviced_deals","pitchbook_serviced_funds","pitchbook_serviced_investors","pitchbook_serviced_limited_partners","pitchbook_shared_search","pitchbook_usage_report","polymarket_get_activity","polymarket_get_event","polymarket_get_events","polymarket_get_holders","polymarket_get_last_trade_price","polymarket_get_leaderboard","polymarket_get_market","polymarket_get_markets","polymarket_get_midpoint","polymarket_get_orderbook","polymarket_get_positions","polymarket_get_price","polymarket_get_price_history","polymarket_get_series","polymarket_get_series_by_id","polymarket_get_spread","polymarket_get_tags","polymarket_get_tick_size","polymarket_get_trades","polymarket_search","postgresql_delete","postgresql_execute","postgresql_insert","postgresql_introspect","postgresql_query","postgresql_update","posthog_batch_events","posthog_capture_event","posthog_create_annotation","posthog_create_cohort","posthog_create_dashboard","posthog_create_experiment","posthog_create_feature_flag","posthog_create_insight","posthog_create_survey","posthog_delete_feature_flag","posthog_delete_person","posthog_delete_survey","posthog_evaluate_flags","posthog_get_cohort","posthog_get_dashboard","posthog_get_event_definition","posthog_get_experiment","posthog_get_feature_flag","posthog_get_insight","posthog_get_organization","posthog_get_person","posthog_get_project","posthog_get_property_definition","posthog_get_session_recording","posthog_get_survey","posthog_list_actions","posthog_list_annotations","posthog_list_cohorts","posthog_list_dashboards","posthog_list_event_definitions","posthog_list_experiments","posthog_list_feature_flags","posthog_list_insights","posthog_list_organizations","posthog_list_persons","posthog_list_projects","posthog_list_property_definitions","posthog_list_recording_playlists","posthog_list_session_recordings","posthog_list_surveys","posthog_query","posthog_update_cohort","posthog_update_event_definition","posthog_update_experiment","posthog_update_feature_flag","posthog_update_insight","posthog_update_property_definition","posthog_update_survey","profound_bot_logs","profound_bots_report","profound_category_assets","profound_category_personas","profound_category_prompts","profound_category_tags","profound_category_topics","profound_citation_prompts","profound_citations_report","profound_list_assets","profound_list_categories","profound_list_domains","profound_list_models","profound_list_optimizations","profound_list_personas","profound_list_regions","profound_optimization_analysis","profound_prompt_answers","profound_prompt_volume","profound_query_fanouts","profound_raw_logs","profound_referrals_report","profound_sentiment_report","profound_visibility_report","prospeo_account_information","prospeo_bulk_enrich_company","prospeo_bulk_enrich_person","prospeo_enrich_company","prospeo_enrich_person","prospeo_search_company","prospeo_search_person","prospeo_search_suggestions","pulse_parser","pulse_parser_v2","qdrant_fetch_points","qdrant_search_vector","qdrant_upsert_points","quartr_get_audio","quartr_get_company","quartr_get_event","quartr_get_event_summary","quartr_get_report","quartr_get_slide_deck","quartr_get_transcript","quartr_list_audio","quartr_list_companies","quartr_list_document_types","quartr_list_documents","quartr_list_event_types","quartr_list_events","quartr_list_live_events","quartr_list_reports","quartr_list_slide_decks","quartr_list_transcripts","quickbooks_add_attachment","quickbooks_create_bill","quickbooks_create_bill_payment","quickbooks_create_credit_memo","quickbooks_create_customer","quickbooks_create_customer_payment","quickbooks_create_deposit","quickbooks_create_employee","quickbooks_create_estimate","quickbooks_create_invoice","quickbooks_create_item","quickbooks_create_journal_entry","quickbooks_create_purchase","quickbooks_create_purchase_order","quickbooks_create_refund_receipt","quickbooks_create_sales_receipt","quickbooks_create_vendor","quickbooks_create_vendor_credit","quickbooks_download_attachment","quickbooks_download_transaction_pdf","quickbooks_email_transaction","quickbooks_get_company_info","quickbooks_read_accounting_transactions","quickbooks_read_attachments","quickbooks_read_master_data","quickbooks_read_purchasing_transactions","quickbooks_read_sales_transactions","quickbooks_run_financial_report","quickbooks_update_bill","quickbooks_update_bill_payment","quickbooks_update_credit_memo","quickbooks_update_customer","quickbooks_update_customer_payment","quickbooks_update_deposit","quickbooks_update_employee","quickbooks_update_estimate","quickbooks_update_invoice","quickbooks_update_item","quickbooks_update_journal_entry","quickbooks_update_purchase","quickbooks_update_purchase_order","quickbooks_update_refund_receipt","quickbooks_update_sales_receipt","quickbooks_update_vendor","quickbooks_update_vendor_credit","quickbooks_void_bill_payment","quickbooks_void_customer_payment","quickbooks_void_invoice","quickbooks_void_sales_receipt","quiver_image_to_svg","quiver_image_to_svg_v2","quiver_list_models","quiver_text_to_svg","quiver_text_to_svg_v2","rabbitmq_create_binding","rabbitmq_create_exchange","rabbitmq_create_policy","rabbitmq_create_queue","rabbitmq_delete_binding","rabbitmq_delete_exchange","rabbitmq_delete_policy","rabbitmq_delete_queue","rabbitmq_get_exchange","rabbitmq_get_messages","rabbitmq_get_overview","rabbitmq_get_queue","rabbitmq_health_check","rabbitmq_list_bindings","rabbitmq_list_channels","rabbitmq_list_connections","rabbitmq_list_consumers","rabbitmq_list_exchange_bindings","rabbitmq_list_exchanges","rabbitmq_list_nodes","rabbitmq_list_policies","rabbitmq_list_queues","rabbitmq_list_vhosts","rabbitmq_publish_message","rabbitmq_purge_queue","railway_create_environment","railway_create_project","railway_create_service","railway_delete_environment","railway_delete_project","railway_delete_service","railway_delete_variable","railway_deploy_service","railway_get_deployment","railway_get_deployment_logs","railway_get_project","railway_list_deployments","railway_list_project_members","railway_list_projects","railway_list_variables","railway_restart_deployment","railway_rollback_deployment","railway_transfer_project","railway_update_project","railway_upsert_variable","rb2b_credit_check","rb2b_email_to_activity","rb2b_hem_to_best_linkedin","rb2b_hem_to_business_profile","rb2b_hem_to_linkedin","rb2b_hem_to_maid","rb2b_ip_to_company","rb2b_ip_to_hem","rb2b_ip_to_maid","rb2b_linkedin_slug_search","rb2b_linkedin_to_best_personal_email","rb2b_linkedin_to_business_profile","rb2b_linkedin_to_hashed_emails","rb2b_linkedin_to_mobile_phone","rb2b_linkedin_to_personal_email","rds_delete","rds_execute","rds_insert","rds_introspect","rds_query","rds_update","reddit_delete","reddit_edit","reddit_get_comments","reddit_get_controversial","reddit_get_info","reddit_get_me","reddit_get_messages","reddit_get_posts","reddit_get_saved","reddit_get_subreddit_info","reddit_get_subreddit_rules","reddit_get_user","reddit_get_user_comments","reddit_get_user_posts","reddit_hide","reddit_hot_posts","reddit_list_my_subreddits","reddit_lock","reddit_mark_all_read","reddit_mark_read","reddit_marknsfw","reddit_mod_approve","reddit_mod_distinguish","reddit_mod_remove","reddit_mod_sticky","reddit_reply","reddit_report","reddit_save","reddit_search","reddit_search_subreddits","reddit_send_message","reddit_submit_post","reddit_subscribe","reddit_unhide","reddit_unlock","reddit_unmarknsfw","reddit_unsave","reddit_vote","redis_command","redis_delete","redis_exists","redis_expire","redis_get","redis_hdel","redis_hget","redis_hgetall","redis_hset","redis_incr","redis_incrby","redis_keys","redis_llen","redis_lpop","redis_lpush","redis_lrange","redis_persist","redis_rpop","redis_rpush","redis_set","redis_setnx","redis_ttl","reducto_parser","reducto_parser_v2","resend_cancel_email","resend_create_audience","resend_create_broadcast","resend_create_contact","resend_delete_audience","resend_delete_contact","resend_get_audience","resend_get_broadcast","resend_get_contact","resend_get_email","resend_list_audiences","resend_list_contacts","resend_list_domains","resend_send","resend_send_broadcast","resend_update_contact","revenuecat_create_purchase","revenuecat_defer_google_subscription","revenuecat_delete_customer","revenuecat_get_customer","revenuecat_grant_entitlement","revenuecat_list_offerings","revenuecat_refund_google_subscription","revenuecat_revoke_entitlement","revenuecat_revoke_google_subscription","revenuecat_update_subscriber_attributes","rippling_bulk_create_custom_object_records","rippling_bulk_delete_custom_object_records","rippling_bulk_update_custom_object_records","rippling_create_business_partner","rippling_create_business_partner_group","rippling_create_custom_app","rippling_create_custom_object","rippling_create_custom_object_field","rippling_create_custom_object_record","rippling_create_custom_page","rippling_create_custom_setting","rippling_create_department","rippling_create_draft_hires","rippling_create_object_category","rippling_create_title","rippling_create_work_location","rippling_delete_business_partner","rippling_delete_business_partner_group","rippling_delete_custom_app","rippling_delete_custom_object","rippling_delete_custom_object_field","rippling_delete_custom_object_record","rippling_delete_custom_page","rippling_delete_custom_setting","rippling_delete_object_category","rippling_delete_title","rippling_delete_work_location","rippling_get_business_partner","rippling_get_business_partner_group","rippling_get_current_user","rippling_get_custom_app","rippling_get_custom_object","rippling_get_custom_object_field","rippling_get_custom_object_record","rippling_get_custom_object_record_by_external_id","rippling_get_custom_page","rippling_get_custom_setting","rippling_get_department","rippling_get_employment_type","rippling_get_job_function","rippling_get_object_category","rippling_get_report_run","rippling_get_supergroup","rippling_get_team","rippling_get_title","rippling_get_user","rippling_get_work_location","rippling_get_worker","rippling_list_business_partner_groups","rippling_list_business_partners","rippling_list_companies","rippling_list_custom_apps","rippling_list_custom_fields","rippling_list_custom_object_fields","rippling_list_custom_object_records","rippling_list_custom_objects","rippling_list_custom_pages","rippling_list_custom_settings","rippling_list_departments","rippling_list_employment_types","rippling_list_entitlements","rippling_list_job_functions","rippling_list_object_categories","rippling_list_supergroup_exclusion_members","rippling_list_supergroup_inclusion_members","rippling_list_supergroup_members","rippling_list_supergroups","rippling_list_teams","rippling_list_titles","rippling_list_users","rippling_list_work_locations","rippling_list_workers","rippling_query_custom_object_records","rippling_trigger_report_run","rippling_update_custom_app","rippling_update_custom_object","rippling_update_custom_object_field","rippling_update_custom_object_record","rippling_update_custom_page","rippling_update_custom_setting","rippling_update_department","rippling_update_object_category","rippling_update_supergroup_exclusion_members","rippling_update_supergroup_inclusion_members","rippling_update_title","rippling_update_work_location","rocketlane_add_field_option","rocketlane_add_project_members","rocketlane_add_task_assignees","rocketlane_add_task_dependencies","rocketlane_add_task_followers","rocketlane_archive_project","rocketlane_assign_placeholders","rocketlane_create_field","rocketlane_create_phase","rocketlane_create_project","rocketlane_create_space","rocketlane_create_space_document","rocketlane_create_task","rocketlane_create_time_entry","rocketlane_create_time_off","rocketlane_delete_field","rocketlane_delete_phase","rocketlane_delete_project","rocketlane_delete_space","rocketlane_delete_space_document","rocketlane_delete_task","rocketlane_delete_time_entry","rocketlane_delete_time_off","rocketlane_get_field","rocketlane_get_invoice","rocketlane_get_invoice_line_items","rocketlane_get_invoice_payments","rocketlane_get_phase","rocketlane_get_project","rocketlane_get_space","rocketlane_get_space_document","rocketlane_get_task","rocketlane_get_time_entry","rocketlane_get_time_off","rocketlane_get_user","rocketlane_import_template","rocketlane_list_fields","rocketlane_list_invoices","rocketlane_list_phases","rocketlane_list_placeholders","rocketlane_list_projects","rocketlane_list_resource_allocations","rocketlane_list_space_documents","rocketlane_list_spaces","rocketlane_list_tasks","rocketlane_list_time_entries","rocketlane_list_time_entry_categories","rocketlane_list_time_offs","rocketlane_list_users","rocketlane_move_task_to_phase","rocketlane_remove_project_members","rocketlane_remove_task_assignees","rocketlane_remove_task_dependencies","rocketlane_remove_task_followers","rocketlane_search_time_entries","rocketlane_unassign_placeholders","rocketlane_update_field","rocketlane_update_field_option","rocketlane_update_phase","rocketlane_update_project","rocketlane_update_space","rocketlane_update_space_document","rocketlane_update_task","rocketlane_update_time_entry","rootly_acknowledge_alert","rootly_add_incident_event","rootly_add_subscribers","rootly_assign_incident_role","rootly_create_action_item","rootly_create_alert","rootly_create_incident","rootly_create_status_page_event","rootly_delete_action_item","rootly_delete_incident","rootly_escalate_alert","rootly_get_alert","rootly_get_incident","rootly_list_action_items","rootly_list_alerts","rootly_list_causes","rootly_list_environments","rootly_list_escalation_policies","rootly_list_functionalities","rootly_list_incident_events","rootly_list_incident_roles","rootly_list_incident_types","rootly_list_incidents","rootly_list_on_calls","rootly_list_playbooks","rootly_list_retrospectives","rootly_list_schedules","rootly_list_services","rootly_list_severities","rootly_list_teams","rootly_list_users","rootly_mitigate_incident","rootly_remove_subscribers","rootly_resolve_alert","rootly_resolve_incident","rootly_run_workflow","rootly_snooze_alert","rootly_unassign_incident_role","rootly_update_action_item","rootly_update_alert","rootly_update_incident","s3_copy_object","s3_create_bucket","s3_delete_bucket","s3_delete_object","s3_delete_objects","s3_get_object","s3_head_object","s3_list_buckets","s3_list_objects","s3_presigned_url","s3_put_object","sailpoint_approve_access_request","sailpoint_cancel_access_request","sailpoint_decide_certification_review_items","sailpoint_get_access_profile","sailpoint_get_access_profile_entitlements","sailpoint_get_access_request_config","sailpoint_get_access_request_status","sailpoint_get_account","sailpoint_get_account_activity","sailpoint_get_account_entitlements","sailpoint_get_account_selections","sailpoint_get_campaign","sailpoint_get_certification","sailpoint_get_entitlement","sailpoint_get_entitlement_request_config","sailpoint_get_identity","sailpoint_get_role","sailpoint_get_role_entitlements","sailpoint_get_source","sailpoint_get_task_status","sailpoint_list_access_profiles","sailpoint_list_account_activities","sailpoint_list_accounts","sailpoint_list_campaigns","sailpoint_list_certification_review_items","sailpoint_list_certifications","sailpoint_list_entitlements","sailpoint_list_identities","sailpoint_list_identity_entitlements","sailpoint_list_pending_access_request_approvals","sailpoint_list_roles","sailpoint_list_sources","sailpoint_load_accounts","sailpoint_load_entitlements","sailpoint_reject_access_request","sailpoint_request_access","sailpoint_search","sailpoint_search_aggregate","sailpoint_search_count","sailpoint_sign_off_certification","salesforce_create_account","salesforce_create_case","salesforce_create_contact","salesforce_create_custom_field","salesforce_create_custom_object","salesforce_create_lead","salesforce_create_opportunity","salesforce_create_task","salesforce_delete_account","salesforce_delete_case","salesforce_delete_contact","salesforce_delete_custom_field","salesforce_delete_lead","salesforce_delete_opportunity","salesforce_delete_task","salesforce_describe_object","salesforce_get_accounts","salesforce_get_cases","salesforce_get_contacts","salesforce_get_dashboard","salesforce_get_leads","salesforce_get_opportunities","salesforce_get_report","salesforce_get_tasks","salesforce_list_dashboards","salesforce_list_objects","salesforce_list_report_types","salesforce_list_reports","salesforce_query","salesforce_query_more","salesforce_refresh_dashboard","salesforce_run_report","salesforce_tooling_query","salesforce_update_account","salesforce_update_case","salesforce_update_contact","salesforce_update_custom_field","salesforce_update_lead","salesforce_update_opportunity","salesforce_update_task","sap_concur_approve_expense_report","sap_concur_associate_attendees","sap_concur_create_cash_advance","sap_concur_create_expected_expense","sap_concur_create_expense_report","sap_concur_create_list_item","sap_concur_create_purchase_request","sap_concur_create_quick_expense","sap_concur_create_quick_expense_with_image","sap_concur_create_report_comment","sap_concur_create_travel_request","sap_concur_create_user","sap_concur_delete_expected_expense","sap_concur_delete_expense","sap_concur_delete_expense_report","sap_concur_delete_list_item","sap_concur_delete_travel_request","sap_concur_delete_user","sap_concur_get_allocation","sap_concur_get_budget","sap_concur_get_cash_advance","sap_concur_get_expected_expense","sap_concur_get_expense","sap_concur_get_expense_report","sap_concur_get_itemizations","sap_concur_get_itinerary","sap_concur_get_list","sap_concur_get_list_item","sap_concur_get_purchase_request","sap_concur_get_receipt","sap_concur_get_receipt_status","sap_concur_get_request_cash_advance","sap_concur_get_travel_profile","sap_concur_get_travel_request","sap_concur_get_user","sap_concur_issue_cash_advance","sap_concur_list_allocations","sap_concur_list_attendee_associations","sap_concur_list_budget_categories","sap_concur_list_budgets","sap_concur_list_exceptions","sap_concur_list_expected_expenses","sap_concur_list_expense_reports","sap_concur_list_expenses","sap_concur_list_itineraries","sap_concur_list_list_items","sap_concur_list_lists","sap_concur_list_receipts","sap_concur_list_report_comments","sap_concur_list_reports_to_approve","sap_concur_list_travel_profiles_summary","sap_concur_list_travel_request_comments","sap_concur_list_travel_requests","sap_concur_list_users","sap_concur_move_travel_request","sap_concur_recall_expense_report","sap_concur_remove_all_attendees","sap_concur_search_locations","sap_concur_search_users","sap_concur_send_back_expense_report","sap_concur_submit_expense_report","sap_concur_update_allocation","sap_concur_update_expected_expense","sap_concur_update_expense","sap_concur_update_expense_report","sap_concur_update_list_item","sap_concur_update_travel_request","sap_concur_update_user","sap_concur_upload_exchange_rates","sap_concur_upload_receipt_image","sap_s4hana_create_business_partner","sap_s4hana_create_purchase_order","sap_s4hana_create_purchase_requisition","sap_s4hana_create_sales_order","sap_s4hana_delete_sales_order","sap_s4hana_get_billing_document","sap_s4hana_get_business_partner","sap_s4hana_get_customer","sap_s4hana_get_inbound_delivery","sap_s4hana_get_material_document","sap_s4hana_get_outbound_delivery","sap_s4hana_get_product","sap_s4hana_get_purchase_order","sap_s4hana_get_purchase_requisition","sap_s4hana_get_sales_order","sap_s4hana_get_supplier","sap_s4hana_get_supplier_invoice","sap_s4hana_list_billing_documents","sap_s4hana_list_business_partners","sap_s4hana_list_customers","sap_s4hana_list_inbound_deliveries","sap_s4hana_list_material_documents","sap_s4hana_list_material_stock","sap_s4hana_list_outbound_deliveries","sap_s4hana_list_products","sap_s4hana_list_purchase_orders","sap_s4hana_list_purchase_requisitions","sap_s4hana_list_sales_orders","sap_s4hana_list_supplier_invoices","sap_s4hana_list_suppliers","sap_s4hana_odata_query","sap_s4hana_update_business_partner","sap_s4hana_update_customer","sap_s4hana_update_product","sap_s4hana_update_purchase_order","sap_s4hana_update_purchase_requisition","sap_s4hana_update_sales_order","sap_s4hana_update_supplier","search_tool","secrets_manager_create_secret","secrets_manager_delete_secret","secrets_manager_describe_secret","secrets_manager_get_secret","secrets_manager_list_secrets","secrets_manager_restore_secret","secrets_manager_rotate_secret","secrets_manager_tag_resource","secrets_manager_untag_resource","secrets_manager_update_secret","semrush_backlinks","semrush_backlinks_anchors","semrush_backlinks_competitors","semrush_backlinks_geo_distribution","semrush_backlinks_indexed_pages","semrush_backlinks_overview","semrush_backlinks_tld_distribution","semrush_batch_keyword_overview","semrush_broad_match_keywords","semrush_domain_ad_copies","semrush_domain_ad_history","semrush_domain_organic_competitors","semrush_domain_organic_keywords","semrush_domain_overview","semrush_domain_overview_all","semrush_domain_overview_history","semrush_domain_paid_competitors","semrush_domain_paid_keywords","semrush_domain_pla_copies","semrush_domain_pla_keywords","semrush_domain_vs_domain","semrush_keyword_ad_history","semrush_keyword_difficulty","semrush_keyword_overview","semrush_keyword_overview_all","semrush_keyword_questions","semrush_organic_results","semrush_paid_results","semrush_referring_domains","semrush_referring_ips","semrush_related_keywords","semrush_subdomain_ad_copies","semrush_subdomain_organic_keywords","semrush_subdomain_overview","semrush_subdomain_overview_all","semrush_subdomain_overview_history","semrush_subdomain_paid_keywords","semrush_top_domains","semrush_url_organic_keywords","semrush_url_overview","semrush_url_overview_all","semrush_url_overview_history","semrush_url_paid_keywords","semrush_winners_and_losers","sendblue_evaluate_service","sendblue_get_message","sendblue_send_group_message","sendblue_send_message","sendblue_send_typing_indicator","sendgrid_add_contact","sendgrid_add_contacts_to_list","sendgrid_create_list","sendgrid_create_template","sendgrid_create_template_version","sendgrid_delete_contacts","sendgrid_delete_list","sendgrid_delete_template","sendgrid_get_contact","sendgrid_get_list","sendgrid_get_template","sendgrid_list_all_lists","sendgrid_list_templates","sendgrid_remove_contacts_from_list","sendgrid_search_contacts","sendgrid_send_mail","sentry_events_get","sentry_events_list","sentry_issues_get","sentry_issues_list","sentry_issues_update","sentry_projects_create","sentry_projects_get","sentry_projects_list","sentry_projects_update","sentry_releases_create","sentry_releases_deploy","sentry_releases_list","sentry_teams_list","serper_search","servicenow_add_incident_comment","servicenow_aggregate","servicenow_close_incident","servicenow_create_change_request","servicenow_create_incident","servicenow_create_record","servicenow_delete_record","servicenow_download_attachment","servicenow_download_attachment_v2","servicenow_find_user","servicenow_get_change_next_states","servicenow_get_change_request","servicenow_get_ci","servicenow_get_incident","servicenow_get_knowledge_article","servicenow_get_requested_item","servicenow_list_approvals","servicenow_list_attachments","servicenow_list_catalog_items","servicenow_list_change_requests","servicenow_list_change_tasks","servicenow_list_ci_relationships","servicenow_list_group_members","servicenow_list_incidents","servicenow_list_requested_items","servicenow_order_catalog_item","servicenow_read_record","servicenow_resolve_incident","servicenow_search_cis","servicenow_search_knowledge","servicenow_update_approval","servicenow_update_change_request","servicenow_update_change_state","servicenow_update_incident","servicenow_update_record","servicenow_upload_attachment","ses_create_configuration_set","ses_create_email_identity","ses_create_template","ses_delete_email_identity","ses_delete_suppressed_destination","ses_delete_template","ses_get_account","ses_get_email_identity","ses_get_suppressed_destination","ses_get_template","ses_list_identities","ses_list_suppressed_destinations","ses_list_templates","ses_put_suppressed_destination","ses_send_bulk_email","ses_send_custom_verification_email","ses_send_email","ses_send_templated_email","ses_update_template","sftp_delete","sftp_download","sftp_download_v2","sftp_list","sftp_mkdir","sftp_upload","sharepoint_add_list_items","sharepoint_create_list","sharepoint_create_page","sharepoint_delete_file","sharepoint_delete_list_item","sharepoint_delete_page","sharepoint_download_file","sharepoint_get_drive_item","sharepoint_get_list","sharepoint_get_list_item","sharepoint_list_sites","sharepoint_publish_page","sharepoint_read_page","sharepoint_update_list","sharepoint_update_page","sharepoint_upload_file","shopify_adjust_inventory","shopify_cancel_order","shopify_create_customer","shopify_create_fulfillment","shopify_create_product","shopify_delete_customer","shopify_delete_product","shopify_get_collection","shopify_get_customer","shopify_get_inventory_level","shopify_get_order","shopify_get_product","shopify_list_collections","shopify_list_customers","shopify_list_inventory_items","shopify_list_locations","shopify_list_orders","shopify_list_products","shopify_update_customer","shopify_update_order","shopify_update_product","similarweb_bounce_rate","similarweb_page_views","similarweb_pages_per_visit","similarweb_traffic_visits","similarweb_visit_duration","similarweb_website_overview","sixtyfour_enrich_company","sixtyfour_enrich_lead","sixtyfour_find_email","sixtyfour_find_phone","slack_add_reaction","slack_archive_conversation","slack_canvas","slack_create_channel_canvas","slack_create_conversation","slack_delete_canvas","slack_delete_message","slack_delete_scheduled_message","slack_download","slack_edit_canvas","slack_ephemeral_message","slack_get_canvas","slack_get_channel_history","slack_get_channel_info","slack_get_message","slack_get_permalink","slack_get_thread","slack_get_thread_replies","slack_get_user","slack_get_user_presence","slack_invite_to_conversation","slack_list_canvases","slack_list_channels","slack_list_members","slack_list_scheduled_messages","slack_list_users","slack_lookup_canvas_sections","slack_message","slack_message_reader","slack_open_view","slack_publish_view","slack_push_view","slack_remove_reaction","slack_rename_agent_session_v2","slack_rename_conversation","slack_schedule_message","slack_set_agent_session_status_v2","slack_set_conversation_purpose","slack_set_conversation_topic","slack_set_status","slack_set_suggested_prompts","slack_set_suggested_prompts_v2","slack_set_title","slack_update_message","slack_update_view","smartlead_add_email_accounts_to_campaign","smartlead_add_leads_to_campaign","smartlead_create_campaign","smartlead_create_lead_list","smartlead_delete_campaign","smartlead_delete_campaign_webhook","smartlead_delete_lead_from_campaign","smartlead_delete_lead_list","smartlead_duplicate_campaign","smartlead_export_campaign_leads","smartlead_get_campaign","smartlead_get_campaign_analytics","smartlead_get_campaign_analytics_by_date","smartlead_get_campaign_lead_statistics","smartlead_get_campaign_mailbox_statistics","smartlead_get_campaign_sequences","smartlead_get_campaign_statistics","smartlead_get_campaign_top_level_analytics_by_date","smartlead_get_campaign_webhook_summary","smartlead_get_lead_by_email","smartlead_get_lead_by_id","smartlead_get_lead_list","smartlead_get_lead_message_history","smartlead_list_campaign_email_accounts","smartlead_list_campaign_leads","smartlead_list_campaign_webhooks","smartlead_list_campaigns","smartlead_list_clients","smartlead_list_email_accounts","smartlead_list_inbox_replies","smartlead_list_lead_activities","smartlead_list_lead_categories","smartlead_list_lead_lists","smartlead_mark_lead_complete","smartlead_pause_lead","smartlead_remove_email_accounts_from_campaign","smartlead_resume_lead","smartlead_save_campaign_sequences","smartlead_unsubscribe_lead_from_campaign","smartlead_unsubscribe_lead_globally","smartlead_update_campaign_schedule","smartlead_update_campaign_settings","smartlead_update_campaign_status","smartlead_update_lead","smartlead_update_lead_category","smartlead_update_lead_list","smartlead_upsert_campaign_webhook","sms_send","smtp_send_mail","snowflake_alter_warehouse","snowflake_call_procedure","snowflake_cancel_statement","snowflake_cancel_task_run","snowflake_delete_rows","snowflake_execute_sql","snowflake_get_statement","snowflake_get_task","snowflake_get_task_run","snowflake_get_task_run_output","snowflake_get_warehouse","snowflake_insert_rows","snowflake_introspect_schema","snowflake_list_copy_history","snowflake_list_databases","snowflake_list_query_history","snowflake_list_schemas","snowflake_list_tables","snowflake_list_task_runs","snowflake_list_tasks","snowflake_list_warehouses","snowflake_load_data","snowflake_resume_task","snowflake_resume_warehouse","snowflake_run_task","snowflake_suspend_task","snowflake_suspend_warehouse","snowflake_unload_data","snowflake_update_rows","snowflake_upsert_rows","splunk_cancel_search_job","splunk_create_search_job","splunk_dispatch_saved_search","splunk_get_fired_alerts","splunk_get_saved_search","splunk_get_search_job","splunk_get_search_results","splunk_list_apps","splunk_list_fired_alerts","splunk_list_indexes","splunk_list_saved_searches","splunk_run_search","sportmonks_core_get_cities","sportmonks_core_get_city","sportmonks_core_get_continent","sportmonks_core_get_continents","sportmonks_core_get_countries","sportmonks_core_get_country","sportmonks_core_get_entity_filters","sportmonks_core_get_my_usage","sportmonks_core_get_region","sportmonks_core_get_regions","sportmonks_core_get_timezones","sportmonks_core_get_type","sportmonks_core_get_type_by_entity","sportmonks_core_get_types","sportmonks_core_search_cities","sportmonks_core_search_countries","sportmonks_core_search_regions","sportmonks_football_expected_by_player","sportmonks_football_expected_by_team","sportmonks_football_get_all_commentaries","sportmonks_football_get_all_fixtures","sportmonks_football_get_all_players","sportmonks_football_get_all_rivals","sportmonks_football_get_all_teams","sportmonks_football_get_all_transfer_rumours","sportmonks_football_get_all_transfers","sportmonks_football_get_brackets_by_season","sportmonks_football_get_coach","sportmonks_football_get_coaches","sportmonks_football_get_coaches_by_country","sportmonks_football_get_commentaries_by_fixture","sportmonks_football_get_current_leagues_by_team","sportmonks_football_get_expected_lineups_by_player","sportmonks_football_get_expected_lineups_by_team","sportmonks_football_get_extended_team_squad","sportmonks_football_get_fixture","sportmonks_football_get_fixtures_by_date","sportmonks_football_get_fixtures_by_date_range","sportmonks_football_get_fixtures_by_date_range_for_team","sportmonks_football_get_fixtures_by_ids","sportmonks_football_get_grouped_standings_by_round","sportmonks_football_get_head_to_head","sportmonks_football_get_inplay_livescores","sportmonks_football_get_latest_coaches","sportmonks_football_get_latest_fixtures","sportmonks_football_get_latest_livescores","sportmonks_football_get_latest_players","sportmonks_football_get_latest_totw","sportmonks_football_get_latest_transfers","sportmonks_football_get_league","sportmonks_football_get_leagues","sportmonks_football_get_leagues_by_country","sportmonks_football_get_leagues_by_date","sportmonks_football_get_leagues_by_team","sportmonks_football_get_live_leagues","sportmonks_football_get_live_probabilities","sportmonks_football_get_live_probabilities_by_fixture","sportmonks_football_get_live_standings_by_league","sportmonks_football_get_livescores","sportmonks_football_get_match_facts","sportmonks_football_get_match_facts_by_date_range","sportmonks_football_get_match_facts_by_fixture","sportmonks_football_get_match_facts_by_league","sportmonks_football_get_past_fixtures_by_tv_station","sportmonks_football_get_player","sportmonks_football_get_players_by_country","sportmonks_football_get_postmatch_news","sportmonks_football_get_postmatch_news_by_season","sportmonks_football_get_predictability_by_league","sportmonks_football_get_prematch_news","sportmonks_football_get_prematch_news_by_season","sportmonks_football_get_prematch_news_upcoming","sportmonks_football_get_probabilities","sportmonks_football_get_probabilities_by_fixture","sportmonks_football_get_referee","sportmonks_football_get_referees","sportmonks_football_get_referees_by_country","sportmonks_football_get_referees_by_season","sportmonks_football_get_rivals_by_team","sportmonks_football_get_round","sportmonks_football_get_round_statistics","sportmonks_football_get_rounds","sportmonks_football_get_rounds_by_season","sportmonks_football_get_schedules_by_season","sportmonks_football_get_schedules_by_season_and_team","sportmonks_football_get_schedules_by_team","sportmonks_football_get_season","sportmonks_football_get_seasons","sportmonks_football_get_seasons_by_team","sportmonks_football_get_stage","sportmonks_football_get_stage_statistics","sportmonks_football_get_stages","sportmonks_football_get_stages_by_season","sportmonks_football_get_standing_corrections_by_season","sportmonks_football_get_standings","sportmonks_football_get_standings_by_round","sportmonks_football_get_standings_by_season","sportmonks_football_get_state","sportmonks_football_get_states","sportmonks_football_get_team","sportmonks_football_get_team_rankings","sportmonks_football_get_team_rankings_by_date","sportmonks_football_get_team_rankings_by_team","sportmonks_football_get_team_squad","sportmonks_football_get_team_squad_by_season","sportmonks_football_get_teams_by_country","sportmonks_football_get_teams_by_season","sportmonks_football_get_topscorers_by_season","sportmonks_football_get_topscorers_by_stage","sportmonks_football_get_totw","sportmonks_football_get_totw_by_round","sportmonks_football_get_transfer","sportmonks_football_get_transfer_rumour","sportmonks_football_get_transfer_rumours_between_dates","sportmonks_football_get_transfer_rumours_by_player","sportmonks_football_get_transfer_rumours_by_team","sportmonks_football_get_transfers_between_dates","sportmonks_football_get_transfers_by_player","sportmonks_football_get_transfers_by_team","sportmonks_football_get_tv_station","sportmonks_football_get_tv_stations","sportmonks_football_get_tv_stations_by_fixture","sportmonks_football_get_upcoming_fixtures_by_market","sportmonks_football_get_upcoming_fixtures_by_tv_station","sportmonks_football_get_value_bets","sportmonks_football_get_value_bets_by_fixture","sportmonks_football_get_venue","sportmonks_football_get_venues","sportmonks_football_get_venues_by_season","sportmonks_football_search_coaches","sportmonks_football_search_fixtures","sportmonks_football_search_leagues","sportmonks_football_search_players","sportmonks_football_search_referees","sportmonks_football_search_rounds","sportmonks_football_search_seasons","sportmonks_football_search_stages","sportmonks_football_search_teams","sportmonks_football_search_venues","sportmonks_motorsport_get_all_fixtures","sportmonks_motorsport_get_current_leagues_by_team","sportmonks_motorsport_get_driver","sportmonks_motorsport_get_driver_standings","sportmonks_motorsport_get_driver_standings_by_season","sportmonks_motorsport_get_drivers","sportmonks_motorsport_get_drivers_by_country","sportmonks_motorsport_get_drivers_by_season","sportmonks_motorsport_get_fixture","sportmonks_motorsport_get_fixtures_by_date","sportmonks_motorsport_get_fixtures_by_date_range","sportmonks_motorsport_get_fixtures_by_ids","sportmonks_motorsport_get_laps_by_fixture","sportmonks_motorsport_get_laps_by_fixture_and_driver","sportmonks_motorsport_get_laps_by_fixture_and_lap","sportmonks_motorsport_get_latest_laps_by_fixture","sportmonks_motorsport_get_latest_pitstops_by_fixture","sportmonks_motorsport_get_latest_stints_by_fixture","sportmonks_motorsport_get_latest_updated_drivers","sportmonks_motorsport_get_latest_updated_fixtures","sportmonks_motorsport_get_league","sportmonks_motorsport_get_leagues","sportmonks_motorsport_get_leagues_by_country","sportmonks_motorsport_get_leagues_by_date","sportmonks_motorsport_get_leagues_by_live","sportmonks_motorsport_get_leagues_by_team","sportmonks_motorsport_get_livescores","sportmonks_motorsport_get_pitstops_by_fixture","sportmonks_motorsport_get_pitstops_by_fixture_and_driver","sportmonks_motorsport_get_pitstops_by_fixture_and_lap","sportmonks_motorsport_get_race_results_by_season_and_driver","sportmonks_motorsport_get_race_results_by_season_and_team","sportmonks_motorsport_get_schedules_by_season","sportmonks_motorsport_get_season","sportmonks_motorsport_get_seasons","sportmonks_motorsport_get_stage","sportmonks_motorsport_get_stages","sportmonks_motorsport_get_stages_by_season","sportmonks_motorsport_get_state","sportmonks_motorsport_get_states","sportmonks_motorsport_get_stints_by_fixture","sportmonks_motorsport_get_stints_by_fixture_and_driver","sportmonks_motorsport_get_stints_by_fixture_and_stint","sportmonks_motorsport_get_team","sportmonks_motorsport_get_team_standings","sportmonks_motorsport_get_team_standings_by_season","sportmonks_motorsport_get_teams","sportmonks_motorsport_get_teams_by_country","sportmonks_motorsport_get_teams_by_season","sportmonks_motorsport_get_venue","sportmonks_motorsport_get_venues","sportmonks_motorsport_get_venues_by_season","sportmonks_motorsport_search_drivers","sportmonks_motorsport_search_leagues","sportmonks_motorsport_search_stages","sportmonks_motorsport_search_teams","sportmonks_motorsport_search_venues","sportmonks_odds_get_all_historical_odds","sportmonks_odds_get_all_inplay_odds","sportmonks_odds_get_all_pre_match_odds","sportmonks_odds_get_all_premium_odds","sportmonks_odds_get_bookmaker","sportmonks_odds_get_bookmaker_event_ids_by_fixture","sportmonks_odds_get_bookmakers","sportmonks_odds_get_bookmakers_by_fixture","sportmonks_odds_get_inplay_odds_by_fixture","sportmonks_odds_get_inplay_odds_by_fixture_and_bookmaker","sportmonks_odds_get_inplay_odds_by_fixture_and_market","sportmonks_odds_get_last_updated_inplay_odds","sportmonks_odds_get_last_updated_pre_match_odds","sportmonks_odds_get_market","sportmonks_odds_get_markets","sportmonks_odds_get_pre_match_odds_by_fixture","sportmonks_odds_get_pre_match_odds_by_fixture_and_bookmaker","sportmonks_odds_get_pre_match_odds_by_fixture_and_market","sportmonks_odds_get_premium_odds_by_fixture","sportmonks_odds_get_premium_odds_by_fixture_and_bookmaker","sportmonks_odds_get_premium_odds_by_fixture_and_market","sportmonks_odds_get_updated_historical_odds_between","sportmonks_odds_get_updated_premium_odds_between","sportmonks_odds_search_bookmakers","sportmonks_odds_search_markets","spotify_add_playlist_cover","spotify_add_to_queue","spotify_add_tracks_to_playlist","spotify_check_following","spotify_check_playlist_followers","spotify_check_saved_albums","spotify_check_saved_audiobooks","spotify_check_saved_episodes","spotify_check_saved_shows","spotify_check_saved_tracks","spotify_create_playlist","spotify_follow_artists","spotify_follow_playlist","spotify_get_album","spotify_get_album_tracks","spotify_get_albums","spotify_get_artist","spotify_get_artist_albums","spotify_get_artist_top_tracks","spotify_get_artists","spotify_get_audiobook","spotify_get_audiobook_chapters","spotify_get_audiobooks","spotify_get_categories","spotify_get_current_user","spotify_get_currently_playing","spotify_get_devices","spotify_get_episode","spotify_get_episodes","spotify_get_followed_artists","spotify_get_markets","spotify_get_new_releases","spotify_get_playback_state","spotify_get_playlist","spotify_get_playlist_cover","spotify_get_playlist_tracks","spotify_get_queue","spotify_get_recently_played","spotify_get_saved_albums","spotify_get_saved_audiobooks","spotify_get_saved_episodes","spotify_get_saved_shows","spotify_get_saved_tracks","spotify_get_show","spotify_get_show_episodes","spotify_get_shows","spotify_get_top_artists","spotify_get_top_tracks","spotify_get_track","spotify_get_tracks","spotify_get_user_playlists","spotify_get_user_profile","spotify_pause","spotify_play","spotify_remove_saved_albums","spotify_remove_saved_audiobooks","spotify_remove_saved_episodes","spotify_remove_saved_shows","spotify_remove_saved_tracks","spotify_remove_tracks_from_playlist","spotify_reorder_playlist_items","spotify_replace_playlist_items","spotify_save_albums","spotify_save_audiobooks","spotify_save_episodes","spotify_save_shows","spotify_save_tracks","spotify_search","spotify_seek","spotify_set_repeat","spotify_set_shuffle","spotify_set_volume","spotify_skip_next","spotify_skip_previous","spotify_transfer_playback","spotify_unfollow_artists","spotify_unfollow_playlist","spotify_update_playlist","sqs_cancel_message_move_task","sqs_change_message_visibility","sqs_change_message_visibility_batch","sqs_create_queue","sqs_delete_message","sqs_delete_message_batch","sqs_delete_queue","sqs_get_queue_attributes","sqs_get_queue_url","sqs_list_dead_letter_source_queues","sqs_list_message_move_tasks","sqs_list_queue_tags","sqs_list_queues","sqs_purge_queue","sqs_receive_message","sqs_send","sqs_send_message_batch","sqs_set_queue_attributes","sqs_start_message_move_task","sqs_tag_queue","sqs_untag_queue","square_batch_retrieve_inventory_counts","square_cancel_invoice","square_cancel_payment","square_complete_payment","square_create_catalog_image","square_create_customer","square_create_invoice","square_create_order","square_create_payment","square_delete_catalog_object","square_delete_customer","square_delete_invoice","square_get_catalog_object","square_get_customer","square_get_invoice","square_get_location","square_get_order","square_get_payment","square_get_refund","square_list_catalog","square_list_customers","square_list_invoices","square_list_locations","square_list_payments","square_list_refunds","square_pay_order","square_publish_invoice","square_refund_payment","square_search_catalog_objects","square_search_customers","square_search_invoices","square_search_orders","square_update_customer","square_upsert_catalog_object","ssh_check_command_exists","ssh_check_file_exists","ssh_create_directory","ssh_delete_file","ssh_download_file","ssh_download_file_v2","ssh_execute_command","ssh_execute_script","ssh_get_system_info","ssh_list_directory","ssh_move_rename","ssh_read_file_content","ssh_upload_file","ssh_write_file_content","ssm_cancel_command","ssm_delete_parameter","ssm_describe_automation_executions","ssm_describe_instance_information","ssm_describe_instance_patch_states","ssm_describe_instance_patches","ssm_describe_parameters","ssm_get_automation_execution","ssm_get_command_invocation","ssm_get_document","ssm_get_parameter","ssm_get_parameters","ssm_get_parameters_by_path","ssm_list_command_invocations","ssm_list_commands","ssm_list_compliance_items","ssm_list_compliance_summaries","ssm_list_documents","ssm_put_parameter","ssm_send_command","ssm_start_automation_execution","ssm_stop_automation_execution","stagehand_agent","stagehand_extract","stripe_cancel_payment_intent","stripe_cancel_subscription","stripe_capture_charge","stripe_capture_payment_intent","stripe_confirm_payment_intent","stripe_create_charge","stripe_create_customer","stripe_create_invoice","stripe_create_payment_intent","stripe_create_price","stripe_create_product","stripe_create_subscription","stripe_delete_customer","stripe_delete_invoice","stripe_delete_product","stripe_finalize_invoice","stripe_list_charges","stripe_list_customers","stripe_list_events","stripe_list_invoices","stripe_list_payment_intents","stripe_list_prices","stripe_list_products","stripe_list_subscriptions","stripe_pay_invoice","stripe_resume_subscription","stripe_retrieve_charge","stripe_retrieve_customer","stripe_retrieve_event","stripe_retrieve_invoice","stripe_retrieve_payment_intent","stripe_retrieve_price","stripe_retrieve_product","stripe_retrieve_subscription","stripe_search_charges","stripe_search_customers","stripe_search_invoices","stripe_search_payment_intents","stripe_search_prices","stripe_search_products","stripe_search_subscriptions","stripe_send_invoice","stripe_update_charge","stripe_update_customer","stripe_update_invoice","stripe_update_payment_intent","stripe_update_price","stripe_update_product","stripe_update_subscription","stripe_void_invoice","sts_assume_role","sts_assume_role_with_saml","sts_assume_role_with_web_identity","sts_get_access_key_info","sts_get_caller_identity","sts_get_session_token","stt_assemblyai","stt_assemblyai_v2","stt_deepgram","stt_deepgram_v2","stt_elevenlabs","stt_elevenlabs_v2","stt_gemini","stt_gemini_v2","stt_whisper","stt_whisper_v2","supabase_count","supabase_delete","supabase_get_row","supabase_insert","supabase_introspect","supabase_invoke_function","supabase_query","supabase_rpc","supabase_storage_copy","supabase_storage_create_bucket","supabase_storage_create_signed_upload_url","supabase_storage_create_signed_url","supabase_storage_delete","supabase_storage_delete_bucket","supabase_storage_download","supabase_storage_empty_bucket","supabase_storage_get_public_url","supabase_storage_list","supabase_storage_list_buckets","supabase_storage_move","supabase_storage_update_bucket","supabase_storage_upload","supabase_text_search","supabase_update","supabase_upsert","supabase_vector_search","table_batch_insert_rows","table_create","table_delete_row","table_delete_rows_by_filter","table_get_row","table_get_schema","table_insert_row","table_list","table_query_rows","table_query_rows_v2","table_update_row","table_update_rows_by_filter","table_upsert_row","tailscale_authorize_device","tailscale_create_auth_key","tailscale_delete_auth_key","tailscale_delete_device","tailscale_delete_user","tailscale_expire_device_key","tailscale_get_acl","tailscale_get_auth_key","tailscale_get_device","tailscale_get_device_routes","tailscale_get_dns_preferences","tailscale_get_dns_searchpaths","tailscale_list_auth_keys","tailscale_list_devices","tailscale_list_dns_nameservers","tailscale_list_users","tailscale_set_acl","tailscale_set_device_routes","tailscale_set_device_tags","tailscale_set_dns_nameservers","tailscale_set_dns_preferences","tailscale_set_dns_searchpaths","tailscale_suspend_user","tailscale_update_device_key","tavily_crawl","tavily_extract","tavily_map","tavily_search","telegram_copy_message","telegram_delete_message","telegram_edit_message_text","telegram_forward_message","telegram_get_chat","telegram_get_chat_member","telegram_message","telegram_pin_message","telegram_send_animation","telegram_send_audio","telegram_send_chat_action","telegram_send_contact","telegram_send_document","telegram_send_location","telegram_send_photo","telegram_send_poll","telegram_send_video","telegram_set_message_reaction","telegram_unpin_message","temporal_cancel_workflow","temporal_count_workflows","temporal_create_schedule","temporal_delete_schedule","temporal_describe_schedule","temporal_describe_task_queue","temporal_describe_workflow","temporal_get_workflow_history","temporal_list_schedules","temporal_list_workflows","temporal_pause_schedule","temporal_query_workflow","temporal_reset_workflow","temporal_signal_with_start","temporal_signal_workflow","temporal_start_workflow","temporal_terminate_workflow","temporal_trigger_schedule","temporal_unpause_schedule","temporal_update_workflow","textract_analyze_expense","textract_analyze_id","textract_parser","textract_parser_v2","thinking_tool","thrive_add_audience_managers","thrive_add_audience_members","thrive_add_user_tags","thrive_create_assignment","thrive_create_audience","thrive_create_completion","thrive_create_user","thrive_delete_assignment","thrive_delete_audience","thrive_delete_user","thrive_get_activity","thrive_get_assignment","thrive_get_audience","thrive_get_completion","thrive_get_content","thrive_get_cpd_category","thrive_get_cpd_entry","thrive_get_cpd_requirement","thrive_get_enrolment","thrive_get_skill_levels","thrive_get_tag","thrive_get_user_by_id","thrive_get_user_by_ref","thrive_list_assignments","thrive_list_audience_managers","thrive_list_audience_members","thrive_list_audiences","thrive_list_completions","thrive_list_enrolments","thrive_list_tags","thrive_query_activities","thrive_query_content","thrive_query_cpd_categories","thrive_query_cpd_entries","thrive_query_cpd_requirements","thrive_query_cpd_user_summaries","thrive_remove_audience_manager","thrive_remove_audience_member","thrive_remove_user_tags","thrive_replace_audience_managers","thrive_replace_audience_members","thrive_search_users","thrive_suspend_user","thrive_update_assignment","thrive_update_audience","thrive_update_user","thrive_update_user_skills","tiktok_get_post_status","tiktok_get_user","tiktok_list_videos","tiktok_query_videos","tiktok_upload_video_draft","tinybird_append_datasource","tinybird_delete_datasource_rows","tinybird_events","tinybird_get_job","tinybird_query","tinybird_query_pipe","tinybird_truncate_datasource","tinyfish_cancel_run","tinyfish_fetch","tinyfish_get_run","tinyfish_list_profiles","tinyfish_list_runs","tinyfish_list_vault_items","tinyfish_run","tinyfish_run_async","tinyfish_search","trello_add_checklist","trello_add_checklist_item","trello_add_comment","trello_add_label","trello_add_member","trello_create_board","trello_create_card","trello_create_list","trello_delete_card","trello_get_actions","trello_get_board","trello_get_card","trello_list_cards","trello_list_lists","trello_list_members","trello_remove_label","trello_remove_member","trello_search","trello_update_card","trello_update_checklist_item","trello_update_list","trigger_dev_activate_schedule","trigger_dev_add_run_tags","trigger_dev_batch_trigger_task","trigger_dev_cancel_run","trigger_dev_complete_waitpoint_token","trigger_dev_create_env_var","trigger_dev_create_schedule","trigger_dev_create_waitpoint_token","trigger_dev_deactivate_schedule","trigger_dev_delete_env_var","trigger_dev_delete_schedule","trigger_dev_execute_query","trigger_dev_get_batch","trigger_dev_get_batch_results","trigger_dev_get_deployment","trigger_dev_get_env_var","trigger_dev_get_latest_deployment","trigger_dev_get_query_schema","trigger_dev_get_queue","trigger_dev_get_run","trigger_dev_get_run_events","trigger_dev_get_run_result","trigger_dev_get_run_trace","trigger_dev_get_schedule","trigger_dev_get_waitpoint_token","trigger_dev_import_env_vars","trigger_dev_list_deployments","trigger_dev_list_env_vars","trigger_dev_list_queues","trigger_dev_list_runs","trigger_dev_list_schedules","trigger_dev_list_timezones","trigger_dev_list_waitpoint_tokens","trigger_dev_override_queue_concurrency","trigger_dev_pause_queue","trigger_dev_promote_deployment","trigger_dev_replay_run","trigger_dev_reschedule_run","trigger_dev_reset_queue_concurrency","trigger_dev_resume_queue","trigger_dev_trigger_task","trigger_dev_update_env_var","trigger_dev_update_run_metadata","trigger_dev_update_schedule","tts_azure","tts_cartesia","tts_deepgram","tts_elevenlabs","tts_google","tts_openai","tts_playht","twilio_send_sms","twilio_voice_get_recording","twilio_voice_list_calls","twilio_voice_make_call","typeform_create_form","typeform_delete_form","typeform_files","typeform_get_form","typeform_insights","typeform_list_forms","typeform_responses","typeform_update_form","upstash_redis_command","upstash_redis_delete","upstash_redis_exists","upstash_redis_expire","upstash_redis_get","upstash_redis_hget","upstash_redis_hgetall","upstash_redis_hset","upstash_redis_incr","upstash_redis_incrby","upstash_redis_keys","upstash_redis_lpush","upstash_redis_lrange","upstash_redis_set","upstash_redis_setnx","upstash_redis_ttl","uptimerobot_create_alert_contact","uptimerobot_create_maintenance_window","uptimerobot_create_monitor","uptimerobot_create_psp","uptimerobot_delete_alert_contact","uptimerobot_delete_maintenance_window","uptimerobot_delete_monitor","uptimerobot_delete_psp","uptimerobot_get_account","uptimerobot_get_alert_contact","uptimerobot_get_incident","uptimerobot_get_maintenance_window","uptimerobot_get_monitor","uptimerobot_get_psp","uptimerobot_list_alert_contacts","uptimerobot_list_incidents","uptimerobot_list_maintenance_windows","uptimerobot_list_monitors","uptimerobot_list_psps","uptimerobot_pause_monitor","uptimerobot_start_monitor","uptimerobot_update_maintenance_window","uptimerobot_update_monitor","uptimerobot_update_psp","vanta_download_document_file","vanta_get_control","vanta_get_document","vanta_get_framework","vanta_get_person","vanta_get_policy","vanta_get_risk_scenario","vanta_get_test","vanta_get_vendor","vanta_get_vulnerable_asset","vanta_list_control_documents","vanta_list_control_tests","vanta_list_controls","vanta_list_document_uploads","vanta_list_documents","vanta_list_framework_controls","vanta_list_frameworks","vanta_list_monitored_computers","vanta_list_people","vanta_list_policies","vanta_list_risk_scenarios","vanta_list_test_entities","vanta_list_tests","vanta_list_vendors","vanta_list_vulnerabilities","vanta_list_vulnerability_remediations","vanta_list_vulnerable_assets","vanta_submit_document","vanta_upload_document_file","vercel_add_domain","vercel_add_project_domain","vercel_cancel_deployment","vercel_create_alias","vercel_create_check","vercel_create_deployment","vercel_create_dns_record","vercel_create_edge_config","vercel_create_env_var","vercel_create_project","vercel_create_webhook","vercel_delete_alias","vercel_delete_deployment","vercel_delete_dns_record","vercel_delete_domain","vercel_delete_edge_config","vercel_delete_env_var","vercel_delete_project","vercel_delete_webhook","vercel_get_alias","vercel_get_check","vercel_get_deployment","vercel_get_deployment_events","vercel_get_domain","vercel_get_domain_config","vercel_get_edge_config","vercel_get_edge_config_items","vercel_get_env_vars","vercel_get_project","vercel_get_team","vercel_get_user","vercel_get_webhook","vercel_list_aliases","vercel_list_checks","vercel_list_deployment_files","vercel_list_deployments","vercel_list_dns_records","vercel_list_domains","vercel_list_edge_configs","vercel_list_project_domains","vercel_list_projects","vercel_list_team_members","vercel_list_teams","vercel_list_webhooks","vercel_pause_project","vercel_promote_deployment","vercel_remove_project_domain","vercel_rerequest_check","vercel_unpause_project","vercel_update_check","vercel_update_dns_record","vercel_update_edge_config_items","vercel_update_env_var","vercel_update_project","vercel_update_project_domain","vercel_verify_project_domain","video_falai","video_luma","video_minimax","video_runway","video_veo","vision_tool","vision_tool_v2","wealthbox_read_contact","wealthbox_read_note","wealthbox_read_task","wealthbox_write_contact","wealthbox_write_note","wealthbox_write_task","webflow_create_item","webflow_delete_item","webflow_get_item","webflow_list_items","webflow_update_item","webhook_request","whatsapp_get_media","whatsapp_mark_read","whatsapp_send_interactive","whatsapp_send_media","whatsapp_send_message","whatsapp_send_reaction","whatsapp_send_template","whatsapp_upload_media","wikipedia_content","wikipedia_random","wikipedia_search","wikipedia_summary","windchill_check_in_document","windchill_check_in_documents","windchill_check_out_document","windchill_check_out_documents","windchill_create_document","windchill_create_documents","windchill_delete_document","windchill_delete_documents","windchill_download_attachment","windchill_download_primary_content","windchill_get_document","windchill_get_document_structure","windchill_get_primary_content","windchill_get_valid_state_transitions","windchill_list_attachments","windchill_list_documents","windchill_revise_document","windchill_revise_documents","windchill_set_lifecycle_state","windchill_undo_check_out_document","windchill_undo_check_out_documents","windchill_update_common_properties","windchill_update_document","windchill_update_document_security_labels","windchill_update_documents","windchill_upload_attachments","windchill_upload_primary_content","wiza_company_enrichment","wiza_get_credits","wiza_individual_reveal","wiza_prospect_search","wordpress_create_category","wordpress_create_comment","wordpress_create_page","wordpress_create_post","wordpress_create_tag","wordpress_delete_category","wordpress_delete_comment","wordpress_delete_media","wordpress_delete_page","wordpress_delete_post","wordpress_delete_tag","wordpress_get_category","wordpress_get_current_user","wordpress_get_media","wordpress_get_page","wordpress_get_post","wordpress_get_tag","wordpress_get_user","wordpress_list_categories","wordpress_list_comments","wordpress_list_media","wordpress_list_pages","wordpress_list_posts","wordpress_list_tags","wordpress_list_users","wordpress_search_content","wordpress_update_category","wordpress_update_comment","wordpress_update_page","wordpress_update_post","wordpress_update_tag","wordpress_upload_media","workday_assign_onboarding","workday_change_job","workday_create_prehire","workday_get_compensation","workday_get_organizations","workday_get_worker","workday_hire_employee","workday_list_workers","workday_terminate_worker","workday_update_worker","workflow_executor","x_create_bookmark","x_create_tweet","x_delete_bookmark","x_delete_tweet","x_get_blocking","x_get_bookmarks","x_get_followers","x_get_following","x_get_liked_tweets","x_get_liking_users","x_get_me","x_get_personalized_trends","x_get_quote_tweets","x_get_retweeted_by","x_get_trends_by_woeid","x_get_tweets_by_ids","x_get_usage","x_get_user_mentions","x_get_user_timeline","x_get_user_tweets","x_hide_reply","x_manage_block","x_manage_follow","x_manage_like","x_manage_mute","x_manage_retweet","x_read","x_search","x_search_tweets","x_search_users","x_user","x_write","youtube_channel_info","youtube_channel_playlists","youtube_channel_videos","youtube_comments","youtube_playlist_items","youtube_search","youtube_trending","youtube_video_categories","youtube_video_details","zendesk_autocomplete_organizations","zendesk_create_organization","zendesk_create_organizations_bulk","zendesk_create_ticket","zendesk_create_tickets_bulk","zendesk_create_user","zendesk_create_users_bulk","zendesk_delete_organization","zendesk_delete_ticket","zendesk_delete_user","zendesk_get_current_user","zendesk_get_organization","zendesk_get_organizations","zendesk_get_ticket","zendesk_get_tickets","zendesk_get_user","zendesk_get_users","zendesk_merge_tickets","zendesk_search","zendesk_search_count","zendesk_search_users","zendesk_update_organization","zendesk_update_ticket","zendesk_update_tickets_bulk","zendesk_update_user","zendesk_update_users_bulk","zep_add_messages","zep_add_user","zep_create_thread","zep_delete_thread","zep_get_context","zep_get_messages","zep_get_threads","zep_get_user","zep_get_user_threads","zerobounce_get_credits","zerobounce_verify_email","zoho_desk_add_comment","zoho_desk_get_attachment","zoho_desk_get_contact","zoho_desk_get_thread","zoho_desk_get_ticket","zoho_desk_list_comments","zoho_desk_list_organizations","zoho_desk_list_threads","zoho_desk_list_tickets","zoho_desk_update_ticket","zoom_create_meeting","zoom_delete_meeting","zoom_delete_recording","zoom_get_meeting","zoom_get_meeting_invitation","zoom_get_meeting_recordings","zoom_list_meetings","zoom_list_past_participants","zoom_list_recordings","zoom_update_meeting","zoominfo_enrich_companies","zoominfo_enrich_contacts","zoominfo_search_companies","zoominfo_search_contacts","zoominfo_search_intent","zoominfo_search_news"]' ) export default toolIds diff --git a/apps/sim/tools/generated/tool-metadata.ts b/apps/sim/tools/generated/tool-metadata.ts index 275e8594c99..dacfa485f2a 100644 --- a/apps/sim/tools/generated/tool-metadata.ts +++ b/apps/sim/tools/generated/tool-metadata.ts @@ -3,7 +3,7 @@ /** Serializable metadata for every built-in tool, keyed by tool id. */ const toolMetadata: Record = JSON.parse( - '{"a2a_cancel_task":{"id":"a2a_cancel_task","name":"A2A Cancel Task","description":"Request cancellation of an in-progress A2A task.","version":"1.0.0","params":{"agentUrl":{"type":"string","required":true,"visibility":"user-only","description":"The A2A agent endpoint URL"},"taskId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The task ID to cancel"},"apiKey":{"type":"string","required":false,"visibility":"user-only","description":"API key for authentication (if required)"}},"hostedApiKey":"none"},"a2a_get_agent_card":{"id":"a2a_get_agent_card","name":"A2A Get Agent Card","description":"Fetch the Agent Card (discovery document) for an external A2A agent.","version":"1.0.0","params":{"agentUrl":{"type":"string","required":true,"visibility":"user-only","description":"The A2A agent endpoint URL"},"apiKey":{"type":"string","required":false,"visibility":"user-only","description":"API key for authentication (if required)"}},"hostedApiKey":"none"},"a2a_get_task":{"id":"a2a_get_task","name":"A2A Get Task","description":"Retrieve the current state and result of an A2A task.","version":"1.0.0","params":{"agentUrl":{"type":"string","required":true,"visibility":"user-only","description":"The A2A agent endpoint URL"},"taskId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The task ID to retrieve"},"historyLength":{"type":"number","required":false,"visibility":"user-or-llm","description":"Maximum number of history messages to include"},"apiKey":{"type":"string","required":false,"visibility":"user-only","description":"API key for authentication (if required)"}},"hostedApiKey":"none"},"a2a_send_message":{"id":"a2a_send_message","name":"A2A Send Message","description":"Send a message to an external A2A agent and return its response.","version":"1.0.0","params":{"agentUrl":{"type":"string","required":true,"visibility":"user-only","description":"The A2A agent endpoint URL"},"message":{"type":"string","required":true,"visibility":"user-or-llm","description":"The message text to send"},"data":{"type":"json","required":false,"visibility":"user-or-llm","description":"Optional structured JSON data to attach"},"files":{"type":"json","required":false,"visibility":"user-or-llm","description":"Optional files to attach"},"taskId":{"type":"string","required":false,"visibility":"user-or-llm","description":"Existing task ID to continue"},"contextId":{"type":"string","required":false,"visibility":"user-or-llm","description":"Conversation context ID to continue"},"apiKey":{"type":"string","required":false,"visibility":"user-only","description":"API key for authentication (if required)"}},"hostedApiKey":"none"},"affinity_batch_update_entity_fields":{"id":"affinity_batch_update_entity_fields","name":"Affinity Batch Update Entity Fields","description":"Write up to 100 non-list field values on one company or person in a single request.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"entityType":{"type":"string","required":true,"visibility":"user-or-llm","description":"Which entity to write the fields on: companies or persons"},"entityId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of that company or person"},"updates":{"type":"json","required":true,"visibility":"user-or-llm","description":"Up to 100 field updates as [{\\"id\\":\\"\\",\\"value\\":{\\"type\\":\\"…\\",\\"data\\":…}}], using the same value shapes as a single field update"}},"hostedApiKey":"none"},"affinity_batch_update_list_entry_fields":{"id":"affinity_batch_update_list_entry_fields","name":"Affinity Batch Update List Entry Fields","description":"Write up to 100 field values on one list row in a single request. Requires the \\"Export data from Lists\\" permission.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"listId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The list ID"},"listEntryId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The list entry ID"},"updates":{"type":"json","required":true,"visibility":"user-or-llm","description":"Up to 100 field updates as [{\\"id\\":\\"\\",\\"value\\":{\\"type\\":\\"…\\",\\"data\\":…}}], using the same value shapes as a single field update"}},"hostedApiKey":"none"},"affinity_create_list":{"id":"affinity_create_list","name":"Affinity Create List","description":"Create a list. Its type fixes which entities it can hold, and the API key holder becomes its creator and owner.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"name":{"type":"string","required":true,"visibility":"user-or-llm","description":"Name of the new list"},"type":{"type":"string","required":true,"visibility":"user-or-llm","description":"Entity kind the list holds: company, opportunity, or person"},"isPublic":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Whether everyone in the organization can see the list"}},"hostedApiKey":"none"},"affinity_create_list_field_dropdown_option":{"id":"affinity_create_list_field_dropdown_option","name":"Affinity Create List Field Dropdown Option","description":"Add a selectable option to a dropdown field on a list. A ranked or status option also needs a rank and a color.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"listId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The list ID"},"fieldId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The dropdown field ID on that list"},"type":{"type":"string","required":true,"visibility":"user-or-llm","description":"Kind of option to create, matching the field. dropdown takes only a label; ranked-dropdown also requires rank and color; status-dropdown additionally requires a status category. Sending a field the kind does not accept is rejected"},"text":{"type":"string","required":true,"visibility":"user-or-llm","description":"The option label"},"rank":{"type":"number","required":false,"visibility":"user-or-llm","description":"Sort order. Required on a ranked-dropdown or status-dropdown option"},"color":{"type":"string","required":false,"visibility":"user-or-llm","description":"Option color: white, gray, blue, green, purple, orange, or red. Required on a ranked-dropdown or status-dropdown option"},"statusCategory":{"type":"string","required":false,"visibility":"user-or-llm","description":"Pipeline meaning of the option: open, won, lost, or on-hold. Status-dropdown options only"},"winRate":{"type":"number","required":false,"visibility":"user-or-llm","description":"Expected win rate of the status. Status-dropdown options only"}},"hostedApiKey":"none"},"affinity_create_merge":{"id":"affinity_create_merge","name":"Affinity Create Merge","description":"Fold a duplicate company or person into the record you are keeping. The merge runs asynchronously — poll the returned task to see it finish. Requires the \\"Manage duplicates\\" permission and an admin role.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"entityType":{"type":"string","required":true,"visibility":"user-or-llm","description":"What to merge: companies or persons"},"primaryId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the record to keep"},"duplicateId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the duplicate record to fold in"}},"hostedApiKey":"none"},"affinity_create_note":{"id":"affinity_create_note","name":"Affinity Create Note","description":"Write a note — attached to companies, persons, and opportunities, anchored to a meeting, call, or chat message, or posted as a reply to an existing note.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"type":{"type":"string","required":true,"visibility":"user-or-llm","description":"Note shape: entities to attach it to records, interaction to anchor it to a meeting, call, or chat message, or user-reply to reply to a note"},"html":{"type":"string","required":true,"visibility":"user-or-llm","description":"The note body as HTML"},"companyIds":{"type":"json","required":false,"visibility":"user-or-llm","description":"Companies to attach the note to, e.g. [1, 2]. Not used on a reply"},"personIds":{"type":"json","required":false,"visibility":"user-or-llm","description":"Persons to attach the note to, e.g. [1, 2]. Not used on a reply"},"opportunityIds":{"type":"json","required":false,"visibility":"user-or-llm","description":"Opportunities to attach the note to, e.g. [1, 2]. Not used on a reply"},"interactionId":{"type":"string","required":false,"visibility":"user-or-llm","description":"The interaction to anchor the note to. Required for an interaction note"},"interactionType":{"type":"string","required":false,"visibility":"user-or-llm","description":"Kind of the anchoring interaction: meeting, call, or chat-message. Required for an interaction note"},"parentId":{"type":"string","required":false,"visibility":"user-or-llm","description":"The note being replied to. Required for a user-reply note"},"creatorId":{"type":"string","required":false,"visibility":"user-or-llm","description":"Attribute the note to another internal person. Defaults to the API key holder"},"createdAt":{"type":"string","required":false,"visibility":"user-or-llm","description":"Backdate the note to this ISO 8601 timestamp"}},"hostedApiKey":"none"},"affinity_create_reminder":{"id":"affinity_create_reminder","name":"Affinity Create Reminder","description":"Create a reminder on one company, person, or opportunity. A recurring reminder resets whenever the chosen signal happens instead of firing once.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"type":{"type":"string","required":true,"visibility":"user-or-llm","description":"one-time to fire once, or recurring to reset on a signal"},"entityType":{"type":"string","required":true,"visibility":"user-or-llm","description":"What the reminder is about: company, person, or opportunity"},"entityId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of that company, person, or opportunity"},"dueDate":{"type":"string","required":false,"visibility":"user-or-llm","description":"When the reminder is due, as an ISO 8601 timestamp. Required for a one-time reminder; on a recurring one Affinity computes it from the period when omitted"},"content":{"type":"string","required":false,"visibility":"user-or-llm","description":"What the reminder says"},"ownerId":{"type":"string","required":true,"visibility":"user-or-llm","description":"User the reminder is assigned to. Must be an internal user. The API key holder is recorded as the creator, which is a separate field"},"resetTrigger":{"type":"string","required":false,"visibility":"user-or-llm","description":"What restarts a recurring reminder: interaction, email, or event. Required when the type is recurring"},"periodDays":{"type":"number","required":false,"visibility":"user-or-llm","description":"Days between firings of a recurring reminder. Required when the type is recurring"}},"hostedApiKey":"none"},"affinity_delete_list_field_dropdown_option":{"id":"affinity_delete_list_field_dropdown_option","name":"Affinity Delete List Field Dropdown Option","description":"Permanently delete a dropdown option on a list field. Every list entry currently set to it is cleared, and those values cannot be recovered.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"listId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The list ID"},"fieldId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The dropdown field ID on that list"},"dropdownOptionId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The dropdown option ID to delete"}},"hostedApiKey":"none"},"affinity_delete_note":{"id":"affinity_delete_note","name":"Affinity Delete Note","description":"Delete a note you created. Deleting a root note also deletes its replies; deleting a reply removes only that reply.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"noteId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The note ID to delete"}},"hostedApiKey":"none"},"affinity_get_company":{"id":"affinity_get_company","name":"Affinity Get Company","description":"Look up one company by ID. Field data is returned only for the Field IDs or Field Types asked for.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"companyId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The company ID"},"fieldIds":{"type":"json","required":false,"visibility":"user-or-llm","description":"Field IDs to return values for, e.g. [\\"affinity-data-location\\"]. Mutually exclusive with Field Types"},"fieldTypes":{"type":"json","required":false,"visibility":"user-or-llm","description":"Field categories to return values for: enriched, global, or relationship-intelligence. Mutually exclusive with Field IDs"}},"hostedApiKey":"none"},"affinity_get_current_user":{"id":"affinity_get_current_user","name":"Affinity Get Current User","description":"Verify an Affinity API key and return the tenant, the user behind the key, and the scopes the grant carries.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"}},"hostedApiKey":"none"},"affinity_get_entity_field_value":{"id":"affinity_get_entity_field_value","name":"Affinity Get Entity Field Value","description":"Read one non-list field value from a company or person.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"entityType":{"type":"string","required":true,"visibility":"user-or-llm","description":"Which entity to read the field from: companies or persons"},"entityId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of that company or person"},"fieldId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The field ID to read"}},"hostedApiKey":"none"},"affinity_get_list":{"id":"affinity_get_list","name":"Affinity Get List","description":"Read one list — its name, type, owner, and privacy setting.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"listId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The list ID"}},"hostedApiKey":"none"},"affinity_get_list_entry":{"id":"affinity_get_list_entry","name":"Affinity Get List Entry","description":"Read one row of a list with its entity. Field data is returned only for the Field IDs or Field Types asked for.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"listId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The list ID"},"listEntryId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The list entry ID"},"fieldIds":{"type":"json","required":false,"visibility":"user-or-llm","description":"Field IDs to return values for, e.g. [\\"affinity-data-location\\"]. Mutually exclusive with Field Types"},"fieldTypes":{"type":"json","required":false,"visibility":"user-or-llm","description":"Field categories to return values for: enriched, global, list, or relationship-intelligence. Mutually exclusive with Field IDs"}},"hostedApiKey":"none"},"affinity_get_list_entry_field":{"id":"affinity_get_list_entry_field","name":"Affinity Get List Entry Field","description":"Read one field value on a list row.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"listId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The list ID"},"listEntryId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The list entry ID"},"fieldId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The field ID to read"}},"hostedApiKey":"none"},"affinity_get_list_field_dropdown_option":{"id":"affinity_get_list_field_dropdown_option","name":"Affinity Get List Field Dropdown Option","description":"Read one dropdown option on a list field.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"listId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The list ID"},"fieldId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The dropdown field ID on that list"},"dropdownOptionId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The dropdown option ID"}},"hostedApiKey":"none"},"affinity_get_merge":{"id":"affinity_get_merge","name":"Affinity Get Merge","description":"Read the status of one company or person merge, including why it failed if it did.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"entityType":{"type":"string","required":true,"visibility":"user-or-llm","description":"Which merge to read: companies or persons"},"mergeId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The merge ID"}},"hostedApiKey":"none"},"affinity_get_merge_task":{"id":"affinity_get_merge_task","name":"Affinity Get Merge Task","description":"Read one merge task and how its merges are progressing. Poll this after starting a merge.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"entityType":{"type":"string","required":true,"visibility":"user-or-llm","description":"Which merge task to read: companies or persons"},"taskId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The merge task ID"}},"hostedApiKey":"none"},"affinity_get_note":{"id":"affinity_get_note","name":"Affinity Get Note","description":"Read one note with its body, author, mentions, and attached records.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"noteId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The note ID"},"includes":{"type":"json","required":false,"visibility":"user-or-llm","description":"Extra properties to return, e.g. [\\"repliesCount\\",\\"personsPreview\\",\\"companiesPreview\\",\\"opportunitiesPreview\\"]. Those four fields are omitted unless requested here"}},"hostedApiKey":"none"},"affinity_get_opportunity":{"id":"affinity_get_opportunity","name":"Affinity Get Opportunity","description":"Read one opportunity and the list it belongs to. Its field data lives on the list entry.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"opportunityId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The opportunity ID"}},"hostedApiKey":"none"},"affinity_get_person":{"id":"affinity_get_person","name":"Affinity Get Person","description":"Look up one person by ID. Field data is returned only for the Field IDs or Field Types asked for.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"personId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The person ID"},"fieldIds":{"type":"json","required":false,"visibility":"user-or-llm","description":"Field IDs to return values for, e.g. [\\"affinity-data-location\\"]. Mutually exclusive with Field Types"},"fieldTypes":{"type":"json","required":false,"visibility":"user-or-llm","description":"Field categories to return values for: enriched, global, or relationship-intelligence. Mutually exclusive with Field IDs"}},"hostedApiKey":"none"},"affinity_get_saved_view":{"id":"affinity_get_saved_view","name":"Affinity Get Saved View","description":"Read one saved view — its name, kind, and creation date.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"listId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The list ID"},"viewId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The saved view ID"}},"hostedApiKey":"none"},"affinity_get_transcript":{"id":"affinity_get_transcript","name":"Affinity Get Transcript","description":"Read one transcript with its first 100 fragments. Page the fragments endpoint for a longer meeting.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"transcriptId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The transcript ID"}},"hostedApiKey":"none"},"affinity_get_user":{"id":"affinity_get_user","name":"Affinity Get User","description":"Read one internal user. A user and their person record share the same numeric ID, so a person ID works here.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"userId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The user ID, which is also their person ID"}},"hostedApiKey":"none"},"affinity_list_calls":{"id":"affinity_list_calls","name":"Affinity List Calls","description":"Page through logged calls and their participants. Only calls the API key holder can see are returned.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"filter":{"type":"string","required":false,"visibility":"user-or-llm","description":"Affinity Filtering Language expression, e.g. \\"createdAt>=2026-01-01\\""},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"}},"hostedApiKey":"none"},"affinity_list_chat_messages":{"id":"affinity_list_chat_messages","name":"Affinity List Chat Messages","description":"Page through logged chat messages and their participants. Only messages the API key holder can see are returned.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"filter":{"type":"string","required":false,"visibility":"user-or-llm","description":"Affinity Filtering Language expression, e.g. \\"createdAt>=2026-01-01\\""},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"}},"hostedApiKey":"none"},"affinity_list_companies":{"id":"affinity_list_companies","name":"Affinity List Companies","description":"Page through companies. Companies come back without field data unless Field IDs or Field Types asks for it.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"ids":{"type":"json","required":false,"visibility":"user-or-llm","description":"Restrict the page to these company IDs, e.g. [1, 2, 3]"},"fieldIds":{"type":"json","required":false,"visibility":"user-or-llm","description":"Field IDs to return values for, e.g. [\\"affinity-data-location\\"]. Mutually exclusive with Field Types"},"fieldTypes":{"type":"json","required":false,"visibility":"user-or-llm","description":"Field categories to return values for: enriched, global, or relationship-intelligence. Mutually exclusive with Field IDs"},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"}},"hostedApiKey":"none"},"affinity_list_coworker_connections":{"id":"affinity_list_coworker_connections","name":"Affinity List Coworker Connections","description":"Find warm paths into a company through shared work history: who in your Affinity data once worked alongside the people you want to reach. Grouped by target, strongest first.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"filter":{"type":"string","required":true,"visibility":"user-or-llm","description":"Required scope. The only supported filter is target.currentCompany.id, e.g. \\"target.currentCompany.id=123\\""},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of targets to return per page, 1-50. Defaults to 20"},"totalCount":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Include the total size of the collection. Costs an extra query"}},"hostedApiKey":"none"},"affinity_list_emails":{"id":"affinity_list_emails","name":"Affinity List Emails","description":"Page through email metadata — subject, participants, and timestamps. Affinity never exposes email bodies through the API.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"filter":{"type":"string","required":false,"visibility":"user-or-llm","description":"Affinity Filtering Language expression, e.g. \\"createdAt>=2026-01-01\\""},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"}},"hostedApiKey":"none"},"affinity_list_entity_field_values":{"id":"affinity_list_entity_field_values","name":"Affinity List Entity Field Values","description":"Page through a company\'s or person\'s non-list field values. List fields are not returned here — read those through the list entry.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"entityType":{"type":"string","required":true,"visibility":"user-or-llm","description":"Which entity to read field values from: companies or persons"},"entityId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of that company or person"},"ids":{"type":"json","required":false,"visibility":"user-or-llm","description":"Restrict to these field IDs. Mutually exclusive with Field Types"},"types":{"type":"json","required":false,"visibility":"user-or-llm","description":"Restrict to these field categories: enriched, global, relationship-intelligence. Mutually exclusive with Field IDs"},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 20"}},"hostedApiKey":"none"},"affinity_list_entity_list_entries":{"id":"affinity_list_entity_list_entries","name":"Affinity List Entity List Entries","description":"Page through a company\'s or person\'s rows across every list, each carrying that list\'s field values and when the entity was added.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"entityType":{"type":"string","required":true,"visibility":"user-or-llm","description":"Which entity to look up the rows of: companies or persons"},"entityId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of that company or person"},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"}},"hostedApiKey":"none"},"affinity_list_entity_lists":{"id":"affinity_list_entity_lists","name":"Affinity List Entity Lists","description":"List every list a company or person appears on that the caller can view.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"entityType":{"type":"string","required":true,"visibility":"user-or-llm","description":"Which entity to look up the lists of: companies or persons"},"entityId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of that company or person"},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"}},"hostedApiKey":"none"},"affinity_list_entity_notes":{"id":"affinity_list_entity_notes","name":"Affinity List Entity Notes","description":"List the notes relevant to one company, person, or opportunity — directly attached notes plus notes reaching it through its people and meetings.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"entityType":{"type":"string","required":true,"visibility":"user-or-llm","description":"Which entity the notes hang off: companies, persons, or opportunities"},"entityId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of that company, person, or opportunity"},"filter":{"type":"string","required":false,"visibility":"user-or-llm","description":"Affinity Filtering Language expression, e.g. \\"createdAt>=2026-01-01\\""},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"},"totalCount":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Include the total size of the collection. Costs an extra query"}},"hostedApiKey":"none"},"affinity_list_entity_relationships":{"id":"affinity_list_entity_relationships","name":"Affinity List Entity Relationships","description":"List who knows a company or person, scored 0.0 to 1.0 by how much the two actually interact. Strongest first by default.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"entityType":{"type":"string","required":true,"visibility":"user-or-llm","description":"Which entity to look up relationships for: companies or persons"},"entityId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of that company or person"},"filter":{"type":"string","required":false,"visibility":"user-or-llm","description":"Affinity Filtering Language expression. This endpoint filters on interactionScore only, e.g. \\"interactionScore>=0.5\\""},"orderBy":{"type":"json","required":false,"visibility":"user-or-llm","description":"Sort order: [\\"interactionScore\\"] for weakest first, [\\"-interactionScore\\"] for strongest first (the default)"},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"},"totalCount":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Include the total size of the collection. Costs an extra query"}},"hostedApiKey":"none"},"affinity_list_field_dropdown_options":{"id":"affinity_list_field_dropdown_options","name":"Affinity List Field Dropdown Options","description":"List the selectable options on a dropdown or ranked-dropdown company or person field. Writing such a field needs the option ID, not its text.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"entityType":{"type":"string","required":true,"visibility":"user-or-llm","description":"Which field family the field belongs to: companies or persons"},"fieldId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The dropdown or ranked-dropdown field ID"},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"}},"hostedApiKey":"none"},"affinity_list_field_metadata":{"id":"affinity_list_field_metadata","name":"Affinity List Field Metadata","description":"List the non-list company or person fields, with the value type, filter operators, and sort support of each. Start here to find the Field IDs the read and write tools take.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"entityType":{"type":"string","required":true,"visibility":"user-or-llm","description":"Which fields to describe: companies or persons"},"includes":{"type":"json","required":false,"visibility":"user-or-llm","description":"Extra properties to return: [\\"filterability\\",\\"sortability\\"]. Both are omitted unless requested here"},"filter":{"type":"string","required":false,"visibility":"user-or-llm","description":"Affinity Filtering Language expression. This endpoint filters on name only, e.g. \\"name=~Status\\""},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"}},"hostedApiKey":"none"},"affinity_list_field_value_changes":{"id":"affinity_list_field_value_changes","name":"Affinity List Field Value Changes","description":"Page through field value changes across the whole workspace. Built for delta sync: follow nextCursor to the end of a run, then resume from the last cursor next time.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"filter":{"type":"string","required":false,"visibility":"user-or-llm","description":"Affinity Filtering Language expression over field.id, listEntry.id, changer.id, changedAt, or actionType. Resume a sync with e.g. \\"changedAt>2026-06-01T12:00:00Z\\""},"orderBy":{"type":"json","required":false,"visibility":"user-or-llm","description":"Sort order: [\\"changedAt\\"] for oldest first (the default), [\\"-changedAt\\"] for newest first"},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"}},"hostedApiKey":"none"},"affinity_list_investor_executive_connections":{"id":"affinity_list_investor_executive_connections","name":"Affinity List Investor Executive Connections","description":"Find warm paths into a company through investment history: which investors in your Affinity data backed a company the people you want to reach once led. Grouped by target, strongest first.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"filter":{"type":"string","required":true,"visibility":"user-or-llm","description":"Required scope. The only supported filter is target.currentCompany.id, e.g. \\"target.currentCompany.id=123\\""},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of targets to return per page, 1-50. Defaults to 20"},"totalCount":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Include the total size of the collection. Costs an extra query"}},"hostedApiKey":"none"},"affinity_list_list_entries":{"id":"affinity_list_list_entries","name":"Affinity List List Entries","description":"Page through the rows of a list. Rows come back without field data unless Field IDs or Field Types asks for it.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"listId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The list ID"},"fieldIds":{"type":"json","required":false,"visibility":"user-or-llm","description":"Field IDs to return values for, e.g. [\\"affinity-data-location\\"]. Mutually exclusive with Field Types"},"fieldTypes":{"type":"json","required":false,"visibility":"user-or-llm","description":"Field categories to return values for: enriched, global, list, or relationship-intelligence. Mutually exclusive with Field IDs"},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"}},"hostedApiKey":"none"},"affinity_list_list_entry_field_value_changes":{"id":"affinity_list_list_entry_field_value_changes","name":"Affinity List List Entry Field Value Changes","description":"Page through the history of one list row — who changed which field, when, and to what.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"listId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The list ID"},"listEntryId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The list entry ID"},"filter":{"type":"string","required":false,"visibility":"user-or-llm","description":"Affinity Filtering Language expression over field.id, changer.id, changedAt, or actionType, e.g. \\"field.id=field-1234\\""},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"}},"hostedApiKey":"none"},"affinity_list_list_entry_fields":{"id":"affinity_list_list_entry_fields","name":"Affinity List List Entry Fields","description":"Page through every field value on one list row, including the list-specific columns. All fields are returned unless narrowed.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"listId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The list ID"},"listEntryId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The list entry ID"},"ids":{"type":"json","required":false,"visibility":"user-or-llm","description":"Restrict to these field IDs. Mutually exclusive with Field Types"},"types":{"type":"json","required":false,"visibility":"user-or-llm","description":"Restrict to these field categories: enriched, global, list, relationship-intelligence. Mutually exclusive with Field IDs"},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 20"}},"hostedApiKey":"none"},"affinity_list_list_field_dropdown_options":{"id":"affinity_list_list_field_dropdown_options","name":"Affinity List List Field Dropdown Options","description":"List the selectable options on a dropdown, ranked-dropdown, or status-dropdown field of a list.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"listId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The list ID"},"fieldId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The dropdown field ID on that list"},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"}},"hostedApiKey":"none"},"affinity_list_list_fields":{"id":"affinity_list_list_fields","name":"Affinity List List Fields","description":"List the fields available on one list, including its list-specific columns. Use these Field IDs when reading or writing list entries.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"listId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The list ID"},"includes":{"type":"json","required":false,"visibility":"user-or-llm","description":"Extra properties to return: [\\"filterability\\",\\"sortability\\"]. Both are omitted unless requested here"},"filter":{"type":"string","required":false,"visibility":"user-or-llm","description":"Affinity Filtering Language expression. This endpoint filters on name only, e.g. \\"name=~Stage\\""},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"}},"hostedApiKey":"none"},"affinity_list_lists":{"id":"affinity_list_lists","name":"Affinity List Lists","description":"Page through the lists in the organization that the caller can view.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"term":{"type":"string","required":false,"visibility":"user-or-llm","description":"Case-insensitive substring match on the list name"},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"}},"hostedApiKey":"none"},"affinity_list_meetings":{"id":"affinity_list_meetings","name":"Affinity List Meetings","description":"Page through past and upcoming meetings with their organizer and attendees.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"filter":{"type":"string","required":false,"visibility":"user-or-llm","description":"Affinity Filtering Language expression, e.g. \\"createdAt>=2026-01-01\\""},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"}},"hostedApiKey":"none"},"affinity_list_merge_tasks":{"id":"affinity_list_merge_tasks","name":"Affinity List Merge Tasks","description":"Page through merge tasks, each summarizing how many of its merges are in progress, succeeded, or failed.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"entityType":{"type":"string","required":true,"visibility":"user-or-llm","description":"Which merge tasks to list: companies or persons"},"filter":{"type":"string","required":false,"visibility":"user-or-llm","description":"Affinity Filtering Language expression. This endpoint filters on status only, e.g. \\"status=in-progress\\""},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"}},"hostedApiKey":"none"},"affinity_list_merges":{"id":"affinity_list_merges","name":"Affinity List Merges","description":"Page through the company or person merges the organization has run, with the status and the records involved in each.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"entityType":{"type":"string","required":true,"visibility":"user-or-llm","description":"Which merges to list: companies or persons"},"filter":{"type":"string","required":false,"visibility":"user-or-llm","description":"Affinity Filtering Language expression over status or taskId, e.g. \\"status=failed\\""},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"}},"hostedApiKey":"none"},"affinity_list_note_attached_companies":{"id":"affinity_list_note_attached_companies","name":"Affinity List Note Attached Companies","description":"List the companies directly attached to one note.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"noteId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The note ID"},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"},"totalCount":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Include the total size of the collection. Costs an extra query"}},"hostedApiKey":"none"},"affinity_list_note_attached_opportunities":{"id":"affinity_list_note_attached_opportunities","name":"Affinity List Note Attached Opportunities","description":"List the opportunities directly attached to one note.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"noteId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The note ID"},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"},"totalCount":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Include the total size of the collection. Costs an extra query"}},"hostedApiKey":"none"},"affinity_list_note_attached_persons":{"id":"affinity_list_note_attached_persons","name":"Affinity List Note Attached Persons","description":"List the persons directly attached to one note.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"noteId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The note ID"},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"},"totalCount":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Include the total size of the collection. Costs an extra query"}},"hostedApiKey":"none"},"affinity_list_note_replies":{"id":"affinity_list_note_replies","name":"Affinity List Note Replies","description":"Page through the replies on one note, including AI Notetaker replies.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"noteId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The note ID whose replies to read"},"filter":{"type":"string","required":false,"visibility":"user-or-llm","description":"Affinity Filtering Language expression, e.g. \\"createdAt>=2026-01-01\\""},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"},"totalCount":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Include the total size of the collection. Costs an extra query"}},"hostedApiKey":"none"},"affinity_list_notes":{"id":"affinity_list_notes","name":"Affinity List Notes","description":"Page through every note the caller can see. Replies are excluded.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"includes":{"type":"json","required":false,"visibility":"user-or-llm","description":"Extra properties to return, e.g. [\\"repliesCount\\",\\"personsPreview\\",\\"companiesPreview\\",\\"opportunitiesPreview\\"]. Those four fields are omitted unless requested here"},"filter":{"type":"string","required":false,"visibility":"user-or-llm","description":"Affinity Filtering Language expression, e.g. \\"createdAt>=2026-01-01\\""},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"},"totalCount":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Include the total size of the collection. Costs an extra query"}},"hostedApiKey":"none"},"affinity_list_opportunities":{"id":"affinity_list_opportunities","name":"Affinity List Opportunities","description":"Page through opportunities. Field data lives on the list entry, not here — read it through the list or saved view the opportunity belongs to.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"ids":{"type":"json","required":false,"visibility":"user-or-llm","description":"Restrict the page to these opportunity IDs, e.g. [1, 2, 3]"},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"}},"hostedApiKey":"none"},"affinity_list_persons":{"id":"affinity_list_persons","name":"Affinity List Persons","description":"Page through persons. Persons come back without field data unless Field IDs or Field Types asks for it.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"ids":{"type":"json","required":false,"visibility":"user-or-llm","description":"Restrict the page to these person IDs, e.g. [1, 2, 3]"},"fieldIds":{"type":"json","required":false,"visibility":"user-or-llm","description":"Field IDs to return values for, e.g. [\\"affinity-data-location\\"]. Mutually exclusive with Field Types"},"fieldTypes":{"type":"json","required":false,"visibility":"user-or-llm","description":"Field categories to return values for: enriched, global, or relationship-intelligence. Mutually exclusive with Field IDs"},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"}},"hostedApiKey":"none"},"affinity_list_reminders":{"id":"affinity_list_reminders","name":"Affinity List Reminders","description":"Page through the reminders the caller can see. Filter by status to surface what is overdue.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"filter":{"type":"string","required":false,"visibility":"user-or-llm","description":"Affinity Filtering Language expression, e.g. \\"createdAt>=2026-01-01\\""},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"},"totalCount":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Include the total size of the collection. Costs an extra query"}},"hostedApiKey":"none"},"affinity_list_saved_view_entries":{"id":"affinity_list_saved_view_entries","name":"Affinity List Saved View Entries","description":"Page through the rows of a saved view. The view\'s own filters and columns decide which rows and which field data come back.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"listId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The list ID"},"viewId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The saved view ID"},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"}},"hostedApiKey":"none"},"affinity_list_saved_views":{"id":"affinity_list_saved_views","name":"Affinity List Saved Views","description":"List the saved views on a list that the caller can view.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"listId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The list ID"},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"}},"hostedApiKey":"none"},"affinity_list_transcript_fragments":{"id":"affinity_list_transcript_fragments","name":"Affinity List Transcript Fragments","description":"Page through everything said in a meeting, segment by segment with the speaker.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"transcriptId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The transcript ID"},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"},"totalCount":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Include the total size of the collection. Costs an extra query"}},"hostedApiKey":"none"},"affinity_list_transcripts":{"id":"affinity_list_transcripts","name":"Affinity List Transcripts","description":"Page through meeting transcript metadata. Read one transcript to get what was actually said.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"filter":{"type":"string","required":false,"visibility":"user-or-llm","description":"Affinity Filtering Language expression, e.g. \\"createdAt>=2026-01-01\\""},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"},"totalCount":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Include the total size of the collection. Costs an extra query"}},"hostedApiKey":"none"},"affinity_list_users":{"id":"affinity_list_users","name":"Affinity List Users","description":"Page through the internal users in the organization. Email addresses and roles are returned only to callers with the \\"Manage Users\\" permission.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"term":{"type":"string","required":false,"visibility":"user-or-llm","description":"Case-insensitive match across first name, last name, and primary email"},"filter":{"type":"string","required":false,"visibility":"user-or-llm","description":"Affinity Filtering Language expression over id or status, e.g. \\"status=active\\""},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"}},"hostedApiKey":"none"},"affinity_search_companies":{"id":"affinity_search_companies","name":"Affinity Search Companies","description":"Search companies by filters, sorts, and a free-text term. Requires the \\"Export All Organizations directory\\" permission.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"filters":{"type":"json","required":false,"visibility":"user-or-llm","description":"Filter group as {operator: \\"and\\"|\\"or\\", filters: [...]}, at most 50 leaves. Each leaf is {valueType, fieldId, operator, value}, and a leaf may itself be a nested group"},"searchTerm":{"type":"string","required":false,"visibility":"user-or-llm","description":"Free-text term matched against the searchable fields. At least 3 characters"},"searchFieldIds":{"type":"json","required":false,"visibility":"user-or-llm","description":"Field IDs the search term is matched against. Defaults to the searchable fields"},"sorts":{"type":"json","required":false,"visibility":"user-or-llm","description":"Sort order as [{fieldId, direction: \\"asc\\"|\\"desc\\", attributeId?}], up to 5, applied in order"},"fieldIds":{"type":"json","required":false,"visibility":"user-or-llm","description":"Field IDs to return values for, e.g. [\\"affinity-data-location\\"]. Mutually exclusive with Field Types"},"fieldTypes":{"type":"json","required":false,"visibility":"user-or-llm","description":"Field categories to return values for: enriched, global, or relationship-intelligence. Mutually exclusive with Field IDs"},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"},"totalCount":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Include the total size of the collection. Costs an extra query"}},"hostedApiKey":"none"},"affinity_search_files":{"id":"affinity_search_files","name":"Affinity Search Files","description":"Search files by keyword, ordered by relevance. Narrow to specific files or to one company, or leave both unset to search the whole account.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"prompt":{"type":"string","required":true,"visibility":"user-or-llm","description":"What to search for. Between 3 and 500 characters"},"ids":{"type":"json","required":false,"visibility":"user-or-llm","description":"Restrict the search to these file IDs. Cannot be combined with Company ID"},"companyId":{"type":"string","required":false,"visibility":"user-or-llm","description":"Restrict the search to one company\'s files. Cannot be combined with file IDs"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Maximum number of files to return, 1-100. Defaults to 20"}},"hostedApiKey":"none"},"affinity_search_list_entries":{"id":"affinity_search_list_entries","name":"Affinity Search List Entries","description":"Search the rows of one list by filters, sorts, and a free-text term. Requires the \\"Export data from Lists\\" permission.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"listId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The list ID to search"},"filters":{"type":"json","required":false,"visibility":"user-or-llm","description":"Filter group as {operator: \\"and\\"|\\"or\\", filters: [...]}, at most 50 leaves. Each leaf is {valueType, fieldId, operator, value}, and a leaf may itself be a nested group"},"searchTerm":{"type":"string","required":false,"visibility":"user-or-llm","description":"Free-text term matched against the searchable fields. At least 3 characters"},"searchFieldIds":{"type":"json","required":false,"visibility":"user-or-llm","description":"Field IDs the search term is matched against. Defaults to the searchable fields"},"sorts":{"type":"json","required":false,"visibility":"user-or-llm","description":"Sort order as [{fieldId, direction: \\"asc\\"|\\"desc\\", attributeId?}], up to 5, applied in order"},"fieldIds":{"type":"json","required":false,"visibility":"user-or-llm","description":"Field IDs to return values for, e.g. [\\"affinity-data-location\\"]. Mutually exclusive with Field Types"},"fieldTypes":{"type":"json","required":false,"visibility":"user-or-llm","description":"Field categories to return values for: enriched, global, list, or relationship-intelligence. Mutually exclusive with Field IDs"},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"},"totalCount":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Include the total size of the collection. Costs an extra query"}},"hostedApiKey":"none"},"affinity_search_notes":{"id":"affinity_search_notes","name":"Affinity Search Notes","description":"Search notes by keyword, ordered by relevance. Narrow to specific notes or to one company, or leave both unset to search the whole account.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"prompt":{"type":"string","required":true,"visibility":"user-or-llm","description":"What to search for. Between 3 and 500 characters"},"ids":{"type":"json","required":false,"visibility":"user-or-llm","description":"Restrict the search to these note IDs. Cannot be combined with Company ID"},"companyId":{"type":"string","required":false,"visibility":"user-or-llm","description":"Restrict the search to one company\'s notes. Cannot be combined with note IDs"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Maximum number of notes to return, 1-100. Defaults to 20"}},"hostedApiKey":"none"},"affinity_search_persons":{"id":"affinity_search_persons","name":"Affinity Search Persons","description":"Search persons by filters, sorts, and a free-text term. Requires the \\"Export All People directory\\" permission.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"filters":{"type":"json","required":false,"visibility":"user-or-llm","description":"Filter group as {operator: \\"and\\"|\\"or\\", filters: [...]}, at most 50 leaves. Each leaf is {valueType, fieldId, operator, value}, and a leaf may itself be a nested group"},"searchTerm":{"type":"string","required":false,"visibility":"user-or-llm","description":"Free-text term matched against the searchable fields. At least 3 characters"},"searchFieldIds":{"type":"json","required":false,"visibility":"user-or-llm","description":"Field IDs the search term is matched against. Defaults to the searchable fields"},"sorts":{"type":"json","required":false,"visibility":"user-or-llm","description":"Sort order as [{fieldId, direction: \\"asc\\"|\\"desc\\", attributeId?}], up to 5, applied in order"},"fieldIds":{"type":"json","required":false,"visibility":"user-or-llm","description":"Field IDs to return values for, e.g. [\\"affinity-data-location\\"]. Mutually exclusive with Field Types"},"fieldTypes":{"type":"json","required":false,"visibility":"user-or-llm","description":"Field categories to return values for: enriched, global, or relationship-intelligence. Mutually exclusive with Field IDs"},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous page, returned as nextCursor or prevCursor"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to return per page, 1-100. Defaults to 100"},"totalCount":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Include the total size of the collection. Costs an extra query"}},"hostedApiKey":"none"},"affinity_semantic_search":{"id":"affinity_semantic_search","name":"Affinity Semantic Search","description":"Find companies from a description in plain language — industry, technology, stage, or business model. Currently searches companies only.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"prompt":{"type":"string","required":true,"visibility":"user-or-llm","description":"What to look for, in plain language, e.g. \\"climate tech companies in our pipeline\\". Up to 500 characters"},"listIds":{"type":"json","required":false,"visibility":"user-or-llm","description":"Restrict the search to companies on these lists, e.g. [1, 2]"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Maximum number of companies to return, 1-100. Defaults to 100"}},"hostedApiKey":"none"},"affinity_update_entity_field_value":{"id":"affinity_update_entity_field_value","name":"Affinity Update Entity Field Value","description":"Write one non-list field value on a company or person. The value type must match how the field is defined.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"entityType":{"type":"string","required":true,"visibility":"user-or-llm","description":"Which entity to write the field on: companies or persons"},"entityId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of that company or person"},"fieldId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The field ID to write"},"value":{"type":"json","required":true,"visibility":"user-or-llm","description":"The new value as {type, data}, where type matches the field\'s value type. Examples: {\\"type\\":\\"text\\",\\"data\\":\\"Series B\\"}, {\\"type\\":\\"number\\",\\"data\\":42}, {\\"type\\":\\"dropdown\\",\\"data\\":{\\"dropdownOptionId\\":7}}, {\\"type\\":\\"person\\",\\"data\\":{\\"id\\":123}}, {\\"type\\":\\"person-multi\\",\\"data\\":[{\\"id\\":123}]}. Pass data as null to clear the field"}},"hostedApiKey":"none"},"affinity_update_list_entry_field":{"id":"affinity_update_list_entry_field","name":"Affinity Update List Entry Field","description":"Write one field value on a list row. Requires the \\"Export data from Lists\\" permission.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"listId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The list ID"},"listEntryId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The list entry ID"},"fieldId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The field ID to write"},"value":{"type":"json","required":true,"visibility":"user-or-llm","description":"The new value as {type, data}, where type matches the field\'s value type. Examples: {\\"type\\":\\"text\\",\\"data\\":\\"Series B\\"}, {\\"type\\":\\"number\\",\\"data\\":42}, {\\"type\\":\\"dropdown\\",\\"data\\":{\\"dropdownOptionId\\":7}}, {\\"type\\":\\"person\\",\\"data\\":{\\"id\\":123}}, {\\"type\\":\\"person-multi\\",\\"data\\":[{\\"id\\":123}]}. Pass data as null to clear the field"}},"hostedApiKey":"none"},"affinity_update_list_field_dropdown_option":{"id":"affinity_update_list_field_dropdown_option","name":"Affinity Update List Field Dropdown Option","description":"Change a dropdown option on a list field. Every field is optional — supply only what should change, and only fields the option\'s kind actually has.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"listId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The list ID"},"fieldId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The dropdown field ID on that list"},"dropdownOptionId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The dropdown option ID to update"},"text":{"type":"string","required":false,"visibility":"user-or-llm","description":"Replacement option label. Supply at least one field to change"},"rank":{"type":"number","required":false,"visibility":"user-or-llm","description":"Sort order. Required on a ranked-dropdown or status-dropdown option"},"color":{"type":"string","required":false,"visibility":"user-or-llm","description":"Option color: white, gray, blue, green, purple, orange, or red. Required on a ranked-dropdown or status-dropdown option"},"statusCategory":{"type":"string","required":false,"visibility":"user-or-llm","description":"Pipeline meaning of the option: open, won, lost, or on-hold. Status-dropdown options only"},"winRate":{"type":"number","required":false,"visibility":"user-or-llm","description":"Expected win rate of the status. Status-dropdown options only"}},"hostedApiKey":"none"},"affinity_update_note":{"id":"affinity_update_note","name":"Affinity Update Note","description":"Rewrite a note\'s body or replace which records it is attached to. Each list of IDs replaces that association wholesale, an empty list clears it, and omitting one leaves it untouched. A note\'s type cannot be changed.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Affinity API key, sent as a bearer token"},"noteId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The note ID to update"},"html":{"type":"string","required":false,"visibility":"user-or-llm","description":"Replacement note body as HTML"},"companyIds":{"type":"json","required":false,"visibility":"user-or-llm","description":"Replacement set of attached companies, e.g. [1, 2]. Send [] to detach every company; omit to leave them unchanged"},"personIds":{"type":"json","required":false,"visibility":"user-or-llm","description":"Replacement set of attached persons, e.g. [1, 2]. Send [] to detach every person; omit to leave them unchanged"},"opportunityIds":{"type":"json","required":false,"visibility":"user-or-llm","description":"Replacement set of attached opportunities, e.g. [1, 2]. Send [] to detach every opportunity; omit to leave them unchanged"}},"hostedApiKey":"none"},"agentmail_create_draft":{"id":"agentmail_create_draft","name":"Create Draft","description":"Create a new email draft in AgentMail","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentMail API key"},"inboxId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the inbox to create the draft in"},"to":{"type":"string","required":false,"visibility":"user-or-llm","description":"Recipient email addresses (comma-separated)"},"subject":{"type":"string","required":false,"visibility":"user-or-llm","description":"Draft subject line"},"text":{"type":"string","required":false,"visibility":"user-or-llm","description":"Plain text draft body"},"html":{"type":"string","required":false,"visibility":"user-or-llm","description":"HTML draft body"},"cc":{"type":"string","required":false,"visibility":"user-or-llm","description":"CC recipient email addresses (comma-separated)"},"bcc":{"type":"string","required":false,"visibility":"user-or-llm","description":"BCC recipient email addresses (comma-separated)"},"inReplyTo":{"type":"string","required":false,"visibility":"user-or-llm","description":"ID of message being replied to"},"sendAt":{"type":"string","required":false,"visibility":"user-or-llm","description":"ISO 8601 timestamp to schedule sending"}},"hostedApiKey":"none"},"agentmail_create_inbox":{"id":"agentmail_create_inbox","name":"Create Inbox","description":"Create a new email inbox with AgentMail","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentMail API key"},"username":{"type":"string","required":false,"visibility":"user-or-llm","description":"Username for the inbox email address"},"domain":{"type":"string","required":false,"visibility":"user-or-llm","description":"Domain for the inbox email address"},"displayName":{"type":"string","required":false,"visibility":"user-or-llm","description":"Display name for the inbox"}},"hostedApiKey":"none"},"agentmail_delete_draft":{"id":"agentmail_delete_draft","name":"Delete Draft","description":"Delete an email draft in AgentMail","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentMail API key"},"inboxId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the inbox containing the draft"},"draftId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the draft to delete"}},"hostedApiKey":"none"},"agentmail_delete_inbox":{"id":"agentmail_delete_inbox","name":"Delete Inbox","description":"Delete an email inbox in AgentMail","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentMail API key"},"inboxId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the inbox to delete"}},"hostedApiKey":"none"},"agentmail_delete_thread":{"id":"agentmail_delete_thread","name":"Delete Thread","description":"Delete an email thread in AgentMail (moves to trash, or permanently deletes if already in trash)","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentMail API key"},"inboxId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the inbox containing the thread"},"threadId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the thread to delete"},"permanent":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Force permanent deletion instead of moving to trash"}},"hostedApiKey":"none"},"agentmail_forward_message":{"id":"agentmail_forward_message","name":"Forward Message","description":"Forward an email message to new recipients in AgentMail","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentMail API key"},"inboxId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the inbox containing the message"},"messageId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the message to forward"},"to":{"type":"string","required":true,"visibility":"user-or-llm","description":"Recipient email addresses (comma-separated)"},"subject":{"type":"string","required":false,"visibility":"user-or-llm","description":"Override subject line"},"text":{"type":"string","required":false,"visibility":"user-or-llm","description":"Additional plain text to prepend"},"html":{"type":"string","required":false,"visibility":"user-or-llm","description":"Additional HTML to prepend"},"cc":{"type":"string","required":false,"visibility":"user-or-llm","description":"CC recipient email addresses (comma-separated)"},"bcc":{"type":"string","required":false,"visibility":"user-or-llm","description":"BCC recipient email addresses (comma-separated)"}},"hostedApiKey":"none"},"agentmail_get_draft":{"id":"agentmail_get_draft","name":"Get Draft","description":"Get details of a specific email draft in AgentMail","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentMail API key"},"inboxId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the inbox the draft belongs to"},"draftId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the draft to retrieve"}},"hostedApiKey":"none"},"agentmail_get_inbox":{"id":"agentmail_get_inbox","name":"Get Inbox","description":"Get details of a specific email inbox in AgentMail","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentMail API key"},"inboxId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the inbox to retrieve"}},"hostedApiKey":"none"},"agentmail_get_message":{"id":"agentmail_get_message","name":"Get Message","description":"Get details of a specific email message in AgentMail","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentMail API key"},"inboxId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the inbox containing the message"},"messageId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the message to retrieve"}},"hostedApiKey":"none"},"agentmail_get_thread":{"id":"agentmail_get_thread","name":"Get Thread","description":"Get details of a specific email thread including messages in AgentMail","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentMail API key"},"inboxId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the inbox containing the thread"},"threadId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the thread to retrieve"}},"hostedApiKey":"none"},"agentmail_list_drafts":{"id":"agentmail_list_drafts","name":"List Drafts","description":"List email drafts in an inbox in AgentMail","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentMail API key"},"inboxId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the inbox to list drafts from"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Maximum number of drafts to return"},"pageToken":{"type":"string","required":false,"visibility":"user-or-llm","description":"Pagination token for next page of results"}},"hostedApiKey":"none"},"agentmail_list_inboxes":{"id":"agentmail_list_inboxes","name":"List Inboxes","description":"List all email inboxes in AgentMail","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentMail API key"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Maximum number of inboxes to return"},"pageToken":{"type":"string","required":false,"visibility":"user-or-llm","description":"Pagination token for next page of results"}},"hostedApiKey":"none"},"agentmail_list_messages":{"id":"agentmail_list_messages","name":"List Messages","description":"List messages in an inbox in AgentMail","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentMail API key"},"inboxId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the inbox to list messages from"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Maximum number of messages to return"},"pageToken":{"type":"string","required":false,"visibility":"user-or-llm","description":"Pagination token for next page of results"}},"hostedApiKey":"none"},"agentmail_list_threads":{"id":"agentmail_list_threads","name":"List Threads","description":"List email threads in AgentMail","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentMail API key"},"inboxId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the inbox to list threads from"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Maximum number of threads to return"},"pageToken":{"type":"string","required":false,"visibility":"user-or-llm","description":"Pagination token for next page of results"},"labels":{"type":"string","required":false,"visibility":"user-or-llm","description":"Comma-separated labels to filter threads by"},"before":{"type":"string","required":false,"visibility":"user-or-llm","description":"Filter threads before this ISO 8601 timestamp"},"after":{"type":"string","required":false,"visibility":"user-or-llm","description":"Filter threads after this ISO 8601 timestamp"}},"hostedApiKey":"none"},"agentmail_reply_message":{"id":"agentmail_reply_message","name":"Reply to Message","description":"Reply to an existing email message in AgentMail","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentMail API key"},"inboxId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the inbox to reply from"},"messageId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the message to reply to"},"text":{"type":"string","required":false,"visibility":"user-or-llm","description":"Plain text reply body"},"html":{"type":"string","required":false,"visibility":"user-or-llm","description":"HTML reply body"},"to":{"type":"string","required":false,"visibility":"user-or-llm","description":"Override recipient email addresses (comma-separated)"},"cc":{"type":"string","required":false,"visibility":"user-or-llm","description":"CC email addresses (comma-separated)"},"bcc":{"type":"string","required":false,"visibility":"user-or-llm","description":"BCC email addresses (comma-separated)"},"replyAll":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Reply to all recipients of the original message"}},"hostedApiKey":"none"},"agentmail_send_draft":{"id":"agentmail_send_draft","name":"Send Draft","description":"Send an existing email draft in AgentMail","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentMail API key"},"inboxId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the inbox containing the draft"},"draftId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the draft to send"}},"hostedApiKey":"none"},"agentmail_send_message":{"id":"agentmail_send_message","name":"Send Message","description":"Send an email message from an AgentMail inbox","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentMail API key"},"inboxId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the inbox to send from"},"to":{"type":"string","required":true,"visibility":"user-or-llm","description":"Recipient email address (comma-separated for multiple)"},"subject":{"type":"string","required":true,"visibility":"user-or-llm","description":"Email subject line"},"text":{"type":"string","required":false,"visibility":"user-or-llm","description":"Plain text email body"},"html":{"type":"string","required":false,"visibility":"user-or-llm","description":"HTML email body"},"cc":{"type":"string","required":false,"visibility":"user-or-llm","description":"CC recipient email addresses (comma-separated)"},"bcc":{"type":"string","required":false,"visibility":"user-or-llm","description":"BCC recipient email addresses (comma-separated)"}},"hostedApiKey":"none"},"agentmail_update_draft":{"id":"agentmail_update_draft","name":"Update Draft","description":"Update an existing email draft in AgentMail","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentMail API key"},"inboxId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the inbox containing the draft"},"draftId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the draft to update"},"to":{"type":"string","required":false,"visibility":"user-or-llm","description":"Recipient email addresses (comma-separated)"},"subject":{"type":"string","required":false,"visibility":"user-or-llm","description":"Draft subject line"},"text":{"type":"string","required":false,"visibility":"user-or-llm","description":"Plain text draft body"},"html":{"type":"string","required":false,"visibility":"user-or-llm","description":"HTML draft body"},"cc":{"type":"string","required":false,"visibility":"user-or-llm","description":"CC recipient email addresses (comma-separated)"},"bcc":{"type":"string","required":false,"visibility":"user-or-llm","description":"BCC recipient email addresses (comma-separated)"},"sendAt":{"type":"string","required":false,"visibility":"user-or-llm","description":"ISO 8601 timestamp to schedule sending"}},"hostedApiKey":"none"},"agentmail_update_inbox":{"id":"agentmail_update_inbox","name":"Update Inbox","description":"Update the display name of an email inbox in AgentMail","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentMail API key"},"inboxId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the inbox to update"},"displayName":{"type":"string","required":true,"visibility":"user-or-llm","description":"New display name for the inbox"}},"hostedApiKey":"none"},"agentmail_update_message":{"id":"agentmail_update_message","name":"Update Message","description":"Add or remove labels on an email message in AgentMail","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentMail API key"},"inboxId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the inbox containing the message"},"messageId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the message to update"},"addLabels":{"type":"string","required":false,"visibility":"user-or-llm","description":"Comma-separated labels to add to the message"},"removeLabels":{"type":"string","required":false,"visibility":"user-or-llm","description":"Comma-separated labels to remove from the message"}},"hostedApiKey":"none"},"agentmail_update_thread":{"id":"agentmail_update_thread","name":"Update Thread Labels","description":"Add or remove labels on an email thread in AgentMail","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentMail API key"},"inboxId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the inbox containing the thread"},"threadId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the thread to update"},"addLabels":{"type":"string","required":false,"visibility":"user-or-llm","description":"Comma-separated labels to add to the thread"},"removeLabels":{"type":"string","required":false,"visibility":"user-or-llm","description":"Comma-separated labels to remove from the thread"}},"hostedApiKey":"none"},"agentphone_create_call":{"id":"agentphone_create_call","name":"Create Outbound Call","description":"Initiate an outbound voice call from an AgentPhone agent","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentPhone API key"},"agentId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Agent that will handle the call"},"toNumber":{"type":"string","required":true,"visibility":"user-or-llm","description":"Phone number to call in E.164 format (e.g. +14155551234)"},"fromNumberId":{"type":"string","required":false,"visibility":"user-or-llm","description":"Phone number ID to use as caller ID. Must belong to the agent. If omitted, the agent\'s first assigned number is used."},"initialGreeting":{"type":"string","required":false,"visibility":"user-or-llm","description":"Optional greeting spoken when the recipient answers"},"voice":{"type":"string","required":false,"visibility":"user-or-llm","description":"Voice ID override for this call (defaults to the agent\'s configured voice)"},"systemPrompt":{"type":"string","required":false,"visibility":"user-or-llm","description":"When provided, uses a built-in LLM for the conversation instead of forwarding to your webhook"}},"hostedApiKey":"none"},"agentphone_create_contact":{"id":"agentphone_create_contact","name":"Create Contact","description":"Create a new contact in AgentPhone","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentPhone API key"},"phoneNumber":{"type":"string","required":true,"visibility":"user-or-llm","description":"Phone number in E.164 format (e.g. +14155551234)"},"name":{"type":"string","required":true,"visibility":"user-or-llm","description":"Contact\'s full name"},"email":{"type":"string","required":false,"visibility":"user-or-llm","description":"Contact\'s email address"},"notes":{"type":"string","required":false,"visibility":"user-or-llm","description":"Freeform notes stored on the contact"}},"hostedApiKey":"none"},"agentphone_create_number":{"id":"agentphone_create_number","name":"Create Phone Number","description":"Provision a new SMS- and voice-enabled phone number","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentPhone API key"},"country":{"type":"string","required":false,"visibility":"user-or-llm","description":"Two-letter country code (e.g. US, CA). Defaults to US."},"areaCode":{"type":"string","required":false,"visibility":"user-or-llm","description":"Preferred area code (US/CA only, e.g. \\"415\\"). Best-effort — may be ignored if unavailable."},"agentId":{"type":"string","required":false,"visibility":"user-or-llm","description":"Optionally attach the number to an agent immediately"}},"hostedApiKey":"none"},"agentphone_delete_contact":{"id":"agentphone_delete_contact","name":"Delete Contact","description":"Delete a contact by ID","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentPhone API key"},"contactId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Contact ID"}},"hostedApiKey":"none"},"agentphone_get_call":{"id":"agentphone_get_call","name":"Get Call","description":"Fetch a call and its full transcript","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentPhone API key"},"callId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the call to retrieve"}},"hostedApiKey":"none"},"agentphone_get_call_transcript":{"id":"agentphone_get_call_transcript","name":"Get Call Transcript","description":"Get the full ordered transcript for a call","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentPhone API key"},"callId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the call to retrieve the transcript for"}},"hostedApiKey":"none"},"agentphone_get_contact":{"id":"agentphone_get_contact","name":"Get Contact","description":"Fetch a single contact by ID","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentPhone API key"},"contactId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Contact ID"}},"hostedApiKey":"none"},"agentphone_get_conversation":{"id":"agentphone_get_conversation","name":"Get Conversation","description":"Get a conversation along with its recent messages","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentPhone API key"},"conversationId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Conversation ID"},"messageLimit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of recent messages to include (default 50, max 100)"}},"hostedApiKey":"none"},"agentphone_get_conversation_messages":{"id":"agentphone_get_conversation_messages","name":"Get Conversation Messages","description":"Get paginated messages for a conversation","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentPhone API key"},"conversationId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Conversation ID"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of messages to return (default 50, max 200)"},"before":{"type":"string","required":false,"visibility":"user-or-llm","description":"Return messages received before this ISO 8601 timestamp"},"after":{"type":"string","required":false,"visibility":"user-or-llm","description":"Return messages received after this ISO 8601 timestamp"}},"hostedApiKey":"none"},"agentphone_get_number_messages":{"id":"agentphone_get_number_messages","name":"Get Phone Number Messages","description":"Fetch messages received on a specific phone number","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentPhone API key"},"numberId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the phone number"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of messages to return (default 50, max 200)"},"before":{"type":"string","required":false,"visibility":"user-or-llm","description":"Return messages received before this ISO 8601 timestamp"},"after":{"type":"string","required":false,"visibility":"user-or-llm","description":"Return messages received after this ISO 8601 timestamp"}},"hostedApiKey":"none"},"agentphone_get_usage":{"id":"agentphone_get_usage","name":"Get Usage","description":"Retrieve current usage statistics for the AgentPhone account","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentPhone API key"}},"hostedApiKey":"none"},"agentphone_get_usage_daily":{"id":"agentphone_get_usage_daily","name":"Get Daily Usage","description":"Get a daily breakdown of usage (messages, calls, webhooks) for the last N days","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentPhone API key"},"days":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of days to return (1-365, default 30)"}},"hostedApiKey":"none"},"agentphone_get_usage_monthly":{"id":"agentphone_get_usage_monthly","name":"Get Monthly Usage","description":"Get monthly usage aggregation (messages, calls, webhooks) for the last N months","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentPhone API key"},"months":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of months to return (1-24, default 6)"}},"hostedApiKey":"none"},"agentphone_list_calls":{"id":"agentphone_list_calls","name":"List Calls","description":"List voice calls for this AgentPhone account","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentPhone API key"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of results to return (default 20, max 100)"},"offset":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of results to skip (min 0)"},"status":{"type":"string","required":false,"visibility":"user-or-llm","description":"Filter by status (completed, in-progress, failed)"},"direction":{"type":"string","required":false,"visibility":"user-or-llm","description":"Filter by direction (inbound, outbound)"},"type":{"type":"string","required":false,"visibility":"user-or-llm","description":"Filter by call type (pstn, web)"},"search":{"type":"string","required":false,"visibility":"user-or-llm","description":"Search by phone number (matches fromNumber or toNumber)"}},"hostedApiKey":"none"},"agentphone_list_contacts":{"id":"agentphone_list_contacts","name":"List Contacts","description":"List contacts for this AgentPhone account","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentPhone API key"},"search":{"type":"string","required":false,"visibility":"user-or-llm","description":"Filter by name or phone number (case-insensitive contains)"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of results to return (default 50, max 200)"},"offset":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of results to skip (min 0)"}},"hostedApiKey":"none"},"agentphone_list_conversations":{"id":"agentphone_list_conversations","name":"List Conversations","description":"List conversations (message threads) for this AgentPhone account","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentPhone API key"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of results to return (default 20, max 100)"},"offset":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of results to skip (min 0)"}},"hostedApiKey":"none"},"agentphone_list_numbers":{"id":"agentphone_list_numbers","name":"List Phone Numbers","description":"List all phone numbers provisioned for this AgentPhone account","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentPhone API key"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of results to return (default 20, max 100)"},"offset":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of results to skip (min 0)"}},"hostedApiKey":"none"},"agentphone_react_to_message":{"id":"agentphone_react_to_message","name":"React to Message","description":"Send an iMessage tapback reaction to a message (iMessage only)","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentPhone API key"},"messageId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the message to react to"},"reaction":{"type":"string","required":true,"visibility":"user-or-llm","description":"Reaction type: love, like, dislike, laugh, emphasize, or question"}},"hostedApiKey":"none"},"agentphone_release_number":{"id":"agentphone_release_number","name":"Release Phone Number","description":"Release (delete) a phone number. This action is irreversible.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentPhone API key"},"numberId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the phone number to release"}},"hostedApiKey":"none"},"agentphone_send_message":{"id":"agentphone_send_message","name":"Send Message","description":"Send an outbound SMS or iMessage from an AgentPhone agent","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentPhone API key"},"agentId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Agent sending the message"},"toNumber":{"type":"string","required":true,"visibility":"user-or-llm","description":"Recipient phone number in E.164 format (e.g. +14155551234)"},"body":{"type":"string","required":true,"visibility":"user-or-llm","description":"Message text to send"},"mediaUrl":{"type":"string","required":false,"visibility":"user-or-llm","description":"Optional URL of an image, video, or file to attach"},"numberId":{"type":"string","required":false,"visibility":"user-or-llm","description":"Phone number ID to send from. If omitted, the agent\'s first assigned number is used."}},"hostedApiKey":"none"},"agentphone_update_contact":{"id":"agentphone_update_contact","name":"Update Contact","description":"Update a contact\'s fields","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentPhone API key"},"contactId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Contact ID"},"phoneNumber":{"type":"string","required":false,"visibility":"user-or-llm","description":"New phone number in E.164 format"},"name":{"type":"string","required":false,"visibility":"user-or-llm","description":"New contact name"},"email":{"type":"string","required":false,"visibility":"user-or-llm","description":"New email address"},"notes":{"type":"string","required":false,"visibility":"user-or-llm","description":"New freeform notes"}},"hostedApiKey":"none"},"agentphone_update_conversation":{"id":"agentphone_update_conversation","name":"Update Conversation","description":"Update conversation metadata (stored state). Pass null to clear existing metadata.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"AgentPhone API key"},"conversationId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Conversation ID"},"metadata":{"type":"json","required":false,"visibility":"user-or-llm","description":"Custom key-value metadata to store on the conversation. Pass null to clear existing metadata."}},"hostedApiKey":"none"},"agiloft_async_status":{"id":"agiloft_async_status","name":"Agiloft Async Status","description":"Check whether an asynchronous Agiloft call, such as a run action button, has completed.","version":"1.0.0","params":{"instanceUrl":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft instance URL (e.g., https://mycompany.agiloft.com)"},"knowledgeBase":{"type":"string","required":true,"visibility":"user-only","description":"Knowledge base name"},"login":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft username"},"password":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft password"},"table":{"type":"string","required":true,"visibility":"user-or-llm","description":"Table the asynchronous call was made against"},"callbackId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Callback ID returned by the asynchronous call, e.g. from Run Action Button"}},"hostedApiKey":"none"},"agiloft_attach_file":{"id":"agiloft_attach_file","name":"Agiloft Attach File","description":"Attach a file to a field in an Agiloft record.","version":"1.0.0","params":{"instanceUrl":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft instance URL (e.g., https://mycompany.agiloft.com)"},"knowledgeBase":{"type":"string","required":true,"visibility":"user-only","description":"Knowledge base name"},"login":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft username"},"password":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft password"},"table":{"type":"string","required":true,"visibility":"user-or-llm","description":"Table name (e.g., \\"contracts\\")"},"recordId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the record to attach the file to"},"fieldName":{"type":"string","required":true,"visibility":"user-or-llm","description":"Name of the attachment field"},"file":{"type":"file","required":true,"visibility":"user-or-llm","description":"File to attach"},"fileName":{"type":"string","required":false,"visibility":"user-or-llm","description":"Name to assign to the file (defaults to original file name)"},"overwrite":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Replace the contents of the field instead of adding another file to it"}},"hostedApiKey":"none"},"agiloft_attachment_info":{"id":"agiloft_attachment_info","name":"Agiloft Attachment Info","description":"Get information about file attachments on a record field.","version":"1.0.0","params":{"instanceUrl":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft instance URL (e.g., https://mycompany.agiloft.com)"},"knowledgeBase":{"type":"string","required":true,"visibility":"user-only","description":"Knowledge base name"},"login":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft username"},"password":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft password"},"table":{"type":"string","required":true,"visibility":"user-or-llm","description":"Table name (e.g., \\"contracts\\")"},"recordId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the record to check attachments on"},"fieldName":{"type":"string","required":true,"visibility":"user-or-llm","description":"Name of the attachment field to inspect"}},"hostedApiKey":"none"},"agiloft_create_record":{"id":"agiloft_create_record","name":"Agiloft Create Record","description":"Create a new record in an Agiloft table.","version":"1.0.0","params":{"instanceUrl":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft instance URL (e.g., https://mycompany.agiloft.com)"},"knowledgeBase":{"type":"string","required":true,"visibility":"user-only","description":"Knowledge base name"},"login":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft username"},"password":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft password"},"table":{"type":"string","required":true,"visibility":"user-or-llm","description":"Table name (e.g., \\"contracts\\", \\"contacts.employees\\")"},"data":{"type":"string","required":true,"visibility":"user-or-llm","description":"Record field values as a JSON object (e.g., {\\"first_name\\": \\"John\\", \\"status\\": \\"Active\\"})"}},"hostedApiKey":"none"},"agiloft_delete_record":{"id":"agiloft_delete_record","name":"Agiloft Delete Record","description":"Delete a record from an Agiloft table.","version":"1.0.0","params":{"instanceUrl":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft instance URL (e.g., https://mycompany.agiloft.com)"},"knowledgeBase":{"type":"string","required":true,"visibility":"user-only","description":"Knowledge base name"},"login":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft username"},"password":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft password"},"table":{"type":"string","required":true,"visibility":"user-or-llm","description":"Table name (e.g., \\"contracts\\", \\"contacts.employees\\")"},"recordId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the record to delete"},"substituteIds":{"type":"string","required":false,"visibility":"user-or-llm","description":"Comma-separated IDs of records that adopt the dependants of the deleted record. Read only when the delete rule is REPLACE_WITH_ANOTHER."},"deleteRule":{"type":"string","required":false,"visibility":"user-or-llm","description":"How to treat records that depend on this one: ERROR_IF_DEPENDANTS (default — fails rather than cascading), APPLY_DELETE_WHERE_POSSIBLE, DELETE_WHERE_POSSIBLE_OTHERWISE_UNLINK, APPLY_UNLINK, UNLINK_WHERE_POSSIBLE_OTHERWISE_DELETE, or REPLACE_WITH_ANOTHER"}},"hostedApiKey":"none"},"agiloft_get_choice_line_id":{"id":"agiloft_get_choice_line_id","name":"Agiloft Get Choice Line ID","description":"Resolve the internal numeric ID of a choice-list value, for use in EWSelect WHERE clauses against choice fields.","version":"1.0.0","params":{"instanceUrl":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft instance URL (e.g., https://mycompany.agiloft.com)"},"knowledgeBase":{"type":"string","required":true,"visibility":"user-only","description":"Knowledge base name"},"login":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft username"},"password":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft password"},"table":{"type":"string","required":true,"visibility":"user-or-llm","description":"Table name (e.g., \\"case\\", \\"contracts\\")"},"fieldName":{"type":"string","required":true,"visibility":"user-or-llm","description":"Choice field name (e.g., \\"priority\\", \\"status\\")"},"value":{"type":"string","required":true,"visibility":"user-or-llm","description":"Choice display value to resolve (e.g., \\"High\\", \\"Active\\")"}},"hostedApiKey":"none"},"agiloft_list_tables":{"id":"agiloft_list_tables","name":"Agiloft List Tables","description":"List the tables and fields in an Agiloft knowledge base, to discover the logical names other operations need.","version":"1.0.0","params":{"instanceUrl":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft instance URL (e.g., https://mycompany.agiloft.com)"},"knowledgeBase":{"type":"string","required":true,"visibility":"user-only","description":"Knowledge base name"},"login":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft username"},"password":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft password"},"table":{"type":"string","required":false,"visibility":"user-or-llm","description":"Logical name of a single table to describe (e.g., \\"contacts\\"). Leave empty to list every table in the knowledge base."},"includeLinkedInfo":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Include the source table and column behind each linked field"},"skipColumnsInfo":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Return table names only, omitting field details, for a much smaller response"}},"hostedApiKey":"none"},"agiloft_lock_record":{"id":"agiloft_lock_record","name":"Agiloft Lock Record","description":"Lock, unlock, or check the lock status of an Agiloft record.","version":"1.0.0","params":{"instanceUrl":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft instance URL (e.g., https://mycompany.agiloft.com)"},"knowledgeBase":{"type":"string","required":true,"visibility":"user-only","description":"Knowledge base name"},"login":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft username"},"password":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft password"},"table":{"type":"string","required":true,"visibility":"user-or-llm","description":"Table name (e.g., \\"contracts\\")"},"recordId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the record to lock, unlock, or check"},"lockAction":{"type":"string","required":true,"visibility":"user-or-llm","description":"Action to perform: \\"lock\\", \\"unlock\\", or \\"check\\""},"force":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Unlock only: release a lock held by another user."}},"hostedApiKey":"none"},"agiloft_nlp_search":{"id":"agiloft_nlp_search","name":"Agiloft Natural Language Search","description":"Search Agiloft records by describing what you want in plain language, such as \\"active NDAs submitted last month\\".","version":"1.0.0","params":{"instanceUrl":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft instance URL (e.g., https://mycompany.agiloft.com)"},"knowledgeBase":{"type":"string","required":true,"visibility":"user-only","description":"Knowledge base name"},"login":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft username"},"password":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft password"},"nlpQuery":{"type":"string","required":true,"visibility":"user-or-llm","description":"The request in plain language, e.g. \\"Show me open, high-priority contracts\\". Structured field filters are not accepted — use Search Records for those."},"fields":{"type":"string","required":true,"visibility":"user-or-llm","description":"Comma-separated field names to return, e.g. \\"id, contract_title1, company_name\\""},"page":{"type":"string","required":false,"visibility":"user-or-llm","description":"Page number, starting from 0"},"limit":{"type":"string","required":false,"visibility":"user-or-llm","description":"Records per page"}},"hostedApiKey":"none"},"agiloft_read_record":{"id":"agiloft_read_record","name":"Agiloft Read Record","description":"Read a record by ID from an Agiloft table.","version":"1.0.0","params":{"instanceUrl":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft instance URL (e.g., https://mycompany.agiloft.com)"},"knowledgeBase":{"type":"string","required":true,"visibility":"user-only","description":"Knowledge base name"},"login":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft username"},"password":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft password"},"table":{"type":"string","required":true,"visibility":"user-or-llm","description":"Table name (e.g., \\"contracts\\", \\"contacts.employees\\")"},"recordId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the record to read"},"fields":{"type":"string","required":false,"visibility":"user-or-llm","description":"Comma-separated list of field names to include in the response"}},"hostedApiKey":"none"},"agiloft_remove_attachment":{"id":"agiloft_remove_attachment","name":"Agiloft Remove Attachment","description":"Remove an attached file from a field in an Agiloft record.","version":"1.0.0","params":{"instanceUrl":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft instance URL (e.g., https://mycompany.agiloft.com)"},"knowledgeBase":{"type":"string","required":true,"visibility":"user-only","description":"Knowledge base name"},"login":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft username"},"password":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft password"},"table":{"type":"string","required":true,"visibility":"user-or-llm","description":"Table name (e.g., \\"contracts\\")"},"recordId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the record containing the attachment"},"fieldName":{"type":"string","required":true,"visibility":"user-or-llm","description":"Name of the attachment field"},"position":{"type":"string","required":true,"visibility":"user-or-llm","description":"Position index of the file to remove (starting from 0)"}},"hostedApiKey":"none"},"agiloft_retrieve_attachment":{"id":"agiloft_retrieve_attachment","name":"Agiloft Retrieve Attachment","description":"Download an attached file from an Agiloft record field.","version":"1.0.0","params":{"instanceUrl":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft instance URL (e.g., https://mycompany.agiloft.com)"},"knowledgeBase":{"type":"string","required":true,"visibility":"user-only","description":"Knowledge base name"},"login":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft username"},"password":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft password"},"table":{"type":"string","required":true,"visibility":"user-or-llm","description":"Table name (e.g., \\"contracts\\")"},"recordId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the record containing the attachment"},"fieldName":{"type":"string","required":true,"visibility":"user-or-llm","description":"Name of the attachment field"},"position":{"type":"string","required":true,"visibility":"user-or-llm","description":"Position index of the file in the field (starting from 0)"}},"hostedApiKey":"none"},"agiloft_run_action_button":{"id":"agiloft_run_action_button","name":"Agiloft Run Action Button","description":"Run an action button on an Agiloft record, such as an approval or send-for-signature step.","version":"1.0.0","params":{"instanceUrl":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft instance URL (e.g., https://mycompany.agiloft.com)"},"knowledgeBase":{"type":"string","required":true,"visibility":"user-only","description":"Knowledge base name"},"login":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft username"},"password":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft password"},"table":{"type":"string","required":true,"visibility":"user-or-llm","description":"Table name (e.g., \\"contracts\\", \\"case\\")"},"recordId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the record to run the action button on"},"actionButtonField":{"type":"string","required":true,"visibility":"user-or-llm","description":"Logical name of the field holding the action button (e.g., \\"ab_field\\")"}},"hostedApiKey":"none"},"agiloft_saved_search":{"id":"agiloft_saved_search","name":"Agiloft Saved Search","description":"List the saved searches defined for an Agiloft table.","version":"1.0.0","params":{"instanceUrl":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft instance URL (e.g., https://mycompany.agiloft.com)"},"knowledgeBase":{"type":"string","required":true,"visibility":"user-only","description":"Knowledge base name"},"login":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft username"},"password":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft password"},"table":{"type":"string","required":true,"visibility":"user-or-llm","description":"Logical table name to list saved searches for (e.g., \\"contract\\")"}},"hostedApiKey":"none"},"agiloft_search_records":{"id":"agiloft_search_records","name":"Agiloft Search Records","description":"Search for records in an Agiloft table using a query.","version":"1.0.0","params":{"instanceUrl":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft instance URL (e.g., https://mycompany.agiloft.com)"},"knowledgeBase":{"type":"string","required":true,"visibility":"user-only","description":"Knowledge base name"},"login":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft username"},"password":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft password"},"table":{"type":"string","required":true,"visibility":"user-or-llm","description":"Table name to search in (e.g., \\"contracts\\", \\"contacts.employees\\")"},"query":{"type":"string","required":false,"visibility":"user-or-llm","description":"Ad hoc EWSearch query. Combine conditions with && (and) or || (or) and quote every value — e.g. \\"summary~=\'test\'&&priority=\'High\'\\". Required unless a saved search is given."},"search":{"type":"string","required":false,"visibility":"user-or-llm","description":"Label of a saved search defined on the table (e.g., \\"C: Status is Closed\\"). Can be combined with a query to narrow it further."},"fields":{"type":"string","required":false,"visibility":"user-or-llm","description":"Comma-separated list of field names to include in the results"},"page":{"type":"string","required":false,"visibility":"user-or-llm","description":"Page number for paginated results (starting from 0)"},"limit":{"type":"string","required":false,"visibility":"user-or-llm","description":"Maximum number of records to return per page. Agiloft treats 0 as \\"all records\\", so leave it unset or use a positive value to keep result sizes bounded."}},"hostedApiKey":"none"},"agiloft_select_records":{"id":"agiloft_select_records","name":"Agiloft Select Records","description":"Select record IDs matching a SQL WHERE clause from an Agiloft table.","version":"1.0.0","params":{"instanceUrl":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft instance URL (e.g., https://mycompany.agiloft.com)"},"knowledgeBase":{"type":"string","required":true,"visibility":"user-only","description":"Knowledge base name"},"login":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft username"},"password":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft password"},"table":{"type":"string","required":true,"visibility":"user-or-llm","description":"Table name (e.g., \\"contracts\\", \\"contacts.employees\\")"},"where":{"type":"string","required":true,"visibility":"user-or-llm","description":"SQL WHERE clause using database column names (e.g., \\"summary like \'%new%\'\\" or \\"assigned_person=\'John Doe\'\\"). EWSelect has no page size and returns every matching ID, so append a database limit such as \\"limit 0,200\\" to bound the result."}},"hostedApiKey":"none"},"agiloft_update_record":{"id":"agiloft_update_record","name":"Agiloft Update Record","description":"Update an existing record in an Agiloft table.","version":"1.0.0","params":{"instanceUrl":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft instance URL (e.g., https://mycompany.agiloft.com)"},"knowledgeBase":{"type":"string","required":true,"visibility":"user-only","description":"Knowledge base name"},"login":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft username"},"password":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft password"},"table":{"type":"string","required":true,"visibility":"user-or-llm","description":"Table name (e.g., \\"contracts\\", \\"contacts.employees\\")"},"recordId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the record to update"},"data":{"type":"string","required":true,"visibility":"user-or-llm","description":"Updated field values as a JSON object (e.g., {\\"status\\": \\"Active\\", \\"priority\\": \\"High\\"})"}},"hostedApiKey":"none"},"agiloft_upsert_record":{"id":"agiloft_upsert_record","name":"Agiloft Upsert Record","description":"Create an Agiloft record, or update it when a record already matches the given fields.","version":"1.0.0","params":{"instanceUrl":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft instance URL (e.g., https://mycompany.agiloft.com)"},"knowledgeBase":{"type":"string","required":true,"visibility":"user-only","description":"Knowledge base name"},"login":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft username"},"password":{"type":"string","required":true,"visibility":"user-only","description":"Agiloft password"},"table":{"type":"string","required":true,"visibility":"user-or-llm","description":"Table name (e.g., \\"contracts\\", \\"contacts.employees\\")"},"match":{"type":"string","required":true,"visibility":"user-or-llm","description":"Field used to find an existing record (e.g., \\"ext_id\\"). Pick something that identifies a record uniquely — if more than one record matches, Agiloft writes nothing and returns a conflict."},"async":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Queue the write instead of waiting for it. Returns a callback ID instead of a record ID; pass that to Async Status to poll the result."},"data":{"type":"string","required":true,"visibility":"user-or-llm","description":"Field values as a JSON object. On create these populate the new record; on update only the supplied fields change."}},"hostedApiKey":"none"},"ahrefs_anchors":{"id":"ahrefs_anchors","name":"Ahrefs Anchors","description":"Get the anchor text distribution for a target domain or URL\'s backlinks, showing how many links and referring domains use each anchor text.","version":"1.0.0","params":{"target":{"type":"string","required":true,"visibility":"user-or-llm","description":"The target domain or URL to analyze. Example: \\"example.com\\" or \\"https://example.com/page\\""},"mode":{"type":"string","required":false,"visibility":"user-or-llm","description":"Analysis mode: domain (entire domain), prefix (URL prefix), subdomains (include all subdomains, default), exact (exact URL match)"},"history":{"type":"string","required":false,"visibility":"user-or-llm","description":"Historical scope: \\"live\\" (currently live), \\"all_time\\" (default, includes lost backlinks), or \\"since:YYYY-MM-DD\\" (backlinks found since a date)"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Maximum number of results to return. Example: 50 (default: 1000)"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Ahrefs API Key"}},"hostedApiKey":"none"},"ahrefs_backlinks":{"id":"ahrefs_backlinks","name":"Ahrefs Backlinks","description":"Get a list of backlinks pointing to a target domain or URL. Returns details about each backlink including source URL, anchor text, and domain rating.","version":"1.0.0","params":{"target":{"type":"string","required":true,"visibility":"user-or-llm","description":"The target domain or URL to analyze. Example: \\"example.com\\" or \\"https://example.com/page\\""},"mode":{"type":"string","required":false,"visibility":"user-or-llm","description":"Analysis mode: domain (entire domain), prefix (URL prefix), subdomains (include all subdomains, default), exact (exact URL match). Example: \\"domain\\""},"history":{"type":"string","required":false,"visibility":"user-or-llm","description":"Historical scope: \\"live\\" (currently live backlinks), \\"all_time\\" (default, includes lost backlinks), or \\"since:YYYY-MM-DD\\" (backlinks found since a date)."},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Maximum number of results to return. Example: 50 (default: 1000)"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Ahrefs API Key"}},"hostedApiKey":"none"},"ahrefs_backlinks_stats":{"id":"ahrefs_backlinks_stats","name":"Ahrefs Backlinks Stats","description":"Get backlink and referring domain totals for a target domain or URL, both currently live and across all time.","version":"1.0.0","params":{"target":{"type":"string","required":true,"visibility":"user-or-llm","description":"The target domain or URL to analyze. Example: \\"example.com\\" or \\"https://example.com/page\\""},"mode":{"type":"string","required":false,"visibility":"user-or-llm","description":"Analysis mode: domain (entire domain), prefix (URL prefix), subdomains (include all subdomains, default), exact (exact URL match). Example: \\"domain\\""},"date":{"type":"string","required":false,"visibility":"user-only","description":"Date to report metrics on, in YYYY-MM-DD format (defaults to today)"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Ahrefs API Key"}},"hostedApiKey":"none"},"ahrefs_batch_analysis":{"id":"ahrefs_batch_analysis","name":"Ahrefs Batch Analysis","description":"Get bulk SEO metrics (Domain Rating, backlinks, referring domains, organic traffic, and more) for multiple domains or URLs in a single request. Useful for comparing many competitors at once.","version":"1.0.0","params":{"targets":{"type":"string","required":true,"visibility":"user-or-llm","description":"Comma-separated list of domains or URLs to analyze. Example: \\"example.com,competitor.com\\""},"mode":{"type":"string","required":false,"visibility":"user-or-llm","description":"Analysis mode applied to every target: domain (entire domain), prefix (URL prefix), subdomains (include all subdomains, default), exact (exact URL match)"},"protocol":{"type":"string","required":false,"visibility":"user-or-llm","description":"Protocol applied to every target: \\"both\\" (default), \\"http\\", or \\"https\\""},"country":{"type":"string","required":false,"visibility":"user-or-llm","description":"Country code for traffic data. Example: \\"us\\", \\"gb\\", \\"de\\" (default: \\"us\\")"},"volumeMode":{"type":"string","required":false,"visibility":"user-or-llm","description":"Search volume calculation: \\"monthly\\" or \\"average\\" (default: \\"monthly\\")"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Ahrefs API Key"}},"hostedApiKey":"none"},"ahrefs_broken_backlinks":{"id":"ahrefs_broken_backlinks","name":"Ahrefs Broken Backlinks","description":"Get a list of broken backlinks pointing to a target domain or URL. Useful for identifying link reclamation opportunities.","version":"1.0.0","params":{"target":{"type":"string","required":true,"visibility":"user-or-llm","description":"The target domain or URL to analyze. Example: \\"example.com\\" or \\"https://example.com/page\\""},"mode":{"type":"string","required":false,"visibility":"user-or-llm","description":"Analysis mode: domain (entire domain), prefix (URL prefix), subdomains (include all subdomains, default), exact (exact URL match). Example: \\"domain\\""},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Maximum number of results to return. Example: 50 (default: 1000)"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Ahrefs API Key"}},"hostedApiKey":"none"},"ahrefs_domain_rating":{"id":"ahrefs_domain_rating","name":"Ahrefs Domain Rating","description":"Get the Domain Rating (DR) and Ahrefs Rank for a target domain. Domain Rating shows the strength of a website\'s backlink profile on a scale from 0 to 100.","version":"1.0.0","params":{"target":{"type":"string","required":true,"visibility":"user-or-llm","description":"The target domain to analyze (e.g., example.com)"},"date":{"type":"string","required":false,"visibility":"user-only","description":"Date for historical data in YYYY-MM-DD format (defaults to today)"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Ahrefs API Key"}},"hostedApiKey":"none"},"ahrefs_domain_rating_history":{"id":"ahrefs_domain_rating_history","name":"Ahrefs Domain Rating History","description":"Get the historical Domain Rating (DR) trend for a target domain or URL over a date range, grouped daily, weekly, or monthly.","version":"1.0.0","params":{"target":{"type":"string","required":true,"visibility":"user-or-llm","description":"The target domain or URL to analyze. Example: \\"example.com\\""},"dateFrom":{"type":"string","required":true,"visibility":"user-only","description":"Start date of the historical period, in YYYY-MM-DD format"},"dateTo":{"type":"string","required":false,"visibility":"user-only","description":"End date of the historical period, in YYYY-MM-DD format (defaults to today)"},"historyGrouping":{"type":"string","required":false,"visibility":"user-or-llm","description":"Time interval for grouping data points: \\"daily\\", \\"weekly\\", or \\"monthly\\" (default: \\"monthly\\")"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Ahrefs API Key"}},"hostedApiKey":"none"},"ahrefs_keyword_overview":{"id":"ahrefs_keyword_overview","name":"Ahrefs Keyword Overview","description":"Get detailed metrics for a keyword including search volume, keyword difficulty, CPC, clicks, and traffic potential.","version":"1.0.0","params":{"keyword":{"type":"string","required":true,"visibility":"user-or-llm","description":"The keyword to analyze"},"country":{"type":"string","required":false,"visibility":"user-or-llm","description":"Country code for keyword data. Example: \\"us\\", \\"gb\\", \\"de\\" (default: \\"us\\")"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Ahrefs API Key"}},"hostedApiKey":"none"},"ahrefs_keywords_history":{"id":"ahrefs_keywords_history","name":"Ahrefs Keywords History","description":"Get the historical organic keyword ranking distribution for a target domain or URL over a date range: how many keywords rank in each position bucket at each point in time.","version":"1.0.0","params":{"target":{"type":"string","required":true,"visibility":"user-or-llm","description":"The target domain or URL to analyze. Example: \\"example.com\\""},"dateFrom":{"type":"string","required":true,"visibility":"user-only","description":"Start date of the historical period, in YYYY-MM-DD format"},"dateTo":{"type":"string","required":false,"visibility":"user-only","description":"End date of the historical period, in YYYY-MM-DD format (defaults to today)"},"historyGrouping":{"type":"string","required":false,"visibility":"user-or-llm","description":"Time interval for grouping data points: \\"daily\\", \\"weekly\\", or \\"monthly\\" (default: \\"monthly\\")"},"country":{"type":"string","required":false,"visibility":"user-or-llm","description":"Country code for search results. Example: \\"us\\", \\"gb\\", \\"de\\" (default: \\"us\\")"},"mode":{"type":"string","required":false,"visibility":"user-or-llm","description":"Analysis mode: domain (entire domain), prefix (URL prefix), subdomains (include all subdomains, default), exact (exact URL match)"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Ahrefs API Key"}},"hostedApiKey":"none"},"ahrefs_metrics":{"id":"ahrefs_metrics","name":"Ahrefs Metrics","description":"Get a one-call organic and paid search overview for a target domain or URL: organic traffic, organic keywords, paid traffic, paid keywords, and estimated traffic cost.","version":"1.0.0","params":{"target":{"type":"string","required":true,"visibility":"user-or-llm","description":"The target domain or URL to analyze. Example: \\"example.com\\""},"country":{"type":"string","required":false,"visibility":"user-or-llm","description":"Country code for traffic data. Example: \\"us\\", \\"gb\\", \\"de\\""},"mode":{"type":"string","required":false,"visibility":"user-or-llm","description":"Analysis mode: domain (entire domain), prefix (URL prefix), subdomains (include all subdomains, default), exact (exact URL match). Example: \\"domain\\""},"date":{"type":"string","required":false,"visibility":"user-only","description":"Date to report metrics on, in YYYY-MM-DD format (defaults to today)"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Ahrefs API Key"}},"hostedApiKey":"none"},"ahrefs_metrics_history":{"id":"ahrefs_metrics_history","name":"Ahrefs Metrics History","description":"Get the historical organic and paid traffic trend for a target domain or URL over a date range: organic traffic/cost and paid traffic/cost at each point in time.","version":"1.0.0","params":{"target":{"type":"string","required":true,"visibility":"user-or-llm","description":"The target domain or URL to analyze. Example: \\"example.com\\""},"dateFrom":{"type":"string","required":true,"visibility":"user-only","description":"Start date of the historical period, in YYYY-MM-DD format"},"dateTo":{"type":"string","required":false,"visibility":"user-only","description":"End date of the historical period, in YYYY-MM-DD format (defaults to today)"},"volumeMode":{"type":"string","required":false,"visibility":"user-or-llm","description":"Search volume calculation: \\"monthly\\" or \\"average\\" (default: \\"monthly\\")"},"historyGrouping":{"type":"string","required":false,"visibility":"user-or-llm","description":"Time interval for grouping data points: \\"daily\\", \\"weekly\\", or \\"monthly\\" (default: \\"monthly\\")"},"country":{"type":"string","required":false,"visibility":"user-or-llm","description":"Country code for traffic data. Example: \\"us\\", \\"gb\\", \\"de\\" (default: \\"us\\")"},"mode":{"type":"string","required":false,"visibility":"user-or-llm","description":"Analysis mode: domain (entire domain), prefix (URL prefix), subdomains (include all subdomains, default), exact (exact URL match)"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Ahrefs API Key"}},"hostedApiKey":"none"},"ahrefs_organic_competitors":{"id":"ahrefs_organic_competitors","name":"Ahrefs Organic Competitors","description":"Get domains that compete with a target domain or URL for the same organic keywords, ranked by keyword overlap.","version":"1.0.0","params":{"target":{"type":"string","required":true,"visibility":"user-or-llm","description":"The target domain or URL to analyze. Example: \\"example.com\\""},"country":{"type":"string","required":false,"visibility":"user-or-llm","description":"Country code for search results. Example: \\"us\\", \\"gb\\", \\"de\\" (default: \\"us\\")"},"mode":{"type":"string","required":false,"visibility":"user-or-llm","description":"Analysis mode: domain (entire domain), prefix (URL prefix), subdomains (include all subdomains, default), exact (exact URL match). Example: \\"domain\\""},"date":{"type":"string","required":false,"visibility":"user-only","description":"Date to report metrics on, in YYYY-MM-DD format (defaults to today)"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Maximum number of results to return. Example: 50 (default: 1000)"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Ahrefs API Key"}},"hostedApiKey":"none"},"ahrefs_organic_keywords":{"id":"ahrefs_organic_keywords","name":"Ahrefs Organic Keywords","description":"Get organic keywords that a target domain or URL ranks for in Google search results. Returns keyword details including search volume, ranking position, and estimated traffic.","version":"1.0.0","params":{"target":{"type":"string","required":true,"visibility":"user-or-llm","description":"The target domain or URL to analyze. Example: \\"example.com\\" or \\"https://example.com/page\\""},"country":{"type":"string","required":false,"visibility":"user-or-llm","description":"Country code for search results. Example: \\"us\\", \\"gb\\", \\"de\\" (default: \\"us\\")"},"mode":{"type":"string","required":false,"visibility":"user-or-llm","description":"Analysis mode: domain (entire domain), prefix (URL prefix), subdomains (include all subdomains, default), exact (exact URL match). Example: \\"domain\\""},"date":{"type":"string","required":false,"visibility":"user-only","description":"Date to report metrics on, in YYYY-MM-DD format (defaults to today)"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Maximum number of results to return. Example: 50 (default: 1000)"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Ahrefs API Key"}},"hostedApiKey":"none"},"ahrefs_paid_pages":{"id":"ahrefs_paid_pages","name":"Ahrefs Paid Pages","description":"Get a target domain\'s pages that receive paid search traffic, sorted by estimated paid traffic. Returns page URLs with their paid traffic, keyword counts, and estimated spend.","version":"1.0.0","params":{"target":{"type":"string","required":true,"visibility":"user-or-llm","description":"The target domain or URL to analyze. Example: \\"example.com\\""},"country":{"type":"string","required":false,"visibility":"user-or-llm","description":"Country code for traffic data. Example: \\"us\\", \\"gb\\", \\"de\\" (default: \\"us\\")"},"mode":{"type":"string","required":false,"visibility":"user-or-llm","description":"Analysis mode: domain (entire domain), prefix (URL prefix), subdomains (include all subdomains, default), exact (exact URL match)"},"date":{"type":"string","required":false,"visibility":"user-only","description":"Date to report metrics on, in YYYY-MM-DD format (defaults to today)"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Maximum number of results to return. Example: 50 (default: 1000)"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Ahrefs API Key"}},"hostedApiKey":"none"},"ahrefs_rank_tracker_competitors_overview":{"id":"ahrefs_rank_tracker_competitors_overview","name":"Ahrefs Rank Tracker Competitors Overview","description":"Get competitor rankings for the keywords tracked in an Ahrefs Rank Tracker project: each tracked keyword\'s volume and difficulty alongside every competitor\'s position, traffic, and traffic value. This endpoint is free and does not consume API units.","version":"1.0.0","params":{"projectId":{"type":"number","required":true,"visibility":"user-or-llm","description":"The Rank Tracker project ID (found in the project URL in Ahrefs)"},"date":{"type":"string","required":true,"visibility":"user-only","description":"Date to report rankings for, in YYYY-MM-DD format"},"device":{"type":"string","required":true,"visibility":"user-or-llm","description":"Rankings device type: \\"desktop\\" or \\"mobile\\""},"dateCompared":{"type":"string","required":false,"visibility":"user-only","description":"Comparison date in YYYY-MM-DD format, to compute position/traffic deltas"},"volumeMode":{"type":"string","required":false,"visibility":"user-or-llm","description":"Search volume calculation: \\"monthly\\" or \\"average\\" (default: \\"monthly\\")"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Maximum number of results to return. Example: 50 (default: 1000)"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Ahrefs API Key"}},"hostedApiKey":"none"},"ahrefs_rank_tracker_competitors_stats":{"id":"ahrefs_rank_tracker_competitors_stats","name":"Ahrefs Rank Tracker Competitors Stats","description":"Get aggregate competitor stats for an Ahrefs Rank Tracker project: each competitor\'s traffic, traffic value, average position, and share of voice across all tracked keywords. This endpoint is free and does not consume API units.","version":"1.0.0","params":{"projectId":{"type":"number","required":true,"visibility":"user-or-llm","description":"The Rank Tracker project ID (found in the project URL in Ahrefs)"},"date":{"type":"string","required":true,"visibility":"user-only","description":"Date to report metrics for, in YYYY-MM-DD format"},"device":{"type":"string","required":true,"visibility":"user-or-llm","description":"Rankings device type: \\"desktop\\" or \\"mobile\\""},"volumeMode":{"type":"string","required":false,"visibility":"user-or-llm","description":"Search volume calculation: \\"monthly\\" or \\"average\\" (default: \\"monthly\\")"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Ahrefs API Key"}},"hostedApiKey":"none"},"ahrefs_rank_tracker_overview":{"id":"ahrefs_rank_tracker_overview","name":"Ahrefs Rank Tracker Overview","description":"Get ranking overview metrics for the keywords tracked in an Ahrefs Rank Tracker project: position, search volume, keyword difficulty, and estimated traffic. This endpoint is free and does not consume API units.","version":"1.0.0","params":{"projectId":{"type":"number","required":true,"visibility":"user-or-llm","description":"The Rank Tracker project ID (found in the project URL in Ahrefs)"},"date":{"type":"string","required":true,"visibility":"user-only","description":"Date to report rankings for, in YYYY-MM-DD format"},"device":{"type":"string","required":true,"visibility":"user-or-llm","description":"Rankings device type: \\"desktop\\" or \\"mobile\\""},"dateCompared":{"type":"string","required":false,"visibility":"user-only","description":"Comparison date in YYYY-MM-DD format, to compute position/traffic deltas"},"volumeMode":{"type":"string","required":false,"visibility":"user-or-llm","description":"Search volume calculation: \\"monthly\\" or \\"average\\" (default: \\"monthly\\")"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Maximum number of results to return. Example: 50 (default: 1000)"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Ahrefs API Key"}},"hostedApiKey":"none"},"ahrefs_rank_tracker_serp_overview":{"id":"ahrefs_rank_tracker_serp_overview","name":"Ahrefs Rank Tracker SERP Overview","description":"Get the full SERP (search engine results page) for a keyword tracked in an Ahrefs Rank Tracker project, including every ranking URL with its position, title, and authority metrics. This endpoint is free and does not consume API units.","version":"1.0.0","params":{"projectId":{"type":"number","required":true,"visibility":"user-or-llm","description":"The Rank Tracker project ID (found in the project URL in Ahrefs)"},"keyword":{"type":"string","required":true,"visibility":"user-or-llm","description":"The tracked keyword to retrieve SERP data for"},"country":{"type":"string","required":true,"visibility":"user-or-llm","description":"Country code for the tracked keyword. Example: \\"us\\", \\"gb\\", \\"de\\""},"device":{"type":"string","required":true,"visibility":"user-or-llm","description":"Rankings device type: \\"desktop\\" or \\"mobile\\""},"topPositions":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of top organic positions to return (defaults to all available)"},"date":{"type":"string","required":false,"visibility":"user-only","description":"Timestamp to return the last available SERP Overview at, in YYYY-MM-DDThh:mm:ss format"},"locationId":{"type":"number","required":false,"visibility":"user-or-llm","description":"Location ID of the tracked keyword, if tracked at a specific location"},"languageCode":{"type":"string","required":false,"visibility":"user-or-llm","description":"Language code of the tracked keyword"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Ahrefs API Key"}},"hostedApiKey":"none"},"ahrefs_refdomains_history":{"id":"ahrefs_refdomains_history","name":"Ahrefs Referring Domains History","description":"Get the historical referring domains trend for a target domain or URL over a date range, grouped daily, weekly, or monthly.","version":"1.0.0","params":{"target":{"type":"string","required":true,"visibility":"user-or-llm","description":"The target domain or URL to analyze. Example: \\"example.com\\""},"dateFrom":{"type":"string","required":true,"visibility":"user-only","description":"Start date of the historical period, in YYYY-MM-DD format"},"dateTo":{"type":"string","required":false,"visibility":"user-only","description":"End date of the historical period, in YYYY-MM-DD format (defaults to today)"},"historyGrouping":{"type":"string","required":false,"visibility":"user-or-llm","description":"Time interval for grouping data points: \\"daily\\", \\"weekly\\", or \\"monthly\\" (default: \\"monthly\\")"},"mode":{"type":"string","required":false,"visibility":"user-or-llm","description":"Analysis mode: domain (entire domain), prefix (URL prefix), subdomains (include all subdomains, default), exact (exact URL match)"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Ahrefs API Key"}},"hostedApiKey":"none"},"ahrefs_referring_domains":{"id":"ahrefs_referring_domains","name":"Ahrefs Referring Domains","description":"Get a list of domains that link to a target domain or URL. Returns unique referring domains with their domain rating, backlink counts, and discovery dates.","version":"1.0.0","params":{"target":{"type":"string","required":true,"visibility":"user-or-llm","description":"The target domain or URL to analyze. Example: \\"example.com\\" or \\"https://example.com/page\\""},"mode":{"type":"string","required":false,"visibility":"user-or-llm","description":"Analysis mode: domain (entire domain), prefix (URL prefix), subdomains (include all subdomains, default), exact (exact URL match). Example: \\"domain\\""},"history":{"type":"string","required":false,"visibility":"user-or-llm","description":"Historical scope: \\"live\\" (currently live), \\"all_time\\" (default, includes lost domains), or \\"since:YYYY-MM-DD\\" (domains found since a date)."},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Maximum number of results to return. Example: 50 (default: 1000)"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Ahrefs API Key"}},"hostedApiKey":"none"},"ahrefs_related_terms":{"id":"ahrefs_related_terms","name":"Ahrefs Related Terms","description":"Get keyword ideas related to a seed keyword: terms the same top-ranking pages also rank for (\\"also rank for\\") or also discuss (\\"also talk about\\"), with volume, difficulty, and CPC.","version":"1.0.0","params":{"keyword":{"type":"string","required":true,"visibility":"user-or-llm","description":"The seed keyword to find related terms for"},"country":{"type":"string","required":false,"visibility":"user-or-llm","description":"Country code for keyword data. Example: \\"us\\", \\"gb\\", \\"de\\" (default: \\"us\\")"},"terms":{"type":"string","required":false,"visibility":"user-or-llm","description":"Type of related keywords to return: \\"also_rank_for\\", \\"also_talk_about\\", or \\"all\\" (default: \\"all\\")"},"viewFor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Whether to derive related terms from the top 10 or top 100 ranking pages (default: \\"top_10\\")"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Maximum number of results to return. Example: 50 (default: 1000)"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Ahrefs API Key"}},"hostedApiKey":"none"},"ahrefs_site_audit_page_explorer":{"id":"ahrefs_site_audit_page_explorer","name":"Ahrefs Site Audit Page Explorer","description":"Get crawled pages from an Ahrefs Site Audit project with health and SEO metrics: HTTP status, title, link counts, backlinks, indexability, and traffic. Optionally filter to pages affected by a specific issue.","version":"1.0.0","params":{"projectId":{"type":"number","required":true,"visibility":"user-or-llm","description":"The Site Audit project ID (found in the project URL in Ahrefs)"},"date":{"type":"string","required":false,"visibility":"user-only","description":"Crawl date in YYYY-MM-DDThh:mm:ss format (defaults to the most recent crawl)"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Maximum number of results to return. Example: 50 (default: 1000)"},"offset":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of results to skip, for pagination"},"issueId":{"type":"string","required":false,"visibility":"user-or-llm","description":"Only return pages affected by this issue ID"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Ahrefs API Key"}},"hostedApiKey":"none"},"ahrefs_top_pages":{"id":"ahrefs_top_pages","name":"Ahrefs Top Pages","description":"Get the top pages of a target domain sorted by organic traffic. Returns page URLs with their traffic, keyword counts, and estimated traffic value.","version":"1.0.0","params":{"target":{"type":"string","required":true,"visibility":"user-or-llm","description":"The target domain to analyze. Example: \\"example.com\\""},"country":{"type":"string","required":false,"visibility":"user-or-llm","description":"Country code for traffic data. Example: \\"us\\", \\"gb\\", \\"de\\" (default: \\"us\\")"},"mode":{"type":"string","required":false,"visibility":"user-or-llm","description":"Analysis mode: domain (entire domain), prefix (URL prefix), subdomains (include all subdomains, default), exact (exact URL match). Example: \\"domain\\""},"date":{"type":"string","required":false,"visibility":"user-only","description":"Date to report metrics on, in YYYY-MM-DD format (defaults to today)"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Maximum number of results to return. Example: 50 (default: 1000)"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Ahrefs API Key"}},"hostedApiKey":"none"},"airtable_create_records":{"id":"airtable_create_records","name":"Airtable Create Records","description":"Write new records to an Airtable table","version":"1.0.0","params":{"accessToken":{"type":"string","required":true,"visibility":"hidden","description":"OAuth access token"},"baseId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Airtable base ID (starts with \\"app\\", e.g., \\"appXXXXXXXXXXXXXX\\")"},"tableId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Table ID (starts with \\"tbl\\") or table name"},"records":{"type":"json","required":true,"visibility":"user-or-llm","description":"Array of records to create, each with a `fields` object"},"typecast":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"When true, Airtable automatically converts string values to the field type"}},"oauth":{"required":true,"provider":"airtable"},"hostedApiKey":"none"},"airtable_delete_records":{"id":"airtable_delete_records","name":"Airtable Delete Records","description":"Delete one or more records from an Airtable table by ID","version":"1.0.0","params":{"accessToken":{"type":"string","required":true,"visibility":"hidden","description":"OAuth access token"},"baseId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Airtable base ID (starts with \\"app\\", e.g., \\"appXXXXXXXXXXXXXX\\")"},"tableId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Table ID (starts with \\"tbl\\") or table name"},"recordIds":{"type":"json","required":true,"visibility":"user-or-llm","description":"Array of record IDs to delete (each starts with \\"rec\\", e.g., [\\"recXXXXXXXXXXXXXX\\"]). Pass a single-element array to delete one record."}},"oauth":{"required":true,"provider":"airtable"},"hostedApiKey":"none"},"airtable_get_base_schema":{"id":"airtable_get_base_schema","name":"Airtable Get Base Schema","description":"Get the schema of all tables, fields, and views in an Airtable base","version":"1.0.0","params":{"accessToken":{"type":"string","required":true,"visibility":"hidden","description":"OAuth access token"},"baseId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Airtable base ID (starts with \\"app\\", e.g., \\"appXXXXXXXXXXXXXX\\")"}},"oauth":{"required":true,"provider":"airtable"},"hostedApiKey":"none"},"airtable_get_record":{"id":"airtable_get_record","name":"Airtable Get Record","description":"Retrieve a single record from an Airtable table by its ID","version":"1.0.0","params":{"accessToken":{"type":"string","required":true,"visibility":"hidden","description":"OAuth access token"},"baseId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Airtable base ID (starts with \\"app\\", e.g., \\"appXXXXXXXXXXXXXX\\")"},"tableId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Table ID (starts with \\"tbl\\") or table name"},"recordId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Record ID to retrieve (starts with \\"rec\\", e.g., \\"recXXXXXXXXXXXXXX\\")"}},"oauth":{"required":true,"provider":"airtable"},"hostedApiKey":"none"},"airtable_list_bases":{"id":"airtable_list_bases","name":"Airtable List Bases","description":"List all bases the authenticated user has access to","version":"1.0.0","params":{"accessToken":{"type":"string","required":true,"visibility":"hidden","description":"OAuth access token"},"offset":{"type":"string","required":false,"visibility":"user-or-llm","description":"Pagination offset for retrieving additional bases"}},"oauth":{"required":true,"provider":"airtable"},"hostedApiKey":"none"},"airtable_list_records":{"id":"airtable_list_records","name":"Airtable List Records","description":"Read records from an Airtable table","version":"1.0.0","params":{"accessToken":{"type":"string","required":true,"visibility":"hidden","description":"OAuth access token"},"baseId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Airtable base ID (starts with \\"app\\", e.g., \\"appXXXXXXXXXXXXXX\\")"},"tableId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Table ID (starts with \\"tbl\\") or table name"},"maxRecords":{"type":"number","required":false,"visibility":"user-or-llm","description":"Maximum number of records to return (default: all records)"},"filterFormula":{"type":"string","required":false,"visibility":"user-or-llm","description":"Formula to filter records (e.g., \\"({Field Name} = \'Value\')\\")"}},"oauth":{"required":true,"provider":"airtable"},"hostedApiKey":"none"},"airtable_list_tables":{"id":"airtable_list_tables","name":"Airtable List Tables","description":"List all tables and their schema in an Airtable base","version":"1.0.0","params":{"accessToken":{"type":"string","required":true,"visibility":"hidden","description":"OAuth access token"},"baseId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Airtable base ID (starts with \\"app\\", e.g., \\"appXXXXXXXXXXXXXX\\")"}},"oauth":{"required":true,"provider":"airtable"},"hostedApiKey":"none"},"airtable_update_multiple_records":{"id":"airtable_update_multiple_records","name":"Airtable Update Multiple Records","description":"Update multiple existing records in an Airtable table","version":"1.0.0","params":{"accessToken":{"type":"string","required":true,"visibility":"hidden","description":"OAuth access token"},"baseId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Airtable base ID (starts with \\"app\\", e.g., \\"appXXXXXXXXXXXXXX\\")"},"tableId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Table ID (starts with \\"tbl\\") or table name"},"records":{"type":"json","required":true,"visibility":"user-or-llm","description":"Array of records to update, each with an `id` and a `fields` object"},"typecast":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"When true, Airtable automatically converts string values to the field type"}},"oauth":{"required":true,"provider":"airtable"},"hostedApiKey":"none"},"airtable_update_record":{"id":"airtable_update_record","name":"Airtable Update Record","description":"Update an existing record in an Airtable table by ID","version":"1.0.0","params":{"accessToken":{"type":"string","required":true,"visibility":"hidden","description":"OAuth access token"},"baseId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Airtable base ID (starts with \\"app\\", e.g., \\"appXXXXXXXXXXXXXX\\")"},"tableId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Table ID (starts with \\"tbl\\") or table name"},"recordId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Record ID to update (starts with \\"rec\\", e.g., \\"recXXXXXXXXXXXXXX\\")"},"fields":{"type":"json","required":true,"visibility":"user-or-llm","description":"An object containing the field names and their new values"},"typecast":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"When true, Airtable automatically converts string values to the field type"}},"oauth":{"required":true,"provider":"airtable"},"hostedApiKey":"none"},"airtable_upsert_records":{"id":"airtable_upsert_records","name":"Airtable Upsert Records","description":"Update existing records or create new ones in an Airtable table, matching on the specified merge fields","version":"1.0.0","params":{"accessToken":{"type":"string","required":true,"visibility":"hidden","description":"OAuth access token"},"baseId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Airtable base ID (starts with \\"app\\", e.g., \\"appXXXXXXXXXXXXXX\\")"},"tableId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Table ID (starts with \\"tbl\\") or table name"},"records":{"type":"json","required":true,"visibility":"user-or-llm","description":"Array of records to upsert, each with a `fields` object"},"fieldsToMergeOn":{"type":"json","required":true,"visibility":"user-or-llm","description":"Array of field names used to match existing records (max 3). A record is updated when all merge fields match, otherwise it is created. Example: [\\"Name\\"]"},"typecast":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"When true, Airtable automatically converts string values to the field type"}},"oauth":{"required":true,"provider":"airtable"},"hostedApiKey":"none"},"airweave_search":{"id":"airweave_search","name":"Airweave Search","description":"Search your synced data collections using Airweave. Supports semantic search with hybrid, neural, or keyword retrieval strategies. Optionally generate AI-powered answers from search results.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Airweave API Key for authentication"},"collectionId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The readable ID of the collection to search"},"query":{"type":"string","required":true,"visibility":"user-or-llm","description":"The search query text"},"limit":{"type":"number","required":false,"visibility":"user-only","description":"Maximum number of results to return (default: 100)"},"retrievalStrategy":{"type":"string","required":false,"visibility":"user-or-llm","description":"Retrieval strategy: hybrid (default), neural, or keyword"},"expandQuery":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Generate query variations to improve recall"},"rerank":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Reorder results for improved relevance using LLM"},"generateAnswer":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Generate a natural-language answer to the query"}},"hostedApiKey":"none"},"algolia_add_record":{"id":"algolia_add_record","name":"Algolia Add Record","description":"Add or replace a record in an Algolia index","version":"1.0","params":{"applicationId":{"type":"string","required":true,"visibility":"user-only","description":"Algolia Application ID"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Algolia Admin API Key"},"indexName":{"type":"string","required":true,"visibility":"user-or-llm","description":"Name of the Algolia index"},"objectID":{"type":"string","required":false,"visibility":"user-or-llm","description":"Object ID for the record (auto-generated if not provided)"},"record":{"type":"json","required":true,"visibility":"user-or-llm","description":"JSON object representing the record to add"}},"hostedApiKey":"none"},"algolia_batch_operations":{"id":"algolia_batch_operations","name":"Algolia Batch Operations","description":"Perform batch add, update, partial update, or delete operations on records in an Algolia index","version":"1.0","params":{"applicationId":{"type":"string","required":true,"visibility":"user-only","description":"Algolia Application ID"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Algolia Admin API Key"},"indexName":{"type":"string","required":true,"visibility":"user-or-llm","description":"Name of the Algolia index"},"requests":{"type":"json","required":true,"visibility":"user-or-llm","description":"Array of batch operations. Each item has \\"action\\" (addObject, updateObject, partialUpdateObject, partialUpdateObjectNoCreate, deleteObject, delete, clear) and \\"body\\" (the record data; must include objectID for update/delete; use an empty object {} for the index-level delete/clear actions)"}},"hostedApiKey":"none"},"algolia_browse_records":{"id":"algolia_browse_records","name":"Algolia Browse Records","description":"Browse and iterate over all records in an Algolia index using cursor pagination","version":"1.0","params":{"applicationId":{"type":"string","required":true,"visibility":"user-only","description":"Algolia Application ID"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Algolia API Key (must have browse ACL)"},"indexName":{"type":"string","required":true,"visibility":"user-or-llm","description":"Name of the Algolia index to browse"},"query":{"type":"string","required":false,"visibility":"user-or-llm","description":"Search query to filter browsed records"},"filters":{"type":"string","required":false,"visibility":"user-or-llm","description":"Filter string to narrow down results"},"attributesToRetrieve":{"type":"string","required":false,"visibility":"user-or-llm","description":"Comma-separated list of attributes to retrieve"},"hitsPerPage":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of hits per page (default: 1000, max: 1000)"},"cursor":{"type":"string","required":false,"visibility":"user-or-llm","description":"Cursor from a previous browse response for pagination"},"aroundLatLng":{"type":"string","required":false,"visibility":"user-or-llm","description":"Coordinates for geo-search (e.g., \\"40.71,-74.01\\")"},"aroundRadius":{"type":"string","required":false,"visibility":"user-or-llm","description":"Maximum radius in meters for geo-search, or \\"all\\" for unlimited"},"insideBoundingBox":{"type":"json","required":false,"visibility":"user-or-llm","description":"Bounding box coordinates as [[lat1, lng1, lat2, lng2]] for geo-search"},"insidePolygon":{"type":"json","required":false,"visibility":"user-or-llm","description":"Polygon coordinates as [[lat1, lng1, lat2, lng2, lat3, lng3, ...]] for geo-search"}},"hostedApiKey":"none"},"algolia_clear_records":{"id":"algolia_clear_records","name":"Algolia Clear Records","description":"Clear all records from an Algolia index while keeping settings, synonyms, and rules","version":"1.0","params":{"applicationId":{"type":"string","required":true,"visibility":"user-only","description":"Algolia Application ID"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Algolia Admin API Key (must have deleteIndex ACL)"},"indexName":{"type":"string","required":true,"visibility":"user-or-llm","description":"Name of the Algolia index to clear"}},"hostedApiKey":"none"},"algolia_copy_move_index":{"id":"algolia_copy_move_index","name":"Algolia Copy/Move Index","description":"Copy or move an Algolia index to a new destination","version":"1.0","params":{"applicationId":{"type":"string","required":true,"visibility":"user-only","description":"Algolia Application ID"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Algolia Admin API Key"},"indexName":{"type":"string","required":true,"visibility":"user-or-llm","description":"Name of the source index"},"operation":{"type":"string","required":true,"visibility":"user-or-llm","description":"Operation to perform: \\"copy\\" or \\"move\\""},"destination":{"type":"string","required":true,"visibility":"user-or-llm","description":"Name of the destination index"},"scope":{"type":"json","required":false,"visibility":"user-or-llm","description":"Array of scopes to copy (only for \\"copy\\" operation): [\\"settings\\", \\"synonyms\\", \\"rules\\"]. Omit to copy everything including records."}},"hostedApiKey":"none"},"algolia_delete_by_filter":{"id":"algolia_delete_by_filter","name":"Algolia Delete By Filter","description":"Delete all records matching a filter from an Algolia index","version":"1.0","params":{"applicationId":{"type":"string","required":true,"visibility":"user-only","description":"Algolia Application ID"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Algolia Admin API Key (must have deleteIndex ACL)"},"indexName":{"type":"string","required":true,"visibility":"user-or-llm","description":"Name of the Algolia index"},"filters":{"type":"string","required":false,"visibility":"user-or-llm","description":"Filter expression to match records for deletion (e.g., \\"category:outdated\\")"},"facetFilters":{"type":"json","required":false,"visibility":"user-or-llm","description":"Array of facet filters (e.g., [\\"brand:Acme\\"])"},"numericFilters":{"type":"json","required":false,"visibility":"user-or-llm","description":"Array of numeric filters (e.g., [\\"price > 100\\"])"},"tagFilters":{"type":"json","required":false,"visibility":"user-or-llm","description":"Array of tag filters using the _tags attribute (e.g., [\\"published\\"])"},"aroundLatLng":{"type":"string","required":false,"visibility":"user-or-llm","description":"Coordinates for geo-search filter (e.g., \\"40.71,-74.01\\")"},"aroundRadius":{"type":"string","required":false,"visibility":"user-or-llm","description":"Maximum radius in meters for geo-search, or \\"all\\" for unlimited"},"insideBoundingBox":{"type":"json","required":false,"visibility":"user-or-llm","description":"Bounding box coordinates as [[lat1, lng1, lat2, lng2]] for geo-search filter"},"insidePolygon":{"type":"json","required":false,"visibility":"user-or-llm","description":"Polygon coordinates as [[lat1, lng1, lat2, lng2, lat3, lng3, ...]] for geo-search filter"}},"hostedApiKey":"none"},"algolia_delete_index":{"id":"algolia_delete_index","name":"Algolia Delete Index","description":"Delete an entire Algolia index and all its records","version":"1.0","params":{"applicationId":{"type":"string","required":true,"visibility":"user-only","description":"Algolia Application ID"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Algolia Admin API Key (must have deleteIndex ACL)"},"indexName":{"type":"string","required":true,"visibility":"user-or-llm","description":"Name of the Algolia index to delete"}},"hostedApiKey":"none"},"algolia_delete_record":{"id":"algolia_delete_record","name":"Algolia Delete Record","description":"Delete a record by objectID from an Algolia index","version":"1.0","params":{"applicationId":{"type":"string","required":true,"visibility":"user-only","description":"Algolia Application ID"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Algolia Admin API Key"},"indexName":{"type":"string","required":true,"visibility":"user-or-llm","description":"Name of the Algolia index"},"objectID":{"type":"string","required":true,"visibility":"user-or-llm","description":"The objectID of the record to delete"}},"hostedApiKey":"none"},"algolia_get_record":{"id":"algolia_get_record","name":"Algolia Get Record","description":"Get a record by objectID from an Algolia index","version":"1.0","params":{"applicationId":{"type":"string","required":true,"visibility":"user-only","description":"Algolia Application ID"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Algolia API Key"},"indexName":{"type":"string","required":true,"visibility":"user-or-llm","description":"Name of the Algolia index"},"objectID":{"type":"string","required":true,"visibility":"user-or-llm","description":"The objectID of the record to retrieve"},"attributesToRetrieve":{"type":"string","required":false,"visibility":"user-or-llm","description":"Comma-separated list of attributes to retrieve"}},"hostedApiKey":"none"},"algolia_get_records":{"id":"algolia_get_records","name":"Algolia Get Records","description":"Retrieve multiple records by objectID from one or more Algolia indices","version":"1.0","params":{"applicationId":{"type":"string","required":true,"visibility":"user-only","description":"Algolia Application ID"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Algolia API Key"},"indexName":{"type":"string","required":true,"visibility":"user-or-llm","description":"Default index name for all requests"},"requests":{"type":"json","required":true,"visibility":"user-or-llm","description":"Array of objects specifying records to retrieve. Each must have \\"objectID\\" and optionally \\"indexName\\" and \\"attributesToRetrieve\\"."}},"hostedApiKey":"none"},"algolia_get_settings":{"id":"algolia_get_settings","name":"Algolia Get Settings","description":"Retrieve the settings of an Algolia index","version":"1.0","params":{"applicationId":{"type":"string","required":true,"visibility":"user-only","description":"Algolia Application ID"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Algolia API Key"},"indexName":{"type":"string","required":true,"visibility":"user-or-llm","description":"Name of the Algolia index"}},"hostedApiKey":"none"},"algolia_get_task_status":{"id":"algolia_get_task_status","name":"Algolia Get Task Status","description":"Check whether an Algolia indexing task has finished publishing","version":"1.0","params":{"applicationId":{"type":"string","required":true,"visibility":"user-only","description":"Algolia Application ID"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Algolia API Key"},"indexName":{"type":"string","required":true,"visibility":"user-or-llm","description":"Name of the Algolia index the task ran against"},"taskID":{"type":"number","required":true,"visibility":"user-or-llm","description":"The taskID returned by a previous write operation"}},"hostedApiKey":"none"},"algolia_list_indices":{"id":"algolia_list_indices","name":"Algolia List Indices","description":"List all indices in an Algolia application","version":"1.0","params":{"applicationId":{"type":"string","required":true,"visibility":"user-only","description":"Algolia Application ID"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Algolia API Key"},"page":{"type":"number","required":false,"visibility":"user-or-llm","description":"Page number for paginating indices (default: not paginated)"},"hitsPerPage":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of indices per page (default: 100)"}},"hostedApiKey":"none"},"algolia_partial_update_record":{"id":"algolia_partial_update_record","name":"Algolia Partial Update Record","description":"Partially update a record in an Algolia index without replacing it entirely","version":"1.0","params":{"applicationId":{"type":"string","required":true,"visibility":"user-only","description":"Algolia Application ID"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Algolia Admin API Key"},"indexName":{"type":"string","required":true,"visibility":"user-or-llm","description":"Name of the Algolia index"},"objectID":{"type":"string","required":true,"visibility":"user-or-llm","description":"The objectID of the record to update"},"attributes":{"type":"json","required":true,"visibility":"user-or-llm","description":"JSON object with attributes to update. Supports built-in operations like {\\"stock\\": {\\"_operation\\": \\"Decrement\\", \\"value\\": 1}}"},"createIfNotExists":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Whether to create the record if it does not exist (default: true)"}},"hostedApiKey":"none"},"algolia_search":{"id":"algolia_search","name":"Algolia Search","description":"Search an Algolia index","version":"1.0","params":{"applicationId":{"type":"string","required":true,"visibility":"user-only","description":"Algolia Application ID"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Algolia API Key"},"indexName":{"type":"string","required":true,"visibility":"user-or-llm","description":"Name of the Algolia index to search"},"query":{"type":"string","required":true,"visibility":"user-or-llm","description":"Search query text"},"hitsPerPage":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of hits per page (default: 20)"},"page":{"type":"number","required":false,"visibility":"user-or-llm","description":"Page number to retrieve (default: 0)"},"filters":{"type":"string","required":false,"visibility":"user-or-llm","description":"Filter string (e.g., \\"category:electronics AND price < 100\\")"},"attributesToRetrieve":{"type":"string","required":false,"visibility":"user-or-llm","description":"Comma-separated list of attributes to retrieve"},"facets":{"type":"string","required":false,"visibility":"user-or-llm","description":"Comma-separated list of facet attribute names to retrieve counts for (use \\"*\\" for all)"},"getRankingInfo":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Whether to include detailed ranking information in each hit"},"aroundLatLng":{"type":"string","required":false,"visibility":"user-or-llm","description":"Coordinates for geo-search (e.g., \\"40.71,-74.01\\")"},"aroundRadius":{"type":"string","required":false,"visibility":"user-or-llm","description":"Maximum radius in meters for geo-search, or \\"all\\" for unlimited"},"insideBoundingBox":{"type":"json","required":false,"visibility":"user-or-llm","description":"Bounding box coordinates as [[lat1, lng1, lat2, lng2]] for geo-search"},"insidePolygon":{"type":"json","required":false,"visibility":"user-or-llm","description":"Polygon coordinates as [[lat1, lng1, lat2, lng2, lat3, lng3, ...]] for geo-search"}},"hostedApiKey":"none"},"algolia_update_settings":{"id":"algolia_update_settings","name":"Algolia Update Settings","description":"Update the settings of an Algolia index","version":"1.0","params":{"applicationId":{"type":"string","required":true,"visibility":"user-only","description":"Algolia Application ID"},"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Algolia Admin API Key (must have editSettings ACL)"},"indexName":{"type":"string","required":true,"visibility":"user-or-llm","description":"Name of the Algolia index"},"settings":{"type":"json","required":true,"visibility":"user-or-llm","description":"JSON object with settings to update (e.g., {\\"searchableAttributes\\": [\\"name\\", \\"description\\"], \\"customRanking\\": [\\"desc(popularity)\\"]})"},"forwardToReplicas":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Whether to apply changes to replica indices (default: false)"}},"hostedApiKey":"none"},"amplitude_event_segmentation":{"id":"amplitude_event_segmentation","name":"Amplitude Event Segmentation","description":"Query event analytics data with segmentation. Get event counts, uniques, averages, and more.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Amplitude API Key"},"secretKey":{"type":"string","required":true,"visibility":"user-only","description":"Amplitude Secret Key"},"eventType":{"type":"string","required":true,"visibility":"user-or-llm","description":"Event type name to analyze"},"start":{"type":"string","required":true,"visibility":"user-or-llm","description":"Start date in YYYYMMDD format"},"end":{"type":"string","required":true,"visibility":"user-or-llm","description":"End date in YYYYMMDD format"},"metric":{"type":"string","required":false,"visibility":"user-or-llm","description":"Metric type: uniques, totals, pct_dau, average, histogram, sums, value_avg, or formula (default: uniques)"},"interval":{"type":"string","required":false,"visibility":"user-or-llm","description":"Time interval: 1 (daily), 7 (weekly), or 30 (monthly)"},"groupBy":{"type":"string","required":false,"visibility":"user-or-llm","description":"Property name to group by (prefix custom user properties with \\"gp:\\")"},"groupBy2":{"type":"string","required":false,"visibility":"user-or-llm","description":"Second property name to group by (prefix custom user properties with \\"gp:\\")"},"limit":{"type":"string","required":false,"visibility":"user-or-llm","description":"Maximum number of group-by values (max 1000)"},"filters":{"type":"string","required":false,"visibility":"user-or-llm","description":"JSON array of filter objects applied to the event, e.g. [{\\"subprop_type\\":\\"event\\",\\"subprop_key\\":\\"city\\",\\"subprop_op\\":\\"is\\",\\"subprop_value\\":[\\"San Francisco\\"]}]"},"formula":{"type":"string","required":false,"visibility":"user-or-llm","description":"Required when metric is \\"formula\\", e.g. \\"UNIQUES(A)/UNIQUES(B)\\""},"segment":{"type":"string","required":false,"visibility":"user-or-llm","description":"JSON segment definition(s) applied to the query"},"dataResidency":{"type":"string","required":false,"visibility":"user-or-llm","description":"Data residency region: \\"us\\" (default) or \\"eu\\""}},"hostedApiKey":"none"},"amplitude_funnels":{"id":"amplitude_funnels","name":"Amplitude Funnels","description":"Analyze conversion rates and drop-off between a sequence of events.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Amplitude API Key"},"secretKey":{"type":"string","required":true,"visibility":"user-only","description":"Amplitude Secret Key"},"events":{"type":"string","required":true,"visibility":"user-or-llm","description":"JSON array of event objects, one per funnel step in order, e.g. [{\\"event_type\\":\\"signup\\"},{\\"event_type\\":\\"purchase\\"}]"},"start":{"type":"string","required":true,"visibility":"user-or-llm","description":"Start date in YYYYMMDD format"},"end":{"type":"string","required":true,"visibility":"user-or-llm","description":"End date in YYYYMMDD format"},"mode":{"type":"string","required":false,"visibility":"user-or-llm","description":"Funnel ordering: \\"ordered\\", \\"unordered\\", or \\"sequential\\" (default: ordered)"},"userType":{"type":"string","required":false,"visibility":"user-or-llm","description":"User type: \\"new\\" or \\"active\\" (default: active)"},"interval":{"type":"string","required":false,"visibility":"user-or-llm","description":"Time interval: -300000 (real-time), -3600000 (hourly), 1 (daily), 7 (weekly), or 30 (monthly)"},"conversionWindowSeconds":{"type":"string","required":false,"visibility":"user-or-llm","description":"Conversion window in seconds (default: 2592000, i.e. 30 days)"},"groupBy":{"type":"string","required":false,"visibility":"user-or-llm","description":"Property to group by (limit: one; prefix custom properties with \\"gp:\\")"},"limit":{"type":"string","required":false,"visibility":"user-or-llm","description":"Maximum number of group-by values (default: 100, max: 1000)"},"segment":{"type":"string","required":false,"visibility":"user-or-llm","description":"JSON segment definition(s) applied to the query"},"dataResidency":{"type":"string","required":false,"visibility":"user-or-llm","description":"Data residency region: \\"us\\" (default) or \\"eu\\""}},"hostedApiKey":"none"},"amplitude_get_active_users":{"id":"amplitude_get_active_users","name":"Amplitude Get Active Users","description":"Get active or new user counts over a date range from the Dashboard REST API.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Amplitude API Key"},"secretKey":{"type":"string","required":true,"visibility":"user-only","description":"Amplitude Secret Key"},"start":{"type":"string","required":true,"visibility":"user-or-llm","description":"Start date in YYYYMMDD format"},"end":{"type":"string","required":true,"visibility":"user-or-llm","description":"End date in YYYYMMDD format"},"metric":{"type":"string","required":false,"visibility":"user-or-llm","description":"Metric type: \\"active\\" or \\"new\\" (default: active)"},"interval":{"type":"string","required":false,"visibility":"user-or-llm","description":"Time interval: 1 (daily), 7 (weekly), or 30 (monthly)"},"groupBy":{"type":"string","required":false,"visibility":"user-or-llm","description":"Property name to group by"},"segment":{"type":"string","required":false,"visibility":"user-or-llm","description":"JSON segment definition(s) applied to the query"},"dataResidency":{"type":"string","required":false,"visibility":"user-or-llm","description":"Data residency region: \\"us\\" (default) or \\"eu\\""}},"hostedApiKey":"none"},"amplitude_get_revenue":{"id":"amplitude_get_revenue","name":"Amplitude Get Revenue","description":"Get revenue LTV data including ARPU, ARPPU, total revenue, and paying user counts.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Amplitude API Key"},"secretKey":{"type":"string","required":true,"visibility":"user-only","description":"Amplitude Secret Key"},"start":{"type":"string","required":true,"visibility":"user-or-llm","description":"Start date in YYYYMMDD format"},"end":{"type":"string","required":true,"visibility":"user-or-llm","description":"End date in YYYYMMDD format"},"metric":{"type":"string","required":false,"visibility":"user-or-llm","description":"Metric: 0 (ARPU), 1 (ARPPU), 2 (Total Revenue), 3 (Paying Users)"},"interval":{"type":"string","required":false,"visibility":"user-or-llm","description":"Time interval: 1 (daily), 7 (weekly), or 30 (monthly)"},"groupBy":{"type":"string","required":false,"visibility":"user-or-llm","description":"Property name to group by (limit: one)"},"segment":{"type":"string","required":false,"visibility":"user-or-llm","description":"JSON segment definition(s) applied to the query"},"dataResidency":{"type":"string","required":false,"visibility":"user-or-llm","description":"Data residency region: \\"us\\" (default) or \\"eu\\""}},"hostedApiKey":"none"},"amplitude_group_identify":{"id":"amplitude_group_identify","name":"Amplitude Group Identify","description":"Set group-level properties in Amplitude. Supports $set, $setOnce, $add, $append, $unset operations.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Amplitude API Key"},"groupType":{"type":"string","required":true,"visibility":"user-or-llm","description":"Group classification (e.g., \\"company\\", \\"org_id\\")"},"groupValue":{"type":"string","required":true,"visibility":"user-or-llm","description":"Specific group identifier (e.g., \\"Acme Corp\\")"},"groupProperties":{"type":"string","required":true,"visibility":"user-or-llm","description":"JSON object of group properties. Use operations like $set, $setOnce, $add, $append, $unset."},"dataResidency":{"type":"string","required":false,"visibility":"user-or-llm","description":"Data residency region: \\"us\\" (default) or \\"eu\\""}},"hostedApiKey":"none"},"amplitude_identify_user":{"id":"amplitude_identify_user","name":"Amplitude Identify User","description":"Set user properties in Amplitude using the Identify API. Supports $set, $setOnce, $add, $append, $unset operations.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Amplitude API Key"},"userId":{"type":"string","required":false,"visibility":"user-or-llm","description":"User ID (required if no device_id)"},"deviceId":{"type":"string","required":false,"visibility":"user-or-llm","description":"Device ID (required if no user_id)"},"userProperties":{"type":"string","required":true,"visibility":"user-or-llm","description":"JSON object of user properties. Use operations like $set, $setOnce, $add, $append, $unset."},"dataResidency":{"type":"string","required":false,"visibility":"user-or-llm","description":"Data residency region: \\"us\\" (default) or \\"eu\\""}},"hostedApiKey":"none"},"amplitude_list_events":{"id":"amplitude_list_events","name":"Amplitude List Events","description":"List all event types in the Amplitude project with their weekly totals and unique counts.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Amplitude API Key"},"secretKey":{"type":"string","required":true,"visibility":"user-only","description":"Amplitude Secret Key"},"dataResidency":{"type":"string","required":false,"visibility":"user-or-llm","description":"Data residency region: \\"us\\" (default) or \\"eu\\""}},"hostedApiKey":"none"},"amplitude_realtime_active_users":{"id":"amplitude_realtime_active_users","name":"Amplitude Real-time Active Users","description":"Get real-time active user counts at 5-minute granularity for the last 2 days.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Amplitude API Key"},"secretKey":{"type":"string","required":true,"visibility":"user-only","description":"Amplitude Secret Key"},"dataResidency":{"type":"string","required":false,"visibility":"user-or-llm","description":"Data residency region: \\"us\\" (default) or \\"eu\\""}},"hostedApiKey":"none"},"amplitude_retention":{"id":"amplitude_retention","name":"Amplitude Retention","description":"Measure how many users return to perform an action after a starting action.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Amplitude API Key"},"secretKey":{"type":"string","required":true,"visibility":"user-only","description":"Amplitude Secret Key"},"startEvent":{"type":"string","required":true,"visibility":"user-or-llm","description":"JSON starting event object, e.g. {\\"event_type\\":\\"_new\\"} or {\\"event_type\\":\\"_active\\"}"},"returnEvent":{"type":"string","required":true,"visibility":"user-or-llm","description":"JSON returning event object, e.g. {\\"event_type\\":\\"_all\\"} or {\\"event_type\\":\\"_active\\"}"},"start":{"type":"string","required":true,"visibility":"user-or-llm","description":"Start date in YYYYMMDD format"},"end":{"type":"string","required":true,"visibility":"user-or-llm","description":"End date in YYYYMMDD format"},"retentionMode":{"type":"string","required":false,"visibility":"user-or-llm","description":"Retention type: \\"bracket\\", \\"rolling\\", or \\"n-day\\" (default: n-day)"},"retentionBrackets":{"type":"string","required":false,"visibility":"user-or-llm","description":"Required when Retention Mode is \\"bracket\\". Day ranges, e.g. [[0,4]]"},"interval":{"type":"string","required":false,"visibility":"user-or-llm","description":"Time interval: 1 (daily), 7 (weekly), or 30 (monthly)"},"groupBy":{"type":"string","required":false,"visibility":"user-or-llm","description":"Property to group by (limit: one; prefix custom properties with \\"gp:\\")"},"segment":{"type":"string","required":false,"visibility":"user-or-llm","description":"JSON segment definition(s) applied to the query"},"dataResidency":{"type":"string","required":false,"visibility":"user-or-llm","description":"Data residency region: \\"us\\" (default) or \\"eu\\""}},"hostedApiKey":"none"},"amplitude_send_event":{"id":"amplitude_send_event","name":"Amplitude Send Event","description":"Track an event in Amplitude using the HTTP V2 API.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Amplitude API Key"},"userId":{"type":"string","required":false,"visibility":"user-or-llm","description":"User ID (required if no device_id)"},"deviceId":{"type":"string","required":false,"visibility":"user-or-llm","description":"Device ID (required if no user_id)"},"eventType":{"type":"string","required":true,"visibility":"user-or-llm","description":"Name of the event (e.g., \\"page_view\\", \\"purchase\\")"},"eventProperties":{"type":"string","required":false,"visibility":"user-or-llm","description":"JSON object of custom event properties"},"userProperties":{"type":"string","required":false,"visibility":"user-or-llm","description":"JSON object of user properties to set (supports $set, $setOnce, $add, $append, $unset)"},"time":{"type":"string","required":false,"visibility":"user-or-llm","description":"Event timestamp in milliseconds since epoch"},"sessionId":{"type":"string","required":false,"visibility":"user-or-llm","description":"Session start time in milliseconds since epoch"},"insertId":{"type":"string","required":false,"visibility":"user-or-llm","description":"Unique ID for deduplication (within 7-day window)"},"appVersion":{"type":"string","required":false,"visibility":"user-or-llm","description":"Application version string"},"platform":{"type":"string","required":false,"visibility":"user-or-llm","description":"Platform (e.g., \\"Web\\", \\"iOS\\", \\"Android\\")"},"country":{"type":"string","required":false,"visibility":"user-or-llm","description":"Two-letter country code"},"language":{"type":"string","required":false,"visibility":"user-or-llm","description":"Language code (e.g., \\"en\\")"},"ip":{"type":"string","required":false,"visibility":"user-or-llm","description":"IP address for geo-location"},"price":{"type":"string","required":false,"visibility":"user-or-llm","description":"Price of the item purchased"},"quantity":{"type":"string","required":false,"visibility":"user-or-llm","description":"Quantity of items purchased"},"revenue":{"type":"string","required":false,"visibility":"user-or-llm","description":"Revenue amount"},"productId":{"type":"string","required":false,"visibility":"user-or-llm","description":"Product identifier"},"revenueType":{"type":"string","required":false,"visibility":"user-or-llm","description":"Revenue type (e.g., \\"purchase\\", \\"refund\\")"},"dataResidency":{"type":"string","required":false,"visibility":"user-or-llm","description":"Data residency region: \\"us\\" (default) or \\"eu\\""}},"hostedApiKey":"none"},"amplitude_user_activity":{"id":"amplitude_user_activity","name":"Amplitude User Activity","description":"Get the event stream for a specific user by their Amplitude ID.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Amplitude API Key"},"secretKey":{"type":"string","required":true,"visibility":"user-only","description":"Amplitude Secret Key"},"amplitudeId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Amplitude internal user ID"},"offset":{"type":"string","required":false,"visibility":"user-or-llm","description":"Offset for pagination (default 0)"},"limit":{"type":"string","required":false,"visibility":"user-or-llm","description":"Maximum number of events to return (default 1000, max 1000)"},"direction":{"type":"string","required":false,"visibility":"user-or-llm","description":"Sort direction: \\"latest\\" or \\"earliest\\" (default: latest)"},"dataResidency":{"type":"string","required":false,"visibility":"user-or-llm","description":"Data residency region: \\"us\\" (default) or \\"eu\\""}},"hostedApiKey":"none"},"amplitude_user_profile":{"id":"amplitude_user_profile","name":"Amplitude User Profile","description":"Get a user profile including properties, cohort memberships, and computed properties. Not available for EU data-residency projects.","version":"1.0.0","params":{"secretKey":{"type":"string","required":true,"visibility":"user-only","description":"Amplitude Secret Key"},"userId":{"type":"string","required":false,"visibility":"user-or-llm","description":"External user ID (required if no device_id)"},"deviceId":{"type":"string","required":false,"visibility":"user-or-llm","description":"Device ID (required if no user_id)"},"getAmpProps":{"type":"string","required":false,"visibility":"user-or-llm","description":"Include Amplitude user properties (true/false, default: false)"},"getCohortIds":{"type":"string","required":false,"visibility":"user-or-llm","description":"Include cohort IDs the user belongs to (true/false, default: false)"},"getComputations":{"type":"string","required":false,"visibility":"user-or-llm","description":"Include computed user properties (true/false, default: false)"}},"hostedApiKey":"none"},"amplitude_user_search":{"id":"amplitude_user_search","name":"Amplitude User Search","description":"Search for a user by User ID, Device ID, or Amplitude ID using the Dashboard REST API.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Amplitude API Key"},"secretKey":{"type":"string","required":true,"visibility":"user-only","description":"Amplitude Secret Key"},"user":{"type":"string","required":true,"visibility":"user-or-llm","description":"User ID, Device ID, or Amplitude ID to search for"},"dataResidency":{"type":"string","required":false,"visibility":"user-or-llm","description":"Data residency region: \\"us\\" (default) or \\"eu\\""}},"hostedApiKey":"none"},"apify_get_dataset_items":{"id":"apify_get_dataset_items","name":"APIFY Get Dataset Items","description":"Retrieve items stored in an APIFY dataset","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"APIFY API token from console.apify.com/account#/integrations"},"datasetId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Dataset ID to read items from. Example: \\"9RnD3Pql2vGZkc5H5\\""},"itemLimit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Max items to return (1-250000). Default: all items. Example: 500"},"offset":{"type":"number","required":false,"visibility":"user-or-llm","description":"Number of items to skip at the start. Default: 0"},"fields":{"type":"string","required":false,"visibility":"user-or-llm","description":"Comma-separated list of fields to include. Example: \\"title,url,price\\""}},"hostedApiKey":"none"},"apify_get_run":{"id":"apify_get_run","name":"APIFY Get Run","description":"Get the status and details of an APIFY actor run","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"APIFY API token from console.apify.com/account#/integrations"},"runId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Actor run ID to fetch. Example: \\"HG7ML7M8z78YcAPEB\\""}},"hostedApiKey":"none"},"apify_run_actor_async":{"id":"apify_run_actor_async","name":"APIFY Run Actor (Async)","description":"Run an APIFY actor asynchronously with polling for long-running tasks","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"APIFY API token from console.apify.com/account#/integrations"},"actorId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Actor ID or username/actor-name. Examples: \\"apify/web-scraper\\", \\"janedoe/my-actor\\", \\"moJRLRc85AitArpNN\\""},"input":{"type":"string","required":false,"visibility":"user-or-llm","description":"Actor input as JSON string. Example: { \\"startUrls\\": [ { \\"url\\": \\"https://example.com\\" } ], \\"maxPages\\": 10 }"},"waitForFinish":{"type":"number","required":false,"visibility":"user-or-llm","description":"Initial wait time in seconds (0-60) before polling starts. Example: 30"},"itemLimit":{"type":"number","required":false,"default":100,"visibility":"user-or-llm","description":"Max dataset items to fetch (1-250000). Default: 100. Example: 500"},"memory":{"type":"number","required":false,"visibility":"user-or-llm","description":"Memory in megabytes allocated for the actor run (128-32768). Example: 1024 for 1GB, 2048 for 2GB"},"timeout":{"type":"number","required":false,"visibility":"user-or-llm","description":"Timeout in seconds for the actor run. Example: 300 for 5 minutes, 3600 for 1 hour"},"build":{"type":"string","required":false,"visibility":"user-or-llm","description":"Actor build to run. Examples: \\"latest\\", \\"beta\\", \\"1.2.3\\", \\"build-tag-name\\""}},"hostedApiKey":"none"},"apify_run_actor_sync":{"id":"apify_run_actor_sync","name":"APIFY Run Actor (Sync)","description":"Run an APIFY actor synchronously and get results (max 5 minutes)","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"APIFY API token from console.apify.com/account#/integrations"},"actorId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Actor ID or username/actor-name. Examples: \\"apify/web-scraper\\", \\"janedoe/my-actor\\", \\"moJRLRc85AitArpNN\\""},"input":{"type":"string","required":false,"visibility":"user-or-llm","description":"Actor input as JSON string. Example: { \\"startUrls\\": [ { \\"url\\": \\"https://example.com\\" } ], \\"maxPages\\": 10 }"},"memory":{"type":"number","required":false,"visibility":"user-or-llm","description":"Memory in megabytes allocated for the actor run (128-32768). Example: 1024 for 1GB, 2048 for 2GB"},"timeout":{"type":"number","required":false,"visibility":"user-or-llm","description":"Timeout in seconds for the actor run. Example: 300 for 5 minutes, 3600 for 1 hour"},"build":{"type":"string","required":false,"visibility":"user-or-llm","description":"Actor build to run. Examples: \\"latest\\", \\"beta\\", \\"1.2.3\\", \\"build-tag-name\\""}},"hostedApiKey":"none"},"apify_run_task":{"id":"apify_run_task","name":"APIFY Run Task","description":"Run a saved APIFY actor task synchronously and get dataset items (max 5 minutes)","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"APIFY API token from console.apify.com/account#/integrations"},"taskId":{"type":"string","required":true,"visibility":"user-or-llm","description":"Task ID or username/task-name. Examples: \\"janedoe/my-task\\", \\"moJRLRc85AitArpNN\\""},"input":{"type":"string","required":false,"visibility":"user-or-llm","description":"JSON string that overrides the task\'s saved input. Example: { \\"startUrls\\": [ { \\"url\\": \\"https://example.com\\" } ] }"},"itemLimit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Max dataset items to return (1-250000). Example: 500"},"memory":{"type":"number","required":false,"visibility":"user-or-llm","description":"Memory in megabytes allocated for the run (128-32768). Example: 1024 for 1GB"},"timeout":{"type":"number","required":false,"visibility":"user-or-llm","description":"Timeout in seconds for the run. Example: 300 for 5 minutes"},"build":{"type":"string","required":false,"visibility":"user-or-llm","description":"Actor build to run. Examples: \\"latest\\", \\"beta\\", \\"1.2.3\\""}},"hostedApiKey":"none"},"apollo_account_bulk_create":{"id":"apollo_account_bulk_create","name":"Apollo Bulk Create Accounts","description":"Create up to 100 accounts at once in your Apollo database. Set run_dedupe=true to deduplicate by domain, organization_id, and name. Master key required.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Apollo API key (master key required)"},"accounts":{"type":"array","required":true,"visibility":"user-or-llm","description":"Array of accounts to create (max 100). Each account should include a name, and may optionally include domain, phone, phone_status_cd, raw_address, owner_id, linkedin_url, facebook_url, twitter_url, salesforce_id, and hubspot_id."},"append_label_names":{"type":"array","required":false,"visibility":"user-only","description":"Array of label names to add to ALL accounts in this request"},"run_dedupe":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"When true, performs aggressive deduplication by domain, organization_id, and name (defaults to false)"}},"hostedApiKey":"none"},"apollo_account_bulk_update":{"id":"apollo_account_bulk_update","name":"Apollo Bulk Update Accounts","description":"Update up to 1000 existing accounts at once in your Apollo database (higher limit than contacts!). Each account must include an id field. Master key required.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Apollo API key (master key required)"},"account_ids":{"type":"array","required":false,"visibility":"user-or-llm","description":"Array of account IDs to update with the same values (max 1000). Use with name/owner_id for uniform updates. Use either this OR account_attributes."},"name":{"type":"string","required":false,"visibility":"user-or-llm","description":"When using account_ids, apply this name to all accounts"},"owner_id":{"type":"string","required":false,"visibility":"user-or-llm","description":"When using account_ids, apply this owner to all accounts"},"account_stage_id":{"type":"string","required":false,"visibility":"user-or-llm","description":"When using account_ids, apply this account stage to all accounts"},"account_attributes":{"type":"json","required":false,"visibility":"user-or-llm","description":"Array of account objects with individual updates (each must include id). Example: [{\\"id\\": \\"acc1\\", \\"name\\": \\"Acme\\", \\"owner_id\\": \\"u1\\", \\"account_stage_id\\": \\"s1\\", \\"typed_custom_fields\\": {\\"field_id\\": \\"value\\"}}]"},"async":{"type":"boolean","required":false,"visibility":"user-only","description":"When true, processes the update asynchronously. Only supported when using account_ids; returns 422 if used with account_attributes."}},"hostedApiKey":"none"},"apollo_account_create":{"id":"apollo_account_create","name":"Apollo Create Account","description":"Create a new account (company) in your Apollo database","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Apollo API key (master key required)"},"name":{"type":"string","required":true,"visibility":"user-or-llm","description":"Company name (e.g., \\"Acme Corporation\\")"},"domain":{"type":"string","required":false,"visibility":"user-or-llm","description":"Company domain without www. prefix (e.g., \\"acme.com\\")"},"phone":{"type":"string","required":false,"visibility":"user-or-llm","description":"Primary phone number for the account"},"owner_id":{"type":"string","required":false,"visibility":"user-only","description":"Apollo user ID of the account owner"},"account_stage_id":{"type":"string","required":false,"visibility":"user-only","description":"Apollo ID for the account stage to assign this account to"},"raw_address":{"type":"string","required":false,"visibility":"user-or-llm","description":"Corporate location (e.g., \\"San Francisco, CA, USA\\")"},"typed_custom_fields":{"type":"json","required":false,"visibility":"user-only","description":"Custom field values as { custom_field_id: value } map"}},"hostedApiKey":"none"},"apollo_account_search":{"id":"apollo_account_search","name":"Apollo Search Accounts","description":"Search your team\'s accounts in Apollo. Display limit: 50,000 records (100 records per page, 500 pages max). Use filters to narrow results. Master key required.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Apollo API key (master key required)"},"q_organization_name":{"type":"string","required":false,"visibility":"user-or-llm","description":"Filter accounts by organization name (partial-match search)"},"account_stage_ids":{"type":"array","required":false,"visibility":"user-only","description":"Filter by account stage IDs"},"account_label_ids":{"type":"array","required":false,"visibility":"user-only","description":"Filter by account label IDs"},"sort_by_field":{"type":"string","required":false,"visibility":"user-or-llm","description":"Sort field: \\"account_last_activity_date\\", \\"account_created_at\\", or \\"account_updated_at\\""},"sort_ascending":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Sort ascending when true. Defaults to descending."},"page":{"type":"number","required":false,"visibility":"user-or-llm","description":"Page number for pagination (e.g., 1, 2, 3)"},"per_page":{"type":"number","required":false,"visibility":"user-or-llm","description":"Results per page, max 100 (e.g., 25, 50, 100)"}},"hostedApiKey":"none"},"apollo_account_update":{"id":"apollo_account_update","name":"Apollo Update Account","description":"Update an existing account in your Apollo database","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Apollo API key"},"account_id":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the account to update (e.g., \\"acc_abc123\\")"},"name":{"type":"string","required":false,"visibility":"user-or-llm","description":"Company name (e.g., \\"Acme Corporation\\")"},"domain":{"type":"string","required":false,"visibility":"user-or-llm","description":"Company domain (e.g., \\"acme.com\\")"},"phone":{"type":"string","required":false,"visibility":"user-or-llm","description":"Company phone number"},"owner_id":{"type":"string","required":false,"visibility":"user-only","description":"Apollo user ID of the account owner"},"account_stage_id":{"type":"string","required":false,"visibility":"user-only","description":"Apollo ID for the account stage to assign this account to"},"raw_address":{"type":"string","required":false,"visibility":"user-or-llm","description":"Corporate location (e.g., \\"San Francisco, CA, USA\\")"},"typed_custom_fields":{"type":"json","required":false,"visibility":"user-only","description":"Custom field values as { custom_field_id: value } map"}},"hostedApiKey":"none"},"apollo_contact_bulk_create":{"id":"apollo_contact_bulk_create","name":"Apollo Bulk Create Contacts","description":"Create up to 100 contacts at once in your Apollo database. Supports deduplication to prevent creating duplicate contacts. Master key required.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Apollo API key (master key required)"},"contacts":{"type":"array","required":true,"visibility":"user-or-llm","description":"Array of contacts to create (max 100). Each contact may include first_name, last_name, email, title, organization_name, account_id, owner_id, contact_stage_id, linkedin_url, phone (single string) or phone_numbers (array of {raw_number, position}), contact_emails, typed_custom_fields, and CRM IDs (salesforce_contact_id, hubspot_id, team_id) for cross-system matching"},"append_label_names":{"type":"array","required":false,"visibility":"user-or-llm","description":"Label names to add to all contacts in this request (e.g., [\\"Hot Lead\\"])"},"run_dedupe":{"type":"boolean","required":false,"visibility":"user-only","description":"Enable deduplication to prevent creating duplicate contacts. When true, existing contacts are returned without modification"}},"hostedApiKey":"none"},"apollo_contact_bulk_update":{"id":"apollo_contact_bulk_update","name":"Apollo Bulk Update Contacts","description":"Update up to 100 existing contacts at once in your Apollo database. Each contact must include an id field. Master key required.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Apollo API key (master key required)"},"contact_ids":{"type":"array","required":false,"visibility":"user-or-llm","description":"Array of contact IDs to update. Must be paired with an object-form contact_attributes specifying the fields to apply uniformly to all listed contacts."},"contact_attributes":{"type":"json","required":false,"visibility":"user-or-llm","description":"Required. Either an array of per-contact updates (each with id) — used standalone — or a single object of attributes to apply to all contact_ids. Supported fields: owner_id, email, organization_name, title, first_name, last_name, account_id, present_raw_address, linkedin_url, typed_custom_fields"},"async":{"type":"boolean","required":false,"visibility":"user-only","description":"Force asynchronous processing. Automatically enabled for >100 contacts"}},"hostedApiKey":"none"},"apollo_contact_create":{"id":"apollo_contact_create","name":"Apollo Create Contact","description":"Create a new contact in your Apollo database","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Apollo API key"},"first_name":{"type":"string","required":true,"visibility":"user-or-llm","description":"First name of the contact"},"last_name":{"type":"string","required":true,"visibility":"user-or-llm","description":"Last name of the contact"},"email":{"type":"string","required":false,"visibility":"user-or-llm","description":"Email address of the contact"},"title":{"type":"string","required":false,"visibility":"user-or-llm","description":"Job title (e.g., \\"VP of Sales\\", \\"Software Engineer\\")"},"account_id":{"type":"string","required":false,"visibility":"user-or-llm","description":"Apollo account ID to associate with (e.g., \\"acc_abc123\\")"},"owner_id":{"type":"string","required":false,"visibility":"user-only","description":"User ID of the contact owner (accepted by Apollo but not officially documented for POST /contacts)"},"organization_name":{"type":"string","required":false,"visibility":"user-or-llm","description":"Name of the contact\'s employer (e.g., \\"Apollo\\")"},"website_url":{"type":"string","required":false,"visibility":"user-or-llm","description":"Corporate website URL (e.g., \\"https://www.apollo.io/\\")"},"label_names":{"type":"array","required":false,"visibility":"user-or-llm","description":"Lists/labels to add the contact to (e.g., [\\"Prospects\\"])"},"contact_stage_id":{"type":"string","required":false,"visibility":"user-or-llm","description":"Apollo ID for the contact stage"},"present_raw_address":{"type":"string","required":false,"visibility":"user-or-llm","description":"Personal location for the contact (e.g., \\"Atlanta, United States\\")"},"direct_phone":{"type":"string","required":false,"visibility":"user-or-llm","description":"Primary phone number"},"corporate_phone":{"type":"string","required":false,"visibility":"user-or-llm","description":"Work/office phone number"},"mobile_phone":{"type":"string","required":false,"visibility":"user-or-llm","description":"Mobile phone number"},"home_phone":{"type":"string","required":false,"visibility":"user-or-llm","description":"Home phone number"},"other_phone":{"type":"string","required":false,"visibility":"user-or-llm","description":"Alternative phone number"},"typed_custom_fields":{"type":"json","required":false,"visibility":"user-or-llm","description":"Custom field values keyed by custom field ID"},"run_dedupe":{"type":"boolean","required":false,"visibility":"user-only","description":"When true, Apollo deduplicates against existing contacts"}},"hostedApiKey":"none"},"apollo_contact_search":{"id":"apollo_contact_search","name":"Apollo Search Contacts","description":"Search your team\'s contacts in Apollo","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Apollo API key"},"q_keywords":{"type":"string","required":false,"visibility":"user-or-llm","description":"Keywords to search for"},"contact_stage_ids":{"type":"array","required":false,"visibility":"user-only","description":"Filter by contact stage IDs"},"contact_label_ids":{"type":"array","required":false,"visibility":"user-only","description":"Filter by Apollo label IDs (lists)"},"sort_by_field":{"type":"string","required":false,"visibility":"user-only","description":"Sort field: contact_last_activity_date, contact_email_last_opened_at, contact_email_last_clicked_at, contact_created_at, or contact_updated_at"},"sort_ascending":{"type":"boolean","required":false,"visibility":"user-only","description":"When true, sort ascending. Must be used together with sort_by_field"},"page":{"type":"number","required":false,"visibility":"user-or-llm","description":"Page number for pagination (e.g., 1, 2, 3)"},"per_page":{"type":"number","required":false,"visibility":"user-or-llm","description":"Results per page, max 100 (e.g., 25, 50, 100)"}},"hostedApiKey":"none"},"apollo_contact_update":{"id":"apollo_contact_update","name":"Apollo Update Contact","description":"Update an existing contact in your Apollo database","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Apollo API key"},"contact_id":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the contact to update (e.g., \\"con_abc123\\")"},"first_name":{"type":"string","required":false,"visibility":"user-or-llm","description":"First name of the contact"},"last_name":{"type":"string","required":false,"visibility":"user-or-llm","description":"Last name of the contact"},"email":{"type":"string","required":false,"visibility":"user-or-llm","description":"Email address"},"title":{"type":"string","required":false,"visibility":"user-or-llm","description":"Job title (e.g., \\"VP of Sales\\", \\"Software Engineer\\")"},"account_id":{"type":"string","required":false,"visibility":"user-or-llm","description":"Apollo account ID (e.g., \\"acc_abc123\\")"},"owner_id":{"type":"string","required":false,"visibility":"user-only","description":"User ID of the contact owner (accepted by Apollo but not officially documented for PATCH /contacts/{id})"},"organization_name":{"type":"string","required":false,"visibility":"user-or-llm","description":"Name of the contact\'s employer (e.g., \\"Apollo\\")"},"website_url":{"type":"string","required":false,"visibility":"user-or-llm","description":"Corporate website URL (e.g., \\"https://www.apollo.io/\\")"},"label_names":{"type":"array","required":false,"visibility":"user-or-llm","description":"Lists/labels to add the contact to (e.g., [\\"Prospects\\"])"},"contact_stage_id":{"type":"string","required":false,"visibility":"user-or-llm","description":"Apollo ID for the contact stage"},"present_raw_address":{"type":"string","required":false,"visibility":"user-or-llm","description":"Personal location for the contact (e.g., \\"Atlanta, United States\\")"},"direct_phone":{"type":"string","required":false,"visibility":"user-or-llm","description":"Primary phone number"},"corporate_phone":{"type":"string","required":false,"visibility":"user-or-llm","description":"Work/office phone number"},"mobile_phone":{"type":"string","required":false,"visibility":"user-or-llm","description":"Mobile phone number"},"home_phone":{"type":"string","required":false,"visibility":"user-or-llm","description":"Home phone number"},"other_phone":{"type":"string","required":false,"visibility":"user-or-llm","description":"Alternative phone number"},"typed_custom_fields":{"type":"json","required":false,"visibility":"user-or-llm","description":"Custom field values keyed by custom field ID"}},"hostedApiKey":"none"},"apollo_email_accounts":{"id":"apollo_email_accounts","name":"Apollo Get Email Accounts","description":"Get list of team\'s linked email accounts in Apollo","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Apollo API key (master key required)"}},"hostedApiKey":"none"},"apollo_opportunity_create":{"id":"apollo_opportunity_create","name":"Apollo Create Opportunity","description":"Create a new deal for an account in your Apollo database (master key required)","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Apollo API key (master key required)"},"name":{"type":"string","required":true,"visibility":"user-or-llm","description":"Name of the opportunity/deal (e.g., \\"Enterprise License - Q1\\")"},"account_id":{"type":"string","required":false,"visibility":"user-or-llm","description":"ID of the account this opportunity belongs to (e.g., \\"acc_abc123\\")"},"amount":{"type":"string","required":false,"visibility":"user-or-llm","description":"Monetary value as a plain number string with no commas or currency symbols"},"opportunity_stage_id":{"type":"string","required":false,"visibility":"user-only","description":"ID of the opportunity stage"},"owner_id":{"type":"string","required":false,"visibility":"user-only","description":"User ID of the opportunity owner"},"closed_date":{"type":"string","required":false,"visibility":"user-or-llm","description":"Expected close date in YYYY-MM-DD format"},"typed_custom_fields":{"type":"json","required":false,"visibility":"user-only","description":"Custom field values as { custom_field_id: value } map"}},"hostedApiKey":"none"},"apollo_opportunity_get":{"id":"apollo_opportunity_get","name":"Apollo Get Opportunity","description":"Retrieve complete details of a specific deal/opportunity by ID","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Apollo API key"},"opportunity_id":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the opportunity to retrieve (e.g., \\"opp_abc123\\")"}},"hostedApiKey":"none"},"apollo_opportunity_search":{"id":"apollo_opportunity_search","name":"Apollo Search Opportunities","description":"Search and list all deals/opportunities in your team\'s Apollo account","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Apollo API key"},"sort_by_field":{"type":"string","required":false,"visibility":"user-or-llm","description":"Sort field: \\"amount\\", \\"is_closed\\", or \\"is_won\\""},"page":{"type":"number","required":false,"visibility":"user-or-llm","description":"Page number for pagination (e.g., 1, 2, 3)"},"per_page":{"type":"number","required":false,"visibility":"user-or-llm","description":"Results per page, max 100 (e.g., 25, 50, 100)"}},"hostedApiKey":"none"},"apollo_opportunity_update":{"id":"apollo_opportunity_update","name":"Apollo Update Opportunity","description":"Update an existing deal/opportunity in your Apollo database","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Apollo API key"},"opportunity_id":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the opportunity to update (e.g., \\"opp_abc123\\")"},"name":{"type":"string","required":false,"visibility":"user-or-llm","description":"Name of the opportunity/deal (e.g., \\"Enterprise License - Q1\\")"},"amount":{"type":"string","required":false,"visibility":"user-or-llm","description":"Monetary value as a plain number string with no commas or currency symbols"},"opportunity_stage_id":{"type":"string","required":false,"visibility":"user-only","description":"ID of the opportunity stage"},"owner_id":{"type":"string","required":false,"visibility":"user-only","description":"User ID of the opportunity owner"},"closed_date":{"type":"string","required":false,"visibility":"user-or-llm","description":"Expected close date in YYYY-MM-DD format"},"typed_custom_fields":{"type":"json","required":false,"visibility":"user-only","description":"Custom field values as { custom_field_id: value } map"}},"hostedApiKey":"none"},"apollo_organization_bulk_enrich":{"id":"apollo_organization_bulk_enrich","name":"Apollo Bulk Organization Enrichment","description":"Enrich data for up to 10 organizations at once using Apollo","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Apollo API key"},"domains":{"type":"array","required":true,"visibility":"user-or-llm","description":"Array of company domains to enrich (max 10, no www. or @, e.g., [\\"apollo.io\\", \\"stripe.com\\"])"}},"hostedApiKey":"none"},"apollo_organization_enrich":{"id":"apollo_organization_enrich","name":"Apollo Organization Enrichment","description":"Enrich data for a single organization using Apollo","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Apollo API key"},"domain":{"type":"string","required":true,"visibility":"user-or-llm","description":"Company domain (e.g., \\"apollo.io\\", \\"acme.com\\")"}},"hostedApiKey":"none"},"apollo_organization_search":{"id":"apollo_organization_search","name":"Apollo Organization Search","description":"Search Apollo\'s database for companies using filters","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Apollo API key"},"organization_locations":{"type":"array","required":false,"visibility":"user-or-llm","description":"Company HQ locations (cities, US states, or countries)"},"organization_not_locations":{"type":"array","required":false,"visibility":"user-or-llm","description":"Exclude companies whose HQ is in these locations"},"organization_num_employees_ranges":{"type":"array","required":false,"visibility":"user-or-llm","description":"Employee count ranges as \\"min,max\\" strings (e.g., [\\"1,10\\", \\"250,500\\", \\"10000,20000\\"])"},"q_organization_keyword_tags":{"type":"array","required":false,"visibility":"user-or-llm","description":"Industry or keyword tags"},"q_organization_name":{"type":"string","required":false,"visibility":"user-or-llm","description":"Organization name to search for (e.g., \\"Acme\\", \\"TechCorp\\")"},"organization_ids":{"type":"array","required":false,"visibility":"user-or-llm","description":"Apollo organization IDs to include (e.g., [\\"5e66b6381e05b4008c8331b8\\"])"},"q_organization_domains_list":{"type":"array","required":false,"visibility":"user-or-llm","description":"Domain names to filter by (no www. or @, up to 1,000)"},"page":{"type":"number","required":false,"visibility":"user-or-llm","description":"Page number for pagination (e.g., 1, 2, 3)"},"per_page":{"type":"number","required":false,"visibility":"user-or-llm","description":"Results per page, max 100 (e.g., 25, 50, 100)"}},"hostedApiKey":"none"},"apollo_people_bulk_enrich":{"id":"apollo_people_bulk_enrich","name":"Apollo Bulk People Enrichment","description":"Enrich data for up to 10 people at once using Apollo","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Apollo API key"},"people":{"type":"array","required":true,"visibility":"user-or-llm","description":"Array of people to enrich (max 10)"},"reveal_personal_emails":{"type":"boolean","required":false,"visibility":"user-only","description":"Reveal personal email addresses (uses credits)"},"reveal_phone_number":{"type":"boolean","required":false,"visibility":"user-only","description":"Reveal phone numbers (uses credits, requires webhook_url)"},"webhook_url":{"type":"string","required":false,"visibility":"user-only","description":"Webhook URL for async phone number delivery (required when reveal_phone_number is true)"}},"hostedApiKey":"none"},"apollo_people_enrich":{"id":"apollo_people_enrich","name":"Apollo People Enrichment","description":"Enrich data for a single person using Apollo","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Apollo API key"},"first_name":{"type":"string","required":false,"visibility":"user-or-llm","description":"First name of the person"},"last_name":{"type":"string","required":false,"visibility":"user-or-llm","description":"Last name of the person"},"name":{"type":"string","required":false,"visibility":"user-or-llm","description":"Full name of the person (alternative to first_name/last_name)"},"id":{"type":"string","required":false,"visibility":"user-or-llm","description":"Apollo ID for the person"},"hashed_email":{"type":"string","required":false,"visibility":"user-or-llm","description":"MD5 or SHA-256 hashed email"},"email":{"type":"string","required":false,"visibility":"user-or-llm","description":"Email address of the person"},"organization_name":{"type":"string","required":false,"visibility":"user-or-llm","description":"Company name where the person works"},"domain":{"type":"string","required":false,"visibility":"user-or-llm","description":"Company domain (e.g., \\"apollo.io\\", \\"acme.com\\")"},"linkedin_url":{"type":"string","required":false,"visibility":"user-or-llm","description":"LinkedIn profile URL"},"reveal_personal_emails":{"type":"boolean","required":false,"visibility":"user-only","description":"Reveal personal email addresses (uses credits)"},"reveal_phone_number":{"type":"boolean","required":false,"visibility":"user-only","description":"Reveal phone numbers (uses credits, requires webhook_url)"},"webhook_url":{"type":"string","required":false,"visibility":"user-only","description":"Webhook URL for async phone number delivery (required when reveal_phone_number is true)"}},"hostedApiKey":"none"},"apollo_people_search":{"id":"apollo_people_search","name":"Apollo People Search","description":"Search Apollo\'s database for people using demographic filters","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Apollo API key"},"person_titles":{"type":"array","required":false,"visibility":"user-or-llm","description":"Job titles to search for (e.g., [\\"CEO\\", \\"VP of Sales\\"])"},"include_similar_titles":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Whether to return people with job titles similar to person_titles"},"person_locations":{"type":"array","required":false,"visibility":"user-or-llm","description":"Locations to search in (e.g., [\\"San Francisco, CA\\", \\"New York, NY\\"])"},"person_seniorities":{"type":"array","required":false,"visibility":"user-or-llm","description":"Seniority levels (one of: owner, founder, c_suite, partner, vp, head, director, manager, senior, entry, intern)"},"organization_ids":{"type":"array","required":false,"visibility":"user-or-llm","description":"Apollo organization IDs to filter by (e.g., [\\"5e66b6381e05b4008c8331b8\\"])"},"organization_names":{"type":"array","required":false,"visibility":"user-or-llm","description":"Company names to search within (legacy filter)"},"organization_locations":{"type":"array","required":false,"visibility":"user-or-llm","description":"Headquarters locations of the people\'s current employer (e.g., [\'texas\', \'tokyo\', \'spain\'])"},"q_organization_domains_list":{"type":"array","required":false,"visibility":"user-or-llm","description":"Employer domain names (e.g., [\\"apollo.io\\", \\"microsoft.com\\"]) — up to 1,000, no www. or @"},"organization_num_employees_ranges":{"type":"array","required":false,"visibility":"user-or-llm","description":"Employee count ranges for the person\'s current employer. Each entry is \\"min,max\\" (e.g., [\\"1,10\\", \\"250,500\\", \\"10000,20000\\"])"},"contact_email_status":{"type":"array","required":false,"visibility":"user-or-llm","description":"Email statuses to filter by: \\"verified\\", \\"unverified\\", \\"likely to engage\\", \\"unavailable\\""},"q_keywords":{"type":"string","required":false,"visibility":"user-or-llm","description":"Keywords to search for"},"page":{"type":"number","required":false,"visibility":"user-or-llm","description":"Page number for pagination, default 1 (e.g., 1, 2, 3)"},"per_page":{"type":"number","required":false,"visibility":"user-or-llm","description":"Results per page, default 25, max 100 (e.g., 25, 50, 100)"}},"hostedApiKey":"none"},"apollo_sequence_add_contacts":{"id":"apollo_sequence_add_contacts","name":"Apollo Add Contacts to Sequence","description":"Add contacts to an Apollo sequence","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Apollo API key (master key required)"},"sequence_id":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the sequence to add contacts to (e.g., \\"seq_abc123\\")"},"contact_ids":{"type":"array","required":false,"visibility":"user-or-llm","description":"Array of contact IDs to add to the sequence (e.g., [\\"con_abc123\\", \\"con_def456\\"]). Either contact_ids or label_names must be provided."},"label_names":{"type":"array","required":false,"visibility":"user-or-llm","description":"Array of label names to identify contacts to add to the sequence. Either contact_ids or label_names must be provided."},"send_email_from_email_account_id":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the email account to send from. Use the Get Email Accounts operation to look this up."},"send_email_from_email_address":{"type":"string","required":false,"visibility":"user-only","description":"Specific email address to send from within the email account."},"sequence_no_email":{"type":"boolean","required":false,"visibility":"user-only","description":"Add contacts even if they have no email address"},"sequence_unverified_email":{"type":"boolean","required":false,"visibility":"user-only","description":"Add contacts with unverified email addresses"},"sequence_job_change":{"type":"boolean","required":false,"visibility":"user-only","description":"Add contacts who recently changed jobs"},"sequence_active_in_other_campaigns":{"type":"boolean","required":false,"visibility":"user-only","description":"Add contacts active in other campaigns"},"sequence_finished_in_other_campaigns":{"type":"boolean","required":false,"visibility":"user-only","description":"Add contacts who finished other campaigns"},"sequence_same_company_in_same_campaign":{"type":"boolean","required":false,"visibility":"user-only","description":"Add contacts even if others from the same company are in the sequence"},"contacts_without_ownership_permission":{"type":"boolean","required":false,"visibility":"user-only","description":"Add contacts without ownership permission"},"add_if_in_queue":{"type":"boolean","required":false,"visibility":"user-only","description":"Add contacts even if they are in the queue"},"contact_verification_skipped":{"type":"boolean","required":false,"visibility":"user-only","description":"Skip contact verification when adding"},"user_id":{"type":"string","required":false,"visibility":"user-only","description":"ID of the user performing the action"},"status":{"type":"string","required":false,"visibility":"user-only","description":"Initial status for added contacts: \\"active\\" or \\"paused\\""},"auto_unpause_at":{"type":"string","required":false,"visibility":"user-only","description":"ISO 8601 datetime to automatically unpause contacts"}},"hostedApiKey":"none"},"apollo_sequence_search":{"id":"apollo_sequence_search","name":"Apollo Search Sequences","description":"Search for sequences/campaigns in your team\'s Apollo account (master key required)","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Apollo API key (master key required)"},"q_name":{"type":"string","required":false,"visibility":"user-or-llm","description":"Search sequences by name (e.g., \\"Outbound Q1\\", \\"Follow-up\\")"},"page":{"type":"number","required":false,"visibility":"user-or-llm","description":"Page number for pagination (e.g., 1, 2, 3)"},"per_page":{"type":"number","required":false,"visibility":"user-or-llm","description":"Results per page, max 100 (e.g., 25, 50, 100)"}},"hostedApiKey":"none"},"apollo_task_create":{"id":"apollo_task_create","name":"Apollo Create Task","description":"Create one or more tasks in Apollo (one task per contact_id, master key required)","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Apollo API key (master key required)"},"user_id":{"type":"string","required":true,"visibility":"user-or-llm","description":"ID of the Apollo user the task is assigned to"},"contact_ids":{"type":"array","required":true,"visibility":"user-or-llm","description":"Array of contact IDs. One task is created per contact."},"priority":{"type":"string","required":false,"visibility":"user-or-llm","description":"Task priority: \\"high\\", \\"medium\\", or \\"low\\" (defaults to \\"medium\\")"},"due_at":{"type":"string","required":true,"visibility":"user-or-llm","description":"Due date/time in ISO 8601 format (e.g., \\"2024-12-31T23:59:59Z\\")"},"type":{"type":"string","required":true,"visibility":"user-or-llm","description":"Task type: \\"call\\", \\"outreach_manual_email\\", \\"linkedin_step_connect\\", \\"linkedin_step_message\\", \\"linkedin_step_view_profile\\", \\"linkedin_step_interact_post\\", or \\"action_item\\""},"status":{"type":"string","required":true,"visibility":"user-or-llm","description":"Task status: \\"scheduled\\", \\"completed\\", or \\"skipped\\""},"note":{"type":"string","required":false,"visibility":"user-or-llm","description":"Free-form note providing context for the task"}},"hostedApiKey":"none"},"apollo_task_search":{"id":"apollo_task_search","name":"Apollo Search Tasks","description":"Search for tasks in Apollo","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Apollo API key (master key required)"},"sort_by_field":{"type":"string","required":false,"visibility":"user-or-llm","description":"Sort field: \\"task_due_at\\" or \\"task_priority\\""},"open_factor_names":{"type":"array","required":false,"visibility":"user-or-llm","description":"Filter by status. Common values: [\\"task_types\\"] for open tasks, [\\"task_completed_at\\"] for completed tasks."},"page":{"type":"number","required":false,"visibility":"user-or-llm","description":"Page number for pagination (e.g., 1, 2, 3)"},"per_page":{"type":"number","required":false,"visibility":"user-or-llm","description":"Results per page, max 100 (e.g., 25, 50, 100)"}},"hostedApiKey":"none"},"appconfig_create_application":{"id":"appconfig_create_application","name":"AppConfig Create Application","description":"Create an application in AWS AppConfig","version":"1.0","params":{"region":{"type":"string","required":true,"visibility":"user-only","description":"AWS region (e.g., us-east-1)"},"accessKeyId":{"type":"string","required":true,"visibility":"user-only","description":"AWS access key ID"},"secretAccessKey":{"type":"string","required":true,"visibility":"user-only","description":"AWS secret access key"},"name":{"type":"string","required":true,"visibility":"user-or-llm","description":"Name of the application to create"},"description":{"type":"string","required":false,"visibility":"user-or-llm","description":"Description of the application"}},"hostedApiKey":"none"},"appconfig_create_configuration_profile":{"id":"appconfig_create_configuration_profile","name":"AppConfig Create Configuration Profile","description":"Create a configuration profile in an AWS AppConfig application","version":"1.0","params":{"region":{"type":"string","required":true,"visibility":"user-only","description":"AWS region (e.g., us-east-1)"},"accessKeyId":{"type":"string","required":true,"visibility":"user-only","description":"AWS access key ID"},"secretAccessKey":{"type":"string","required":true,"visibility":"user-only","description":"AWS secret access key"},"applicationId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The application ID to create the configuration profile in"},"name":{"type":"string","required":true,"visibility":"user-or-llm","description":"Name of the configuration profile"},"locationUri":{"type":"string","required":true,"visibility":"user-or-llm","description":"Where the configuration is stored. Use \\"hosted\\" for AppConfig-hosted configurations, or an SSM/S3 URI"},"description":{"type":"string","required":false,"visibility":"user-or-llm","description":"Description of the configuration profile"},"retrievalRoleArn":{"type":"string","required":false,"visibility":"user-or-llm","description":"ARN of an IAM role to retrieve the configuration (required for non-hosted URIs)"},"type":{"type":"string","required":false,"visibility":"user-or-llm","description":"Profile type: AWS.Freeform (default) or AWS.AppConfig.FeatureFlags"}},"hostedApiKey":"none"},"appconfig_create_environment":{"id":"appconfig_create_environment","name":"AppConfig Create Environment","description":"Create an environment for an AWS AppConfig application","version":"1.0","params":{"region":{"type":"string","required":true,"visibility":"user-only","description":"AWS region (e.g., us-east-1)"},"accessKeyId":{"type":"string","required":true,"visibility":"user-only","description":"AWS access key ID"},"secretAccessKey":{"type":"string","required":true,"visibility":"user-only","description":"AWS secret access key"},"applicationId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The application ID to create the environment in"},"name":{"type":"string","required":true,"visibility":"user-or-llm","description":"Name of the environment to create"},"description":{"type":"string","required":false,"visibility":"user-or-llm","description":"Description of the environment"}},"hostedApiKey":"none"},"appconfig_create_hosted_configuration_version":{"id":"appconfig_create_hosted_configuration_version","name":"AppConfig Create Hosted Configuration Version","description":"Create a new hosted configuration version for an AppConfig configuration profile","version":"1.0","params":{"region":{"type":"string","required":true,"visibility":"user-only","description":"AWS region (e.g., us-east-1)"},"accessKeyId":{"type":"string","required":true,"visibility":"user-only","description":"AWS access key ID"},"secretAccessKey":{"type":"string","required":true,"visibility":"user-only","description":"AWS secret access key"},"applicationId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The application ID that owns the configuration profile"},"configurationProfileId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The configuration profile ID to add the version to"},"content":{"type":"string","required":true,"visibility":"user-or-llm","description":"The configuration content (e.g., a JSON or YAML document)"},"contentType":{"type":"string","required":true,"visibility":"user-or-llm","description":"Content type of the configuration (e.g., application/json, text/plain)"},"description":{"type":"string","required":false,"visibility":"user-or-llm","description":"Description of the configuration version"},"latestVersionNumber":{"type":"number","required":false,"visibility":"user-or-llm","description":"The version number of the latest version, used for optimistic concurrency"},"versionLabel":{"type":"string","required":false,"visibility":"user-or-llm","description":"A user-defined label for the configuration version"}},"hostedApiKey":"none"},"appconfig_delete_application":{"id":"appconfig_delete_application","name":"AppConfig Delete Application","description":"Delete an AWS AppConfig application","version":"1.0","params":{"region":{"type":"string","required":true,"visibility":"user-only","description":"AWS region (e.g., us-east-1)"},"accessKeyId":{"type":"string","required":true,"visibility":"user-only","description":"AWS access key ID"},"secretAccessKey":{"type":"string","required":true,"visibility":"user-only","description":"AWS secret access key"},"applicationId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The application ID to delete"}},"hostedApiKey":"none"},"appconfig_delete_configuration_profile":{"id":"appconfig_delete_configuration_profile","name":"AppConfig Delete Configuration Profile","description":"Delete an AWS AppConfig configuration profile","version":"1.0","params":{"region":{"type":"string","required":true,"visibility":"user-only","description":"AWS region (e.g., us-east-1)"},"accessKeyId":{"type":"string","required":true,"visibility":"user-only","description":"AWS access key ID"},"secretAccessKey":{"type":"string","required":true,"visibility":"user-only","description":"AWS secret access key"},"applicationId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The application ID that owns the configuration profile"},"configurationProfileId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The configuration profile ID to delete"}},"hostedApiKey":"none"},"appconfig_delete_environment":{"id":"appconfig_delete_environment","name":"AppConfig Delete Environment","description":"Delete an AWS AppConfig environment","version":"1.0","params":{"region":{"type":"string","required":true,"visibility":"user-only","description":"AWS region (e.g., us-east-1)"},"accessKeyId":{"type":"string","required":true,"visibility":"user-only","description":"AWS access key ID"},"secretAccessKey":{"type":"string","required":true,"visibility":"user-only","description":"AWS secret access key"},"applicationId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The application ID that owns the environment"},"environmentId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The environment ID to delete"}},"hostedApiKey":"none"},"appconfig_delete_hosted_configuration_version":{"id":"appconfig_delete_hosted_configuration_version","name":"AppConfig Delete Hosted Configuration Version","description":"Delete a specific hosted configuration version from an AppConfig profile","version":"1.0","params":{"region":{"type":"string","required":true,"visibility":"user-only","description":"AWS region (e.g., us-east-1)"},"accessKeyId":{"type":"string","required":true,"visibility":"user-only","description":"AWS access key ID"},"secretAccessKey":{"type":"string","required":true,"visibility":"user-only","description":"AWS secret access key"},"applicationId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The application ID that owns the configuration profile"},"configurationProfileId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The configuration profile ID that owns the version"},"versionNumber":{"type":"number","required":true,"visibility":"user-or-llm","description":"The version number to delete"}},"hostedApiKey":"none"},"appconfig_get_application":{"id":"appconfig_get_application","name":"AppConfig Get Application","description":"Get details about a single AWS AppConfig application","version":"1.0","params":{"region":{"type":"string","required":true,"visibility":"user-only","description":"AWS region (e.g., us-east-1)"},"accessKeyId":{"type":"string","required":true,"visibility":"user-only","description":"AWS access key ID"},"secretAccessKey":{"type":"string","required":true,"visibility":"user-only","description":"AWS secret access key"},"applicationId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The application ID to retrieve"}},"hostedApiKey":"none"},"appconfig_get_configuration":{"id":"appconfig_get_configuration","name":"AppConfig Get Configuration","description":"Retrieve the latest deployed configuration for an AppConfig application, environment, and profile","version":"1.0","params":{"region":{"type":"string","required":true,"visibility":"user-only","description":"AWS region (e.g., us-east-1)"},"accessKeyId":{"type":"string","required":true,"visibility":"user-only","description":"AWS access key ID"},"secretAccessKey":{"type":"string","required":true,"visibility":"user-only","description":"AWS secret access key"},"applicationId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The application ID or name to retrieve configuration for"},"environmentId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The environment ID or name to retrieve configuration for"},"configurationProfileId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The configuration profile ID or name to retrieve"}},"hostedApiKey":"none"},"appconfig_get_configuration_profile":{"id":"appconfig_get_configuration_profile","name":"AppConfig Get Configuration Profile","description":"Get details about a single AWS AppConfig configuration profile","version":"1.0","params":{"region":{"type":"string","required":true,"visibility":"user-only","description":"AWS region (e.g., us-east-1)"},"accessKeyId":{"type":"string","required":true,"visibility":"user-only","description":"AWS access key ID"},"secretAccessKey":{"type":"string","required":true,"visibility":"user-only","description":"AWS secret access key"},"applicationId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The application ID that owns the configuration profile"},"configurationProfileId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The configuration profile ID to retrieve"}},"hostedApiKey":"none"},"appconfig_get_deployment":{"id":"appconfig_get_deployment","name":"AppConfig Get Deployment","description":"Get details about a specific AWS AppConfig deployment","version":"1.0","params":{"region":{"type":"string","required":true,"visibility":"user-only","description":"AWS region (e.g., us-east-1)"},"accessKeyId":{"type":"string","required":true,"visibility":"user-only","description":"AWS access key ID"},"secretAccessKey":{"type":"string","required":true,"visibility":"user-only","description":"AWS secret access key"},"applicationId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The application ID of the deployment"},"environmentId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The environment ID of the deployment"},"deploymentNumber":{"type":"number","required":true,"visibility":"user-or-llm","description":"The sequence number of the deployment"}},"hostedApiKey":"none"},"appconfig_get_environment":{"id":"appconfig_get_environment","name":"AppConfig Get Environment","description":"Get details about a single AWS AppConfig environment","version":"1.0","params":{"region":{"type":"string","required":true,"visibility":"user-only","description":"AWS region (e.g., us-east-1)"},"accessKeyId":{"type":"string","required":true,"visibility":"user-only","description":"AWS access key ID"},"secretAccessKey":{"type":"string","required":true,"visibility":"user-only","description":"AWS secret access key"},"applicationId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The application ID that owns the environment"},"environmentId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The environment ID to retrieve"}},"hostedApiKey":"none"},"appconfig_get_hosted_configuration_version":{"id":"appconfig_get_hosted_configuration_version","name":"AppConfig Get Hosted Configuration Version","description":"Retrieve a specific hosted configuration version from an AppConfig profile","version":"1.0","params":{"region":{"type":"string","required":true,"visibility":"user-only","description":"AWS region (e.g., us-east-1)"},"accessKeyId":{"type":"string","required":true,"visibility":"user-only","description":"AWS access key ID"},"secretAccessKey":{"type":"string","required":true,"visibility":"user-only","description":"AWS secret access key"},"applicationId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The application ID that owns the configuration profile"},"configurationProfileId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The configuration profile ID to read the version from"},"versionNumber":{"type":"number","required":true,"visibility":"user-or-llm","description":"The version number to retrieve"}},"hostedApiKey":"none"},"appconfig_list_applications":{"id":"appconfig_list_applications","name":"AppConfig List Applications","description":"List applications in AWS AppConfig","version":"1.0","params":{"region":{"type":"string","required":true,"visibility":"user-only","description":"AWS region (e.g., us-east-1)"},"accessKeyId":{"type":"string","required":true,"visibility":"user-only","description":"AWS access key ID"},"secretAccessKey":{"type":"string","required":true,"visibility":"user-only","description":"AWS secret access key"},"maxResults":{"type":"number","required":false,"visibility":"user-or-llm","description":"Maximum number of applications to return (1-50)"},"nextToken":{"type":"string","required":false,"visibility":"user-or-llm","description":"Pagination token from a previous response"}},"hostedApiKey":"none"},"appconfig_list_configuration_profiles":{"id":"appconfig_list_configuration_profiles","name":"AppConfig List Configuration Profiles","description":"List configuration profiles for an AWS AppConfig application","version":"1.0","params":{"region":{"type":"string","required":true,"visibility":"user-only","description":"AWS region (e.g., us-east-1)"},"accessKeyId":{"type":"string","required":true,"visibility":"user-only","description":"AWS access key ID"},"secretAccessKey":{"type":"string","required":true,"visibility":"user-only","description":"AWS secret access key"},"applicationId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The application ID that owns the configuration profiles"},"maxResults":{"type":"number","required":false,"visibility":"user-or-llm","description":"Maximum number of configuration profiles to return (1-50)"},"nextToken":{"type":"string","required":false,"visibility":"user-or-llm","description":"Pagination token from a previous response"}},"hostedApiKey":"none"},"appconfig_list_deployment_strategies":{"id":"appconfig_list_deployment_strategies","name":"AppConfig List Deployment Strategies","description":"List deployment strategies available in AWS AppConfig","version":"1.0","params":{"region":{"type":"string","required":true,"visibility":"user-only","description":"AWS region (e.g., us-east-1)"},"accessKeyId":{"type":"string","required":true,"visibility":"user-only","description":"AWS access key ID"},"secretAccessKey":{"type":"string","required":true,"visibility":"user-only","description":"AWS secret access key"},"maxResults":{"type":"number","required":false,"visibility":"user-or-llm","description":"Maximum number of deployment strategies to return (1-50)"},"nextToken":{"type":"string","required":false,"visibility":"user-or-llm","description":"Pagination token from a previous response"}},"hostedApiKey":"none"},"appconfig_list_deployments":{"id":"appconfig_list_deployments","name":"AppConfig List Deployments","description":"List deployments for an AWS AppConfig environment","version":"1.0","params":{"region":{"type":"string","required":true,"visibility":"user-only","description":"AWS region (e.g., us-east-1)"},"accessKeyId":{"type":"string","required":true,"visibility":"user-only","description":"AWS access key ID"},"secretAccessKey":{"type":"string","required":true,"visibility":"user-only","description":"AWS secret access key"},"applicationId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The application ID of the deployments"},"environmentId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The environment ID of the deployments"},"maxResults":{"type":"number","required":false,"visibility":"user-or-llm","description":"Maximum number of deployments to return (1-50)"},"nextToken":{"type":"string","required":false,"visibility":"user-or-llm","description":"Pagination token from a previous response"}},"hostedApiKey":"none"},"appconfig_list_environments":{"id":"appconfig_list_environments","name":"AppConfig List Environments","description":"List environments for an AWS AppConfig application","version":"1.0","params":{"region":{"type":"string","required":true,"visibility":"user-only","description":"AWS region (e.g., us-east-1)"},"accessKeyId":{"type":"string","required":true,"visibility":"user-only","description":"AWS access key ID"},"secretAccessKey":{"type":"string","required":true,"visibility":"user-only","description":"AWS secret access key"},"applicationId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The application ID that owns the environments"},"maxResults":{"type":"number","required":false,"visibility":"user-or-llm","description":"Maximum number of environments to return (1-50)"},"nextToken":{"type":"string","required":false,"visibility":"user-or-llm","description":"Pagination token from a previous response"}},"hostedApiKey":"none"},"appconfig_list_hosted_configuration_versions":{"id":"appconfig_list_hosted_configuration_versions","name":"AppConfig List Hosted Configuration Versions","description":"List hosted configuration versions for an AWS AppConfig configuration profile","version":"1.0","params":{"region":{"type":"string","required":true,"visibility":"user-only","description":"AWS region (e.g., us-east-1)"},"accessKeyId":{"type":"string","required":true,"visibility":"user-only","description":"AWS access key ID"},"secretAccessKey":{"type":"string","required":true,"visibility":"user-only","description":"AWS secret access key"},"applicationId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The application ID that owns the configuration profile"},"configurationProfileId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The configuration profile ID to list versions for"},"maxResults":{"type":"number","required":false,"visibility":"user-or-llm","description":"Maximum number of versions to return (1-50)"},"nextToken":{"type":"string","required":false,"visibility":"user-or-llm","description":"Pagination token from a previous response"}},"hostedApiKey":"none"},"appconfig_start_deployment":{"id":"appconfig_start_deployment","name":"AppConfig Start Deployment","description":"Start deploying a configuration version to an AWS AppConfig environment","version":"1.0","params":{"region":{"type":"string","required":true,"visibility":"user-only","description":"AWS region (e.g., us-east-1)"},"accessKeyId":{"type":"string","required":true,"visibility":"user-only","description":"AWS access key ID"},"secretAccessKey":{"type":"string","required":true,"visibility":"user-only","description":"AWS secret access key"},"applicationId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The application ID to deploy in"},"environmentId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The environment ID to deploy to"},"deploymentStrategyId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The deployment strategy ID to use"},"configurationProfileId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The configuration profile ID to deploy"},"configurationVersion":{"type":"string","required":true,"visibility":"user-or-llm","description":"The configuration version to deploy"},"description":{"type":"string","required":false,"visibility":"user-or-llm","description":"Description of the deployment"}},"hostedApiKey":"none"},"appconfig_stop_deployment":{"id":"appconfig_stop_deployment","name":"AppConfig Stop Deployment","description":"Stop an in-progress AWS AppConfig deployment","version":"1.0","params":{"region":{"type":"string","required":true,"visibility":"user-only","description":"AWS region (e.g., us-east-1)"},"accessKeyId":{"type":"string","required":true,"visibility":"user-only","description":"AWS access key ID"},"secretAccessKey":{"type":"string","required":true,"visibility":"user-only","description":"AWS secret access key"},"applicationId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The application ID of the deployment"},"environmentId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The environment ID of the deployment"},"deploymentNumber":{"type":"number","required":true,"visibility":"user-or-llm","description":"The sequence number of the deployment to stop"}},"hostedApiKey":"none"},"appconfig_update_application":{"id":"appconfig_update_application","name":"AppConfig Update Application","description":"Update the name or description of an AWS AppConfig application","version":"1.0","params":{"region":{"type":"string","required":true,"visibility":"user-only","description":"AWS region (e.g., us-east-1)"},"accessKeyId":{"type":"string","required":true,"visibility":"user-only","description":"AWS access key ID"},"secretAccessKey":{"type":"string","required":true,"visibility":"user-only","description":"AWS secret access key"},"applicationId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The application ID to update"},"name":{"type":"string","required":false,"visibility":"user-or-llm","description":"New name for the application"},"description":{"type":"string","required":false,"visibility":"user-or-llm","description":"New description for the application"}},"hostedApiKey":"none"},"appconfig_update_configuration_profile":{"id":"appconfig_update_configuration_profile","name":"AppConfig Update Configuration Profile","description":"Update the name, description, or retrieval role of an AppConfig configuration profile","version":"1.0","params":{"region":{"type":"string","required":true,"visibility":"user-only","description":"AWS region (e.g., us-east-1)"},"accessKeyId":{"type":"string","required":true,"visibility":"user-only","description":"AWS access key ID"},"secretAccessKey":{"type":"string","required":true,"visibility":"user-only","description":"AWS secret access key"},"applicationId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The application ID that owns the configuration profile"},"configurationProfileId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The configuration profile ID to update"},"name":{"type":"string","required":false,"visibility":"user-or-llm","description":"New name for the configuration profile"},"description":{"type":"string","required":false,"visibility":"user-or-llm","description":"New description for the configuration profile"},"retrievalRoleArn":{"type":"string","required":false,"visibility":"user-or-llm","description":"New ARN of the IAM role used to retrieve the configuration"}},"hostedApiKey":"none"},"appconfig_update_environment":{"id":"appconfig_update_environment","name":"AppConfig Update Environment","description":"Update the name or description of an AWS AppConfig environment","version":"1.0","params":{"region":{"type":"string","required":true,"visibility":"user-only","description":"AWS region (e.g., us-east-1)"},"accessKeyId":{"type":"string","required":true,"visibility":"user-only","description":"AWS access key ID"},"secretAccessKey":{"type":"string","required":true,"visibility":"user-only","description":"AWS secret access key"},"applicationId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The application ID that owns the environment"},"environmentId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The environment ID to update"},"name":{"type":"string","required":false,"visibility":"user-or-llm","description":"New name for the environment"},"description":{"type":"string","required":false,"visibility":"user-or-llm","description":"New description for the environment"}},"hostedApiKey":"none"},"arxiv_get_author_papers":{"id":"arxiv_get_author_papers","name":"ArXiv Get Author Papers","description":"Search for papers by a specific author on ArXiv.","version":"1.0.0","params":{"authorName":{"type":"string","required":true,"visibility":"user-or-llm","description":"Author name to search for"},"maxResults":{"type":"number","required":false,"visibility":"user-only","description":"Maximum number of results to return (default: 10, max: 2000)"}},"hostedApiKey":"none"},"arxiv_get_paper":{"id":"arxiv_get_paper","name":"ArXiv Get Paper","description":"Get detailed information about a specific ArXiv paper by its ID.","version":"1.0.0","params":{"paperId":{"type":"string","required":true,"visibility":"user-or-llm","description":"ArXiv paper ID (e.g., \\"1706.03762\\")"}},"hostedApiKey":"none"},"arxiv_search":{"id":"arxiv_search","name":"ArXiv Search","description":"Search for academic papers on ArXiv by keywords, authors, titles, or other fields.","version":"1.0.0","params":{"searchQuery":{"type":"string","required":true,"visibility":"user-or-llm","description":"The search query to execute"},"searchField":{"type":"string","required":false,"visibility":"user-only","description":"Field to search in: all, ti (title), au (author), abs (abstract), co (comment), jr (journal), cat (category), rn (report number)"},"maxResults":{"type":"number","required":false,"visibility":"user-only","description":"Maximum number of results to return (default: 10, max: 2000)"},"sortBy":{"type":"string","required":false,"visibility":"user-only","description":"Sort by: relevance, lastUpdatedDate, submittedDate (default: relevance)"},"sortOrder":{"type":"string","required":false,"visibility":"user-only","description":"Sort order: ascending, descending (default: descending)"}},"hostedApiKey":"none"},"asana_add_comment":{"id":"asana_add_comment","name":"Asana Add Comment","description":"Add a comment (story) to an Asana task","version":"1.0.0","params":{"accessToken":{"type":"string","required":true,"visibility":"hidden","description":"OAuth access token for Asana"},"taskGid":{"type":"string","required":true,"visibility":"user-or-llm","description":"Asana task GID (numeric string)"},"text":{"type":"string","required":true,"visibility":"user-or-llm","description":"The text content of the comment"}},"oauth":{"required":true,"provider":"asana"},"hostedApiKey":"none"},"asana_add_followers":{"id":"asana_add_followers","name":"Asana Add Followers","description":"Add one or more followers to an Asana task","version":"1.0.0","params":{"accessToken":{"type":"string","required":true,"visibility":"hidden","description":"OAuth access token for Asana"},"taskGid":{"type":"string","required":true,"visibility":"user-or-llm","description":"GID of the Asana task (numeric string)"},"followers":{"type":"array","required":true,"visibility":"user-or-llm","description":"Array of user GIDs to add as followers to the task"}},"oauth":{"required":true,"provider":"asana"},"hostedApiKey":"none"},"asana_create_project":{"id":"asana_create_project","name":"Asana Create Project","description":"Create a new project in an Asana workspace","version":"1.0.0","params":{"accessToken":{"type":"string","required":true,"visibility":"hidden","description":"OAuth access token for Asana"},"workspace":{"type":"string","required":true,"visibility":"user-or-llm","description":"Asana workspace GID (numeric string) where the project will be created"},"name":{"type":"string","required":true,"visibility":"user-or-llm","description":"Name of the project"},"notes":{"type":"string","required":false,"visibility":"user-or-llm","description":"Notes or description for the project"}},"oauth":{"required":true,"provider":"asana"},"hostedApiKey":"none"},"asana_create_section":{"id":"asana_create_section","name":"Asana Create Section","description":"Create a new section in an Asana project","version":"1.0.0","params":{"accessToken":{"type":"string","required":true,"visibility":"hidden","description":"OAuth access token for Asana"},"projectGid":{"type":"string","required":true,"visibility":"user-or-llm","description":"GID of the Asana project (numeric string) to add the section to"},"name":{"type":"string","required":true,"visibility":"user-or-llm","description":"Name of the section"}},"oauth":{"required":true,"provider":"asana"},"hostedApiKey":"none"},"asana_create_subtask":{"id":"asana_create_subtask","name":"Asana Create Subtask","description":"Create a subtask under an existing Asana task","version":"1.0.0","params":{"accessToken":{"type":"string","required":true,"visibility":"hidden","description":"OAuth access token for Asana"},"taskGid":{"type":"string","required":true,"visibility":"user-or-llm","description":"GID of the parent Asana task (numeric string)"},"name":{"type":"string","required":true,"visibility":"user-or-llm","description":"Name of the subtask"},"notes":{"type":"string","required":false,"visibility":"user-or-llm","description":"Notes or description for the subtask"},"assignee":{"type":"string","required":false,"visibility":"user-or-llm","description":"User GID to assign the subtask to"},"due_on":{"type":"string","required":false,"visibility":"user-or-llm","description":"Due date in YYYY-MM-DD format"}},"oauth":{"required":true,"provider":"asana"},"hostedApiKey":"none"},"asana_create_task":{"id":"asana_create_task","name":"Asana Create Task","description":"Create a new task in Asana","version":"1.0.0","params":{"accessToken":{"type":"string","required":true,"visibility":"hidden","description":"OAuth access token for Asana"},"workspace":{"type":"string","required":true,"visibility":"user-or-llm","description":"Asana workspace GID (numeric string) where the task will be created"},"name":{"type":"string","required":true,"visibility":"user-or-llm","description":"Name of the task"},"notes":{"type":"string","required":false,"visibility":"user-or-llm","description":"Notes or description for the task"},"assignee":{"type":"string","required":false,"visibility":"user-or-llm","description":"User GID to assign the task to"},"due_on":{"type":"string","required":false,"visibility":"user-or-llm","description":"Due date in YYYY-MM-DD format"}},"oauth":{"required":true,"provider":"asana"},"hostedApiKey":"none"},"asana_delete_task":{"id":"asana_delete_task","name":"Asana Delete Task","description":"Delete an Asana task by its GID (moves it to the trash)","version":"1.0.0","params":{"accessToken":{"type":"string","required":true,"visibility":"hidden","description":"OAuth access token for Asana"},"taskGid":{"type":"string","required":true,"visibility":"user-or-llm","description":"GID of the Asana task to delete (numeric string)"}},"oauth":{"required":true,"provider":"asana"},"hostedApiKey":"none"},"asana_get_project":{"id":"asana_get_project","name":"Asana Get Project","description":"Retrieve a single Asana project by its GID","version":"1.0.0","params":{"accessToken":{"type":"string","required":true,"visibility":"hidden","description":"OAuth access token for Asana"},"projectGid":{"type":"string","required":true,"visibility":"user-or-llm","description":"Asana project GID (numeric string) to retrieve"}},"oauth":{"required":true,"provider":"asana"},"hostedApiKey":"none"},"asana_get_projects":{"id":"asana_get_projects","name":"Asana Get Projects","description":"Retrieve all projects from an Asana workspace","version":"1.0.0","params":{"accessToken":{"type":"string","required":true,"visibility":"hidden","description":"OAuth access token for Asana"},"workspace":{"type":"string","required":true,"visibility":"user-or-llm","description":"Asana workspace GID (numeric string) to retrieve projects from"}},"oauth":{"required":true,"provider":"asana"},"hostedApiKey":"none"},"asana_get_task":{"id":"asana_get_task","name":"Asana Get Task","description":"Retrieve a single task by GID or get multiple tasks with filters","version":"1.0.0","params":{"accessToken":{"type":"string","required":true,"visibility":"hidden","description":"OAuth access token for Asana"},"taskGid":{"type":"string","required":false,"visibility":"user-or-llm","description":"The globally unique identifier (GID) of the task. If not provided, will get multiple tasks."},"workspace":{"type":"string","required":false,"visibility":"user-or-llm","description":"Asana workspace GID (numeric string) to filter tasks (required when not using taskGid)"},"project":{"type":"string","required":false,"visibility":"user-or-llm","description":"Asana project GID (numeric string) to filter tasks"},"limit":{"type":"number","required":false,"visibility":"user-or-llm","description":"Maximum number of tasks to return (default: 50)"}},"oauth":{"required":true,"provider":"asana"},"hostedApiKey":"none"},"asana_list_sections":{"id":"asana_list_sections","name":"Asana List Sections","description":"List all sections in an Asana project","version":"1.0.0","params":{"accessToken":{"type":"string","required":true,"visibility":"hidden","description":"OAuth access token for Asana"},"projectGid":{"type":"string","required":true,"visibility":"user-or-llm","description":"GID of the Asana project (numeric string) to list sections from"}},"oauth":{"required":true,"provider":"asana"},"hostedApiKey":"none"},"asana_list_workspaces":{"id":"asana_list_workspaces","name":"Asana List Workspaces","description":"List all Asana workspaces and organizations the authenticated user belongs to","version":"1.0.0","params":{"accessToken":{"type":"string","required":true,"visibility":"hidden","description":"OAuth access token for Asana"}},"oauth":{"required":true,"provider":"asana"},"hostedApiKey":"none"},"asana_search_tasks":{"id":"asana_search_tasks","name":"Asana Search Tasks","description":"Search for tasks in an Asana workspace","version":"1.0.0","params":{"accessToken":{"type":"string","required":true,"visibility":"hidden","description":"OAuth access token for Asana"},"workspace":{"type":"string","required":true,"visibility":"user-or-llm","description":"Asana workspace GID (numeric string) to search tasks in"},"text":{"type":"string","required":false,"visibility":"user-or-llm","description":"Text to search for in task names"},"assignee":{"type":"string","required":false,"visibility":"user-or-llm","description":"Filter tasks by assignee user GID"},"projects":{"type":"array","required":false,"visibility":"user-or-llm","description":"Array of Asana project GIDs (numeric strings) to filter tasks by"},"completed":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Filter by completion status"}},"oauth":{"required":true,"provider":"asana"},"hostedApiKey":"none"},"asana_update_task":{"id":"asana_update_task","name":"Asana Update Task","description":"Update an existing task in Asana","version":"1.0.0","params":{"accessToken":{"type":"string","required":true,"visibility":"hidden","description":"OAuth access token for Asana"},"taskGid":{"type":"string","required":true,"visibility":"user-or-llm","description":"Asana task GID (numeric string) of the task to update"},"name":{"type":"string","required":false,"visibility":"user-or-llm","description":"Updated name for the task"},"notes":{"type":"string","required":false,"visibility":"user-or-llm","description":"Updated notes or description for the task"},"assignee":{"type":"string","required":false,"visibility":"user-or-llm","description":"Updated assignee user GID"},"completed":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Mark task as completed or not completed"},"due_on":{"type":"string","required":false,"visibility":"user-or-llm","description":"Updated due date in YYYY-MM-DD format"}},"oauth":{"required":true,"provider":"asana"},"hostedApiKey":"none"},"ashby_add_candidate_tag":{"id":"ashby_add_candidate_tag","name":"Ashby Add Candidate Tag","description":"Adds a tag to a candidate in Ashby and returns the updated candidate.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Ashby API Key"},"onBehalfOfUserId":{"type":"string","required":false,"visibility":"user-or-llm","description":"Active Ashby user UUID to attribute this mutation to; the API key must permit on-behalf-of calls"},"candidateId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The UUID of the candidate to add the tag to"},"tagId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The UUID of the tag to add"}},"hostedApiKey":"none"},"ashby_anonymize_candidate":{"id":"ashby_anonymize_candidate","name":"Ashby Anonymize Candidate","description":"Strips personally identifiable information from a candidate in Ashby. This does not delete the candidate - the record and its applications remain, with the PII removed. Ashby exposes no candidate deletion endpoint; true deletion is UI-only, restricted by role, and limited to a 10-day window. Requires the candidatesWrite permission.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Ashby API Key"},"onBehalfOfUserId":{"type":"string","required":false,"visibility":"user-or-llm","description":"Active Ashby user UUID to attribute this mutation to; the API key must permit on-behalf-of calls"},"candidateId":{"type":"string","required":true,"visibility":"user-or-llm","description":"UUID of the candidate to anonymize"}},"hostedApiKey":"none"},"ashby_change_application_source":{"id":"ashby_change_application_source","name":"Ashby Change Application Source","description":"Changes the source attributed to an existing application, so programmatically created applications report correctly on the recruiting side. Requires the candidatesWrite permission.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Ashby API Key"},"onBehalfOfUserId":{"type":"string","required":false,"visibility":"user-or-llm","description":"Active Ashby user UUID to attribute this mutation to; the API key must permit on-behalf-of calls"},"applicationId":{"type":"string","required":true,"visibility":"user-or-llm","description":"UUID of the application whose source should change"},"sourceId":{"type":"string","required":false,"visibility":"user-or-llm","description":"UUID of the source to attribute the application to, as returned by List Sources. Omit only when unsetSource is true."},"unsetSource":{"type":"boolean","required":false,"visibility":"user-or-llm","description":"Set true to deliberately clear the application source. Required to unset, so that a missing or empty sourceId cannot wipe attribution by accident."}},"hostedApiKey":"none"},"ashby_change_application_stage":{"id":"ashby_change_application_stage","name":"Ashby Change Application Stage","description":"Moves an application to a different interview stage. Requires an archive reason when moving to an Archived stage.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Ashby API Key"},"onBehalfOfUserId":{"type":"string","required":false,"visibility":"user-or-llm","description":"Active Ashby user UUID to attribute this mutation to; the API key must permit on-behalf-of calls"},"applicationId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The UUID of the application to update the stage of"},"interviewStageId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The UUID of the interview stage to move the application to"},"archiveReasonId":{"type":"string","required":false,"visibility":"user-or-llm","description":"Archive reason UUID. Required when moving to an Archived stage, ignored otherwise"},"archiveEmail":{"type":"json","required":false,"visibility":"user-or-llm","description":"Archive email configuration with communicationTemplateId and optional sendAt ISO 8601 timestamp. Pass null or omit to send no archive email."}},"hostedApiKey":"none"},"ashby_create_application":{"id":"ashby_create_application","name":"Ashby Create Application","description":"Creates a new application for a candidate on a job. Optionally specify interview plan, stage, source, and credited user.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Ashby API Key"},"onBehalfOfUserId":{"type":"string","required":false,"visibility":"user-or-llm","description":"Active Ashby user UUID to attribute this mutation to; the API key must permit on-behalf-of calls"},"candidateId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The UUID of the candidate to consider for the job"},"jobId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The UUID of the job to consider the candidate for"},"interviewPlanId":{"type":"string","required":false,"visibility":"user-or-llm","description":"UUID of the interview plan to use (defaults to the job default plan)"},"interviewStageId":{"type":"string","required":false,"visibility":"user-or-llm","description":"UUID of the interview stage to place the application in, or FirstPreInterviewScreen (defaults to the first Lead stage)"},"sourceId":{"type":"string","required":false,"visibility":"user-or-llm","description":"UUID of the source to set on the application"},"creditedToUserId":{"type":"string","required":false,"visibility":"user-or-llm","description":"UUID of the user the application is credited to"},"createdAt":{"type":"string","required":false,"visibility":"user-or-llm","description":"ISO 8601 timestamp to set as the application creation date (defaults to now)"},"applicationHistory":{"type":"json","required":false,"visibility":"user-or-llm","description":"Optional documented application history entries to create with the application"}},"hostedApiKey":"none"},"ashby_create_candidate":{"id":"ashby_create_candidate","name":"Ashby Create Candidate","description":"Creates a new candidate record in Ashby.","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Ashby API Key"},"onBehalfOfUserId":{"type":"string","required":false,"visibility":"user-or-llm","description":"Active Ashby user UUID to attribute this mutation to; the API key must permit on-behalf-of calls"},"name":{"type":"string","required":true,"visibility":"user-or-llm","description":"The candidate full name"},"email":{"type":"string","required":false,"visibility":"user-or-llm","description":"Primary email address for the candidate"},"phoneNumber":{"type":"string","required":false,"visibility":"user-or-llm","description":"Primary phone number for the candidate"},"linkedInUrl":{"type":"string","required":false,"visibility":"user-or-llm","description":"LinkedIn profile URL"},"githubUrl":{"type":"string","required":false,"visibility":"user-or-llm","description":"GitHub profile URL"},"website":{"type":"string","required":false,"visibility":"user-or-llm","description":"Personal website URL"},"sourceId":{"type":"string","required":false,"visibility":"user-or-llm","description":"UUID of the source to attribute the candidate to"},"creditedToUserId":{"type":"string","required":false,"visibility":"user-or-llm","description":"UUID of the Ashby user to credit with sourcing this candidate"},"createdAt":{"type":"string","required":false,"visibility":"user-or-llm","description":"Backdated creation timestamp in ISO 8601 (e.g. 2024-01-01T00:00:00Z). Defaults to now."},"alternateEmailAddresses":{"type":"json","required":false,"visibility":"user-or-llm","description":"Array of additional email address strings to add to the candidate, e.g. [\\"a@x.com\\",\\"b@y.com\\"]"},"location":{"type":"json","required":false,"visibility":"user-or-llm","description":"Candidate location object with optional city, region, and country"}},"hostedApiKey":"none"},"ashby_create_note":{"id":"ashby_create_note","name":"Ashby Create Note","description":"Creates a note on a candidate in Ashby. Supports plain text and HTML content (bold, italic, underline, links, lists, code).","version":"1.0.0","params":{"apiKey":{"type":"string","required":true,"visibility":"user-only","description":"Ashby API Key"},"onBehalfOfUserId":{"type":"string","required":false,"visibility":"user-or-llm","description":"Active Ashby user UUID to attribute this mutation to; the API key must permit on-behalf-of calls"},"candidateId":{"type":"string","required":true,"visibility":"user-or-llm","description":"The UUID of the candidate to add the note to"},"note":{"type":"string","required":true,"visibility":"user-or-llm","description":"The note content. If noteType is text/html, supports: , , , ,