forked from CodebuffAI/codebuff
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.ts
More file actions
31 lines (29 loc) · 896 Bytes
/
Copy pathutils.ts
File metadata and controls
31 lines (29 loc) · 896 Bytes
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
import {
endsAgentStepParam,
endToolTag,
startToolTag,
toolNameParam,
} from './constants'
import { $toolParams } from './list'
import type { ToolName } from './constants'
import type z from 'zod/v4'
export function getToolCallString<T extends ToolName | (string & {})>(
toolName: T,
params: T extends ToolName
? z.input<(typeof $toolParams)[T]['parameters']>
: Record<string, any>,
...endsAgentStep: T extends ToolName ? [] : [boolean]
): string {
const endsAgentStepValue =
toolName in $toolParams
? $toolParams[toolName as keyof typeof $toolParams].endsAgentStep
: endsAgentStep[0] ?? false
const obj: Record<string, any> = {
[toolNameParam]: toolName,
...params,
}
if (endsAgentStepValue) {
obj[endsAgentStepParam] = endsAgentStepValue satisfies true
}
return [startToolTag, JSON.stringify(obj, null, 2), endToolTag].join('')
}