6b947b7593
- Remove clone_mode/branch/new_branch from frontend create session flow. - Add workspace picker to CreateSessionForm; auto-create default workspace when repo selected. - Fix tool-starter.tsx and use-start-tool.ts createInstance signatures after API change. - Remove clone mode badge from SessionCard. - Delete stale backend unit tests referencing removed clone_mode schema fields. - Update OpenSpec working-copies tasks and mark change completed. - Regenerate project maps. Quality gates: npm run typecheck, npm run lint, npm test -- --run (82 passed), python3 -m py_compile on changed backend files.
62 lines
1.4 KiB
TypeScript
62 lines
1.4 KiB
TypeScript
/** Shared hook for starting a tool on a workspace. */
|
|
|
|
import { useCallback, useState } from "react";
|
|
import { createInstance, startInstance } from "../api/sessions";
|
|
import type { Workspace } from "../types/workspace";
|
|
import type { ToolInstance } from "../api/sessions";
|
|
|
|
export interface UseStartToolResult {
|
|
starting: boolean;
|
|
error: string | null;
|
|
startTool: (
|
|
workspace: Workspace,
|
|
toolTypeId: string,
|
|
displayName?: string,
|
|
configProfileId?: string,
|
|
) => Promise<ToolInstance | null>;
|
|
}
|
|
|
|
export function useStartTool(): UseStartToolResult {
|
|
const [starting, setStarting] = useState(false);
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
|
const startTool = useCallback(
|
|
async (
|
|
workspace: Workspace,
|
|
toolTypeId: string,
|
|
displayName?: string,
|
|
configProfileId?: string,
|
|
): Promise<ToolInstance | null> => {
|
|
setStarting(true);
|
|
setError(null);
|
|
try {
|
|
const instance = await createInstance(
|
|
workspace.project_id,
|
|
workspace.repo_id,
|
|
toolTypeId,
|
|
displayName || workspace.name,
|
|
workspace.id,
|
|
configProfileId,
|
|
[],
|
|
);
|
|
await startInstance(
|
|
workspace.project_id,
|
|
workspace.repo_id,
|
|
instance.id,
|
|
configProfileId,
|
|
);
|
|
return instance;
|
|
} catch (err) {
|
|
const msg = err instanceof Error ? err.message : "Failed to start tool";
|
|
setError(msg);
|
|
return null;
|
|
} finally {
|
|
setStarting(false);
|
|
}
|
|
},
|
|
[],
|
|
);
|
|
|
|
return { starting, error, startTool };
|
|
}
|