Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -468,10 +468,14 @@ export class AppAgentManager implements ActionConfigProvider {
if (useNFAGrammar && agentGrammarRegistry) {
try {
// Enrich grammar with checked variables from .pas.json if available
if (config.compiledSchemaFilePath) {
const compiledSchemaFilePath =
config.schemaFilePath?.endsWith(".pas.json")
? config.schemaFilePath
: undefined;
if (compiledSchemaFilePath) {
try {
const pasJsonPath = getPackageFilePath(
config.compiledSchemaFilePath,
compiledSchemaFilePath,
);
enrichGrammarWithCheckedVariables(
g,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ import fs from "node:fs";
import { CosmosClient, PartitionKeyBuilder } from "@azure/cosmos";
import { CosmosPartitionKeyBuilder } from "telemetry";
import { DefaultAzureCredential } from "@azure/identity";
import { DisplayLog } from "../displayLog.js";
import {
fromJSONParsedActionSchema,
ParsedActionSchemaJSON,
} from "@typeagent/action-schema";

const debug = registerDebug("typeagent:dispatcher:init");
const debugError = registerDebug("typeagent:dispatcher:init:error");
Expand Down Expand Up @@ -157,10 +162,13 @@ export type CommandHandlerContext = {
currentScriptDir: string;
logger?: Logger | undefined;
currentRequestId: RequestId | undefined;
currentAbortSignal: AbortSignal | undefined;
activeRequests: Map<string, AbortController>;
noReasoning: boolean;
commandResult?: CommandResult | undefined;
chatHistory: ChatHistory;
constructionProvider?: ConstructionProvider | undefined;
displayLog: DisplayLog;

batchMode: boolean;
pendingChoiceRoutes: Map<
Expand Down Expand Up @@ -582,6 +590,8 @@ export async function initializeCommandHandlerContext(
// Runtime context
commandLock: createLimiter(1), // Make sure we process one command at a time.
currentRequestId: undefined,
currentAbortSignal: undefined,
activeRequests: new Map<string, AbortController>(),
noReasoning: false,
pendingToggleTransientAgents: [],
agentCache: await getAgentCache(
Expand All @@ -598,6 +608,7 @@ export async function initializeCommandHandlerContext(
chatHistory: createChatHistory(
session.getConfig().execution.history,
),
displayLog: await DisplayLog.load(persistDir),
logger,
metricsManager: metrics ? new RequestMetricsManager() : undefined,
promptLogger: createPromptLogger(getCosmosFactories()),
Expand Down Expand Up @@ -771,16 +782,19 @@ async function setupGrammarGeneration(context: CommandHandlerContext) {
);
}

// Prefer explicit compiledSchemaFile field
if (actionConfig.compiledSchemaFilePath) {
return getPackageFilePath(actionConfig.compiledSchemaFilePath);
}
let schemaPath: string | undefined;

// Fallback: try to derive .pas.json path from .ts schemaFilePath
// Use schemaFilePath directly if it's already a .pas.json file
if (
actionConfig.schemaFilePath &&
actionConfig.schemaFilePath.endsWith(".pas.json")
) {
schemaPath = getPackageFilePath(actionConfig.schemaFilePath);
} else if (
actionConfig.schemaFilePath &&
actionConfig.schemaFilePath.endsWith(".ts")
) {
// Fallback: try to derive .pas.json path from .ts schemaFilePath
// Try common pattern: ./src/schema.ts -> ../dist/schema.pas.json
const derivedPath = actionConfig.schemaFilePath
.replace(/^\.\/src\//, "../dist/")
Expand All @@ -789,15 +803,22 @@ async function setupGrammarGeneration(context: CommandHandlerContext) {
`Attempting fallback .pas.json path for ${schemaName}: ${derivedPath}`,
);
try {
return getPackageFilePath(derivedPath);
schemaPath = getPackageFilePath(derivedPath);
} catch {
// Fallback path doesn't exist, continue to error
}
}

throw new Error(
`Compiled schema file path (.pas.json) not found for schema: ${schemaName}. ` +
`Please add 'compiledSchemaFile' field to the manifest pointing to the .pas.json file.`,
if (!schemaPath) {
throw new Error(
`Compiled schema file path (.pas.json) not found for schema: ${schemaName}. ` +
`Please ensure the schema is compiled to a .pas.json file.`,
);
}

const content = fs.readFileSync(schemaPath, "utf-8");
return fromJSONParsedActionSchema(
JSON.parse(content) as ParsedActionSchemaJSON,
);
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import chalk from "chalk";
import {
ActionContext,
CompletionGroup,
CompletionGroups,
ParameterDefinitions,
ParsedCommandParams,
PartialParsedCommandParams,
Expand Down Expand Up @@ -509,7 +510,7 @@ class AgentToggleCommandHandler implements CommandHandler {
}
}

return completions;
return { groups: completions };
}
}

Expand Down Expand Up @@ -564,7 +565,7 @@ class ExplainerCommandHandler implements CommandHandler {
});
}
}
return completions;
return { groups: completions };
}
}

Expand Down Expand Up @@ -633,7 +634,7 @@ class ConfigModelSetCommandHandler implements CommandHandler {
context: SessionContext<CommandHandlerContext>,
params: PartialParsedCommandParams<ParameterDefinitions>,
names: string[],
): Promise<CompletionGroup[]> {
): Promise<CompletionGroups> {
const completions: CompletionGroup[] = [];
for (const name of names) {
if (name === "model") {
Expand All @@ -644,7 +645,7 @@ class ConfigModelSetCommandHandler implements CommandHandler {
}
}

return completions;
return { groups: completions };
}
}

Expand Down Expand Up @@ -753,7 +754,7 @@ class FixedSchemaCommandHandler implements CommandHandler {
context: SessionContext<CommandHandlerContext>,
params: PartialParsedCommandParams<ParameterDefinitions>,
names: string[],
): Promise<CompletionGroup[]> {
): Promise<CompletionGroups> {
const completions: CompletionGroup[] = [];
const systemContext = context.agentContext;
for (const name of names) {
Expand All @@ -764,7 +765,7 @@ class FixedSchemaCommandHandler implements CommandHandler {
});
}
}
return completions;
return { groups: completions };
}
}

Expand Down Expand Up @@ -846,7 +847,7 @@ class GrammarSystemCommandHandler implements CommandHandler {
});
}
}
return completions;
return { groups: completions };
}
}
class GrammarUseDFACommandHandler implements CommandHandler {
Expand Down Expand Up @@ -889,7 +890,7 @@ class GrammarUseDFACommandHandler implements CommandHandler {
completions.push({ name, completions: ["true", "false"] });
}
}
return completions;
return { groups: completions };
}
}

Expand Down Expand Up @@ -1226,7 +1227,7 @@ class ConfigRequestCommandHandler implements CommandHandler {
context: SessionContext<CommandHandlerContext>,
params: PartialParsedCommandParams<ParameterDefinitions>,
names: string[],
): Promise<CompletionGroup[]> {
): Promise<CompletionGroups> {
const completions: CompletionGroup[] = [];
const systemContext = context.agentContext;
for (const name of names) {
Expand All @@ -1251,7 +1252,7 @@ class ConfigRequestCommandHandler implements CommandHandler {
}
}
}
return completions;
return { groups: completions };
}
}

Expand Down