@onyx.dev/onyx-database 1.2.0 → 2.0.1
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 +78 -51
- package/dist/{aggregates-LoteczVS.d.cts → aggregates-BPpzRHGH.d.cts} +129 -2
- package/dist/{aggregates-LoteczVS.d.ts → aggregates-BPpzRHGH.d.ts} +129 -2
- package/dist/edge.cjs +118 -64
- package/dist/edge.cjs.map +1 -1
- package/dist/edge.d.cts +3 -6
- package/dist/edge.d.ts +3 -6
- package/dist/edge.js +116 -63
- package/dist/edge.js.map +1 -1
- package/dist/gen/cli/generate.cjs +78 -25
- package/dist/gen/cli/generate.cjs.map +1 -1
- package/dist/index.cjs +119 -64
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -6
- package/dist/index.d.ts +3 -6
- package/dist/index.js +117 -63
- package/dist/index.js.map +1 -1
- package/dist/schema/cli/schema.cjs +79 -25
- package/dist/schema/cli/schema.cjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -63,20 +63,16 @@ npm i @onyx.dev/onyx-database
|
|
|
63
63
|
|
|
64
64
|
The package is dual-module (ESM + CJS) and has **no runtime or peer dependencies**.
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
CLI tooling and schema codegen now live in the dedicated **Onyx CLI** repo:
|
|
67
|
+
<https://github.com/OnyxDevTools/onyx-cli>. Install it via the official install
|
|
68
|
+
script or Homebrew (macOS):
|
|
67
69
|
|
|
68
70
|
```bash
|
|
69
|
-
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
To install the CLI globally from this repo checkout (useful for local development and testing):
|
|
71
|
+
curl -fsSL https://raw.githubusercontent.com/OnyxDevTools/onyx-cli/main/scripts/install.sh | bash
|
|
73
72
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
npm run build
|
|
78
|
-
npm uninstall -g @onyx.dev/onyx-database # optional: clear older global versions
|
|
79
|
-
npm install -g . # installs the built onyx-schema and onyx-gen
|
|
73
|
+
# macOS (Homebrew)
|
|
74
|
+
brew tap OnyxDevTools/onyx-cli
|
|
75
|
+
brew install onyx-cli
|
|
80
76
|
```
|
|
81
77
|
|
|
82
78
|
---
|
|
@@ -94,6 +90,7 @@ Set the following environment variables for your database:
|
|
|
94
90
|
- `ONYX_DATABASE_API_KEY`
|
|
95
91
|
- `ONYX_DATABASE_API_SECRET`
|
|
96
92
|
- `ONYX_AI_BASE_URL` (optional; defaults to `https://ai.onyx.dev`)
|
|
93
|
+
- `ONYX_DEFAULT_MODEL` (optional; used by `db.chat('...')`, defaults to `onyx`)
|
|
97
94
|
|
|
98
95
|
```ts
|
|
99
96
|
import { onyx } from '@onyx.dev/onyx-database';
|
|
@@ -110,6 +107,7 @@ import { onyx } from '@onyx.dev/onyx-database';
|
|
|
110
107
|
const db = onyx.init({
|
|
111
108
|
baseUrl: 'https://api.onyx.dev',
|
|
112
109
|
aiBaseUrl: 'https://ai.onyx.dev', // optional: override AI base path
|
|
110
|
+
defaultModel: 'onyx', // optional: shorthand `db.chat()` model
|
|
113
111
|
databaseId: 'YOUR_DATABASE_ID',
|
|
114
112
|
apiKey: 'YOUR_KEY',
|
|
115
113
|
apiSecret: 'YOUR_SECRET',
|
|
@@ -184,7 +182,7 @@ necessary unless you create many short‑lived clients.
|
|
|
184
182
|
|
|
185
183
|
## Onyx AI (chat & models)
|
|
186
184
|
|
|
187
|
-
AI endpoints are OpenAI-compatible and use the same credentials as database calls. The AI base URL defaults to `https://ai.onyx.dev` and can be overridden with `aiBaseUrl` (or `ONYX_AI_BASE_URL`). The `databaseId` query param is optional; when omitted, the configured databaseId is used for grounding and billing.
|
|
185
|
+
AI endpoints are OpenAI-compatible and use the same credentials as database calls. Use `db.ai` for chat, models, and script approvals; `db.chat()`/`db.chat('...')` remain supported as equivalent entrypoints. A shorthand `db.chat('content')` call is available and uses `config.defaultModel` (defaults to `onyx`). The AI base URL defaults to `https://ai.onyx.dev` and can be overridden with `aiBaseUrl` (or `ONYX_AI_BASE_URL`). The `databaseId` query param is optional; when omitted, the configured databaseId is used for grounding and billing.
|
|
188
186
|
|
|
189
187
|
### Chat completions
|
|
190
188
|
|
|
@@ -195,17 +193,27 @@ import { onyx } from '@onyx.dev/onyx-database';
|
|
|
195
193
|
|
|
196
194
|
const db = onyx.init();
|
|
197
195
|
|
|
198
|
-
const
|
|
196
|
+
const quick = await db.chat('Reply with exactly one short greeting sentence.'); // returns first message content
|
|
197
|
+
|
|
198
|
+
const completion = await db.ai.chat({
|
|
199
199
|
model: 'onyx-chat',
|
|
200
200
|
messages: [{ role: 'user', content: 'Summarize last week’s traffic.' }],
|
|
201
201
|
});
|
|
202
202
|
console.log(completion.choices[0]?.message?.content);
|
|
203
|
+
|
|
204
|
+
// Override defaults (model/role/temperature/stream) in shorthand form
|
|
205
|
+
const custom = await db.chat('List three colors.', {
|
|
206
|
+
model: 'onyx-chat',
|
|
207
|
+
role: 'user',
|
|
208
|
+
temperature: 0.2,
|
|
209
|
+
stream: false, // set raw: true to receive full completion response instead of the first message content
|
|
210
|
+
});
|
|
203
211
|
```
|
|
204
212
|
|
|
205
213
|
Streaming works as an async iterable:
|
|
206
214
|
|
|
207
215
|
```ts
|
|
208
|
-
const stream = await db.chat(
|
|
216
|
+
const stream = await db.ai.chat({
|
|
209
217
|
model: 'onyx-chat',
|
|
210
218
|
stream: true,
|
|
211
219
|
messages: [{ role: 'user', content: 'Write a short onboarding checklist.' }],
|
|
@@ -242,12 +250,12 @@ const prompt = {
|
|
|
242
250
|
],
|
|
243
251
|
};
|
|
244
252
|
|
|
245
|
-
const first = await db.chat(
|
|
253
|
+
const first = await db.ai.chat(prompt);
|
|
246
254
|
const toolCall = first.choices[0]?.message?.tool_calls?.[0];
|
|
247
255
|
|
|
248
256
|
if (toolCall) {
|
|
249
257
|
const toolResult = await getRevenue(JSON.parse(toolCall.function.arguments)); // your impl
|
|
250
|
-
const followup = await db.chat(
|
|
258
|
+
const followup = await db.ai.chat({
|
|
251
259
|
model: prompt.model,
|
|
252
260
|
messages: [
|
|
253
261
|
...prompt.messages,
|
|
@@ -264,14 +272,14 @@ if (toolCall) {
|
|
|
264
272
|
Example: `examples/ai/models.ts`.
|
|
265
273
|
|
|
266
274
|
```ts
|
|
267
|
-
const models = await db.getModels();
|
|
268
|
-
const chatModel = await db.getModel('onyx-chat');
|
|
275
|
+
const models = await db.ai.getModels();
|
|
276
|
+
const chatModel = await db.ai.getModel('onyx-chat');
|
|
269
277
|
```
|
|
270
278
|
|
|
271
279
|
### Script mutation approvals
|
|
272
280
|
|
|
273
281
|
```ts
|
|
274
|
-
const approval = await db.requestScriptApproval({
|
|
282
|
+
const approval = await db.ai.requestScriptApproval({
|
|
275
283
|
script: "db.save({ id: 'u1', email: 'a@b.com' })",
|
|
276
284
|
});
|
|
277
285
|
if (approval.requiresApproval) {
|
|
@@ -283,15 +291,19 @@ if (approval.requiresApproval) {
|
|
|
283
291
|
|
|
284
292
|
## Optional: generate TypeScript types from your schema
|
|
285
293
|
|
|
286
|
-
|
|
294
|
+
Use the **Onyx CLI** (`onyx`) from <https://github.com/OnyxDevTools/onyx-cli> to
|
|
295
|
+
emit per-table interfaces, a `tables` enum, and a `Schema` mapping for
|
|
296
|
+
compile-time safety and IntelliSense. Each generated interface also includes an
|
|
297
|
+
index signature so extra properties (for graph attachments in cascade saves)
|
|
298
|
+
don't trigger type errors.
|
|
287
299
|
|
|
288
300
|
Generate directly from the API (using the same credential resolver as `init()`):
|
|
289
301
|
|
|
290
302
|
```bash
|
|
291
|
-
|
|
303
|
+
onyx gen --ts --source api --out ./src/onyx/types.ts --name OnyxSchema
|
|
292
304
|
```
|
|
293
305
|
|
|
294
|
-
With `--source api`, `onyx
|
|
306
|
+
With `--source api`, `onyx gen` calls the Schema API (same as `onyx schema get`) using the
|
|
295
307
|
standard config chain (env, project file, home profile).
|
|
296
308
|
|
|
297
309
|
Timestamp attributes are emitted as `Date` fields by default. When saving,
|
|
@@ -301,30 +313,30 @@ Timestamp attributes are emitted as `Date` fields by default. When saving,
|
|
|
301
313
|
Or from a local schema file you export from the console:
|
|
302
314
|
|
|
303
315
|
```bash
|
|
304
|
-
|
|
316
|
+
onyx gen --ts --source file --schema ./onyx.schema.json --out ./src/onyx/types.ts --name OnyxSchema
|
|
305
317
|
```
|
|
306
318
|
|
|
307
|
-
Run it with no flags to use the defaults: `onyx
|
|
319
|
+
Run it with no flags to use the defaults: `onyx gen` reads `./onyx.schema.json` and writes to `./onyx/types.ts`.
|
|
308
320
|
|
|
309
321
|
### Manage schemas from the CLI
|
|
310
322
|
|
|
311
|
-
Publish or download schema JSON directly via API using the `onyx
|
|
323
|
+
Publish or download schema JSON directly via API using the `onyx schema` helper:
|
|
312
324
|
|
|
313
325
|
```bash
|
|
314
326
|
# Publish ./onyx.schema.json with publish=true by default
|
|
315
|
-
onyx
|
|
327
|
+
onyx schema publish
|
|
316
328
|
|
|
317
329
|
# Overwrite ./onyx.schema.json with the remote schema
|
|
318
|
-
onyx
|
|
330
|
+
onyx schema get
|
|
319
331
|
|
|
320
332
|
# Print the remote schema without writing a file
|
|
321
|
-
onyx
|
|
333
|
+
onyx schema get --print
|
|
322
334
|
|
|
323
335
|
# Fetch only selected tables (prints to stdout; does not overwrite files)
|
|
324
|
-
onyx
|
|
336
|
+
onyx schema get --tables=User,Profile
|
|
325
337
|
|
|
326
338
|
# Example subset output
|
|
327
|
-
onyx
|
|
339
|
+
onyx schema get --tables=User,Profile
|
|
328
340
|
# {
|
|
329
341
|
# "tables": [
|
|
330
342
|
# {
|
|
@@ -345,10 +357,10 @@ onyx-schema get --tables=User,Profile
|
|
|
345
357
|
# }
|
|
346
358
|
|
|
347
359
|
# Validate a schema file without publishing
|
|
348
|
-
onyx
|
|
360
|
+
onyx schema validate ./onyx.schema.json
|
|
349
361
|
|
|
350
362
|
# Diff local schema vs API
|
|
351
|
-
onyx
|
|
363
|
+
onyx schema diff ./onyx.schema.json
|
|
352
364
|
# Prints YAML with added/removed/changed tables and attribute differences between the API schema and your local file.
|
|
353
365
|
```
|
|
354
366
|
|
|
@@ -379,7 +391,7 @@ console.log(diff.changedTables);
|
|
|
379
391
|
You can also emit to multiple paths in one run (comma-separated or by repeating `--out`):
|
|
380
392
|
|
|
381
393
|
```bash
|
|
382
|
-
onyx
|
|
394
|
+
onyx gen --ts --out ./src/onyx/types.ts,./apps/admin/src/onyx/types.ts
|
|
383
395
|
```
|
|
384
396
|
|
|
385
397
|
Use in code:
|
|
@@ -399,12 +411,12 @@ const User = await db
|
|
|
399
411
|
```
|
|
400
412
|
|
|
401
413
|
For a schema with `User`, `UserProfile`, `Role`, and `Permission` tables,
|
|
402
|
-
`onyx
|
|
414
|
+
`onyx gen` emits plain interfaces keyed by IDs. Each interface includes an
|
|
403
415
|
index signature so resolver-attached fields or embedded objects remain
|
|
404
416
|
type-safe:
|
|
405
417
|
|
|
406
418
|
```ts
|
|
407
|
-
// AUTO-GENERATED BY onyx
|
|
419
|
+
// AUTO-GENERATED BY onyx gen. DO NOT EDIT.
|
|
408
420
|
export interface User {
|
|
409
421
|
id?: string;
|
|
410
422
|
name: string;
|
|
@@ -523,6 +535,26 @@ import {
|
|
|
523
535
|
- `inOp`/`notIn` remain available for backward compatibility and are exact aliases.
|
|
524
536
|
- `search(text, minScore?)` builds a Lucene `MATCHES` predicate on `__full_text__` and always serializes `minScore` (null when omitted).
|
|
525
537
|
|
|
538
|
+
### Aggregate helpers
|
|
539
|
+
|
|
540
|
+
```ts
|
|
541
|
+
import {
|
|
542
|
+
avg, sum, count, min, max,
|
|
543
|
+
std, variance, median,
|
|
544
|
+
upper, lower,
|
|
545
|
+
substring, replace, percentile,
|
|
546
|
+
format
|
|
547
|
+
} from '@onyx.dev/onyx-database';
|
|
548
|
+
|
|
549
|
+
const rows = await db
|
|
550
|
+
.select(format('createdAt', 'yyyy-MM-dd'))
|
|
551
|
+
.from('User')
|
|
552
|
+
.list();
|
|
553
|
+
```
|
|
554
|
+
|
|
555
|
+
- `format(field, formatter)` uses Java-style format strings for dates and numbers.
|
|
556
|
+
- Example: `examples/query/format.ts`
|
|
557
|
+
|
|
526
558
|
### Inner queries (IN/NOT IN with sub-selects)
|
|
527
559
|
|
|
528
560
|
You can pass another query builder to `within` or `notWithin` to create nested filters. The SDK serializes the inner query (including its table) before sending the request.
|
|
@@ -877,36 +909,31 @@ const db = onyx.init({
|
|
|
877
909
|
+----------------------+-----------------------------------------------+--------------------------------------------------------------+
|
|
878
910
|
| Command | Flags | Defaults / notes |
|
|
879
911
|
+----------------------+-----------------------------------------------+--------------------------------------------------------------+
|
|
880
|
-
| onyx
|
|
881
|
-
| | --
|
|
882
|
-
| | --
|
|
883
|
-
| | --
|
|
884
|
-
| | --
|
|
885
|
-
| | --
|
|
886
|
-
| | --prefix <Prefix> | |
|
|
887
|
-
| | --optional non-null|nullable|none | |
|
|
888
|
-
| | --emit-json / --no-emit-json | |
|
|
889
|
-
| | --json-out <dir> | |
|
|
890
|
-
| | --api-path <path> (repeatable) | |
|
|
912
|
+
| onyx gen | --ts/--typescript | Default: --source file; --schema ./onyx.schema.json; |
|
|
913
|
+
| | --source auto|api|file | --out ./onyx/types.ts (file or dir; repeatable); |
|
|
914
|
+
| | --schema <path> | schema type name: OnyxSchema; timestamps default: date. |
|
|
915
|
+
| | --out <dir|file> | Use --overwrite to force output; quiet=false. |
|
|
916
|
+
| | --name <T> | |
|
|
917
|
+
| | --timestamps string|date|number | |
|
|
891
918
|
| | --overwrite / --no-overwrite | |
|
|
892
919
|
| | -q / --quiet | |
|
|
893
920
|
| | -h / --help | |
|
|
894
921
|
+----------------------+-----------------------------------------------+--------------------------------------------------------------+
|
|
895
|
-
| onyx
|
|
922
|
+
| onyx schema get | [file] (positional) | Default file: ./onyx.schema.json; writes file unless |
|
|
896
923
|
| | --tables a,b | --tables or --print (then prints to stdout). |
|
|
897
924
|
| | --print | |
|
|
898
925
|
| | -h / --help | |
|
|
899
926
|
+----------------------+-----------------------------------------------+--------------------------------------------------------------+
|
|
900
|
-
| onyx
|
|
927
|
+
| onyx schema publish | [file] (positional) | Default file: ./onyx.schema.json; validates before publishing; |
|
|
901
928
|
| | -h / --help | uses onyx.init credential resolver. |
|
|
902
929
|
+----------------------+-----------------------------------------------+--------------------------------------------------------------+
|
|
903
|
-
| onyx
|
|
930
|
+
| onyx schema validate | [file] (positional) | Default file: ./onyx.schema.json; exits non-zero on errors. |
|
|
904
931
|
| | -h / --help | |
|
|
905
932
|
+----------------------+-----------------------------------------------+--------------------------------------------------------------+
|
|
906
|
-
| onyx
|
|
933
|
+
| onyx schema diff | [file] (positional) | Default file: ./onyx.schema.json; prints YAML diff vs API. |
|
|
907
934
|
| | -h / --help | |
|
|
908
935
|
+----------------------+-----------------------------------------------+--------------------------------------------------------------+
|
|
909
|
-
| onyx
|
|
936
|
+
| onyx schema info | -h / --help | Shows resolved config sources, config path, connection check.|
|
|
910
937
|
+----------------------+-----------------------------------------------+--------------------------------------------------------------+
|
|
911
938
|
```
|
|
912
939
|
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
var name = "@onyx.dev/onyx-database";
|
|
2
|
+
var version = "2.0.1";
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* Supported operators for building query criteria.
|
|
3
6
|
*
|
|
@@ -822,6 +825,10 @@ interface OnyxConfig {
|
|
|
822
825
|
apiKey?: string;
|
|
823
826
|
apiSecret?: string;
|
|
824
827
|
fetch?: FetchImpl;
|
|
828
|
+
/**
|
|
829
|
+
* Default AI model when using shorthand chat calls (`db.chat('...')`). Defaults to `onyx`.
|
|
830
|
+
*/
|
|
831
|
+
defaultModel?: string;
|
|
825
832
|
/**
|
|
826
833
|
* Default partition for queries, `findById`, and deletes when removing by
|
|
827
834
|
* primary key. Saves rely on the entity's partition field instead.
|
|
@@ -934,6 +941,28 @@ interface AiChatCompletionChunk {
|
|
|
934
941
|
interface AiChatCompletionStream extends AsyncIterable<AiChatCompletionChunk> {
|
|
935
942
|
cancel(): void;
|
|
936
943
|
}
|
|
944
|
+
interface AiChatOptions extends AiRequestOptions {
|
|
945
|
+
/**
|
|
946
|
+
* Model to use for the shorthand `db.chat()` call. Defaults to config.defaultModel or `onyx`.
|
|
947
|
+
*/
|
|
948
|
+
model?: string;
|
|
949
|
+
/**
|
|
950
|
+
* Role for the constructed message. Defaults to `user`.
|
|
951
|
+
*/
|
|
952
|
+
role?: AiChatRole;
|
|
953
|
+
/**
|
|
954
|
+
* Temperature for the completion. Omit to use the service default.
|
|
955
|
+
*/
|
|
956
|
+
temperature?: number | null;
|
|
957
|
+
/**
|
|
958
|
+
* Enable SSE streaming. Defaults to `false`.
|
|
959
|
+
*/
|
|
960
|
+
stream?: boolean;
|
|
961
|
+
/**
|
|
962
|
+
* When true, return the raw completion response instead of the first message content.
|
|
963
|
+
*/
|
|
964
|
+
raw?: boolean;
|
|
965
|
+
}
|
|
937
966
|
interface AiChatClient {
|
|
938
967
|
create(request: AiChatCompletionRequest & {
|
|
939
968
|
stream?: false;
|
|
@@ -968,9 +997,90 @@ interface AiErrorResponse {
|
|
|
968
997
|
[key: string]: unknown;
|
|
969
998
|
} | null;
|
|
970
999
|
}
|
|
1000
|
+
interface AiClient {
|
|
1001
|
+
/**
|
|
1002
|
+
* Run a chat completion. Accepts shorthand strings or full requests.
|
|
1003
|
+
*
|
|
1004
|
+
* @example
|
|
1005
|
+
* ```ts
|
|
1006
|
+
* const quick = await db.ai.chat('Summarize last week.'); // returns first message content
|
|
1007
|
+
* const completion = await db.ai.chat(
|
|
1008
|
+
* { model: 'onyx-chat', messages: [{ role: 'user', content: 'Summarize last week.' }] },
|
|
1009
|
+
* { databaseId: 'db1', raw: true }, // returns full response
|
|
1010
|
+
* );
|
|
1011
|
+
* ```
|
|
1012
|
+
*/
|
|
1013
|
+
chat(content: string, options?: AiChatOptions & {
|
|
1014
|
+
stream?: false;
|
|
1015
|
+
raw?: false | undefined;
|
|
1016
|
+
}): Promise<string>;
|
|
1017
|
+
chat(content: string, options: AiChatOptions & {
|
|
1018
|
+
stream: true;
|
|
1019
|
+
}): Promise<AiChatCompletionStream>;
|
|
1020
|
+
chat(content: string, options: AiChatOptions & {
|
|
1021
|
+
raw: true;
|
|
1022
|
+
}): Promise<AiChatCompletionResponse | AiChatCompletionStream>;
|
|
1023
|
+
chat(request: AiChatCompletionRequest & {
|
|
1024
|
+
stream?: false;
|
|
1025
|
+
}, options?: AiRequestOptions): Promise<AiChatCompletionResponse>;
|
|
1026
|
+
chat(request: AiChatCompletionRequest & {
|
|
1027
|
+
stream: true;
|
|
1028
|
+
}, options?: AiRequestOptions): Promise<AiChatCompletionStream>;
|
|
1029
|
+
chat(request: AiChatCompletionRequest, options?: AiRequestOptions): Promise<AiChatCompletionResponse | AiChatCompletionStream>;
|
|
1030
|
+
/**
|
|
1031
|
+
* Access the chat client for more control over streaming and cancellation.
|
|
1032
|
+
*/
|
|
1033
|
+
chatClient(): AiChatClient;
|
|
1034
|
+
/**
|
|
1035
|
+
* List available AI models.
|
|
1036
|
+
*
|
|
1037
|
+
* @example
|
|
1038
|
+
* ```ts
|
|
1039
|
+
* const models = await db.ai.getModels();
|
|
1040
|
+
* ```
|
|
1041
|
+
*/
|
|
1042
|
+
getModels(): Promise<AiModelsResponse>;
|
|
1043
|
+
/**
|
|
1044
|
+
* Retrieve a single AI model by ID.
|
|
1045
|
+
*
|
|
1046
|
+
* @example
|
|
1047
|
+
* ```ts
|
|
1048
|
+
* const model = await db.ai.getModel('onyx-chat');
|
|
1049
|
+
* ```
|
|
1050
|
+
*/
|
|
1051
|
+
getModel(modelId: string): Promise<AiModel>;
|
|
1052
|
+
/**
|
|
1053
|
+
* Request mutation approval for a script.
|
|
1054
|
+
*
|
|
1055
|
+
* @example
|
|
1056
|
+
* ```ts
|
|
1057
|
+
* const approval = await db.ai.requestScriptApproval({
|
|
1058
|
+
* script: "db.save({ id: 'u1', email: 'a@b.com' })"
|
|
1059
|
+
* });
|
|
1060
|
+
* ```
|
|
1061
|
+
*/
|
|
1062
|
+
requestScriptApproval(input: AiScriptApprovalRequest): Promise<AiScriptApprovalResponse>;
|
|
1063
|
+
}
|
|
971
1064
|
interface IOnyxDatabase<Schema = Record<string, unknown>> {
|
|
972
1065
|
/**
|
|
973
|
-
*
|
|
1066
|
+
* AI helpers (chat, models, script approvals) grouped under `db.ai`.
|
|
1067
|
+
*
|
|
1068
|
+
* @example
|
|
1069
|
+
* ```ts
|
|
1070
|
+
* const completion = await db.ai.chat({
|
|
1071
|
+
* model: 'onyx-chat',
|
|
1072
|
+
* messages: [{ role: 'user', content: 'Summarize last week.' }],
|
|
1073
|
+
* });
|
|
1074
|
+
* ```
|
|
1075
|
+
*/
|
|
1076
|
+
ai: AiClient;
|
|
1077
|
+
/**
|
|
1078
|
+
* Access OpenAI-compatible chat completions via `db.chat('...')` or `db.chat().create(...)`.
|
|
1079
|
+
*
|
|
1080
|
+
* @example
|
|
1081
|
+
* ```ts
|
|
1082
|
+
* const completion = await db.chat('Summarize last week.'); // returns first message content
|
|
1083
|
+
* ```
|
|
974
1084
|
*
|
|
975
1085
|
* @example
|
|
976
1086
|
* ```ts
|
|
@@ -995,10 +1105,22 @@ interface IOnyxDatabase<Schema = Record<string, unknown>> {
|
|
|
995
1105
|
* }
|
|
996
1106
|
* ```
|
|
997
1107
|
*/
|
|
1108
|
+
chat(content: string, options?: AiChatOptions & {
|
|
1109
|
+
stream?: false;
|
|
1110
|
+
raw?: false | undefined;
|
|
1111
|
+
}): Promise<string>;
|
|
1112
|
+
chat(content: string, options: AiChatOptions & {
|
|
1113
|
+
stream: true;
|
|
1114
|
+
}): Promise<AiChatCompletionStream>;
|
|
1115
|
+
chat(content: string, options: AiChatOptions & {
|
|
1116
|
+
raw: true;
|
|
1117
|
+
}): Promise<AiChatCompletionResponse | AiChatCompletionStream>;
|
|
998
1118
|
chat(): AiChatClient;
|
|
999
1119
|
/**
|
|
1000
1120
|
* List available AI models.
|
|
1001
1121
|
*
|
|
1122
|
+
* @deprecated Prefer `db.ai.getModels()`.
|
|
1123
|
+
*
|
|
1002
1124
|
* @example
|
|
1003
1125
|
* ```ts
|
|
1004
1126
|
* const models = await db.getModels();
|
|
@@ -1008,6 +1130,8 @@ interface IOnyxDatabase<Schema = Record<string, unknown>> {
|
|
|
1008
1130
|
/**
|
|
1009
1131
|
* Retrieve a single AI model by ID.
|
|
1010
1132
|
*
|
|
1133
|
+
* @deprecated Prefer `db.ai.getModel(...)`.
|
|
1134
|
+
*
|
|
1011
1135
|
* @example
|
|
1012
1136
|
* ```ts
|
|
1013
1137
|
* const model = await db.getModel('onyx-chat');
|
|
@@ -1017,6 +1141,8 @@ interface IOnyxDatabase<Schema = Record<string, unknown>> {
|
|
|
1017
1141
|
/**
|
|
1018
1142
|
* Request mutation approval for a script.
|
|
1019
1143
|
*
|
|
1144
|
+
* @deprecated Prefer `db.ai.requestScriptApproval(...)`.
|
|
1145
|
+
*
|
|
1020
1146
|
* @example
|
|
1021
1147
|
* ```ts
|
|
1022
1148
|
* const approval = await db.requestScriptApproval({
|
|
@@ -1632,6 +1758,7 @@ declare const upper: (attribute: string) => string;
|
|
|
1632
1758
|
declare const lower: (attribute: string) => string;
|
|
1633
1759
|
declare const substring: (attribute: string, from: number, length: number) => string;
|
|
1634
1760
|
declare const replace: (attribute: string, pattern: string, repl: string) => string;
|
|
1761
|
+
declare const format: (attribute: string, formatter: string) => string;
|
|
1635
1762
|
declare const percentile: (attribute: string, p: number) => string;
|
|
1636
1763
|
|
|
1637
|
-
export { type
|
|
1764
|
+
export { type SchemaIndexChange as $, type AiRequestOptions as A, type AiClient as B, type SecretRecord as C, type SecretsListResponse as D, type SecretSaveRequest as E, type FullTextQuery as F, type SchemaDataType as G, type SchemaIdentifierGenerator as H, type IOnyxDatabase as I, type SchemaIdentifier as J, type SchemaAttribute as K, type SchemaIndexType as L, type SchemaIndex as M, type SchemaResolver as N, type OnyxFacade as O, type SchemaTriggerEvent as P, QueryResults as Q, type RetryOptions as R, type SecretMetadata as S, type SchemaTrigger as T, type SchemaEntity as U, type SchemaRevisionMetadata as V, type SchemaRevision as W, type SchemaHistoryEntry as X, type SchemaUpsertRequest as Y, type SchemaValidationResult as Z, type SchemaAttributeChange as _, type QueryResultsPromise as a, type SchemaResolverChange as a0, type SchemaTriggerChange as a1, type SchemaTableDiff as a2, type SchemaDiff as a3, type QueryCriteriaOperator as a4, type LogicalOperator as a5, type Sort as a6, type StreamAction as a7, type OnyxDocument as a8, type FetchResponse as a9, notMatches as aA, like as aB, notLike as aC, contains as aD, containsIgnoreCase as aE, notContains as aF, notContainsIgnoreCase as aG, startsWith as aH, notStartsWith as aI, isNull as aJ, notNull as aK, avg as aL, sum as aM, count as aN, min as aO, max as aP, std as aQ, variance as aR, median as aS, upper as aT, lower as aU, substring as aV, replace as aW, format as aX, percentile as aY, type FetchImpl as aa, type QueryCriteria as ab, type QueryCondition as ac, type SelectQuery as ad, type UpdateQuery as ae, type QueryPage as af, type IConditionBuilder as ag, type IQueryBuilder as ah, type ISaveBuilder as ai, type ICascadeBuilder as aj, type ICascadeRelationshipBuilder as ak, asc as al, desc as am, eq as an, neq as ao, inOp as ap, within as aq, notIn as ar, notWithin as as, between as at, gt as au, gte as av, lt as aw, lte as ax, matches as ay, search as az, type OnyxConfig as b, type AiChatRole as c, type AiToolCallFunction as d, type AiToolCall as e, type AiChatMessage as f, type AiToolFunction as g, type AiTool as h, type AiToolChoice as i, type AiChatCompletionRequest as j, type AiChatCompletionUsage as k, type AiChatCompletionChoice as l, type AiChatCompletionResponse as m, name as n, type AiChatCompletionChunkDelta as o, type AiChatCompletionChunkChoice as p, type AiChatCompletionChunk as q, type AiChatCompletionStream as r, type AiChatOptions as s, type AiChatClient as t, type AiScriptApprovalRequest as u, version as v, type AiScriptApprovalResponse as w, type AiModelsResponse as x, type AiModel as y, type AiErrorResponse as z };
|