@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/dist/index.d.cts CHANGED
@@ -1,9 +1,6 @@
1
- import { O as OnyxFacade } from './aggregates-LoteczVS.cjs';
2
- export { r as AiChatClient, l as AiChatCompletionChoice, p as AiChatCompletionChunk, o as AiChatCompletionChunkChoice, n as AiChatCompletionChunkDelta, j as AiChatCompletionRequest, m as AiChatCompletionResponse, q as AiChatCompletionStream, k as AiChatCompletionUsage, f as AiChatMessage, c as AiChatRole, w as AiErrorResponse, v as AiModel, u as AiModelsResponse, A as AiRequestOptions, s as AiScriptApprovalRequest, t as AiScriptApprovalResponse, h as AiTool, e as AiToolCall, d as AiToolCallFunction, i as AiToolChoice, g as AiToolFunction, a6 as FetchImpl, a5 as FetchResponse, F as FullTextQuery, af as ICascadeBuilder, ag as ICascadeRelationshipBuilder, ac as IConditionBuilder, I as IOnyxDatabase, ad as IQueryBuilder, ae as ISaveBuilder, a1 as LogicalOperator, b as OnyxConfig, a4 as OnyxDocument, a8 as QueryCondition, a7 as QueryCriteria, a0 as QueryCriteriaOperator, ab as QueryPage, Q as QueryResults, a as QueryResultsPromise, R as RetryOptions, E as SchemaAttribute, W as SchemaAttributeChange, B as SchemaDataType, $ as SchemaDiff, M as SchemaEntity, T as SchemaHistoryEntry, D as SchemaIdentifier, C as SchemaIdentifierGenerator, H as SchemaIndex, X as SchemaIndexChange, G as SchemaIndexType, J as SchemaResolver, Y as SchemaResolverChange, P as SchemaRevision, N as SchemaRevisionMetadata, _ as SchemaTableDiff, L as SchemaTrigger, Z as SchemaTriggerChange, K as SchemaTriggerEvent, U as SchemaUpsertRequest, V as SchemaValidationResult, S as SecretMetadata, x as SecretRecord, z as SecretSaveRequest, y as SecretsListResponse, a9 as SelectQuery, a2 as Sort, a3 as StreamAction, aa as UpdateQuery, ah as asc, aH as avg, ap as between, az as contains, aA as containsIgnoreCase, aJ as count, ai as desc, aj as eq, aq as gt, ar as gte, al as inOp, aF as isNull, ax as like, aQ as lower, as as lt, at as lte, au as matches, aL as max, aO as median, aK as min, ak as neq, aB as notContains, aC as notContainsIgnoreCase, an as notIn, ay as notLike, aw as notMatches, aG as notNull, aE as notStartsWith, ao as notWithin, aT as percentile, aS as replace, av as search, aD as startsWith, aM as std, aR as substring, aI as sum, aP as upper, aN as variance, am as within } from './aggregates-LoteczVS.cjs';
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
- declare const sdkName = "@onyx.dev/onyx-database";
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-LoteczVS.js';
2
- export { r as AiChatClient, l as AiChatCompletionChoice, p as AiChatCompletionChunk, o as AiChatCompletionChunkChoice, n as AiChatCompletionChunkDelta, j as AiChatCompletionRequest, m as AiChatCompletionResponse, q as AiChatCompletionStream, k as AiChatCompletionUsage, f as AiChatMessage, c as AiChatRole, w as AiErrorResponse, v as AiModel, u as AiModelsResponse, A as AiRequestOptions, s as AiScriptApprovalRequest, t as AiScriptApprovalResponse, h as AiTool, e as AiToolCall, d as AiToolCallFunction, i as AiToolChoice, g as AiToolFunction, a6 as FetchImpl, a5 as FetchResponse, F as FullTextQuery, af as ICascadeBuilder, ag as ICascadeRelationshipBuilder, ac as IConditionBuilder, I as IOnyxDatabase, ad as IQueryBuilder, ae as ISaveBuilder, a1 as LogicalOperator, b as OnyxConfig, a4 as OnyxDocument, a8 as QueryCondition, a7 as QueryCriteria, a0 as QueryCriteriaOperator, ab as QueryPage, Q as QueryResults, a as QueryResultsPromise, R as RetryOptions, E as SchemaAttribute, W as SchemaAttributeChange, B as SchemaDataType, $ as SchemaDiff, M as SchemaEntity, T as SchemaHistoryEntry, D as SchemaIdentifier, C as SchemaIdentifierGenerator, H as SchemaIndex, X as SchemaIndexChange, G as SchemaIndexType, J as SchemaResolver, Y as SchemaResolverChange, P as SchemaRevision, N as SchemaRevisionMetadata, _ as SchemaTableDiff, L as SchemaTrigger, Z as SchemaTriggerChange, K as SchemaTriggerEvent, U as SchemaUpsertRequest, V as SchemaValidationResult, S as SecretMetadata, x as SecretRecord, z as SecretSaveRequest, y as SecretsListResponse, a9 as SelectQuery, a2 as Sort, a3 as StreamAction, aa as UpdateQuery, ah as asc, aH as avg, ap as between, az as contains, aA as containsIgnoreCase, aJ as count, ai as desc, aj as eq, aq as gt, ar as gte, al as inOp, aF as isNull, ax as like, aQ as lower, as as lt, at as lte, au as matches, aL as max, aO as median, aK as min, ak as neq, aB as notContains, aC as notContainsIgnoreCase, an as notIn, ay as notLike, aw as notMatches, aG as notNull, aE as notStartsWith, ao as notWithin, aT as percentile, aS as replace, av as search, aD as startsWith, aM as std, aR as substring, aI as sum, aP as upper, aN as variance, am as within } from './aggregates-LoteczVS.js';
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
- declare const sdkName = "@onyx.dev/onyx-database";
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(name) {
947
- this.graphName = name;
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 [name, local] of localMap.entries()) {
1035
- if (!apiMap.has(name)) {
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(name);
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 name of apiMap.keys()) {
1051
- if (!localMap.has(name)) removed.push(name);
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 [name, local] of localMap.entries()) {
1066
- if (!apiMap.has(name)) {
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(name);
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 name of apiMap.keys()) {
1080
- if (!localMap.has(name)) removed.push(name);
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 [name, local] of localMap.entries()) {
1095
- if (!apiMap.has(name)) {
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(name);
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 name of apiMap.keys()) {
1105
- if (!localMap.has(name)) removed.push(name);
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 [name, local] of localMap.entries()) {
1120
- if (!apiMap.has(name)) {
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(name);
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 name of apiMap.keys()) {
1130
- if (!localMap.has(name)) removed.push(name);
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 [name, localEntity] of localMap.entries()) {
1147
- if (!apiMap.has(name)) {
1148
- newTables.push(name);
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(name);
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 name of apiMap.keys()) {
1178
- if (!localMap.has(name)) removedTables.push(name);
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 ensureClient() {
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: this.resolved.baseUrl,
1291
- apiKey: this.resolved.apiKey,
1292
- apiSecret: this.resolved.apiSecret,
1293
- fetchImpl: this.resolved.fetch,
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: this.resolved.retryEnabled,
1297
- maxRetries: this.resolved.maxRetries,
1298
- retryInitialDelayMs: this.resolved.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: this.resolved.fetch,
1304
- baseUrl: this.resolved.baseUrl,
1305
- databaseId: this.resolved.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
- if (!this.resolved) {
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: this.resolved.aiBaseUrl,
1315
- apiKey: this.resolved.apiKey,
1316
- apiSecret: this.resolved.apiSecret,
1317
- fetchImpl: this.resolved.fetch,
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: this.resolved.retryEnabled,
1321
- maxRetries: this.resolved.maxRetries,
1322
- retryInitialDelayMs: this.resolved.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: this.resolved.fetch,
1328
- aiBaseUrl: this.resolved.aiBaseUrl,
1329
- databaseId: this.resolved.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
- chat() {
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
- // src/index.ts
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