@artooi/ag-ui-web-component 0.3.1 → 0.4.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"ag_ui_chat.d.ts","sourceRoot":"","sources":["../../src/core/ag_ui_chat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAW,IAAI,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EACL,YAAY,EAOb,MAAM,iBAAiB,CAAC;AAGzB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,KAAK,UAAU,EAAsB,MAAM,kCAAkC,CAAC;AAGvF,OAAO,EAAwB,KAAK,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE1E,OAAO,EAAoB,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACxE,OAAO,EAAwB,KAAK,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAO9E,OAAO,EAAgB,KAAK,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAO7E,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EAE1B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,KAAK,YAAY,EAAmB,MAAM,wBAAwB,CAAC;AAE5E,8CAA8C;AAC9C,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,OAAO,YAAY,CAAC,CAAC;AAE3E,8DAA8D;AAC9D,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,8DAA8D;AAC9D,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC7B;AAKD;;;;;;;;;;;GAWG;AACH,qBAAa,QAAS,SAAQ,WAAW;;IACvC,wEAAwE;IACxE,YAAY,EAAE,YAAY,CAAmB;IAE7C,6DAA6D;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;;;;;;OAMG;IACH,aAAa,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,GAAG,cAAc;CAuZlE"}
@@ -48,11 +48,19 @@ export interface AgUiClientHandlers {
48
48
  onToolResult(toolCallId: string, content: string): void;
49
49
  onRunEnd(): void;
50
50
  onError(message: string): void;
51
+ /**
52
+ * Fired when the user cancelled the run ({@link AgUiClient.cancel}) — the
53
+ * deliberate-stop sibling of `onError`. Any partial assistant text already
54
+ * streamed stays valid; the host should keep the bubble and show a muted
55
+ * "stopped" affordance rather than an error. `onSettled` still follows.
56
+ */
57
+ onCancelled(): void;
51
58
  /**
52
59
  * Fired exactly once when the whole interaction settles — after the run loop
53
60
  * ends for any reason (a server-only round, frontend-tool rounds exhausted,
54
- * or an error). The terminal guarantee that the UI returns to rest (pending
55
- * indicator cleared, input re-enabled) no matter how the run finished.
61
+ * a cancellation, or an error). The terminal guarantee that the UI returns
62
+ * to rest (pending indicator cleared, input re-enabled) no matter how the
63
+ * run finished.
56
64
  */
57
65
  onSettled(): void;
58
66
  }
@@ -108,5 +116,13 @@ export declare class AgUiClient {
108
116
  resume(): Promise<void>;
109
117
  /** Append a frontend tool result to history (used by the resume path). */
110
118
  addToolResult(toolCallId: string, content: string): void;
119
+ /**
120
+ * Cancel the in-flight run (AG-UI has no server cancel route — aborting the
121
+ * streaming request is the protocol's cancel; the server observes the
122
+ * disconnect). Safe to call with no run in flight. Partial text already
123
+ * streamed stays in history; {@link AgUiClientHandlers.onCancelled} fires
124
+ * instead of `onError`, and `onSettled` still follows.
125
+ */
126
+ cancel(): void;
111
127
  }
112
128
  //# sourceMappingURL=agui_client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"agui_client.d.ts","sourceRoot":"","sources":["../../src/core/agui_client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAoC,MAAM,eAAe,CAAC;AACrF,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,M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E;IACxE,IAAI,QAAQ,IAAI,SAAS,OAAO,EAAE,CAEjC;IAED;;;;;;OAMG;IACG,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAM1C;;;;OAIG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAI7B,0EAA0E;IAC1E,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAKxD;;;;;;OAMG;IACH,MAAM,IAAI,IAAI;CAgHf"}
package/dist/index.d.ts CHANGED
@@ -15,7 +15,7 @@ export { createPageMapContext, type PageMap } from "./tools/page_map.js";
15
15
  export { parseToolCatalog, type ToolCatalogEntry } from "./tools/parse_tool_catalog.js";
16
16
  export { createRouteTools, type Route, type RouteMap, type RouteWithParams, } from "./tools/route_map.js";
17
17
  export { createStateHookTools, type StateHook } from "./tools/state_hook.js";
18
- export { type ConfirmationRequest, requestConfirmation } from "./ui/confirmation_card.js";
18
+ export { type ConfirmationOptions, type ConfirmationRequest, requestConfirmation, } from "./ui/confirmation_card.js";
19
19
  export { prettifyToolName } from "./ui/prettify_tool_name.js";
20
20
  export { type RenderMarkdownOptions, renderMarkdown } from "./ui/render_markdown.js";
21
21
  export { type SettledStatus, ToolCallCard, type ToolCallStatus, type ToolDisplayMode, } from "./ui/tool_call_card.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,WAAW,EACX,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,aAAa,GACd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,QAAQ,EACR,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,YAAY,GAClB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,UAAU,EACV,KAAK,gBAAg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aAAa,EAClB,YAAY,EACZ,KAAK,cAAc,EACnB,KAAK,eAAe,GACrB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -239,7 +239,7 @@ function actionButton(modifier, label) {
239
239
  button.textContent = label;
240
240
  return button;
241
241
  }
242
- function requestConfirmation(host, request) {
242
+ function requestConfirmation(host, request, options = {}) {
243
243
  return new Promise((resolve) => {
244
244
  const card = document.createElement("div");
245
245
  card.className = "confirm";
@@ -256,7 +256,12 @@ function requestConfirmation(host, request) {
256
256
  actions.className = "confirm-actions";
257
257
  const cancel = actionButton("cancel", "Cancel");
258
258
  const confirm = actionButton("confirm", "Confirm");
259
+ let settled = false;
259
260
  const close = (accepted) => {
261
+ if (settled) {
262
+ return;
263
+ }
264
+ settled = true;
260
265
  cancel.disabled = true;
261
266
  confirm.disabled = true;
262
267
  card.setAttribute("data-resolved", accepted ? "confirmed" : "declined");
@@ -264,9 +269,14 @@ function requestConfirmation(host, request) {
264
269
  };
265
270
  cancel.addEventListener("click", () => close(false));
266
271
  confirm.addEventListener("click", () => close(true));
272
+ options.signal?.addEventListener("abort", () => close(false), { once: true });
267
273
  actions.append(cancel, confirm);
268
274
  card.append(body, args, actions);
269
275
  host.appendChild(card);
276
+ if (options.signal?.aborted === true) {
277
+ close(false);
278
+ return;
279
+ }
270
280
  confirm.focus();
271
281
  });
272
282
  }
@@ -3449,6 +3459,19 @@ var STYLES = `
3449
3459
  cursor: default;
3450
3460
  }
3451
3461
 
3462
+ /* The composer button doubles as the Stop control while a run is in flight. */
3463
+ .send[data-state="running"] {
3464
+ background: var(--ag-ui-muted);
3465
+ }
3466
+
3467
+ /* Muted "\u23F9 Stopped" line after a cancelled run \u2014 a note, not an error bubble. */
3468
+ .stopped-note {
3469
+ align-self: flex-start;
3470
+ color: var(--ag-ui-muted);
3471
+ font-size: 12px;
3472
+ padding: 2px 4px;
3473
+ }
3474
+
3452
3475
  /* Inline confirmation card \u2014 lives in the transcript, no focus-stealing overlay. */
3453
3476
  .confirm {
3454
3477
  align-self: stretch;
@@ -3669,6 +3692,9 @@ var AgUiClient = class {
3669
3692
  #getContext;
3670
3693
  #executeTool;
3671
3694
  #onPersist;
3695
+ // Set by cancel(); reset at the top of each #run(). Checked by the loop so
3696
+ // a cancel between frontend-tool rounds doesn't start another round.
3697
+ #cancelled = false;
3672
3698
  constructor(config) {
3673
3699
  this.#agent = config.agent;
3674
3700
  this.#handlers = config.handlers;
@@ -3711,23 +3737,52 @@ var AgUiClient = class {
3711
3737
  this.#agent.addMessage({ id: randomUUID(), role: "tool", content, toolCallId });
3712
3738
  this.#onPersist(this.#agent.messages);
3713
3739
  }
3740
+ /**
3741
+ * Cancel the in-flight run (AG-UI has no server cancel route — aborting the
3742
+ * streaming request is the protocol's cancel; the server observes the
3743
+ * disconnect). Safe to call with no run in flight. Partial text already
3744
+ * streamed stays in history; {@link AgUiClientHandlers.onCancelled} fires
3745
+ * instead of `onError`, and `onSettled` still follows.
3746
+ */
3747
+ cancel() {
3748
+ this.#cancelled = true;
3749
+ this.#agent.abortRun();
3750
+ }
3714
3751
  async #run() {
3752
+ this.#cancelled = false;
3715
3753
  try {
3716
3754
  await this.#runLoop();
3755
+ if (this.#cancelled) {
3756
+ this.#onCancelled();
3757
+ }
3717
3758
  } catch (error) {
3718
- this.#handlers.onError(error instanceof Error ? error.message : String(error));
3759
+ if (this.#cancelled || isAbortError(error)) {
3760
+ this.#onCancelled();
3761
+ } else {
3762
+ this.#handlers.onError(error instanceof Error ? error.message : String(error));
3763
+ }
3719
3764
  } finally {
3720
3765
  this.#handlers.onSettled();
3721
3766
  }
3722
3767
  }
3768
+ #onCancelled() {
3769
+ this.#onPersist(this.#agent.messages);
3770
+ this.#handlers.onCancelled();
3771
+ }
3723
3772
  async #runLoop() {
3724
3773
  for (let round = 0; round < MAX_TOOL_ROUNDS; round += 1) {
3774
+ if (this.#cancelled) {
3775
+ return;
3776
+ }
3725
3777
  const pending = [];
3726
3778
  await this.#agent.runAgent(
3727
3779
  { tools: this.#getTools(), context: this.#getContext() },
3728
3780
  this.#buildSubscriber(pending)
3729
3781
  );
3730
3782
  this.#onPersist(this.#agent.messages);
3783
+ if (this.#cancelled) {
3784
+ return;
3785
+ }
3731
3786
  if (this.#executeTool === null || pending.length === 0) {
3732
3787
  return;
3733
3788
  }
@@ -3787,6 +3842,9 @@ var AgUiClient = class {
3787
3842
  };
3788
3843
  }
3789
3844
  };
3845
+ function isAbortError(error) {
3846
+ return error instanceof Error && error.name === "AbortError";
3847
+ }
3790
3848
 
3791
3849
  // src/core/conversation_store.ts
3792
3850
  import { randomUUID as randomUUID2 } from "@ag-ui/client";
@@ -3981,6 +4039,13 @@ var AgUiChat = class extends HTMLElement {
3981
4039
  #skillsMenu;
3982
4040
  #skillHint;
3983
4041
  #client = null;
4042
+ // Whether an interaction is in flight (first onRunStart → onSettled). Drives
4043
+ // the Send⇄Stop button: `agent.isRunning` is false between frontend-tool
4044
+ // rounds, but the user must still be able to stop there.
4045
+ #running = false;
4046
+ // Aborting this dismisses (declines) an open confirmation card when the run
4047
+ // is cancelled while the card awaits a decision. One controller per card.
4048
+ #confirmAbort = null;
3984
4049
  #streamingBubble = null;
3985
4050
  // Text deltas applied to the current streaming bubble. >1 ⇒ the message
3986
4051
  // revealed progressively as it streamed, so the word reveal must not re-animate
@@ -4216,6 +4281,7 @@ var AgUiChat = class extends HTMLElement {
4216
4281
  * in-memory run state, clear the transcript, and mint a new thread id.
4217
4282
  */
4218
4283
  newChat() {
4284
+ this.#cancelRun();
4219
4285
  this.conversationStore.clear(this.#threadId);
4220
4286
  this.#client = null;
4221
4287
  this.#streamingBubble = null;
@@ -4225,7 +4291,7 @@ var AgUiChat = class extends HTMLElement {
4225
4291
  this.#initialMessages = [];
4226
4292
  this.#messages.replaceChildren();
4227
4293
  this.#threadId = this.conversationStore.threadId();
4228
- this.#send.disabled = false;
4294
+ this.#setRunning(false);
4229
4295
  }
4230
4296
  /**
4231
4297
  * Restore the conversation from the store on mount, then — if a navigating
@@ -4370,7 +4436,13 @@ var AgUiChat = class extends HTMLElement {
4370
4436
  this.#send.className = "send";
4371
4437
  this.#send.type = "button";
4372
4438
  this.#send.textContent = "Send";
4439
+ this.#send.setAttribute("aria-label", "Send");
4440
+ this.#send.dataset["state"] = "idle";
4373
4441
  this.#send.addEventListener("click", () => {
4442
+ if (this.#running) {
4443
+ this.#cancelRun();
4444
+ return;
4445
+ }
4374
4446
  void this.#submit();
4375
4447
  });
4376
4448
  this.#skillHint.className = "skill-hint";
@@ -4396,11 +4468,34 @@ var AgUiChat = class extends HTMLElement {
4396
4468
  event.preventDefault();
4397
4469
  return;
4398
4470
  }
4471
+ if (event.key === "Escape" && this.#running) {
4472
+ event.preventDefault();
4473
+ this.#cancelRun();
4474
+ return;
4475
+ }
4399
4476
  if (event.key === "Enter" && !event.shiftKey) {
4400
4477
  event.preventDefault();
4401
4478
  void this.#submit();
4402
4479
  }
4403
4480
  }
4481
+ /**
4482
+ * Stop the in-flight run: decline any confirmation card awaiting a decision
4483
+ * (the loop is suspended on it), then cancel the client run — the abort
4484
+ * closes the streaming request, which is AG-UI's cancel (the server
4485
+ * observes the disconnect).
4486
+ */
4487
+ #cancelRun() {
4488
+ this.#confirmAbort?.abort();
4489
+ this.#client?.cancel();
4490
+ }
4491
+ /** Swap the composer button between Send (idle) and Stop (running). */
4492
+ #setRunning(running) {
4493
+ this.#running = running;
4494
+ const label = running ? "Stop" : "Send";
4495
+ this.#send.textContent = label;
4496
+ this.#send.setAttribute("aria-label", label);
4497
+ this.#send.dataset["state"] = running ? "running" : "idle";
4498
+ }
4404
4499
  async #submit() {
4405
4500
  const content = this.#input.value.trim();
4406
4501
  if (content === "") {
@@ -4472,9 +4567,13 @@ var AgUiChat = class extends HTMLElement {
4472
4567
  if (typeof confirmText === "string") {
4473
4568
  request.message = confirmText;
4474
4569
  }
4475
- const decision = requestConfirmation(this.#messages, request);
4570
+ this.#confirmAbort = new AbortController();
4571
+ const decision = requestConfirmation(this.#messages, request, {
4572
+ signal: this.#confirmAbort.signal
4573
+ });
4476
4574
  this.#messages.scrollTop = this.#messages.scrollHeight;
4477
4575
  const accepted = await decision;
4576
+ this.#confirmAbort = null;
4478
4577
  if (!accepted) {
4479
4578
  const message = "User declined the action.";
4480
4579
  card.settle(TOOL_CALL_STATUS.DECLINED, message);
@@ -4509,7 +4608,7 @@ var AgUiChat = class extends HTMLElement {
4509
4608
  #handlers() {
4510
4609
  return {
4511
4610
  onRunStart: () => {
4512
- this.#send.disabled = true;
4611
+ this.#setRunning(true);
4513
4612
  this.#showPending();
4514
4613
  },
4515
4614
  onTextDelta: (buffer) => {
@@ -4538,22 +4637,34 @@ var AgUiChat = class extends HTMLElement {
4538
4637
  },
4539
4638
  onRunEnd: () => {
4540
4639
  this.#hidePending();
4541
- this.#send.disabled = false;
4542
4640
  this.#streamingBubble = null;
4543
4641
  },
4544
4642
  onError: (message) => {
4545
4643
  this.#hidePending();
4546
4644
  this.#revealWords(this.appendMessage(MESSAGE_ROLE.ASSISTANT, `\u26A0\uFE0F ${message}`));
4547
- this.#send.disabled = false;
4645
+ this.#streamingBubble = null;
4646
+ },
4647
+ onCancelled: () => {
4648
+ this.#hidePending();
4649
+ this.#appendStoppedNote();
4548
4650
  this.#streamingBubble = null;
4549
4651
  },
4550
4652
  onSettled: () => {
4551
4653
  this.#hidePending();
4552
- this.#send.disabled = false;
4654
+ this.#setRunning(false);
4553
4655
  this.#streamingBubble = null;
4554
4656
  }
4555
4657
  };
4556
4658
  }
4659
+ /** A muted "⏹ Stopped" line in the transcript (distinct from the ⚠️ error bubble). */
4660
+ #appendStoppedNote() {
4661
+ const note = document.createElement("div");
4662
+ note.className = "stopped-note";
4663
+ note.setAttribute("role", "status");
4664
+ note.textContent = "\u23F9 Stopped";
4665
+ this.#messages.appendChild(note);
4666
+ this.#messages.scrollTop = this.#messages.scrollHeight;
4667
+ }
4557
4668
  /**
4558
4669
  * Show a "thinking" indicator while the agent is being awaited — both the
4559
4670
  * silent stretch before the first token and the gap after a tool result
@@ -4775,7 +4886,7 @@ function setControlValue(el, value) {
4775
4886
  }
4776
4887
 
4777
4888
  // src/version.ts
4778
- var VERSION = "0.3.1";
4889
+ var VERSION = "0.4.0";
4779
4890
  export {
4780
4891
  AgUiChat,
4781
4892
  AgUiClient,