mirror of
https://github.com/logancyang/obsidian-copilot.git
synced 2026-07-22 07:50:24 +00:00
* fix(tools): remove zod transforms from tool schemas that break agent bindTools readNote.chunkIndex was defined as z.preprocess(...).optional(), which is a zod transform/pipe. When the autonomous agent binds tools, LangChain's toJsonSchema() rewrites the schema to its input form (interopZodTransformInputSchema), exposing the transform node, then zod v4's toJSONSchema() throws "Transforms cannot be represented in JSON Schema". This surfaces at langchainStream.ts as "Model request failed: ..." and breaks the entire brain-icon ReAct agent loop (the non-agent Plus path is unaffected because it binds only clean utility tools). Replace the preprocess fields with JSON-Schema-representable unions and move the string coercion into each tool's func: - readNote.chunkIndex -> z.union([z.number().int().min(0), z.string()]).optional() - writeFile.confirmation -> z.union([z.boolean(), z.string()]).optional() (writeFile only dodged the throw via its .default() wrapper; fixed defensively) Add src/tools/toolSchemas.jsonschema.test.ts, which runs LangChain's toJsonSchema() over the read/composer tools so a future transform in a tool schema fails in CI instead of at runtime. Refs logancyang/obsidian-copilot-preview#69 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(tools): validate readNote chunkIndex to prevent out-of-bounds crash The union schema's string branch bypassed the old z.number().int().min(0) validation, so a string like "-1" or "1.5" was coerced straight through; the bounds check only rejects index >= totalChunks, so chunks[chunkIndex] became undefined and the tool crashed while logging chunk.chunkIndex. coerceChunkIndex now returns null for any value that is not a non-negative integer (undefined still defaults to 0), and readNote returns a structured invalid_chunk_index response instead of indexing out of bounds. Add coverage for "-1", "1.5", and "abc". Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> |
||
|---|---|---|
| .. | ||
| allTools.validation.test.ts | ||
| builtinTools.ts | ||
| CanvasLoader.ts | ||
| ComposerTools.test.ts | ||
| ComposerTools.ts | ||
| createLangChainTool.ts | ||
| FileParserManager.ts | ||
| FileTreeTools.test.ts | ||
| FileTreeTools.ts | ||
| memoryTools.ts | ||
| NoteTools.ts | ||
| ObsidianCliDailyTools.test.ts | ||
| ObsidianCliDailyTools.ts | ||
| ObsidianCliTools.test.ts | ||
| ObsidianCliTools.ts | ||
| ReadNoteTool.test.ts | ||
| SearchTools.dedupe.test.ts | ||
| SearchTools.schema.test.ts | ||
| SearchTools.ts | ||
| TagTools.test.ts | ||
| TagTools.ts | ||
| TimeTools.test.ts | ||
| TimeTools.timezone.test.ts | ||
| TimeTools.ts | ||
| toolManager.ts | ||
| ToolRegistry.ts | ||
| ToolResultFormatter.test.ts | ||
| ToolResultFormatter.ts | ||
| toolSchemas.jsonschema.test.ts | ||
| YoutubeTools.ts | ||