@onyx.dev/onyx-database 1.1.0 → 1.2.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 +108 -0
- package/dist/{aggregates-DodZNu9-.d.cts → aggregates-LoteczVS.d.cts} +185 -1
- package/dist/{aggregates-DodZNu9-.d.ts → aggregates-LoteczVS.d.ts} +185 -1
- package/dist/edge.cjs +204 -0
- 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 +204 -0
- package/dist/edge.js.map +1 -1
- package/dist/gen/cli/generate.cjs +205 -0
- package/dist/gen/cli/generate.cjs.map +1 -1
- package/dist/index.cjs +205 -0
- 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 +205 -0
- package/dist/index.js.map +1 -1
- package/dist/schema/cli/schema.cjs +206 -0
- 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-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';
|
|
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-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';
|
|
3
3
|
|
|
4
4
|
declare const onyx: OnyxFacade;
|
|
5
5
|
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/config/defaults.ts
|
|
2
2
|
var DEFAULT_BASE_URL = "https://api.onyx.dev";
|
|
3
|
+
var DEFAULT_AI_BASE_URL = "https://ai.onyx.dev";
|
|
3
4
|
var sanitizeBaseUrl = (u) => u.replace(/\/+$/, "");
|
|
4
5
|
|
|
5
6
|
// src/errors/config-error.ts
|
|
@@ -58,6 +59,7 @@ function readEnv(targetId) {
|
|
|
58
59
|
if (targetId && envId !== targetId) return {};
|
|
59
60
|
const res = dropUndefined({
|
|
60
61
|
baseUrl: pick("ONYX_DATABASE_BASE_URL"),
|
|
62
|
+
aiBaseUrl: pick("ONYX_AI_BASE_URL"),
|
|
61
63
|
databaseId: envId,
|
|
62
64
|
apiKey: pick("ONYX_DATABASE_API_KEY"),
|
|
63
65
|
apiSecret: pick("ONYX_DATABASE_API_SECRET")
|
|
@@ -194,6 +196,7 @@ async function resolveConfig(input) {
|
|
|
194
196
|
}
|
|
195
197
|
const merged = {
|
|
196
198
|
baseUrl: DEFAULT_BASE_URL,
|
|
199
|
+
aiBaseUrl: DEFAULT_AI_BASE_URL,
|
|
197
200
|
...dropUndefined(home),
|
|
198
201
|
...dropUndefined(project),
|
|
199
202
|
...dropUndefined(cfgPath),
|
|
@@ -202,6 +205,7 @@ async function resolveConfig(input) {
|
|
|
202
205
|
};
|
|
203
206
|
dbg("merged (pre-validate):", mask(merged));
|
|
204
207
|
const baseUrl = sanitizeBaseUrl(merged.baseUrl ?? DEFAULT_BASE_URL);
|
|
208
|
+
const aiBaseUrl = sanitizeBaseUrl(merged.aiBaseUrl ?? DEFAULT_AI_BASE_URL);
|
|
205
209
|
const databaseId = merged.databaseId ?? "";
|
|
206
210
|
const apiKey = merged.apiKey ?? "";
|
|
207
211
|
const apiSecret = merged.apiSecret ?? "";
|
|
@@ -237,6 +241,7 @@ async function resolveConfig(input) {
|
|
|
237
241
|
}
|
|
238
242
|
const resolved = {
|
|
239
243
|
baseUrl,
|
|
244
|
+
aiBaseUrl,
|
|
240
245
|
databaseId,
|
|
241
246
|
apiKey,
|
|
242
247
|
apiSecret,
|
|
@@ -247,6 +252,7 @@ async function resolveConfig(input) {
|
|
|
247
252
|
};
|
|
248
253
|
const source = {
|
|
249
254
|
databaseId: input?.databaseId ? "explicit config" : env.databaseId ? "env" : cfgPath.databaseId ? "env ONYX_CONFIG_PATH" : project.databaseId ? "project file" : home.databaseId ? "home profile" : "unknown",
|
|
255
|
+
aiBaseUrl: input?.aiBaseUrl ? "explicit config" : env.aiBaseUrl ? "env" : cfgPath.aiBaseUrl ? "env ONYX_CONFIG_PATH" : project.aiBaseUrl ? "project file" : home.aiBaseUrl ? "home profile" : "default",
|
|
250
256
|
apiKey: input?.apiKey ? "explicit config" : env.apiKey ? "env" : cfgPath.apiKey ? "env ONYX_CONFIG_PATH" : project.apiKey ? "project file" : home.apiKey ? "home profile" : "unknown",
|
|
251
257
|
apiSecret: input?.apiSecret ? "explicit config" : env.apiSecret ? "env" : cfgPath.apiSecret ? "env ONYX_CONFIG_PATH" : project.apiSecret ? "project file" : home.apiSecret ? "home profile" : "unknown"
|
|
252
258
|
};
|
|
@@ -1264,6 +1270,7 @@ var OnyxDatabaseImpl = class {
|
|
|
1264
1270
|
cfgPromise;
|
|
1265
1271
|
resolved = null;
|
|
1266
1272
|
http = null;
|
|
1273
|
+
aiHttp = null;
|
|
1267
1274
|
streams = /* @__PURE__ */ new Set();
|
|
1268
1275
|
requestLoggingEnabled;
|
|
1269
1276
|
responseLoggingEnabled;
|
|
@@ -1298,6 +1305,30 @@ var OnyxDatabaseImpl = class {
|
|
|
1298
1305
|
databaseId: this.resolved.databaseId
|
|
1299
1306
|
};
|
|
1300
1307
|
}
|
|
1308
|
+
async ensureAiClient() {
|
|
1309
|
+
if (!this.resolved) {
|
|
1310
|
+
this.resolved = await this.cfgPromise;
|
|
1311
|
+
}
|
|
1312
|
+
if (!this.aiHttp) {
|
|
1313
|
+
this.aiHttp = new HttpClient({
|
|
1314
|
+
baseUrl: this.resolved.aiBaseUrl,
|
|
1315
|
+
apiKey: this.resolved.apiKey,
|
|
1316
|
+
apiSecret: this.resolved.apiSecret,
|
|
1317
|
+
fetchImpl: this.resolved.fetch,
|
|
1318
|
+
requestLoggingEnabled: this.requestLoggingEnabled,
|
|
1319
|
+
responseLoggingEnabled: this.responseLoggingEnabled,
|
|
1320
|
+
retryEnabled: this.resolved.retryEnabled,
|
|
1321
|
+
maxRetries: this.resolved.maxRetries,
|
|
1322
|
+
retryInitialDelayMs: this.resolved.retryInitialDelayMs
|
|
1323
|
+
});
|
|
1324
|
+
}
|
|
1325
|
+
return {
|
|
1326
|
+
http: this.aiHttp,
|
|
1327
|
+
fetchImpl: this.resolved.fetch,
|
|
1328
|
+
aiBaseUrl: this.resolved.aiBaseUrl,
|
|
1329
|
+
databaseId: this.resolved.databaseId
|
|
1330
|
+
};
|
|
1331
|
+
}
|
|
1301
1332
|
registerStream(handle) {
|
|
1302
1333
|
this.streams.add(handle);
|
|
1303
1334
|
return {
|
|
@@ -1310,7 +1341,34 @@ var OnyxDatabaseImpl = class {
|
|
|
1310
1341
|
}
|
|
1311
1342
|
};
|
|
1312
1343
|
}
|
|
1344
|
+
getRequestLoggingEnabled() {
|
|
1345
|
+
return this.requestLoggingEnabled;
|
|
1346
|
+
}
|
|
1347
|
+
getResponseLoggingEnabled() {
|
|
1348
|
+
return this.responseLoggingEnabled;
|
|
1349
|
+
}
|
|
1313
1350
|
/** -------- IOnyxDatabase -------- */
|
|
1351
|
+
chat() {
|
|
1352
|
+
return new AiChatClientImpl(
|
|
1353
|
+
() => this.ensureAiClient(),
|
|
1354
|
+
(handle) => this.registerStream(handle),
|
|
1355
|
+
() => this.requestLoggingEnabled,
|
|
1356
|
+
() => this.responseLoggingEnabled
|
|
1357
|
+
);
|
|
1358
|
+
}
|
|
1359
|
+
async getModels() {
|
|
1360
|
+
const { http } = await this.ensureAiClient();
|
|
1361
|
+
return http.request("GET", "/v1/models");
|
|
1362
|
+
}
|
|
1363
|
+
async getModel(modelId) {
|
|
1364
|
+
const { http } = await this.ensureAiClient();
|
|
1365
|
+
const path = `/v1/models/${encodeURIComponent(modelId)}`;
|
|
1366
|
+
return http.request("GET", path);
|
|
1367
|
+
}
|
|
1368
|
+
async requestScriptApproval(input) {
|
|
1369
|
+
const { http } = await this.ensureAiClient();
|
|
1370
|
+
return http.request("POST", "/api/script-approvals", input);
|
|
1371
|
+
}
|
|
1314
1372
|
from(table) {
|
|
1315
1373
|
return new QueryBuilderImpl(this, String(table), this.defaultPartition);
|
|
1316
1374
|
}
|
|
@@ -1860,6 +1918,153 @@ var CascadeBuilderImpl = class {
|
|
|
1860
1918
|
return this.db.delete(table, primaryKey, opts);
|
|
1861
1919
|
}
|
|
1862
1920
|
};
|
|
1921
|
+
var AiChatClientImpl = class {
|
|
1922
|
+
constructor(resolveAiClient, registerStream, requestLoggingEnabled, responseLoggingEnabled) {
|
|
1923
|
+
this.resolveAiClient = resolveAiClient;
|
|
1924
|
+
this.registerStream = registerStream;
|
|
1925
|
+
this.requestLoggingEnabled = requestLoggingEnabled;
|
|
1926
|
+
this.responseLoggingEnabled = responseLoggingEnabled;
|
|
1927
|
+
}
|
|
1928
|
+
normalizeEventData(rawEvent) {
|
|
1929
|
+
const lines = rawEvent.split("\n");
|
|
1930
|
+
const dataLines = [];
|
|
1931
|
+
for (const line of lines) {
|
|
1932
|
+
const trimmed = line.trim();
|
|
1933
|
+
if (!trimmed || trimmed.startsWith(":")) continue;
|
|
1934
|
+
if (trimmed.startsWith("data:")) {
|
|
1935
|
+
dataLines.push(trimmed.slice(5).trim());
|
|
1936
|
+
} else {
|
|
1937
|
+
dataLines.push(trimmed);
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
if (!dataLines.length) return null;
|
|
1941
|
+
const joined = dataLines.join("\n").trim();
|
|
1942
|
+
return joined.length > 0 ? joined : null;
|
|
1943
|
+
}
|
|
1944
|
+
logRequest(url, body, headers) {
|
|
1945
|
+
if (!this.requestLoggingEnabled()) return;
|
|
1946
|
+
console.log(`POST ${url}`);
|
|
1947
|
+
if (body != null) {
|
|
1948
|
+
const serialized = typeof body === "string" ? body : JSON.stringify(body);
|
|
1949
|
+
console.log(serialized);
|
|
1950
|
+
}
|
|
1951
|
+
const headerLog = { ...headers };
|
|
1952
|
+
if (headerLog["x-onyx-secret"]) headerLog["x-onyx-secret"] = "[REDACTED]";
|
|
1953
|
+
console.log("Headers:", headerLog);
|
|
1954
|
+
}
|
|
1955
|
+
logResponse(status, statusText, raw) {
|
|
1956
|
+
if (!this.responseLoggingEnabled()) return;
|
|
1957
|
+
const statusLine = `${status} ${statusText}`.trim();
|
|
1958
|
+
console.log(statusLine);
|
|
1959
|
+
if (raw && raw.trim().length > 0) {
|
|
1960
|
+
console.log(raw);
|
|
1961
|
+
}
|
|
1962
|
+
}
|
|
1963
|
+
toOnyxError(status, statusText, raw) {
|
|
1964
|
+
let parsed = raw;
|
|
1965
|
+
try {
|
|
1966
|
+
parsed = parseJsonAllowNaN(raw);
|
|
1967
|
+
} catch {
|
|
1968
|
+
}
|
|
1969
|
+
const message = typeof parsed === "object" && parsed !== null && "error" in parsed && typeof parsed.error === "object" && typeof parsed.error?.message === "string" ? String(parsed.error.message) : `${status} ${statusText}`;
|
|
1970
|
+
return new OnyxHttpError(message, status, statusText, parsed, raw);
|
|
1971
|
+
}
|
|
1972
|
+
async create(request, options) {
|
|
1973
|
+
const body = { ...request, stream: !!request.stream };
|
|
1974
|
+
const { http, fetchImpl, aiBaseUrl, databaseId } = await this.resolveAiClient();
|
|
1975
|
+
const params = new URLSearchParams();
|
|
1976
|
+
const scopedDb = options?.databaseId ?? databaseId;
|
|
1977
|
+
if (scopedDb) params.append("databaseId", scopedDb);
|
|
1978
|
+
const path = `/v1/chat/completions${params.size ? `?${params.toString()}` : ""}`;
|
|
1979
|
+
if (!body.stream) {
|
|
1980
|
+
return http.request("POST", path, body);
|
|
1981
|
+
}
|
|
1982
|
+
const url = `${aiBaseUrl}${path}`;
|
|
1983
|
+
const headers = http.headers({ Accept: "text/event-stream" });
|
|
1984
|
+
this.logRequest(url, body, headers);
|
|
1985
|
+
const res = await fetchImpl(url, {
|
|
1986
|
+
method: "POST",
|
|
1987
|
+
headers,
|
|
1988
|
+
body: JSON.stringify(body)
|
|
1989
|
+
});
|
|
1990
|
+
if (!res.ok) {
|
|
1991
|
+
const raw = await res.text();
|
|
1992
|
+
this.logResponse(res.status, res.statusText, raw);
|
|
1993
|
+
throw this.toOnyxError(res.status, res.statusText, raw);
|
|
1994
|
+
}
|
|
1995
|
+
this.logResponse(res.status, res.statusText);
|
|
1996
|
+
const bodyStream = res.body;
|
|
1997
|
+
const reader = bodyStream && typeof bodyStream.getReader === "function" ? bodyStream.getReader() : null;
|
|
1998
|
+
if (!reader) {
|
|
1999
|
+
throw new OnyxHttpError(
|
|
2000
|
+
"Streaming response body is not readable",
|
|
2001
|
+
res.status,
|
|
2002
|
+
res.statusText,
|
|
2003
|
+
null,
|
|
2004
|
+
""
|
|
2005
|
+
);
|
|
2006
|
+
}
|
|
2007
|
+
let canceled = false;
|
|
2008
|
+
const handle = {
|
|
2009
|
+
cancel: () => {
|
|
2010
|
+
if (canceled) return;
|
|
2011
|
+
canceled = true;
|
|
2012
|
+
try {
|
|
2013
|
+
reader.cancel?.();
|
|
2014
|
+
} catch {
|
|
2015
|
+
}
|
|
2016
|
+
}
|
|
2017
|
+
};
|
|
2018
|
+
const registered = this.registerStream(handle);
|
|
2019
|
+
const normalizeEvent = (rawEvent) => this.normalizeEventData(rawEvent);
|
|
2020
|
+
const stream = {
|
|
2021
|
+
async *[Symbol.asyncIterator]() {
|
|
2022
|
+
const decoder = new TextDecoder("utf-8");
|
|
2023
|
+
let buffer = "";
|
|
2024
|
+
try {
|
|
2025
|
+
while (!canceled) {
|
|
2026
|
+
const { done, value } = await reader.read();
|
|
2027
|
+
if (done) break;
|
|
2028
|
+
if (value) {
|
|
2029
|
+
buffer += decoder.decode(value, { stream: true });
|
|
2030
|
+
}
|
|
2031
|
+
let splitIndex = buffer.indexOf("\n\n");
|
|
2032
|
+
while (splitIndex !== -1) {
|
|
2033
|
+
const rawEvent = buffer.slice(0, splitIndex);
|
|
2034
|
+
buffer = buffer.slice(splitIndex + 2);
|
|
2035
|
+
const data = normalizeEvent(rawEvent);
|
|
2036
|
+
if (data === "[DONE]") return;
|
|
2037
|
+
if (data) {
|
|
2038
|
+
try {
|
|
2039
|
+
yield parseJsonAllowNaN(data);
|
|
2040
|
+
} catch {
|
|
2041
|
+
}
|
|
2042
|
+
}
|
|
2043
|
+
splitIndex = buffer.indexOf("\n\n");
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
buffer += decoder.decode();
|
|
2047
|
+
const remaining = buffer.trim();
|
|
2048
|
+
if (remaining && remaining !== "[DONE]") {
|
|
2049
|
+
const data = normalizeEvent(remaining);
|
|
2050
|
+
if (data && data !== "[DONE]") {
|
|
2051
|
+
try {
|
|
2052
|
+
yield parseJsonAllowNaN(data);
|
|
2053
|
+
} catch {
|
|
2054
|
+
}
|
|
2055
|
+
}
|
|
2056
|
+
}
|
|
2057
|
+
} finally {
|
|
2058
|
+
registered.cancel();
|
|
2059
|
+
}
|
|
2060
|
+
},
|
|
2061
|
+
cancel() {
|
|
2062
|
+
registered.cancel();
|
|
2063
|
+
}
|
|
2064
|
+
};
|
|
2065
|
+
return stream;
|
|
2066
|
+
}
|
|
2067
|
+
};
|
|
1863
2068
|
function createOnyxFacade(resolveConfig2) {
|
|
1864
2069
|
let cachedCfg = null;
|
|
1865
2070
|
function resolveConfigWithCache(config) {
|