@aui.io/aui-client 3.1.0 → 3.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -80,7 +80,6 @@ import { ApolloEnvironment } from '@aui.io/aui-client';
80
80
  ApolloEnvironment.Gcp = {
81
81
  base: 'https://api-v3.aui.io/apollo-api-v2', // REST
82
82
  production: 'wss://api-v3.aui.io/apollo-api-v2', // WebSocket
83
- local: 'ws://localhost:8000', // WebSocket (local)
84
83
  };
85
84
  ```
86
85
 
@@ -145,8 +144,9 @@ socket.on('message', (msg) => {
145
144
  socket.on('error', (err) => console.error('WS error:', err));
146
145
  socket.on('close', (event) => console.log('Closed:', event.code));
147
146
 
148
- // Send a turn
147
+ // Send a turn (type is required on the WS submit frame)
149
148
  socket.sendSubmitMessage({
149
+ type: 'message',
150
150
  agent_id: agentId,
151
151
  user_id: 'end-user-123',
152
152
  text: 'Hello over WebSocket',
@@ -156,6 +156,14 @@ socket.sendSubmitMessage({
156
156
  socket.close();
157
157
  ```
158
158
 
159
+ > **Notes**
160
+ > - `socket.on(event, handler)` registers a **single** handler per event — calling it
161
+ > again for the same event replaces the previous handler rather than adding one.
162
+ > - The socket type is exported as `SessionSocket` (`import { SessionSocket } from '@aui.io/aui-client'`).
163
+ > - Request timeouts are **per call** via `timeoutInSeconds` on a request's options; there
164
+ > is no client-wide default timeout. Pass it on slow calls, e.g.
165
+ > `client.threads.listThreads({ filters: {} }, { timeoutInSeconds: 120 })`.
166
+
159
167
  ## Key Context Helpers
160
168
 
161
169
  After the first request (or an explicit `getContext()`), scope resolved from the key is available:
@@ -172,13 +180,17 @@ client.organizationId;
172
180
 
173
181
  ## Error Handling
174
182
 
183
+ `ApolloError` (the base API error) and `ApolloTimeoutError` are exported at the top
184
+ level. The per-status errors (e.g. `UnprocessableEntityError`) live under the `Apollo`
185
+ namespace.
186
+
175
187
  ```typescript
176
- import { ApolloError, UnprocessableEntityError } from '@aui.io/aui-client';
188
+ import { ApolloError, Apollo } from '@aui.io/aui-client';
177
189
 
178
190
  try {
179
191
  await client.agents.getAgent('missing-id');
180
192
  } catch (error) {
181
- if (error instanceof UnprocessableEntityError) {
193
+ if (error instanceof Apollo.UnprocessableEntityError) {
182
194
  console.error('Validation failed:', error.body);
183
195
  } else if (error instanceof ApolloError) {
184
196
  console.error('API error:', error.statusCode, error.body);
@@ -196,6 +208,7 @@ The SDK ships full type definitions. Models are namespaced under `Apollo`:
196
208
  import { ApolloClient, Apollo } from '@aui.io/aui-client';
197
209
 
198
210
  const req: Apollo.SubmitMessageRequest = {
211
+ type: 'message',
199
212
  agent_id: 'agent-123',
200
213
  user_id: 'end-user-123',
201
214
  text: 'Typed request',
@@ -39,11 +39,12 @@ export declare class ApolloClient extends _GeneratedClient {
39
39
  keyType: PublishableKeyType;
40
40
  }>;
41
41
  /**
42
- * Open a messaging WebSocket session. The bearer token is resolved and sent as
43
- * Authorization on the upgrade, and the required `aui-websocket` subprotocol is
44
- * negotiated. Built here (rather than via the generated session resource) so the
45
- * generated code stays vanilla Fern emits protocols: [] and forwards only
46
- * per-call headers, neither of which the v2 server accepts.
42
+ * Open a messaging WebSocket session. The bearer token is passed as the first
43
+ * subprotocol (with `aui-websocket` second) the gateway reads auth from
44
+ * Sec-WebSocket-Protocol, the only upgrade header a browser can set. The token is
45
+ * also sent as an Authorization header for Node. Built here (rather than via the
46
+ * generated session resource) so the generated code stays vanilla — Fern emits
47
+ * protocols: [] and forwards only per-call headers, neither of which the server accepts.
47
48
  */
48
49
  connect(args?: ApolloClient.ConnectArgs): Promise<SessionSocket>;
49
50
  }
@@ -58,6 +58,16 @@ const SESSION_WS_PATH = "/messaging/v1/session";
58
58
  // The v2 messaging server negotiates this subprotocol on the WS upgrade; the
59
59
  // connection is rejected without it. Fern emits protocols: [], so we set it here.
60
60
  const WS_SUBPROTOCOL = "aui-websocket";
61
+ // Fern injects SDK-telemetry headers (X-Fern-*) on every request. The API doesn't need
62
+ // them, and in the browser each custom header triggers a CORS preflight that fails unless
63
+ // the gateway allow-lists it. Passing null strips them (mergeHeaders deletes null values).
64
+ const STRIPPED_SDK_HEADERS = {
65
+ "X-Fern-Language": null,
66
+ "X-Fern-SDK-Name": null,
67
+ "X-Fern-SDK-Version": null,
68
+ "X-Fern-Runtime": null,
69
+ "X-Fern-Runtime-Version": null,
70
+ };
61
71
  // Publishable-key exchange + token caching. Kept as a standalone object so the header
62
72
  // suppliers can close over it — a subclass may not touch `this` before super() runs.
63
73
  class Auth {
@@ -144,7 +154,7 @@ class ApolloClient extends Client_js_1.ApolloClient {
144
154
  const auth = new Auth(env.base, options.publishableKey, options.organizationApiKey);
145
155
  super({
146
156
  environment: env,
147
- headers: Object.assign({}, (auth.hasCredential ? { Authorization: () => __awaiter(this, void 0, void 0, function* () { return `Bearer ${yield auth.getToken()}`; }) } : {})),
157
+ headers: Object.assign(Object.assign({}, STRIPPED_SDK_HEADERS), (auth.hasCredential ? { Authorization: () => __awaiter(this, void 0, void 0, function* () { return `Bearer ${yield auth.getToken()}`; }) } : {})),
148
158
  });
149
159
  this._tokenAuth = auth;
150
160
  this._env = env;
@@ -166,11 +176,12 @@ class ApolloClient extends Client_js_1.ApolloClient {
166
176
  return this._tokenAuth.getContext();
167
177
  }
168
178
  /**
169
- * Open a messaging WebSocket session. The bearer token is resolved and sent as
170
- * Authorization on the upgrade, and the required `aui-websocket` subprotocol is
171
- * negotiated. Built here (rather than via the generated session resource) so the
172
- * generated code stays vanilla Fern emits protocols: [] and forwards only
173
- * per-call headers, neither of which the v2 server accepts.
179
+ * Open a messaging WebSocket session. The bearer token is passed as the first
180
+ * subprotocol (with `aui-websocket` second) the gateway reads auth from
181
+ * Sec-WebSocket-Protocol, the only upgrade header a browser can set. The token is
182
+ * also sent as an Authorization header for Node. Built here (rather than via the
183
+ * generated session resource) so the generated code stays vanilla — Fern emits
184
+ * protocols: [] and forwards only per-call headers, neither of which the server accepts.
174
185
  */
175
186
  connect() {
176
187
  return __awaiter(this, arguments, void 0, function* (args = {}) {
@@ -179,7 +190,9 @@ class ApolloClient extends Client_js_1.ApolloClient {
179
190
  const headers = Object.assign(Object.assign({}, (token ? { Authorization: `Bearer ${token}` } : {})), args.headers);
180
191
  const socket = new core.ReconnectingWebSocket({
181
192
  url: core.url.join(this._env.production, SESSION_WS_PATH),
182
- protocols: [WS_SUBPROTOCOL],
193
+ // Order matters: the gateway treats the FIRST subprotocol as the token and
194
+ // requires `aui-websocket` to follow. This is what makes browser WS auth work.
195
+ protocols: token ? [token, WS_SUBPROTOCOL] : [WS_SUBPROTOCOL],
183
196
  queryParameters: {},
184
197
  headers,
185
198
  options: {
@@ -61,8 +61,8 @@ class ApolloClient {
61
61
  this._options = Object.assign(Object.assign({}, _options), { logging: core.logging.createLogger(_options === null || _options === void 0 ? void 0 : _options.logging), headers: (0, headers_js_1.mergeHeaders)({
62
62
  "X-Fern-Language": "JavaScript",
63
63
  "X-Fern-SDK-Name": "@aui.io/aui-client",
64
- "X-Fern-SDK-Version": "3.1.0",
65
- "User-Agent": "@aui.io/aui-client/3.1.0",
64
+ "X-Fern-SDK-Version": "3.1.2",
65
+ "User-Agent": "@aui.io/aui-client/3.1.2",
66
66
  "X-Fern-Runtime": core.RUNTIME.type,
67
67
  "X-Fern-Runtime-Version": core.RUNTIME.version,
68
68
  }, _options === null || _options === void 0 ? void 0 : _options.headers) });
@@ -4,7 +4,7 @@ export declare namespace SessionSocket {
4
4
  interface Args {
5
5
  socket: core.ReconnectingWebSocket;
6
6
  }
7
- type Response = Apollo.SubmitMessageRequest | Apollo.ResumeRequest;
7
+ type Response = Apollo.ThreadEnvelope | Apollo.MessageEnvelope | Apollo.EventEnvelope | Apollo.ErrorEnvelope;
8
8
  type EventHandlers = {
9
9
  open?: () => void;
10
10
  message?: (message: Response) => void;
@@ -33,10 +33,8 @@ export declare class SessionSocket {
33
33
  * ```
34
34
  */
35
35
  on<T extends keyof SessionSocket.EventHandlers>(event: T, callback: SessionSocket.EventHandlers[T]): void;
36
- sendThreadAnnouncement(message: Apollo.ThreadEnvelope): void;
37
- sendAgentMessage(message: Apollo.MessageEnvelope): void;
38
- sendForwardedEvent(message: Apollo.EventEnvelope): void;
39
- sendErrorFrame(message: Apollo.ErrorEnvelope): void;
36
+ sendSubmitMessage(message: Apollo.SubmitMessageRequest): void;
37
+ sendResume(message: Apollo.ResumeRequest): void;
40
38
  /** Connect to the websocket and register event handlers. */
41
39
  connect(): SessionSocket;
42
40
  /** Close the websocket and unregister event handlers. */
@@ -48,5 +46,5 @@ export declare class SessionSocket {
48
46
  /** Send a binary payload to the websocket. */
49
47
  protected sendBinary(payload: ArrayBufferLike | Blob | ArrayBufferView): void;
50
48
  /** Send a JSON payload to the websocket. */
51
- protected sendJson(payload: Apollo.ThreadEnvelope | Apollo.MessageEnvelope | Apollo.EventEnvelope | Apollo.ErrorEnvelope): void;
49
+ protected sendJson(payload: Apollo.SubmitMessageRequest | Apollo.ResumeRequest): void;
52
50
  }
@@ -90,19 +90,11 @@ class SessionSocket {
90
90
  on(event, callback) {
91
91
  this.eventHandlers[event] = callback;
92
92
  }
93
- sendThreadAnnouncement(message) {
93
+ sendSubmitMessage(message) {
94
94
  this.assertSocketIsOpen();
95
95
  this.sendJson(message);
96
96
  }
97
- sendAgentMessage(message) {
98
- this.assertSocketIsOpen();
99
- this.sendJson(message);
100
- }
101
- sendForwardedEvent(message) {
102
- this.assertSocketIsOpen();
103
- this.sendJson(message);
104
- }
105
- sendErrorFrame(message) {
97
+ sendResume(message) {
106
98
  this.assertSocketIsOpen();
107
99
  this.sendJson(message);
108
100
  }
@@ -6,3 +6,4 @@
6
6
  * `export * from "./exports.js"`.
7
7
  */
8
8
  export * from "./core/exports.js";
9
+ export { SessionSocket } from "./api/resources/session/client/Socket.js";
@@ -21,4 +21,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
21
21
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
22
22
  };
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.SessionSocket = void 0;
24
25
  __exportStar(require("./core/exports.js"), exports);
26
+ // The generated session resource doesn't re-export its socket class, so consumers
27
+ // couldn't name the type returned by `client.connect()`. Surface it at the package root.
28
+ var Socket_js_1 = require("./api/resources/session/client/Socket.js");
29
+ Object.defineProperty(exports, "SessionSocket", { enumerable: true, get: function () { return Socket_js_1.SessionSocket; } });
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "3.1.0";
1
+ export declare const SDK_VERSION = "3.1.2";
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SDK_VERSION = void 0;
4
- exports.SDK_VERSION = "3.1.0";
4
+ exports.SDK_VERSION = "3.1.2";
@@ -39,11 +39,12 @@ export declare class ApolloClient extends _GeneratedClient {
39
39
  keyType: PublishableKeyType;
40
40
  }>;
41
41
  /**
42
- * Open a messaging WebSocket session. The bearer token is resolved and sent as
43
- * Authorization on the upgrade, and the required `aui-websocket` subprotocol is
44
- * negotiated. Built here (rather than via the generated session resource) so the
45
- * generated code stays vanilla Fern emits protocols: [] and forwards only
46
- * per-call headers, neither of which the v2 server accepts.
42
+ * Open a messaging WebSocket session. The bearer token is passed as the first
43
+ * subprotocol (with `aui-websocket` second) the gateway reads auth from
44
+ * Sec-WebSocket-Protocol, the only upgrade header a browser can set. The token is
45
+ * also sent as an Authorization header for Node. Built here (rather than via the
46
+ * generated session resource) so the generated code stays vanilla — Fern emits
47
+ * protocols: [] and forwards only per-call headers, neither of which the server accepts.
47
48
  */
48
49
  connect(args?: ApolloClient.ConnectArgs): Promise<SessionSocket>;
49
50
  }
@@ -22,6 +22,16 @@ const SESSION_WS_PATH = "/messaging/v1/session";
22
22
  // The v2 messaging server negotiates this subprotocol on the WS upgrade; the
23
23
  // connection is rejected without it. Fern emits protocols: [], so we set it here.
24
24
  const WS_SUBPROTOCOL = "aui-websocket";
25
+ // Fern injects SDK-telemetry headers (X-Fern-*) on every request. The API doesn't need
26
+ // them, and in the browser each custom header triggers a CORS preflight that fails unless
27
+ // the gateway allow-lists it. Passing null strips them (mergeHeaders deletes null values).
28
+ const STRIPPED_SDK_HEADERS = {
29
+ "X-Fern-Language": null,
30
+ "X-Fern-SDK-Name": null,
31
+ "X-Fern-SDK-Version": null,
32
+ "X-Fern-Runtime": null,
33
+ "X-Fern-Runtime-Version": null,
34
+ };
25
35
  // Publishable-key exchange + token caching. Kept as a standalone object so the header
26
36
  // suppliers can close over it — a subclass may not touch `this` before super() runs.
27
37
  class Auth {
@@ -108,7 +118,7 @@ export class ApolloClient extends _GeneratedClient {
108
118
  const auth = new Auth(env.base, options.publishableKey, options.organizationApiKey);
109
119
  super({
110
120
  environment: env,
111
- headers: Object.assign({}, (auth.hasCredential ? { Authorization: () => __awaiter(this, void 0, void 0, function* () { return `Bearer ${yield auth.getToken()}`; }) } : {})),
121
+ headers: Object.assign(Object.assign({}, STRIPPED_SDK_HEADERS), (auth.hasCredential ? { Authorization: () => __awaiter(this, void 0, void 0, function* () { return `Bearer ${yield auth.getToken()}`; }) } : {})),
112
122
  });
113
123
  this._tokenAuth = auth;
114
124
  this._env = env;
@@ -130,11 +140,12 @@ export class ApolloClient extends _GeneratedClient {
130
140
  return this._tokenAuth.getContext();
131
141
  }
132
142
  /**
133
- * Open a messaging WebSocket session. The bearer token is resolved and sent as
134
- * Authorization on the upgrade, and the required `aui-websocket` subprotocol is
135
- * negotiated. Built here (rather than via the generated session resource) so the
136
- * generated code stays vanilla Fern emits protocols: [] and forwards only
137
- * per-call headers, neither of which the v2 server accepts.
143
+ * Open a messaging WebSocket session. The bearer token is passed as the first
144
+ * subprotocol (with `aui-websocket` second) the gateway reads auth from
145
+ * Sec-WebSocket-Protocol, the only upgrade header a browser can set. The token is
146
+ * also sent as an Authorization header for Node. Built here (rather than via the
147
+ * generated session resource) so the generated code stays vanilla — Fern emits
148
+ * protocols: [] and forwards only per-call headers, neither of which the server accepts.
138
149
  */
139
150
  connect() {
140
151
  return __awaiter(this, arguments, void 0, function* (args = {}) {
@@ -143,7 +154,9 @@ export class ApolloClient extends _GeneratedClient {
143
154
  const headers = Object.assign(Object.assign({}, (token ? { Authorization: `Bearer ${token}` } : {})), args.headers);
144
155
  const socket = new core.ReconnectingWebSocket({
145
156
  url: core.url.join(this._env.production, SESSION_WS_PATH),
146
- protocols: [WS_SUBPROTOCOL],
157
+ // Order matters: the gateway treats the FIRST subprotocol as the token and
158
+ // requires `aui-websocket` to follow. This is what makes browser WS auth work.
159
+ protocols: token ? [token, WS_SUBPROTOCOL] : [WS_SUBPROTOCOL],
147
160
  queryParameters: {},
148
161
  headers,
149
162
  options: {
@@ -25,8 +25,8 @@ export class ApolloClient {
25
25
  this._options = Object.assign(Object.assign({}, _options), { logging: core.logging.createLogger(_options === null || _options === void 0 ? void 0 : _options.logging), headers: mergeHeaders({
26
26
  "X-Fern-Language": "JavaScript",
27
27
  "X-Fern-SDK-Name": "@aui.io/aui-client",
28
- "X-Fern-SDK-Version": "3.1.0",
29
- "User-Agent": "@aui.io/aui-client/3.1.0",
28
+ "X-Fern-SDK-Version": "3.1.2",
29
+ "User-Agent": "@aui.io/aui-client/3.1.2",
30
30
  "X-Fern-Runtime": core.RUNTIME.type,
31
31
  "X-Fern-Runtime-Version": core.RUNTIME.version,
32
32
  }, _options === null || _options === void 0 ? void 0 : _options.headers) });
@@ -4,7 +4,7 @@ export declare namespace SessionSocket {
4
4
  interface Args {
5
5
  socket: core.ReconnectingWebSocket;
6
6
  }
7
- type Response = Apollo.SubmitMessageRequest | Apollo.ResumeRequest;
7
+ type Response = Apollo.ThreadEnvelope | Apollo.MessageEnvelope | Apollo.EventEnvelope | Apollo.ErrorEnvelope;
8
8
  type EventHandlers = {
9
9
  open?: () => void;
10
10
  message?: (message: Response) => void;
@@ -33,10 +33,8 @@ export declare class SessionSocket {
33
33
  * ```
34
34
  */
35
35
  on<T extends keyof SessionSocket.EventHandlers>(event: T, callback: SessionSocket.EventHandlers[T]): void;
36
- sendThreadAnnouncement(message: Apollo.ThreadEnvelope): void;
37
- sendAgentMessage(message: Apollo.MessageEnvelope): void;
38
- sendForwardedEvent(message: Apollo.EventEnvelope): void;
39
- sendErrorFrame(message: Apollo.ErrorEnvelope): void;
36
+ sendSubmitMessage(message: Apollo.SubmitMessageRequest): void;
37
+ sendResume(message: Apollo.ResumeRequest): void;
40
38
  /** Connect to the websocket and register event handlers. */
41
39
  connect(): SessionSocket;
42
40
  /** Close the websocket and unregister event handlers. */
@@ -48,5 +46,5 @@ export declare class SessionSocket {
48
46
  /** Send a binary payload to the websocket. */
49
47
  protected sendBinary(payload: ArrayBufferLike | Blob | ArrayBufferView): void;
50
48
  /** Send a JSON payload to the websocket. */
51
- protected sendJson(payload: Apollo.ThreadEnvelope | Apollo.MessageEnvelope | Apollo.EventEnvelope | Apollo.ErrorEnvelope): void;
49
+ protected sendJson(payload: Apollo.SubmitMessageRequest | Apollo.ResumeRequest): void;
52
50
  }
@@ -54,19 +54,11 @@ export class SessionSocket {
54
54
  on(event, callback) {
55
55
  this.eventHandlers[event] = callback;
56
56
  }
57
- sendThreadAnnouncement(message) {
57
+ sendSubmitMessage(message) {
58
58
  this.assertSocketIsOpen();
59
59
  this.sendJson(message);
60
60
  }
61
- sendAgentMessage(message) {
62
- this.assertSocketIsOpen();
63
- this.sendJson(message);
64
- }
65
- sendForwardedEvent(message) {
66
- this.assertSocketIsOpen();
67
- this.sendJson(message);
68
- }
69
- sendErrorFrame(message) {
61
+ sendResume(message) {
70
62
  this.assertSocketIsOpen();
71
63
  this.sendJson(message);
72
64
  }
@@ -6,3 +6,4 @@
6
6
  * `export * from "./exports.mjs"`.
7
7
  */
8
8
  export * from "./core/exports.mjs";
9
+ export { SessionSocket } from "./api/resources/session/client/Socket.mjs";
@@ -6,3 +6,6 @@
6
6
  * `export * from "./exports.mjs"`.
7
7
  */
8
8
  export * from "./core/exports.mjs";
9
+ // The generated session resource doesn't re-export its socket class, so consumers
10
+ // couldn't name the type returned by `client.connect()`. Surface it at the package root.
11
+ export { SessionSocket } from "./api/resources/session/client/Socket.mjs";
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "3.1.0";
1
+ export declare const SDK_VERSION = "3.1.2";
@@ -1 +1 @@
1
- export const SDK_VERSION = "3.1.0";
1
+ export const SDK_VERSION = "3.1.2";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aui.io/aui-client",
3
- "version": "3.1.0",
3
+ "version": "3.1.2",
4
4
  "private": false,
5
5
  "repository": "github:aui-io/aui-client-typescript",
6
6
  "type": "commonjs",