@ateam-ai-mobile/core 0.1.26 → 0.1.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ateam-ai-mobile/core",
3
- "version": "0.1.26",
3
+ "version": "0.1.27",
4
4
  "description": "Headless ADAS SDK core — auth bridge, API client, chat/job streaming, MCP calls, theme tokens. No UI, no Expo dependencies.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/acs/ws.ts CHANGED
@@ -24,7 +24,7 @@
24
24
  * the WS is healthy. This file is the realtime cherry on top.
25
25
  */
26
26
 
27
- import { getCoreWsUrl } from '../config';
27
+ import { openCoreWs } from '../config';
28
28
  import { useWidgetsStore } from './widgetsStore';
29
29
  import { useHomeActionsStore } from './homeActionsStore';
30
30
 
@@ -133,9 +133,8 @@ function openSocket() {
133
133
  if (_ws) return;
134
134
  if (!_token || !_tenant) return;
135
135
 
136
- const url = `${getCoreWsUrl()}/ws?token=${encodeURIComponent(_token)}&tenant=${encodeURIComponent(_tenant)}`;
137
136
  console.log(`[acsWs] opening`);
138
- const ws = new WebSocket(url);
137
+ const ws = openCoreWs(_tenant, _token);
139
138
  _ws = ws;
140
139
 
141
140
  // IDENTITY GUARD. `connectAcsWs()` (tenant switch / re-auth) and reconnects
package/src/chat/store.ts CHANGED
@@ -12,7 +12,7 @@
12
12
  * from the host via initAdas().
13
13
  */
14
14
  import { create } from 'zustand';
15
- import { getCoreApiUrl, getCoreWsUrl, getToken, getTenant, getUser, getConfig } from '../config';
15
+ import { getCoreApiUrl, openCoreWs, getToken, getTenant, getUser, getConfig } from '../config';
16
16
  import { pluginCommandEmitter } from '../utils/emitter';
17
17
  import type { OutgoingAttachment } from '../storage/types';
18
18
  import type { Message, MessageAttachment, JobProgress, UIAction } from './types';
@@ -744,8 +744,7 @@ let _currentJobId: string | null = null;
744
744
  function ensureWs(tenant: string, token: string | null): WebSocket {
745
745
  if (_ws && _wsReady) return _ws;
746
746
 
747
- const wsUrl = `${getCoreWsUrl()}/ws?token=${encodeURIComponent(token || '')}&tenant=${encodeURIComponent(tenant)}`;
748
- const ws = new WebSocket(wsUrl);
747
+ const ws = openCoreWs(tenant, token);
749
748
  _ws = ws;
750
749
  _wsReady = false;
751
750
 
package/src/config.ts CHANGED
@@ -120,6 +120,21 @@ export function getCoreWsUrl(): string {
120
120
  return getCoreApiUrl().replace(/^http/, 'ws');
121
121
  }
122
122
 
123
+ // Core's /ws protocol. The sign-in token travels as the "adas.bearer.<token>"
124
+ // subprotocol next to "adas.v1" (the one the server selects, so the token is
125
+ // never echoed), not in the URL: a URL is written to every access log it passes
126
+ // (nginx, Core's request log, Cloudflare). Core: apps/backend/utils/urlToken.js.
127
+ export const CORE_WS_PROTOCOL = 'adas.v1';
128
+ const CORE_WS_BEARER_PREFIX = 'adas.bearer.';
129
+
130
+ /** Open Core's /ws for a tenant, with the token in the subprotocol, never the URL. */
131
+ export function openCoreWs(tenant: string, token: string | null): WebSocket {
132
+ const url = `${getCoreWsUrl()}/ws?tenant=${encodeURIComponent(tenant)}`;
133
+ const protocols = [CORE_WS_PROTOCOL];
134
+ if (token) protocols.push(CORE_WS_BEARER_PREFIX + token);
135
+ return new WebSocket(url, protocols);
136
+ }
137
+
123
138
  export function getVoiceApiUrl(): string {
124
139
  const url = getConfig().voiceUrl;
125
140
  if (!url) throw new Error('[adas] voiceUrl not configured');