@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.
Files changed (138) hide show
  1. package/README.md +14 -5
  2. package/dist/ai/ai-sdk.d.ts +48 -0
  3. package/dist/ai/ai-sdk.js +235 -0
  4. package/dist/ai/ai-sdk.js.map +1 -0
  5. package/dist/ai/index.d.ts +44 -3
  6. package/dist/ai/index.js +164 -9
  7. package/dist/ai/index.js.map +1 -1
  8. package/dist/ai/public.d.ts +6 -1
  9. package/dist/ai/public.js +2 -0
  10. package/dist/ai/public.js.map +1 -1
  11. package/dist/ai/ui.d.ts +47 -0
  12. package/dist/ai/ui.js +33 -0
  13. package/dist/ai/ui.js.map +1 -0
  14. package/dist/api-version.d.ts +32 -0
  15. package/dist/api-version.js +45 -0
  16. package/dist/api-version.js.map +1 -0
  17. package/dist/app.d.ts +60 -6
  18. package/dist/app.js +310 -66
  19. package/dist/app.js.map +1 -1
  20. package/dist/astro.d.ts +60 -0
  21. package/dist/astro.js +68 -0
  22. package/dist/astro.js.map +1 -0
  23. package/dist/audit.d.ts +57 -0
  24. package/dist/audit.js +99 -0
  25. package/dist/audit.js.map +1 -0
  26. package/dist/auth.d.ts +1 -0
  27. package/dist/auth.js +1 -0
  28. package/dist/auth.js.map +1 -1
  29. package/dist/azure.d.ts +66 -0
  30. package/dist/azure.js +119 -0
  31. package/dist/azure.js.map +1 -0
  32. package/dist/cache.d.ts +96 -0
  33. package/dist/cache.js +247 -0
  34. package/dist/cache.js.map +1 -0
  35. package/dist/cli/main.js +28 -7
  36. package/dist/cli/main.js.map +1 -1
  37. package/dist/client-ip.d.ts +36 -1
  38. package/dist/client-ip.js +80 -1
  39. package/dist/client-ip.js.map +1 -1
  40. package/dist/db/memory.js +2 -1
  41. package/dist/db/memory.js.map +1 -1
  42. package/dist/db/postgres.js +4 -1
  43. package/dist/db/postgres.js.map +1 -1
  44. package/dist/db/table.d.ts +37 -5
  45. package/dist/db/table.js +96 -15
  46. package/dist/db/table.js.map +1 -1
  47. package/dist/db/types.d.ts +2 -0
  48. package/dist/describe.d.ts +54 -2
  49. package/dist/describe.js +34 -3
  50. package/dist/describe.js.map +1 -1
  51. package/dist/events.d.ts +134 -0
  52. package/dist/events.js +196 -0
  53. package/dist/events.js.map +1 -0
  54. package/dist/fastify.d.ts +10 -2
  55. package/dist/fastify.js +22 -4
  56. package/dist/fastify.js.map +1 -1
  57. package/dist/h3.d.ts +76 -0
  58. package/dist/h3.js +61 -0
  59. package/dist/h3.js.map +1 -0
  60. package/dist/hapi.d.ts +45 -0
  61. package/dist/hapi.js +57 -0
  62. package/dist/hapi.js.map +1 -0
  63. package/dist/index.d.ts +25 -5
  64. package/dist/index.js +9 -1
  65. package/dist/index.js.map +1 -1
  66. package/dist/jobs.d.ts +70 -10
  67. package/dist/jobs.js +78 -13
  68. package/dist/jobs.js.map +1 -1
  69. package/dist/koa.d.ts +51 -0
  70. package/dist/koa.js +45 -0
  71. package/dist/koa.js.map +1 -0
  72. package/dist/lambda.d.ts +110 -0
  73. package/dist/lambda.js +169 -0
  74. package/dist/lambda.js.map +1 -0
  75. package/dist/langchain.d.ts +58 -0
  76. package/dist/langchain.js +220 -0
  77. package/dist/langchain.js.map +1 -0
  78. package/dist/mcp.d.ts +1 -1
  79. package/dist/mcp.js +7 -3
  80. package/dist/mcp.js.map +1 -1
  81. package/dist/model.d.ts +23 -6
  82. package/dist/model.js +35 -6
  83. package/dist/model.js.map +1 -1
  84. package/dist/module.d.ts +52 -0
  85. package/dist/module.js +152 -0
  86. package/dist/module.js.map +1 -0
  87. package/dist/nextjs.d.ts +35 -0
  88. package/dist/nextjs.js +33 -0
  89. package/dist/nextjs.js.map +1 -0
  90. package/dist/openapi.d.ts +3 -0
  91. package/dist/openapi.js +12 -3
  92. package/dist/openapi.js.map +1 -1
  93. package/dist/permissions.d.ts +26 -0
  94. package/dist/permissions.js +78 -0
  95. package/dist/permissions.js.map +1 -0
  96. package/dist/rate-limit.d.ts +5 -3
  97. package/dist/rate-limit.js +3 -3
  98. package/dist/rate-limit.js.map +1 -1
  99. package/dist/react-router.d.ts +41 -0
  100. package/dist/react-router.js +42 -0
  101. package/dist/react-router.js.map +1 -0
  102. package/dist/redis-events.d.ts +27 -0
  103. package/dist/redis-events.js +163 -0
  104. package/dist/redis-events.js.map +1 -0
  105. package/dist/redis-jobs.d.ts +24 -0
  106. package/dist/redis-jobs.js +203 -0
  107. package/dist/redis-jobs.js.map +1 -0
  108. package/dist/redis.d.ts +30 -0
  109. package/dist/redis.js +106 -0
  110. package/dist/redis.js.map +1 -0
  111. package/dist/request-matcher.d.ts +4 -0
  112. package/dist/request-matcher.js +14 -0
  113. package/dist/request-matcher.js.map +1 -0
  114. package/dist/response-body.d.ts +6 -0
  115. package/dist/response-body.js +7 -0
  116. package/dist/response-body.js.map +1 -0
  117. package/dist/route.d.ts +50 -2
  118. package/dist/route.js +24 -0
  119. package/dist/route.js.map +1 -1
  120. package/dist/schema.d.ts +2 -2
  121. package/dist/serve.d.ts +26 -2
  122. package/dist/serve.js +111 -10
  123. package/dist/serve.js.map +1 -1
  124. package/dist/service-client.d.ts +91 -0
  125. package/dist/service-client.js +177 -0
  126. package/dist/service-client.js.map +1 -0
  127. package/dist/sessions.d.ts +74 -0
  128. package/dist/sessions.js +172 -0
  129. package/dist/sessions.js.map +1 -0
  130. package/dist/sveltekit.d.ts +72 -0
  131. package/dist/sveltekit.js +68 -0
  132. package/dist/sveltekit.js.map +1 -0
  133. package/dist/tracing.d.ts +122 -0
  134. package/dist/tracing.js +210 -0
  135. package/dist/tracing.js.map +1 -0
  136. package/llms.txt +8 -3
  137. package/package.json +78 -4
  138. 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 "ai" are built in): { redis: () => redis.ping() }. */
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 crons: jobs, cron(schedule, job) values, arrays or modules (import * as jobs from "./jobs.ts"). */
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
- /** Where route rateLimit counts are kept: { store: "memory" } (default) or { store: "database" } (Postgres, shared by every instance). */
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
- openapi(): Record<string, unknown>;
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>]>;