logancyang_obsidian-copilot/__mocks__/@agentclientprotocol/sdk.js
Zero Liu 6250b25a04 feat(agent-mode): wire ACP backend, agent session, and chat UI
Add the ACP-driven agent harness end-to-end: backend process and
process manager, AgentSession with VaultClient, OpencodeBackend, plus
the agent chat router, status, tool-call, and permission modal UI.
Extend MessageRepository and ChatUIState with agent session parts so
the chat surface can render streamed agent output and tool activity.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-25 00:58:44 -07:00

67 lines
2 KiB
JavaScript

// Lightweight mock for @agentclientprotocol/sdk so unit tests can import
// modules that reference its runtime values (RequestError, ClientSideConnection,
// PROTOCOL_VERSION, ndJsonStream) without pulling the real ESM package
// through ts-jest. Tests that need behavior beyond this mock should stub
// their own.
/* eslint-disable no-undef */
class RequestError extends Error {
constructor(code, message, data) {
super(message);
this.code = code;
this.data = data;
this.name = "RequestError";
}
static parseError(data, msg) {
return new RequestError(-32700, msg ?? "Parse error", data);
}
static invalidRequest(data, msg) {
return new RequestError(-32600, msg ?? "Invalid Request", data);
}
static methodNotFound(method) {
return new RequestError(-32601, `Method not found: ${method}`);
}
static invalidParams(data, msg) {
return new RequestError(-32602, msg ?? "Invalid params", data);
}
static internalError(data, msg) {
return new RequestError(-32603, msg ?? "Internal error", data);
}
static authRequired(data, msg) {
return new RequestError(-32000, msg ?? "Authentication required", data);
}
static resourceNotFound(uri) {
return new RequestError(-32001, `Resource not found${uri ? `: ${uri}` : ""}`);
}
toResult() {
return { error: this.toErrorResponse() };
}
toErrorResponse() {
return { code: this.code, message: this.message, data: this.data };
}
}
class ClientSideConnection {
constructor(toClient, _stream) {
this._client = toClient(this);
}
initialize = jest.fn(async () => ({ protocolVersion: 1 }));
newSession = jest.fn(async () => ({ sessionId: "test-session" }));
prompt = jest.fn(async () => ({ stopReason: "end_turn" }));
cancel = jest.fn(async () => undefined);
}
class AgentSideConnection {
constructor() {}
}
const ndJsonStream = jest.fn(() => ({}));
const PROTOCOL_VERSION = 1;
module.exports = {
RequestError,
ClientSideConnection,
AgentSideConnection,
ndJsonStream,
PROTOCOL_VERSION,
};