@pawabase/client 0.1.3 → 0.2.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 (192) hide show
  1. package/README.md +26 -14
  2. package/dist/cjs/admin.d.ts +70 -0
  3. package/dist/cjs/admin.d.ts.map +1 -1
  4. package/dist/cjs/admin.js +75 -1
  5. package/dist/cjs/admin.js.map +1 -1
  6. package/dist/cjs/agents.d.ts +87 -0
  7. package/dist/cjs/agents.d.ts.map +1 -0
  8. package/dist/cjs/agents.js +153 -0
  9. package/dist/cjs/agents.js.map +1 -0
  10. package/dist/cjs/ai.d.ts +78 -0
  11. package/dist/cjs/ai.d.ts.map +1 -0
  12. package/dist/cjs/ai.js +127 -0
  13. package/dist/cjs/ai.js.map +1 -0
  14. package/dist/cjs/auth.d.ts +38 -0
  15. package/dist/cjs/auth.d.ts.map +1 -1
  16. package/dist/cjs/auth.js +52 -0
  17. package/dist/cjs/auth.js.map +1 -1
  18. package/dist/cjs/client.d.ts +18 -3
  19. package/dist/cjs/client.d.ts.map +1 -1
  20. package/dist/cjs/client.js +30 -3
  21. package/dist/cjs/client.js.map +1 -1
  22. package/dist/cjs/data.d.ts +28 -0
  23. package/dist/cjs/data.d.ts.map +1 -1
  24. package/dist/cjs/data.js +42 -7
  25. package/dist/cjs/data.js.map +1 -1
  26. package/dist/cjs/errors.d.ts +1 -1
  27. package/dist/cjs/errors.d.ts.map +1 -1
  28. package/dist/cjs/errors.js +8 -1
  29. package/dist/cjs/errors.js.map +1 -1
  30. package/dist/cjs/functions.d.ts +0 -28
  31. package/dist/cjs/functions.d.ts.map +1 -1
  32. package/dist/cjs/functions.js +1 -42
  33. package/dist/cjs/functions.js.map +1 -1
  34. package/dist/cjs/index.d.ts +6 -2
  35. package/dist/cjs/index.d.ts.map +1 -1
  36. package/dist/cjs/index.js +6 -2
  37. package/dist/cjs/index.js.map +1 -1
  38. package/dist/cjs/manage/access.d.ts +4 -62
  39. package/dist/cjs/manage/access.d.ts.map +1 -1
  40. package/dist/cjs/manage/access.js +4 -85
  41. package/dist/cjs/manage/access.js.map +1 -1
  42. package/dist/cjs/manage/agents.d.ts +76 -0
  43. package/dist/cjs/manage/agents.d.ts.map +1 -0
  44. package/dist/cjs/manage/agents.js +89 -0
  45. package/dist/cjs/manage/agents.js.map +1 -0
  46. package/dist/cjs/manage/ai.d.ts +90 -0
  47. package/dist/cjs/manage/ai.d.ts.map +1 -0
  48. package/dist/cjs/manage/ai.js +101 -0
  49. package/dist/cjs/manage/ai.js.map +1 -0
  50. package/dist/cjs/manage/base.d.ts +6 -16
  51. package/dist/cjs/manage/base.d.ts.map +1 -1
  52. package/dist/cjs/manage/base.js +11 -11
  53. package/dist/cjs/manage/base.js.map +1 -1
  54. package/dist/cjs/manage/data.d.ts +14 -16
  55. package/dist/cjs/manage/data.d.ts.map +1 -1
  56. package/dist/cjs/manage/data.js +15 -22
  57. package/dist/cjs/manage/data.js.map +1 -1
  58. package/dist/cjs/manage/files.d.ts +5 -0
  59. package/dist/cjs/manage/files.d.ts.map +1 -1
  60. package/dist/cjs/manage/files.js +10 -1
  61. package/dist/cjs/manage/files.js.map +1 -1
  62. package/dist/cjs/manage/index.d.ts +11 -10
  63. package/dist/cjs/manage/index.d.ts.map +1 -1
  64. package/dist/cjs/manage/index.js +15 -12
  65. package/dist/cjs/manage/index.js.map +1 -1
  66. package/dist/cjs/manage/lifecycle.d.ts +15 -38
  67. package/dist/cjs/manage/lifecycle.d.ts.map +1 -1
  68. package/dist/cjs/manage/lifecycle.js +21 -52
  69. package/dist/cjs/manage/lifecycle.js.map +1 -1
  70. package/dist/cjs/manage/mail.d.ts +12 -2
  71. package/dist/cjs/manage/mail.d.ts.map +1 -1
  72. package/dist/cjs/manage/mail.js +12 -1
  73. package/dist/cjs/manage/mail.js.map +1 -1
  74. package/dist/cjs/manage/observe.d.ts +6 -0
  75. package/dist/cjs/manage/observe.d.ts.map +1 -1
  76. package/dist/cjs/manage/observe.js +8 -2
  77. package/dist/cjs/manage/observe.js.map +1 -1
  78. package/dist/cjs/types.d.ts +3 -3
  79. package/dist/cjs/types.d.ts.map +1 -1
  80. package/dist/cjs/version.d.ts +1 -1
  81. package/dist/cjs/version.js +1 -1
  82. package/dist/esm/admin.d.ts +70 -0
  83. package/dist/esm/admin.d.ts.map +1 -1
  84. package/dist/esm/admin.js +72 -0
  85. package/dist/esm/admin.js.map +1 -1
  86. package/dist/esm/agents.d.ts +87 -0
  87. package/dist/esm/agents.d.ts.map +1 -0
  88. package/dist/esm/agents.js +148 -0
  89. package/dist/esm/agents.js.map +1 -0
  90. package/dist/esm/ai.d.ts +78 -0
  91. package/dist/esm/ai.d.ts.map +1 -0
  92. package/dist/esm/ai.js +123 -0
  93. package/dist/esm/ai.js.map +1 -0
  94. package/dist/esm/auth.d.ts +38 -0
  95. package/dist/esm/auth.d.ts.map +1 -1
  96. package/dist/esm/auth.js +52 -0
  97. package/dist/esm/auth.js.map +1 -1
  98. package/dist/esm/client.d.ts +18 -3
  99. package/dist/esm/client.d.ts.map +1 -1
  100. package/dist/esm/client.js +31 -4
  101. package/dist/esm/client.js.map +1 -1
  102. package/dist/esm/data.d.ts +28 -0
  103. package/dist/esm/data.d.ts.map +1 -1
  104. package/dist/esm/data.js +42 -7
  105. package/dist/esm/data.js.map +1 -1
  106. package/dist/esm/errors.d.ts +1 -1
  107. package/dist/esm/errors.d.ts.map +1 -1
  108. package/dist/esm/errors.js +8 -1
  109. package/dist/esm/errors.js.map +1 -1
  110. package/dist/esm/functions.d.ts +0 -28
  111. package/dist/esm/functions.d.ts.map +1 -1
  112. package/dist/esm/functions.js +0 -40
  113. package/dist/esm/functions.js.map +1 -1
  114. package/dist/esm/index.d.ts +6 -2
  115. package/dist/esm/index.d.ts.map +1 -1
  116. package/dist/esm/index.js +3 -1
  117. package/dist/esm/index.js.map +1 -1
  118. package/dist/esm/manage/access.d.ts +4 -62
  119. package/dist/esm/manage/access.d.ts.map +1 -1
  120. package/dist/esm/manage/access.js +3 -83
  121. package/dist/esm/manage/access.js.map +1 -1
  122. package/dist/esm/manage/agents.d.ts +76 -0
  123. package/dist/esm/manage/agents.d.ts.map +1 -0
  124. package/dist/esm/manage/agents.js +82 -0
  125. package/dist/esm/manage/agents.js.map +1 -0
  126. package/dist/esm/manage/ai.d.ts +90 -0
  127. package/dist/esm/manage/ai.d.ts.map +1 -0
  128. package/dist/esm/manage/ai.js +97 -0
  129. package/dist/esm/manage/ai.js.map +1 -0
  130. package/dist/esm/manage/base.d.ts +6 -16
  131. package/dist/esm/manage/base.d.ts.map +1 -1
  132. package/dist/esm/manage/base.js +11 -11
  133. package/dist/esm/manage/base.js.map +1 -1
  134. package/dist/esm/manage/data.d.ts +14 -16
  135. package/dist/esm/manage/data.d.ts.map +1 -1
  136. package/dist/esm/manage/data.js +14 -19
  137. package/dist/esm/manage/data.js.map +1 -1
  138. package/dist/esm/manage/files.d.ts +5 -0
  139. package/dist/esm/manage/files.d.ts.map +1 -1
  140. package/dist/esm/manage/files.js +10 -1
  141. package/dist/esm/manage/files.js.map +1 -1
  142. package/dist/esm/manage/index.d.ts +11 -10
  143. package/dist/esm/manage/index.d.ts.map +1 -1
  144. package/dist/esm/manage/index.js +18 -15
  145. package/dist/esm/manage/index.js.map +1 -1
  146. package/dist/esm/manage/lifecycle.d.ts +15 -38
  147. package/dist/esm/manage/lifecycle.d.ts.map +1 -1
  148. package/dist/esm/manage/lifecycle.js +19 -50
  149. package/dist/esm/manage/lifecycle.js.map +1 -1
  150. package/dist/esm/manage/mail.d.ts +12 -2
  151. package/dist/esm/manage/mail.d.ts.map +1 -1
  152. package/dist/esm/manage/mail.js +13 -2
  153. package/dist/esm/manage/mail.js.map +1 -1
  154. package/dist/esm/manage/observe.d.ts +6 -0
  155. package/dist/esm/manage/observe.d.ts.map +1 -1
  156. package/dist/esm/manage/observe.js +8 -2
  157. package/dist/esm/manage/observe.js.map +1 -1
  158. package/dist/esm/types.d.ts +3 -3
  159. package/dist/esm/types.d.ts.map +1 -1
  160. package/dist/esm/version.d.ts +1 -1
  161. package/dist/esm/version.js +1 -1
  162. package/package.json +2 -2
  163. package/src/admin.ts +104 -0
  164. package/src/agents.ts +184 -0
  165. package/src/ai.ts +164 -0
  166. package/src/auth.ts +70 -0
  167. package/src/client.ts +31 -4
  168. package/src/data.ts +52 -5
  169. package/src/errors.ts +6 -1
  170. package/src/functions.ts +0 -49
  171. package/src/index.ts +6 -1
  172. package/src/manage/access.ts +3 -96
  173. package/src/manage/agents.ts +98 -0
  174. package/src/manage/ai.ts +129 -0
  175. package/src/manage/base.ts +11 -11
  176. package/src/manage/data.ts +15 -20
  177. package/src/manage/files.ts +12 -1
  178. package/src/manage/index.ts +18 -15
  179. package/src/manage/lifecycle.ts +20 -64
  180. package/src/manage/mail.ts +16 -2
  181. package/src/manage/observe.ts +9 -2
  182. package/src/types.ts +3 -3
  183. package/src/version.ts +1 -1
  184. package/dist/cjs/manage/functions.d.ts +0 -48
  185. package/dist/cjs/manage/functions.d.ts.map +0 -1
  186. package/dist/cjs/manage/functions.js +0 -61
  187. package/dist/cjs/manage/functions.js.map +0 -1
  188. package/dist/esm/manage/functions.d.ts +0 -48
  189. package/dist/esm/manage/functions.d.ts.map +0 -1
  190. package/dist/esm/manage/functions.js +0 -57
  191. package/dist/esm/manage/functions.js.map +0 -1
  192. package/src/manage/functions.ts +0 -69
package/src/functions.ts CHANGED
@@ -24,55 +24,6 @@ function pass(options: CallOptions): {
24
24
  };
25
25
  }
26
26
 
27
- export interface FetchOptions extends CallOptions {
28
- method?: string;
29
- query?: Record<string, QueryValue | QueryValue[]>;
30
- /** An object is sent as JSON; strings, `Blob`, `FormData`, buffers and streams as they are. */
31
- body?: unknown;
32
- /** Run the function deployed on this branch (`x-pawabase-branch`). */
33
- branch?: string;
34
- }
35
-
36
- /** Functions you wrote in your project's code, invoked at `/functions/v1/<name>`. */
37
- export class FunctionsClient {
38
- constructor(private readonly http: HttpClient) {}
39
-
40
- /**
41
- * Call a function and return what it returned. The API key needs the
42
- * `functions:invoke` scope (an unrestricted key has it).
43
- */
44
- async invoke<T = unknown>(name: string, input?: unknown, options: CallOptions = {}): Promise<T> {
45
- const body = await this.http.request<{ data: T } | undefined>({
46
- method: "POST",
47
- path: `/functions/v1/${encodePath(name)}`,
48
- body: input === undefined ? undefined : input,
49
- ...pass(options),
50
- });
51
- return (body as { data: T } | undefined)?.data as T;
52
- }
53
-
54
- /**
55
- * Call an HTTP function (`functions/<name>/index.ts`) with any method and path, and get its `Response` as it is — status, headers
56
- * and a streaming body. An error status is returned, not thrown; the API key and the signed-in user's token are sent as for any call.
57
- *
58
- * ```ts
59
- * const res = await pawabase.functions.fetch("orders", "/42/items", { method: "POST", body: { sku: "A1" } });
60
- * if (res.ok) console.log(await res.json());
61
- * ```
62
- */
63
- fetch(name: string, path = "/", options: FetchOptions = {}): Promise<Response> {
64
- const rest = path === "/" || path === "" ? "" : path.startsWith("/") ? path : `/${path}`;
65
- return this.http.send({
66
- method: options.method ?? (options.body === undefined ? "GET" : "POST"),
67
- path: `/functions/v1/${encodePath(name)}${rest}`,
68
- ...(options.query ? { query: options.query } : {}),
69
- ...(options.body !== undefined ? { body: options.body } : {}),
70
- ...pass({ ...options, headers: { ...(options.branch ? { "x-pawabase-branch": options.branch } : {}), ...options.headers } }),
71
- throwOnError: false,
72
- });
73
- }
74
- }
75
-
76
27
  /**
77
28
  * Flows with an HTTP trigger that has no path, invoked at `/flows/v1/<name>`.
78
29
  * (Flows bound to a path are reached as routes, see {@link RoutesClient}.)
package/src/index.ts CHANGED
@@ -1,12 +1,17 @@
1
1
  export { PawabaseClient, createClient } from "./client.js";
2
2
  export type { ClientOptions, DatabaseShape } from "./client.js";
3
3
 
4
+ export { AiClient } from "./ai.js";
5
+ export { AgentsClient, KnowledgeClient } from "./agents.js";
6
+ export type { AgentEvent, AgentRun, AgentRunOptions, AgentRunStatus, KnowledgeDocument, KnowledgeHit } from "./agents.js";
7
+ export type { AiModelInfo, ChatCompletion, ChatMessage, ChatOptions } from "./ai.js";
4
8
  export { AuthClient } from "./auth.js";
5
9
  export type {
6
10
  AuthChangeEvent,
7
11
  AuthListener,
8
12
  AuthOptions,
9
13
  IssuedToken,
14
+ MachineToken,
10
15
  Passkey,
11
16
  PasskeyChallenge,
12
17
  SignInResult,
@@ -29,7 +34,7 @@ export type {
29
34
  ResourceTypes,
30
35
  } from "./data.js";
31
36
 
32
- export { FlowsClient, FunctionsClient, RoutesClient } from "./functions.js";
37
+ export { FlowsClient, RoutesClient } from "./functions.js";
33
38
  export type { CallOptions, RouteOptions } from "./functions.js";
34
39
 
35
40
  export { BucketClient, StorageClient } from "./files.js";
@@ -15,8 +15,8 @@ export class Keys extends Service {
15
15
  }
16
16
 
17
17
  /**
18
- * Make a key; the key itself is in the answer once. `scopes` limit what it may do (`resource:read`, `functions:invoke`…),
19
- * `allowedIps` and `allowedRoutes` (`"GET /rest/v1/orders"`, `"/functions/v1/*"`) limit where and what it may call.
18
+ * Make a key; the key itself is in the answer once. `scopes` limit what it may do (`resource:read`, `routes:invoke`…),
19
+ * `allowedIps` and `allowedRoutes` (`"GET /rest/v1/orders"`, `"/flows/v1/*"`) limit where and what it may call.
20
20
  */
21
21
  create(name: string, options: { role?: "publishable" | "secret"; scopes?: string[]; expiresAt?: When; allowedIps?: string[]; allowedRoutes?: string[] } = {}): Promise<Api> {
22
22
  return this.post("/keys", {
@@ -39,7 +39,7 @@ export class Keys extends Service {
39
39
  }
40
40
  }
41
41
 
42
- /** Secrets functions and flows read (`ctx.runtime.secret(name)`). Values are never returned. */
42
+ /** Secrets flows read (`ctx.runtime.secret(name)`). Values are never returned. */
43
43
  export class Secrets extends Service {
44
44
  list(): Promise<Api> {
45
45
  return this.get("/secrets");
@@ -111,96 +111,3 @@ export interface FirewallRule {
111
111
  expiresAt?: When;
112
112
  note?: string;
113
113
  }
114
-
115
- /**
116
- * The firewall at the gateway: ordered rules (allow, block, log, rate limit), managed attack signatures, bans, and what it did.
117
- *
118
- * ```ts
119
- * await m.firewall.addRule({ name: "Burst", action: "rate_limit",
120
- * conditions: [{ field: "path", op: "starts_with", value: "/auth/v1/token" }],
121
- * rateLimit: { requests: 10, window_seconds: 60, by: "ip", ban_seconds: 900 } });
122
- * ```
123
- */
124
- export class Firewall extends Service {
125
- /** Rules in the order they are tried. */
126
- rules(): Promise<Api> {
127
- return this.get("/firewall");
128
- }
129
-
130
- /** Add a rule at the end. */
131
- addRule(rule: FirewallRule): Promise<Api> {
132
- return this.post("/firewall", {
133
- name: rule.name,
134
- action: rule.action ?? "block",
135
- conditions: rule.conditions ?? [],
136
- logic: rule.logic ?? "all",
137
- match: rule.match ?? {},
138
- rate_limit: rule.rateLimit,
139
- mode: rule.mode ?? "enforce",
140
- enabled: rule.enabled ?? true,
141
- expires_at: iso(rule.expiresAt),
142
- note: rule.note ?? "",
143
- });
144
- }
145
-
146
- /** Change some fields of a rule, using the server's field names (`clear_expiry: true` removes an expiry). */
147
- updateRule(ruleId: string, changes: Body): Promise<Api> {
148
- return this.patch(seg("firewall", ruleId), changes);
149
- }
150
-
151
- removeRule(ruleId: string): Promise<Api> {
152
- return this.del(seg("firewall", ruleId));
153
- }
154
-
155
- /** Set the order rules are tried in: every rule exactly once. */
156
- order(ruleIds: string[]): Promise<Api> {
157
- return this.put("/firewall-order", { ids: ruleIds });
158
- }
159
-
160
- /** Managed rule sets (`sqli`, `xss`, `traversal`, `scanners`, `sensitive_files`, `no_user_agent`, `methods`) and automatic bans. */
161
- config(): Promise<Api> {
162
- return this.get("/firewall-config");
163
- }
164
-
165
- /** `managed`: `{ sqli: "block", scanners: "log" }` (`off`, `log`, `block`). `autoBan`: `{ enabled, threshold, window_seconds, ban_seconds, statuses, exempt }`. */
166
- setConfig(options: { managed?: Record<string, string>; autoBan?: Body }): Promise<Api> {
167
- return this.put("/firewall-config", { managed: options.managed, auto_ban: options.autoBan });
168
- }
169
-
170
- bans(options: { includeExpired?: boolean } = {}): Promise<Api> {
171
- return this.get("/firewall-bans", { all: options.includeExpired ? 1 : undefined });
172
- }
173
-
174
- /** Ban an address or CIDR range for `seconds` (`0`: until lifted). */
175
- ban(ip: string, options: { seconds?: number; reason?: string } = {}): Promise<Api> {
176
- return this.post("/firewall-bans", { ip, seconds: options.seconds ?? 0, reason: options.reason ?? "" });
177
- }
178
-
179
- liftBan(banId: string): Promise<Api> {
180
- return this.del(seg("firewall-bans", banId));
181
- }
182
-
183
- events(options: { action?: string; source?: string; ip?: string; path?: string; ruleId?: string; limit?: number } = {}): Promise<Api> {
184
- const { ruleId, ...rest } = options;
185
- return this.get("/firewall-events", { limit: 100, ...rest, rule_id: ruleId });
186
- }
187
-
188
- /** Totals, a timeline, and the top addresses, paths, rules and countries. */
189
- stats(options: { hours?: number } = {}): Promise<Api> {
190
- return this.get("/firewall-stats", { hours: options.hours ?? 24 });
191
- }
192
-
193
- /** What the firewall would do with a request, step by step. Nothing is sent or counted. */
194
- test(ip: string, options: { path?: string; method?: string; userAgent?: string; query?: string; headers?: Record<string, string>; country?: string; role?: string } = {}): Promise<Api> {
195
- return this.post("/firewall-test", {
196
- ip,
197
- path: options.path ?? "/",
198
- method: options.method ?? "GET",
199
- user_agent: options.userAgent ?? "",
200
- query: options.query ?? "",
201
- headers: options.headers ?? {},
202
- country: options.country ?? "",
203
- role: options.role ?? "none",
204
- });
205
- }
206
- }
@@ -0,0 +1,98 @@
1
+ import { Definitions, Service, seg, type Api, type Body, type Query } from "./base.js";
2
+
3
+ /**
4
+ * Agents: a model with instructions, tools and knowledge, run on the server with approvals, limits and threads.
5
+ *
6
+ * ```ts
7
+ * await m.agents.create({ name: "support", model: "chat", instructions: "Answer from the docs.", knowledge: ["docs"] });
8
+ * const run = await m.agents.run("support", "How do I reset a password?");
9
+ * ```
10
+ */
11
+ export class Agents extends Definitions {
12
+ protected override readonly kind = "agents";
13
+
14
+ /** Run an agent as the studio would. `thread` carries a conversation on; `background` returns before it finishes. */
15
+ run(name: string, input: string, options: { thread?: string; background?: boolean } = {}): Promise<Api> {
16
+ return this.post(seg(this.kind, name, "runs"), { input, thread: options.thread, background: options.background ?? false });
17
+ }
18
+ }
19
+
20
+ /** Agent runs: what each did, step by step, and the ones waiting for someone to approve a tool call. */
21
+ export class AgentRuns extends Service {
22
+ /** Newest first. Filter by `agent`, `status` or `thread`. */
23
+ list(options: { agent?: string; status?: string; thread?: string; limit?: number; offset?: number } = {}): Promise<Api> {
24
+ return this.get("/agent-runs", options as Query);
25
+ }
26
+
27
+ getOne(runId: string): Promise<Api> {
28
+ return this.get(seg("agent-runs", runId));
29
+ }
30
+
31
+ /** Approve or decline what a run is waiting on: a decision per call id, and `approve` for any not named. */
32
+ decide(runId: string, options: { decisions?: Record<string, boolean>; approve?: boolean; background?: boolean } = {}): Promise<Api> {
33
+ return this.post(seg("agent-runs", runId, "decide"), { decisions: options.decisions ?? {}, approve: options.approve, background: options.background ?? false });
34
+ }
35
+
36
+ remove(runId: string): Promise<Api> {
37
+ return this.del(seg("agent-runs", runId));
38
+ }
39
+
40
+ /** The tools an agent can be given, by kind. */
41
+ tools(): Promise<Api> {
42
+ return this.get("/agent-tools");
43
+ }
44
+ }
45
+
46
+ /** Knowledge bases: documents split and embedded so agents can search them by meaning and by words. */
47
+ export class KnowledgeBases extends Definitions {
48
+ protected override readonly kind = "knowledge-bases";
49
+
50
+ documents(name: string, options: { limit?: number; offset?: number } = {}): Promise<Api> {
51
+ return this.get(seg(this.kind, name, "documents"), options);
52
+ }
53
+
54
+ /** Add text, or a web page to read (`url`). Adding the same `source` again replaces it. */
55
+ addDocument(name: string, input: { text?: string; url?: string; title?: string; source?: string }): Promise<Api> {
56
+ return this.post(seg(this.kind, name, "documents"), { title: input.title ?? "", source: input.source ?? "", text: input.text, url: input.url });
57
+ }
58
+
59
+ /** Add a file (PDF, Word, HTML or text). */
60
+ addFile(name: string, file: Blob, options: { title?: string; source?: string; filename?: string } = {}): Promise<Api> {
61
+ const form = new FormData();
62
+ form.append("file", file, options.filename ?? (file as File).name ?? "document");
63
+ if (options.title) form.append("title", options.title);
64
+ if (options.source) form.append("source", options.source);
65
+ return this.post(seg(this.kind, name, "documents"), form);
66
+ }
67
+
68
+ removeDocument(name: string, documentId: string): Promise<Api> {
69
+ return this.del(seg(this.kind, name, "documents", documentId));
70
+ }
71
+
72
+ /** Split and embed a document again, for one that failed or after changing the base's chunk size. */
73
+ reindexDocument(name: string, documentId: string): Promise<Api> {
74
+ return this.post(seg(this.kind, name, "documents", documentId, "reindex"));
75
+ }
76
+
77
+ /** What an agent would find. */
78
+ search(name: string, query: string, options: { limit?: number } = {}): Promise<Api> {
79
+ return this.post(seg(this.kind, name, "search"), { query, limit: options.limit ?? 5 });
80
+ }
81
+
82
+ /** Bring in pages from a Notion connection; pages unchanged since last time are skipped. */
83
+ sync(name: string, connection: string): Promise<Api> {
84
+ return this.post(seg(this.kind, name, "sync"), { connection });
85
+ }
86
+ }
87
+
88
+ /** Connections: stored access to outside services (MCP servers, Notion, web search) that agents use as tools. The secret is sealed on arrival. */
89
+ export class Connections extends Definitions {
90
+ protected override readonly kind = "connections";
91
+
92
+ /** Call the service with the stored key and say what was found, or why it could not be reached. */
93
+ test(name: string): Promise<Api> {
94
+ return this.post(seg(this.kind, name, "test"));
95
+ }
96
+ }
97
+
98
+ export type { Body };
@@ -0,0 +1,129 @@
1
+ import { Service, seg, type Api, type Body } from "./base.js";
2
+
3
+ /**
4
+ * The AI gateway of the environment: connect providers (OpenAI, Anthropic, Gemini, Mistral, Groq, or any OpenAI-compatible server), expose
5
+ * models by name, try them, and read what they cost. Provider keys are sealed on arrival and never returned.
6
+ */
7
+ export class Ai extends Service {
8
+ protected override path(suffix = ""): string {
9
+ return super.path(`/ai${suffix}`);
10
+ }
11
+
12
+ /** The kinds of provider that can be connected, with suggested models. */
13
+ catalog(): Promise<Api> {
14
+ return this.get("/catalog");
15
+ }
16
+
17
+ providers(): Promise<Api> {
18
+ return this.get("/providers");
19
+ }
20
+
21
+ /** The models a connected provider offers this key, asked live: `{ data: [{ id, kind, label }], source: "provider" | "catalog", error }`. */
22
+ providerModels(name: string): Promise<Api> {
23
+ return this.get(seg("providers", name, "models"));
24
+ }
25
+
26
+ /** Connect a provider. `kind` is `openai`, `anthropic`, `gemini`, `mistral`, `groq` or `openai_compatible` (which needs `baseUrl`). */
27
+ connect(input: { name: string; kind: string; key?: string; baseUrl?: string }): Promise<Api> {
28
+ return this.post("/providers", { name: input.name, kind: input.kind, key: input.key ?? "", base_url: input.baseUrl ?? "" });
29
+ }
30
+
31
+ updateProvider(name: string, input: { key?: string; baseUrl?: string; enabled?: boolean }): Promise<Api> {
32
+ return this.patch(seg("providers", name), { key: input.key, base_url: input.baseUrl, enabled: input.enabled });
33
+ }
34
+
35
+ /** Disconnect a provider and every model on it. */
36
+ disconnect(name: string): Promise<Api> {
37
+ return this.del(seg("providers", name));
38
+ }
39
+
40
+ models(): Promise<Api> {
41
+ return this.get("/models");
42
+ }
43
+
44
+ /**
45
+ * Expose a model under `alias`. `policy` is who may call it: `service` (servers only, the default), `authenticated`, `public`, or a
46
+ * named policy. `params` are defaults such as `system` and `temperature`; prices are USD per million tokens.
47
+ */
48
+ addModel(input: {
49
+ alias: string;
50
+ provider: string;
51
+ upstream: string;
52
+ kind?: "chat" | "embedding";
53
+ description?: string;
54
+ policy?: unknown;
55
+ params?: Body;
56
+ dimensions?: number;
57
+ inputPrice?: number;
58
+ outputPrice?: number;
59
+ fallback?: string;
60
+ enabled?: boolean;
61
+ }): Promise<Api> {
62
+ return this.post("/models", {
63
+ alias: input.alias,
64
+ provider: input.provider,
65
+ upstream: input.upstream,
66
+ kind: input.kind ?? "chat",
67
+ description: input.description ?? "",
68
+ policy: input.policy ?? "service",
69
+ params: input.params ?? {},
70
+ dimensions: input.dimensions,
71
+ input_price: input.inputPrice,
72
+ output_price: input.outputPrice,
73
+ fallback: input.fallback,
74
+ enabled: input.enabled ?? true,
75
+ });
76
+ }
77
+
78
+ updateModel(
79
+ alias: string,
80
+ input: { provider?: string; upstream?: string; description?: string; policy?: unknown; params?: Body; dimensions?: number | null; inputPrice?: number | null; outputPrice?: number | null; fallback?: string | null; enabled?: boolean },
81
+ ): Promise<Api> {
82
+ return this.patch(seg("models", alias), {
83
+ provider: input.provider,
84
+ upstream: input.upstream,
85
+ description: input.description,
86
+ policy: input.policy,
87
+ params: input.params,
88
+ dimensions: input.dimensions,
89
+ input_price: input.inputPrice,
90
+ output_price: input.outputPrice,
91
+ fallback: input.fallback,
92
+ enabled: input.enabled,
93
+ });
94
+ }
95
+
96
+ removeModel(alias: string): Promise<Api> {
97
+ return this.del(seg("models", alias));
98
+ }
99
+
100
+ /** Send one request to a model, the way Studio's playground does. Returns `{ text, usage, ms }`, or `{ error }`. */
101
+ tryModel(alias: string, input: { messages?: Body[]; input?: string[]; maxTokens?: number } = {}): Promise<Api> {
102
+ return this.post(seg("models", alias, "try"), { messages: input.messages, input: input.input, max_tokens: input.maxTokens });
103
+ }
104
+
105
+ /** Calls, tokens, cost and latency over `days` (1 to 90), in all and per model. */
106
+ usage(options: { days?: number } = {}): Promise<Api> {
107
+ return this.get("/usage", { days: options.days ?? 7 });
108
+ }
109
+
110
+ /** Recent calls. Never includes what was asked or answered. */
111
+ requests(options: { alias?: string; failed?: boolean; limit?: number } = {}): Promise<Api> {
112
+ return this.get("/requests", { alias: options.alias, failed: options.failed ? "true" : undefined, limit: options.limit ?? 50 });
113
+ }
114
+
115
+ /** Vector fields in the environment, and how many records have no vector yet. */
116
+ vectors(): Promise<Api> {
117
+ return this.get("/vectors");
118
+ }
119
+
120
+ /** Embed up to `limit` records of a resource that have no vector. Call again while `embedded` is above zero. */
121
+ backfill(resource: string, options: { limit?: number } = {}): Promise<Api> {
122
+ return this.post(seg("backfill", resource), undefined, { limit: options.limit ?? 100 });
123
+ }
124
+
125
+ /** Search a resource by meaning, as the Studio does: with `text` or a `vector`. */
126
+ search(resource: string, input: { text?: string; vector?: number[]; field?: string; metric?: "cosine" | "l2" | "ip"; limit?: number }): Promise<Api> {
127
+ return this.post(seg("search", resource), { text: input.text, vector: input.vector, field: input.field, metric: input.metric ?? "cosine", limit: input.limit ?? 10 });
128
+ }
129
+ }
@@ -55,29 +55,29 @@ export class Service {
55
55
 
56
56
  /**
57
57
  * A kind of definition an environment holds (`flows`, `policies`, `webhooks`…): list, get, create, replace, remove.
58
- * Pass `branch` to work on a feature branch's draft instead of the live environment. A definition is addressed by its name
58
+ * A definition is addressed by its name
59
59
  * (inbound hooks: their slug).
60
60
  */
61
61
  export class Definitions extends Service {
62
62
  protected readonly kind: string = "";
63
63
 
64
- list(options: { branch?: string } = {}): Promise<Api> {
65
- return this.get(seg(this.kind), { branch: options.branch });
64
+ list(): Promise<Api> {
65
+ return this.get(seg(this.kind));
66
66
  }
67
67
 
68
- getOne(key: string, options: { branch?: string } = {}): Promise<Api> {
69
- return this.get(seg(this.kind, key), { branch: options.branch });
68
+ getOne(key: string): Promise<Api> {
69
+ return this.get(seg(this.kind, key));
70
70
  }
71
71
 
72
- create(body: Body, options: { branch?: string } = {}): Promise<Api> {
73
- return this.post(seg(this.kind), body, { branch: options.branch });
72
+ create(body: Body): Promise<Api> {
73
+ return this.post(seg(this.kind), body);
74
74
  }
75
75
 
76
- replace(key: string, body: Body, options: { branch?: string } = {}): Promise<Api> {
77
- return this.put(seg(this.kind, key), body, { branch: options.branch });
76
+ replace(key: string, body: Body): Promise<Api> {
77
+ return this.put(seg(this.kind, key), body);
78
78
  }
79
79
 
80
- remove(key: string, options: { branch?: string } = {}): Promise<Api> {
81
- return this.del(seg(this.kind, key), { branch: options.branch });
80
+ remove(key: string): Promise<Api> {
81
+ return this.del(seg(this.kind, key));
82
82
  }
83
83
  }
@@ -100,7 +100,7 @@ export class Schema extends Service {
100
100
  }
101
101
  }
102
102
 
103
- /** Named access policies (conditions) that resources, buckets, channels and functions refer to. */
103
+ /** Named access policies (conditions) that resources, buckets and channels refer to. */
104
104
  export class Policies extends Definitions {
105
105
  protected override readonly kind = "policies";
106
106
  }
@@ -110,11 +110,6 @@ export class Schemas extends Definitions {
110
110
  protected override readonly kind = "schemas";
111
111
  }
112
112
 
113
- /** Transformers that reshape a field's value on the way out (hide, mask, format). */
114
- export class Transformers extends Definitions {
115
- protected override readonly kind = "transformers";
116
- }
117
-
118
113
  /** Custom HTTP routes under `/rest` that run a flow. */
119
114
  export class Routes extends Definitions {
120
115
  protected override readonly kind = "routes";
@@ -135,25 +130,25 @@ export class Database extends Service {
135
130
  return this.get(seg("database", "tables", table, "rows"), { limit: options.limit, offset: options.offset, sort: options.sort, ...options.filters });
136
131
  }
137
132
 
138
- /** Run one statement. A write needs `allowWrite`; it is audited and clears the environment's caches. */
139
- query(sql: string, params: unknown[] = [], options: { allowWrite?: boolean } = {}): Promise<Api> {
140
- return this.post("/database/query", { sql, params, allow_write: options.allowWrite ?? false });
133
+ /** Saved queries: the SQL console's bookmarks. */
134
+ savedQueries(): Promise<Api> {
135
+ return this.get("/database/queries");
141
136
  }
142
- }
143
137
 
144
- /** The runtime capabilities a function sees, called remotely (what `pawabase emulate` uses). */
145
- export class Runtime extends Service {
146
- call(method: string, args: unknown[] = [], kwargs: Body = {}, options: { asUser?: Body; branch?: string } = {}): Promise<Api> {
147
- return this.post("/runtime/call", { method, args, kwargs, as_user: options.asUser ?? null, branch: options.branch ?? null });
138
+ saveQuery(input: { name: string; sql: string; description?: string }): Promise<Api> {
139
+ return this.post("/database/queries", { name: input.name, sql: input.sql, description: input.description ?? "" });
148
140
  }
149
141
 
150
- /** `fetch`, `insert`, `execute`, `begin`, `commit`…, optionally inside a transaction (`tx`). */
151
- sql(op: string, fields: Body = {}): Promise<Api> {
152
- return this.post("/runtime/db", { op, ...fields });
142
+ updateQuery(queryId: string, input: { name: string; sql: string; description?: string }): Promise<Api> {
143
+ return this.put(seg("database", "queries", queryId), { name: input.name, sql: input.sql, description: input.description ?? "" });
153
144
  }
154
145
 
155
- /** Who a user access token belongs to. */
156
- identify(token: string | null): Promise<Api> {
157
- return this.post("/runtime/identify", { token });
146
+ deleteQuery(queryId: string): Promise<Api> {
147
+ return this.del(seg("database", "queries", queryId));
148
+ }
149
+
150
+ /** Run one statement. A write needs `allowWrite`; it is audited and clears the environment's caches. */
151
+ query(sql: string, params: unknown[] = [], options: { allowWrite?: boolean } = {}): Promise<Api> {
152
+ return this.post("/database/query", { sql, params, allow_write: options.allowWrite ?? false });
158
153
  }
159
154
  }
@@ -64,12 +64,23 @@ export class Buckets extends Definitions {
64
64
  revokeShare(bucket: string, shareId: string): Promise<Api> {
65
65
  return this.del(seg(this.kind, bucket, "shares", shareId));
66
66
  }
67
+
68
+ /** Make an empty folder (`prefix` like `reports/2026`). */
69
+ createFolder(bucket: string, prefix: string): Promise<Api> {
70
+ return this.post(seg(this.kind, bucket, "folders"), { prefix });
71
+ }
72
+
73
+ /** Remove a folder; it must be empty. */
74
+ deleteFolder(bucket: string, prefix: string): Promise<Api> {
75
+ return this.del(`${seg(this.kind, bucket, "folders")}/${prefix.split("/").filter(Boolean).map(encodeURIComponent).join("/")}`);
76
+ }
67
77
  }
68
78
 
69
79
  /** The environment's response cache. */
70
80
  export class Cache extends Service {
81
+ /** The project's cache statistics (not scoped to one environment). */
71
82
  stats(): Promise<Api> {
72
- return this.get("/cache");
83
+ return this.project("GET", "/cache");
73
84
  }
74
85
 
75
86
  /** Drop cached responses by tag (`resource:posts`) or for whole resources. */
@@ -14,12 +14,13 @@
14
14
  import type { PawabaseClient } from "../client.js";
15
15
  import { ConfigError } from "../errors.js";
16
16
  import { isSecretKey } from "../util.js";
17
- import { Domains, Firewall, Keys, Secrets } from "./access.js";
17
+ import { Domains, Keys, Secrets } from "./access.js";
18
+ import { AgentRuns, Agents, Connections, KnowledgeBases } from "./agents.js";
19
+ import { Ai } from "./ai.js";
18
20
  import { Events, Flows, InboundHooks, Jobs, Schedules, Subscriptions, Webhooks } from "./automation.js";
19
- import { Database, Policies, Resources, Routes, Runtime, Schema, Schemas, Transformers } from "./data.js";
21
+ import { Database, Policies, Resources, Routes, Schema, Schemas } from "./data.js";
20
22
  import { Buckets, Cache } from "./files.js";
21
- import { Functions } from "./functions.js";
22
- import { Backups, Environments, Releases } from "./lifecycle.js";
23
+ import { Backups, Environments, Versions } from "./lifecycle.js";
23
24
  import { Mail, MailTemplates } from "./mail.js";
24
25
  import { Alarms, Health, Observability, StatusPage } from "./observe.js";
25
26
  import { Dashboards, RealtimeChannels } from "./realtime.js";
@@ -30,10 +31,8 @@ export class Manage {
30
31
  readonly schema: Schema;
31
32
  readonly policies: Policies;
32
33
  readonly schemas: Schemas;
33
- readonly transformers: Transformers;
34
34
  readonly routes: Routes;
35
35
  readonly database: Database;
36
- readonly runtime: Runtime;
37
36
  // automation
38
37
  readonly flows: Flows;
39
38
  readonly schedules: Schedules;
@@ -42,7 +41,6 @@ export class Manage {
42
41
  readonly webhooks: Webhooks;
43
42
  readonly inboundHooks: InboundHooks;
44
43
  readonly jobs: Jobs;
45
- readonly functions: Functions;
46
44
  // files and mail
47
45
  readonly buckets: Buckets;
48
46
  readonly cache: Cache;
@@ -55,15 +53,20 @@ export class Manage {
55
53
  readonly keys: Keys;
56
54
  readonly secrets: Secrets;
57
55
  readonly domains: Domains;
58
- readonly firewall: Firewall;
59
56
  // observe
60
57
  readonly observability: Observability;
61
58
  readonly alarms: Alarms;
62
59
  readonly statusPage: StatusPage;
63
60
  readonly health: Health;
61
+ // ai
62
+ readonly ai: Ai;
63
+ readonly agents: Agents;
64
+ readonly agentRuns: AgentRuns;
65
+ readonly knowledgeBases: KnowledgeBases;
66
+ readonly connections: Connections;
64
67
  // lifecycle
65
68
  readonly environments: Environments;
66
- readonly releases: Releases;
69
+ readonly versions: Versions;
67
70
  readonly backups: Backups;
68
71
 
69
72
  constructor(
@@ -75,10 +78,8 @@ export class Manage {
75
78
  this.schema = new Schema(http, environment);
76
79
  this.policies = new Policies(http, environment);
77
80
  this.schemas = new Schemas(http, environment);
78
- this.transformers = new Transformers(http, environment);
79
81
  this.routes = new Routes(http, environment);
80
82
  this.database = new Database(http, environment);
81
- this.runtime = new Runtime(http, environment);
82
83
  this.flows = new Flows(http, environment);
83
84
  this.schedules = new Schedules(http, environment);
84
85
  this.subscriptions = new Subscriptions(http, environment);
@@ -86,7 +87,6 @@ export class Manage {
86
87
  this.webhooks = new Webhooks(http, environment);
87
88
  this.inboundHooks = new InboundHooks(http, environment);
88
89
  this.jobs = new Jobs(http, environment);
89
- this.functions = new Functions(http, environment);
90
90
  this.buckets = new Buckets(http, environment);
91
91
  this.cache = new Cache(http, environment);
92
92
  this.mail = new Mail(http, environment);
@@ -96,13 +96,17 @@ export class Manage {
96
96
  this.keys = new Keys(http, environment);
97
97
  this.secrets = new Secrets(http, environment);
98
98
  this.domains = new Domains(http, environment);
99
- this.firewall = new Firewall(http, environment);
100
99
  this.observability = new Observability(http, environment);
101
100
  this.alarms = new Alarms(http, environment);
102
101
  this.statusPage = new StatusPage(http, environment);
103
102
  this.health = new Health(http, environment);
103
+ this.ai = new Ai(http, environment);
104
+ this.agents = new Agents(http, environment);
105
+ this.agentRuns = new AgentRuns(http, environment);
106
+ this.knowledgeBases = new KnowledgeBases(http, environment);
107
+ this.connections = new Connections(http, environment);
104
108
  this.environments = new Environments(http, environment);
105
- this.releases = new Releases(http, environment);
109
+ this.versions = new Versions(http, environment);
106
110
  this.backups = new Backups(http, environment);
107
111
  }
108
112
 
@@ -125,7 +129,6 @@ export * from "./automation.js";
125
129
  export * from "./base.js";
126
130
  export * from "./data.js";
127
131
  export * from "./files.js";
128
- export * from "./functions.js";
129
132
  export * from "./lifecycle.js";
130
133
  export * from "./mail.js";
131
134
  export * from "./observe.js";