Skip to content
Merged
16 changes: 11 additions & 5 deletions nodejs/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -831,11 +831,6 @@ export class CopilotClient {

private setupClientGlobalHandlers(): void {
const handlers: import("./generated/rpc.js").ClientGlobalApiHandlers = {};
// `hooks.invoke` is a client-global RPC method whose payload carries a
// `sessionId`; route each invocation to the matching session's dispatcher.
handlers.hooks = {
invoke: async (params) => await this.handleHooksInvoke(params),
};
if (this.requestHandler) {
handlers.llmInference = createCopilotRequestAdapter(this.requestHandler, () => {
if (!this.connection) {
Expand Down Expand Up @@ -2843,6 +2838,17 @@ export class CopilotClient {
// — the runtime calls into a single handler for the whole connection.
registerClientGlobalApiHandlers(this.connection, this.clientGlobalHandlers);

// `hooks.invoke` is an internal RPC method: the runtime calls it to
// invoke a hook callback on the client. Route each call to the matching
// session's dispatcher. Not part of the public ClientGlobalApiHandlers
// interface because HookInvokeRequest/HookType are internal types.
this.connection.onRequest(
"hooks.invoke",
async (params: { sessionId: string; hookType: string; input: unknown }) => {
return await this.handleHooksInvoke(params);
}
);

this.connection.onClose(() => {
this.state = "disconnected";
});
Expand Down
19 changes: 0 additions & 19 deletions nodejs/src/generated/rpc.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

100 changes: 0 additions & 100 deletions nodejs/src/generated/session-events.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions nodejs/test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3140,8 +3140,9 @@ describe("CopilotClient", () => {
});

it("routes hooks.invoke JSON-RPC requests to the SessionHooks handler", async () => {
// Validates the full JSON-RPC entry point used by the CLI:
// clientGlobalHandlers.hooks.invoke({sessionId, hookType, input})
// Validates the full entry point used by the CLI when the runtime
// calls the internal `hooks.invoke` RPC method:
// handleHooksInvoke({sessionId, hookType, input})
// → CopilotSession._handleHooksInvoke(hookType, input)
// → SessionHooks.onPostToolUseFailure(normalizedInput, {sessionId})
//
Expand Down Expand Up @@ -3172,7 +3173,7 @@ describe("CopilotClient", () => {
cwd: "/tmp",
};

const response = await (client as any).clientGlobalHandlers.hooks.invoke({
const response = await (client as any).handleHooksInvoke({
sessionId: session.sessionId,
hookType: "postToolUseFailure",
input: failureInput,
Expand Down Expand Up @@ -3249,7 +3250,7 @@ describe("CopilotClient", () => {
},
});

const response = await (client as any).clientGlobalHandlers.hooks.invoke({
const response = await (client as any).handleHooksInvoke({
sessionId: session.sessionId,
hookType: "agentStop",
input: {
Expand Down
Loading
Loading