@onyx.dev/onyx-database 2.1.1 → 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 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)
@@ -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.1.1";
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 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 };
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.1.1";
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 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 };
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.1.1";
5
+ var version = "2.3.0";
6
6
 
7
7
  // src/config/defaults.ts
8
8
  var DEFAULT_BASE_URL = "https://api.onyx.dev";
@@ -1279,6 +1279,27 @@ var OnyxDatabaseImpl = class {
1279
1279
  const { http } = await this.ensureAiClient();
1280
1280
  return http.request("POST", "/api/script-approvals", input);
1281
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
+ }
1282
1303
  from(table) {
1283
1304
  return new QueryBuilderImpl(this, String(table), this.defaultPartition);
1284
1305
  }