@onyx.dev/onyx-database 2.1.0 → 2.3.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 +27 -1
- package/dist/{aggregates-DREvey7b.d.cts → aggregates-BpGa31jk.d.cts} +46 -2
- package/dist/{aggregates-DREvey7b.d.ts → aggregates-BpGa31jk.d.ts} +46 -2
- package/dist/edge.cjs +22 -2
- 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 +22 -2
- package/dist/edge.js.map +1 -1
- package/dist/gen/cli/generate.cjs +26 -7
- package/dist/gen/cli/generate.cjs.map +1 -1
- package/dist/index.cjs +22 -2
- 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 +22 -2
- package/dist/index.js.map +1 -1
- package/dist/schema/cli/schema.cjs +21 -1
- package/dist/schema/cli/schema.cjs.map +1 -1
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -19,6 +19,7 @@ TypeScript client SDK for **Onyx Cloud Database** — a zero-dependency, strict-
|
|
|
19
19
|
- [Install](#install)
|
|
20
20
|
- [Initialize the client](#initialize-the-client)
|
|
21
21
|
- [Onyx AI (chat & models)](#onyx-ai-chat--models)
|
|
22
|
+
- [Published model predictions](#published-model-predictions)
|
|
22
23
|
- [Generate schema types](#optional-generate-typescript-types-from-your-schema)
|
|
23
24
|
- [Query helpers](#query-helpers-at-a-glance)
|
|
24
25
|
- [Full-text search](#full-text-search-lucene)
|
|
@@ -91,7 +92,7 @@ Set these environment variables for your database:
|
|
|
91
92
|
|
|
92
93
|
| Variable | Purpose | Default when unset |
|
|
93
94
|
| --- | --- | --- |
|
|
94
|
-
| `ONYX_DATABASE_ID` |
|
|
95
|
+
| `ONYX_DATABASE_ID` | Optional database scope for env credentials; omit to use file/profile/default context | optional |
|
|
95
96
|
| `ONYX_DATABASE_BASE_URL` | Base URL for DB API | `https://api.onyx.dev` |
|
|
96
97
|
| `ONYX_DATABASE_API_KEY` | API key | required |
|
|
97
98
|
| `ONYX_DATABASE_API_SECRET` | API secret | required |
|
|
@@ -317,6 +318,31 @@ if (approval.requiresApproval) {
|
|
|
317
318
|
|
|
318
319
|
---
|
|
319
320
|
|
|
321
|
+
## Published model predictions
|
|
322
|
+
|
|
323
|
+
Use a published model key with raw input rows, or let a saved script provide the
|
|
324
|
+
input rows for prediction.
|
|
325
|
+
|
|
326
|
+
```ts
|
|
327
|
+
const rawPrediction = await db.predict('churn-model', [
|
|
328
|
+
{ age: 42, country: 'US', usageScore: 0.87 },
|
|
329
|
+
{ age: 31, country: 'CA', usageScore: 0.42 },
|
|
330
|
+
]);
|
|
331
|
+
|
|
332
|
+
console.log(rawPrediction.predictions);
|
|
333
|
+
console.log(rawPrediction.rawPredictions);
|
|
334
|
+
|
|
335
|
+
const scriptPrediction = await db.predictFromScript(
|
|
336
|
+
'churn-model',
|
|
337
|
+
'score-active-users',
|
|
338
|
+
{ segment: 'enterprise' },
|
|
339
|
+
);
|
|
340
|
+
|
|
341
|
+
console.log(scriptPrediction.inputCount);
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
---
|
|
345
|
+
|
|
320
346
|
## Optional: generate TypeScript types from your schema
|
|
321
347
|
|
|
322
348
|
Use the **Onyx CLI** (`onyx`) from <https://github.com/OnyxDevTools/onyx-cli> to
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
var name = "@onyx.dev/onyx-database";
|
|
2
|
-
var version = "2.
|
|
2
|
+
var version = "2.3.0";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Supported operators for building query criteria.
|
|
@@ -997,6 +997,25 @@ interface AiErrorResponse {
|
|
|
997
997
|
[key: string]: unknown;
|
|
998
998
|
} | null;
|
|
999
999
|
}
|
|
1000
|
+
type PublishedModelPredictionInput = Record<string, unknown>;
|
|
1001
|
+
type PublishedModelPredictionInputs = PublishedModelPredictionInput | PublishedModelPredictionInput[];
|
|
1002
|
+
interface PublishedModelRawPredictionRequest {
|
|
1003
|
+
inputs: PublishedModelPredictionInputs;
|
|
1004
|
+
}
|
|
1005
|
+
interface PublishedModelScriptPredictionRequest {
|
|
1006
|
+
scriptId: string;
|
|
1007
|
+
scriptParameters?: Record<string, string>;
|
|
1008
|
+
}
|
|
1009
|
+
interface PublishedModelPredictionResponse {
|
|
1010
|
+
publishedModelId: string;
|
|
1011
|
+
modelId: string;
|
|
1012
|
+
inputCount: number;
|
|
1013
|
+
inputs: PublishedModelPredictionInput[];
|
|
1014
|
+
predictions: PublishedModelPredictionInput[];
|
|
1015
|
+
rawPredictions: number[][];
|
|
1016
|
+
scriptId?: string | null;
|
|
1017
|
+
scriptParameters: Record<string, string>;
|
|
1018
|
+
}
|
|
1000
1019
|
interface AiClient {
|
|
1001
1020
|
/**
|
|
1002
1021
|
* Run a chat completion. Accepts shorthand strings or full requests.
|
|
@@ -1151,6 +1170,31 @@ interface IOnyxDatabase<Schema = Record<string, unknown>> {
|
|
|
1151
1170
|
* ```
|
|
1152
1171
|
*/
|
|
1153
1172
|
requestScriptApproval(input: AiScriptApprovalRequest): Promise<AiScriptApprovalResponse>;
|
|
1173
|
+
/**
|
|
1174
|
+
* Predict with a published model using raw input data.
|
|
1175
|
+
*
|
|
1176
|
+
* @example
|
|
1177
|
+
* ```ts
|
|
1178
|
+
* const prediction = await db.predict('churn-model', {
|
|
1179
|
+
* age: 42,
|
|
1180
|
+
* country: 'US'
|
|
1181
|
+
* });
|
|
1182
|
+
* ```
|
|
1183
|
+
*/
|
|
1184
|
+
predict(publishedModelId: string, inputs: PublishedModelPredictionInputs): Promise<PublishedModelPredictionResponse>;
|
|
1185
|
+
/**
|
|
1186
|
+
* Predict with a published model using rows returned from a saved script.
|
|
1187
|
+
*
|
|
1188
|
+
* @example
|
|
1189
|
+
* ```ts
|
|
1190
|
+
* const prediction = await db.predictFromScript(
|
|
1191
|
+
* 'churn-model',
|
|
1192
|
+
* 'score-active-users',
|
|
1193
|
+
* { segment: 'enterprise' }
|
|
1194
|
+
* );
|
|
1195
|
+
* ```
|
|
1196
|
+
*/
|
|
1197
|
+
predictFromScript(publishedModelId: string, scriptId: string, scriptParameters?: Record<string, string>): Promise<PublishedModelPredictionResponse>;
|
|
1154
1198
|
/**
|
|
1155
1199
|
* Begin a query against a table.
|
|
1156
1200
|
*
|
|
@@ -1761,4 +1805,4 @@ declare const replace: (attribute: string, pattern: string, repl: string) => str
|
|
|
1761
1805
|
declare const format: (attribute: string, formatter: string) => string;
|
|
1762
1806
|
declare const percentile: (attribute: string, p: number) => string;
|
|
1763
1807
|
|
|
1764
|
-
export { type
|
|
1808
|
+
export { type SchemaEntity as $, type AiChatClient as A, type IConditionBuilder as B, type IOnyxDatabase as C, type IQueryBuilder as D, type ISaveBuilder as E, type FetchImpl as F, type OnyxConfig as G, type OnyxDocument as H, type ICascadeBuilder as I, type PublishedModelPredictionInputs as J, type PublishedModelPredictionResponse as K, type LogicalOperator as L, type PublishedModelRawPredictionRequest as M, type PublishedModelScriptPredictionRequest as N, type OnyxFacade as O, type PublishedModelPredictionInput as P, type QueryCondition as Q, type QueryCriteria as R, type QueryCriteriaOperator as S, type QueryPage as T, QueryResults as U, type QueryResultsPromise as V, type RetryOptions as W, type SchemaAttribute as X, type SchemaAttributeChange as Y, type SchemaDataType as Z, type SchemaDiff as _, type AiChatCompletionChoice as a, upper as a$, type SchemaHistoryEntry as a0, type SchemaIdentifier as a1, type SchemaIdentifierGenerator as a2, type SchemaIndex as a3, type SchemaIndexChange as a4, type SchemaIndexType as a5, type SchemaResolver as a6, type SchemaResolverChange as a7, type SchemaRevision as a8, type SchemaRevisionMetadata as a9, isNull as aA, like as aB, lower as aC, lt as aD, lte as aE, matches as aF, max as aG, median as aH, min as aI, neq as aJ, notContains as aK, notContainsIgnoreCase as aL, notIn as aM, notLike as aN, notMatches as aO, notNull as aP, notStartsWith as aQ, notWithin as aR, percentile as aS, replace as aT, name as aU, version as aV, search as aW, startsWith as aX, std as aY, substring as aZ, sum as a_, type SchemaTableDiff as aa, type SchemaTrigger as ab, type SchemaTriggerChange as ac, type SchemaTriggerEvent as ad, type SchemaUpsertRequest as ae, type SchemaValidationResult as af, type SecretMetadata as ag, type SecretRecord as ah, type SecretSaveRequest as ai, type SecretsListResponse as aj, type SelectQuery as ak, type Sort as al, type StreamAction as am, type UpdateQuery as an, asc as ao, avg as ap, between as aq, contains as ar, containsIgnoreCase as as, count as at, desc as au, eq as av, format as aw, gt as ax, gte as ay, inOp as az, type AiChatCompletionChunk as b, variance as b0, within as b1, type AiChatCompletionChunkChoice as c, type AiChatCompletionChunkDelta as d, type AiChatCompletionRequest as e, type AiChatCompletionResponse as f, type AiChatCompletionStream as g, type AiChatCompletionUsage as h, type AiChatMessage as i, type AiChatOptions as j, type AiChatRole as k, type AiClient as l, type AiErrorResponse as m, type AiModel as n, type AiModelsResponse as o, type AiRequestOptions as p, type AiScriptApprovalRequest as q, type AiScriptApprovalResponse as r, type AiTool as s, type AiToolCall as t, type AiToolCallFunction as u, type AiToolChoice as v, type AiToolFunction as w, type FetchResponse as x, type FullTextQuery as y, type ICascadeRelationshipBuilder as z };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
var name = "@onyx.dev/onyx-database";
|
|
2
|
-
var version = "2.
|
|
2
|
+
var version = "2.3.0";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Supported operators for building query criteria.
|
|
@@ -997,6 +997,25 @@ interface AiErrorResponse {
|
|
|
997
997
|
[key: string]: unknown;
|
|
998
998
|
} | null;
|
|
999
999
|
}
|
|
1000
|
+
type PublishedModelPredictionInput = Record<string, unknown>;
|
|
1001
|
+
type PublishedModelPredictionInputs = PublishedModelPredictionInput | PublishedModelPredictionInput[];
|
|
1002
|
+
interface PublishedModelRawPredictionRequest {
|
|
1003
|
+
inputs: PublishedModelPredictionInputs;
|
|
1004
|
+
}
|
|
1005
|
+
interface PublishedModelScriptPredictionRequest {
|
|
1006
|
+
scriptId: string;
|
|
1007
|
+
scriptParameters?: Record<string, string>;
|
|
1008
|
+
}
|
|
1009
|
+
interface PublishedModelPredictionResponse {
|
|
1010
|
+
publishedModelId: string;
|
|
1011
|
+
modelId: string;
|
|
1012
|
+
inputCount: number;
|
|
1013
|
+
inputs: PublishedModelPredictionInput[];
|
|
1014
|
+
predictions: PublishedModelPredictionInput[];
|
|
1015
|
+
rawPredictions: number[][];
|
|
1016
|
+
scriptId?: string | null;
|
|
1017
|
+
scriptParameters: Record<string, string>;
|
|
1018
|
+
}
|
|
1000
1019
|
interface AiClient {
|
|
1001
1020
|
/**
|
|
1002
1021
|
* Run a chat completion. Accepts shorthand strings or full requests.
|
|
@@ -1151,6 +1170,31 @@ interface IOnyxDatabase<Schema = Record<string, unknown>> {
|
|
|
1151
1170
|
* ```
|
|
1152
1171
|
*/
|
|
1153
1172
|
requestScriptApproval(input: AiScriptApprovalRequest): Promise<AiScriptApprovalResponse>;
|
|
1173
|
+
/**
|
|
1174
|
+
* Predict with a published model using raw input data.
|
|
1175
|
+
*
|
|
1176
|
+
* @example
|
|
1177
|
+
* ```ts
|
|
1178
|
+
* const prediction = await db.predict('churn-model', {
|
|
1179
|
+
* age: 42,
|
|
1180
|
+
* country: 'US'
|
|
1181
|
+
* });
|
|
1182
|
+
* ```
|
|
1183
|
+
*/
|
|
1184
|
+
predict(publishedModelId: string, inputs: PublishedModelPredictionInputs): Promise<PublishedModelPredictionResponse>;
|
|
1185
|
+
/**
|
|
1186
|
+
* Predict with a published model using rows returned from a saved script.
|
|
1187
|
+
*
|
|
1188
|
+
* @example
|
|
1189
|
+
* ```ts
|
|
1190
|
+
* const prediction = await db.predictFromScript(
|
|
1191
|
+
* 'churn-model',
|
|
1192
|
+
* 'score-active-users',
|
|
1193
|
+
* { segment: 'enterprise' }
|
|
1194
|
+
* );
|
|
1195
|
+
* ```
|
|
1196
|
+
*/
|
|
1197
|
+
predictFromScript(publishedModelId: string, scriptId: string, scriptParameters?: Record<string, string>): Promise<PublishedModelPredictionResponse>;
|
|
1154
1198
|
/**
|
|
1155
1199
|
* Begin a query against a table.
|
|
1156
1200
|
*
|
|
@@ -1761,4 +1805,4 @@ declare const replace: (attribute: string, pattern: string, repl: string) => str
|
|
|
1761
1805
|
declare const format: (attribute: string, formatter: string) => string;
|
|
1762
1806
|
declare const percentile: (attribute: string, p: number) => string;
|
|
1763
1807
|
|
|
1764
|
-
export { type
|
|
1808
|
+
export { type SchemaEntity as $, type AiChatClient as A, type IConditionBuilder as B, type IOnyxDatabase as C, type IQueryBuilder as D, type ISaveBuilder as E, type FetchImpl as F, type OnyxConfig as G, type OnyxDocument as H, type ICascadeBuilder as I, type PublishedModelPredictionInputs as J, type PublishedModelPredictionResponse as K, type LogicalOperator as L, type PublishedModelRawPredictionRequest as M, type PublishedModelScriptPredictionRequest as N, type OnyxFacade as O, type PublishedModelPredictionInput as P, type QueryCondition as Q, type QueryCriteria as R, type QueryCriteriaOperator as S, type QueryPage as T, QueryResults as U, type QueryResultsPromise as V, type RetryOptions as W, type SchemaAttribute as X, type SchemaAttributeChange as Y, type SchemaDataType as Z, type SchemaDiff as _, type AiChatCompletionChoice as a, upper as a$, type SchemaHistoryEntry as a0, type SchemaIdentifier as a1, type SchemaIdentifierGenerator as a2, type SchemaIndex as a3, type SchemaIndexChange as a4, type SchemaIndexType as a5, type SchemaResolver as a6, type SchemaResolverChange as a7, type SchemaRevision as a8, type SchemaRevisionMetadata as a9, isNull as aA, like as aB, lower as aC, lt as aD, lte as aE, matches as aF, max as aG, median as aH, min as aI, neq as aJ, notContains as aK, notContainsIgnoreCase as aL, notIn as aM, notLike as aN, notMatches as aO, notNull as aP, notStartsWith as aQ, notWithin as aR, percentile as aS, replace as aT, name as aU, version as aV, search as aW, startsWith as aX, std as aY, substring as aZ, sum as a_, type SchemaTableDiff as aa, type SchemaTrigger as ab, type SchemaTriggerChange as ac, type SchemaTriggerEvent as ad, type SchemaUpsertRequest as ae, type SchemaValidationResult as af, type SecretMetadata as ag, type SecretRecord as ah, type SecretSaveRequest as ai, type SecretsListResponse as aj, type SelectQuery as ak, type Sort as al, type StreamAction as am, type UpdateQuery as an, asc as ao, avg as ap, between as aq, contains as ar, containsIgnoreCase as as, count as at, desc as au, eq as av, format as aw, gt as ax, gte as ay, inOp as az, type AiChatCompletionChunk as b, variance as b0, within as b1, type AiChatCompletionChunkChoice as c, type AiChatCompletionChunkDelta as d, type AiChatCompletionRequest as e, type AiChatCompletionResponse as f, type AiChatCompletionStream as g, type AiChatCompletionUsage as h, type AiChatMessage as i, type AiChatOptions as j, type AiChatRole as k, type AiClient as l, type AiErrorResponse as m, type AiModel as n, type AiModelsResponse as o, type AiRequestOptions as p, type AiScriptApprovalRequest as q, type AiScriptApprovalResponse as r, type AiTool as s, type AiToolCall as t, type AiToolCallFunction as u, type AiToolChoice as v, type AiToolFunction as w, type FetchResponse as x, type FullTextQuery as y, type ICascadeRelationshipBuilder as z };
|
package/dist/edge.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// package.json
|
|
4
4
|
var name = "@onyx.dev/onyx-database";
|
|
5
|
-
var version = "2.
|
|
5
|
+
var version = "2.3.0";
|
|
6
6
|
|
|
7
7
|
// src/config/defaults.ts
|
|
8
8
|
var DEFAULT_BASE_URL = "https://api.onyx.dev";
|
|
@@ -100,7 +100,6 @@ async function resolveConfig(input) {
|
|
|
100
100
|
const maxRetries = retryConfig.maxRetries ?? 3;
|
|
101
101
|
const retryInitialDelayMs = retryConfig.initialDelayMs ?? 300;
|
|
102
102
|
const missing = [];
|
|
103
|
-
if (!databaseId) missing.push("databaseId");
|
|
104
103
|
if (!apiKey) missing.push("apiKey");
|
|
105
104
|
if (!apiSecret) missing.push("apiSecret");
|
|
106
105
|
if (missing.length) {
|
|
@@ -1280,6 +1279,27 @@ var OnyxDatabaseImpl = class {
|
|
|
1280
1279
|
const { http } = await this.ensureAiClient();
|
|
1281
1280
|
return http.request("POST", "/api/script-approvals", input);
|
|
1282
1281
|
}
|
|
1282
|
+
async predict(publishedModelId, inputs) {
|
|
1283
|
+
const { http, databaseId } = await this.ensureClient();
|
|
1284
|
+
const path = `/data/${encodeURIComponent(
|
|
1285
|
+
databaseId
|
|
1286
|
+
)}/model-builder/published-model/${encodeURIComponent(publishedModelId)}/predict`;
|
|
1287
|
+
return http.request(
|
|
1288
|
+
"POST",
|
|
1289
|
+
path,
|
|
1290
|
+
serializeDates({ inputs })
|
|
1291
|
+
);
|
|
1292
|
+
}
|
|
1293
|
+
async predictFromScript(publishedModelId, scriptId, scriptParameters = {}) {
|
|
1294
|
+
const { http, databaseId } = await this.ensureClient();
|
|
1295
|
+
const path = `/data/${encodeURIComponent(
|
|
1296
|
+
databaseId
|
|
1297
|
+
)}/model-builder/published-model/${encodeURIComponent(publishedModelId)}/predict/script`;
|
|
1298
|
+
return http.request("POST", path, {
|
|
1299
|
+
scriptId,
|
|
1300
|
+
scriptParameters
|
|
1301
|
+
});
|
|
1302
|
+
}
|
|
1283
1303
|
from(table) {
|
|
1284
1304
|
return new QueryBuilderImpl(this, String(table), this.defaultPartition);
|
|
1285
1305
|
}
|