@onyx.dev/onyx-database 1.1.0 → 1.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.
- package/README.md +108 -0
- package/dist/{aggregates-DodZNu9-.d.cts → aggregates-LoteczVS.d.cts} +185 -1
- package/dist/{aggregates-DodZNu9-.d.ts → aggregates-LoteczVS.d.ts} +185 -1
- package/dist/edge.cjs +204 -0
- package/dist/edge.cjs.map +1 -1
- package/dist/edge.d.cts +2 -2
- package/dist/edge.d.ts +2 -2
- package/dist/edge.js +204 -0
- package/dist/edge.js.map +1 -1
- package/dist/gen/cli/generate.cjs +205 -0
- package/dist/gen/cli/generate.cjs.map +1 -1
- package/dist/index.cjs +205 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +205 -0
- package/dist/index.js.map +1 -1
- package/dist/schema/cli/schema.cjs +206 -0
- package/dist/schema/cli/schema.cjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,6 +18,7 @@ TypeScript client SDK for **Onyx Cloud Database** — a zero-dependency, strict-
|
|
|
18
18
|
- [Getting started](#getting-started-cloud--keys--connect)
|
|
19
19
|
- [Install](#install)
|
|
20
20
|
- [Initialize the client](#initialize-the-client)
|
|
21
|
+
- [Onyx AI (chat & models)](#onyx-ai-chat--models)
|
|
21
22
|
- [Generate schema types](#optional-generate-typescript-types-from-your-schema)
|
|
22
23
|
- [Query helpers](#query-helpers-at-a-glance)
|
|
23
24
|
- [Full-text search](#full-text-search-lucene)
|
|
@@ -92,6 +93,7 @@ Set the following environment variables for your database:
|
|
|
92
93
|
- `ONYX_DATABASE_BASE_URL`
|
|
93
94
|
- `ONYX_DATABASE_API_KEY`
|
|
94
95
|
- `ONYX_DATABASE_API_SECRET`
|
|
96
|
+
- `ONYX_AI_BASE_URL` (optional; defaults to `https://ai.onyx.dev`)
|
|
95
97
|
|
|
96
98
|
```ts
|
|
97
99
|
import { onyx } from '@onyx.dev/onyx-database';
|
|
@@ -107,6 +109,7 @@ import { onyx } from '@onyx.dev/onyx-database';
|
|
|
107
109
|
|
|
108
110
|
const db = onyx.init({
|
|
109
111
|
baseUrl: 'https://api.onyx.dev',
|
|
112
|
+
aiBaseUrl: 'https://ai.onyx.dev', // optional: override AI base path
|
|
110
113
|
databaseId: 'YOUR_DATABASE_ID',
|
|
111
114
|
apiKey: 'YOUR_KEY',
|
|
112
115
|
apiSecret: 'YOUR_SECRET',
|
|
@@ -179,6 +182,105 @@ necessary unless you create many short‑lived clients.
|
|
|
179
182
|
|
|
180
183
|
---
|
|
181
184
|
|
|
185
|
+
## Onyx AI (chat & models)
|
|
186
|
+
|
|
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.
|
|
188
|
+
|
|
189
|
+
### Chat completions
|
|
190
|
+
|
|
191
|
+
Examples: `examples/ai/chat.ts`, `examples/ai/chat-stream.ts`.
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
import { onyx } from '@onyx.dev/onyx-database';
|
|
195
|
+
|
|
196
|
+
const db = onyx.init();
|
|
197
|
+
|
|
198
|
+
const completion = await db.chat().create({
|
|
199
|
+
model: 'onyx-chat',
|
|
200
|
+
messages: [{ role: 'user', content: 'Summarize last week’s traffic.' }],
|
|
201
|
+
});
|
|
202
|
+
console.log(completion.choices[0]?.message?.content);
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Streaming works as an async iterable:
|
|
206
|
+
|
|
207
|
+
```ts
|
|
208
|
+
const stream = await db.chat().create({
|
|
209
|
+
model: 'onyx-chat',
|
|
210
|
+
stream: true,
|
|
211
|
+
messages: [{ role: 'user', content: 'Write a short onboarding checklist.' }],
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
for await (const chunk of stream) {
|
|
215
|
+
process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
|
|
216
|
+
}
|
|
217
|
+
// stream.cancel() is available if you need to stop early
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
Tool calls mirror the ChatGPT TypeScript client:
|
|
221
|
+
|
|
222
|
+
```ts
|
|
223
|
+
const prompt = {
|
|
224
|
+
model: 'onyx-chat',
|
|
225
|
+
messages: [{ role: 'user', content: 'Find revenue for ACME in 2023.' }],
|
|
226
|
+
tools: [
|
|
227
|
+
{
|
|
228
|
+
type: 'function',
|
|
229
|
+
function: {
|
|
230
|
+
name: 'get_revenue',
|
|
231
|
+
description: 'Fetch revenue for a company and year',
|
|
232
|
+
parameters: {
|
|
233
|
+
type: 'object',
|
|
234
|
+
properties: {
|
|
235
|
+
company: { type: 'string' },
|
|
236
|
+
year: { type: 'number' },
|
|
237
|
+
},
|
|
238
|
+
required: ['company', 'year'],
|
|
239
|
+
},
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
],
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
const first = await db.chat().create(prompt);
|
|
246
|
+
const toolCall = first.choices[0]?.message?.tool_calls?.[0];
|
|
247
|
+
|
|
248
|
+
if (toolCall) {
|
|
249
|
+
const toolResult = await getRevenue(JSON.parse(toolCall.function.arguments)); // your impl
|
|
250
|
+
const followup = await db.chat().create({
|
|
251
|
+
model: prompt.model,
|
|
252
|
+
messages: [
|
|
253
|
+
...prompt.messages,
|
|
254
|
+
first.choices[0].message,
|
|
255
|
+
{ role: 'tool', tool_call_id: toolCall.id ?? '', content: JSON.stringify(toolResult) },
|
|
256
|
+
],
|
|
257
|
+
});
|
|
258
|
+
console.log(followup.choices[0]?.message?.content);
|
|
259
|
+
}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### Model metadata
|
|
263
|
+
|
|
264
|
+
Example: `examples/ai/models.ts`.
|
|
265
|
+
|
|
266
|
+
```ts
|
|
267
|
+
const models = await db.getModels();
|
|
268
|
+
const chatModel = await db.getModel('onyx-chat');
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### Script mutation approvals
|
|
272
|
+
|
|
273
|
+
```ts
|
|
274
|
+
const approval = await db.requestScriptApproval({
|
|
275
|
+
script: "db.save({ id: 'u1', email: 'a@b.com' })",
|
|
276
|
+
});
|
|
277
|
+
if (approval.requiresApproval) {
|
|
278
|
+
console.log(`Requires approval until ${approval.expiresAtIso}`);
|
|
279
|
+
}
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
---
|
|
283
|
+
|
|
182
284
|
## Optional: generate TypeScript types from your schema
|
|
183
285
|
|
|
184
286
|
The package ships a small codegen CLI that emits per-table interfaces, a `tables` enum, and a `Schema` mapping for compile-time safety and IntelliSense. Each generated interface also includes an index signature so extra properties (for graph attachments in cascade saves) don't trigger type errors.
|
|
@@ -483,6 +585,12 @@ const activeMatch = await db
|
|
|
483
585
|
.firstOrNull();
|
|
484
586
|
```
|
|
485
587
|
|
|
588
|
+
**Examples**
|
|
589
|
+
- Table search (minScore null): `examples/query/lucine-table-search.ts`
|
|
590
|
+
- Table search (minScore 4.4): `examples/query/lucine-table-search-min-score.ts`
|
|
591
|
+
- ALL tables search (minScore null): `examples/query/lucine-search-all-tables.ts`
|
|
592
|
+
- ALL tables search (minScore 4.4): `examples/query/lucine-search-all-tables-min-score.ts`
|
|
593
|
+
|
|
486
594
|
---
|
|
487
595
|
|
|
488
596
|
## Usage examples with `User`, `Role`, `Permission`
|
|
@@ -814,6 +814,10 @@ interface RetryOptions {
|
|
|
814
814
|
}
|
|
815
815
|
interface OnyxConfig {
|
|
816
816
|
baseUrl?: string;
|
|
817
|
+
/**
|
|
818
|
+
* Base URL for AI endpoints. Defaults to https://ai.onyx.dev.
|
|
819
|
+
*/
|
|
820
|
+
aiBaseUrl?: string;
|
|
817
821
|
databaseId?: string;
|
|
818
822
|
apiKey?: string;
|
|
819
823
|
apiSecret?: string;
|
|
@@ -840,7 +844,187 @@ interface OnyxConfig {
|
|
|
840
844
|
*/
|
|
841
845
|
retry?: RetryOptions;
|
|
842
846
|
}
|
|
847
|
+
interface AiRequestOptions {
|
|
848
|
+
/**
|
|
849
|
+
* Optional database scope for AI calls. Defaults to the configured databaseId.
|
|
850
|
+
*/
|
|
851
|
+
databaseId?: string;
|
|
852
|
+
}
|
|
853
|
+
type AiChatRole = 'system' | 'user' | 'assistant' | 'tool';
|
|
854
|
+
interface AiToolCallFunction {
|
|
855
|
+
name: string;
|
|
856
|
+
arguments: string;
|
|
857
|
+
}
|
|
858
|
+
interface AiToolCall {
|
|
859
|
+
id?: string | null;
|
|
860
|
+
type?: string | null;
|
|
861
|
+
function: AiToolCallFunction;
|
|
862
|
+
}
|
|
863
|
+
interface AiChatMessage {
|
|
864
|
+
role: AiChatRole;
|
|
865
|
+
content?: string | null;
|
|
866
|
+
tool_calls?: AiToolCall[] | null;
|
|
867
|
+
tool_call_id?: string | null;
|
|
868
|
+
name?: string | null;
|
|
869
|
+
}
|
|
870
|
+
interface AiToolFunction {
|
|
871
|
+
name: string;
|
|
872
|
+
description?: string | null;
|
|
873
|
+
parameters?: Record<string, unknown> | null;
|
|
874
|
+
}
|
|
875
|
+
interface AiTool {
|
|
876
|
+
type: string;
|
|
877
|
+
function: AiToolFunction;
|
|
878
|
+
}
|
|
879
|
+
type AiToolChoice = 'none' | 'auto' | {
|
|
880
|
+
type: 'function';
|
|
881
|
+
function: {
|
|
882
|
+
name: string;
|
|
883
|
+
};
|
|
884
|
+
} | null;
|
|
885
|
+
interface AiChatCompletionRequest {
|
|
886
|
+
model: string;
|
|
887
|
+
messages: AiChatMessage[];
|
|
888
|
+
stream?: boolean;
|
|
889
|
+
temperature?: number | null;
|
|
890
|
+
top_p?: number | null;
|
|
891
|
+
max_tokens?: number | null;
|
|
892
|
+
metadata?: Record<string, unknown>;
|
|
893
|
+
tools?: AiTool[];
|
|
894
|
+
tool_choice?: AiToolChoice;
|
|
895
|
+
user?: string | null;
|
|
896
|
+
}
|
|
897
|
+
interface AiChatCompletionUsage {
|
|
898
|
+
prompt_tokens?: number | null;
|
|
899
|
+
completion_tokens?: number | null;
|
|
900
|
+
total_tokens?: number | null;
|
|
901
|
+
}
|
|
902
|
+
interface AiChatCompletionChoice {
|
|
903
|
+
index: number;
|
|
904
|
+
message: AiChatMessage;
|
|
905
|
+
finish_reason?: string | null;
|
|
906
|
+
}
|
|
907
|
+
interface AiChatCompletionResponse {
|
|
908
|
+
id: string;
|
|
909
|
+
object: string;
|
|
910
|
+
created: number;
|
|
911
|
+
model: string;
|
|
912
|
+
choices: AiChatCompletionChoice[];
|
|
913
|
+
usage?: AiChatCompletionUsage;
|
|
914
|
+
}
|
|
915
|
+
interface AiChatCompletionChunkDelta {
|
|
916
|
+
role?: AiChatRole | null;
|
|
917
|
+
content?: string | null;
|
|
918
|
+
tool_calls?: AiToolCall[] | null;
|
|
919
|
+
tool_call_id?: string | null;
|
|
920
|
+
name?: string | null;
|
|
921
|
+
}
|
|
922
|
+
interface AiChatCompletionChunkChoice {
|
|
923
|
+
index: number;
|
|
924
|
+
delta: AiChatCompletionChunkDelta;
|
|
925
|
+
finish_reason?: string | null;
|
|
926
|
+
}
|
|
927
|
+
interface AiChatCompletionChunk {
|
|
928
|
+
id: string;
|
|
929
|
+
object: string;
|
|
930
|
+
created: number;
|
|
931
|
+
model?: string | null;
|
|
932
|
+
choices: AiChatCompletionChunkChoice[];
|
|
933
|
+
}
|
|
934
|
+
interface AiChatCompletionStream extends AsyncIterable<AiChatCompletionChunk> {
|
|
935
|
+
cancel(): void;
|
|
936
|
+
}
|
|
937
|
+
interface AiChatClient {
|
|
938
|
+
create(request: AiChatCompletionRequest & {
|
|
939
|
+
stream?: false;
|
|
940
|
+
}, options?: AiRequestOptions): Promise<AiChatCompletionResponse>;
|
|
941
|
+
create(request: AiChatCompletionRequest & {
|
|
942
|
+
stream: true;
|
|
943
|
+
}, options?: AiRequestOptions): Promise<AiChatCompletionStream>;
|
|
944
|
+
create(request: AiChatCompletionRequest, options?: AiRequestOptions): Promise<AiChatCompletionResponse | AiChatCompletionStream>;
|
|
945
|
+
}
|
|
946
|
+
interface AiScriptApprovalRequest {
|
|
947
|
+
script: string;
|
|
948
|
+
}
|
|
949
|
+
interface AiScriptApprovalResponse {
|
|
950
|
+
normalizedScript: string;
|
|
951
|
+
expiresAtIso: string;
|
|
952
|
+
requiresApproval: boolean;
|
|
953
|
+
findings?: string;
|
|
954
|
+
}
|
|
955
|
+
interface AiModelsResponse {
|
|
956
|
+
object: string;
|
|
957
|
+
data: AiModel[];
|
|
958
|
+
}
|
|
959
|
+
interface AiModel {
|
|
960
|
+
id: string;
|
|
961
|
+
object: string;
|
|
962
|
+
created: number;
|
|
963
|
+
owned_by: string;
|
|
964
|
+
}
|
|
965
|
+
interface AiErrorResponse {
|
|
966
|
+
error?: string | {
|
|
967
|
+
message?: string;
|
|
968
|
+
[key: string]: unknown;
|
|
969
|
+
} | null;
|
|
970
|
+
}
|
|
843
971
|
interface IOnyxDatabase<Schema = Record<string, unknown>> {
|
|
972
|
+
/**
|
|
973
|
+
* Access OpenAI-compatible chat completions.
|
|
974
|
+
*
|
|
975
|
+
* @example
|
|
976
|
+
* ```ts
|
|
977
|
+
* const chat = db.chat();
|
|
978
|
+
* const completion = await chat.create({
|
|
979
|
+
* model: 'onyx-chat',
|
|
980
|
+
* messages: [{ role: 'user', content: 'Summarize last week.' }],
|
|
981
|
+
* });
|
|
982
|
+
* ```
|
|
983
|
+
*
|
|
984
|
+
* @example
|
|
985
|
+
* ```ts
|
|
986
|
+
* const stream = await db
|
|
987
|
+
* .chat()
|
|
988
|
+
* .create({
|
|
989
|
+
* model: 'onyx-chat',
|
|
990
|
+
* stream: true,
|
|
991
|
+
* messages: [{ role: 'user', content: 'Draft an onboarding checklist.' }],
|
|
992
|
+
* });
|
|
993
|
+
* for await (const chunk of stream) {
|
|
994
|
+
* process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
|
|
995
|
+
* }
|
|
996
|
+
* ```
|
|
997
|
+
*/
|
|
998
|
+
chat(): AiChatClient;
|
|
999
|
+
/**
|
|
1000
|
+
* List available AI models.
|
|
1001
|
+
*
|
|
1002
|
+
* @example
|
|
1003
|
+
* ```ts
|
|
1004
|
+
* const models = await db.getModels();
|
|
1005
|
+
* ```
|
|
1006
|
+
*/
|
|
1007
|
+
getModels(): Promise<AiModelsResponse>;
|
|
1008
|
+
/**
|
|
1009
|
+
* Retrieve a single AI model by ID.
|
|
1010
|
+
*
|
|
1011
|
+
* @example
|
|
1012
|
+
* ```ts
|
|
1013
|
+
* const model = await db.getModel('onyx-chat');
|
|
1014
|
+
* ```
|
|
1015
|
+
*/
|
|
1016
|
+
getModel(modelId: string): Promise<AiModel>;
|
|
1017
|
+
/**
|
|
1018
|
+
* Request mutation approval for a script.
|
|
1019
|
+
*
|
|
1020
|
+
* @example
|
|
1021
|
+
* ```ts
|
|
1022
|
+
* const approval = await db.requestScriptApproval({
|
|
1023
|
+
* script: "db.save({ id: 'u1', email: 'a@b.com' })"
|
|
1024
|
+
* });
|
|
1025
|
+
* ```
|
|
1026
|
+
*/
|
|
1027
|
+
requestScriptApproval(input: AiScriptApprovalRequest): Promise<AiScriptApprovalResponse>;
|
|
844
1028
|
/**
|
|
845
1029
|
* Begin a query against a table.
|
|
846
1030
|
*
|
|
@@ -1450,4 +1634,4 @@ declare const substring: (attribute: string, from: number, length: number) => st
|
|
|
1450
1634
|
declare const replace: (attribute: string, pattern: string, repl: string) => string;
|
|
1451
1635
|
declare const percentile: (attribute: string, p: number) => string;
|
|
1452
1636
|
|
|
1453
|
-
export {
|
|
1637
|
+
export { type SchemaDiff as $, type AiRequestOptions as A, type SchemaDataType as B, type SchemaIdentifierGenerator as C, type SchemaIdentifier as D, type SchemaAttribute as E, type FullTextQuery as F, type SchemaIndexType as G, type SchemaIndex as H, type IOnyxDatabase as I, type SchemaResolver as J, type SchemaTriggerEvent as K, type SchemaTrigger as L, type SchemaEntity as M, type SchemaRevisionMetadata as N, type OnyxFacade as O, type SchemaRevision as P, QueryResults as Q, type RetryOptions as R, type SecretMetadata as S, type SchemaHistoryEntry as T, type SchemaUpsertRequest as U, type SchemaValidationResult as V, type SchemaAttributeChange as W, type SchemaIndexChange as X, type SchemaResolverChange as Y, type SchemaTriggerChange as Z, type SchemaTableDiff as _, type QueryResultsPromise as a, type QueryCriteriaOperator as a0, type LogicalOperator as a1, type Sort as a2, type StreamAction as a3, type OnyxDocument as a4, type FetchResponse as a5, type FetchImpl as a6, type QueryCriteria as a7, type QueryCondition as a8, type SelectQuery as a9, containsIgnoreCase as aA, notContains as aB, notContainsIgnoreCase as aC, startsWith as aD, notStartsWith as aE, isNull as aF, notNull as aG, avg as aH, sum as aI, count as aJ, min as aK, max as aL, std as aM, variance as aN, median as aO, upper as aP, lower as aQ, substring as aR, replace as aS, percentile as aT, type UpdateQuery as aa, type QueryPage as ab, type IConditionBuilder as ac, type IQueryBuilder as ad, type ISaveBuilder as ae, type ICascadeBuilder as af, type ICascadeRelationshipBuilder as ag, asc as ah, desc as ai, eq as aj, neq as ak, inOp as al, within as am, notIn as an, notWithin as ao, between as ap, gt as aq, gte as ar, lt as as, lte as at, matches as au, search as av, notMatches as aw, like as ax, notLike as ay, contains 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, type AiChatCompletionChunkDelta as n, type AiChatCompletionChunkChoice as o, type AiChatCompletionChunk as p, type AiChatCompletionStream as q, type AiChatClient as r, type AiScriptApprovalRequest as s, type AiScriptApprovalResponse as t, type AiModelsResponse as u, type AiModel as v, type AiErrorResponse as w, type SecretRecord as x, type SecretsListResponse as y, type SecretSaveRequest as z };
|
|
@@ -814,6 +814,10 @@ interface RetryOptions {
|
|
|
814
814
|
}
|
|
815
815
|
interface OnyxConfig {
|
|
816
816
|
baseUrl?: string;
|
|
817
|
+
/**
|
|
818
|
+
* Base URL for AI endpoints. Defaults to https://ai.onyx.dev.
|
|
819
|
+
*/
|
|
820
|
+
aiBaseUrl?: string;
|
|
817
821
|
databaseId?: string;
|
|
818
822
|
apiKey?: string;
|
|
819
823
|
apiSecret?: string;
|
|
@@ -840,7 +844,187 @@ interface OnyxConfig {
|
|
|
840
844
|
*/
|
|
841
845
|
retry?: RetryOptions;
|
|
842
846
|
}
|
|
847
|
+
interface AiRequestOptions {
|
|
848
|
+
/**
|
|
849
|
+
* Optional database scope for AI calls. Defaults to the configured databaseId.
|
|
850
|
+
*/
|
|
851
|
+
databaseId?: string;
|
|
852
|
+
}
|
|
853
|
+
type AiChatRole = 'system' | 'user' | 'assistant' | 'tool';
|
|
854
|
+
interface AiToolCallFunction {
|
|
855
|
+
name: string;
|
|
856
|
+
arguments: string;
|
|
857
|
+
}
|
|
858
|
+
interface AiToolCall {
|
|
859
|
+
id?: string | null;
|
|
860
|
+
type?: string | null;
|
|
861
|
+
function: AiToolCallFunction;
|
|
862
|
+
}
|
|
863
|
+
interface AiChatMessage {
|
|
864
|
+
role: AiChatRole;
|
|
865
|
+
content?: string | null;
|
|
866
|
+
tool_calls?: AiToolCall[] | null;
|
|
867
|
+
tool_call_id?: string | null;
|
|
868
|
+
name?: string | null;
|
|
869
|
+
}
|
|
870
|
+
interface AiToolFunction {
|
|
871
|
+
name: string;
|
|
872
|
+
description?: string | null;
|
|
873
|
+
parameters?: Record<string, unknown> | null;
|
|
874
|
+
}
|
|
875
|
+
interface AiTool {
|
|
876
|
+
type: string;
|
|
877
|
+
function: AiToolFunction;
|
|
878
|
+
}
|
|
879
|
+
type AiToolChoice = 'none' | 'auto' | {
|
|
880
|
+
type: 'function';
|
|
881
|
+
function: {
|
|
882
|
+
name: string;
|
|
883
|
+
};
|
|
884
|
+
} | null;
|
|
885
|
+
interface AiChatCompletionRequest {
|
|
886
|
+
model: string;
|
|
887
|
+
messages: AiChatMessage[];
|
|
888
|
+
stream?: boolean;
|
|
889
|
+
temperature?: number | null;
|
|
890
|
+
top_p?: number | null;
|
|
891
|
+
max_tokens?: number | null;
|
|
892
|
+
metadata?: Record<string, unknown>;
|
|
893
|
+
tools?: AiTool[];
|
|
894
|
+
tool_choice?: AiToolChoice;
|
|
895
|
+
user?: string | null;
|
|
896
|
+
}
|
|
897
|
+
interface AiChatCompletionUsage {
|
|
898
|
+
prompt_tokens?: number | null;
|
|
899
|
+
completion_tokens?: number | null;
|
|
900
|
+
total_tokens?: number | null;
|
|
901
|
+
}
|
|
902
|
+
interface AiChatCompletionChoice {
|
|
903
|
+
index: number;
|
|
904
|
+
message: AiChatMessage;
|
|
905
|
+
finish_reason?: string | null;
|
|
906
|
+
}
|
|
907
|
+
interface AiChatCompletionResponse {
|
|
908
|
+
id: string;
|
|
909
|
+
object: string;
|
|
910
|
+
created: number;
|
|
911
|
+
model: string;
|
|
912
|
+
choices: AiChatCompletionChoice[];
|
|
913
|
+
usage?: AiChatCompletionUsage;
|
|
914
|
+
}
|
|
915
|
+
interface AiChatCompletionChunkDelta {
|
|
916
|
+
role?: AiChatRole | null;
|
|
917
|
+
content?: string | null;
|
|
918
|
+
tool_calls?: AiToolCall[] | null;
|
|
919
|
+
tool_call_id?: string | null;
|
|
920
|
+
name?: string | null;
|
|
921
|
+
}
|
|
922
|
+
interface AiChatCompletionChunkChoice {
|
|
923
|
+
index: number;
|
|
924
|
+
delta: AiChatCompletionChunkDelta;
|
|
925
|
+
finish_reason?: string | null;
|
|
926
|
+
}
|
|
927
|
+
interface AiChatCompletionChunk {
|
|
928
|
+
id: string;
|
|
929
|
+
object: string;
|
|
930
|
+
created: number;
|
|
931
|
+
model?: string | null;
|
|
932
|
+
choices: AiChatCompletionChunkChoice[];
|
|
933
|
+
}
|
|
934
|
+
interface AiChatCompletionStream extends AsyncIterable<AiChatCompletionChunk> {
|
|
935
|
+
cancel(): void;
|
|
936
|
+
}
|
|
937
|
+
interface AiChatClient {
|
|
938
|
+
create(request: AiChatCompletionRequest & {
|
|
939
|
+
stream?: false;
|
|
940
|
+
}, options?: AiRequestOptions): Promise<AiChatCompletionResponse>;
|
|
941
|
+
create(request: AiChatCompletionRequest & {
|
|
942
|
+
stream: true;
|
|
943
|
+
}, options?: AiRequestOptions): Promise<AiChatCompletionStream>;
|
|
944
|
+
create(request: AiChatCompletionRequest, options?: AiRequestOptions): Promise<AiChatCompletionResponse | AiChatCompletionStream>;
|
|
945
|
+
}
|
|
946
|
+
interface AiScriptApprovalRequest {
|
|
947
|
+
script: string;
|
|
948
|
+
}
|
|
949
|
+
interface AiScriptApprovalResponse {
|
|
950
|
+
normalizedScript: string;
|
|
951
|
+
expiresAtIso: string;
|
|
952
|
+
requiresApproval: boolean;
|
|
953
|
+
findings?: string;
|
|
954
|
+
}
|
|
955
|
+
interface AiModelsResponse {
|
|
956
|
+
object: string;
|
|
957
|
+
data: AiModel[];
|
|
958
|
+
}
|
|
959
|
+
interface AiModel {
|
|
960
|
+
id: string;
|
|
961
|
+
object: string;
|
|
962
|
+
created: number;
|
|
963
|
+
owned_by: string;
|
|
964
|
+
}
|
|
965
|
+
interface AiErrorResponse {
|
|
966
|
+
error?: string | {
|
|
967
|
+
message?: string;
|
|
968
|
+
[key: string]: unknown;
|
|
969
|
+
} | null;
|
|
970
|
+
}
|
|
843
971
|
interface IOnyxDatabase<Schema = Record<string, unknown>> {
|
|
972
|
+
/**
|
|
973
|
+
* Access OpenAI-compatible chat completions.
|
|
974
|
+
*
|
|
975
|
+
* @example
|
|
976
|
+
* ```ts
|
|
977
|
+
* const chat = db.chat();
|
|
978
|
+
* const completion = await chat.create({
|
|
979
|
+
* model: 'onyx-chat',
|
|
980
|
+
* messages: [{ role: 'user', content: 'Summarize last week.' }],
|
|
981
|
+
* });
|
|
982
|
+
* ```
|
|
983
|
+
*
|
|
984
|
+
* @example
|
|
985
|
+
* ```ts
|
|
986
|
+
* const stream = await db
|
|
987
|
+
* .chat()
|
|
988
|
+
* .create({
|
|
989
|
+
* model: 'onyx-chat',
|
|
990
|
+
* stream: true,
|
|
991
|
+
* messages: [{ role: 'user', content: 'Draft an onboarding checklist.' }],
|
|
992
|
+
* });
|
|
993
|
+
* for await (const chunk of stream) {
|
|
994
|
+
* process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
|
|
995
|
+
* }
|
|
996
|
+
* ```
|
|
997
|
+
*/
|
|
998
|
+
chat(): AiChatClient;
|
|
999
|
+
/**
|
|
1000
|
+
* List available AI models.
|
|
1001
|
+
*
|
|
1002
|
+
* @example
|
|
1003
|
+
* ```ts
|
|
1004
|
+
* const models = await db.getModels();
|
|
1005
|
+
* ```
|
|
1006
|
+
*/
|
|
1007
|
+
getModels(): Promise<AiModelsResponse>;
|
|
1008
|
+
/**
|
|
1009
|
+
* Retrieve a single AI model by ID.
|
|
1010
|
+
*
|
|
1011
|
+
* @example
|
|
1012
|
+
* ```ts
|
|
1013
|
+
* const model = await db.getModel('onyx-chat');
|
|
1014
|
+
* ```
|
|
1015
|
+
*/
|
|
1016
|
+
getModel(modelId: string): Promise<AiModel>;
|
|
1017
|
+
/**
|
|
1018
|
+
* Request mutation approval for a script.
|
|
1019
|
+
*
|
|
1020
|
+
* @example
|
|
1021
|
+
* ```ts
|
|
1022
|
+
* const approval = await db.requestScriptApproval({
|
|
1023
|
+
* script: "db.save({ id: 'u1', email: 'a@b.com' })"
|
|
1024
|
+
* });
|
|
1025
|
+
* ```
|
|
1026
|
+
*/
|
|
1027
|
+
requestScriptApproval(input: AiScriptApprovalRequest): Promise<AiScriptApprovalResponse>;
|
|
844
1028
|
/**
|
|
845
1029
|
* Begin a query against a table.
|
|
846
1030
|
*
|
|
@@ -1450,4 +1634,4 @@ declare const substring: (attribute: string, from: number, length: number) => st
|
|
|
1450
1634
|
declare const replace: (attribute: string, pattern: string, repl: string) => string;
|
|
1451
1635
|
declare const percentile: (attribute: string, p: number) => string;
|
|
1452
1636
|
|
|
1453
|
-
export {
|
|
1637
|
+
export { type SchemaDiff as $, type AiRequestOptions as A, type SchemaDataType as B, type SchemaIdentifierGenerator as C, type SchemaIdentifier as D, type SchemaAttribute as E, type FullTextQuery as F, type SchemaIndexType as G, type SchemaIndex as H, type IOnyxDatabase as I, type SchemaResolver as J, type SchemaTriggerEvent as K, type SchemaTrigger as L, type SchemaEntity as M, type SchemaRevisionMetadata as N, type OnyxFacade as O, type SchemaRevision as P, QueryResults as Q, type RetryOptions as R, type SecretMetadata as S, type SchemaHistoryEntry as T, type SchemaUpsertRequest as U, type SchemaValidationResult as V, type SchemaAttributeChange as W, type SchemaIndexChange as X, type SchemaResolverChange as Y, type SchemaTriggerChange as Z, type SchemaTableDiff as _, type QueryResultsPromise as a, type QueryCriteriaOperator as a0, type LogicalOperator as a1, type Sort as a2, type StreamAction as a3, type OnyxDocument as a4, type FetchResponse as a5, type FetchImpl as a6, type QueryCriteria as a7, type QueryCondition as a8, type SelectQuery as a9, containsIgnoreCase as aA, notContains as aB, notContainsIgnoreCase as aC, startsWith as aD, notStartsWith as aE, isNull as aF, notNull as aG, avg as aH, sum as aI, count as aJ, min as aK, max as aL, std as aM, variance as aN, median as aO, upper as aP, lower as aQ, substring as aR, replace as aS, percentile as aT, type UpdateQuery as aa, type QueryPage as ab, type IConditionBuilder as ac, type IQueryBuilder as ad, type ISaveBuilder as ae, type ICascadeBuilder as af, type ICascadeRelationshipBuilder as ag, asc as ah, desc as ai, eq as aj, neq as ak, inOp as al, within as am, notIn as an, notWithin as ao, between as ap, gt as aq, gte as ar, lt as as, lte as at, matches as au, search as av, notMatches as aw, like as ax, notLike as ay, contains 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, type AiChatCompletionChunkDelta as n, type AiChatCompletionChunkChoice as o, type AiChatCompletionChunk as p, type AiChatCompletionStream as q, type AiChatClient as r, type AiScriptApprovalRequest as s, type AiScriptApprovalResponse as t, type AiModelsResponse as u, type AiModel as v, type AiErrorResponse as w, type SecretRecord as x, type SecretsListResponse as y, type SecretSaveRequest as z };
|