@copilotkit/web-inspector 1.73.2 → 1.73.3

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.cjs CHANGED
@@ -1264,6 +1264,7 @@ var CpkThreadInspector = class CpkThreadInspector extends PortableLitElement {
1264
1264
  this._loadingEvents = false;
1265
1265
  this._loadingState = false;
1266
1266
  this._messagesError = null;
1267
+ this._messageRefreshError = null;
1267
1268
  this._eventsError = null;
1268
1269
  this._stateError = null;
1269
1270
  this._expandedTools = /* @__PURE__ */ new Set();
@@ -1356,6 +1357,7 @@ var CpkThreadInspector = class CpkThreadInspector extends PortableLitElement {
1356
1357
  _loadingEvents: { state: true },
1357
1358
  _loadingState: { state: true },
1358
1359
  _messagesError: { state: true },
1360
+ _messageRefreshError: { state: true },
1359
1361
  _eventsError: { state: true },
1360
1362
  _stateError: { state: true },
1361
1363
  _expandedTools: { state: true },
@@ -1432,7 +1434,7 @@ var CpkThreadInspector = class CpkThreadInspector extends PortableLitElement {
1432
1434
  </div>`;
1433
1435
  }
1434
1436
  renderTabContent(id) {
1435
- if (id === "timeline") return lit.html`${this._showEventTimeline ? lit.html`<div class="cpk-td__timeline-toolbar">${this.renderTimelineBulkButtons()}</div>${this.renderTimeline()}` : this._conversation.length || this._loadingMessages || this._messagesError ? this.renderConversation() : this.renderTimeline()}`;
1437
+ if (id === "timeline") return lit.html`${this._messageRefreshError ? lit.html`<div class="cpk-td__status cpk-td__status--error" role="status">${this._messageRefreshError}</div>` : lit.nothing}${this._showEventTimeline ? lit.html`<div class="cpk-td__timeline-toolbar">${this.renderTimelineBulkButtons()}</div>${this.renderTimeline()}` : this._conversation.length || this._loadingMessages || this._messagesError ? this.renderConversation() : this.renderTimeline()}`;
1436
1438
  if (id === "state") return this.renderState();
1437
1439
  return this.renderEvents();
1438
1440
  }
@@ -1985,10 +1987,19 @@ var CpkThreadInspector = class CpkThreadInspector extends PortableLitElement {
1985
1987
  background: #ffffff;
1986
1988
  color: #71717a;
1987
1989
  cursor: pointer;
1990
+ width: 100%;
1991
+ border: 0;
1992
+ font-family: inherit;
1993
+ text-align: left;
1988
1994
  font-size: 11px;
1989
1995
  user-select: none;
1990
1996
  }
1991
1997
 
1998
+ .cpk-td__tool-header:focus-visible {
1999
+ outline: 2px solid var(--cpk-primary-color, #7076b3);
2000
+ outline-offset: -2px;
2001
+ }
2002
+
1992
2003
  .cpk-td__tool-header:hover {
1993
2004
  background: #fafafa;
1994
2005
  }
@@ -2825,7 +2836,7 @@ var CpkThreadInspector = class CpkThreadInspector extends PortableLitElement {
2825
2836
  }
2826
2837
  scrollToFocusedMessage() {
2827
2838
  if (!this.focusMessageId) return;
2828
- const message = Array.from(this.shadowRoot?.querySelectorAll("[data-message-id]") ?? []).find((candidate) => candidate.dataset.messageId === this.focusMessageId);
2839
+ const message = Array.from(this.shadowRoot?.querySelectorAll(`#${this.panelDomId(this._tab)}:not([hidden]) [data-message-id]`) ?? []).find((candidate) => candidate.dataset.messageId === this.focusMessageId);
2829
2840
  if (!message) return;
2830
2841
  message.scrollIntoView?.({ block: "center" });
2831
2842
  this._scrolledFocusRequestId = this.focusRequestId;
@@ -2893,6 +2904,7 @@ var CpkThreadInspector = class CpkThreadInspector extends PortableLitElement {
2893
2904
  this._loadingEvents = false;
2894
2905
  this._loadingState = false;
2895
2906
  this._messagesError = null;
2907
+ this._messageRefreshError = null;
2896
2908
  this._eventsError = null;
2897
2909
  this._stateError = null;
2898
2910
  this._fetchedMetadata = null;
@@ -2911,7 +2923,7 @@ var CpkThreadInspector = class CpkThreadInspector extends PortableLitElement {
2911
2923
  this._fetchedMetadata = metadata;
2912
2924
  } catch (err) {
2913
2925
  if (err instanceof Error && err.name === "AbortError") return;
2914
- if (this.threadId !== threadId) return;
2926
+ if (controller.signal.aborted || this.threadId !== threadId) return;
2915
2927
  this._fetchedMetadata = null;
2916
2928
  }
2917
2929
  }
@@ -2936,19 +2948,23 @@ var CpkThreadInspector = class CpkThreadInspector extends PortableLitElement {
2936
2948
  if (!silent) {
2937
2949
  this._loadingMessages = true;
2938
2950
  this._messagesError = null;
2951
+ this._messageRefreshError = null;
2939
2952
  }
2940
2953
  try {
2941
2954
  const messages = this.provider?.getMessages ? await this.provider.getMessages(threadId, { signal: controller.signal }) : await this.fetchRuntimeMessages(threadId, controller.signal);
2942
2955
  if (controller.signal.aborted || this.threadId !== threadId) return;
2943
2956
  this._conversation = this.mapMessages(messages);
2957
+ this._messagesError = null;
2958
+ this._messageRefreshError = null;
2944
2959
  } catch (err) {
2960
+ if (controller.signal.aborted || this.threadId !== threadId) return;
2945
2961
  if (err instanceof Error && err.name === "AbortError") return;
2946
- if (!silent) {
2962
+ if (!silent || this._conversation.length === 0) {
2947
2963
  this._messagesError = err instanceof Error ? err.message : "Failed to load messages";
2948
2964
  this._conversation = [];
2949
- }
2965
+ } else this._messageRefreshError = "Could not refresh messages. Showing the last loaded conversation.";
2950
2966
  } finally {
2951
- if (!silent && !controller.signal.aborted) this._loadingMessages = false;
2967
+ if (!controller.signal.aborted && this.threadId === threadId) this._loadingMessages = false;
2952
2968
  }
2953
2969
  }
2954
2970
  async fetchEvents(threadId) {
@@ -2975,7 +2991,7 @@ var CpkThreadInspector = class CpkThreadInspector extends PortableLitElement {
2975
2991
  this._fetchedEvents = this.mapApiEvents(result.events);
2976
2992
  } catch (err) {
2977
2993
  if (err instanceof Error && err.name === "AbortError") return;
2978
- if (this.threadId !== threadId) return;
2994
+ if (controller.signal.aborted || this.threadId !== threadId) return;
2979
2995
  this._eventsError = err instanceof Error ? err.message : "Failed to load events";
2980
2996
  this._fetchedEvents = [];
2981
2997
  } finally {
@@ -3006,7 +3022,7 @@ var CpkThreadInspector = class CpkThreadInspector extends PortableLitElement {
3006
3022
  this._fetchedState = result.state ?? null;
3007
3023
  } catch (err) {
3008
3024
  if (err instanceof Error && err.name === "AbortError") return;
3009
- if (this.threadId !== threadId) return;
3025
+ if (controller.signal.aborted || this.threadId !== threadId) return;
3010
3026
  this._stateError = err instanceof Error ? err.message : "Failed to load state";
3011
3027
  this._fetchedState = null;
3012
3028
  } finally {
@@ -3083,6 +3099,7 @@ var CpkThreadInspector = class CpkThreadInspector extends PortableLitElement {
3083
3099
  toolCallId: tc.id,
3084
3100
  arguments: args,
3085
3101
  result: null,
3102
+ hasResult: false,
3086
3103
  createdAt: ""
3087
3104
  };
3088
3105
  toolCallMap.set(tc.id, item);
@@ -3103,18 +3120,23 @@ var CpkThreadInspector = class CpkThreadInspector extends PortableLitElement {
3103
3120
  });
3104
3121
  else if (msg.role === "tool" && msg.toolCallId) {
3105
3122
  const tc = toolCallMap.get(msg.toolCallId);
3106
- if (tc) try {
3107
- tc.result = this.parseToolCallContent(msg.content);
3108
- } catch (err) {
3109
- console.error("[CopilotKit Inspector] Failed to parse tool-call result content", {
3110
- toolCallId: msg.toolCallId,
3111
- raw: msg.content,
3112
- error: err
3113
- });
3114
- tc.result = {
3115
- __parseError: true,
3116
- __raw: msg.content ?? null
3117
- };
3123
+ if (tc) {
3124
+ tc.hasResult = true;
3125
+ tc.resultUnreadable = false;
3126
+ try {
3127
+ tc.result = this.parseToolCallContent(msg.content);
3128
+ } catch (err) {
3129
+ console.error("[CopilotKit Inspector] Failed to parse tool-call result content", {
3130
+ toolCallId: msg.toolCallId,
3131
+ raw: msg.content,
3132
+ error: err
3133
+ });
3134
+ tc.resultUnreadable = true;
3135
+ tc.result = {
3136
+ __parseError: true,
3137
+ __raw: msg.content ?? null
3138
+ };
3139
+ }
3118
3140
  }
3119
3141
  }
3120
3142
  return items;
@@ -3870,13 +3892,60 @@ var CpkThreadInspector = class CpkThreadInspector extends PortableLitElement {
3870
3892
  <span>No messages yet</span>
3871
3893
  </div>
3872
3894
  `;
3895
+ const items = this.renderItems;
3896
+ const errors = this.conversationRunErrors(items);
3873
3897
  return this.cachedPanelTpl("timeline-fallback", [
3874
3898
  this._conversation,
3875
3899
  this._expandedTools,
3876
- this._expandedMessages
3900
+ this._expandedMessages,
3901
+ JSON.stringify(errors),
3902
+ this._expandedTimelineDetails
3877
3903
  ], () => {
3878
- return lit.html`${this.renderItems.map((item) => this.renderRenderItem(item))}`;
3904
+ const errorsAfter = /* @__PURE__ */ new Map();
3905
+ for (const { after, item } of errors) {
3906
+ const group = errorsAfter.get(after) ?? [];
3907
+ group.push(item);
3908
+ errorsAfter.set(after, group);
3909
+ }
3910
+ const renderErrors = (after) => errorsAfter.get(after)?.map((item) => this.renderTimelineItem(item));
3911
+ return lit.html`
3912
+ ${renderErrors(-1)}
3913
+ ${items.map((item, index) => lit.html`${this.renderRenderItem(item)}${renderErrors(index)}`)}
3914
+ `;
3915
+ });
3916
+ }
3917
+ conversationRunErrors(items) {
3918
+ const positions = /* @__PURE__ */ new Map();
3919
+ items.forEach((item, index) => {
3920
+ positions.set(item.id, index);
3921
+ if (item.type === "tool_call_group") for (const tool of item.items) positions.set(tool.id, index);
3879
3922
  });
3923
+ const errors = [];
3924
+ let after = -1;
3925
+ let hasAnchor = false;
3926
+ for (const event of this.activeEvents) {
3927
+ const id = (event.type.startsWith("TOOL_CALL") ? [
3928
+ "toolCallId",
3929
+ "tool_call_id",
3930
+ "callId",
3931
+ "id"
3932
+ ] : event.type.startsWith("TEXT_MESSAGE") || event.type.startsWith("ACTIVITY") ? [
3933
+ "messageId",
3934
+ "message_id",
3935
+ "id"
3936
+ ] : []).map((key) => event.payload[key]).find((value) => typeof value === "string");
3937
+ const position = id == null ? void 0 : positions.get(id);
3938
+ if (position !== void 0) {
3939
+ after = Math.max(after, position);
3940
+ hasAnchor = true;
3941
+ }
3942
+ if (event.type === "RUN_ERROR" || event.type === "ERROR") for (const item of this.timelineItemsFromEvents([event])) errors.push({
3943
+ after,
3944
+ item
3945
+ });
3946
+ }
3947
+ if (!hasAnchor) for (const error of errors) error.after = items.length - 1;
3948
+ return errors;
3880
3949
  }
3881
3950
  /**
3882
3951
  * Memoize the rendered TemplateResult for `slot` keyed by tuple
@@ -3950,32 +4019,40 @@ var CpkThreadInspector = class CpkThreadInspector extends PortableLitElement {
3950
4019
  const expanded = this._expandedTools.has(item.id);
3951
4020
  return lit.html`
3952
4021
  <div class="cpk-td__tool-block">
3953
- <div
4022
+ <button
4023
+ type="button"
3954
4024
  class="cpk-td__tool-header"
4025
+ aria-expanded=${expanded}
3955
4026
  @click=${() => this.toggleToolExpand(item.id)}
3956
4027
  >
3957
- <svg width="10" height="10" viewBox="0 0 10 10" fill="none">
4028
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" aria-hidden="true">
3958
4029
  <path
3959
- d="M1 9C1 9 2 7 5 7C8 7 9 9 9 9M5 1C5 1 7 2.5 7 4.5C7 6.5 5 7 5 7C5 7 3 6.5 3 4.5C3 2.5 5 1 5 1Z"
4030
+ d="M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94z"
3960
4031
  stroke="currentColor"
3961
- stroke-width="1.2"
4032
+ stroke-width="2"
3962
4033
  stroke-linecap="round"
3963
4034
  stroke-linejoin="round"
3964
4035
  />
3965
4036
  </svg>
3966
4037
  <span class="cpk-td__tool-name">${item.toolName}</span>
3967
- ${item.result || Object.keys(item.arguments).length > 0 ? lit.html`
3968
- <span class="cpk-td__tool-status">Complete</span>
3969
- ` : lit.html`
3970
- <span class="cpk-td__tool-status cpk-td__tool-status--pending">Pending</span>
3971
- `}
4038
+ ${item.resultUnreadable ? lit.html`
4039
+ <span class="cpk-td__tool-status cpk-td__tool-status--pending"
4040
+ >Result unreadable</span
4041
+ >
4042
+ ` : item.hasResult ? lit.html`
4043
+ <span class="cpk-td__tool-status">Result received</span>
4044
+ ` : lit.html`
4045
+ <span class="cpk-td__tool-status cpk-td__tool-status--pending"
4046
+ >No result recorded</span
4047
+ >
4048
+ `}
3972
4049
  <span class="cpk-td__tool-chevron">${expanded ? "▾" : "▸"}</span>
3973
- </div>
4050
+ </button>
3974
4051
  ${expanded ? lit.html`
3975
4052
  <div class="cpk-td__tool-body">
3976
4053
  <div class="cpk-td__tool-section-label">Arguments</div>
3977
4054
  ${renderHighlightedJsonBlock(item.arguments)}
3978
- ${item.result ? lit.html`
4055
+ ${item.hasResult ? lit.html`
3979
4056
  <div
3980
4057
  class="cpk-td__tool-section-label"
3981
4058
  style="margin-top:8px"
@@ -10358,17 +10435,15 @@ var WebInspectorElement = class WebInspectorElement extends lit.LitElement {
10358
10435
  }
10359
10436
  renderHomeView() {
10360
10437
  const model = this.getHomeModel();
10361
- const connected = model.hero.connection === "connected";
10362
10438
  return lit.html`
10363
10439
  <div
10364
10440
  class="inspector-home"
10365
10441
  data-inspector-home
10366
- data-inspector-home-state=${connected ? "connected" : "disconnected"}
10442
+ data-inspector-home-state=${model.hero.connection === "connected" ? "connected" : "disconnected"}
10367
10443
  >
10368
10444
  ${this.renderHomeWhatsNewPreview(model.news)}
10369
- <header class="inspector-home-heading"><div><h1>${connected ? model.project?.projectName ?? "Your agent workspace" : "Welcome to Intelligence"}</h1><p>${connected ? "Inspect conversations and see what your agent is learning." : "Connect your agent. Intelligence learns from experience."}</p></div></header>
10370
- ${connected ? this.renderHomeSystemHealth(model) : this.renderHomeIntelligenceHud(model)}
10371
- ${connected ? this.renderHomeIntelligenceHud(model) : this.renderHomeSystemHealth(model)}
10445
+ ${this.renderHomeSystemHealth(model)}
10446
+ ${this.renderHomeIntelligenceHud(model)}
10372
10447
  ${this.renderHomeFeatures(model)}
10373
10448
  </div>
10374
10449
  `;