@xylex-group/athena 2.9.0 → 2.10.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.
Files changed (42) hide show
  1. package/README.md +1 -1
  2. package/dist/browser.cjs +828 -74
  3. package/dist/browser.cjs.map +1 -1
  4. package/dist/browser.d.cts +3 -3
  5. package/dist/browser.d.ts +3 -3
  6. package/dist/browser.js +825 -75
  7. package/dist/browser.js.map +1 -1
  8. package/dist/cli/index.cjs +748 -40
  9. package/dist/cli/index.cjs.map +1 -1
  10. package/dist/cli/index.js +748 -40
  11. package/dist/cli/index.js.map +1 -1
  12. package/dist/{client-CfAE_QOj.d.cts → client-B7EQ_hPV.d.cts} +506 -22
  13. package/dist/{client-D6EIJdQS.d.ts → client-BYii6dU9.d.ts} +506 -22
  14. package/dist/index.cjs +828 -74
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +2 -2
  17. package/dist/index.d.ts +2 -2
  18. package/dist/index.js +825 -75
  19. package/dist/index.js.map +1 -1
  20. package/dist/{react-email-BvJ3fj_F.d.cts → module-DC96HJa3.d.cts} +97 -2
  21. package/dist/{react-email-PLAJuZuO.d.ts → module-DbHlxpeR.d.ts} +97 -2
  22. package/dist/next/client.cjs +756 -40
  23. package/dist/next/client.cjs.map +1 -1
  24. package/dist/next/client.d.cts +3 -4
  25. package/dist/next/client.d.ts +3 -4
  26. package/dist/next/client.js +756 -40
  27. package/dist/next/client.js.map +1 -1
  28. package/dist/next/server.cjs +756 -40
  29. package/dist/next/server.cjs.map +1 -1
  30. package/dist/next/server.d.cts +2 -2
  31. package/dist/next/server.d.ts +2 -2
  32. package/dist/next/server.js +756 -40
  33. package/dist/next/server.js.map +1 -1
  34. package/dist/react.cjs +1 -1
  35. package/dist/react.cjs.map +1 -1
  36. package/dist/react.d.cts +2 -3
  37. package/dist/react.d.ts +2 -3
  38. package/dist/react.js +1 -1
  39. package/dist/react.js.map +1 -1
  40. package/dist/{shared-BW6hoLBY.d.cts → shared-BMVGMnti.d.cts} +3 -1
  41. package/dist/{shared-BiJvoURI.d.ts → shared-DRptGBWP.d.ts} +3 -1
  42. package/package.json +1 -1
@@ -138,8 +138,8 @@ function parseCookies(cookieHeader) {
138
138
  });
139
139
  return cookieMap;
140
140
  }
141
- var getSessionCookie = (request, config) => {
142
- const cookies = (request instanceof Headers || !("headers" in request) ? request : request.headers).get("cookie");
141
+ var getSessionCookie = (request2, config) => {
142
+ const cookies = (request2 instanceof Headers || !("headers" in request2) ? request2 : request2.headers).get("cookie");
143
143
  if (!cookies) {
144
144
  return null;
145
145
  }
@@ -162,7 +162,7 @@ var getSessionCookie = (request, config) => {
162
162
 
163
163
  // package.json
164
164
  var package_default = {
165
- version: "2.9.0"
165
+ version: "2.10.0"
166
166
  };
167
167
 
168
168
  // src/sdk-version.ts
@@ -1143,6 +1143,50 @@ function mergeCallOptions(base, override) {
1143
1143
  }
1144
1144
  };
1145
1145
  }
1146
+ function copyDefinedField(target, source, targetKey, sourceKey) {
1147
+ if (!(sourceKey in source)) {
1148
+ return;
1149
+ }
1150
+ const value = source[sourceKey];
1151
+ if (value !== void 0) {
1152
+ target[targetKey] = value;
1153
+ }
1154
+ }
1155
+ function normalizeAdminEmailTemplatePayload(payload) {
1156
+ const normalized = { ...payload };
1157
+ copyDefinedField(normalized, payload, "template_key", "templateKey");
1158
+ copyDefinedField(normalized, payload, "event_type", "eventType");
1159
+ copyDefinedField(normalized, payload, "subject_template", "subjectTemplate");
1160
+ copyDefinedField(normalized, payload, "text_template", "textTemplate");
1161
+ copyDefinedField(normalized, payload, "html_template", "htmlTemplate");
1162
+ copyDefinedField(normalized, payload, "variable_bindings", "variableBindings");
1163
+ copyDefinedField(normalized, payload, "attachment_failure_mode", "attachmentFailureMode");
1164
+ copyDefinedField(normalized, payload, "is_active", "isActive");
1165
+ return normalized;
1166
+ }
1167
+ function toReactEmailTemplateCompatibilityInput(input) {
1168
+ const payload = input;
1169
+ const compatibility = { ...payload };
1170
+ copyDefinedField(compatibility, payload, "templateKey", "template_key");
1171
+ copyDefinedField(compatibility, payload, "eventType", "event_type");
1172
+ copyDefinedField(compatibility, payload, "subjectTemplate", "subject_template");
1173
+ copyDefinedField(compatibility, payload, "textTemplate", "text_template");
1174
+ copyDefinedField(compatibility, payload, "htmlTemplate", "html_template");
1175
+ copyDefinedField(compatibility, payload, "variableBindings", "variable_bindings");
1176
+ copyDefinedField(compatibility, payload, "attachmentFailureMode", "attachment_failure_mode");
1177
+ copyDefinedField(compatibility, payload, "isActive", "is_active");
1178
+ return compatibility;
1179
+ }
1180
+ function normalizeAdminEmailTemplateSendPayload(payload) {
1181
+ const normalized = { ...payload };
1182
+ copyDefinedField(normalized, payload, "template_id", "templateId");
1183
+ copyDefinedField(normalized, payload, "recipient_email", "recipientEmail");
1184
+ copyDefinedField(normalized, payload, "render_variables", "renderVariables");
1185
+ copyDefinedField(normalized, payload, "user_id", "userId");
1186
+ copyDefinedField(normalized, payload, "organization_id", "organizationId");
1187
+ copyDefinedField(normalized, payload, "session_token", "sessionToken");
1188
+ return normalized;
1189
+ }
1146
1190
  function toSessionGuardFailure(sessionResult) {
1147
1191
  if (sessionResult.status === 401 || sessionResult.data == null) {
1148
1192
  return {
@@ -1449,7 +1493,7 @@ function createAuthClient(config = {}) {
1449
1493
  ...config,
1450
1494
  baseUrl: normalizedBaseUrl
1451
1495
  };
1452
- const request = (input, options) => {
1496
+ const request2 = (input, options) => {
1453
1497
  const method = input.method ?? (input.body !== void 0 ? "POST" : inferDefaultMethod(input.endpoint));
1454
1498
  const mergedOptions = mergeCallOptions(input.fetchOptions, options);
1455
1499
  return callAuthEndpoint(
@@ -1462,7 +1506,7 @@ function createAuthClient(config = {}) {
1462
1506
  };
1463
1507
  const postGeneric = (endpoint, input, options) => {
1464
1508
  const { payload, fetchOptions } = extractFetchOptions(input);
1465
- return request(
1509
+ return request2(
1466
1510
  {
1467
1511
  endpoint,
1468
1512
  method: "POST",
@@ -1474,7 +1518,7 @@ function createAuthClient(config = {}) {
1474
1518
  };
1475
1519
  const getGeneric = (endpoint, input, options) => {
1476
1520
  const { fetchOptions } = extractFetchOptions(input);
1477
- return request(
1521
+ return request2(
1478
1522
  {
1479
1523
  endpoint,
1480
1524
  method: "GET",
@@ -1486,7 +1530,7 @@ function createAuthClient(config = {}) {
1486
1530
  const getWithQuery = (endpoint, input, options) => {
1487
1531
  const { payload, fetchOptions } = extractFetchOptions(input);
1488
1532
  const query = payload?.query;
1489
- return request(
1533
+ return request2(
1490
1534
  {
1491
1535
  endpoint,
1492
1536
  method: "GET",
@@ -1504,18 +1548,19 @@ function createAuthClient(config = {}) {
1504
1548
  htmlField: "htmlBody",
1505
1549
  textField: "textBody"
1506
1550
  }, withReactEmailRoute(route));
1507
- const resolveAdminEmailTemplatePayload = (route, input) => resolveReactEmailPayloadFields(input, {
1551
+ const resolveAdminEmailTemplatePayload = (route, input) => resolveReactEmailPayloadFields(toReactEmailTemplateCompatibilityInput(input), {
1508
1552
  htmlField: "htmlTemplate",
1509
1553
  textField: "textTemplate",
1510
1554
  variablesField: "variables"
1511
1555
  }, withReactEmailRoute(route)).then((payload) => {
1556
+ const normalizedPayload = normalizeAdminEmailTemplatePayload(payload);
1512
1557
  if ("variables" in payload && payload.variables !== void 0 && payload.variables !== null) {
1513
1558
  assertAthenaAuthTemplateVariables(
1514
1559
  payload.variables,
1515
1560
  `${route} variables`
1516
1561
  );
1517
1562
  }
1518
- return payload;
1563
+ return normalizedPayload;
1519
1564
  });
1520
1565
  const requireSession = async (input, options) => {
1521
1566
  const sessionInput = input?.fetchOptions ? { fetchOptions: input.fetchOptions } : void 0;
@@ -2091,7 +2136,15 @@ function createAuthClient(config = {}) {
2091
2136
  await resolveAdminEmailTemplatePayload("/admin/email-template/update", input),
2092
2137
  options
2093
2138
  ),
2094
- delete: (input, options) => postGeneric("/admin/email-template/delete", input, options)
2139
+ delete: (input, options) => postGeneric("/admin/email-template/delete", input, options),
2140
+ send: (input, options) => postGeneric(
2141
+ "/admin/email-template/send",
2142
+ normalizeAdminEmailTemplateSendPayload(extractFetchOptions(input).payload),
2143
+ options
2144
+ )
2145
+ },
2146
+ eventType: {
2147
+ list: (input, options) => getWithQuery("/admin/email-event-type/list", input, options)
2095
2148
  }
2096
2149
  },
2097
2150
  emailTemplate: {
@@ -2107,7 +2160,15 @@ function createAuthClient(config = {}) {
2107
2160
  "/admin/email-template/update",
2108
2161
  await resolveAdminEmailTemplatePayload("/admin/email-template/update", input),
2109
2162
  options
2163
+ ),
2164
+ send: (input, options) => postGeneric(
2165
+ "/admin/email-template/send",
2166
+ normalizeAdminEmailTemplateSendPayload(extractFetchOptions(input).payload),
2167
+ options
2110
2168
  )
2169
+ },
2170
+ emailEventType: {
2171
+ list: (input, options) => getWithQuery("/admin/email-event-type/list", input, options)
2111
2172
  }
2112
2173
  },
2113
2174
  apiKey: {
@@ -2147,7 +2208,7 @@ function createAuthClient(config = {}) {
2147
2208
  throw new Error("callback.provider requires non-empty code and state values");
2148
2209
  }
2149
2210
  const endpoint = `/callback/${encodeURIComponent(provider)}`;
2150
- return request({
2211
+ return request2({
2151
2212
  endpoint,
2152
2213
  method: "GET",
2153
2214
  query: {
@@ -2161,7 +2222,7 @@ function createAuthClient(config = {}) {
2161
2222
  };
2162
2223
  return {
2163
2224
  baseUrl: normalizedBaseUrl,
2164
- request,
2225
+ request: request2,
2165
2226
  signIn: {
2166
2227
  email: (input, options) => executePostWithCompatibleInput(
2167
2228
  resolvedConfig,
@@ -2699,16 +2760,16 @@ function createStorageFileModule(base, config = {}) {
2699
2760
  };
2700
2761
  });
2701
2762
  input.onProgress?.(createProgressSnapshot("preparing", sources, 0, 0, 0));
2702
- const uploadUrls = uploadRequests.length === 1 ? [await base.createStorageUploadUrl(uploadRequests[0].uploadRequest, options)] : (await base.createStorageUploadUrls({ files: uploadRequests.map((request) => request.uploadRequest) }, options)).files;
2763
+ const uploadUrls = uploadRequests.length === 1 ? [await base.createStorageUploadUrl(uploadRequests[0].uploadRequest, options)] : (await base.createStorageUploadUrls({ files: uploadRequests.map((request2) => request2.uploadRequest) }, options)).files;
2703
2764
  const aggregateLoaded = new Array(uploadRequests.length).fill(0);
2704
2765
  const uploaded = [];
2705
2766
  for (let index = 0; index < uploadRequests.length; index += 1) {
2706
- const request = uploadRequests[index];
2767
+ const request2 = uploadRequests[index];
2707
2768
  const uploadUrl = uploadUrls[index];
2708
2769
  const response = await putUploadBody(
2709
2770
  uploadUrl.upload.url,
2710
2771
  uploadUrl.upload.headers ?? {},
2711
- request.source,
2772
+ request2.source,
2712
2773
  input,
2713
2774
  options,
2714
2775
  (progress) => {
@@ -2719,13 +2780,13 @@ function createStorageFileModule(base, config = {}) {
2719
2780
  uploaded.push({
2720
2781
  file: uploadUrl.file,
2721
2782
  upload: uploadUrl.upload,
2722
- source: request.source.source,
2723
- fileName: request.source.fileName,
2724
- storage_key: request.uploadRequest.storage_key,
2783
+ source: request2.source.source,
2784
+ fileName: request2.source.fileName,
2785
+ storage_key: request2.uploadRequest.storage_key,
2725
2786
  response
2726
2787
  });
2727
- aggregateLoaded[index] = request.source.sizeBytes;
2728
- input.onProgress?.(createProgressSnapshot("complete", sources, index, request.source.sizeBytes, sum(aggregateLoaded)));
2788
+ aggregateLoaded[index] = request2.source.sizeBytes;
2789
+ input.onProgress?.(createProgressSnapshot("complete", sources, index, request2.source.sizeBytes, sum(aggregateLoaded)));
2729
2790
  }
2730
2791
  return {
2731
2792
  files: uploaded,
@@ -4686,6 +4747,484 @@ function createStorageModule(gateway, runtimeOptions) {
4686
4747
  };
4687
4748
  }
4688
4749
 
4750
+ // src/chat/module.ts
4751
+ var SDK_NAME3 = "xylex-group/athena-chat";
4752
+ var SDK_HEADER_VALUE3 = buildSdkHeaderValue(SDK_NAME3);
4753
+ var NO_CACHE_HEADER_VALUE3 = "no-cache";
4754
+ var AthenaChatError = class extends Error {
4755
+ status;
4756
+ endpoint;
4757
+ method;
4758
+ requestId;
4759
+ body;
4760
+ constructor(input) {
4761
+ super(input.message);
4762
+ this.name = "AthenaChatError";
4763
+ this.status = input.status;
4764
+ this.endpoint = input.endpoint;
4765
+ this.method = input.method;
4766
+ this.requestId = input.requestId;
4767
+ this.body = input.body;
4768
+ }
4769
+ };
4770
+ function deriveRealtimeInfoUrl(wsUrl) {
4771
+ if (!wsUrl) {
4772
+ return void 0;
4773
+ }
4774
+ const parsed = new URL(normalizeWsUrl(wsUrl, "Athena chat WebSocket URL"));
4775
+ parsed.protocol = parsed.protocol === "wss:" ? "https:" : "http:";
4776
+ parsed.pathname = parsed.pathname.replace(/\/wss\/gateway$/, "/wss/info");
4777
+ return parsed.toString();
4778
+ }
4779
+ function normalizeWsUrl(value, label) {
4780
+ const normalized = value.trim();
4781
+ if (!normalized) {
4782
+ throw new Error(`${label} is required.`);
4783
+ }
4784
+ let parsed;
4785
+ try {
4786
+ parsed = new URL(normalized);
4787
+ } catch {
4788
+ throw new Error(`${label} must be a valid absolute ws(s) URL.`);
4789
+ }
4790
+ if (parsed.protocol !== "ws:" && parsed.protocol !== "wss:") {
4791
+ throw new Error(`${label} must use ws or wss.`);
4792
+ }
4793
+ parsed.pathname = parsed.pathname.replace(/\/+$/, "");
4794
+ return parsed.toString().replace(/\/$/, "");
4795
+ }
4796
+ function isRecord7(value) {
4797
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
4798
+ }
4799
+ function normalizeHeaderValue3(value) {
4800
+ return value ? value : void 0;
4801
+ }
4802
+ function parseResponseBody4(rawText, contentType) {
4803
+ if (!rawText) {
4804
+ return { parsed: null, parseFailed: false };
4805
+ }
4806
+ const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
4807
+ const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
4808
+ if (!looksJson) {
4809
+ return { parsed: rawText, parseFailed: false };
4810
+ }
4811
+ try {
4812
+ return { parsed: JSON.parse(rawText), parseFailed: false };
4813
+ } catch {
4814
+ return { parsed: rawText, parseFailed: true };
4815
+ }
4816
+ }
4817
+ function resolveRequestId3(headers) {
4818
+ return headers.get("x-request-id") ?? headers.get("x-correlation-id") ?? headers.get("x-athena-request-id") ?? void 0;
4819
+ }
4820
+ function resolveErrorMessage4(payload, fallback) {
4821
+ if (isRecord7(payload)) {
4822
+ for (const candidate of [payload.error, payload.message, payload.details]) {
4823
+ if (typeof candidate === "string" && candidate.trim().length > 0) {
4824
+ return candidate.trim();
4825
+ }
4826
+ }
4827
+ }
4828
+ if (typeof payload === "string" && payload.trim().length > 0) {
4829
+ return payload.trim();
4830
+ }
4831
+ return fallback;
4832
+ }
4833
+ function encodePathSegment(value, label) {
4834
+ const normalized = value.trim();
4835
+ if (!normalized) {
4836
+ throw new Error(`${label} is required.`);
4837
+ }
4838
+ return encodeURIComponent(normalized);
4839
+ }
4840
+ function encodeQuery(query) {
4841
+ if (!query) {
4842
+ return "";
4843
+ }
4844
+ const params = new URLSearchParams();
4845
+ for (const [key, value] of Object.entries(query)) {
4846
+ if (value === void 0 || value === null) {
4847
+ continue;
4848
+ }
4849
+ if (Array.isArray(value)) {
4850
+ for (const item of value) {
4851
+ if (item !== void 0 && item !== null) {
4852
+ params.append(key, String(item));
4853
+ }
4854
+ }
4855
+ continue;
4856
+ }
4857
+ params.set(key, String(value));
4858
+ }
4859
+ const encoded = params.toString();
4860
+ return encoded ? `?${encoded}` : "";
4861
+ }
4862
+ function createSocket(factory, url, protocols) {
4863
+ try {
4864
+ return new factory(url, protocols);
4865
+ } catch (error) {
4866
+ if (error instanceof TypeError) {
4867
+ return factory(url, protocols);
4868
+ }
4869
+ throw error;
4870
+ }
4871
+ }
4872
+ function buildHeaders3(config, options) {
4873
+ const headers = {
4874
+ Accept: "application/json",
4875
+ apikey: config.apiKey,
4876
+ "x-api-key": config.apiKey,
4877
+ "X-Athena-Sdk": SDK_HEADER_VALUE3
4878
+ };
4879
+ if (config.client || options?.client) {
4880
+ headers["X-Athena-Client"] = options?.client ?? config.client ?? "";
4881
+ }
4882
+ const bearerToken = options?.bearerToken ?? config.bearerToken;
4883
+ if (typeof bearerToken === "string" && bearerToken.trim()) {
4884
+ headers.Authorization = bearerToken.startsWith("Bearer ") ? bearerToken : `Bearer ${bearerToken}`;
4885
+ }
4886
+ const cookie = options?.cookie ?? config.cookie;
4887
+ if (typeof cookie === "string" && cookie.trim()) {
4888
+ headers.Cookie = cookie;
4889
+ }
4890
+ const sessionToken = options?.sessionToken ?? config.sessionToken;
4891
+ if (typeof sessionToken === "string" && sessionToken.trim()) {
4892
+ headers["X-Athena-Auth-Session-Token"] = sessionToken;
4893
+ }
4894
+ if (config.forceNoCache || options?.forceNoCache) {
4895
+ headers["Cache-Control"] = NO_CACHE_HEADER_VALUE3;
4896
+ }
4897
+ for (const source of [config.headers, options?.headers]) {
4898
+ for (const [key, value] of Object.entries(source ?? {})) {
4899
+ const normalized = normalizeHeaderValue3(value);
4900
+ if (normalized) {
4901
+ headers[key] = normalized;
4902
+ }
4903
+ }
4904
+ }
4905
+ return headers;
4906
+ }
4907
+ function withJsonBody(init, body) {
4908
+ return {
4909
+ ...init,
4910
+ body: body === void 0 ? void 0 : JSON.stringify(body),
4911
+ headers: {
4912
+ "Content-Type": "application/json",
4913
+ ...init.headers
4914
+ }
4915
+ };
4916
+ }
4917
+ async function request(config, method, endpoint, options, body) {
4918
+ if (!config.baseUrl) {
4919
+ throw new Error(
4920
+ "Athena chat base URL is not configured. Pass createClient({ url }) for unified routing or set chat.url / chatUrl explicitly."
4921
+ );
4922
+ }
4923
+ const url = `${config.baseUrl}${endpoint}`;
4924
+ const init = {
4925
+ method,
4926
+ headers: buildHeaders3(config, options),
4927
+ signal: options?.signal
4928
+ };
4929
+ const finalInit = body === void 0 || method === "GET" ? init : withJsonBody(init, body);
4930
+ const response = await fetch(url, finalInit);
4931
+ const rawText = await response.text();
4932
+ const { parsed } = parseResponseBody4(rawText, response.headers.get("content-type"));
4933
+ if (!response.ok) {
4934
+ throw new AthenaChatError({
4935
+ message: resolveErrorMessage4(parsed, `Athena chat ${method} ${endpoint} failed with ${response.status}`),
4936
+ status: response.status,
4937
+ endpoint,
4938
+ method,
4939
+ requestId: resolveRequestId3(response.headers),
4940
+ body: parsed
4941
+ });
4942
+ }
4943
+ return parsed;
4944
+ }
4945
+ function createRealtimeConnection(config, options) {
4946
+ if (!config.wsUrl) {
4947
+ throw new Error(
4948
+ "Athena chat WebSocket URL is not configured. Pass createClient({ url }) for unified routing or set chat.wsUrl / chatWsUrl explicitly."
4949
+ );
4950
+ }
4951
+ const wsFactory = config.webSocketFactory ?? globalThis.WebSocket;
4952
+ if (!wsFactory) {
4953
+ throw new Error(
4954
+ "No WebSocket implementation is available. Provide chat.webSocketFactory in createClient(...) or run in a runtime with global WebSocket support."
4955
+ );
4956
+ }
4957
+ const socket = createSocket(wsFactory, config.wsUrl, options?.protocols);
4958
+ const send = (command) => {
4959
+ socket.send(JSON.stringify(command));
4960
+ };
4961
+ if (options?.onMessage) {
4962
+ const listener = (event) => {
4963
+ const messageEvent = event;
4964
+ const raw = messageEvent?.data;
4965
+ if (typeof raw !== "string") {
4966
+ return;
4967
+ }
4968
+ try {
4969
+ options.onMessage?.(JSON.parse(raw));
4970
+ } catch {
4971
+ options.onMessage?.({ type: "error", error: "Invalid JSON message from Athena chat realtime gateway." });
4972
+ }
4973
+ };
4974
+ if (typeof socket.addEventListener === "function") {
4975
+ socket.addEventListener("message", listener);
4976
+ } else {
4977
+ socket.onmessage = listener;
4978
+ }
4979
+ }
4980
+ const hello = (command) => {
4981
+ send({
4982
+ type: "auth.hello",
4983
+ token: command?.token,
4984
+ room_subscriptions: command?.room_subscriptions
4985
+ });
4986
+ };
4987
+ if (options?.hello) {
4988
+ const onOpen = () => hello({
4989
+ token: options.hello?.token ?? void 0,
4990
+ room_subscriptions: options.hello?.room_subscriptions ?? void 0
4991
+ });
4992
+ if (typeof socket.addEventListener === "function") {
4993
+ socket.addEventListener("open", onOpen);
4994
+ } else {
4995
+ socket.onopen = onOpen;
4996
+ }
4997
+ }
4998
+ return {
4999
+ socket,
5000
+ send,
5001
+ hello,
5002
+ subscribe(roomId, fromSeq) {
5003
+ send({
5004
+ type: "chat.subscribe",
5005
+ room_id: roomId,
5006
+ from_seq: fromSeq ?? void 0
5007
+ });
5008
+ },
5009
+ unsubscribe(roomId) {
5010
+ send({
5011
+ type: "chat.unsubscribe",
5012
+ room_id: roomId
5013
+ });
5014
+ },
5015
+ resume(rooms) {
5016
+ send({
5017
+ type: "chat.resume",
5018
+ rooms
5019
+ });
5020
+ },
5021
+ typingStart(roomId) {
5022
+ send({
5023
+ type: "chat.typing.start",
5024
+ room_id: roomId
5025
+ });
5026
+ },
5027
+ typingStop(roomId) {
5028
+ send({
5029
+ type: "chat.typing.stop",
5030
+ room_id: roomId
5031
+ });
5032
+ },
5033
+ presenceHeartbeat(activeRoomId) {
5034
+ send({
5035
+ type: "chat.presence.heartbeat",
5036
+ active_room_id: activeRoomId ?? void 0
5037
+ });
5038
+ },
5039
+ readUpTo(roomId, input) {
5040
+ send({
5041
+ type: "chat.read.up_to",
5042
+ room_id: roomId,
5043
+ message_id: input?.message_id ?? void 0,
5044
+ seq: input?.seq ?? void 0
5045
+ });
5046
+ },
5047
+ ping(at = (/* @__PURE__ */ new Date()).toISOString()) {
5048
+ send({
5049
+ type: "ping",
5050
+ at
5051
+ });
5052
+ },
5053
+ close(code, reason) {
5054
+ socket.close(code, reason);
5055
+ }
5056
+ };
5057
+ }
5058
+ function createChatModule(config) {
5059
+ const realtime = {
5060
+ info(options) {
5061
+ const realtimeInfoUrl = config.realtimeInfoUrl ?? deriveRealtimeInfoUrl(config.wsUrl);
5062
+ if (!realtimeInfoUrl) {
5063
+ throw new Error(
5064
+ "Athena chat realtime info URL is not configured. Pass createClient({ url }) for unified routing or set chat.wsUrl / chatWsUrl explicitly."
5065
+ );
5066
+ }
5067
+ return request(
5068
+ {
5069
+ ...config,
5070
+ baseUrl: realtimeInfoUrl
5071
+ },
5072
+ "GET",
5073
+ "",
5074
+ options
5075
+ );
5076
+ },
5077
+ connect(options) {
5078
+ return createRealtimeConnection(config, options);
5079
+ }
5080
+ };
5081
+ return {
5082
+ room: {
5083
+ list(query, options) {
5084
+ return request(
5085
+ config,
5086
+ "GET",
5087
+ `/rooms${encodeQuery(query)}`,
5088
+ options
5089
+ );
5090
+ },
5091
+ create(input, options) {
5092
+ return request(config, "POST", "/rooms", options, input);
5093
+ },
5094
+ get(roomId, options) {
5095
+ return request(
5096
+ config,
5097
+ "GET",
5098
+ `/rooms/${encodePathSegment(roomId, "chat room ID")}`,
5099
+ options
5100
+ );
5101
+ },
5102
+ update(roomId, input, options) {
5103
+ return request(
5104
+ config,
5105
+ "PATCH",
5106
+ `/rooms/${encodePathSegment(roomId, "chat room ID")}`,
5107
+ options,
5108
+ input
5109
+ );
5110
+ },
5111
+ archive(roomId, options) {
5112
+ return request(
5113
+ config,
5114
+ "POST",
5115
+ `/rooms/${encodePathSegment(roomId, "chat room ID")}/archive`,
5116
+ options
5117
+ );
5118
+ },
5119
+ readCursor: {
5120
+ upTo(roomId, input, options) {
5121
+ return request(
5122
+ config,
5123
+ "POST",
5124
+ `/rooms/${encodePathSegment(roomId, "chat room ID")}/read-cursor`,
5125
+ options,
5126
+ input ?? {}
5127
+ );
5128
+ }
5129
+ },
5130
+ member: {
5131
+ list(roomId, options) {
5132
+ return request(
5133
+ config,
5134
+ "GET",
5135
+ `/rooms/${encodePathSegment(roomId, "chat room ID")}/members`,
5136
+ options
5137
+ );
5138
+ },
5139
+ add(roomId, input, options) {
5140
+ return request(
5141
+ config,
5142
+ "POST",
5143
+ `/rooms/${encodePathSegment(roomId, "chat room ID")}/members`,
5144
+ options,
5145
+ input
5146
+ );
5147
+ },
5148
+ remove(roomId, userId, options) {
5149
+ return request(
5150
+ config,
5151
+ "DELETE",
5152
+ `/rooms/${encodePathSegment(roomId, "chat room ID")}/members/${encodePathSegment(userId, "chat user ID")}`,
5153
+ options
5154
+ );
5155
+ }
5156
+ },
5157
+ message: {
5158
+ list(roomId, query, options) {
5159
+ return request(
5160
+ config,
5161
+ "GET",
5162
+ `/rooms/${encodePathSegment(roomId, "chat room ID")}/messages${encodeQuery(query)}`,
5163
+ options
5164
+ );
5165
+ },
5166
+ send(roomId, input, options) {
5167
+ return request(
5168
+ config,
5169
+ "POST",
5170
+ `/rooms/${encodePathSegment(roomId, "chat room ID")}/messages`,
5171
+ options,
5172
+ input
5173
+ );
5174
+ },
5175
+ update(roomId, messageId, input, options) {
5176
+ return request(
5177
+ config,
5178
+ "PATCH",
5179
+ `/rooms/${encodePathSegment(roomId, "chat room ID")}/messages/${encodePathSegment(messageId, "chat message ID")}`,
5180
+ options,
5181
+ input
5182
+ );
5183
+ },
5184
+ delete(roomId, messageId, options) {
5185
+ return request(
5186
+ config,
5187
+ "DELETE",
5188
+ `/rooms/${encodePathSegment(roomId, "chat room ID")}/messages/${encodePathSegment(messageId, "chat message ID")}`,
5189
+ options
5190
+ );
5191
+ }
5192
+ }
5193
+ },
5194
+ message: {
5195
+ reaction: {
5196
+ add(messageId, input, options) {
5197
+ return request(
5198
+ config,
5199
+ "POST",
5200
+ `/messages/${encodePathSegment(messageId, "chat message ID")}/reactions`,
5201
+ options,
5202
+ input
5203
+ );
5204
+ },
5205
+ remove(messageId, emoji, options) {
5206
+ return request(
5207
+ config,
5208
+ "DELETE",
5209
+ `/messages/${encodePathSegment(messageId, "chat message ID")}/reactions/${encodePathSegment(emoji, "reaction emoji")}`,
5210
+ options
5211
+ );
5212
+ }
5213
+ },
5214
+ search(input, options) {
5215
+ return request(
5216
+ config,
5217
+ "POST",
5218
+ "/messages/search",
5219
+ options,
5220
+ input
5221
+ );
5222
+ }
5223
+ },
5224
+ realtime
5225
+ };
5226
+ }
5227
+
4689
5228
  // src/client-builder.ts
4690
5229
  var DEFAULT_BACKEND = { type: "athena" };
4691
5230
  function toBackendConfig(value) {
@@ -4898,7 +5437,7 @@ var BOOLEAN_SAFE_OPERATORS = /* @__PURE__ */ new Set([
4898
5437
  "ilike",
4899
5438
  "is"
4900
5439
  ]);
4901
- function isRecord7(value) {
5440
+ function isRecord8(value) {
4902
5441
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
4903
5442
  }
4904
5443
  function isUuidString(value) {
@@ -4911,7 +5450,7 @@ function shouldUseUuidTextComparison(column, value) {
4911
5450
  return typeof value === "string" && isUuidString(value) && isUuidIdentifierColumn(column);
4912
5451
  }
4913
5452
  function isRelationSelectNode(value) {
4914
- return isRecord7(value) && isRecord7(value.select);
5453
+ return isRecord8(value) && isRecord8(value.select);
4915
5454
  }
4916
5455
  function normalizeIdentifier(value, label) {
4917
5456
  const normalized = value.trim();
@@ -4967,7 +5506,7 @@ function compileRelationToken(key, node) {
4967
5506
  return `${prefix}${relationToken}(${nested})`;
4968
5507
  }
4969
5508
  function compileSelectShape(select) {
4970
- if (!isRecord7(select)) {
5509
+ if (!isRecord8(select)) {
4971
5510
  throw new Error("findMany select must be an object");
4972
5511
  }
4973
5512
  const tokens = [];
@@ -4991,7 +5530,7 @@ function compileSelectShape(select) {
4991
5530
  return tokens.join(",");
4992
5531
  }
4993
5532
  function selectShapeUsesRelationSchema(select) {
4994
- if (!isRecord7(select)) {
5533
+ if (!isRecord8(select)) {
4995
5534
  return false;
4996
5535
  }
4997
5536
  for (const rawValue of Object.values(select)) {
@@ -5009,7 +5548,7 @@ function selectShapeUsesRelationSchema(select) {
5009
5548
  }
5010
5549
  function compileColumnWhere(column, input) {
5011
5550
  const normalizedColumn = normalizeIdentifier(column, "where column");
5012
- if (!isRecord7(input)) {
5551
+ if (!isRecord8(input)) {
5013
5552
  return [buildGatewayCondition("eq", normalizedColumn, input)];
5014
5553
  }
5015
5554
  const conditions = [];
@@ -5037,7 +5576,7 @@ function compileColumnWhere(column, input) {
5037
5576
  return conditions;
5038
5577
  }
5039
5578
  function compileBooleanExpressionTerms(clause, label) {
5040
- if (!isRecord7(clause)) {
5579
+ if (!isRecord8(clause)) {
5041
5580
  throw new Error(`findMany where.${label} clauses must be objects`);
5042
5581
  }
5043
5582
  const entries = Object.entries(clause).filter(([, value]) => value !== void 0);
@@ -5046,7 +5585,7 @@ function compileBooleanExpressionTerms(clause, label) {
5046
5585
  }
5047
5586
  const [rawColumn, rawValue] = entries[0];
5048
5587
  const column = normalizeIdentifier(rawColumn, `where.${label} column`);
5049
- if (!isRecord7(rawValue)) {
5588
+ if (!isRecord8(rawValue)) {
5050
5589
  return [`${column}.eq.${stringifyFilterValue(rawValue)}`];
5051
5590
  }
5052
5591
  const operatorEntries = Object.entries(rawValue).filter(([, value]) => value !== void 0);
@@ -5070,7 +5609,7 @@ function compileWhere(where) {
5070
5609
  if (where === void 0) {
5071
5610
  return void 0;
5072
5611
  }
5073
- if (!isRecord7(where)) {
5612
+ if (!isRecord8(where)) {
5074
5613
  throw new Error("findMany where must be an object");
5075
5614
  }
5076
5615
  const conditions = [];
@@ -5120,7 +5659,7 @@ function compileOrderBy(orderBy) {
5120
5659
  if (orderBy === void 0) {
5121
5660
  return void 0;
5122
5661
  }
5123
- if (!isRecord7(orderBy)) {
5662
+ if (!isRecord8(orderBy)) {
5124
5663
  throw new Error("findMany orderBy must be an object");
5125
5664
  }
5126
5665
  if ("column" in orderBy) {
@@ -5295,11 +5834,11 @@ function toFindManyAstOrder(order) {
5295
5834
  ascending: order.direction !== "descending"
5296
5835
  };
5297
5836
  }
5298
- function isRecord8(value) {
5837
+ function isRecord9(value) {
5299
5838
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
5300
5839
  }
5301
5840
  function normalizeFindManyAstColumnPredicate(value) {
5302
- if (!isRecord8(value)) {
5841
+ if (!isRecord9(value)) {
5303
5842
  return {
5304
5843
  eq: value
5305
5844
  };
@@ -5323,7 +5862,7 @@ function normalizeFindManyAstBooleanOperand(clause) {
5323
5862
  return normalized;
5324
5863
  }
5325
5864
  function normalizeFindManyAstWhere(where) {
5326
- if (!where || !isRecord8(where)) {
5865
+ if (!where || !isRecord9(where)) {
5327
5866
  return where;
5328
5867
  }
5329
5868
  const normalized = {};
@@ -5337,7 +5876,7 @@ function normalizeFindManyAstWhere(where) {
5337
5876
  );
5338
5877
  continue;
5339
5878
  }
5340
- if (key === "not" && isRecord8(value)) {
5879
+ if (key === "not" && isRecord9(value)) {
5341
5880
  normalized.not = normalizeFindManyAstBooleanOperand(
5342
5881
  value
5343
5882
  );
@@ -5348,7 +5887,7 @@ function normalizeFindManyAstWhere(where) {
5348
5887
  return normalized;
5349
5888
  }
5350
5889
  function predicateRequiresUuidQueryFallback(column, value) {
5351
- if (!isRecord8(value)) {
5890
+ if (!isRecord9(value)) {
5352
5891
  return shouldUseUuidTextComparison(column, value);
5353
5892
  }
5354
5893
  const eqValue = value.eq;
@@ -5366,7 +5905,7 @@ function booleanOperandRequiresUuidQueryFallback(clause) {
5366
5905
  return false;
5367
5906
  }
5368
5907
  function findManyAstWhereRequiresLegacyTransport(where) {
5369
- if (!where || !isRecord8(where)) {
5908
+ if (!where || !isRecord9(where)) {
5370
5909
  return false;
5371
5910
  }
5372
5911
  for (const [key, value] of Object.entries(where)) {
@@ -5381,7 +5920,7 @@ function findManyAstWhereRequiresLegacyTransport(where) {
5381
5920
  }
5382
5921
  continue;
5383
5922
  }
5384
- if (key === "not" && isRecord8(value)) {
5923
+ if (key === "not" && isRecord9(value)) {
5385
5924
  if (booleanOperandRequiresUuidQueryFallback(value)) {
5386
5925
  return true;
5387
5926
  }
@@ -5924,6 +6463,7 @@ function resolveAthenaModelTargetTableName(target, options = {}) {
5924
6463
  var DEFAULT_COLUMNS = "*";
5925
6464
  var SAFE_CAST_PATTERN = /^[a-z_][a-z0-9_]*(?:\[\])?$/i;
5926
6465
  var ATHENA_NORMALIZED_ERROR_KEY = "__athenaNormalizedError";
6466
+ var SDK_NAME4 = "xylex-group/athena";
5927
6467
  function formatResult(response) {
5928
6468
  const result = {
5929
6469
  data: response.data ?? null,
@@ -6000,7 +6540,7 @@ async function executeExperimentalRead(experimental, runner) {
6000
6540
  throw error;
6001
6541
  }
6002
6542
  }
6003
- function isRecord9(value) {
6543
+ function isRecord10(value) {
6004
6544
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
6005
6545
  }
6006
6546
  function firstNonEmptyString2(...values) {
@@ -6012,8 +6552,8 @@ function firstNonEmptyString2(...values) {
6012
6552
  return void 0;
6013
6553
  }
6014
6554
  function resolveStructuredErrorPayload2(raw) {
6015
- if (!isRecord9(raw)) return null;
6016
- return isRecord9(raw.error) ? raw.error : raw;
6555
+ if (!isRecord10(raw)) return null;
6556
+ return isRecord10(raw.error) ? raw.error : raw;
6017
6557
  }
6018
6558
  function resolveStructuredErrorDetails(payload, message) {
6019
6559
  if (!payload || !("details" in payload)) {
@@ -6029,7 +6569,7 @@ function resolveStructuredErrorDetails(payload, message) {
6029
6569
  return details;
6030
6570
  }
6031
6571
  function createResultError(response, result, normalized) {
6032
- const rawRecord = isRecord9(response.raw) ? response.raw : null;
6572
+ const rawRecord = isRecord10(response.raw) ? response.raw : null;
6033
6573
  const payload = resolveStructuredErrorPayload2(response.raw);
6034
6574
  const message = firstNonEmptyString2(
6035
6575
  response.error,
@@ -6092,6 +6632,43 @@ function asAthenaJsonObject(value) {
6092
6632
  function asAthenaJsonObjectArray(values) {
6093
6633
  return values;
6094
6634
  }
6635
+ function parseArbitraryResponseBody(rawText, contentType) {
6636
+ if (!rawText) {
6637
+ return null;
6638
+ }
6639
+ const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
6640
+ const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
6641
+ if (!looksJson) {
6642
+ return rawText;
6643
+ }
6644
+ try {
6645
+ return JSON.parse(rawText);
6646
+ } catch {
6647
+ return rawText;
6648
+ }
6649
+ }
6650
+ function toRequestQueryString(query) {
6651
+ if (!query) {
6652
+ return "";
6653
+ }
6654
+ const params = new URLSearchParams();
6655
+ for (const [key, value] of Object.entries(query)) {
6656
+ if (value === void 0 || value === null) {
6657
+ continue;
6658
+ }
6659
+ if (Array.isArray(value)) {
6660
+ for (const item of value) {
6661
+ if (item !== void 0 && item !== null) {
6662
+ params.append(key, String(item));
6663
+ }
6664
+ }
6665
+ continue;
6666
+ }
6667
+ params.set(key, String(value));
6668
+ }
6669
+ const encoded = params.toString();
6670
+ return encoded ? `?${encoded}` : "";
6671
+ }
6095
6672
  function normalizeSelectColumnsInput(columns) {
6096
6673
  if (columns === void 0) {
6097
6674
  return void 0;
@@ -7398,6 +7975,8 @@ var ATHENA_ENV_GATEWAY_URL_KEYS = [
7398
7975
  "NEXT_PUBLIC_ATHENA_DB_API_URL"
7399
7976
  ];
7400
7977
  var ATHENA_ENV_AUTH_URL_KEYS = ["ATHENA_AUTH_URL", "NEXT_PUBLIC_ATHENA_AUTH_URL"];
7978
+ var ATHENA_ENV_CHAT_URL_KEYS = ["ATHENA_CHAT_URL", "NEXT_PUBLIC_ATHENA_CHAT_URL"];
7979
+ var ATHENA_ENV_CHAT_WS_URL_KEYS = ["ATHENA_CHAT_WS_URL", "NEXT_PUBLIC_ATHENA_CHAT_WS_URL"];
7401
7980
  var ATHENA_ENV_STORAGE_URL_KEYS = ["ATHENA_STORAGE_URL", "NEXT_PUBLIC_ATHENA_STORAGE_URL"];
7402
7981
  var ATHENA_ENV_KEY_KEYS = [
7403
7982
  "ATHENA_API_KEY",
@@ -7478,6 +8057,15 @@ function appendServicePath(baseUrl, segment) {
7478
8057
  const normalizedBaseUrl = normalizeAthenaGatewayBaseUrl(baseUrl, { label: "Athena public base URL" });
7479
8058
  return `${normalizedBaseUrl}/${segment.replace(/^\/+/, "")}`;
7480
8059
  }
8060
+ function appendRealtimeGatewayPath(baseUrl) {
8061
+ const normalizedBaseUrl = normalizeAthenaGatewayBaseUrl(baseUrl, { label: "Athena public base URL" });
8062
+ const wsUrl = new URL(normalizedBaseUrl);
8063
+ wsUrl.protocol = wsUrl.protocol === "https:" ? "wss:" : "ws:";
8064
+ wsUrl.pathname = `${wsUrl.pathname.replace(/\/+$/, "")}/wss/gateway`;
8065
+ wsUrl.search = "";
8066
+ wsUrl.hash = "";
8067
+ return wsUrl.toString();
8068
+ }
7481
8069
  function resolveServiceUrlOverride(value, label) {
7482
8070
  return resolveClientServiceBaseUrl(value, label);
7483
8071
  }
@@ -7486,6 +8074,8 @@ function resolveServiceUrls(config) {
7486
8074
  return {
7487
8075
  dbUrl: resolveServiceUrlOverride(config.db?.url, "Athena DB base URL") ?? resolveServiceUrlOverride(config.gateway?.url, "Athena gateway base URL") ?? resolveServiceUrlOverride(config.dbUrl, "Athena DB base URL") ?? resolveServiceUrlOverride(config.gatewayUrl, "Athena gateway base URL") ?? (baseUrl ? appendServicePath(baseUrl, "db") : void 0),
7488
8076
  authUrl: resolveServiceUrlOverride(config.auth?.url, "Athena auth base URL") ?? resolveServiceUrlOverride(config.auth?.baseUrl, "Athena auth base URL") ?? resolveServiceUrlOverride(config.authUrl, "Athena auth base URL") ?? (baseUrl ? appendServicePath(baseUrl, "auth") : void 0),
8077
+ chatUrl: resolveServiceUrlOverride(config.chat?.url, "Athena chat base URL") ?? resolveServiceUrlOverride(config.chatUrl, "Athena chat base URL") ?? (baseUrl ? appendServicePath(baseUrl, "chat") : void 0),
8078
+ chatWsUrl: normalizeOptionalString(config.chat?.wsUrl) ?? normalizeOptionalString(config.chatWsUrl) ?? (baseUrl ? appendRealtimeGatewayPath(baseUrl) : void 0),
7489
8079
  storageUrl: resolveServiceUrlOverride(config.storage?.url, "Athena storage base URL") ?? resolveServiceUrlOverride(config.storageUrl, "Athena storage base URL") ?? (baseUrl ? appendServicePath(baseUrl, "storage") : void 0)
7490
8080
  };
7491
8081
  }
@@ -7578,6 +8168,7 @@ function mergeClientOverrideOptions(base, overrides) {
7578
8168
  } : void 0,
7579
8169
  db: base.db ? { ...base.db } : void 0,
7580
8170
  gateway: base.gateway ? { ...base.gateway } : void 0,
8171
+ chat: base.chat ? { ...base.chat } : void 0,
7581
8172
  storage: base.storage ? { ...base.storage } : void 0
7582
8173
  };
7583
8174
  }
@@ -7588,6 +8179,7 @@ function mergeClientOverrideOptions(base, overrides) {
7588
8179
  auth: mergeAuthClientOptions(base.auth, overrides.auth),
7589
8180
  db: mergeServiceUrlOverrides(base.db, overrides.db),
7590
8181
  gateway: mergeServiceUrlOverrides(base.gateway, overrides.gateway),
8182
+ chat: mergeServiceUrlOverrides(base.chat, overrides.chat),
7591
8183
  storage: mergeServiceUrlOverrides(base.storage, overrides.storage)
7592
8184
  };
7593
8185
  }
@@ -7646,6 +8238,9 @@ function resolveCreateClientConfig(config) {
7646
8238
  headers: config.headers,
7647
8239
  auth: config.auth,
7648
8240
  authUrl: resolvedUrls.authUrl,
8241
+ chat: config.chat,
8242
+ chatUrl: resolvedUrls.chatUrl,
8243
+ chatWsUrl: resolvedUrls.chatWsUrl,
7649
8244
  storageUrl: resolvedUrls.storageUrl,
7650
8245
  experimental: config.experimental
7651
8246
  };
@@ -7730,6 +8325,119 @@ function createClientFromConfig(config, sourceConfig) {
7730
8325
  queryTracer
7731
8326
  );
7732
8327
  const db = createDbModule({ from, rpc, query });
8328
+ const chat = createChatModule({
8329
+ baseUrl: config.chatUrl,
8330
+ apiKey: config.apiKey,
8331
+ client: config.client,
8332
+ headers: config.headers,
8333
+ bearerToken: normalizedAuthConfig?.bearerToken,
8334
+ cookie: normalizedAuthConfig?.cookie,
8335
+ sessionToken: normalizedAuthConfig?.sessionToken,
8336
+ forceNoCache: config.forceNoCache,
8337
+ wsUrl: config.chatWsUrl,
8338
+ webSocketFactory: config.chat?.webSocketFactory ?? void 0
8339
+ });
8340
+ const request2 = async (options) => {
8341
+ const method = options.method ?? "GET";
8342
+ const responseType = options.responseType ?? "json";
8343
+ const service = options.service ?? "db";
8344
+ const baseUrlByService = {
8345
+ db: config.baseUrl,
8346
+ auth: config.authUrl,
8347
+ chat: config.chatUrl,
8348
+ storage: config.storageUrl
8349
+ };
8350
+ const resolvedBaseUrl = options.url ?? baseUrlByService[service];
8351
+ if (!resolvedBaseUrl) {
8352
+ throw new Error(
8353
+ `Athena ${service} base URL is not configured. Pass createClient({ url }) for unified routing or set the service-specific URL first.`
8354
+ );
8355
+ }
8356
+ const normalizedBaseUrl = normalizeAthenaGatewayBaseUrl(resolvedBaseUrl, {
8357
+ label: `Athena ${service} base URL`
8358
+ });
8359
+ const normalizedPath = options.url ? "" : (() => {
8360
+ const path = options.path?.trim();
8361
+ if (!path) {
8362
+ throw new Error("client.request(...) requires either an absolute url or a non-empty path.");
8363
+ }
8364
+ return path.startsWith("/") ? path : `/${path}`;
8365
+ })();
8366
+ const targetUrl = options.url ? `${normalizedBaseUrl}${toRequestQueryString(options.query)}` : `${normalizedBaseUrl}${normalizedPath}${toRequestQueryString(options.query)}`;
8367
+ const headers = {
8368
+ "X-Athena-Sdk": buildSdkHeaderValue(SDK_NAME4),
8369
+ ...config.headers ?? {},
8370
+ ...options.headers ?? {}
8371
+ };
8372
+ if (service !== "auth") {
8373
+ headers.apikey = headers.apikey ?? config.apiKey;
8374
+ headers["x-api-key"] = headers["x-api-key"] ?? config.apiKey;
8375
+ if (config.client && !hasHeaderIgnoreCase(headers, "X-Athena-Client")) {
8376
+ headers["X-Athena-Client"] = config.client;
8377
+ }
8378
+ if (config.userId && !hasHeaderIgnoreCase(headers, "X-User-Id")) {
8379
+ headers["X-User-Id"] = config.userId;
8380
+ }
8381
+ if (config.organizationId && !hasHeaderIgnoreCase(headers, "X-Organization-Id")) {
8382
+ headers["X-Organization-Id"] = config.organizationId;
8383
+ }
8384
+ if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
8385
+ headers["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
8386
+ }
8387
+ if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Bearer-Token")) {
8388
+ headers["X-Athena-Auth-Bearer-Token"] = normalizedAuthConfig.bearerToken;
8389
+ }
8390
+ if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
8391
+ headers.Cookie = normalizedAuthConfig.cookie;
8392
+ }
8393
+ } else {
8394
+ const authApiKey = normalizedAuthConfig?.apiKey ?? config.apiKey;
8395
+ if (authApiKey && !hasHeaderIgnoreCase(headers, "x-api-key")) {
8396
+ headers.apikey = headers.apikey ?? authApiKey;
8397
+ headers["x-api-key"] = headers["x-api-key"] ?? authApiKey;
8398
+ }
8399
+ if (normalizedAuthConfig?.bearerToken && !hasHeaderIgnoreCase(headers, "Authorization")) {
8400
+ headers.Authorization = `Bearer ${normalizedAuthConfig.bearerToken}`;
8401
+ }
8402
+ if (normalizedAuthConfig?.cookie && !hasHeaderIgnoreCase(headers, "Cookie")) {
8403
+ headers.Cookie = normalizedAuthConfig.cookie;
8404
+ }
8405
+ if (normalizedAuthConfig?.sessionToken && !hasHeaderIgnoreCase(headers, "X-Athena-Auth-Session-Token")) {
8406
+ headers["X-Athena-Auth-Session-Token"] = normalizedAuthConfig.sessionToken;
8407
+ }
8408
+ }
8409
+ const shouldSendJsonBody = options.body !== void 0 && options.body !== null && !(options.body instanceof FormData) && !(options.body instanceof Blob) && !(options.body instanceof URLSearchParams) && !(options.body instanceof ArrayBuffer) && !ArrayBuffer.isView(options.body) && typeof options.body !== "string";
8410
+ if (shouldSendJsonBody && !hasHeaderIgnoreCase(headers, "Content-Type")) {
8411
+ headers["Content-Type"] = "application/json";
8412
+ }
8413
+ const response = await fetch(targetUrl, {
8414
+ method,
8415
+ headers,
8416
+ body: options.body === void 0 || options.body === null ? void 0 : shouldSendJsonBody ? JSON.stringify(options.body) : options.body,
8417
+ signal: options.signal,
8418
+ credentials: options.credentials
8419
+ });
8420
+ if (responseType === "response") {
8421
+ return {
8422
+ ok: response.ok,
8423
+ status: response.status,
8424
+ statusText: response.statusText,
8425
+ headers: response.headers,
8426
+ data: null,
8427
+ raw: response
8428
+ };
8429
+ }
8430
+ const rawText = await response.text();
8431
+ const parsed = responseType === "text" ? rawText : parseArbitraryResponseBody(rawText, response.headers.get("content-type"));
8432
+ return {
8433
+ ok: response.ok,
8434
+ status: response.status,
8435
+ statusText: response.statusText,
8436
+ headers: response.headers,
8437
+ data: parsed,
8438
+ raw: response
8439
+ };
8440
+ };
7733
8441
  const withContext = (context) => createClientFromInput(
7734
8442
  mergeClientOverrideOptions(sourceConfig, toClientContextOverrides(context))
7735
8443
  );
@@ -7745,8 +8453,10 @@ function createClientFromConfig(config, sourceConfig) {
7745
8453
  db,
7746
8454
  rpc,
7747
8455
  query,
8456
+ request: request2,
7748
8457
  verifyConnection: gateway.verifyConnection,
7749
8458
  auth: auth.auth,
8459
+ chat,
7750
8460
  withContext,
7751
8461
  withSession,
7752
8462
  withOptions: authWithOptions
@@ -7791,6 +8501,8 @@ var AthenaClient = class {
7791
8501
  const url = options.url ?? readFirstEnvValue(env, ATHENA_ENV_URL_KEYS);
7792
8502
  const gatewayUrl = options.gatewayUrl ?? readFirstEnvValue(env, ATHENA_ENV_GATEWAY_URL_KEYS);
7793
8503
  const authUrl = options.authUrl ?? readFirstEnvValue(env, ATHENA_ENV_AUTH_URL_KEYS);
8504
+ const chatUrl = options.chatUrl ?? readFirstEnvValue(env, ATHENA_ENV_CHAT_URL_KEYS);
8505
+ const chatWsUrl = options.chatWsUrl ?? readFirstEnvValue(env, ATHENA_ENV_CHAT_WS_URL_KEYS);
7794
8506
  const storageUrl = options.storageUrl ?? readFirstEnvValue(env, ATHENA_ENV_STORAGE_URL_KEYS);
7795
8507
  const key = options.key ?? readFirstEnvValue(env, ATHENA_ENV_KEY_KEYS);
7796
8508
  const client = options.client ?? readFirstEnvValue(env, ATHENA_ENV_CLIENT_KEYS);
@@ -7805,6 +8517,8 @@ var AthenaClient = class {
7805
8517
  url,
7806
8518
  gatewayUrl,
7807
8519
  authUrl,
8520
+ chatUrl,
8521
+ chatWsUrl,
7808
8522
  storageUrl,
7809
8523
  key,
7810
8524
  client
@@ -7845,6 +8559,8 @@ function createAdapterClient(options, context) {
7845
8559
  url: options?.url,
7846
8560
  gatewayUrl: options?.gatewayUrl,
7847
8561
  authUrl: options?.authUrl,
8562
+ chatUrl: options?.chatUrl,
8563
+ chatWsUrl: options?.chatWsUrl,
7848
8564
  storageUrl: options?.storageUrl,
7849
8565
  key: options?.key,
7850
8566
  client: options?.client,