Skip to content

Commit

Permalink
refactor(agent): Remove unused tests. Rename StdIO to JsonLineServer. (
Browse files Browse the repository at this point in the history
…TabbyML#1224)

* chore(agent): remove unused tests.

* refactor(agent): rename StdIO -> JsonLineServer.
  • Loading branch information
icycodes authored Jan 17, 2024
1 parent 71fe585 commit 7cf219d
Show file tree
Hide file tree
Showing 14 changed files with 11 additions and 301 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type CancellationRequest = [
},
];

type StdIORequest = AgentFunctionRequest<keyof AgentFunction> | CancellationRequest;
type JsonLineRequest = AgentFunctionRequest<keyof AgentFunction> | CancellationRequest;

type AgentFunctionResponse<T extends keyof AgentFunction> = [
id: number, // Matched request id
Expand All @@ -36,16 +36,16 @@ type CancellationResponse = [
data: boolean | null,
];

type StdIOResponse = AgentFunctionResponse<keyof AgentFunction> | AgentEventNotification | CancellationResponse;
type JsonLineResponse = AgentFunctionResponse<keyof AgentFunction> | AgentEventNotification | CancellationResponse;

/**
* Every request and response should be single line JSON string and end with a newline.
*/
export class StdIO {
export class JsonLineServer {
private readonly process: NodeJS.Process = process;
private readonly inStream: NodeJS.ReadStream = process.stdin;
private readonly outStream: NodeJS.WriteStream = process.stdout;
private readonly logger = rootLogger.child({ component: "StdIO" });
private readonly logger = rootLogger.child({ component: "JsonLineServer" });

private abortControllers: { [id: string]: AbortController } = {};

Expand All @@ -54,9 +54,9 @@ export class StdIO {
constructor() {}

private async handleLine(line: string) {
let request: StdIORequest;
let request: JsonLineRequest;
try {
request = JSON.parse(line) as StdIORequest;
request = JSON.parse(line) as JsonLineRequest;
} catch (error) {
this.logger.error({ error }, `Failed to parse request: ${line}`);
return;
Expand All @@ -67,9 +67,9 @@ export class StdIO {
this.logger.debug({ response }, "Sent response");
}

private async handleRequest(request: StdIORequest): Promise<StdIOResponse> {
private async handleRequest(request: JsonLineRequest): Promise<JsonLineResponse> {
let requestId: number = 0;
const response: StdIOResponse = [0, null];
const response: JsonLineResponse = [0, null];
const abortController = new AbortController();
try {
if (!this.agent) {
Expand Down Expand Up @@ -119,7 +119,7 @@ export class StdIO {
return false;
}

private sendResponse(response: StdIOResponse): void {
private sendResponse(response: JsonLineResponse): void {
this.outStream.write(JSON.stringify(response) + "\n");
}

Expand Down
4 changes: 2 additions & 2 deletions clients/tabby-agent/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/env node

import { TabbyAgent } from "./TabbyAgent";
import { StdIO } from "./StdIO";
import { JsonLineServer } from "./JsonLineServer";
import { LspServer } from "./LspServer";

const args = process.argv.slice(2);
Expand All @@ -10,7 +10,7 @@ let server;
if (args.indexOf("--lsp") >= 0) {
server = new LspServer();
} else {
server = new StdIO();
server = new JsonLineServer();
}
const agent = new TabbyAgent();
server.bind(agent);
Expand Down
15 changes: 0 additions & 15 deletions clients/tabby-agent/tests/bad_cases/0-javascript.js

This file was deleted.

7 changes: 0 additions & 7 deletions clients/tabby-agent/tests/bad_cases/1-python.py

This file was deleted.

3 changes: 0 additions & 3 deletions clients/tabby-agent/tests/bad_cases/2-typescript.ts

This file was deleted.

199 changes: 0 additions & 199 deletions clients/tabby-agent/tests/golden.test.ts

This file was deleted.

6 changes: 0 additions & 6 deletions clients/tabby-agent/tests/golden/0-python.py

This file was deleted.

17 changes: 0 additions & 17 deletions clients/tabby-agent/tests/golden/1-python.py

This file was deleted.

11 changes: 0 additions & 11 deletions clients/tabby-agent/tests/golden/2-typescript.ts

This file was deleted.

1 change: 0 additions & 1 deletion clients/tabby-agent/tests/golden/3-typescript.ts

This file was deleted.

9 changes: 0 additions & 9 deletions clients/tabby-agent/tests/golden/4-typescript.ts

This file was deleted.

9 changes: 0 additions & 9 deletions clients/tabby-agent/tests/golden/5-go.go

This file was deleted.

9 changes: 0 additions & 9 deletions clients/tabby-agent/tests/golden/6-rust.rs

This file was deleted.

4 changes: 0 additions & 4 deletions clients/tabby-agent/tests/golden/7-ruby.rb

This file was deleted.

0 comments on commit 7cf219d

Please sign in to comment.