-
Notifications
You must be signed in to change notification settings - Fork 1
claude-code-chat-browser: Frontend tool registry - link to backend dispatch table via generated manifest #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6c450fd
feat: link frontend tool registry to generated tool_types.json manifest
clean6378-max-it d6f4cfd
fix: non-blocking manifest init, fetch timeout, stricter manifest parse
clean6378-max-it 8475dc3
fix(test): ensure fake timers cleanup in manifest timeout test
clean6378-max-it e217de2
fix(frontend): drop unused tool_types_state scaffolding
clean6378-max-it File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #!/usr/bin/env python3 | ||
| """Write ``static/tool_types.json`` from ``KNOWN_TOOL_TYPES``. | ||
|
|
||
| Run after adding a tool type to ``utils/tool_dispatch.py``:: | ||
|
|
||
| python scripts/gen_tool_types_manifest.py | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| _REPO_ROOT = Path(__file__).resolve().parents[1] | ||
| _MANIFEST_PATH = _REPO_ROOT / "static" / "tool_types.json" | ||
|
|
||
|
|
||
| def write_tool_types_manifest(path: Path | None = None) -> int: | ||
| if str(_REPO_ROOT) not in sys.path: | ||
| sys.path.insert(0, str(_REPO_ROOT)) | ||
| from utils.tool_dispatch import KNOWN_TOOL_TYPES | ||
|
|
||
| dest = path or _MANIFEST_PATH | ||
| payload = {"tool_types": sorted(KNOWN_TOOL_TYPES)} | ||
| dest.write_text(json.dumps(payload, indent=2) + "\n", encoding="utf-8") | ||
| return len(KNOWN_TOOL_TYPES) | ||
|
|
||
|
|
||
| def main() -> None: | ||
| count = write_tool_types_manifest() | ||
| print(f"Wrote {count} tool types to {_MANIFEST_PATH}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,11 @@ | ||
| import { esc, truncate } from '../../shared/utils.js'; | ||
| import { finishToolResult } from './common.js'; | ||
| import { UNKNOWN_DISPATCH_KEY } from '../constants.js'; | ||
|
|
||
| export function renderToolResultFallback(parsed) { | ||
| const rt = parsed.result_type || UNKNOWN_DISPATCH_KEY; | ||
| const summary = `Tool result (${rt})`; | ||
| return finishToolResult(summary, ''); | ||
| const summary = `Unknown tool result: ${rt}`; | ||
| const payload = JSON.stringify(parsed, null, 2); | ||
| const body = `<pre><code>${esc(truncate(payload, 500))}</code></pre>`; | ||
| return finishToolResult(summary, body); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { TOOL_USE_RENDERERS } from './registry.js'; | ||
|
|
||
| const MANIFEST_URL = '/static/tool_types.json'; | ||
| const MANIFEST_FETCH_TIMEOUT_MS = 5000; | ||
|
|
||
| /** | ||
| * Load backend tool-type manifest and cross-check ``TOOL_USE_RENDERERS``. | ||
| * Logs ``console.warn`` when the backend list and frontend registry diverge. | ||
| */ | ||
| export async function initToolTypesManifest() { | ||
| const controller = new AbortController(); | ||
| const timeoutId = setTimeout(() => controller.abort(), MANIFEST_FETCH_TIMEOUT_MS); | ||
| try { | ||
| const res = await fetch(MANIFEST_URL, { signal: controller.signal }); | ||
| if (!res.ok) { | ||
| console.warn(`[tool registry] Could not load ${MANIFEST_URL}: HTTP ${res.status}`); | ||
| return; | ||
| } | ||
| const data = await res.json(); | ||
| const types = Array.isArray(data.tool_types) ? data.tool_types : []; | ||
| const manifest = new Set(types.filter((t) => typeof t === 'string')); | ||
|
|
||
| for (const name of manifest) { | ||
| if (!Object.prototype.hasOwnProperty.call(TOOL_USE_RENDERERS, name)) { | ||
| console.warn( | ||
| `[tool registry] Backend tool type "${name}" has no TOOL_USE_RENDERERS entry`, | ||
| ); | ||
| } | ||
| } | ||
| for (const name of Object.keys(TOOL_USE_RENDERERS)) { | ||
| if (!manifest.has(name)) { | ||
| console.warn( | ||
| `[tool registry] TOOL_USE_RENDERERS entry "${name}" is missing from ${MANIFEST_URL}`, | ||
| ); | ||
| } | ||
| } | ||
| } catch (err) { | ||
| if (err?.name === 'AbortError') { | ||
| console.warn( | ||
| `[tool registry] Could not load ${MANIFEST_URL}: timed out after ${MANIFEST_FETCH_TIMEOUT_MS}ms`, | ||
| ); | ||
| return; | ||
| } | ||
| console.warn('[tool registry] Could not load tool types manifest:', err); | ||
| } finally { | ||
| clearTimeout(timeoutId); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; | ||
| import { initToolTypesManifest } from './tool_types_manifest.js'; | ||
| import { TOOL_USE_RENDERERS } from './registry.js'; | ||
|
|
||
| describe('initToolTypesManifest', () => { | ||
| beforeEach(() => { | ||
| vi.restoreAllMocks(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.unstubAllGlobals(); | ||
| }); | ||
|
|
||
| it('cross-checks manifest against TOOL_USE_RENDERERS and warns on drift', async () => { | ||
| const warn = vi.spyOn(console, 'warn').mockImplementation(() => {}); | ||
| const manifestTypes = [...Object.keys(TOOL_USE_RENDERERS), 'FutureToolXYZ']; | ||
| vi.stubGlobal( | ||
| 'fetch', | ||
| vi.fn().mockResolvedValue({ | ||
| ok: true, | ||
| json: async () => ({ tool_types: manifestTypes }), | ||
| }), | ||
| ); | ||
|
|
||
| await initToolTypesManifest(); | ||
|
|
||
| expect(warn).toHaveBeenCalledWith( | ||
| '[tool registry] Backend tool type "FutureToolXYZ" has no TOOL_USE_RENDERERS entry', | ||
| ); | ||
| }); | ||
|
|
||
| it('warns when fetch fails', async () => { | ||
| const warn = vi.spyOn(console, 'warn').mockImplementation(() => {}); | ||
| vi.stubGlobal('fetch', vi.fn().mockRejectedValue(new Error('network'))); | ||
|
|
||
| await initToolTypesManifest(); | ||
|
|
||
| expect(warn).toHaveBeenCalledWith( | ||
| '[tool registry] Could not load tool types manifest:', | ||
| expect.any(Error), | ||
| ); | ||
| }); | ||
|
|
||
| it('warns when fetch times out', async () => { | ||
| vi.useFakeTimers(); | ||
| try { | ||
| const warn = vi.spyOn(console, 'warn').mockImplementation(() => {}); | ||
| vi.stubGlobal( | ||
| 'fetch', | ||
| vi.fn((_url, init) => | ||
| new Promise((_resolve, reject) => { | ||
| init?.signal?.addEventListener('abort', () => { | ||
| reject(Object.assign(new Error('aborted'), { name: 'AbortError' })); | ||
| }); | ||
| }), | ||
| ), | ||
| ); | ||
|
|
||
| const promise = initToolTypesManifest(); | ||
| await vi.advanceTimersByTimeAsync(5000); | ||
| await promise; | ||
|
|
||
| expect(warn).toHaveBeenCalledWith( | ||
| '[tool registry] Could not load /static/tool_types.json: timed out after 5000ms', | ||
| ); | ||
| } finally { | ||
| vi.useRealTimers(); | ||
| } | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| "tool_types": [ | ||
| "AskUserQuestion", | ||
| "Bash", | ||
| "Edit", | ||
| "Glob", | ||
| "Grep", | ||
| "Read", | ||
| "Task", | ||
| "TodoWrite", | ||
| "WebFetch", | ||
| "WebSearch", | ||
| "Write" | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.