@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/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { O as OnyxFacade } from './aggregates-
|
|
2
|
-
export {
|
|
1
|
+
import { O as OnyxFacade } from './aggregates-BPpzRHGH.cjs';
|
|
2
|
+
export { t as AiChatClient, l as AiChatCompletionChoice, q as AiChatCompletionChunk, p as AiChatCompletionChunkChoice, o as AiChatCompletionChunkDelta, j as AiChatCompletionRequest, m as AiChatCompletionResponse, r as AiChatCompletionStream, k as AiChatCompletionUsage, f as AiChatMessage, s as AiChatOptions, c as AiChatRole, B as AiClient, z as AiErrorResponse, y as AiModel, x as AiModelsResponse, A as AiRequestOptions, u as AiScriptApprovalRequest, w as AiScriptApprovalResponse, h as AiTool, e as AiToolCall, d as AiToolCallFunction, i as AiToolChoice, g as AiToolFunction, aa as FetchImpl, a9 as FetchResponse, F as FullTextQuery, aj as ICascadeBuilder, ak as ICascadeRelationshipBuilder, ag as IConditionBuilder, I as IOnyxDatabase, ah as IQueryBuilder, ai as ISaveBuilder, a5 as LogicalOperator, b as OnyxConfig, a8 as OnyxDocument, ac as QueryCondition, ab as QueryCriteria, a4 as QueryCriteriaOperator, af as QueryPage, Q as QueryResults, a as QueryResultsPromise, R as RetryOptions, K as SchemaAttribute, _ as SchemaAttributeChange, G as SchemaDataType, a3 as SchemaDiff, U as SchemaEntity, X as SchemaHistoryEntry, J as SchemaIdentifier, H as SchemaIdentifierGenerator, M as SchemaIndex, $ as SchemaIndexChange, L as SchemaIndexType, N as SchemaResolver, a0 as SchemaResolverChange, W as SchemaRevision, V as SchemaRevisionMetadata, a2 as SchemaTableDiff, T as SchemaTrigger, a1 as SchemaTriggerChange, P as SchemaTriggerEvent, Y as SchemaUpsertRequest, Z as SchemaValidationResult, S as SecretMetadata, C as SecretRecord, E as SecretSaveRequest, D as SecretsListResponse, ad as SelectQuery, a6 as Sort, a7 as StreamAction, ae as UpdateQuery, al as asc, aL as avg, at as between, aD as contains, aE as containsIgnoreCase, aN as count, am as desc, an as eq, aX as format, au as gt, av as gte, ap as inOp, aJ as isNull, aB as like, aU as lower, aw as lt, ax as lte, ay as matches, aP as max, aS as median, aO as min, ao as neq, aF as notContains, aG as notContainsIgnoreCase, ar as notIn, aC as notLike, aA as notMatches, aK as notNull, aI as notStartsWith, as as notWithin, aY as percentile, aW as replace, n as sdkName, v as sdkVersion, az as search, aH as startsWith, aQ as std, aV as substring, aM as sum, aT as upper, aR as variance, aq as within } from './aggregates-BPpzRHGH.cjs';
|
|
3
3
|
|
|
4
4
|
declare const onyx: OnyxFacade;
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
declare const sdkVersion = "0.1.0";
|
|
8
|
-
|
|
9
|
-
export { OnyxFacade, onyx, sdkName, sdkVersion };
|
|
6
|
+
export { OnyxFacade, onyx };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { O as OnyxFacade } from './aggregates-
|
|
2
|
-
export {
|
|
1
|
+
import { O as OnyxFacade } from './aggregates-BPpzRHGH.js';
|
|
2
|
+
export { t as AiChatClient, l as AiChatCompletionChoice, q as AiChatCompletionChunk, p as AiChatCompletionChunkChoice, o as AiChatCompletionChunkDelta, j as AiChatCompletionRequest, m as AiChatCompletionResponse, r as AiChatCompletionStream, k as AiChatCompletionUsage, f as AiChatMessage, s as AiChatOptions, c as AiChatRole, B as AiClient, z as AiErrorResponse, y as AiModel, x as AiModelsResponse, A as AiRequestOptions, u as AiScriptApprovalRequest, w as AiScriptApprovalResponse, h as AiTool, e as AiToolCall, d as AiToolCallFunction, i as AiToolChoice, g as AiToolFunction, aa as FetchImpl, a9 as FetchResponse, F as FullTextQuery, aj as ICascadeBuilder, ak as ICascadeRelationshipBuilder, ag as IConditionBuilder, I as IOnyxDatabase, ah as IQueryBuilder, ai as ISaveBuilder, a5 as LogicalOperator, b as OnyxConfig, a8 as OnyxDocument, ac as QueryCondition, ab as QueryCriteria, a4 as QueryCriteriaOperator, af as QueryPage, Q as QueryResults, a as QueryResultsPromise, R as RetryOptions, K as SchemaAttribute, _ as SchemaAttributeChange, G as SchemaDataType, a3 as SchemaDiff, U as SchemaEntity, X as SchemaHistoryEntry, J as SchemaIdentifier, H as SchemaIdentifierGenerator, M as SchemaIndex, $ as SchemaIndexChange, L as SchemaIndexType, N as SchemaResolver, a0 as SchemaResolverChange, W as SchemaRevision, V as SchemaRevisionMetadata, a2 as SchemaTableDiff, T as SchemaTrigger, a1 as SchemaTriggerChange, P as SchemaTriggerEvent, Y as SchemaUpsertRequest, Z as SchemaValidationResult, S as SecretMetadata, C as SecretRecord, E as SecretSaveRequest, D as SecretsListResponse, ad as SelectQuery, a6 as Sort, a7 as StreamAction, ae as UpdateQuery, al as asc, aL as avg, at as between, aD as contains, aE as containsIgnoreCase, aN as count, am as desc, an as eq, aX as format, au as gt, av as gte, ap as inOp, aJ as isNull, aB as like, aU as lower, aw as lt, ax as lte, ay as matches, aP as max, aS as median, aO as min, ao as neq, aF as notContains, aG as notContainsIgnoreCase, ar as notIn, aC as notLike, aA as notMatches, aK as notNull, aI as notStartsWith, as as notWithin, aY as percentile, aW as replace, n as sdkName, v as sdkVersion, az as search, aH as startsWith, aQ as std, aV as substring, aM as sum, aT as upper, aR as variance, aq as within } from './aggregates-BPpzRHGH.js';
|
|
3
3
|
|
|
4
4
|
declare const onyx: OnyxFacade;
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
declare const sdkVersion = "0.1.0";
|
|
8
|
-
|
|
9
|
-
export { OnyxFacade, onyx, sdkName, sdkVersion };
|
|
6
|
+
export { OnyxFacade, onyx };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
// package.json
|
|
2
|
+
var name = "@onyx.dev/onyx-database";
|
|
3
|
+
var version = "2.0.1";
|
|
4
|
+
|
|
1
5
|
// src/config/defaults.ts
|
|
2
6
|
var DEFAULT_BASE_URL = "https://api.onyx.dev";
|
|
3
7
|
var DEFAULT_AI_BASE_URL = "https://ai.onyx.dev";
|
|
8
|
+
var DEFAULT_AI_MODEL = "onyx";
|
|
4
9
|
var sanitizeBaseUrl = (u) => u.replace(/\/+$/, "");
|
|
5
10
|
|
|
6
11
|
// src/errors/config-error.ts
|
|
@@ -60,6 +65,7 @@ function readEnv(targetId) {
|
|
|
60
65
|
const res = dropUndefined({
|
|
61
66
|
baseUrl: pick("ONYX_DATABASE_BASE_URL"),
|
|
62
67
|
aiBaseUrl: pick("ONYX_AI_BASE_URL"),
|
|
68
|
+
defaultModel: pick("ONYX_DEFAULT_MODEL"),
|
|
63
69
|
databaseId: envId,
|
|
64
70
|
apiKey: pick("ONYX_DATABASE_API_KEY"),
|
|
65
71
|
apiSecret: pick("ONYX_DATABASE_API_SECRET")
|
|
@@ -197,6 +203,7 @@ async function resolveConfig(input) {
|
|
|
197
203
|
const merged = {
|
|
198
204
|
baseUrl: DEFAULT_BASE_URL,
|
|
199
205
|
aiBaseUrl: DEFAULT_AI_BASE_URL,
|
|
206
|
+
defaultModel: DEFAULT_AI_MODEL,
|
|
200
207
|
...dropUndefined(home),
|
|
201
208
|
...dropUndefined(project),
|
|
202
209
|
...dropUndefined(cfgPath),
|
|
@@ -206,6 +213,7 @@ async function resolveConfig(input) {
|
|
|
206
213
|
dbg("merged (pre-validate):", mask(merged));
|
|
207
214
|
const baseUrl = sanitizeBaseUrl(merged.baseUrl ?? DEFAULT_BASE_URL);
|
|
208
215
|
const aiBaseUrl = sanitizeBaseUrl(merged.aiBaseUrl ?? DEFAULT_AI_BASE_URL);
|
|
216
|
+
const defaultModel = typeof merged.defaultModel === "string" && merged.defaultModel.trim() ? merged.defaultModel.trim() : DEFAULT_AI_MODEL;
|
|
209
217
|
const databaseId = merged.databaseId ?? "";
|
|
210
218
|
const apiKey = merged.apiKey ?? "";
|
|
211
219
|
const apiSecret = merged.apiSecret ?? "";
|
|
@@ -242,6 +250,7 @@ async function resolveConfig(input) {
|
|
|
242
250
|
const resolved = {
|
|
243
251
|
baseUrl,
|
|
244
252
|
aiBaseUrl,
|
|
253
|
+
defaultModel,
|
|
245
254
|
databaseId,
|
|
246
255
|
apiKey,
|
|
247
256
|
apiSecret,
|
|
@@ -253,6 +262,7 @@ async function resolveConfig(input) {
|
|
|
253
262
|
const source = {
|
|
254
263
|
databaseId: input?.databaseId ? "explicit config" : env.databaseId ? "env" : cfgPath.databaseId ? "env ONYX_CONFIG_PATH" : project.databaseId ? "project file" : home.databaseId ? "home profile" : "unknown",
|
|
255
264
|
aiBaseUrl: input?.aiBaseUrl ? "explicit config" : env.aiBaseUrl ? "env" : cfgPath.aiBaseUrl ? "env ONYX_CONFIG_PATH" : project.aiBaseUrl ? "project file" : home.aiBaseUrl ? "home profile" : "default",
|
|
265
|
+
defaultModel: input?.defaultModel ? "explicit config" : env.defaultModel ? "env" : cfgPath.defaultModel ? "env ONYX_CONFIG_PATH" : project.defaultModel ? "project file" : home.defaultModel ? "home profile" : "default",
|
|
256
266
|
apiKey: input?.apiKey ? "explicit config" : env.apiKey ? "env" : cfgPath.apiKey ? "env ONYX_CONFIG_PATH" : project.apiKey ? "project file" : home.apiKey ? "home profile" : "unknown",
|
|
257
267
|
apiSecret: input?.apiSecret ? "explicit config" : env.apiSecret ? "env" : cfgPath.apiSecret ? "env ONYX_CONFIG_PATH" : project.apiSecret ? "project file" : home.apiSecret ? "home profile" : "unknown"
|
|
258
268
|
};
|
|
@@ -943,8 +953,8 @@ var CascadeRelationshipBuilder = class {
|
|
|
943
953
|
* builder.graph('programs');
|
|
944
954
|
* ```
|
|
945
955
|
*/
|
|
946
|
-
graph(
|
|
947
|
-
this.graphName =
|
|
956
|
+
graph(name2) {
|
|
957
|
+
this.graphName = name2;
|
|
948
958
|
return this;
|
|
949
959
|
}
|
|
950
960
|
/**
|
|
@@ -1031,24 +1041,24 @@ function diffAttributes(apiAttrs, localAttrs) {
|
|
|
1031
1041
|
const added = [];
|
|
1032
1042
|
const removed = [];
|
|
1033
1043
|
const changed = [];
|
|
1034
|
-
for (const [
|
|
1035
|
-
if (!apiMap.has(
|
|
1044
|
+
for (const [name2, local] of localMap.entries()) {
|
|
1045
|
+
if (!apiMap.has(name2)) {
|
|
1036
1046
|
added.push(local);
|
|
1037
1047
|
continue;
|
|
1038
1048
|
}
|
|
1039
|
-
const api = apiMap.get(
|
|
1049
|
+
const api = apiMap.get(name2);
|
|
1040
1050
|
const apiNull = Boolean(api.isNullable);
|
|
1041
1051
|
const localNull = Boolean(local.isNullable);
|
|
1042
1052
|
if (api.type !== local.type || apiNull !== localNull) {
|
|
1043
1053
|
changed.push({
|
|
1044
|
-
name,
|
|
1054
|
+
name: name2,
|
|
1045
1055
|
from: { type: api.type, isNullable: apiNull },
|
|
1046
1056
|
to: { type: local.type, isNullable: localNull }
|
|
1047
1057
|
});
|
|
1048
1058
|
}
|
|
1049
1059
|
}
|
|
1050
|
-
for (const
|
|
1051
|
-
if (!localMap.has(
|
|
1060
|
+
for (const name2 of apiMap.keys()) {
|
|
1061
|
+
if (!localMap.has(name2)) removed.push(name2);
|
|
1052
1062
|
}
|
|
1053
1063
|
added.sort((a, b) => a.name.localeCompare(b.name));
|
|
1054
1064
|
removed.sort();
|
|
@@ -1062,22 +1072,22 @@ function diffIndexes(apiIndexes, localIndexes) {
|
|
|
1062
1072
|
const added = [];
|
|
1063
1073
|
const removed = [];
|
|
1064
1074
|
const changed = [];
|
|
1065
|
-
for (const [
|
|
1066
|
-
if (!apiMap.has(
|
|
1075
|
+
for (const [name2, local] of localMap.entries()) {
|
|
1076
|
+
if (!apiMap.has(name2)) {
|
|
1067
1077
|
added.push(local);
|
|
1068
1078
|
continue;
|
|
1069
1079
|
}
|
|
1070
|
-
const api = apiMap.get(
|
|
1080
|
+
const api = apiMap.get(name2);
|
|
1071
1081
|
const apiType = api.type ?? "DEFAULT";
|
|
1072
1082
|
const localType = local.type ?? "DEFAULT";
|
|
1073
1083
|
const apiScore = api.minimumScore;
|
|
1074
1084
|
const localScore = local.minimumScore;
|
|
1075
1085
|
if (apiType !== localType || apiScore !== localScore) {
|
|
1076
|
-
changed.push({ name, from: api, to: local });
|
|
1086
|
+
changed.push({ name: name2, from: api, to: local });
|
|
1077
1087
|
}
|
|
1078
1088
|
}
|
|
1079
|
-
for (const
|
|
1080
|
-
if (!localMap.has(
|
|
1089
|
+
for (const name2 of apiMap.keys()) {
|
|
1090
|
+
if (!localMap.has(name2)) removed.push(name2);
|
|
1081
1091
|
}
|
|
1082
1092
|
added.sort((a, b) => a.name.localeCompare(b.name));
|
|
1083
1093
|
removed.sort();
|
|
@@ -1091,18 +1101,18 @@ function diffResolvers(apiResolvers, localResolvers) {
|
|
|
1091
1101
|
const added = [];
|
|
1092
1102
|
const removed = [];
|
|
1093
1103
|
const changed = [];
|
|
1094
|
-
for (const [
|
|
1095
|
-
if (!apiMap.has(
|
|
1104
|
+
for (const [name2, local] of localMap.entries()) {
|
|
1105
|
+
if (!apiMap.has(name2)) {
|
|
1096
1106
|
added.push(local);
|
|
1097
1107
|
continue;
|
|
1098
1108
|
}
|
|
1099
|
-
const api = apiMap.get(
|
|
1109
|
+
const api = apiMap.get(name2);
|
|
1100
1110
|
if (api.resolver !== local.resolver) {
|
|
1101
|
-
changed.push({ name, from: api, to: local });
|
|
1111
|
+
changed.push({ name: name2, from: api, to: local });
|
|
1102
1112
|
}
|
|
1103
1113
|
}
|
|
1104
|
-
for (const
|
|
1105
|
-
if (!localMap.has(
|
|
1114
|
+
for (const name2 of apiMap.keys()) {
|
|
1115
|
+
if (!localMap.has(name2)) removed.push(name2);
|
|
1106
1116
|
}
|
|
1107
1117
|
added.sort((a, b) => a.name.localeCompare(b.name));
|
|
1108
1118
|
removed.sort();
|
|
@@ -1116,18 +1126,18 @@ function diffTriggers(apiTriggers, localTriggers) {
|
|
|
1116
1126
|
const added = [];
|
|
1117
1127
|
const removed = [];
|
|
1118
1128
|
const changed = [];
|
|
1119
|
-
for (const [
|
|
1120
|
-
if (!apiMap.has(
|
|
1129
|
+
for (const [name2, local] of localMap.entries()) {
|
|
1130
|
+
if (!apiMap.has(name2)) {
|
|
1121
1131
|
added.push(local);
|
|
1122
1132
|
continue;
|
|
1123
1133
|
}
|
|
1124
|
-
const api = apiMap.get(
|
|
1134
|
+
const api = apiMap.get(name2);
|
|
1125
1135
|
if (api.event !== local.event || api.trigger !== local.trigger) {
|
|
1126
|
-
changed.push({ name, from: api, to: local });
|
|
1136
|
+
changed.push({ name: name2, from: api, to: local });
|
|
1127
1137
|
}
|
|
1128
1138
|
}
|
|
1129
|
-
for (const
|
|
1130
|
-
if (!localMap.has(
|
|
1139
|
+
for (const name2 of apiMap.keys()) {
|
|
1140
|
+
if (!localMap.has(name2)) removed.push(name2);
|
|
1131
1141
|
}
|
|
1132
1142
|
added.sort((a, b) => a.name.localeCompare(b.name));
|
|
1133
1143
|
removed.sort();
|
|
@@ -1143,13 +1153,13 @@ function computeSchemaDiff(apiSchema, localSchema) {
|
|
|
1143
1153
|
const newTables = [];
|
|
1144
1154
|
const removedTables = [];
|
|
1145
1155
|
const changedTables = [];
|
|
1146
|
-
for (const [
|
|
1147
|
-
if (!apiMap.has(
|
|
1148
|
-
newTables.push(
|
|
1156
|
+
for (const [name2, localEntity] of localMap.entries()) {
|
|
1157
|
+
if (!apiMap.has(name2)) {
|
|
1158
|
+
newTables.push(name2);
|
|
1149
1159
|
continue;
|
|
1150
1160
|
}
|
|
1151
|
-
const apiEntity = apiMap.get(
|
|
1152
|
-
const tableDiff = { name };
|
|
1161
|
+
const apiEntity = apiMap.get(name2);
|
|
1162
|
+
const tableDiff = { name: name2 };
|
|
1153
1163
|
const partitionFrom = normalizePartition(apiEntity.partition);
|
|
1154
1164
|
const partitionTo = normalizePartition(localEntity.partition);
|
|
1155
1165
|
if (partitionFrom !== partitionTo) {
|
|
@@ -1174,8 +1184,8 @@ function computeSchemaDiff(apiSchema, localSchema) {
|
|
|
1174
1184
|
changedTables.push(tableDiff);
|
|
1175
1185
|
}
|
|
1176
1186
|
}
|
|
1177
|
-
for (const
|
|
1178
|
-
if (!localMap.has(
|
|
1187
|
+
for (const name2 of apiMap.keys()) {
|
|
1188
|
+
if (!localMap.has(name2)) removedTables.push(name2);
|
|
1179
1189
|
}
|
|
1180
1190
|
newTables.sort();
|
|
1181
1191
|
removedTables.sort();
|
|
@@ -1275,58 +1285,64 @@ var OnyxDatabaseImpl = class {
|
|
|
1275
1285
|
requestLoggingEnabled;
|
|
1276
1286
|
responseLoggingEnabled;
|
|
1277
1287
|
defaultPartition;
|
|
1288
|
+
ai;
|
|
1278
1289
|
constructor(config, resolveConfigWithCache) {
|
|
1279
1290
|
this.requestLoggingEnabled = !!config?.requestLoggingEnabled;
|
|
1280
1291
|
this.responseLoggingEnabled = !!config?.responseLoggingEnabled;
|
|
1281
1292
|
this.defaultPartition = config?.partition;
|
|
1282
1293
|
this.cfgPromise = resolveConfigWithCache(config);
|
|
1294
|
+
this.ai = this.createAiFacade();
|
|
1283
1295
|
}
|
|
1284
|
-
async
|
|
1296
|
+
async resolveConfig() {
|
|
1285
1297
|
if (!this.resolved) {
|
|
1286
1298
|
this.resolved = await this.cfgPromise;
|
|
1287
1299
|
}
|
|
1300
|
+
return this.resolved;
|
|
1301
|
+
}
|
|
1302
|
+
async ensureClient() {
|
|
1303
|
+
const cfg = await this.resolveConfig();
|
|
1288
1304
|
if (!this.http) {
|
|
1289
1305
|
this.http = new HttpClient({
|
|
1290
|
-
baseUrl:
|
|
1291
|
-
apiKey:
|
|
1292
|
-
apiSecret:
|
|
1293
|
-
fetchImpl:
|
|
1306
|
+
baseUrl: cfg.baseUrl,
|
|
1307
|
+
apiKey: cfg.apiKey,
|
|
1308
|
+
apiSecret: cfg.apiSecret,
|
|
1309
|
+
fetchImpl: cfg.fetch,
|
|
1294
1310
|
requestLoggingEnabled: this.requestLoggingEnabled,
|
|
1295
1311
|
responseLoggingEnabled: this.responseLoggingEnabled,
|
|
1296
|
-
retryEnabled:
|
|
1297
|
-
maxRetries:
|
|
1298
|
-
retryInitialDelayMs:
|
|
1312
|
+
retryEnabled: cfg.retryEnabled,
|
|
1313
|
+
maxRetries: cfg.maxRetries,
|
|
1314
|
+
retryInitialDelayMs: cfg.retryInitialDelayMs
|
|
1299
1315
|
});
|
|
1300
1316
|
}
|
|
1301
1317
|
return {
|
|
1302
1318
|
http: this.http,
|
|
1303
|
-
fetchImpl:
|
|
1304
|
-
baseUrl:
|
|
1305
|
-
databaseId:
|
|
1319
|
+
fetchImpl: cfg.fetch,
|
|
1320
|
+
baseUrl: cfg.baseUrl,
|
|
1321
|
+
databaseId: cfg.databaseId,
|
|
1322
|
+
defaultModel: cfg.defaultModel ?? DEFAULT_AI_MODEL
|
|
1306
1323
|
};
|
|
1307
1324
|
}
|
|
1308
1325
|
async ensureAiClient() {
|
|
1309
|
-
|
|
1310
|
-
this.resolved = await this.cfgPromise;
|
|
1311
|
-
}
|
|
1326
|
+
const cfg = await this.resolveConfig();
|
|
1312
1327
|
if (!this.aiHttp) {
|
|
1313
1328
|
this.aiHttp = new HttpClient({
|
|
1314
|
-
baseUrl:
|
|
1315
|
-
apiKey:
|
|
1316
|
-
apiSecret:
|
|
1317
|
-
fetchImpl:
|
|
1329
|
+
baseUrl: cfg.aiBaseUrl,
|
|
1330
|
+
apiKey: cfg.apiKey,
|
|
1331
|
+
apiSecret: cfg.apiSecret,
|
|
1332
|
+
fetchImpl: cfg.fetch,
|
|
1318
1333
|
requestLoggingEnabled: this.requestLoggingEnabled,
|
|
1319
1334
|
responseLoggingEnabled: this.responseLoggingEnabled,
|
|
1320
|
-
retryEnabled:
|
|
1321
|
-
maxRetries:
|
|
1322
|
-
retryInitialDelayMs:
|
|
1335
|
+
retryEnabled: cfg.retryEnabled,
|
|
1336
|
+
maxRetries: cfg.maxRetries,
|
|
1337
|
+
retryInitialDelayMs: cfg.retryInitialDelayMs
|
|
1323
1338
|
});
|
|
1324
1339
|
}
|
|
1325
1340
|
return {
|
|
1326
1341
|
http: this.aiHttp,
|
|
1327
|
-
fetchImpl:
|
|
1328
|
-
aiBaseUrl:
|
|
1329
|
-
databaseId:
|
|
1342
|
+
fetchImpl: cfg.fetch,
|
|
1343
|
+
aiBaseUrl: cfg.aiBaseUrl,
|
|
1344
|
+
databaseId: cfg.databaseId,
|
|
1345
|
+
defaultModel: cfg.defaultModel ?? DEFAULT_AI_MODEL
|
|
1330
1346
|
};
|
|
1331
1347
|
}
|
|
1332
1348
|
registerStream(handle) {
|
|
@@ -1341,6 +1357,21 @@ var OnyxDatabaseImpl = class {
|
|
|
1341
1357
|
}
|
|
1342
1358
|
};
|
|
1343
1359
|
}
|
|
1360
|
+
createAiFacade() {
|
|
1361
|
+
const chat = ((contentOrRequest, options) => {
|
|
1362
|
+
if (typeof contentOrRequest === "string") {
|
|
1363
|
+
return this.chatWithContent(contentOrRequest, options);
|
|
1364
|
+
}
|
|
1365
|
+
return this.getAiChatClient().create(contentOrRequest, options);
|
|
1366
|
+
});
|
|
1367
|
+
return {
|
|
1368
|
+
chat,
|
|
1369
|
+
chatClient: () => this.getAiChatClient(),
|
|
1370
|
+
getModels: () => this.getModels(),
|
|
1371
|
+
getModel: (modelId) => this.getModel(modelId),
|
|
1372
|
+
requestScriptApproval: (input) => this.requestScriptApproval(input)
|
|
1373
|
+
};
|
|
1374
|
+
}
|
|
1344
1375
|
getRequestLoggingEnabled() {
|
|
1345
1376
|
return this.requestLoggingEnabled;
|
|
1346
1377
|
}
|
|
@@ -1348,7 +1379,7 @@ var OnyxDatabaseImpl = class {
|
|
|
1348
1379
|
return this.responseLoggingEnabled;
|
|
1349
1380
|
}
|
|
1350
1381
|
/** -------- IOnyxDatabase -------- */
|
|
1351
|
-
|
|
1382
|
+
getAiChatClient() {
|
|
1352
1383
|
return new AiChatClientImpl(
|
|
1353
1384
|
() => this.ensureAiClient(),
|
|
1354
1385
|
(handle) => this.registerStream(handle),
|
|
@@ -1356,6 +1387,32 @@ var OnyxDatabaseImpl = class {
|
|
|
1356
1387
|
() => this.responseLoggingEnabled
|
|
1357
1388
|
);
|
|
1358
1389
|
}
|
|
1390
|
+
async chatWithContent(content, options) {
|
|
1391
|
+
const { defaultModel } = await this.ensureAiClient();
|
|
1392
|
+
const stream = options?.stream ?? false;
|
|
1393
|
+
const request = {
|
|
1394
|
+
model: options?.model ?? defaultModel,
|
|
1395
|
+
messages: [{ role: options?.role ?? "user", content }],
|
|
1396
|
+
stream
|
|
1397
|
+
};
|
|
1398
|
+
if (options && "temperature" in options) {
|
|
1399
|
+
request.temperature = options.temperature ?? null;
|
|
1400
|
+
}
|
|
1401
|
+
const result = await this.getAiChatClient().create(request, options);
|
|
1402
|
+
if (stream) return result;
|
|
1403
|
+
if (options?.raw) return result;
|
|
1404
|
+
const first = result.choices?.[0]?.message?.content;
|
|
1405
|
+
if (typeof first === "string" && first.trim().length > 0) {
|
|
1406
|
+
return first;
|
|
1407
|
+
}
|
|
1408
|
+
throw new Error("Chat completion response is missing message content");
|
|
1409
|
+
}
|
|
1410
|
+
chat(content, options) {
|
|
1411
|
+
if (typeof content === "string") {
|
|
1412
|
+
return this.chatWithContent(content, options);
|
|
1413
|
+
}
|
|
1414
|
+
return this.getAiChatClient();
|
|
1415
|
+
}
|
|
1359
1416
|
async getModels() {
|
|
1360
1417
|
const { http } = await this.ensureAiClient();
|
|
1361
1418
|
return http.request("GET", "/v1/models");
|
|
@@ -2272,12 +2329,9 @@ var upper = (attribute) => `upper(${attribute})`;
|
|
|
2272
2329
|
var lower = (attribute) => `lower(${attribute})`;
|
|
2273
2330
|
var substring = (attribute, from, length) => `substring(${attribute},${from},${length})`;
|
|
2274
2331
|
var replace = (attribute, pattern, repl) => `replace(${attribute}, '${pattern.replace(/'/g, "\\'")}', '${repl.replace(/'/g, "\\'")}')`;
|
|
2332
|
+
var format = (attribute, formatter) => `format(${attribute}, '${formatter.replace(/'/g, "\\'")}')`;
|
|
2275
2333
|
var percentile = (attribute, p) => `percentile(${attribute}, ${p})`;
|
|
2276
2334
|
|
|
2277
|
-
|
|
2278
|
-
var sdkName = "@onyx.dev/onyx-database";
|
|
2279
|
-
var sdkVersion = "0.1.0";
|
|
2280
|
-
|
|
2281
|
-
export { QueryResults, asc, avg, between, contains, containsIgnoreCase, count, desc, eq, gt, gte, inOp, isNull, like, lower, lt, lte, matches, max, median, min, neq, notContains, notContainsIgnoreCase, notIn, notLike, notMatches, notNull, notStartsWith, notWithin, onyx, percentile, replace, sdkName, sdkVersion, search, startsWith, std, substring, sum, upper, variance, within };
|
|
2335
|
+
export { QueryResults, asc, avg, between, contains, containsIgnoreCase, count, desc, eq, format, gt, gte, inOp, isNull, like, lower, lt, lte, matches, max, median, min, neq, notContains, notContainsIgnoreCase, notIn, notLike, notMatches, notNull, notStartsWith, notWithin, onyx, percentile, replace, name as sdkName, version as sdkVersion, search, startsWith, std, substring, sum, upper, variance, within };
|
|
2282
2336
|
//# sourceMappingURL=index.js.map
|
|
2283
2337
|
//# sourceMappingURL=index.js.map
|