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

Commitd6d568b

Browse files
BrunoQuaresmaaslilac
authored andcommitted
fix(site): fix agent logs streaming for third party apps (#14541)
(cherry picked from commit242b1ea)
1 parentfc1210a commitd6d568b

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe("useAgentLogs", () => {
2828
expect(wsSpy).not.toHaveBeenCalled();
2929
});
3030

31-
it("should return existing logs without network calls",async()=>{
31+
it("should return existing logs without network calls if state is off",async()=>{
3232
constqueryClient=createTestQueryClient();
3333
queryClient.setQueryData(
3434
agentLogsKey(MockWorkspace.id,MockWorkspaceAgent.id),
@@ -39,7 +39,7 @@ describe("useAgentLogs", () => {
3939
const{ result}=renderUseAgentLogs(queryClient,{
4040
workspaceId:MockWorkspace.id,
4141
agentId:MockWorkspaceAgent.id,
42-
agentLifeCycleState:"ready",
42+
agentLifeCycleState:"off",
4343
});
4444
awaitwaitFor(()=>{
4545
expect(result.current).toHaveLength(5);
@@ -48,12 +48,12 @@ describe("useAgentLogs", () => {
4848
expect(wsSpy).not.toHaveBeenCalled();
4949
});
5050

51-
it("should fetch logs when empty and should not connect to WebSocket when not starting",async()=>{
51+
it("should fetch logs when empty",async()=>{
5252
constqueryClient=createTestQueryClient();
5353
constfetchSpy=jest
5454
.spyOn(API,"getWorkspaceAgentLogs")
5555
.mockResolvedValueOnce(generateLogs(5));
56-
constwsSpy=jest.spyOn(APIModule,"watchWorkspaceAgentLogs");
56+
jest.spyOn(APIModule,"watchWorkspaceAgentLogs");
5757
const{ result}=renderUseAgentLogs(queryClient,{
5858
workspaceId:MockWorkspace.id,
5959
agentId:MockWorkspaceAgent.id,
@@ -63,10 +63,9 @@ describe("useAgentLogs", () => {
6363
expect(result.current).toHaveLength(5);
6464
});
6565
expect(fetchSpy).toHaveBeenCalledWith(MockWorkspaceAgent.id);
66-
expect(wsSpy).not.toHaveBeenCalled();
6766
});
6867

69-
it("should fetch logs and connect to websocket when agent is starting",async()=>{
68+
it("should fetch logs and connect to websocket",async()=>{
7069
constqueryClient=createTestQueryClient();
7170
constlogs=generateLogs(5);
7271
constfetchSpy=jest

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,13 @@ export type UseAgentLogsOptions = Readonly<{
1717

1818
/**
1919
* Defines a custom hook that gives you all workspace agent logs for a given
20-
* workspace.
21-
*
22-
* Depending on the status of the workspace, all logs may or may not be
23-
* available.
20+
* workspace.Depending on the status of the workspace, all logs may or may not
21+
* be available.
2422
*/
2523
exportfunctionuseAgentLogs(
2624
options:UseAgentLogsOptions,
2725
):readonlyWorkspaceAgentLog[]|undefined{
2826
const{ workspaceId, agentId, agentLifeCycleState, enabled=true}=options;
29-
3027
constqueryClient=useQueryClient();
3128
constqueryOptions=agentLogs(workspaceId,agentId);
3229
const{data:logs, isFetched}=useQuery({ ...queryOptions, enabled});
@@ -55,7 +52,17 @@ export function useAgentLogs(
5552
});
5653

5754
useEffect(()=>{
58-
if(agentLifeCycleState!=="starting"||!isFetched){
55+
// Stream data only for new logs. Old logs should be loaded beforehand
56+
// using a regular fetch to avoid overloading the websocket with all
57+
// logs at once.
58+
if(!isFetched){
59+
return;
60+
}
61+
62+
// If the agent is off, we don't need to stream logs. This is the only state
63+
// where the Coder API can't receive logs for the agent from third-party
64+
// apps like envbuilder.
65+
if(agentLifeCycleState==="off"){
5966
return;
6067
}
6168

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp