mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-16 15:02:39 +00:00
parent
400f9a214e
commit
99abb9d42e
171 changed files with 7260 additions and 7342 deletions
|
|
@ -24,7 +24,7 @@ export interface FoundryAppClient {
|
|||
cancelScheduledRenewal(organizationId: string): Promise<void>;
|
||||
resumeSubscription(organizationId: string): Promise<void>;
|
||||
reconnectGithub(organizationId: string): Promise<void>;
|
||||
recordSeatUsage(workspaceId: string): Promise<void>;
|
||||
recordSeatUsage(organizationId: string): Promise<void>;
|
||||
}
|
||||
|
||||
export interface CreateFoundryAppClientOptions {
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,10 +1,10 @@
|
|||
export * from "./app-client.js";
|
||||
export * from "./backend-client.js";
|
||||
export * from "./interest/manager.js";
|
||||
export * from "./interest/mock-manager.js";
|
||||
export * from "./interest/remote-manager.js";
|
||||
export * from "./interest/topics.js";
|
||||
export * from "./interest/use-interest.js";
|
||||
export * from "./subscription/manager.js";
|
||||
export * from "./subscription/mock-manager.js";
|
||||
export * from "./subscription/remote-manager.js";
|
||||
export * from "./subscription/topics.js";
|
||||
export * from "./subscription/use-subscription.js";
|
||||
export * from "./keys.js";
|
||||
export * from "./mock-app.js";
|
||||
export * from "./view-model.js";
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
import { createMockBackendClient } from "../mock/backend-client.js";
|
||||
import { RemoteInterestManager } from "./remote-manager.js";
|
||||
|
||||
/**
|
||||
* Mock implementation shares the same interest-manager harness as the remote
|
||||
* path, but uses the in-memory mock backend that synthesizes actor events.
|
||||
*/
|
||||
export class MockInterestManager extends RemoteInterestManager {
|
||||
constructor() {
|
||||
super(createMockBackendClient());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,29 +1,21 @@
|
|||
export type ActorKey = string[];
|
||||
|
||||
export function workspaceKey(workspaceId: string): ActorKey {
|
||||
return ["ws", workspaceId];
|
||||
export function organizationKey(organizationId: string): ActorKey {
|
||||
return ["org", organizationId];
|
||||
}
|
||||
|
||||
export function projectKey(workspaceId: string, repoId: string): ActorKey {
|
||||
return ["ws", workspaceId, "project", repoId];
|
||||
export function repositoryKey(organizationId: string, repoId: string): ActorKey {
|
||||
return ["org", organizationId, "repository", repoId];
|
||||
}
|
||||
|
||||
export function taskKey(workspaceId: string, repoId: string, taskId: string): ActorKey {
|
||||
return ["ws", workspaceId, "project", repoId, "task", taskId];
|
||||
export function taskKey(organizationId: string, repoId: string, taskId: string): ActorKey {
|
||||
return ["org", organizationId, "repository", repoId, "task", taskId];
|
||||
}
|
||||
|
||||
export function taskSandboxKey(workspaceId: string, sandboxId: string): ActorKey {
|
||||
return ["ws", workspaceId, "sandbox", sandboxId];
|
||||
export function taskSandboxKey(organizationId: string, sandboxId: string): ActorKey {
|
||||
return ["org", organizationId, "sandbox", sandboxId];
|
||||
}
|
||||
|
||||
export function historyKey(workspaceId: string, repoId: string): ActorKey {
|
||||
return ["ws", workspaceId, "project", repoId, "history"];
|
||||
}
|
||||
|
||||
export function projectPrSyncKey(workspaceId: string, repoId: string): ActorKey {
|
||||
return ["ws", workspaceId, "project", repoId, "pr-sync"];
|
||||
}
|
||||
|
||||
export function projectBranchSyncKey(workspaceId: string, repoId: string): ActorKey {
|
||||
return ["ws", workspaceId, "project", repoId, "branch-sync"];
|
||||
export function historyKey(organizationId: string, repoId: string): ActorKey {
|
||||
return ["org", organizationId, "repository", repoId, "history"];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ export interface MockFoundryOrganizationSettings {
|
|||
|
||||
export interface MockFoundryOrganization {
|
||||
id: string;
|
||||
workspaceId: string;
|
||||
organizationId: string;
|
||||
kind: MockOrganizationKind;
|
||||
settings: MockFoundryOrganizationSettings;
|
||||
github: MockFoundryGithubState;
|
||||
|
|
@ -118,7 +118,7 @@ export interface MockFoundryAppClient {
|
|||
cancelScheduledRenewal(organizationId: string): Promise<void>;
|
||||
resumeSubscription(organizationId: string): Promise<void>;
|
||||
reconnectGithub(organizationId: string): Promise<void>;
|
||||
recordSeatUsage(workspaceId: string): void;
|
||||
recordSeatUsage(organizationId: string): void;
|
||||
}
|
||||
|
||||
const STORAGE_KEY = "sandbox-agent-foundry:mock-app:v1";
|
||||
|
|
@ -173,7 +173,7 @@ function buildRivetOrganization(): MockFoundryOrganization {
|
|||
|
||||
return {
|
||||
id: "rivet",
|
||||
workspaceId: "rivet",
|
||||
organizationId: "rivet",
|
||||
kind: "organization",
|
||||
settings: {
|
||||
displayName: rivetDevFixture.name ?? rivetDevFixture.login,
|
||||
|
|
@ -254,7 +254,7 @@ function buildDefaultSnapshot(): MockFoundryAppSnapshot {
|
|||
organizations: [
|
||||
{
|
||||
id: "personal-nathan",
|
||||
workspaceId: "personal-nathan",
|
||||
organizationId: "personal-nathan",
|
||||
kind: "personal",
|
||||
settings: {
|
||||
displayName: "Nathan",
|
||||
|
|
@ -290,7 +290,7 @@ function buildDefaultSnapshot(): MockFoundryAppSnapshot {
|
|||
},
|
||||
{
|
||||
id: "acme",
|
||||
workspaceId: "acme",
|
||||
organizationId: "acme",
|
||||
kind: "organization",
|
||||
settings: {
|
||||
displayName: "Acme",
|
||||
|
|
@ -335,7 +335,7 @@ function buildDefaultSnapshot(): MockFoundryAppSnapshot {
|
|||
buildRivetOrganization(),
|
||||
{
|
||||
id: "personal-jamie",
|
||||
workspaceId: "personal-jamie",
|
||||
organizationId: "personal-jamie",
|
||||
kind: "personal",
|
||||
settings: {
|
||||
displayName: "Jamie",
|
||||
|
|
@ -659,8 +659,8 @@ class MockFoundryAppStore implements MockFoundryAppClient {
|
|||
}));
|
||||
}
|
||||
|
||||
recordSeatUsage(workspaceId: string): void {
|
||||
const org = this.snapshot.organizations.find((candidate) => candidate.workspaceId === workspaceId);
|
||||
recordSeatUsage(organizationId: string): void {
|
||||
const org = this.snapshot.organizations.find((candidate) => candidate.organizationId === organizationId);
|
||||
const currentUser = currentMockUser(this.snapshot);
|
||||
if (!org || !currentUser) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import type {
|
||||
AddRepoInput,
|
||||
AppEvent,
|
||||
CreateTaskInput,
|
||||
FoundryAppSnapshot,
|
||||
|
|
@ -17,21 +16,19 @@ import type {
|
|||
TaskWorkbenchSetSessionUnreadInput,
|
||||
TaskWorkbenchSendMessageInput,
|
||||
TaskWorkbenchSnapshot,
|
||||
TaskWorkbenchTabInput,
|
||||
TaskWorkbenchSessionInput,
|
||||
TaskWorkbenchUpdateDraftInput,
|
||||
TaskEvent,
|
||||
WorkbenchSessionDetail,
|
||||
WorkbenchTaskDetail,
|
||||
WorkbenchTaskSummary,
|
||||
WorkspaceEvent,
|
||||
WorkspaceSummarySnapshot,
|
||||
OrganizationEvent,
|
||||
OrganizationSummarySnapshot,
|
||||
HistoryEvent,
|
||||
HistoryQueryInput,
|
||||
ProviderId,
|
||||
SandboxProviderId,
|
||||
RepoOverview,
|
||||
RepoRecord,
|
||||
RepoStackActionInput,
|
||||
RepoStackActionResult,
|
||||
StarSandboxAgentRepoResult,
|
||||
SwitchResult,
|
||||
} from "@sandbox-agent/foundry-shared";
|
||||
|
|
@ -91,7 +88,7 @@ function toTaskStatus(status: TaskRecord["status"], archived: boolean): TaskReco
|
|||
return status;
|
||||
}
|
||||
|
||||
export function createMockBackendClient(defaultWorkspaceId = "default"): BackendClient {
|
||||
export function createMockBackendClient(defaultOrganizationId = "default"): BackendClient {
|
||||
const workbench = getSharedMockWorkbenchClient();
|
||||
const listenersBySandboxId = new Map<string, Set<() => void>>();
|
||||
const processesBySandboxId = new Map<string, MockProcessRecord[]>();
|
||||
|
|
@ -176,9 +173,10 @@ export function createMockBackendClient(defaultWorkspaceId = "default"): Backend
|
|||
updatedAtMs: task.updatedAtMs,
|
||||
branch: task.branch,
|
||||
pullRequest: task.pullRequest,
|
||||
sessionsSummary: task.tabs.map((tab) => ({
|
||||
sessionsSummary: task.sessions.map((tab) => ({
|
||||
id: tab.id,
|
||||
sessionId: tab.sessionId,
|
||||
sandboxSessionId: tab.sandboxSessionId ?? tab.sessionId,
|
||||
sessionName: tab.sessionName,
|
||||
agent: tab.agent,
|
||||
model: tab.model,
|
||||
|
|
@ -192,10 +190,10 @@ export function createMockBackendClient(defaultWorkspaceId = "default"): Backend
|
|||
const buildTaskDetail = (task: TaskWorkbenchSnapshot["tasks"][number]): WorkbenchTaskDetail => ({
|
||||
...buildTaskSummary(task),
|
||||
task: task.title,
|
||||
agentType: task.tabs[0]?.agent === "Codex" ? "codex" : "claude",
|
||||
agentType: task.sessions[0]?.agent === "Codex" ? "codex" : "claude",
|
||||
runtimeStatus: toTaskStatus(task.status === "archived" ? "archived" : "running", task.status === "archived"),
|
||||
statusMessage: task.status === "archived" ? "archived" : "mock sandbox ready",
|
||||
activeSessionId: task.tabs[0]?.sessionId ?? null,
|
||||
activeSessionId: task.sessions[0]?.sessionId ?? null,
|
||||
diffStat: task.fileChanges.length > 0 ? `+${task.fileChanges.length}/-${task.fileChanges.length}` : "+0/-0",
|
||||
prUrl: task.pullRequest ? `https://example.test/pr/${task.pullRequest.number}` : null,
|
||||
reviewStatus: null,
|
||||
|
|
@ -205,7 +203,7 @@ export function createMockBackendClient(defaultWorkspaceId = "default"): Backend
|
|||
minutesUsed: task.minutesUsed,
|
||||
sandboxes: [
|
||||
{
|
||||
providerId: "local",
|
||||
sandboxProviderId: "local",
|
||||
sandboxId: task.id,
|
||||
cwd: mockCwd(task.repoName, task.id),
|
||||
},
|
||||
|
|
@ -213,15 +211,14 @@ export function createMockBackendClient(defaultWorkspaceId = "default"): Backend
|
|||
activeSandboxId: task.id,
|
||||
});
|
||||
|
||||
const buildSessionDetail = (task: TaskWorkbenchSnapshot["tasks"][number], tabId: string): WorkbenchSessionDetail => {
|
||||
const tab = task.tabs.find((candidate) => candidate.id === tabId);
|
||||
const buildSessionDetail = (task: TaskWorkbenchSnapshot["tasks"][number], sessionId: string): WorkbenchSessionDetail => {
|
||||
const tab = task.sessions.find((candidate) => candidate.id === sessionId);
|
||||
if (!tab) {
|
||||
throw new Error(`Unknown mock tab ${tabId} for task ${task.id}`);
|
||||
throw new Error(`Unknown mock session ${sessionId} for task ${task.id}`);
|
||||
}
|
||||
return {
|
||||
sessionId: tab.id,
|
||||
tabId: tab.id,
|
||||
sandboxSessionId: tab.sessionId,
|
||||
sandboxSessionId: tab.sandboxSessionId ?? tab.sessionId,
|
||||
sessionName: tab.sessionName,
|
||||
agent: tab.agent,
|
||||
model: tab.model,
|
||||
|
|
@ -234,11 +231,11 @@ export function createMockBackendClient(defaultWorkspaceId = "default"): Backend
|
|||
};
|
||||
};
|
||||
|
||||
const buildWorkspaceSummary = (): WorkspaceSummarySnapshot => {
|
||||
const buildOrganizationSummary = (): OrganizationSummarySnapshot => {
|
||||
const snapshot = workbench.getSnapshot();
|
||||
const taskSummaries = snapshot.tasks.map(buildTaskSummary);
|
||||
return {
|
||||
workspaceId: defaultWorkspaceId,
|
||||
organizationId: defaultOrganizationId,
|
||||
repos: snapshot.repos.map((repo) => {
|
||||
const repoTasks = taskSummaries.filter((task) => task.repoId === repo.id);
|
||||
return {
|
||||
|
|
@ -253,39 +250,40 @@ export function createMockBackendClient(defaultWorkspaceId = "default"): Backend
|
|||
};
|
||||
};
|
||||
|
||||
const workspaceScope = (workspaceId: string): string => `workspace:${workspaceId}`;
|
||||
const taskScope = (workspaceId: string, repoId: string, taskId: string): string => `task:${workspaceId}:${repoId}:${taskId}`;
|
||||
const sandboxScope = (workspaceId: string, providerId: string, sandboxId: string): string => `sandbox:${workspaceId}:${providerId}:${sandboxId}`;
|
||||
const organizationScope = (organizationId: string): string => `organization:${organizationId}`;
|
||||
const taskScope = (organizationId: string, repoId: string, taskId: string): string => `task:${organizationId}:${repoId}:${taskId}`;
|
||||
const sandboxScope = (organizationId: string, sandboxProviderId: string, sandboxId: string): string =>
|
||||
`sandbox:${organizationId}:${sandboxProviderId}:${sandboxId}`;
|
||||
|
||||
const emitWorkspaceSnapshot = (): void => {
|
||||
const summary = buildWorkspaceSummary();
|
||||
const emitOrganizationSnapshot = (): void => {
|
||||
const summary = buildOrganizationSummary();
|
||||
const latestTask = [...summary.taskSummaries].sort((left, right) => right.updatedAtMs - left.updatedAtMs)[0] ?? null;
|
||||
if (latestTask) {
|
||||
emitConnectionEvent(workspaceScope(defaultWorkspaceId), "workspaceUpdated", {
|
||||
emitConnectionEvent(organizationScope(defaultOrganizationId), "organizationUpdated", {
|
||||
type: "taskSummaryUpdated",
|
||||
taskSummary: latestTask,
|
||||
} satisfies WorkspaceEvent);
|
||||
} satisfies OrganizationEvent);
|
||||
}
|
||||
};
|
||||
|
||||
const emitTaskUpdate = (taskId: string): void => {
|
||||
const task = requireTask(taskId);
|
||||
emitConnectionEvent(taskScope(defaultWorkspaceId, task.repoId, task.id), "taskUpdated", {
|
||||
emitConnectionEvent(taskScope(defaultOrganizationId, task.repoId, task.id), "taskUpdated", {
|
||||
type: "taskDetailUpdated",
|
||||
detail: buildTaskDetail(task),
|
||||
} satisfies TaskEvent);
|
||||
};
|
||||
|
||||
const emitSessionUpdate = (taskId: string, tabId: string): void => {
|
||||
const emitSessionUpdate = (taskId: string, sessionId: string): void => {
|
||||
const task = requireTask(taskId);
|
||||
emitConnectionEvent(taskScope(defaultWorkspaceId, task.repoId, task.id), "sessionUpdated", {
|
||||
emitConnectionEvent(taskScope(defaultOrganizationId, task.repoId, task.id), "sessionUpdated", {
|
||||
type: "sessionUpdated",
|
||||
session: buildSessionDetail(task, tabId),
|
||||
session: buildSessionDetail(task, sessionId),
|
||||
} satisfies SessionEvent);
|
||||
};
|
||||
|
||||
const emitSandboxProcessesUpdate = (sandboxId: string): void => {
|
||||
emitConnectionEvent(sandboxScope(defaultWorkspaceId, "local", sandboxId), "processesUpdated", {
|
||||
emitConnectionEvent(sandboxScope(defaultOrganizationId, "local", sandboxId), "processesUpdated", {
|
||||
type: "processesUpdated",
|
||||
processes: ensureProcessList(sandboxId).map((process) => cloneProcess(process)),
|
||||
} satisfies SandboxProcessesEvent);
|
||||
|
|
@ -296,22 +294,22 @@ export function createMockBackendClient(defaultWorkspaceId = "default"): Backend
|
|||
const cwd = mockCwd(task.repoName, task.id);
|
||||
const archived = task.status === "archived";
|
||||
return {
|
||||
workspaceId: defaultWorkspaceId,
|
||||
organizationId: defaultOrganizationId,
|
||||
repoId: task.repoId,
|
||||
repoRemote: mockRepoRemote(task.repoName),
|
||||
taskId: task.id,
|
||||
branchName: task.branch,
|
||||
title: task.title,
|
||||
task: task.title,
|
||||
providerId: "local",
|
||||
sandboxProviderId: "local",
|
||||
status: toTaskStatus(archived ? "archived" : "running", archived),
|
||||
statusMessage: archived ? "archived" : "mock sandbox ready",
|
||||
activeSandboxId: task.id,
|
||||
activeSessionId: task.tabs[0]?.sessionId ?? null,
|
||||
activeSessionId: task.sessions[0]?.sessionId ?? null,
|
||||
sandboxes: [
|
||||
{
|
||||
sandboxId: task.id,
|
||||
providerId: "local",
|
||||
sandboxProviderId: "local",
|
||||
sandboxActorId: "mock-sandbox",
|
||||
switchTarget: `mock://${task.id}`,
|
||||
cwd,
|
||||
|
|
@ -319,7 +317,7 @@ export function createMockBackendClient(defaultWorkspaceId = "default"): Backend
|
|||
updatedAt: task.updatedAtMs,
|
||||
},
|
||||
],
|
||||
agentType: task.tabs[0]?.agent === "Codex" ? "codex" : "claude",
|
||||
agentType: task.sessions[0]?.agent === "Codex" ? "codex" : "claude",
|
||||
prSubmitted: Boolean(task.pullRequest),
|
||||
diffStat: task.fileChanges.length > 0 ? `+${task.fileChanges.length}/-${task.fileChanges.length}` : "+0/-0",
|
||||
prUrl: task.pullRequest ? `https://example.test/pr/${task.pullRequest.number}` : null,
|
||||
|
|
@ -366,16 +364,16 @@ export function createMockBackendClient(defaultWorkspaceId = "default"): Backend
|
|||
return unsupportedAppSnapshot();
|
||||
},
|
||||
|
||||
async connectWorkspace(workspaceId: string): Promise<ActorConn> {
|
||||
return createConn(workspaceScope(workspaceId));
|
||||
async connectOrganization(organizationId: string): Promise<ActorConn> {
|
||||
return createConn(organizationScope(organizationId));
|
||||
},
|
||||
|
||||
async connectTask(workspaceId: string, repoId: string, taskId: string): Promise<ActorConn> {
|
||||
return createConn(taskScope(workspaceId, repoId, taskId));
|
||||
async connectTask(organizationId: string, repoId: string, taskId: string): Promise<ActorConn> {
|
||||
return createConn(taskScope(organizationId, repoId, taskId));
|
||||
},
|
||||
|
||||
async connectSandbox(workspaceId: string, providerId: ProviderId, sandboxId: string): Promise<ActorConn> {
|
||||
return createConn(sandboxScope(workspaceId, providerId, sandboxId));
|
||||
async connectSandbox(organizationId: string, sandboxProviderId: SandboxProviderId, sandboxId: string): Promise<ActorConn> {
|
||||
return createConn(sandboxScope(organizationId, sandboxProviderId, sandboxId));
|
||||
},
|
||||
|
||||
subscribeApp(): () => void {
|
||||
|
|
@ -434,13 +432,9 @@ export function createMockBackendClient(defaultWorkspaceId = "default"): Backend
|
|||
return unsupportedAppSnapshot();
|
||||
},
|
||||
|
||||
async addRepo(_workspaceId: string, _remoteUrl: string): Promise<RepoRecord> {
|
||||
notSupported("addRepo");
|
||||
},
|
||||
|
||||
async listRepos(_workspaceId: string): Promise<RepoRecord[]> {
|
||||
async listRepos(_organizationId: string): Promise<RepoRecord[]> {
|
||||
return workbench.getSnapshot().repos.map((repo) => ({
|
||||
workspaceId: defaultWorkspaceId,
|
||||
organizationId: defaultOrganizationId,
|
||||
repoId: repo.id,
|
||||
remoteUrl: mockRepoRemote(repo.label),
|
||||
createdAt: nowMs(),
|
||||
|
|
@ -452,12 +446,12 @@ export function createMockBackendClient(defaultWorkspaceId = "default"): Backend
|
|||
notSupported("createTask");
|
||||
},
|
||||
|
||||
async listTasks(_workspaceId: string, repoId?: string): Promise<TaskSummary[]> {
|
||||
async listTasks(_organizationId: string, repoId?: string): Promise<TaskSummary[]> {
|
||||
return workbench
|
||||
.getSnapshot()
|
||||
.tasks.filter((task) => !repoId || task.repoId === repoId)
|
||||
.map((task) => ({
|
||||
workspaceId: defaultWorkspaceId,
|
||||
organizationId: defaultOrganizationId,
|
||||
repoId: task.repoId,
|
||||
taskId: task.id,
|
||||
branchName: task.branch,
|
||||
|
|
@ -467,15 +461,10 @@ export function createMockBackendClient(defaultWorkspaceId = "default"): Backend
|
|||
}));
|
||||
},
|
||||
|
||||
async getRepoOverview(_workspaceId: string, _repoId: string): Promise<RepoOverview> {
|
||||
async getRepoOverview(_organizationId: string, _repoId: string): Promise<RepoOverview> {
|
||||
notSupported("getRepoOverview");
|
||||
},
|
||||
|
||||
async runRepoStackAction(_input: RepoStackActionInput): Promise<RepoStackActionResult> {
|
||||
notSupported("runRepoStackAction");
|
||||
},
|
||||
|
||||
async getTask(_workspaceId: string, taskId: string): Promise<TaskRecord> {
|
||||
async getTask(_organizationId: string, taskId: string): Promise<TaskRecord> {
|
||||
return buildTaskRecord(taskId);
|
||||
},
|
||||
|
||||
|
|
@ -483,23 +472,23 @@ export function createMockBackendClient(defaultWorkspaceId = "default"): Backend
|
|||
return [];
|
||||
},
|
||||
|
||||
async switchTask(_workspaceId: string, taskId: string): Promise<SwitchResult> {
|
||||
async switchTask(_organizationId: string, taskId: string): Promise<SwitchResult> {
|
||||
return {
|
||||
workspaceId: defaultWorkspaceId,
|
||||
organizationId: defaultOrganizationId,
|
||||
taskId,
|
||||
providerId: "local",
|
||||
sandboxProviderId: "local",
|
||||
switchTarget: `mock://${taskId}`,
|
||||
};
|
||||
},
|
||||
|
||||
async attachTask(_workspaceId: string, taskId: string): Promise<{ target: string; sessionId: string | null }> {
|
||||
async attachTask(_organizationId: string, taskId: string): Promise<{ target: string; sessionId: string | null }> {
|
||||
return {
|
||||
target: `mock://${taskId}`,
|
||||
sessionId: requireTask(taskId).tabs[0]?.sessionId ?? null,
|
||||
sessionId: requireTask(taskId).sessions[0]?.sessionId ?? null,
|
||||
};
|
||||
},
|
||||
|
||||
async runAction(_workspaceId: string, _taskId: string): Promise<void> {
|
||||
async runAction(_organizationId: string, _taskId: string): Promise<void> {
|
||||
notSupported("runAction");
|
||||
},
|
||||
|
||||
|
|
@ -516,8 +505,8 @@ export function createMockBackendClient(defaultWorkspaceId = "default"): Backend
|
|||
},
|
||||
|
||||
async createSandboxProcess(input: {
|
||||
workspaceId: string;
|
||||
providerId: ProviderId;
|
||||
organizationId: string;
|
||||
sandboxProviderId: SandboxProviderId;
|
||||
sandboxId: string;
|
||||
request: ProcessCreateRequest;
|
||||
}): Promise<SandboxProcessRecord> {
|
||||
|
|
@ -529,15 +518,15 @@ export function createMockBackendClient(defaultWorkspaceId = "default"): Backend
|
|||
return cloneProcess(created);
|
||||
},
|
||||
|
||||
async listSandboxProcesses(_workspaceId: string, _providerId: ProviderId, sandboxId: string): Promise<{ processes: SandboxProcessRecord[] }> {
|
||||
async listSandboxProcesses(_organizationId: string, _providerId: SandboxProviderId, sandboxId: string): Promise<{ processes: SandboxProcessRecord[] }> {
|
||||
return {
|
||||
processes: ensureProcessList(sandboxId).map((process) => cloneProcess(process)),
|
||||
};
|
||||
},
|
||||
|
||||
async getSandboxProcessLogs(
|
||||
_workspaceId: string,
|
||||
_providerId: ProviderId,
|
||||
_organizationId: string,
|
||||
_providerId: SandboxProviderId,
|
||||
sandboxId: string,
|
||||
processId: string,
|
||||
query?: ProcessLogFollowQuery,
|
||||
|
|
@ -564,8 +553,8 @@ export function createMockBackendClient(defaultWorkspaceId = "default"): Backend
|
|||
},
|
||||
|
||||
async stopSandboxProcess(
|
||||
_workspaceId: string,
|
||||
_providerId: ProviderId,
|
||||
_organizationId: string,
|
||||
_providerId: SandboxProviderId,
|
||||
sandboxId: string,
|
||||
processId: string,
|
||||
_query?: ProcessSignalQuery,
|
||||
|
|
@ -583,8 +572,8 @@ export function createMockBackendClient(defaultWorkspaceId = "default"): Backend
|
|||
},
|
||||
|
||||
async killSandboxProcess(
|
||||
_workspaceId: string,
|
||||
_providerId: ProviderId,
|
||||
_organizationId: string,
|
||||
_providerId: SandboxProviderId,
|
||||
sandboxId: string,
|
||||
processId: string,
|
||||
_query?: ProcessSignalQuery,
|
||||
|
|
@ -601,7 +590,7 @@ export function createMockBackendClient(defaultWorkspaceId = "default"): Backend
|
|||
return cloneProcess(process);
|
||||
},
|
||||
|
||||
async deleteSandboxProcess(_workspaceId: string, _providerId: ProviderId, sandboxId: string, processId: string): Promise<void> {
|
||||
async deleteSandboxProcess(_organizationId: string, _providerId: SandboxProviderId, sandboxId: string, processId: string): Promise<void> {
|
||||
processesBySandboxId.set(
|
||||
sandboxId,
|
||||
ensureProcessList(sandboxId).filter((candidate) => candidate.id !== processId),
|
||||
|
|
@ -609,7 +598,7 @@ export function createMockBackendClient(defaultWorkspaceId = "default"): Backend
|
|||
notifySandbox(sandboxId);
|
||||
},
|
||||
|
||||
subscribeSandboxProcesses(_workspaceId: string, _providerId: ProviderId, sandboxId: string, listener: () => void): () => void {
|
||||
subscribeSandboxProcesses(_organizationId: string, _providerId: SandboxProviderId, sandboxId: string, listener: () => void): () => void {
|
||||
let listeners = listenersBySandboxId.get(sandboxId);
|
||||
if (!listeners) {
|
||||
listeners = new Set();
|
||||
|
|
@ -637,26 +626,26 @@ export function createMockBackendClient(defaultWorkspaceId = "default"): Backend
|
|||
},
|
||||
|
||||
async sandboxProviderState(
|
||||
_workspaceId: string,
|
||||
_providerId: ProviderId,
|
||||
_organizationId: string,
|
||||
_providerId: SandboxProviderId,
|
||||
sandboxId: string,
|
||||
): Promise<{ providerId: ProviderId; sandboxId: string; state: string; at: number }> {
|
||||
return { providerId: "local", sandboxId, state: "running", at: nowMs() };
|
||||
): Promise<{ sandboxProviderId: SandboxProviderId; sandboxId: string; state: string; at: number }> {
|
||||
return { sandboxProviderId: "local", sandboxId, state: "running", at: nowMs() };
|
||||
},
|
||||
|
||||
async getSandboxAgentConnection(): Promise<{ endpoint: string; token?: string }> {
|
||||
return { endpoint: "mock://terminal-unavailable" };
|
||||
},
|
||||
|
||||
async getWorkspaceSummary(): Promise<WorkspaceSummarySnapshot> {
|
||||
return buildWorkspaceSummary();
|
||||
async getOrganizationSummary(): Promise<OrganizationSummarySnapshot> {
|
||||
return buildOrganizationSummary();
|
||||
},
|
||||
|
||||
async getTaskDetail(_workspaceId: string, _repoId: string, taskId: string): Promise<WorkbenchTaskDetail> {
|
||||
async getTaskDetail(_organizationId: string, _repoId: string, taskId: string): Promise<WorkbenchTaskDetail> {
|
||||
return buildTaskDetail(requireTask(taskId));
|
||||
},
|
||||
|
||||
async getSessionDetail(_workspaceId: string, _repoId: string, taskId: string, sessionId: string): Promise<WorkbenchSessionDetail> {
|
||||
async getSessionDetail(_organizationId: string, _repoId: string, taskId: string, sessionId: string): Promise<WorkbenchSessionDetail> {
|
||||
return buildSessionDetail(requireTask(taskId), sessionId);
|
||||
},
|
||||
|
||||
|
|
@ -664,103 +653,103 @@ export function createMockBackendClient(defaultWorkspaceId = "default"): Backend
|
|||
return workbench.getSnapshot();
|
||||
},
|
||||
|
||||
subscribeWorkbench(_workspaceId: string, listener: () => void): () => void {
|
||||
subscribeWorkbench(_organizationId: string, listener: () => void): () => void {
|
||||
return workbench.subscribe(listener);
|
||||
},
|
||||
|
||||
async createWorkbenchTask(_workspaceId: string, input: TaskWorkbenchCreateTaskInput): Promise<TaskWorkbenchCreateTaskResponse> {
|
||||
async createWorkbenchTask(_organizationId: string, input: TaskWorkbenchCreateTaskInput): Promise<TaskWorkbenchCreateTaskResponse> {
|
||||
const created = await workbench.createTask(input);
|
||||
emitWorkspaceSnapshot();
|
||||
emitOrganizationSnapshot();
|
||||
emitTaskUpdate(created.taskId);
|
||||
if (created.tabId) {
|
||||
emitSessionUpdate(created.taskId, created.tabId);
|
||||
if (created.sessionId) {
|
||||
emitSessionUpdate(created.taskId, created.sessionId);
|
||||
}
|
||||
return created;
|
||||
},
|
||||
|
||||
async markWorkbenchUnread(_workspaceId: string, input: TaskWorkbenchSelectInput): Promise<void> {
|
||||
async markWorkbenchUnread(_organizationId: string, input: TaskWorkbenchSelectInput): Promise<void> {
|
||||
await workbench.markTaskUnread(input);
|
||||
emitWorkspaceSnapshot();
|
||||
emitOrganizationSnapshot();
|
||||
emitTaskUpdate(input.taskId);
|
||||
},
|
||||
|
||||
async renameWorkbenchTask(_workspaceId: string, input: TaskWorkbenchRenameInput): Promise<void> {
|
||||
async renameWorkbenchTask(_organizationId: string, input: TaskWorkbenchRenameInput): Promise<void> {
|
||||
await workbench.renameTask(input);
|
||||
emitWorkspaceSnapshot();
|
||||
emitOrganizationSnapshot();
|
||||
emitTaskUpdate(input.taskId);
|
||||
},
|
||||
|
||||
async renameWorkbenchBranch(_workspaceId: string, input: TaskWorkbenchRenameInput): Promise<void> {
|
||||
async renameWorkbenchBranch(_organizationId: string, input: TaskWorkbenchRenameInput): Promise<void> {
|
||||
await workbench.renameBranch(input);
|
||||
emitWorkspaceSnapshot();
|
||||
emitOrganizationSnapshot();
|
||||
emitTaskUpdate(input.taskId);
|
||||
},
|
||||
|
||||
async createWorkbenchSession(_workspaceId: string, input: TaskWorkbenchSelectInput & { model?: string }): Promise<{ tabId: string }> {
|
||||
const created = await workbench.addTab(input);
|
||||
emitWorkspaceSnapshot();
|
||||
async createWorkbenchSession(_organizationId: string, input: TaskWorkbenchSelectInput & { model?: string }): Promise<{ sessionId: string }> {
|
||||
const created = await workbench.addSession(input);
|
||||
emitOrganizationSnapshot();
|
||||
emitTaskUpdate(input.taskId);
|
||||
emitSessionUpdate(input.taskId, created.tabId);
|
||||
emitSessionUpdate(input.taskId, created.sessionId);
|
||||
return created;
|
||||
},
|
||||
|
||||
async renameWorkbenchSession(_workspaceId: string, input: TaskWorkbenchRenameSessionInput): Promise<void> {
|
||||
async renameWorkbenchSession(_organizationId: string, input: TaskWorkbenchRenameSessionInput): Promise<void> {
|
||||
await workbench.renameSession(input);
|
||||
emitWorkspaceSnapshot();
|
||||
emitOrganizationSnapshot();
|
||||
emitTaskUpdate(input.taskId);
|
||||
emitSessionUpdate(input.taskId, input.tabId);
|
||||
emitSessionUpdate(input.taskId, input.sessionId);
|
||||
},
|
||||
|
||||
async setWorkbenchSessionUnread(_workspaceId: string, input: TaskWorkbenchSetSessionUnreadInput): Promise<void> {
|
||||
async setWorkbenchSessionUnread(_organizationId: string, input: TaskWorkbenchSetSessionUnreadInput): Promise<void> {
|
||||
await workbench.setSessionUnread(input);
|
||||
emitWorkspaceSnapshot();
|
||||
emitOrganizationSnapshot();
|
||||
emitTaskUpdate(input.taskId);
|
||||
emitSessionUpdate(input.taskId, input.tabId);
|
||||
emitSessionUpdate(input.taskId, input.sessionId);
|
||||
},
|
||||
|
||||
async updateWorkbenchDraft(_workspaceId: string, input: TaskWorkbenchUpdateDraftInput): Promise<void> {
|
||||
async updateWorkbenchDraft(_organizationId: string, input: TaskWorkbenchUpdateDraftInput): Promise<void> {
|
||||
await workbench.updateDraft(input);
|
||||
emitWorkspaceSnapshot();
|
||||
emitOrganizationSnapshot();
|
||||
emitTaskUpdate(input.taskId);
|
||||
emitSessionUpdate(input.taskId, input.tabId);
|
||||
emitSessionUpdate(input.taskId, input.sessionId);
|
||||
},
|
||||
|
||||
async changeWorkbenchModel(_workspaceId: string, input: TaskWorkbenchChangeModelInput): Promise<void> {
|
||||
async changeWorkbenchModel(_organizationId: string, input: TaskWorkbenchChangeModelInput): Promise<void> {
|
||||
await workbench.changeModel(input);
|
||||
emitWorkspaceSnapshot();
|
||||
emitOrganizationSnapshot();
|
||||
emitTaskUpdate(input.taskId);
|
||||
emitSessionUpdate(input.taskId, input.tabId);
|
||||
emitSessionUpdate(input.taskId, input.sessionId);
|
||||
},
|
||||
|
||||
async sendWorkbenchMessage(_workspaceId: string, input: TaskWorkbenchSendMessageInput): Promise<void> {
|
||||
async sendWorkbenchMessage(_organizationId: string, input: TaskWorkbenchSendMessageInput): Promise<void> {
|
||||
await workbench.sendMessage(input);
|
||||
emitWorkspaceSnapshot();
|
||||
emitOrganizationSnapshot();
|
||||
emitTaskUpdate(input.taskId);
|
||||
emitSessionUpdate(input.taskId, input.tabId);
|
||||
emitSessionUpdate(input.taskId, input.sessionId);
|
||||
},
|
||||
|
||||
async stopWorkbenchSession(_workspaceId: string, input: TaskWorkbenchTabInput): Promise<void> {
|
||||
async stopWorkbenchSession(_organizationId: string, input: TaskWorkbenchSessionInput): Promise<void> {
|
||||
await workbench.stopAgent(input);
|
||||
emitWorkspaceSnapshot();
|
||||
emitOrganizationSnapshot();
|
||||
emitTaskUpdate(input.taskId);
|
||||
emitSessionUpdate(input.taskId, input.tabId);
|
||||
emitSessionUpdate(input.taskId, input.sessionId);
|
||||
},
|
||||
|
||||
async closeWorkbenchSession(_workspaceId: string, input: TaskWorkbenchTabInput): Promise<void> {
|
||||
await workbench.closeTab(input);
|
||||
emitWorkspaceSnapshot();
|
||||
async closeWorkbenchSession(_organizationId: string, input: TaskWorkbenchSessionInput): Promise<void> {
|
||||
await workbench.closeSession(input);
|
||||
emitOrganizationSnapshot();
|
||||
emitTaskUpdate(input.taskId);
|
||||
},
|
||||
|
||||
async publishWorkbenchPr(_workspaceId: string, input: TaskWorkbenchSelectInput): Promise<void> {
|
||||
async publishWorkbenchPr(_organizationId: string, input: TaskWorkbenchSelectInput): Promise<void> {
|
||||
await workbench.publishPr(input);
|
||||
emitWorkspaceSnapshot();
|
||||
emitOrganizationSnapshot();
|
||||
emitTaskUpdate(input.taskId);
|
||||
},
|
||||
|
||||
async revertWorkbenchFile(_workspaceId: string, input: TaskWorkbenchDiffInput): Promise<void> {
|
||||
async revertWorkbenchFile(_organizationId: string, input: TaskWorkbenchDiffInput): Promise<void> {
|
||||
await workbench.revertFile(input);
|
||||
emitWorkspaceSnapshot();
|
||||
emitOrganizationSnapshot();
|
||||
emitTaskUpdate(input.taskId);
|
||||
},
|
||||
|
||||
|
|
@ -776,8 +765,8 @@ export function createMockBackendClient(defaultWorkspaceId = "default"): Backend
|
|||
return { ok: true };
|
||||
},
|
||||
|
||||
async useWorkspace(workspaceId: string): Promise<{ workspaceId: string }> {
|
||||
return { workspaceId };
|
||||
async useOrganization(organizationId: string): Promise<{ organizationId: string }> {
|
||||
return { organizationId };
|
||||
},
|
||||
|
||||
async starSandboxAgentRepo(): Promise<StarSandboxAgentRepoResult> {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import {
|
||||
MODEL_GROUPS,
|
||||
buildInitialMockLayoutViewModel,
|
||||
groupWorkbenchProjects,
|
||||
groupWorkbenchRepositories,
|
||||
nowMs,
|
||||
providerAgent,
|
||||
randomReply,
|
||||
|
|
@ -10,7 +10,7 @@ import {
|
|||
uid,
|
||||
} from "../workbench-model.js";
|
||||
import type {
|
||||
TaskWorkbenchAddTabResponse,
|
||||
TaskWorkbenchAddSessionResponse,
|
||||
TaskWorkbenchChangeModelInput,
|
||||
TaskWorkbenchCreateTaskInput,
|
||||
TaskWorkbenchCreateTaskResponse,
|
||||
|
|
@ -21,9 +21,9 @@ import type {
|
|||
TaskWorkbenchSetSessionUnreadInput,
|
||||
TaskWorkbenchSendMessageInput,
|
||||
TaskWorkbenchSnapshot,
|
||||
TaskWorkbenchTabInput,
|
||||
TaskWorkbenchSessionInput,
|
||||
TaskWorkbenchUpdateDraftInput,
|
||||
WorkbenchAgentTab as AgentTab,
|
||||
WorkbenchSession as AgentSession,
|
||||
WorkbenchTask as Task,
|
||||
WorkbenchTranscriptEvent as TranscriptEvent,
|
||||
} from "@sandbox-agent/foundry-shared";
|
||||
|
|
@ -65,7 +65,7 @@ class MockWorkbenchStore implements TaskWorkbenchClient {
|
|||
|
||||
async createTask(input: TaskWorkbenchCreateTaskInput): Promise<TaskWorkbenchCreateTaskResponse> {
|
||||
const id = uid();
|
||||
const tabId = `session-${id}`;
|
||||
const sessionId = `session-${id}`;
|
||||
const repo = this.snapshot.repos.find((candidate) => candidate.id === input.repoId);
|
||||
if (!repo) {
|
||||
throw new Error(`Cannot create mock task for unknown repo ${input.repoId}`);
|
||||
|
|
@ -79,10 +79,10 @@ class MockWorkbenchStore implements TaskWorkbenchClient {
|
|||
updatedAtMs: nowMs(),
|
||||
branch: input.branch?.trim() || null,
|
||||
pullRequest: null,
|
||||
tabs: [
|
||||
sessions: [
|
||||
{
|
||||
id: tabId,
|
||||
sessionId: tabId,
|
||||
id: sessionId,
|
||||
sessionId: sessionId,
|
||||
sessionName: "Session 1",
|
||||
agent: providerAgent(
|
||||
MODEL_GROUPS.find((group) => group.models.some((model) => model.id === (input.model ?? "claude-sonnet-4")))?.provider ?? "Claude",
|
||||
|
|
@ -106,19 +106,19 @@ class MockWorkbenchStore implements TaskWorkbenchClient {
|
|||
...current,
|
||||
tasks: [nextTask, ...current.tasks],
|
||||
}));
|
||||
return { taskId: id, tabId };
|
||||
return { taskId: id, sessionId };
|
||||
}
|
||||
|
||||
async markTaskUnread(input: TaskWorkbenchSelectInput): Promise<void> {
|
||||
this.updateTask(input.taskId, (task) => {
|
||||
const targetTab = task.tabs[task.tabs.length - 1] ?? null;
|
||||
if (!targetTab) {
|
||||
const targetSession = task.sessions[task.sessions.length - 1] ?? null;
|
||||
if (!targetSession) {
|
||||
return task;
|
||||
}
|
||||
|
||||
return {
|
||||
...task,
|
||||
tabs: task.tabs.map((tab) => (tab.id === targetTab.id ? { ...tab, unread: true } : tab)),
|
||||
sessions: task.sessions.map((session) => (session.id === targetSession.id ? { ...session, unread: true } : session)),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
|
@ -168,12 +168,12 @@ class MockWorkbenchStore implements TaskWorkbenchClient {
|
|||
}
|
||||
|
||||
async updateDraft(input: TaskWorkbenchUpdateDraftInput): Promise<void> {
|
||||
this.assertTab(input.taskId, input.tabId);
|
||||
this.assertSession(input.taskId, input.sessionId);
|
||||
this.updateTask(input.taskId, (task) => ({
|
||||
...task,
|
||||
updatedAtMs: nowMs(),
|
||||
tabs: task.tabs.map((tab) =>
|
||||
tab.id === input.tabId
|
||||
sessions: task.sessions.map((tab) =>
|
||||
tab.id === input.sessionId
|
||||
? {
|
||||
...tab,
|
||||
draft: {
|
||||
|
|
@ -193,7 +193,7 @@ class MockWorkbenchStore implements TaskWorkbenchClient {
|
|||
throw new Error(`Cannot send an empty mock prompt for task ${input.taskId}`);
|
||||
}
|
||||
|
||||
this.assertTab(input.taskId, input.tabId);
|
||||
this.assertSession(input.taskId, input.sessionId);
|
||||
const startedAtMs = nowMs();
|
||||
|
||||
this.updateTask(input.taskId, (currentTask) => {
|
||||
|
|
@ -202,10 +202,10 @@ class MockWorkbenchStore implements TaskWorkbenchClient {
|
|||
const newBranch = isFirstOnTask ? `feat/${slugify(newTitle)}` : currentTask.branch;
|
||||
const userMessageLines = [text, ...input.attachments.map((attachment) => `@ ${attachment.filePath}:${attachment.lineNumber}`)];
|
||||
const userEvent = buildTranscriptEvent({
|
||||
sessionId: input.tabId,
|
||||
sessionId: input.sessionId,
|
||||
sender: "client",
|
||||
createdAt: startedAtMs,
|
||||
eventIndex: candidateEventIndex(currentTask, input.tabId),
|
||||
eventIndex: candidateEventIndex(currentTask, input.sessionId),
|
||||
payload: {
|
||||
method: "session/prompt",
|
||||
params: {
|
||||
|
|
@ -220,8 +220,8 @@ class MockWorkbenchStore implements TaskWorkbenchClient {
|
|||
branch: newBranch,
|
||||
status: "running",
|
||||
updatedAtMs: startedAtMs,
|
||||
tabs: currentTask.tabs.map((candidate) =>
|
||||
candidate.id === input.tabId
|
||||
sessions: currentTask.sessions.map((candidate) =>
|
||||
candidate.id === input.sessionId
|
||||
? {
|
||||
...candidate,
|
||||
created: true,
|
||||
|
|
@ -236,20 +236,20 @@ class MockWorkbenchStore implements TaskWorkbenchClient {
|
|||
};
|
||||
});
|
||||
|
||||
const existingTimer = this.pendingTimers.get(input.tabId);
|
||||
const existingTimer = this.pendingTimers.get(input.sessionId);
|
||||
if (existingTimer) {
|
||||
clearTimeout(existingTimer);
|
||||
}
|
||||
|
||||
const timer = setTimeout(() => {
|
||||
const task = this.requireTask(input.taskId);
|
||||
const replyTab = this.requireTab(task, input.tabId);
|
||||
this.requireSession(task, input.sessionId);
|
||||
const completedAtMs = nowMs();
|
||||
const replyEvent = buildTranscriptEvent({
|
||||
sessionId: input.tabId,
|
||||
sessionId: input.sessionId,
|
||||
sender: "agent",
|
||||
createdAt: completedAtMs,
|
||||
eventIndex: candidateEventIndex(task, input.tabId),
|
||||
eventIndex: candidateEventIndex(task, input.sessionId),
|
||||
payload: {
|
||||
result: {
|
||||
text: randomReply(),
|
||||
|
|
@ -259,8 +259,8 @@ class MockWorkbenchStore implements TaskWorkbenchClient {
|
|||
});
|
||||
|
||||
this.updateTask(input.taskId, (currentTask) => {
|
||||
const updatedTabs = currentTask.tabs.map((candidate) => {
|
||||
if (candidate.id !== input.tabId) {
|
||||
const updatedTabs = currentTask.sessions.map((candidate) => {
|
||||
if (candidate.id !== input.sessionId) {
|
||||
return candidate;
|
||||
}
|
||||
|
||||
|
|
@ -277,35 +277,35 @@ class MockWorkbenchStore implements TaskWorkbenchClient {
|
|||
return {
|
||||
...currentTask,
|
||||
updatedAtMs: completedAtMs,
|
||||
tabs: updatedTabs,
|
||||
sessions: updatedTabs,
|
||||
status: currentTask.status === "archived" ? "archived" : anyRunning ? "running" : "idle",
|
||||
};
|
||||
});
|
||||
|
||||
this.pendingTimers.delete(input.tabId);
|
||||
this.pendingTimers.delete(input.sessionId);
|
||||
}, 2_500);
|
||||
|
||||
this.pendingTimers.set(input.tabId, timer);
|
||||
this.pendingTimers.set(input.sessionId, timer);
|
||||
}
|
||||
|
||||
async stopAgent(input: TaskWorkbenchTabInput): Promise<void> {
|
||||
this.assertTab(input.taskId, input.tabId);
|
||||
const existing = this.pendingTimers.get(input.tabId);
|
||||
async stopAgent(input: TaskWorkbenchSessionInput): Promise<void> {
|
||||
this.assertSession(input.taskId, input.sessionId);
|
||||
const existing = this.pendingTimers.get(input.sessionId);
|
||||
if (existing) {
|
||||
clearTimeout(existing);
|
||||
this.pendingTimers.delete(input.tabId);
|
||||
this.pendingTimers.delete(input.sessionId);
|
||||
}
|
||||
|
||||
this.updateTask(input.taskId, (currentTask) => {
|
||||
const updatedTabs = currentTask.tabs.map((candidate) =>
|
||||
candidate.id === input.tabId ? { ...candidate, status: "idle" as const, thinkingSinceMs: null } : candidate,
|
||||
const updatedTabs = currentTask.sessions.map((candidate) =>
|
||||
candidate.id === input.sessionId ? { ...candidate, status: "idle" as const, thinkingSinceMs: null } : candidate,
|
||||
);
|
||||
const anyRunning = updatedTabs.some((candidate) => candidate.status === "running");
|
||||
|
||||
return {
|
||||
...currentTask,
|
||||
updatedAtMs: nowMs(),
|
||||
tabs: updatedTabs,
|
||||
sessions: updatedTabs,
|
||||
status: currentTask.status === "archived" ? "archived" : anyRunning ? "running" : "idle",
|
||||
};
|
||||
});
|
||||
|
|
@ -314,40 +314,42 @@ class MockWorkbenchStore implements TaskWorkbenchClient {
|
|||
async setSessionUnread(input: TaskWorkbenchSetSessionUnreadInput): Promise<void> {
|
||||
this.updateTask(input.taskId, (currentTask) => ({
|
||||
...currentTask,
|
||||
tabs: currentTask.tabs.map((candidate) => (candidate.id === input.tabId ? { ...candidate, unread: input.unread } : candidate)),
|
||||
sessions: currentTask.sessions.map((candidate) => (candidate.id === input.sessionId ? { ...candidate, unread: input.unread } : candidate)),
|
||||
}));
|
||||
}
|
||||
|
||||
async renameSession(input: TaskWorkbenchRenameSessionInput): Promise<void> {
|
||||
const title = input.title.trim();
|
||||
if (!title) {
|
||||
throw new Error(`Cannot rename session ${input.tabId} to an empty title`);
|
||||
throw new Error(`Cannot rename session ${input.sessionId} to an empty title`);
|
||||
}
|
||||
this.updateTask(input.taskId, (currentTask) => ({
|
||||
...currentTask,
|
||||
tabs: currentTask.tabs.map((candidate) => (candidate.id === input.tabId ? { ...candidate, sessionName: title } : candidate)),
|
||||
sessions: currentTask.sessions.map((candidate) => (candidate.id === input.sessionId ? { ...candidate, sessionName: title } : candidate)),
|
||||
}));
|
||||
}
|
||||
|
||||
async closeTab(input: TaskWorkbenchTabInput): Promise<void> {
|
||||
async closeSession(input: TaskWorkbenchSessionInput): Promise<void> {
|
||||
this.updateTask(input.taskId, (currentTask) => {
|
||||
if (currentTask.tabs.length <= 1) {
|
||||
if (currentTask.sessions.length <= 1) {
|
||||
return currentTask;
|
||||
}
|
||||
|
||||
return {
|
||||
...currentTask,
|
||||
tabs: currentTask.tabs.filter((candidate) => candidate.id !== input.tabId),
|
||||
sessions: currentTask.sessions.filter((candidate) => candidate.id !== input.sessionId),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async addTab(input: TaskWorkbenchSelectInput): Promise<TaskWorkbenchAddTabResponse> {
|
||||
async addSession(input: TaskWorkbenchSelectInput): Promise<TaskWorkbenchAddSessionResponse> {
|
||||
this.assertTask(input.taskId);
|
||||
const nextTab: AgentTab = {
|
||||
id: uid(),
|
||||
sessionId: null,
|
||||
sessionName: `Session ${this.requireTask(input.taskId).tabs.length + 1}`,
|
||||
const nextSessionId = uid();
|
||||
const nextSession: AgentSession = {
|
||||
id: nextSessionId,
|
||||
sessionId: nextSessionId,
|
||||
sandboxSessionId: null,
|
||||
sessionName: `Session ${this.requireTask(input.taskId).sessions.length + 1}`,
|
||||
agent: "Claude",
|
||||
model: "claude-sonnet-4",
|
||||
status: "idle",
|
||||
|
|
@ -361,9 +363,9 @@ class MockWorkbenchStore implements TaskWorkbenchClient {
|
|||
this.updateTask(input.taskId, (currentTask) => ({
|
||||
...currentTask,
|
||||
updatedAtMs: nowMs(),
|
||||
tabs: [...currentTask.tabs, nextTab],
|
||||
sessions: [...currentTask.sessions, nextSession],
|
||||
}));
|
||||
return { tabId: nextTab.id };
|
||||
return { sessionId: nextSession.id };
|
||||
}
|
||||
|
||||
async changeModel(input: TaskWorkbenchChangeModelInput): Promise<void> {
|
||||
|
|
@ -374,8 +376,8 @@ class MockWorkbenchStore implements TaskWorkbenchClient {
|
|||
|
||||
this.updateTask(input.taskId, (currentTask) => ({
|
||||
...currentTask,
|
||||
tabs: currentTask.tabs.map((candidate) =>
|
||||
candidate.id === input.tabId ? { ...candidate, model: input.model, agent: providerAgent(group.provider) } : candidate,
|
||||
sessions: currentTask.sessions.map((candidate) =>
|
||||
candidate.id === input.sessionId ? { ...candidate, model: input.model, agent: providerAgent(group.provider) } : candidate,
|
||||
),
|
||||
}));
|
||||
}
|
||||
|
|
@ -384,7 +386,7 @@ class MockWorkbenchStore implements TaskWorkbenchClient {
|
|||
const nextSnapshot = updater(this.snapshot);
|
||||
this.snapshot = {
|
||||
...nextSnapshot,
|
||||
projects: groupWorkbenchProjects(nextSnapshot.repos, nextSnapshot.tasks),
|
||||
repositories: groupWorkbenchRepositories(nextSnapshot.repos, nextSnapshot.tasks),
|
||||
};
|
||||
this.notify();
|
||||
}
|
||||
|
|
@ -407,9 +409,9 @@ class MockWorkbenchStore implements TaskWorkbenchClient {
|
|||
this.requireTask(taskId);
|
||||
}
|
||||
|
||||
private assertTab(taskId: string, tabId: string): void {
|
||||
private assertSession(taskId: string, sessionId: string): void {
|
||||
const task = this.requireTask(taskId);
|
||||
this.requireTab(task, tabId);
|
||||
this.requireSession(task, sessionId);
|
||||
}
|
||||
|
||||
private requireTask(taskId: string): Task {
|
||||
|
|
@ -420,18 +422,18 @@ class MockWorkbenchStore implements TaskWorkbenchClient {
|
|||
return task;
|
||||
}
|
||||
|
||||
private requireTab(task: Task, tabId: string): AgentTab {
|
||||
const tab = task.tabs.find((candidate) => candidate.id === tabId);
|
||||
if (!tab) {
|
||||
throw new Error(`Unable to find mock tab ${tabId} in task ${task.id}`);
|
||||
private requireSession(task: Task, sessionId: string): AgentSession {
|
||||
const session = task.sessions.find((candidate) => candidate.id === sessionId);
|
||||
if (!session) {
|
||||
throw new Error(`Unable to find mock session ${sessionId} in task ${task.id}`);
|
||||
}
|
||||
return tab;
|
||||
return session;
|
||||
}
|
||||
}
|
||||
|
||||
function candidateEventIndex(task: Task, tabId: string): number {
|
||||
const tab = task.tabs.find((candidate) => candidate.id === tabId);
|
||||
return (tab?.transcript.length ?? 0) + 1;
|
||||
function candidateEventIndex(task: Task, sessionId: string): number {
|
||||
const session = task.sessions.find((candidate) => candidate.id === sessionId);
|
||||
return (session?.transcript.length ?? 0) + 1;
|
||||
}
|
||||
|
||||
let sharedMockWorkbenchClient: TaskWorkbenchClient | null = null;
|
||||
|
|
|
|||
|
|
@ -104,8 +104,8 @@ class RemoteFoundryAppStore implements FoundryAppClient {
|
|||
await this.backend.reconnectAppGithub(organizationId);
|
||||
}
|
||||
|
||||
async recordSeatUsage(workspaceId: string): Promise<void> {
|
||||
this.snapshot = await this.backend.recordAppSeatUsage(workspaceId);
|
||||
async recordSeatUsage(organizationId: string): Promise<void> {
|
||||
this.snapshot = await this.backend.recordAppSeatUsage(organizationId);
|
||||
this.notify();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import type {
|
||||
TaskWorkbenchAddTabResponse,
|
||||
TaskWorkbenchAddSessionResponse,
|
||||
TaskWorkbenchChangeModelInput,
|
||||
TaskWorkbenchCreateTaskInput,
|
||||
TaskWorkbenchCreateTaskResponse,
|
||||
|
|
@ -10,21 +10,21 @@ import type {
|
|||
TaskWorkbenchSetSessionUnreadInput,
|
||||
TaskWorkbenchSendMessageInput,
|
||||
TaskWorkbenchSnapshot,
|
||||
TaskWorkbenchTabInput,
|
||||
TaskWorkbenchSessionInput,
|
||||
TaskWorkbenchUpdateDraftInput,
|
||||
} from "@sandbox-agent/foundry-shared";
|
||||
import type { BackendClient } from "../backend-client.js";
|
||||
import { groupWorkbenchProjects } from "../workbench-model.js";
|
||||
import { groupWorkbenchRepositories } from "../workbench-model.js";
|
||||
import type { TaskWorkbenchClient } from "../workbench-client.js";
|
||||
|
||||
export interface RemoteWorkbenchClientOptions {
|
||||
backend: BackendClient;
|
||||
workspaceId: string;
|
||||
organizationId: string;
|
||||
}
|
||||
|
||||
class RemoteWorkbenchStore implements TaskWorkbenchClient {
|
||||
private readonly backend: BackendClient;
|
||||
private readonly workspaceId: string;
|
||||
private readonly organizationId: string;
|
||||
private snapshot: TaskWorkbenchSnapshot;
|
||||
private readonly listeners = new Set<() => void>();
|
||||
private unsubscribeWorkbench: (() => void) | null = null;
|
||||
|
|
@ -33,11 +33,11 @@ class RemoteWorkbenchStore implements TaskWorkbenchClient {
|
|||
|
||||
constructor(options: RemoteWorkbenchClientOptions) {
|
||||
this.backend = options.backend;
|
||||
this.workspaceId = options.workspaceId;
|
||||
this.organizationId = options.organizationId;
|
||||
this.snapshot = {
|
||||
workspaceId: options.workspaceId,
|
||||
organizationId: options.organizationId,
|
||||
repos: [],
|
||||
projects: [],
|
||||
repositories: [],
|
||||
tasks: [],
|
||||
};
|
||||
}
|
||||
|
|
@ -63,86 +63,86 @@ class RemoteWorkbenchStore implements TaskWorkbenchClient {
|
|||
}
|
||||
|
||||
async createTask(input: TaskWorkbenchCreateTaskInput): Promise<TaskWorkbenchCreateTaskResponse> {
|
||||
const created = await this.backend.createWorkbenchTask(this.workspaceId, input);
|
||||
const created = await this.backend.createWorkbenchTask(this.organizationId, input);
|
||||
await this.refresh();
|
||||
return created;
|
||||
}
|
||||
|
||||
async markTaskUnread(input: TaskWorkbenchSelectInput): Promise<void> {
|
||||
await this.backend.markWorkbenchUnread(this.workspaceId, input);
|
||||
await this.backend.markWorkbenchUnread(this.organizationId, input);
|
||||
await this.refresh();
|
||||
}
|
||||
|
||||
async renameTask(input: TaskWorkbenchRenameInput): Promise<void> {
|
||||
await this.backend.renameWorkbenchTask(this.workspaceId, input);
|
||||
await this.backend.renameWorkbenchTask(this.organizationId, input);
|
||||
await this.refresh();
|
||||
}
|
||||
|
||||
async renameBranch(input: TaskWorkbenchRenameInput): Promise<void> {
|
||||
await this.backend.renameWorkbenchBranch(this.workspaceId, input);
|
||||
await this.backend.renameWorkbenchBranch(this.organizationId, input);
|
||||
await this.refresh();
|
||||
}
|
||||
|
||||
async archiveTask(input: TaskWorkbenchSelectInput): Promise<void> {
|
||||
await this.backend.runAction(this.workspaceId, input.taskId, "archive");
|
||||
await this.backend.runAction(this.organizationId, input.taskId, "archive");
|
||||
await this.refresh();
|
||||
}
|
||||
|
||||
async publishPr(input: TaskWorkbenchSelectInput): Promise<void> {
|
||||
await this.backend.publishWorkbenchPr(this.workspaceId, input);
|
||||
await this.backend.publishWorkbenchPr(this.organizationId, input);
|
||||
await this.refresh();
|
||||
}
|
||||
|
||||
async revertFile(input: TaskWorkbenchDiffInput): Promise<void> {
|
||||
await this.backend.revertWorkbenchFile(this.workspaceId, input);
|
||||
await this.backend.revertWorkbenchFile(this.organizationId, input);
|
||||
await this.refresh();
|
||||
}
|
||||
|
||||
async updateDraft(input: TaskWorkbenchUpdateDraftInput): Promise<void> {
|
||||
await this.backend.updateWorkbenchDraft(this.workspaceId, input);
|
||||
await this.backend.updateWorkbenchDraft(this.organizationId, input);
|
||||
// Skip refresh — the server broadcast will trigger it, and the frontend
|
||||
// holds local draft state to avoid the round-trip overwriting user input.
|
||||
}
|
||||
|
||||
async sendMessage(input: TaskWorkbenchSendMessageInput): Promise<void> {
|
||||
await this.backend.sendWorkbenchMessage(this.workspaceId, input);
|
||||
await this.backend.sendWorkbenchMessage(this.organizationId, input);
|
||||
await this.refresh();
|
||||
}
|
||||
|
||||
async stopAgent(input: TaskWorkbenchTabInput): Promise<void> {
|
||||
await this.backend.stopWorkbenchSession(this.workspaceId, input);
|
||||
async stopAgent(input: TaskWorkbenchSessionInput): Promise<void> {
|
||||
await this.backend.stopWorkbenchSession(this.organizationId, input);
|
||||
await this.refresh();
|
||||
}
|
||||
|
||||
async setSessionUnread(input: TaskWorkbenchSetSessionUnreadInput): Promise<void> {
|
||||
await this.backend.setWorkbenchSessionUnread(this.workspaceId, input);
|
||||
await this.backend.setWorkbenchSessionUnread(this.organizationId, input);
|
||||
await this.refresh();
|
||||
}
|
||||
|
||||
async renameSession(input: TaskWorkbenchRenameSessionInput): Promise<void> {
|
||||
await this.backend.renameWorkbenchSession(this.workspaceId, input);
|
||||
await this.backend.renameWorkbenchSession(this.organizationId, input);
|
||||
await this.refresh();
|
||||
}
|
||||
|
||||
async closeTab(input: TaskWorkbenchTabInput): Promise<void> {
|
||||
await this.backend.closeWorkbenchSession(this.workspaceId, input);
|
||||
async closeSession(input: TaskWorkbenchSessionInput): Promise<void> {
|
||||
await this.backend.closeWorkbenchSession(this.organizationId, input);
|
||||
await this.refresh();
|
||||
}
|
||||
|
||||
async addTab(input: TaskWorkbenchSelectInput): Promise<TaskWorkbenchAddTabResponse> {
|
||||
const created = await this.backend.createWorkbenchSession(this.workspaceId, input);
|
||||
async addSession(input: TaskWorkbenchSelectInput): Promise<TaskWorkbenchAddSessionResponse> {
|
||||
const created = await this.backend.createWorkbenchSession(this.organizationId, input);
|
||||
await this.refresh();
|
||||
return created;
|
||||
}
|
||||
|
||||
async changeModel(input: TaskWorkbenchChangeModelInput): Promise<void> {
|
||||
await this.backend.changeWorkbenchModel(this.workspaceId, input);
|
||||
await this.backend.changeWorkbenchModel(this.organizationId, input);
|
||||
await this.refresh();
|
||||
}
|
||||
|
||||
private ensureStarted(): void {
|
||||
if (!this.unsubscribeWorkbench) {
|
||||
this.unsubscribeWorkbench = this.backend.subscribeWorkbench(this.workspaceId, () => {
|
||||
this.unsubscribeWorkbench = this.backend.subscribeWorkbench(this.organizationId, () => {
|
||||
void this.refresh().catch(() => {
|
||||
this.scheduleRefreshRetry();
|
||||
});
|
||||
|
|
@ -173,14 +173,14 @@ class RemoteWorkbenchStore implements TaskWorkbenchClient {
|
|||
}
|
||||
|
||||
this.refreshPromise = (async () => {
|
||||
const nextSnapshot = await this.backend.getWorkbench(this.workspaceId);
|
||||
const nextSnapshot = await this.backend.getWorkbench(this.organizationId);
|
||||
if (this.refreshRetryTimeout) {
|
||||
clearTimeout(this.refreshRetryTimeout);
|
||||
this.refreshRetryTimeout = null;
|
||||
}
|
||||
this.snapshot = {
|
||||
...nextSnapshot,
|
||||
projects: nextSnapshot.projects ?? groupWorkbenchProjects(nextSnapshot.repos, nextSnapshot.tasks),
|
||||
repositories: nextSnapshot.repositories ?? groupWorkbenchRepositories(nextSnapshot.repos, nextSnapshot.tasks),
|
||||
};
|
||||
for (const listener of [...this.listeners]) {
|
||||
listener();
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import type { TopicData, TopicKey, TopicParams } from "./topics.js";
|
|||
|
||||
export type TopicStatus = "loading" | "connected" | "error";
|
||||
|
||||
export interface DebugInterestTopic {
|
||||
export interface DebugSubscriptionTopic {
|
||||
topicKey: TopicKey;
|
||||
cacheKey: string;
|
||||
listenerCount: number;
|
||||
|
|
@ -17,17 +17,17 @@ export interface TopicState<K extends TopicKey> {
|
|||
}
|
||||
|
||||
/**
|
||||
* The InterestManager owns all realtime actor connections and cached state.
|
||||
* The SubscriptionManager owns all realtime actor connections and cached state.
|
||||
*
|
||||
* Multiple subscribers to the same topic share one connection and one cache
|
||||
* entry. After the last subscriber leaves, a short grace period keeps the
|
||||
* connection warm so navigation does not thrash actor connections.
|
||||
*/
|
||||
export interface InterestManager {
|
||||
export interface SubscriptionManager {
|
||||
subscribe<K extends TopicKey>(topicKey: K, params: TopicParams<K>, listener: () => void): () => void;
|
||||
getSnapshot<K extends TopicKey>(topicKey: K, params: TopicParams<K>): TopicData<K> | undefined;
|
||||
getStatus<K extends TopicKey>(topicKey: K, params: TopicParams<K>): TopicStatus;
|
||||
getError<K extends TopicKey>(topicKey: K, params: TopicParams<K>): Error | null;
|
||||
listDebugTopics(): DebugInterestTopic[];
|
||||
listDebugTopics(): DebugSubscriptionTopic[];
|
||||
dispose(): void;
|
||||
}
|
||||
12
foundry/packages/client/src/subscription/mock-manager.ts
Normal file
12
foundry/packages/client/src/subscription/mock-manager.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import { createMockBackendClient } from "../mock/backend-client.js";
|
||||
import { RemoteSubscriptionManager } from "./remote-manager.js";
|
||||
|
||||
/**
|
||||
* Mock implementation shares the same subscription-manager harness as the remote
|
||||
* path, but uses the in-memory mock backend that synthesizes actor events.
|
||||
*/
|
||||
export class MockSubscriptionManager extends RemoteSubscriptionManager {
|
||||
constructor() {
|
||||
super(createMockBackendClient());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +1,14 @@
|
|||
import type { BackendClient } from "../backend-client.js";
|
||||
import type { DebugInterestTopic, InterestManager, TopicStatus } from "./manager.js";
|
||||
import type { DebugSubscriptionTopic, SubscriptionManager, TopicStatus } from "./manager.js";
|
||||
import { topicDefinitions, type TopicData, type TopicDefinition, type TopicKey, type TopicParams } from "./topics.js";
|
||||
|
||||
const GRACE_PERIOD_MS = 30_000;
|
||||
|
||||
/**
|
||||
* Remote implementation of InterestManager.
|
||||
* Remote implementation of SubscriptionManager.
|
||||
* Each cache entry owns one actor connection plus one materialized snapshot.
|
||||
*/
|
||||
export class RemoteInterestManager implements InterestManager {
|
||||
export class RemoteSubscriptionManager implements SubscriptionManager {
|
||||
private entries = new Map<string, TopicEntry<any, any, any>>();
|
||||
|
||||
constructor(private readonly backend: BackendClient) {}
|
||||
|
|
@ -53,7 +53,7 @@ export class RemoteInterestManager implements InterestManager {
|
|||
return this.entries.get((topicDefinitions[topicKey] as any).key(params))?.error ?? null;
|
||||
}
|
||||
|
||||
listDebugTopics(): DebugInterestTopic[] {
|
||||
listDebugTopics(): DebugSubscriptionTopic[] {
|
||||
return [...this.entries.values()]
|
||||
.filter((entry) => entry.listenerCount > 0)
|
||||
.map((entry) => entry.getDebugTopic())
|
||||
|
|
@ -91,7 +91,7 @@ class TopicEntry<TData, TParams, TEvent> {
|
|||
private readonly params: TParams,
|
||||
) {}
|
||||
|
||||
getDebugTopic(): DebugInterestTopic {
|
||||
getDebugTopic(): DebugSubscriptionTopic {
|
||||
return {
|
||||
topicKey: this.topicKey,
|
||||
cacheKey: this.cacheKey,
|
||||
|
|
@ -1,19 +1,19 @@
|
|||
import type {
|
||||
AppEvent,
|
||||
FoundryAppSnapshot,
|
||||
ProviderId,
|
||||
SandboxProviderId,
|
||||
SandboxProcessesEvent,
|
||||
SessionEvent,
|
||||
TaskEvent,
|
||||
WorkbenchSessionDetail,
|
||||
WorkbenchTaskDetail,
|
||||
WorkspaceEvent,
|
||||
WorkspaceSummarySnapshot,
|
||||
OrganizationEvent,
|
||||
OrganizationSummarySnapshot,
|
||||
} from "@sandbox-agent/foundry-shared";
|
||||
import type { ActorConn, BackendClient, SandboxProcessRecord } from "../backend-client.js";
|
||||
|
||||
/**
|
||||
* Topic definitions for the interest manager.
|
||||
* Topic definitions for the subscription manager.
|
||||
*
|
||||
* Each topic describes one actor connection plus one materialized read model.
|
||||
* Events always carry full replacement payloads for the changed entity so the
|
||||
|
|
@ -28,23 +28,23 @@ export interface TopicDefinition<TData, TParams, TEvent> {
|
|||
}
|
||||
|
||||
export interface AppTopicParams {}
|
||||
export interface WorkspaceTopicParams {
|
||||
workspaceId: string;
|
||||
export interface OrganizationTopicParams {
|
||||
organizationId: string;
|
||||
}
|
||||
export interface TaskTopicParams {
|
||||
workspaceId: string;
|
||||
organizationId: string;
|
||||
repoId: string;
|
||||
taskId: string;
|
||||
}
|
||||
export interface SessionTopicParams {
|
||||
workspaceId: string;
|
||||
organizationId: string;
|
||||
repoId: string;
|
||||
taskId: string;
|
||||
sessionId: string;
|
||||
}
|
||||
export interface SandboxProcessesTopicParams {
|
||||
workspaceId: string;
|
||||
providerId: ProviderId;
|
||||
organizationId: string;
|
||||
sandboxProviderId: SandboxProviderId;
|
||||
sandboxId: string;
|
||||
}
|
||||
|
||||
|
|
@ -62,17 +62,17 @@ export const topicDefinitions = {
|
|||
app: {
|
||||
key: () => "app",
|
||||
event: "appUpdated",
|
||||
connect: (backend: BackendClient, _params: AppTopicParams) => backend.connectWorkspace("app"),
|
||||
connect: (backend: BackendClient, _params: AppTopicParams) => backend.connectOrganization("app"),
|
||||
fetchInitial: (backend: BackendClient, _params: AppTopicParams) => backend.getAppSnapshot(),
|
||||
applyEvent: (_current: FoundryAppSnapshot, event: AppEvent) => event.snapshot,
|
||||
} satisfies TopicDefinition<FoundryAppSnapshot, AppTopicParams, AppEvent>,
|
||||
|
||||
workspace: {
|
||||
key: (params: WorkspaceTopicParams) => `workspace:${params.workspaceId}`,
|
||||
event: "workspaceUpdated",
|
||||
connect: (backend: BackendClient, params: WorkspaceTopicParams) => backend.connectWorkspace(params.workspaceId),
|
||||
fetchInitial: (backend: BackendClient, params: WorkspaceTopicParams) => backend.getWorkspaceSummary(params.workspaceId),
|
||||
applyEvent: (current: WorkspaceSummarySnapshot, event: WorkspaceEvent) => {
|
||||
organization: {
|
||||
key: (params: OrganizationTopicParams) => `organization:${params.organizationId}`,
|
||||
event: "organizationUpdated",
|
||||
connect: (backend: BackendClient, params: OrganizationTopicParams) => backend.connectOrganization(params.organizationId),
|
||||
fetchInitial: (backend: BackendClient, params: OrganizationTopicParams) => backend.getOrganizationSummary(params.organizationId),
|
||||
applyEvent: (current: OrganizationSummarySnapshot, event: OrganizationEvent) => {
|
||||
switch (event.type) {
|
||||
case "taskSummaryUpdated":
|
||||
return {
|
||||
|
|
@ -107,22 +107,22 @@ export const topicDefinitions = {
|
|||
};
|
||||
}
|
||||
},
|
||||
} satisfies TopicDefinition<WorkspaceSummarySnapshot, WorkspaceTopicParams, WorkspaceEvent>,
|
||||
} satisfies TopicDefinition<OrganizationSummarySnapshot, OrganizationTopicParams, OrganizationEvent>,
|
||||
|
||||
task: {
|
||||
key: (params: TaskTopicParams) => `task:${params.workspaceId}:${params.taskId}`,
|
||||
key: (params: TaskTopicParams) => `task:${params.organizationId}:${params.taskId}`,
|
||||
event: "taskUpdated",
|
||||
connect: (backend: BackendClient, params: TaskTopicParams) => backend.connectTask(params.workspaceId, params.repoId, params.taskId),
|
||||
fetchInitial: (backend: BackendClient, params: TaskTopicParams) => backend.getTaskDetail(params.workspaceId, params.repoId, params.taskId),
|
||||
connect: (backend: BackendClient, params: TaskTopicParams) => backend.connectTask(params.organizationId, params.repoId, params.taskId),
|
||||
fetchInitial: (backend: BackendClient, params: TaskTopicParams) => backend.getTaskDetail(params.organizationId, params.repoId, params.taskId),
|
||||
applyEvent: (_current: WorkbenchTaskDetail, event: TaskEvent) => event.detail,
|
||||
} satisfies TopicDefinition<WorkbenchTaskDetail, TaskTopicParams, TaskEvent>,
|
||||
|
||||
session: {
|
||||
key: (params: SessionTopicParams) => `session:${params.workspaceId}:${params.taskId}:${params.sessionId}`,
|
||||
key: (params: SessionTopicParams) => `session:${params.organizationId}:${params.taskId}:${params.sessionId}`,
|
||||
event: "sessionUpdated",
|
||||
connect: (backend: BackendClient, params: SessionTopicParams) => backend.connectTask(params.workspaceId, params.repoId, params.taskId),
|
||||
connect: (backend: BackendClient, params: SessionTopicParams) => backend.connectTask(params.organizationId, params.repoId, params.taskId),
|
||||
fetchInitial: (backend: BackendClient, params: SessionTopicParams) =>
|
||||
backend.getSessionDetail(params.workspaceId, params.repoId, params.taskId, params.sessionId),
|
||||
backend.getSessionDetail(params.organizationId, params.repoId, params.taskId, params.sessionId),
|
||||
applyEvent: (current: WorkbenchSessionDetail, event: SessionEvent) => {
|
||||
if (event.session.sessionId !== current.sessionId) {
|
||||
return current;
|
||||
|
|
@ -132,11 +132,12 @@ export const topicDefinitions = {
|
|||
} satisfies TopicDefinition<WorkbenchSessionDetail, SessionTopicParams, SessionEvent>,
|
||||
|
||||
sandboxProcesses: {
|
||||
key: (params: SandboxProcessesTopicParams) => `sandbox:${params.workspaceId}:${params.providerId}:${params.sandboxId}`,
|
||||
key: (params: SandboxProcessesTopicParams) => `sandbox:${params.organizationId}:${params.sandboxProviderId}:${params.sandboxId}`,
|
||||
event: "processesUpdated",
|
||||
connect: (backend: BackendClient, params: SandboxProcessesTopicParams) => backend.connectSandbox(params.workspaceId, params.providerId, params.sandboxId),
|
||||
connect: (backend: BackendClient, params: SandboxProcessesTopicParams) =>
|
||||
backend.connectSandbox(params.organizationId, params.sandboxProviderId, params.sandboxId),
|
||||
fetchInitial: async (backend: BackendClient, params: SandboxProcessesTopicParams) =>
|
||||
(await backend.listSandboxProcesses(params.workspaceId, params.providerId, params.sandboxId)).processes,
|
||||
(await backend.listSandboxProcesses(params.organizationId, params.sandboxProviderId, params.sandboxId)).processes,
|
||||
applyEvent: (_current: SandboxProcessRecord[], event: SandboxProcessesEvent) => event.processes,
|
||||
} satisfies TopicDefinition<SandboxProcessRecord[], SandboxProcessesTopicParams, SandboxProcessesEvent>,
|
||||
} as const;
|
||||
|
|
@ -1,14 +1,14 @@
|
|||
import { useMemo, useRef, useSyncExternalStore } from "react";
|
||||
import type { InterestManager, TopicState } from "./manager.js";
|
||||
import type { SubscriptionManager, TopicState } from "./manager.js";
|
||||
import { topicDefinitions, type TopicKey, type TopicParams } from "./topics.js";
|
||||
|
||||
/**
|
||||
* React bridge for the interest manager.
|
||||
* React bridge for the subscription manager.
|
||||
*
|
||||
* `null` params disable the subscription entirely, which is how screens express
|
||||
* conditional interest in task/session/sandbox topics.
|
||||
* conditional subscription in task/session/sandbox topics.
|
||||
*/
|
||||
export function useInterest<K extends TopicKey>(manager: InterestManager, topicKey: K, params: TopicParams<K> | null): TopicState<K> {
|
||||
export function useSubscription<K extends TopicKey>(manager: SubscriptionManager, topicKey: K, params: TopicParams<K> | null): TopicState<K> {
|
||||
const paramsKey = params ? (topicDefinitions[topicKey] as any).key(params) : null;
|
||||
const paramsRef = useRef<TopicParams<K> | null>(params);
|
||||
paramsRef.current = params;
|
||||
|
|
@ -87,7 +87,7 @@ export function summarizeTasks(rows: TaskRecord[]): TaskSummary {
|
|||
|
||||
for (const row of rows) {
|
||||
byStatus[groupTaskStatus(row.status)] += 1;
|
||||
byProvider[row.providerId] = (byProvider[row.providerId] ?? 0) + 1;
|
||||
byProvider[row.sandboxProviderId] = (byProvider[row.sandboxProviderId] ?? 0) + 1;
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import type {
|
||||
TaskWorkbenchAddTabResponse,
|
||||
TaskWorkbenchAddSessionResponse,
|
||||
TaskWorkbenchChangeModelInput,
|
||||
TaskWorkbenchCreateTaskInput,
|
||||
TaskWorkbenchCreateTaskResponse,
|
||||
|
|
@ -10,7 +10,7 @@ import type {
|
|||
TaskWorkbenchSetSessionUnreadInput,
|
||||
TaskWorkbenchSendMessageInput,
|
||||
TaskWorkbenchSnapshot,
|
||||
TaskWorkbenchTabInput,
|
||||
TaskWorkbenchSessionInput,
|
||||
TaskWorkbenchUpdateDraftInput,
|
||||
} from "@sandbox-agent/foundry-shared";
|
||||
import type { BackendClient } from "./backend-client.js";
|
||||
|
|
@ -22,7 +22,7 @@ export type TaskWorkbenchClientMode = "mock" | "remote";
|
|||
export interface CreateTaskWorkbenchClientOptions {
|
||||
mode: TaskWorkbenchClientMode;
|
||||
backend?: BackendClient;
|
||||
workspaceId?: string;
|
||||
organizationId?: string;
|
||||
}
|
||||
|
||||
export interface TaskWorkbenchClient {
|
||||
|
|
@ -37,11 +37,11 @@ export interface TaskWorkbenchClient {
|
|||
revertFile(input: TaskWorkbenchDiffInput): Promise<void>;
|
||||
updateDraft(input: TaskWorkbenchUpdateDraftInput): Promise<void>;
|
||||
sendMessage(input: TaskWorkbenchSendMessageInput): Promise<void>;
|
||||
stopAgent(input: TaskWorkbenchTabInput): Promise<void>;
|
||||
stopAgent(input: TaskWorkbenchSessionInput): Promise<void>;
|
||||
setSessionUnread(input: TaskWorkbenchSetSessionUnreadInput): Promise<void>;
|
||||
renameSession(input: TaskWorkbenchRenameSessionInput): Promise<void>;
|
||||
closeTab(input: TaskWorkbenchTabInput): Promise<void>;
|
||||
addTab(input: TaskWorkbenchSelectInput): Promise<TaskWorkbenchAddTabResponse>;
|
||||
closeSession(input: TaskWorkbenchSessionInput): Promise<void>;
|
||||
addSession(input: TaskWorkbenchSelectInput): Promise<TaskWorkbenchAddSessionResponse>;
|
||||
changeModel(input: TaskWorkbenchChangeModelInput): Promise<void>;
|
||||
}
|
||||
|
||||
|
|
@ -53,12 +53,12 @@ export function createTaskWorkbenchClient(options: CreateTaskWorkbenchClientOpti
|
|||
if (!options.backend) {
|
||||
throw new Error("Remote task workbench client requires a backend client");
|
||||
}
|
||||
if (!options.workspaceId) {
|
||||
throw new Error("Remote task workbench client requires a workspace id");
|
||||
if (!options.organizationId) {
|
||||
throw new Error("Remote task workbench client requires a organization id");
|
||||
}
|
||||
|
||||
return createRemoteWorkbenchClient({
|
||||
backend: options.backend,
|
||||
workspaceId: options.workspaceId,
|
||||
organizationId: options.organizationId,
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import type {
|
||||
WorkbenchAgentKind as AgentKind,
|
||||
WorkbenchAgentTab as AgentTab,
|
||||
WorkbenchSession as AgentSession,
|
||||
WorkbenchDiffLineKind as DiffLineKind,
|
||||
WorkbenchFileTreeNode as FileTreeNode,
|
||||
WorkbenchTask as Task,
|
||||
|
|
@ -9,7 +9,7 @@ import type {
|
|||
WorkbenchModelGroup as ModelGroup,
|
||||
WorkbenchModelId as ModelId,
|
||||
WorkbenchParsedDiffLine as ParsedDiffLine,
|
||||
WorkbenchProjectSection,
|
||||
WorkbenchRepositorySection,
|
||||
WorkbenchRepo,
|
||||
WorkbenchTranscriptEvent as TranscriptEvent,
|
||||
} from "@sandbox-agent/foundry-shared";
|
||||
|
|
@ -186,17 +186,17 @@ function historyDetail(event: TranscriptEvent): string {
|
|||
return content || "Untitled event";
|
||||
}
|
||||
|
||||
export function buildHistoryEvents(tabs: AgentTab[]): HistoryEvent[] {
|
||||
return tabs
|
||||
.flatMap((tab) =>
|
||||
tab.transcript
|
||||
export function buildHistoryEvents(sessions: AgentSession[]): HistoryEvent[] {
|
||||
return sessions
|
||||
.flatMap((session) =>
|
||||
session.transcript
|
||||
.filter((event) => event.sender === "client")
|
||||
.map((event) => ({
|
||||
id: `history-${tab.id}-${event.id}`,
|
||||
id: `history-${session.id}-${event.id}`,
|
||||
messageId: event.id,
|
||||
preview: historyPreview(event),
|
||||
sessionName: tab.sessionName,
|
||||
tabId: tab.id,
|
||||
sessionName: session.sessionName,
|
||||
sessionId: session.id,
|
||||
createdAtMs: event.createdAt,
|
||||
detail: historyDetail(event),
|
||||
})),
|
||||
|
|
@ -316,7 +316,7 @@ export function buildInitialTasks(): Task[] {
|
|||
updatedAtMs: minutesAgo(8),
|
||||
branch: "NathanFlurry/pi-bootstrap-fix",
|
||||
pullRequest: { number: 227, status: "ready" },
|
||||
tabs: [
|
||||
sessions: [
|
||||
{
|
||||
id: "t1",
|
||||
sessionId: "t1",
|
||||
|
|
@ -485,7 +485,7 @@ export function buildInitialTasks(): Task[] {
|
|||
updatedAtMs: minutesAgo(3),
|
||||
branch: "feat/builtin-agent-skills",
|
||||
pullRequest: { number: 223, status: "draft" },
|
||||
tabs: [
|
||||
sessions: [
|
||||
{
|
||||
id: "t3",
|
||||
sessionId: "t3",
|
||||
|
|
@ -585,7 +585,7 @@ export function buildInitialTasks(): Task[] {
|
|||
updatedAtMs: minutesAgo(45),
|
||||
branch: "hooks-example",
|
||||
pullRequest: { number: 225, status: "ready" },
|
||||
tabs: [
|
||||
sessions: [
|
||||
{
|
||||
id: "t4",
|
||||
sessionId: "t4",
|
||||
|
|
@ -660,7 +660,7 @@ export function buildInitialTasks(): Task[] {
|
|||
updatedAtMs: minutesAgo(15),
|
||||
branch: "actor-reschedule-endpoint",
|
||||
pullRequest: { number: 4400, status: "ready" },
|
||||
tabs: [
|
||||
sessions: [
|
||||
{
|
||||
id: "t5",
|
||||
sessionId: "t5",
|
||||
|
|
@ -794,7 +794,7 @@ export function buildInitialTasks(): Task[] {
|
|||
updatedAtMs: minutesAgo(35),
|
||||
branch: "feat/dynamic-actors",
|
||||
pullRequest: { number: 4395, status: "draft" },
|
||||
tabs: [
|
||||
sessions: [
|
||||
{
|
||||
id: "t6",
|
||||
sessionId: "t6",
|
||||
|
|
@ -851,7 +851,7 @@ export function buildInitialTasks(): Task[] {
|
|||
updatedAtMs: minutesAgo(25),
|
||||
branch: "fix-use-full-cloud-run-pool-name",
|
||||
pullRequest: { number: 235, status: "ready" },
|
||||
tabs: [
|
||||
sessions: [
|
||||
{
|
||||
id: "t7",
|
||||
sessionId: "t7",
|
||||
|
|
@ -960,7 +960,7 @@ export function buildInitialTasks(): Task[] {
|
|||
updatedAtMs: minutesAgo(50),
|
||||
branch: "fix-guard-support-https-targets",
|
||||
pullRequest: { number: 125, status: "ready" },
|
||||
tabs: [
|
||||
sessions: [
|
||||
{
|
||||
id: "t8",
|
||||
sessionId: "t8",
|
||||
|
|
@ -1074,7 +1074,7 @@ export function buildInitialTasks(): Task[] {
|
|||
updatedAtMs: minutesAgo(2 * 24 * 60),
|
||||
branch: "chore-move-compute-gateway-to",
|
||||
pullRequest: { number: 123, status: "ready" },
|
||||
tabs: [
|
||||
sessions: [
|
||||
{
|
||||
id: "t9",
|
||||
sessionId: "t9",
|
||||
|
|
@ -1116,7 +1116,7 @@ export function buildInitialTasks(): Task[] {
|
|||
updatedAtMs: minutesAgo(90),
|
||||
branch: "fix/namespace-isolation",
|
||||
pullRequest: null,
|
||||
tabs: [
|
||||
sessions: [
|
||||
{
|
||||
id: "t10",
|
||||
sessionId: "t10",
|
||||
|
|
@ -1172,9 +1172,9 @@ export function buildInitialTasks(): Task[] {
|
|||
updatedAtMs: minutesAgo(2),
|
||||
branch: "fix/auth-middleware",
|
||||
pullRequest: null,
|
||||
tabs: [
|
||||
sessions: [
|
||||
{
|
||||
id: "status-error-tab",
|
||||
id: "status-error-session",
|
||||
sessionId: "status-error-session",
|
||||
sessionName: "Auth fix",
|
||||
agent: "Claude",
|
||||
|
|
@ -1204,10 +1204,11 @@ export function buildInitialTasks(): Task[] {
|
|||
updatedAtMs: minutesAgo(0),
|
||||
branch: null,
|
||||
pullRequest: null,
|
||||
tabs: [
|
||||
sessions: [
|
||||
{
|
||||
id: "status-prov-tab",
|
||||
sessionId: null,
|
||||
id: "status-prov-session",
|
||||
sessionId: "status-prov-session",
|
||||
sandboxSessionId: null,
|
||||
sessionName: "Session 1",
|
||||
agent: "Claude",
|
||||
model: "claude-sonnet-4",
|
||||
|
|
@ -1263,9 +1264,9 @@ export function buildInitialTasks(): Task[] {
|
|||
updatedAtMs: minutesAgo(1),
|
||||
branch: "refactor/ws-handler",
|
||||
pullRequest: null,
|
||||
tabs: [
|
||||
sessions: [
|
||||
{
|
||||
id: "status-run-tab",
|
||||
id: "status-run-session",
|
||||
sessionId: "status-run-session",
|
||||
sessionName: "WS refactor",
|
||||
agent: "Codex",
|
||||
|
|
@ -1275,7 +1276,7 @@ export function buildInitialTasks(): Task[] {
|
|||
unread: false,
|
||||
created: true,
|
||||
draft: { text: "", attachments: [], updatedAtMs: null },
|
||||
transcript: transcriptFromLegacyMessages("status-run-tab", [
|
||||
transcript: transcriptFromLegacyMessages("status-run-session", [
|
||||
{
|
||||
id: "sr1",
|
||||
role: "user",
|
||||
|
|
@ -1297,7 +1298,7 @@ export function buildInitialTasks(): Task[] {
|
|||
/**
|
||||
* Build repos list from the rivet-dev fixture data (scripts/data/rivet-dev.json).
|
||||
* Uses real public repos so the mock sidebar matches what an actual rivet-dev
|
||||
* workspace would show after a GitHub sync.
|
||||
* organization would show after a GitHub sync.
|
||||
*/
|
||||
function buildMockRepos(): WorkbenchRepo[] {
|
||||
return rivetDevFixture.repos.map((r) => ({
|
||||
|
|
@ -1314,7 +1315,7 @@ function repoIdFromFullName(fullName: string): string {
|
|||
|
||||
/**
|
||||
* Build task entries from open PR fixture data.
|
||||
* Maps to the backend's PR sync behavior (ProjectPrSyncActor) where PRs
|
||||
* Maps to the backend's PR sync behavior (RepositoryPrSyncActor) where PRs
|
||||
* appear as first-class sidebar items even without an associated task.
|
||||
* Each open PR gets a lightweight task entry so it shows in the sidebar.
|
||||
*/
|
||||
|
|
@ -1339,7 +1340,7 @@ function buildPrTasks(): Task[] {
|
|||
updatedAtMs: new Date(pr.updatedAt).getTime(),
|
||||
branch: pr.headRefName,
|
||||
pullRequest: { number: pr.number, status: pr.draft ? ("draft" as const) : ("ready" as const) },
|
||||
tabs: [],
|
||||
sessions: [],
|
||||
fileChanges: [],
|
||||
diffs: {},
|
||||
fileTree: [],
|
||||
|
|
@ -1352,15 +1353,15 @@ export function buildInitialMockLayoutViewModel(): TaskWorkbenchSnapshot {
|
|||
const repos = buildMockRepos();
|
||||
const tasks = [...buildInitialTasks(), ...buildPrTasks()];
|
||||
return {
|
||||
workspaceId: "default",
|
||||
organizationId: "default",
|
||||
repos,
|
||||
projects: groupWorkbenchProjects(repos, tasks),
|
||||
repositories: groupWorkbenchRepositories(repos, tasks),
|
||||
tasks,
|
||||
};
|
||||
}
|
||||
|
||||
export function groupWorkbenchProjects(repos: WorkbenchRepo[], tasks: Task[]): WorkbenchProjectSection[] {
|
||||
const grouped = new Map<string, WorkbenchProjectSection>();
|
||||
export function groupWorkbenchRepositories(repos: WorkbenchRepo[], tasks: Task[]): WorkbenchRepositorySection[] {
|
||||
const grouped = new Map<string, WorkbenchRepositorySection>();
|
||||
|
||||
for (const repo of repos) {
|
||||
grouped.set(repo.id, {
|
||||
|
|
@ -1385,11 +1386,11 @@ export function groupWorkbenchProjects(repos: WorkbenchRepo[], tasks: Task[]): W
|
|||
}
|
||||
|
||||
return [...grouped.values()]
|
||||
.map((project) => ({
|
||||
...project,
|
||||
tasks: [...project.tasks].sort((a, b) => b.updatedAtMs - a.updatedAtMs),
|
||||
updatedAtMs: project.tasks.length > 0 ? Math.max(...project.tasks.map((task) => task.updatedAtMs)) : project.updatedAtMs,
|
||||
.map((repository) => ({
|
||||
...repository,
|
||||
tasks: [...repository.tasks].sort((a, b) => b.updatedAtMs - a.updatedAtMs),
|
||||
updatedAtMs: repository.tasks.length > 0 ? Math.max(...repository.tasks.map((task) => task.updatedAtMs)) : repository.updatedAtMs,
|
||||
}))
|
||||
.filter((project) => project.tasks.length > 0)
|
||||
.filter((repository) => repository.tasks.length > 0)
|
||||
.sort((a, b) => b.updatedAtMs - a.updatedAtMs);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue