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

Commit4d8a9c2

Browse files
committed
Support workspace name in get workspace tool
This lets the LLM skip the list workspace step.
1 parent4bd7c7b commit4d8a9c2

File tree

2 files changed

+39
-16
lines changed

2 files changed

+39
-16
lines changed

‎codersdk/toolsdk/toolsdk.go‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -317,13 +317,14 @@ type GetWorkspaceArgs struct {
317317
varGetWorkspace=Tool[GetWorkspaceArgs, codersdk.Workspace]{
318318
Tool: aisdk.Tool{
319319
Name:ToolNameGetWorkspace,
320-
Description:`Get a workspace by ID.
320+
Description:`Get a workspace byname orID.
321321
322322
This returns more data than list_workspaces to reduce token usage.`,
323323
Schema: aisdk.Schema{
324324
Properties:map[string]any{
325325
"workspace_id":map[string]any{
326-
"type":"string",
326+
"type":"string",
327+
"description":workspaceDescription,
327328
},
328329
},
329330
Required: []string{"workspace_id"},
@@ -332,7 +333,7 @@ This returns more data than list_workspaces to reduce token usage.`,
332333
Handler:func(ctx context.Context,depsDeps,argsGetWorkspaceArgs) (codersdk.Workspace,error) {
333334
wsID,err:=uuid.Parse(args.WorkspaceID)
334335
iferr!=nil {
335-
returncodersdk.Workspace{},xerrors.New("workspace_id must be a valid UUID")
336+
returnnormalizedNamedWorkspace(ctx,deps.coderClient,args.WorkspaceID)
336337
}
337338
returndeps.coderClient.Workspace(ctx,wsID)
338339
},
@@ -1415,7 +1416,7 @@ var WorkspaceLS = Tool[WorkspaceLSArgs, WorkspaceLSResponse]{
14151416
Properties:map[string]any{
14161417
"workspace":map[string]any{
14171418
"type":"string",
1418-
"description":workspaceDescription,
1419+
"description":workspaceAgentDescription,
14191420
},
14201421
"path":map[string]any{
14211422
"type":"string",
@@ -1472,7 +1473,7 @@ var WorkspaceReadFile = Tool[WorkspaceReadFileArgs, WorkspaceReadFileResponse]{
14721473
Properties:map[string]any{
14731474
"workspace":map[string]any{
14741475
"type":"string",
1475-
"description":workspaceDescription,
1476+
"description":workspaceAgentDescription,
14761477
},
14771478
"path":map[string]any{
14781479
"type":"string",
@@ -1537,7 +1538,7 @@ var WorkspaceWriteFile = Tool[WorkspaceWriteFileArgs, codersdk.Response]{
15371538
Properties:map[string]any{
15381539
"workspace":map[string]any{
15391540
"type":"string",
1540-
"description":workspaceDescription,
1541+
"description":workspaceAgentDescription,
15411542
},
15421543
"path":map[string]any{
15431544
"type":"string",
@@ -1585,7 +1586,7 @@ var WorkspaceEditFile = Tool[WorkspaceEditFileArgs, codersdk.Response]{
15851586
Properties:map[string]any{
15861587
"workspace":map[string]any{
15871588
"type":"string",
1588-
"description":workspaceDescription,
1589+
"description":workspaceAgentDescription,
15891590
},
15901591
"path":map[string]any{
15911592
"type":"string",
@@ -1652,7 +1653,7 @@ var WorkspaceEditFiles = Tool[WorkspaceEditFilesArgs, codersdk.Response]{
16521653
Properties:map[string]any{
16531654
"workspace":map[string]any{
16541655
"type":"string",
1655-
"description":workspaceDescription,
1656+
"description":workspaceAgentDescription,
16561657
},
16571658
"files":map[string]any{
16581659
"type":"array",
@@ -1726,7 +1727,7 @@ var WorkspacePortForward = Tool[WorkspacePortForwardArgs, WorkspacePortForwardRe
17261727
Properties:map[string]any{
17271728
"workspace":map[string]any{
17281729
"type":"string",
1729-
"description":workspaceDescription,
1730+
"description":workspaceAgentDescription,
17301731
},
17311732
"port":map[string]any{
17321733
"type":"number",
@@ -1783,7 +1784,7 @@ var WorkspaceListApps = Tool[WorkspaceListAppsArgs, WorkspaceListAppsResponse]{
17831784
Properties:map[string]any{
17841785
"workspace":map[string]any{
17851786
"type":"string",
1786-
"description":workspaceDescription,
1787+
"description":workspaceAgentDescription,
17871788
},
17881789
},
17891790
Required: []string{"workspace"},
@@ -2196,7 +2197,9 @@ func newAgentConn(ctx context.Context, client *codersdk.Client, workspace string
21962197
returnconn,nil
21972198
}
21982199

2199-
constworkspaceDescription="The workspace name in the format [owner/]workspace[.agent]. If an owner is not specified, the authenticated user is used."
2200+
constworkspaceDescription="The workspace ID or name in the format [owner/]workspace. If an owner is not specified, the authenticated user is used."
2201+
2202+
constworkspaceAgentDescription="The workspace name in the format [owner/]workspace[.agent]. If an owner is not specified, the authenticated user is used."
22002203

22012204
functaskIDDescription(actionstring)string {
22022205
returnfmt.Sprintf("ID or workspace identifier in the format [owner/]workspace[.agent] for the task to %s. If an owner is not specified, the authenticated user is used.",action)

‎codersdk/toolsdk/toolsdk_test.go‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,32 @@ func TestTools(t *testing.T) {
125125
t.Run("GetWorkspace",func(t*testing.T) {
126126
tb,err:=toolsdk.NewDeps(memberClient)
127127
require.NoError(t,err)
128-
result,err:=testTool(t,toolsdk.GetWorkspace,tb, toolsdk.GetWorkspaceArgs{
129-
WorkspaceID:r.Workspace.ID.String(),
130-
})
131128

132-
require.NoError(t,err)
133-
require.Equal(t,r.Workspace.ID,result.ID,"expected the workspace ID to match")
129+
tests:= []struct {
130+
namestring
131+
workspacestring
132+
}{
133+
{
134+
name:"ByID",
135+
workspace:r.Workspace.ID.String(),
136+
},
137+
{
138+
name:"ByName",
139+
workspace:r.Workspace.Name,
140+
},
141+
}
142+
143+
for_,tt:=rangetests {
144+
t.Run(tt.name,func(t*testing.T) {
145+
t.Parallel()
146+
147+
result,err:=testTool(t,toolsdk.GetWorkspace,tb, toolsdk.GetWorkspaceArgs{
148+
WorkspaceID:tt.workspace,
149+
})
150+
require.NoError(t,err)
151+
require.Equal(t,r.Workspace.ID,result.ID,"expected the workspace ID to match")
152+
})
153+
}
134154
})
135155

136156
t.Run("ListTemplates",func(t*testing.T) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp