Skip to content

Commit 257f9fd

Browse files
committed
fix style check
1 parent 5095bda commit 257f9fd

File tree

7 files changed

+157
-55
lines changed

7 files changed

+157
-55
lines changed

ui/goose2/src/app/hooks/useAppStartup.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ export function useAppStartup() {
6161
loadProviders(),
6262
loadSessionState(),
6363
]);
64-
6564
})();
6665
}, []);
6766
}

ui/goose2/src/shared/api/acp.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import { invoke } from "@tauri-apps/api/core";
22
import { USE_DIRECT_ACP } from "./acpFeatureFlag";
33
import * as directAcp from "./acpApi";
44
import * as sessionTracker from "./acpSessionTracker";
5-
import { setActiveMessageId, clearActiveMessageId } from "./acpNotificationHandler";
5+
import {
6+
setActiveMessageId,
7+
clearActiveMessageId,
8+
} from "./acpNotificationHandler";
69
import { searchSessionsViaExports } from "./sessionSearch";
710

811
export interface AcpProvider {
@@ -42,7 +45,10 @@ export async function acpSendMessage(
4245
if (USE_DIRECT_ACP) {
4346
const { systemPrompt, personaId, images } = options;
4447

45-
const gooseSessionId = sessionTracker.getGooseSessionId(sessionId, personaId);
48+
const gooseSessionId = sessionTracker.getGooseSessionId(
49+
sessionId,
50+
personaId,
51+
);
4652
if (!gooseSessionId) {
4753
throw new Error("Session not prepared. Call acpPrepareSession first.");
4854
}
@@ -90,7 +96,12 @@ export async function acpPrepareSession(
9096
): Promise<void> {
9197
if (USE_DIRECT_ACP) {
9298
const workingDir = options.workingDir ?? "~/.goose/artifacts";
93-
await sessionTracker.prepareSession(sessionId, providerId, workingDir, options.personaId);
99+
await sessionTracker.prepareSession(
100+
sessionId,
101+
providerId,
102+
workingDir,
103+
options.personaId,
104+
);
94105
return;
95106
}
96107
const { workingDir, personaId } = options;
@@ -164,7 +175,12 @@ export async function acpLoadSession(
164175
if (USE_DIRECT_ACP) {
165176
const effectiveWorkingDir = workingDir ?? "~/.goose/artifacts";
166177
await directAcp.loadSession(gooseSessionId, effectiveWorkingDir);
167-
sessionTracker.registerSession(sessionId, gooseSessionId, "goose", effectiveWorkingDir);
178+
sessionTracker.registerSession(
179+
sessionId,
180+
gooseSessionId,
181+
"goose",
182+
effectiveWorkingDir,
183+
);
168184
return;
169185
}
170186
return invoke("acp_load_session", {
@@ -208,7 +224,10 @@ export async function acpCancelSession(
208224
personaId?: string,
209225
): Promise<boolean> {
210226
if (USE_DIRECT_ACP) {
211-
const gooseSessionId = sessionTracker.getGooseSessionId(sessionId, personaId);
227+
const gooseSessionId = sessionTracker.getGooseSessionId(
228+
sessionId,
229+
personaId,
230+
);
212231
await directAcp.cancelSession(gooseSessionId ?? sessionId);
213232
return true;
214233
}

ui/goose2/src/shared/api/acpApi.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ export async function cancelSession(sessionId: string): Promise<void> {
105105
await client.cancel({ sessionId });
106106
}
107107

108-
export async function newSession(workingDir: string): Promise<NewSessionResponse> {
108+
export async function newSession(
109+
workingDir: string,
110+
): Promise<NewSessionResponse> {
109111
const client = await getClient();
110112
return client.newSession({ cwd: workingDir, mcpServers: [] });
111113
}

ui/goose2/src/shared/api/acpConnection.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ function createClientCallbacks(): () => Client {
3636
};
3737
},
3838

39-
sessionUpdate: async (
40-
notification: SessionNotification,
41-
): Promise<void> => {
39+
sessionUpdate: async (notification: SessionNotification): Promise<void> => {
4240
if (notificationHandler) {
4341
await notificationHandler.handleSessionNotification(notification);
4442
}
@@ -49,12 +47,16 @@ function createClientCallbacks(): () => Client {
4947
function monitorConnection(client: GooseClient): void {
5048
client.closed
5149
.then(() => {
52-
console.warn("[acp] Connection closed. Will reconnect on next getClient().");
50+
console.warn(
51+
"[acp] Connection closed. Will reconnect on next getClient().",
52+
);
5353
resolvedClient = null;
5454
clientPromise = null;
5555
})
5656
.catch(() => {
57-
console.warn("[acp] Connection error. Will reconnect on next getClient().");
57+
console.warn(
58+
"[acp] Connection error. Will reconnect on next getClient().",
59+
);
5860
resolvedClient = null;
5961
clientPromise = null;
6062
});

ui/goose2/src/shared/api/acpNotificationHandler.ts

Lines changed: 70 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
1-
import type { SessionNotification, SessionUpdate } from "@agentclientprotocol/sdk";
1+
import type {
2+
SessionNotification,
3+
SessionUpdate,
4+
} from "@agentclientprotocol/sdk";
25
import { useChatStore } from "@/features/chat/stores/chatStore";
36
import { useChatSessionStore } from "@/features/chat/stores/chatSessionStore";
47
import {
58
ensureReplayBuffer,
69
getBufferedMessage,
710
findLatestUnpairedToolRequest,
811
} from "@/features/chat/hooks/replayBuffer";
9-
import type { ToolRequestContent, ToolResponseContent } from "@/shared/types/messages";
12+
import type {
13+
ToolRequestContent,
14+
ToolResponseContent,
15+
} from "@/shared/types/messages";
1016
import type { AcpNotificationHandler } from "./acpConnection";
1117
import { getLocalSessionId } from "./acpSessionTracker";
1218

1319
// Pre-set message ID for the next live stream per goose session
1420
const presetMessageIds = new Map<string, string>();
1521

16-
export function setActiveMessageId(gooseSessionId: string, messageId: string): void {
22+
export function setActiveMessageId(
23+
gooseSessionId: string,
24+
messageId: string,
25+
): void {
1726
presetMessageIds.set(gooseSessionId, messageId);
1827
}
1928

@@ -70,15 +79,23 @@ function handleReplay(sessionId: string, update: SessionUpdate): void {
7079
const messageId = update.messageId ?? crypto.randomUUID();
7180
const buffer = ensureReplayBuffer(sessionId);
7281
const existing = getBufferedMessage(sessionId, messageId);
73-
if (!existing && update.content.type === "text" && "text" in update.content) {
82+
if (
83+
!existing &&
84+
update.content.type === "text" &&
85+
"text" in update.content
86+
) {
7487
buffer.push({
7588
id: messageId,
7689
role: "user",
7790
created: Date.now(),
7891
content: [{ type: "text", text: update.content.text }],
7992
metadata: { userVisible: true, agentVisible: true },
8093
});
81-
} else if (existing && update.content.type === "text" && "text" in update.content) {
94+
} else if (
95+
existing &&
96+
update.content.type === "text" &&
97+
"text" in update.content
98+
) {
8299
const last = existing.content[existing.content.length - 1];
83100
if (last?.type === "text") {
84101
(last as { type: "text"; text: string }).text += update.content.text;
@@ -122,7 +139,10 @@ function handleReplay(sessionId: string, update: SessionUpdate): void {
122139
if (tc && tc.type === "toolRequest") {
123140
const idx = msg.content.indexOf(tc);
124141
if (idx >= 0) {
125-
msg.content[idx] = { ...tc, status: "completed" } as ToolRequestContent;
142+
msg.content[idx] = {
143+
...tc,
144+
status: "completed",
145+
} as ToolRequestContent;
126146
}
127147
}
128148
const resultText = extractToolResultText(update);
@@ -149,13 +169,22 @@ function handleReplay(sessionId: string, update: SessionUpdate): void {
149169
}
150170
}
151171

152-
function handleLive(sessionId: string, gooseSessionId: string, update: SessionUpdate): void {
172+
function handleLive(
173+
sessionId: string,
174+
gooseSessionId: string,
175+
update: SessionUpdate,
176+
): void {
153177
const store = useChatStore.getState();
154178

155179
switch (update.sessionUpdate) {
156180
case "agent_message_chunk": {
157-
const messageId = update.messageId ?? presetMessageIds.get(gooseSessionId) ?? crypto.randomUUID();
158-
const existing = store.messagesBySession[sessionId]?.find(m => m.id === messageId);
181+
const messageId =
182+
update.messageId ??
183+
presetMessageIds.get(gooseSessionId) ??
184+
crypto.randomUUID();
185+
const existing = store.messagesBySession[sessionId]?.find(
186+
(m) => m.id === messageId,
187+
);
159188

160189
if (!existing) {
161190
store.addMessage(sessionId, {
@@ -257,22 +286,28 @@ function handleLive(sessionId: string, gooseSessionId: string, update: SessionUp
257286
function handleShared(sessionId: string, update: SessionUpdate): void {
258287
switch (update.sessionUpdate) {
259288
case "session_info_update": {
260-
const info = update as SessionUpdate & { sessionUpdate: "session_info_update" };
289+
const info = update as SessionUpdate & {
290+
sessionUpdate: "session_info_update";
291+
};
261292
if ("title" in info && info.title) {
262293
const session = useChatSessionStore.getState().getSession(sessionId);
263294
if (session && !session.userSetName) {
264-
useChatSessionStore.getState().updateSession(
265-
sessionId,
266-
{ title: info.title as string },
267-
{ persistOverlay: false },
268-
);
295+
useChatSessionStore
296+
.getState()
297+
.updateSession(
298+
sessionId,
299+
{ title: info.title as string },
300+
{ persistOverlay: false },
301+
);
269302
}
270303
}
271304
break;
272305
}
273306

274307
case "config_option_update": {
275-
const configUpdate = update as SessionUpdate & { sessionUpdate: "config_option_update" };
308+
const configUpdate = update as SessionUpdate & {
309+
sessionUpdate: "config_option_update";
310+
};
276311
if ("options" in configUpdate && Array.isArray(configUpdate.options)) {
277312
const modelOption = configUpdate.options.find(
278313
(opt: any) => opt.category === "model",
@@ -295,7 +330,8 @@ function handleShared(sessionId: string, update: SessionUpdate): void {
295330
}
296331

297332
const currentModelName =
298-
availableModels.find((m) => m.id === currentModelId)?.name ?? currentModelId;
333+
availableModels.find((m) => m.id === currentModelId)?.name ??
334+
currentModelId;
299335

300336
const sessionStore = useChatSessionStore.getState();
301337
sessionStore.setSessionModels(sessionId, availableModels);
@@ -326,26 +362,38 @@ function handleShared(sessionId: string, update: SessionUpdate): void {
326362
// Helpers
327363

328364
function findStreamingMessageId(sessionId: string): string | null {
329-
return useChatStore.getState().getSessionRuntime(sessionId).streamingMessageId;
365+
return useChatStore.getState().getSessionRuntime(sessionId)
366+
.streamingMessageId;
330367
}
331368

332-
function findMessageInBuffer(sessionId: string, _toolCallId: string): ReturnType<typeof getBufferedMessage> {
369+
function findMessageInBuffer(
370+
sessionId: string,
371+
_toolCallId: string,
372+
): ReturnType<typeof getBufferedMessage> {
333373
const buffer = ensureReplayBuffer(sessionId);
334374
return buffer[buffer.length - 1];
335375
}
336376

337-
function findMessageWithToolCall(sessionId: string, toolCallId: string): ReturnType<typeof getBufferedMessage> {
377+
function findMessageWithToolCall(
378+
sessionId: string,
379+
toolCallId: string,
380+
): ReturnType<typeof getBufferedMessage> {
338381
const buffer = ensureReplayBuffer(sessionId);
339382
for (let i = buffer.length - 1; i >= 0; i--) {
340383
const msg = buffer[i];
341-
if (msg.content.some((c) => c.type === "toolRequest" && c.id === toolCallId)) {
384+
if (
385+
msg.content.some((c) => c.type === "toolRequest" && c.id === toolCallId)
386+
) {
342387
return msg;
343388
}
344389
}
345390
return buffer[buffer.length - 1];
346391
}
347392

348-
function extractToolResultText(update: { content?: Array<any> | null; rawOutput?: unknown }): string {
393+
function extractToolResultText(update: {
394+
content?: Array<any> | null;
395+
rawOutput?: unknown;
396+
}): string {
349397
if (update.content && update.content.length > 0) {
350398
for (const item of update.content) {
351399
if (item.type === "content" && item.content?.type === "text") {

ui/goose2/src/shared/api/acpSessionTracker.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ export async function prepareSession(
4242
try {
4343
await acpApi.loadSession(sessionId, workingDir);
4444
gooseSessionId = sessionId;
45-
} catch {
46-
}
45+
} catch {}
4746

4847
if (!gooseSessionId) {
4948
const response = await acpApi.newSession(workingDir);
@@ -59,9 +58,16 @@ export async function prepareSession(
5958
return gooseSessionId;
6059
}
6160

62-
export function getGooseSessionId(sessionId: string, personaId?: string): string | null {
61+
export function getGooseSessionId(
62+
sessionId: string,
63+
personaId?: string,
64+
): string | null {
6365
const key = makeKey(sessionId, personaId);
64-
return prepared.get(key)?.gooseSessionId ?? prepared.get(sessionId)?.gooseSessionId ?? null;
66+
return (
67+
prepared.get(key)?.gooseSessionId ??
68+
prepared.get(sessionId)?.gooseSessionId ??
69+
null
70+
);
6571
}
6672

6773
export function getLocalSessionId(gooseSessionId: string): string | null {
@@ -78,4 +84,3 @@ export function registerSession(
7884
prepared.set(sessionId, entry);
7985
gooseToLocal.set(gooseSessionId, sessionId);
8086
}
81-

0 commit comments

Comments
 (0)