fix pi cwd resolution and super admin home dir for all pi endpoints
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -4,7 +4,7 @@ import type { PiEvent, MessageCost, Message } from '@@/api/pi/types';
|
||||
import { sessionManager } from '@@/api/pi/session-manager';
|
||||
import * as storage from '@@/api/pi/storage';
|
||||
import * as piBridge from '@@/api/pi/pi-bridge';
|
||||
import { getHomeDir } from '@@/data-path';
|
||||
import { getHomeDirForRole } from '@@/data-path';
|
||||
import { getUserSettings } from 'officerdb';
|
||||
import { logger } from '@@/api/pi/logger';
|
||||
import { sendClaudeCode, clearClaudeCodeSession } from './send-claude-code';
|
||||
@@ -21,6 +21,7 @@ type SendAndAwaitParams = {
|
||||
context: string;
|
||||
contextId: string;
|
||||
model?: string;
|
||||
role?: string;
|
||||
};
|
||||
|
||||
type SendAndAwaitResult = {
|
||||
@@ -132,7 +133,7 @@ function createDispatcher(sessionId: string): (event: PiEvent) => void {
|
||||
|
||||
async function doSend(sessionId: string, params: SendAndAwaitParams): Promise<SendAndAwaitResult> {
|
||||
const { userId, email, username, prompt, context, contextId } = params;
|
||||
const homeDir = getHomeDir(email);
|
||||
const homeDir = getHomeDirForRole(email, params.role ?? null);
|
||||
const cwd = homeDir;
|
||||
|
||||
// Resolve model: explicit param > !model override > user default > existing session > system default
|
||||
@@ -294,15 +295,16 @@ async function doSend(sessionId: string, params: SendAndAwaitParams): Promise<Se
|
||||
(async () => {
|
||||
try {
|
||||
if (!session.piProcess) {
|
||||
let spawnOptions: { sessionFile?: string; username?: string } | undefined;
|
||||
const role = params.role;
|
||||
let spawnOptions: { sessionFile?: string; username?: string; role?: string } | undefined;
|
||||
if (session.messages.length > 0) {
|
||||
await storage.saveSession(homeDir, sessionId, session.meta, session.messages);
|
||||
const hostPath = await storage.getSessionFilePath(homeDir, sessionId);
|
||||
if (hostPath) {
|
||||
spawnOptions = { sessionFile: hostPath, username };
|
||||
spawnOptions = { sessionFile: hostPath, username, role };
|
||||
}
|
||||
}
|
||||
if (!spawnOptions) spawnOptions = { username };
|
||||
if (!spawnOptions) spawnOptions = { username, role };
|
||||
|
||||
const dispatcher = createDispatcher(sessionId);
|
||||
session.piProcess = await piBridge.spawnPi(cwd, model!, userId, email, dispatcher, spawnOptions);
|
||||
|
||||
Reference in New Issue
Block a user