Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert GrpcSerializer to use buildbuf_es instead of timostamm-protobuf-ts #1876

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
47 changes: 12 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 5 additions & 8 deletions src/extension/ai/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ import * as parser_pb from '@buf/stateful_runme.bufbuild_es/runme/parser/v1/pars

import { ServerLifecycleIdentity, getServerConfigurationValue } from '../../utils/configuration'
import { Serializer } from '../../types'
import * as serializerTypes from '../grpc/serializerTypes'
import * as parserTypes from '../grpc/parser/tcp/types'
import * as serializer from '../serializer'
import { Kernel } from '../kernel'

import * as protos from './protos'

// Converter provides converstion routines from vscode data types to protocol buffer types.
// It is a class because in order to handle the conversion we need to keep track of the kernel
// because we need to add execution information to the cells before serializing.
Expand All @@ -30,8 +28,7 @@ export class Converter {
let notebookDataWithExec = new vscode.NotebookData(cellDataWithExec)
// marshalNotebook returns a protocol buffer using the ts client library from buf we need to
// convert it to es
let notebookProto = serializer.GrpcSerializer.marshalNotebook(notebookDataWithExec)
return protos.notebookTSToES(notebookProto)
return serializer.GrpcSerializer.marshalNotebook(notebookDataWithExec)
}
}

Expand All @@ -56,14 +53,14 @@ export function cellToCellData(cell: vscode.NotebookCell): vscode.NotebookCellDa
}

// cellProtosToCellData converts an array of RunMe cell protos to an array of VSCode CellData
export function cellProtosToCellData(cells: serializerTypes.Cell[]): vscode.NotebookCellData[] {
export function cellProtosToCellData(cells: parserTypes.Cell[]): vscode.NotebookCellData[] {
let notebook: Serializer.Notebook = {
cells: [],
}
for (let cell of cells) {
let kind: vscode.NotebookCellKind = vscode.NotebookCellKind.Markup

if (cell.kind === serializerTypes.CellKind.CODE) {
if (cell.kind === parserTypes.CellKind.CODE) {
kind = vscode.NotebookCellKind.Code
}

Expand All @@ -80,7 +77,7 @@ export function cellProtosToCellData(cells: serializerTypes.Cell[]): vscode.Note

const identity: ServerLifecycleIdentity = getServerConfigurationValue<ServerLifecycleIdentity>(
'lifecycleIdentity',
serializerTypes.RunmeIdentity.ALL,
parserTypes.RunmeIdentity.ALL,
)
let newCellData = serializer.SerializerBase.revive(notebook, identity)
return newCellData
Expand Down
2 changes: 1 addition & 1 deletion src/extension/ai/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
} from '@buf/jlewi_foyle.bufbuild_es/foyle/v1alpha1/agent_pb'

import getLogger from '../logger'
import * as protos from '../grpc/parser/protos'

import { Converter } from './converters'
import * as protos from './protos'
import * as converters from './converters'
const log = getLogger('AIGenerate')

Expand Down
2 changes: 1 addition & 1 deletion src/extension/ai/ghost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { StreamGenerateRequest_Trigger } from '@buf/jlewi_foyle.bufbuild_es/foyl

import getLogger from '../logger'
import { RUNME_CELL_ID } from '../constants'
import * as protos from '../grpc/parser/protos'

import * as converters from './converters'
import * as stream from './stream'
import * as protos from './protos'
import { SessionManager } from './sessions'
import { getEventReporter } from './events'

Expand Down
2 changes: 1 addition & 1 deletion src/extension/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ import * as manager from './ai/manager'
import getLogger from './logger'
import { EnvironmentManager } from './environment/manager'
import ContextState from './contextState'
import { RunmeIdentity } from './grpc/serializerTypes'
import { RunmeIdentity } from './grpc/parser/tcp/types'
import * as features from './features'
import AuthSessionChangeHandler from './authSessionChangeHandler'

Expand Down
23 changes: 23 additions & 0 deletions src/extension/grpc/parser/h2/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ParserService } from '@buf/stateful_runme.connectrpc_es/runme/parser/v1/parser_connect'
import {
createGrpcTransport,
GrpcTransportOptions,
ConnectTransportOptions,
createConnectTransport,
} from '@connectrpc/connect-node'
import {
createClient as createConnectClient,
Client as ConnectClient,
Transport as ConnectTransport,
} from '@connectrpc/connect'

export {
ParserService,
createGrpcTransport,
createConnectTransport,
GrpcTransportOptions,
ConnectTransportOptions,
createConnectClient,
ConnectClient,
ConnectTransport,
}
1 change: 1 addition & 0 deletions src/extension/grpc/parser/h2/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '@buf/stateful_runme.bufbuild_es/runme/parser/v1/parser_pb'
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import * as parser_pb from '@buf/stateful_runme.bufbuild_es/runme/parser/v1/parser_pb'

import * as serializerTypes from '../grpc/serializerTypes'
import * as parserTypes from './tcp/types'

// Convert from a notebook protobuf represented as protobuf-ts (https://github.com/timostamm/protobuf-ts/tree/main)
// to protobuf-es. See https://github.com/stateful/runme/issues/641.
export function notebookTSToES(left: serializerTypes.Notebook): parser_pb.Notebook {
export function notebookTSToES(left: parserTypes.Notebook): parser_pb.Notebook {
try {
// N.B. Notebook.toJson raises an exception
let binaryValue = serializerTypes.Notebook.toBinary(left)
let binaryValue = parserTypes.Notebook.toBinary(left)
return parser_pb.Notebook.fromBinary(binaryValue)
} catch (e) {
console.log(`Failed to convert notebook; error :${e}`)
}
return new parser_pb.Notebook()
}

export function cellTSToES(left: serializerTypes.Cell): parser_pb.Cell {
let data = serializerTypes.Cell.toBinary(left)
export function cellTSToES(left: parserTypes.Cell): parser_pb.Cell {
let data = parserTypes.Cell.toBinary(left)
return parser_pb.Cell.fromBinary(data)
}

export function cellsESToTS(left: parser_pb.Cell[]): serializerTypes.Cell[] {
export function cellsESToTS(left: parser_pb.Cell[]): parserTypes.Cell[] {
let cells = []
for (let cell of left) {
let binaryValue = cell.toBinary()
cells.push(serializerTypes.Cell.fromBinary(binaryValue))
cells.push(parserTypes.Cell.fromBinary(binaryValue))
}
return cells
}
File renamed without changes.
6 changes: 3 additions & 3 deletions src/extension/kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ import {
import { getEventReporter } from './ai/events'
import { getSystemShellPath, isShellLanguage } from './executors/utils'
import './wasm/wasm_exec.js'
import { RpcError, TransformRequest, TransformResponse } from './grpc/client'
import { RpcError, TransformRequest, TransformResponse } from './grpc/tcpClient'
import { IRunner, IRunnerReady, RunProgramOptions } from './runner'
import { IRunnerEnvironment } from './runner/environment'
import { IKernelRunnerOptions, executeRunner } from './executors/runner'
Expand All @@ -103,7 +103,7 @@ import { handleCellOutputMessage } from './messages/cellOutput'
import handleGitHubMessage, { handleGistMessage } from './messages/github'
import { getNotebookCategories } from './utils'
import PanelManager from './panels/panelManager'
import { GrpcSerializer, SerializerBase } from './serializer'
import { GrpcSerializer } from './serializer'
import { askAlternativeOutputsAction, openSplitViewAsMarkdownText } from './commands'
import { handlePlatformApiMessage } from './messages/platformRequest'
import { handleGCPMessage } from './messages/gcp'
Expand Down Expand Up @@ -150,7 +150,7 @@ export class Kernel implements Disposable {
protected activeTerminals: ActiveTerminal[] = []
protected category?: string
protected panelManager: PanelManager
protected serializer?: SerializerBase
protected serializer?: GrpcSerializer
protected reporter?: GrpcReporter
protected featuresState$?: FeatureObserver

Expand Down
6 changes: 3 additions & 3 deletions src/extension/messages/platformRequest/saveCellExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Uri, env, workspace, commands } from 'vscode'
import { TelemetryReporter } from 'vscode-telemetry'
import getMAC from 'getmac'
import YAML from 'yaml'
import { FetchResult } from '@apollo/client'
import { FetchResult, MutationOptions } from '@apollo/client'

import { ClientMessages, NOTEBOOK_AUTOSAVE_ON, RUNME_FRONTMATTER_PARSED } from '../../../constants'
import { ClientMessage, FeatureName, IApiMessage } from '../../../types'
Expand All @@ -23,7 +23,7 @@ import {
CreateNotebookInput,
ReporterFrontmatterInput,
} from '../../__generated-platform__/graphql'
import { Frontmatter } from '../../grpc/serializerTypes'
import { Frontmatter } from '../../grpc/parser/tcp/types'
import { getCellById } from '../../cell'
import { StatefulAuthProvider } from '../../provider/statefulAuth'
import features from '../../features'
Expand Down Expand Up @@ -188,7 +188,7 @@ export default async function saveCellExecution(
},
},
}
const result = await graphClient.mutate(mutation)
const result = await graphClient.mutate(mutation as MutationOptions)
data = result
}
// TODO: Remove the legacy createCellExecution mutation once the reporter is fully tested.
Expand Down
4 changes: 2 additions & 2 deletions src/extension/provider/runmeTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ import { IRunnerEnvironment } from '../runner/environment'
import { getCellCwd, getCellProgram, getNotebookSkipPromptEnvSetting } from '../executors/utils'
import { Kernel } from '../kernel'
import KernelServer from '../server/kernelServer'
import { ProjectServiceClient, initProjectClient, type ReadyPromise } from '../grpc/client'
import { ProjectServiceClient, initProjectClient, type ReadyPromise } from '../grpc/tcpClient'
import { LoadEventFoundTask, LoadRequest, LoadResponse } from '../grpc/projectTypes'
import { RunmeIdentity } from '../grpc/serializerTypes'
import { RunmeIdentity } from '../grpc/parser/tcp/types'
import { resolveRunProgramExecution } from '../executors/runner'
import {
CommandMode,
Expand Down
2 changes: 1 addition & 1 deletion src/extension/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ReporterServiceClient,
TransformRequest,
type ReadyPromise,
} from './grpc/client'
} from './grpc/tcpClient'
import { IServer } from './server/kernelServer'

export class GrpcReporter {
Expand Down
2 changes: 1 addition & 1 deletion src/extension/runner/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
ResolveProgramResponse,
} from '../grpc/runner/types'
import { UpdateSessionRequest, UpdateSessionResponse } from '../grpc/runner/v2'
import { IRunnerServiceClient, getRunnerServiceClient } from '../grpc/client'
import { IRunnerServiceClient, getRunnerServiceClient } from '../grpc/tcpClient'
import { IServer } from '../server/kernelServer'

import { IRunnerReady } from '.'
Expand Down
2 changes: 1 addition & 1 deletion src/extension/runner/environment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IRunnerServiceClient } from '../grpc/client'
import { IRunnerServiceClient } from '../grpc/tcpClient'
import { Session } from '../grpc/runner/types'
import getLogger from '../logger'
import { convertEnvList } from '../utils'
Expand Down
2 changes: 1 addition & 1 deletion src/extension/runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
} from '../grpc/runner/types'
import { ExecuteDuplex } from '../grpc/runner/types'
import { progconf } from '../grpc/runner/v2'
import { IRunnerServiceClient, RpcError } from '../grpc/client'
import { IRunnerServiceClient, RpcError } from '../grpc/tcpClient'
import { getSystemShellPath } from '../executors/utils'
import { IServer } from '../server/kernelServer'
import { convertEnvList } from '../utils'
Expand Down
2 changes: 1 addition & 1 deletion src/extension/runner/monitorEnv.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Disposable } from 'vscode'
import { ServerStreamingCall } from '@protobuf-ts/runtime-rpc'

import { IRunnerServiceClient } from '../grpc/client'
import { IRunnerServiceClient } from '../grpc/tcpClient'
import { MonitorEnvStoreRequest, MonitorEnvStoreResponse } from '../grpc/runner/v1'

import { IRunnerChild } from './types'
Expand Down
2 changes: 1 addition & 1 deletion src/extension/runner/program.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Disposable } from 'vscode'

import { IRunnerServiceClient } from '../grpc/client'
import { IRunnerServiceClient } from '../grpc/tcpClient'
import { ResolveProgramRequestImpl, ResolveProgramRequest_Mode } from '../grpc/runner/types'

import { IRunnerChild } from './types'
Expand Down
Loading
Loading