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
23 changes: 20 additions & 3 deletions ts/packages/actionGrammar/src/generation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Grammar generation module for creating Action Grammar rules from schemas and examples
*/

import { ParsedActionSchema } from "@typeagent/action-schema";
import { Cardinal } from "../builtInEntities.js";

export {
Expand Down Expand Up @@ -44,6 +45,7 @@ export {

export {
loadSchemaInfo,
getSchemaInfoFromParsedSchema,
SchemaInfo,
ActionInfo,
ParameterValidationInfo,
Expand All @@ -65,7 +67,10 @@ export {
} from "./grammarWarmer.js";

import { ClaudeGrammarGenerator, GrammarAnalysis } from "./grammarGenerator.js";
import { loadSchemaInfo } from "./schemaReader.js";
import {
getSchemaInfoFromParsedSchema,
loadSchemaInfo,
} from "./schemaReader.js";
import { GrammarTestCase } from "./testTypes.js";
import { loadGrammarRulesNoThrow } from "../grammarLoader.js";
import { compileGrammarToNFA } from "../nfaCompiler.js";
Expand Down Expand Up @@ -199,7 +204,9 @@ export interface CachePopulationRequest {
parameters: Record<string, any>;
};
// Path to the .pas.json schema file for validation info
schemaPath: string;
schemaPath?: string;
// Already-loaded parsed action schema (preferred over schemaPath)
parsedSchema?: ParsedActionSchema;
}

/**
Expand Down Expand Up @@ -276,7 +283,17 @@ export async function populateCache(
): Promise<CachePopulationResult> {
try {
// Load schema information
const schemaInfo = loadSchemaInfo(request.schemaPath);
if (!request.parsedSchema && !request.schemaPath) {
throw new Error(
"Either parsedSchema or schemaPath must be provided",
);
}
const schemaInfo = request.parsedSchema
? getSchemaInfoFromParsedSchema(
request.schemaName,
request.parsedSchema,
)
: loadSchemaInfo(request.schemaPath!);

// Validate that parameter values appear in the request.
// If a value was inferred by the LLM (not in the request), strip it
Expand Down
11 changes: 11 additions & 0 deletions ts/packages/actionGrammar/src/generation/schemaReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import fs from "fs";
import {
fromJSONParsedActionSchema,
ParsedActionSchema,
ParsedActionSchemaJSON,
ActionSchemaTypeDefinition,
ParamSpec,
Expand Down Expand Up @@ -58,6 +59,16 @@ export function loadSchemaInfo(pasJsonPath: string): SchemaInfo {
// Extract schema name from path - use path.basename to avoid regex issues
const fileName = pasJsonPath.split(/[/\\]/).pop() || "";
const schemaName = fileName.replace(/\.pas\.json$/, "") || "unknown";
return getSchemaInfoFromParsedSchema(schemaName, parsedSchema);
}

/**
* Extract schema info from an already-loaded ParsedActionSchema
*/
export function getSchemaInfoFromParsedSchema(
schemaName: string,
parsedSchema: ParsedActionSchema,
): SchemaInfo {
const actions = new Map<string, ActionInfo>();
const entityTypes = new Set<string>();

Expand Down
81 changes: 30 additions & 51 deletions ts/packages/actionGrammar/src/grammarMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,77 +1,56 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import fs from "fs";
import {
fromJSONParsedActionSchema,
ParsedActionSchemaJSON,
ActionSchemaTypeDefinition,
} from "@typeagent/action-schema";
import { ParsedActionSchema } from "@typeagent/action-schema";
import { Grammar } from "./grammarTypes.js";

/**
* Enrich a Grammar with checked variable metadata from a .pas.json schema file
* Enrich a Grammar with checked variable metadata from a parsed action schema
*
* Reads the schema file to find parameters with checked_wildcard paramSpec
* Finds parameters with checked_wildcard paramSpec
* and adds their variable names to grammar.checkedVariables
*
* @param grammar The grammar to enrich
* @param schemaPath Path to the .pas.json file
* @param parsedSchema The parsed action schema
* @returns The enriched grammar (modifies in place and returns for chaining)
*/
export function enrichGrammarWithCheckedVariables(
grammar: Grammar,
schemaPath: string,
parsedSchema: ParsedActionSchema,
): Grammar {
try {
const jsonContent = fs.readFileSync(schemaPath, "utf8");
const json: ParsedActionSchemaJSON = JSON.parse(jsonContent);
const parsedSchema = fromJSONParsedActionSchema(json);
const checkedVariables = new Set<string>();

const checkedVariables = new Set<string>();
// Process each action to find parameters with checked_wildcard paramSpec
for (const actionDef of parsedSchema.actionSchemas.values()) {
const paramSpecs = actionDef.paramSpecs;

// Process each action to find parameters with checked_wildcard paramSpec
for (const [
_actionName,
actionDef,
] of parsedSchema.actionSchemas.entries()) {
const paramSpecs = (actionDef as ActionSchemaTypeDefinition)
.paramSpecs;

if (!paramSpecs || typeof paramSpecs !== "object") {
continue;
}
if (!paramSpecs || typeof paramSpecs !== "object") {
continue;
}

// Find all parameters with checked_wildcard paramSpec
for (const [paramName, paramSpec] of Object.entries(paramSpecs)) {
if (paramSpec === "checked_wildcard") {
// Add the parameter name as a checked variable
// Also handle array element specs (e.g., "artists.*" -> "artist")
if (paramName.endsWith(".*")) {
const baseName = paramName.slice(0, -2);
// Convert plural to singular for grammar variable names
const singularName = getSingularVariableName(baseName);
checkedVariables.add(singularName);
} else {
checkedVariables.add(paramName);
}
// Find all parameters with checked_wildcard paramSpec
for (const [paramName, paramSpec] of Object.entries(paramSpecs)) {
if (paramSpec === "checked_wildcard") {
// Add the parameter name as a checked variable
// Also handle array element specs (e.g., "artists.*" -> "artist")
if (paramName.endsWith(".*")) {
const baseName = paramName.slice(0, -2);
// Convert plural to singular for grammar variable names
const singularName = getSingularVariableName(baseName);
checkedVariables.add(singularName);
} else {
checkedVariables.add(paramName);
}
}
}
}

// Add to grammar
if (checkedVariables.size > 0) {
grammar.checkedVariables = checkedVariables;
}

return grammar;
} catch (error) {
// If schema file doesn't exist or can't be read, return grammar unchanged
console.warn(
`Could not read schema file ${schemaPath} for checked variable metadata: ${error}`,
);
return grammar;
// Add to grammar
if (checkedVariables.size > 0) {
grammar.checkedVariables = checkedVariables;
}

return grammar;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions ts/packages/agentSdk/src/agentInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ export type GrammarContent = { format: GrammarFormat; content: string };
export type SchemaManifest = {
description: string;
schemaType: string | SchemaTypeNames; // string if there are only action schemas
schemaFile: string | SchemaContent;
compiledSchemaFile?: string; // path to .pas.json file for grammar generation metadata extraction
grammarFile?: string | GrammarContent;
schemaFile: string | SchemaContent; // path relative to the manifest file (resolved to absolute at load time)
originalSchemaFile?: string; // path to the original .ts schema source for code paths not yet converted to use .pas format (relative to the manifest file)
grammarFile?: string | GrammarContent; // path relative to the manifest file (resolved to absolute at load time)
injected?: boolean; // whether the translator is injected into other domains, default is false
cached?: boolean; // whether the translator's action should be cached, default is true
streamingActions?: string[];
Expand Down
1 change: 1 addition & 0 deletions ts/packages/agents/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"build": {
"dependsOn": [
"^build",
"asc",
"build:extension",
"build:views",
"tsc:agent",
Expand Down
4 changes: 2 additions & 2 deletions ts/packages/agents/browser/src/agent/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
},
"schema": {
"description": "Browser agent that allows you control browser windows and perform actions such as web browsing (opening, closing, reading pages), opening a new tab, closing a tab, scrolling, zooming and navigating to a specific URL.",
"schemaFile": "./browserActionSchema.mts",
"compiledSchemaFile": "agents/browser/dist/agent/browserSchema.pas.json",
"originalSchemaFile": "./browserActionSchema.mts",
"schemaFile": "../../dist/agent/browserSchema.pas.json",
"grammarFile": "../../dist/agent/browserSchema.ag.json",
"schemaType": {
"action": "BrowserActions",
Expand Down
4 changes: 2 additions & 2 deletions ts/packages/agents/calendar/src/calendarManifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"description": "Agent integration with MS Graph's calendar",
"schema": {
"description": "Calendar agent that keeps track of important dates and events. Use it to schedule appointments, set reminders, and organize activities.",
"schemaFile": "./calendarActionsSchemaV3.ts",
"compiledSchemaFile": "agents/calendar/dist/calendarSchema.pas.json",
"originalSchemaFile": "./calendarActionsSchemaV3.ts",
"schemaFile": "../dist/calendarSchema.pas.json",
"grammarFile": "../dist/calendarSchema.ag.json",
"schemaType": "CalendarActionV3"
}
Expand Down
28 changes: 14 additions & 14 deletions ts/packages/agents/code/src/codeManifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"defaultEnabled": false,
"schema": {
"description": "Code agent helps you with productivity in using an editor and performing actions like creating files, editor customization, writing code, intelligent code suggestions, real-time error detection, debugging, and source control tasks etc.",
"schemaFile": "./codeActionsSchema.ts",
"compiledSchemaFile": "agents/code/dist/codeSchema.pas.json",
"originalSchemaFile": "./codeActionsSchema.ts",
"schemaFile": "../dist/codeSchema.pas.json",
"schemaType": {
"action": "CodeActions",
"activity": "CodeActivity"
Expand All @@ -15,48 +15,48 @@
"code-debug": {
"schema": {
"description": "Code agent that helps you debug code including handling actions like showing the debug panel, adding/toggling breakpoints, stepping in/out of code etc.",
"schemaFile": "./vscode/debugActionsSchema.ts",
"compiledSchemaFile": "agents/code/dist/debugSchema.pas.json",
"originalSchemaFile": "./vscode/debugActionsSchema.ts",
"schemaFile": "../dist/debugSchema.pas.json",
"schemaType": "CodeDebugActions"
}
},
"code-display": {
"schema": {
"description": "Code agent that helps you work with display keyboard bindings, Zoom in, Zoom out, do text search and replace, show extensions etc.",
"schemaFile": "./vscode/displayActionsSchema.ts",
"compiledSchemaFile": "agents/code/dist/displaySchema.pas.json",
"originalSchemaFile": "./vscode/displayActionsSchema.ts",
"schemaFile": "../dist/displaySchema.pas.json",
"schemaType": "CodeDisplayActions"
}
},
"code-general": {
"schema": {
"description": "Code agent that helps you perform actions like finding a file, go to a symbol or a line in a file, Open new vscode window, show the command palette, user settings json etc.",
"schemaFile": "./vscode/generalActionsSchema.ts",
"compiledSchemaFile": "agents/code/dist/generalSchema.pas.json",
"originalSchemaFile": "./vscode/generalActionsSchema.ts",
"schemaFile": "../dist/generalSchema.pas.json",
"schemaType": "CodeGeneralActions"
}
},
"code-editor": {
"schema": {
"description": "Code agent that helps you perform vscode editor actions like create a new file, go to a reference, reveal a declaration, clipboard copy or paste, add a comment line etc.",
"schemaFile": "./vscode/editorCodeActionsSchema.ts",
"compiledSchemaFile": "agents/code/dist/editorSchema.pas.json",
"originalSchemaFile": "./vscode/editorCodeActionsSchema.ts",
"schemaFile": "../dist/editorSchema.pas.json",
"schemaType": "EditorCodeActions"
}
},
"code-workbench": {
"schema": {
"description": "Code agent that helps you perform vscode workbench actions like open a file, close a file etc.",
"schemaFile": "./vscode/workbenchCommandActionsSchema.ts",
"compiledSchemaFile": "agents/code/dist/workbenchSchema.pas.json",
"originalSchemaFile": "./vscode/workbenchCommandActionsSchema.ts",
"schemaFile": "../dist/workbenchSchema.pas.json",
"schemaType": "CodeWorkbenchActions"
}
},
"code-extension": {
"schema": {
"description": "Code agent that helps you perform vscode extension actions like show, install, update, enable, disable, uninstall extensions etc.",
"schemaFile": "./vscode/extensionsActionsSchema.ts",
"compiledSchemaFile": "agents/code/dist/extensionSchema.pas.json",
"originalSchemaFile": "./vscode/extensionsActionsSchema.ts",
"schemaFile": "../dist/extensionSchema.pas.json",
"schemaType": "CodeWorkbenchExtensionActions"
}
}
Expand Down
32 changes: 16 additions & 16 deletions ts/packages/agents/desktop/src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,71 +4,71 @@
"defaultEnabled": false,
"schema": {
"description": "Desktop agent that allows you to manage the programs running on a computer, change Windows settings, control the desktop environment, and perform actions such as opening a file, closing a window, tiling windows, launching a program, maximizing windows, adjusting display settings, managing privacy settings, and controlling system features.",
"schemaFile": "./actionsSchema.ts",
"compiledSchemaFile": "agents/desktop/dist/desktopSchema.pas.json",
"originalSchemaFile": "./actionsSchema.ts",
"schemaFile": "../dist/desktopSchema.pas.json",
"grammarFile": "../dist/desktopSchema.ag.json",
"schemaType": "DesktopActions"
},
"subActionManifests": {
"desktop-display": {
"schema": {
"description": "Desktop agent for display and screen settings including night light, color temperature, scaling, orientation, and rotation lock.",
"schemaFile": "./windows/displayActionsSchema.ts",
"compiledSchemaFile": "agents/desktop/dist/displaySchema.pas.json",
"originalSchemaFile": "./windows/displayActionsSchema.ts",
"schemaFile": "../dist/displaySchema.pas.json",
"grammarFile": "../dist/displaySchema.ag.json",
"schemaType": "DesktopDisplayActions"
}
},
"desktop-personalization": {
"schema": {
"description": "Desktop agent for personalization settings including transparency effects, title bar colors, and high contrast themes.",
"schemaFile": "./windows/personalizationActionsSchema.ts",
"compiledSchemaFile": "agents/desktop/dist/personalizationSchema.pas.json",
"originalSchemaFile": "./windows/personalizationActionsSchema.ts",
"schemaFile": "../dist/personalizationSchema.pas.json",
"grammarFile": "../dist/personalizationSchema.ag.json",
"schemaType": "DesktopPersonalizationActions"
}
},
"desktop-taskbar": {
"schema": {
"description": "Desktop agent for taskbar settings including auto-hide, alignment, task view, widgets, badges, and system clock options.",
"schemaFile": "./windows/taskbarActionsSchema.ts",
"compiledSchemaFile": "agents/desktop/dist/taskbarSchema.pas.json",
"originalSchemaFile": "./windows/taskbarActionsSchema.ts",
"schemaFile": "../dist/taskbarSchema.pas.json",
"grammarFile": "../dist/taskbarSchema.ag.json",
"schemaType": "DesktopTaskbarActions"
}
},
"desktop-input": {
"schema": {
"description": "Desktop agent for mouse and touchpad settings including cursor speed, scroll lines, button configuration, pointer precision, and touchpad controls.",
"schemaFile": "./windows/inputActionsSchema.ts",
"compiledSchemaFile": "agents/desktop/dist/inputSchema.pas.json",
"originalSchemaFile": "./windows/inputActionsSchema.ts",
"schemaFile": "../dist/inputSchema.pas.json",
"grammarFile": "../dist/inputSchema.ag.json",
"schemaType": "DesktopInputActions"
}
},
"desktop-privacy": {
"schema": {
"description": "Desktop agent for privacy settings to manage microphone, camera, and location access for applications.",
"schemaFile": "./windows/privacyActionsSchema.ts",
"compiledSchemaFile": "agents/desktop/dist/privacySchema.pas.json",
"originalSchemaFile": "./windows/privacyActionsSchema.ts",
"schemaFile": "../dist/privacySchema.pas.json",
"grammarFile": "../dist/privacySchema.ag.json",
"schemaType": "DesktopPrivacyActions"
}
},
"desktop-power": {
"schema": {
"description": "Desktop agent for power management settings including battery saver and power mode configuration.",
"schemaFile": "./windows/powerActionsSchema.ts",
"compiledSchemaFile": "agents/desktop/dist/powerSchema.pas.json",
"originalSchemaFile": "./windows/powerActionsSchema.ts",
"schemaFile": "../dist/powerSchema.pas.json",
"grammarFile": "../dist/powerSchema.ag.json",
"schemaType": "DesktopPowerActions"
}
},
"desktop-system": {
"schema": {
"description": "Desktop agent for system settings including accessibility features, file explorer options, time settings, focus assist, multi-monitor configuration, and other system-level controls.",
"schemaFile": "./windows/systemActionsSchema.ts",
"compiledSchemaFile": "agents/desktop/dist/systemSchema.pas.json",
"originalSchemaFile": "./windows/systemActionsSchema.ts",
"schemaFile": "../dist/systemSchema.pas.json",
"grammarFile": "../dist/systemSchema.ag.json",
"schemaType": "DesktopSystemActions"
}
Expand Down
Loading
Loading