site-operator 0.2.5 → 0.2.7

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
@@ -81,6 +81,11 @@ export declare class AgentChat extends LitElement {
81
81
  setAppLocation(location: AppState["location"]): void;
82
82
  setAppUI(ui: AppState["ui"]): void;
83
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;
84
89
  private _toggleHistory;
85
90
  private _handleSelectThread;
86
91
  private _toggleInspector;
@@ -287,6 +292,14 @@ export declare class ChatController implements ReactiveController {
287
292
  * Retorna el listado de conversaciones recientes.
288
293
  */
289
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;
290
303
  /**
291
304
  * Envía un mensaje a través del servicio.
292
305
  * @param content Contenido del mensaje.
@@ -315,6 +328,15 @@ export declare class ChatController implements ReactiveController {
315
328
  setAppLocation(location: AppState["location"]): void;
316
329
  setAppUI(ui: AppState["ui"]): void;
317
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;
318
340
  /**
319
341
  * Refresca el listado de conversaciones desde el servidor.
320
342
  */
@@ -372,6 +394,8 @@ declare class ChatService extends EventTarget {
372
394
  private _conversations;
373
395
  private _appContext;
374
396
  private _appState;
397
+ private _suggestedPrompts;
398
+ private _showPrompts;
375
399
  get isRunning(): boolean;
376
400
  get messages(): ({
377
401
  id: string;
@@ -423,6 +447,8 @@ declare class ChatService extends EventTarget {
423
447
  content: Record<string, any>;
424
448
  activityType: string;
425
449
  })[];
450
+ get suggestedPrompts(): SuggestedPrompt[];
451
+ get showPrompts(): boolean;
426
452
  private subscriber;
427
453
  constructor();
428
454
  /**
@@ -460,6 +486,15 @@ declare class ChatService extends EventTarget {
460
486
  setAppLocation(location: AppState["location"]): void;
461
487
  setAppUI(ui: AppState["ui"]): void;
462
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;
463
498
  sendMessage(content: string, role?: "developer" | "user" | "assistant" | "system" | "tool" | "activity"): Promise<void>;
464
499
  _ensureConversation(): Promise<void>;
465
500
  addPlaceholderMessage(): void;
@@ -482,6 +517,7 @@ export declare interface ChatThread {
482
517
  messages: UIMessage[];
483
518
  isRunning: boolean;
484
519
  title?: string;
520
+ suggestedPrompts?: SuggestedPrompt[];
485
521
  }
486
522
 
487
523
  /**
@@ -655,6 +691,11 @@ export declare interface NavigationAction {
655
691
  */
656
692
  export declare function register(): void;
657
693
 
694
+ export declare interface SuggestedPrompt {
695
+ caption: string;
696
+ message: string;
697
+ }
698
+
658
699
  export declare type UIMessage = Message & {
659
700
  isThinking?: boolean;
660
701
  createdAt?: number;
@@ -1378,10 +1378,43 @@ const styles$3 = i$1`
1378
1378
  font-size: 0.75rem;
1379
1379
  padding: 0.5rem;
1380
1380
  }
1381
+
1382
+ .prompts-list {
1383
+ display: flex;
1384
+ flex-direction: column;
1385
+ margin-bottom: 0.75rem;
1386
+ padding: 0 0.5rem;
1387
+ }
1388
+
1389
+ .prompt-item {
1390
+ background: transparent;
1391
+ border: none;
1392
+ border-bottom: 1px solid rgba(0, 0, 0, 0.05);
1393
+ padding: 0.625rem 0.5rem;
1394
+ text-align: left;
1395
+ cursor: pointer;
1396
+ font-size: 0.875rem;
1397
+ color: var(--agent-text-zinc-600, #52525b);
1398
+ transition: all 0.2s ease;
1399
+ border-radius: 0.375rem;
1400
+ white-space: nowrap;
1401
+ overflow: hidden;
1402
+ text-overflow: ellipsis;
1403
+ }
1404
+
1405
+ .prompt-item:last-child {
1406
+ border-bottom: none;
1407
+ }
1408
+
1409
+ .prompt-item:hover {
1410
+ background-color: var(--agent-bg-zinc-50, #fafafa);
1411
+ color: var(--agent-text-foreground, #09090b);
1412
+ padding-left: 0.75rem;
1413
+ }
1381
1414
  `;
1382
1415
  var ChatComposer = class extends i {
1383
1416
  constructor(...o) {
1384
- super(...o), this.isRunning = !1, this.disclaimer = "", this.placeholder = "", this._value = "";
1417
+ super(...o), this.isRunning = !1, this.disclaimer = "", this.placeholder = "", this.prompts = [], this._value = "";
1385
1418
  }
1386
1419
  static #e = this.styles = styles$3;
1387
1420
  _handleInput(o) {
@@ -1393,6 +1426,9 @@ var ChatComposer = class extends i {
1393
1426
  _adjustHeight() {
1394
1427
  this._textarea && (this._textarea.style.height = "auto", this._textarea.style.height = `${Math.min(this._textarea.scrollHeight, 160)}px`);
1395
1428
  }
1429
+ _handlePromptClick(o) {
1430
+ this._value = o.message, this._textarea.focus(), setTimeout(() => this._adjustHeight(), 0);
1431
+ }
1396
1432
  async _handleSubmit() {
1397
1433
  this._value.trim() && (this.dispatchEvent(new CustomEvent("send", {
1398
1434
  detail: { content: this._value },
@@ -1408,6 +1444,15 @@ var ChatComposer = class extends i {
1408
1444
  }
1409
1445
  render() {
1410
1446
  return b`
1447
+ ${this.prompts.length > 0 ? b`
1448
+ <div class="prompts-list">
1449
+ ${this.prompts.map((o) => b`
1450
+ <button class="prompt-item" @click="${() => this._handlePromptClick(o)}">
1451
+ ${o.caption}
1452
+ </button>
1453
+ `)}
1454
+ </div>
1455
+ ` : ""}
1411
1456
  <div class="composer-container">
1412
1457
  <textarea
1413
1458
  placeholder="${this.placeholder}"
@@ -1426,7 +1471,7 @@ var ChatComposer = class extends i {
1426
1471
  `;
1427
1472
  }
1428
1473
  };
1429
- __decorate([n({ type: Boolean })], ChatComposer.prototype, "isRunning", void 0), __decorate([n({ type: String })], ChatComposer.prototype, "disclaimer", void 0), __decorate([n({ type: String })], ChatComposer.prototype, "placeholder", void 0), __decorate([r()], ChatComposer.prototype, "_value", void 0), __decorate([e$5("textarea")], ChatComposer.prototype, "_textarea", void 0), ChatComposer = __decorate([t("agent-chat-composer")], ChatComposer);
1474
+ __decorate([n({ type: Boolean })], ChatComposer.prototype, "isRunning", void 0), __decorate([n({ type: String })], ChatComposer.prototype, "disclaimer", void 0), __decorate([n({ type: String })], ChatComposer.prototype, "placeholder", void 0), __decorate([n({ type: Array })], ChatComposer.prototype, "prompts", void 0), __decorate([r()], ChatComposer.prototype, "_value", void 0), __decorate([e$5("textarea")], ChatComposer.prototype, "_textarea", void 0), ChatComposer = __decorate([t("agent-chat-composer")], ChatComposer);
1430
1475
  var __defProp = Object.defineProperty, __defNormalProp = (o, O, M) => O in o ? __defProp(o, O, {
1431
1476
  enumerable: !0,
1432
1477
  configurable: !0,
@@ -3188,12 +3233,18 @@ const chatService = new class extends EventTarget {
3188
3233
  get messages() {
3189
3234
  return this.agent?.messages || [];
3190
3235
  }
3236
+ get suggestedPrompts() {
3237
+ return this._suggestedPrompts;
3238
+ }
3239
+ get showPrompts() {
3240
+ return this._showPrompts;
3241
+ }
3191
3242
  constructor() {
3192
3243
  super(), this._conversations = [], this._appContext = null, this._appState = {
3193
3244
  v: "1.1",
3194
3245
  location: { path: "" },
3195
3246
  ui: { visibleClickTargetIds: [] }
3196
- }, this.subscriber = new ChatSubscriber(this), chatPortalService.addEventListener("portal-registered", (o) => {
3247
+ }, this._suggestedPrompts = [], this._showPrompts = !1, this.subscriber = new ChatSubscriber(this), chatPortalService.addEventListener("portal-registered", (o) => {
3197
3248
  let O = o.detail;
3198
3249
  console.log("ChatService: Portal context detected", O), this.setAppContext(O);
3199
3250
  });
@@ -3243,6 +3294,15 @@ const chatService = new class extends EventTarget {
3243
3294
  setAppFocus(o) {
3244
3295
  this._appState.focus = o, this.notify();
3245
3296
  }
3297
+ setSuggestedPrompts(o) {
3298
+ this._suggestedPrompts = o.map((o) => ({
3299
+ ...o,
3300
+ caption: o.caption.slice(0, 50)
3301
+ })), this._showPrompts = !0, this.notify();
3302
+ }
3303
+ hideSuggestedPrompts() {
3304
+ this._showPrompts = !1, this.notify();
3305
+ }
3246
3306
  async sendMessage(o, O = "user") {
3247
3307
  if (!this.agent) {
3248
3308
  console.error("ChatService not initialized. Call initialize() first.");
@@ -3310,7 +3370,7 @@ const chatService = new class extends EventTarget {
3310
3370
  } catch (o) {
3311
3371
  console.error("Failed to send message", o);
3312
3372
  } finally {
3313
- this.notify();
3373
+ this._showPrompts = !1, this.notify();
3314
3374
  }
3315
3375
  }
3316
3376
  async _ensureConversation() {
@@ -3369,7 +3429,7 @@ const chatService = new class extends EventTarget {
3369
3429
  this.agent.messages = [...F, M], this.notify();
3370
3430
  }
3371
3431
  async startNewThread() {
3372
- localStorage.removeItem(STORAGE_THREAD_ID_KEY), this.agent && (this.agent.threadId = threadIdPlaceHolder, this.agent.messages = [], this.agent.isRunning = !1), this.notify();
3432
+ localStorage.removeItem(STORAGE_THREAD_ID_KEY), this.agent && (this.agent.threadId = threadIdPlaceHolder, this.agent.messages = [], this.agent.isRunning = !1), this._suggestedPrompts.length > 0 && (this._showPrompts = !0), this.notify();
3373
3433
  }
3374
3434
  async refreshConversations() {
3375
3435
  try {
@@ -3409,6 +3469,12 @@ var ChatController = class {
3409
3469
  get conversations() {
3410
3470
  return chatService.conversations;
3411
3471
  }
3472
+ get suggestedPrompts() {
3473
+ return chatService.suggestedPrompts;
3474
+ }
3475
+ get showPrompts() {
3476
+ return chatService.showPrompts;
3477
+ }
3412
3478
  sendMessage(o, O = "user") {
3413
3479
  return chatService.sendMessage(o, O);
3414
3480
  }
@@ -3433,6 +3499,12 @@ var ChatController = class {
3433
3499
  setAppFocus(o) {
3434
3500
  return chatService.setAppFocus(o);
3435
3501
  }
3502
+ setSuggestedPrompts(o) {
3503
+ return chatService.setSuggestedPrompts(o);
3504
+ }
3505
+ hideSuggestedPrompts() {
3506
+ return chatService.hideSuggestedPrompts();
3507
+ }
3436
3508
  refreshConversations() {
3437
3509
  return chatService.refreshConversations();
3438
3510
  }
@@ -3512,6 +3584,9 @@ var AgentChat = class extends i {
3512
3584
  setAppFocus(o) {
3513
3585
  this._chatController.setAppFocus(o);
3514
3586
  }
3587
+ setSuggestedPrompts(o) {
3588
+ this._chatController.setSuggestedPrompts(o);
3589
+ }
3515
3590
  _toggleHistory() {
3516
3591
  this._historyOpen = !this._historyOpen, this._historyOpen && this._chatController.refreshConversations();
3517
3592
  }
@@ -3546,6 +3621,7 @@ var AgentChat = class extends i {
3546
3621
  ?isRunning="${this._chatController.isRunning}"
3547
3622
  .disclaimer="${this.disclaimer}"
3548
3623
  .placeholder="${this.placeholder}"
3624
+ .prompts="${this._chatController.showPrompts ? this._chatController.suggestedPrompts : []}"
3549
3625
  @send="${this._handleSend}">
3550
3626
  </agent-chat-composer>
3551
3627