@amigo-ai/platform-sdk 0.17.3 → 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 +4 -2
- package/dist/index.cjs +128 -1
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +128 -1
- package/dist/index.mjs.map +2 -2
- package/dist/resources/conversations.js +134 -0
- package/dist/resources/conversations.js.map +1 -1
- package/dist/resources/operators.js.map +1 -1
- package/dist/types/generated/api.d.ts +1607 -418
- package/dist/types/generated/api.d.ts.map +1 -1
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.cts.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/resources/billing.d.ts +4 -0
- package/dist/types/resources/billing.d.ts.map +1 -1
- package/dist/types/resources/calls.d.ts +1 -1
- package/dist/types/resources/conversations.d.ts +97 -0
- package/dist/types/resources/conversations.d.ts.map +1 -1
- package/dist/types/resources/functions.d.ts.map +1 -1
- package/dist/types/resources/integrations.d.ts +140 -10
- package/dist/types/resources/integrations.d.ts.map +1 -1
- package/dist/types/resources/metrics.d.ts.map +1 -1
- package/dist/types/resources/operators.d.ts +8 -5
- package/dist/types/resources/operators.d.ts.map +1 -1
- package/dist/types/resources/recordings.d.ts +1 -1
- package/dist/types/resources/settings.d.ts.map +1 -1
- package/package.json +1 -1
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.
|
|
@@ -239,7 +239,9 @@ All workspace-scoped resources also expose `withOptions(options)`.
|
|
|
239
239
|
- `get`
|
|
240
240
|
- `close`
|
|
241
241
|
- `createTurn`
|
|
242
|
+
- `createTurnStream`
|
|
242
243
|
- `textStreamUrl`
|
|
244
|
+
- `sessionConnectUrl`
|
|
243
245
|
|
|
244
246
|
### `phoneNumbers`
|
|
245
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,
|
|
@@ -1984,10 +1985,47 @@ var ConversationsResource = class extends WorkspaceScopedResource {
|
|
|
1984
1985
|
params: {
|
|
1985
1986
|
path: { workspace_id: this.workspaceId, conversation_id: conversationId }
|
|
1986
1987
|
},
|
|
1987
|
-
body: request
|
|
1988
|
+
body: request,
|
|
1989
|
+
headers: { Accept: "application/json" }
|
|
1988
1990
|
})
|
|
1989
1991
|
);
|
|
1990
1992
|
}
|
|
1993
|
+
/**
|
|
1994
|
+
* Send a message and receive the agent's response as an SSE stream.
|
|
1995
|
+
*
|
|
1996
|
+
* Returns a `ReadableStream` of SSE bytes. Use `EventSourceParserStream`
|
|
1997
|
+
* (from `eventsource-parser/stream`) to parse into typed `TurnStreamEvent`.
|
|
1998
|
+
*
|
|
1999
|
+
* @example
|
|
2000
|
+
* ```ts
|
|
2001
|
+
* const stream = await client.conversations.createTurnStream(convId, { message: "Hello" });
|
|
2002
|
+
* const events = stream
|
|
2003
|
+
* .pipeThrough(new TextDecoderStream())
|
|
2004
|
+
* .pipeThrough(new EventSourceParserStream());
|
|
2005
|
+
* for await (const event of events) {
|
|
2006
|
+
* const parsed = JSON.parse(event.data) as TurnStreamEvent;
|
|
2007
|
+
* if (parsed.event === "token") console.log(parsed.text);
|
|
2008
|
+
* }
|
|
2009
|
+
* ```
|
|
2010
|
+
*/
|
|
2011
|
+
async createTurnStream(conversationId, request, options) {
|
|
2012
|
+
const result = await this.client.POST(
|
|
2013
|
+
"/v1/{workspace_id}/conversations/{conversation_id}/turns",
|
|
2014
|
+
{
|
|
2015
|
+
params: {
|
|
2016
|
+
path: { workspace_id: this.workspaceId, conversation_id: conversationId }
|
|
2017
|
+
},
|
|
2018
|
+
body: request,
|
|
2019
|
+
headers: { Accept: "text/event-stream" },
|
|
2020
|
+
parseAs: "stream",
|
|
2021
|
+
signal: options?.signal
|
|
2022
|
+
}
|
|
2023
|
+
);
|
|
2024
|
+
if (result.error !== void 0) {
|
|
2025
|
+
throw new Error(`API error: ${JSON.stringify(result.error)}`);
|
|
2026
|
+
}
|
|
2027
|
+
return result.data;
|
|
2028
|
+
}
|
|
1991
2029
|
/** Build the real-time text WebSocket URL for browser or custom clients. */
|
|
1992
2030
|
textStreamUrl(params) {
|
|
1993
2031
|
const url = buildTextStreamUrl({
|
|
@@ -1997,6 +2035,32 @@ var ConversationsResource = class extends WorkspaceScopedResource {
|
|
|
1997
2035
|
});
|
|
1998
2036
|
return url.toString();
|
|
1999
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
|
+
}
|
|
2000
2064
|
};
|
|
2001
2065
|
function textStreamAuthProtocols(apiKey) {
|
|
2002
2066
|
const token = validateTextStreamAuthToken(apiKey, "apiKey");
|
|
@@ -2008,6 +2072,9 @@ function textStreamAuthProtocols(apiKey) {
|
|
|
2008
2072
|
}
|
|
2009
2073
|
return ["auth", token];
|
|
2010
2074
|
}
|
|
2075
|
+
function sessionConnectAuthProtocols(apiKey) {
|
|
2076
|
+
return textStreamAuthProtocols(apiKey);
|
|
2077
|
+
}
|
|
2011
2078
|
function buildTextStreamUrl({
|
|
2012
2079
|
baseUrl,
|
|
2013
2080
|
workspaceId: workspaceId2,
|
|
@@ -2083,6 +2150,66 @@ function deriveTextStreamUrl(baseUrl) {
|
|
|
2083
2150
|
url.hash = "";
|
|
2084
2151
|
return url;
|
|
2085
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
|
+
}
|
|
2086
2213
|
function describeInvalidSubprotocolChars(token) {
|
|
2087
2214
|
const chars = /* @__PURE__ */ new Set();
|
|
2088
2215
|
for (const char of token) {
|