palbase 0.6.2 → 0.7.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 -14
- package/dist/backend/engine.js +2 -2
- package/dist/backend/env.js +1 -1
- package/dist/backend/index.js +8 -8
- package/dist/backend/stack.js +1 -1
- package/dist/backend/test.js +2 -2
- package/dist/chunks/3ALGILOX.js +2 -0
- package/dist/chunks/{GVFZM4BI.js → 5ZJCEQV5.js} +3 -3
- package/dist/chunks/AIIKXCWN.js +2 -0
- package/dist/chunks/{53FS342F.js → BKVU4I5R.js} +2 -2
- package/dist/chunks/ELEE7XO2.js +18 -0
- package/dist/chunks/{DRTZ33XF.js → G3BK7L3J.js} +2 -2
- package/dist/chunks/G7E26S3Y.js +13 -0
- package/dist/chunks/H2EPK74V.js +20 -0
- package/dist/chunks/{VP7V7YRH.js → HEXIIGWS.js} +2 -2
- package/dist/chunks/{IYCW6PWG.js → JS3TTUHS.js} +2 -2
- package/dist/chunks/{SUX2BJG4.js → KDSWK3XW.js} +1 -1
- package/dist/chunks/{U4OZ4HOF.js → L3NTI4AZ.js} +2 -2
- package/dist/chunks/LEBVOSG6.js +4 -0
- package/dist/chunks/OIA7KLRW.js +2 -0
- package/dist/chunks/{AYY4J3B2.js → PJVWGUIT.js} +1 -1
- package/dist/chunks/{A3CDCPXX.js → SU7BP6VF.js} +1 -1
- package/dist/chunks/{KLANM6M6.js → X3MTLJRV.js} +1 -1
- package/dist/chunks/{SXH5AIQX.js → ZBOJEH7K.js} +2 -2
- package/dist/cli.js +133 -133
- 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 +2 -4
- package/types/ai/src/chats.d.ts +40 -10
- package/types/ai/src/index.d.ts +2 -2
- package/types/ai/src/tools.d.ts +3 -8
- package/types/backend/src/container.d.ts +2 -2
- package/types/backend/src/engine.d.ts +1 -4
- package/types/backend/src/gateways.d.ts +250 -0
- package/types/backend/src/index.d.ts +2 -2
- package/types/backend/src/openapi.d.ts +3 -6
- package/types/backend/src/runtime.d.ts +39 -2
- package/types/internal/src/chat.d.ts +7 -39
- package/types/internal/src/modules/ai.d.ts +68 -35
- package/types/internal/src/modules/realtime.d.ts +9 -1
- package/types/web/src/backends.d.ts +19 -12
- package/types/web/src/chat.d.ts +118 -0
- package/types/web/src/client.d.ts +0 -3
- package/types/web/src/gateways.d.ts +89 -0
- package/types/web/src/index.d.ts +3 -3
- package/types/web/src/socket.d.ts +18 -2
- package/dist/chunks/2RG3I7LX.js +0 -6
- package/dist/chunks/A76UZBAF.js +0 -2
- package/dist/chunks/AD5LBZAB.js +0 -4
- package/dist/chunks/DRGYTL6T.js +0 -20
- package/dist/chunks/IVEAUFGE.js +0 -13
- package/dist/chunks/KL7FIRII.js +0 -2
- package/types/backend/src/channels.d.ts +0 -81
- package/types/backend/src/rooms.d.ts +0 -178
- package/types/web/src/ai.d.ts +0 -224
- package/types/web/src/rooms.d.ts +0 -61
package/dist/refuse/ai.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! palbase 0.
|
|
1
|
+
/*! palbase 0.7.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.7.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.7.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.7.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/L3NTI4AZ.js";import"../chunks/KDSWK3XW.js";import{m as b}from"../chunks/AIIKXCWN.js";import"../chunks/ZBOJEH7K.js";import{b as a}from"../chunks/JS3TTUHS.js";import"../chunks/X3MTLJRV.js";import"../chunks/SU7BP6VF.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.7.0 — Palbase SDK License (see LICENSE) */
|
|
2
|
+
import{a,b,c,d}from"../chunks/G3BK7L3J.js";import"../chunks/X3MTLJRV.js";import"../chunks/SU7BP6VF.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 t,b as
|
|
1
|
+
/*! palbase 0.7.0 — Palbase SDK License (see LICENSE) */
|
|
2
|
+
import{a as t,b as r,c as a,d as o,e as p,f as n,g as i,h as m}from"../chunks/3ALGILOX.js";import{a as y,b as s,e as l}from"../chunks/G7E26S3Y.js";import"../chunks/5ZJCEQV5.js";import"../chunks/OIA7KLRW.js";import"../chunks/AIIKXCWN.js";import"../chunks/ZBOJEH7K.js";import{b as e}from"../chunks/JS3TTUHS.js";import"../chunks/X3MTLJRV.js";import"../chunks/SU7BP6VF.js";export{n as Analytics,y as BackendError,o as Channel,l as GatewayError,e as PalbaseError,i as Purchases,p as RealtimeSocket,t as SessionChangedError,m as createClient,s as isBackendError,a as localStore,r as memoryStore};
|
package/dist/web/palbe.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! palbase 0.
|
|
2
|
-
import{c as e,d as r,h as t}from"../chunks/
|
|
1
|
+
/*! palbase 0.7.0 — Palbase SDK License (see LICENSE) */
|
|
2
|
+
import{c as e,d as r,h as t}from"../chunks/G7E26S3Y.js";import"../chunks/OIA7KLRW.js";import"../chunks/ZBOJEH7K.js";import"../chunks/JS3TTUHS.js";import"../chunks/X3MTLJRV.js";import"../chunks/SU7BP6VF.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.7.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/5ZJCEQV5.js";import"../chunks/JS3TTUHS.js";import"../chunks/X3MTLJRV.js";import"../chunks/SU7BP6VF.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{
|
|
1
|
+
/*! palbase 0.7.0 — Palbase SDK License (see LICENSE) */
|
|
2
|
+
import{h as f}from"../chunks/3ALGILOX.js";import"../chunks/G7E26S3Y.js";import"../chunks/5ZJCEQV5.js";import"../chunks/OIA7KLRW.js";import"../chunks/AIIKXCWN.js";import"../chunks/ZBOJEH7K.js";import"../chunks/JS3TTUHS.js";import"../chunks/X3MTLJRV.js";import"../chunks/SU7BP6VF.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.7.0 — Palbase SDK License (see LICENSE) */
|
|
2
|
+
import"../chunks/SU7BP6VF.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.7.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.7.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
|
@@ -213,17 +213,15 @@ export interface AI {
|
|
|
213
213
|
* Made once, at a module's top level.
|
|
214
214
|
*/
|
|
215
215
|
tool<S extends StandardSchema>(tool: BackendToolOptions<S>): BackendTool<S>;
|
|
216
|
-
/** A tool the app
|
|
216
|
+
/** A tool the app answers — through its gateway, whose backend gives the answer (chats.answer): the turn waits for it. */
|
|
217
217
|
clientTool<S extends StandardSchema>(tool: ClientToolOptions<S>): ClientTool;
|
|
218
218
|
/**
|
|
219
219
|
* An agent the backend defines at each turn's start, from the turn's
|
|
220
220
|
* context: put it with ai.agents.put(agent), and its chats' turns ask the
|
|
221
|
-
* machine for it
|
|
222
|
-
* themselves. Made once, at a module's top level.
|
|
221
|
+
* machine for it. Made once, at a module's top level.
|
|
223
222
|
*/
|
|
224
223
|
agent(name: string, define: (ctx: AgentContext) => TurnDefinition | Promise<TurnDefinition>, options?: {
|
|
225
224
|
machine?: string;
|
|
226
|
-
clients?: boolean;
|
|
227
225
|
}): BackendAgent;
|
|
228
226
|
/**
|
|
229
227
|
* A GitHub repository a chat's workspace works in, whose tokens this
|
package/types/ai/src/chats.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type ChatStream, type FollowChatOptions } from '../../internal/src/chat.js';
|
|
2
1
|
import type * as modules from '../../internal/src/modules/index.js';
|
|
3
2
|
import { type ToolResult } from '../../internal/src/tool-output.js';
|
|
4
3
|
import { type AgentDefinitionInput, type BackendAgent, type BackendRepo } from './tools.js';
|
|
@@ -10,7 +9,7 @@ export type Endpoint = modules.ai.Endpoint;
|
|
|
10
9
|
export type Decision = modules.ai.Decision;
|
|
11
10
|
/** What the project allows its chats. */
|
|
12
11
|
export interface AISettings {
|
|
13
|
-
/** The app's users
|
|
12
|
+
/** The app's users reach the chats they are members of with their own session (the server starts every chat). */
|
|
14
13
|
clients: boolean;
|
|
15
14
|
/** How many messages one user sends a minute. */
|
|
16
15
|
userMessagesPerMinute: number;
|
|
@@ -163,28 +162,59 @@ export interface Chats {
|
|
|
163
162
|
messages: ChatMessage[];
|
|
164
163
|
nextCursor?: string;
|
|
165
164
|
}>;
|
|
166
|
-
/**
|
|
167
|
-
|
|
165
|
+
/**
|
|
166
|
+
* What happens in the chat — its messages, its turns, the answer as it is written, the tools and subagents — as a
|
|
167
|
+
* source a gateway pipes into its channel: `ctx.pipe(Palbase.ai.chats.events(id))`. The platform writes the chat
|
|
168
|
+
* into the channel itself from then on; the backend is not in the stream, and the gateway's members hear it.
|
|
169
|
+
*/
|
|
170
|
+
events(id: string): ChatEvents;
|
|
168
171
|
/** Stops the turn it is working on: what it wrote stays. Its response's id, or null when none ran. */
|
|
169
172
|
stop(id: string): Promise<string | null>;
|
|
170
|
-
/**
|
|
171
|
-
|
|
173
|
+
/**
|
|
174
|
+
* A tool call that waits for a person's yes (a tool event's approval_id): made. As a member (as), the server is held to
|
|
175
|
+
* their rules — a turn another member began is not theirs to decide (403 not_your_turn); without it, the server decides any.
|
|
176
|
+
*/
|
|
177
|
+
approve(id: string, approvalId: string, options?: {
|
|
178
|
+
reason?: string;
|
|
179
|
+
as?: string;
|
|
180
|
+
}): Promise<Decision>;
|
|
172
181
|
/** Not made: the agent is told, with the reason, and goes on. */
|
|
173
|
-
deny(id: string, approvalId: string,
|
|
174
|
-
|
|
182
|
+
deny(id: string, approvalId: string, options?: {
|
|
183
|
+
reason?: string;
|
|
184
|
+
as?: string;
|
|
185
|
+
}): Promise<Decision>;
|
|
186
|
+
/**
|
|
187
|
+
* The answer of a client tool's call (a tool event's call_id): true when it is the one taken, false when another came
|
|
188
|
+
* first. As a member (as): the app of the member whose turn it is answers it (403 not_your_turn otherwise).
|
|
189
|
+
*/
|
|
175
190
|
answer(id: string, callId: string, output: ToolResult, options?: {
|
|
176
191
|
isError?: boolean;
|
|
192
|
+
as?: string;
|
|
177
193
|
}): Promise<boolean>;
|
|
178
|
-
/** A message for one of the agent's subagents at work (an agent event's run_id), at its next step. */
|
|
194
|
+
/** A message for one of the agent's subagents at work (an agent event's run_id), at its next step — as a member, held to their rules. */
|
|
179
195
|
sendToSubagent(id: string, runId: string, text: string, options?: {
|
|
180
196
|
clientId?: string;
|
|
197
|
+
as?: string;
|
|
181
198
|
}): Promise<{
|
|
182
199
|
runId: string;
|
|
183
200
|
clientId: string;
|
|
184
201
|
}>;
|
|
185
202
|
}
|
|
203
|
+
/** A chat's stream as a gateway pipes it into its channel (gateways' PipeSource). */
|
|
204
|
+
export interface ChatEvents {
|
|
205
|
+
readonly kind: 'ai.chat';
|
|
206
|
+
readonly chatId: string;
|
|
207
|
+
/** Writes the chat into the channel from now on — from its start, for a channel that had not been its own. */
|
|
208
|
+
pipe(topic: string, options?: {
|
|
209
|
+
signal?: AbortSignal;
|
|
210
|
+
}): Promise<void>;
|
|
211
|
+
/** Writes it nowhere from now on. */
|
|
212
|
+
unpipe(options?: {
|
|
213
|
+
signal?: AbortSignal;
|
|
214
|
+
}): Promise<void>;
|
|
215
|
+
}
|
|
186
216
|
export interface Agents {
|
|
187
|
-
/** Names an agent: its definition, or a backend's ai.agent (its chats' turns ask the backend's machine)
|
|
217
|
+
/** Names an agent: its definition, or a backend's ai.agent (its chats' turns ask the backend's machine). */
|
|
188
218
|
put(name: string, definition: AgentDefinitionInput | BackendAgent): Promise<Agent>;
|
|
189
219
|
put(agent: BackendAgent): Promise<Agent>;
|
|
190
220
|
list(): Promise<Agent[]>;
|
package/types/ai/src/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { AISchemaError, prepare } from './schema.js';
|
|
|
4
4
|
export { ToolError } from './tools.js';
|
|
5
5
|
export type { Infer, StandardSchema } from './schema.js';
|
|
6
6
|
export { partial } from './partial.js';
|
|
7
|
-
export type { AISettings, Agent, Agents, Chat, ChatMessage, Chats, CreateChat, Decision, Endpoint, EndpointInput, Endpoints, MemberInput, Repo, Repos, SendMessage, Settings, TurnArtifact, TurnCost } from './chats.js';
|
|
7
|
+
export type { AISettings, Agent, Agents, Chat, ChatEvents, ChatMessage, Chats, CreateChat, Decision, Endpoint, EndpointInput, Endpoints, MemberInput, Repo, Repos, SendMessage, Settings, TurnArtifact, TurnCost } from './chats.js';
|
|
8
8
|
export type { AgentContext, AgentDefinitionInput, BackendAgent, BackendRepo, BackendTool, BackendToolOptions, ChatContext, ClientTool, ClientToolOptions, HttpsToolRef, McpToolRef, SubagentDefinition, Tool, ToolContext, TurnDefinition, } from './tools.js';
|
|
9
|
-
export type { AgentEvent, ChatEvent,
|
|
9
|
+
export type { AgentEvent, ChatEvent, MessageEvent, ResetEvent, TextEvent, ToolEvent, ToolStatus, TurnEvent, TurnStatus, WaitingReason } from '../../internal/src/chat.js';
|
|
10
10
|
export type { ToolPart, ToolResult } from '../../internal/src/tool-output.js';
|
package/types/ai/src/tools.d.ts
CHANGED
|
@@ -73,7 +73,7 @@ export interface ClientToolOptions<S extends StandardSchema> {
|
|
|
73
73
|
input?: S;
|
|
74
74
|
approval?: boolean;
|
|
75
75
|
}
|
|
76
|
-
/** A tool the app
|
|
76
|
+
/** A tool the app answers — through its gateway, whose backend gives the answer (chats.answer): the turn waits for it. */
|
|
77
77
|
export interface ClientTool {
|
|
78
78
|
readonly source: 'client';
|
|
79
79
|
readonly name: string;
|
|
@@ -116,19 +116,15 @@ export interface AgentDefinitionInput {
|
|
|
116
116
|
subagents?: SubagentDefinition[];
|
|
117
117
|
/** How many tool calls a turn makes at most (1–200): past it the agent is told it has no tools left and answers. */
|
|
118
118
|
maxToolCalls?: number;
|
|
119
|
-
/** A named agent's: the app's users start chats with it themselves (when the project lets them). Left out, the server's alone. */
|
|
120
|
-
clients?: boolean;
|
|
121
119
|
}
|
|
122
|
-
/** What a backend's agent is for one turn
|
|
123
|
-
export type TurnDefinition =
|
|
120
|
+
/** What a backend's agent is for one turn. */
|
|
121
|
+
export type TurnDefinition = AgentDefinitionInput;
|
|
124
122
|
/** An agent the backend defines at each turn's start: put with ai.agents.put(agent), its chats' turns ask its machine. */
|
|
125
123
|
export interface BackendAgent {
|
|
126
124
|
readonly kind: 'agent';
|
|
127
125
|
readonly name: string;
|
|
128
126
|
/** The project's machine that defines it (default backend). */
|
|
129
127
|
readonly machine?: string;
|
|
130
|
-
/** The app's users start chats with it themselves (put with it). */
|
|
131
|
-
readonly clients: boolean;
|
|
132
128
|
/** The definition for a turn, said as the platform takes it, with the backend tools it hands out. */
|
|
133
129
|
resolve(ctx: AgentContext): Promise<{
|
|
134
130
|
definition: AgentDefinition;
|
|
@@ -193,7 +189,6 @@ export declare function backendRepo(options: {
|
|
|
193
189
|
}): BackendRepo;
|
|
194
190
|
export declare function backendAgent(name: string, define: (ctx: AgentContext) => TurnDefinition | Promise<TurnDefinition>, options?: {
|
|
195
191
|
machine?: string;
|
|
196
|
-
clients?: boolean;
|
|
197
192
|
}): BackendAgent;
|
|
198
193
|
/** A tool as the platform takes it (ToolRef). */
|
|
199
194
|
export declare function toolRef(t: Tool, what: string): ToolRef;
|
|
@@ -28,8 +28,8 @@ export declare class Container {
|
|
|
28
28
|
readonly cronProviders: Ctor[];
|
|
29
29
|
/** The providers that are @Task classes: the platform runs them as their tasks come due. */
|
|
30
30
|
readonly taskProviders: Ctor[];
|
|
31
|
-
/** The providers that are @
|
|
32
|
-
readonly
|
|
31
|
+
/** The providers that are @Gateway classes. */
|
|
32
|
+
readonly gateways: Ctor[];
|
|
33
33
|
constructor(modules: Function[]);
|
|
34
34
|
private collect;
|
|
35
35
|
private validate;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { type PalbaseServer, type TokenUser, type TokenVerifier, type WebhookEvent } from '../../server/src/index.js';
|
|
2
2
|
import { type AuthSpec, type RateLimitConfig } from './decorators.js';
|
|
3
3
|
import { type ContractOptions } from './openapi.js';
|
|
4
|
-
import { type ChannelsDef } from './channels.js';
|
|
5
4
|
import { type StringsTable } from './i18n.js';
|
|
6
5
|
import type { RequestTelemetry } from './requests.js';
|
|
7
6
|
/** The signed-in user, as @User() gives it. */
|
|
@@ -63,8 +62,6 @@ export interface AppOptions {
|
|
|
63
62
|
cors?: CorsOptions;
|
|
64
63
|
/** The framework's own handlers of the platform's events (user.deleted → forget), run before the app's @On. */
|
|
65
64
|
events?: Record<string, ((event: WebhookEvent) => Promise<unknown>)[]>;
|
|
66
|
-
/** The app's channels; the ones defineChannels declared in this process unless given (a test's own). */
|
|
67
|
-
channels?: ChannelsDef;
|
|
68
65
|
/** The app's database: each request (and each delivery) one transaction, as its caller or as the service role. */
|
|
69
66
|
database?: {
|
|
70
67
|
app: RequestDatabases;
|
|
@@ -104,7 +101,7 @@ export interface AppOptions {
|
|
|
104
101
|
* never to be done (TaskFailure, or a payload its schema refuses), or the
|
|
105
102
|
* failure the platform tries again;
|
|
106
103
|
* - its @Upload routes' two steps, from storage (upload.ts), and its
|
|
107
|
-
* @
|
|
104
|
+
* @Gateway classes' joins, messages and moments, from realtime (gateways.ts):
|
|
108
105
|
* platform-calls.ts;
|
|
109
106
|
* - its ai tools and agents (@palbase/ai's ai.tool and ai.agent), from the
|
|
110
107
|
* ai module: POST /_palbase/ai/tools runs the tool an agent called (its
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import type { realtime } from '../../internal/src/modules/index.js';
|
|
2
|
+
import { type StandardSchemaV1 } from './decorators.js';
|
|
3
|
+
import { type SignedUser } from './platform-calls.js';
|
|
4
|
+
export declare const GATEWAY: unique symbol;
|
|
5
|
+
export declare const GATEWAY_HOOKS: unique symbol;
|
|
6
|
+
/** The moments a gateway's methods are told of. */
|
|
7
|
+
export type GatewayHook = 'authorize' | 'first' | 'connect' | 'disconnect' | 'empty';
|
|
8
|
+
export interface GatewayOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Who may join, decided by realtime: 'owner' — the pattern's one {param}
|
|
11
|
+
* is the joining user's id; 'public' — any signed-in user. Left out, an
|
|
12
|
+
* @Authorize method decides.
|
|
13
|
+
*/
|
|
14
|
+
access?: 'owner' | 'public';
|
|
15
|
+
/**
|
|
16
|
+
* Members broadcast to each other, as realtime carries it — a gateway of
|
|
17
|
+
* no method only: one with methods takes its members' messages itself
|
|
18
|
+
* (@Subscribe).
|
|
19
|
+
*/
|
|
20
|
+
publish?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Keeps what it sends: true a day, or { keepSeconds } (1 to 604800). A
|
|
23
|
+
* member that was away is sent what it missed, in order, once — a chat's
|
|
24
|
+
* stream that a phone walking out of range does not lose.
|
|
25
|
+
*/
|
|
26
|
+
durable?: boolean | {
|
|
27
|
+
keepSeconds: number;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* How long it is held after its last member left before it is empty
|
|
31
|
+
* (@OnEmpty), in milliseconds: 60000 unless said.
|
|
32
|
+
*/
|
|
33
|
+
graceMs?: number;
|
|
34
|
+
/**
|
|
35
|
+
* It carries a chat of the project's agents (ctx.pipe(Palbase.ai.chats.events(id))):
|
|
36
|
+
* its event `chat` is the platform's — the chat's parts — and every
|
|
37
|
+
* generated client holds the chat's state for its view (messages, the
|
|
38
|
+
* answer as it is written, tools, approvals). Kept a day unless durable
|
|
39
|
+
* says how long: a member that comes later, or was away, has the chat.
|
|
40
|
+
*/
|
|
41
|
+
chat?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Something the platform writes into a gateway's channel itself, the backend
|
|
45
|
+
* not in it: a chat's stream (Palbase.ai.chats.events(id)).
|
|
46
|
+
*/
|
|
47
|
+
export interface PipeSource {
|
|
48
|
+
pipe(topic: string, options?: {
|
|
49
|
+
signal?: AbortSignal;
|
|
50
|
+
}): Promise<void>;
|
|
51
|
+
}
|
|
52
|
+
/** The platform's event of a chat-carrying gateway: one part of the chat (its type, the journal's number, its data). */
|
|
53
|
+
export declare const ChatPart: StandardSchemaV1<{
|
|
54
|
+
type: string;
|
|
55
|
+
id?: number;
|
|
56
|
+
data: Record<string, unknown>;
|
|
57
|
+
}>;
|
|
58
|
+
/**
|
|
59
|
+
* Thrown by a @Subscribe: the member's message is refused, with this reason —
|
|
60
|
+
* the client's GatewayError.reason, a word the app chose for its own app to
|
|
61
|
+
* act on ('not_your_turn', 'too_many_messages'). What the method wrote is
|
|
62
|
+
* rolled back. Anything else a method throws is the app's log's: its words
|
|
63
|
+
* could carry anything, and the member is told handler_failed.
|
|
64
|
+
*/
|
|
65
|
+
export declare class GatewayRefusal extends Error {
|
|
66
|
+
readonly reason: string;
|
|
67
|
+
constructor(reason: string);
|
|
68
|
+
}
|
|
69
|
+
/** What a gateway class declares its events with: `static readonly events = { name: schema }`. */
|
|
70
|
+
export interface GatewayEvents {
|
|
71
|
+
readonly events?: Readonly<Record<string, StandardSchemaV1>>;
|
|
72
|
+
}
|
|
73
|
+
/** A gateway as its decorators declare it. */
|
|
74
|
+
export interface GatewayDeclaration {
|
|
75
|
+
/** The class's name: its client's, in every generated client. */
|
|
76
|
+
name: string;
|
|
77
|
+
pattern: string;
|
|
78
|
+
access?: 'owner' | 'public';
|
|
79
|
+
publish: boolean;
|
|
80
|
+
/** How long it keeps what it sends, in seconds: 0 keeps nothing. */
|
|
81
|
+
logKeepSeconds: number;
|
|
82
|
+
/** It carries a chat (GatewayOptions.chat): its event `chat` is the chat's parts. */
|
|
83
|
+
chat: boolean;
|
|
84
|
+
events: Record<string, StandardSchemaV1>;
|
|
85
|
+
graceMs: number;
|
|
86
|
+
/** Each moment, the method told of it. */
|
|
87
|
+
hooks: Partial<Record<GatewayHook, string>>;
|
|
88
|
+
/** Each message a member may send: its method, its payload's schema, and its ack's when said — an object of no prototype, whatever the names. */
|
|
89
|
+
messages: Record<string, {
|
|
90
|
+
fn: string;
|
|
91
|
+
schema: StandardSchemaV1;
|
|
92
|
+
reply?: StandardSchemaV1;
|
|
93
|
+
}>;
|
|
94
|
+
}
|
|
95
|
+
/** Whether the machine serves it — a method of it is told of something — or realtime decides it alone. */
|
|
96
|
+
export declare const servedByTheApp: (g: GatewayDeclaration) => boolean;
|
|
97
|
+
/** Who a member is, to a gateway's methods. */
|
|
98
|
+
export interface GatewayUser {
|
|
99
|
+
/** The user's id; "" in @OnFirst and @OnEmpty, which no one in particular caused. */
|
|
100
|
+
id: string;
|
|
101
|
+
}
|
|
102
|
+
/** What @Authorize is given: who asks to join, and the channel's parameters. */
|
|
103
|
+
export interface GatewayAuthorizeContext {
|
|
104
|
+
user: GatewayUser;
|
|
105
|
+
params: Readonly<Record<string, string>>;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* What @Authorize answers: true lets the user in to hear and to send; an
|
|
109
|
+
* object says which — { read: false } is no way in, { write: false } a
|
|
110
|
+
* listener who may not send; null, undefined or false keep the user out. So
|
|
111
|
+
* does any other answer, and a method that throws: only a grant lets anyone
|
|
112
|
+
* in, and the app's log says what was answered instead.
|
|
113
|
+
*/
|
|
114
|
+
export type GatewayGrant = boolean | null | undefined | {
|
|
115
|
+
read?: boolean;
|
|
116
|
+
write?: boolean;
|
|
117
|
+
};
|
|
118
|
+
/** What a gateway's moments are given (@OnFirst, @OnConnect, @OnDisconnect, @OnEmpty). */
|
|
119
|
+
export interface GatewayContext {
|
|
120
|
+
/** The channel: "chat:42". */
|
|
121
|
+
channel: string;
|
|
122
|
+
/** The pattern's parameters: { chatId: "42" }. */
|
|
123
|
+
params: Readonly<Record<string, string>>;
|
|
124
|
+
/**
|
|
125
|
+
* The channel's own: aborted when it empties (before @OnEmpty runs), or
|
|
126
|
+
* when owner.release() gives it up — what @OnFirst started stops on it.
|
|
127
|
+
*/
|
|
128
|
+
signal: AbortSignal;
|
|
129
|
+
/** Its members now, across realtime's replicas; 0 in a @Subscribe. */
|
|
130
|
+
count: number;
|
|
131
|
+
user: GatewayUser;
|
|
132
|
+
/**
|
|
133
|
+
* An event to the channel's members — in @OnConnect, to the member who
|
|
134
|
+
* joined alone. Sent in the order emitted, and never thrown: what could
|
|
135
|
+
* not be sent is in the app's log.
|
|
136
|
+
*/
|
|
137
|
+
emit(event: string, payload?: unknown): void;
|
|
138
|
+
/**
|
|
139
|
+
* The platform writes `source` into this channel from now on — a chat's
|
|
140
|
+
* stream: `ctx.pipe(Palbase.ai.chats.events(chatId))`. The backend is not
|
|
141
|
+
* in the stream after; the gateway's members hear it.
|
|
142
|
+
*/
|
|
143
|
+
pipe(source: PipeSource): Promise<void>;
|
|
144
|
+
owner: {
|
|
145
|
+
/** Runs `work` past the method, until the channel's signal aborts: an upstream's loop. Its failure is logged, never the app's crash. */
|
|
146
|
+
hold(work: (signal: AbortSignal) => unknown): void;
|
|
147
|
+
/** Gives the channel up now: its signal aborts, and the next member to come finds it unheld (@OnFirst again). */
|
|
148
|
+
release(): void;
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/** What a @Subscribe is given: the channel's context, the member, and the payload as its schema made it. */
|
|
152
|
+
export interface GatewayMessageContext<P = unknown> extends GatewayContext {
|
|
153
|
+
payload: P;
|
|
154
|
+
}
|
|
155
|
+
/** v2 held a room a minute after its last member: twice the slowest client's heartbeat, and margin. */
|
|
156
|
+
export declare const DEFAULT_GRACE_MS = 60000;
|
|
157
|
+
/** A durable gateway keeps what it sends a day unless it says; a week at most. */
|
|
158
|
+
export declare const DEFAULT_KEEP_SECONDS = 86400;
|
|
159
|
+
export declare const MAX_KEEP_SECONDS = 604800;
|
|
160
|
+
/** The most a @Subscribe's ack carries (realtime's roomReplyMax). */
|
|
161
|
+
export declare const MAX_REPLY_BYTES: number;
|
|
162
|
+
/**
|
|
163
|
+
* Why `pattern` is no gateway's, or undefined. A pattern is a channel's: ':'
|
|
164
|
+
* segments, a "{name}" segment taking exactly one — and realtime takes a
|
|
165
|
+
* pattern it cannot decide for no channel at all, silently: the gateway
|
|
166
|
+
* would compile, ship and never be joined. So everything it would not take is
|
|
167
|
+
* refused here, by name, while someone is looking.
|
|
168
|
+
*/
|
|
169
|
+
export declare function patternProblem(pattern: string): string | undefined;
|
|
170
|
+
/**
|
|
171
|
+
* A class whose methods manage the channels `pattern` names (see the top of
|
|
172
|
+
* this file). It is a provider a module lists (its constructor injected as
|
|
173
|
+
* any provider's), built once: what @OnFirst starts and @OnEmpty stops lives
|
|
174
|
+
* in it. Its events are its class's `static readonly events`.
|
|
175
|
+
*/
|
|
176
|
+
export declare function Gateway(pattern: string, options?: GatewayOptions): ClassDecorator;
|
|
177
|
+
/** Who may join: answers a GatewayGrant (GatewayAuthorizeContext) — for a gateway with no access of realtime's. */
|
|
178
|
+
export declare const Authorize: () => MethodDecorator;
|
|
179
|
+
/**
|
|
180
|
+
* The channel is occupied and held by no one: start what it needs. Told once
|
|
181
|
+
* across realtime's replicas when its first member comes — before that
|
|
182
|
+
* member is answered — and again only after it emptied.
|
|
183
|
+
*/
|
|
184
|
+
export declare const OnFirst: () => MethodDecorator;
|
|
185
|
+
/** A member joined (after it was answered): what it emits goes to that member alone. */
|
|
186
|
+
export declare const OnConnect: () => MethodDecorator;
|
|
187
|
+
/** A member left. */
|
|
188
|
+
export declare const OnDisconnect: () => MethodDecorator;
|
|
189
|
+
/** Nobody has been on the channel for its graceMs: stop what @OnFirst started. Its signal is aborted already. */
|
|
190
|
+
export declare const OnEmpty: () => MethodDecorator;
|
|
191
|
+
/**
|
|
192
|
+
* A message a member sends, `name`, its payload checked against `schema`
|
|
193
|
+
* before the method runs (GatewayMessageContext): a payload that does not
|
|
194
|
+
* fit never reaches it, and the member hears why. What the method returns
|
|
195
|
+
* is the member's ack — `reply` its schema in every generated client.
|
|
196
|
+
*/
|
|
197
|
+
export declare function Subscribe(name: string, schema: StandardSchemaV1, options?: {
|
|
198
|
+
reply?: StandardSchemaV1;
|
|
199
|
+
}): MethodDecorator;
|
|
200
|
+
/** The gateway a class declares, or undefined: a gateway is one by its decorator, never its name. */
|
|
201
|
+
export declare function gatewayOf(cls: Function): GatewayDeclaration | undefined;
|
|
202
|
+
/** A gateway's channel's parameters, or undefined when the channel is not one of its. */
|
|
203
|
+
export declare function matchChannel(pattern: string, channel: string): Record<string, string> | undefined;
|
|
204
|
+
/** The channel of a gateway's parameters: each named by its pattern, a whole segment — or why not. */
|
|
205
|
+
export declare function channelOf(pattern: string, params: Readonly<Record<string, unknown>>): string | {
|
|
206
|
+
problem: string;
|
|
207
|
+
};
|
|
208
|
+
/** One event to a gateway's members, as realtime's broadcast takes it: its channel (topic), and conn_id for one membership alone. */
|
|
209
|
+
type GatewayBroadcast = realtime.BroadcastMessage;
|
|
210
|
+
export interface GatewayDeps {
|
|
211
|
+
/**
|
|
212
|
+
* `work` as the platform's caller names it — in a transaction as `user`,
|
|
213
|
+
* or as the app itself when the moment is no one's (first, empty) —
|
|
214
|
+
* committed unless it throws, or the platform hung up before it ended.
|
|
215
|
+
*/
|
|
216
|
+
run<T>(user: SignedUser | undefined, where: string, signal: AbortSignal | undefined, work: () => Promise<T>): Promise<T>;
|
|
217
|
+
/** realtime's POST /realtime/broadcast, as the app (its secret key). */
|
|
218
|
+
broadcast(messages: GatewayBroadcast[]): Promise<unknown>;
|
|
219
|
+
/** The platform's infrastructure, not the method, failed: the call is answered 503, and realtime asks again. */
|
|
220
|
+
isOutage(e: unknown): boolean;
|
|
221
|
+
}
|
|
222
|
+
/** What a gateway's call is answered: JSON, nothing (204), or a refusal. */
|
|
223
|
+
export type GatewayAnswer = {
|
|
224
|
+
status: 200;
|
|
225
|
+
body: unknown;
|
|
226
|
+
} | {
|
|
227
|
+
status: 204;
|
|
228
|
+
} | {
|
|
229
|
+
status: number;
|
|
230
|
+
code: string;
|
|
231
|
+
message: string;
|
|
232
|
+
retryAfter?: number;
|
|
233
|
+
};
|
|
234
|
+
export interface Gateways {
|
|
235
|
+
readonly declarations: readonly GatewayDeclaration[];
|
|
236
|
+
/** The platform's call about a gateway — authorize, message or lifecycle — its JSON body. */
|
|
237
|
+
serve(kind: string, body: unknown, signal?: AbortSignal): Promise<GatewayAnswer>;
|
|
238
|
+
/** An event to a gateway's channel from anywhere in the app (Palbase.gateways.to). */
|
|
239
|
+
emit(cls: Function, params: Readonly<Record<string, unknown>>, event: string, payload: unknown): void;
|
|
240
|
+
/** A source piped into a gateway's channel from anywhere in the app (Palbase.gateways.to(…).pipe). */
|
|
241
|
+
pipe(cls: Function, params: Readonly<Record<string, unknown>>, source: PipeSource): Promise<void>;
|
|
242
|
+
/** Every channel let go: what was held is aborted (the app is stopping). */
|
|
243
|
+
close(): void;
|
|
244
|
+
}
|
|
245
|
+
/** The app's gateways, served: `classes` its providers that are gateways, each with its instance. */
|
|
246
|
+
export declare function createGateways(classes: {
|
|
247
|
+
cls: Function;
|
|
248
|
+
instance: object;
|
|
249
|
+
}[], deps: GatewayDeps): Gateways;
|
|
250
|
+
export {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
export { Body, Client, Controller, Delete, Get, getRegisteredControllers, getRoutes, Headers, Cron, Injectable, Module, On, OptionalUser, Param, Patch, Post, Put, Query, QueryParams, Req, RequestId, Resolve, TraceId, User, Webhook, type AuthConfig, type AuthSpec, type ControllerOptions, type EventHandler, type CronMeta, type CronOptions, type ModuleDef, type OnOptions, type ParamResolver, type RateLimitConfig, type ResolveContext, type RouteInfo, type RouteOptions, type SignatureSpec, type StandardSchemaV1, type Token, type WebhookOptions, type WebhookProvider, } from './decorators.js';
|
|
3
3
|
export { Task, TaskFailure, Tasks, type EnqueueOptions, type PayloadOf, type QueuedTask, type TaskClass, type TaskMeta, type TaskOptions, type TasksService } from './tasks.js';
|
|
4
|
-
export { defineChannels, ownerOnly, publicChannel, type ChannelAuthorizeCtx, type ChannelEntry, type ChannelGrant, type ChannelsDef, type ChannelsInput } from './channels.js';
|
|
5
4
|
export { Upload, UploadedObject, type UploadConfig } from './upload.js';
|
|
6
|
-
export {
|
|
5
|
+
export { Authorize, ChatPart, Gateway, GatewayRefusal, OnConnect, OnDisconnect, OnEmpty, OnFirst, Subscribe, type GatewayAuthorizeContext, type GatewayContext, type GatewayEvents, type GatewayGrant, type GatewayMessageContext, type GatewayOptions, type GatewayUser, type PipeSource, } from './gateways.js';
|
|
6
|
+
export type { GatewaysApi, GatewayTarget } from './runtime.js';
|
|
7
7
|
export { getWebhookManifest, type WebhookEventHandler, type WebhookMeta } from './webhooks.js';
|
|
8
8
|
export { DiError, type DiErrorKind } from './container.js';
|
|
9
9
|
export { BadRequest, Conflict, DeadlockDetected, Forbidden, HttpError, NotFound, PalError, SerializationFailure, TooManyRequests, Unauthorized, UniqueViolation, defineError, type DefinedError, type DefinedErrorWithData, type Envelope, type FieldIssue, } from './errors.js';
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { RateLimitConfig, StandardSchemaV1 } from './decorators.js';
|
|
2
2
|
import type { RegisteredError } from './errors.js';
|
|
3
|
-
import type
|
|
4
|
-
import type { RoomDeclaration } from './rooms.js';
|
|
3
|
+
import { type GatewayDeclaration } from './gateways.js';
|
|
5
4
|
import type { Route } from './router.js';
|
|
6
5
|
/** Where the platform delivers the project's events to the app. */
|
|
7
6
|
export declare const PLATFORM_EVENTS_PATH = "/webhooks/palbase";
|
|
@@ -33,10 +32,8 @@ export interface ContractOptions {
|
|
|
33
32
|
routes?: (route: Route) => RouteContract | undefined;
|
|
34
33
|
/** The release's errors by wire code (defineError's registry): what a thrown code is typed as. */
|
|
35
34
|
errors?: ReadonlyMap<string, RegisteredError>;
|
|
36
|
-
/** The app's @
|
|
37
|
-
|
|
38
|
-
/** The owner and public channels defineChannels declares, in its order: x-palbase-channels, decided by realtime itself. */
|
|
39
|
-
channels?: readonly ChannelRow[];
|
|
35
|
+
/** The app's @Gateway classes, as their decorators declare them. */
|
|
36
|
+
gateways?: readonly GatewayDeclaration[];
|
|
40
37
|
}
|
|
41
38
|
/** What a route answers and throws, as its source declares. */
|
|
42
39
|
export interface RouteContract {
|