@mcpstack/agent-sdk 1.0.0-pr.16.7572c080abaa.13.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.
- package/LICENSE +21 -0
- package/README.md +254 -0
- package/dist/app/index.d.mts +969 -0
- package/dist/app/index.d.ts +969 -0
- package/dist/app/index.js +4025 -0
- package/dist/app/index.js.map +1 -0
- package/dist/app/index.mjs +3977 -0
- package/dist/app/index.mjs.map +1 -0
- package/dist/index.d.mts +639 -0
- package/dist/index.d.ts +639 -0
- package/dist/index.js +2649 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2620 -0
- package/dist/index.mjs.map +1 -0
- package/dist/react/index.d.mts +982 -0
- package/dist/react/index.d.ts +982 -0
- package/dist/react/index.js +4722 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/index.mjs +4700 -0
- package/dist/react/index.mjs.map +1 -0
- package/dist/react-embed/index.d.mts +361 -0
- package/dist/react-embed/index.d.ts +361 -0
- package/dist/react-embed/index.js +6500 -0
- package/dist/react-embed/index.js.map +1 -0
- package/dist/react-embed/index.mjs +6454 -0
- package/dist/react-embed/index.mjs.map +1 -0
- package/dist/react-native/index.d.mts +982 -0
- package/dist/react-native/index.d.ts +982 -0
- package/dist/react-native/index.js +4075 -0
- package/dist/react-native/index.js.map +1 -0
- package/dist/react-native/index.mjs +4053 -0
- package/dist/react-native/index.mjs.map +1 -0
- package/package.json +96 -0
|
@@ -0,0 +1,982 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
interface ClientToolParameter {
|
|
5
|
+
type: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
required?: boolean;
|
|
8
|
+
enum?: string[];
|
|
9
|
+
items?: ClientToolParameter;
|
|
10
|
+
properties?: Record<string, ClientToolParameter>;
|
|
11
|
+
additionalProperties?: boolean | ClientToolParameter;
|
|
12
|
+
}
|
|
13
|
+
interface ClientToolDefinition {
|
|
14
|
+
description: string;
|
|
15
|
+
parameters: Record<string, ClientToolParameter>;
|
|
16
|
+
selection?: ClientToolSelection;
|
|
17
|
+
execute: (params: Record<string, unknown>) => Promise<unknown>;
|
|
18
|
+
}
|
|
19
|
+
type ClientToolsMap$1 = Record<string, ClientToolDefinition>;
|
|
20
|
+
interface ClientToolSelection {
|
|
21
|
+
categories?: string[];
|
|
22
|
+
alwaysInclude?: boolean;
|
|
23
|
+
includeWhen?: string[];
|
|
24
|
+
risk?: 'low' | 'medium' | 'high' | string;
|
|
25
|
+
serverPreferred?: boolean;
|
|
26
|
+
}
|
|
27
|
+
interface McpStackEmbeddedAuthIdentity {
|
|
28
|
+
subject?: string;
|
|
29
|
+
email?: string;
|
|
30
|
+
organizationId?: string;
|
|
31
|
+
displayName?: string;
|
|
32
|
+
avatarUrl?: string;
|
|
33
|
+
}
|
|
34
|
+
interface McpStackEmbeddedAuthConfig {
|
|
35
|
+
hostIdentity?: McpStackEmbeddedAuthIdentity;
|
|
36
|
+
mismatchPolicy: 'block_with_switch';
|
|
37
|
+
}
|
|
38
|
+
interface McpStackAppTokenAuthConfig {
|
|
39
|
+
mode: 'app-token';
|
|
40
|
+
appId?: string;
|
|
41
|
+
getToken: () => Promise<string | undefined> | string | undefined;
|
|
42
|
+
}
|
|
43
|
+
interface McpStackStorageLike {
|
|
44
|
+
getItem(key: string): string | null;
|
|
45
|
+
setItem(key: string, value: string): void;
|
|
46
|
+
removeItem(key: string): void;
|
|
47
|
+
}
|
|
48
|
+
interface AudioTurnDetectionConfig {
|
|
49
|
+
/**
|
|
50
|
+
* Enables SDK-side end-of-speech detection. Defaults to true.
|
|
51
|
+
* When enabled, the SDK commits microphone input after the user has spoken
|
|
52
|
+
* and then paused for `silenceDurationMs`.
|
|
53
|
+
*/
|
|
54
|
+
enabled?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Whether detected end-of-speech should automatically submit the transcript.
|
|
57
|
+
* Defaults to true. Set false for push-to-talk/manual-stop experiences.
|
|
58
|
+
*/
|
|
59
|
+
autoSubmit?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Trailing silence required before the SDK commits audio, in milliseconds.
|
|
62
|
+
* Defaults to 850ms.
|
|
63
|
+
*/
|
|
64
|
+
silenceDurationMs?: number;
|
|
65
|
+
/**
|
|
66
|
+
* Minimum detected speech duration before a turn is considered real speech.
|
|
67
|
+
* Defaults to 180ms to ignore clicks and short bumps.
|
|
68
|
+
*/
|
|
69
|
+
minSpeechDurationMs?: number;
|
|
70
|
+
/**
|
|
71
|
+
* Time to keep listening before speech starts, in milliseconds.
|
|
72
|
+
* Defaults to 12000ms. Set to 0 to disable.
|
|
73
|
+
*/
|
|
74
|
+
noSpeechTimeoutMs?: number;
|
|
75
|
+
/**
|
|
76
|
+
* Absolute RMS threshold from 0 to 1. Defaults to 0.012.
|
|
77
|
+
* The SDK also adapts to the ambient noise floor.
|
|
78
|
+
*/
|
|
79
|
+
speechThreshold?: number;
|
|
80
|
+
/**
|
|
81
|
+
* Multiplier applied to the measured ambient noise floor. Defaults to 2.4.
|
|
82
|
+
*/
|
|
83
|
+
noiseMultiplier?: number;
|
|
84
|
+
}
|
|
85
|
+
interface McpStackAudioInputConfig {
|
|
86
|
+
/**
|
|
87
|
+
* SDK-owned turn detection configuration. Consumer apps can tune it, but
|
|
88
|
+
* they do not need to implement their own microphone VAD.
|
|
89
|
+
*/
|
|
90
|
+
turnDetection?: AudioTurnDetectionConfig;
|
|
91
|
+
}
|
|
92
|
+
interface McpStackAgentConfig {
|
|
93
|
+
/** API key for authenticating with the MCP Stack API */
|
|
94
|
+
apiKey: string;
|
|
95
|
+
/** Agent ID from the MCP Stack dashboard */
|
|
96
|
+
agentId: string;
|
|
97
|
+
/** MCP Stack API URL. Defaults to https://api.mcpstack.com */
|
|
98
|
+
agentServiceUrl?: string;
|
|
99
|
+
/**
|
|
100
|
+
* Callback URL used by the standalone popup OAuth flow.
|
|
101
|
+
* Defaults to the hosted MCP Stack callback page so downstream auth servers
|
|
102
|
+
* only need to allow a single redirect URI.
|
|
103
|
+
*/
|
|
104
|
+
oauthCallbackUrl?: string;
|
|
105
|
+
/**
|
|
106
|
+
* Public URL for this client's hosted metadata document when using
|
|
107
|
+
* Client ID Metadata Documents (CIMD).
|
|
108
|
+
*/
|
|
109
|
+
oauthClientMetadataUrl?: string;
|
|
110
|
+
/**
|
|
111
|
+
* Callback to get the auth token for MCP Stack API requests.
|
|
112
|
+
* If provided, called before each chat API request.
|
|
113
|
+
* Use this when your session token may expire and needs refresh (e.g., dashboard playground).
|
|
114
|
+
* If not provided, uses the static `apiKey` value.
|
|
115
|
+
*/
|
|
116
|
+
getAuthToken?: () => Promise<string | undefined>;
|
|
117
|
+
/**
|
|
118
|
+
* Host app auth-session boundary for persisted MCP auth state.
|
|
119
|
+
* Use the current app session id so logging out forces MCP reconnect,
|
|
120
|
+
* even when the same browser later signs back in as the same user.
|
|
121
|
+
*/
|
|
122
|
+
authSessionKey?: string | null;
|
|
123
|
+
/**
|
|
124
|
+
* Embedded popup auth settings.
|
|
125
|
+
* Use this to tell MCP Stack which host-app user is currently signed in so
|
|
126
|
+
* the built-in popup flow can prefer the same downstream account.
|
|
127
|
+
*/
|
|
128
|
+
embeddedAuth?: McpStackEmbeddedAuthConfig;
|
|
129
|
+
/**
|
|
130
|
+
* App-owned MCP auth for embedded products.
|
|
131
|
+
* Use this when your app already authenticated the user and can return a
|
|
132
|
+
* short-lived app access token. The SDK exchanges that token at Gateway for
|
|
133
|
+
* an MCP-facing token without opening a second sign-in window.
|
|
134
|
+
*/
|
|
135
|
+
auth?: McpStackAppTokenAuthConfig;
|
|
136
|
+
/**
|
|
137
|
+
* If true, MCP server calls include cookies (for cookie-based auth).
|
|
138
|
+
* Default: false
|
|
139
|
+
*/
|
|
140
|
+
useCookies?: boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Called when an MCP server requires authentication and the built-in
|
|
143
|
+
* popup flow is not being used. The SDK will invoke this so the
|
|
144
|
+
* integrator can trigger a custom login flow.
|
|
145
|
+
*
|
|
146
|
+
* Return the token response on success, or undefined to cancel.
|
|
147
|
+
* The SDK stores the token and handles refresh automatically.
|
|
148
|
+
*/
|
|
149
|
+
onAuthRequired?: (mcpServerUrl: string, authConfig: McpServerAuthConfig) => Promise<OAuthTokenResponse | undefined>;
|
|
150
|
+
/** Optional: external user ID to associate with conversations */
|
|
151
|
+
externalUserId?: string;
|
|
152
|
+
/** Optional: additional context sent with each message */
|
|
153
|
+
context?: Record<string, unknown>;
|
|
154
|
+
/** Optional: microphone input behavior. */
|
|
155
|
+
audioInput?: McpStackAudioInputConfig;
|
|
156
|
+
/**
|
|
157
|
+
* Optional: resume an existing server-side conversation on init.
|
|
158
|
+
* Use this with persisted conversation ids in the host app.
|
|
159
|
+
*/
|
|
160
|
+
initialConversationId?: string | null;
|
|
161
|
+
/**
|
|
162
|
+
* Page size for conversation replay bootstrap and older-message loading.
|
|
163
|
+
* Default: 50
|
|
164
|
+
*/
|
|
165
|
+
conversationHistoryPageSize?: number;
|
|
166
|
+
/**
|
|
167
|
+
* Client tools — execute locally in browser, exposed to LLM.
|
|
168
|
+
* The agent can call these to interact with the host app (e.g. fill forms, read page state).
|
|
169
|
+
*/
|
|
170
|
+
clientTools?: ClientToolsMap$1;
|
|
171
|
+
/**
|
|
172
|
+
* Optional persistent storage override used for MCP auth/session artifacts.
|
|
173
|
+
* If omitted, the runtime falls back to `localStorage` when available.
|
|
174
|
+
*/
|
|
175
|
+
storage?: McpStackStorageLike | null;
|
|
176
|
+
}
|
|
177
|
+
interface ChatMessage {
|
|
178
|
+
id: string;
|
|
179
|
+
role: 'user' | 'assistant' | 'tool_call' | 'tool_result' | 'error';
|
|
180
|
+
content: string;
|
|
181
|
+
toolName?: string;
|
|
182
|
+
toolLabel?: string;
|
|
183
|
+
toolCallId?: string;
|
|
184
|
+
timestamp: Date;
|
|
185
|
+
toolCallStatus?: 'calling' | 'completed' | 'error';
|
|
186
|
+
toolCallStartTime?: number;
|
|
187
|
+
toolCallDuration?: number;
|
|
188
|
+
toolResult?: string;
|
|
189
|
+
toolError?: string;
|
|
190
|
+
errorCode?: string;
|
|
191
|
+
metadataJson?: string | null;
|
|
192
|
+
}
|
|
193
|
+
interface ConversationReplayMessage {
|
|
194
|
+
id: string;
|
|
195
|
+
sequenceNumber: number;
|
|
196
|
+
role: ChatMessage['role'];
|
|
197
|
+
content?: string | null;
|
|
198
|
+
createdAt: string;
|
|
199
|
+
toolName?: string | null;
|
|
200
|
+
toolLabel?: string | null;
|
|
201
|
+
toolCallId?: string | null;
|
|
202
|
+
toolCallStatus?: 'calling' | 'completed' | 'error' | null;
|
|
203
|
+
toolCallDurationMs?: number | null;
|
|
204
|
+
toolArgumentsJson?: string | null;
|
|
205
|
+
toolResultJson?: string | null;
|
|
206
|
+
toolError?: string | null;
|
|
207
|
+
errorCode?: string | null;
|
|
208
|
+
metadataJson?: string | null;
|
|
209
|
+
}
|
|
210
|
+
interface ConversationMessagesPage {
|
|
211
|
+
conversationId: string;
|
|
212
|
+
messages: ConversationReplayMessage[];
|
|
213
|
+
pageSize: number;
|
|
214
|
+
nextCursor?: string | null;
|
|
215
|
+
hasNextPage: boolean;
|
|
216
|
+
}
|
|
217
|
+
type ConversationFeedbackSentiment = 'up' | 'down';
|
|
218
|
+
interface SubmitConversationFeedbackRequest {
|
|
219
|
+
sentiment: ConversationFeedbackSentiment;
|
|
220
|
+
comment?: string;
|
|
221
|
+
source?: string;
|
|
222
|
+
toolCallId?: string;
|
|
223
|
+
conversationMessageId?: string;
|
|
224
|
+
metadata?: Record<string, unknown>;
|
|
225
|
+
}
|
|
226
|
+
interface ConversationFeedback {
|
|
227
|
+
id: string;
|
|
228
|
+
conversationId: string;
|
|
229
|
+
sentiment: ConversationFeedbackSentiment;
|
|
230
|
+
comment?: string | null;
|
|
231
|
+
source: string;
|
|
232
|
+
toolCallId?: string | null;
|
|
233
|
+
conversationMessageId?: string | null;
|
|
234
|
+
metadataJson?: string | null;
|
|
235
|
+
createdAt: string;
|
|
236
|
+
}
|
|
237
|
+
interface McpServerAuthConfig {
|
|
238
|
+
authType: 'none' | 'apiKey' | 'bearer' | 'oauth2';
|
|
239
|
+
issuer?: string;
|
|
240
|
+
authorizationServerUrl?: string;
|
|
241
|
+
authorizationServerMetadataUrl?: string;
|
|
242
|
+
authorizationEndpoint?: string;
|
|
243
|
+
loginUrl?: string;
|
|
244
|
+
tokenEndpoint?: string;
|
|
245
|
+
tokenUrl?: string;
|
|
246
|
+
registrationEndpoint?: string;
|
|
247
|
+
clientId?: string;
|
|
248
|
+
scopes?: string[];
|
|
249
|
+
resource?: string;
|
|
250
|
+
callbackUrl?: string;
|
|
251
|
+
protectedResourceMetadataUrl?: string;
|
|
252
|
+
clientIdMetadataDocumentSupported?: boolean;
|
|
253
|
+
resourceParameterSupported?: boolean;
|
|
254
|
+
registrationPreference?: McpClientRegistrationPreference;
|
|
255
|
+
clientMode?: McpResolvedClientMode;
|
|
256
|
+
authRecipe?: McpAuthRecipe;
|
|
257
|
+
manualOverrides?: string[];
|
|
258
|
+
discovered?: boolean;
|
|
259
|
+
}
|
|
260
|
+
type McpAuthRecipe = 'sqlos' | 'auth0' | 'entra' | 'workos' | 'manual';
|
|
261
|
+
type McpClientRegistrationPreference = 'auto' | 'preregistered' | 'cimd' | 'dcr' | 'manual';
|
|
262
|
+
type McpResolvedClientMode = 'preregistered' | 'cimd' | 'dcr' | 'manual';
|
|
263
|
+
/** OAuth token response from token endpoint */
|
|
264
|
+
interface OAuthTokenResponse {
|
|
265
|
+
accessToken: string;
|
|
266
|
+
refreshToken?: string;
|
|
267
|
+
expiresIn?: number;
|
|
268
|
+
tokenType?: string;
|
|
269
|
+
resolvedAuthConfig?: McpServerAuthConfig;
|
|
270
|
+
}
|
|
271
|
+
interface McpServerInfo {
|
|
272
|
+
id: string;
|
|
273
|
+
name: string;
|
|
274
|
+
url: string;
|
|
275
|
+
authStatus: 'connected' | 'needs_auth';
|
|
276
|
+
authConfig?: McpServerAuthConfig | null;
|
|
277
|
+
}
|
|
278
|
+
interface AgentConfigResponse {
|
|
279
|
+
agentId: string;
|
|
280
|
+
name: string;
|
|
281
|
+
conversationResumeVersion: string;
|
|
282
|
+
/** @deprecated Use mcpServers instead */
|
|
283
|
+
mcpServerUrl?: string;
|
|
284
|
+
mcpServers: McpServerInfo[];
|
|
285
|
+
widgetConfig?: WidgetConfig | null;
|
|
286
|
+
modelConfig?: AgentPublicModelConfig | null;
|
|
287
|
+
audio?: AgentPublicAudioConfig | null;
|
|
288
|
+
}
|
|
289
|
+
interface AgentModelCapabilities {
|
|
290
|
+
textInput?: boolean;
|
|
291
|
+
textOutput?: boolean;
|
|
292
|
+
audioInput?: boolean;
|
|
293
|
+
audioOutput?: boolean;
|
|
294
|
+
realtime?: boolean;
|
|
295
|
+
toolCalls?: boolean;
|
|
296
|
+
text?: boolean;
|
|
297
|
+
realtimeAudioInput?: boolean;
|
|
298
|
+
realtimeAudioOutput?: boolean;
|
|
299
|
+
transcription?: boolean;
|
|
300
|
+
translation?: boolean;
|
|
301
|
+
}
|
|
302
|
+
interface AgentPublicModelConfig {
|
|
303
|
+
id: string;
|
|
304
|
+
provider: string;
|
|
305
|
+
displayName: string;
|
|
306
|
+
capabilities: AgentModelCapabilities;
|
|
307
|
+
}
|
|
308
|
+
interface AgentPublicAudioConfig {
|
|
309
|
+
inputEnabled: boolean;
|
|
310
|
+
outputEnabled: boolean;
|
|
311
|
+
maxSessionSeconds: number;
|
|
312
|
+
transcriptionModel?: string | null;
|
|
313
|
+
}
|
|
314
|
+
interface WidgetConfig {
|
|
315
|
+
theme?: string;
|
|
316
|
+
position?: string;
|
|
317
|
+
title?: string;
|
|
318
|
+
placeholder?: string;
|
|
319
|
+
welcomeMessage?: string;
|
|
320
|
+
}
|
|
321
|
+
interface SseContentDelta {
|
|
322
|
+
text: string;
|
|
323
|
+
}
|
|
324
|
+
interface SseToolCall {
|
|
325
|
+
toolCallId: string;
|
|
326
|
+
toolName: string;
|
|
327
|
+
toolLabel?: string;
|
|
328
|
+
arguments: Record<string, unknown>;
|
|
329
|
+
mcpServerUrl?: string;
|
|
330
|
+
mcpServerName?: string;
|
|
331
|
+
/** When 'client', execute locally via clientTools; when 'mcp' or absent with mcpServerUrl, use MCP */
|
|
332
|
+
source?: 'client' | 'mcp';
|
|
333
|
+
}
|
|
334
|
+
interface SseMessageEnd {
|
|
335
|
+
inputTokens: number;
|
|
336
|
+
outputTokens: number;
|
|
337
|
+
toolCalls: number;
|
|
338
|
+
}
|
|
339
|
+
interface AgentBudgetSnapshot {
|
|
340
|
+
enabled: boolean;
|
|
341
|
+
currency: string;
|
|
342
|
+
identityType: 'identified' | 'anonymous' | string;
|
|
343
|
+
externalUserId: string;
|
|
344
|
+
displayName: string;
|
|
345
|
+
budgetSource: 'explicit' | 'default_user' | 'anonymous' | 'none' | string;
|
|
346
|
+
windowStartUtc: string;
|
|
347
|
+
windowEndUtc: string;
|
|
348
|
+
agentMonthlyBudgetUsd?: number | null;
|
|
349
|
+
agentCurrentMonthSpendUsd: number;
|
|
350
|
+
agentRemainingBudgetUsd?: number | null;
|
|
351
|
+
userMonthlyBudgetUsd?: number | null;
|
|
352
|
+
userCurrentMonthSpendUsd: number;
|
|
353
|
+
userRemainingBudgetUsd?: number | null;
|
|
354
|
+
organizationCreditsRemainingUsd?: number | null;
|
|
355
|
+
effectiveRemainingUsd?: number | null;
|
|
356
|
+
status: 'healthy' | 'warning' | 'blocked' | 'disabled' | string;
|
|
357
|
+
}
|
|
358
|
+
interface SseError {
|
|
359
|
+
code: string;
|
|
360
|
+
message: string;
|
|
361
|
+
budget?: AgentBudgetSnapshot | null;
|
|
362
|
+
}
|
|
363
|
+
type AudioInputStatus = 'idle' | 'requesting_permission' | 'connecting' | 'listening' | 'transcribing' | 'sending' | 'error';
|
|
364
|
+
interface AudioInputState {
|
|
365
|
+
status: AudioInputStatus;
|
|
366
|
+
isSupported: boolean;
|
|
367
|
+
isEnabled: boolean;
|
|
368
|
+
transcript: string;
|
|
369
|
+
partialTranscript: string;
|
|
370
|
+
error: SseError | null;
|
|
371
|
+
sessionId?: string | null;
|
|
372
|
+
conversationId?: string | null;
|
|
373
|
+
maxSessionSeconds?: number | null;
|
|
374
|
+
inputLevel?: number;
|
|
375
|
+
isSpeaking?: boolean;
|
|
376
|
+
speechMs?: number;
|
|
377
|
+
silenceMs?: number;
|
|
378
|
+
autoSubmitEnabled?: boolean;
|
|
379
|
+
}
|
|
380
|
+
interface AudioTranscriptDeltaEvent {
|
|
381
|
+
text: string;
|
|
382
|
+
transcript: string;
|
|
383
|
+
isFinal: false;
|
|
384
|
+
}
|
|
385
|
+
interface AudioTranscriptFinalEvent {
|
|
386
|
+
text: string;
|
|
387
|
+
transcript: string;
|
|
388
|
+
conversationId: string;
|
|
389
|
+
}
|
|
390
|
+
interface AudioActivityEvent {
|
|
391
|
+
inputLevel: number;
|
|
392
|
+
noiseFloor: number;
|
|
393
|
+
isSpeaking: boolean;
|
|
394
|
+
speechMs: number;
|
|
395
|
+
silenceMs: number;
|
|
396
|
+
}
|
|
397
|
+
interface McpAuthStatusEvent {
|
|
398
|
+
mcpServerUrl: string;
|
|
399
|
+
mcpServerName: string;
|
|
400
|
+
authStatus: 'connected' | 'needs_auth';
|
|
401
|
+
}
|
|
402
|
+
type McpStackAgentEventMap = {
|
|
403
|
+
message: ChatMessage;
|
|
404
|
+
content_delta: SseContentDelta;
|
|
405
|
+
tool_call: SseToolCall;
|
|
406
|
+
tool_result: {
|
|
407
|
+
toolCallId: string;
|
|
408
|
+
result: unknown;
|
|
409
|
+
duration: number;
|
|
410
|
+
};
|
|
411
|
+
tool_error: {
|
|
412
|
+
toolCallId: string;
|
|
413
|
+
error: string;
|
|
414
|
+
duration: number;
|
|
415
|
+
};
|
|
416
|
+
message_end: SseMessageEnd;
|
|
417
|
+
budget_snapshot: AgentBudgetSnapshot;
|
|
418
|
+
error: SseError;
|
|
419
|
+
loading: boolean;
|
|
420
|
+
thinking: boolean;
|
|
421
|
+
mcp_auth_status: McpAuthStatusEvent;
|
|
422
|
+
audio_state: AudioInputState;
|
|
423
|
+
audio_activity: AudioActivityEvent;
|
|
424
|
+
audio_transcript_delta: AudioTranscriptDeltaEvent;
|
|
425
|
+
audio_transcript_final: AudioTranscriptFinalEvent;
|
|
426
|
+
};
|
|
427
|
+
type McpStackAgentEvent = keyof McpStackAgentEventMap;
|
|
428
|
+
|
|
429
|
+
type ClientToolsMap = ClientToolsMap$1;
|
|
430
|
+
type AppAgentUserIdentity = McpStackEmbeddedAuthIdentity;
|
|
431
|
+
interface KeyValueStore {
|
|
432
|
+
getItem(key: string): Promise<string | null> | string | null;
|
|
433
|
+
setItem(key: string, value: string): Promise<void> | void;
|
|
434
|
+
removeItem(key: string): Promise<void> | void;
|
|
435
|
+
}
|
|
436
|
+
interface OAuthSessionRequest {
|
|
437
|
+
authorizeUrl: string;
|
|
438
|
+
redirectUri: string;
|
|
439
|
+
preferEphemeralSession?: boolean;
|
|
440
|
+
}
|
|
441
|
+
type OAuthSessionResult = {
|
|
442
|
+
type: 'success';
|
|
443
|
+
url: string;
|
|
444
|
+
} | {
|
|
445
|
+
type: 'cancel' | 'dismiss';
|
|
446
|
+
} | {
|
|
447
|
+
type: 'error';
|
|
448
|
+
message?: string;
|
|
449
|
+
};
|
|
450
|
+
interface AppAgentPlatform {
|
|
451
|
+
storage?: {
|
|
452
|
+
durable: KeyValueStore;
|
|
453
|
+
secure?: KeyValueStore;
|
|
454
|
+
};
|
|
455
|
+
auth?: {
|
|
456
|
+
openOAuthSession(request: OAuthSessionRequest): Promise<OAuthSessionResult>;
|
|
457
|
+
dismissOAuthSession?(): Promise<void> | void;
|
|
458
|
+
};
|
|
459
|
+
lifecycle?: {
|
|
460
|
+
onForegroundChange?(listener: (isForeground: boolean) => void): () => void;
|
|
461
|
+
onConnectivityChange?(listener: (isOnline: boolean) => void): () => void;
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
interface AppAgentApproval {
|
|
465
|
+
id: string;
|
|
466
|
+
title: string;
|
|
467
|
+
rationale?: string;
|
|
468
|
+
steps: string[];
|
|
469
|
+
toolCallId?: string | null;
|
|
470
|
+
confirmLabel?: string;
|
|
471
|
+
cancelLabel?: string;
|
|
472
|
+
}
|
|
473
|
+
interface AppAgentInputOption {
|
|
474
|
+
label: string;
|
|
475
|
+
value: string;
|
|
476
|
+
}
|
|
477
|
+
interface AppAgentInputField {
|
|
478
|
+
key: string;
|
|
479
|
+
label: string;
|
|
480
|
+
kind: 'text' | 'textarea' | 'number' | 'select' | 'boolean';
|
|
481
|
+
required?: boolean;
|
|
482
|
+
placeholder?: string;
|
|
483
|
+
options?: AppAgentInputOption[];
|
|
484
|
+
}
|
|
485
|
+
interface AppAgentInputRequest {
|
|
486
|
+
id: string;
|
|
487
|
+
title: string;
|
|
488
|
+
prompt?: string;
|
|
489
|
+
fields: AppAgentInputField[];
|
|
490
|
+
toolCallId?: string | null;
|
|
491
|
+
submitLabel?: string;
|
|
492
|
+
cancelLabel?: string;
|
|
493
|
+
}
|
|
494
|
+
interface AppAgentIssue {
|
|
495
|
+
code: 'stale_conversation' | 'runtime_error' | 'config_error';
|
|
496
|
+
message: string;
|
|
497
|
+
recoverable: boolean;
|
|
498
|
+
}
|
|
499
|
+
interface AppAgentFeedbackState {
|
|
500
|
+
isSubmitting: boolean;
|
|
501
|
+
error: string | null;
|
|
502
|
+
lastSubmittedAt: string | null;
|
|
503
|
+
lastFeedback: ConversationFeedback | null;
|
|
504
|
+
}
|
|
505
|
+
interface AppAgentConnection {
|
|
506
|
+
url: string;
|
|
507
|
+
name: string;
|
|
508
|
+
authStatus: 'connected' | 'needs_auth';
|
|
509
|
+
canSignOut: boolean;
|
|
510
|
+
}
|
|
511
|
+
interface AppAgentConfig {
|
|
512
|
+
apiKey: string;
|
|
513
|
+
agentId: string;
|
|
514
|
+
serviceUrl?: string;
|
|
515
|
+
initialConnections?: AppAgentConnection[];
|
|
516
|
+
oauthCallbackUrl?: string;
|
|
517
|
+
oauthClientMetadataUrl?: string;
|
|
518
|
+
getAuthToken?: () => Promise<string | undefined>;
|
|
519
|
+
appSessionKey?: string | null;
|
|
520
|
+
userIdentity?: AppAgentUserIdentity;
|
|
521
|
+
auth?: McpStackAppTokenAuthConfig;
|
|
522
|
+
useCookies?: boolean;
|
|
523
|
+
externalUserId?: string;
|
|
524
|
+
appContext?: Record<string, unknown>;
|
|
525
|
+
clientTools?: ClientToolsMap;
|
|
526
|
+
platform?: AppAgentPlatform;
|
|
527
|
+
onAuthRequired?: (mcpServerUrl: string, authConfig: McpServerAuthConfig) => Promise<OAuthTokenResponse | undefined>;
|
|
528
|
+
conversation?: {
|
|
529
|
+
namespace?: string;
|
|
530
|
+
historyPageSize?: number;
|
|
531
|
+
};
|
|
532
|
+
feedbackSource?: string;
|
|
533
|
+
storage?: McpStackStorageLike | null;
|
|
534
|
+
}
|
|
535
|
+
interface AppAgentLifecycleState {
|
|
536
|
+
isReady: boolean;
|
|
537
|
+
isLoading: boolean;
|
|
538
|
+
isLoadingHistory: boolean;
|
|
539
|
+
isThinking: boolean;
|
|
540
|
+
hasOlderMessages: boolean;
|
|
541
|
+
error: SseError | null;
|
|
542
|
+
issue: AppAgentIssue | null;
|
|
543
|
+
}
|
|
544
|
+
interface AppAgentSnapshotBase {
|
|
545
|
+
runtime: {
|
|
546
|
+
agent: unknown;
|
|
547
|
+
agentConfig: AgentConfigResponse | null;
|
|
548
|
+
};
|
|
549
|
+
conversation: AppAgentLifecycleState & {
|
|
550
|
+
id: string | null;
|
|
551
|
+
messages: ChatMessage[];
|
|
552
|
+
streamingContent: string;
|
|
553
|
+
statusLabel: string;
|
|
554
|
+
resumeKey: string | null;
|
|
555
|
+
};
|
|
556
|
+
connections: {
|
|
557
|
+
items: AppAgentConnection[];
|
|
558
|
+
needsAttention: boolean;
|
|
559
|
+
};
|
|
560
|
+
approvals: {
|
|
561
|
+
pending: AppAgentApproval[];
|
|
562
|
+
};
|
|
563
|
+
requests: {
|
|
564
|
+
pending: AppAgentInputRequest[];
|
|
565
|
+
};
|
|
566
|
+
feedback: AppAgentFeedbackState;
|
|
567
|
+
budget: AgentBudgetSnapshot | null;
|
|
568
|
+
voice: AudioInputState;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
type EventHandler<T> = (data: T) => void;
|
|
572
|
+
/**
|
|
573
|
+
* Core orchestration class for the MCP Stack Agent SDK.
|
|
574
|
+
* Framework-agnostic — works in any JavaScript environment.
|
|
575
|
+
*
|
|
576
|
+
* Handles:
|
|
577
|
+
* - Communication with the MCP Stack chat API (SSE streaming)
|
|
578
|
+
* - Tool execution via MCP server (browser-side, with user's auth token)
|
|
579
|
+
* - Conversation state management
|
|
580
|
+
* - Event emission for UI updates
|
|
581
|
+
*/
|
|
582
|
+
declare class McpStackAgent {
|
|
583
|
+
private config;
|
|
584
|
+
private agentConfig;
|
|
585
|
+
private budgetSnapshot;
|
|
586
|
+
private conversationId;
|
|
587
|
+
private messages;
|
|
588
|
+
private historyCursor;
|
|
589
|
+
private hasOlderMessages;
|
|
590
|
+
private isLoadingHistory;
|
|
591
|
+
private abortController;
|
|
592
|
+
private isLoading;
|
|
593
|
+
private listeners;
|
|
594
|
+
/** Per-server MCP session tracking */
|
|
595
|
+
private mcpSessions;
|
|
596
|
+
/** OAuth tokens per MCP server URL (standalone mode only) */
|
|
597
|
+
private oauthTokens;
|
|
598
|
+
/** Servers explicitly disconnected by the user and awaiting manual re-auth */
|
|
599
|
+
private manuallySignedOutServers;
|
|
600
|
+
private audioState;
|
|
601
|
+
private audioStream;
|
|
602
|
+
private audioContext;
|
|
603
|
+
private audioSource;
|
|
604
|
+
private audioProcessor;
|
|
605
|
+
private audioSilentGain;
|
|
606
|
+
private audioSocket;
|
|
607
|
+
private audioSessionTimer;
|
|
608
|
+
private audioSessionStopRequested;
|
|
609
|
+
private audioFinalTranscript;
|
|
610
|
+
private audioTurnState;
|
|
611
|
+
constructor(config: McpStackAgentConfig);
|
|
612
|
+
private resolveAuthToken;
|
|
613
|
+
/** Initialize: fetch agent config (tools, widget settings, MCP servers) */
|
|
614
|
+
init(): Promise<AgentConfigResponse>;
|
|
615
|
+
/** Get current MCP server auth statuses */
|
|
616
|
+
getMcpServers(): Array<{
|
|
617
|
+
url: string;
|
|
618
|
+
name: string;
|
|
619
|
+
authStatus: 'connected' | 'needs_auth';
|
|
620
|
+
canSignOut: boolean;
|
|
621
|
+
}>;
|
|
622
|
+
/** Send a message and process the full orchestration loop (including tool calls) */
|
|
623
|
+
sendMessage(message: string): Promise<void>;
|
|
624
|
+
/** Start a new conversation */
|
|
625
|
+
newConversation(): void;
|
|
626
|
+
/** Cancel the current in-flight request */
|
|
627
|
+
cancel(): void;
|
|
628
|
+
/** Get all messages in the current conversation */
|
|
629
|
+
getMessages(): ChatMessage[];
|
|
630
|
+
/** Get the current conversation ID */
|
|
631
|
+
getConversationId(): string | null;
|
|
632
|
+
getHasOlderMessages(): boolean;
|
|
633
|
+
getIsLoadingHistory(): boolean;
|
|
634
|
+
/** Get the loaded agent config */
|
|
635
|
+
getAgentConfig(): AgentConfigResponse | null;
|
|
636
|
+
getAudioInputState(): AudioInputState;
|
|
637
|
+
startVoiceInput(): Promise<void>;
|
|
638
|
+
stopVoiceInput(): Promise<void>;
|
|
639
|
+
cancelVoiceInput(): void;
|
|
640
|
+
loadConversation(conversationId: string, pageSize?: number): Promise<ConversationMessagesPage>;
|
|
641
|
+
loadOlderMessages(pageSize?: number): Promise<ConversationMessagesPage | null>;
|
|
642
|
+
submitFeedback(input: SubmitConversationFeedbackRequest): Promise<ConversationFeedback>;
|
|
643
|
+
/** Convert client tools to the API schema format. */
|
|
644
|
+
private clientToolsToSchemas;
|
|
645
|
+
private resolveExternalUserId;
|
|
646
|
+
private buildExternalUserContext;
|
|
647
|
+
/** Latest runtime budget snapshot for the current SDK identity. */
|
|
648
|
+
getBudgetSnapshot(): AgentBudgetSnapshot | null;
|
|
649
|
+
/** Refresh the current SDK identity's budget snapshot from the API. */
|
|
650
|
+
refreshBudgetSnapshot(): Promise<AgentBudgetSnapshot | null>;
|
|
651
|
+
/** Whether a request is currently in flight */
|
|
652
|
+
getIsLoading(): boolean;
|
|
653
|
+
/** Update the per-turn app context sent with each chat request. */
|
|
654
|
+
setAppContext(context: Record<string, unknown> | undefined): void;
|
|
655
|
+
/** Update the client tools exposed to the agent without recreating the session. */
|
|
656
|
+
setClientTools(clientTools: ClientToolsMap$1 | undefined): void;
|
|
657
|
+
/**
|
|
658
|
+
* Proactively authenticate with an MCP server before sending a message.
|
|
659
|
+
* If a token response is provided directly, it is stored immediately.
|
|
660
|
+
* Otherwise, this uses the configured OAuth flow and verifies via MCP init.
|
|
661
|
+
*
|
|
662
|
+
* @param mcpServerUrl - The MCP server URL to authenticate with
|
|
663
|
+
* @param tokenResponse - Optional: provide token response directly (from OAuth popup)
|
|
664
|
+
*/
|
|
665
|
+
authenticate(mcpServerUrl: string, tokenResponse?: OAuthTokenResponse): Promise<boolean>;
|
|
666
|
+
/** Disconnect from an MCP server and require explicit re-authentication before reuse. */
|
|
667
|
+
signOutMcpServer(mcpServerUrl: string): Promise<void>;
|
|
668
|
+
/** Get the auth config for an MCP server (from agent config) */
|
|
669
|
+
getServerAuthConfig(mcpServerUrl: string): McpServerAuthConfig | null;
|
|
670
|
+
getOAuthCallbackUrl(): string;
|
|
671
|
+
getOAuthClientMetadataUrl(): string;
|
|
672
|
+
private getDefaultAuthRequiredHandler;
|
|
673
|
+
setOnAuthRequired(onAuthRequired: McpStackAgentConfig['onAuthRequired']): void;
|
|
674
|
+
private isAudioInputSupported;
|
|
675
|
+
private isAudioInputEnabled;
|
|
676
|
+
private isAudioAutoSubmitEnabled;
|
|
677
|
+
private getAudioTurnDetectionConfig;
|
|
678
|
+
private clampNumber;
|
|
679
|
+
private buildAudioState;
|
|
680
|
+
private setAudioState;
|
|
681
|
+
private getAudioContextConstructor;
|
|
682
|
+
private createRealtimeTranscriptionSession;
|
|
683
|
+
private buildApiError;
|
|
684
|
+
private openAudioSocket;
|
|
685
|
+
private normalizeAudioSocketUrl;
|
|
686
|
+
private bindAudioSocket;
|
|
687
|
+
private handleAudioSocketMessage;
|
|
688
|
+
private commitVoiceInput;
|
|
689
|
+
private stopVoiceInputWithoutTranscript;
|
|
690
|
+
private createAudioTurnState;
|
|
691
|
+
private analyzeAudioFrame;
|
|
692
|
+
private processAudioTurnActivity;
|
|
693
|
+
private updateNoiseFloor;
|
|
694
|
+
private emitAudioActivity;
|
|
695
|
+
private startAudioCapture;
|
|
696
|
+
private resampleToPcm16;
|
|
697
|
+
private floatToPcm16;
|
|
698
|
+
private pcm16ToBase64;
|
|
699
|
+
private cleanupAudioCapture;
|
|
700
|
+
private clearAudioSessionTimer;
|
|
701
|
+
private extractErrorCode;
|
|
702
|
+
private getPersistentStorage;
|
|
703
|
+
private resolveOAuthClientRegistration;
|
|
704
|
+
/** Subscribe to events */
|
|
705
|
+
on<K extends McpStackAgentEvent>(event: K, handler: EventHandler<McpStackAgentEventMap[K]>): void;
|
|
706
|
+
/** Unsubscribe from events */
|
|
707
|
+
off<K extends McpStackAgentEvent>(event: K, handler: EventHandler<McpStackAgentEventMap[K]>): void;
|
|
708
|
+
private buildProtectedResourceMetadataCandidates;
|
|
709
|
+
private hasSameOrigin;
|
|
710
|
+
private extractQuotedHeaderValue;
|
|
711
|
+
private buildAuthorizationServerMetadataCandidates;
|
|
712
|
+
private hasExplicitManualOverride;
|
|
713
|
+
private pickAuthConfigValue;
|
|
714
|
+
private pickAuthConfigArrayValue;
|
|
715
|
+
private mergeAuthConfigs;
|
|
716
|
+
private discoverAuthConfig;
|
|
717
|
+
private resolveServerAuthConfig;
|
|
718
|
+
private ensureServerAuthConfig;
|
|
719
|
+
private updateServerAuthConfig;
|
|
720
|
+
private emit;
|
|
721
|
+
/** Generate the legacy token cache suffix used before auth-aware keying. */
|
|
722
|
+
private hashUrl;
|
|
723
|
+
private getLegacyTokenStorageKey;
|
|
724
|
+
private getAuthSessionKey;
|
|
725
|
+
private getTokenStorageKey;
|
|
726
|
+
private getTokenStorageCandidates;
|
|
727
|
+
/** Load OAuth token from memory/persistent storage using auth-aware cache keying. */
|
|
728
|
+
private loadOAuthToken;
|
|
729
|
+
/** Check if we have a valid (non-expired) OAuth token */
|
|
730
|
+
private hasValidOAuthToken;
|
|
731
|
+
/** Store OAuth token to memory and persistent storage */
|
|
732
|
+
private storeOAuthToken;
|
|
733
|
+
/** Clear OAuth token from memory and persistent storage */
|
|
734
|
+
private clearOAuthToken;
|
|
735
|
+
/** Refresh OAuth token using refresh token */
|
|
736
|
+
private refreshOAuthToken;
|
|
737
|
+
/**
|
|
738
|
+
* Resolve the auth token for an MCP server.
|
|
739
|
+
* - OAuth mode: Checks stored token, refreshes if expired, triggers auth if needed
|
|
740
|
+
*/
|
|
741
|
+
private resolveToken;
|
|
742
|
+
/**
|
|
743
|
+
* The core orchestration loop:
|
|
744
|
+
* 1. Send message to chat API
|
|
745
|
+
* 2. Stream response
|
|
746
|
+
* 3. If tool_call → execute tool via MCP → send result → continue
|
|
747
|
+
* 4. If message_end → done
|
|
748
|
+
*/
|
|
749
|
+
private runChatLoop;
|
|
750
|
+
private callChatApi;
|
|
751
|
+
private fetchConversationMessages;
|
|
752
|
+
private applyConversationPage;
|
|
753
|
+
private mapReplayMessage;
|
|
754
|
+
/**
|
|
755
|
+
* Process an SSE stream from the chat API.
|
|
756
|
+
* Returns when the stream ends (either message_end or tool_call).
|
|
757
|
+
*/
|
|
758
|
+
private processSseStream;
|
|
759
|
+
/** Build headers for MCP server requests */
|
|
760
|
+
private getMcpHeaders;
|
|
761
|
+
/** Best-effort MCP session teardown so reconnect starts cleanly after sign-out. */
|
|
762
|
+
private closeMcpSession;
|
|
763
|
+
/** Initialize the MCP session for a specific server (required before tools/call) */
|
|
764
|
+
private initMcpSession;
|
|
765
|
+
/** Update auth status for an MCP server and emit event */
|
|
766
|
+
private updateMcpAuthStatus;
|
|
767
|
+
/** Parse a JSON-RPC response from either JSON or SSE format */
|
|
768
|
+
private parseMcpResponse;
|
|
769
|
+
private executeTool;
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
type AppAgentToolCallMessage = ChatMessage & {
|
|
773
|
+
role: 'tool_call';
|
|
774
|
+
};
|
|
775
|
+
type AppAgentAssistantMessage = ChatMessage & {
|
|
776
|
+
role: 'assistant';
|
|
777
|
+
};
|
|
778
|
+
type AppAgentUserMessage = ChatMessage & {
|
|
779
|
+
role: 'user';
|
|
780
|
+
};
|
|
781
|
+
type AppAgentErrorMessage = ChatMessage & {
|
|
782
|
+
role: 'error';
|
|
783
|
+
};
|
|
784
|
+
type AppAgentConversationMessage = AppAgentAssistantMessage | AppAgentUserMessage | AppAgentErrorMessage;
|
|
785
|
+
type AppAgentVisibleMessage = AppAgentConversationMessage | AppAgentToolCallMessage;
|
|
786
|
+
type AppAgentLastTurnSummary = {
|
|
787
|
+
prompt: string;
|
|
788
|
+
toolsUsed: number;
|
|
789
|
+
durationMs: number | null;
|
|
790
|
+
};
|
|
791
|
+
type AppAgentRenderedNode = {
|
|
792
|
+
kind: 'user';
|
|
793
|
+
id: string;
|
|
794
|
+
content: string;
|
|
795
|
+
} | {
|
|
796
|
+
kind: 'assistant';
|
|
797
|
+
id: string;
|
|
798
|
+
content: string;
|
|
799
|
+
} | {
|
|
800
|
+
kind: 'tools';
|
|
801
|
+
id: string;
|
|
802
|
+
tools: AppAgentToolCallMessage[];
|
|
803
|
+
};
|
|
804
|
+
type AppAgentInlinePendingTurnState = {
|
|
805
|
+
prompt: string;
|
|
806
|
+
baselineAssistantId: string | null;
|
|
807
|
+
baselineToolCount: number;
|
|
808
|
+
};
|
|
809
|
+
type AppAgentInlineFeedState = {
|
|
810
|
+
isActive: boolean;
|
|
811
|
+
pendingPrompt: string | null;
|
|
812
|
+
recentTools: AppAgentToolCallMessage[];
|
|
813
|
+
previewText: string | null;
|
|
814
|
+
waitingForActivity: boolean;
|
|
815
|
+
};
|
|
816
|
+
declare function deriveVisibleMessages(messages: ChatMessage[]): AppAgentVisibleMessage[];
|
|
817
|
+
declare function deriveConversationMessages(messages: ChatMessage[]): AppAgentConversationMessage[];
|
|
818
|
+
declare function deriveToolMessages(messages: ChatMessage[]): AppAgentToolCallMessage[];
|
|
819
|
+
declare function getLatestAssistantMessage(messages: ChatMessage[]): AppAgentAssistantMessage | null;
|
|
820
|
+
declare function getLatestUserMessage(messages: ChatMessage[]): AppAgentUserMessage | null;
|
|
821
|
+
declare function getLatestToolMessage(messages: ChatMessage[]): AppAgentToolCallMessage | null;
|
|
822
|
+
declare function createInlinePendingTurnState(prompt: string, messages: ChatMessage[]): AppAgentInlinePendingTurnState;
|
|
823
|
+
declare function buildRenderedNodes(messages: ChatMessage[]): AppAgentRenderedNode[];
|
|
824
|
+
declare function deriveLastTurnSummary(messages: ChatMessage[]): AppAgentLastTurnSummary | null;
|
|
825
|
+
declare function deriveInlineFeedState(options: {
|
|
826
|
+
pendingTurn: AppAgentInlinePendingTurnState | null;
|
|
827
|
+
toolMessages: AppAgentToolCallMessage[];
|
|
828
|
+
latestAssistantMessage?: {
|
|
829
|
+
id: string;
|
|
830
|
+
content: string;
|
|
831
|
+
} | null;
|
|
832
|
+
streamingContent?: string;
|
|
833
|
+
isLoading: boolean;
|
|
834
|
+
isThinking: boolean;
|
|
835
|
+
maxRecentTools?: number;
|
|
836
|
+
}): AppAgentInlineFeedState;
|
|
837
|
+
|
|
838
|
+
type Listener = () => void;
|
|
839
|
+
type AppAgentSnapshot = AppAgentSnapshotBase & {
|
|
840
|
+
runtime: AppAgentSnapshotBase['runtime'] & {
|
|
841
|
+
agent: McpStackAgent;
|
|
842
|
+
};
|
|
843
|
+
conversation: AppAgentSnapshotBase['conversation'] & {
|
|
844
|
+
visibleMessages: ReturnType<typeof deriveVisibleMessages>;
|
|
845
|
+
conversationMessages: ReturnType<typeof deriveConversationMessages>;
|
|
846
|
+
toolMessages: ReturnType<typeof deriveToolMessages>;
|
|
847
|
+
renderedNodes: ReturnType<typeof buildRenderedNodes>;
|
|
848
|
+
latestAssistantMessage: ReturnType<typeof getLatestAssistantMessage>;
|
|
849
|
+
latestToolMessage: ReturnType<typeof getLatestToolMessage>;
|
|
850
|
+
latestUserMessage: ReturnType<typeof getLatestUserMessage>;
|
|
851
|
+
lastTurn: ReturnType<typeof deriveLastTurnSummary>;
|
|
852
|
+
pendingTurn: ReturnType<typeof createInlinePendingTurnState> | null;
|
|
853
|
+
inlineFeed: ReturnType<typeof deriveInlineFeedState>;
|
|
854
|
+
};
|
|
855
|
+
};
|
|
856
|
+
declare class AppAgentController {
|
|
857
|
+
private config;
|
|
858
|
+
private readonly listeners;
|
|
859
|
+
private readonly agent;
|
|
860
|
+
private readonly platform;
|
|
861
|
+
private readonly recoveredConversationIds;
|
|
862
|
+
private readonly approvalResolvers;
|
|
863
|
+
private readonly inputResolvers;
|
|
864
|
+
private readonly pendingToolCallsByAction;
|
|
865
|
+
private readonly lifecycleUnsubscribers;
|
|
866
|
+
private readonly userMessageDisplayOverrides;
|
|
867
|
+
private state;
|
|
868
|
+
private snapshot;
|
|
869
|
+
private started;
|
|
870
|
+
private disposed;
|
|
871
|
+
private initializationPromise;
|
|
872
|
+
private pendingDisplayText;
|
|
873
|
+
constructor(config: AppAgentConfig);
|
|
874
|
+
getAgent(): McpStackAgent;
|
|
875
|
+
getSnapshot: () => AppAgentSnapshot;
|
|
876
|
+
private buildSnapshot;
|
|
877
|
+
subscribe(listener: Listener): () => void;
|
|
878
|
+
start(): void;
|
|
879
|
+
dispose(): void;
|
|
880
|
+
updateDynamicConfig(config: Pick<AppAgentConfig, 'appContext' | 'clientTools' | 'feedbackSource'>): void;
|
|
881
|
+
setAuthRequiredHandler(onAuthRequired: ((mcpServerUrl: string, authConfig: McpServerAuthConfig) => Promise<OAuthTokenResponse | undefined>) | undefined): void;
|
|
882
|
+
send(prompt: string, options?: {
|
|
883
|
+
displayText?: string;
|
|
884
|
+
}): Promise<void>;
|
|
885
|
+
cancel(): void;
|
|
886
|
+
startVoiceInput(): Promise<void>;
|
|
887
|
+
stopVoiceInput(): Promise<void>;
|
|
888
|
+
cancelVoiceInput(): void;
|
|
889
|
+
loadMore(): Promise<void>;
|
|
890
|
+
resetConversation(): Promise<void>;
|
|
891
|
+
connect(serverUrl: string): Promise<boolean>;
|
|
892
|
+
disconnect(serverUrl: string): Promise<void>;
|
|
893
|
+
submitFeedback(input: Omit<SubmitConversationFeedbackRequest, 'source'>): Promise<ConversationFeedback>;
|
|
894
|
+
resolveApproval(id: string, approved: boolean): void;
|
|
895
|
+
submitRequest(id: string, values?: Record<string, unknown>): void;
|
|
896
|
+
cancelRequest(id: string): void;
|
|
897
|
+
private initialize;
|
|
898
|
+
private ensureInitialized;
|
|
899
|
+
private bindRuntimeEvents;
|
|
900
|
+
private readonly handleMessage;
|
|
901
|
+
private readonly handleContentDelta;
|
|
902
|
+
private readonly handleToolCall;
|
|
903
|
+
private readonly handleToolResult;
|
|
904
|
+
private readonly handleToolError;
|
|
905
|
+
private readonly handleThinking;
|
|
906
|
+
private readonly handleLoading;
|
|
907
|
+
private readonly handleError;
|
|
908
|
+
private readonly handleBudgetSnapshot;
|
|
909
|
+
private readonly handleMcpAuthStatus;
|
|
910
|
+
private readonly handleAudioState;
|
|
911
|
+
private handleStaleConversation;
|
|
912
|
+
private bindLifecycleSignals;
|
|
913
|
+
private buildClientTools;
|
|
914
|
+
private shiftPendingToolCallId;
|
|
915
|
+
private syncFromRuntime;
|
|
916
|
+
private finalizePendingTurnIfSettled;
|
|
917
|
+
private getResumeStorageKey;
|
|
918
|
+
private readResumeRecord;
|
|
919
|
+
private persistResumeRecord;
|
|
920
|
+
private clearResumeRecord;
|
|
921
|
+
private setState;
|
|
922
|
+
private recomputeDerivedState;
|
|
923
|
+
private emit;
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
interface OAuthPopupState {
|
|
927
|
+
serverName: string;
|
|
928
|
+
serverUrl: string;
|
|
929
|
+
phase: 'prompt' | 'preparing' | 'waiting' | 'exchanging' | 'blocked' | 'canceled' | 'error';
|
|
930
|
+
statusMessage?: string | null;
|
|
931
|
+
errorMessage?: string | null;
|
|
932
|
+
hostIdentityLabel?: string | null;
|
|
933
|
+
}
|
|
934
|
+
interface UseAppAgentOptions {
|
|
935
|
+
enabled?: boolean;
|
|
936
|
+
}
|
|
937
|
+
interface UseAppAgentReturn {
|
|
938
|
+
controller: AppAgentController;
|
|
939
|
+
runtime: AppAgentSnapshot['runtime'];
|
|
940
|
+
conversation: AppAgentSnapshot['conversation'] & {
|
|
941
|
+
loadMore: () => Promise<void>;
|
|
942
|
+
reset: () => Promise<void>;
|
|
943
|
+
};
|
|
944
|
+
composer: {
|
|
945
|
+
send: (prompt: string, options?: {
|
|
946
|
+
displayText?: string;
|
|
947
|
+
}) => Promise<void>;
|
|
948
|
+
cancel: () => void;
|
|
949
|
+
};
|
|
950
|
+
connections: AppAgentSnapshot['connections'] & {
|
|
951
|
+
connect: (serverUrl: string) => Promise<boolean>;
|
|
952
|
+
disconnect: (serverUrl: string) => Promise<void>;
|
|
953
|
+
};
|
|
954
|
+
approvals: AppAgentSnapshot['approvals'] & {
|
|
955
|
+
resolve: (id: string, approved: boolean) => void;
|
|
956
|
+
};
|
|
957
|
+
requests: AppAgentSnapshot['requests'] & {
|
|
958
|
+
submit: (id: string, values?: Record<string, unknown>) => void;
|
|
959
|
+
cancel: (id: string) => void;
|
|
960
|
+
};
|
|
961
|
+
feedback: AppAgentSnapshot['feedback'] & {
|
|
962
|
+
submit: (input: Omit<SubmitConversationFeedbackRequest, 'source'>) => Promise<unknown>;
|
|
963
|
+
};
|
|
964
|
+
budget: AppAgentSnapshot['budget'];
|
|
965
|
+
voice: AppAgentSnapshot['voice'] & {
|
|
966
|
+
start: () => Promise<void>;
|
|
967
|
+
stop: () => Promise<void>;
|
|
968
|
+
cancel: () => void;
|
|
969
|
+
};
|
|
970
|
+
popupAuthState: OAuthPopupState | null;
|
|
971
|
+
startOrRetryPopupAuth: () => void;
|
|
972
|
+
cancelPopupAuth: () => void;
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
interface AppAgentProviderProps extends AppAgentConfig {
|
|
976
|
+
children: React.ReactNode;
|
|
977
|
+
}
|
|
978
|
+
declare function useAppAgent(config: AppAgentConfig, options?: UseAppAgentOptions): UseAppAgentReturn;
|
|
979
|
+
declare function AppAgentProvider({ children, ...config }: AppAgentProviderProps): react_jsx_runtime.JSX.Element;
|
|
980
|
+
declare function useAppAgentContext(): UseAppAgentReturn;
|
|
981
|
+
|
|
982
|
+
export { AppAgentProvider, type AppAgentProviderProps, type UseAppAgentOptions, type UseAppAgentReturn, useAppAgent, useAppAgentContext };
|