mirror of
https://github.com/bendtherules/ask262.git
synced 2026-08-18 13:21:55 +00:00
Tools - Move all description to a named export toolMetadata
This commit is contained in:
@@ -7,8 +7,23 @@
|
||||
import { DynamicStructuredTool } from "@langchain/core/tools";
|
||||
import { z } from "zod";
|
||||
|
||||
/**
|
||||
* Tool metadata for reuse in OpenCode tools.
|
||||
*/
|
||||
export const toolMetadata = {
|
||||
description:
|
||||
"Executes JavaScript code in the engine262 JavaScript engine and captures which ECMAScript specification sections are hit during execution. " +
|
||||
"Returns the full marks array as JSON. Useful for understanding how specific JavaScript operations map to the ECMAScript spec. " +
|
||||
"ask262Debug is available globally in the execution context (no import needed). " +
|
||||
"Use ask262Debug.startImportant() and ask262Debug.stopImportant() to mark important sections. " +
|
||||
"Example: ask262Debug.startImportant(); let x = 1 + 2; ask262Debug.stopImportant();",
|
||||
args: {
|
||||
code: "JavaScript code to execute in engine262 (e.g., '[1,2,3].map(x => x * 2)')",
|
||||
},
|
||||
};
|
||||
|
||||
const evaluateSchema = z.object({
|
||||
code: z.string().describe("JavaScript code to execute in engine262"),
|
||||
code: z.string().describe(toolMetadata.args.code),
|
||||
});
|
||||
|
||||
// Type definitions for engine262 module
|
||||
@@ -41,12 +56,7 @@ async function loadEngine262() {
|
||||
export function createEvaluateInEngine262Tool() {
|
||||
return new DynamicStructuredTool({
|
||||
name: "ask262_evaluate_in_engine262",
|
||||
description:
|
||||
"Executes JavaScript code in the engine262 JavaScript engine and captures which ECMAScript specification sections are hit during execution. " +
|
||||
"Returns the full marks array as JSON. Useful for understanding how specific JavaScript operations map to the ECMAScript spec. " +
|
||||
"ask262Debug is available globally in the execution context (no import needed). " +
|
||||
"Use ask262Debug.startImportant() and ask262Debug.stopImportant() to mark important sections. " +
|
||||
"Example: ask262Debug.startImportant(); let x = 1 + 2; ask262Debug.stopImportant();",
|
||||
description: toolMetadata.description,
|
||||
schema: evaluateSchema,
|
||||
func: async ({ code }) => {
|
||||
try {
|
||||
|
||||
@@ -7,18 +7,26 @@ import type { Table } from "@lancedb/lancedb";
|
||||
import { DynamicStructuredTool } from "@langchain/core/tools";
|
||||
import { z } from "zod";
|
||||
|
||||
const getSectionContentSchema = z.object({
|
||||
sectionId: z
|
||||
.string()
|
||||
.describe("The section ID (e.g., 'sec-if-statement') to fetch chunks for"),
|
||||
recursive: z
|
||||
.boolean()
|
||||
.default(true)
|
||||
.describe(
|
||||
/**
|
||||
* Tool metadata for reuse in OpenCode tools.
|
||||
*/
|
||||
export const toolMetadata = {
|
||||
description:
|
||||
"Retrieves all text chunks from a specific specification section by sectionid. " +
|
||||
"Supports recursive fetching - if recursive=true and the section has children, it will fetch all descendants. " +
|
||||
"Use this to get complete content when you see 'Subsection available' or 'partial section' references.",
|
||||
args: {
|
||||
sectionId: "The section ID (e.g., 'sec-if-statement') to fetch chunks for",
|
||||
recursive:
|
||||
"If true, recursively fetches content from all child sections and their descendants. " +
|
||||
"If false, only returns content from the specified section itself. " +
|
||||
"Use false when you only need the specific section's content without subsections.",
|
||||
),
|
||||
"If false, only returns content from the specified section itself. " +
|
||||
"Use false when you only need the specific section's content without subsections.",
|
||||
},
|
||||
};
|
||||
|
||||
const getSectionContentSchema = z.object({
|
||||
sectionId: z.string().describe(toolMetadata.args.sectionId),
|
||||
recursive: z.boolean().default(true).describe(toolMetadata.args.recursive),
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -30,10 +38,7 @@ const getSectionContentSchema = z.object({
|
||||
export function createGetSectionContentTool(table: Table) {
|
||||
return new DynamicStructuredTool({
|
||||
name: "ask262_get_section_content",
|
||||
description:
|
||||
"Retrieves all text chunks from a specific specification section by sectionid. " +
|
||||
"Supports recursive fetching - if recursive=true and the section has children, it will fetch all descendants. " +
|
||||
"Use this to get complete content when you see 'Subsection available' or 'partial section' references.",
|
||||
description: toolMetadata.description,
|
||||
schema: getSectionContentSchema,
|
||||
func: async ({ sectionId, recursive }) => {
|
||||
const allDocs: string[] = [];
|
||||
|
||||
@@ -3,8 +3,17 @@
|
||||
* Exports all tool factory functions and utilities.
|
||||
*/
|
||||
|
||||
export { createEvaluateInEngine262Tool } from "./evaluateInEngine262";
|
||||
export { createGetSectionContentTool } from "./getSectionContent";
|
||||
export {
|
||||
createEvaluateInEngine262Tool,
|
||||
toolMetadata as evaluateToolMetadata,
|
||||
} from "./evaluateInEngine262";
|
||||
export {
|
||||
createGetSectionContentTool,
|
||||
toolMetadata as sectionContentToolMetadata,
|
||||
} from "./getSectionContent";
|
||||
export { createGraphExplorerTool } from "./graphExplorer";
|
||||
export { type RerankResult, rerankDocuments } from "./reranker";
|
||||
export { createSearchSpecSectionsTool } from "./searchSpecSections";
|
||||
export {
|
||||
createSearchSpecSectionsTool,
|
||||
toolMetadata as searchSpecToolMetadata,
|
||||
} from "./searchSpecSections";
|
||||
|
||||
@@ -8,10 +8,23 @@ import { DynamicStructuredTool } from "@langchain/core/tools";
|
||||
import type { OllamaEmbeddings } from "@langchain/ollama";
|
||||
import { z } from "zod";
|
||||
|
||||
/**
|
||||
* Tool metadata for reuse in OpenCode tools.
|
||||
*/
|
||||
export const toolMetadata = {
|
||||
description:
|
||||
"Vector search the ECMAScript specification for sections relevant to a query. " +
|
||||
"Returns JSON array with sectionId, sectionTitle, score, partIndex, totalParts, and content. " +
|
||||
"partIndex and totalParts indicate which chunk of a multi-part section this is " +
|
||||
"(0-indexed, partIndex+1/totalParts), null if single-part.",
|
||||
args: {
|
||||
query:
|
||||
"The search query to find relevant specification sections (e.g., 'how does array map work')",
|
||||
},
|
||||
};
|
||||
|
||||
const searchSpecSchema = z.object({
|
||||
query: z
|
||||
.string()
|
||||
.describe("The search query to find relevant specification sections"),
|
||||
query: z.string().describe(toolMetadata.args.query),
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -26,8 +39,7 @@ export function createSearchSpecSectionsTool(
|
||||
) {
|
||||
return new DynamicStructuredTool({
|
||||
name: "ask262_search_spec_sections",
|
||||
description:
|
||||
"Vector search the ECMAScript specification for sections relevant to a query. Returns JSON array with sectionId, sectionTitle, score, partIndex, totalParts, and content. partIndex and totalParts indicate which chunk of a multi-part section this is (0-indexed, partIndex+1/totalParts), null if single-part.",
|
||||
description: toolMetadata.description,
|
||||
schema: searchSpecSchema,
|
||||
func: async ({ query }) => {
|
||||
// Generate embedding for the query
|
||||
|
||||
Reference in New Issue
Block a user