PageSourceSearch

https://www.smartchats.ai/_site/_next/static/chunks/pages/docs/pac…/smartchats-database-70cb8ee740b9a3b8.js

js smartchats.ai collected 2026-10-05 15:06:43 UTC 25,912 bytes, 1 lines download raw bytes

1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[772],{7499:function(s,i,e){(window.__NEXT_P=window.__NEXT_P||[]).push(["/docs/packages/smartchats-database",function(){return e(8623)}])},8623:function(s,i,e){"use strict";e.r(i),e.d(i,{useTOC:function(){return d}});var n=e(2322),r=e(4974),t=e(5889),a=e(7854),l=e(8095),h=e(5733);function d(s){let i={code:"code",...(0,a.a)()};return[{value:"Layered model",id:"layered-model",depth:2},{value:"What’s in the package",id:"whats-in-the-package",depth:2},{value:"Quick start",id:"quick-start",depth:2},{value:"Building a query",id:"building-a-query",depth:3},{value:"Running a query (Node — direct SurrealDB)",id:"running-a-query-node--direct-surrealdb",depth:3},{value:(0,n.jsxs)(n.Fragment,{children:["Running a query (browser — through ",(0,n.jsx)(i.code,{children:"DataAPI"}),")"]}),id:"running-a-query-browser--through-dataapi",depth:3},{value:"Operations — multi-step composition",id:"operations--multi-step-composition",depth:2},{value:"Schema",id:"schema",depth:2},{value:"Why no I/O at the query layer?",id:"why-no-io-at-the-query-layer",depth:2},{value:"Source",id:"source",depth:2}]}i.default=(0,r.c)(function(s){let{toc:i=d(s)}=s,e={code:"code",h1:"h1",h2:"h2",h3:"h3",li:"li",ol:"ol",p:"p",pre:"pre",span:"span",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,a.a)(),...s.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h1,{children:"smartchats-database"}),"\n",(0,n.jsxs)(e.p,{children:["The ",(0,n.jsx)(e.strong,{children:"data layer"})," for SmartChats. Pure SurrealQL query builders, a\nclient abstraction, and a multi-step operations layer — all without\nany I/O at the lowest layer."]}),"\n",(0,n.jsxs)(e.p,{children:["The principle: ",(0,n.jsx)(e.strong,{children:"separate query construction from query execution"}),".\nBuilders return ",(0,n.jsx)(e.code,{children:"QuerySpec"})," values (a query string + variables); the\nruntime hands those specs to a ",(0,n.jsx)(e.code,{children:"Client"})," that knows how to talk to a\nreal SurrealDB instance. This lets the same query code run in the\nbrowser (cloud-side, via auth), in Node (CLI/MCP, direct SDK), or in\ntests (mocked client)."]}),"\n",(0,n.jsx)(e.h2,{id:i[0].id,children:i[0].value}),"\n",(0,n.jsx)(e.pre,{tabIndex:"0","data-language":"plaintext","data-word-wrap":"",children:(0,n.jsxs)(e.code,{children:[(0,n.jsx)(e.span,{children:(0,n.jsx)(e.span,{children:"your code  →  operations.X(args)      ← multi-step (e.g. importBundle)"})}),"\n",(0,n.jsx)(e.span,{children:(0,n.jsx)(e.span,{children:"                       │"})}),"\n",(0,n.jsx)(e.span,{children:(0,n.jsx)(e.span,{children:"                       ▼"})}),"\n",(0,n.jsx)(e.span,{children:(0,n.jsx)(e.span,{children:"              queries.Y(args)         ← pure: args → { query, variables }"})}),"\n",(0,n.jsx)(e.span,{children:(0,n.jsx)(e.span,{children:"                       │"})}),"\n",(0,n.jsx)(e.span,{children:(0,n.jsx)(e.span,{children:"                       ▼"})}),"\n",(0,n.jsx)(e.span,{children:(0,n.jsx)(e.span,{children:"              client.query(spec)      ← I/O happens here"})}),"\n",(0,n.jsx)(e.span,{children:(0,n.jsx)(e.span,{children:"                  ╱              ╲"})}),"\n",(0,n.jsx)(e.span,{children:(0,n.jsx)(e.span,{children:"        Cloud client         Local SDK client"})}),"\n",(0,n.jsx)(e.span,{children:(0,n.jsx)(e.span,{children:"        (firebase auth        (createClient — direct"})}),"\n",(0,n.jsx)(e.span,{children:(0,n.jsx)(e.span,{children:"         + Functions          SurrealDB connection)"})}),"\n",(0,n.jsx)(e.span,{children:(0,n.jsx)(e.span,{children:"         relay)"})})]})}),"\n",(0,n.jsx)(e.h2,{id:i[1].id,children:i[1].value}),"\n",(0,n.jsxs)(e.table,{children:[(0,n.jsx)(e.thead,{children:(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.th,{children:"Module"}),(0,n.jsx)(e.th,{children:"Purpose"})]})}),(0,n.jsxs)(e.tbody,{children:[(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:"queries/*"})}),(0,n.jsxs)(e.td,{children:["Pure ",(0,n.jsx)(e.code,{children:"QuerySpec"})," builders — one file per domain (sessions, logs, knowledge_graph, todos, byo_keys, etc.)"]})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:"operations/*"})}),(0,n.jsxs)(e.td,{children:["Multi-step ops that compose queries: ",(0,n.jsx)(e.code,{children:"exportBun
1dle"}),", ",(0,n.jsx)(e.code,{children:"importBundle"}),", etc."]})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:"schema/*"})}),(0,n.jsx)(e.td,{children:"Canonical SurrealQL schema for cloud + local variants"})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:"client.ts"})}),(0,n.jsxs)(e.td,{children:[(0,n.jsx)(e.code,{children:"createClient"}),", ",(0,n.jsx)(e.code,{children:"createLazyClient"}),", ",(0,n.jsx)(e.code,{children:"createUserClient"})," — direct-to-SurrealDB connection factories"]})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:"data_api.ts"})}),(0,n.jsxs)(e.td,{children:["Backend-flavored factories (",(0,n.jsx)(e.code,{children:"makeCloudDataAPI"}),", ",(0,n.jsx)(e.code,{children:"makeLocalDataAPI"}),") for use with ",(0,n.jsx)(e.code,{children:"smartchats-backend"})]})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:"types.ts"})}),(0,n.jsxs)(e.td,{children:[(0,n.jsx)(e.code,{children:"QuerySpec"}),", ",(0,n.jsx)(e.code,{children:"AuditFields"})]})]})]})]}),"\n",(0,n.jsx)(e.h2,{id:i[2].id,children:i[2].value}),"\n",(0,n.jsx)(e.h3,{id:i[3].id,children:i[3].value}),"\n",(0,n.jsx)(e.pre,{icon:h.KP,tabIndex:"0","data-language":"ts","data-word-wrap":"",children:(0,n.jsxs)(e.code,{children:[(0,n.jsxs)(e.span,{children:[(0,n.jsx)(e.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:"import"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:" { queries } "}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:"from"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#032F62","--shiki-dark":"#9ECBFF"},children:" 'smartchats-database'"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:";"})]}),"\n",(0,n.jsx)(e.span,{children:" "}),"\n",(0,n.jsxs)(e.span,{children:[(0,n.jsx)(e.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:"const"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#005CC5","--shiki-dark":"#79B8FF"},children:" spec"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:" ="}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:" queries."}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#6F42C1","--shiki-dark":"#B392F0"},children:"listSessions"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:"({"})]}),"\n",(0,n.jsxs)(e.span,{children:[(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:"  app: "}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#032F62","--shiki-dark":"#9ECBFF"},children:"'smartchats'"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:","})]}),"\n",(0,n.jsxs)(e.span,{children:[(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:"  since: Date."}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#6F42C1","--shiki-dark":"#B392F0"},children:"now"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:"() "}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:"-"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#005CC5","--shiki-dark":"#79B8FF"},children:" 7"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:" *"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#005CC5","--shiki-dark":"#79B8FF"},children:" 86400_000"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:","})]}),"\n",(0,n.jsxs)(e.span,{children:[(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:"  limit: "}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#005CC5","--shiki-dark":"#79B8FF"},children:"50"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:","})]}),"\n",(0,n.jsx)(e.span,{children:(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:"});"})}),"\n",(0,n.jsx)(e.span,{children:" "}),"\n",(0,n.jsx)(e.span,{children:(0,n.jsx)(e.span,{style:{"--shiki-light":"#6A737D","--shiki-dark":"#6A737D"},children:'// spec is { query: "SELECT ... FROM session WHERE ...", variables: {...} }'})})]})}),"\n",(0,n.jsx)(e.p,{children:"The builder has zero side effects. You can log it, snapshot-test it,\ninspect what would run — without touching a database."}),"\n",(0,n.jsx)(e.h3,{id:i[4].id,children:i[4].value}),"\n",(0,n.jsx)(e.pre,{icon:h.KP,tabIndex:"0","data-language":"ts","data-word-wrap":"",children:(0,n.jsxs)(e.code,{children:[(0,n.jsxs)(e.span,{children:[(0,n.jsx)(e.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:"import"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:" { createClient, queries } "}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:"from"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#032F62","--shiki-dark":"#9ECBFF"},children:" 'smartchats-database'"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:";"})]}),"\n",(0,n.jsx)(e.span,{children:" "}),"\n",(0,n.jsxs)(e.span,{children:[(0,n.jsx)(e.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:"const"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#005CC5","--shiki-dark":"#79B8FF"},children:" client"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:" ="}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:" await"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#6F42C1","--shiki-dark":"#B392F0"},children:" createClient"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:"({"})]}),"\n",(0,n.jsxs)(e.span,{children:[(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:"  url: "}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#032F62","--shiki-dark":"#9ECBFF"},children:"'ws://localhost:8001'"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:","})]}),"\n",(0,n.jsxs)(e.span,{children:[(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:"  ns: "}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#032F62","--shiki-dark":"#9ECBFF"},children:"'smartchats'"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:","})]}),"\n",(0,n.jsxs)(e.span,{children:[(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:"  db: "}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#032F62","--shiki-dark":"#9ECBFF"},children:"'smartchats'"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:","})]}),"\n",(0,n.jsxs)(e.span,{children:[(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:"  user: "}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#032F62","--shiki-dark":"#9ECBFF"},children:"'root'"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:","})]}),"\n",(0,n.jsxs)(e.span,{children:[(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:"  password: "}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#032F62","--shiki-dark":"#9ECBFF"},children:"'root'"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:","})]}),"\n",(0,n.jsx)(e.span,{children:(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:"});"})}),"\n",(0,n.jsx)(e.span,{children:" "}),"\n",(0,n.jsxs)(e.span,{children:[(0,n.jsx)(e.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:"const"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#005CC5","--shiki-dark":"#79B8FF"},children:" sessions"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:" ="}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:" await"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:" client."}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#6F42C1","--shiki-dark":"#B392F0"},children:"query"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:"(queries."}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#6F42C1","--shiki-dark":"#B392F0"},children:"listSessions"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:"({ limit: "}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#005CC5","--shiki-dark":"#79B8FF"},children:"10"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:" }));"})]})]})}),"\n",(0,n.jsx)(e.h3,{id:i[5].id,children:i[5].value}),"\n",(0,n.jsx)(e.p,{children:"The browser app doesn’t talk to SurrealDB directly. It goes through\nthe backend contract:"}),"\n",(0,n.jsx)(e.pre,{icon:h.KP,tabIndex:"0","data-language":"ts","data-word-wrap":"",children:(0,n.jsxs)(e.code,{children:[(0,n.jsxs)(e.span,{children:[(0,n.jsx)(e.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:"import"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:" { getBackend } "}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:"from"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#032F62","--shiki-dark":"#9ECBFF"},children:" '@/lib/backend'"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:";"})]}),"\n",(0,n.jsxs)(e.span,{children:[(0,n.jsx)(e.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:"import"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:" { queries } "}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:"from"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#032F62","--shiki-dark":"#9ECBFF"},children:" 'smartchats-database'"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:";"})]}),"\n",(0,n.jsx)(e.span,{children:" "}),"\n",(0,n.jsxs)(e.span,{children:[(0,n.jsx)(e.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:"const"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#005CC5","--shiki-dark":"#79B8FF"},children:" backend"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:" ="}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#6F42C1","--shiki-dark":"#B392F0"},children:" getBackend"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"}
1,children:"();"})]}),"\n",(0,n.jsxs)(e.span,{children:[(0,n.jsx)(e.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:"const"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#005CC5","--shiki-dark":"#79B8FF"},children:" sessions"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:" ="}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:" await"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:" backend.data."}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#6F42C1","--shiki-dark":"#B392F0"},children:"query"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:"(queries."}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#6F42C1","--shiki-dark":"#B392F0"},children:"listSessions"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:"({ limit: "}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#005CC5","--shiki-dark":"#79B8FF"},children:"10"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:" }));"})]})]})}),"\n",(0,n.jsxs)(e.p,{children:["Same ",(0,n.jsx)(e.code,{children:"QuerySpec"}),". The cloud backend wraps it in a Firebase callable\nthat relays to SurrealDB; the local backend talks to SurrealDB directly.\nYour call site doesn’t change."]}),"\n",(0,n.jsx)(e.h2,{id:i[6].id,children:i[6].value}),"\n",(0,n.jsxs)(e.p,{children:["Some workflows need several queries + ordering + error handling.\nThose live in ",(0,n.jsx)(e.code,{children:"operations/"}),":"]}),"\n",(0,n.jsx)(e.pre,{icon:h.KP,tabIndex:"0","data-language":"ts","data-word-wrap":"",children:(0,n.jsxs)(e.code,{children:[(0,n.jsxs)(e.span,{children:[(0,n.jsx)(e.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:"import"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:" { operations } "}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:"from"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#032F62","--shiki-dark":"#9ECBFF"},children:" 'smartchats-database'"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:";"})]}),"\n",(0,n.jsx)(e.span,{children:" "}),"\n",(0,n.jsxs)(e.span,{children:[(0,n.jsx)(e.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:"const"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#005CC5","--shiki-dark":"#79B8FF"},children:" bundle"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:" ="}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#D73A49","--shiki-dark":"#F97583"},children:" await"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:" operations."}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#6F42C1","--shiki-dark":"#B392F0"},children:"exportBundle"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:"(client, {"})]}),"\n",(0,n.jsxs)(e.span,{children:[(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:"  app: "}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#032F62","--shiki-dark":"#9ECBFF"},children:"'smartchats'"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:","})]}),"\n",(0,n.jsxs)(e.span,{children:[(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:"  sessionId: "}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#032F62","--shiki-dark":"#9ECBFF"},children:"'ses_xxx'"}),(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:","})]}),"\n",(0,n.jsx)(e.span,{children:(0,n.jsx)(e.span,{style:{"--shiki-light":"#24292E","--shiki-dark":"#E1E4E8"},children:"});"})}),"\n",(0,n.jsx)(e.span,{children:" "}),"\n",(0,n.jsx)(e.span,{children:(0,n.jsx)(e.span,{style:{"--shiki-light":"#6A737D","--shiki-dark":"#6A737D"},children:"// bundle has events + logs + KG snapshot, ready to feed importBundle elsewhere"})})]})}),"\n",(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:"exportBun
1dle"})," and ",(0,n.jsx)(e.code,{children:"importBundle"})," are the bridge for “move my data\nfrom cloud to local” — same shape on both sides."]}),"\n",(0,n.jsx)(e.h2,{id:i[7].id,children:i[7].value}),"\n",(0,n.jsxs)(e.p,{children:["Canonical schema lives at ",(0,n.jsx)(e.code,{children:"packages/smartchats-database/src/schema/"}),".\nTwo variants exist (cloud + local) for fields that differ between\nthe two environments. The schema file is what gets applied when you\nrun ",(0,n.jsx)(e.code,{children:"bin/cloud_test_db"})," or initialize a fresh local instance."]}),"\n",(0,n.jsxs)(l.U,{type:"info",children:[(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.strong,{children:"SurrealDB v3."})," SmartChats moved to v3.0.5 in 2026-Q2.\nNotable v3 differences:"]}),(0,n.jsxs)(e.ul,{children:["\n",(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:"type::record"})," replaces ",(0,n.jsx)(e.code,{children:"type::thing"})," for record constructors"]}),"\n",(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:"type::is_string(x)"})," (not ",(0,n.jsx)(e.code,{children:"type::is::string(x)"}),") for type predicates"]}),"\n",(0,n.jsxs)(e.li,{children:["The ",(0,n.jsx)(e.code,{children:"logs"})," table is SCHEMALESS — ",(0,n.jsx)(e.code,{children:"content"})," can be NONE, a string,\nor a record link; query builders that pattern-match on\n",(0,n.jsx)(e.code,{children:"content"})," must guard with ",(0,n.jsx)(e.code,{children:"type::is_string(content)"})]}),"\n"]})]}),"\n",(0,n.jsx)(e.h2,{id:i[8].id,children:i[8].value}),"\n",(0,n.jsx)(e.p,{children:"Three reasons that compound:"}),"\n",(0,n.jsxs)(e.ol,{children:["\n",(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:"Tests."})," Snapshot tests on ",(0,n.jsx)(e.code,{children:"QuerySpec"})," outputs catch query\nregressions without spinning up a database. The bug-detection\nreach of “the query string changed” is huge."]}),"\n",(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:"Reuse."})," The exact same query runs in the browser (cloud\nrelay), in Node (direct SDK), and in tests (mocked client).\nOne implementation, three deploys."]}),"\n",(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:"Cloud vs local symmetry."})," Both backends accept ",(0,n.jsx)(e.code,{children:"QuerySpec"}),".\nAdding a new query means writing one builder, not two."]}),"\n"]}),"\n",(0,n.jsx)(e.h2,{id:i[9].id,children:i[9].value}),"\n",(0,n.jsxs)(e.ul,{children:["\n",(0,n.jsxs)(e.li,{children:["Package: ",(0,n.jsx)(e.code,{children:"packages/smartchats-database/"})]}),"\n",(0,n.jsxs)(e.li,{children:["Entry: ",(0,n.jsx)(e.code,{children:"packages/smartchats-database/src/index.ts"})]}),"\n",(0,n.jsxs)(e.li,{children:["Query builders: ",(0,n.jsx)(e.code,{children:"packages/smartchats-database/src/queries/"})]}),"\n",(0,n.jsxs)(e.li,{children:["Operations: ",(0,n.jsx)(e.code,{children:"packages/smartchats-database/src/operations/"})]}),"\n",(0,n.jsxs)(e.li,{children:["Schema: ",(0,n.jsx)(e.code,{children:"packages/smartchats-database/src/schema/"})]}),"\n"]})]})},"/docs/packages/smartchats-database",{filePath:"pages/docs/packages/smartchats-database.mdx",timestamp:1786799065e3,pageMap:t.v,frontMatter:{},title:"smartchats-database"},"undefined"==typeof RemoteContent?d:RemoteContent.useTOC)},8095:function(s,i,e){"use strict";e.d(i,{U:function(){return h}});var n=e(2322),r=e(489),t=e(5733);let a={default:"\uD83D\uDCA1",error:"\uD83D\uDEAB",info:(0,n.jsx)(t.AV,{className:"_mt-1"}),warning:"⚠️"},l={default:(0,r.Z)("_border-orange-100 _bg-orange-50 _text-orange-800 dark:_border-orange-400/30 dark:_bg-orange-400/20 dark:_text-orange-300"),error:(0,r.Z)("_border-red-200 _bg-red-100 _text-red-900 dark:_border-red-200/30 dark:_bg-red-900/30 dark:_text-red-200"),info:(0,r.Z)("_border-blue-200 _bg-blue-100 _text-blue-900 dark:_border-blue-200/30 dark:_bg-blue-900/30 dark:_text-blue-200"),warning:(0,r.Z)("_border-yellow-100 _bg-yellow-50 _text-yellow-900 dark:_border-yellow-200/30 dark:_bg-yellow-700/30 dark:_text-yellow-200")};function h({children:s,type:i="default",emoji:e=a[i]}){return(0,n.jsxs)("div",{className:(0,r.Z)("nextra-callout _overflow-x-auto _mt-6 _flex _rounded-lg _border _py-2 ltr:_pr-4 rtl:_pl-4","contrast-more:_border-current contrast-more:dark:_border-current",l[i]),children:[(0,n.jsx)("div",{className:"_select-none _text-xl ltr:_pl-3 ltr:_pr-2 rtl:_pr-3 rtl:_pl-2",style:{fontFamily:'"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"'},children:e}),(0,n.jsx)("div",{className:"_w-full _min-w-0 _leading-7",children:s})]})}},5889:function(s,i,e){"use strict";e.d(i,{v:function(){return n}});let n=[{name:"docs",route:"/docs",children:[{data:{index:"Welcome",quickstart:"Quick Start","self-host":"Self-Hosting",cli:"CLI Reference",architecture:"Architecture",packages:"Packages",mcp:"MCP Server",contributing:"Contributing"}}
1,{name:"architecture",route:"/docs/architecture",frontMatter:{sidebarTitle:"Architecture"}},{name:"cli",route:"/docs/cli",frontMatter:{sidebarTitle:"CLI"}},{name:"contributing",route:"/docs/contributing",frontMatter:{sidebarTitle:"Contributing"}},{name:"index",route:"/docs",frontMatter:{sidebarTitle:"Index"}},{name:"mcp",route:"/docs/mcp",frontMatter:{sidebarTitle:"Mcp"}},{name:"packages",route:"/docs/packages",children:[{data:{index:"Overview",tivi:"tivi — Voice Interface",cortex:"cortex — Agent Runtime","smartchats-database":"smartchats-database","smartchats-backend":"smartchats-backend","smartchats-sessions":"smartchats-sessions","llm-service":"llm-service",simi:"simi — Workflow Tests"}},{name:"cortex",route:"/docs/packages/cortex",frontMatter:{sidebarTitle:"Cortex"}},{name:"index",route:"/docs/packages",frontMatter:{sidebarTitle:"Index"}},{name:"llm-service",route:"/docs/packages/llm-service",frontMatter:{sidebarTitle:"Llm Service"}},{name:"simi",route:"/docs/packages/simi",frontMatter:{sidebarTitle:"Simi"}},{name:"smartchats-backend",route:"/docs/packages/smartchats-backend",frontMatter:{sidebarTitle:"Smartchats Backend"}},{name:"smartchats-database",route:"/docs/packages/smartchats-database",frontMatter:{sidebarTitle:"Smartchats Database"}},{name:"smartchats-sessions",route:"/docs/packages/smartchats-sessions",frontMatter:{sidebarTitle:"Smartchats Sessions"}},{name:"tivi",route:"/docs/packages/tivi",frontMatter:{sidebarTitle:"Tivi"}}]},{name:"quickstart",route:"/docs/quickstart",frontMatter:{sidebarTitle:"Quickstart"}},{name:"self-host",route:"/docs/self-host",frontMatter:{sidebarTitle:"Self Host"}}]}]}},function(s){s.O(0,[974,888,774,179],function(){return s(s.s=7499)}),_N_E=s.O()}]);

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.