CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
tool-error.ts137 linesDownload Raw Back to tools
1/**2 * @license3 * Copyright 2025 Google LLC4 * SPDX-License-Identifier: Apache-2.05 */6 7/**8 * A type-safe enum for tool-related errors.9 */10export enum ToolErrorType {11  // General Errors12  INVALID_TOOL_PARAMS = 'invalid_tool_params',13  UNKNOWN = 'unknown',14  UNHANDLED_EXCEPTION = 'unhandled_exception',15  TOOL_NOT_REGISTERED = 'tool_not_registered',16  EXECUTION_FAILED = 'execution_failed',17  // A tool call exceeded the per-tool execution timeout and was aborted.18  EXECUTION_TIMEOUT = 'execution_timeout',19  // Try to execute a tool that is excluded due to the approval mode20  EXECUTION_DENIED = 'execution_denied',21 22  // File System Errors23  FILE_NOT_FOUND = 'file_not_found',24  FILE_WRITE_FAILURE = 'file_write_failure',25  READ_CONTENT_FAILURE = 'read_content_failure',26  ATTEMPT_TO_CREATE_EXISTING_FILE = 'attempt_to_create_existing_file',27  FILE_TOO_LARGE = 'file_too_large',28  PERMISSION_DENIED = 'permission_denied',29  NO_SPACE_LEFT = 'no_space_left',30  TARGET_IS_DIRECTORY = 'target_is_directory',31  PATH_NOT_IN_WORKSPACE = 'path_not_in_workspace',32  SEARCH_PATH_NOT_FOUND = 'search_path_not_found',33  SEARCH_PATH_NOT_A_DIRECTORY = 'search_path_not_a_directory',34 35  // Edit-specific Errors36  EDIT_PREPARATION_FAILURE = 'edit_preparation_failure',37  EDIT_NO_OCCURRENCE_FOUND = 'edit_no_occurrence_found',38  EDIT_EXPECTED_OCCURRENCE_MISMATCH = 'edit_expected_occurrence_mismatch',39  EDIT_NO_CHANGE = 'edit_no_change',40  EDIT_NO_CHANGE_LLM_JUDGEMENT = 'edit_no_change_llm_judgement',41  // Returned when Edit / WriteFile is asked to mutate a file in a42  // state the session-scoped FileReadCache cannot vouch for. Three43  // cases share this code:44  //45  //   1. The file has not been read this session via ReadFile (the46  //      original "model never saw the bytes" case).47  //   2. The file was read only as a partial / ranged / truncated48  //      view, so the model has not seen the full text content the49  //      mutation could touch.50  //   3. The file is a structural dead end that no amount of51  //      re-reading can change: non-text payloads (binary / image /52  //      audio / video / PDF / notebook). read_file returns these as53  //      structured values that Edit / WriteFile cannot mutate safely;54  //      the rejection message tells the model to use a different tool55  //      (shell with a binary-aware writer).56  //57  // Despite the `EDIT_` prefix this code is shared between EditTool58  // and WriteFileTool: the boundary it guards is "the model is about59  // to mutate bytes it has not legitimately seen", which both tools60  // can hit. The prefix is kept for backwards-compatibility with61  // logs/dashboards already keyed on it; consumers that need to62  // distinguish edit-vs-write should look at the originating tool63  // name in the surrounding ToolCallEvent rather than the error64  // code itself.65  //66  // Note for operators routing alerts: a single `edit_requires_prior_read`67  // signal can mean any of the three cases above. If per-cause monitoring68  // becomes important, splitting this into separate codes (e.g.69  // `EDIT_NO_PRIOR_READ`, `EDIT_PARTIAL_PRIOR_READ`,70  // `EDIT_TARGET_NOT_TEXT_EDITABLE`) is a follow-up; for now the71  // originating tool name and the message text already disambiguate.72  EDIT_REQUIRES_PRIOR_READ = 'edit_requires_prior_read',73  // Returned when Edit / WriteFile is asked to mutate a file the model74  // *has* read this session, but the on-disk bytes have changed since75  // (mtime or size differs from the recorded fingerprint). The model76  // is expected to re-read with ReadFile to refresh its mental model77  // before retrying the edit.78  FILE_CHANGED_SINCE_READ = 'file_changed_since_read',79  // Returned when Edit / WriteFile cannot determine whether the model80  // has read a file because `fs.stat` itself failed for a reason81  // other than ENOENT (typically EACCES, EBUSY, or an NFS hiccup).82  // Distinct from EDIT_REQUIRES_PRIOR_READ ("definitely not read")83  // because the model may have legitimately read the file — we just84  // cannot verify. Operators monitoring on error codes can route this85  // separately.86  PRIOR_READ_VERIFICATION_FAILED = 'prior_read_verification_failed',87  // Returned when a path resolves but is not a regular file (FIFO / socket /88  // character or block device). Re-reading cannot make these editable, so this89  // is distinct from EDIT_REQUIRES_PRIOR_READ to avoid read/edit retry loops.90  TARGET_NOT_REGULAR_FILE = 'target_not_regular_file',91 92  // Notebook-specific Errors93  NOTEBOOK_EDIT_FAILURE = 'notebook_edit_failure',94  NOTEBOOK_INVALID_JSON = 'notebook_invalid_json',95  NOTEBOOK_CELL_NOT_FOUND = 'notebook_cell_not_found',96 97  // Glob-specific Errors98  GLOB_EXECUTION_ERROR = 'glob_execution_error',99 100  // Grep-specific Errors101  GREP_EXECUTION_ERROR = 'grep_execution_error',102 103  // Ls-specific Errors104  LS_EXECUTION_ERROR = 'ls_execution_error',105  PATH_IS_NOT_A_DIRECTORY = 'path_is_not_a_directory',106 107  // MCP-specific Errors108  MCP_TOOL_ERROR = 'mcp_tool_error',109 110  // Memory-specific Errors111  MEMORY_TOOL_EXECUTION_ERROR = 'memory_tool_execution_error',112 113  // Shell errors114  SHELL_EXECUTE_ERROR = 'shell_execute_error',115 116  // DiscoveredTool-specific Errors117  DISCOVERED_TOOL_EXECUTION_ERROR = 'discovered_tool_execution_error',118 119  // WebFetch-specific Errors120  WEB_FETCH_NO_URL_IN_PROMPT = 'web_fetch_no_url_in_prompt',121  WEB_FETCH_FALLBACK_FAILED = 'web_fetch_fallback_failed',122  WEB_FETCH_PROCESSING_ERROR = 'web_fetch_processing_error',123 124  // Truncation Errors125  OUTPUT_TRUNCATED = 'output_truncated',126 127  // TaskStop-specific Errors128  TASK_STOP_NOT_FOUND = 'task_stop_not_found',129  TASK_STOP_NOT_RUNNING = 'task_stop_not_running',130  TASK_STOP_NOT_CANCELLABLE = 'task_stop_not_cancellable',131  TASK_STOP_INTERNAL_ERROR = 'task_stop_internal_error',132 133  // SendMessage-specific Errors134  SEND_MESSAGE_NOT_FOUND = 'send_message_not_found',135  SEND_MESSAGE_NOT_RUNNING = 'send_message_not_running',136}137 
basant307/AI_Governance_Project · CoolFace