index.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. "apply_diff",
  13. "search_files",
  14. "list_files",
  15. "list_code_definition_names",
  16. "browser_action",
  17. "use_mcp_tool",
  18. "access_mcp_resource",
  19. "ask_followup_question",
  20. "attempt_completion",
  21. ] as const
  22. // Converts array of tool call names into a union type ("execute_command" | "read_file" | ...)
  23. export type ToolUseName = (typeof toolUseNames)[number]
  24. export const toolParamNames = [
  25. "command",
  26. "path",
  27. "content",
  28. "line_count",
  29. "regex",
  30. "file_pattern",
  31. "recursive",
  32. "action",
  33. "url",
  34. "coordinate",
  35. "text",
  36. "server_name",
  37. "tool_name",
  38. "arguments",
  39. "uri",
  40. "question",
  41. "result",
  42. "diff",
  43. "start_line",
  44. "end_line",
  45. ] as const
  46. export type ToolParamName = (typeof toolParamNames)[number]
  47. export interface ToolUse {
  48. type: "tool_use"
  49. name: ToolUseName
  50. // params is a partial record, allowing only some or none of the possible parameters to be used
  51. params: Partial<Record<ToolParamName, string>>
  52. partial: boolean
  53. }
  54. export interface ExecuteCommandToolUse extends ToolUse {
  55. name: "execute_command"
  56. // Pick<Record<ToolParamName, string>, "command"> makes "command" required, but Partial<> makes it optional
  57. params: Partial<Pick<Record<ToolParamName, string>, "command">>
  58. }
  59. export interface ReadFileToolUse extends ToolUse {
  60. name: "read_file"
  61. params: Partial<Pick<Record<ToolParamName, string>, "path">>
  62. }
  63. export interface WriteToFileToolUse extends ToolUse {
  64. name: "write_to_file"
  65. params: Partial<Pick<Record<ToolParamName, string>, "path" | "content" | "line_count">>
  66. }
  67. export interface SearchFilesToolUse extends ToolUse {
  68. name: "search_files"
  69. params: Partial<Pick<Record<ToolParamName, string>, "path" | "regex" | "file_pattern">>
  70. }
  71. export interface ListFilesToolUse extends ToolUse {
  72. name: "list_files"
  73. params: Partial<Pick<Record<ToolParamName, string>, "path" | "recursive">>
  74. }
  75. export interface ListCodeDefinitionNamesToolUse extends ToolUse {
  76. name: "list_code_definition_names"
  77. params: Partial<Pick<Record<ToolParamName, string>, "path">>
  78. }
  79. export interface BrowserActionToolUse extends ToolUse {
  80. name: "browser_action"
  81. params: Partial<Pick<Record<ToolParamName, string>, "action" | "url" | "coordinate" | "text">>
  82. }
  83. export interface UseMcpToolToolUse extends ToolUse {
  84. name: "use_mcp_tool"
  85. params: Partial<Pick<Record<ToolParamName, string>, "server_name" | "tool_name" | "arguments">>
  86. }
  87. export interface AccessMcpResourceToolUse extends ToolUse {
  88. name: "access_mcp_resource"
  89. params: Partial<Pick<Record<ToolParamName, string>, "server_name" | "uri">>
  90. }
  91. export interface AskFollowupQuestionToolUse extends ToolUse {
  92. name: "ask_followup_question"
  93. params: Partial<Pick<Record<ToolParamName, string>, "question">>
  94. }
  95. export interface AttemptCompletionToolUse extends ToolUse {
  96. name: "attempt_completion"
  97. params: Partial<Pick<Record<ToolParamName, string>, "result" | "command">>
  98. }