Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion apps/code/src/main/services/cloud-task/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ export const sendCommandInput = z.object({
runId: z.string(),
apiHost: z.string(),
teamId: z.number(),
method: z.enum(["user_message", "cancel", "close"]),
method: z.enum([
"user_message",
"cancel",
"close",
"permission_response",
"set_config_option",
]),
params: z.record(z.string(), z.unknown()).optional(),
});

Expand Down
31 changes: 31 additions & 0 deletions apps/code/src/main/services/cloud-task/service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { CloudTaskPermissionRequestUpdate } from "@shared/types";
import type { StoredLogEntry } from "@shared/types/session-events";
import { net } from "electron";
import { inject, injectable, preDestroy } from "inversify";
Expand Down Expand Up @@ -122,6 +123,24 @@ function isSseErrorEvent(data: unknown): data is SseErrorEventData {
);
}

interface PermissionRequestEventData {
type: "permission_request";
requestId: string;
toolCall: CloudTaskPermissionRequestUpdate["toolCall"];
options: CloudTaskPermissionRequestUpdate["options"];
}

function isPermissionRequestEvent(
data: unknown,
): data is PermissionRequestEventData {
return (
typeof data === "object" &&
data !== null &&
(data as { type?: string }).type === "permission_request" &&
typeof (data as { requestId?: string }).requestId === "string"
);
}

function createStreamStatusError(status: number): CloudTaskStreamError {
switch (status) {
case 401:
Expand Down Expand Up @@ -682,6 +701,18 @@ export class CloudTaskService extends TypedEventEmitter<CloudTaskEvents> {
return;
}

if (isPermissionRequestEvent(event.data)) {
this.emit(CloudTaskEvent.Update, {
taskId: watcher.taskId,
runId: watcher.runId,
kind: "permission_request" as const,
requestId: event.data.requestId,
toolCall: event.data.toolCall,
options: event.data.options,
});
return;
}

watcher.pendingLogEntries.push(event.data as StoredLogEntry);
if (watcher.pendingLogEntries.length >= EVENT_BATCH_MAX_SIZE) {
this.flushLogBatch(key);
Expand Down
4 changes: 4 additions & 0 deletions apps/code/src/renderer/api/posthogClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,7 @@ export class PostHogAPIClient {
runSource?: CloudRunSource;
signalReportId?: string;
githubUserToken?: string;
initialPermissionMode?: string;
},
): Promise<Task> {
const teamId = await this.getTeamId();
Expand Down Expand Up @@ -774,6 +775,9 @@ export class PostHogAPIClient {
if (options?.githubUserToken) {
body.github_user_token = options.githubUserToken;
}
if (options?.initialPermissionMode) {
body.initial_permission_mode = options.initialPermissionMode;
}

const data = await this.api.post(
`/api/projects/{project_id}/tasks/{id}/run/`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ export function useSessionConnection({
if (!cloudAuthState.projectId || !cloudAuthState.cloudRegion) return;

const runId = task.latest_run.id;
const initialMode =
typeof task.latest_run.state?.initial_permission_mode === "string"
? task.latest_run.state.initial_permission_mode
: undefined;
const cleanup = getSessionService().watchCloudTask(
task.id,
runId,
Expand All @@ -81,6 +85,7 @@ export function useSessionConnection({
queryClient.invalidateQueries({ queryKey: ["tasks"] });
},
task.latest_run?.log_url,
initialMode,
);
return cleanup;
}, [
Expand All @@ -93,6 +98,7 @@ export function useSessionConnection({
task.id,
task.latest_run?.id,
task.latest_run?.log_url,
task.latest_run?.state?.initial_permission_mode,
]);

useEffect(() => {
Expand Down
Loading
Loading