@aui.io/aui-client 3.1.2 → 3.2.1

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 +226 -143
  2. package/dist/cjs/ApolloClientWrapper.d.ts +54 -26
  3. package/dist/cjs/ApolloClientWrapper.js +88 -64
  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 +54 -26
  84. package/dist/esm/ApolloClientWrapper.mjs +85 -62
  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
package/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # @aui.io/aui-client
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/@aui.io/aui-client)](https://www.npmjs.com/package/@aui.io/aui-client)
4
- [![Built with Fern](https://img.shields.io/badge/Built%20with-Fern-brightgreen)](https://buildwithfern.com)
5
4
 
6
- > **Official TypeScript/JavaScript SDK for the AUI Apollo API v2.** REST access to projects, agents, threads, and messaging, plus a real-time WebSocket messaging session.
5
+ Official TypeScript/JavaScript SDK for the AUI Apollo API. Provides REST access to
6
+ messaging, projects, agents, and threads, plus a real-time WebSocket messaging session.
7
7
 
8
8
  ## Installation
9
9
 
@@ -11,220 +11,303 @@
11
11
  npm install @aui.io/aui-client
12
12
  ```
13
13
 
14
- ## Authentication
14
+ ## Clients
15
15
 
16
- The SDK authenticates with a **publishable key** or an **organization API key** you never manage bearer tokens yourself.
16
+ The package exposes two clients, one per credential. Import and use the one that
17
+ matches your environment.
17
18
 
18
- - **Publishable key** (`pk_network_…` for a single agent, or `pk_org_…` for an organization): exchanged automatically at `POST /management/v1/auth/token` for a short-lived bearer token that is cached and refreshed transparently.
19
- - **Organization API key**: used directly as the bearer token.
19
+ | Client | Credential | Browser | Purpose |
20
+ | --- | --- | --- | --- |
21
+ | `ApolloMessagingClient` | Publishable key (`pk_network_...`) | Yes | End-user messaging and channels |
22
+ | `ApolloManagementClient` | Organization API key | No — server only | Managing projects, agents, versions, and threads |
20
23
 
21
- Pass exactly one of them:
24
+ ---
22
25
 
23
- ```typescript
24
- import { ApolloClient } from '@aui.io/aui-client';
26
+ ## Messaging
25
27
 
26
- // With a publishable key (recommended for client / agent-scoped use)
27
- const client = new ApolloClient({
28
- publishableKey: 'pk_network_xxxxxxxxxxxxxxxxxxxxxxxx',
29
- });
28
+ `ApolloMessagingClient` authenticates with a publishable key. It exchanges the key
29
+ for a short-lived access token and refreshes it as needed, so you never handle tokens
30
+ directly. The agent is derived from the key and is not passed in request bodies. The
31
+ client is safe to use in the browser.
30
32
 
31
- // Or with an organization API key
32
- const orgClient = new ApolloClient({
33
- organizationApiKey: 'YOUR_ORG_API_KEY',
33
+ ```ts
34
+ import { ApolloMessagingClient } from '@aui.io/aui-client';
35
+
36
+ const client = new ApolloMessagingClient({
37
+ publishableKey: 'pk_network_xxxxxxxxxxxxxxxxxxxxxxxx',
34
38
  });
35
39
  ```
36
40
 
37
- ## Quick Start
41
+ ### Send a message
38
42
 
39
- ```typescript
40
- import { ApolloClient } from '@aui.io/aui-client';
43
+ Omit `thread_id` to start a new thread, or pass it to continue one.
41
44
 
42
- const client = new ApolloClient({
43
- publishableKey: 'pk_network_xxxxxxxxxxxxxxxxxxxxxxxx',
45
+ ```ts
46
+ const response = await client.messaging.sendMessage({
47
+ user_id: 'end-user-123',
48
+ text: 'What can you help me with?',
49
+ // thread_id: existingThreadId,
44
50
  });
45
51
 
46
- // List projects, then the agents in the first project
47
- const projects = await client.projects.listProjects();
48
- const projectId = projects.results[0].id;
52
+ console.log(response.thread_id);
53
+ ```
49
54
 
50
- const agents = await client.agents.listAgents(projectId, { filters: {} });
51
- const agentId = agents.results[0].id;
55
+ You can pass optional per-message values for the agent's configured context variables:
52
56
 
53
- // Send a message (creates a thread if thread_id is omitted)
54
- const response = await client.messaging.sendMessage({
55
- agent_id: agentId,
56
- user_id: 'end-user-123',
57
- text: 'Hello from the SDK',
57
+ ```ts
58
+ await client.messaging.sendMessage({
59
+ user_id: 'end-user-123',
60
+ text: 'Where is my order?',
61
+ agent_variables: {
62
+ static: { customer_name: 'Ada' },
63
+ dynamic: { order_id: 'ORD-1042' },
64
+ },
58
65
  });
59
-
60
- console.log('Thread:', response.thread_id);
61
66
  ```
62
67
 
63
- ## Configuration
68
+ ### Stream a message
64
69
 
65
- The `ApolloClient` constructor accepts:
70
+ `streamMessage` returns the reply as Server-Sent Events.
66
71
 
67
- ```typescript
68
- interface ApolloClient.Options {
69
- environment?: ApolloEnvironment; // Defaults to ApolloEnvironment.Gcp
70
- publishableKey?: string; // pk_network_… or pk_org_…
71
- organizationApiKey?: string; // Organization API key
72
+ ```ts
73
+ const stream = await client.messaging.streamMessage({
74
+ user_id: 'end-user-123',
75
+ text: 'Tell me about my account',
76
+ });
77
+
78
+ for await (const event of stream) {
79
+ console.log(event);
72
80
  }
73
81
  ```
74
82
 
75
- ### Environments
83
+ ### Welcome message and follow-up suggestions
76
84
 
77
- ```typescript
78
- import { ApolloEnvironment } from '@aui.io/aui-client';
85
+ ```ts
86
+ const { welcome_message } = await client.messaging.getWelcomeMessage();
79
87
 
80
- ApolloEnvironment.Gcp = {
81
- base: 'https://api-v3.aui.io/apollo-api-v2', // REST
82
- production: 'wss://api-v3.aui.io/apollo-api-v2', // WebSocket
83
- };
88
+ const { suggestions } = await client.messaging.generateFollowupSuggestions({
89
+ context: { topic: 'order tracking' },
90
+ });
84
91
  ```
85
92
 
86
- `environment` defaults to `ApolloEnvironment.Gcp`, so most callers only need to pass a key.
93
+ ### Other messaging methods
94
+
95
+ | Method | Description |
96
+ | --- | --- |
97
+ | `sendMessage(request)` | Send a message and return the reply. |
98
+ | `streamMessage(request)` | Send a message and stream the reply (SSE). |
99
+ | `rerun(threadId, request)` | Re-run the latest turn of a thread. |
100
+ | `listMessages(threadId)` | Return the messages in a thread. |
101
+ | `threadTrace(threadId)` | Return the reasoning trace for each interaction in a thread. |
102
+ | `interactionTrace(interactionId)` | Return the reasoning trace for a single interaction. |
103
+ | `getWelcomeMessage()` | Return the agent's welcome message. |
104
+ | `generateFollowupSuggestions(request)` | Generate follow-up prompts from a context. |
105
+
106
+ ### Channels (SMS and WhatsApp)
107
+
108
+ Start an outbound thread on a channel with `channels.initiateThread`. Pass `'sms'`
109
+ or `'whatsapp'` as the channel.
110
+
111
+ ```ts
112
+ const thread = await client.channels.initiateThread('sms', {
113
+ phone_number: '+14155551234',
114
+ user_id: 'end-user-123',
115
+ text: 'Hi! Your order has shipped.',
116
+ // thread_id: existingThreadId,
117
+ });
87
118
 
88
- ## REST API
119
+ console.log(thread.thread_id);
120
+ ```
89
121
 
90
- Resources are grouped on the client. All list endpoints are paginated and return `{ results, meta }`, where `meta.has_more` indicates further pages.
122
+ ### WebSocket sessions
91
123
 
92
- ### Projects `client.projects`
124
+ `connect()` opens a real-time messaging session. Authentication is handled for you,
125
+ and it works in both Node and the browser.
93
126
 
94
- ```typescript
95
- const page = await client.projects.listProjects(); // { results, meta }
96
- const project = await client.projects.getProject(projectId);
97
- const usage = await client.projects.getProjectUsage(projectId);
98
- ```
127
+ ```ts
128
+ const socket = await client.connect();
129
+ await socket.waitForOpen();
99
130
 
100
- ### Agents `client.agents`
131
+ socket.on('message', (message) => console.log(message));
132
+ socket.on('error', (error) => console.error(error));
133
+ socket.on('close', (event) => console.log('closed', event.code));
101
134
 
102
- ```typescript
103
- const page = await client.agents.listAgents(projectId, { filters: {} });
104
- const agent = await client.agents.getAgent(agentId); // agent.live_version_id,
105
- const usage = await client.agents.getAgentUsage(agentId);
135
+ socket.sendSubmitMessage({
136
+ type: 'message',
137
+ agent_id: agentId,
138
+ user_id: 'end-user-123',
139
+ text: 'Hello over WebSocket',
140
+ });
141
+
142
+ socket.close();
106
143
  ```
107
144
 
108
- ### Threads `client.threads`
145
+ The socket exposes `waitForOpen()`, `on(event, handler)` (events: `open`, `message`,
146
+ `error`, `close`), `sendSubmitMessage(request)`, `sendResume(request)`, and `close()`.
147
+ Note that `on()` registers a single handler per event; calling it again for the same
148
+ event replaces the previous handler. The socket type is exported as `SessionSocket`.
109
149
 
110
- ```typescript
111
- const page = await client.threads.listThreads({ filters: {} });
112
- const thread = await client.threads.getThread(threadId);
113
- const messages = await client.threads.getThreadMessages(threadId);
114
- const trace = await client.threads.getThreadTrace(threadId);
115
- ```
150
+ ### Resolved key context
116
151
 
117
- ### Messaging `client.messaging`
152
+ After the first request, or after calling `getContext()`, the scope resolved from the
153
+ publishable key is available.
118
154
 
119
- ```typescript
120
- // Send a message. Omit thread_id to start a new thread.
121
- const res = await client.messaging.sendMessage({
122
- agent_id: agentId,
123
- user_id: 'end-user-123',
124
- text: 'What can you help me with?',
125
- // thread_id: existingThreadId,
126
- });
127
- console.log('Thread:', res.thread_id);
155
+ ```ts
156
+ const context = await client.getContext();
157
+ console.log(context.agentId, context.organizationId);
128
158
 
129
- // List the messages in a thread
130
- const messages = await client.messaging.listMessages(res.thread_id);
159
+ client.agentId; // set after the first token exchange
160
+ client.organizationId;
131
161
  ```
132
162
 
133
- ## WebSocket Messaging
163
+ ---
134
164
 
135
- `client.connect()` opens a real-time session. The bearer token is resolved and attached to the upgrade automatically.
165
+ ## Management
136
166
 
137
- ```typescript
138
- const socket = await client.connect();
139
- await socket.waitForOpen();
167
+ `ApolloManagementClient` authenticates with an organization API key, sent as the
168
+ `x-organization-api-key` header on every request. It is intended for backend services
169
+ and CI. Do not expose the organization API key in the browser.
140
170
 
141
- socket.on('message', (msg) => {
142
- console.log('Agent:', msg);
143
- });
144
- socket.on('error', (err) => console.error('WS error:', err));
145
- socket.on('close', (event) => console.log('Closed:', event.code));
171
+ ```ts
172
+ import { ApolloManagementClient } from '@aui.io/aui-client';
146
173
 
147
- // Send a turn (type is required on the WS submit frame)
148
- socket.sendSubmitMessage({
149
- type: 'message',
150
- agent_id: agentId,
151
- user_id: 'end-user-123',
152
- text: 'Hello over WebSocket',
174
+ const client = new ApolloManagementClient({
175
+ organizationApiKey: process.env.AUI_ORG_API_KEY,
153
176
  });
177
+ ```
154
178
 
155
- // When done
156
- socket.close();
179
+ ### Projects
180
+
181
+ | Method | Description |
182
+ | --- | --- |
183
+ | `listProjects()` | List the organization's projects. |
184
+ | `createProject(request)` | Create a project. |
185
+ | `getProject(projectId)` | Fetch one project. |
186
+ | `deleteProject(projectId)` | Delete a project. |
187
+ | `getProjectUsage(projectId)` | Usage metrics aggregated across the project. |
188
+
189
+ ```ts
190
+ const page = await client.projects.listProjects();
191
+ const project = await client.projects.createProject({ name: 'My project' });
192
+ const usage = await client.projects.getProjectUsage(project.id);
193
+ ```
194
+
195
+ ### Agents
196
+
197
+ | Method | Description |
198
+ | --- | --- |
199
+ | `listAgents(projectId, { filters })` | List a project's agents. |
200
+ | `createAgent(projectId, request)` | Create an agent. |
201
+ | `getAgent(agentId)` | Fetch one agent. |
202
+ | `updateAgent(agentId, request)` | Rename an agent. |
203
+ | `deleteAgent(agentId)` | Delete an agent and its versions. |
204
+ | `getAgentUsage(agentId)` | Usage metrics for one agent. |
205
+
206
+ ```ts
207
+ const page = await client.agents.listAgents(projectId, { filters: {} });
208
+ const agent = await client.agents.createAgent(projectId, { name: 'Support bot' });
209
+ const usage = await client.agents.getAgentUsage(agent.id);
210
+ ```
211
+
212
+ ### Agent versions
213
+
214
+ | Method | Description |
215
+ | --- | --- |
216
+ | `listVersions(agentId, { filters })` | List an agent's versions, newest first. |
217
+ | `createVersion(agentId, request)` | Create a draft version. |
218
+ | `updateVersion(agentId, versionId, request)` | Update a version's metadata. |
219
+ | `pushVersion(agentId, versionId, request)` | Push a configuration bundle. |
220
+ | `pullVersion(agentId, versionId, request?)` | Download a version's configuration bundle. |
221
+ | `publishVersion(agentId, versionId)` | Make a version the agent's live version. |
222
+ | `archiveVersion(agentId, versionId)` | Archive a version. |
223
+
224
+ ```ts
225
+ const draft = await client.agentVersions.createVersion(agentId, {});
226
+ await client.agentVersions.pushVersion(agentId, draft.id, { /* config bundle */ });
227
+ await client.agentVersions.publishVersion(agentId, draft.id);
228
+ ```
229
+
230
+ ### Threads
231
+
232
+ | Method | Description |
233
+ | --- | --- |
234
+ | `listThreads({ filters })` | List the organization's threads, newest first. |
235
+ | `getThread(threadId)` | Fetch one thread. |
236
+ | `updateThread(threadId, request)` | Update a thread (currently `title`). |
237
+ | `getThreadMessages(threadId)` | Return the thread's transcript. |
238
+ | `getThreadTrace(threadId)` | Return the reasoning trace for each interaction. |
239
+ | `getInteractionTrace(interactionId)` | Return the reasoning trace for a single interaction. |
240
+
241
+ `filters` supports `project_id`, `agent_id`, `user_id`, `external_id`, `created`
242
+ (range), `tool`, `rule`, and `param`. Prefer a filter such as `project_id` over an
243
+ empty object; the unfiltered list sorts every thread in the organization and can be slow.
244
+
245
+ ```ts
246
+ const page = await client.threads.listThreads(
247
+ { filters: { project_id: projectId } },
248
+ { timeoutInSeconds: 120 },
249
+ );
250
+ const thread = await client.threads.getThread(threadId);
251
+ await client.threads.updateThread(threadId, { title: 'Renamed conversation' });
157
252
  ```
158
253
 
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 })`.
254
+ ---
166
255
 
167
- ## Key Context Helpers
256
+ ## Pagination
168
257
 
169
- After the first request (or an explicit `getContext()`), scope resolved from the key is available:
258
+ List endpoints return `{ results, meta }`. Use `meta.has_more` to detect further pages.
170
259
 
171
- ```typescript
172
- console.log(client.keyType); // 'agent' | 'org' | 'unknown'
260
+ ## Timeouts
173
261
 
174
- const ctx = await client.getContext();
175
- console.log(ctx.agentId, ctx.organizationId, ctx.keyType);
262
+ There is no client-wide timeout. Set `timeoutInSeconds` per call when needed:
176
263
 
177
- client.agentId; // populated once a token has been exchanged
178
- client.organizationId;
264
+ ```ts
265
+ await client.threads.listThreads({ filters: {} }, { timeoutInSeconds: 120 });
179
266
  ```
180
267
 
181
- ## Error Handling
268
+ ## Error handling
182
269
 
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.
270
+ `ApolloError` and `ApolloTimeoutError` are exported at the top level. Per-status errors,
271
+ such as `UnprocessableEntityError`, are available under the `Apollo` namespace.
186
272
 
187
- ```typescript
273
+ ```ts
188
274
  import { ApolloError, Apollo } from '@aui.io/aui-client';
189
275
 
190
276
  try {
191
- await client.agents.getAgent('missing-id');
277
+ await client.agents.getAgent('missing-id');
192
278
  } catch (error) {
193
- if (error instanceof Apollo.UnprocessableEntityError) {
194
- console.error('Validation failed:', error.body);
195
- } else if (error instanceof ApolloError) {
196
- console.error('API error:', error.statusCode, error.body);
197
- } else {
198
- console.error('Unexpected error:', error);
199
- }
279
+ if (error instanceof Apollo.UnprocessableEntityError) {
280
+ console.error(error.body);
281
+ } else if (error instanceof ApolloError) {
282
+ console.error(error.statusCode, error.body);
283
+ } else {
284
+ throw error;
285
+ }
200
286
  }
201
287
  ```
202
288
 
203
- ## TypeScript Support
289
+ ## TypeScript
204
290
 
205
- The SDK ships full type definitions. Models are namespaced under `Apollo`:
291
+ The package ships type definitions. Request and response models are available under the
292
+ `Apollo` namespace.
206
293
 
207
- ```typescript
208
- import { ApolloClient, Apollo } from '@aui.io/aui-client';
294
+ ```ts
295
+ import { Apollo } from '@aui.io/aui-client';
209
296
 
210
- const req: Apollo.SubmitMessageRequest = {
211
- type: 'message',
212
- agent_id: 'agent-123',
213
- user_id: 'end-user-123',
214
- text: 'Typed request',
297
+ const request: Apollo.SubmitMessageRequest = {
298
+ type: 'message',
299
+ agent_id: 'agent-123',
300
+ user_id: 'end-user-123',
301
+ text: 'Typed request',
215
302
  };
216
303
  ```
217
304
 
218
305
  ## Resources
219
306
 
220
- - **GitHub:** [aui-io/aui-client-typescript](https://github.com/aui-io/aui-client-typescript)
221
- - **npm:** [@aui.io/aui-client](https://www.npmjs.com/package/@aui.io/aui-client)
222
- - **Issues:** [GitHub Issues](https://github.com/aui-io/aui-client-typescript/issues)
307
+ - npm: [@aui.io/aui-client](https://www.npmjs.com/package/@aui.io/aui-client)
308
+ - GitHub: [aui-io/aui-client-typescript](https://github.com/aui-io/aui-client-typescript)
309
+ - Issues: [GitHub Issues](https://github.com/aui-io/aui-client-typescript/issues)
223
310
 
224
311
  ## License
225
312
 
226
- Proprietary software. Unauthorized copying or distribution is prohibited.
227
-
228
- ---
229
-
230
- **Built by the AUI team**
313
+ Proprietary. Unauthorized copying or distribution is prohibited.
@@ -2,31 +2,42 @@ import { ApolloClient as _GeneratedClient } from "./Client.js";
2
2
  import type { ApolloEnvironmentUrls } from "./environments.js";
3
3
  import { SessionSocket } from "./api/resources/session/client/Socket.js";
4
4
  import type { Session } from "./api/resources/session/client/Client.js";
5
+ import type { Messaging } from "./api/resources/messaging/client/Client.js";
6
+ import type { Channels } from "./api/resources/channels/client/Client.js";
7
+ import type { Projects } from "./api/resources/projects/client/Client.js";
8
+ import type { Agents } from "./api/resources/agents/client/Client.js";
9
+ import type { AgentVersions } from "./api/resources/agentVersions/client/Client.js";
10
+ import type { Threads } from "./api/resources/threads/client/Client.js";
5
11
  /** Publishable-key family, inferred from the key prefix. */
6
- export type PublishableKeyType = "agent" | "org" | "unknown";
7
- export declare namespace ApolloClient {
12
+ export type PublishableKeyType = "agent" | "unknown";
13
+ type AuthHeaders = Record<string, string | (() => Promise<string>) | null>;
14
+ declare class BaseApolloClient {
15
+ protected readonly _client: _GeneratedClient;
16
+ protected readonly _env: ApolloEnvironmentUrls;
17
+ constructor(env: ApolloEnvironmentUrls, authHeaders: AuthHeaders);
18
+ }
19
+ export declare namespace ApolloMessagingClient {
8
20
  interface Options {
9
- /** Deployment environment. Defaults to ApolloEnvironment.Gcp. */
10
- environment?: ApolloEnvironmentUrls;
11
- /** Publishable key (pk_network_ or pk_org_); exchanged for a bearer token. */
12
- publishableKey?: string;
13
- /** Organization API key; used directly as the bearer token. */
14
- organizationApiKey?: string;
21
+ /** Publishable key (pk_network_...). */
22
+ publishableKey: string;
23
+ /** Internal: override the API host. Defaults to production. */
24
+ baseUrl?: string;
15
25
  }
16
26
  interface ConnectArgs extends Session.ConnectArgs {
17
27
  }
18
28
  }
19
29
  /**
20
- * ApolloClient adds authentication on top of the generated client: it takes a
21
- * publishable key (or organization API key) and handles the token exchange/refresh
22
- * transparently. Every generated resource (agents, threads, messaging, …) is
23
- * inherited unchanged.
30
+ * Publishable-key client for end-user / widget messaging (browser-safe).
31
+ * Exposes the `messaging` audience only.
24
32
  */
25
- export declare class ApolloClient extends _GeneratedClient {
26
- private readonly _tokenAuth;
27
- private readonly _env;
28
- constructor(options?: ApolloClient.Options);
29
- /** Publishable-key family (agent / org / unknown). */
33
+ export declare class ApolloMessagingClient extends BaseApolloClient {
34
+ private readonly _pkAuth;
35
+ constructor(options: ApolloMessagingClient.Options);
36
+ /** Send / stream messages and read thread & interaction traces. */
37
+ get messaging(): Messaging;
38
+ /** Initiate channel-scoped threads (e.g. SMS). */
39
+ get channels(): Channels;
40
+ /** Publishable-key family (agent / unknown). */
30
41
  get keyType(): PublishableKeyType;
31
42
  /** Agent resolved from an agent-scoped key. Populated after the first exchange. */
32
43
  get agentId(): string | undefined;
@@ -38,13 +49,30 @@ export declare class ApolloClient extends _GeneratedClient {
38
49
  organizationId?: string;
39
50
  keyType: PublishableKeyType;
40
51
  }>;
41
- /**
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.
48
- */
49
- connect(args?: ApolloClient.ConnectArgs): Promise<SessionSocket>;
52
+ /** Open a messaging WebSocket session. */
53
+ connect(args?: ApolloMessagingClient.ConnectArgs): Promise<SessionSocket>;
54
+ }
55
+ export declare namespace ApolloManagementClient {
56
+ interface Options {
57
+ /** Organization API key. Server-side only. */
58
+ organizationApiKey: string;
59
+ /** Internal: override the API host. Defaults to production. */
60
+ baseUrl?: string;
61
+ }
62
+ }
63
+ /**
64
+ * Organization-API-key client for backend services and CI (server-side only).
65
+ * Exposes the `management` audience only.
66
+ */
67
+ export declare class ApolloManagementClient extends BaseApolloClient {
68
+ constructor(options: ApolloManagementClient.Options);
69
+ /** Projects: listing, retrieval, and usage. */
70
+ get projects(): Projects;
71
+ /** Agents: listing, retrieval, and usage. */
72
+ get agents(): Agents;
73
+ /** Agent versions. */
74
+ get agentVersions(): AgentVersions;
75
+ /** Threads: listing, retrieval, updates, and traces. */
76
+ get threads(): Threads;
50
77
  }
78
+ export {};