index.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. export type AssistantMessageContent = TextContent | ToolUse
  2. export { parseAssistantMessage } from "./parse-assistant-message"
  3. export interface TextContent {
  4. type: "text"
  5. content: string
  6. partial: boolean
  7. }
  8. export const toolUseNames = [
  9. "execute_command",
  10. "read_file",
  11. "write_to_file",
  12. "search_files",
  13. "list_files",
  14. "list_code_definition_names",
  15. "inspect_site",
  16. "ask_followup_question",
  17. "attempt_completion",
  18. ] as const
  19. // Converts array of tool call names into a union type ("execute_command" | "read_file" | ...)
  20. export type ToolUseName = (typeof toolUseNames)[number]
  21. export const toolParamNames = [
  22. "command",
  23. "path",
  24. "content",
  25. "regex",
  26. "file_pattern",
  27. "recursive",
  28. "url",
  29. "question",
  30. "result",
  31. ] as const
  32. export type ToolParamName = (typeof toolParamNames)[number]
  33. export interface ToolUse {
  34. type: "tool_use"
  35. name: ToolUseName
  36. // params is a partial record, allowing only some or none of the possible parameters to be used
  37. params: Partial<Record<ToolParamName, string>>
  38. partial: boolean
  39. }
  40. export interface ExecuteCommandToolUse extends ToolUse {
  41. name: "execute_command"
  42. // Pick<Record<ToolParamName, string>, "command"> makes "command" required, but Partial<> makes it optional
  43. params: Partial<Pick<Record<ToolParamName, string>, "command">>
  44. }
  45. export interface ReadFileToolUse extends ToolUse {
  46. name: "read_file"
  47. params: Partial<Pick<Record<ToolParamName, string>, "path">>
  48. }
  49. export interface WriteToFileToolUse extends ToolUse {
  50. name: "write_to_file"
  51. params: Partial<Pick<Record<ToolParamName, string>, "path" | "content">>
  52. }
  53. export interface SearchFilesToolUse extends ToolUse {
  54. name: "search_files"
  55. params: Partial<Pick<Record<ToolParamName, string>, "path" | "regex" | "file_pattern">>
  56. }
  57. export interface ListFilesToolUse extends ToolUse {
  58. name: "list_files"
  59. params: Partial<Pick<Record<ToolParamName, string>, "path" | "recursive">>
  60. }
  61. export interface ListCodeDefinitionNamesToolUse extends ToolUse {
  62. name: "list_code_definition_names"
  63. params: Partial<Pick<Record<ToolParamName, string>, "path">>
  64. }
  65. export interface InspectSiteToolUse extends ToolUse {
  66. name: "inspect_site"
  67. params: Partial<Pick<Record<ToolParamName, string>, "url">>
  68. }
  69. export interface AskFollowupQuestionToolUse extends ToolUse {
  70. name: "ask_followup_question"
  71. params: Partial<Pick<Record<ToolParamName, string>, "question">>
  72. }
  73. export interface AttemptCompletionToolUse extends ToolUse {
  74. name: "attempt_completion"
  75. params: Partial<Pick<Record<ToolParamName, string>, "result" | "command">>
  76. }