Skip to content

Commit

Permalink
Clean up and fix command line (#472)
Browse files Browse the repository at this point in the history
- Switch to use run.js in pnpm run scripts to not use `ts-node`
- Remove `@correct` command for explanation that is no longer used
- update corepack pnpm version
  • Loading branch information
curtisman authored Dec 10, 2024
1 parent 19a140f commit 420f16a
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 103 deletions.
5 changes: 4 additions & 1 deletion ts/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@
{"name": "memoryProviders", "rootPath": "examples/memoryProviders"},
{"name": "typeagent", "rootPath": "packages/typeagent"}
],
"jest.runMode": "on-demand"
"jest.runMode": "on-demand",
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
3 changes: 2 additions & 1 deletion ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"check:policy:fix": "node tools/scripts/repo-policy-check.mjs --fix",
"clean": "fluid-build . -t clean",
"cli": "pnpm -C packages/cli run start",
"cli:dev": "pnpm -C packages/cli run start:dev",
"elevate": "node tools/scripts/elevate.js",
"getKeys": "node tools/scripts/getKeys.mjs",
"knowledgeVisualizer": "pnpm -C packages/knowledgeVisualizer exec npm run start",
Expand All @@ -42,7 +43,7 @@
"markdown-link-check": "^3.12.2",
"prettier": "^3.2.5"
},
"packageManager": "pnpm@9.12.3+sha512.cce0f9de9c5a7c95bef944169cc5dfe8741abfb145078c0d508b868056848a87c81e626246cb60967cbd7fd29a6c062ef73ff840d96b3c86c40ac92cf4a813ee",
"packageManager": "pnpm@9.15.0+sha512.76e2379760a4328ec4415815bcd6628dee727af3779aaa4c914e3944156c4299921a89f976381ee107d41f12cfa4b66681ca9c718f0668fa0831ed4c6d8ba56c",
"engines": {
"node": ">=18",
"pnpm": ">=9"
Expand Down
25 changes: 0 additions & 25 deletions ts/packages/cache/src/cache/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,31 +290,6 @@ export class AgentCache {
}
}

public async correctExplanation(
requestAction: RequestAction,
explanation: object,
correction: string,
): Promise<ProcessExplanationResult> {
const startTime = performance.now();
const actions = requestAction.actions;
const explainer = this.getExplainerForActions(actions);

if (!explainer.correct) {
throw new Error("Explainer doesn't support correction");
}
const result = await explainer.correct(
requestAction,
explanation,
correction,
);

return {
explanation: result,
elapsedMs: performance.now() - startTime,
toPrettyString: explainer.toPrettyString,
};
}

public async import(data: ExplanationData[]) {
return this._constructionStore.import(
data,
Expand Down
6 changes: 5 additions & 1 deletion ts/packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ TypeAgent CLI includes addition commands to help with development.

## Running

After setting up and building at the workspace root, there are several additional ways to start the CLI in this directory.
After setting up and building at the workspace root (repo `ts` directory), there are several additional ways to start the CLI in this directory.

### Workspace root (repo `ts` directory)

At the repo `ts` directory, run `pnpm run cli` or `pnpm run cli:dev` to run the development version.

### Globally Link the package

Expand Down
8 changes: 4 additions & 4 deletions ts/packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
"clean": "rimraf --glob dist *.tsbuildinfo *.done.build.log",
"prettier": "prettier --check . --ignore-path ../../.prettierignore",
"prettier:fix": "prettier --write . --ignore-path ../../.prettierignore",
"regen": "node ./bin/dev.js data regenerate -f ../dispatcher/test/data/**/**/*.json ../dispatcher/test/repo/explanations/**/**/*.json",
"regen:builtin": "node ./bin/dev.js data regenerate --builtin player",
"regen": "node ./bin/run.js data regenerate -f ../dispatcher/test/data/**/**/*.json ../dispatcher/test/repo/explanations/**/**/*.json",
"regen:builtin": "node ./bin/run.js data regenerate --builtin v5",
"start": "node ./bin/run.js",
"start:dev": "node ./bin/dev.js",
"stat": "node ./bin/dev.js data stat -f ../dispatcher/test/data/**/**/*.json ../dispatcher/test/repo/explanations/**/**/*.json",
"start:dev": "node --loader ts-node/esm --no-warnings=ExperimentalWarning ./bin/dev.js",
"stat": "node ./bin/run.js data stat -f ../dispatcher/test/data/**/**/*.json ../dispatcher/test/repo/explanations/**/**/*.json",
"tsc": "tsc -b"
},
"oclif": {
Expand Down
2 changes: 0 additions & 2 deletions ts/packages/dispatcher/src/dispatcher/dispatcherAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
import { RequestCommandHandler } from "../handlers/requestCommandHandler.js";
import { TranslateCommandHandler } from "../handlers/translateCommandHandler.js";
import { ExplainCommandHandler } from "../handlers/explainCommandHandler.js";
import { CorrectCommandHandler } from "../handlers/correctCommandHandler.js";
import { ActionContext, AppAction, AppAgent } from "@typeagent/agent-sdk";
import { CommandHandlerContext } from "../internal.js";
import { createActionResultNoDisplay } from "@typeagent/agent-sdk/helpers/action";
Expand All @@ -28,7 +27,6 @@ const dispatcherHandlers: CommandHandlerTable = {
request: new RequestCommandHandler(),
translate: new TranslateCommandHandler(),
explain: new ExplainCommandHandler(),
correct: new CorrectCommandHandler(),
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,27 +108,12 @@ export type CommandHandlerContext = {

batchMode: boolean;

// For @correct
lastRequestAction?: RequestAction;
lastExplanation?: object;

streamingActionContext?: ActionContextWithClose | undefined;

metricsManager?: RequestMetricsManager | undefined;
commandProfiler?: Profiler | undefined;
};

export function updateCorrectionContext(
context: CommandHandlerContext,
requestAction: RequestAction,
explanationResult: GenericExplanationResult,
) {
if (explanationResult.success) {
context.lastExplanation = explanationResult.data;
context.lastRequestAction = requestAction;
}
}

export function getTranslatorForSchema(
context: CommandHandlerContext,
translatorName: string,
Expand Down
37 changes: 0 additions & 37 deletions ts/packages/dispatcher/src/handlers/correctCommandHandler.ts

This file was deleted.

10 changes: 1 addition & 9 deletions ts/packages/dispatcher/src/handlers/explainCommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import {
displayResult,
displayStatus,
} from "@typeagent/agent-sdk/helpers/display";
import {
CommandHandlerContext,
updateCorrectionContext,
} from "./common/commandHandlerContext.js";
import { CommandHandlerContext } from "./common/commandHandlerContext.js";
import { RequestAction, printProcessRequestActionResult } from "agent-cache";

export class ExplainCommandHandler implements CommandHandler {
Expand All @@ -35,11 +32,6 @@ export class ExplainCommandHandler implements CommandHandler {
requestAction,
false,
);
updateCorrectionContext(
systemContext,
requestAction,
result.explanationResult.explanation,
);
displayResult((log) => {
printProcessRequestActionResult(result, log);
}, context);
Expand Down
8 changes: 0 additions & 8 deletions ts/packages/dispatcher/src/handlers/requestCommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
CommandHandlerContext,
getTranslatorForSchema,
getTranslatorForSelectedActions,
updateCorrectionContext,
} from "./common/commandHandlerContext.js";

import {
Expand Down Expand Up @@ -965,13 +964,6 @@ async function requestExplain(
const processRequestActionResult = await processRequestActionP;
notifyExplained(processRequestActionResult);

// Only capture if done synchronously.
updateCorrectionContext(
context,
requestAction,
processRequestActionResult.explanationResult.explanation,
);

printProcessRequestActionResult(processRequestActionResult);
}
}
Expand Down

0 comments on commit 420f16a

Please sign in to comment.