Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit952c254

Browse files
fix: fix duplicated agent logs (#17806)
Fix#16355
1 parent2c49fd9 commit952c254

File tree

15 files changed

+136
-307
lines changed

15 files changed

+136
-307
lines changed

‎site/src/api/api.ts

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,11 @@ export const watchBuildLogsByTemplateVersionId = (
221221

222222
exportconstwatchWorkspaceAgentLogs=(
223223
agentId:string,
224-
{ after, onMessage, onDone, onError}:WatchWorkspaceAgentLogsOptions,
224+
params?:WatchWorkspaceAgentLogsParams,
225225
)=>{
226226
constsearchParams=newURLSearchParams({
227227
follow:"true",
228-
after:after.toString(),
228+
after:params?.after?.toString()??"",
229229
});
230230

231231
/**
@@ -237,32 +237,14 @@ export const watchWorkspaceAgentLogs = (
237237
searchParams.set("no_compression","");
238238
}
239239

240-
constsocket=createWebSocket(
241-
`/api/v2/workspaceagents/${agentId}/logs`,
240+
returnnewOneWayWebSocket<TypesGen.WorkspaceAgentLog[]>({
241+
apiRoute:`/api/v2/workspaceagents/${agentId}/logs`,
242242
searchParams,
243-
);
244-
245-
socket.addEventListener("message",(event)=>{
246-
constlogs=JSON.parse(event.data)asTypesGen.WorkspaceAgentLog[];
247-
onMessage(logs);
248-
});
249-
250-
socket.addEventListener("error",()=>{
251-
onError(newError("socket errored"));
252243
});
253-
254-
socket.addEventListener("close",()=>{
255-
onDone?.();
256-
});
257-
258-
returnsocket;
259244
};
260245

261-
typeWatchWorkspaceAgentLogsOptions={
262-
after:number;
263-
onMessage:(logs:TypesGen.WorkspaceAgentLog[])=>void;
264-
onDone?:()=>void;
265-
onError:(error:Error)=>void;
246+
typeWatchWorkspaceAgentLogsParams={
247+
after?:number;
266248
};
267249

268250
typeWatchBuildLogsByBuildIdOptions={

‎site/src/api/queries/workspaces.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
ProvisionerLogLevel,
66
UsageAppName,
77
Workspace,
8+
WorkspaceAgentLog,
89
WorkspaceBuild,
910
WorkspaceBuildParameter,
1011
WorkspacesRequest,
@@ -20,6 +21,7 @@ import type {
2021
QueryClient,
2122
QueryOptions,
2223
UseMutationOptions,
24+
UseQueryOptions,
2325
}from"react-query";
2426
import{checkAuthorization}from"./authCheck";
2527
import{disabledRefetchOptions}from"./util";
@@ -342,20 +344,14 @@ export const buildLogs = (workspace: Workspace) => {
342344
};
343345
};
344346

345-
exportconstagentLogsKey=(workspaceId:string,agentId:string)=>[
346-
"workspaces",
347-
workspaceId,
348-
"agents",
349-
agentId,
350-
"logs",
351-
];
347+
exportconstagentLogsKey=(agentId:string)=>["agents",agentId,"logs"];
352348

353-
exportconstagentLogs=(workspaceId:string,agentId:string)=>{
349+
exportconstagentLogs=(agentId:string)=>{
354350
return{
355-
queryKey:agentLogsKey(workspaceId,agentId),
351+
queryKey:agentLogsKey(agentId),
356352
queryFn:()=>API.getWorkspaceAgentLogs(agentId),
357353
...disabledRefetchOptions,
358-
};
354+
}satisfiesUseQueryOptions<WorkspaceAgentLog[]>;
359355
};
360356

361357
// workspace usage options

‎site/src/modules/resources/AgentLogs/useAgentLogs.test.tsx

Lines changed: 0 additions & 142 deletions
This file was deleted.

‎site/src/modules/resources/AgentLogs/useAgentLogs.ts

Lines changed: 0 additions & 95 deletions
This file was deleted.

‎site/src/modules/resources/AgentRow.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import { AgentDevcontainerCard } from "./AgentDevcontainerCard";
3131
import{AgentLatency}from"./AgentLatency";
3232
import{AGENT_LOG_LINE_HEIGHT}from"./AgentLogs/AgentLogLine";
3333
import{AgentLogs}from"./AgentLogs/AgentLogs";
34-
import{useAgentLogs}from"./AgentLogs/useAgentLogs";
3534
import{AgentMetadata}from"./AgentMetadata";
3635
import{AgentStatus}from"./AgentStatus";
3736
import{AgentVersion}from"./AgentVersion";
@@ -41,6 +40,7 @@ import { PortForwardButton } from "./PortForwardButton";
4140
import{AgentSSHButton}from"./SSHButton/SSHButton";
4241
import{TerminalLink}from"./TerminalLink/TerminalLink";
4342
import{VSCodeDesktopButton}from"./VSCodeDesktopButton/VSCodeDesktopButton";
43+
import{useAgentLogs}from"./useAgentLogs";
4444

4545
exportinterfaceAgentRowProps{
4646
agent:WorkspaceAgent;
@@ -89,12 +89,7 @@ export const AgentRow: FC<AgentRowProps> = ({
8989
["starting","start_timeout"].includes(agent.lifecycle_state)&&
9090
hasStartupFeatures,
9191
);
92-
constagentLogs=useAgentLogs({
93-
workspaceId:workspace.id,
94-
agentId:agent.id,
95-
agentLifeCycleState:agent.lifecycle_state,
96-
enabled:showLogs,
97-
});
92+
constagentLogs=useAgentLogs(agent,showLogs);
9893
constlogListRef=useRef<List>(null);
9994
constlogListDivRef=useRef<HTMLDivElement>(null);
10095
conststartupLogs=useMemo(()=>{

‎site/src/modules/resources/DownloadAgentLogsButton.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const meta: Meta<typeof DownloadAgentLogsButton> = {
1515
parameters:{
1616
queries:[
1717
{
18-
key:agentLogsKey(MockWorkspace.id,MockWorkspaceAgent.id),
18+
key:agentLogsKey(MockWorkspaceAgent.id),
1919
data:generateLogs(5),
2020
},
2121
],

‎site/src/modules/resources/DownloadAgentLogsButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const DownloadAgentLogsButton: FC<DownloadAgentLogsButtonProps> = ({
2323
const[isDownloading,setIsDownloading]=useState(false);
2424

2525
constfetchLogs=async()=>{
26-
constqueryOpts=agentLogs(workspaceId,agent.id);
26+
constqueryOpts=agentLogs(agent.id);
2727
letlogs=queryClient.getQueryData<WorkspaceAgentLog[]>(
2828
queryOpts.queryKey,
2929
);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp