-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathsession.ts
More file actions
49 lines (42 loc) · 1.5 KB
/
session.ts
File metadata and controls
49 lines (42 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { tool } from "@opencode-ai/plugin/tool"
import { createCodeNomadRequester, type CodeNomadConfig } from "./request"
type SessionRenameResponse = {
sessionID: string
title: string
}
export function createSessionTools(config: CodeNomadConfig) {
const requester = createCodeNomadRequester(config)
const request = async <T>(path: string, init?: RequestInit): Promise<T> => {
return requester.requestJson<T>(path, init)
}
return {
rename_session: tool({
description:
"Rename the current session when the user asks to change the chat title. Use a short descriptive title that reflects the current task.",
args: {
title: tool.schema
.string()
.describe("New session title, kept short and descriptive, for example 'Fix login bug' or 'Add session rename tool'"),
},
async execute(args, context) {
const sessionID = context.sessionID
if (!sessionID) {
return "Error: No active session is available for renaming."
}
const trimmedTitle = args.title.trim()
if (!trimmedTitle) {
return "Error: Session title cannot be empty."
}
const result = await request<SessionRenameResponse>("/session/title", {
method: "POST",
body: JSON.stringify({
sessionID,
directory: context.directory,
title: trimmedTitle,
}),
})
return `Renamed session ${result.sessionID} to \"${result.title}\".`
},
}),
}
}