@servicetitan/titan-chatbot-api 7.1.2 → 9.0.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 (178) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/api-client/__mocks__/chatbot-api-client.mock.d.ts +1 -0
  3. package/dist/api-client/__mocks__/chatbot-api-client.mock.d.ts.map +1 -1
  4. package/dist/api-client/__mocks__/chatbot-api-client.mock.js +22 -47
  5. package/dist/api-client/__mocks__/chatbot-api-client.mock.js.map +1 -1
  6. package/dist/api-client/base/chatbot-api-client.d.ts +7 -0
  7. package/dist/api-client/base/chatbot-api-client.d.ts.map +1 -1
  8. package/dist/api-client/base/chatbot-api-client.js +3 -4
  9. package/dist/api-client/base/chatbot-api-client.js.map +1 -1
  10. package/dist/api-client/index.d.ts +2 -2
  11. package/dist/api-client/index.d.ts.map +1 -1
  12. package/dist/api-client/index.js +12 -7
  13. package/dist/api-client/index.js.map +1 -1
  14. package/dist/api-client/models/__mocks__/models.mock.js +154 -124
  15. package/dist/api-client/models/__mocks__/models.mock.js.map +1 -1
  16. package/dist/api-client/models/index.d.ts +2 -1
  17. package/dist/api-client/models/index.d.ts.map +1 -1
  18. package/dist/api-client/models/index.js +8 -7
  19. package/dist/api-client/models/index.js.map +1 -1
  20. package/dist/api-client/titan-chat/__tests__/chatbot-api-client-stream.test.d.ts +2 -0
  21. package/dist/api-client/titan-chat/__tests__/chatbot-api-client-stream.test.d.ts.map +1 -0
  22. package/dist/api-client/titan-chat/__tests__/chatbot-api-client-stream.test.js +240 -0
  23. package/dist/api-client/titan-chat/__tests__/chatbot-api-client-stream.test.js.map +1 -0
  24. package/dist/api-client/titan-chat/__tests__/native-client.test.js +6 -6
  25. package/dist/api-client/titan-chat/__tests__/native-client.test.js.map +1 -1
  26. package/dist/api-client/titan-chat/chatbot-api-client.d.ts +11 -0
  27. package/dist/api-client/titan-chat/chatbot-api-client.d.ts.map +1 -1
  28. package/dist/api-client/titan-chat/chatbot-api-client.js +69 -35
  29. package/dist/api-client/titan-chat/chatbot-api-client.js.map +1 -1
  30. package/dist/api-client/titan-chat/index.d.ts +2 -1
  31. package/dist/api-client/titan-chat/index.d.ts.map +1 -1
  32. package/dist/api-client/titan-chat/index.js +1 -0
  33. package/dist/api-client/titan-chat/index.js.map +1 -1
  34. package/dist/api-client/titan-chat/native-client.js +359 -812
  35. package/dist/api-client/titan-chat/native-client.js.map +1 -1
  36. package/dist/api-client/utils/__tests__/model-utils.test.js +454 -191
  37. package/dist/api-client/utils/__tests__/model-utils.test.js.map +1 -1
  38. package/dist/api-client/utils/model-utils.d.ts.map +1 -1
  39. package/dist/api-client/utils/model-utils.js +28 -25
  40. package/dist/api-client/utils/model-utils.js.map +1 -1
  41. package/dist/hooks/use-customization-chatbot.js +2 -1
  42. package/dist/hooks/use-customization-chatbot.js.map +1 -1
  43. package/dist/index.d.ts +3 -2
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +7 -5
  46. package/dist/index.js.map +1 -1
  47. package/dist/models/__tests__/chatbot-customizations.test.d.ts +2 -0
  48. package/dist/models/__tests__/chatbot-customizations.test.d.ts.map +1 -0
  49. package/dist/models/__tests__/chatbot-customizations.test.js +36 -0
  50. package/dist/models/__tests__/chatbot-customizations.test.js.map +1 -0
  51. package/dist/models/chatbot-customizations.d.ts +17 -0
  52. package/dist/models/chatbot-customizations.d.ts.map +1 -1
  53. package/dist/models/chatbot-customizations.js +7 -1
  54. package/dist/models/chatbot-customizations.js.map +1 -1
  55. package/dist/models/index.js +1 -0
  56. package/dist/models/index.js.map +1 -1
  57. package/dist/stores/__tests__/chatbot-ui-backend.store.observability.test.d.ts +2 -0
  58. package/dist/stores/__tests__/chatbot-ui-backend.store.observability.test.d.ts.map +1 -0
  59. package/dist/stores/__tests__/chatbot-ui-backend.store.observability.test.js +107 -0
  60. package/dist/stores/__tests__/chatbot-ui-backend.store.observability.test.js.map +1 -0
  61. package/dist/stores/__tests__/chatbot-ui-backend.store.streaming.test.d.ts +2 -0
  62. package/dist/stores/__tests__/chatbot-ui-backend.store.streaming.test.d.ts.map +1 -0
  63. package/dist/stores/__tests__/chatbot-ui-backend.store.streaming.test.js +312 -0
  64. package/dist/stores/__tests__/chatbot-ui-backend.store.streaming.test.js.map +1 -0
  65. package/dist/stores/__tests__/chatbot-ui-backend.store.test.js +267 -172
  66. package/dist/stores/__tests__/chatbot-ui-backend.store.test.js.map +1 -1
  67. package/dist/stores/__tests__/chatbot-ui.store.test.js +61 -64
  68. package/dist/stores/__tests__/chatbot-ui.store.test.js.map +1 -1
  69. package/dist/stores/__tests__/filter.store.test.js +243 -116
  70. package/dist/stores/__tests__/filter.store.test.js.map +1 -1
  71. package/dist/stores/__tests__/initialize.store.test.js +9 -8
  72. package/dist/stores/__tests__/initialize.store.test.js.map +1 -1
  73. package/dist/stores/__tests__/message-feedback-guardrail.store.test.js +8 -7
  74. package/dist/stores/__tests__/message-feedback-guardrail.store.test.js.map +1 -1
  75. package/dist/stores/__tests__/message-feedback.store.test.js +34 -27
  76. package/dist/stores/__tests__/message-feedback.store.test.js.map +1 -1
  77. package/dist/stores/__tests__/session-feedback.store.test.js +9 -8
  78. package/dist/stores/__tests__/session-feedback.store.test.js.map +1 -1
  79. package/dist/stores/chatbot-ui-backend.store.d.ts +26 -2
  80. package/dist/stores/chatbot-ui-backend.store.d.ts.map +1 -1
  81. package/dist/stores/chatbot-ui-backend.store.js +295 -239
  82. package/dist/stores/chatbot-ui-backend.store.js.map +1 -1
  83. package/dist/stores/chatbot-ui.store.js +73 -46
  84. package/dist/stores/chatbot-ui.store.js.map +1 -1
  85. package/dist/stores/filter.store.js +298 -378
  86. package/dist/stores/filter.store.js.map +1 -1
  87. package/dist/stores/index.d.ts +5 -3
  88. package/dist/stores/index.d.ts.map +1 -1
  89. package/dist/stores/index.js +3 -2
  90. package/dist/stores/index.js.map +1 -1
  91. package/dist/stores/initialize.store.js +55 -51
  92. package/dist/stores/initialize.store.js.map +1 -1
  93. package/dist/stores/message-feedback-base.store.js +2 -1
  94. package/dist/stores/message-feedback-base.store.js.map +1 -1
  95. package/dist/stores/message-feedback-guardrail.store.js +50 -47
  96. package/dist/stores/message-feedback-guardrail.store.js.map +1 -1
  97. package/dist/stores/message-feedback.store.js +84 -89
  98. package/dist/stores/message-feedback.store.js.map +1 -1
  99. package/dist/stores/session-feedback.store.js +46 -39
  100. package/dist/stores/session-feedback.store.js.map +1 -1
  101. package/dist/streaming/__tests__/agent-stream.test.d.ts +2 -0
  102. package/dist/streaming/__tests__/agent-stream.test.d.ts.map +1 -0
  103. package/dist/streaming/__tests__/agent-stream.test.js +92 -0
  104. package/dist/streaming/__tests__/agent-stream.test.js.map +1 -0
  105. package/dist/streaming/agent-stream.d.ts +83 -0
  106. package/dist/streaming/agent-stream.d.ts.map +1 -0
  107. package/dist/streaming/agent-stream.js +28 -0
  108. package/dist/streaming/agent-stream.js.map +1 -0
  109. package/dist/streaming/index.d.ts +3 -0
  110. package/dist/streaming/index.d.ts.map +1 -0
  111. package/dist/streaming/index.js +4 -0
  112. package/dist/streaming/index.js.map +1 -0
  113. package/dist/streaming/run-agent-stream.d.ts +23 -0
  114. package/dist/streaming/run-agent-stream.d.ts.map +1 -0
  115. package/dist/streaming/run-agent-stream.js +83 -0
  116. package/dist/streaming/run-agent-stream.js.map +1 -0
  117. package/dist/utils/__tests__/axios-utils.test.js +8 -7
  118. package/dist/utils/__tests__/axios-utils.test.js.map +1 -1
  119. package/dist/utils/axios-utils.js +9 -7
  120. package/dist/utils/axios-utils.js.map +1 -1
  121. package/dist/utils/test-utils.js +5 -5
  122. package/dist/utils/test-utils.js.map +1 -1
  123. package/package.json +6 -3
  124. package/src/api-client/__mocks__/chatbot-api-client.mock.ts +1 -0
  125. package/src/api-client/base/chatbot-api-client.ts +11 -0
  126. package/src/api-client/index.ts +2 -7
  127. package/src/api-client/models/index.ts +15 -13
  128. package/src/api-client/titan-chat/__tests__/chatbot-api-client-stream.test.ts +208 -0
  129. package/src/api-client/titan-chat/chatbot-api-client.ts +46 -0
  130. package/src/api-client/titan-chat/index.ts +2 -1
  131. package/src/api-client/utils/model-utils.ts +4 -8
  132. package/src/index.ts +7 -2
  133. package/src/models/__tests__/chatbot-customizations.test.ts +26 -0
  134. package/src/models/chatbot-customizations.ts +20 -0
  135. package/src/stores/__tests__/chatbot-ui-backend.store.observability.test.ts +105 -0
  136. package/src/stores/__tests__/chatbot-ui-backend.store.streaming.test.ts +261 -0
  137. package/src/stores/chatbot-ui-backend.store.ts +179 -4
  138. package/src/stores/index.ts +5 -12
  139. package/src/streaming/__tests__/agent-stream.test.ts +80 -0
  140. package/src/streaming/agent-stream.ts +103 -0
  141. package/src/streaming/index.ts +2 -0
  142. package/src/streaming/run-agent-stream.ts +109 -0
  143. package/tsconfig.tsbuildinfo +1 -1
  144. package/dist/api-client/help-center/__tests__/converter-from-models.test.d.ts +0 -2
  145. package/dist/api-client/help-center/__tests__/converter-from-models.test.d.ts.map +0 -1
  146. package/dist/api-client/help-center/__tests__/converter-from-models.test.js +0 -34
  147. package/dist/api-client/help-center/__tests__/converter-from-models.test.js.map +0 -1
  148. package/dist/api-client/help-center/__tests__/converter-to-models.test.d.ts +0 -2
  149. package/dist/api-client/help-center/__tests__/converter-to-models.test.d.ts.map +0 -1
  150. package/dist/api-client/help-center/__tests__/converter-to-models.test.js +0 -82
  151. package/dist/api-client/help-center/__tests__/converter-to-models.test.js.map +0 -1
  152. package/dist/api-client/help-center/chatbot-api-client.d.ts +0 -32
  153. package/dist/api-client/help-center/chatbot-api-client.d.ts.map +0 -1
  154. package/dist/api-client/help-center/chatbot-api-client.js +0 -102
  155. package/dist/api-client/help-center/chatbot-api-client.js.map +0 -1
  156. package/dist/api-client/help-center/converter-from-models.d.ts +0 -13
  157. package/dist/api-client/help-center/converter-from-models.d.ts.map +0 -1
  158. package/dist/api-client/help-center/converter-from-models.js +0 -114
  159. package/dist/api-client/help-center/converter-from-models.js.map +0 -1
  160. package/dist/api-client/help-center/converter-to-models.d.ts +0 -13
  161. package/dist/api-client/help-center/converter-to-models.d.ts.map +0 -1
  162. package/dist/api-client/help-center/converter-to-models.js +0 -98
  163. package/dist/api-client/help-center/converter-to-models.js.map +0 -1
  164. package/dist/api-client/help-center/index.d.ts +0 -2
  165. package/dist/api-client/help-center/index.d.ts.map +0 -1
  166. package/dist/api-client/help-center/index.js +0 -2
  167. package/dist/api-client/help-center/index.js.map +0 -1
  168. package/dist/api-client/help-center/native-client.d.ts +0 -1268
  169. package/dist/api-client/help-center/native-client.d.ts.map +0 -1
  170. package/dist/api-client/help-center/native-client.js +0 -6242
  171. package/dist/api-client/help-center/native-client.js.map +0 -1
  172. package/src/api-client/help-center/__tests__/converter-from-models.test.ts +0 -41
  173. package/src/api-client/help-center/__tests__/converter-to-models.test.ts +0 -89
  174. package/src/api-client/help-center/chatbot-api-client.ts +0 -122
  175. package/src/api-client/help-center/converter-from-models.ts +0 -133
  176. package/src/api-client/help-center/converter-to-models.ts +0 -127
  177. package/src/api-client/help-center/index.ts +0 -1
  178. package/src/api-client/help-center/native-client.ts +0 -5727
@@ -1,52 +1,68 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
1
+ function _define_property(obj, key, value) {
2
+ if (key in obj) {
3
+ Object.defineProperty(obj, key, {
4
+ value: value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ } else {
10
+ obj[key] = value;
11
+ }
12
+ return obj;
13
+ }
14
+ function _ts_decorate(decorators, target, key, desc) {
2
15
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
16
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
17
+ else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
18
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
19
+ }
20
+ function _ts_metadata(k, v) {
8
21
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
- var __param = (this && this.__param) || function (paramIndex, decorator) {
11
- return function (target, key) { decorator(target, key, paramIndex); }
12
- };
22
+ }
23
+ function _ts_param(paramIndex, decorator) {
24
+ return function(target, key) {
25
+ decorator(target, key, paramIndex);
26
+ };
27
+ }
13
28
  import { inject, injectable } from '@servicetitan/react-ioc';
14
- import { CHATBOT_CLIENT_SETTINGS, } from '../base/chatbot-api-client';
29
+ import { runAgentStream } from '../../streaming';
30
+ import { CHATBOT_CLIENT_SETTINGS } from '../base/chatbot-api-client';
15
31
  // eslint-disable-next-line no-restricted-imports
16
32
  import { Client } from './native-client';
17
- /**
18
- * Client adapter adopts the generated titan chatbot client to the generic IChatbotApiClient interface.
19
- * Contains client-specific methods for interacting with the titan chatbot API.
20
- */
21
- let ChatbotApiClient = class ChatbotApiClient {
33
+ /** Streaming endpoint template, mirroring the generated client's `/api/v{version}/message`. */ const AGENT_STREAM_PATH_TEMPLATE = '/api/v{version}/message/stream';
34
+ export class ChatbotApiClient {
22
35
  get version() {
23
36
  return this.chatbotApiClientSettings.version;
24
37
  }
25
38
  get clientId() {
26
39
  return this.chatbotApiClientSettings.clientId;
27
40
  }
28
- constructor(chatbotApiClientSettings) {
29
- Object.defineProperty(this, "chatbotApiClientSettings", {
30
- enumerable: true,
31
- configurable: true,
32
- writable: true,
33
- value: chatbotApiClientSettings
34
- });
35
- Object.defineProperty(this, "client", {
36
- enumerable: true,
37
- configurable: true,
38
- writable: true,
39
- value: void 0
40
- });
41
- const { baseUrl, httpClient } = this.chatbotApiClientSettings.constructorParametersFactory();
42
- this.client = new Client(baseUrl, httpClient);
43
- }
44
41
  postFeedback(body, abortSignal) {
45
42
  return this.client.feedback(this.version, this.clientId, body, abortSignal);
46
43
  }
47
44
  postMessage(body, abortSignal) {
48
45
  return this.client.message(this.version, this.clientId, body, abortSignal);
49
46
  }
47
+ streamMessage(body, handlers, abortSignal) {
48
+ var _ref;
49
+ var _this_chatbotApiClientSettings_streamHeadersFactory, _this_chatbotApiClientSettings;
50
+ /*
51
+ * Build the URL exactly as the generated Client does for `/api/v{version}/message`:
52
+ * substitute {version}, then strip a dangling query separator.
53
+ */ const url = (this.baseUrl + AGENT_STREAM_PATH_TEMPLATE).replace('{version}', encodeURIComponent('' + this.version)).replace(/[?&]$/, '');
54
+ return runAgentStream({
55
+ url,
56
+ fetch: this.httpFetch,
57
+ headers: {
58
+ 'X-Client-ID': this.clientId,
59
+ ...(_ref = (_this_chatbotApiClientSettings_streamHeadersFactory = (_this_chatbotApiClientSettings = this.chatbotApiClientSettings).streamHeadersFactory) === null || _this_chatbotApiClientSettings_streamHeadersFactory === void 0 ? void 0 : _this_chatbotApiClientSettings_streamHeadersFactory.call(_this_chatbotApiClientSettings)) !== null && _ref !== void 0 ? _ref : {}
60
+ },
61
+ body,
62
+ handlers,
63
+ abortSignal
64
+ });
65
+ }
50
66
  postFollowUpEmail(body, abortSignal) {
51
67
  return this.client.followUpEmail(this.version, this.clientId, body, abortSignal);
52
68
  }
@@ -65,11 +81,29 @@ let ChatbotApiClient = class ChatbotApiClient {
65
81
  getTranscripts(start, end, signal) {
66
82
  return this.client.transcripts(start, end, this.version, this.clientId, signal);
67
83
  }
68
- };
69
- ChatbotApiClient = __decorate([
84
+ constructor(chatbotApiClientSettings){
85
+ _define_property(this, "chatbotApiClientSettings", void 0);
86
+ _define_property(this, "client", void 0);
87
+ /** Same base URL the generated `Client` uses, so streaming URLs are built identically. */ _define_property(this, "baseUrl", void 0);
88
+ /** Same `fetch` the generated `Client` uses, so the SSE request gets identical auth/headers. */ _define_property(this, "httpFetch", void 0);
89
+ this.chatbotApiClientSettings = chatbotApiClientSettings;
90
+ const { baseUrl, httpClient } = this.chatbotApiClientSettings.constructorParametersFactory();
91
+ this.client = new Client(baseUrl, httpClient);
92
+ // Mirror the generated client's `this.baseUrl = baseUrl ?? ""`.
93
+ this.baseUrl = baseUrl !== null && baseUrl !== void 0 ? baseUrl : '';
94
+ /*
95
+ * Reuse the same fetch the generated client uses, so the SSE request goes through the
96
+ * consumer's request configuration (auth token, X-HC-Instance, credentials, …).
97
+ */ this.httpFetch = httpClient === null || httpClient === void 0 ? void 0 : httpClient.fetch;
98
+ }
99
+ }
100
+ ChatbotApiClient = _ts_decorate([
70
101
  injectable(),
71
- __param(0, inject(CHATBOT_CLIENT_SETTINGS)),
72
- __metadata("design:paramtypes", [Object])
102
+ _ts_param(0, inject(CHATBOT_CLIENT_SETTINGS)),
103
+ _ts_metadata("design:type", Function),
104
+ _ts_metadata("design:paramtypes", [
105
+ typeof IChatbotClientSettingsTitanChat === "undefined" ? Object : IChatbotClientSettingsTitanChat
106
+ ])
73
107
  ], ChatbotApiClient);
74
- export { ChatbotApiClient };
108
+
75
109
  //# sourceMappingURL=chatbot-api-client.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"chatbot-api-client.js","sourceRoot":"","sources":["../../../src/api-client/titan-chat/chatbot-api-client.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE7D,OAAO,EACH,uBAAuB,GAK1B,MAAM,4BAA4B,CAAC;AACpC,iDAAiD;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAezC;;;GAGG;AAEI,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAGzB,IAAI,OAAO;QACP,OAAO,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAAC;IACjD,CAAC;IAED,IAAI,QAAQ;QACR,OAAO,IAAI,CAAC,wBAAwB,CAAC,QAAQ,CAAC;IAClD,CAAC;IAED,YAEI,wBAA0E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I,CAAC,QAAQ,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;IACpF,CAAC;IAED,aAAa,CAAC,IAAoB,EAAE,WAAyB;QACzD,OAAO,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;IACrF,CAAC;IAED,cAAc,CAAC,KAAY,EAAE,GAAU,EAAE,MAAoB;QACzD,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACpF,CAAC;CACJ,CAAA;AAnDY,gBAAgB;IAD5B,UAAU,EAAE;IAaJ,WAAA,MAAM,CAAC,uBAAuB,CAAC,CAAA;;GAZ3B,gBAAgB,CAmD5B"}
1
+ {"version":3,"sources":["../../../src/api-client/titan-chat/chatbot-api-client.ts"],"sourcesContent":["import { inject, injectable } from '@servicetitan/react-ioc';\nimport { Models } from '..';\nimport { AgentStreamHandlers, runAgentStream } from '../../streaming';\nimport {\n CHATBOT_CLIENT_SETTINGS,\n FirstParameterType,\n IChatbotApiClient,\n IChatbotClientSettings,\n SecondParameterType,\n} from '../base/chatbot-api-client';\n// eslint-disable-next-line no-restricted-imports\nimport { Client } from './native-client';\n\n/** Streaming endpoint template, mirroring the generated client's `/api/v{version}/message`. */\nconst AGENT_STREAM_PATH_TEMPLATE = '/api/v{version}/message/stream';\n\n/**\n * Settings for the chatbot client, which includes a factory for constructor parameters, and additional settings\n * like version and clientId which are used in the API calls.\n */\nexport interface IChatbotClientSettingsTitanChat extends IChatbotClientSettings {\n constructorParametersFactory: () => {\n baseUrl?: FirstParameterType<typeof Client>;\n httpClient?: SecondParameterType<typeof Client>;\n };\n version: string;\n clientId: string;\n /**\n * Extra headers for the SSE streaming request. `X-Client-ID` is always sent (from `clientId`);\n * use this for anything the fetch http client would otherwise add (e.g. Authorization). Optional.\n */\n streamHeadersFactory?: () => Record<string, string>;\n}\n\n/**\n * Client adapter adopts the generated titan chatbot client to the generic IChatbotApiClient interface.\n * Contains client-specific methods for interacting with the titan chatbot API.\n */\n@injectable()\nexport class ChatbotApiClient implements IChatbotApiClient {\n private readonly client: Client;\n /** Same base URL the generated `Client` uses, so streaming URLs are built identically. */\n private readonly baseUrl: string;\n /** Same `fetch` the generated `Client` uses, so the SSE request gets identical auth/headers. */\n private readonly httpFetch?: typeof fetch;\n\n get version(): string {\n return this.chatbotApiClientSettings.version;\n }\n\n get clientId(): string {\n return this.chatbotApiClientSettings.clientId;\n }\n\n constructor(\n @inject(CHATBOT_CLIENT_SETTINGS)\n private readonly chatbotApiClientSettings: IChatbotClientSettingsTitanChat\n ) {\n const { baseUrl, httpClient } =\n this.chatbotApiClientSettings.constructorParametersFactory();\n this.client = new Client(baseUrl, httpClient);\n // Mirror the generated client's `this.baseUrl = baseUrl ?? \"\"`.\n this.baseUrl = baseUrl ?? '';\n /*\n * Reuse the same fetch the generated client uses, so the SSE request goes through the\n * consumer's request configuration (auth token, X-HC-Instance, credentials, …).\n */\n this.httpFetch = httpClient?.fetch as typeof fetch | undefined;\n }\n\n postFeedback(body: Models.Feedback, abortSignal?: AbortSignal) {\n return this.client.feedback(this.version, this.clientId, body, abortSignal);\n }\n\n postMessage(body: Models.UserMessage, abortSignal?: AbortSignal) {\n return this.client.message(this.version, this.clientId, body, abortSignal);\n }\n\n streamMessage(\n body: Models.IUserMessage,\n handlers: AgentStreamHandlers,\n abortSignal?: AbortSignal\n ): Promise<Models.BotMessage> {\n /*\n * Build the URL exactly as the generated Client does for `/api/v{version}/message`:\n * substitute {version}, then strip a dangling query separator.\n */\n const url = (this.baseUrl + AGENT_STREAM_PATH_TEMPLATE)\n .replace('{version}', encodeURIComponent('' + this.version))\n .replace(/[?&]$/, '');\n\n return runAgentStream({\n url,\n fetch: this.httpFetch,\n headers: {\n 'X-Client-ID': this.clientId,\n ...(this.chatbotApiClientSettings.streamHeadersFactory?.() ?? {}),\n },\n body,\n handlers,\n abortSignal,\n });\n }\n\n postFollowUpEmail(body: Models.UserMessage, abortSignal?: AbortSignal) {\n return this.client.followUpEmail(this.version, this.clientId, body, abortSignal);\n }\n\n getOptions(abortSignal?: AbortSignal): Promise<Models.FrontendModel> {\n return this.client.options(this.version, this.clientId, abortSignal);\n }\n\n async postSession(body: Models.Session, abortSignal?: AbortSignal) {\n return this.client.sessionPOST(this.version, this.clientId, body, abortSignal);\n }\n\n patchSession(body: Models.Session, abortSignal?: AbortSignal) {\n return this.client.sessionPATCH(this.version, this.clientId, body, abortSignal);\n }\n\n deleteSession(body: Models.Session, abortSignal?: AbortSignal) {\n return this.client.sessionDELETE(this.version, this.clientId, body, abortSignal);\n }\n\n getTranscripts(start?: Date, end?: Date, signal?: AbortSignal) {\n return this.client.transcripts(start, end, this.version, this.clientId, signal);\n }\n}\n"],"names":["inject","injectable","runAgentStream","CHATBOT_CLIENT_SETTINGS","Client","AGENT_STREAM_PATH_TEMPLATE","ChatbotApiClient","version","chatbotApiClientSettings","clientId","postFeedback","body","abortSignal","client","feedback","postMessage","message","streamMessage","handlers","url","baseUrl","replace","encodeURIComponent","fetch","httpFetch","headers","streamHeadersFactory","postFollowUpEmail","followUpEmail","getOptions","options","postSession","sessionPOST","patchSession","sessionPATCH","deleteSession","sessionDELETE","getTranscripts","start","end","signal","transcripts","httpClient","constructorParametersFactory"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,MAAM,EAAEC,UAAU,QAAQ,0BAA0B;AAE7D,SAA8BC,cAAc,QAAQ,kBAAkB;AACtE,SACIC,uBAAuB,QAKpB,6BAA6B;AACpC,iDAAiD;AACjD,SAASC,MAAM,QAAQ,kBAAkB;AAEzC,6FAA6F,GAC7F,MAAMC,6BAA6B;AAyBnC,OAAO,MAAMC;IAOT,IAAIC,UAAkB;QAClB,OAAO,IAAI,CAACC,wBAAwB,CAACD,OAAO;I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AAO,IAAI,CAACC,MAAM,CAACmB,WAAW,CAAC,IAAI,CAACzB,OAAO,EAAE,IAAI,CAACE,QAAQ,EAAEE,MAAMC;IACtE;IAEAqB,aAAatB,IAAoB,EAAEC,WAAyB,EAAE;QAC1D,OAAO,IAAI,CAACC,MAAM,CAACqB,YAAY,CAAC,IAAI,CAAC3B,OAAO,EAAE,IAAI,CAACE,QAAQ,EAAEE,MAAMC;IACvE;IAEAuB,cAAcxB,IAAoB,EAAEC,WAAyB,EAAE;QAC3D,OAAO,IAAI,CAACC,MAAM,CAACuB,aAAa,CAAC,IAAI,CAAC7B,OAAO,EAAE,IAAI,CAACE,QAAQ,EAAEE,MAAMC;IACxE;IAEAyB,eAAeC,KAAY,EAAEC,GAAU,EAAEC,MAAoB,EAAE;QAC3D,OAAO,IAAI,CAAC3B,MAAM,CAAC4B,WAAW,CAACH,OAAOC,KAAK,IAAI,CAAChC,OAAO,EAAE,IAAI,CAACE,QAAQ,EAAE+B;IAC5E;IAxEA,YACI,AACiBhC,wBAAyD,CAC5E;;QAjBF,uBAAiBK,UAAjB,KAAA;QACA,wFAAwF,GACxF,uBAAiBO,WAAjB,KAAA;QACA,8FAA8F,GAC9F,uBAAiBI,aAAjB,KAAA;aAYqBhB,2BAAAA;QAEjB,MAAM,EAAEY,OAAO,EAAEsB,UAAU,EAAE,GACzB,IAAI,CAAClC,wBAAwB,CAACmC,4BAA4B;QAC9D,IAAI,CAAC9B,MAAM,GAAG,IAAIT,OAAOgB,SAASsB;QAClC,gEAAgE;QAChE,IAAI,CAACtB,OAAO,GAAGA,oBAAAA,qBAAAA,UAAW;QAC1B;;;SAGC,GACD,IAAI,CAACI,SAAS,GAAGkB,uBAAAA,iCAAAA,WAAYnB,KAAK;IACtC;AA2DJ"}
@@ -1,2 +1,3 @@
1
- export { ChatbotApiClient, IChatbotClientSettingsTitanChat } from './chatbot-api-client';
1
+ export type { IChatbotClientSettingsTitanChat } from './chatbot-api-client';
2
+ export { ChatbotApiClient } from './chatbot-api-client';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api-client/titan-chat/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,+BAA+B,EAAE,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api-client/titan-chat/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,+BAA+B,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC"}
@@ -1,2 +1,3 @@
1
1
  export { ChatbotApiClient } from './chatbot-api-client';
2
+
2
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api-client/titan-chat/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAmC,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"sources":["../../../src/api-client/titan-chat/index.ts"],"sourcesContent":["export type { IChatbotClientSettingsTitanChat } from './chatbot-api-client';\nexport { ChatbotApiClient } from './chatbot-api-client';\n"],"names":["ChatbotApiClient"],"mappings":"AACA,SAASA,gBAAgB,QAAQ,uBAAuB"}