Skip to content

[RSDK-8305] Send SDK/API version #332

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

Merged
merged 6 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/update_protos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:

- name: Update api
run: |
echo ${{ github.event.client_payload.tag }} > api_version.lock
sudo chown -R testbot .
sudo -u testbot bash -lc 'make update-buf'

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,6 @@ bin/

# typedoc documentation
docs/dist

# build-time outputs
src/api-version.ts
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ update-buf: $(node_modules)
.PHONY: build-buf
build-buf: $(node_modules) clean-buf
$(buf) generate $$(./scripts/get-buf-lock-version.js buf.build/googleapis/googleapis)
$(buf) generate $$(./scripts/get-buf-lock-version.js buf.build/viamrobotics/api) --path common,component,robot,service,app,provisioning,tagger,stream
$(buf) generate buf.build/viamrobotics/api:$$(cat api_version.lock) --path common,component,robot,service,app,provisioning,tagger,stream
$(buf) generate $$(./scripts/get-buf-lock-version.js buf.build/viamrobotics/goutils)

# js targets
Expand Down
1 change: 1 addition & 0 deletions api_version.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v0.1.330
8 changes: 4 additions & 4 deletions buf.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ deps:
- remote: buf.build
owner: googleapis
repository: googleapis
commit: 2bbd25900cb34c79bae97d85c948d3cf
digest: shake256:a6446e23f4408160217c22738a0c8c370ff3ff966f601d678960b803829cf53b5cf5998d20fcb3f9c9be944b24337843e7beb6e681ddbf9d036fb6491c0e47e7
commit: 8bc2c51e08c447cd8886cdea48a73e14
digest: shake256:a969155953a5cedc5b2df5b42c368f2bc66ff8ce1804bc96e0f14ff2ee8a893687963058909df844d1643cdbc98ff099d2daa6bc9f9f5b8886c49afdc60e19af
- remote: buf.build
owner: viamrobotics
repository: api
commit: 50ed3af8a5ba4ae1b2cff6c9536163f7
digest: shake256:c7a5a1a961713ab6316f08c4c0ea8308cf5b068516229d4c74ea78b7e2233ba51011616021e431a49a71ea8f7944f55bc70deb7a8dd2800ecdbb1107f026244f
commit: 611b5d52df6843bdb8f407dd7aa3e2fa
digest: shake256:c53316f527a616e8c4d9d96df342040d41a51f575b8410c091940eb774cfe5b9474ed888226d25a0464f48053e032746c60022df2a7bd90f29e85607c2545949
- remote: buf.build
owner: viamrobotics
repository: goutils
Expand Down
3 changes: 2 additions & 1 deletion examples/vanilla/package-lock.json

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

145 changes: 145 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
}
},
"scripts": {
"prebuild": "ts-node ./scripts/write-versions.ts",
"build": "npm run build:bundle && npm run build:types && npm run build:copy-dts",
"build:bundle": "vite build",
"build:types": "tsc --project tsconfig.build.json",
Expand Down Expand Up @@ -72,6 +73,7 @@
"prettier": "^3.1.1",
"prettier-plugin-jsdoc": "^1.1.1",
"protoc-gen-js": "^3.21.2",
"ts-node": "^10.9.2",
"ts-protoc-gen": "^0.15.0",
"typedoc": "^0.25.4",
"typescript": "^5.3.3",
Expand Down
7 changes: 7 additions & 0 deletions scripts/write-versions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const fs = require('node:fs');

const apiVersion = fs.readFileSync('./api_version.lock').toString().trim();
fs.writeFileSync(
'./src/api-version.ts',
`export const apiVersion = "${apiVersion}";`
);
27 changes: 4 additions & 23 deletions src/app/viam-transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { dialDirect } from '@viamrobotics/rpc';

import { AuthenticateRequest, Credentials } from '../gen/proto/rpc/v1/auth_pb';
import { AuthServiceClient } from '../gen/proto/rpc/v1/auth_pb_service';
import { MetadataTransport } from '../utils';

/** A credential that can be exchanged to obtain an access token */
export interface Credential {
Expand Down Expand Up @@ -94,33 +95,13 @@ const createWithCredential = async (
new ViamTransport(transportFactory, opts, accessToken);
};

export class ViamTransport implements grpc.Transport {
private accessToken: string;
protected readonly transport: grpc.Transport;

export class ViamTransport extends MetadataTransport {
constructor(
transportFactory: grpc.TransportFactory,
opts: grpc.TransportOptions,
accessToken: string
) {
this.transport = transportFactory(opts);
this.accessToken = accessToken;
}

public start(metadata: grpc.Metadata): void {
metadata.set('authorization', `Bearer ${this.accessToken}`);
this.transport.start(metadata);
}

public sendMessage(msgBytes: Uint8Array): void {
this.transport.sendMessage(msgBytes);
}

public finishSend(): void {
this.transport.finishSend();
}

public cancel(): void {
this.transport.cancel();
const md = new grpc.Metadata({ authorization: `Bearer ${accessToken}` });
super(transportFactory, opts, md);
}
}
15 changes: 11 additions & 4 deletions src/robot/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { SensorsServiceClient } from '../gen/service/sensors/v1/sensors_pb_servi
import { SLAMServiceClient } from '../gen/service/slam/v1/slam_pb_service';
import { VisionServiceClient } from '../gen/service/vision/v1/vision_pb_service';
import { ViamResponseStream } from '../responses';
import { encodeResourceName, promisify } from '../utils';
import { encodeResourceName, promisify, MetadataTransport } from '../utils';
import GRPCConnectionManager from './grpc-connection-manager';
import type { Robot, RobotStatusStream } from './robot';
import SessionManager from './session-manager';
Expand Down Expand Up @@ -525,9 +525,16 @@ export class RobotClient extends EventDispatcher implements Robot {
await this.gRPCConnectionManager.start();
}

const clientTransportFactory = this.sessionOptions?.disabled
? this.transportFactory
: this.sessionManager.transportFactory;
const ctf: grpc.TransportFactory = (
options: grpc.TransportOptions
): grpc.Transport => {
const tf = this.sessionOptions?.disabled
? this.transportFactory
: this.sessionManager.transportFactory;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return new MetadataTransport(tf!, options);
};
const clientTransportFactory = ctf;
const grpcOptions = { transport: clientTransportFactory };

this.robotServiceClient = new RobotServiceClient(
Expand Down
Loading