feat: associate threads with projects (#8745)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { ContentBlock } from "@agentclientprotocol/sdk";
|
||||
import * as directAcp from "./acpApi";
|
||||
import type { AcpSessionInfo } from "./acpApi";
|
||||
import * as sessionTracker from "./acpSessionTracker";
|
||||
import {
|
||||
getCatalogEntry,
|
||||
@@ -27,6 +28,7 @@ export interface AcpSendMessageOptions {
|
||||
|
||||
export interface AcpPrepareSessionOptions {
|
||||
personaId?: string;
|
||||
projectId?: string;
|
||||
}
|
||||
|
||||
export interface AcpCreateSessionOptions extends AcpPrepareSessionOptions {
|
||||
@@ -116,6 +118,7 @@ export async function acpPrepareSession(
|
||||
providerId,
|
||||
workingDir,
|
||||
options.personaId,
|
||||
options.projectId,
|
||||
);
|
||||
perfLog(
|
||||
`[perf:prepare] ${sid} acpPrepareSession done in ${(performance.now() - t0).toFixed(1)}ms`,
|
||||
@@ -155,13 +158,7 @@ export async function acpSetModel(
|
||||
return directAcp.setModel(gooseSessionId ?? sessionId, modelId);
|
||||
}
|
||||
|
||||
/** Session info returned by the goose binary's list_sessions. */
|
||||
export interface AcpSessionInfo {
|
||||
sessionId: string;
|
||||
title: string | null;
|
||||
updatedAt: string | null;
|
||||
messageCount: number;
|
||||
}
|
||||
export type { AcpSessionInfo };
|
||||
|
||||
export interface AcpSessionSearchResult {
|
||||
sessionId: string;
|
||||
|
||||
@@ -18,6 +18,7 @@ export interface AcpSessionInfo {
|
||||
title: string | null;
|
||||
updatedAt: string | null;
|
||||
messageCount: number;
|
||||
projectId?: string | null;
|
||||
}
|
||||
|
||||
const DEPRECATED_PROVIDER_IDS = new Set(["claude-code", "codex", "gemini-cli"]);
|
||||
@@ -50,6 +51,7 @@ export async function listSessions(): Promise<AcpSessionInfo[]> {
|
||||
title: info.title ?? null,
|
||||
updatedAt: info.updatedAt ?? null,
|
||||
messageCount: (info._meta?.messageCount as number) ?? 0,
|
||||
projectId: (info._meta?.projectId as string) ?? null,
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -124,6 +126,17 @@ export async function updateWorkingDir(
|
||||
await client.extMethod("goose/working_dir/update", { sessionId, workingDir });
|
||||
}
|
||||
|
||||
export async function updateSessionProject(
|
||||
sessionId: string,
|
||||
projectId: string | null,
|
||||
): Promise<void> {
|
||||
const client = await getClient();
|
||||
await client.extMethod("_goose/session/update_project", {
|
||||
sessionId,
|
||||
projectId,
|
||||
});
|
||||
}
|
||||
|
||||
export async function cancelSession(sessionId: string): Promise<void> {
|
||||
const client = await getClient();
|
||||
await client.cancel({ sessionId });
|
||||
@@ -132,6 +145,7 @@ export async function cancelSession(sessionId: string): Promise<void> {
|
||||
export async function newSession(
|
||||
workingDir: string,
|
||||
providerId?: string,
|
||||
projectId?: string,
|
||||
): Promise<NewSessionResponse> {
|
||||
const tClient = performance.now();
|
||||
const client = await getClient();
|
||||
@@ -142,9 +156,10 @@ export async function newSession(
|
||||
mcpServers: [],
|
||||
};
|
||||
|
||||
if (providerId) {
|
||||
request.meta = { provider: providerId };
|
||||
}
|
||||
const meta: Record<string, string> = {};
|
||||
if (providerId) meta.provider = providerId;
|
||||
if (projectId) meta.projectId = projectId;
|
||||
if (Object.keys(meta).length > 0) request.meta = meta;
|
||||
|
||||
const tCall = performance.now();
|
||||
const response = await client.newSession(request);
|
||||
|
||||
@@ -56,6 +56,7 @@ export async function prepareSession(
|
||||
providerId: string,
|
||||
workingDir: string,
|
||||
personaId?: string,
|
||||
projectId?: string,
|
||||
): Promise<string> {
|
||||
const sid = sessionId.slice(0, 8);
|
||||
const key = makeKey(sessionId, personaId);
|
||||
@@ -101,7 +102,7 @@ export async function prepareSession(
|
||||
|
||||
if (!gooseSessionId) {
|
||||
const tNew = performance.now();
|
||||
const response = await acpApi.newSession(workingDir, providerId);
|
||||
const response = await acpApi.newSession(workingDir, providerId, projectId);
|
||||
gooseSessionId = response.sessionId;
|
||||
perfLog(
|
||||
`[perf:prepare] ${sid} tracker newSession done in ${(performance.now() - tNew).toFixed(1)}ms (goose_sid=${gooseSessionId.slice(0, 8)})`,
|
||||
|
||||
Reference in New Issue
Block a user