palbase 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai/index.js +2 -2
- package/dist/backend/engine.js +2 -2
- package/dist/backend/env.js +1 -1
- package/dist/backend/index.js +9 -9
- package/dist/backend/stack.js +1 -1
- package/dist/backend/test.js +2 -2
- package/dist/chunks/5VTGMNPL.js +20 -0
- package/dist/chunks/{ZBOJEH7K.js → BO5KR2EQ.js} +2 -2
- package/dist/chunks/{PJVWGUIT.js → BRBCWPR3.js} +1 -1
- package/dist/chunks/DB3SIBKB.js +2 -0
- package/dist/chunks/EGNEXFTZ.js +2 -0
- package/dist/chunks/{HEXIIGWS.js → FZ3MQOVA.js} +2 -2
- package/dist/chunks/{SU7BP6VF.js → JSJVV43D.js} +1 -1
- package/dist/chunks/K6RRNI23.js +4 -0
- package/dist/chunks/{KDSWK3XW.js → KDWDPSL2.js} +1 -1
- package/dist/chunks/P4Z5E6ZI.js +2 -0
- package/dist/chunks/PDOHT46N.js +2 -0
- package/dist/chunks/PGPQGKH2.js +18 -0
- package/dist/chunks/{G3BK7L3J.js → RBA6V3UO.js} +2 -2
- package/dist/chunks/{X3MTLJRV.js → RO5Y5YU4.js} +1 -1
- package/dist/chunks/{BKVU4I5R.js → TUGRIOFX.js} +2 -2
- package/dist/chunks/WEI32SAJ.js +13 -0
- package/dist/chunks/{5ZJCEQV5.js → WINBISC2.js} +3 -3
- package/dist/chunks/Z5JVQNAZ.js +2 -0
- package/dist/cli.js +121 -120
- package/dist/refuse/ai.js +1 -1
- package/dist/refuse/backend.js +1 -1
- package/dist/refuse/server.js +1 -1
- package/dist/server/index.js +2 -2
- package/dist/server/testing.js +2 -2
- package/dist/web/index.js +2 -2
- package/dist/web/palbe.js +2 -2
- package/dist/web/paywall.js +2 -2
- package/dist/web/ssr.js +2 -2
- package/dist/web/vite.js +2 -2
- package/package.json +2 -2
- package/types/ai/src/ai.d.ts +44 -15
- package/types/ai/src/chats.d.ts +442 -12
- package/types/ai/src/index.d.ts +4 -4
- package/types/ai/src/tools.d.ts +158 -21
- package/types/backend/src/bootstrap.d.ts +8 -0
- package/types/backend/src/container.d.ts +9 -0
- package/types/backend/src/database.d.ts +17 -2
- package/types/backend/src/engine.d.ts +2 -0
- package/types/backend/src/gateways.d.ts +19 -0
- package/types/backend/src/index.d.ts +1 -0
- package/types/backend/src/runtime.d.ts +12 -0
- package/types/backend/src/testing/unit.d.ts +3 -1
- package/types/internal/src/chat.d.ts +168 -3
- package/types/internal/src/modules/ai.d.ts +1305 -57
- package/types/internal/src/modules/auth.d.ts +14 -2
- package/types/internal/src/modules/events.d.ts +2 -2
- package/types/internal/src/modules/machines.d.ts +57 -1
- package/types/internal/src/modules/notify.d.ts +6 -6
- package/types/internal/src/modules/purchases.d.ts +357 -13
- package/types/internal/src/modules/realtime.d.ts +36 -0
- package/types/internal/src/modules/stores.d.ts +259 -22
- package/types/internal/src/transport.d.ts +5 -0
- package/types/server/src/auth/jwt.d.ts +1 -6
- package/types/web/src/auth.d.ts +15 -4
- package/types/web/src/backends.d.ts +1 -1
- package/types/web/src/chat.d.ts +215 -4
- package/types/web/src/client.d.ts +28 -0
- package/types/web/src/gateways.d.ts +4 -3
- package/types/web/src/index.d.ts +3 -2
- package/types/web/src/session.d.ts +11 -1
- package/types/web/src/voice.d.ts +36 -0
- package/dist/chunks/3ALGILOX.js +0 -2
- package/dist/chunks/AIIKXCWN.js +0 -2
- package/dist/chunks/ELEE7XO2.js +0 -18
- package/dist/chunks/G7E26S3Y.js +0 -13
- package/dist/chunks/H2EPK74V.js +0 -20
- package/dist/chunks/JS3TTUHS.js +0 -2
- package/dist/chunks/L3NTI4AZ.js +0 -2
- package/dist/chunks/LEBVOSG6.js +0 -4
- package/dist/chunks/OIA7KLRW.js +0 -2
package/dist/refuse/ai.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! palbase 0.
|
|
1
|
+
/*! palbase 0.8.0 — Palbase SDK License (see LICENSE) */
|
|
2
2
|
throw new Error("palbase/ai is for servers: it speaks with the project secret key, which never goes into a browser or a mobile app \u2014 call your backend, and let it ask the model");
|
package/dist/refuse/backend.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! palbase 0.
|
|
1
|
+
/*! palbase 0.8.0 — Palbase SDK License (see LICENSE) */
|
|
2
2
|
throw new Error("palbase/backend is a server framework: it runs on your backend, never in a browser or a mobile app \u2014 apps use palbase/web (or the native SDKs)");
|
package/dist/refuse/server.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! palbase 0.
|
|
1
|
+
/*! palbase 0.8.0 — Palbase SDK License (see LICENSE) */
|
|
2
2
|
throw new Error("palbase/server is for servers: its secret key never goes into a browser or a mobile app \u2014 apps use palbase/web (or the native SDKs) with the publishable key");
|
package/dist/server/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! palbase 0.
|
|
2
|
-
import{a as c,b as d,c as e,d as f,e as g,f as h,g as i,h as j,i as k,j as l,k as m,l as n,m as o,n as p,o as q,p as r,q as s,r as t}from"../chunks/
|
|
1
|
+
/*! palbase 0.8.0 — Palbase SDK License (see LICENSE) */
|
|
2
|
+
import{a as c,b as d,c as e,d as f,e as g,f as h,g as i,h as j,i as k,j as l,k as m,l as n,m as o,n as p,o as q,p as r,q as s,r as t}from"../chunks/Z5JVQNAZ.js";import"../chunks/KDWDPSL2.js";import{m as b}from"../chunks/EGNEXFTZ.js";import"../chunks/BO5KR2EQ.js";import{b as a}from"../chunks/PDOHT46N.js";import"../chunks/RO5Y5YU4.js";import"../chunks/JSJVV43D.js";export{j as AuthUnavailable,b as EVENT_TYPES,a as PalbaseError,o as ReservationSettled,i as TokenError,l as TokenVerifier,d as WebhookSignatureError,c as createServer,n as isEntitled,t as loadSecrets,q as pages,s as platformOwn,r as processOwn,m as requestAddress,k as sessionStanding,g as signatureHeader,f as verifySignature,e as verifyWebhook,h as verifyWebhookRequest,p as withReservation};
|
package/dist/server/testing.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! palbase 0.
|
|
2
|
-
import{a,b,c,d}from"../chunks/
|
|
1
|
+
/*! palbase 0.8.0 — Palbase SDK License (see LICENSE) */
|
|
2
|
+
import{a,b,c,d}from"../chunks/RBA6V3UO.js";import"../chunks/RO5Y5YU4.js";import"../chunks/JSJVV43D.js";export{a as TestApiError,d as api,b as createTestApi,c as testRun};
|
package/dist/web/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! palbase 0.
|
|
2
|
-
import{a as
|
|
1
|
+
/*! palbase 0.8.0 — Palbase SDK License (see LICENSE) */
|
|
2
|
+
import{a as h,b as g,c as w,d as C,e as v,f as E,g as S,h as k}from"../chunks/DB3SIBKB.js";import{a as T,b,f as P}from"../chunks/WEI32SAJ.js";import"../chunks/WINBISC2.js";import"../chunks/P4Z5E6ZI.js";import"../chunks/EGNEXFTZ.js";import"../chunks/BO5KR2EQ.js";import{b as m}from"../chunks/PDOHT46N.js";import"../chunks/RO5Y5YU4.js";import"../chunks/JSJVV43D.js";var R="oai-events";async function V(e){if(typeof e?.start!="function")throw new TypeError("connectVoice: start(sdp) is the round trip to the app's backend, which starts the voice (chats.voice.start) and answers { id, sdp }");let o=e.rtc??M(),t=e.signal;t?.throwIfAborted();let s=e.audio??O(),c=e.microphone===void 0,a=e.microphone??await o.getUserMedia({audio:!0});if(t?.aborted){if(c)for(let n of a.getTracks())n.stop();throw t.reason}let r=new o.RTCPeerConnection,d=!1,p=()=>{if(!d){if(d=!0,u.close(),r.close(),c)for(let n of a.getTracks())n.stop();s.srcObject!==null&&(s.srcObject=null)}};r.addEventListener("track",n=>{s.srcObject=n.streams[0]??new MediaStream([n.track]),s.play?.()?.catch?.(()=>{})}),r.addEventListener("connectionstatechange",()=>e.onState?.(r.connectionState));for(let n of a.getAudioTracks())r.addTrack(n,a);let u=r.createDataChannel(R);u.addEventListener("message",n=>{let i=x(n.data);i!==void 0&&e.onError?.(i)});let l=()=>p();t?.addEventListener("abort",l,{once:!0});try{await r.setLocalDescription(await r.createOffer()),t?.throwIfAborted(),await A(r,e.iceTimeoutMs??1e4,t);let n=r.localDescription?.sdp;if(!n)throw new Error("connectVoice: the peer connection made no offer");let i=await e.start(n);if(t?.throwIfAborted(),typeof i?.id!="string"||i.id===""||typeof i.sdp!="string"||i.sdp==="")throw new TypeError("connectVoice: start answered no voice \u2014 it is { id, sdp }, chats.voice.start's answer as the backend got it");return await r.setRemoteDescription({type:"answer",sdp:i.sdp}),t?.removeEventListener("abort",l),{id:i.id,peer:r,audio:s,microphone:a,get muted(){return a.getAudioTracks().every(y=>!y.enabled)},mute(y){for(let f of a.getAudioTracks())f.enabled=!y},close:p}}catch(n){throw t?.removeEventListener("abort",l),p(),t?.aborted?t.reason:n}}function A(e,o,t){return e.iceGatheringState==="complete"?Promise.resolve():t?.aborted?Promise.reject(t.reason):new Promise((s,c)=>{let a=()=>{clearTimeout(p),e.removeEventListener("icegatheringstatechange",r),t?.removeEventListener("abort",d)},r=()=>{e.iceGatheringState==="complete"&&(a(),s())},d=()=>{a(),c(t?.reason)},p=setTimeout(()=>{a(),c(new Error(`connectVoice: the network candidates were not gathered in ${o} ms`))},o);e.addEventListener("icegatheringstatechange",r),t?.addEventListener("abort",d,{once:!0})})}function x(e){if(typeof e=="string")try{let o=JSON.parse(e);return o.type!=="error"?void 0:typeof o.error?.message=="string"?o.error.message:typeof o.error?.code=="string"?o.error.code:"the voice failed"}catch{return}}function M(){let e=globalThis;if(typeof e.RTCPeerConnection!="function"||typeof e.navigator?.mediaDevices?.getUserMedia!="function")throw new TypeError("connectVoice: this runtime has no WebRTC (RTCPeerConnection, navigator.mediaDevices): a chat's voice is a browser's");let o=e.navigator.mediaDevices;return{RTCPeerConnection:e.RTCPeerConnection,getUserMedia:t=>o.getUserMedia(t)}}function O(){let e=globalThis.document;if(!e)throw new TypeError("connectVoice: give audio \u2014 the element the voice plays in \u2014 where there is no document");let o=e.createElement("audio");return o.autoplay=!0,o}export{E as Analytics,T as BackendError,C as Channel,P as GatewayError,m as PalbaseError,S as Purchases,v as RealtimeSocket,h as SessionChangedError,V as connectVoice,k as createClient,b as isBackendError,w as localStore,g as memoryStore};
|
package/dist/web/palbe.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! palbase 0.
|
|
2
|
-
import{c as e,d as r,
|
|
1
|
+
/*! palbase 0.8.0 — Palbase SDK License (see LICENSE) */
|
|
2
|
+
import{c as e,d as r,i as t}from"../chunks/WEI32SAJ.js";import"../chunks/P4Z5E6ZI.js";import"../chunks/BO5KR2EQ.js";import"../chunks/PDOHT46N.js";import"../chunks/RO5Y5YU4.js";import"../chunks/JSJVV43D.js";export{e as RESERVED_CLIENT_NAMES,t as __registerBackend,r as isClientName};
|
package/dist/web/paywall.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! palbase 0.
|
|
2
|
-
import{a as e,b as a,c as t,d as l,e as o,f as p,g as r,h as y,i as s,j as P,k as i,l as n,m as w,n as f,o as d,p as m,q as u,r as A,s as c,t as v}from"../chunks/
|
|
1
|
+
/*! palbase 0.8.0 — Palbase SDK License (see LICENSE) */
|
|
2
|
+
import{a as e,b as a,c as t,d as l,e as o,f as p,g as r,h as y,i as s,j as P,k as i,l as n,m as w,n as f,o as d,p as m,q as u,r as A,s as c,t as v}from"../chunks/WINBISC2.js";import"../chunks/PDOHT46N.js";import"../chunks/RO5Y5YU4.js";import"../chunks/JSJVV43D.js";export{w as PAYWALL_COMPONENTS,i as PAYWALL_ICONS,n as PAYWALL_SCHEMA,c as Paywall,a as assetId,p as attributesHeader,f as countdownValues,v as defaultPaywall,e as fontFamily,s as formatPeriod,y as formatPrice,o as htmlDocument,P as packageValues,d as packagesOf,r as parseDuration,t as prepareAssets,A as renderPaywall,m as resolvePaywall,u as resolvePaywallWithPaths,l as unzip};
|
package/dist/web/ssr.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! palbase 0.
|
|
2
|
-
import{h as f}from"../chunks/
|
|
1
|
+
/*! palbase 0.8.0 — Palbase SDK License (see LICENSE) */
|
|
2
|
+
import{h as f}from"../chunks/DB3SIBKB.js";import"../chunks/WEI32SAJ.js";import"../chunks/WINBISC2.js";import"../chunks/P4Z5E6ZI.js";import"../chunks/EGNEXFTZ.js";import"../chunks/BO5KR2EQ.js";import"../chunks/PDOHT46N.js";import"../chunks/RO5Y5YU4.js";import"../chunks/JSJVV43D.js";var C=Object.freeze({"Cache-Control":"private, no-cache, no-store, must-revalidate, max-age=0",Expires:"0",Pragma:"no-cache"}),x={path:"/",sameSite:"lax",secure:!0,httpOnly:!1,maxAge:400*24*60*60},u=3180,k=5*6e4;function d(t){let e=/^pb_([a-z0-9]+)_c/.exec(t)?.[1];if(e===void 0)throw new TypeError("publishableKey is the project publishable key (pb_<ref>_c\u2026)");return`pb-${e}-session`}var y=t=>{let e=new TextEncoder().encode(JSON.stringify(t)),o="";for(let s of e)o+=String.fromCharCode(s);return btoa(o).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")},b=t=>{try{let e=atob(t.replace(/-/g,"+").replace(/_/g,"/")),o=JSON.parse(new TextDecoder().decode(Uint8Array.from(e,s=>s.charCodeAt(0))));return typeof o.accessToken!="string"||typeof o.refreshToken!="string"||typeof o.expiresAt!="number"||typeof o.userId!="string"?null:o}catch{return null}};function m(t,e,o={},s=!1){let c={...x,...o},g=async()=>new Map((await e.getAll()).map(n=>[n.name,n.value])),S=n=>n===t||n.startsWith(`${t}.`)&&/^\d+$/.test(n.slice(t.length+1)),h=async n=>{if(!e.setAll)return;let i=n===null?[]:n.length<=u?[[t,n]]:Array.from({length:Math.ceil(n.length/u)},(r,l)=>[`${t}.${l}`,n.slice(l*u,(l+1)*u)]),p=new Set(i.map(([r])=>r)),a=i.map(([r,l])=>({name:r,value:l,options:c}));for(let r of(await g()).keys())S(r)&&!p.has(r)&&a.push({name:r,value:"",options:{...c,maxAge:0}});a.length>0&&await e.setAll(a,{...C})};return{async load(){let n=await g(),i=n.get(t);if(i===void 0){let p="";for(let a=0;n.has(`${t}.${a}`);a++)p+=n.get(`${t}.${a}`);i=p}return i?b(i):null},save:n=>h(y(n)),clear:()=>h(null),shared:s}}function A(t){let{cookies:e,cookieOptions:o,...s}=t,c=t.refresh??(e.setAll?"before":"never");return f({...s,refresh:c,storage:m(d(t.publishableKey),e,o)})}function O(){let t=()=>{let e=globalThis.document;if(!e)throw new Error("documentCookies: there is no document here \u2014 a server gives its request's cookies to createServerClient");return e};return{getAll:()=>t().cookie.split(";").map(e=>e.trim()).filter(e=>e.includes("=")).map(e=>{let o=e.indexOf("=");return{name:e.slice(0,o),value:e.slice(o+1)}}),setAll(e){for(let o of e){let s=o.options,c=[`Path=${s.path??"/"}`,s.domain?`Domain=${s.domain}`:"",s.maxAge!==void 0?`Max-Age=${s.maxAge}`:"",s.expires?`Expires=${s.expires.toUTCString()}`:"",s.sameSite?`SameSite=${s.sameSite.charAt(0).toUpperCase()}${s.sameSite.slice(1)}`:"",s.secure?"Secure":""].filter(Boolean);t().cookie=[`${o.name}=${o.value}`,...c].join("; ")}}}}function $(t){let{cookieOptions:e,...o}=t,s=globalThis.location?.protocol==="https:";return f({...o,storage:m(d(t.publishableKey),O(),{secure:s,...e},!0)})}async function v(t){let e=await t.auth.currentSession();if(!e||(e.expiresAt-Date.now()<=k&&await t.auth.refreshSession().catch(()=>{}),!await t.auth.currentSession()))return null;try{return(await t.auth.api.verifyTokenUser()).data}catch(o){if(o.status===401)return null;throw o}}export{C as NO_STORE_HEADERS,x as SESSION_COOKIE_OPTIONS,m as cookieSessionStore,$ as createBrowserClient,A as createServerClient,O as documentCookies,v as keepSession,d as sessionCookieName};
|
package/dist/web/vite.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
/*! palbase 0.
|
|
2
|
-
import"../chunks/
|
|
1
|
+
/*! palbase 0.8.0 — Palbase SDK License (see LICENSE) */
|
|
2
|
+
import"../chunks/JSJVV43D.js";import{execFile as $}from"node:child_process";import{existsSync as y,mkdtempSync as k,readFileSync as S,rmSync as x,writeFileSync as P}from"node:fs";import{createRequire as O}from"node:module";import{tmpdir as W}from"node:os";import{dirname as g,join as o,relative as u,resolve as v,sep as d}from"node:path";var E=/\.(?:ts|js|mts|mjs)$/;function F(n){if(!/^[a-z][a-z0-9-]*$/.test(n.app))throw new TypeError(`palbase({ app }): ${JSON.stringify(n.app)} is an app's slug (palbase apps:list)`);let c=process.cwd(),p="",i="",f=()=>v(c,n.dir??"palbase"),m=()=>{let e=n.environments[p];if(!e)throw new Error(`palbase: the mode "${p}" is not built against any environment \u2014 say which in vite.config: palbase({ environments: { ${JSON.stringify(p)}: '<environment slug>' } })`);return e};return{name:"palbase",enforce:"pre",config(e,s){p=s.mode,i=s.command??"";let r=e.build?.rollupOptions?.onwarn;return{build:{rollupOptions:{onwarn(t,a){let l=String(t.exporter??t.id??"");if(t.code==="MISSING_EXPORT"&&l.includes(`${d}environments${d}`))throw new Error(`palbase: ${t.message} \u2014 ${m()}'s backend has no such route (palbase apps:sync brings what it has)`);r?r(t,a):a(t)}}}}},configResolved(e){c=e.root,p=e.mode,i=e.command??i},async buildStart(){i!=="build"||n.typecheck===!1||await j(c,m(),n.tsconfig)},resolveId(e,s){if(!s)return null;let r=f();if(e==="palbase"||e.startsWith("palbase/")){let w=u(r,s);return w.startsWith("..")||w===""?null:this.resolve(e,o(c,"index.html"),{skipSelf:!0})}if(!(e.startsWith(".")||e.startsWith("/")))return null;let t=v(g(s),e);if(E.test(t)||(t+=".ts"),g(t)!==r&&g(t)!==o(r,"palbe"))return null;let a=u(r,t),l=`${n.app}.ts`;if(a!==l&&!a.startsWith(`palbe${d}`))return null;let h=m(),b=o(r,"environments",h,a===l?l:o("palbe",a.slice(`palbe${d}`.length)));if(!y(b))throw new Error(`palbase: ${u(c,b)} is not there \u2014 palbase apps:sync writes it (is ${n.app} set in ${h}, and has ${h} that machine?)`);return b}}}async function j(n,c,p){let i=p?v(n,p):["tsconfig.app.json","tsconfig.json"].map(e=>o(n,e)).find(y);if(!i)return;if(!y(i))throw new Error(`palbase({ tsconfig }): ${u(n,i)} is not there`);let f;try{let e=O(o(n,"package.json")).resolve("typescript/package.json"),s=JSON.parse(S(e,"utf8")).bin?.tsc;if(!s)throw new Error("no tsc");f=o(g(e),s)}catch{throw new Error("palbase: the build type-checks the app against its environment with the app's TypeScript, and the app has none (npm i -D typescript) \u2014 or say palbase({ typecheck: false })")}let m=k(o(W(),"palbase-typecheck-"));try{let e=o(m,"tsconfig.json");P(e,JSON.stringify({extends:i,compilerOptions:{noEmit:!0,composite:!1,incremental:!1,moduleSuffixes:[`.${c}`,""]}}));let s=await new Promise(r=>$(process.execPath,[f,"-p",e,"--pretty","false"],{cwd:n,maxBuffer:16<<20},(t,a,l)=>r({code:t?typeof t.code=="number"?t.code:1:0,text:`${a}${l}`.trim()})));if(s.code!==0)throw new Error(`palbase: the app does not type-check against ${c}, the environment this build is made for \u2014 a route its backend does not have, or a call that does not fit it:
|
|
3
3
|
${s.text}`)}finally{x(m,{recursive:!0,force:!0})}}export{F as palbase};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "palbase",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Palbase for JavaScript: the web client (palbase/web), the server SDK (palbase/server), the backend framework (palbase/backend), AI (palbase/ai) and the CLI (npx palbase).",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"homepage": "https://palbase.studio",
|
|
@@ -109,7 +109,7 @@
|
|
|
109
109
|
"README.md"
|
|
110
110
|
],
|
|
111
111
|
"dependencies": {
|
|
112
|
-
"palgres": "0.
|
|
112
|
+
"palgres": "0.8.0",
|
|
113
113
|
"reflect-metadata": "^0.2.2",
|
|
114
114
|
"typescript": "~6.0.3",
|
|
115
115
|
"zod": "^4.6.5"
|
package/types/ai/src/ai.d.ts
CHANGED
|
@@ -3,10 +3,13 @@ import { type RetryPolicy } from '../../internal/src/retry.js';
|
|
|
3
3
|
import * as modules from '../../internal/src/modules/index.js';
|
|
4
4
|
import { type Infer, type PreparedSchema, type StandardSchema } from './schema.js';
|
|
5
5
|
import { type Agents, type Chats, type Endpoints, type Repos, type Settings } from './chats.js';
|
|
6
|
-
import { type AgentContext, type BackendAgent, type BackendRepo, type BackendTool, type BackendToolOptions, type ClientTool, type ClientToolOptions, type HttpsToolRef, type McpToolRef, type TurnDefinition } from './tools.js';
|
|
6
|
+
import { type AgentContext, type BackendAgent, type BackendRepo, type BackendTool, type BackendToolOptions, type DeferredAnswer, type RepoTokenContext, type RepoTokens, type ClientTool, type ClientToolOptions, type HttpsToolRef, type McpToolRef, type TurnDefinition } from './tools.js';
|
|
7
7
|
type Module = ReturnType<typeof modules.ai.client>;
|
|
8
8
|
export type Response = Awaited<ReturnType<Module['getResponse']>>['data'];
|
|
9
9
|
export type Usage = Awaited<ReturnType<Module['listUsage']>>['data']['usage'][number];
|
|
10
|
+
export type Models = modules.ai.Models;
|
|
11
|
+
/** A text model a turn may name, as the engine's catalogue says it (ai.models().chat). */
|
|
12
|
+
export type ChatModel = modules.ai.ChatModel;
|
|
10
13
|
export interface AIOptions {
|
|
11
14
|
/** The project's address (https://<ref>.<domain>); default PALBASE_URL. */
|
|
12
15
|
url?: string;
|
|
@@ -38,11 +41,13 @@ export interface Message {
|
|
|
38
41
|
content: string;
|
|
39
42
|
}
|
|
40
43
|
/**
|
|
41
|
-
* A picture a question is about: a file of the project's own storage,
|
|
42
|
-
* https address.
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* the
|
|
44
|
+
* A picture a question is about: a file of the project's own storage, an
|
|
45
|
+
* https address, or its bytes. A file of the storage ({ bucket, path }) is
|
|
46
|
+
* read by the model through a link signed for the while it answers, and the
|
|
47
|
+
* platform keeps no copy of it. Its bytes ({ mediaType, data }: png, jpeg,
|
|
48
|
+
* webp or gif — a screenshot the server holds — base64 or a Uint8Array, 5 MiB
|
|
49
|
+
* each and 6 MiB together) are kept in the project's storage while the
|
|
50
|
+
* question is answered, then deleted.
|
|
46
51
|
*
|
|
47
52
|
* Do not take bucket and path from the end user as they send them: the
|
|
48
53
|
* question is asked with the project's secret key, and the model can be
|
|
@@ -54,6 +59,9 @@ export type AskImage = {
|
|
|
54
59
|
path: string;
|
|
55
60
|
} | {
|
|
56
61
|
url: string;
|
|
62
|
+
} | {
|
|
63
|
+
mediaType: 'image/png' | 'image/jpeg' | 'image/webp' | 'image/gif' | (string & {});
|
|
64
|
+
data: string | Uint8Array;
|
|
57
65
|
};
|
|
58
66
|
/** What a one-shot answer may call: the backend's ai.tool, the project's HTTPS tools and MCP servers — never an app's client tool. */
|
|
59
67
|
export type AskTool = BackendTool<StandardSchema> | HttpsToolRef | McpToolRef;
|
|
@@ -63,11 +71,11 @@ export interface Ask {
|
|
|
63
71
|
messages?: Message[];
|
|
64
72
|
instructions?: string;
|
|
65
73
|
model?: Model;
|
|
66
|
-
/** Pictures the question is about (4 at most)
|
|
74
|
+
/** Pictures the question is about (4 at most): in the project's storage ({ bucket, path }), at an https address ({ url }), or their bytes ({ mediaType, data }) — a user's own file, checked by you (AskImage). */
|
|
67
75
|
images?: AskImage[];
|
|
68
76
|
/** What the model may call to answer: an ai.tool runs on the backend's machine; an app's client tool is a chat's alone. */
|
|
69
77
|
tools?: AskTool[];
|
|
70
|
-
/** How many tool calls the answer makes at most (1–
|
|
78
|
+
/** How many tool calls the answer makes at most (1–10 000, the engine's own bound): past it the model is told it has no tools left, and answers. */
|
|
71
79
|
maxToolCalls?: number;
|
|
72
80
|
/** The caller's own labels: returned with the response and its event. */
|
|
73
81
|
metadata?: Record<string, string>;
|
|
@@ -183,10 +191,20 @@ export interface AI {
|
|
|
183
191
|
embed(text: string, options?: Embed): Promise<number[]>;
|
|
184
192
|
/** Pictures for a prompt: waits for the job (it takes the provider up to minutes). */
|
|
185
193
|
image(request: ImageRequest): Promise<Images>;
|
|
186
|
-
|
|
187
|
-
|
|
194
|
+
/**
|
|
195
|
+
* What the project may name: the roles, the embedding and picture models — and chat, every text model a turn may
|
|
196
|
+
* name (an agent's, a response's) with the efforts it takes, its window, its token limits and its price: what a
|
|
197
|
+
* model picker offers a person. unavailable: the providers whose models could not be listed just now.
|
|
198
|
+
*/
|
|
199
|
+
models(): Promise<Models>;
|
|
200
|
+
/**
|
|
201
|
+
* Uses of models and their cost, newest first. Each carries its labels (metadata): its caller's — and a chat's turn
|
|
202
|
+
* the chat's labels and the chat (chat). With metadata, only the uses that carry every one of those labels: a
|
|
203
|
+
* product's spend, a task's — a deleted chat's too.
|
|
204
|
+
*/
|
|
188
205
|
usage(options?: {
|
|
189
206
|
kind?: 'text' | 'embedding' | 'image';
|
|
207
|
+
metadata?: Record<string, string>;
|
|
190
208
|
limit?: number;
|
|
191
209
|
cursor?: string;
|
|
192
210
|
}): Promise<{
|
|
@@ -215,6 +233,14 @@ export interface AI {
|
|
|
215
233
|
tool<S extends StandardSchema>(tool: BackendToolOptions<S>): BackendTool<S>;
|
|
216
234
|
/** A tool the app answers — through its gateway, whose backend gives the answer (chats.answer): the turn waits for it. */
|
|
217
235
|
clientTool<S extends StandardSchema>(tool: ClientToolOptions<S>): ClientTool;
|
|
236
|
+
/**
|
|
237
|
+
* What a backend tool's run returns when its work outlasts a call (110 seconds): a chat's call waits, and the
|
|
238
|
+
* project's server answers it later with chats.answer(ctx.chatId, ctx.callId, output), within expiresInSeconds
|
|
239
|
+
* (a minute to a day; an hour).
|
|
240
|
+
*/
|
|
241
|
+
deferred(options?: {
|
|
242
|
+
expiresInSeconds?: number;
|
|
243
|
+
}): DeferredAnswer;
|
|
218
244
|
/**
|
|
219
245
|
* An agent the backend defines at each turn's start, from the turn's
|
|
220
246
|
* context: put it with ai.agents.put(agent), and its chats' turns ask the
|
|
@@ -233,12 +259,15 @@ export interface AI {
|
|
|
233
259
|
repository: string;
|
|
234
260
|
defaultBranch?: string;
|
|
235
261
|
machine?: string;
|
|
236
|
-
token: (ctx:
|
|
237
|
-
repo: string;
|
|
238
|
-
repository: string;
|
|
239
|
-
signal: AbortSignal;
|
|
240
|
-
}) => string | Promise<string>;
|
|
262
|
+
token: (ctx: RepoTokenContext) => string | Promise<string>;
|
|
241
263
|
}): BackendRepo;
|
|
264
|
+
/**
|
|
265
|
+
* The tokens of the repositories put by name at run time (ai.repos.put(name, { repository, backend })) — one a
|
|
266
|
+
* product makes for itself — that no ai.repo of this backend names: each clone and push of a chat's workspace asks
|
|
267
|
+
* this machine, and give answers with a token for that one operation, or null for one it gives none for. Given
|
|
268
|
+
* once, at a module's top level; an ai.repo answers for its own repository first.
|
|
269
|
+
*/
|
|
270
|
+
repoTokens(give: RepoTokens): void;
|
|
242
271
|
/** The project's repositories a chat's workspace works in (chats.create({ workspace })). */
|
|
243
272
|
readonly repos: Repos;
|
|
244
273
|
/** The generated client of the ai module, for what the methods above do not say. */
|