site-operator 0.2.1 → 0.2.5

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;
@@ -50,6 +86,17 @@ export declare class AgentChat extends LitElement {
50
86
  private _toggleInspector;
51
87
  render(): TemplateResult<1>;
52
88
  private _handleContextUpdate;
89
+ private _handleA2UIAction;
90
+ /**
91
+ * Maneja acciones de tipo 'decision' (Aprobar/Denegar).
92
+ * Si es 'approve', abre una URL y espera a que se cierre la pestaña antes de notificar.
93
+ * Si es 'deny', notifica inmediatamente.
94
+ */
95
+ private _handleAuthDecision;
96
+ /**
97
+ * Handler genérico para cualquier acción que contenga una URL.
98
+ */
99
+ private _handleGenericUrlAction;
53
100
  private _handleStateUpdate;
54
101
  }
55
102
 
@@ -243,8 +290,9 @@ export declare class ChatController implements ReactiveController {
243
290
  /**
244
291
  * Envía un mensaje a través del servicio.
245
292
  * @param content Contenido del mensaje.
293
+ * @param role Rol del mensaje (opcional, por defecto 'user').
246
294
  */
247
- sendMessage(content: string): Promise<void>;
295
+ sendMessage(content: string, role?: Parameters<typeof chatService.sendMessage>[1]): Promise<void>;
248
296
  /**
249
297
  * Inicia un nuevo hilo de charla.
250
298
  */
@@ -285,22 +333,31 @@ export declare interface ChatPortalAPI {
285
333
  /**
286
334
  * Registers the host application's static context.
287
335
  * @param context The application definition (routes, site info, etc.)
336
+ * @param handlers Optional handlers for executing plans (e.g. navigation)
288
337
  */
289
- registerPortal(context: AppContext): void;
338
+ registerPortal(context: AppContext, handlers?: {
339
+ executePlan?: (plan: Action) => Promise<ExecutePlanResult>;
340
+ }): void;
290
341
  /**
291
342
  * Executes a proposed plan of actions (navigation, clicks).
292
343
  * @param plan The plan object generated by the agent.
293
344
  */
294
- executePlan(plan: unknown): Promise<ExecutePlanResult>;
345
+ executePlan(plan: Action): Promise<ExecutePlanResult>;
295
346
  }
296
347
 
297
348
  export declare class ChatPortalService extends EventTarget implements ChatPortalAPI {
298
349
  private _context;
350
+ private _visibleTargetIds;
299
351
  private static _instance;
352
+ private _executePlanHandler;
300
353
  private constructor();
301
354
  static getInstance(): ChatPortalService;
302
- registerPortal(context: AppContext): void;
303
- executePlan(plan: unknown): Promise<ExecutePlanResult>;
355
+ registerPortal(context: AppContext, handlers?: {
356
+ executePlan?: (plan: Action) => Promise<ExecutePlanResult>;
357
+ }): void;
358
+ setVisibleTargets(ids: string[]): void;
359
+ executePlan(plan: Action): Promise<ExecutePlanResult>;
360
+ private _waitForTarget;
304
361
  get context(): AppContext | null;
305
362
  /**
306
363
  * @deprecated Use context instead
@@ -310,6 +367,116 @@ export declare class ChatPortalService extends EventTarget implements ChatPortal
310
367
 
311
368
  export declare const chatPortalService: ChatPortalService;
312
369
 
370
+ declare class ChatService extends EventTarget {
371
+ private agent?;
372
+ private _conversations;
373
+ private _appContext;
374
+ private _appState;
375
+ get isRunning(): boolean;
376
+ get messages(): ({
377
+ id: string;
378
+ role: "developer";
379
+ content: string;
380
+ name?: string | undefined;
381
+ } | {
382
+ id: string;
383
+ role: "system";
384
+ content: string;
385
+ name?: string | undefined;
386
+ } | {
387
+ id: string;
388
+ role: "assistant";
389
+ name?: string | undefined;
390
+ content?: string | undefined;
391
+ toolCalls?: {
392
+ function: {
393
+ name: string;
394
+ arguments: string;
395
+ };
396
+ type: "function";
397
+ id: string;
398
+ }[] | undefined;
399
+ } | {
400
+ id: string;
401
+ role: "user";
402
+ content: string | ({
403
+ type: "text";
404
+ text: string;
405
+ } | {
406
+ type: "binary";
407
+ mimeType: string;
408
+ id?: string | undefined;
409
+ url?: string | undefined;
410
+ data?: string | undefined;
411
+ filename?: string | undefined;
412
+ })[];
413
+ name?: string | undefined;
414
+ } | {
415
+ id: string;
416
+ role: "tool";
417
+ content: string;
418
+ toolCallId: string;
419
+ error?: string | undefined;
420
+ } | {
421
+ id: string;
422
+ role: "activity";
423
+ content: Record<string, any>;
424
+ activityType: string;
425
+ })[];
426
+ private subscriber;
427
+ constructor();
428
+ /**
429
+ * Inicializa el servicio de chat con las URLs necesarias y el nombre de la aplicación.
430
+ * @param config Configuración de inicialización.
431
+ */
432
+ initialize(config: {
433
+ backendUrl: string;
434
+ conversationUrl: string;
435
+ appName: string;
436
+ inspector?: boolean;
437
+ }): Promise<void>;
438
+ /**
439
+ * Carga una conversación existente por su ID.
440
+ * @param id ID de la conversación a cargar.
441
+ */
442
+ loadConversation(id: string): Promise<void>;
443
+ get conversations(): ConversationSummary[];
444
+ /**
445
+ * Establece el contexto de la aplicación para el agente.
446
+ * Este contexto se envía en cada mensaje.
447
+ * @param context El contexto de la aplicación (AgentState o AppContext)
448
+ */
449
+ setAppContext(context: AppContext): void;
450
+ /**
451
+ * Establece el estado dinámico de la aplicación.
452
+ * @param state El estado completo de la aplicación.
453
+ */
454
+ setAppState(state: AppState): void;
455
+ /**
456
+ * Actualiza el estado dinámico de la aplicación de forma parcial.
457
+ * @param partial El estado parcial de la aplicación.
458
+ */
459
+ updateAppState(partial: Partial<AppState>): void;
460
+ setAppLocation(location: AppState["location"]): void;
461
+ setAppUI(ui: AppState["ui"]): void;
462
+ setAppFocus(focus: AppState["focus"]): void;
463
+ sendMessage(content: string, role?: "developer" | "user" | "assistant" | "system" | "tool" | "activity"): Promise<void>;
464
+ _ensureConversation(): Promise<void>;
465
+ addPlaceholderMessage(): void;
466
+ prepareMessageForStreaming(newId: string): void;
467
+ appendMessageContent(id: string, content: string): void;
468
+ setMessages(messages: Message[]): void;
469
+ addA2UIMessage(event: ActivitySnapshotEvent): void;
470
+ startNewThread(): Promise<void>;
471
+ /**
472
+ * Refresca la lista de conversaciones desde el servicio de conversaciones.
473
+ */
474
+ refreshConversations(): Promise<void>;
475
+ private notify;
476
+ }
477
+
478
+ declare const chatService: ChatService;
479
+
313
480
  export declare interface ChatThread {
314
481
  id: string;
315
482
  messages: UIMessage[];
@@ -317,32 +484,6 @@ export declare interface ChatThread {
317
484
  title?: string;
318
485
  }
319
486
 
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
487
  /**
347
488
  * Defines a clickable or interactive element in the UI.
348
489
  */
@@ -375,7 +516,7 @@ export declare interface ClickTarget {
375
516
  href?: string;
376
517
  };
377
518
  /** The action that should be performed when this target is activated */
378
- action: ClickAction;
519
+ action: Action;
379
520
  }
380
521
 
381
522
  /**
@@ -497,6 +638,17 @@ export { Message }
497
638
  */
498
639
  export declare function mount(element: HTMLElement, options?: any): AgentChat;
499
640
 
641
+ /**
642
+ * Specific action for navigation, often initiated by an agent.
643
+ */
644
+ export declare interface NavigationAction {
645
+ type: "navigate";
646
+ /** The path to navigate to */
647
+ toPath: string;
648
+ /** The reason for the navigation */
649
+ reason?: string;
650
+ }
651
+
500
652
  /**
501
653
  * Registers the web component.
502
654
  * (It's already registered by import, but this can be a safe-guard re-export or initialization function)