@copilotkitnext/react 0.0.11 → 0.0.12

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.mts CHANGED
@@ -37,7 +37,7 @@ interface CopilotChatConfigurationProviderProps {
37
37
  threadId: string;
38
38
  }
39
39
  declare const CopilotChatConfigurationProvider: React__default.FC<CopilotChatConfigurationProviderProps>;
40
- declare const useCopilotChatConfiguration: () => CopilotChatConfigurationValue;
40
+ declare const useCopilotChatConfiguration: () => CopilotChatConfigurationValue | null;
41
41
 
42
42
  /** Finite-state machine for every recorder implementation */
43
43
  type AudioRecorderState = "idle" | "recording" | "processing";
@@ -255,11 +255,12 @@ declare namespace CopilotChatView {
255
255
  const Disclaimer: React__default.FC<React__default.HTMLAttributes<HTMLDivElement>>;
256
256
  }
257
257
 
258
- type CopilotChatProps = Omit<CopilotChatViewProps, "messages"> & {
258
+ type CopilotChatProps = Omit<CopilotChatViewProps, "messages" | "isRunning"> & {
259
259
  agentId?: string;
260
260
  threadId?: string;
261
+ labels?: Partial<CopilotChatLabels>;
261
262
  };
262
- declare function CopilotChat({ agentId, threadId, ...props }: CopilotChatProps): react_jsx_runtime.JSX.Element;
263
+ declare function CopilotChat({ agentId, threadId, labels, ...props }: CopilotChatProps): react_jsx_runtime.JSX.Element;
263
264
 
264
265
  declare const WildcardToolCallRender: ReactToolCallRender<any>;
265
266
 
package/dist/index.d.ts CHANGED
@@ -37,7 +37,7 @@ interface CopilotChatConfigurationProviderProps {
37
37
  threadId: string;
38
38
  }
39
39
  declare const CopilotChatConfigurationProvider: React__default.FC<CopilotChatConfigurationProviderProps>;
40
- declare const useCopilotChatConfiguration: () => CopilotChatConfigurationValue;
40
+ declare const useCopilotChatConfiguration: () => CopilotChatConfigurationValue | null;
41
41
 
42
42
  /** Finite-state machine for every recorder implementation */
43
43
  type AudioRecorderState = "idle" | "recording" | "processing";
@@ -255,11 +255,12 @@ declare namespace CopilotChatView {
255
255
  const Disclaimer: React__default.FC<React__default.HTMLAttributes<HTMLDivElement>>;
256
256
  }
257
257
 
258
- type CopilotChatProps = Omit<CopilotChatViewProps, "messages"> & {
258
+ type CopilotChatProps = Omit<CopilotChatViewProps, "messages" | "isRunning"> & {
259
259
  agentId?: string;
260
260
  threadId?: string;
261
+ labels?: Partial<CopilotChatLabels>;
261
262
  };
262
- declare function CopilotChat({ agentId, threadId, ...props }: CopilotChatProps): react_jsx_runtime.JSX.Element;
263
+ declare function CopilotChat({ agentId, threadId, labels, ...props }: CopilotChatProps): react_jsx_runtime.JSX.Element;
263
264
 
264
265
  declare const WildcardToolCallRender: ReactToolCallRender<any>;
265
266
 
package/dist/index.js CHANGED
@@ -100,11 +100,6 @@ var CopilotChatConfigurationProvider = ({
100
100
  };
101
101
  var useCopilotChatConfiguration = () => {
102
102
  const configuration = (0, import_react.useContext)(CopilotChatConfiguration);
103
- if (!configuration) {
104
- throw new Error(
105
- "useCopilotChatConfiguration must be used within CopilotChatConfigurationProvider"
106
- );
107
- }
108
103
  return configuration;
109
104
  };
110
105
 
@@ -734,7 +729,8 @@ function CopilotChatInput({
734
729
  }
735
730
  ) });
736
731
  CopilotChatInput2.ToolbarButton = ({ icon, labelKey, defaultClassName, className, ...props }) => {
737
- const { labels } = useCopilotChatConfiguration();
732
+ const config = useCopilotChatConfiguration();
733
+ const labels = config?.labels ?? CopilotChatDefaultLabels;
738
734
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Tooltip, { children: [
739
735
  /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
740
736
  Button,
@@ -787,7 +783,8 @@ function CopilotChatInput({
787
783
  }
788
784
  );
789
785
  CopilotChatInput2.ToolsButton = ({ className, toolsMenu, ...props }) => {
790
- const { labels } = useCopilotChatConfiguration();
786
+ const config = useCopilotChatConfiguration();
787
+ const labels = config?.labels ?? CopilotChatDefaultLabels;
791
788
  const renderMenuItems = (items) => {
792
789
  return items.map((item, index) => {
793
790
  if (item === "-") {
@@ -840,7 +837,8 @@ function CopilotChatInput({
840
837
  function TextArea2({ maxRows = 5, style, className, ...props }, ref) {
841
838
  const internalTextareaRef = (0, import_react4.useRef)(null);
842
839
  const [maxHeight, setMaxHeight] = (0, import_react4.useState)(0);
843
- const { labels } = useCopilotChatConfiguration();
840
+ const config = useCopilotChatConfiguration();
841
+ const labels = config?.labels ?? CopilotChatDefaultLabels;
844
842
  (0, import_react4.useImperativeHandle)(
845
843
  ref,
846
844
  () => internalTextareaRef.current
@@ -1013,9 +1011,7 @@ var CopilotKitProvider = ({
1013
1011
  ...tool.agentId && { agentId: tool.agentId },
1014
1012
  handler: async () => {
1015
1013
  return new Promise((resolve) => {
1016
- console.warn(
1017
- `Human-in-the-loop tool '${tool.name}' called but no interactive handler is set up.`
1018
- );
1014
+ console.warn(`Human-in-the-loop tool '${tool.name}' called but no interactive handler is set up.`);
1019
1015
  resolve(void 0);
1020
1016
  });
1021
1017
  }
@@ -1061,7 +1057,7 @@ var CopilotKitProvider = ({
1061
1057
  runtimeUrl: void 0,
1062
1058
  headers,
1063
1059
  properties,
1064
- agents,
1060
+ agents__unsafe_dev_only: agents,
1065
1061
  tools: allTools
1066
1062
  };
1067
1063
  const copilotkit2 = new import_core.CopilotKitCore(config);
@@ -1097,7 +1093,7 @@ var CopilotKitProvider = ({
1097
1093
  copilotkit.setRuntimeUrl(runtimeUrl);
1098
1094
  copilotkit.setHeaders(headers);
1099
1095
  copilotkit.setProperties(properties);
1100
- copilotkit.setAgents(agents);
1096
+ copilotkit.setAgents__unsafe_dev_only(agents);
1101
1097
  }, [runtimeUrl, headers, properties, agents]);
1102
1098
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1103
1099
  CopilotKitContext.Provider,
@@ -1133,10 +1129,12 @@ var useCopilotKit = () => {
1133
1129
 
1134
1130
  // src/hooks/use-render-tool-call.tsx
1135
1131
  var import_shared2 = require("@copilotkitnext/shared");
1132
+ var import_shared3 = require("@copilotkitnext/shared");
1136
1133
  var import_jsx_runtime8 = require("react/jsx-runtime");
1137
1134
  function useRenderToolCall() {
1138
1135
  const { currentRenderToolCalls, copilotkit } = useCopilotKit();
1139
- const { agentId } = useCopilotChatConfiguration();
1136
+ const config = useCopilotChatConfiguration();
1137
+ const agentId = config?.agentId ?? import_shared2.DEFAULT_AGENT_ID;
1140
1138
  const [executingToolCallIds, setExecutingToolCallIds] = (0, import_react6.useState)(() => /* @__PURE__ */ new Set());
1141
1139
  (0, import_react6.useEffect)(() => {
1142
1140
  const unsubscribe = copilotkit.subscribe({
@@ -1172,7 +1170,7 @@ function useRenderToolCall() {
1172
1170
  return null;
1173
1171
  }
1174
1172
  const RenderComponent = renderConfig.render;
1175
- const args = (0, import_shared2.partialJSONParse)(toolCall.function.arguments);
1173
+ const args = (0, import_shared3.partialJSONParse)(toolCall.function.arguments);
1176
1174
  const toolName = toolCall.function.name;
1177
1175
  if (toolMessage) {
1178
1176
  return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
@@ -1325,14 +1323,14 @@ function useHumanInTheLoop(tool) {
1325
1323
 
1326
1324
  // src/hooks/use-agent.tsx
1327
1325
  var import_react10 = require("react");
1328
- var import_shared3 = require("@copilotkitnext/shared");
1326
+ var import_shared4 = require("@copilotkitnext/shared");
1329
1327
  var ALL_UPDATES = [
1330
1328
  "OnMessagesChanged" /* OnMessagesChanged */,
1331
1329
  "OnStateChanged" /* OnStateChanged */,
1332
1330
  "OnRunStatusChanged" /* OnRunStatusChanged */
1333
1331
  ];
1334
1332
  function useAgent({ agentId, updates } = {}) {
1335
- agentId ??= import_shared3.DEFAULT_AGENT_ID;
1333
+ agentId ??= import_shared4.DEFAULT_AGENT_ID;
1336
1334
  const { copilotkit } = useCopilotKit();
1337
1335
  const [, forceUpdate] = (0, import_react10.useReducer)((x) => x + 1, 0);
1338
1336
  const updateFlags = (0, import_react10.useMemo)(
@@ -1572,7 +1570,8 @@ function CopilotChatAssistantMessage({
1572
1570
  );
1573
1571
  };
1574
1572
  const CodeBlock = ({ children, className, onClick, ...props }) => {
1575
- const { labels } = useCopilotChatConfiguration();
1573
+ const config = useCopilotChatConfiguration();
1574
+ const labels = config?.labels ?? CopilotChatDefaultLabels;
1576
1575
  const [copied, setCopied] = (0, import_react13.useState)(false);
1577
1576
  const getCodeContent = (node) => {
1578
1577
  if (typeof node === "string") return node;
@@ -1685,7 +1684,8 @@ function CopilotChatAssistantMessage({
1685
1684
  ] });
1686
1685
  };
1687
1686
  CopilotChatAssistantMessage2.CopyButton = ({ className, title, onClick, ...props }) => {
1688
- const { labels } = useCopilotChatConfiguration();
1687
+ const config = useCopilotChatConfiguration();
1688
+ const labels = config?.labels ?? CopilotChatDefaultLabels;
1689
1689
  const [copied, setCopied] = (0, import_react13.useState)(false);
1690
1690
  const handleClick = (event) => {
1691
1691
  setCopied(true);
@@ -1706,7 +1706,8 @@ function CopilotChatAssistantMessage({
1706
1706
  );
1707
1707
  };
1708
1708
  CopilotChatAssistantMessage2.ThumbsUpButton = ({ title, ...props }) => {
1709
- const { labels } = useCopilotChatConfiguration();
1709
+ const config = useCopilotChatConfiguration();
1710
+ const labels = config?.labels ?? CopilotChatDefaultLabels;
1710
1711
  return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1711
1712
  CopilotChatAssistantMessage2.ToolbarButton,
1712
1713
  {
@@ -1717,7 +1718,8 @@ function CopilotChatAssistantMessage({
1717
1718
  );
1718
1719
  };
1719
1720
  CopilotChatAssistantMessage2.ThumbsDownButton = ({ title, ...props }) => {
1720
- const { labels } = useCopilotChatConfiguration();
1721
+ const config = useCopilotChatConfiguration();
1722
+ const labels = config?.labels ?? CopilotChatDefaultLabels;
1721
1723
  return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1722
1724
  CopilotChatAssistantMessage2.ToolbarButton,
1723
1725
  {
@@ -1728,7 +1730,8 @@ function CopilotChatAssistantMessage({
1728
1730
  );
1729
1731
  };
1730
1732
  CopilotChatAssistantMessage2.ReadAloudButton = ({ title, ...props }) => {
1731
- const { labels } = useCopilotChatConfiguration();
1733
+ const config = useCopilotChatConfiguration();
1734
+ const labels = config?.labels ?? CopilotChatDefaultLabels;
1732
1735
  return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1733
1736
  CopilotChatAssistantMessage2.ToolbarButton,
1734
1737
  {
@@ -1739,7 +1742,8 @@ function CopilotChatAssistantMessage({
1739
1742
  );
1740
1743
  };
1741
1744
  CopilotChatAssistantMessage2.RegenerateButton = ({ title, ...props }) => {
1742
- const { labels } = useCopilotChatConfiguration();
1745
+ const config = useCopilotChatConfiguration();
1746
+ const labels = config?.labels ?? CopilotChatDefaultLabels;
1743
1747
  return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1744
1748
  CopilotChatAssistantMessage2.ToolbarButton,
1745
1749
  {
@@ -1903,7 +1907,8 @@ function CopilotChatUserMessage({
1903
1907
  ] });
1904
1908
  };
1905
1909
  CopilotChatUserMessage2.CopyButton = ({ className, title, onClick, ...props }) => {
1906
- const { labels } = useCopilotChatConfiguration();
1910
+ const config = useCopilotChatConfiguration();
1911
+ const labels = config?.labels ?? CopilotChatDefaultLabels;
1907
1912
  const [copied, setCopied] = (0, import_react14.useState)(false);
1908
1913
  const handleClick = (event) => {
1909
1914
  setCopied(true);
@@ -1924,7 +1929,8 @@ function CopilotChatUserMessage({
1924
1929
  );
1925
1930
  };
1926
1931
  CopilotChatUserMessage2.EditButton = ({ className, title, ...props }) => {
1927
- const { labels } = useCopilotChatConfiguration();
1932
+ const config = useCopilotChatConfiguration();
1933
+ const labels = config?.labels ?? CopilotChatDefaultLabels;
1928
1934
  return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1929
1935
  CopilotChatUserMessage2.ToolbarButton,
1930
1936
  {
@@ -2315,7 +2321,8 @@ function CopilotChatView({
2315
2321
  className,
2316
2322
  ...props
2317
2323
  }) => {
2318
- const { labels } = useCopilotChatConfiguration();
2324
+ const config = useCopilotChatConfiguration();
2325
+ const labels = config?.labels ?? CopilotChatDefaultLabels;
2319
2326
  return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
2320
2327
  "div",
2321
2328
  {
@@ -2332,23 +2339,32 @@ function CopilotChatView({
2332
2339
  var CopilotChatView_default = CopilotChatView;
2333
2340
 
2334
2341
  // src/components/chat/CopilotChat.tsx
2335
- var import_shared4 = require("@copilotkitnext/shared");
2342
+ var import_shared5 = require("@copilotkitnext/shared");
2336
2343
  var import_react16 = require("react");
2337
2344
  var import_ts_deepmerge = require("ts-deepmerge");
2338
2345
  var import_client = require("@ag-ui/client");
2339
2346
  var import_jsx_runtime14 = require("react/jsx-runtime");
2340
- function CopilotChat({
2341
- agentId = import_shared4.DEFAULT_AGENT_ID,
2342
- threadId,
2343
- ...props
2344
- }) {
2345
- const { agent } = useAgent({ agentId });
2347
+ function CopilotChat({ agentId, threadId, labels, ...props }) {
2348
+ const existingConfig = useCopilotChatConfiguration();
2349
+ const resolvedAgentId = agentId ?? existingConfig?.agentId ?? import_shared5.DEFAULT_AGENT_ID;
2350
+ const resolvedThreadId = (0, import_react16.useMemo)(
2351
+ () => threadId ?? existingConfig?.threadId ?? (0, import_shared5.randomUUID)(),
2352
+ [threadId, existingConfig?.threadId]
2353
+ );
2354
+ const resolvedLabels = (0, import_react16.useMemo)(
2355
+ () => ({
2356
+ ...CopilotChatDefaultLabels,
2357
+ ...existingConfig?.labels || {},
2358
+ ...labels || {}
2359
+ }),
2360
+ [existingConfig?.labels, labels]
2361
+ );
2362
+ const { agent } = useAgent({ agentId: resolvedAgentId });
2346
2363
  const { copilotkit } = useCopilotKit();
2347
- const resolvedThreadId = (0, import_react16.useMemo)(() => threadId ?? (0, import_shared4.randomUUID)(), [threadId]);
2348
2364
  (0, import_react16.useEffect)(() => {
2349
2365
  const connect = async (agent2) => {
2350
2366
  try {
2351
- await copilotkit.connectAgent({ agent: agent2, agentId });
2367
+ await copilotkit.connectAgent({ agent: agent2, agentId: resolvedAgentId });
2352
2368
  } catch (error) {
2353
2369
  if (error instanceof import_client.AGUIConnectNotImplementedError) {
2354
2370
  } else {
@@ -2362,29 +2378,25 @@ function CopilotChat({
2362
2378
  }
2363
2379
  return () => {
2364
2380
  };
2365
- }, [resolvedThreadId, agent, copilotkit, agentId]);
2381
+ }, [resolvedThreadId, agent, copilotkit, resolvedAgentId]);
2366
2382
  const onSubmitInput = (0, import_react16.useCallback)(
2367
2383
  async (value) => {
2368
2384
  agent?.addMessage({
2369
- id: (0, import_shared4.randomUUID)(),
2385
+ id: (0, import_shared5.randomUUID)(),
2370
2386
  role: "user",
2371
2387
  content: value
2372
2388
  });
2373
2389
  if (agent) {
2374
2390
  try {
2375
- await copilotkit.runAgent({ agent, agentId });
2391
+ await copilotkit.runAgent({ agent, agentId: resolvedAgentId });
2376
2392
  } catch (error) {
2377
2393
  console.error("CopilotChat: runAgent failed", error);
2378
2394
  }
2379
2395
  }
2380
2396
  },
2381
- [agent, copilotkit, agentId]
2397
+ [agent, copilotkit, resolvedAgentId]
2382
2398
  );
2383
- const {
2384
- inputProps: providedInputProps,
2385
- messageView: providedMessageView,
2386
- ...restProps
2387
- } = props;
2399
+ const { inputProps: providedInputProps, messageView: providedMessageView, ...restProps } = props;
2388
2400
  const mergedProps = (0, import_ts_deepmerge.merge)(
2389
2401
  {
2390
2402
  isRunning: agent?.isRunning ?? false
@@ -2394,26 +2406,19 @@ function CopilotChat({
2394
2406
  ...typeof providedMessageView === "string" ? { messageView: { className: providedMessageView } } : providedMessageView !== void 0 ? { messageView: providedMessageView } : {}
2395
2407
  }
2396
2408
  );
2397
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
2398
- CopilotChatConfigurationProvider,
2409
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(CopilotChatConfigurationProvider, { agentId: resolvedAgentId, threadId: resolvedThreadId, labels: resolvedLabels, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
2410
+ CopilotChatView,
2399
2411
  {
2400
- agentId,
2401
- threadId: resolvedThreadId,
2402
- children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
2403
- CopilotChatView,
2404
- {
2405
- ...{
2406
- messages: agent?.messages ?? [],
2407
- inputProps: {
2408
- onSubmitMessage: onSubmitInput,
2409
- ...providedInputProps
2410
- },
2411
- ...mergedProps
2412
- }
2413
- }
2414
- )
2412
+ ...{
2413
+ messages: agent?.messages ?? [],
2414
+ inputProps: {
2415
+ onSubmitMessage: onSubmitInput,
2416
+ ...providedInputProps
2417
+ },
2418
+ ...mergedProps
2419
+ }
2415
2420
  }
2416
- );
2421
+ ) });
2417
2422
  }
2418
2423
 
2419
2424
  // src/types/defineToolCallRender.ts