chat: add model switching and preloaded instructions
Expose the OpenCode model list and session model switch over the chat protocol, carry a per-session model provider on chat rows, and apply a preloaded behavior brief as a durable session instruction entry when a chat is created.
This commit is contained in:
@@ -367,6 +367,29 @@ test("chatPrompt includes files when present and reads chat_queued", async () =>
|
||||
assert.equal(queued, true);
|
||||
});
|
||||
|
||||
test("chatModels and switchChatModel use the session-scoped wire shapes", async () => {
|
||||
const { repo, ws } = connected();
|
||||
ws.reply = (frame) => {
|
||||
if (frame.type === "chat_models") {
|
||||
return { id: frame.id, type: "chat_models", chat_models: [{ id: "m1", provider: "p1", name: "Model One" }] };
|
||||
}
|
||||
return { id: frame.id, type: "chat_model", chat_model: frame.chat_model };
|
||||
};
|
||||
const models = await repo.chatModels("s1");
|
||||
assert.deepEqual(lastFrame(ws), {
|
||||
type: "chat_models",
|
||||
chat_query: { session_id: "s1" },
|
||||
});
|
||||
assert.deepEqual(models, [{ id: "m1", provider: "p1", name: "Model One" }]);
|
||||
|
||||
const selected = await repo.switchChatModel("s1", "p1", "m1");
|
||||
assert.deepEqual(lastFrame(ws), {
|
||||
type: "chat_model",
|
||||
chat_model: { session_id: "s1", provider: "p1", model: "m1" },
|
||||
});
|
||||
assert.equal(selected.model, "m1");
|
||||
});
|
||||
|
||||
test("chatPrompt sends browser attachment bytes with their name and mime", async () => {
|
||||
const { repo, ws } = connected();
|
||||
ws.reply = (frame) => ({ id: frame.id, type: "chat_prompt" });
|
||||
@@ -441,6 +464,13 @@ test("chatCreate sends title/directory/operation_id and returns chat_session", a
|
||||
assert.deepEqual(session, created);
|
||||
});
|
||||
|
||||
test("chatCreate sends a preloaded behavior brief when provided", async () => {
|
||||
const { repo, ws } = connected();
|
||||
ws.reply = (frame) => ({ id: frame.id, type: "chat_create", chat_session: { id: "s1" } });
|
||||
await repo.chatCreate("New chat", "/repo", "op-5", { instructions: "be careful" });
|
||||
assert.equal(lastFrame(ws).chat_create.instructions, "be careful");
|
||||
});
|
||||
|
||||
test("chatCreate throws when the reply carries no chat_session", async () => {
|
||||
const { repo, ws } = connected();
|
||||
ws.reply = (frame) => ({ id: frame.id, type: "chat_create" });
|
||||
|
||||
Reference in New Issue
Block a user