site-operator 0.2.1 → 0.2.6

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.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { ActivitySnapshotEvent } from '@ag-ui/client';
1
2
  import { CSSResult } from 'lit';
2
3
  import { LitElement } from 'lit';
3
4
  import { Message } from '@ag-ui/client';
@@ -6,11 +7,46 @@ import { ReactiveController } from 'lit';
6
7
  import { ReactiveControllerHost } from 'lit';
7
8
  import { TemplateResult } from 'lit-html';
8
9
 
10
+ /**
11
+ * Union type representing the possible actions triggered by a ClickTarget.
12
+ */
13
+ export declare type Action = NavigationAction | {
14
+ /** Navigates to a different page using route ID */
15
+ type: "navigate";
16
+ /** ID of the target route */
17
+ toRouteId?: string;
18
+ /** Fallback path if route ID is not provided */
19
+ toPath?: string;
20
+ } | {
21
+ /** Opens a modal, drawer, or panel */
22
+ type: "open";
23
+ /** Identifier for the target UI component to open */
24
+ targetId: string;
25
+ } | {
26
+ /** Triggers a custom event or callback in the host application */
27
+ type: "trigger";
28
+ /** Custom string to identify the trigger in the application logic */
29
+ trigger: string;
30
+ } | {
31
+ /** Clicks on a specific element by ID */
32
+ type: "click";
33
+ /** Identifier for the target UI element to click or interact with */
34
+ targetId: string;
35
+ /** Optional reason for the click */
36
+ reason?: string;
37
+ } | {
38
+ /** Generic action type for extension */
39
+ type: string;
40
+ [k: string]: unknown;
41
+ };
42
+
9
43
  export declare class AgentChat extends LitElement {
10
44
  static styles: CSSResult;
11
45
  private _chatController;
12
46
  get controller(): ChatController;
13
47
  protected firstUpdated(): void;
48
+ connectedCallback(): void;
49
+ disconnectedCallback(): void;
14
50
  backendUrl: string;
15
51
  appName: string;
16
52
  conversationUrl: string;
@@ -45,11 +81,27 @@ export declare class AgentChat extends LitElement {
45
81
  setAppLocation(location: AppState["location"]): void;
46
82
  setAppUI(ui: AppState["ui"]): void;
47
83
  setAppFocus(focus: AppState["focus"]): void;
84
+ /**
85
+ * Establece los prompts sugeridos que se mostrarán al usuario.
86
+ * @param prompts Lista de prompts sugeridos.
87
+ */
88
+ setSuggestedPrompts(prompts: SuggestedPrompt[]): void;
48
89
  private _toggleHistory;
49
90
  private _handleSelectThread;
50
91
  private _toggleInspector;
51
92
  render(): TemplateResult<1>;
52
93
  private _handleContextUpdate;
94
+ private _handleA2UIAction;
95
+ /**
96
+ * Maneja acciones de tipo 'decision' (Aprobar/Denegar).
97
+ * Si es 'approve', abre una URL y espera a que se cierre la pestaña antes de notificar.
98
+ * Si es 'deny', notifica inmediatamente.
99
+ */
100
+ private _handleAuthDecision;
101
+ /**
102
+ * Handler genérico para cualquier acción que contenga una URL.
103
+ */
104
+ private _handleGenericUrlAction;
53
105
  private _handleStateUpdate;
54
106
  }
55
107
 
@@ -240,11 +292,20 @@ export declare class ChatController implements ReactiveController {
240
292
  * Retorna el listado de conversaciones recientes.
241
293
  */
242
294
  get conversations(): ConversationSummary[];
295
+ /**
296
+ * Retorna los prompts sugeridos.
297
+ */
298
+ get suggestedPrompts(): SuggestedPrompt[];
299
+ /**
300
+ * Indica si se deben mostrar los prompts.
301
+ */
302
+ get showPrompts(): boolean;
243
303
  /**
244
304
  * Envía un mensaje a través del servicio.
245
305
  * @param content Contenido del mensaje.
306
+ * @param role Rol del mensaje (opcional, por defecto 'user').
246
307
  */
247
- sendMessage(content: string): Promise<void>;
308
+ sendMessage(content: string, role?: Parameters<typeof chatService.sendMessage>[1]): Promise<void>;
248
309
  /**
249
310
  * Inicia un nuevo hilo de charla.
250
311
  */
@@ -267,6 +328,15 @@ export declare class ChatController implements ReactiveController {
267
328
  setAppLocation(location: AppState["location"]): void;
268
329
  setAppUI(ui: AppState["ui"]): void;
269
330
  setAppFocus(focus: AppState["focus"]): void;
331
+ /**
332
+ * Establece los prompts sugeridos.
333
+ * @param prompts Lista de prompts.
334
+ */
335
+ setSuggestedPrompts(prompts: SuggestedPrompt[]): void;
336
+ /**
337
+ * Oculta los prompts sugeridos.
338
+ */
339
+ hideSuggestedPrompts(): void;
270
340
  /**
271
341
  * Refresca el listado de conversaciones desde el servidor.
272
342
  */
@@ -285,22 +355,31 @@ export declare interface ChatPortalAPI {
285
355
  /**
286
356
  * Registers the host application's static context.
287
357
  * @param context The application definition (routes, site info, etc.)
358
+ * @param handlers Optional handlers for executing plans (e.g. navigation)
288
359
  */
289
- registerPortal(context: AppContext): void;
360
+ registerPortal(context: AppContext, handlers?: {
361
+ executePlan?: (plan: Action) => Promise<ExecutePlanResult>;
362
+ }): void;
290
363
  /**
291
364
  * Executes a proposed plan of actions (navigation, clicks).
292
365
  * @param plan The plan object generated by the agent.
293
366
  */
294
- executePlan(plan: unknown): Promise<ExecutePlanResult>;
367
+ executePlan(plan: Action): Promise<ExecutePlanResult>;
295
368
  }
296
369
 
297
370
  export declare class ChatPortalService extends EventTarget implements ChatPortalAPI {
298
371
  private _context;
372
+ private _visibleTargetIds;
299
373
  private static _instance;
374
+ private _executePlanHandler;
300
375
  private constructor();
301
376
  static getInstance(): ChatPortalService;
302
- registerPortal(context: AppContext): void;
303
- executePlan(plan: unknown): Promise<ExecutePlanResult>;
377
+ registerPortal(context: AppContext, handlers?: {
378
+ executePlan?: (plan: Action) => Promise<ExecutePlanResult>;
379
+ }): void;
380
+ setVisibleTargets(ids: string[]): void;
381
+ executePlan(plan: Action): Promise<ExecutePlanResult>;
382
+ private _waitForTarget;
304
383
  get context(): AppContext | null;
305
384
  /**
306
385
  * @deprecated Use context instead
@@ -310,39 +389,137 @@ export declare class ChatPortalService extends EventTarget implements ChatPortal
310
389
 
311
390
  export declare const chatPortalService: ChatPortalService;
312
391
 
392
+ declare class ChatService extends EventTarget {
393
+ private agent?;
394
+ private _conversations;
395
+ private _appContext;
396
+ private _appState;
397
+ private _suggestedPrompts;
398
+ private _showPrompts;
399
+ get isRunning(): boolean;
400
+ get messages(): ({
401
+ id: string;
402
+ role: "developer";
403
+ content: string;
404
+ name?: string | undefined;
405
+ } | {
406
+ id: string;
407
+ role: "system";
408
+ content: string;
409
+ name?: string | undefined;
410
+ } | {
411
+ id: string;
412
+ role: "assistant";
413
+ name?: string | undefined;
414
+ content?: string | undefined;
415
+ toolCalls?: {
416
+ function: {
417
+ name: string;
418
+ arguments: string;
419
+ };
420
+ type: "function";
421
+ id: string;
422
+ }[] | undefined;
423
+ } | {
424
+ id: string;
425
+ role: "user";
426
+ content: string | ({
427
+ type: "text";
428
+ text: string;
429
+ } | {
430
+ type: "binary";
431
+ mimeType: string;
432
+ id?: string | undefined;
433
+ url?: string | undefined;
434
+ data?: string | undefined;
435
+ filename?: string | undefined;
436
+ })[];
437
+ name?: string | undefined;
438
+ } | {
439
+ id: string;
440
+ role: "tool";
441
+ content: string;
442
+ toolCallId: string;
443
+ error?: string | undefined;
444
+ } | {
445
+ id: string;
446
+ role: "activity";
447
+ content: Record<string, any>;
448
+ activityType: string;
449
+ })[];
450
+ get suggestedPrompts(): SuggestedPrompt[];
451
+ get showPrompts(): boolean;
452
+ private subscriber;
453
+ constructor();
454
+ /**
455
+ * Inicializa el servicio de chat con las URLs necesarias y el nombre de la aplicación.
456
+ * @param config Configuración de inicialización.
457
+ */
458
+ initialize(config: {
459
+ backendUrl: string;
460
+ conversationUrl: string;
461
+ appName: string;
462
+ inspector?: boolean;
463
+ }): Promise<void>;
464
+ /**
465
+ * Carga una conversación existente por su ID.
466
+ * @param id ID de la conversación a cargar.
467
+ */
468
+ loadConversation(id: string): Promise<void>;
469
+ get conversations(): ConversationSummary[];
470
+ /**
471
+ * Establece el contexto de la aplicación para el agente.
472
+ * Este contexto se envía en cada mensaje.
473
+ * @param context El contexto de la aplicación (AgentState o AppContext)
474
+ */
475
+ setAppContext(context: AppContext): void;
476
+ /**
477
+ * Establece el estado dinámico de la aplicación.
478
+ * @param state El estado completo de la aplicación.
479
+ */
480
+ setAppState(state: AppState): void;
481
+ /**
482
+ * Actualiza el estado dinámico de la aplicación de forma parcial.
483
+ * @param partial El estado parcial de la aplicación.
484
+ */
485
+ updateAppState(partial: Partial<AppState>): void;
486
+ setAppLocation(location: AppState["location"]): void;
487
+ setAppUI(ui: AppState["ui"]): void;
488
+ setAppFocus(focus: AppState["focus"]): void;
489
+ /**
490
+ * Establece los prompts sugeridos que se mostrarán al usuario.
491
+ * @param prompts Lista de prompts sugeridos. El caption tiene un máximo de 50 caracteres.
492
+ */
493
+ setSuggestedPrompts(prompts: SuggestedPrompt[]): void;
494
+ /**
495
+ * Oculta la lista de prompts sugeridos.
496
+ */
497
+ hideSuggestedPrompts(): void;
498
+ sendMessage(content: string, role?: "developer" | "user" | "assistant" | "system" | "tool" | "activity"): Promise<void>;
499
+ _ensureConversation(): Promise<void>;
500
+ addPlaceholderMessage(): void;
501
+ prepareMessageForStreaming(newId: string): void;
502
+ appendMessageContent(id: string, content: string): void;
503
+ setMessages(messages: Message[]): void;
504
+ addA2UIMessage(event: ActivitySnapshotEvent): void;
505
+ startNewThread(): Promise<void>;
506
+ /**
507
+ * Refresca la lista de conversaciones desde el servicio de conversaciones.
508
+ */
509
+ refreshConversations(): Promise<void>;
510
+ private notify;
511
+ }
512
+
513
+ declare const chatService: ChatService;
514
+
313
515
  export declare interface ChatThread {
314
516
  id: string;
315
517
  messages: UIMessage[];
316
518
  isRunning: boolean;
317
519
  title?: string;
520
+ suggestedPrompts?: SuggestedPrompt[];
318
521
  }
319
522
 
320
- /**
321
- * Union type representing the possible actions triggered by a ClickTarget.
322
- */
323
- export declare type ClickAction = {
324
- /** Navigates to a different page */
325
- type: "navigate";
326
- /** ID of the target route */
327
- toRouteId?: string;
328
- /** Fallback path if route ID is not provided */
329
- toPath?: string;
330
- } | {
331
- /** Opens a modal, drawer, or panel */
332
- type: "open";
333
- /** Identifier for the target UI component to open */
334
- targetId: string;
335
- } | {
336
- /** Triggers a custom event or callback in the host application */
337
- type: "trigger";
338
- /** Custom string to identify the trigger in the application logic */
339
- trigger: string;
340
- } | {
341
- /** Generic action type for extension */
342
- type: string;
343
- [k: string]: unknown;
344
- };
345
-
346
523
  /**
347
524
  * Defines a clickable or interactive element in the UI.
348
525
  */
@@ -375,7 +552,7 @@ export declare interface ClickTarget {
375
552
  href?: string;
376
553
  };
377
554
  /** The action that should be performed when this target is activated */
378
- action: ClickAction;
555
+ action: Action;
379
556
  }
380
557
 
381
558
  /**
@@ -497,12 +674,28 @@ export { Message }
497
674
  */
498
675
  export declare function mount(element: HTMLElement, options?: any): AgentChat;
499
676
 
677
+ /**
678
+ * Specific action for navigation, often initiated by an agent.
679
+ */
680
+ export declare interface NavigationAction {
681
+ type: "navigate";
682
+ /** The path to navigate to */
683
+ toPath: string;
684
+ /** The reason for the navigation */
685
+ reason?: string;
686
+ }
687
+
500
688
  /**
501
689
  * Registers the web component.
502
690
  * (It's already registered by import, but this can be a safe-guard re-export or initialization function)
503
691
  */
504
692
  export declare function register(): void;
505
693
 
694
+ export declare interface SuggestedPrompt {
695
+ caption: string;
696
+ message: string;
697
+ }
698
+
506
699
  export declare type UIMessage = Message & {
507
700
  isThinking?: boolean;
508
701
  createdAt?: number;