@aui.io/aui-client 3.1.2 → 3.2.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 (197) hide show
  1. package/README.md +196 -69
  2. package/dist/cjs/ApolloClientWrapper.d.ts +52 -24
  3. package/dist/cjs/ApolloClientWrapper.js +86 -58
  4. package/dist/cjs/BaseClient.d.ts +5 -0
  5. package/dist/cjs/Client.d.ts +4 -1
  6. package/dist/cjs/Client.js +24 -9
  7. package/dist/cjs/api/resources/agentVersions/client/Client.d.ts +26 -2
  8. package/dist/cjs/api/resources/agentVersions/client/Client.js +96 -43
  9. package/dist/cjs/api/resources/agentVersions/client/requests/AgentVersionPushRequest.d.ts +1 -1
  10. package/dist/cjs/api/resources/agents/client/Client.d.ts +22 -7
  11. package/dist/cjs/api/resources/agents/client/Client.js +80 -39
  12. package/dist/cjs/api/resources/agents/client/requests/{ExternalAgentCreateRequest.d.ts → AgentCreateRequest.d.ts} +1 -1
  13. package/dist/{esm/api/resources/agents/client/requests/ExternalAgentUpdateRequest.d.mts → cjs/api/resources/agents/client/requests/AgentUpdateRequest.d.ts} +1 -1
  14. package/dist/cjs/api/resources/agents/client/requests/ListAgentsRequest.d.ts +1 -1
  15. package/dist/cjs/api/resources/agents/client/requests/index.d.ts +2 -2
  16. package/dist/cjs/api/resources/auth/client/Client.d.ts +3 -2
  17. package/dist/cjs/api/resources/auth/client/Client.js +20 -8
  18. package/dist/cjs/api/resources/channels/client/Client.d.ts +7 -6
  19. package/dist/cjs/api/resources/channels/client/Client.js +24 -12
  20. package/dist/cjs/api/resources/channels/client/requests/InitiateThreadRequest.d.ts +3 -10
  21. package/dist/cjs/api/resources/messaging/client/Client.d.ts +51 -14
  22. package/dist/cjs/api/resources/messaging/client/Client.js +249 -50
  23. package/dist/cjs/api/resources/messaging/client/requests/GenerateFollowupSuggestionsRequest.d.ts +9 -0
  24. package/dist/cjs/api/resources/messaging/client/requests/RerunMessageRequest.d.ts +2 -2
  25. package/dist/cjs/api/resources/messaging/client/requests/StreamMessageRequest.d.ts +0 -1
  26. package/dist/cjs/api/resources/messaging/client/requests/index.d.ts +1 -0
  27. package/dist/cjs/api/resources/projects/client/Client.d.ts +14 -2
  28. package/dist/cjs/api/resources/projects/client/Client.js +66 -31
  29. package/dist/cjs/api/resources/session/client/Client.d.ts +2 -1
  30. package/dist/cjs/api/resources/session/client/Client.js +12 -2
  31. package/dist/cjs/api/resources/threads/client/Client.d.ts +37 -2
  32. package/dist/cjs/api/resources/threads/client/Client.js +155 -31
  33. package/dist/cjs/api/resources/threads/client/requests/UpdateThreadRequest.d.ts +8 -0
  34. package/dist/cjs/api/resources/threads/client/requests/index.d.ts +1 -0
  35. package/dist/cjs/api/types/{ExternalAgent.d.ts → Agent.d.ts} +1 -1
  36. package/dist/cjs/api/types/{ExternalAgentCreateResponse.d.ts → AgentCreateResponse.d.ts} +1 -1
  37. package/dist/cjs/api/types/{ExternalAgentListFilters.d.ts → AgentListFilters.d.ts} +1 -1
  38. package/dist/{esm/api/types/ExternalAgentUpdateResponse.d.mts → cjs/api/types/AgentUpdateResponse.d.ts} +1 -1
  39. package/dist/cjs/api/types/AgentVariables.d.ts +12 -0
  40. package/dist/cjs/api/types/AgentVersionPullResponse.d.ts +2 -3
  41. package/dist/cjs/api/types/AgentVersionPushResponse.d.ts +1 -1
  42. package/dist/cjs/api/types/AgentVersionWelcomeMessageResponse.d.ts +6 -0
  43. package/dist/cjs/api/types/GenerateFollowupSuggestionsResponse.d.ts +4 -0
  44. package/dist/cjs/api/types/PageAgent.d.ts +6 -0
  45. package/dist/cjs/api/types/PageAgentVersion.d.ts +6 -0
  46. package/dist/cjs/api/types/PageAgentVersion.js +3 -0
  47. package/dist/cjs/api/types/{ExternalPageLinks.d.ts → PageLinks.d.ts} +1 -1
  48. package/dist/cjs/api/types/PageLinks.js +3 -0
  49. package/dist/cjs/api/types/{ExternalPageMeta.d.ts → PageMeta.d.ts} +1 -1
  50. package/dist/cjs/api/types/PageMeta.js +3 -0
  51. package/dist/cjs/api/types/PageProject.d.ts +6 -0
  52. package/dist/cjs/api/types/PageProject.js +3 -0
  53. package/dist/cjs/api/types/PageThreadListItem.d.ts +6 -0
  54. package/dist/cjs/api/types/PageThreadListItem.js +3 -0
  55. package/dist/cjs/api/types/Project.d.ts +1 -1
  56. package/dist/cjs/api/types/SendMessageRequest.d.ts +7 -5
  57. package/dist/cjs/api/types/ThreadListFilters.d.ts +2 -5
  58. package/dist/cjs/api/types/TokenResponse.d.ts +4 -8
  59. package/dist/cjs/api/types/TraceDecision.d.ts +1 -2
  60. package/dist/cjs/api/types/VersionStats.d.ts +1 -2
  61. package/dist/cjs/api/types/index.d.ts +13 -10
  62. package/dist/cjs/api/types/index.js +13 -10
  63. package/dist/cjs/core/auth/AuthProvider.d.ts +4 -0
  64. package/dist/cjs/core/auth/AuthProvider.js +2 -0
  65. package/dist/cjs/core/auth/AuthRequest.d.ts +9 -0
  66. package/dist/cjs/core/auth/AuthRequest.js +2 -0
  67. package/dist/cjs/core/auth/BasicAuth.d.ts +8 -0
  68. package/dist/cjs/core/auth/BasicAuth.js +27 -0
  69. package/dist/cjs/core/auth/BearerToken.d.ts +5 -0
  70. package/dist/cjs/core/auth/BearerToken.js +15 -0
  71. package/dist/cjs/core/auth/index.d.ts +4 -0
  72. package/dist/cjs/core/auth/index.js +7 -0
  73. package/dist/cjs/core/base64.d.ts +2 -0
  74. package/dist/cjs/core/base64.js +26 -0
  75. package/dist/cjs/core/index.d.ts +2 -0
  76. package/dist/cjs/core/index.js +2 -0
  77. package/dist/cjs/environments.d.ts +2 -2
  78. package/dist/cjs/environments.js +2 -2
  79. package/dist/cjs/index.d.ts +1 -1
  80. package/dist/cjs/index.js +3 -2
  81. package/dist/cjs/version.d.ts +1 -1
  82. package/dist/cjs/version.js +1 -1
  83. package/dist/esm/ApolloClientWrapper.d.mts +52 -24
  84. package/dist/esm/ApolloClientWrapper.mjs +83 -56
  85. package/dist/esm/BaseClient.d.mts +5 -0
  86. package/dist/esm/Client.d.mts +4 -1
  87. package/dist/esm/Client.mjs +25 -10
  88. package/dist/esm/api/resources/agentVersions/client/Client.d.mts +26 -2
  89. package/dist/esm/api/resources/agentVersions/client/Client.mjs +97 -44
  90. package/dist/esm/api/resources/agentVersions/client/requests/AgentVersionPushRequest.d.mts +1 -1
  91. package/dist/esm/api/resources/agents/client/Client.d.mts +22 -7
  92. package/dist/esm/api/resources/agents/client/Client.mjs +81 -40
  93. package/dist/esm/api/resources/agents/client/requests/{ExternalAgentCreateRequest.d.mts → AgentCreateRequest.d.mts} +1 -1
  94. package/dist/{cjs/api/resources/agents/client/requests/ExternalAgentUpdateRequest.d.ts → esm/api/resources/agents/client/requests/AgentUpdateRequest.d.mts} +1 -1
  95. package/dist/esm/api/resources/agents/client/requests/ListAgentsRequest.d.mts +1 -1
  96. package/dist/esm/api/resources/agents/client/requests/index.d.mts +2 -2
  97. package/dist/esm/api/resources/auth/client/Client.d.mts +3 -2
  98. package/dist/esm/api/resources/auth/client/Client.mjs +21 -9
  99. package/dist/esm/api/resources/channels/client/Client.d.mts +7 -6
  100. package/dist/esm/api/resources/channels/client/Client.mjs +25 -13
  101. package/dist/esm/api/resources/channels/client/requests/InitiateThreadRequest.d.mts +3 -10
  102. package/dist/esm/api/resources/messaging/client/Client.d.mts +51 -14
  103. package/dist/esm/api/resources/messaging/client/Client.mjs +249 -50
  104. package/dist/esm/api/resources/messaging/client/requests/GenerateFollowupSuggestionsRequest.d.mts +9 -0
  105. package/dist/esm/api/resources/messaging/client/requests/RerunMessageRequest.d.mts +2 -2
  106. package/dist/esm/api/resources/messaging/client/requests/StreamMessageRequest.d.mts +0 -1
  107. package/dist/esm/api/resources/messaging/client/requests/index.d.mts +1 -0
  108. package/dist/esm/api/resources/projects/client/Client.d.mts +14 -2
  109. package/dist/esm/api/resources/projects/client/Client.mjs +67 -32
  110. package/dist/esm/api/resources/session/client/Client.d.mts +2 -1
  111. package/dist/esm/api/resources/session/client/Client.mjs +12 -2
  112. package/dist/esm/api/resources/threads/client/Client.d.mts +37 -2
  113. package/dist/esm/api/resources/threads/client/Client.mjs +156 -32
  114. package/dist/esm/api/resources/threads/client/requests/UpdateThreadRequest.d.mts +8 -0
  115. package/dist/esm/api/resources/threads/client/requests/index.d.mts +1 -0
  116. package/dist/esm/api/types/{ExternalAgent.d.mts → Agent.d.mts} +1 -1
  117. package/dist/esm/api/types/{ExternalAgentCreateResponse.d.mts → AgentCreateResponse.d.mts} +1 -1
  118. package/dist/esm/api/types/{ExternalAgentListFilters.d.mts → AgentListFilters.d.mts} +1 -1
  119. package/dist/{cjs/api/types/ExternalAgentUpdateResponse.d.ts → esm/api/types/AgentUpdateResponse.d.mts} +1 -1
  120. package/dist/esm/api/types/AgentVariables.d.mts +12 -0
  121. package/dist/esm/api/types/AgentVersionPullResponse.d.mts +2 -3
  122. package/dist/esm/api/types/AgentVersionPushResponse.d.mts +1 -1
  123. package/dist/esm/api/types/AgentVersionWelcomeMessageResponse.d.mts +6 -0
  124. package/dist/esm/api/types/GenerateFollowupSuggestionsResponse.d.mts +4 -0
  125. package/dist/esm/api/types/PageAgent.d.mts +6 -0
  126. package/dist/esm/api/types/PageAgentVersion.d.mts +6 -0
  127. package/dist/esm/api/types/PageAgentVersion.mjs +2 -0
  128. package/dist/esm/api/types/{ExternalPageLinks.d.mts → PageLinks.d.mts} +1 -1
  129. package/dist/esm/api/types/PageLinks.mjs +2 -0
  130. package/dist/esm/api/types/{ExternalPageMeta.d.mts → PageMeta.d.mts} +1 -1
  131. package/dist/esm/api/types/PageMeta.mjs +2 -0
  132. package/dist/esm/api/types/PageProject.d.mts +6 -0
  133. package/dist/esm/api/types/PageProject.mjs +2 -0
  134. package/dist/esm/api/types/PageThreadListItem.d.mts +6 -0
  135. package/dist/esm/api/types/PageThreadListItem.mjs +2 -0
  136. package/dist/esm/api/types/Project.d.mts +1 -1
  137. package/dist/esm/api/types/SendMessageRequest.d.mts +7 -5
  138. package/dist/esm/api/types/ThreadListFilters.d.mts +2 -5
  139. package/dist/esm/api/types/TokenResponse.d.mts +4 -8
  140. package/dist/esm/api/types/TraceDecision.d.mts +1 -2
  141. package/dist/esm/api/types/VersionStats.d.mts +1 -2
  142. package/dist/esm/api/types/index.d.mts +13 -10
  143. package/dist/esm/api/types/index.mjs +13 -10
  144. package/dist/esm/core/auth/AuthProvider.d.mts +4 -0
  145. package/dist/esm/core/auth/AuthProvider.mjs +1 -0
  146. package/dist/esm/core/auth/AuthRequest.d.mts +9 -0
  147. package/dist/esm/core/auth/AuthRequest.mjs +1 -0
  148. package/dist/esm/core/auth/BasicAuth.d.mts +8 -0
  149. package/dist/esm/core/auth/BasicAuth.mjs +24 -0
  150. package/dist/esm/core/auth/BearerToken.d.mts +5 -0
  151. package/dist/esm/core/auth/BearerToken.mjs +12 -0
  152. package/dist/esm/core/auth/index.d.mts +4 -0
  153. package/dist/esm/core/auth/index.mjs +2 -0
  154. package/dist/esm/core/base64.d.mts +2 -0
  155. package/dist/esm/core/base64.mjs +22 -0
  156. package/dist/esm/core/index.d.mts +2 -0
  157. package/dist/esm/core/index.mjs +2 -0
  158. package/dist/esm/environments.d.mts +2 -2
  159. package/dist/esm/environments.mjs +2 -2
  160. package/dist/esm/index.d.mts +1 -1
  161. package/dist/esm/index.mjs +1 -1
  162. package/dist/esm/version.d.mts +1 -1
  163. package/dist/esm/version.mjs +1 -1
  164. package/package.json +1 -1
  165. package/reference.md +568 -29
  166. package/dist/cjs/api/types/ExternalPageAgentVersion.d.ts +0 -6
  167. package/dist/cjs/api/types/ExternalPageExternalAgent.d.ts +0 -6
  168. package/dist/cjs/api/types/ExternalPageProject.d.ts +0 -6
  169. package/dist/cjs/api/types/ExternalPageThreadListItem.d.ts +0 -6
  170. package/dist/esm/api/types/ExternalPageAgentVersion.d.mts +0 -6
  171. package/dist/esm/api/types/ExternalPageExternalAgent.d.mts +0 -6
  172. package/dist/esm/api/types/ExternalPageProject.d.mts +0 -6
  173. package/dist/esm/api/types/ExternalPageThreadListItem.d.mts +0 -6
  174. /package/dist/cjs/api/resources/agents/client/requests/{ExternalAgentCreateRequest.js → AgentCreateRequest.js} +0 -0
  175. /package/dist/cjs/api/resources/agents/client/requests/{ExternalAgentUpdateRequest.js → AgentUpdateRequest.js} +0 -0
  176. /package/dist/cjs/api/{types/ExternalAgent.js → resources/messaging/client/requests/GenerateFollowupSuggestionsRequest.js} +0 -0
  177. /package/dist/cjs/api/{types/ExternalAgentCreateResponse.js → resources/threads/client/requests/UpdateThreadRequest.js} +0 -0
  178. /package/dist/cjs/api/types/{ExternalAgentListFilters.js → Agent.js} +0 -0
  179. /package/dist/cjs/api/types/{ExternalAgentUpdateResponse.js → AgentCreateResponse.js} +0 -0
  180. /package/dist/cjs/api/types/{ExternalPageAgentVersion.js → AgentListFilters.js} +0 -0
  181. /package/dist/cjs/api/types/{ExternalPageExternalAgent.js → AgentUpdateResponse.js} +0 -0
  182. /package/dist/cjs/api/types/{ExternalPageLinks.js → AgentVariables.js} +0 -0
  183. /package/dist/cjs/api/types/{ExternalPageMeta.js → AgentVersionWelcomeMessageResponse.js} +0 -0
  184. /package/dist/cjs/api/types/{ExternalPageProject.js → GenerateFollowupSuggestionsResponse.js} +0 -0
  185. /package/dist/cjs/api/types/{ExternalPageThreadListItem.js → PageAgent.js} +0 -0
  186. /package/dist/esm/api/resources/agents/client/requests/{ExternalAgentCreateRequest.mjs → AgentCreateRequest.mjs} +0 -0
  187. /package/dist/esm/api/resources/agents/client/requests/{ExternalAgentUpdateRequest.mjs → AgentUpdateRequest.mjs} +0 -0
  188. /package/dist/esm/api/{types/ExternalAgent.mjs → resources/messaging/client/requests/GenerateFollowupSuggestionsRequest.mjs} +0 -0
  189. /package/dist/esm/api/{types/ExternalAgentCreateResponse.mjs → resources/threads/client/requests/UpdateThreadRequest.mjs} +0 -0
  190. /package/dist/esm/api/types/{ExternalAgentListFilters.mjs → Agent.mjs} +0 -0
  191. /package/dist/esm/api/types/{ExternalAgentUpdateResponse.mjs → AgentCreateResponse.mjs} +0 -0
  192. /package/dist/esm/api/types/{ExternalPageAgentVersion.mjs → AgentListFilters.mjs} +0 -0
  193. /package/dist/esm/api/types/{ExternalPageExternalAgent.mjs → AgentUpdateResponse.mjs} +0 -0
  194. /package/dist/esm/api/types/{ExternalPageLinks.mjs → AgentVariables.mjs} +0 -0
  195. /package/dist/esm/api/types/{ExternalPageMeta.mjs → AgentVersionWelcomeMessageResponse.mjs} +0 -0
  196. /package/dist/esm/api/types/{ExternalPageProject.mjs → GenerateFollowupSuggestionsResponse.mjs} +0 -0
  197. /package/dist/esm/api/types/{ExternalPageThreadListItem.mjs → PageAgent.mjs} +0 -0
@@ -42,25 +42,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
42
42
  });
43
43
  };
44
44
  Object.defineProperty(exports, "__esModule", { value: true });
45
- exports.ApolloClient = void 0;
45
+ exports.ApolloManagementClient = exports.ApolloMessagingClient = void 0;
46
46
  const ws_1 = require("ws");
47
47
  const Client_js_1 = require("./Client.js");
48
48
  const environments_js_1 = require("./environments.js");
49
49
  const core = __importStar(require("./core/index.js"));
50
50
  const Socket_js_1 = require("./api/resources/session/client/Socket.js");
51
- // A publishable key is exchanged (POST /management/v1/auth/token) for a short-lived
52
- // bearer token; every request then sends Authorization: Bearer <token>.
53
51
  const TOKEN_EXCHANGE_PATH = "/management/v1/auth/token";
54
- // Re-exchange this many ms before the token expires.
55
52
  const REFRESH_SKEW_MS = 60000;
56
- // Messaging WebSocket channel path (relative to the environment's WS base).
57
53
  const SESSION_WS_PATH = "/messaging/v1/session";
58
- // The v2 messaging server negotiates this subprotocol on the WS upgrade; the
59
- // connection is rejected without it. Fern emits protocols: [], so we set it here.
60
54
  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).
55
+ const ORG_API_KEY_HEADER = "x-organization-api-key";
56
+ // Strip Fern's telemetry headers (null deletes them); they trip browser CORS preflight.
64
57
  const STRIPPED_SDK_HEADERS = {
65
58
  "X-Fern-Language": null,
66
59
  "X-Fern-SDK-Name": null,
@@ -68,18 +61,13 @@ const STRIPPED_SDK_HEADERS = {
68
61
  "X-Fern-Runtime": null,
69
62
  "X-Fern-Runtime-Version": null,
70
63
  };
71
- // Publishable-key exchange + token caching. Kept as a standalone object so the header
72
- // suppliers can close over it — a subclass may not touch `this` before super() runs.
73
- class Auth {
74
- constructor(baseUrl, publishableKey, organizationApiKey) {
64
+ // Publishable-key exchange + token cache.
65
+ class PkAuth {
66
+ constructor(baseUrl, publishableKey) {
75
67
  this.pk = publishableKey;
76
68
  this.keyType = detectKeyType(publishableKey);
77
- this._staticToken = organizationApiKey;
78
69
  this._baseUrl = baseUrl;
79
70
  }
80
- get hasCredential() {
81
- return Boolean(this.pk || this._staticToken);
82
- }
83
71
  get agentId() {
84
72
  var _a;
85
73
  return (_a = this._cache) === null || _a === void 0 ? void 0 : _a.agentId;
@@ -91,18 +79,13 @@ class Auth {
91
79
  getContext() {
92
80
  return __awaiter(this, void 0, void 0, function* () {
93
81
  var _a, _b;
94
- if (this.pk)
95
- yield this.getToken();
82
+ yield this.getToken();
96
83
  return { agentId: (_a = this._cache) === null || _a === void 0 ? void 0 : _a.agentId, organizationId: (_b = this._cache) === null || _b === void 0 ? void 0 : _b.organizationId, keyType: this.keyType };
97
84
  });
98
85
  }
99
86
  getToken() {
100
87
  return __awaiter(this, void 0, void 0, function* () {
101
88
  var _a, _b;
102
- if (this._staticToken)
103
- return this._staticToken;
104
- if (!this.pk)
105
- return "";
106
89
  if (((_a = this._cache) === null || _a === void 0 ? void 0 : _a.token) && Date.now() < this._cache.expiresAt - REFRESH_SKEW_MS) {
107
90
  return this._cache.token;
108
91
  }
@@ -141,66 +124,74 @@ class Auth {
141
124
  });
142
125
  }
143
126
  }
144
- /**
145
- * ApolloClient adds authentication on top of the generated client: it takes a
146
- * publishable key (or organization API key) and handles the token exchange/refresh
147
- * transparently. Every generated resource (agents, threads, messaging, …) is
148
- * inherited unchanged.
149
- */
150
- class ApolloClient extends Client_js_1.ApolloClient {
151
- constructor(options = {}) {
152
- var _a;
153
- const env = (_a = options.environment) !== null && _a !== void 0 ? _a : environments_js_1.ApolloEnvironment.Gcp;
154
- const auth = new Auth(env.base, options.publishableKey, options.organizationApiKey);
155
- super({
127
+ // Shared base: wraps the generated client, strips telemetry headers, defaults the
128
+ // environment, and lets each client expose only its own audience's resources. Not exported.
129
+ class BaseApolloClient {
130
+ constructor(env, authHeaders) {
131
+ // `organizationApiKey` is typed as required by Fern but we authenticate via
132
+ // headers, so cast to the generated options shape.
133
+ this._client = new Client_js_1.ApolloClient({
156
134
  environment: env,
157
- headers: Object.assign(Object.assign({}, STRIPPED_SDK_HEADERS), (auth.hasCredential ? { Authorization: () => __awaiter(this, void 0, void 0, function* () { return `Bearer ${yield auth.getToken()}`; }) } : {})),
135
+ headers: Object.assign(Object.assign({}, STRIPPED_SDK_HEADERS), authHeaders),
158
136
  });
159
- this._tokenAuth = auth;
160
137
  this._env = env;
161
138
  }
139
+ }
140
+ /**
141
+ * Publishable-key client for end-user / widget messaging (browser-safe).
142
+ * Exposes the `messaging` audience only.
143
+ */
144
+ class ApolloMessagingClient extends BaseApolloClient {
145
+ constructor(options) {
146
+ if (!(options === null || options === void 0 ? void 0 : options.publishableKey)) {
147
+ throw new Error("ApolloMessagingClient requires a publishableKey.");
148
+ }
149
+ const env = resolveEnv(options.baseUrl);
150
+ const auth = new PkAuth(env.base, options.publishableKey);
151
+ super(env, { Authorization: () => __awaiter(this, void 0, void 0, function* () { return `Bearer ${yield auth.getToken()}`; }) });
152
+ this._pkAuth = auth;
153
+ }
154
+ /** Send / stream messages and read thread & interaction traces. */
155
+ get messaging() {
156
+ return this._client.messaging;
157
+ }
158
+ /** Initiate channel-scoped threads (e.g. SMS). */
159
+ get channels() {
160
+ return this._client.channels;
161
+ }
162
162
  /** Publishable-key family (agent / org / unknown). */
163
163
  get keyType() {
164
- return this._tokenAuth.keyType;
164
+ return this._pkAuth.keyType;
165
165
  }
166
166
  /** Agent resolved from an agent-scoped key. Populated after the first exchange. */
167
167
  get agentId() {
168
- return this._tokenAuth.agentId;
168
+ return this._pkAuth.agentId;
169
169
  }
170
170
  /** Organization the key belongs to. Populated after the first exchange. */
171
171
  get organizationId() {
172
- return this._tokenAuth.organizationId;
172
+ return this._pkAuth.organizationId;
173
173
  }
174
174
  /** Force a token exchange (if needed) and return the resolved scope. */
175
175
  getContext() {
176
- return this._tokenAuth.getContext();
177
- }
178
- /**
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.
185
- */
176
+ return this._pkAuth.getContext();
177
+ }
178
+ /** Open a messaging WebSocket session. */
186
179
  connect() {
187
180
  return __awaiter(this, arguments, void 0, function* (args = {}) {
188
181
  var _a, _b;
189
- const token = yield this._tokenAuth.getToken();
182
+ const token = yield this._pkAuth.getToken();
190
183
  const headers = Object.assign(Object.assign({}, (token ? { Authorization: `Bearer ${token}` } : {})), args.headers);
191
184
  const socket = new core.ReconnectingWebSocket({
192
185
  url: core.url.join(this._env.production, SESSION_WS_PATH),
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.
186
+ // Token as the first subprotocol is how the gateway reads auth (browsers can't
187
+ // set upgrade headers); `aui-websocket` must follow.
195
188
  protocols: token ? [token, WS_SUBPROTOCOL] : [WS_SUBPROTOCOL],
196
189
  queryParameters: {},
197
190
  headers,
198
191
  options: {
199
192
  debug: (_a = args.debug) !== null && _a !== void 0 ? _a : false,
200
193
  maxRetries: (_b = args.reconnectAttempts) !== null && _b !== void 0 ? _b : 30,
201
- // On Node 22+ the global (undici) WebSocket drops custom headers on the
202
- // upgrade, so the bearer token never arrives. Force the `ws` library on
203
- // Node; browsers fall back to the native global WebSocket.
194
+ // Node's global WebSocket drops upgrade headers; force the `ws` library there.
204
195
  WebSocket: core.RUNTIME.type === "node" ? ws_1.WebSocket : undefined,
205
196
  },
206
197
  });
@@ -208,7 +199,44 @@ class ApolloClient extends Client_js_1.ApolloClient {
208
199
  });
209
200
  }
210
201
  }
211
- exports.ApolloClient = ApolloClient;
202
+ exports.ApolloMessagingClient = ApolloMessagingClient;
203
+ /**
204
+ * Organization-API-key client for backend services and CI (server-side only).
205
+ * Exposes the `management` audience only.
206
+ */
207
+ class ApolloManagementClient extends BaseApolloClient {
208
+ constructor(options) {
209
+ if (!(options === null || options === void 0 ? void 0 : options.organizationApiKey)) {
210
+ throw new Error("ApolloManagementClient requires an organizationApiKey.");
211
+ }
212
+ const env = resolveEnv(options.baseUrl);
213
+ super(env, { [ORG_API_KEY_HEADER]: options.organizationApiKey });
214
+ }
215
+ /** Projects: listing, retrieval, and usage. */
216
+ get projects() {
217
+ return this._client.projects;
218
+ }
219
+ /** Agents: listing, retrieval, and usage. */
220
+ get agents() {
221
+ return this._client.agents;
222
+ }
223
+ /** Agent versions. */
224
+ get agentVersions() {
225
+ return this._client.agentVersions;
226
+ }
227
+ /** Threads: listing, retrieval, updates, and traces. */
228
+ get threads() {
229
+ return this._client.threads;
230
+ }
231
+ }
232
+ exports.ApolloManagementClient = ApolloManagementClient;
233
+ // Build the REST + WS URLs from an optional host override, deriving ws(s):// from http(s)://.
234
+ function resolveEnv(baseUrl) {
235
+ if (!baseUrl)
236
+ return environments_js_1.ApolloEnvironment.Gcp;
237
+ const base = baseUrl.replace(/\/+$/, "");
238
+ return { base, production: base.replace(/^http/i, "ws") };
239
+ }
212
240
  function detectKeyType(publishableKey) {
213
241
  if (!publishableKey)
214
242
  return "unknown";
@@ -4,6 +4,9 @@ export interface BaseClientOptions {
4
4
  environment?: core.Supplier<environments.ApolloEnvironment | environments.ApolloEnvironmentUrls>;
5
5
  /** Specify a custom URL to connect the client to. */
6
6
  baseUrl?: core.Supplier<string>;
7
+ token?: core.Supplier<core.BearerToken | undefined>;
8
+ /** Override the x-organization-api-key header */
9
+ organizationApiKey: core.Supplier<string>;
7
10
  /** Additional headers to include in requests. */
8
11
  headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
9
12
  /** The default maximum time to wait for a response in seconds. */
@@ -22,6 +25,8 @@ export interface BaseRequestOptions {
22
25
  maxRetries?: number;
23
26
  /** A hook to abort the request. */
24
27
  abortSignal?: AbortSignal;
28
+ /** Override the x-organization-api-key header */
29
+ organizationApiKey?: string;
25
30
  /** Additional query string parameters to include in the request. */
26
31
  queryParams?: Record<string, unknown>;
27
32
  /** Additional headers to include in the request. */
@@ -24,7 +24,7 @@ export declare class ApolloClient {
24
24
  protected _channels: Channels | undefined;
25
25
  protected _auth: Auth | undefined;
26
26
  protected _session: Session | undefined;
27
- constructor(_options?: ApolloClient.Options);
27
+ constructor(_options: ApolloClient.Options);
28
28
  get agents(): Agents;
29
29
  get agentVersions(): AgentVersions;
30
30
  get projects(): Projects;
@@ -34,6 +34,8 @@ export declare class ApolloClient {
34
34
  get auth(): Auth;
35
35
  get session(): Session;
36
36
  /**
37
+ * Liveness probe. Returns ``{"status": "ok"}`` when the service is up.
38
+ *
37
39
  * @param {ApolloClient.RequestOptions} requestOptions - Request-specific configuration.
38
40
  *
39
41
  * @example
@@ -41,4 +43,5 @@ export declare class ApolloClient {
41
43
  */
42
44
  health(requestOptions?: ApolloClient.RequestOptions): core.HttpResponsePromise<Record<string, unknown>>;
43
45
  private __health;
46
+ protected _getAuthorizationHeader(): Promise<string | undefined>;
44
47
  }
@@ -57,12 +57,13 @@ const core = __importStar(require("./core/index.js"));
57
57
  const environments = __importStar(require("./environments.js"));
58
58
  const errors = __importStar(require("./errors/index.js"));
59
59
  class ApolloClient {
60
- constructor(_options = {}) {
60
+ constructor(_options) {
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
+ "x-organization-api-key": _options === null || _options === void 0 ? void 0 : _options.organizationApiKey,
62
63
  "X-Fern-Language": "JavaScript",
63
64
  "X-Fern-SDK-Name": "@aui.io/aui-client",
64
- "X-Fern-SDK-Version": "3.1.2",
65
- "User-Agent": "@aui.io/aui-client/3.1.2",
65
+ "X-Fern-SDK-Version": "3.2.0",
66
+ "User-Agent": "@aui.io/aui-client/3.2.0",
66
67
  "X-Fern-Runtime": core.RUNTIME.type,
67
68
  "X-Fern-Runtime-Version": core.RUNTIME.version,
68
69
  }, _options === null || _options === void 0 ? void 0 : _options.headers) });
@@ -100,6 +101,8 @@ class ApolloClient {
100
101
  return ((_a = this._session) !== null && _a !== void 0 ? _a : (this._session = new Client_js_7.Session(this._options)));
101
102
  }
102
103
  /**
104
+ * Liveness probe. Returns ``{"status": "ok"}`` when the service is up.
105
+ *
103
106
  * @param {ApolloClient.RequestOptions} requestOptions - Request-specific configuration.
104
107
  *
105
108
  * @example
@@ -110,17 +113,20 @@ class ApolloClient {
110
113
  }
111
114
  __health(requestOptions) {
112
115
  return __awaiter(this, void 0, void 0, function* () {
113
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
114
- const _headers = (0, headers_js_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
116
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
117
+ const _headers = (0, headers_js_1.mergeHeaders)((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, (0, headers_js_1.mergeOnlyDefinedHeaders)({
118
+ Authorization: yield this._getAuthorizationHeader(),
119
+ "x-organization-api-key": (_b = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.organizationApiKey) !== null && _b !== void 0 ? _b : (_c = this._options) === null || _c === void 0 ? void 0 : _c.organizationApiKey,
120
+ }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
115
121
  const _response = yield core.fetcher({
116
- url: core.url.join((_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : ((_c = (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.ApolloEnvironment.Gcp).base, "health"),
122
+ url: core.url.join((_d = (yield core.Supplier.get(this._options.baseUrl))) !== null && _d !== void 0 ? _d : ((_e = (yield core.Supplier.get(this._options.environment))) !== null && _e !== void 0 ? _e : environments.ApolloEnvironment.Gcp).base, "health"),
117
123
  method: "GET",
118
124
  headers: _headers,
119
125
  queryParameters: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.queryParams,
120
- timeoutMs: ((_f = (_d = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _d !== void 0 ? _d : (_e = this._options) === null || _e === void 0 ? void 0 : _e.timeoutInSeconds) !== null && _f !== void 0 ? _f : 60) * 1000,
121
- maxRetries: (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.maxRetries,
126
+ timeoutMs: ((_h = (_f = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _f !== void 0 ? _f : (_g = this._options) === null || _g === void 0 ? void 0 : _g.timeoutInSeconds) !== null && _h !== void 0 ? _h : 60) * 1000,
127
+ maxRetries: (_j = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _j !== void 0 ? _j : (_k = this._options) === null || _k === void 0 ? void 0 : _k.maxRetries,
122
128
  abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
123
- fetchFn: (_j = this._options) === null || _j === void 0 ? void 0 : _j.fetch,
129
+ fetchFn: (_l = this._options) === null || _l === void 0 ? void 0 : _l.fetch,
124
130
  logging: this._options.logging,
125
131
  });
126
132
  if (_response.ok) {
@@ -150,5 +156,14 @@ class ApolloClient {
150
156
  }
151
157
  });
152
158
  }
159
+ _getAuthorizationHeader() {
160
+ return __awaiter(this, void 0, void 0, function* () {
161
+ const bearer = yield core.Supplier.get(this._options.token);
162
+ if (bearer != null) {
163
+ return `Bearer ${bearer}`;
164
+ }
165
+ return undefined;
166
+ });
167
+ }
153
168
  }
154
169
  exports.ApolloClient = ApolloClient;
@@ -9,8 +9,11 @@ export declare namespace AgentVersions {
9
9
  }
10
10
  export declare class AgentVersions {
11
11
  protected readonly _options: AgentVersions.Options;
12
- constructor(_options?: AgentVersions.Options);
12
+ constructor(_options: AgentVersions.Options);
13
13
  /**
14
+ * List an agent's versions, newest first. Filter by status, tag, label,
15
+ * or version number; set ``exclude_revisions`` to see only base versions.
16
+ *
14
17
  * @param {string} agentId
15
18
  * @param {Apollo.ListVersionsRequest} request
16
19
  * @param {AgentVersions.RequestOptions} requestOptions - Request-specific configuration.
@@ -28,9 +31,13 @@ export declare class AgentVersions {
28
31
  * filters: {}
29
32
  * })
30
33
  */
31
- listVersions(agentId: string, request: Apollo.ListVersionsRequest, requestOptions?: AgentVersions.RequestOptions): core.HttpResponsePromise<Apollo.ExternalPageAgentVersion>;
34
+ listVersions(agentId: string, request: Apollo.ListVersionsRequest, requestOptions?: AgentVersions.RequestOptions): core.HttpResponsePromise<Apollo.PageAgentVersion>;
32
35
  private __listVersions;
33
36
  /**
37
+ * Create a new draft version — empty, from a template, or cloned from an
38
+ * existing version (``source`` selects which). Drafts stay editable until
39
+ * published.
40
+ *
34
41
  * @param {string} agentId
35
42
  * @param {Apollo.AgentVersionCreateRequest} request
36
43
  * @param {AgentVersions.RequestOptions} requestOptions - Request-specific configuration.
@@ -51,6 +58,9 @@ export declare class AgentVersions {
51
58
  createVersion(agentId: string, request: Apollo.AgentVersionCreateRequest, requestOptions?: AgentVersions.RequestOptions): core.HttpResponsePromise<Apollo.AgentVersionCreateResponse>;
52
59
  private __createVersion;
53
60
  /**
61
+ * Update a version's metadata: label, tags, and notes. The configuration
62
+ * itself changes through push, never here.
63
+ *
54
64
  * @param {string} agentId
55
65
  * @param {string} versionId
56
66
  * @param {Apollo.AgentVersionUpdateRequest} request
@@ -70,6 +80,10 @@ export declare class AgentVersions {
70
80
  updateVersion(agentId: string, versionId: string, request?: Apollo.AgentVersionUpdateRequest, requestOptions?: AgentVersions.RequestOptions): core.HttpResponsePromise<Apollo.AgentVersionUpdateResponse>;
71
81
  private __updateVersion;
72
82
  /**
83
+ * Make this version the agent's live version. Publishing a draft freezes
84
+ * it first; publishing an already-published version re-activates it — the
85
+ * same call handles shipping, switching, and rolling back.
86
+ *
73
87
  * @param {string} agentId
74
88
  * @param {string} versionId
75
89
  * @param {AgentVersions.RequestOptions} requestOptions - Request-specific configuration.
@@ -88,6 +102,9 @@ export declare class AgentVersions {
88
102
  publishVersion(agentId: string, versionId: string, requestOptions?: AgentVersions.RequestOptions): core.HttpResponsePromise<Apollo.AgentVersionPublishResponse>;
89
103
  private __publishVersion;
90
104
  /**
105
+ * Archive a version to retire it from everyday use. The agent's live
106
+ * version can't be archived — publish another version first.
107
+ *
91
108
  * @param {string} agentId
92
109
  * @param {string} versionId
93
110
  * @param {AgentVersions.RequestOptions} requestOptions - Request-specific configuration.
@@ -106,6 +123,9 @@ export declare class AgentVersions {
106
123
  archiveVersion(agentId: string, versionId: string, requestOptions?: AgentVersions.RequestOptions): core.HttpResponsePromise<Apollo.AgentVersionArchiveResponse>;
107
124
  private __archiveVersion;
108
125
  /**
126
+ * Upload a configuration bundle to a version, committing a new revision.
127
+ * The response carries the new revision's tag and content digest.
128
+ *
109
129
  * @param {string} agentId
110
130
  * @param {string} versionId
111
131
  * @param {Apollo.AgentVersionPushRequest} request
@@ -130,6 +150,9 @@ export declare class AgentVersions {
130
150
  pushVersion(agentId: string, versionId: string, request: Apollo.AgentVersionPushRequest, requestOptions?: AgentVersions.RequestOptions): core.HttpResponsePromise<Apollo.AgentVersionPushResponse>;
131
151
  private __pushVersion;
132
152
  /**
153
+ * Download a version's configuration bundle — the current revision, or a
154
+ * specific one via ``version_tag``.
155
+ *
133
156
  * @param {string} agentId
134
157
  * @param {string} versionId
135
158
  * @param {Apollo.PullVersionRequest} request
@@ -150,4 +173,5 @@ export declare class AgentVersions {
150
173
  */
151
174
  pullVersion(agentId: string, versionId: string, request?: Apollo.PullVersionRequest, requestOptions?: AgentVersions.RequestOptions): core.HttpResponsePromise<Apollo.AgentVersionPullResponse>;
152
175
  private __pullVersion;
176
+ protected _getAuthorizationHeader(): Promise<string | undefined>;
153
177
  }