@browserlessapi/inferlo 0.5.0 → 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/README.md +14 -5
- package/dist/ai/ai-sdk.d.ts +48 -0
- package/dist/ai/ai-sdk.js +235 -0
- package/dist/ai/ai-sdk.js.map +1 -0
- package/dist/ai/index.d.ts +44 -3
- package/dist/ai/index.js +164 -9
- package/dist/ai/index.js.map +1 -1
- package/dist/ai/public.d.ts +6 -1
- package/dist/ai/public.js +2 -0
- package/dist/ai/public.js.map +1 -1
- package/dist/ai/ui.d.ts +47 -0
- package/dist/ai/ui.js +33 -0
- package/dist/ai/ui.js.map +1 -0
- package/dist/api-version.d.ts +32 -0
- package/dist/api-version.js +45 -0
- package/dist/api-version.js.map +1 -0
- package/dist/app.d.ts +60 -6
- package/dist/app.js +310 -66
- package/dist/app.js.map +1 -1
- package/dist/astro.d.ts +60 -0
- package/dist/astro.js +68 -0
- package/dist/astro.js.map +1 -0
- package/dist/audit.d.ts +57 -0
- package/dist/audit.js +99 -0
- package/dist/audit.js.map +1 -0
- package/dist/auth.d.ts +1 -0
- package/dist/auth.js +1 -0
- package/dist/auth.js.map +1 -1
- package/dist/azure.d.ts +66 -0
- package/dist/azure.js +119 -0
- package/dist/azure.js.map +1 -0
- package/dist/cache.d.ts +96 -0
- package/dist/cache.js +247 -0
- package/dist/cache.js.map +1 -0
- package/dist/cli/main.js +28 -7
- package/dist/cli/main.js.map +1 -1
- package/dist/client-ip.d.ts +36 -1
- package/dist/client-ip.js +80 -1
- package/dist/client-ip.js.map +1 -1
- package/dist/db/memory.js +2 -1
- package/dist/db/memory.js.map +1 -1
- package/dist/db/postgres.js +4 -1
- package/dist/db/postgres.js.map +1 -1
- package/dist/db/table.d.ts +37 -5
- package/dist/db/table.js +96 -15
- package/dist/db/table.js.map +1 -1
- package/dist/db/types.d.ts +2 -0
- package/dist/describe.d.ts +54 -2
- package/dist/describe.js +34 -3
- package/dist/describe.js.map +1 -1
- package/dist/events.d.ts +134 -0
- package/dist/events.js +196 -0
- package/dist/events.js.map +1 -0
- package/dist/fastify.d.ts +10 -2
- package/dist/fastify.js +22 -4
- package/dist/fastify.js.map +1 -1
- package/dist/h3.d.ts +76 -0
- package/dist/h3.js +61 -0
- package/dist/h3.js.map +1 -0
- package/dist/hapi.d.ts +45 -0
- package/dist/hapi.js +57 -0
- package/dist/hapi.js.map +1 -0
- package/dist/index.d.ts +25 -5
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/jobs.d.ts +70 -10
- package/dist/jobs.js +78 -13
- package/dist/jobs.js.map +1 -1
- package/dist/koa.d.ts +51 -0
- package/dist/koa.js +45 -0
- package/dist/koa.js.map +1 -0
- package/dist/lambda.d.ts +110 -0
- package/dist/lambda.js +169 -0
- package/dist/lambda.js.map +1 -0
- package/dist/langchain.d.ts +58 -0
- package/dist/langchain.js +220 -0
- package/dist/langchain.js.map +1 -0
- package/dist/mcp.d.ts +1 -1
- package/dist/mcp.js +7 -3
- package/dist/mcp.js.map +1 -1
- package/dist/model.d.ts +23 -6
- package/dist/model.js +35 -6
- package/dist/model.js.map +1 -1
- package/dist/module.d.ts +52 -0
- package/dist/module.js +152 -0
- package/dist/module.js.map +1 -0
- package/dist/nextjs.d.ts +35 -0
- package/dist/nextjs.js +33 -0
- package/dist/nextjs.js.map +1 -0
- package/dist/openapi.d.ts +3 -0
- package/dist/openapi.js +12 -3
- package/dist/openapi.js.map +1 -1
- package/dist/permissions.d.ts +26 -0
- package/dist/permissions.js +78 -0
- package/dist/permissions.js.map +1 -0
- package/dist/rate-limit.d.ts +5 -3
- package/dist/rate-limit.js +3 -3
- package/dist/rate-limit.js.map +1 -1
- package/dist/react-router.d.ts +41 -0
- package/dist/react-router.js +42 -0
- package/dist/react-router.js.map +1 -0
- package/dist/redis-events.d.ts +27 -0
- package/dist/redis-events.js +163 -0
- package/dist/redis-events.js.map +1 -0
- package/dist/redis-jobs.d.ts +24 -0
- package/dist/redis-jobs.js +203 -0
- package/dist/redis-jobs.js.map +1 -0
- package/dist/redis.d.ts +30 -0
- package/dist/redis.js +106 -0
- package/dist/redis.js.map +1 -0
- package/dist/request-matcher.d.ts +4 -0
- package/dist/request-matcher.js +14 -0
- package/dist/request-matcher.js.map +1 -0
- package/dist/response-body.d.ts +6 -0
- package/dist/response-body.js +7 -0
- package/dist/response-body.js.map +1 -0
- package/dist/route.d.ts +50 -2
- package/dist/route.js +24 -0
- package/dist/route.js.map +1 -1
- package/dist/schema.d.ts +2 -2
- package/dist/serve.d.ts +26 -2
- package/dist/serve.js +111 -10
- package/dist/serve.js.map +1 -1
- package/dist/service-client.d.ts +91 -0
- package/dist/service-client.js +177 -0
- package/dist/service-client.js.map +1 -0
- package/dist/sessions.d.ts +74 -0
- package/dist/sessions.js +172 -0
- package/dist/sessions.js.map +1 -0
- package/dist/sveltekit.d.ts +72 -0
- package/dist/sveltekit.js +68 -0
- package/dist/sveltekit.js.map +1 -0
- package/dist/tracing.d.ts +122 -0
- package/dist/tracing.js +210 -0
- package/dist/tracing.js.map +1 -0
- package/llms.txt +8 -3
- package/package.json +78 -4
- package/templates/app/AGENTS.md +10 -6
package/dist/app.d.ts
CHANGED
|
@@ -3,15 +3,21 @@
|
|
|
3
3
|
* fetch(Request) => Response handler that runs on Node, Bun, Deno and edge runtimes.
|
|
4
4
|
*/
|
|
5
5
|
import { type AI, type AIConfig } from "./ai/index.ts";
|
|
6
|
+
import { type Cache, type CacheConfig } from "./cache.ts";
|
|
6
7
|
import { type Db } from "./db/table.ts";
|
|
7
8
|
import type { Adapter } from "./db/types.ts";
|
|
8
9
|
import { type AppDescription } from "./describe.ts";
|
|
9
10
|
import type { AnyModel } from "./model.ts";
|
|
10
11
|
import { type AppDb, type AppUser, type Method, type RouteDef } from "./route.ts";
|
|
12
|
+
import { type RedisClient } from "./redis.ts";
|
|
11
13
|
import { type RateLimitConfig } from "./rate-limit.ts";
|
|
12
14
|
import { type AppJobs, type JobQueueConfig, type JobSource } from "./jobs.ts";
|
|
15
|
+
import { type AppEvents, type EventsConfig } from "./events.ts";
|
|
13
16
|
import { type LogFields, type LoggingConfig } from "./logging.ts";
|
|
17
|
+
import { type TracingConfig } from "./tracing.ts";
|
|
14
18
|
import { type MetricsConfig } from "./metrics.ts";
|
|
19
|
+
import { type AnyModule, type ModuleModels } from "./module.ts";
|
|
20
|
+
import { type Permissions } from "./permissions.ts";
|
|
15
21
|
import { type SecureHeadersConfig } from "./secure-headers.ts";
|
|
16
22
|
export interface AuthConfig {
|
|
17
23
|
/** Return the signed-in user for this request, or null. */
|
|
@@ -21,6 +27,12 @@ export interface AuthConfig {
|
|
|
21
27
|
}): AppUser | null | undefined | Promise<AppUser | null | undefined>;
|
|
22
28
|
/** Roles of a user, checked when a route uses auth: "<role>". Default: user.roles ?? []. */
|
|
23
29
|
roles?(user: AppUser): string[];
|
|
30
|
+
/**
|
|
31
|
+
* The tenant (organisation, workspace, customer) a user belongs to, for tenant-scoped models
|
|
32
|
+
* (model(name, fields, { tenant: true })): ctx.db filters and stamps their rows with it.
|
|
33
|
+
* Default: user.tenantId. Return null for a user without a tenant.
|
|
34
|
+
*/
|
|
35
|
+
tenant?(user: AppUser): string | null | undefined;
|
|
24
36
|
}
|
|
25
37
|
export interface CorsConfig {
|
|
26
38
|
/** Allowed origins, or "*". */
|
|
@@ -52,7 +64,7 @@ export interface HealthConfig {
|
|
|
52
64
|
path?: string;
|
|
53
65
|
/** Readiness endpoint: 200 when every check passes, 503 otherwise. Default "/ready". */
|
|
54
66
|
readyPath?: string;
|
|
55
|
-
/** Your own checks, by name ("database" and "
|
|
67
|
+
/** Your own checks, by name ("database", "ai" and, with createApp({ redis }), "redis" are built in): { search: () => search.ping() }. */
|
|
56
68
|
checks?: Record<string, HealthCheck>;
|
|
57
69
|
/** Time each check may take before it fails. Default 5000 ms. */
|
|
58
70
|
timeoutMs?: number;
|
|
@@ -80,20 +92,37 @@ export interface ReadinessReport {
|
|
|
80
92
|
export type RouteSource = RouteDef | readonly RouteSource[] | {
|
|
81
93
|
readonly [name: string]: unknown;
|
|
82
94
|
};
|
|
83
|
-
export interface AppConfig<Models extends readonly AnyModel[]> {
|
|
95
|
+
export interface AppConfig<Models extends readonly AnyModel[], Modules extends readonly AnyModule[] = readonly AnyModule[]> {
|
|
84
96
|
/** Shown in OpenAPI, MCP and describe. */
|
|
85
97
|
name?: string;
|
|
86
98
|
version?: string;
|
|
87
99
|
description?: string;
|
|
88
100
|
models?: Models;
|
|
101
|
+
/**
|
|
102
|
+
* Feature modules from module("billing", { imports, models, routes, jobs, provides }). Their models, routes
|
|
103
|
+
* and jobs join the app's own; every module a module imports must be listed here too.
|
|
104
|
+
*/
|
|
105
|
+
modules?: Modules;
|
|
89
106
|
routes?: RouteSource[];
|
|
90
|
-
/** Background jobs and
|
|
107
|
+
/** Background jobs, crons and event subscriptions: jobs, cron(schedule, job) and on(event, job) values, arrays or modules (import * as jobs from "./jobs.ts"). */
|
|
91
108
|
jobs?: JobSource[];
|
|
92
109
|
/** Where queued jobs are kept: { store: "memory" } (default) or { store: "database" } (Postgres table inferlo_jobs, shared by every instance). */
|
|
93
110
|
jobQueue?: JobQueueConfig;
|
|
111
|
+
/**
|
|
112
|
+
* Events between services: { transport: "redis" } sends published events through Redis Streams (needs redis and
|
|
113
|
+
* name), so every service with an on(event, job) subscription gets them. Default: events stay in this app.
|
|
114
|
+
*/
|
|
115
|
+
events?: EventsConfig;
|
|
116
|
+
/**
|
|
117
|
+
* Where ctx.cache and app.cache keep entries: { store: "memory" } (default), { store: "database" } (Postgres
|
|
118
|
+
* table inferlo_cache) or { store: "redis" } (createApp({ redis })), both shared by every instance.
|
|
119
|
+
*/
|
|
120
|
+
cache?: CacheConfig;
|
|
94
121
|
/** Database adapter. Default: memory(). Use postgres() from "@browserlessapi/inferlo/postgres" in production. */
|
|
95
122
|
db?: Adapter;
|
|
96
123
|
auth?: AuthConfig;
|
|
124
|
+
/** Named permissions from permissions({ ... }), required when a route sets permission. */
|
|
125
|
+
permissions?: Permissions<any>;
|
|
97
126
|
ai?: AIConfig;
|
|
98
127
|
cors?: boolean | CorsConfig;
|
|
99
128
|
middleware?: Middleware[];
|
|
@@ -103,7 +132,16 @@ export interface AppConfig<Models extends readonly AnyModel[]> {
|
|
|
103
132
|
mcp?: string | false;
|
|
104
133
|
/** Maximum request body in bytes. Default 1 MiB. */
|
|
105
134
|
maxBodySize?: number;
|
|
106
|
-
/**
|
|
135
|
+
/**
|
|
136
|
+
* A connected Redis client (createClient() from the redis package, after await client.connect()), for
|
|
137
|
+
* rateLimit: { store: "redis" } and cache: { store: "redis" }. /ready checks that it answers. Inferlo never closes it: call client.close()
|
|
138
|
+
* after app.close().
|
|
139
|
+
*/
|
|
140
|
+
redis?: RedisClient;
|
|
141
|
+
/**
|
|
142
|
+
* Where route rateLimit counts are kept: { store: "memory" } (default), { store: "database" } (Postgres) or
|
|
143
|
+
* { store: "redis" } (createApp({ redis })), both shared by every instance.
|
|
144
|
+
*/
|
|
107
145
|
rateLimit?: RateLimitConfig;
|
|
108
146
|
/**
|
|
109
147
|
* Behind a load balancer or proxy that sets X-Forwarded-For: true uses its first address as the client IP
|
|
@@ -148,6 +186,12 @@ export interface AppConfig<Models extends readonly AnyModel[]> {
|
|
|
148
186
|
* public, so keep it off the internet. Off by default.
|
|
149
187
|
*/
|
|
150
188
|
metrics?: boolean | MetricsConfig;
|
|
189
|
+
/**
|
|
190
|
+
* OpenTelemetry tracing: import * as otel from "@opentelemetry/api", then tracing: { api: otel }. Every request
|
|
191
|
+
* gets a server span that continues the caller's trace, and log entries get traceId and spanId. AI calls and
|
|
192
|
+
* database queries inside it get client spans (model, tokens and cost; table and operation). Off by default.
|
|
193
|
+
*/
|
|
194
|
+
tracing?: TracingConfig;
|
|
151
195
|
}
|
|
152
196
|
export interface RequestOptions {
|
|
153
197
|
method?: Method | Lowercase<Method> | "OPTIONS" | "HEAD";
|
|
@@ -163,11 +207,18 @@ export interface App<Models extends readonly AnyModel[]> {
|
|
|
163
207
|
readonly name: string;
|
|
164
208
|
readonly version: string;
|
|
165
209
|
readonly routes: readonly RouteDef[];
|
|
210
|
+
/** Every model: createApp({ models }) and then the models of each module. */
|
|
166
211
|
readonly models: Models;
|
|
212
|
+
/** The feature modules from createApp({ modules }). */
|
|
213
|
+
readonly modules: readonly AnyModule[];
|
|
167
214
|
readonly db: Db<Models>;
|
|
168
215
|
readonly ai: AI;
|
|
169
216
|
/** Background jobs: app.jobs.enqueue(job, input), app.jobs.start() to run them, app.jobs.runDue() in tests. */
|
|
170
217
|
readonly jobs: AppJobs;
|
|
218
|
+
/** Events: app.events.publish(orderPaid, payload) queues the jobs subscribed with on(event, job) in createApp({ jobs }). */
|
|
219
|
+
readonly events: AppEvents;
|
|
220
|
+
/** The app cache, the same as ctx.cache: await app.cache.getOrSet(key, { ttlMs, tags }, compute), app.cache.invalidate(tag). */
|
|
221
|
+
readonly cache: Cache;
|
|
171
222
|
/** Standard fetch handler: export default app works on Bun, Deno and Cloudflare Workers. */
|
|
172
223
|
fetch(req: Request, ...rest: unknown[]): Promise<Response>;
|
|
173
224
|
/** In-process request for tests: await app.request("/tickets", { method: "POST", json: {...}, as: user }). */
|
|
@@ -189,6 +240,9 @@ export interface App<Models extends readonly AnyModel[]> {
|
|
|
189
240
|
close(options?: CloseOptions): Promise<void>;
|
|
190
241
|
/** Machine-readable map of the whole app: routes, models, auth and AI. */
|
|
191
242
|
describe(): AppDescription;
|
|
192
|
-
|
|
243
|
+
/** The OpenAPI 3.1 document: every route, or with { version: "v1" } the routes of apiVersion("v1", ...) and the routes outside every version. */
|
|
244
|
+
openapi(options?: {
|
|
245
|
+
version?: string;
|
|
246
|
+
}): Record<string, unknown>;
|
|
193
247
|
}
|
|
194
|
-
export declare function createApp<const Models extends readonly AnyModel[] = []>(config?: AppConfig<Models>): App<Models>;
|
|
248
|
+
export declare function createApp<const Models extends readonly AnyModel[] = [], const Modules extends readonly AnyModule[] = []>(config?: AppConfig<Models, Modules>): App<[...Models, ...ModuleModels<Modules>]>;
|