@healthcloudai/hc-ams 0.0.1 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -5,6 +5,14 @@ function resolveBaseUrl(environment) {
5
5
  const prefix = environment === "prod" ? "" : `${environment}-`;
6
6
  return `https://${prefix}amsservices.health.cloud/api/ams`;
7
7
  }
8
+ function resolveAmsAuthBaseUrl(environment) {
9
+ const prefix = environment === "prod" ? "" : `${environment}-`;
10
+ return `https://${prefix}amsservices.health.cloud/api/auth`;
11
+ }
12
+ function resolveWssBaseUrl(environment) {
13
+ const prefix = environment === "prod" ? "" : `${environment}-`;
14
+ return `wss://${prefix}amsservices.health.cloud`;
15
+ }
8
16
  function assertEnvironment(environment) {
9
17
  if (environment !== "dev" && environment !== "uat" && environment !== "prod") {
10
18
  throw new Error(`Unsupported HealthCloud environment: "${environment}"`);
@@ -236,10 +244,639 @@ var AmsClient = class extends BaseServiceClient {
236
244
  }
237
245
  };
238
246
 
247
+ // src/clients/AgentsClient.ts
248
+ var AgentsClient = class extends BaseServiceClient {
249
+ constructor(http) {
250
+ super(http);
251
+ }
252
+ /** GET /agents */
253
+ list() {
254
+ return this.send("GET", "/agents");
255
+ }
256
+ /** GET /agents/{agent_id} */
257
+ get(agentId) {
258
+ return this.send("GET", "/agents/{agent_id}", {
259
+ pathParams: { agent_id: agentId }
260
+ });
261
+ }
262
+ /** POST /agents */
263
+ create(request) {
264
+ return this.send("POST", "/agents", { body: request });
265
+ }
266
+ /** PUT /agents/{agent_id} */
267
+ update(agentId, request) {
268
+ return this.send("PUT", "/agents/{agent_id}", {
269
+ pathParams: { agent_id: agentId },
270
+ body: request
271
+ });
272
+ }
273
+ /** DELETE /agents/{agent_id} */
274
+ delete(agentId) {
275
+ return this.send("DELETE", "/agents/{agent_id}", {
276
+ pathParams: { agent_id: agentId }
277
+ });
278
+ }
279
+ /** GET /agents/candidates — non-orchestrator agents eligible as transfer targets. */
280
+ listTransferCandidates() {
281
+ return this.send("GET", "/agents/candidates");
282
+ }
283
+ /**
284
+ * GET /agents/{agent_id}/conversation?session_id={tenant_id}/{patient_id}
285
+ *
286
+ * `sessionId` must be the literal `"{tenant_id}/{patient_id}"` string used
287
+ * to key the WSS session (see {@link "../wss/WssClient".WssClient}).
288
+ */
289
+ getConversation(agentId, sessionId) {
290
+ return this.send("GET", "/agents/{agent_id}/conversation", {
291
+ pathParams: { agent_id: agentId },
292
+ query: { session_id: sessionId }
293
+ });
294
+ }
295
+ /**
296
+ * DELETE /agents/{agent_id}/conversation?session_id={tenant_id}/{patient_id}
297
+ *
298
+ * Deletes both the persisted chat history and any live WSS session state
299
+ * for that session.
300
+ */
301
+ deleteConversation(agentId, sessionId) {
302
+ return this.send("DELETE", "/agents/{agent_id}/conversation", {
303
+ pathParams: { agent_id: agentId },
304
+ query: { session_id: sessionId }
305
+ });
306
+ }
307
+ };
308
+
309
+ // src/clients/DepartmentsClient.ts
310
+ var DepartmentsClient = class extends BaseServiceClient {
311
+ constructor(http) {
312
+ super(http);
313
+ }
314
+ /** GET /departments */
315
+ list() {
316
+ return this.send("GET", "/departments");
317
+ }
318
+ /** GET /departments/{department_id} */
319
+ get(departmentId) {
320
+ return this.send("GET", "/departments/{department_id}", {
321
+ pathParams: { department_id: departmentId }
322
+ });
323
+ }
324
+ /** POST /departments */
325
+ create(request) {
326
+ return this.send("POST", "/departments", { body: request });
327
+ }
328
+ /** PUT /departments/{department_id} */
329
+ update(departmentId, request) {
330
+ return this.send("PUT", "/departments/{department_id}", {
331
+ pathParams: { department_id: departmentId },
332
+ body: request
333
+ });
334
+ }
335
+ /** DELETE /departments/{department_id} */
336
+ delete(departmentId) {
337
+ return this.send("DELETE", "/departments/{department_id}", {
338
+ pathParams: { department_id: departmentId }
339
+ });
340
+ }
341
+ /** POST /departments/{department_id}/activate */
342
+ activate(departmentId) {
343
+ return this.send("POST", "/departments/{department_id}/activate", {
344
+ pathParams: { department_id: departmentId }
345
+ });
346
+ }
347
+ /** POST /departments/{department_id}/deactivate */
348
+ deactivate(departmentId) {
349
+ return this.send("POST", "/departments/{department_id}/deactivate", {
350
+ pathParams: { department_id: departmentId }
351
+ });
352
+ }
353
+ };
354
+
355
+ // src/clients/TeamsClient.ts
356
+ var TeamsClient = class extends BaseServiceClient {
357
+ constructor(http) {
358
+ super(http);
359
+ }
360
+ /** GET /teams */
361
+ list() {
362
+ return this.send("GET", "/teams");
363
+ }
364
+ /** GET /teams/{team_id} */
365
+ get(teamId) {
366
+ return this.send("GET", "/teams/{team_id}", {
367
+ pathParams: { team_id: teamId }
368
+ });
369
+ }
370
+ /** POST /teams */
371
+ create(request) {
372
+ return this.send("POST", "/teams", { body: request });
373
+ }
374
+ /** PUT /teams/{team_id} */
375
+ update(teamId, request) {
376
+ return this.send("PUT", "/teams/{team_id}", {
377
+ pathParams: { team_id: teamId },
378
+ body: request
379
+ });
380
+ }
381
+ /** DELETE /teams/{team_id} */
382
+ delete(teamId) {
383
+ return this.send("DELETE", "/teams/{team_id}", {
384
+ pathParams: { team_id: teamId }
385
+ });
386
+ }
387
+ };
388
+
389
+ // src/clients/SkillsClient.ts
390
+ var SkillsClient = class extends BaseServiceClient {
391
+ constructor(http) {
392
+ super(http);
393
+ }
394
+ /** GET /skills */
395
+ list() {
396
+ return this.send("GET", "/skills");
397
+ }
398
+ /** GET /skills/{skill_id} */
399
+ get(skillId) {
400
+ return this.send("GET", "/skills/{skill_id}", {
401
+ pathParams: { skill_id: skillId }
402
+ });
403
+ }
404
+ /** POST /skills */
405
+ create(request) {
406
+ return this.send("POST", "/skills", { body: request });
407
+ }
408
+ /** PUT /skills/{skill_id} */
409
+ update(skillId, request) {
410
+ return this.send("PUT", "/skills/{skill_id}", {
411
+ pathParams: { skill_id: skillId },
412
+ body: request
413
+ });
414
+ }
415
+ /** DELETE /skills/{skill_id} */
416
+ delete(skillId) {
417
+ return this.send("DELETE", "/skills/{skill_id}", {
418
+ pathParams: { skill_id: skillId }
419
+ });
420
+ }
421
+ };
422
+
423
+ // src/clients/PoliciesClient.ts
424
+ var PoliciesClient = class extends BaseServiceClient {
425
+ constructor(http) {
426
+ super(http);
427
+ }
428
+ /** GET /policies */
429
+ list() {
430
+ return this.send("GET", "/policies");
431
+ }
432
+ /** GET /policies/{policy_id} */
433
+ get(policyId) {
434
+ return this.send("GET", "/policies/{policy_id}", {
435
+ pathParams: { policy_id: policyId }
436
+ });
437
+ }
438
+ /** POST /policies */
439
+ create(request) {
440
+ return this.send("POST", "/policies", { body: request });
441
+ }
442
+ /** PUT /policies/{policy_id} */
443
+ update(policyId, request) {
444
+ return this.send("PUT", "/policies/{policy_id}", {
445
+ pathParams: { policy_id: policyId },
446
+ body: request
447
+ });
448
+ }
449
+ /** DELETE /policies/{policy_id} */
450
+ delete(policyId) {
451
+ return this.send("DELETE", "/policies/{policy_id}", {
452
+ pathParams: { policy_id: policyId }
453
+ });
454
+ }
455
+ };
456
+
457
+ // src/clients/GuardrailsClient.ts
458
+ var GuardrailsClient = class extends BaseServiceClient {
459
+ constructor(http) {
460
+ super(http);
461
+ }
462
+ /** GET /guardrails */
463
+ list() {
464
+ return this.send("GET", "/guardrails");
465
+ }
466
+ /** GET /guardrails/{guardrail_id} */
467
+ get(guardrailId) {
468
+ return this.send("GET", "/guardrails/{guardrail_id}", {
469
+ pathParams: { guardrail_id: guardrailId }
470
+ });
471
+ }
472
+ /** POST /guardrails */
473
+ create(request) {
474
+ return this.send("POST", "/guardrails", { body: request });
475
+ }
476
+ /** PUT /guardrails/{guardrail_id} */
477
+ update(guardrailId, request) {
478
+ return this.send("PUT", "/guardrails/{guardrail_id}", {
479
+ pathParams: { guardrail_id: guardrailId },
480
+ body: request
481
+ });
482
+ }
483
+ /** DELETE /guardrails/{guardrail_id} */
484
+ delete(guardrailId) {
485
+ return this.send("DELETE", "/guardrails/{guardrail_id}", {
486
+ pathParams: { guardrail_id: guardrailId }
487
+ });
488
+ }
489
+ };
490
+
491
+ // src/clients/DataSourcesClient.ts
492
+ var DataSourcesClient = class extends BaseServiceClient {
493
+ constructor(http) {
494
+ super(http);
495
+ }
496
+ /** GET /data-sources */
497
+ list() {
498
+ return this.send("GET", "/data-sources");
499
+ }
500
+ /** GET /data-sources/{data_source_id} */
501
+ get(dataSourceId) {
502
+ return this.send("GET", "/data-sources/{data_source_id}", {
503
+ pathParams: { data_source_id: dataSourceId }
504
+ });
505
+ }
506
+ };
507
+
508
+ // src/clients/ToolsClient.ts
509
+ var ToolsClient = class extends BaseServiceClient {
510
+ constructor(http) {
511
+ super(http);
512
+ }
513
+ /** GET /tools */
514
+ list() {
515
+ return this.send("GET", "/tools");
516
+ }
517
+ /** GET /tools/{tool_id} */
518
+ get(toolId) {
519
+ return this.send("GET", "/tools/{tool_id}", {
520
+ pathParams: { tool_id: toolId }
521
+ });
522
+ }
523
+ };
524
+
525
+ // src/clients/TestPersonasClient.ts
526
+ var TestPersonasClient = class extends BaseServiceClient {
527
+ constructor(http) {
528
+ super(http);
529
+ }
530
+ /** GET /test-patient-credentials */
531
+ list() {
532
+ return this.send("GET", "/test-patient-credentials");
533
+ }
534
+ /** GET /test-patient-credentials/{credential_id} */
535
+ get(credentialId) {
536
+ return this.send("GET", "/test-patient-credentials/{credential_id}", {
537
+ pathParams: { credential_id: credentialId }
538
+ });
539
+ }
540
+ /** POST /test-patient-credentials */
541
+ create(request) {
542
+ return this.send("POST", "/test-patient-credentials", { body: request });
543
+ }
544
+ /** PUT /test-patient-credentials/{credential_id} */
545
+ update(credentialId, request) {
546
+ return this.send("PUT", "/test-patient-credentials/{credential_id}", {
547
+ pathParams: { credential_id: credentialId },
548
+ body: request
549
+ });
550
+ }
551
+ /** DELETE /test-patient-credentials/{credential_id} */
552
+ delete(credentialId) {
553
+ return this.send("DELETE", "/test-patient-credentials/{credential_id}", {
554
+ pathParams: { credential_id: credentialId }
555
+ });
556
+ }
557
+ /**
558
+ * POST /test-patient-credentials/{credential_id}/login
559
+ *
560
+ * Logs this persona into Health Cloud and returns a real patient access
561
+ * token — feed `access_token`/`patient_id` into
562
+ * {@link "../wss/WssClient".WssClient} to open a chat session as this persona.
563
+ */
564
+ login(credentialId) {
565
+ return this.send("POST", "/test-patient-credentials/{credential_id}/login", {
566
+ pathParams: { credential_id: credentialId }
567
+ });
568
+ }
569
+ };
570
+
571
+ // src/clients/AuthClient.ts
572
+ var AuthClient = class extends BaseServiceClient {
573
+ constructor(http) {
574
+ super(http);
575
+ }
576
+ /** POST /api/auth/login (public) */
577
+ login(request) {
578
+ return this.send("POST", "/login", { body: request, auth: false });
579
+ }
580
+ /** POST /api/auth/reset-password (public) */
581
+ resetPassword(request) {
582
+ return this.send("POST", "/reset-password", { body: request, auth: false });
583
+ }
584
+ /** POST /api/auth/confirm-reset-password (public) */
585
+ confirmResetPassword(request) {
586
+ return this.send("POST", "/confirm-reset-password", { body: request, auth: false });
587
+ }
588
+ /** POST /api/auth/register (public) */
589
+ register(request) {
590
+ return this.send("POST", "/register", { body: request, auth: false });
591
+ }
592
+ /** GET /api/auth/me (Bearer required) */
593
+ me() {
594
+ return this.send("GET", "/me");
595
+ }
596
+ };
597
+
598
+ // src/wss/WssClient.ts
599
+ var WssClient = class {
600
+ constructor(options) {
601
+ this.options = options;
602
+ this.authenticated = false;
603
+ // Storage is necessarily untyped across the heterogeneous event map; `on`/`dispatch` restore type safety at the boundary.
604
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
605
+ this.listeners = /* @__PURE__ */ new Map();
606
+ var _a, _b, _c, _d;
607
+ if (options.healthcloudToken === void 0 && options.getAccessToken === void 0) {
608
+ throw new SDKError({
609
+ message: "WssClient requires either `healthcloudToken` or `getAccessToken`.",
610
+ statusCode: 0
611
+ });
612
+ }
613
+ const base = (_a = options.baseUrlOverride) != null ? _a : resolveWssBaseUrl(options.environment);
614
+ const sessionId = `${options.tenantId}/${options.patientId}`;
615
+ const path = options.agentId ? `/ws/agents/${encodeURIComponent(options.agentId)}/chat` : "/ws";
616
+ const url = new URL(`${base}${path}`);
617
+ url.searchParams.set("session_id", sessionId);
618
+ if (options.lang) url.searchParams.set("lang", options.lang);
619
+ if (options.voice) url.searchParams.set("voice", "1");
620
+ if (options.voiceId) url.searchParams.set("voice_id", options.voiceId);
621
+ if (options.audioFormat) url.searchParams.set("audio_format", options.audioFormat);
622
+ if (options.replaySince !== void 0) url.searchParams.set("replay_since", String(options.replaySince));
623
+ if (options.handoff && options.handoff.length > 0) {
624
+ url.searchParams.set("handoff", JSON.stringify(options.handoff));
625
+ }
626
+ this.url = url.toString();
627
+ this.turnTimeoutMs = (_b = options.turnTimeoutMs) != null ? _b : 6e4;
628
+ this.authTimeoutMs = (_c = options.authTimeoutMs) != null ? _c : 1e4;
629
+ const ctor = (_d = options.WebSocketImpl) != null ? _d : globalThis.WebSocket;
630
+ if (!ctor) {
631
+ throw new SDKError({
632
+ message: 'No WebSocket implementation available. Pass `WebSocketImpl` (e.g. `new WssClient({ ..., WebSocketImpl: require("ws") })`) on runtimes without a global WebSocket (Node < 21).',
633
+ statusCode: 0
634
+ });
635
+ }
636
+ this.WebSocketCtor = ctor;
637
+ }
638
+ async resolveToken() {
639
+ var _a;
640
+ if (this.options.getAccessToken) {
641
+ return this.options.getAccessToken();
642
+ }
643
+ return (_a = this.options.healthcloudToken) != null ? _a : "";
644
+ }
645
+ /**
646
+ * Opens the socket and runs the auth handshake: sends
647
+ * `{"type":"auth","token":...}` as soon as the socket opens, and resolves
648
+ * only once the server replies `{"type":"auth_ok"}`. Rejects on a
649
+ * connect/auth error, an auth timeout, or a rejection frame — in every
650
+ * case before any chat frame can be sent (see {@link send}).
651
+ */
652
+ connect() {
653
+ return new Promise((resolve, reject) => {
654
+ this.authenticated = false;
655
+ const socket = new this.WebSocketCtor(this.url);
656
+ this.socket = socket;
657
+ let authTimer;
658
+ const settle = (fn) => {
659
+ cleanup();
660
+ fn();
661
+ };
662
+ const onOpen = () => {
663
+ authTimer = setTimeout(() => {
664
+ settle(
665
+ () => reject(new SDKError({ message: `Authentication timed out after ${this.authTimeoutMs}ms.`, statusCode: 0 }))
666
+ );
667
+ socket.close();
668
+ }, this.authTimeoutMs);
669
+ this.resolveToken().then((token) => socket.send(JSON.stringify({ type: "auth", token }))).catch((error) => {
670
+ clearTimeout(authTimer);
671
+ settle(
672
+ () => reject(
673
+ new SDKError({
674
+ message: "Failed to resolve the Health Cloud access token for the auth frame.",
675
+ statusCode: 0,
676
+ cause: error
677
+ })
678
+ )
679
+ );
680
+ socket.close();
681
+ });
682
+ };
683
+ const onError = (event) => {
684
+ clearTimeout(authTimer);
685
+ settle(() => reject(new SDKError({ message: "WebSocket connection failed.", statusCode: 0, cause: event })));
686
+ };
687
+ const onClose = (event) => {
688
+ clearTimeout(authTimer);
689
+ if (this.authenticated) return;
690
+ settle(
691
+ () => {
692
+ var _a, _b;
693
+ return reject(
694
+ new SDKError({
695
+ message: `WebSocket closed before authenticating (code ${(_a = event.code) != null ? _a : "unknown"}): ${(_b = event.reason) != null ? _b : ""}`.trim(),
696
+ statusCode: 0
697
+ })
698
+ );
699
+ }
700
+ );
701
+ };
702
+ const onMessage = (event) => {
703
+ var _a, _b;
704
+ if (!this.authenticated) {
705
+ let frame;
706
+ try {
707
+ frame = JSON.parse(String((_a = event.data) != null ? _a : ""));
708
+ } catch {
709
+ return;
710
+ }
711
+ if ((frame == null ? void 0 : frame.type) === "auth_ok") {
712
+ clearTimeout(authTimer);
713
+ this.authenticated = true;
714
+ settle(() => resolve());
715
+ return;
716
+ }
717
+ if ((frame == null ? void 0 : frame.type) === "error") {
718
+ clearTimeout(authTimer);
719
+ settle(
720
+ () => {
721
+ var _a2, _b2;
722
+ return reject(
723
+ new SDKError({
724
+ message: `WebSocket authentication was rejected: ${(_b2 = (_a2 = frame == null ? void 0 : frame.payload) == null ? void 0 : _a2.message) != null ? _b2 : "unknown error"}`,
725
+ statusCode: 401
726
+ })
727
+ );
728
+ }
729
+ );
730
+ return;
731
+ }
732
+ return;
733
+ }
734
+ this.dispatch((_b = event.data) != null ? _b : "");
735
+ };
736
+ const cleanup = () => {
737
+ socket.removeEventListener("open", onOpen);
738
+ socket.removeEventListener("error", onError);
739
+ socket.removeEventListener("close", onClose);
740
+ };
741
+ socket.addEventListener("open", onOpen);
742
+ socket.addEventListener("error", onError);
743
+ socket.addEventListener("close", onClose);
744
+ socket.addEventListener("message", onMessage);
745
+ });
746
+ }
747
+ /** Subscribes to a typed server event. Returns an unsubscribe function. */
748
+ on(type, handler) {
749
+ let set = this.listeners.get(type);
750
+ if (!set) {
751
+ set = /* @__PURE__ */ new Set();
752
+ this.listeners.set(type, set);
753
+ }
754
+ set.add(handler);
755
+ return () => set.delete(handler);
756
+ }
757
+ /** Sends a raw outgoing frame: `{"type": type, "payload": payload}`. */
758
+ send(type, payload = {}) {
759
+ if (!this.socket) {
760
+ throw new SDKError({ message: "WssClient is not connected. Call connect() first.", statusCode: 0 });
761
+ }
762
+ if (!this.authenticated) {
763
+ throw new SDKError({
764
+ message: "WssClient has not finished authenticating yet. Await connect() before sending frames.",
765
+ statusCode: 0
766
+ });
767
+ }
768
+ this.socket.send(JSON.stringify({ type, payload }));
769
+ }
770
+ sendChat(payload) {
771
+ this.send("chat", payload);
772
+ }
773
+ sendVoice(active) {
774
+ this.send("voice", { active });
775
+ }
776
+ sendAudioInput(payload) {
777
+ this.send("audio_input", payload);
778
+ }
779
+ sendToolConfirmation(payload) {
780
+ this.send("tool_confirmation", payload);
781
+ }
782
+ sendHandoff(messages) {
783
+ this.send("handoff", { messages });
784
+ }
785
+ /**
786
+ * Sends a `chat` frame and resolves once that turn completes, buffering
787
+ * every streamed `chat` delta into the final `message` and collecting
788
+ * `activity`/`transfer`/`artifact_block`/`notification`/`response_suggestions`
789
+ * events emitted during the turn.
790
+ *
791
+ * Resolves with `status: "failed"`/`"cancelled"` (rather than rejecting)
792
+ * on `turn_failed`/`turn_cancelled`, so callers can inspect whatever
793
+ * partial `message`/side-effects were collected before the turn ended.
794
+ * Rejects only if no terminal event arrives within `timeoutMs`.
795
+ */
796
+ sendAndAwaitTurn(content, opts = {}) {
797
+ const { timeoutMs = this.turnTimeoutMs, ...chatOpts } = opts;
798
+ return new Promise((resolve, reject) => {
799
+ let message = "";
800
+ const activity = [];
801
+ const transfers = [];
802
+ const artifacts = [];
803
+ const notifications = [];
804
+ let suggestions;
805
+ let turnId;
806
+ const unsubscribers = [];
807
+ const cleanup = () => {
808
+ clearTimeout(timer);
809
+ unsubscribers.forEach((unsub) => unsub());
810
+ };
811
+ const timer = setTimeout(() => {
812
+ cleanup();
813
+ reject(new SDKError({ message: `Turn timed out after ${timeoutMs}ms.`, statusCode: 0 }));
814
+ }, timeoutMs);
815
+ unsubscribers.push(
816
+ this.on("chat", (event) => {
817
+ var _a;
818
+ turnId = (_a = event.turn_id) != null ? _a : turnId;
819
+ if (event.replace) {
820
+ message = event.content;
821
+ } else {
822
+ message += event.content;
823
+ }
824
+ }),
825
+ this.on("activity", (event) => activity.push(event)),
826
+ this.on("transfer", (event) => transfers.push(event)),
827
+ this.on("artifact_block", (event) => artifacts.push(event)),
828
+ this.on("notification", (event) => notifications.push(event)),
829
+ this.on("response_suggestions", (event) => {
830
+ suggestions = event;
831
+ }),
832
+ this.on("turn_completed", (event) => {
833
+ var _a;
834
+ turnId = (_a = event.turn_id) != null ? _a : turnId;
835
+ cleanup();
836
+ resolve({ message, activity, transfers, artifacts, notifications, suggestions, turnId, status: "completed" });
837
+ }),
838
+ this.on("turn_failed", (event) => {
839
+ var _a;
840
+ turnId = (_a = event.turn_id) != null ? _a : turnId;
841
+ cleanup();
842
+ resolve({ message, activity, transfers, artifacts, notifications, suggestions, turnId, status: "failed" });
843
+ }),
844
+ this.on("turn_cancelled", (event) => {
845
+ var _a;
846
+ turnId = (_a = event.turn_id) != null ? _a : turnId;
847
+ cleanup();
848
+ resolve({ message, activity, transfers, artifacts, notifications, suggestions, turnId, status: "cancelled" });
849
+ })
850
+ );
851
+ this.sendChat({ content, ...chatOpts });
852
+ });
853
+ }
854
+ /** Closes the socket and clears all listeners. */
855
+ close(code, reason) {
856
+ var _a;
857
+ (_a = this.socket) == null ? void 0 : _a.close(code, reason);
858
+ this.authenticated = false;
859
+ this.listeners.clear();
860
+ }
861
+ dispatch(raw) {
862
+ let frame;
863
+ try {
864
+ frame = JSON.parse(raw);
865
+ } catch {
866
+ return;
867
+ }
868
+ const set = this.listeners.get(frame.type);
869
+ if (!set) return;
870
+ for (const handler of set) {
871
+ handler(frame.payload);
872
+ }
873
+ }
874
+ };
875
+
239
876
  // src/HCAmsSDK.ts
240
877
  var HCAmsSDK = class {
241
878
  constructor(config) {
242
- var _a, _b;
879
+ var _a, _b, _c;
243
880
  assertEnvironment(config.environment);
244
881
  assertTimeout((_a = config.timeout) != null ? _a : DEFAULT_TIMEOUT_MS);
245
882
  this.state = {
@@ -250,7 +887,60 @@ var HCAmsSDK = class {
250
887
  timeout: (_b = config.timeout) != null ? _b : DEFAULT_TIMEOUT_MS
251
888
  };
252
889
  this.http = new HttpClient(this.state);
890
+ const authBaseUrlOverride = (_c = config.baseUrlOverride) != null ? _c : resolveAmsAuthBaseUrl(config.environment);
891
+ const state = this.state;
892
+ const authState = {
893
+ get environment() {
894
+ return state.environment;
895
+ },
896
+ get tenantId() {
897
+ return state.tenantId;
898
+ },
899
+ get accessToken() {
900
+ return state.accessToken;
901
+ },
902
+ set accessToken(value) {
903
+ state.accessToken = value;
904
+ },
905
+ get baseUrlOverride() {
906
+ return authBaseUrlOverride;
907
+ },
908
+ get timeout() {
909
+ return state.timeout;
910
+ }
911
+ };
912
+ this.authHttp = new HttpClient(authState);
253
913
  this.ams = new AmsClient(this.http);
914
+ this.agents = new AgentsClient(this.http);
915
+ this.departments = new DepartmentsClient(this.http);
916
+ this.teams = new TeamsClient(this.http);
917
+ this.skills = new SkillsClient(this.http);
918
+ this.policies = new PoliciesClient(this.http);
919
+ this.guardrails = new GuardrailsClient(this.http);
920
+ this.dataSources = new DataSourcesClient(this.http);
921
+ this.tools = new ToolsClient(this.http);
922
+ this.testPersonas = new TestPersonasClient(this.http);
923
+ this.auth = new AuthClient(this.authHttp);
924
+ }
925
+ /**
926
+ * Opens a WebSocket agent-chat session using this SDK's configured
927
+ * environment (and `tenantId`, if set and not overridden here). See
928
+ * {@link WssClient} for the full API (typed event subscription,
929
+ * `sendAndAwaitTurn`, etc).
930
+ */
931
+ connectAgentChat(options) {
932
+ var _a;
933
+ const tenantId = (_a = options.tenantId) != null ? _a : this.state.tenantId;
934
+ if (!tenantId) {
935
+ throw new Error(
936
+ "connectAgentChat requires a tenantId \u2014 pass one explicitly or configure it on HCAmsSDK."
937
+ );
938
+ }
939
+ return new WssClient({
940
+ ...options,
941
+ environment: this.state.environment,
942
+ tenantId
943
+ });
254
944
  }
255
945
  /** Get the current runtime environment. */
256
946
  get environment() {
@@ -270,12 +960,25 @@ var HCAmsSDK = class {
270
960
  }
271
961
  };
272
962
  export {
963
+ AgentsClient,
273
964
  AmsClient,
965
+ AuthClient,
274
966
  DEFAULT_TIMEOUT_MS,
967
+ DataSourcesClient,
968
+ DepartmentsClient,
969
+ GuardrailsClient,
275
970
  HCAmsSDK,
971
+ PoliciesClient,
276
972
  SDKError,
277
973
  SERVICE_NAME,
974
+ SkillsClient,
975
+ TeamsClient,
976
+ TestPersonasClient,
977
+ ToolsClient,
978
+ WssClient,
278
979
  assertEnvironment,
279
980
  assertTimeout,
280
- resolveBaseUrl
981
+ resolveAmsAuthBaseUrl,
982
+ resolveBaseUrl,
983
+ resolveWssBaseUrl
281
984
  };