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