@amigo-ai/platform-sdk 0.19.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/api.md CHANGED
@@ -51,8 +51,8 @@ Notes:
51
51
  - Request option types: `AmigoRequestOptions`, `ScopedRequestOptions`
52
52
  - Webhooks: `verifyWebhookSignature`, `parseWebhookEvent`, `WebhookVerificationError`
53
53
  - Pagination and response helpers: `paginate`, `buildLastResponse`, `extractRequestId`
54
- - Conversation helpers: `textStreamAuthProtocols`
55
- - Conversation types: `ConversationDetail`, `ConversationListResponse`, `ConversationSummary`, `ConversationTurn`, `CreateConversationRequest`, `ListConversationsParams`, `TextStreamAuthProtocols` (WebSocket constructor subprotocol tuple), `TextStreamUrlParams`, `TurnRequest`, `TurnResponse`
54
+ - Conversation helpers: `sessionConnectAuthProtocols`, `textStreamAuthProtocols`
55
+ - Conversation types: `ConversationDetail`, `ConversationListResponse`, `ConversationSummary`, `ConversationTurn`, `CreateConversationRequest`, `ListConversationsParams`, `SessionConnectUrlParams`, `TextStreamAuthProtocols` (WebSocket constructor subprotocol tuple), `TextStreamUrlParams`, `TurnDoneEvent`, `TurnErrorEvent`, `TurnMessageEvent`, `TurnRequest`, `TurnResponse`, `TurnStreamEvent`, `TurnThinkingEvent`, `TurnTokenEvent`, `TurnToolCallCompletedEvent`, `TurnToolCallStartedEvent`
56
56
  - Response and hook types: `PaginatedList`, `ListParams`, `LastResponseInfo`, `ResponseMetadata`, `WithResponseMetadata`, `AmigoResponse`, `RetryOptions`, `RateLimitInfo`, `ClientHooks`, `RequestHookContext`, `ResponseHookContext`, `ErrorHookContext`
57
57
  - Generated OpenAPI types: `paths`, `components`, `operations`
58
58
  - Generated API types are produced with `npm run gen-types` from the committed `openapi.json` snapshot.
@@ -241,6 +241,7 @@ All workspace-scoped resources also expose `withOptions(options)`.
241
241
  - `createTurn`
242
242
  - `createTurnStream`
243
243
  - `textStreamUrl`
244
+ - `sessionConnectUrl`
244
245
 
245
246
  ### `phoneNumbers`
246
247
 
package/dist/index.cjs CHANGED
@@ -82,6 +82,7 @@ __export(index_exports, {
82
82
  personaId: () => personaId,
83
83
  phoneNumberId: () => phoneNumberId,
84
84
  serviceId: () => serviceId,
85
+ sessionConnectAuthProtocols: () => sessionConnectAuthProtocols,
85
86
  simulationRunId: () => simulationRunId,
86
87
  simulationSessionId: () => simulationSessionId,
87
88
  skillId: () => skillId,
@@ -2034,6 +2035,32 @@ var ConversationsResource = class extends WorkspaceScopedResource {
2034
2035
  });
2035
2036
  return url.toString();
2036
2037
  }
2038
+ /**
2039
+ * Build the URL for the workspace-scoped session-connect WebSocket
2040
+ * (``WS /v1/{workspace_id}/sessions/connect``).
2041
+ *
2042
+ * Pair the returned URL with {@link sessionConnectAuthProtocols} so the
2043
+ * bearer token is delivered via the ``Sec-WebSocket-Protocol`` header — the
2044
+ * endpoint rejects query-param tokens to keep credentials out of URLs.
2045
+ *
2046
+ * @example
2047
+ * ```ts
2048
+ * const url = client.conversations.sessionConnectUrl({
2049
+ * serviceId: SERVICE_ID,
2050
+ * entityId: ENTITY_ID,
2051
+ * conversationId: existingConversationId, // optional resume
2052
+ * });
2053
+ * const ws = new WebSocket(url, sessionConnectAuthProtocols(apiKey));
2054
+ * ```
2055
+ */
2056
+ sessionConnectUrl(params) {
2057
+ const url = buildSessionConnectUrl({
2058
+ baseUrl: this.platformBaseUrl,
2059
+ workspaceId: this.workspaceId,
2060
+ ...params
2061
+ });
2062
+ return url.toString();
2063
+ }
2037
2064
  };
2038
2065
  function textStreamAuthProtocols(apiKey) {
2039
2066
  const token = validateTextStreamAuthToken(apiKey, "apiKey");
@@ -2045,6 +2072,9 @@ function textStreamAuthProtocols(apiKey) {
2045
2072
  }
2046
2073
  return ["auth", token];
2047
2074
  }
2075
+ function sessionConnectAuthProtocols(apiKey) {
2076
+ return textStreamAuthProtocols(apiKey);
2077
+ }
2048
2078
  function buildTextStreamUrl({
2049
2079
  baseUrl,
2050
2080
  workspaceId: workspaceId2,
@@ -2120,6 +2150,66 @@ function deriveTextStreamUrl(baseUrl) {
2120
2150
  url.hash = "";
2121
2151
  return url;
2122
2152
  }
2153
+ function buildSessionConnectUrl({
2154
+ baseUrl,
2155
+ workspaceId: workspaceId2,
2156
+ serviceId: serviceId2,
2157
+ entityId: entityId2,
2158
+ conversationId,
2159
+ toolEvents,
2160
+ sessionConnectUrl: sessionConnectUrlOverride
2161
+ }) {
2162
+ const url = sessionConnectUrlOverride ? parseSessionConnectUrlOverride(sessionConnectUrlOverride) : deriveSessionConnectUrl(baseUrl, workspaceId2);
2163
+ url.searchParams.set("service_id", serviceId2);
2164
+ url.searchParams.set("entity_id", entityId2);
2165
+ if (conversationId) url.searchParams.set("conversation_id", conversationId);
2166
+ if (toolEvents === false) url.searchParams.set("tool_events", "false");
2167
+ return url;
2168
+ }
2169
+ function parseSessionConnectUrlOverride(sessionConnectUrl) {
2170
+ try {
2171
+ const url = new URL(sessionConnectUrl);
2172
+ if (url.protocol !== "ws:" && url.protocol !== "wss:") {
2173
+ throw new ConfigurationError("sessionConnectUrl overrides must use ws: or wss: URLs");
2174
+ }
2175
+ if (url.search || url.hash) {
2176
+ throw new ConfigurationError(
2177
+ "sessionConnectUrl overrides must not include query parameters or fragments; pass SDK-managed fields through sessionConnectUrl() options"
2178
+ );
2179
+ }
2180
+ return url;
2181
+ } catch (cause) {
2182
+ if (cause instanceof ConfigurationError) throw cause;
2183
+ throw new ConfigurationError(
2184
+ `sessionConnectUrl must be an absolute URL for session-connect overrides: ${String(cause)}`
2185
+ );
2186
+ }
2187
+ }
2188
+ function deriveSessionConnectUrl(baseUrl, workspaceId2) {
2189
+ if (!/^[a-z][a-z\d+.-]*:\/\//i.test(baseUrl)) {
2190
+ throw new ConfigurationError(
2191
+ "sessionConnectUrl cannot be derived from a relative baseUrl; pass sessionConnectUrl explicitly"
2192
+ );
2193
+ }
2194
+ const url = new URL(baseUrl);
2195
+ if (url.protocol === "ws:" || url.protocol === "wss:") {
2196
+ } else if (url.protocol === "http:" || url.protocol === "https:") {
2197
+ url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
2198
+ } else {
2199
+ throw new ConfigurationError(
2200
+ "sessionConnectUrl can only be derived from an http, https, ws, or wss baseUrl; pass sessionConnectUrl explicitly"
2201
+ );
2202
+ }
2203
+ if (url.pathname !== "/" && url.pathname !== "") {
2204
+ throw new ConfigurationError(
2205
+ "sessionConnectUrl can only be derived from an origin-only baseUrl; pass sessionConnectUrl explicitly when using path-prefixed gateways"
2206
+ );
2207
+ }
2208
+ url.pathname = `/v1/${workspaceId2}/sessions/connect`;
2209
+ url.search = "";
2210
+ url.hash = "";
2211
+ return url;
2212
+ }
2123
2213
  function describeInvalidSubprotocolChars(token) {
2124
2214
  const chars = /* @__PURE__ */ new Set();
2125
2215
  for (const char of token) {