@copilotkit/core 1.71.2 → 1.72.1-canary.sp-longthread-perf

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
@@ -648,6 +648,13 @@ var ProxiedCopilotRuntimeAgent = class ProxiedCopilotRuntimeAgent extends _ag_ui
648
648
  credentials;
649
649
  runtimeAgentId;
650
650
  transport;
651
+ /**
652
+ * The runtime URL exactly as the caller supplied it. `runtimeUrl` is the
653
+ * slash-stripped form used for path joins; the single-route endpoint (run,
654
+ * connect, stop, info envelopes) is this verbatim value, because a trailing
655
+ * slash can select a different proxy location.
656
+ */
657
+ runtimeEndpointUrl;
651
658
  singleEndpointUrl;
652
659
  runtimeMode;
653
660
  intelligence;
@@ -658,13 +665,14 @@ var ProxiedCopilotRuntimeAgent = class ProxiedCopilotRuntimeAgent extends _ag_ui
658
665
  const normalizedRuntimeUrl = config.runtimeUrl ? config.runtimeUrl.replace(/\/$/, "") : void 0;
659
666
  const transport = config.transport ?? "auto";
660
667
  const routedId = config.runtimeAgentId ?? config.agentId ?? "";
661
- const runUrl = transport === "single" ? normalizedRuntimeUrl ?? config.runtimeUrl ?? "" : `${normalizedRuntimeUrl ?? config.runtimeUrl}/agent/${encodeURIComponent(routedId)}/run`;
668
+ const runUrl = transport === "single" ? config.runtimeUrl ?? "" : `${normalizedRuntimeUrl ?? config.runtimeUrl}/agent/${encodeURIComponent(routedId)}/run`;
662
669
  if (!runUrl) throw new Error("ProxiedCopilotRuntimeAgent requires a runtimeUrl when transport is set to 'single'.");
663
670
  super({
664
671
  ...config,
665
672
  url: runUrl
666
673
  });
667
674
  this.runtimeUrl = normalizedRuntimeUrl ?? config.runtimeUrl;
675
+ this.runtimeEndpointUrl = config.runtimeUrl;
668
676
  this.credentials = config.credentials;
669
677
  this.runtimeAgentId = config.runtimeAgentId;
670
678
  this.transport = transport;
@@ -672,7 +680,7 @@ var ProxiedCopilotRuntimeAgent = class ProxiedCopilotRuntimeAgent extends _ag_ui
672
680
  this.intelligence = config.intelligence;
673
681
  this._capabilities = config.capabilities;
674
682
  if (config.debug) this.debug = config.debug;
675
- if (this.transport === "single") this.singleEndpointUrl = this.runtimeUrl;
683
+ if (this.transport === "single") this.singleEndpointUrl = this.runtimeEndpointUrl;
676
684
  }
677
685
  /**
678
686
  * The agent id used for outbound runtime requests — `runtimeAgentId` when
@@ -827,7 +835,7 @@ var ProxiedCopilotRuntimeAgent = class ProxiedCopilotRuntimeAgent extends _ag_ui
827
835
  }
828
836
  clone() {
829
837
  const cloned = new ProxiedCopilotRuntimeAgent({
830
- runtimeUrl: this.runtimeUrl,
838
+ runtimeUrl: this.runtimeEndpointUrl ?? this.runtimeUrl,
831
839
  agentId: this.agentId,
832
840
  runtimeAgentId: this.runtimeAgentId,
833
841
  description: this.description,
@@ -899,7 +907,7 @@ var ProxiedCopilotRuntimeAgent = class ProxiedCopilotRuntimeAgent extends _ag_ui
899
907
  if (this.transport === "single") {
900
908
  if (!this.singleEndpointUrl) throw new Error("Single endpoint transport requires a runtimeUrl");
901
909
  if (!headers["Content-Type"]) headers["Content-Type"] = "application/json";
902
- url = this.runtimeUrl;
910
+ url = this.singleEndpointUrl;
903
911
  init = {
904
912
  method: "POST",
905
913
  body: JSON.stringify({ method: "info" })
@@ -929,7 +937,8 @@ var ProxiedCopilotRuntimeAgent = class ProxiedCopilotRuntimeAgent extends _ag_ui
929
937
  } catch {}
930
938
  const singleHeaders = { ...headers };
931
939
  if (!singleHeaders["Content-Type"]) singleHeaders["Content-Type"] = "application/json";
932
- const response = await this.fetch(this.runtimeUrl, {
940
+ const endpointUrl = this.runtimeEndpointUrl ?? this.runtimeUrl;
941
+ const response = await this.fetch(endpointUrl, {
933
942
  method: "POST",
934
943
  headers: singleHeaders,
935
944
  body: JSON.stringify({ method: "info" }),
@@ -937,7 +946,7 @@ var ProxiedCopilotRuntimeAgent = class ProxiedCopilotRuntimeAgent extends _ag_ui
937
946
  });
938
947
  if (!response.ok) throw await runtimeInfoError(response);
939
948
  this.transport = "single";
940
- this.singleEndpointUrl = this.runtimeUrl;
949
+ this.singleEndpointUrl = endpointUrl;
941
950
  return await response.json();
942
951
  }
943
952
  createSingleRouteRequestInit(input, method, params) {
@@ -1102,6 +1111,8 @@ var AgentRegistry = class {
1102
1111
  remoteAgents = {};
1103
1112
  mintedThreadIds = /* @__PURE__ */ new WeakMap();
1104
1113
  _runtimeUrl;
1114
+ /** The runtime URL as the caller supplied it; the single-route endpoint uses it verbatim. */
1115
+ _runtimeEndpointUrl;
1105
1116
  _connectionInFlight;
1106
1117
  _runtimeConnectionGeneration = 0;
1107
1118
  _activeRuntimeConnectionAttempt;
@@ -1236,7 +1247,8 @@ var AgentRegistry = class {
1236
1247
  */
1237
1248
  setRuntimeUrl(runtimeUrl, options) {
1238
1249
  const normalizedRuntimeUrl = runtimeUrl ? runtimeUrl.replace(/\/$/, "") : void 0;
1239
- if (this._runtimeUrl === normalizedRuntimeUrl) return;
1250
+ const runtimeEndpointUrl = runtimeUrl || void 0;
1251
+ if (this._runtimeUrl === normalizedRuntimeUrl && this._runtimeEndpointUrl === runtimeEndpointUrl) return;
1240
1252
  this.invalidateInspectorMetadataConnection();
1241
1253
  this.abandonRuntimeHealthProbe();
1242
1254
  this.resetRuntimeEntitlementRetry();
@@ -1244,6 +1256,7 @@ var AgentRegistry = class {
1244
1256
  this._runtimeEntitlements = void 0;
1245
1257
  this._singleRouteResourceOperations = false;
1246
1258
  this._runtimeUrl = normalizedRuntimeUrl;
1259
+ this._runtimeEndpointUrl = runtimeEndpointUrl;
1247
1260
  if (options?.deferConnection) return;
1248
1261
  this.updateRuntimeConnection({ preserveOnFailure: this.hasLiveRuntimeKnowledgeToProtect() });
1249
1262
  }
@@ -1362,7 +1375,7 @@ var AgentRegistry = class {
1362
1375
  const friends = this.core;
1363
1376
  const debug = friends.debug;
1364
1377
  const agent = new ProxiedCopilotRuntimeAgent({
1365
- runtimeUrl: this._runtimeUrl,
1378
+ runtimeUrl: this._runtimeEndpointUrl ?? this._runtimeUrl,
1366
1379
  agentId,
1367
1380
  runtimeAgentId,
1368
1381
  transport: this._runtimeTransport,
@@ -1443,7 +1456,7 @@ var AgentRegistry = class {
1443
1456
  const meta = () => runtimeRequestMeta(init);
1444
1457
  const watchdog = this.armRuntimeRequestWatchdog(meta());
1445
1458
  try {
1446
- const singleRouteRequest = this._runtimeTransport === "single" && this._singleRouteResourceOperations && this._runtimeUrl ? await createSingleRouteResourceRequest(input, init, this._runtimeUrl) : null;
1459
+ const singleRouteRequest = this._runtimeTransport === "single" && this._singleRouteResourceOperations && this._runtimeUrl ? await createSingleRouteResourceRequest(input, init, this._runtimeEndpointUrl ?? this._runtimeUrl) : null;
1447
1460
  const response = singleRouteRequest ? await fetch(singleRouteRequest.input, singleRouteRequest.init) : await fetch(input, init);
1448
1461
  watchdog.clear();
1449
1462
  this.handleRuntimeRequestOutcome(response.ok ? "ok" : meta()?.nonCritical ? "ignored" : "failed", watchdog.checked);
@@ -1534,7 +1547,7 @@ var AgentRegistry = class {
1534
1547
  try {
1535
1548
  const request = (async () => {
1536
1549
  const response = resolvedTransport === "single" ? await this.fetchInspectorMetadataSingle({
1537
- runtimeUrl,
1550
+ runtimeUrl: this.singleEndpointUrlFor(runtimeUrl),
1538
1551
  headers,
1539
1552
  credentials,
1540
1553
  signal: abortController.signal
@@ -1731,13 +1744,13 @@ var AgentRegistry = class {
1731
1744
  }
1732
1745
  /** Return the stable key that scopes connection and entitlement retries. */
1733
1746
  runtimeConnectionKey() {
1734
- return `${this._runtimeUrl ?? ""}::${this._requestedTransport}`;
1747
+ return `${this._runtimeEndpointUrl ?? this._runtimeUrl ?? ""}::${this._requestedTransport}`;
1735
1748
  }
1736
1749
  /** Return whether a proxy still targets this Runtime connection. */
1737
1750
  canReuseRuntimeAgent(agent, runtimeUrl, transport) {
1738
1751
  if (!runtimeUrl) return false;
1739
1752
  const connection = this.remoteAgentConnections.get(agent);
1740
- return connection?.runtimeUrl === runtimeUrl.replace(/\/$/, "") && connection.transport === transport;
1753
+ return connection?.runtimeUrl === runtimeUrl.replace(/\/$/, "") && connection.endpointUrl === this._runtimeEndpointUrl && connection.transport === transport;
1741
1754
  }
1742
1755
  /** Return whether an async attempt still owns the active Runtime state. */
1743
1756
  isCurrentRuntimeConnection(attempt) {
@@ -1829,7 +1842,7 @@ var AgentRegistry = class {
1829
1842
  return [id, existing];
1830
1843
  }
1831
1844
  const agent = new ProxiedCopilotRuntimeAgent({
1832
- runtimeUrl,
1845
+ runtimeUrl: this._runtimeEndpointUrl ?? runtimeUrl,
1833
1846
  agentId: id,
1834
1847
  description,
1835
1848
  transport: this._runtimeTransport,
@@ -1849,6 +1862,7 @@ var AgentRegistry = class {
1849
1862
  }
1850
1863
  this.remoteAgentConnections.set(agent, {
1851
1864
  runtimeUrl,
1865
+ endpointUrl: this._runtimeEndpointUrl,
1852
1866
  transport: this._runtimeTransport
1853
1867
  });
1854
1868
  return [id, agent];
@@ -1930,7 +1944,7 @@ var AgentRegistry = class {
1930
1944
  const credentials = this.core.credentials;
1931
1945
  const headers = { ...baseHeaders };
1932
1946
  if (runtimeTransport === "single") return {
1933
- runtimeInfo: await this.fetchRuntimeInfoSingle(runtimeUrl, headers, credentials, signal),
1947
+ runtimeInfo: await this.fetchRuntimeInfoSingle(this.singleEndpointUrlFor(runtimeUrl), headers, credentials, signal),
1934
1948
  resolvedTransport: "single"
1935
1949
  };
1936
1950
  if (runtimeTransport === "auto") return this.fetchRuntimeInfoAutoDetect(runtimeUrl, headers, credentials, signal);
@@ -1945,6 +1959,15 @@ var AgentRegistry = class {
1945
1959
  resolvedTransport: "rest"
1946
1960
  };
1947
1961
  }
1962
+ /**
1963
+ * The URL a single-route request targets: the runtime URL as the caller
1964
+ * supplied it. `runtimeUrl` is the slash-stripped form used for path joins;
1965
+ * a trailing slash can select a different proxy location, so the endpoint
1966
+ * itself keeps it.
1967
+ */
1968
+ singleEndpointUrlFor(runtimeUrl) {
1969
+ return this._runtimeEndpointUrl !== void 0 && this._runtimeUrl === runtimeUrl ? this._runtimeEndpointUrl : runtimeUrl;
1970
+ }
1948
1971
  async fetchRuntimeInfoSingle(runtimeUrl, headers, credentials, signal) {
1949
1972
  const response = await fetch(runtimeUrl, {
1950
1973
  method: "POST",
@@ -1974,7 +1997,7 @@ var AgentRegistry = class {
1974
1997
  };
1975
1998
  } catch {}
1976
1999
  return {
1977
- runtimeInfo: await this.fetchRuntimeInfoSingle(runtimeUrl, { ...headers }, credentials, signal),
2000
+ runtimeInfo: await this.fetchRuntimeInfoSingle(this.singleEndpointUrlFor(runtimeUrl), { ...headers }, credentials, signal),
1978
2001
  resolvedTransport: "single"
1979
2002
  };
1980
2003
  }
@@ -2647,6 +2670,15 @@ var RunHandler = class {
2647
2670
  */
2648
2671
  _disabledToolKeys = /* @__PURE__ */ new Set();
2649
2672
  /**
2673
+ * Registry keys already reported by {@link warnOnMissingToolParameters}.
2674
+ * Development only, and per instance rather than per module so tests and
2675
+ * multiple cores stay independent. Deliberately NOT cleared by
2676
+ * {@link removeTool}: `useFrontendTool` tears down and re-registers on every
2677
+ * dependency change, so clearing it would turn one warning into one per
2678
+ * render. Key = `capabilityKey(name, agentId)`.
2679
+ */
2680
+ _warnedMissingToolParameters = /* @__PURE__ */ new Set();
2681
+ /**
2650
2682
  * Tracks whether the current run (including in-flight tool execution)
2651
2683
  * has been aborted via `stopAgent()` or `agent.abortRun()`. Created
2652
2684
  * fresh in `runAgent()`, aborted by `abortCurrentRun()`.
@@ -2736,6 +2768,7 @@ var RunHandler = class {
2736
2768
  initialize(tools) {
2737
2769
  this._propTools = [...tools];
2738
2770
  this._cachedMergedTools = null;
2771
+ this.warnOnMissingToolParameters(this._propTools);
2739
2772
  this.syncWebMCP();
2740
2773
  }
2741
2774
  /**
@@ -2750,9 +2783,39 @@ var RunHandler = class {
2750
2783
  }
2751
2784
  this._hookTools.set(key, tool);
2752
2785
  this._cachedMergedTools = null;
2786
+ this.warnOnMissingToolParameters([tool]);
2753
2787
  this.syncWebMCP();
2754
2788
  }
2755
2789
  /**
2790
+ * Report, once per tool and at development time only, a tool registered with
2791
+ * no `parameters` schema.
2792
+ *
2793
+ * `createToolSchema` substitutes `{ type: "object", properties: {} }` for a
2794
+ * missing `parameters` and returns silently, and `parameters` is optional on
2795
+ * `FrontendTool`, so nothing — not the compiler, not the runtime — tells the
2796
+ * developer that the model was handed a tool with nothing to fill in. It then
2797
+ * calls the tool with no arguments. `useComponent`, `useFrontendTool` and
2798
+ * `useHumanInTheLoop` all funnel into {@link addTool}; the provider's `tools`
2799
+ * prop funnels into {@link initialize} and {@link setTools}.
2800
+ *
2801
+ * A parameterless tool is legitimate (a HITL confirm dialog, say), so this
2802
+ * stays a warning rather than an error. An explicit empty schema
2803
+ * (`parameters: z.object({})`) is the way to say "takes none on purpose": it
2804
+ * satisfies the check below and `createToolSchema` reduces it to the same
2805
+ * advertised `{ type: "object", properties: {} }` that omitting `parameters`
2806
+ * produces, so silencing the warning costs nothing on the wire.
2807
+ */
2808
+ warnOnMissingToolParameters(tools) {
2809
+ if (process.env.NODE_ENV === "production") return;
2810
+ for (const tool of tools) {
2811
+ if (tool.parameters) continue;
2812
+ const key = this.capabilityKey(tool.name, tool.agentId);
2813
+ if (this._warnedMissingToolParameters.has(key)) continue;
2814
+ this._warnedMissingToolParameters.add(key);
2815
+ _copilotkit_shared.logger.warn(`Tool has no parameters schema: '${tool.name}' for agent '${tool.agentId || "global"}'. The model is told it takes no arguments and will call it with none. Add \`parameters\` (a Zod or Standard Schema object) if it should receive arguments, or \`parameters: z.object({})\` to declare that it takes none and silence this warning.`);
2816
+ }
2817
+ }
2818
+ /**
2756
2819
  * Remove a tool by name and optionally by agentId
2757
2820
  */
2758
2821
  removeTool(id, agentId) {
@@ -2785,6 +2848,7 @@ var RunHandler = class {
2785
2848
  setTools(tools) {
2786
2849
  this._propTools = [...tools];
2787
2850
  this._cachedMergedTools = null;
2851
+ this.warnOnMissingToolParameters(this._propTools);
2788
2852
  this.syncWebMCP();
2789
2853
  }
2790
2854
  /**