Skip to content

Commit

Permalink
Fix action command handler with no parameters (#640)
Browse files Browse the repository at this point in the history
Also fix the test script that should call test:local in package.json
  • Loading branch information
curtisman authored Jan 30, 2025
1 parent b7aacdd commit 9dd2d10
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 14 deletions.
2 changes: 1 addition & 1 deletion ts/examples/memoryProviders/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"clean": "rimraf --glob dist *.tsbuildinfo *.done.build.log",
"prettier": "prettier --check . --ignore-path ../../.prettierignore",
"prettier:fix": "prettier --write . --ignore-path ../../.prettierignore",
"test": "npm run test",
"test": "npm run test:local",
"test:local": "node --no-warnings --experimental-vm-modules ./node_modules/jest/bin/jest.js --testPathPattern=\".*\\.spec\\.js\"",
"test:local:debug": "node --inspect-brk --no-warnings --experimental-vm-modules ./node_modules/jest/bin/jest.js --testPathPattern=\".*\\.spec\\.js\"",
"tsc": "tsc -b"
Expand Down
2 changes: 1 addition & 1 deletion ts/packages/actionSchema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"clean": "rimraf --glob dist *.tsbuildinfo *.done.build.log",
"prettier": "prettier --check . --ignore-path ../../.prettierignore",
"prettier:fix": "prettier --write . --ignore-path ../../prettierignore",
"test": "npm run test",
"test": "npm run test:local",
"test:local": "node --no-warnings --experimental-vm-modules ./node_modules/jest/bin/jest.js --testPathPattern=\".*\\.spec\\.js\"",
"test:local:debug": "node --inspect-brk --no-warnings --experimental-vm-modules ./node_modules/jest/bin/jest.js --testPathPattern=\".*\\.spec\\.js\"",
"tsc": "tsc -b"
Expand Down
2 changes: 1 addition & 1 deletion ts/packages/actionSchema/src/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function validateObject(
ignoreExtraneous?.includes(actualField) !== true
) {
const fullName = name ? `${name}.${actualField}` : actualField;
throw new Error(`Extraneous property ${fullName}`);
throw new Error(`Extraneous property '${fullName}'`);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion ts/packages/agents/test/src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ async function executeAction(
case "add":
const { a, b } = action.parameters;
return createActionResult(`The sum of ${a} and ${b} is ${a + b}`);
case "random":
return createActionResult(`Random number: ${Math.random()}`);
default:
throw new Error(`Unknown action: ${action.actionName}`);
throw new Error(`Unknown action: ${(action as any).actionName}`);
}
}
6 changes: 5 additions & 1 deletion ts/packages/agents/test/src/schema.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

export type TestActions = AddAction;
export type TestActions = AddAction | RandomNumberAction;
type AddAction = {
actionName: "add";
parameters: {
a: number;
b: number;
};
};

type RandomNumberAction = {
actionName: "random";
};
2 changes: 1 addition & 1 deletion ts/packages/aiclient/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"clean": "rimraf --glob dist *.tsbuildinfo *.done.build.log",
"prettier": "prettier --check . --ignore-path ../../.prettierignore",
"prettier:fix": "prettier --write . --ignore-path ../../prettierignore",
"test": "npm run test",
"test": "npm run test:local",
"test:local": "node --no-warnings --experimental-vm-modules ./node_modules/jest/bin/jest.js --testPathPattern=\".*\\.spec\\.js\"",
"test:local:debug": "node --inspect-brk --no-warnings --experimental-vm-modules ./node_modules/jest/bin/jest.js --testPathPattern=\".*\\.spec\\.js\"",
"tsc": "tsc -b"
Expand Down
2 changes: 1 addition & 1 deletion ts/packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"prettier": "prettier --check . --ignore-path ../../.prettierignore",
"prettier:fix": "prettier --write . --ignore-path ../../.prettierignore",
"start": "node ./dist/index.js",
"test": "npm run test",
"test": "npm run test:local",
"test:local": "node --no-warnings --experimental-vm-modules ./node_modules/jest/bin/jest.js --testPathPattern=\".*\\.spec\\.js\"",
"test:local:debug": "node --inspect-brk --no-warnings --experimental-vm-modules ./node_modules/jest/bin/jest.js --testPathPattern=\".*\\.spec\\.js\"",
"tsc": "tsc -b"
Expand Down
2 changes: 1 addition & 1 deletion ts/packages/cache/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"clean": "rimraf --glob dist *.tsbuildinfo *.done.build.log",
"prettier": "prettier --check . --ignore-path ../../.prettierignore",
"prettier:fix": "prettier --write . --ignore-path ../../.prettierignore",
"test": "npm run test",
"test": "npm run test:local",
"test:local": "node --no-warnings --experimental-vm-modules ./node_modules/jest/bin/jest.js --testPathPattern=\".*\\.spec\\.js\"",
"test:local:debug": "node --inspect-brk --no-warnings --experimental-vm-modules ./node_modules/jest/bin/jest.js --testPathPattern=\".*\\.spec\\.js\"",
"tsc": "tsc -b"
Expand Down
2 changes: 1 addition & 1 deletion ts/packages/commonUtils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"clean": "rimraf --glob dist *.tsbuildinfo *.done.build.log",
"prettier": "prettier --check . --ignore-path ../../.prettierignore",
"prettier:fix": "prettier --write . --ignore-path ../../.prettierignore",
"test": "npm run test",
"test": "npm run test:local",
"test:local": "node --no-warnings --experimental-vm-modules ./node_modules/jest/bin/jest.js --testPathPattern=\".*\\.spec\\.js\"",
"test:local:debug": "node --inspect-brk --no-warnings --experimental-vm-modules ./node_modules/jest/bin/jest.js --testPathPattern=\".*\\.spec\\.js\"",
"tsc": "tsc -b"
Expand Down
2 changes: 1 addition & 1 deletion ts/packages/dispatcher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"clean": "rimraf --glob dist *.tsbuildinfo *.done.build.log",
"prettier": "prettier --check . --ignore-path ../../.prettierignore",
"prettier:fix": "prettier --write . --ignore-path ../../.prettierignore",
"test": "npm run test",
"test": "npm run test:local",
"test:local": "node --no-warnings --experimental-vm-modules ./node_modules/jest/bin/jest.js --testPathPattern=\".*\\.spec\\.js\"",
"test:local:debug": "node --inspect-brk --no-warnings --experimental-vm-modules ./node_modules/jest/bin/jest.js --testPathPattern=\".*\\.spec\\.js\"",
"tsc": "tsc -b"
Expand Down
5 changes: 4 additions & 1 deletion ts/packages/dispatcher/src/context/system/systemAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,12 @@ class ActionCommandHandler implements CommandHandler {
const action: AppAction = {
translatorName,
actionName,
parameters: params.flags.parameters,
};

if (params.flags.parameters !== undefined) {
action.parameters = params.flags.parameters;
}

validateAction(actionSchema, action, true);

return executeActions(
Expand Down
6 changes: 6 additions & 0 deletions ts/packages/dispatcher/test/provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ describe("dispatcher", () => {
expect(output[1].message).toBe("The sum of 1 and 2 is 3");
});

it("action command no parameters", async () => {
await dispatcher.processCommand("@action test random");

expect(output).toHaveLength(2);
expect(output[1].message).toMatch(/Random number: [0-9.]+/);
});
const errorCommands = [
{
name: "Empty Command",
Expand Down
2 changes: 1 addition & 1 deletion ts/packages/knowledgeProcessor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"clean": "rimraf --glob dist *.tsbuildinfo *.done.build.log",
"prettier": "prettier --check . --ignore-path ../../.prettierignore",
"prettier:fix": "prettier --write . --ignore-path ../../.prettierignore",
"test": "npm run test",
"test": "npm run test:local",
"test:local": "node --no-warnings --experimental-vm-modules ./node_modules/jest/bin/jest.js --testPathPattern=\".*\\.spec\\.js\"",
"test:local:debug": "node --inspect-brk --no-warnings --experimental-vm-modules ./node_modules/jest/bin/jest.js --testPathPattern=\".*\\.spec\\.js\"",
"tsc": "tsc -b"
Expand Down
2 changes: 1 addition & 1 deletion ts/packages/telemetry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"clean": "rimraf --glob dist *.tsbuildinfo *.done.build.log",
"prettier": "prettier --check . --ignore-path ../../.prettierignore",
"prettier:fix": "prettier --write . --ignore-path ../../.prettierignore",
"test": "npm run test",
"test": "npm run test:local",
"test:local": "node --no-warnings --experimental-vm-modules ./node_modules/jest/bin/jest.js --testPathPattern=\".*\\.spec\\.js\"",
"test:local:debug": "node --inspect-brk --no-warnings --experimental-vm-modules ./node_modules/jest/bin/jest.js --testPathPattern=\".*\\.spec\\.js\"",
"tsc": "tsc -b"
Expand Down
2 changes: 1 addition & 1 deletion ts/packages/typeagent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"clean": "rimraf --glob dist *.tsbuildinfo *.done.build.log",
"prettier": "prettier --check . --ignore-path ../../.prettierignore",
"prettier:fix": "prettier --write . --ignore-path ../../prettierignore",
"test": "npm run test",
"test": "npm run test:local",
"test:local": "node --no-warnings --experimental-vm-modules ./node_modules/jest/bin/jest.js --testPathPattern=\".*\\.spec\\.js\"",
"test:local:debug": "node --inspect-brk --no-warnings --experimental-vm-modules ./node_modules/jest/bin/jest.js --testPathPattern=\".*\\.spec\\.js\"",
"tsc": "tsc -b"
Expand Down

0 comments on commit 9dd2d10

Please sign in to comment.