Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,16 @@ export const conversationThreadListAdapter: RemoteThreadListAdapter = {
};
},

// New conversations do not have a backend ID until their first agent run.
// Accept metadata updates so assistant-ui can retain the selected agent in
// its local thread state while users switch between conversations.
async updateCustom(
_remoteId: string,
_custom: Record<string, unknown> | undefined
): Promise<void> {
return;
},

async rename(remoteId: string, newTitle: string): Promise<void> {
const candidateId = await waitForServerConversationId(remoteId);
const conversationId = Number(candidateId);
Expand Down
5 changes: 5 additions & 0 deletions frontend/app/[locale]/newchat/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,11 @@ const HomeContent: FC<{
async (agent: Agent) => {
shouldRestoreAgentRef.current = true;
await runtime.threads.switchToNewThread();
const thread = runtime.threads.getItemById(
runtime.threads.getState().mainThreadId
);
await thread.initialize();
await thread.updateCustom({ agentId: agent.id });
Comment thread
WMC001 marked this conversation as resolved.
onAgentSelected(agent);
},
[runtime, onAgentSelected]
Expand Down
3 changes: 0 additions & 3 deletions frontend/services/storageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,6 @@ export async function fetchImageBlob(url: string): Promise<Blob> {
const apiUrl = convertImageUrlToApiUrl(url);
log.info(`[fetchImageBlob] input=${url}, apiUrl=${apiUrl}`);
const response = await fetch(apiUrl);
log.info(
`[fetchImageBlob] status=${response.status}, contentType=${response.headers.get("content-type")}`
);
if (!response.ok) {
throw new Error(
`Failed to fetch image: ${response.status} ${response.statusText}`
Expand Down
36 changes: 36 additions & 0 deletions frontend/tests/newchatThreadAgentBinding.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import test from "node:test";

const pagePath = new URL("../app/[locale]/newchat/page.tsx", import.meta.url);
const adapterPath = new URL(
"../app/[locale]/newchat/adapter/conversation-thread-list-adapter.tsx",
import.meta.url
);

test("binds an agent selected for a new thread to that thread's metadata", async () => {
const page = await readFile(pagePath, "utf8");

assert.match(
page,
/thread\.updateCustom\(\{\s*agentId:\s*agent\.id\s*\}\)/
);
});

test("initializes a new thread before storing its selected agent", async () => {
const page = await readFile(pagePath, "utf8");

assert.match(
page,
/const thread = runtime\.threads\.getItemById\([\s\S]*await thread\.initialize\(\);[\s\S]*await thread\.updateCustom\(/
);
});

test("supports storing an agent on a new thread before the conversation exists on the server", async () => {
const adapter = await readFile(adapterPath, "utf8");

assert.match(
adapter,
/async updateCustom\(\s*_remoteId: string,\s*_custom: Record<string, unknown> \| undefined\s*\): Promise<void>/
);
});
Loading