移除对 copilot 的兼容。更新示例和文档,统一使用 session_id 代替 conversationId
This commit is contained in:
+11
-11
@@ -8,7 +8,7 @@ import { type ChatSessionBridge } from "../chat/sessionBridge.js";
|
||||
|
||||
const payloadSchema = z.object({
|
||||
message: z.string().min(1).max(10000),
|
||||
conversation_id: z.string().max(128).optional(),
|
||||
session_id: z.string().max(128).optional(),
|
||||
});
|
||||
|
||||
export const buildChatRouter = (
|
||||
@@ -36,7 +36,7 @@ export const buildChatRouter = (
|
||||
const traceId = req.header("x-trace-id") ?? undefined;
|
||||
|
||||
const { binding, requestContext, created } = await sessionBridge.resolve({
|
||||
conversationId: parsed.data.conversation_id,
|
||||
clientSessionId: parsed.data.session_id,
|
||||
accessToken,
|
||||
projectId,
|
||||
traceId,
|
||||
@@ -44,7 +44,7 @@ export const buildChatRouter = (
|
||||
|
||||
logger.info(
|
||||
{
|
||||
conversationId: requestContext.conversationId,
|
||||
clientSessionId: requestContext.clientSessionId,
|
||||
sessionId: binding.sessionId,
|
||||
created,
|
||||
traceId: requestContext.traceId,
|
||||
@@ -53,7 +53,7 @@ export const buildChatRouter = (
|
||||
"processing chat request",
|
||||
);
|
||||
|
||||
// 当前先走“发送 prompt 后回读最近消息”的兼容实现。
|
||||
// 当前先走“发送 prompt 后回读最近消息”的 opencode SDK 实现。
|
||||
// 后续切到真正的 opencode 事件流时,只需要替换这里的取数方式。
|
||||
const messages = await runtime.sendPrompt(binding.sessionId, parsed.data.message);
|
||||
const assistantMessage = messages.find(
|
||||
@@ -66,13 +66,13 @@ export const buildChatRouter = (
|
||||
res.setHeader("Connection", "keep-alive");
|
||||
res.setHeader("X-Accel-Buffering", "no");
|
||||
|
||||
const conversationId = requestContext.conversationId;
|
||||
const clientSessionId = requestContext.clientSessionId;
|
||||
const parts = assistantMessage?.parts ?? [];
|
||||
const textContent = collectTextContent(parts);
|
||||
if (textContent) {
|
||||
res.write(
|
||||
toSse("token", {
|
||||
conversationId,
|
||||
session_id: clientSessionId,
|
||||
content: textContent,
|
||||
}),
|
||||
);
|
||||
@@ -81,7 +81,7 @@ export const buildChatRouter = (
|
||||
for (const toolCall of collectToolCalls(parts)) {
|
||||
res.write(
|
||||
toSse("tool_call", {
|
||||
conversationId,
|
||||
session_id: clientSessionId,
|
||||
tool: toolCall.tool,
|
||||
params: toolCall.params,
|
||||
}),
|
||||
@@ -91,7 +91,7 @@ export const buildChatRouter = (
|
||||
if (assistantMessage?.info.role === "assistant" && assistantMessage.info.error) {
|
||||
res.write(
|
||||
toSse("error", {
|
||||
conversationId,
|
||||
session_id: clientSessionId,
|
||||
message: getErrorMessage(assistantMessage.info.error),
|
||||
detail: assistantMessage.info.error.name,
|
||||
}),
|
||||
@@ -99,13 +99,13 @@ export const buildChatRouter = (
|
||||
} else if (!assistantMessage) {
|
||||
res.write(
|
||||
toSse("error", {
|
||||
conversationId,
|
||||
session_id: clientSessionId,
|
||||
message: "assistant response unavailable",
|
||||
detail: "no assistant message found after prompt",
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
res.write(toSse("done", { conversationId }));
|
||||
res.write(toSse("done", { session_id: clientSessionId }));
|
||||
}
|
||||
|
||||
res.end();
|
||||
@@ -125,7 +125,7 @@ export const buildChatRouter = (
|
||||
const toSse = (event: string, data: Record<string, unknown>) =>
|
||||
`event: ${event}\ndata: ${JSON.stringify(data)}\n\n`;
|
||||
|
||||
// 先把 opencode 的 Part 结构压平成前端当前消费的 SSE 语义。
|
||||
// 先把 opencode 的 Part 结构压平成 Agent API 的 SSE 语义。
|
||||
const collectTextContent = (parts: Part[]) =>
|
||||
parts
|
||||
.filter((part): part is Extract<Part, { type: "text" }> => part.type === "text")
|
||||
|
||||
Reference in New Issue
Block a user