@copilotkit/web-inspector 1.78.0 → 1.79.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.
package/dist/index.cjs CHANGED
@@ -28,6 +28,14 @@ let lucide = require("lucide");
28
28
  let _copilotkit_core = require("@copilotkit/core");
29
29
 
30
30
  //#region src/index.ts
31
+ /**
32
+ * Resolve the attached core's request headers at send time. A core released
33
+ * before `resolveHeaders()` existed has only the static `headers` map, so an
34
+ * inspector attached to it falls back to a copy of that map.
35
+ */
36
+ function resolveAttachedCoreHeaders(core) {
37
+ return typeof core.resolveHeaders === "function" ? core.resolveHeaders() : { ...core.headers };
38
+ }
31
39
  const WEB_INSPECTOR_TAG = "cpk-web-inspector";
32
40
  const THREAD_INSPECTOR_TAG = "cpk-thread-inspector";
33
41
  /**
@@ -1335,6 +1343,8 @@ var CpkThreadInspector = class CpkThreadInspector extends PortableLitElement {
1335
1343
  this.thread = null;
1336
1344
  this.runtimeUrl = "";
1337
1345
  this.headers = {};
1346
+ this.resolveHeaders = CpkThreadInspector.ɵdefaultResolveHeaders;
1347
+ this.headersGeneration = 0;
1338
1348
  this.threadInspectionAvailable = false;
1339
1349
  this.agentStateInput = null;
1340
1350
  this.agentEventsInput = [];
@@ -1429,6 +1439,8 @@ var CpkThreadInspector = class CpkThreadInspector extends PortableLitElement {
1429
1439
  thread: { attribute: false },
1430
1440
  runtimeUrl: { attribute: false },
1431
1441
  headers: { attribute: false },
1442
+ resolveHeaders: { attribute: false },
1443
+ headersGeneration: { attribute: false },
1432
1444
  threadInspectionAvailable: { attribute: false },
1433
1445
  agentStateInput: { attribute: false },
1434
1446
  agentEventsInput: { attribute: false },
@@ -1468,6 +1480,9 @@ var CpkThreadInspector = class CpkThreadInspector extends PortableLitElement {
1468
1480
  static {
1469
1481
  this.nextDomId = 1;
1470
1482
  }
1483
+ static {
1484
+ this.ɵdefaultResolveHeaders = () => ({});
1485
+ }
1471
1486
  static {
1472
1487
  this.COLLAPSE_THRESHOLD = 800;
1473
1488
  }
@@ -1509,14 +1524,6 @@ var CpkThreadInspector = class CpkThreadInspector extends PortableLitElement {
1509
1524
  provider.getState ? "state:1" : "state:0"
1510
1525
  ].join("|");
1511
1526
  }
1512
- /**
1513
- * Build a deterministic signature for runtime fetch headers so auth/CSRF
1514
- * changes invalidate cached thread data even when the selected thread is
1515
- * otherwise unchanged.
1516
- */
1517
- static headersLoadKey(headers) {
1518
- return JSON.stringify(Object.entries(headers).sort(([leftKey], [rightKey]) => leftKey.localeCompare(rightKey)));
1519
- }
1520
1527
  renderConversationActions() {
1521
1528
  return lit.html`<div class="cpk-td__timeline-toolbar">
1522
1529
  <button type="button" class="cpk-td__timeline-bulk-toggle" aria-pressed=${this._showEventTimeline} @click=${() => {
@@ -3017,7 +3024,7 @@ var CpkThreadInspector = class CpkThreadInspector extends PortableLitElement {
3017
3024
  this.threadId ?? "thread:none",
3018
3025
  CpkThreadInspector.providerLoadKey(this.provider),
3019
3026
  `runtime:${this.runtimeUrl}`,
3020
- `headers:${CpkThreadInspector.headersLoadKey(this.headers)}`,
3027
+ `headersGen:${this.headersGeneration}`,
3021
3028
  `inspect:${this.threadInspectionAvailable ? "1" : "0"}`
3022
3029
  ].join("||");
3023
3030
  }
@@ -3172,9 +3179,16 @@ var CpkThreadInspector = class CpkThreadInspector extends PortableLitElement {
3172
3179
  if (!controller.signal.aborted && this.threadId === threadId) this._loadingState = false;
3173
3180
  }
3174
3181
  }
3182
+ /**
3183
+ * `resolveHeaders` when a host actually set it; otherwise the deprecated
3184
+ * `headers` fallback. Never both — see the `headers` field's doc.
3185
+ */
3186
+ ɵresolveInspectorHeaders() {
3187
+ return this.resolveHeaders === CpkThreadInspector.ɵdefaultResolveHeaders ? this.headers : this.resolveHeaders();
3188
+ }
3175
3189
  async fetchRuntimeMessages(threadId, signal) {
3176
3190
  const res = await fetch(this.getThreadInspectionUrl(threadId, "messages"), {
3177
- headers: { ...this.headers },
3191
+ headers: { ...await this.ɵresolveInspectorHeaders() },
3178
3192
  signal
3179
3193
  });
3180
3194
  if (!res.ok) throw new Error(`HTTP ${res.status}`);
@@ -3182,7 +3196,7 @@ var CpkThreadInspector = class CpkThreadInspector extends PortableLitElement {
3182
3196
  }
3183
3197
  async fetchRuntimeEvents(threadId, signal) {
3184
3198
  const res = await fetch(this.getThreadInspectionUrl(threadId, "events"), {
3185
- headers: { ...this.headers },
3199
+ headers: { ...await this.ɵresolveInspectorHeaders() },
3186
3200
  signal
3187
3201
  });
3188
3202
  if (res.status === 501) return { status: "not-available" };
@@ -3194,7 +3208,7 @@ var CpkThreadInspector = class CpkThreadInspector extends PortableLitElement {
3194
3208
  }
3195
3209
  async fetchRuntimeState(threadId, signal) {
3196
3210
  const res = await fetch(this.getThreadInspectionUrl(threadId, "state"), {
3197
- headers: { ...this.headers },
3211
+ headers: { ...await this.ɵresolveInspectorHeaders() },
3198
3212
  signal
3199
3213
  });
3200
3214
  if (res.status === 501) return { status: "not-available" };
@@ -5145,6 +5159,7 @@ var WebInspectorElement = class WebInspectorElement extends lit.LitElement {
5145
5159
  constructor(..._args4) {
5146
5160
  super(..._args4);
5147
5161
  this._core = null;
5162
+ this.resolveCoreHeaders = () => this._core ? resolveAttachedCoreHeaders(this._core) : {};
5148
5163
  this.coreSubscriber = null;
5149
5164
  this.coreUnsubscribe = null;
5150
5165
  this._memories = [];
@@ -5462,7 +5477,6 @@ var WebInspectorElement = class WebInspectorElement extends lit.LitElement {
5462
5477
  insightsPage: options.insightsPage ?? this.learningSnapshot?.insightsPage.page ?? 1
5463
5478
  },
5464
5479
  fetch: core.ɵruntimeFetch,
5465
- headers: core.headers,
5466
5480
  credentials: core.credentials,
5467
5481
  signal: controller.signal
5468
5482
  });
@@ -6696,11 +6710,12 @@ var WebInspectorElement = class WebInspectorElement extends lit.LitElement {
6696
6710
  if (this.core?.getThreadStore(agentId)) return;
6697
6711
  const core = this.core;
6698
6712
  if (!core?.runtimeUrl) return;
6699
- const store = (0, _copilotkit_core.ɵcreateThreadStore)({ fetch: typeof core.ɵruntimeFetch === "function" ? core.ɵruntimeFetch : globalThis.fetch });
6713
+ const hasRuntimeFetch = typeof core.ɵruntimeFetch === "function";
6714
+ const store = (0, _copilotkit_core.ɵcreateThreadStore)({ fetch: hasRuntimeFetch ? core.ɵruntimeFetch : globalThis.fetch });
6700
6715
  store.start();
6701
6716
  store.setContext({
6702
6717
  runtimeUrl: core.runtimeUrl,
6703
- headers: { ...core.headers },
6718
+ ...hasRuntimeFetch ? {} : { headers: { ...core.headers } },
6704
6719
  wsUrl: core.intelligence?.wsUrl,
6705
6720
  agentId
6706
6721
  });
@@ -6738,9 +6753,10 @@ var WebInspectorElement = class WebInspectorElement extends lit.LitElement {
6738
6753
  if (!this.areThreadEndpointsAvailable()) return;
6739
6754
  const core = this.core;
6740
6755
  if (!core?.runtimeUrl) return;
6756
+ const hasRuntimeFetch = typeof core.ɵruntimeFetch === "function";
6741
6757
  for (const [agentId, store] of this._ownedThreadStores) store.setContext({
6742
6758
  runtimeUrl: core.runtimeUrl,
6743
- headers: { ...headers },
6759
+ ...hasRuntimeFetch ? {} : { headers: { ...headers } },
6744
6760
  wsUrl: core.intelligence?.wsUrl,
6745
6761
  agentId
6746
6762
  });
@@ -12547,7 +12563,8 @@ var WebInspectorElement = class WebInspectorElement extends lit.LitElement {
12547
12563
  if (!core?.runtimeUrl) throw new Error("Failed to load thread.");
12548
12564
  const baseUrl = core.runtimeUrl.replace(/\/+$/, "");
12549
12565
  const encodedThreadId = encodeURIComponent(thread.id);
12550
- const [messagesResponse, stateResponse] = await Promise.all([fetch(`${baseUrl}/threads/${encodedThreadId}/messages`, { headers: { ...core.headers } }), fetch(`${baseUrl}/threads/${encodedThreadId}/state`, { headers: { ...core.headers } })]);
12566
+ const headers = { ...await resolveAttachedCoreHeaders(core) };
12567
+ const [messagesResponse, stateResponse] = await Promise.all([fetch(`${baseUrl}/threads/${encodedThreadId}/messages`, { headers }), fetch(`${baseUrl}/threads/${encodedThreadId}/state`, { headers })]);
12551
12568
  if (!messagesResponse.ok) throw new Error(`Failed to load thread (HTTP ${messagesResponse.status}).`);
12552
12569
  const messagesBody = await messagesResponse.json();
12553
12570
  const stateBody = stateResponse.ok ? await stateResponse.json() : { state: {} };
@@ -14247,7 +14264,8 @@ var WebInspectorElement = class WebInspectorElement extends lit.LitElement {
14247
14264
  .thread=${selectedThread}
14248
14265
  .provider=${selectedThreadIsLocalExample ? this.getExampleThreadProvider(selectedThread.id) : null}
14249
14266
  .runtimeUrl=${selectedThreadIsLocalExample ? "" : this._core?.runtimeUrl ?? ""}
14250
- .headers=${this._core?.headers ?? {}}
14267
+ .resolveHeaders=${this.resolveCoreHeaders}
14268
+ .headersGeneration=${this._core?.ɵheadersGeneration ?? 0}
14251
14269
  .threadInspectionAvailable=${selectedThreadIsLocalExample || this.areThreadEndpointsAvailable() && this._core?.threadEndpoints?.inspect !== false}
14252
14270
  .liveMessageVersion=${this.liveMessageVersion.get(selectedThread.id) ?? 0}
14253
14271
  .viewInAppMode=${this.getViewInAppMode(selectedThread, selectedThreadIsLocalExample)}