@onyx.dev/onyx-database 1.1.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/dist/edge.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { O as OnyxFacade } from './aggregates-DodZNu9-.cjs';
2
- export { G as FetchImpl, E as FetchResponse, F as FullTextQuery, V as ICascadeBuilder, W as ICascadeRelationshipBuilder, N as IConditionBuilder, I as IOnyxDatabase, P as IQueryBuilder, T as ISaveBuilder, L as LogicalOperator, b as OnyxConfig, D as OnyxDocument, J as QueryCondition, H as QueryCriteria, A as QueryCriteriaOperator, M as QueryPage, Q as QueryResults, a as QueryResultsPromise, R as RetryOptions, i as SchemaAttribute, u as SchemaAttributeChange, f as SchemaDataType, z as SchemaDiff, o as SchemaEntity, r as SchemaHistoryEntry, h as SchemaIdentifier, g as SchemaIdentifierGenerator, k as SchemaIndex, v as SchemaIndexChange, j as SchemaIndexType, l as SchemaResolver, w as SchemaResolverChange, q as SchemaRevision, p as SchemaRevisionMetadata, y as SchemaTableDiff, n as SchemaTrigger, x as SchemaTriggerChange, m as SchemaTriggerEvent, s as SchemaUpsertRequest, t as SchemaValidationResult, S as SecretMetadata, c as SecretRecord, e as SecretSaveRequest, d as SecretsListResponse, K as SelectQuery, B as Sort, C as StreamAction, U as UpdateQuery, X as asc, al as avg, a3 as between, ad as contains, ae as containsIgnoreCase, an as count, Y as desc, Z as eq, a4 as gt, a5 as gte, $ as inOp, aj as isNull, ab as like, au as lower, a6 as lt, a7 as lte, a8 as matches, ap as max, as as median, ao as min, _ as neq, af as notContains, ag as notContainsIgnoreCase, a1 as notIn, ac as notLike, aa as notMatches, ak as notNull, ai as notStartsWith, a2 as notWithin, ax as percentile, aw as replace, a9 as search, ah as startsWith, aq as std, av as substring, am as sum, at as upper, ar as variance, a0 as within } from './aggregates-DodZNu9-.cjs';
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-DodZNu9-.js';
2
- export { G as FetchImpl, E as FetchResponse, F as FullTextQuery, V as ICascadeBuilder, W as ICascadeRelationshipBuilder, N as IConditionBuilder, I as IOnyxDatabase, P as IQueryBuilder, T as ISaveBuilder, L as LogicalOperator, b as OnyxConfig, D as OnyxDocument, J as QueryCondition, H as QueryCriteria, A as QueryCriteriaOperator, M as QueryPage, Q as QueryResults, a as QueryResultsPromise, R as RetryOptions, i as SchemaAttribute, u as SchemaAttributeChange, f as SchemaDataType, z as SchemaDiff, o as SchemaEntity, r as SchemaHistoryEntry, h as SchemaIdentifier, g as SchemaIdentifierGenerator, k as SchemaIndex, v as SchemaIndexChange, j as SchemaIndexType, l as SchemaResolver, w as SchemaResolverChange, q as SchemaRevision, p as SchemaRevisionMetadata, y as SchemaTableDiff, n as SchemaTrigger, x as SchemaTriggerChange, m as SchemaTriggerEvent, s as SchemaUpsertRequest, t as SchemaValidationResult, S as SecretMetadata, c as SecretRecord, e as SecretSaveRequest, d as SecretsListResponse, K as SelectQuery, B as Sort, C as StreamAction, U as UpdateQuery, X as asc, al as avg, a3 as between, ad as contains, ae as containsIgnoreCase, an as count, Y as desc, Z as eq, a4 as gt, a5 as gte, $ as inOp, aj as isNull, ab as like, au as lower, a6 as lt, a7 as lte, a8 as matches, ap as max, as as median, ao as min, _ as neq, af as notContains, ag as notContainsIgnoreCase, a1 as notIn, ac as notLike, aa as notMatches, ak as notNull, ai as notStartsWith, a2 as notWithin, ax as percentile, aw as replace, a9 as search, ah as startsWith, aq as std, av as substring, am as sum, at as upper, ar as variance, a0 as within } from './aggregates-DodZNu9-.js';
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,5 +1,7 @@
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";
4
+ var DEFAULT_AI_MODEL = "onyx";
3
5
  var sanitizeBaseUrl = (u) => u.replace(/\/+$/, "");
4
6
 
5
7
  // src/errors/config-error.ts
@@ -51,6 +53,8 @@ function readEnv(targetId) {
51
53
  if (targetId && envId !== targetId) return {};
52
54
  const res = dropUndefined({
53
55
  baseUrl: pick("ONYX_DATABASE_BASE_URL"),
56
+ aiBaseUrl: pick("ONYX_AI_BASE_URL"),
57
+ defaultModel: pick("ONYX_DEFAULT_MODEL"),
54
58
  databaseId: envId,
55
59
  apiKey: pick("ONYX_DATABASE_API_KEY"),
56
60
  apiSecret: pick("ONYX_DATABASE_API_SECRET")
@@ -69,11 +73,15 @@ async function resolveConfig(input) {
69
73
  const env = readEnv(input?.databaseId);
70
74
  const merged = {
71
75
  baseUrl: DEFAULT_BASE_URL,
76
+ aiBaseUrl: DEFAULT_AI_BASE_URL,
77
+ defaultModel: DEFAULT_AI_MODEL,
72
78
  ...dropUndefined(env),
73
79
  ...dropUndefined(input)
74
80
  };
75
81
  dbg("merged (pre-validate):", mask(merged));
76
82
  const baseUrl = sanitizeBaseUrl(merged.baseUrl ?? DEFAULT_BASE_URL);
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;
77
85
  const databaseId = merged.databaseId ?? "";
78
86
  const apiKey = merged.apiKey ?? "";
79
87
  const apiSecret = merged.apiSecret ?? "";
@@ -98,6 +106,8 @@ async function resolveConfig(input) {
98
106
  }
99
107
  const resolved = {
100
108
  baseUrl,
109
+ aiBaseUrl,
110
+ defaultModel,
101
111
  databaseId,
102
112
  apiKey,
103
113
  apiSecret,
@@ -1118,38 +1128,69 @@ var OnyxDatabaseImpl = class {
1118
1128
  cfgPromise;
1119
1129
  resolved = null;
1120
1130
  http = null;
1131
+ aiHttp = null;
1121
1132
  streams = /* @__PURE__ */ new Set();
1122
1133
  requestLoggingEnabled;
1123
1134
  responseLoggingEnabled;
1124
1135
  defaultPartition;
1136
+ ai;
1125
1137
  constructor(config, resolveConfigWithCache) {
1126
1138
  this.requestLoggingEnabled = !!config?.requestLoggingEnabled;
1127
1139
  this.responseLoggingEnabled = !!config?.responseLoggingEnabled;
1128
1140
  this.defaultPartition = config?.partition;
1129
1141
  this.cfgPromise = resolveConfigWithCache(config);
1142
+ this.ai = this.createAiFacade();
1130
1143
  }
1131
- async ensureClient() {
1144
+ async resolveConfig() {
1132
1145
  if (!this.resolved) {
1133
1146
  this.resolved = await this.cfgPromise;
1134
1147
  }
1148
+ return this.resolved;
1149
+ }
1150
+ async ensureClient() {
1151
+ const cfg = await this.resolveConfig();
1135
1152
  if (!this.http) {
1136
1153
  this.http = new HttpClient({
1137
- baseUrl: this.resolved.baseUrl,
1138
- apiKey: this.resolved.apiKey,
1139
- apiSecret: this.resolved.apiSecret,
1140
- fetchImpl: this.resolved.fetch,
1154
+ baseUrl: cfg.baseUrl,
1155
+ apiKey: cfg.apiKey,
1156
+ apiSecret: cfg.apiSecret,
1157
+ fetchImpl: cfg.fetch,
1141
1158
  requestLoggingEnabled: this.requestLoggingEnabled,
1142
1159
  responseLoggingEnabled: this.responseLoggingEnabled,
1143
- retryEnabled: this.resolved.retryEnabled,
1144
- maxRetries: this.resolved.maxRetries,
1145
- retryInitialDelayMs: this.resolved.retryInitialDelayMs
1160
+ retryEnabled: cfg.retryEnabled,
1161
+ maxRetries: cfg.maxRetries,
1162
+ retryInitialDelayMs: cfg.retryInitialDelayMs
1146
1163
  });
1147
1164
  }
1148
1165
  return {
1149
1166
  http: this.http,
1150
- fetchImpl: this.resolved.fetch,
1151
- baseUrl: this.resolved.baseUrl,
1152
- databaseId: this.resolved.databaseId
1167
+ fetchImpl: cfg.fetch,
1168
+ baseUrl: cfg.baseUrl,
1169
+ databaseId: cfg.databaseId,
1170
+ defaultModel: cfg.defaultModel ?? DEFAULT_AI_MODEL
1171
+ };
1172
+ }
1173
+ async ensureAiClient() {
1174
+ const cfg = await this.resolveConfig();
1175
+ if (!this.aiHttp) {
1176
+ this.aiHttp = new HttpClient({
1177
+ baseUrl: cfg.aiBaseUrl,
1178
+ apiKey: cfg.apiKey,
1179
+ apiSecret: cfg.apiSecret,
1180
+ fetchImpl: cfg.fetch,
1181
+ requestLoggingEnabled: this.requestLoggingEnabled,
1182
+ responseLoggingEnabled: this.responseLoggingEnabled,
1183
+ retryEnabled: cfg.retryEnabled,
1184
+ maxRetries: cfg.maxRetries,
1185
+ retryInitialDelayMs: cfg.retryInitialDelayMs
1186
+ });
1187
+ }
1188
+ return {
1189
+ http: this.aiHttp,
1190
+ fetchImpl: cfg.fetch,
1191
+ aiBaseUrl: cfg.aiBaseUrl,
1192
+ databaseId: cfg.databaseId,
1193
+ defaultModel: cfg.defaultModel ?? DEFAULT_AI_MODEL
1153
1194
  };
1154
1195
  }
1155
1196
  registerStream(handle) {
@@ -1164,7 +1205,75 @@ var OnyxDatabaseImpl = class {
1164
1205
  }
1165
1206
  };
1166
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
+ }
1223
+ getRequestLoggingEnabled() {
1224
+ return this.requestLoggingEnabled;
1225
+ }
1226
+ getResponseLoggingEnabled() {
1227
+ return this.responseLoggingEnabled;
1228
+ }
1167
1229
  /** -------- IOnyxDatabase -------- */
1230
+ getAiChatClient() {
1231
+ return new AiChatClientImpl(
1232
+ () => this.ensureAiClient(),
1233
+ (handle) => this.registerStream(handle),
1234
+ () => this.requestLoggingEnabled,
1235
+ () => this.responseLoggingEnabled
1236
+ );
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
+ }
1264
+ async getModels() {
1265
+ const { http } = await this.ensureAiClient();
1266
+ return http.request("GET", "/v1/models");
1267
+ }
1268
+ async getModel(modelId) {
1269
+ const { http } = await this.ensureAiClient();
1270
+ const path = `/v1/models/${encodeURIComponent(modelId)}`;
1271
+ return http.request("GET", path);
1272
+ }
1273
+ async requestScriptApproval(input) {
1274
+ const { http } = await this.ensureAiClient();
1275
+ return http.request("POST", "/api/script-approvals", input);
1276
+ }
1168
1277
  from(table) {
1169
1278
  return new QueryBuilderImpl(this, String(table), this.defaultPartition);
1170
1279
  }
@@ -1714,6 +1823,153 @@ var CascadeBuilderImpl = class {
1714
1823
  return this.db.delete(table, primaryKey, opts);
1715
1824
  }
1716
1825
  };
1826
+ var AiChatClientImpl = class {
1827
+ constructor(resolveAiClient, registerStream, requestLoggingEnabled, responseLoggingEnabled) {
1828
+ this.resolveAiClient = resolveAiClient;
1829
+ this.registerStream = registerStream;
1830
+ this.requestLoggingEnabled = requestLoggingEnabled;
1831
+ this.responseLoggingEnabled = responseLoggingEnabled;
1832
+ }
1833
+ normalizeEventData(rawEvent) {
1834
+ const lines = rawEvent.split("\n");
1835
+ const dataLines = [];
1836
+ for (const line of lines) {
1837
+ const trimmed = line.trim();
1838
+ if (!trimmed || trimmed.startsWith(":")) continue;
1839
+ if (trimmed.startsWith("data:")) {
1840
+ dataLines.push(trimmed.slice(5).trim());
1841
+ } else {
1842
+ dataLines.push(trimmed);
1843
+ }
1844
+ }
1845
+ if (!dataLines.length) return null;
1846
+ const joined = dataLines.join("\n").trim();
1847
+ return joined.length > 0 ? joined : null;
1848
+ }
1849
+ logRequest(url, body, headers) {
1850
+ if (!this.requestLoggingEnabled()) return;
1851
+ console.log(`POST ${url}`);
1852
+ if (body != null) {
1853
+ const serialized = typeof body === "string" ? body : JSON.stringify(body);
1854
+ console.log(serialized);
1855
+ }
1856
+ const headerLog = { ...headers };
1857
+ if (headerLog["x-onyx-secret"]) headerLog["x-onyx-secret"] = "[REDACTED]";
1858
+ console.log("Headers:", headerLog);
1859
+ }
1860
+ logResponse(status, statusText, raw) {
1861
+ if (!this.responseLoggingEnabled()) return;
1862
+ const statusLine = `${status} ${statusText}`.trim();
1863
+ console.log(statusLine);
1864
+ if (raw && raw.trim().length > 0) {
1865
+ console.log(raw);
1866
+ }
1867
+ }
1868
+ toOnyxError(status, statusText, raw) {
1869
+ let parsed = raw;
1870
+ try {
1871
+ parsed = parseJsonAllowNaN(raw);
1872
+ } catch {
1873
+ }
1874
+ 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}`;
1875
+ return new OnyxHttpError(message, status, statusText, parsed, raw);
1876
+ }
1877
+ async create(request, options) {
1878
+ const body = { ...request, stream: !!request.stream };
1879
+ const { http, fetchImpl, aiBaseUrl, databaseId } = await this.resolveAiClient();
1880
+ const params = new URLSearchParams();
1881
+ const scopedDb = options?.databaseId ?? databaseId;
1882
+ if (scopedDb) params.append("databaseId", scopedDb);
1883
+ const path = `/v1/chat/completions${params.size ? `?${params.toString()}` : ""}`;
1884
+ if (!body.stream) {
1885
+ return http.request("POST", path, body);
1886
+ }
1887
+ const url = `${aiBaseUrl}${path}`;
1888
+ const headers = http.headers({ Accept: "text/event-stream" });
1889
+ this.logRequest(url, body, headers);
1890
+ const res = await fetchImpl(url, {
1891
+ method: "POST",
1892
+ headers,
1893
+ body: JSON.stringify(body)
1894
+ });
1895
+ if (!res.ok) {
1896
+ const raw = await res.text();
1897
+ this.logResponse(res.status, res.statusText, raw);
1898
+ throw this.toOnyxError(res.status, res.statusText, raw);
1899
+ }
1900
+ this.logResponse(res.status, res.statusText);
1901
+ const bodyStream = res.body;
1902
+ const reader = bodyStream && typeof bodyStream.getReader === "function" ? bodyStream.getReader() : null;
1903
+ if (!reader) {
1904
+ throw new OnyxHttpError(
1905
+ "Streaming response body is not readable",
1906
+ res.status,
1907
+ res.statusText,
1908
+ null,
1909
+ ""
1910
+ );
1911
+ }
1912
+ let canceled = false;
1913
+ const handle = {
1914
+ cancel: () => {
1915
+ if (canceled) return;
1916
+ canceled = true;
1917
+ try {
1918
+ reader.cancel?.();
1919
+ } catch {
1920
+ }
1921
+ }
1922
+ };
1923
+ const registered = this.registerStream(handle);
1924
+ const normalizeEvent = (rawEvent) => this.normalizeEventData(rawEvent);
1925
+ const stream = {
1926
+ async *[Symbol.asyncIterator]() {
1927
+ const decoder = new TextDecoder("utf-8");
1928
+ let buffer = "";
1929
+ try {
1930
+ while (!canceled) {
1931
+ const { done, value } = await reader.read();
1932
+ if (done) break;
1933
+ if (value) {
1934
+ buffer += decoder.decode(value, { stream: true });
1935
+ }
1936
+ let splitIndex = buffer.indexOf("\n\n");
1937
+ while (splitIndex !== -1) {
1938
+ const rawEvent = buffer.slice(0, splitIndex);
1939
+ buffer = buffer.slice(splitIndex + 2);
1940
+ const data = normalizeEvent(rawEvent);
1941
+ if (data === "[DONE]") return;
1942
+ if (data) {
1943
+ try {
1944
+ yield parseJsonAllowNaN(data);
1945
+ } catch {
1946
+ }
1947
+ }
1948
+ splitIndex = buffer.indexOf("\n\n");
1949
+ }
1950
+ }
1951
+ buffer += decoder.decode();
1952
+ const remaining = buffer.trim();
1953
+ if (remaining && remaining !== "[DONE]") {
1954
+ const data = normalizeEvent(remaining);
1955
+ if (data && data !== "[DONE]") {
1956
+ try {
1957
+ yield parseJsonAllowNaN(data);
1958
+ } catch {
1959
+ }
1960
+ }
1961
+ }
1962
+ } finally {
1963
+ registered.cancel();
1964
+ }
1965
+ },
1966
+ cancel() {
1967
+ registered.cancel();
1968
+ }
1969
+ };
1970
+ return stream;
1971
+ }
1972
+ };
1717
1973
  function createOnyxFacade(resolveConfig2) {
1718
1974
  let cachedCfg = null;
1719
1975
  function resolveConfigWithCache(config) {