@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/index.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/index.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/index.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
|
|
@@ -60,6 +61,7 @@ function readEnv(targetId) {
|
|
|
60
61
|
const res = dropUndefined({
|
|
61
62
|
baseUrl: pick("ONYX_DATABASE_BASE_URL"),
|
|
62
63
|
aiBaseUrl: pick("ONYX_AI_BASE_URL"),
|
|
64
|
+
defaultModel: pick("ONYX_DEFAULT_MODEL"),
|
|
63
65
|
databaseId: envId,
|
|
64
66
|
apiKey: pick("ONYX_DATABASE_API_KEY"),
|
|
65
67
|
apiSecret: pick("ONYX_DATABASE_API_SECRET")
|
|
@@ -197,6 +199,7 @@ async function resolveConfig(input) {
|
|
|
197
199
|
const merged = {
|
|
198
200
|
baseUrl: DEFAULT_BASE_URL,
|
|
199
201
|
aiBaseUrl: DEFAULT_AI_BASE_URL,
|
|
202
|
+
defaultModel: DEFAULT_AI_MODEL,
|
|
200
203
|
...dropUndefined(home),
|
|
201
204
|
...dropUndefined(project),
|
|
202
205
|
...dropUndefined(cfgPath),
|
|
@@ -206,6 +209,7 @@ async function resolveConfig(input) {
|
|
|
206
209
|
dbg("merged (pre-validate):", mask(merged));
|
|
207
210
|
const baseUrl = sanitizeBaseUrl(merged.baseUrl ?? DEFAULT_BASE_URL);
|
|
208
211
|
const aiBaseUrl = sanitizeBaseUrl(merged.aiBaseUrl ?? DEFAULT_AI_BASE_URL);
|
|
212
|
+
const defaultModel = typeof merged.defaultModel === "string" && merged.defaultModel.trim() ? merged.defaultModel.trim() : DEFAULT_AI_MODEL;
|
|
209
213
|
const databaseId = merged.databaseId ?? "";
|
|
210
214
|
const apiKey = merged.apiKey ?? "";
|
|
211
215
|
const apiSecret = merged.apiSecret ?? "";
|
|
@@ -242,6 +246,7 @@ async function resolveConfig(input) {
|
|
|
242
246
|
const resolved = {
|
|
243
247
|
baseUrl,
|
|
244
248
|
aiBaseUrl,
|
|
249
|
+
defaultModel,
|
|
245
250
|
databaseId,
|
|
246
251
|
apiKey,
|
|
247
252
|
apiSecret,
|
|
@@ -253,6 +258,7 @@ async function resolveConfig(input) {
|
|
|
253
258
|
const source = {
|
|
254
259
|
databaseId: input?.databaseId ? "explicit config" : env.databaseId ? "env" : cfgPath.databaseId ? "env ONYX_CONFIG_PATH" : project.databaseId ? "project file" : home.databaseId ? "home profile" : "unknown",
|
|
255
260
|
aiBaseUrl: input?.aiBaseUrl ? "explicit config" : env.aiBaseUrl ? "env" : cfgPath.aiBaseUrl ? "env ONYX_CONFIG_PATH" : project.aiBaseUrl ? "project file" : home.aiBaseUrl ? "home profile" : "default",
|
|
261
|
+
defaultModel: input?.defaultModel ? "explicit config" : env.defaultModel ? "env" : cfgPath.defaultModel ? "env ONYX_CONFIG_PATH" : project.defaultModel ? "project file" : home.defaultModel ? "home profile" : "default",
|
|
256
262
|
apiKey: input?.apiKey ? "explicit config" : env.apiKey ? "env" : cfgPath.apiKey ? "env ONYX_CONFIG_PATH" : project.apiKey ? "project file" : home.apiKey ? "home profile" : "unknown",
|
|
257
263
|
apiSecret: input?.apiSecret ? "explicit config" : env.apiSecret ? "env" : cfgPath.apiSecret ? "env ONYX_CONFIG_PATH" : project.apiSecret ? "project file" : home.apiSecret ? "home profile" : "unknown"
|
|
258
264
|
};
|
|
@@ -1275,58 +1281,64 @@ var OnyxDatabaseImpl = class {
|
|
|
1275
1281
|
requestLoggingEnabled;
|
|
1276
1282
|
responseLoggingEnabled;
|
|
1277
1283
|
defaultPartition;
|
|
1284
|
+
ai;
|
|
1278
1285
|
constructor(config, resolveConfigWithCache) {
|
|
1279
1286
|
this.requestLoggingEnabled = !!config?.requestLoggingEnabled;
|
|
1280
1287
|
this.responseLoggingEnabled = !!config?.responseLoggingEnabled;
|
|
1281
1288
|
this.defaultPartition = config?.partition;
|
|
1282
1289
|
this.cfgPromise = resolveConfigWithCache(config);
|
|
1290
|
+
this.ai = this.createAiFacade();
|
|
1283
1291
|
}
|
|
1284
|
-
async
|
|
1292
|
+
async resolveConfig() {
|
|
1285
1293
|
if (!this.resolved) {
|
|
1286
1294
|
this.resolved = await this.cfgPromise;
|
|
1287
1295
|
}
|
|
1296
|
+
return this.resolved;
|
|
1297
|
+
}
|
|
1298
|
+
async ensureClient() {
|
|
1299
|
+
const cfg = await this.resolveConfig();
|
|
1288
1300
|
if (!this.http) {
|
|
1289
1301
|
this.http = new HttpClient({
|
|
1290
|
-
baseUrl:
|
|
1291
|
-
apiKey:
|
|
1292
|
-
apiSecret:
|
|
1293
|
-
fetchImpl:
|
|
1302
|
+
baseUrl: cfg.baseUrl,
|
|
1303
|
+
apiKey: cfg.apiKey,
|
|
1304
|
+
apiSecret: cfg.apiSecret,
|
|
1305
|
+
fetchImpl: cfg.fetch,
|
|
1294
1306
|
requestLoggingEnabled: this.requestLoggingEnabled,
|
|
1295
1307
|
responseLoggingEnabled: this.responseLoggingEnabled,
|
|
1296
|
-
retryEnabled:
|
|
1297
|
-
maxRetries:
|
|
1298
|
-
retryInitialDelayMs:
|
|
1308
|
+
retryEnabled: cfg.retryEnabled,
|
|
1309
|
+
maxRetries: cfg.maxRetries,
|
|
1310
|
+
retryInitialDelayMs: cfg.retryInitialDelayMs
|
|
1299
1311
|
});
|
|
1300
1312
|
}
|
|
1301
1313
|
return {
|
|
1302
1314
|
http: this.http,
|
|
1303
|
-
fetchImpl:
|
|
1304
|
-
baseUrl:
|
|
1305
|
-
databaseId:
|
|
1315
|
+
fetchImpl: cfg.fetch,
|
|
1316
|
+
baseUrl: cfg.baseUrl,
|
|
1317
|
+
databaseId: cfg.databaseId,
|
|
1318
|
+
defaultModel: cfg.defaultModel ?? DEFAULT_AI_MODEL
|
|
1306
1319
|
};
|
|
1307
1320
|
}
|
|
1308
1321
|
async ensureAiClient() {
|
|
1309
|
-
|
|
1310
|
-
this.resolved = await this.cfgPromise;
|
|
1311
|
-
}
|
|
1322
|
+
const cfg = await this.resolveConfig();
|
|
1312
1323
|
if (!this.aiHttp) {
|
|
1313
1324
|
this.aiHttp = new HttpClient({
|
|
1314
|
-
baseUrl:
|
|
1315
|
-
apiKey:
|
|
1316
|
-
apiSecret:
|
|
1317
|
-
fetchImpl:
|
|
1325
|
+
baseUrl: cfg.aiBaseUrl,
|
|
1326
|
+
apiKey: cfg.apiKey,
|
|
1327
|
+
apiSecret: cfg.apiSecret,
|
|
1328
|
+
fetchImpl: cfg.fetch,
|
|
1318
1329
|
requestLoggingEnabled: this.requestLoggingEnabled,
|
|
1319
1330
|
responseLoggingEnabled: this.responseLoggingEnabled,
|
|
1320
|
-
retryEnabled:
|
|
1321
|
-
maxRetries:
|
|
1322
|
-
retryInitialDelayMs:
|
|
1331
|
+
retryEnabled: cfg.retryEnabled,
|
|
1332
|
+
maxRetries: cfg.maxRetries,
|
|
1333
|
+
retryInitialDelayMs: cfg.retryInitialDelayMs
|
|
1323
1334
|
});
|
|
1324
1335
|
}
|
|
1325
1336
|
return {
|
|
1326
1337
|
http: this.aiHttp,
|
|
1327
|
-
fetchImpl:
|
|
1328
|
-
aiBaseUrl:
|
|
1329
|
-
databaseId:
|
|
1338
|
+
fetchImpl: cfg.fetch,
|
|
1339
|
+
aiBaseUrl: cfg.aiBaseUrl,
|
|
1340
|
+
databaseId: cfg.databaseId,
|
|
1341
|
+
defaultModel: cfg.defaultModel ?? DEFAULT_AI_MODEL
|
|
1330
1342
|
};
|
|
1331
1343
|
}
|
|
1332
1344
|
registerStream(handle) {
|
|
@@ -1341,6 +1353,21 @@ var OnyxDatabaseImpl = class {
|
|
|
1341
1353
|
}
|
|
1342
1354
|
};
|
|
1343
1355
|
}
|
|
1356
|
+
createAiFacade() {
|
|
1357
|
+
const chat = ((contentOrRequest, options) => {
|
|
1358
|
+
if (typeof contentOrRequest === "string") {
|
|
1359
|
+
return this.chatWithContent(contentOrRequest, options);
|
|
1360
|
+
}
|
|
1361
|
+
return this.getAiChatClient().create(contentOrRequest, options);
|
|
1362
|
+
});
|
|
1363
|
+
return {
|
|
1364
|
+
chat,
|
|
1365
|
+
chatClient: () => this.getAiChatClient(),
|
|
1366
|
+
getModels: () => this.getModels(),
|
|
1367
|
+
getModel: (modelId) => this.getModel(modelId),
|
|
1368
|
+
requestScriptApproval: (input) => this.requestScriptApproval(input)
|
|
1369
|
+
};
|
|
1370
|
+
}
|
|
1344
1371
|
getRequestLoggingEnabled() {
|
|
1345
1372
|
return this.requestLoggingEnabled;
|
|
1346
1373
|
}
|
|
@@ -1348,7 +1375,7 @@ var OnyxDatabaseImpl = class {
|
|
|
1348
1375
|
return this.responseLoggingEnabled;
|
|
1349
1376
|
}
|
|
1350
1377
|
/** -------- IOnyxDatabase -------- */
|
|
1351
|
-
|
|
1378
|
+
getAiChatClient() {
|
|
1352
1379
|
return new AiChatClientImpl(
|
|
1353
1380
|
() => this.ensureAiClient(),
|
|
1354
1381
|
(handle) => this.registerStream(handle),
|
|
@@ -1356,6 +1383,32 @@ var OnyxDatabaseImpl = class {
|
|
|
1356
1383
|
() => this.responseLoggingEnabled
|
|
1357
1384
|
);
|
|
1358
1385
|
}
|
|
1386
|
+
async chatWithContent(content, options) {
|
|
1387
|
+
const { defaultModel } = await this.ensureAiClient();
|
|
1388
|
+
const stream = options?.stream ?? false;
|
|
1389
|
+
const request = {
|
|
1390
|
+
model: options?.model ?? defaultModel,
|
|
1391
|
+
messages: [{ role: options?.role ?? "user", content }],
|
|
1392
|
+
stream
|
|
1393
|
+
};
|
|
1394
|
+
if (options && "temperature" in options) {
|
|
1395
|
+
request.temperature = options.temperature ?? null;
|
|
1396
|
+
}
|
|
1397
|
+
const result = await this.getAiChatClient().create(request, options);
|
|
1398
|
+
if (stream) return result;
|
|
1399
|
+
if (options?.raw) return result;
|
|
1400
|
+
const first = result.choices?.[0]?.message?.content;
|
|
1401
|
+
if (typeof first === "string" && first.trim().length > 0) {
|
|
1402
|
+
return first;
|
|
1403
|
+
}
|
|
1404
|
+
throw new Error("Chat completion response is missing message content");
|
|
1405
|
+
}
|
|
1406
|
+
chat(content, options) {
|
|
1407
|
+
if (typeof content === "string") {
|
|
1408
|
+
return this.chatWithContent(content, options);
|
|
1409
|
+
}
|
|
1410
|
+
return this.getAiChatClient();
|
|
1411
|
+
}
|
|
1359
1412
|
async getModels() {
|
|
1360
1413
|
const { http } = await this.ensureAiClient();
|
|
1361
1414
|
return http.request("GET", "/v1/models");
|