Skip to content

Commit 494ce33

Browse files
authored
Initial work for adding host bridge client for external hosts (RooCodeInc#4144)
* Add a host bridge client that uses the appropriate underlying client (vscode or external grpc service) Add placeholders for the external clients. Move the hosts directory under src, add an alias in tsconfig.json for @hosts * Update package.json
1 parent 0ae2dc3 commit 494ce33

File tree

15 files changed

+64
-21
lines changed

15 files changed

+64
-21
lines changed

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ src/shared/proto/host/*.ts
3232
webview-ui/src/services/grpc-client.ts
3333
# Standalone
3434
src/standalone/server-setup.ts
35-
src/standalone/services/host-grpc-client.ts
3635
# Host bridge
37-
hosts/vscode/*/methods.ts
38-
hosts/vscode/*/index.ts
39-
hosts/vscode/host-grpc-service-config.ts
36+
src/hosts/vscode/*/methods.ts
37+
src/hosts/vscode/*/index.ts
38+
src/hosts/vscode/client/host-grpc-client.ts
39+
src/hosts/vscode/host-grpc-service-config.ts

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@
331331
"watch:tsc": "tsc --noEmit --watch --project tsconfig.json",
332332
"package": "npm run check-types && npm run build:webview && npm run lint && node esbuild.js --production",
333333
"protos": "node proto/build-proto.js && node scripts/generate-server-setup.mjs",
334-
"postprotos": "prettier src/shared/proto src/core/controller webview-ui/src/services src/standalone/server-setup.ts --write --log-level silent",
334+
"postprotos": "prettier src/shared/proto src/core/controller src/hosts/ webview-ui/src/services src/standalone/server-setup.ts --write --log-level silent",
335335
"compile-tests": "node ./scripts/build-tests.js",
336336
"watch-tests": "tsc -p . -w --outDir out",
337337
"pretest": "npm run compile-tests && npm run compile && npm run compile-standalone && npm run lint",

proto/build-proto.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ const tsProtoPlugin = isWindows
2121
? path.join(ROOT_DIR, "node_modules", ".bin", "protoc-gen-ts_proto.cmd") // Use the .bin directory path for Windows
2222
: require.resolve("ts-proto/protoc-gen-ts_proto")
2323

24+
const TS_PROTO_OPTIONS = [
25+
"env=node",
26+
"esModuleInterop=true",
27+
28+
"outputIndex=true", // output an index file for each package which exports all protos in the package.
29+
"outputServices=generic-definitions",
30+
31+
"useOptionals=messages", // Message fields are optional, scalars are not.
32+
"useDate=false", // Timestamp fields will not be automatically converted to Date.
33+
]
34+
2435
// List of gRPC services
2536
// To add a new service, simply add it to this map and run this script
2637
// The service handler will be automatically discovered and used by grpc-handler.ts
@@ -47,7 +58,9 @@ const hostServiceNameMap = {
4758
watch: "host.WatchService",
4859
// Add new host services here
4960
}
50-
const hostServiceDirs = Object.keys(hostServiceNameMap).map((serviceKey) => path.join(ROOT_DIR, "hosts", "vscode", serviceKey))
61+
const hostServiceDirs = Object.keys(hostServiceNameMap).map((serviceKey) =>
62+
path.join(ROOT_DIR, "src", "hosts", "vscode", serviceKey),
63+
)
5164

5265
async function main() {
5366
console.log(chalk.bold.blue("Starting Protocol Buffer code generation..."))
@@ -81,9 +94,7 @@ async function main() {
8194
`--proto_path="${SCRIPT_DIR}"`,
8295
`--plugin=protoc-gen-ts_proto="${tsProtoPlugin}"`,
8396
`--ts_proto_out="${TS_OUT_DIR}"`,
84-
"--ts_proto_opt=exportCommonSymbols=false",
85-
"--ts_proto_opt=outputIndex=true",
86-
"--ts_proto_opt=outputServices=generic-definitions,env=node,esModuleInterop=true,useDate=false,useOptionals=messages",
97+
`--ts_proto_opt=${TS_PROTO_OPTIONS.join(",")} `,
8798
...protoFiles,
8899
].join(" ")
89100
try {
@@ -592,7 +603,7 @@ export interface HostServiceHandlerConfig {
592603
export const hostServiceHandlers: Record<string, HostServiceHandlerConfig> = {${serviceConfigs.join(",")}
593604
};`
594605

595-
const configPath = path.join(ROOT_DIR, "hosts", "vscode", "host-grpc-service-config.ts")
606+
const configPath = path.join(ROOT_DIR, "src", "hosts", "vscode", "host-grpc-service-config.ts")
596607
await fs.mkdir(path.dirname(configPath), { recursive: true })
597608
await fs.writeFile(configPath, content)
598609
console.log(chalk.green(`Generated host service configuration at ${configPath}`))
@@ -637,7 +648,7 @@ export {
637648
${serviceExports.join(",\n\t")}
638649
}`
639650

640-
const configPath = path.join(ROOT_DIR, "src", "standalone", "services", "host-grpc-client.ts")
651+
const configPath = path.join(ROOT_DIR, "src", "hosts", "vscode", "client", "host-grpc-client.ts")
641652
await fs.mkdir(path.dirname(configPath), { recursive: true })
642653
await fs.writeFile(configPath, content)
643654
console.log(chalk.green(`Generated host gRPC client at ${configPath}`))

src/core/controller/file/getRelativePaths.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { RelativePathsRequest, RelativePaths } from "@shared/proto/file"
33
import { FileMethodHandler } from "./index"
44
import * as vscode from "vscode"
55
import * as path from "path"
6-
import { UriServiceClient } from "../../../standalone/services/host-grpc-client"
6+
import { UriServiceClient } from "@hosts/host-bridge-client"
77
import { Metadata, StringRequest } from "@shared/proto/common"
88

99
/**
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { StringRequest } from "@/shared/proto/common"
2+
import { Uri } from "@/shared/proto/host/uri"
3+
import { FileChangeEvent_ChangeType, SubscribeToFileRequest } from "@/shared/proto/host/watch"
4+
5+
const UriServiceClient = {
6+
parse: function (_: StringRequest): Uri {
7+
throw Error("Unimplemented")
8+
},
9+
}
10+
const WatchServiceClient = {
11+
subscribeToFile: function (
12+
_r: SubscribeToFileRequest,
13+
_h: {
14+
onResponse?: (response: { type: FileChangeEvent_ChangeType }) => void | Promise<void>
15+
onError?: (error: any) => void
16+
onComplete?: () => void
17+
},
18+
) {
19+
throw Error("Unimplemented")
20+
},
21+
}
22+
23+
export { UriServiceClient, WatchServiceClient }

src/hosts/host-bridge-client.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import * as VscodeClient from "./vscode/client/host-grpc-client"
2+
import * as ExternalClient from "./external/client/host-bridge-client"
3+
4+
const isHostBridgeExternal = process.env.HOST_BRIDGE_ADDRESS !== undefined && process.env.HOST_BRIDGE_ADDRESS !== "vscode"
5+
const Client = isHostBridgeExternal ? ExternalClient : VscodeClient
6+
7+
export const UriServiceClient = Client.UriServiceClient
8+
export const WatchServiceClient = Client.WatchServiceClient

src/standalone/services/host-grpc-client-base.ts renamed to src/hosts/vscode/client/host-grpc-client-base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { v4 as uuidv4 } from "uuid"
2-
import { GrpcHandler, StreamingCallbacks } from "../../../hosts/vscode/host-grpc-handler"
2+
import { GrpcHandler, StreamingCallbacks } from "../host-grpc-handler"
33

44
// Generic type for any protobuf service definition
55
export type ProtoService = {

hosts/vscode/host-grpc-handler.ts renamed to src/hosts/vscode/host-grpc-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { v4 as uuidv4 } from "uuid"
22
import { hostServiceHandlers } from "./host-grpc-service-config"
3-
import { GrpcRequestRegistry } from "../../src/core/controller/grpc-request-registry"
3+
import { GrpcRequestRegistry } from "@core/controller/grpc-request-registry"
44

55
/**
66
* Type definition for a streaming response handler
File renamed without changes.

hosts/vscode/uri/file.ts renamed to src/hosts/vscode/uri/file.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as vscode from "vscode"
2-
import { Uri } from "../../../src/shared/proto/host/uri"
3-
import { StringRequest } from "../../../src/shared/proto/common"
2+
import { Uri } from "@shared/proto/host/uri"
3+
import { StringRequest } from "@shared/proto/common"
44

55
/**
66
* Creates a file URI from a file path

0 commit comments

Comments
 (0)