1"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[2550],{2234:(s,l,e)=>{e.d(l,{A:()=>n});const n=e.p+"assets/images/ue-blueprint-procedure-callback-a022ea5b8cbc6a85706ac0375f781677.png"},18343:(s,l,e)=>{e.r(l),e.d(l,{assets:()=>t,contentTitle:()=>i,default:()=>h,frontMatter:()=>F,metadata:()=>n,toc:()=>d});const n=JSON.parse('{"id":"core-concepts/functions/procedures","title":"Procedures","description":"A procedure is a function exported by a database, similar to a reducer.","source":"@site/versioned_docs/version-1.12.0/00200-core-concepts/00200-functions/00400-procedures.md","sourceDirName":"00200-core-concepts/00200-functions","slug":"/functions/procedures","permalink":"/docs/1.12.0/functions/procedures","draft":false,"unlisted":false,"editUrl":"https://github.com/clockworklabs/SpacetimeDB/edit/master/docs/versioned_docs/version-1.12.0/00200-core-concepts/00200-functions/00400-procedures.md","tags":[],"version":"1.12.0","sidebarPosition":400,"frontMatter":{"title":"Procedures","slug":"/functions/procedures"},"sidebar":"sidebar","previous":{"title":"Error Handling","permalink":"/docs/1.12.0/functions/reducers/error-handling"},"next":{"title":"Views","permalink":"/docs/1.12.0/functions/views"}}');var c=e(86106),r=e(56225),o=e(51471),a=e(43244);const F={title:"Procedures",slug:"/functions/procedures"},i=void 0,t={},d=[{value:"Defining Procedures",id:"defining-procedures",level:2},{value:"Accessing the database",id:"accessing-the-database",level:3},{value:"Fallible database operations",id:"fallible-database-operations",level:4},{value:"Reading values out of the database",id:"reading-values-out-of-the-database",level:4},{value:"HTTP Requests",id:"http-requests",level:2},{value:"Calling Reducers from Procedures",id:"calling-reducers-from-procedures",level:2},{value:"Calling procedures",id:"calling-procedures",level:2},{value:"Observing return values",id:"observing-return-values",level:3},{value:"Example: Calling an External AI API",id:"example-calling-an-external-ai-api",level:2},{value:"Calling from a client",id:"calling-from-a-client",level:3}];function p(s){const l={a:"a",admonition:"admonition",code:"code",em:"em",h2:"h2",h3:"h3",h4:"h4",img:"img",li:"li",p:"p",pre:"pre",span:"span",strong:"strong",ul:"ul",...(0,r.R)(),...s.components};return(0,c.jsxs)(c.Fragment,{children:[(0,c.jsxs)(l.p,{children:["A ",(0,c.jsx)(l.strong,{children:"procedure"})," is a function exported by a ",(0,c.jsx)(l.a,{href:"/docs/1.12.0/databases",children:"database"}),", similar to a ",(0,c.jsx)(l.a,{href:"/docs/1.12.0/functions/reducers",children:"reducer"}),".\nConnected ",(0,c.jsx)(l.a,{href:"/docs/1.12.0/sdks",children:"clients"})," can call procedures.\nProcedures can perform additional operations not possible in reducers, including making HTTP requests to external services.\nHowever, procedures don't automatically run in database transactions,\nand must manually open and commit a transaction in order to read from or modify the database state.\nFor this reason, prefer defining reducers rather than procedures unless you need to use one of the special procedure operators."]}),"\n",(0,c.jsx)(l.admonition,{type:"warning",children:(0,c.jsx)(l.p,{children:(0,c.jsx)(l.em,{children:(0,c.jsx)(l.strong,{children:"Procedures are currently in beta, and their API may change in upcoming SpacetimeDB releases."})})})}),"\n",(0,c.jsx)(l.h2,{id:"defining-procedures",children:"Defining Procedures"}),"\n",(0,c.jsxs)(o.A,{groupId:"server-language",queryString:!0,children:[(0,c.jsxs)(a.A,{value:"typescript",label:"TypeScript",children:[(0,c.jsxs)(l.p,{children:["Define a procedure with ",(0,c.jsx)(l.code,{children:"spacetimedb.procedure"}),":"]}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"spacetimedb."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"procedure"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:' "'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"add_two_numbers"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" { lhs"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"u32"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"(), rhs"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"u32"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"() },"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"u64"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(),"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ("}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"ctx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", { "}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"lhs"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"rhs"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }) "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"=>"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" BigInt"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(lhs) "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"+"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" BigInt"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(rhs),"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})})]})})}),(0,c.jsxs)(l.p,{children:["The ",(0,c.jsx)(l.code,{children:"spacetimedb.procedure"})," function takes:"]}),(0,c.jsxs)(l.ul,{children:["\n",(0,c.jsx)(l.li,{children:"the procedure name,"}),"\n",(0,c.jsx)(l.li,{children:"(optional) an object representing its parameter types,"}),"\n",(0,c.jsx)(l.li,{children:"its return type,"}),"\n",(0,c.jsx)(l.li,{children:"and the procedure function itself."}),"\n"]}),(0,c.jsxs)(l.p,{children:["The function will receive a ",(0,c.jsx)(l.code,{children:"ProcedureContext"})," and an object of its arguments, and it must return\na value corresponding to its return type. This return value will be sent to the caller, but will\nnot be broadcast to any other clients."]})]}),(0,c.jsxs)(a.A,{value:"csharp",label:"C#",children:[(0,c.jsx)(l.admonition,{title:"Unstable Feature",type:"warning",children:(0,c.jsxs)(l.p,{children:["Procedures in C# are currently unstable. To use them, add ",(0,c.jsx)(l.code,{children:"#pragma warning disable STDB_UNSTABLE"})," at the top of your file."]})}),(0,c.jsxs)(l.p,{children:["Define a procedure by annotating a static method with ",(0,c.jsx)(l.code,{children:"[SpacetimeDB.Procedure]"}),"."]}),(0,c.jsxs)(l.p,{children:["The method's first argument must be of type ",(0,c.jsx)(l.code,{children:"ProcedureContext"}),". A procedure may accept any number of additional arguments and may return a value."]}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"#pragma"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" warning"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" disable"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" STDB_UNSTABLE"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"["}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"SpacetimeDB"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"Procedure"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" static"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" ulong"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" AddTwoNumbers"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"ProcedureContext"}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" ctx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"uint"}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" lhs"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"uint"}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" rhs"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"{"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" return"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"ulong"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")lhs "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"+"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"ulong"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")rhs;"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})})]}),(0,c.jsxs)(a.A,{value:"rust",label:"Rust",children:[(0,c.jsxs)(l.p,{children:["Because procedures are unstable, Rust modules that define them must opt in to the ",(0,c.jsx)(l.code,{children:"unstable"})," feature in their ",(0,c.jsx)(l.code,{children:"Cargo.toml"}),":"]}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"["}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD"},children:"dependencies"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#8BE9FD"},children:"spacetimedb"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" ="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" { "}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD"},children:"version"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" ="}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:' "'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"1.*"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD"},children:"features"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" ="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ["}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"unstable"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"] }"})]})]})})}),(0,c.jsxs)(l.p,{children:["Define a procedure by annotating a function with ",(0,c.jsx)(l.code,{children:"#[spacetimedb::procedure]"}),"."]}),(0,c.jsxs)(l.p,{children:["This function's first argument must be of type ",(0,c.jsx)(l.code,{children:"&mut spacetimedb::ProcedureContext"}),".\nBy convention, this argument is named ",(0,c.jsx)(l.code,{children:"ctx"}),"."]}),(0,c.jsxs)(l.p,{children:["A procedure may accept any number of additional arguments.\nEach argument must be of a type that implements ",(0,c.jsx)(l.code,{children:"spacetimedb::SpacetimeType"}),".\nWhen defining a ",(0,c.jsx)(l.code,{children:"struct"})," or ",(0,c.jsx)(l.code,{children:"enum"}),", annotate it with ",(0,c.jsx)(l.code,{children:"#[derive(spacetimedb::SpacetimeType)]"}),"\nto make it usable as a procedure argument.\nThese argument values will not be broadcast to clients other than the caller."]}),(0,c.jsxs)(l.p,{children:["A procedure may return a value of any type that implements ",(0,c.jsx)(l.code,{children:"spacetimedb::SpacetimeType"}),".\nThis return value will be sent to the caller, but will not be broadcast to any other clients."]}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"#[spacetimedb"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"procedure]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"fn"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" add_two_numbers"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" &mut"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" spacetimedb"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"ProcedureContext"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", lhs"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" u32"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", rhs"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" u32"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:") "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"->"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" u64"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" lhs "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"as"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" u64"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" +"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" rhs "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"as"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" u64"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})})]})]}),"\n",(0,c.jsx)(l.h3,{id:"accessing-the-database",children:"Accessing the database"}),"\n",(0,c.jsxs)(o.A,{groupId:"server-language",queryString:!0,children:[(0,c.jsxs)(a.A,{value:"typescript",label:"TypeScript",children:[(0,c.jsxs)(l.p,{children:["Unlike reducers, procedures don't automatically run in database transactions.\nThis means there's no ",(0,c.jsx)(l.code,{children:"ctx.db"})," field to access the database.\nInstead, procedure code must manage transactions explicitly with ",(0,c.jsx)(l.code,{children:"ProcedureCtx.withTx"}),"."]}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" MyTable "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" table"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" { name"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:' "'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"my_table"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" },"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" a"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"u32"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"(),"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" b"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"string"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(),"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" },"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" spacetimedb "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" schema"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(MyTable);"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"#[spacetimedb::procedure]"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"spacetimedb."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"procedure"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"insert_a_value"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", { a"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"u32"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(), b"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"u32"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"() }, t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"unit"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(), ("}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"ctx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", { "}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"a"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"b"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }) "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"=>"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"withTx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" =>"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx.myTable."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"insert"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"({ a, b });"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" });"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" return"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {};"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"})"})})]})})}),(0,c.jsxs)(l.p,{children:[(0,c.jsx)(l.code,{children:"ProcedureCtx.withTx"})," takes a function of ",(0,c.jsx)(l.code,{children:"(ctx: TransactionCtx) => T"}),".\nWithin that function, the ",(0,c.jsx)(l.code,{children:"TransactionCtx"})," can be used to access the database\n",(0,c.jsxs)(l.a,{href:"/docs/1.12.0/functions/reducers/reducer-context",children:["in all the same ways as a ",(0,c.jsx)(l.code,{children:"ReducerCtx"})]}),"\nWhen the function returns, the transaction will be committed,\nand its changes to the database state will become permanent and be broadcast to clients.\nIf the function throws an error, the transaction will be rolled back, and its changes will be discarded."]}),(0,c.jsxs)(l.admonition,{type:"warning",children:[(0,c.jsxs)(l.p,{children:["The function passed to ",(0,c.jsx)(l.code,{children:"ProcedureCtx.withTx"})," may be invoked multiple times,\npossibly seeing a different version of the database state each time."]}),(0,c.jsx)(l.p,{children:"If invoked more than once with reference to the same database state,\nit must perform the same operations and return the same result each time."}),(0,c.jsx)(l.p,{children:"If invoked more than once with reference to different database states,\nvalues observed during prior runs must not influence the behavior of the function or the calling procedure."}),(0,c.jsxs)(l.p,{children:["Avoid capturing mutable state within functions passed to ",(0,c.jsx)(l.code,{children:"withTx"}),"."]})]})]}),(0,c.jsxs)(a.A,{value:"csharp",label:"C#",children:[(0,c.jsxs)(l.p,{children:["Unlike reducers, procedures don't automatically run in database transactions.\nThis means there's no ",(0,c.jsx)(l.code,{children:"ctx.Db"})," field to access the database.\nInstead, procedure code must manage transactions explicitly with ",(0,c.jsx)(l.code,{children:"ProcedureContext.WithTx"}),"."]}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"#pragma"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" warning"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" disable"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" STDB_UNSTABLE"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"using"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" SpacetimeDB"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" static"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" partial"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" class"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD"},children:" Module"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"{"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ["}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"SpacetimeDB"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"Table"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(Name "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:' "'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"MyTable"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" partial"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" struct"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" MyTable"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" uint"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" A;"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" string"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" B;"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ["}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"SpacetimeDB"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"Procedure"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" static"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" void"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" InsertAValue"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"ProcedureContext"}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" ctx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"uint"}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" a"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"string"}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" b"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"WithTx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"txCtx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" =>"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" txCtx.Db.MyTable."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Insert"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"new"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" MyTable"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" { A "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" a, B "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" b });"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" return"}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" 0"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" });"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})}),(0,c.jsxs)(l.p,{children:[(0,c.jsx)(l.code,{children:"ProcedureContext.WithTx"})," takes a function of type ",(0,c.jsx)(l.code,{children:"Func<ProcedureTxContext, T>"}),".\nWithin that function, the ",(0,c.jsx)(l.code,{children:"TransactionContext"})," can be used to access the database\n",(0,c.jsxs)(l.a,{href:"/docs/1.12.0/functions/reducers/reducer-context",children:["in all the same ways as a ",(0,c.jsx)(l.code,{children:"ReducerContext"})]}),".\nWhen the function returns, the transaction will be committed,\nand its changes to the database state will become permanent and be broadcast to clients.\nIf the function throws an exception, the transaction will be rolled back, and its changes will be discarded."]}),(0,c.jsxs)(l.admonition,{type:"warning",children:[(0,c.jsxs)(l.p,{children:["The function passed to ",(0,c.jsx)(l.code,{children:"ProcedureContext.WithTx"})," may be invoked multiple times,\npossibly seeing a different version of the database state each time."]}),(0,c.jsx)(l.p,{children:"If invoked more than once with reference to the same database state,\nit must perform the same operations and return the same result each time."}),(0,c.jsx)(l.p,{children:"If invoked more than once with reference to different database states,\nvalues observed during prior runs must not influence the behavior of the function or the calling procedure."}),(0,c.jsxs)(l.p,{children:["Avoid capturing mutable state within functions passed to ",(0,c.jsx)(l.code,{children:"WithTx"}),"."]})]})]}),(0,c.jsxs)(a.A,{value:"rust",label:"Rust",children:[(0,c.jsxs)(l.p,{children:["Unlike reducers, procedures don't automatically run in database transactions.\nThis means there's no ",(0,c.jsx)(l.code,{children:"ctx.db"})," field to access the database.\nInstead, procedure code must manage transactions explicitly with ",(0,c.jsx)(l.code,{children:"ProcedureContext::with_tx"}),"."]}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"#[spacetimedb"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"table(name "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" my_table)]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"struct"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" MyTable"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" a"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" u32"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" b"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" String"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"#[spacetimedb"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"procedure]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"fn"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" insert_a_value"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" &mut"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" ProcedureContext"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", a"}),(0,c.jsx)(l.span,
1{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" u32"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", b"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" String"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:") {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"with_tx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"|"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"|"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"my_table"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"()"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"insert"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"MyTable"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" { a, b });"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" });"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})}),(0,c.jsxs)(l.p,{children:[(0,c.jsx)(l.code,{children:"ProcedureContext::with_tx"})," takes a function of type ",(0,c.jsx)(l.code,{children:"Fn(&TxContext) -> T"}),".\nWithin that function, the ",(0,c.jsx)(l.code,{children:"&TxContext"})," can be used to access the database\n",(0,c.jsxs)(l.a,{href:"https://docs.rs/spacetimedb/latest/spacetimedb/struct.ReducerContext.html",children:["in all the same ways as a ",(0,c.jsx)(l.code,{children:"ReducerContext"})]}),".\nWhen the function returns, the transaction will be committed,\nand its changes to the database state will become permanent and be broadcast to clients.\nIf the function panics, the transaction will be rolled back, and its changes will be discarded.\nHowever, for transactions that may fail,\n",(0,c.jsxs)(l.a,{href:"#fallible-database-operations",children:["prefer calling ",(0,c.jsx)(l.code,{children:"try_with_tx"})," and returning a ",(0,c.jsx)(l.code,{children:"Result"})]})," rather than panicking."]}),(0,c.jsxs)(l.admonition,{type:"warning",children:[(0,c.jsxs)(l.p,{children:["The function passed to ",(0,c.jsx)(l.code,{children:"ProcedureContext::with_tx"})," may be invoked multiple times,\npossibly seeing a different version of the database state each time."]}),(0,c.jsx)(l.p,{children:"If invoked more than once with reference to the same database state,\nit must perform the same operations and return the same result each time."}),(0,c.jsx)(l.p,{children:"If invoked more than once with reference to different database states,\nvalues observed during prior runs must not influence the behavior of the function or the calling procedure."}),(0,c.jsxs)(l.p,{children:["Avoid capturing mutable state within functions passed to ",(0,c.jsx)(l.code,{children:"with_tx"}),"."]})]})]})]}),"\n",(0,c.jsx)(l.h4,{id:"fallible-database-operations",children:"Fallible database operations"}),"\n",(0,c.jsxs)(o.A,{groupId:"server-language",queryString:!0,children:[(0,c.jsxs)(a.A,{value:"typescript",label:"TypeScript",children:[(0,c.jsx)(l.p,{children:"For fallible database operations, you can throw an error inside the transaction function:"}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"spacetimedb."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"procedure"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"maybe_insert_a_value"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", { a"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"u32"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"(), b"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"string"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"() }, t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"unit"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(), ("}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"ctx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", { "}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"a"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"b"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }) "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"=>"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"withTx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" =>"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" if"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" (a "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"<"}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" 10"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:") {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" throw"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6",fontWeight:"bold"},children:" new"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" SenderError"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"a is less than 10!"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx.myTable."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"insert"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"({ a, b });"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" });"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"})"})})]})})})]}),(0,c.jsxs)(a.A,{value:"csharp",label:"C#",children:[(0,c.jsx)(l.p,{children:"For fallible database operations, you can throw an exception inside the transaction function:"}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"#pragma"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" warning"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" disable"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" STDB_UNSTABLE"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"using"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" SpacetimeDB"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" static"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" partial"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" class"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD"},children:" Module"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"{"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ["}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"SpacetimeDB"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"Procedure"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" static"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" void"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" MaybeInsertAValue"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"ProcedureContext"}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" ctx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"uint"}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" a"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"string"}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" b"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"WithTx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"txCtx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" =>"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" if"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" (a "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"<"}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" 10"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" throw"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" new"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Exception"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"a is less than 10!"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" txCtx.Db.MyTable."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Insert"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"new"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" MyTable"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" { A "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" a, B "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" b });"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" return"}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" 0"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" });"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})})]}),(0,c.jsxs)(a.A,{value:"rust",label:"Rust",children:[(0,c.jsxs)(l.p,{children:["For fallible database operations, instead use ",(0,c.jsx)(l.code,{children:"ProcedureContext::try_with_tx"}),":"]}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"#[spacetimedb"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"procedure]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"fn"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" maybe_insert_a_value"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" &mut"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" ProcedureContext"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", a"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" u32"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", b"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" String"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:") {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"try_with_tx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"|"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"|"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" if"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" a "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"<"}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" 10"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" return"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Err"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"a is less than 10!"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"my_table"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"()"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"insert"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"MyTable"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" { a, b });"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Ok"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(())"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" });"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})}),(0,c.jsxs)(l.p,{children:[(0,c.jsx)(l.code,{children:"ProcedureContext::try_with_tx"})," takes a function of type ",(0,c.jsx)(l.code,{children:"Fn(&TxContext) -> Result<T, E>"}),".\nIf the function returns ",(0,c.jsx)(l.code,{children:"Ok"}),", the transaction will be committed,\nand its changes to the database state will become permanent and be broadcast to clients.\nIf that function returns ",(0,c.jsx)(l.code,{children:"Err"}),", the transaction will be rolled back, and its changes will be discarded."]})]})]}),"\n",(0,c.jsx)(l.h4,{id:"reading-values-out-of-the-database",children:"Reading values out of the database"}),"\n",(0,c.jsxs)(o.A,{groupId:"server-language",queryString:!0,children:[(0,c.jsxs)(a.A,{value:"typescript",label:"TypeScript",children:[(0,c.jsxs)(l.p,{children:["Functions passed to\n",(0,c.jsx)(l.a,{href:"#accessing-the-database",children:(0,c.jsx)(l.code,{children:"ProcedureCtx.withTx"})}),"\nmay return a value, and that value will be returned to the calling procedure."]}),(0,c.jsx)(l.p,{children:"Transaction return values are never saved or broadcast to clients, and are used only by the calling procedure."}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" Player "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" table"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" { name"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:' "'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"player"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" },"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" id"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"identity"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(),"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" level"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"u32"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(),"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" },"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" spacetimedb "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" schema"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(Player);"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"spacetimedb."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"procedure"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"find_highest_level_player"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"unit"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"(), "}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" =>"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" let"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" highestLevelPlayer "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"withTx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" =>"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" Iterator."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"from"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(ctx.db.player)."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"reduce"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ("}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"a"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"b"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:") "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"=>"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" a "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"=="}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" null"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" ||"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" b.level "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:">"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" a.level "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"?"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" b "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" a,"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" null"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" )"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" );"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" if"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" (highestLevelPlayer "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"!="}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" null"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:") {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" console."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"log"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Congratulations to "}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", highestLevelPlayer.id);"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" } "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"else"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" console."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"warn"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"No players..."}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" return"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {};"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"});"})})]})})})]}),(0,c.jsxs)(a.A,{value:"csharp",label:"C#",children:[(0,c.jsxs)(l.p,{children:["Functions passed to\n",(0,c.jsx)(l.a,{href:"#accessing-the-database",children:(0,c.jsx)(l.code,{children:"ProcedureContext.WithTx"})}),"\nmay return a value, and that value will be returned to the calling procedure."]}),(0,c.jsx)(l.p,{children:"Transaction return values are never saved or broadcast to clients, and are used only by the calling procedure."}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"#pragma"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" warning"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" disable"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" STDB_UNSTABLE"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"using"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" SpacetimeDB"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" static"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" partial"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" class"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD"},children:" Module"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"{"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ["}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"SpacetimeDB"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"Table"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(Name "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:' "'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Player"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" partial"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" struct"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Player"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" public"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Identity"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" Id;"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" uint"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" Level;"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ["}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"SpacetimeDB"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"Procedure"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" static"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" void"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" FindHighestLevelPlayer"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"ProcedureContext"}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" ctx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" var"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:" highestLevelPlayer "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"WithTx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"txCtx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" =>"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Player"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"? highest "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" null"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" foreach"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"var"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" player "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"in"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" txCtx.Db.Player."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Iter"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"())"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" if"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" (highest "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"=="}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" null"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" ||"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" player.Level "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:">"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" highest.Value.Level)"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" highest "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" player;"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" return"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" highest;"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" });"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" if"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" (highestLevelPlayer.HasValue)"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" Log."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Info"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'$"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Congratulations to "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"{"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"highestLevelPlayer"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"Value"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"Id"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"}"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" else"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" Log."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Warn"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"No players..."}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})})]}),(0,c.jsxs)(a.A,{value:"rust",label:"Rust",children:[(0,c.jsxs)(l.p,{children:["Functions passed to\n",(0,c.jsx)(l.a,{href:"#accessing-the-database",children:(0,c.jsx)(l.code,{children:"ProcedureContext::with_tx"})})," and ",(0,c.jsx)(l.a,{href:"#fallible-database-operations",children:(0,c.jsx)(l.code,{children:"ProcedureContext::try_with_tx"})}),"\nmay return a value, and that value will be returned to the calling procedure."]}),(0,c.jsx)(l.p,{children:"Transaction return values are never saved or broadcast to clients, and are used only by the calling procedure."}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"#[spacetimedb"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"table(name "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" player)]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"struct"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Player"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" id"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" spacetimedb"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"Identity"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" level"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" u32"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"#[spacetimedb"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"procedure]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"fn"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" find_highest_level_player"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" &mut"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" ProcedureContext"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:") {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" let"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:" highest_level_player "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"with_tx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"|"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"|"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"db"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"player"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"()"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"iter"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"()"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"max_by_key"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"|"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"player"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"|"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" player"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"level)"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" });"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" match"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" highest_level_player {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Some"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(player) "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"=>"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" log"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"info!"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"Congratulations to {}"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", player"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"id),"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" None"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" =>"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" log"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"warn!"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"No players..."'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"),"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})})]})]}),"\n",(0,c.jsx)(l.h2,{id:"http-requests",children:"HTTP Requests"}),"\n",(0,c.jsxs)(o.A,{groupId:"server-language",queryString:!0,children:[(0,c.jsxs)(a.A,{value:"typescript",label:"TypeScript",children:[(0,c.jsxs)(l.p,{children:["Procedures can make HTTP requests to external services using methods contained in ",(0,c.jsx)(l.code,{children:"ctx.http"}),"."]}),(0,c.jsxs)(l.p,{children:[(0,c.jsx)(l.code,{children:"ctx.http.fetch"})," is similar to the browser ",(0,c.jsx)(l.code,{children:"fetch()"})," API, but is synchronous."]}),(0,c.jsxs)(l.p,{children:["It can perform simple ",(0,c.jsx)(l.code,{children:"GET"})," requests:"]}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"#[spacetimedb::procedure]"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"spacetimedb."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"procedure"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"get_request"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"unit"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"(), "}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" =>"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" try"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx.http."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"fetch"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"https://example.invalid"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" body "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"text"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"();"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" console."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"log"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"`Got response with status "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"${"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"response.status"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"}"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:" and body "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"${"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"body"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"}"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"`"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" } "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"catch"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" (e) {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" console."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"error"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Request failed: "}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", e);"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" return"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {};"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"});"})})]})})}),(0,c.jsx)(l.p,{children:"It can also accept an options object to specify a body, headers, HTTP method, and timeout:"}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"spacetimedb."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"procedure"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"post_request"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"unit"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"(), "}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" =>"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" try"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx.http."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"fetch"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"https://example.invalid/upload"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" method"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:' "'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"POST"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" headers"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" { "}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Content-Type"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:' "'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"text/plain"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" },"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" body"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:' "'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"This is the body of the HTTP request"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" });"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" body "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"text"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"();"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" console."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"log"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"`Got response with status "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"${"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"response.status"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"}"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:" and body {body}`"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" } "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"catch"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" (e) {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" console."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"error"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Request failed: "}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", e);"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" return"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {};"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"});"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"spacetimedb."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"procedure"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"get_request_with_short_timeout"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"unit"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"(), "}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" =>"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" try"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx.http."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"fetch"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"https://example.invalid"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" method"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:' "'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"GET"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" timeout"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" TimeDuration."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"fromMillis"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"10"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"),"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" });"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" body "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"text"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"();"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" console."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"log"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"`Got response with status "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"${"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"response.status"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"}"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:" and body {body}`"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" } "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"catch"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" (e) {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" console."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"error"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Request failed: "}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", e);"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" return"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {};"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"});"})})]})})}),(0,c.jsxs)(l.p,{children:["Procedures can't send requests at the same time as holding open a ",(0,c.jsx)(l.a,{href:"#accessing-the-database",children:"transaction"}),"."]})]}),(0,c.jsxs)(a.A,{value:"csharp",label:"C#",children:[(0,c.jsxs)(l.p,{children:["Procedures can make HTTP requests to external services using methods on ",(0,c.jsx)(l.code,{children:"ctx.Http"}),"."]}),(0,c.jsxs)(l.p,{children:[(0,c.jsx)(l.code,{children:"ctx.Http.Get"})," performs simple ",(0,c.jsx)(l.code,{children:"GET"})," requests with no headers:"]}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"#pragma"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" warning"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" disable"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" STDB_UNSTABLE"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"using"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" SpacetimeDB"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" static"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" partial"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" class"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD"},children:" Module"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"{"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ["}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"SpacetimeDB"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"Procedure"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" static"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" void"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" GetRequest"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"ProcedureContext"}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" ctx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" var"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" result "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx.Http."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Get"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"}
1,children:"https://example.invalid"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" switch"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" (result)"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" case"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Result"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"<"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"HttpResponse"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"HttpError"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:">."}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"OkR"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"var"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response):"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" var"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" body "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response.Body."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"ToStringUtf8Lossy"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"();"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" Log."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Info"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'$"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Got response with status "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"{"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"response"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"StatusCode"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"}"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:" and body "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"{"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"body"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"}"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" break"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" case"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Result"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"<"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"HttpResponse"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"HttpError"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:">."}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"ErrR"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"var"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" e):"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" Log."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Error"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'$"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Request failed: "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"{"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"e"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"Message"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"}"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" break"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})}),(0,c.jsxs)(l.p,{children:[(0,c.jsx)(l.code,{children:"ctx.Http.Send"})," sends an ",(0,c.jsx)(l.code,{children:"HttpRequest"})," with custom method, headers, and body:"]}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"#pragma"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" warning"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" disable"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" STDB_UNSTABLE"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"using"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" SpacetimeDB"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" static"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" partial"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" class"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD"},children:" Module"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"{"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ["}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"SpacetimeDB"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"Procedure"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" static"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" void"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" PostRequest"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"ProcedureContext"}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" ctx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" var"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" request "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" new"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" HttpRequest"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" Method "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" SpacetimeDB.HttpMethod.Post,"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" Uri "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:' "'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"}
1,children:"https://example.invalid/upload"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" Headers "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" new"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" List"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"<"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"HttpHeader"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:">"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" new"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" HttpHeader"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Content-Type"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"text/plain"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" },"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" Body "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" HttpBody."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"FromString"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"This is the body of the HTTP request"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" };"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" var"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" result "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx.Http."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Send"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(request);"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" switch"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" (result)"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" case"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Result"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"<"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"HttpResponse"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"HttpError"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:">."}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"OkR"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"var"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response):"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" var"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" body "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response.Body."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"ToStringUtf8Lossy"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"();"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" Log."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Info"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'$"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Got response with status "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"{"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"response"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"StatusCode"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"}"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:" and body "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"{"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"body"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"}"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" break"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" case"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Result"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"<"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"HttpResponse"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"HttpError"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:">."}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"ErrR"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"var"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" e):"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" Log."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Error"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'$"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Request failed: "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"{"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"e"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"Message"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"}"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" break"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})}),(0,c.jsxs)(l.p,{children:["Procedures can't send requests at the same time as holding open a ",(0,c.jsx)(l.a,{href:"#accessing-the-database",children:"transaction"}),"."]})]}),(0,c.jsxs)(a.A,{value:"rust",label:"Rust",children:[(0,c.jsxs)(l.p,{children:["Procedures can make HTTP requests to external services using methods contained in ",(0,c.jsx)(l.code,{children:"ctx.http"}),"."]}),(0,c.jsxs)(l.p,{children:[(0,c.jsx)(l.code,{children:"ctx.http.get"})," performs simple ",(0,c.jsx)(l.code,{children:"GET"})," requests with no headers:"]}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"#[spacetimedb"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"procedure]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"fn"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" get_request"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" &mut"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" ProcedureContext"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:") {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" match"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"http"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"get"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"}
1,children:'"https://example.invalid"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:") {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Ok"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(response) "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"=>"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" let"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" (response, body) "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"into_parts"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"();"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" log"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"info!"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:' "Got response with status {} and body {}"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"status,"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" body"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"into_string_lossy"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(),"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" )"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" },"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Err"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(error) "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"=>"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" log"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"error!"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"Request failed: {error:?}"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"),"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})}),(0,c.jsxs)(l.p,{children:[(0,c.jsx)(l.code,{children:"ctx.http.send"})," sends any ",(0,c.jsx)(l.a,{href:"https://docs.rs/http/latest/http/request/struct.Request.html",children:(0,c.jsx)(l.code,{children:"http::Request"})}),"\nwhose body can be converted to ",(0,c.jsx)(l.code,{children:"spacetimedb::http::Body"}),".\n",(0,c.jsx)(l.code,{children:"http::Request"})," is re-exported as ",(0,c.jsx)(l.code,{children:"spacetimedb::http::Request"}),"."]}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"#[spacetimedb"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"procedure]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"fn"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" post_request"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" &mut"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" spacetimedb"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"ProcedureContext"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:") {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" let"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" request "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" spacetimedb"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"http"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"Request"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"builder"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"()"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" ."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"uri"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"https://example.invalid/upload"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" ."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"method"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"POST"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" ."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"header"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"Content-Type"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"text/plain"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" ."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"body"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"This is the body of the HTTP request"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" ."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"expect"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"Building `Request` object failed"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" match"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"http"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"send"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(request) {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Ok"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(response) "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"=>"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" let"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" (response, body) "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"into_parts"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"();"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" log"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"info!"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:' "Got response with status {} and body {}"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"status,"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" body"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"into_string_lossy"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"(),"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" )"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Err"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(error) "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"=>"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" log"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"error!"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"Request failed: {error:?}"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"),"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})}),(0,c.jsxs)(l.p,{children:["Each of these methods returns a ",(0,c.jsx)(l.a,{href:"https://docs.rs/http/latest/http/response/struct.Response.html#method.body",children:(0,c.jsx)(l.code,{children:"http::Response"})}),"\ncontaining a ",(0,c.jsx)(l.code,{children:"spacetimedb::http::Body"}),". ",(0,c.jsx)(l.code,{children:"http::Response"})," is re-exported as ",(0,c.jsx)(l.code,{children:"spacetimedb::http::Response"}),"."]}),(0,c.jsxs)(l.p,{children:["Set a timeout for a ",(0,c.jsx)(l.code,{children:"ctx.http.send"})," request by including a ",(0,c.jsx)(l.code,{children:"spacetimedb::http::Timeout"})," as an ",(0,c.jsx)(l.a,{href:"https://docs.rs/http/latest/http/request/struct.Builder.html#method.extension",children:(0,c.jsx)(l.code,{children:"extension"})}),":"]}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"#[spacetimedb"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"procedure]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"fn"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" get_request_with_short_timeout"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" &mut"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" spacetimedb"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"ProcedureContext"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:") {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" let"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" request "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" spacetimedb"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"http"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"Request"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"builder"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"()"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" ."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"uri"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"https://example.invalid"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" ."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"method"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"GET"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:" // Set a timeout of 10 ms."})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" ."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"extension"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"(spacetimedb"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"http"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Timeout"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(std"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"time"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"Duration"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"from_millis"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"10"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"into"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"()))"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:" // Empty body for a `GET` request."})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" ."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"body"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(())"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" ."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"expect"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"Building `Request` object failed"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"http"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"send"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(request)"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"expect"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"HTTP request failed"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})}),(0,c.jsxs)(l.p,{children:["Procedures can't send requests at the same time as holding open a ",(0,c.jsx)(l.a,{href:"#accessing-the-database",children:"transaction"}),"."]})]})]}),"\n",(0,c.jsx)(l.h2,{id:"calling-reducers-from-procedures",children:"Calling Reducers from Procedures"}),"\n",(0,c.jsx)(l.p,{children:"Procedures can call reducers by invoking them within a transaction block. The reducer function runs within the transaction context:"}),"\n",(0,c.jsxs)(o.A,{groupId:"server-language",queryString:!0,children:[(0,c.jsx)(a.A,{value:"typescript",label:"TypeScript",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"// Define a reducer and save the reference"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" processItem "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" spacetimedb."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"reducer"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"process_item"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", { itemId"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"u64"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"() }, ("}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"ctx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", { "}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"itemId"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }) "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"=>"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:" // ... reducer logic"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"});"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"// Call it from a procedure using the saved reference"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"spacetimedb."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"procedure"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"fetch_and_process"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", { url"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"string"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"() }, t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"unit"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(), ("}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"ctx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", { "}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"url"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }) "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"=>"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:" // Fetch external data"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx.http."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"fetch"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(url);"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" data "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"json"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"();"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:" // Call the reducer within a transaction"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"withTx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"txCtx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" =>"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" processItem"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(txCtx, { itemId"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" data.id });"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" });"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" return"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {};"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"});"})})]})})})}),(0,c.jsx)(a.A,{value:"csharp",label:"C#",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"#pragma"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" warning"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" disable"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" STDB_UNSTABLE"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"using"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" SpacetimeDB"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" static"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" partial"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" class"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD"},children:" Module"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"{"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:" // Note: In C#, you can define helper methods that work with the transaction context"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:" // rather than calling reducers directly."})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" private"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" static"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" void"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" ProcessItemLogic"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"ulong"}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" itemId"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:" // ... item processing logic"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ["}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"SpacetimeDB"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"Procedure"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" static"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" void"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" FetchAndProcess"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"ProcedureContext"}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" ctx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"string"}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" url"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:" // Fetch external data"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" var"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" result "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx.Http."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Get"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(url);"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" var"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" result."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"UnwrapOrThrow"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"();"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" var"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" body "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response.Body."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"ToStringUtf8Lossy"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"();"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" var"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" itemId "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" ParseId"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(body);"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:" // Process within a transaction"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"WithTx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"txCtx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" =>"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" ProcessItemLogic"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(itemId);"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" return"}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" 0"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" });"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" private"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" static"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" ulong"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" ParseId"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"string"}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" body"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:" // Parse the ID from the response body"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" return"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" ulong"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Parse"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(body);"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})})}),(0,c.jsx)(a.A,{value:"rust",label:"Rust",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"#[spacetimedb"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"reducer]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"fn"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" process_item"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" &"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"ReducerContext"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", item_id"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" u64"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:") {"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:" // ... reducer logic"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"#[spacetimedb"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"procedure]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"fn"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" fetch_and_process"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" &mut"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" ProcedureContext"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", url"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" String"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:") "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"->"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Result"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"<(), "}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"String"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"> {"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:" // Fetch external data"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" let"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"http"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"get"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"&"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"url)"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"map_err"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"|"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"e"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"|"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" format!"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"{e:?}"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"))"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"?"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" let"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" (_, body) "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"into_parts"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"();"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" let"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" item_id"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" u64"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" ="}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" parse_id"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"&"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"body"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"into_string_lossy"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"());"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:" // Call the reducer within a transaction"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"with_tx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"|"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"tx_ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"|"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" process_item"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(tx_ctx, item_id);"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" });"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Ok"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(())"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})})})]}),"\n",(0,c.jsx)(l.admonition,{type:"note",children:(0,c.jsxs)(l.p,{children:["When you call a reducer function inside ",(0,c.jsx)(l.code,{children:"withTx"}),", it executes as part of the same transaction, not as a subtransaction. The reducer's logic runs inline within your anonymous transaction block, just like calling any other helper function."]})}),"\n",(0,c.jsx)(l.p,{children:"This pattern is useful when you need to:"}),"\n",(0,c.jsxs)(l.ul,{children:["\n",(0,c.jsx)(l.li,{children:"Fetch external data and then process it transactionally"}),"\n",(0,c.jsx)(l.li,{children:"Reuse existing reducer logic from a procedure"}),"\n",(0,c.jsx)(l.li,{children:"Combine side effects (HTTP) with database operations"}),"\n"]}),"\n",(0,c.jsx)(l.h2,{id:"calling-procedures",children:"Calling procedures"}),"\n",(0,c.jsxs)(o.A,{groupId:"client-language",queryString:!0,children:[(0,c.jsxs)(a.A,{value:"typescript",label:"TypeScript",children:[(0,c.jsxs)(l.p,{children:["Clients can invoke procedures using methods on ",(0,c.jsx)(l.code,{children:"ctx.procedures"}),":"]}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsx)(l.code,{children:(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"ctx.procedures."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"insertAValue"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"({ a"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" 12"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", b"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:' "'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Foo"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" });"})]})})})})]}),(0,c.jsxs)(a.A,{value:"csharp",label:"C#",children:[(0,c.jsxs)(l.p,{children:["Clients can invoke procedures using methods on ",(0,c.jsx)(l.code,{children:"ctx.Procedures"}),":"]}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsx)(l.code,{children:(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"ctx.Procedures."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"InsertAValue"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"12"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Foo"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]})})})})]}),(0,c.jsxs)(a.A,{value:"rust",label:"Rust",children:[(0,c.jsxs)(l.p,{children:["Clients can invoke procedures using methods on ",(0,c.jsx)(l.code,{children:"ctx.procedures"}),":"]}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsx)(l.code,{children:(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"procedures"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"insert_a_value"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"12"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"Foo"'}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"to_string"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"());"})]})})})})]}),(0,c.jsxs)(a.A,{value:"cpp",label:"Unreal C++",children:[(0,c.jsxs)(l.p,{children:["Clients can invoke procedures using methods on ",(0,c.jsx)(l.code,{children:"ctx.Procedures"}),":"]}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsx)(l.code,{children:(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"Context.Procedures"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"->"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"InsertAValue"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"12"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"TEXT"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Foo"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"), {});"})]})})})})]}),(0,c.jsxs)(a.A,{value:"blueprint",label:"Unreal Blueprint",children:[(0,c.jsxs)(l.p,{children:["Clients can invoke procedures using methods on ",(0,c.jsx)(l.code,{children:"ctx.Procedures"}),":"]}),(0,c.jsx)(l.p,{children:(0,c.jsx)(l.img,{alt:"Calling Procedures",src:e(31023).A+"",width:"411",height:"463"})})]})]}),"\n",(0,c.jsx)(l.h3,{id:"observing-return-values",children:"Observing return values"}),"\n",(0,c.jsxs)(o.A,{groupId:"client-language",queryString:!0,children:[(0,c.jsxs)(a.A,{value:"typescript",label:"TypeScript",children:[(0,c.jsxs)(l.p,{children:["When a client invokes a procedure, it gets a ",(0,c.jsx)(l.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",children:(0,c.jsx)(l.code,{children:"Promise"})})," which resolves to the return value of the procedure."]}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"ctx.procedures."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"addTwoNumbers"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"({ lhs"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" 1"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", rhs"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" 2"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" })."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"then"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" sum"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" =>"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" console."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"log"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"`1 + 2 = "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"${"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"sum"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"}"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"`"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})})]})})})]}),(0,c.jsxs)(a.A,{value:"csharp",label:"C#",children:[(0,c.jsx)(l.p,{children:"A client can also invoke a procedure while registering a callback to run when it completes.\nThat callback will have access to the return value of the procedure,\nor an error if the procedure fails."}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"ctx.Procedures."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"AddTwoNumbers"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"1"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"2"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", ("}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"ctx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"result"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:") "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"=>"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"{"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" if"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" (result.IsSuccess)"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" Log."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Info"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'$"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"1 + 2 = "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"{"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"result"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"Value"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"!}"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" else"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" throw"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" result.Error"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"!"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"});"})})]})})})]}),(0,c.jsxs)(a.A,{value:"rust",label:"Rust",children:[(0,c.jsx)(l.p,{children:"A client can also invoke a procedure while registering a callback to run when it completes.\nThat callback will have access to the return value of the procedure,\nor an error if the procedure fails."}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"procedures"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"add_two_numbers_then"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"1"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"2"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"|"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"ctx, result"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"|"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" let"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" sum "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" result"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"expect"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"Procedure failed"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" println!"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"1 + 2 = {sum}"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"});"})})]})})})]}),(0,c.jsxs)(a.A,{value:"cpp",label:"Unreal C++",children:[(0,c.jsx)(l.p,{children:"A client can also invoke a procedure while registering a callback to run when it completes.\nThat callback will have access to the return value of the procedure,\nor an error if the procedure fails."}),(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"{"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ... "})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" FOnAddTwoNumbersComplete ReturnCallback;"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" BIND_DELEGATE_SAFE"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(ReturnCallback, "}),(0,c.jsx)(l.span,{style:{color:"#BD93F9",fontStyle:"italic"},children:"this"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", AGameManager, OnAddTwoNumbersComplete);"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" Context.Procedures"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"->"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"AddTwoNumbers"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"1"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"2"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", ReturnCallback);"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"void"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" AGameManager"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"OnAddTwoNumbersComplete"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"const"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" FProcedureEventContext"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"&"}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" Context"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"int32"}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" Result"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"bool"}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" bSuccess"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"{"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" if"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" (bSuccess)"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" UE_LOG"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(LogTemp, Log, "}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"TEXT"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"1 + 2 = "}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"%d"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"), Result);"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" else"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" if"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" (Context.Event.Status."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"IsInternalError"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"())"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" UE_LOG"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(LogTemp, Error, "}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"TEXT"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Error: "}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"%s"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"), "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"*"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"Context.Event.Status."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"GetAsInternalError"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"());"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" return"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" UE_LOG"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(LogTemp, Error, "}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"TEXT"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Out of energy!"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"));"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})})]}),(0,c.jsxs)(a.A,{value:"blueprint",label:"Unreal Blueprint",children:[(0,c.jsx)(l.p,{children:"A client can also invoke a procedure while registering a callback to run when it completes.\nThat callback will have access to the return value of the procedure,\nor an error if the procedure fails."}),(0,c.jsx)(l.p,{children:(0,c.jsx)(l.img,{alt:"Procedure Callbacks",src:e(2234).A+"",width:"901",height:"764"})})]})]}),"\n",(0,c.jsx)(l.h2,{id:"example-calling-an-external-ai-api",children:"Example: Calling an External AI API"}),"\n",(0,c.jsx)(l.p,{children:"A common use case for procedures is integrating with external APIs like OpenAI's ChatGPT. Here's a complete example showing how to build an AI-powered chat feature."}),"\n",(0,c.jsxs)(o.A,{groupId:"server-language",queryString:!0,children:[(0,c.jsx)(a.A,{value:"typescript",label:"TypeScript",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"import"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" { schema, t, table, SenderError } "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"from"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:" '"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"spacetimedb/server"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" AiMessage "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" table"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" { name"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:" '"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"ai_message"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" true"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" },"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" user"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"identity"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"(),"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" prompt"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"string"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(),"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"string"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(),"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" createdAt"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"timestamp"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(),"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" spacetimedb "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" schema"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(AiMessage);"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"spacetimedb."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"procedure"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:" '"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"ask_ai"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" { prompt"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"string"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(), apiKey"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"string"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"() },"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" t."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"string"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(),"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ("}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"ctx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", { "}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"prompt"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"apiKey"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }) "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"=>"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:" // Make the HTTP request to OpenAI"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx.http."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"fetch"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"}
1,children:"https://api.openai.com/v1/chat/completions"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" method"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:" '"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"POST"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" headers"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:" '"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Content-Type"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:" '"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"application/json"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:" '"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Authorization"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:" `Bearer "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"${"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"apiKey"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"}"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"`"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" },"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" body"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" JSON"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"stringify"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"({"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" model"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:" '"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"gpt-4"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" messages"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" [{ role"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:" '"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"user"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", content"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" prompt }],"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }),"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" });"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" if"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" (response.status "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"!=="}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" 200"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:") {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" throw"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6",fontWeight:"bold"},children:" new"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" SenderError"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"`API returned status "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"${"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"response.status"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"}"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"`"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" data "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"json"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"();"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" aiResponse "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" data.choices?.["}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"0"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"]?.message?.content;"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" if"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"!"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"aiResponse) {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" throw"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6",fontWeight:"bold"},children:" new"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" SenderError"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Failed to parse AI response"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:"'"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:" // Store the conversation in the database"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"withTx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"txCtx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" =>"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" txCtx.db.aiMessage."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"insert"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"({"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" user"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" txCtx.sender,"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" prompt,"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" aiResponse,"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" createdAt"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" txCtx.timestamp,"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" });"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" });"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" return"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" aiResponse;"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})})]})})})}),(0,c.jsx)(a.A,{value:"csharp",label:"C#",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"#pragma"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" warning"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" disable"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" STDB_UNSTABLE"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"using"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" SpacetimeDB"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"using"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" System"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"Text"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"Json"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" static"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" partial"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" class"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD"},children:" Module"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"{"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ["}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"SpacetimeDB"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"Table"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(Name "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:' "'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"AiMessage"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", Public "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" true"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" partial"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" struct"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" AiMessage"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" public"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Identity"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" User;"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" string"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" Prompt;"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" string"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" Response;"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" public"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Timestamp"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" CreatedAt;"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ["}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"SpacetimeDB"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"Procedure"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" public"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" static"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" string"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" AskAi"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"ProcedureContext"}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" ctx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"string"}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" prompt"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"string"}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" apiKey"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:" // Build the request to OpenAI's API"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" var"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" requestBody "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" JsonSerializer."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Serialize"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"new"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" model "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:' "'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"gpt-4"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" messages "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" new"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"[] { "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"new"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" { role "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:' "'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"user"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", content "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" prompt } }"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" });"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" var"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" request "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" new"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" HttpRequest"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" Method "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" SpacetimeDB.HttpMethod.Post,"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" Uri "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:' "'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"}
1,children:"https://api.openai.com/v1/chat/completions"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" Headers "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" new"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" List"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"<"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"HttpHeader"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:">"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" new"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" HttpHeader"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Content-Type"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"application/json"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"),"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" new"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" HttpHeader"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Authorization"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'$"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Bearer "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"{"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"apiKey"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"}"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" },"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" Body "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" HttpBody."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"FromString"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(requestBody)"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" };"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:" // Make the HTTP request"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" var"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx.Http."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Send"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(request)."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"UnwrapOrThrow"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"();"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" if"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" (response.StatusCode "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"!="}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" 200"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" throw"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" new"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Exception"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'$"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"API returned status "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"{"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"response"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"StatusCode"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"}"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" var"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" bodyStr "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response.Body."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"ToStringUtf8Lossy"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"();"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:" // Parse the response"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" var"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" aiResponse "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" ExtractContent"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(bodyStr)"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" ??"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" throw"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" new"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Exception"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Failed to parse AI response"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:" // Store the conversation in the database"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"WithTx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"txCtx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" =>"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" txCtx.Db.AiMessage."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Insert"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"new"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" AiMessage"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" User "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" txCtx.Sender,"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" Prompt "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" prompt,"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" Response "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" aiResponse,"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" CreatedAt "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" txCtx.Timestamp"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" });"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" return"}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" 0"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" });"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" return"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" aiResponse;"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" private"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" static"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" string"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"? "}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"ExtractContent"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"string"}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" json"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:" // Simple extraction - in production, use proper JSON parsing"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" var"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" doc "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" JsonDocument."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"Parse"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(json);"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" return"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" doc.RootElement"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"GetProperty"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"choices"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")["}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"0"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"GetProperty"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"message"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"GetProperty"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"content"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"GetString"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"();"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})})}),(0,c.jsx)(a.A,{value:"rust",label:"Rust",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"use"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" spacetimedb"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"{table, procedure, "}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"ProcedureContext"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"Identity"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"Timestamp"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"};"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"#[table(name "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ai_message, public)]"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"pub"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" struct"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" AiMessage"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" user"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Identity"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" prompt"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" String"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" String"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" created_at"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Timestamp"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"#[procedure]"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"pub"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" fn"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" ask_ai"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" &mut"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" ProcedureContext"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", prompt"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" String"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", api_key"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" String"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:") "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"->"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Result"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"<"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"String"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"String"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"> {"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:" // Build the request to OpenAI's API"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" let"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" request_body "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" format!"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:' r#"{{"model": "gpt-4", "messages": [{{"role": "user", "content": "{}"}}]}}"#'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" prompt"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"replace"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"'\"'"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:'\\\\\\"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" );"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" let"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" request "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" spacetimedb"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"http"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"Request"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"::"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"builder"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"()"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" ."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"uri"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"https://api.openai.com/v1/chat/completions"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" ."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"method"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"POST"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" ."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"header"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"Content-Type"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"application/json"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" ."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"header"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"Authorization"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"format!"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"Bearer {}"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", api_key))"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" ."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"body"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(request_body)"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" ."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"map_err"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"|"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"e"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"|"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" format!"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"Failed to build request: {e}"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"))"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"?"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:" // Make the HTTP request"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" let"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"http"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"send"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(request)"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" ."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"map_err"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"|"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"e"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"|"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" format!"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"HTTP request failed: {e:?}"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"))"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"?"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" let"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" (parts, body) "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"into_parts"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"();"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" if"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" parts"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"status "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"!="}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" 200"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" return"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Err"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"format!"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"API returned status {}"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", parts"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"status));"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" let"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" body_str "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" body"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"into_string_lossy"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"();"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:" // Parse the response (simplified - in production use serde_json)"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" let"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ai_response "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" extract_content"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"&"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"body_str)"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" ."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"ok_or"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"Failed to parse AI response"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"?"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:" // Store the conversation in the database"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"with_tx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"|"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"tx_ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"|"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" tx_ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"db"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"ai_message"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"()"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"insert"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"AiMessage"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" user"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" tx_ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"sender,"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" prompt"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" prompt"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"clone"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(),"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ai_response"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"clone"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(),"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" created_at"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" tx_ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"timestamp,"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" });"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" });"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Ok"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(ai_response)"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"fn"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" extract_content"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(json"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" &"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"str"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:") "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"->"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Option"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"<"}),(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"String"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"> {"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:" // Simple extraction - in production, use proper JSON parsing"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" let"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" content_start "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" json"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"find"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:'\\"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"content"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:'\\"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:':"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"?"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" +"}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:" 11"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" let"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" content_end "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" json[content_start"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:".."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"]"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"find"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"'\"'"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:")"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"?"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" +"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" content_start;"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Some"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(json[content_start"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:".."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"content_end]"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"to_string"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"())"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"}"})})]})})})})]}),"\n",(0,c.jsx)(l.h3,{id:"calling-from-a-client",children:"Calling from a client"}),"\n",(0,c.jsxs)(o.A,{groupId:"client-language",queryString:!0,children:[(0,c.jsx)(a.A,{value:"typescript",label:"TypeScript",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#6272A4"},children:"// Call the procedure and wait for the AI response"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"const"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" response "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"="}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" await"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" ctx.procedures."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"askAi"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"({"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" prompt"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:' "'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"What is SpacetimeDB?"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" apiKey"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:":"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" process.env."}),(0,c.jsx)(l.span,{style:{color:"#BD93F9"},children:"OPENAI_API_KEY"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:","})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"});"})}),"\n",(0,c.jsx)(l.span,{className:"line"}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"console."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"log"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"AI says:"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", response);"})]})]})})})}),(0,c.jsx)(a.A,{value:"csharp",label:"C#",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"ctx.Procedures."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"AskAi"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"What is SpacetimeDB?"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", apiKey, ("}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"ctx"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", "}),(0,c.jsx)(l.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"result"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:") "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"=>"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"{"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" if"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" (result.IsSuccess)"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" Console."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"WriteLine"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'$"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"AI says: "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"{"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"result"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"Value"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"}"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" else"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" Console."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"WriteLine"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'$"'}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"Error: "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"{"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"result"}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"Error"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"}"}),(0,c.jsx)(l.span,{style:{color:"#E9F284"},children:'"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"});"})})]})})})}),(0,c.jsx)(a.A,{value:"rust",label:"Rust",children:(0,c.jsx)(c.Fragment,{children:(0,c.jsx)(l.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,c.jsxs)(l.code,{children:[(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"ctx"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"procedures"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"ask_ai_then"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:' "What is SpacetimeDB?"'}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"."}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:"to_string"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"}
1,children:"(),"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" api_key,"})}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" |"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"_ctx, result"}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"|"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:" match"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" result {"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Ok"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(response) "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"=>"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" println!"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"AI says: {}"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", response),"})]}),"\n",(0,c.jsxs)(l.span,{className:"line",children:[(0,c.jsx)(l.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Err"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"(e) "}),(0,c.jsx)(l.span,{style:{color:"#FF79C6"},children:"=>"}),(0,c.jsx)(l.span,{style:{color:"#50FA7B"},children:" eprintln!"}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:"("}),(0,c.jsx)(l.span,{style:{color:"#F1FA8C"},children:'"Error: {:?}"'}),(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:", e),"})]}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" }"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:" },"})}),"\n",(0,c.jsx)(l.span,{className:"line",children:(0,c.jsx)(l.span,{style:{color:"#F8F8F2"},children:");"})})]})})})})]}),"\n",(0,c.jsx)(l.admonition,{type:"warning",children:(0,c.jsxs)(l.p,{children:[(0,c.jsx)(l.strong,{children:"Security note:"})," Never hardcode API keys in your client code. Consider storing them securely on the server side or using environment variables during development."]})})]})}function h(s={}){const{wrapper:l}={...(0,r.R)(),...s.components};return l?(0,c.jsx)(l,{...s,children:(0,c.jsx)(p,{...s})}):p(s)}},31023:(s,l,e)=>{e.d(l,{A:()=>n});const n=e.p+"assets/images/ue-blueprint-calling-procedure-265d7e3c7cf419716bdd4d6fbdfd2489.png"},43244:(s,l,e)=>{e.d(l,{A:()=>o});e(7378);var n=e(23372);const c={tabItem:"tabItem_w6aI"};var r=e(86106);function o({children:s,hidden:l,className:e}){return(0,r.jsx)("div",{role:"tabpanel",className:(0,n.A)(c.tabItem,e),hidden:l,children:s})}},51471:(s,l,e)=>{e.d(l,{A:()=>A});var n=e(7378),c=e(23372),r=e(23418),o=e(46585),a=e(30505),F=e(99202),i=e(81922),t=e(46923),d=e(73126);function p(s){return n.Children.toArray(s).filter(s=>"\n"!==s).map(s=>{if(!s||(0,n.isValidElement)(s)&&function(s){const{props:l}=s;return!!l&&"object"==typeof l&&"value"in l}(s))return s;throw new Error(`Docusaurus error: Bad <Tabs> child <${"string"==typeof s.type?s.type:s.type.name}>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop.`)})?.filter(Boolean)??[]}function h(s){const{values:l,children:e}=s;return(0,n.useMemo)(()=>{const s=l??function(s){return p(s).map(({props:{value:s,label:l,attributes:e,default:n}})=>({value:s,label:l,attributes:e,default:n}))}(e);return function(s){const l=(0,t.XI)(s,(s,l)=>s.value===l.value);if(l.length>0)throw new Error(`Docusaurus error: Duplicate values "${l.map(s=>s.value).join(", ")}" found in <Tabs>. Every value needs to be unique.`)}(s),s},[l,e])}function x({value:s,tabValues:l}){return l.some(l=>l.value===s)}function j({queryString:s=!1,groupId:l}){const e=(0,a.W6)(),c=function({queryString:s=!1,groupId:l}){if("string"==typeof s)return s;if(!1===s)return null;if(!0===s&&!l)throw new Error('Docusaurus error: The <Tabs> component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return l??null}({queryString:s,groupId:l});return[(0,i.aZ)(c),(0,n.useCallback)(s=>
1{if(!c)return;const l=new URLSearchParams(e.location.search);l.set(c,s),e.replace({...e.location,search:l.toString()})},[c,e])]}function y(s){const{defaultValue:l,queryString:e=!1,groupId:c}=s,r=h(s),[o,a]=(0,n.useState)(()=>function({defaultValue:s,tabValues:l}){if(0===l.length)throw new Error("Docusaurus error: the <Tabs> component requires at least one <TabItem> children component");if(s){if(!x({value:s,tabValues:l}))throw new Error(`Docusaurus error: The <Tabs> has a defaultValue "${s}" but none of its children has the corresponding value. Available values are: ${l.map(s=>s.value).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return s}const e=l.find(s=>s.default)??l[0];if(!e)throw new Error("Unexpected error: 0 tabValues");return e.value}({defaultValue:l,tabValues:r})),[i,t]=j({queryString:e,groupId:c}),[p,y]=function({groupId:s}){const l=function(s){return s?`docusaurus.tab.${s}`:null}(s),[e,c]=(0,d.Dv)(l);return[e,(0,n.useCallback)(s=>{l&&c.set(s)},[l,c])]}({groupId:c}),m=(()=>{const s=i??p;return x({value:s,tabValues:r})?s:null})();(0,F.A)(()=>{m&&a(m)},[m]);return{selectedValue:o,selectValue:(0,n.useCallback)(s=>{if(!x({value:s,tabValues:r}))throw new Error(`Can't select invalid tab value=${s}`);a(s),t(s),y(s)},[t,y,r]),tabValues:r}}var m=e(52538);const u={tabList:"tabList_duiv",tabItem:"tabItem_a1H9"};var C=e(86106);function N({className:s,block:l,selectedValue:e,selectValue:n,tabValues:r}){const a=[],{blockElementScrollPositionUntilNextRender:F}=(0,o.a_)(),i=s=>{const l=s.currentTarget,c=a.indexOf(l),o=r[c].value;o!==e&&(F(l),n(o))},t=s=>{let l=null;switch(s.key){case"Enter":i(s);break;case"ArrowRight":{const e=a.indexOf(s.currentTarget)+1;l=a[e]??a[0];break}case"ArrowLeft":{const e=a.indexOf(s.currentTarget)-1;l=a[e]??a[a.length-1];break}}l?.focus()};return(0,C.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,c.A)("tabs",{"tabs--block":l},s),children:r.map(({value:s,label:l,attributes:n})=>(0,C.jsx)("li",{role:"tab",tabIndex:e===s?0:-1,"aria-selected":e===s,ref:s=>{a.push(s)},onKeyDown:t,onClick:i,...n,className:(0,c.A)("tabs__item",u.tabItem,n?.className,{"tabs__item--active":e===s}),children:l??s},s))})}function b({lazy:s,children:l,selectedValue:e}){const r=(Array.isArray(l)?l:[l]).filter(Boolean);if(s){const s=r.find(s=>s.props.value===e);return s?(0,n.cloneElement)(s,{className:(0,c.A)("margin-top--md",s.props.className)}):null}return(0,C.jsx)("div",{className:"margin-top--md",children:r.map((s,l)=>(0,n.cloneElement)(s,{key:l,hidden:s.props.value!==e}))})}function B(s){const l=y(s);return(0,C.jsxs)("div",{className:(0,c.A)(r.G.tabs.container,"tabs-container",u.tabList),
1children:[(0,C.jsx)(N,{...l,...s}),(0,C.jsx)(b,{...l,...s})]})}function A(s){const l=(0,m.A)();return(0,C.jsx)(B,{...s,children:p(s.children)},String(l))}},56225:(s,l,e)=>{e.d(l,{R:()=>o,x:()=>a});var n=e(7378);const c={},r=n.createContext(c);function o(s){const l=n.useContext(r);return n.useMemo(function(){return"function"==typeof s?s(l):{...l,...s}},[l,s])}function a(s){let l;return l=s.disableParentContext?"function"==typeof s.components?s.components(c):s.components||c:o(s.components),n.createElement(r.Provider,{value:l},s.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.