Skip to content

Commit 5bb9296

Browse files
authored
feat(react-core): forward followUp option through useComponent (CopilotKit#4897)
## Summary `useComponent` wraps `useFrontendTool` but wasn't forwarding `followUp`. Adds the option to the config and passes it through. ## Changes - Forward `followUp?: boolean` from `useComponent` config to `useFrontendTool` - Add test coverage in `use-component.test.tsx` (`forwards followUp option to useFrontendTool`) - Document the option in the v2 hook reference ## Test plan - [x] `nx test react-core` passes (new `forwards followUp option to useFrontendTool` case) - [x] Manually verified in `examples/v2/react`
2 parents 59ffe91 + 3ad8fbe commit 5bb9296

3 files changed

Lines changed: 8 additions & 1 deletion

File tree

docs/content/docs/reference/v2/hooks/useComponent.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function useComponent<
3030
// When omitted, render accepts any props.
3131
render: ComponentType<InferRenderProps<TSchema>>;
3232
agentId?: string;
33+
followUp?: boolean;
3334
},
3435
deps?: ReadonlyArray<unknown>,
3536
): void;
@@ -42,6 +43,7 @@ function useComponent<
4243
- `config.parameters`: optional Zod schema for typed/validated parameters. When provided, `render` props are inferred from the schema.
4344
- `config.render`: React component rendered with parsed tool parameters. Accepts any props when `parameters` is omitted.
4445
- `config.agentId`: optional agent scope for the registration.
46+
- `config.followUp`: optional, defaults to `true`. Set `false` to suppress the agent's follow-up message after rendering.
4547
- `deps`: optional dependency array for refreshing registration.
4648

4749
## Behavior

packages/react-core/src/v2/hooks/__tests__/use-component.test.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe("useComponent", () => {
4545
);
4646
});
4747

48-
it("appends custom description and forwards parameters, agentId, and deps", () => {
48+
it("appends custom description and forwards parameters, agentId, deps, and followUp", () => {
4949
const weatherSchema = z.object({
5050
city: z.string(),
5151
unit: z.enum(["c", "f"]),
@@ -65,6 +65,7 @@ describe("useComponent", () => {
6565
parameters: weatherSchema,
6666
render: DemoComponent,
6767
agentId: "weather-agent",
68+
followUp: false,
6869
},
6970
deps,
7071
);
@@ -79,6 +80,7 @@ describe("useComponent", () => {
7980
description: string;
8081
parameters: typeof weatherSchema;
8182
agentId?: string;
83+
followUp?: boolean;
8284
},
8385
ReadonlyArray<unknown>,
8486
];
@@ -91,6 +93,7 @@ describe("useComponent", () => {
9193
);
9294
expect(toolConfig.parameters).toBe(weatherSchema);
9395
expect(toolConfig.agentId).toBe("weather-agent");
96+
expect(toolConfig.followUp).toBe(false);
9497
expect(forwardedDeps).toBe(deps);
9598
});
9699

packages/react-core/src/v2/hooks/use-component.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export function useComponent<
6565
parameters?: TSchema;
6666
render: ComponentType<NoInfer<InferRenderProps<TSchema>>>;
6767
agentId?: string;
68+
followUp?: boolean;
6869
},
6970
deps?: ReadonlyArray<unknown>,
7071
): void {
@@ -83,6 +84,7 @@ export function useComponent<
8384
return <Component {...(args as InferRenderProps<TSchema>)} />;
8485
},
8586
agentId: config.agentId,
87+
followUp: config.followUp,
8688
},
8789
deps,
8890
);

0 commit comments

Comments
 (0)