Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions ts/packages/actionGrammar/src/agentGrammarRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Grammar } from "./grammarTypes.js";
import { NFA } from "./nfa.js";
import { matchNFA, NFAMatchResult } from "./nfaInterpreter.js";
import { compileGrammarToNFA } from "./nfaCompiler.js";
import { loadGrammarRules } from "./grammarLoader.js";
import { loadGrammarRulesNoThrow } from "./grammarLoader.js";
import { mergeGrammarRules } from "./grammarMerger.js";
import { globalEntityRegistry } from "./entityRegistry.js";

Expand Down Expand Up @@ -63,7 +63,7 @@ export class AgentGrammar {
const errors: string[] = [];

// Parse the generated rules
const newGrammar = loadGrammarRules(
const newGrammar = loadGrammarRulesNoThrow(
`<generated-${this.agentId}>`,
agrText,
errors,
Expand Down Expand Up @@ -341,18 +341,12 @@ export class AgentGrammarRegistry {
errors?: string[];
} {
const errors: string[] = [];
let grammar;

try {
grammar = loadGrammarRules(`${agentId}.agr`, agrText, errors);
} catch (error) {
return {
success: false,
errors: [
`Failed to parse grammar: ${error instanceof Error ? error.message : String(error)}`,
],
};
}
const grammar = loadGrammarRulesNoThrow(
`${agentId}.agr`,
agrText,
errors,
);

if (!grammar) {
return {
Expand Down
6 changes: 3 additions & 3 deletions ts/packages/actionGrammar/src/dynamicGrammarLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

import { Grammar, GrammarPart } from "./grammarTypes.js";
import { loadGrammarRules } from "./grammarLoader.js";
import { loadGrammarRulesNoThrow } from "./grammarLoader.js";
import { mergeGrammarRules } from "./grammarMerger.js";
import { compileGrammarToNFA } from "./nfaCompiler.js";
import { NFA } from "./nfa.js";
Expand Down Expand Up @@ -46,7 +46,7 @@ export class DynamicGrammarLoader {
const errors: string[] = [];

// Step 1: Parse the grammar rules
const newGrammar = loadGrammarRules("<dynamic>", agrText, errors);
const newGrammar = loadGrammarRulesNoThrow("<dynamic>", agrText, errors);

if (!newGrammar) {
return {
Expand Down Expand Up @@ -117,7 +117,7 @@ export class DynamicGrammarLoader {
const errors: string[] = [];

// Step 1: Parse the grammar rules
const grammar = loadGrammarRules("<dynamic>", agrText, errors);
const grammar = loadGrammarRulesNoThrow("<dynamic>", agrText, errors);

if (!grammar) {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ScenarioTemplate,
getPrefixSuffixPatterns,
} from "./scenarioTemplates.js";
import { loadGrammarRules } from "../grammarLoader.js";
import { loadGrammarRulesNoThrow } from "../grammarLoader.js";

/**
* Configuration for scenario-based grammar generation
Expand Down Expand Up @@ -960,7 +960,7 @@ export class ScenarioBasedGrammarGenerator {

while (retries <= this.maxRetries) {
const errors: string[] = [];
loadGrammarRules("generated.agr", currentGrammar, errors);
loadGrammarRulesNoThrow("generated.agr", currentGrammar, errors);

if (errors.length === 0) {
if (retries > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { query } from "@anthropic-ai/claude-agent-sdk";
import { SchemaInfo, ActionInfo } from "./schemaReader.js";
import { GrammarTestCase } from "./testTypes.js";
import { loadGrammarRules } from "../grammarLoader.js";
import { loadGrammarRulesNoThrow } from "../grammarLoader.js";

/**
* Configuration for grammar generation from a schema
Expand Down Expand Up @@ -459,7 +459,7 @@ export class SchemaToGrammarGenerator {

while (retries <= this.maxRetries) {
const errors: string[] = [];
loadGrammarRules("generated.agr", currentGrammar, errors);
loadGrammarRulesNoThrow("generated.agr", currentGrammar, errors);

if (errors.length === 0) {
if (retries > 0) {
Expand Down
Loading