@onyx.dev/onyx-database 1.2.0 → 2.0.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 +20 -8
- package/dist/{aggregates-LoteczVS.d.cts → aggregates-BJT5DGGX.d.cts} +125 -2
- package/dist/{aggregates-LoteczVS.d.ts → aggregates-BJT5DGGX.d.ts} +125 -2
- package/dist/edge.cjs +77 -25
- package/dist/edge.cjs.map +1 -1
- package/dist/edge.d.cts +2 -2
- package/dist/edge.d.ts +2 -2
- package/dist/edge.js +77 -25
- 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 +78 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +78 -25
- 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/edge.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { O as OnyxFacade } from './aggregates-
|
|
2
|
-
export {
|
|
1
|
+
import { O as OnyxFacade } from './aggregates-BJT5DGGX.cjs';
|
|
2
|
+
export { s 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, r as AiChatOptions, c as AiChatRole, y as AiClient, x as AiErrorResponse, w as AiModel, v as AiModelsResponse, A as AiRequestOptions, t as AiScriptApprovalRequest, u as AiScriptApprovalResponse, h as AiTool, e as AiToolCall, d as AiToolCallFunction, i as AiToolChoice, g as AiToolFunction, a8 as FetchImpl, a7 as FetchResponse, F as FullTextQuery, ah as ICascadeBuilder, ai as ICascadeRelationshipBuilder, ae as IConditionBuilder, I as IOnyxDatabase, af as IQueryBuilder, ag as ISaveBuilder, a3 as LogicalOperator, b as OnyxConfig, a6 as OnyxDocument, aa as QueryCondition, a9 as QueryCriteria, a2 as QueryCriteriaOperator, ad as QueryPage, Q as QueryResults, a as QueryResultsPromise, R as RetryOptions, H as SchemaAttribute, Y as SchemaAttributeChange, D as SchemaDataType, a1 as SchemaDiff, P as SchemaEntity, V as SchemaHistoryEntry, G as SchemaIdentifier, E as SchemaIdentifierGenerator, K as SchemaIndex, Z as SchemaIndexChange, J as SchemaIndexType, L as SchemaResolver, _ as SchemaResolverChange, U as SchemaRevision, T as SchemaRevisionMetadata, a0 as SchemaTableDiff, N as SchemaTrigger, $ as SchemaTriggerChange, M as SchemaTriggerEvent, W as SchemaUpsertRequest, X as SchemaValidationResult, S as SecretMetadata, z as SecretRecord, C as SecretSaveRequest, B as SecretsListResponse, ab as SelectQuery, a4 as Sort, a5 as StreamAction, ac as UpdateQuery, aj as asc, aJ as avg, ar as between, aB as contains, aC as containsIgnoreCase, aL as count, ak as desc, al as eq, as as gt, at as gte, an as inOp, aH as isNull, az as like, aS as lower, au as lt, av as lte, aw as matches, aN as max, aQ as median, aM as min, am as neq, aD as notContains, aE as notContainsIgnoreCase, ap as notIn, aA as notLike, ay as notMatches, aI as notNull, aG as notStartsWith, aq as notWithin, aV as percentile, aU as replace, ax as search, aF as startsWith, aO as std, aT as substring, aK as sum, aR as upper, aP as variance, ao as within } from './aggregates-BJT5DGGX.cjs';
|
|
3
3
|
|
|
4
4
|
declare const onyx: OnyxFacade;
|
|
5
5
|
|
package/dist/edge.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { O as OnyxFacade } from './aggregates-
|
|
2
|
-
export {
|
|
1
|
+
import { O as OnyxFacade } from './aggregates-BJT5DGGX.js';
|
|
2
|
+
export { s 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, r as AiChatOptions, c as AiChatRole, y as AiClient, x as AiErrorResponse, w as AiModel, v as AiModelsResponse, A as AiRequestOptions, t as AiScriptApprovalRequest, u as AiScriptApprovalResponse, h as AiTool, e as AiToolCall, d as AiToolCallFunction, i as AiToolChoice, g as AiToolFunction, a8 as FetchImpl, a7 as FetchResponse, F as FullTextQuery, ah as ICascadeBuilder, ai as ICascadeRelationshipBuilder, ae as IConditionBuilder, I as IOnyxDatabase, af as IQueryBuilder, ag as ISaveBuilder, a3 as LogicalOperator, b as OnyxConfig, a6 as OnyxDocument, aa as QueryCondition, a9 as QueryCriteria, a2 as QueryCriteriaOperator, ad as QueryPage, Q as QueryResults, a as QueryResultsPromise, R as RetryOptions, H as SchemaAttribute, Y as SchemaAttributeChange, D as SchemaDataType, a1 as SchemaDiff, P as SchemaEntity, V as SchemaHistoryEntry, G as SchemaIdentifier, E as SchemaIdentifierGenerator, K as SchemaIndex, Z as SchemaIndexChange, J as SchemaIndexType, L as SchemaResolver, _ as SchemaResolverChange, U as SchemaRevision, T as SchemaRevisionMetadata, a0 as SchemaTableDiff, N as SchemaTrigger, $ as SchemaTriggerChange, M as SchemaTriggerEvent, W as SchemaUpsertRequest, X as SchemaValidationResult, S as SecretMetadata, z as SecretRecord, C as SecretSaveRequest, B as SecretsListResponse, ab as SelectQuery, a4 as Sort, a5 as StreamAction, ac as UpdateQuery, aj as asc, aJ as avg, ar as between, aB as contains, aC as containsIgnoreCase, aL as count, ak as desc, al as eq, as as gt, at as gte, an as inOp, aH as isNull, az as like, aS as lower, au as lt, av as lte, aw as matches, aN as max, aQ as median, aM as min, am as neq, aD as notContains, aE as notContainsIgnoreCase, ap as notIn, aA as notLike, ay as notMatches, aI as notNull, aG as notStartsWith, aq as notWithin, aV as percentile, aU as replace, ax as search, aF as startsWith, aO as std, aT as substring, aK as sum, aR as upper, aP as variance, ao as within } from './aggregates-BJT5DGGX.js';
|
|
3
3
|
|
|
4
4
|
declare const onyx: OnyxFacade;
|
|
5
5
|
|
package/dist/edge.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/config/defaults.ts
|
|
2
2
|
var DEFAULT_BASE_URL = "https://api.onyx.dev";
|
|
3
3
|
var DEFAULT_AI_BASE_URL = "https://ai.onyx.dev";
|
|
4
|
+
var DEFAULT_AI_MODEL = "onyx";
|
|
4
5
|
var sanitizeBaseUrl = (u) => u.replace(/\/+$/, "");
|
|
5
6
|
|
|
6
7
|
// src/errors/config-error.ts
|
|
@@ -53,6 +54,7 @@ function readEnv(targetId) {
|
|
|
53
54
|
const res = dropUndefined({
|
|
54
55
|
baseUrl: pick("ONYX_DATABASE_BASE_URL"),
|
|
55
56
|
aiBaseUrl: pick("ONYX_AI_BASE_URL"),
|
|
57
|
+
defaultModel: pick("ONYX_DEFAULT_MODEL"),
|
|
56
58
|
databaseId: envId,
|
|
57
59
|
apiKey: pick("ONYX_DATABASE_API_KEY"),
|
|
58
60
|
apiSecret: pick("ONYX_DATABASE_API_SECRET")
|
|
@@ -72,12 +74,14 @@ async function resolveConfig(input) {
|
|
|
72
74
|
const merged = {
|
|
73
75
|
baseUrl: DEFAULT_BASE_URL,
|
|
74
76
|
aiBaseUrl: DEFAULT_AI_BASE_URL,
|
|
77
|
+
defaultModel: DEFAULT_AI_MODEL,
|
|
75
78
|
...dropUndefined(env),
|
|
76
79
|
...dropUndefined(input)
|
|
77
80
|
};
|
|
78
81
|
dbg("merged (pre-validate):", mask(merged));
|
|
79
82
|
const baseUrl = sanitizeBaseUrl(merged.baseUrl ?? DEFAULT_BASE_URL);
|
|
80
83
|
const aiBaseUrl = sanitizeBaseUrl(merged.aiBaseUrl ?? DEFAULT_AI_BASE_URL);
|
|
84
|
+
const defaultModel = typeof merged.defaultModel === "string" && merged.defaultModel.trim() ? merged.defaultModel.trim() : DEFAULT_AI_MODEL;
|
|
81
85
|
const databaseId = merged.databaseId ?? "";
|
|
82
86
|
const apiKey = merged.apiKey ?? "";
|
|
83
87
|
const apiSecret = merged.apiSecret ?? "";
|
|
@@ -103,6 +107,7 @@ async function resolveConfig(input) {
|
|
|
103
107
|
const resolved = {
|
|
104
108
|
baseUrl,
|
|
105
109
|
aiBaseUrl,
|
|
110
|
+
defaultModel,
|
|
106
111
|
databaseId,
|
|
107
112
|
apiKey,
|
|
108
113
|
apiSecret,
|
|
@@ -1128,58 +1133,64 @@ var OnyxDatabaseImpl = class {
|
|
|
1128
1133
|
requestLoggingEnabled;
|
|
1129
1134
|
responseLoggingEnabled;
|
|
1130
1135
|
defaultPartition;
|
|
1136
|
+
ai;
|
|
1131
1137
|
constructor(config, resolveConfigWithCache) {
|
|
1132
1138
|
this.requestLoggingEnabled = !!config?.requestLoggingEnabled;
|
|
1133
1139
|
this.responseLoggingEnabled = !!config?.responseLoggingEnabled;
|
|
1134
1140
|
this.defaultPartition = config?.partition;
|
|
1135
1141
|
this.cfgPromise = resolveConfigWithCache(config);
|
|
1142
|
+
this.ai = this.createAiFacade();
|
|
1136
1143
|
}
|
|
1137
|
-
async
|
|
1144
|
+
async resolveConfig() {
|
|
1138
1145
|
if (!this.resolved) {
|
|
1139
1146
|
this.resolved = await this.cfgPromise;
|
|
1140
1147
|
}
|
|
1148
|
+
return this.resolved;
|
|
1149
|
+
}
|
|
1150
|
+
async ensureClient() {
|
|
1151
|
+
const cfg = await this.resolveConfig();
|
|
1141
1152
|
if (!this.http) {
|
|
1142
1153
|
this.http = new HttpClient({
|
|
1143
|
-
baseUrl:
|
|
1144
|
-
apiKey:
|
|
1145
|
-
apiSecret:
|
|
1146
|
-
fetchImpl:
|
|
1154
|
+
baseUrl: cfg.baseUrl,
|
|
1155
|
+
apiKey: cfg.apiKey,
|
|
1156
|
+
apiSecret: cfg.apiSecret,
|
|
1157
|
+
fetchImpl: cfg.fetch,
|
|
1147
1158
|
requestLoggingEnabled: this.requestLoggingEnabled,
|
|
1148
1159
|
responseLoggingEnabled: this.responseLoggingEnabled,
|
|
1149
|
-
retryEnabled:
|
|
1150
|
-
maxRetries:
|
|
1151
|
-
retryInitialDelayMs:
|
|
1160
|
+
retryEnabled: cfg.retryEnabled,
|
|
1161
|
+
maxRetries: cfg.maxRetries,
|
|
1162
|
+
retryInitialDelayMs: cfg.retryInitialDelayMs
|
|
1152
1163
|
});
|
|
1153
1164
|
}
|
|
1154
1165
|
return {
|
|
1155
1166
|
http: this.http,
|
|
1156
|
-
fetchImpl:
|
|
1157
|
-
baseUrl:
|
|
1158
|
-
databaseId:
|
|
1167
|
+
fetchImpl: cfg.fetch,
|
|
1168
|
+
baseUrl: cfg.baseUrl,
|
|
1169
|
+
databaseId: cfg.databaseId,
|
|
1170
|
+
defaultModel: cfg.defaultModel ?? DEFAULT_AI_MODEL
|
|
1159
1171
|
};
|
|
1160
1172
|
}
|
|
1161
1173
|
async ensureAiClient() {
|
|
1162
|
-
|
|
1163
|
-
this.resolved = await this.cfgPromise;
|
|
1164
|
-
}
|
|
1174
|
+
const cfg = await this.resolveConfig();
|
|
1165
1175
|
if (!this.aiHttp) {
|
|
1166
1176
|
this.aiHttp = new HttpClient({
|
|
1167
|
-
baseUrl:
|
|
1168
|
-
apiKey:
|
|
1169
|
-
apiSecret:
|
|
1170
|
-
fetchImpl:
|
|
1177
|
+
baseUrl: cfg.aiBaseUrl,
|
|
1178
|
+
apiKey: cfg.apiKey,
|
|
1179
|
+
apiSecret: cfg.apiSecret,
|
|
1180
|
+
fetchImpl: cfg.fetch,
|
|
1171
1181
|
requestLoggingEnabled: this.requestLoggingEnabled,
|
|
1172
1182
|
responseLoggingEnabled: this.responseLoggingEnabled,
|
|
1173
|
-
retryEnabled:
|
|
1174
|
-
maxRetries:
|
|
1175
|
-
retryInitialDelayMs:
|
|
1183
|
+
retryEnabled: cfg.retryEnabled,
|
|
1184
|
+
maxRetries: cfg.maxRetries,
|
|
1185
|
+
retryInitialDelayMs: cfg.retryInitialDelayMs
|
|
1176
1186
|
});
|
|
1177
1187
|
}
|
|
1178
1188
|
return {
|
|
1179
1189
|
http: this.aiHttp,
|
|
1180
|
-
fetchImpl:
|
|
1181
|
-
aiBaseUrl:
|
|
1182
|
-
databaseId:
|
|
1190
|
+
fetchImpl: cfg.fetch,
|
|
1191
|
+
aiBaseUrl: cfg.aiBaseUrl,
|
|
1192
|
+
databaseId: cfg.databaseId,
|
|
1193
|
+
defaultModel: cfg.defaultModel ?? DEFAULT_AI_MODEL
|
|
1183
1194
|
};
|
|
1184
1195
|
}
|
|
1185
1196
|
registerStream(handle) {
|
|
@@ -1194,6 +1205,21 @@ var OnyxDatabaseImpl = class {
|
|
|
1194
1205
|
}
|
|
1195
1206
|
};
|
|
1196
1207
|
}
|
|
1208
|
+
createAiFacade() {
|
|
1209
|
+
const chat = ((contentOrRequest, options) => {
|
|
1210
|
+
if (typeof contentOrRequest === "string") {
|
|
1211
|
+
return this.chatWithContent(contentOrRequest, options);
|
|
1212
|
+
}
|
|
1213
|
+
return this.getAiChatClient().create(contentOrRequest, options);
|
|
1214
|
+
});
|
|
1215
|
+
return {
|
|
1216
|
+
chat,
|
|
1217
|
+
chatClient: () => this.getAiChatClient(),
|
|
1218
|
+
getModels: () => this.getModels(),
|
|
1219
|
+
getModel: (modelId) => this.getModel(modelId),
|
|
1220
|
+
requestScriptApproval: (input) => this.requestScriptApproval(input)
|
|
1221
|
+
};
|
|
1222
|
+
}
|
|
1197
1223
|
getRequestLoggingEnabled() {
|
|
1198
1224
|
return this.requestLoggingEnabled;
|
|
1199
1225
|
}
|
|
@@ -1201,7 +1227,7 @@ var OnyxDatabaseImpl = class {
|
|
|
1201
1227
|
return this.responseLoggingEnabled;
|
|
1202
1228
|
}
|
|
1203
1229
|
/** -------- IOnyxDatabase -------- */
|
|
1204
|
-
|
|
1230
|
+
getAiChatClient() {
|
|
1205
1231
|
return new AiChatClientImpl(
|
|
1206
1232
|
() => this.ensureAiClient(),
|
|
1207
1233
|
(handle) => this.registerStream(handle),
|
|
@@ -1209,6 +1235,32 @@ var OnyxDatabaseImpl = class {
|
|
|
1209
1235
|
() => this.responseLoggingEnabled
|
|
1210
1236
|
);
|
|
1211
1237
|
}
|
|
1238
|
+
async chatWithContent(content, options) {
|
|
1239
|
+
const { defaultModel } = await this.ensureAiClient();
|
|
1240
|
+
const stream = options?.stream ?? false;
|
|
1241
|
+
const request = {
|
|
1242
|
+
model: options?.model ?? defaultModel,
|
|
1243
|
+
messages: [{ role: options?.role ?? "user", content }],
|
|
1244
|
+
stream
|
|
1245
|
+
};
|
|
1246
|
+
if (options && "temperature" in options) {
|
|
1247
|
+
request.temperature = options.temperature ?? null;
|
|
1248
|
+
}
|
|
1249
|
+
const result = await this.getAiChatClient().create(request, options);
|
|
1250
|
+
if (stream) return result;
|
|
1251
|
+
if (options?.raw) return result;
|
|
1252
|
+
const first = result.choices?.[0]?.message?.content;
|
|
1253
|
+
if (typeof first === "string" && first.trim().length > 0) {
|
|
1254
|
+
return first;
|
|
1255
|
+
}
|
|
1256
|
+
throw new Error("Chat completion response is missing message content");
|
|
1257
|
+
}
|
|
1258
|
+
chat(content, options) {
|
|
1259
|
+
if (typeof content === "string") {
|
|
1260
|
+
return this.chatWithContent(content, options);
|
|
1261
|
+
}
|
|
1262
|
+
return this.getAiChatClient();
|
|
1263
|
+
}
|
|
1212
1264
|
async getModels() {
|
|
1213
1265
|
const { http } = await this.ensureAiClient();
|
|
1214
1266
|
return http.request("GET", "/v1/models");
|