@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/edge.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/edge.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/edge.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
@@ -53,6 +58,7 @@ function readEnv(targetId) {
53
58
  const res = dropUndefined({
54
59
  baseUrl: pick("ONYX_DATABASE_BASE_URL"),
55
60
  aiBaseUrl: pick("ONYX_AI_BASE_URL"),
61
+ defaultModel: pick("ONYX_DEFAULT_MODEL"),
56
62
  databaseId: envId,
57
63
  apiKey: pick("ONYX_DATABASE_API_KEY"),
58
64
  apiSecret: pick("ONYX_DATABASE_API_SECRET")
@@ -72,12 +78,14 @@ async function resolveConfig(input) {
72
78
  const merged = {
73
79
  baseUrl: DEFAULT_BASE_URL,
74
80
  aiBaseUrl: DEFAULT_AI_BASE_URL,
81
+ defaultModel: DEFAULT_AI_MODEL,
75
82
  ...dropUndefined(env),
76
83
  ...dropUndefined(input)
77
84
  };
78
85
  dbg("merged (pre-validate):", mask(merged));
79
86
  const baseUrl = sanitizeBaseUrl(merged.baseUrl ?? DEFAULT_BASE_URL);
80
87
  const aiBaseUrl = sanitizeBaseUrl(merged.aiBaseUrl ?? DEFAULT_AI_BASE_URL);
88
+ const defaultModel = typeof merged.defaultModel === "string" && merged.defaultModel.trim() ? merged.defaultModel.trim() : DEFAULT_AI_MODEL;
81
89
  const databaseId = merged.databaseId ?? "";
82
90
  const apiKey = merged.apiKey ?? "";
83
91
  const apiSecret = merged.apiSecret ?? "";
@@ -103,6 +111,7 @@ async function resolveConfig(input) {
103
111
  const resolved = {
104
112
  baseUrl,
105
113
  aiBaseUrl,
114
+ defaultModel,
106
115
  databaseId,
107
116
  apiKey,
108
117
  apiSecret,
@@ -796,8 +805,8 @@ var CascadeRelationshipBuilder = class {
796
805
  * builder.graph('programs');
797
806
  * ```
798
807
  */
799
- graph(name) {
800
- this.graphName = name;
808
+ graph(name2) {
809
+ this.graphName = name2;
801
810
  return this;
802
811
  }
803
812
  /**
@@ -884,24 +893,24 @@ function diffAttributes(apiAttrs, localAttrs) {
884
893
  const added = [];
885
894
  const removed = [];
886
895
  const changed = [];
887
- for (const [name, local] of localMap.entries()) {
888
- if (!apiMap.has(name)) {
896
+ for (const [name2, local] of localMap.entries()) {
897
+ if (!apiMap.has(name2)) {
889
898
  added.push(local);
890
899
  continue;
891
900
  }
892
- const api = apiMap.get(name);
901
+ const api = apiMap.get(name2);
893
902
  const apiNull = Boolean(api.isNullable);
894
903
  const localNull = Boolean(local.isNullable);
895
904
  if (api.type !== local.type || apiNull !== localNull) {
896
905
  changed.push({
897
- name,
906
+ name: name2,
898
907
  from: { type: api.type, isNullable: apiNull },
899
908
  to: { type: local.type, isNullable: localNull }
900
909
  });
901
910
  }
902
911
  }
903
- for (const name of apiMap.keys()) {
904
- if (!localMap.has(name)) removed.push(name);
912
+ for (const name2 of apiMap.keys()) {
913
+ if (!localMap.has(name2)) removed.push(name2);
905
914
  }
906
915
  added.sort((a, b) => a.name.localeCompare(b.name));
907
916
  removed.sort();
@@ -915,22 +924,22 @@ function diffIndexes(apiIndexes, localIndexes) {
915
924
  const added = [];
916
925
  const removed = [];
917
926
  const changed = [];
918
- for (const [name, local] of localMap.entries()) {
919
- if (!apiMap.has(name)) {
927
+ for (const [name2, local] of localMap.entries()) {
928
+ if (!apiMap.has(name2)) {
920
929
  added.push(local);
921
930
  continue;
922
931
  }
923
- const api = apiMap.get(name);
932
+ const api = apiMap.get(name2);
924
933
  const apiType = api.type ?? "DEFAULT";
925
934
  const localType = local.type ?? "DEFAULT";
926
935
  const apiScore = api.minimumScore;
927
936
  const localScore = local.minimumScore;
928
937
  if (apiType !== localType || apiScore !== localScore) {
929
- changed.push({ name, from: api, to: local });
938
+ changed.push({ name: name2, from: api, to: local });
930
939
  }
931
940
  }
932
- for (const name of apiMap.keys()) {
933
- if (!localMap.has(name)) removed.push(name);
941
+ for (const name2 of apiMap.keys()) {
942
+ if (!localMap.has(name2)) removed.push(name2);
934
943
  }
935
944
  added.sort((a, b) => a.name.localeCompare(b.name));
936
945
  removed.sort();
@@ -944,18 +953,18 @@ function diffResolvers(apiResolvers, localResolvers) {
944
953
  const added = [];
945
954
  const removed = [];
946
955
  const changed = [];
947
- for (const [name, local] of localMap.entries()) {
948
- if (!apiMap.has(name)) {
956
+ for (const [name2, local] of localMap.entries()) {
957
+ if (!apiMap.has(name2)) {
949
958
  added.push(local);
950
959
  continue;
951
960
  }
952
- const api = apiMap.get(name);
961
+ const api = apiMap.get(name2);
953
962
  if (api.resolver !== local.resolver) {
954
- changed.push({ name, from: api, to: local });
963
+ changed.push({ name: name2, from: api, to: local });
955
964
  }
956
965
  }
957
- for (const name of apiMap.keys()) {
958
- if (!localMap.has(name)) removed.push(name);
966
+ for (const name2 of apiMap.keys()) {
967
+ if (!localMap.has(name2)) removed.push(name2);
959
968
  }
960
969
  added.sort((a, b) => a.name.localeCompare(b.name));
961
970
  removed.sort();
@@ -969,18 +978,18 @@ function diffTriggers(apiTriggers, localTriggers) {
969
978
  const added = [];
970
979
  const removed = [];
971
980
  const changed = [];
972
- for (const [name, local] of localMap.entries()) {
973
- if (!apiMap.has(name)) {
981
+ for (const [name2, local] of localMap.entries()) {
982
+ if (!apiMap.has(name2)) {
974
983
  added.push(local);
975
984
  continue;
976
985
  }
977
- const api = apiMap.get(name);
986
+ const api = apiMap.get(name2);
978
987
  if (api.event !== local.event || api.trigger !== local.trigger) {
979
- changed.push({ name, from: api, to: local });
988
+ changed.push({ name: name2, from: api, to: local });
980
989
  }
981
990
  }
982
- for (const name of apiMap.keys()) {
983
- if (!localMap.has(name)) removed.push(name);
991
+ for (const name2 of apiMap.keys()) {
992
+ if (!localMap.has(name2)) removed.push(name2);
984
993
  }
985
994
  added.sort((a, b) => a.name.localeCompare(b.name));
986
995
  removed.sort();
@@ -996,13 +1005,13 @@ function computeSchemaDiff(apiSchema, localSchema) {
996
1005
  const newTables = [];
997
1006
  const removedTables = [];
998
1007
  const changedTables = [];
999
- for (const [name, localEntity] of localMap.entries()) {
1000
- if (!apiMap.has(name)) {
1001
- newTables.push(name);
1008
+ for (const [name2, localEntity] of localMap.entries()) {
1009
+ if (!apiMap.has(name2)) {
1010
+ newTables.push(name2);
1002
1011
  continue;
1003
1012
  }
1004
- const apiEntity = apiMap.get(name);
1005
- const tableDiff = { name };
1013
+ const apiEntity = apiMap.get(name2);
1014
+ const tableDiff = { name: name2 };
1006
1015
  const partitionFrom = normalizePartition(apiEntity.partition);
1007
1016
  const partitionTo = normalizePartition(localEntity.partition);
1008
1017
  if (partitionFrom !== partitionTo) {
@@ -1027,8 +1036,8 @@ function computeSchemaDiff(apiSchema, localSchema) {
1027
1036
  changedTables.push(tableDiff);
1028
1037
  }
1029
1038
  }
1030
- for (const name of apiMap.keys()) {
1031
- if (!localMap.has(name)) removedTables.push(name);
1039
+ for (const name2 of apiMap.keys()) {
1040
+ if (!localMap.has(name2)) removedTables.push(name2);
1032
1041
  }
1033
1042
  newTables.sort();
1034
1043
  removedTables.sort();
@@ -1128,58 +1137,64 @@ var OnyxDatabaseImpl = class {
1128
1137
  requestLoggingEnabled;
1129
1138
  responseLoggingEnabled;
1130
1139
  defaultPartition;
1140
+ ai;
1131
1141
  constructor(config, resolveConfigWithCache) {
1132
1142
  this.requestLoggingEnabled = !!config?.requestLoggingEnabled;
1133
1143
  this.responseLoggingEnabled = !!config?.responseLoggingEnabled;
1134
1144
  this.defaultPartition = config?.partition;
1135
1145
  this.cfgPromise = resolveConfigWithCache(config);
1146
+ this.ai = this.createAiFacade();
1136
1147
  }
1137
- async ensureClient() {
1148
+ async resolveConfig() {
1138
1149
  if (!this.resolved) {
1139
1150
  this.resolved = await this.cfgPromise;
1140
1151
  }
1152
+ return this.resolved;
1153
+ }
1154
+ async ensureClient() {
1155
+ const cfg = await this.resolveConfig();
1141
1156
  if (!this.http) {
1142
1157
  this.http = new HttpClient({
1143
- baseUrl: this.resolved.baseUrl,
1144
- apiKey: this.resolved.apiKey,
1145
- apiSecret: this.resolved.apiSecret,
1146
- fetchImpl: this.resolved.fetch,
1158
+ baseUrl: cfg.baseUrl,
1159
+ apiKey: cfg.apiKey,
1160
+ apiSecret: cfg.apiSecret,
1161
+ fetchImpl: cfg.fetch,
1147
1162
  requestLoggingEnabled: this.requestLoggingEnabled,
1148
1163
  responseLoggingEnabled: this.responseLoggingEnabled,
1149
- retryEnabled: this.resolved.retryEnabled,
1150
- maxRetries: this.resolved.maxRetries,
1151
- retryInitialDelayMs: this.resolved.retryInitialDelayMs
1164
+ retryEnabled: cfg.retryEnabled,
1165
+ maxRetries: cfg.maxRetries,
1166
+ retryInitialDelayMs: cfg.retryInitialDelayMs
1152
1167
  });
1153
1168
  }
1154
1169
  return {
1155
1170
  http: this.http,
1156
- fetchImpl: this.resolved.fetch,
1157
- baseUrl: this.resolved.baseUrl,
1158
- databaseId: this.resolved.databaseId
1171
+ fetchImpl: cfg.fetch,
1172
+ baseUrl: cfg.baseUrl,
1173
+ databaseId: cfg.databaseId,
1174
+ defaultModel: cfg.defaultModel ?? DEFAULT_AI_MODEL
1159
1175
  };
1160
1176
  }
1161
1177
  async ensureAiClient() {
1162
- if (!this.resolved) {
1163
- this.resolved = await this.cfgPromise;
1164
- }
1178
+ const cfg = await this.resolveConfig();
1165
1179
  if (!this.aiHttp) {
1166
1180
  this.aiHttp = new HttpClient({
1167
- baseUrl: this.resolved.aiBaseUrl,
1168
- apiKey: this.resolved.apiKey,
1169
- apiSecret: this.resolved.apiSecret,
1170
- fetchImpl: this.resolved.fetch,
1181
+ baseUrl: cfg.aiBaseUrl,
1182
+ apiKey: cfg.apiKey,
1183
+ apiSecret: cfg.apiSecret,
1184
+ fetchImpl: cfg.fetch,
1171
1185
  requestLoggingEnabled: this.requestLoggingEnabled,
1172
1186
  responseLoggingEnabled: this.responseLoggingEnabled,
1173
- retryEnabled: this.resolved.retryEnabled,
1174
- maxRetries: this.resolved.maxRetries,
1175
- retryInitialDelayMs: this.resolved.retryInitialDelayMs
1187
+ retryEnabled: cfg.retryEnabled,
1188
+ maxRetries: cfg.maxRetries,
1189
+ retryInitialDelayMs: cfg.retryInitialDelayMs
1176
1190
  });
1177
1191
  }
1178
1192
  return {
1179
1193
  http: this.aiHttp,
1180
- fetchImpl: this.resolved.fetch,
1181
- aiBaseUrl: this.resolved.aiBaseUrl,
1182
- databaseId: this.resolved.databaseId
1194
+ fetchImpl: cfg.fetch,
1195
+ aiBaseUrl: cfg.aiBaseUrl,
1196
+ databaseId: cfg.databaseId,
1197
+ defaultModel: cfg.defaultModel ?? DEFAULT_AI_MODEL
1183
1198
  };
1184
1199
  }
1185
1200
  registerStream(handle) {
@@ -1194,6 +1209,21 @@ var OnyxDatabaseImpl = class {
1194
1209
  }
1195
1210
  };
1196
1211
  }
1212
+ createAiFacade() {
1213
+ const chat = ((contentOrRequest, options) => {
1214
+ if (typeof contentOrRequest === "string") {
1215
+ return this.chatWithContent(contentOrRequest, options);
1216
+ }
1217
+ return this.getAiChatClient().create(contentOrRequest, options);
1218
+ });
1219
+ return {
1220
+ chat,
1221
+ chatClient: () => this.getAiChatClient(),
1222
+ getModels: () => this.getModels(),
1223
+ getModel: (modelId) => this.getModel(modelId),
1224
+ requestScriptApproval: (input) => this.requestScriptApproval(input)
1225
+ };
1226
+ }
1197
1227
  getRequestLoggingEnabled() {
1198
1228
  return this.requestLoggingEnabled;
1199
1229
  }
@@ -1201,7 +1231,7 @@ var OnyxDatabaseImpl = class {
1201
1231
  return this.responseLoggingEnabled;
1202
1232
  }
1203
1233
  /** -------- IOnyxDatabase -------- */
1204
- chat() {
1234
+ getAiChatClient() {
1205
1235
  return new AiChatClientImpl(
1206
1236
  () => this.ensureAiClient(),
1207
1237
  (handle) => this.registerStream(handle),
@@ -1209,6 +1239,32 @@ var OnyxDatabaseImpl = class {
1209
1239
  () => this.responseLoggingEnabled
1210
1240
  );
1211
1241
  }
1242
+ async chatWithContent(content, options) {
1243
+ const { defaultModel } = await this.ensureAiClient();
1244
+ const stream = options?.stream ?? false;
1245
+ const request = {
1246
+ model: options?.model ?? defaultModel,
1247
+ messages: [{ role: options?.role ?? "user", content }],
1248
+ stream
1249
+ };
1250
+ if (options && "temperature" in options) {
1251
+ request.temperature = options.temperature ?? null;
1252
+ }
1253
+ const result = await this.getAiChatClient().create(request, options);
1254
+ if (stream) return result;
1255
+ if (options?.raw) return result;
1256
+ const first = result.choices?.[0]?.message?.content;
1257
+ if (typeof first === "string" && first.trim().length > 0) {
1258
+ return first;
1259
+ }
1260
+ throw new Error("Chat completion response is missing message content");
1261
+ }
1262
+ chat(content, options) {
1263
+ if (typeof content === "string") {
1264
+ return this.chatWithContent(content, options);
1265
+ }
1266
+ return this.getAiChatClient();
1267
+ }
1212
1268
  async getModels() {
1213
1269
  const { http } = await this.ensureAiClient();
1214
1270
  return http.request("GET", "/v1/models");
@@ -2125,12 +2181,9 @@ var upper = (attribute) => `upper(${attribute})`;
2125
2181
  var lower = (attribute) => `lower(${attribute})`;
2126
2182
  var substring = (attribute, from, length) => `substring(${attribute},${from},${length})`;
2127
2183
  var replace = (attribute, pattern, repl) => `replace(${attribute}, '${pattern.replace(/'/g, "\\'")}', '${repl.replace(/'/g, "\\'")}')`;
2184
+ var format = (attribute, formatter) => `format(${attribute}, '${formatter.replace(/'/g, "\\'")}')`;
2128
2185
  var percentile = (attribute, p) => `percentile(${attribute}, ${p})`;
2129
2186
 
2130
- // src/edge.ts
2131
- var sdkName = "@onyx.dev/onyx-database";
2132
- var sdkVersion = "0.1.0";
2133
-
2134
- 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 };
2187
+ 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 };
2135
2188
  //# sourceMappingURL=edge.js.map
2136
2189
  //# sourceMappingURL=edge.js.map