@copilotkitnext/react 0.0.9-alpha.0 → 0.0.9-alpha.2

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
@@ -118,9 +118,8 @@ declare namespace CopilotChatInput {
118
118
  type CopilotChatToolCallsViewProps = {
119
119
  message: AssistantMessage;
120
120
  messages?: Message[];
121
- isRunning?: boolean;
122
121
  };
123
- declare function CopilotChatToolCallsView({ message, messages, isRunning, }: CopilotChatToolCallsViewProps): react_jsx_runtime.JSX.Element | null;
122
+ declare function CopilotChatToolCallsView({ message, messages, }: CopilotChatToolCallsViewProps): react_jsx_runtime.JSX.Element | null;
124
123
 
125
124
  type CopilotChatAssistantMessageProps = WithSlots<{
126
125
  markdownRenderer: typeof CopilotChatAssistantMessage.MarkdownRenderer;
@@ -265,7 +264,6 @@ declare function CopilotChat({ agentId, threadId, ...props }: CopilotChatProps):
265
264
  interface UseRenderToolCallProps {
266
265
  toolCall: ToolCall;
267
266
  toolMessage?: ToolMessage;
268
- isRunning: boolean;
269
267
  }
270
268
  /**
271
269
  * Hook that returns a function to render tool calls based on the render functions
@@ -273,7 +271,7 @@ interface UseRenderToolCallProps {
273
271
  *
274
272
  * @returns A function that takes a tool call and optional tool message and returns the rendered component
275
273
  */
276
- declare function useRenderToolCall(): ({ toolCall, toolMessage, isRunning, }: UseRenderToolCallProps) => React__default.ReactElement | null;
274
+ declare function useRenderToolCall(): ({ toolCall, toolMessage, }: UseRenderToolCallProps) => React__default.ReactElement | null;
277
275
 
278
276
  interface ReactToolCallRender<T> {
279
277
  name: string;
@@ -351,7 +349,7 @@ declare function useAgentContext(context: Context): void;
351
349
 
352
350
  interface CopilotKitContextValue {
353
351
  copilotkit: CopilotKitCore;
354
- renderToolCalls: ReactToolCallRender<unknown>[];
352
+ renderToolCalls: ReactToolCallRender<any>[];
355
353
  currentRenderToolCalls: ReactToolCallRender<unknown>[];
356
354
  setCurrentRenderToolCalls: React__default.Dispatch<React__default.SetStateAction<ReactToolCallRender<unknown>[]>>;
357
355
  }
@@ -361,7 +359,7 @@ interface CopilotKitProviderProps {
361
359
  headers?: Record<string, string>;
362
360
  properties?: Record<string, unknown>;
363
361
  agents?: Record<string, AbstractAgent>;
364
- renderToolCalls?: ReactToolCallRender<unknown>[];
362
+ renderToolCalls?: ReactToolCallRender<any>[];
365
363
  frontendTools?: ReactFrontendTool[];
366
364
  humanInTheLoop?: ReactHumanInTheLoop[];
367
365
  }
@@ -373,12 +371,33 @@ declare const useCopilotKit: () => CopilotKitContextValue;
373
371
  * - Accepts a single object whose keys match ReactToolCallRender's fields: { name, args, render, agentId? }.
374
372
  * - Derives `args` type from the provided Zod schema.
375
373
  * - Ensures the render function param type exactly matches ReactToolCallRender<T>["render"]'s param.
374
+ * - For wildcard tools (name: "*"), args is optional and defaults to z.any()
376
375
  */
377
- type RenderProps<S extends z.ZodTypeAny> = React__default.ComponentProps<ReactToolCallRender<z.infer<S>>["render"]>;
376
+ type RenderProps<T> = {
377
+ name: string;
378
+ args: Partial<T>;
379
+ status: ToolCallStatus.InProgress;
380
+ result: undefined;
381
+ } | {
382
+ name: string;
383
+ args: T;
384
+ status: ToolCallStatus.Executing;
385
+ result: undefined;
386
+ } | {
387
+ name: string;
388
+ args: T;
389
+ status: ToolCallStatus.Complete;
390
+ result: string;
391
+ };
392
+ declare function defineToolCallRender(def: {
393
+ name: "*";
394
+ render: (props: RenderProps<any>) => React__default.ReactElement;
395
+ agentId?: string;
396
+ }): ReactToolCallRender<any>;
378
397
  declare function defineToolCallRender<S extends z.ZodTypeAny>(def: {
379
398
  name: string;
380
399
  args: S;
381
- render: (props: RenderProps<S>) => React__default.ReactElement;
400
+ render: (props: RenderProps<z.infer<S>>) => React__default.ReactElement;
382
401
  agentId?: string;
383
402
  }): ReactToolCallRender<z.infer<S>>;
384
403
 
package/dist/index.d.ts CHANGED
@@ -118,9 +118,8 @@ declare namespace CopilotChatInput {
118
118
  type CopilotChatToolCallsViewProps = {
119
119
  message: AssistantMessage;
120
120
  messages?: Message[];
121
- isRunning?: boolean;
122
121
  };
123
- declare function CopilotChatToolCallsView({ message, messages, isRunning, }: CopilotChatToolCallsViewProps): react_jsx_runtime.JSX.Element | null;
122
+ declare function CopilotChatToolCallsView({ message, messages, }: CopilotChatToolCallsViewProps): react_jsx_runtime.JSX.Element | null;
124
123
 
125
124
  type CopilotChatAssistantMessageProps = WithSlots<{
126
125
  markdownRenderer: typeof CopilotChatAssistantMessage.MarkdownRenderer;
@@ -265,7 +264,6 @@ declare function CopilotChat({ agentId, threadId, ...props }: CopilotChatProps):
265
264
  interface UseRenderToolCallProps {
266
265
  toolCall: ToolCall;
267
266
  toolMessage?: ToolMessage;
268
- isRunning: boolean;
269
267
  }
270
268
  /**
271
269
  * Hook that returns a function to render tool calls based on the render functions
@@ -273,7 +271,7 @@ interface UseRenderToolCallProps {
273
271
  *
274
272
  * @returns A function that takes a tool call and optional tool message and returns the rendered component
275
273
  */
276
- declare function useRenderToolCall(): ({ toolCall, toolMessage, isRunning, }: UseRenderToolCallProps) => React__default.ReactElement | null;
274
+ declare function useRenderToolCall(): ({ toolCall, toolMessage, }: UseRenderToolCallProps) => React__default.ReactElement | null;
277
275
 
278
276
  interface ReactToolCallRender<T> {
279
277
  name: string;
@@ -351,7 +349,7 @@ declare function useAgentContext(context: Context): void;
351
349
 
352
350
  interface CopilotKitContextValue {
353
351
  copilotkit: CopilotKitCore;
354
- renderToolCalls: ReactToolCallRender<unknown>[];
352
+ renderToolCalls: ReactToolCallRender<any>[];
355
353
  currentRenderToolCalls: ReactToolCallRender<unknown>[];
356
354
  setCurrentRenderToolCalls: React__default.Dispatch<React__default.SetStateAction<ReactToolCallRender<unknown>[]>>;
357
355
  }
@@ -361,7 +359,7 @@ interface CopilotKitProviderProps {
361
359
  headers?: Record<string, string>;
362
360
  properties?: Record<string, unknown>;
363
361
  agents?: Record<string, AbstractAgent>;
364
- renderToolCalls?: ReactToolCallRender<unknown>[];
362
+ renderToolCalls?: ReactToolCallRender<any>[];
365
363
  frontendTools?: ReactFrontendTool[];
366
364
  humanInTheLoop?: ReactHumanInTheLoop[];
367
365
  }
@@ -373,12 +371,33 @@ declare const useCopilotKit: () => CopilotKitContextValue;
373
371
  * - Accepts a single object whose keys match ReactToolCallRender's fields: { name, args, render, agentId? }.
374
372
  * - Derives `args` type from the provided Zod schema.
375
373
  * - Ensures the render function param type exactly matches ReactToolCallRender<T>["render"]'s param.
374
+ * - For wildcard tools (name: "*"), args is optional and defaults to z.any()
376
375
  */
377
- type RenderProps<S extends z.ZodTypeAny> = React__default.ComponentProps<ReactToolCallRender<z.infer<S>>["render"]>;
376
+ type RenderProps<T> = {
377
+ name: string;
378
+ args: Partial<T>;
379
+ status: ToolCallStatus.InProgress;
380
+ result: undefined;
381
+ } | {
382
+ name: string;
383
+ args: T;
384
+ status: ToolCallStatus.Executing;
385
+ result: undefined;
386
+ } | {
387
+ name: string;
388
+ args: T;
389
+ status: ToolCallStatus.Complete;
390
+ result: string;
391
+ };
392
+ declare function defineToolCallRender(def: {
393
+ name: "*";
394
+ render: (props: RenderProps<any>) => React__default.ReactElement;
395
+ agentId?: string;
396
+ }): ReactToolCallRender<any>;
378
397
  declare function defineToolCallRender<S extends z.ZodTypeAny>(def: {
379
398
  name: string;
380
399
  args: S;
381
- render: (props: RenderProps<S>) => React__default.ReactElement;
400
+ render: (props: RenderProps<z.infer<S>>) => React__default.ReactElement;
382
401
  agentId?: string;
383
402
  }): ReactToolCallRender<z.infer<S>>;
384
403
 
package/dist/index.js CHANGED
@@ -946,6 +946,7 @@ var import_core2 = require("@copilotkitnext/core");
946
946
 
947
947
  // src/providers/CopilotKitProvider.tsx
948
948
  var import_react5 = require("react");
949
+ var import_zod = require("zod");
949
950
  var import_core = require("@copilotkitnext/core");
950
951
  var import_jsx_runtime7 = require("react/jsx-runtime");
951
952
  var CopilotKitContext = (0, import_react5.createContext)({
@@ -1039,12 +1040,15 @@ var CopilotKitProvider = ({
1039
1040
  const allRenderToolCalls = (0, import_react5.useMemo)(() => {
1040
1041
  const combined = [...renderToolCallsList];
1041
1042
  frontendToolsList.forEach((tool) => {
1042
- if (tool.render && tool.parameters) {
1043
- combined.push({
1044
- name: tool.name,
1045
- args: tool.parameters,
1046
- render: tool.render
1047
- });
1043
+ if (tool.render) {
1044
+ const args = tool.parameters || (tool.name === "*" ? import_zod.z.any() : void 0);
1045
+ if (args) {
1046
+ combined.push({
1047
+ name: tool.name,
1048
+ args,
1049
+ render: tool.render
1050
+ });
1051
+ }
1048
1052
  }
1049
1053
  });
1050
1054
  combined.push(...processedHumanInTheLoopTools.renderToolCalls);
@@ -1157,8 +1161,7 @@ function useRenderToolCall() {
1157
1161
  const renderToolCall = (0, import_react6.useCallback)(
1158
1162
  ({
1159
1163
  toolCall,
1160
- toolMessage,
1161
- isRunning
1164
+ toolMessage
1162
1165
  }) => {
1163
1166
  const exactMatches = currentRenderToolCalls.filter(
1164
1167
  (rc) => rc.name === toolCall.function.name
@@ -1192,7 +1195,7 @@ function useRenderToolCall() {
1192
1195
  },
1193
1196
  toolCall.id
1194
1197
  );
1195
- } else if (isRunning) {
1198
+ } else {
1196
1199
  return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1197
1200
  RenderComponent,
1198
1201
  {
@@ -1203,17 +1206,6 @@ function useRenderToolCall() {
1203
1206
  },
1204
1207
  toolCall.id
1205
1208
  );
1206
- } else {
1207
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1208
- RenderComponent,
1209
- {
1210
- name: toolName,
1211
- args,
1212
- status: import_core2.ToolCallStatus.Complete,
1213
- result: ""
1214
- },
1215
- toolCall.id
1216
- );
1217
1209
  }
1218
1210
  },
1219
1211
  [currentRenderToolCalls, executingToolCallIds, agentId]
@@ -1410,8 +1402,7 @@ var import_react12 = __toESM(require("react"));
1410
1402
  var import_jsx_runtime9 = require("react/jsx-runtime");
1411
1403
  function CopilotChatToolCallsView({
1412
1404
  message,
1413
- messages = [],
1414
- isRunning = false
1405
+ messages = []
1415
1406
  }) {
1416
1407
  const renderToolCall = useRenderToolCall();
1417
1408
  if (!message.toolCalls || message.toolCalls.length === 0) {
@@ -1423,8 +1414,7 @@ function CopilotChatToolCallsView({
1423
1414
  );
1424
1415
  return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_react12.default.Fragment, { children: renderToolCall({
1425
1416
  toolCall,
1426
- toolMessage,
1427
- isRunning
1417
+ toolMessage
1428
1418
  }) }, toolCall.id);
1429
1419
  }) });
1430
1420
  }
@@ -1523,10 +1513,11 @@ function CopilotChatAssistantMessage({
1523
1513
  CopilotChatToolCallsView_default,
1524
1514
  {
1525
1515
  message,
1526
- messages,
1527
- isRunning
1516
+ messages
1528
1517
  }
1529
1518
  );
1519
+ const hasContent = !!(message.content && message.content.trim().length > 0);
1520
+ const shouldShowToolbar = toolbarVisible && hasContent;
1530
1521
  if (children) {
1531
1522
  return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_jsx_runtime10.Fragment, { children: children({
1532
1523
  markdownRenderer: boundMarkdownRenderer,
@@ -1545,7 +1536,7 @@ function CopilotChatAssistantMessage({
1545
1536
  onReadAloud,
1546
1537
  onRegenerate,
1547
1538
  additionalToolbarItems,
1548
- toolbarVisible
1539
+ toolbarVisible: shouldShowToolbar
1549
1540
  }) });
1550
1541
  }
1551
1542
  return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
@@ -1560,7 +1551,7 @@ function CopilotChatAssistantMessage({
1560
1551
  children: [
1561
1552
  boundMarkdownRenderer,
1562
1553
  boundToolCallsView,
1563
- toolbarVisible && boundToolbar
1554
+ shouldShowToolbar && boundToolbar
1564
1555
  ]
1565
1556
  }
1566
1557
  );
@@ -2425,11 +2416,12 @@ function CopilotChat({
2425
2416
  }
2426
2417
 
2427
2418
  // src/types/defineToolCallRender.ts
2419
+ var import_zod2 = require("zod");
2428
2420
  function defineToolCallRender(def) {
2421
+ const argsSchema = def.name === "*" && !def.args ? import_zod2.z.any() : def.args;
2429
2422
  return {
2430
2423
  name: def.name,
2431
- args: def.args,
2432
- // Coerce to ComponentType to align with ReactToolCallRender
2424
+ args: argsSchema,
2433
2425
  render: def.render,
2434
2426
  ...def.agentId ? { agentId: def.agentId } : {}
2435
2427
  };