585
* session one level deeper so its own `create_session` calls are bounded too.
586
*/
587
>
export async function applyCreateSessionTool(accessor: ISessionServerToolAccessor, rawArgs: unknown, currentSession?: URI): Promise<ICreateSessionResult> {
sessionServerTools.ts
588
>
const parentDepth = currentSession ? accessor.getSessionSpawnDepth(currentSession) : 0;
589
>
if (parentDepth >= maxSessionSpawnDepth) {
590
throw new Error(`Refusing to create a session: recursion limit reached (max spawn depth ${maxSessionSpawnDepth}). This session was itself created ${parentDepth} level(s) deep.`);
591
}
593
>
const args = getCreateSessionArgs(rawArgs, sessions, accessor.getModels());
594
>
const config: IAgentCreateSessionConfig = {
595
>
workingDirectory: args.workspace,
596
>
...(args.model !== undefined ? { provider: args.model.provider, model: { id: args.model.id } } : {}),
597
>
};
598
>
const session = await accessor.createSession(config);
599
>
accessor.setSessionSpawnDepth(session, parentDepth + 1);
600
>
const chat = URI.parse(buildDefaultChatUri(session));
601
>
await accessor.startPrompt(session, chat, args.prompt);
602
>
return { session: session.toString(), chat: chat.toString(), openLink: buildOpenSessionLinkUri(session) };
603
>
}
604
605
/**