pika-shared 1.4.0 → 1.4.2
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/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types/chatbot/bedrock-lambda-error.js.map +1 -1
- package/dist/types/chatbot/bedrock-lambda-error.mjs.map +1 -1
- package/dist/types/chatbot/chatbot-types.d.mts +421 -24
- package/dist/types/chatbot/chatbot-types.d.ts +421 -24
- package/dist/types/chatbot/chatbot-types.js +9 -1
- package/dist/types/chatbot/chatbot-types.js.map +1 -1
- package/dist/types/chatbot/chatbot-types.mjs +6 -2
- package/dist/types/chatbot/chatbot-types.mjs.map +1 -1
- package/dist/types/chatbot/webcomp-types.d.mts +326 -0
- package/dist/types/chatbot/webcomp-types.d.ts +326 -0
- package/dist/types/chatbot/webcomp-types.js +4 -0
- package/dist/types/chatbot/webcomp-types.js.map +1 -0
- package/dist/types/chatbot/webcomp-types.mjs +3 -0
- package/dist/types/chatbot/webcomp-types.mjs.map +1 -0
- package/dist/util/api-gateway-utils.js.map +1 -1
- package/dist/util/api-gateway-utils.mjs.map +1 -1
- package/dist/util/bad-request-error.js.map +1 -1
- package/dist/util/bad-request-error.mjs.map +1 -1
- package/dist/util/bedrock.js.map +1 -1
- package/dist/util/bedrock.mjs.map +1 -1
- package/dist/util/chatbot-shared-utils.js.map +1 -1
- package/dist/util/chatbot-shared-utils.mjs.map +1 -1
- package/dist/util/forbidden-error.js.map +1 -1
- package/dist/util/forbidden-error.mjs.map +1 -1
- package/dist/util/http-status-error.js.map +1 -1
- package/dist/util/http-status-error.mjs.map +1 -1
- package/dist/util/icon-utils.d.mts +12 -0
- package/dist/util/icon-utils.d.ts +12 -0
- package/dist/util/icon-utils.js +26 -0
- package/dist/util/icon-utils.js.map +1 -0
- package/dist/util/icon-utils.mjs +24 -0
- package/dist/util/icon-utils.mjs.map +1 -0
- package/dist/util/instruction-assistance-utils.d.mts +28 -1
- package/dist/util/instruction-assistance-utils.d.ts +28 -1
- package/dist/util/instruction-assistance-utils.js +56 -8
- package/dist/util/instruction-assistance-utils.js.map +1 -1
- package/dist/util/instruction-assistance-utils.mjs +55 -9
- package/dist/util/instruction-assistance-utils.mjs.map +1 -1
- package/dist/util/jwt.js.map +1 -1
- package/dist/util/jwt.mjs.map +1 -1
- package/dist/util/server-client-utils.js.map +1 -1
- package/dist/util/server-client-utils.mjs.map +1 -1
- package/dist/util/server-utils.js +6 -2
- package/dist/util/server-utils.js.map +1 -1
- package/dist/util/server-utils.mjs +6 -2
- package/dist/util/server-utils.mjs.map +1 -1
- package/dist/util/unauthorized-error.js.map +1 -1
- package/dist/util/unauthorized-error.mjs.map +1 -1
- package/dist/util/wc-utils.d.mts +22 -0
- package/dist/util/wc-utils.d.ts +22 -0
- package/dist/util/wc-utils.js +26 -0
- package/dist/util/wc-utils.js.map +1 -0
- package/dist/util/wc-utils.mjs +24 -0
- package/dist/util/wc-utils.mjs.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import { UploadStatus } from '../upload-types.mjs';
|
|
2
|
+
import { ShowToastFn, ChatUser, RecordOrUndef, UserAwsCredentials, WidgetRenderingContextType, ShareSessionState, UserPrefs, ChatAppMode, IUserWidgetDataStoreState, CustomDataUiRepresentation, ChatAppOverridableFeatures, TagDefinition, TagDefinitionWidget, ChatSession, UserDataOverrideSettings, ChatMessageForRendering, ChatApp, InvokeAgentAsComponentOptions, WidgetMetadata, WidgetAction } from './chatbot-types.mjs';
|
|
3
|
+
import '@aws-sdk/client-bedrock-agent-runtime';
|
|
4
|
+
import '@aws-sdk/client-bedrock-agentcore';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Note!!! The interfaces in this file are meant to expose public functionality to the web component authors.
|
|
8
|
+
* They are not meant to be exhaustive or complete.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
type SidebarState = any;
|
|
12
|
+
type Snippet = any;
|
|
13
|
+
/** Declare global event map for pika context request */
|
|
14
|
+
declare global {
|
|
15
|
+
interface HTMLElementEventMap {
|
|
16
|
+
'pika-wc-context-request': PikaWCContextRequestEvent;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
interface IIdentityState {
|
|
20
|
+
readonly fullName: string;
|
|
21
|
+
readonly initials: string;
|
|
22
|
+
readonly user: ChatUser<RecordOrUndef>;
|
|
23
|
+
readonly isSiteAdmin: boolean;
|
|
24
|
+
readonly isInternalUser: boolean;
|
|
25
|
+
readonly isContentAdmin: boolean;
|
|
26
|
+
getUserAwsCredentials(): Promise<UserAwsCredentials | undefined>;
|
|
27
|
+
}
|
|
28
|
+
interface IAppState {
|
|
29
|
+
readonly showToast: ShowToastFn;
|
|
30
|
+
readonly identity: IIdentityState;
|
|
31
|
+
readonly isMobile: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Widget Metadata API - scoped to a specific widget instance.
|
|
35
|
+
* Returned by getWidgetMetadataAPI() and bound to the widget's instanceId.
|
|
36
|
+
*
|
|
37
|
+
* This API allows widgets to register and update their display metadata (title and actions)
|
|
38
|
+
* which the parent app uses to render context-appropriate chrome.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```js
|
|
42
|
+
* const ctx = await getPikaContext($host());
|
|
43
|
+
* const metadata = ctx.chatAppState.getWidgetMetadataAPI('weather', 'favorite-cities', ctx.instanceId, ctx.renderingContext);
|
|
44
|
+
*
|
|
45
|
+
* metadata.setMetadata({
|
|
46
|
+
* title: 'Favorite Cities',
|
|
47
|
+
* actions: [
|
|
48
|
+
* { id: 'refresh', title: 'Refresh', iconSvg: '<svg>...</svg>', callback: () => refresh() }
|
|
49
|
+
* ]
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
interface IWidgetMetadataAPI {
|
|
54
|
+
/**
|
|
55
|
+
* Register or update complete metadata (title and actions).
|
|
56
|
+
* Replaces any previously registered metadata for this widget instance.
|
|
57
|
+
*
|
|
58
|
+
* @param metadata - The metadata to register
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```js
|
|
62
|
+
* metadata.setMetadata({
|
|
63
|
+
* title: 'Weather Comparison',
|
|
64
|
+
* actions: [
|
|
65
|
+
* { id: 'refresh', title: 'Refresh', iconSvg: '<svg>...</svg>', callback: () => refresh() },
|
|
66
|
+
* { id: 'settings', title: 'Settings', iconSvg: '<svg>...</svg>', callback: () => showSettings() }
|
|
67
|
+
* ]
|
|
68
|
+
* });
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
setMetadata(metadata: WidgetMetadata): void;
|
|
72
|
+
/**
|
|
73
|
+
* Update just the widget title without affecting actions.
|
|
74
|
+
*
|
|
75
|
+
* @param title - The new title
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```js
|
|
79
|
+
* metadata.updateTitle(`Temperature Trend - ${newCity}`);
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
updateTitle(title: string): void;
|
|
83
|
+
/**
|
|
84
|
+
* Update a specific action's properties (e.g., disable/enable).
|
|
85
|
+
* Only updates the properties provided in `updates`.
|
|
86
|
+
*
|
|
87
|
+
* @param actionId - The ID of the action to update
|
|
88
|
+
* @param updates - Partial properties to update (cannot change id or callback)
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```js
|
|
92
|
+
* // Disable the refresh button during loading
|
|
93
|
+
* metadata.updateAction('refresh', { disabled: true });
|
|
94
|
+
*
|
|
95
|
+
* // Re-enable it after loading
|
|
96
|
+
* metadata.updateAction('refresh', { disabled: false });
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
updateAction(actionId: string, updates: Partial<Omit<WidgetAction, 'id' | 'callback'>>): void;
|
|
100
|
+
/**
|
|
101
|
+
* Add a new action button dynamically.
|
|
102
|
+
*
|
|
103
|
+
* @param action - The action to add
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```js
|
|
107
|
+
* if (userHasPremium) {
|
|
108
|
+
* metadata.addAction({
|
|
109
|
+
* id: 'export',
|
|
110
|
+
* title: 'Export data',
|
|
111
|
+
* iconSvg: '<svg>...</svg>',
|
|
112
|
+
* callback: () => exportData()
|
|
113
|
+
* });
|
|
114
|
+
* }
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
addAction(action: WidgetAction): void;
|
|
118
|
+
/**
|
|
119
|
+
* Remove an action button.
|
|
120
|
+
*
|
|
121
|
+
* @param actionId - The ID of the action to remove
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```js
|
|
125
|
+
* metadata.removeAction('export');
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
removeAction(actionId: string): void;
|
|
129
|
+
/**
|
|
130
|
+
* Set the loading status for the widget.
|
|
131
|
+
*
|
|
132
|
+
* @param loading - Whether the widget is loading
|
|
133
|
+
* @param loadingMsg - The message to display while loading
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```js
|
|
137
|
+
* metadata.setLoadingStatus(true, 'Loading...');
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
setLoadingStatus(loading: boolean, loadingMsg?: string): void;
|
|
141
|
+
}
|
|
142
|
+
interface IChatAppState {
|
|
143
|
+
readonly entityFeatureEnabled: boolean;
|
|
144
|
+
readonly shareCurrentSessionState: ShareSessionState;
|
|
145
|
+
readonly showToast: ShowToastFn;
|
|
146
|
+
readonly userPrefs: IUserPrefsState;
|
|
147
|
+
readonly mode: ChatAppMode;
|
|
148
|
+
/**
|
|
149
|
+
* Get component-specific storage scoped to this component (scope.tag) and current user.
|
|
150
|
+
* Max 400KB per component.
|
|
151
|
+
*/
|
|
152
|
+
getUserWidgetDataStoreState(scope: string, tag: string): IUserWidgetDataStoreState;
|
|
153
|
+
readonly customDataUiRepresentation: CustomDataUiRepresentation | undefined;
|
|
154
|
+
readonly features: ChatAppOverridableFeatures;
|
|
155
|
+
readonly tagDefs: TagDefinition<TagDefinitionWidget>[];
|
|
156
|
+
readonly userIsContentAdmin: boolean;
|
|
157
|
+
readonly userNeedsToProvideDataOverrides: boolean;
|
|
158
|
+
readonly isViewingContentForAnotherUser: boolean;
|
|
159
|
+
readonly currentSessionIsSharedBySomeoneElse: boolean;
|
|
160
|
+
readonly currentShareId: string | undefined;
|
|
161
|
+
readonly currentSessionIsReadOnly: boolean;
|
|
162
|
+
readonly sortedChatSessions: ChatSession<RecordOrUndef>[];
|
|
163
|
+
readonly userDataOverrideSettings: UserDataOverrideSettings;
|
|
164
|
+
readonly enableFileUpload: boolean;
|
|
165
|
+
readonly chatSessions: ChatSession<RecordOrUndef>[];
|
|
166
|
+
readonly waitingForFirstStreamedResponse: boolean;
|
|
167
|
+
readonly isStreamingResponseNow: boolean;
|
|
168
|
+
readonly isInterimSession: boolean;
|
|
169
|
+
readonly currentSession: ChatSession<RecordOrUndef>;
|
|
170
|
+
readonly currentSessionMessages: ChatMessageForRendering[];
|
|
171
|
+
readonly inputFiles: IUploadInstance[];
|
|
172
|
+
readonly newSession: boolean;
|
|
173
|
+
readonly chatInput: string;
|
|
174
|
+
readonly chatApp: ChatApp;
|
|
175
|
+
readonly retrievingMessages: boolean;
|
|
176
|
+
readonly pageTitle: string | undefined;
|
|
177
|
+
setCurrentSessionById(sessionId: string): void;
|
|
178
|
+
removeFile(s3Key: string): void;
|
|
179
|
+
startNewChatSession(): void;
|
|
180
|
+
refreshChatSessions(): Promise<void>;
|
|
181
|
+
downloadFile(s3Key: string): Promise<void>;
|
|
182
|
+
refreshMessagesForCurrentSession(): Promise<void>;
|
|
183
|
+
sendMessage(): Promise<void>;
|
|
184
|
+
getMessageByMessageId(messageId: string): ChatMessageForRendering | undefined;
|
|
185
|
+
uploadFiles(files: File[]): Promise<void>;
|
|
186
|
+
initializeData(): Promise<void>;
|
|
187
|
+
renderTag(tagId: string, context: 'spotlight' | 'inline' | 'dialog' | 'canvas', data?: Record<string, any>): Promise<void>;
|
|
188
|
+
closeCanvas(): void;
|
|
189
|
+
closeDialog(): void;
|
|
190
|
+
/**
|
|
191
|
+
* Invoke the agent directly from a web component using the 'chat-app-component' invocation mode.
|
|
192
|
+
* This allows components to make out-of-band requests to the LLM without creating user sessions.
|
|
193
|
+
*
|
|
194
|
+
* The component must have a tag definition with `componentAgentInstructionsMd` that
|
|
195
|
+
* includes instructions for the specified `instructionName`.
|
|
196
|
+
*
|
|
197
|
+
* @param scope - The scope of the tag definition (e.g., 'weather')
|
|
198
|
+
* @param tag - The tag name (e.g., 'favorite-cities')
|
|
199
|
+
* @param instructionName - The key in the tag definition's componentAgentInstructionsMd
|
|
200
|
+
* @param userMessage - The message/query to send to the agent
|
|
201
|
+
* @param options - Optional streaming callbacks and configuration
|
|
202
|
+
* @returns Promise that resolves to the parsed JSON response from the agent
|
|
203
|
+
* @throws Error if the request fails or response cannot be parsed
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* Simple usage:
|
|
207
|
+
* ```typescript
|
|
208
|
+
* const weatherData = await chatAppState.invokeAgentAsComponent<{ temperature: number, condition: string }>(
|
|
209
|
+
* 'weather',
|
|
210
|
+
* 'favorite-cities',
|
|
211
|
+
* 'get-weather',
|
|
212
|
+
* 'Get current weather for San Francisco'
|
|
213
|
+
* );
|
|
214
|
+
* ```
|
|
215
|
+
*
|
|
216
|
+
* With streaming callbacks:
|
|
217
|
+
* ```typescript
|
|
218
|
+
* const data = await chatAppState.invokeAgentAsComponent<WeatherData>(
|
|
219
|
+
* 'weather',
|
|
220
|
+
* 'favorite-cities',
|
|
221
|
+
* 'get-weather',
|
|
222
|
+
* 'Get weather for NYC',
|
|
223
|
+
* {
|
|
224
|
+
* onThinking: (text) => console.log('Thinking:', text),
|
|
225
|
+
* onToolCall: (call) => console.log('Calling tool:', call.name)
|
|
226
|
+
* }
|
|
227
|
+
* );
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
invokeAgentAsComponent<T = any>(scope: string, tag: string, instructionName: string, userMessage: string, options?: InvokeAgentAsComponentOptions): Promise<T>;
|
|
231
|
+
/**
|
|
232
|
+
* Get a scoped metadata API for registering widget title and actions.
|
|
233
|
+
* Call this once during widget initialization to get an API bound to this widget instance.
|
|
234
|
+
*
|
|
235
|
+
* The metadata you register will be used by the parent app to render context-appropriate chrome:
|
|
236
|
+
* - **Spotlight**: Small title bar overlay with icon + title + action menu
|
|
237
|
+
* - **Canvas**: Full title bar with all action buttons + close
|
|
238
|
+
* - **Dialog**: Title in header, actions as buttons in footer
|
|
239
|
+
* - **Inline**: No chrome rendered (widget manages own UI)
|
|
240
|
+
*
|
|
241
|
+
* **IMPORTANT**: You MUST pass instanceId and renderingContext from the PikaWCContext.
|
|
242
|
+
* These values are automatically set during component injection.
|
|
243
|
+
*
|
|
244
|
+
* @param scope - Widget scope (e.g., 'weather', 'pika')
|
|
245
|
+
* @param tag - Widget tag (e.g., 'favorite-cities')
|
|
246
|
+
* @param instanceId - Unique instance ID from context.instanceId (set during injection)
|
|
247
|
+
* @param renderingContext - Rendering context from context.renderingContext (set during injection)
|
|
248
|
+
* @returns Scoped API for this widget instance
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* Correct usage (always pass context values):
|
|
252
|
+
* ```js
|
|
253
|
+
* const ctx = await getPikaContext($host());
|
|
254
|
+
* const metadata = ctx.chatAppState.getWidgetMetadataAPI(
|
|
255
|
+
* 'weather',
|
|
256
|
+
* 'favorite-cities',
|
|
257
|
+
* ctx.instanceId, // REQUIRED - set during injection
|
|
258
|
+
* ctx.renderingContext // REQUIRED - set during injection
|
|
259
|
+
* );
|
|
260
|
+
*
|
|
261
|
+
* metadata.setMetadata({
|
|
262
|
+
* title: 'Favorite Cities',
|
|
263
|
+
* actions: [
|
|
264
|
+
* {
|
|
265
|
+
* id: 'refresh',
|
|
266
|
+
* title: 'Refresh weather data',
|
|
267
|
+
* lucideIconName: 'refresh-cw', // MUST be lowercase kebab-case
|
|
268
|
+
* callback: async () => {
|
|
269
|
+
* loading = true;
|
|
270
|
+
* await fetchWeatherData();
|
|
271
|
+
* loading = false;
|
|
272
|
+
* }
|
|
273
|
+
* }
|
|
274
|
+
* ]
|
|
275
|
+
* });
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
getWidgetMetadataAPI(scope: string, tag: string, instanceId: string, renderingContext: WidgetRenderingContextType): IWidgetMetadataAPI;
|
|
279
|
+
}
|
|
280
|
+
interface IUserPrefsState {
|
|
281
|
+
readonly initialized: boolean;
|
|
282
|
+
readonly prefs: UserPrefs | undefined;
|
|
283
|
+
refreshPrefsFromServer(): Promise<void>;
|
|
284
|
+
getPref<T>(key: string): Promise<T | undefined>;
|
|
285
|
+
modifyPref(key: string, value: unknown): Promise<void>;
|
|
286
|
+
}
|
|
287
|
+
interface IUploadInstance {
|
|
288
|
+
readonly s3Key: string;
|
|
289
|
+
readonly file: File | undefined;
|
|
290
|
+
readonly fileName: string;
|
|
291
|
+
readonly size: number;
|
|
292
|
+
readonly lastModified: number;
|
|
293
|
+
readonly type: string;
|
|
294
|
+
readonly xhr: XMLHttpRequest;
|
|
295
|
+
readonly status: {
|
|
296
|
+
status: UploadStatus['status'];
|
|
297
|
+
progress?: number;
|
|
298
|
+
error?: string;
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* This is the context object that is passed to the web component when it is rendered.
|
|
303
|
+
*/
|
|
304
|
+
interface PikaWCContext {
|
|
305
|
+
appState: IAppState;
|
|
306
|
+
renderingContext: WidgetRenderingContextType;
|
|
307
|
+
chatAppState: IChatAppState;
|
|
308
|
+
chatAppId: string;
|
|
309
|
+
/**
|
|
310
|
+
* Unique instance ID for this component instance.
|
|
311
|
+
* Set by injectChatAppWebComponent() and used by getWidgetMetadataAPI().
|
|
312
|
+
*/
|
|
313
|
+
instanceId: string;
|
|
314
|
+
/** Arbitrary data to be passed to the widget. */
|
|
315
|
+
dataForWidget: Record<string, any>;
|
|
316
|
+
}
|
|
317
|
+
type PikaWCContextWithoutInstanceId = Omit<PikaWCContext, 'instanceId'>;
|
|
318
|
+
type PikaWCContextRequestCallbackFn = (contextRequest: PikaWCContext) => void;
|
|
319
|
+
interface PikaWCContextRequestDetail {
|
|
320
|
+
callback: PikaWCContextRequestCallbackFn;
|
|
321
|
+
}
|
|
322
|
+
interface PikaWCContextRequestEvent extends CustomEvent<PikaWCContextRequestDetail> {
|
|
323
|
+
detail: PikaWCContextRequestDetail;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export type { IAppState, IChatAppState, IIdentityState, IUploadInstance, IUserPrefsState, IWidgetMetadataAPI, PikaWCContext, PikaWCContextRequestCallbackFn, PikaWCContextRequestDetail, PikaWCContextRequestEvent, PikaWCContextWithoutInstanceId, SidebarState, Snippet };
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import { UploadStatus } from '../upload-types.js';
|
|
2
|
+
import { ShowToastFn, ChatUser, RecordOrUndef, UserAwsCredentials, WidgetRenderingContextType, ShareSessionState, UserPrefs, ChatAppMode, IUserWidgetDataStoreState, CustomDataUiRepresentation, ChatAppOverridableFeatures, TagDefinition, TagDefinitionWidget, ChatSession, UserDataOverrideSettings, ChatMessageForRendering, ChatApp, InvokeAgentAsComponentOptions, WidgetMetadata, WidgetAction } from './chatbot-types.js';
|
|
3
|
+
import '@aws-sdk/client-bedrock-agent-runtime';
|
|
4
|
+
import '@aws-sdk/client-bedrock-agentcore';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Note!!! The interfaces in this file are meant to expose public functionality to the web component authors.
|
|
8
|
+
* They are not meant to be exhaustive or complete.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
type SidebarState = any;
|
|
12
|
+
type Snippet = any;
|
|
13
|
+
/** Declare global event map for pika context request */
|
|
14
|
+
declare global {
|
|
15
|
+
interface HTMLElementEventMap {
|
|
16
|
+
'pika-wc-context-request': PikaWCContextRequestEvent;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
interface IIdentityState {
|
|
20
|
+
readonly fullName: string;
|
|
21
|
+
readonly initials: string;
|
|
22
|
+
readonly user: ChatUser<RecordOrUndef>;
|
|
23
|
+
readonly isSiteAdmin: boolean;
|
|
24
|
+
readonly isInternalUser: boolean;
|
|
25
|
+
readonly isContentAdmin: boolean;
|
|
26
|
+
getUserAwsCredentials(): Promise<UserAwsCredentials | undefined>;
|
|
27
|
+
}
|
|
28
|
+
interface IAppState {
|
|
29
|
+
readonly showToast: ShowToastFn;
|
|
30
|
+
readonly identity: IIdentityState;
|
|
31
|
+
readonly isMobile: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Widget Metadata API - scoped to a specific widget instance.
|
|
35
|
+
* Returned by getWidgetMetadataAPI() and bound to the widget's instanceId.
|
|
36
|
+
*
|
|
37
|
+
* This API allows widgets to register and update their display metadata (title and actions)
|
|
38
|
+
* which the parent app uses to render context-appropriate chrome.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```js
|
|
42
|
+
* const ctx = await getPikaContext($host());
|
|
43
|
+
* const metadata = ctx.chatAppState.getWidgetMetadataAPI('weather', 'favorite-cities', ctx.instanceId, ctx.renderingContext);
|
|
44
|
+
*
|
|
45
|
+
* metadata.setMetadata({
|
|
46
|
+
* title: 'Favorite Cities',
|
|
47
|
+
* actions: [
|
|
48
|
+
* { id: 'refresh', title: 'Refresh', iconSvg: '<svg>...</svg>', callback: () => refresh() }
|
|
49
|
+
* ]
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
interface IWidgetMetadataAPI {
|
|
54
|
+
/**
|
|
55
|
+
* Register or update complete metadata (title and actions).
|
|
56
|
+
* Replaces any previously registered metadata for this widget instance.
|
|
57
|
+
*
|
|
58
|
+
* @param metadata - The metadata to register
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```js
|
|
62
|
+
* metadata.setMetadata({
|
|
63
|
+
* title: 'Weather Comparison',
|
|
64
|
+
* actions: [
|
|
65
|
+
* { id: 'refresh', title: 'Refresh', iconSvg: '<svg>...</svg>', callback: () => refresh() },
|
|
66
|
+
* { id: 'settings', title: 'Settings', iconSvg: '<svg>...</svg>', callback: () => showSettings() }
|
|
67
|
+
* ]
|
|
68
|
+
* });
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
setMetadata(metadata: WidgetMetadata): void;
|
|
72
|
+
/**
|
|
73
|
+
* Update just the widget title without affecting actions.
|
|
74
|
+
*
|
|
75
|
+
* @param title - The new title
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```js
|
|
79
|
+
* metadata.updateTitle(`Temperature Trend - ${newCity}`);
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
updateTitle(title: string): void;
|
|
83
|
+
/**
|
|
84
|
+
* Update a specific action's properties (e.g., disable/enable).
|
|
85
|
+
* Only updates the properties provided in `updates`.
|
|
86
|
+
*
|
|
87
|
+
* @param actionId - The ID of the action to update
|
|
88
|
+
* @param updates - Partial properties to update (cannot change id or callback)
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```js
|
|
92
|
+
* // Disable the refresh button during loading
|
|
93
|
+
* metadata.updateAction('refresh', { disabled: true });
|
|
94
|
+
*
|
|
95
|
+
* // Re-enable it after loading
|
|
96
|
+
* metadata.updateAction('refresh', { disabled: false });
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
updateAction(actionId: string, updates: Partial<Omit<WidgetAction, 'id' | 'callback'>>): void;
|
|
100
|
+
/**
|
|
101
|
+
* Add a new action button dynamically.
|
|
102
|
+
*
|
|
103
|
+
* @param action - The action to add
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```js
|
|
107
|
+
* if (userHasPremium) {
|
|
108
|
+
* metadata.addAction({
|
|
109
|
+
* id: 'export',
|
|
110
|
+
* title: 'Export data',
|
|
111
|
+
* iconSvg: '<svg>...</svg>',
|
|
112
|
+
* callback: () => exportData()
|
|
113
|
+
* });
|
|
114
|
+
* }
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
addAction(action: WidgetAction): void;
|
|
118
|
+
/**
|
|
119
|
+
* Remove an action button.
|
|
120
|
+
*
|
|
121
|
+
* @param actionId - The ID of the action to remove
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```js
|
|
125
|
+
* metadata.removeAction('export');
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
removeAction(actionId: string): void;
|
|
129
|
+
/**
|
|
130
|
+
* Set the loading status for the widget.
|
|
131
|
+
*
|
|
132
|
+
* @param loading - Whether the widget is loading
|
|
133
|
+
* @param loadingMsg - The message to display while loading
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```js
|
|
137
|
+
* metadata.setLoadingStatus(true, 'Loading...');
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
setLoadingStatus(loading: boolean, loadingMsg?: string): void;
|
|
141
|
+
}
|
|
142
|
+
interface IChatAppState {
|
|
143
|
+
readonly entityFeatureEnabled: boolean;
|
|
144
|
+
readonly shareCurrentSessionState: ShareSessionState;
|
|
145
|
+
readonly showToast: ShowToastFn;
|
|
146
|
+
readonly userPrefs: IUserPrefsState;
|
|
147
|
+
readonly mode: ChatAppMode;
|
|
148
|
+
/**
|
|
149
|
+
* Get component-specific storage scoped to this component (scope.tag) and current user.
|
|
150
|
+
* Max 400KB per component.
|
|
151
|
+
*/
|
|
152
|
+
getUserWidgetDataStoreState(scope: string, tag: string): IUserWidgetDataStoreState;
|
|
153
|
+
readonly customDataUiRepresentation: CustomDataUiRepresentation | undefined;
|
|
154
|
+
readonly features: ChatAppOverridableFeatures;
|
|
155
|
+
readonly tagDefs: TagDefinition<TagDefinitionWidget>[];
|
|
156
|
+
readonly userIsContentAdmin: boolean;
|
|
157
|
+
readonly userNeedsToProvideDataOverrides: boolean;
|
|
158
|
+
readonly isViewingContentForAnotherUser: boolean;
|
|
159
|
+
readonly currentSessionIsSharedBySomeoneElse: boolean;
|
|
160
|
+
readonly currentShareId: string | undefined;
|
|
161
|
+
readonly currentSessionIsReadOnly: boolean;
|
|
162
|
+
readonly sortedChatSessions: ChatSession<RecordOrUndef>[];
|
|
163
|
+
readonly userDataOverrideSettings: UserDataOverrideSettings;
|
|
164
|
+
readonly enableFileUpload: boolean;
|
|
165
|
+
readonly chatSessions: ChatSession<RecordOrUndef>[];
|
|
166
|
+
readonly waitingForFirstStreamedResponse: boolean;
|
|
167
|
+
readonly isStreamingResponseNow: boolean;
|
|
168
|
+
readonly isInterimSession: boolean;
|
|
169
|
+
readonly currentSession: ChatSession<RecordOrUndef>;
|
|
170
|
+
readonly currentSessionMessages: ChatMessageForRendering[];
|
|
171
|
+
readonly inputFiles: IUploadInstance[];
|
|
172
|
+
readonly newSession: boolean;
|
|
173
|
+
readonly chatInput: string;
|
|
174
|
+
readonly chatApp: ChatApp;
|
|
175
|
+
readonly retrievingMessages: boolean;
|
|
176
|
+
readonly pageTitle: string | undefined;
|
|
177
|
+
setCurrentSessionById(sessionId: string): void;
|
|
178
|
+
removeFile(s3Key: string): void;
|
|
179
|
+
startNewChatSession(): void;
|
|
180
|
+
refreshChatSessions(): Promise<void>;
|
|
181
|
+
downloadFile(s3Key: string): Promise<void>;
|
|
182
|
+
refreshMessagesForCurrentSession(): Promise<void>;
|
|
183
|
+
sendMessage(): Promise<void>;
|
|
184
|
+
getMessageByMessageId(messageId: string): ChatMessageForRendering | undefined;
|
|
185
|
+
uploadFiles(files: File[]): Promise<void>;
|
|
186
|
+
initializeData(): Promise<void>;
|
|
187
|
+
renderTag(tagId: string, context: 'spotlight' | 'inline' | 'dialog' | 'canvas', data?: Record<string, any>): Promise<void>;
|
|
188
|
+
closeCanvas(): void;
|
|
189
|
+
closeDialog(): void;
|
|
190
|
+
/**
|
|
191
|
+
* Invoke the agent directly from a web component using the 'chat-app-component' invocation mode.
|
|
192
|
+
* This allows components to make out-of-band requests to the LLM without creating user sessions.
|
|
193
|
+
*
|
|
194
|
+
* The component must have a tag definition with `componentAgentInstructionsMd` that
|
|
195
|
+
* includes instructions for the specified `instructionName`.
|
|
196
|
+
*
|
|
197
|
+
* @param scope - The scope of the tag definition (e.g., 'weather')
|
|
198
|
+
* @param tag - The tag name (e.g., 'favorite-cities')
|
|
199
|
+
* @param instructionName - The key in the tag definition's componentAgentInstructionsMd
|
|
200
|
+
* @param userMessage - The message/query to send to the agent
|
|
201
|
+
* @param options - Optional streaming callbacks and configuration
|
|
202
|
+
* @returns Promise that resolves to the parsed JSON response from the agent
|
|
203
|
+
* @throws Error if the request fails or response cannot be parsed
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* Simple usage:
|
|
207
|
+
* ```typescript
|
|
208
|
+
* const weatherData = await chatAppState.invokeAgentAsComponent<{ temperature: number, condition: string }>(
|
|
209
|
+
* 'weather',
|
|
210
|
+
* 'favorite-cities',
|
|
211
|
+
* 'get-weather',
|
|
212
|
+
* 'Get current weather for San Francisco'
|
|
213
|
+
* );
|
|
214
|
+
* ```
|
|
215
|
+
*
|
|
216
|
+
* With streaming callbacks:
|
|
217
|
+
* ```typescript
|
|
218
|
+
* const data = await chatAppState.invokeAgentAsComponent<WeatherData>(
|
|
219
|
+
* 'weather',
|
|
220
|
+
* 'favorite-cities',
|
|
221
|
+
* 'get-weather',
|
|
222
|
+
* 'Get weather for NYC',
|
|
223
|
+
* {
|
|
224
|
+
* onThinking: (text) => console.log('Thinking:', text),
|
|
225
|
+
* onToolCall: (call) => console.log('Calling tool:', call.name)
|
|
226
|
+
* }
|
|
227
|
+
* );
|
|
228
|
+
* ```
|
|
229
|
+
*/
|
|
230
|
+
invokeAgentAsComponent<T = any>(scope: string, tag: string, instructionName: string, userMessage: string, options?: InvokeAgentAsComponentOptions): Promise<T>;
|
|
231
|
+
/**
|
|
232
|
+
* Get a scoped metadata API for registering widget title and actions.
|
|
233
|
+
* Call this once during widget initialization to get an API bound to this widget instance.
|
|
234
|
+
*
|
|
235
|
+
* The metadata you register will be used by the parent app to render context-appropriate chrome:
|
|
236
|
+
* - **Spotlight**: Small title bar overlay with icon + title + action menu
|
|
237
|
+
* - **Canvas**: Full title bar with all action buttons + close
|
|
238
|
+
* - **Dialog**: Title in header, actions as buttons in footer
|
|
239
|
+
* - **Inline**: No chrome rendered (widget manages own UI)
|
|
240
|
+
*
|
|
241
|
+
* **IMPORTANT**: You MUST pass instanceId and renderingContext from the PikaWCContext.
|
|
242
|
+
* These values are automatically set during component injection.
|
|
243
|
+
*
|
|
244
|
+
* @param scope - Widget scope (e.g., 'weather', 'pika')
|
|
245
|
+
* @param tag - Widget tag (e.g., 'favorite-cities')
|
|
246
|
+
* @param instanceId - Unique instance ID from context.instanceId (set during injection)
|
|
247
|
+
* @param renderingContext - Rendering context from context.renderingContext (set during injection)
|
|
248
|
+
* @returns Scoped API for this widget instance
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* Correct usage (always pass context values):
|
|
252
|
+
* ```js
|
|
253
|
+
* const ctx = await getPikaContext($host());
|
|
254
|
+
* const metadata = ctx.chatAppState.getWidgetMetadataAPI(
|
|
255
|
+
* 'weather',
|
|
256
|
+
* 'favorite-cities',
|
|
257
|
+
* ctx.instanceId, // REQUIRED - set during injection
|
|
258
|
+
* ctx.renderingContext // REQUIRED - set during injection
|
|
259
|
+
* );
|
|
260
|
+
*
|
|
261
|
+
* metadata.setMetadata({
|
|
262
|
+
* title: 'Favorite Cities',
|
|
263
|
+
* actions: [
|
|
264
|
+
* {
|
|
265
|
+
* id: 'refresh',
|
|
266
|
+
* title: 'Refresh weather data',
|
|
267
|
+
* lucideIconName: 'refresh-cw', // MUST be lowercase kebab-case
|
|
268
|
+
* callback: async () => {
|
|
269
|
+
* loading = true;
|
|
270
|
+
* await fetchWeatherData();
|
|
271
|
+
* loading = false;
|
|
272
|
+
* }
|
|
273
|
+
* }
|
|
274
|
+
* ]
|
|
275
|
+
* });
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
getWidgetMetadataAPI(scope: string, tag: string, instanceId: string, renderingContext: WidgetRenderingContextType): IWidgetMetadataAPI;
|
|
279
|
+
}
|
|
280
|
+
interface IUserPrefsState {
|
|
281
|
+
readonly initialized: boolean;
|
|
282
|
+
readonly prefs: UserPrefs | undefined;
|
|
283
|
+
refreshPrefsFromServer(): Promise<void>;
|
|
284
|
+
getPref<T>(key: string): Promise<T | undefined>;
|
|
285
|
+
modifyPref(key: string, value: unknown): Promise<void>;
|
|
286
|
+
}
|
|
287
|
+
interface IUploadInstance {
|
|
288
|
+
readonly s3Key: string;
|
|
289
|
+
readonly file: File | undefined;
|
|
290
|
+
readonly fileName: string;
|
|
291
|
+
readonly size: number;
|
|
292
|
+
readonly lastModified: number;
|
|
293
|
+
readonly type: string;
|
|
294
|
+
readonly xhr: XMLHttpRequest;
|
|
295
|
+
readonly status: {
|
|
296
|
+
status: UploadStatus['status'];
|
|
297
|
+
progress?: number;
|
|
298
|
+
error?: string;
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* This is the context object that is passed to the web component when it is rendered.
|
|
303
|
+
*/
|
|
304
|
+
interface PikaWCContext {
|
|
305
|
+
appState: IAppState;
|
|
306
|
+
renderingContext: WidgetRenderingContextType;
|
|
307
|
+
chatAppState: IChatAppState;
|
|
308
|
+
chatAppId: string;
|
|
309
|
+
/**
|
|
310
|
+
* Unique instance ID for this component instance.
|
|
311
|
+
* Set by injectChatAppWebComponent() and used by getWidgetMetadataAPI().
|
|
312
|
+
*/
|
|
313
|
+
instanceId: string;
|
|
314
|
+
/** Arbitrary data to be passed to the widget. */
|
|
315
|
+
dataForWidget: Record<string, any>;
|
|
316
|
+
}
|
|
317
|
+
type PikaWCContextWithoutInstanceId = Omit<PikaWCContext, 'instanceId'>;
|
|
318
|
+
type PikaWCContextRequestCallbackFn = (contextRequest: PikaWCContext) => void;
|
|
319
|
+
interface PikaWCContextRequestDetail {
|
|
320
|
+
callback: PikaWCContextRequestCallbackFn;
|
|
321
|
+
}
|
|
322
|
+
interface PikaWCContextRequestEvent extends CustomEvent<PikaWCContextRequestDetail> {
|
|
323
|
+
detail: PikaWCContextRequestDetail;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export type { IAppState, IChatAppState, IIdentityState, IUploadInstance, IUserPrefsState, IWidgetMetadataAPI, PikaWCContext, PikaWCContextRequestCallbackFn, PikaWCContextRequestDetail, PikaWCContextRequestEvent, PikaWCContextWithoutInstanceId, SidebarState, Snippet };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"webcomp-types.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"webcomp-types.mjs"}
|