适配新的 opencode Agent 框架
This commit is contained in:
+14
-14
@@ -1,4 +1,4 @@
|
||||
import { streamCopilotChat } from "./chatStream";
|
||||
import { streamAgentChat } from "./chatStream";
|
||||
import { ReadableStream } from "stream/web";
|
||||
import { TextEncoder, TextDecoder } from "util";
|
||||
|
||||
@@ -32,7 +32,7 @@ const makeStream = (chunks: string[]) =>
|
||||
},
|
||||
});
|
||||
|
||||
describe("streamCopilotChat", () => {
|
||||
describe("streamAgentChat", () => {
|
||||
beforeEach(() => {
|
||||
apiFetch.mockReset();
|
||||
});
|
||||
@@ -41,21 +41,21 @@ describe("streamCopilotChat", () => {
|
||||
apiFetch.mockResolvedValue({
|
||||
ok: true,
|
||||
body: makeStream([
|
||||
'event: token\ndata: {"conversationId":"c1","content":"he"}\n\n',
|
||||
'event: token\ndata: {"conversationId":"c1","content":"llo"}\n\n',
|
||||
'event: done\ndata: {"conversationId":"c1"}\n\n',
|
||||
'event: token\ndata: {"session_id":"s1","content":"he"}\n\n',
|
||||
'event: token\ndata: {"session_id":"s1","content":"llo"}\n\n',
|
||||
'event: done\ndata: {"session_id":"s1"}\n\n',
|
||||
]),
|
||||
});
|
||||
|
||||
const events: Array<{ type: string; content?: string; conversationId?: string }> = [];
|
||||
const events: Array<{ type: string; content?: string; sessionId?: string }> = [];
|
||||
|
||||
await streamCopilotChat({
|
||||
await streamAgentChat({
|
||||
message: "hi",
|
||||
onEvent: (event) => events.push(event),
|
||||
});
|
||||
|
||||
expect(apiFetch).toHaveBeenCalledWith(
|
||||
expect.stringContaining("/api/v1/copilot/chat/stream"),
|
||||
expect.stringContaining("/api/v1/agent/chat/stream"),
|
||||
expect.objectContaining({
|
||||
method: "POST",
|
||||
projectHeaderMode: "include",
|
||||
@@ -64,9 +64,9 @@ describe("streamCopilotChat", () => {
|
||||
);
|
||||
|
||||
expect(events).toEqual([
|
||||
{ type: "token", conversationId: "c1", content: "he" },
|
||||
{ type: "token", conversationId: "c1", content: "llo" },
|
||||
{ type: "done", conversationId: "c1" },
|
||||
{ type: "token", sessionId: "s1", content: "he" },
|
||||
{ type: "token", sessionId: "s1", content: "llo" },
|
||||
{ type: "done", sessionId: "s1" },
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -78,7 +78,7 @@ describe("streamCopilotChat", () => {
|
||||
});
|
||||
|
||||
const events: Array<{ type: string; message?: string; detail?: string }> = [];
|
||||
await streamCopilotChat({
|
||||
await streamAgentChat({
|
||||
message: "hi",
|
||||
onEvent: (event) => events.push(event),
|
||||
});
|
||||
@@ -97,7 +97,7 @@ describe("streamCopilotChat", () => {
|
||||
});
|
||||
|
||||
const events: Array<{ type: string; message?: string; detail?: string }> = [];
|
||||
await streamCopilotChat({
|
||||
await streamAgentChat({
|
||||
message: "hi",
|
||||
onEvent: (event) => events.push(event),
|
||||
});
|
||||
@@ -111,7 +111,7 @@ describe("streamCopilotChat", () => {
|
||||
apiFetch.mockRejectedValue(new TypeError("Failed to fetch"));
|
||||
|
||||
const events: Array<{ type: string; message?: string; detail?: string }> = [];
|
||||
await streamCopilotChat({
|
||||
await streamAgentChat({
|
||||
message: "hi",
|
||||
onEvent: (event) => events.push(event),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user