Skip to content

Commit 1f7e31d

Browse files
viambotnjooma
andauthored
AI update based on proto changes (#618)
Co-authored-by: Naveed Jooma <[email protected]>
1 parent 5841157 commit 1f7e31d

File tree

4 files changed

+140
-32
lines changed

4 files changed

+140
-32
lines changed

src/services/data-manager/client.ts

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import { Struct, type JsonValue } from '@bufbuild/protobuf';
2-
import type { CallOptions, PromiseClient } from '@connectrpc/connect';
2+
import type { CallOptions, Client } from '@connectrpc/connect';
3+
import { MimeType } from '../../gen/app/datasync/v1/data_sync_pb.js';
34
import { DataManagerService } from '../../gen/service/datamanager/v1/data_manager_connect.js';
4-
import { SyncRequest } from '../../gen/service/datamanager/v1/data_manager_pb.js';
5+
import {
6+
SyncRequest,
7+
UploadBinaryDataToDatasetsRequest,
8+
} from '../../gen/service/datamanager/v1/data_manager_pb.js';
59
import type { RobotClient } from '../../robot';
610
import type { Options } from '../../types';
711
import { doCommandFromClient } from '../../utils';
812
import type { DataManager } from './data-manager';
913

1014
export class DataManagerClient implements DataManager {
11-
private client: PromiseClient<typeof DataManagerService>;
15+
private client: Client<typeof DataManagerService>;
1216
public readonly name: string;
1317
private readonly options: Options;
1418
public callOptions: CallOptions = { headers: {} as Record<string, string> };
@@ -80,4 +84,49 @@ export class DataManagerClient implements DataManager {
8084
callOptions
8185
);
8286
}
87+
88+
/**
89+
* Uploads binary data to specified datasets.
90+
*
91+
* @example
92+
*
93+
* ```ts
94+
* const dataManager = new VIAM.DataManagerClient(
95+
* machine,
96+
* 'my_data_manager'
97+
* );
98+
* await dataManager.uploadBinaryDataToDatasets(
99+
* new Uint8Array([1, 2, 3]),
100+
* ['tag1', 'tag2'],
101+
* ['datasetId1', 'datasetId2'],
102+
* MimeType.MIME_TYPE_JPEG
103+
* );
104+
* ```
105+
*
106+
* @param binaryData - The binary data to upload.
107+
* @param tags - Tags to associate with the binary data.
108+
* @param datasetIds - IDs of the datasets to associate the binary data with.
109+
* @param mimeType - The MIME type of the binary data.
110+
* @param extra - Extra arguments to pass to the upload request.
111+
* @param callOptions - Call options for the upload request.
112+
*/
113+
async uploadBinaryDataToDatasets(
114+
binaryData: Uint8Array,
115+
tags: string[],
116+
datasetIds: string[],
117+
mimeType: MimeType,
118+
extra = {},
119+
callOptions = this.callOptions
120+
) {
121+
const request = new UploadBinaryDataToDatasetsRequest({
122+
name: this.name,
123+
binaryData,
124+
tags,
125+
datasetIds,
126+
mimeType,
127+
extra: Struct.fromJson(extra),
128+
});
129+
this.options.requestLogger?.(request);
130+
await this.client.uploadBinaryDataToDatasets(request, callOptions);
131+
}
83132
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import type { Struct } from '@bufbuild/protobuf';
2+
import { MimeType } from '../../gen/app/datasync/v1/data_sync_pb.js';
23
import type { Resource } from '../../types';
34

45
export interface DataManager extends Resource {
56
sync: (extra?: Struct) => Promise<void>;
7+
uploadBinaryDataToDatasets: (
8+
binaryData: Uint8Array,
9+
tags: string[],
10+
datasetIds: string[],
11+
mimeType: MimeType,
12+
extra?: Struct
13+
) => Promise<void>;
614
}

src/services/motion/client.spec.ts

Lines changed: 77 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,32 @@ vi.mock('../../gen/service/motion/v1/motion_pb_service');
88
vi.mock('../../robot');
99

1010
import { Struct, Timestamp } from '@bufbuild/protobuf';
11-
import {
12-
createPromiseClient,
13-
createRouterTransport,
14-
} from '@connectrpc/connect';
11+
import { createClient, createRouterTransport } from '@connectrpc/connect';
1512
import { MotionService } from '../../gen/service/motion/v1/motion_connect';
1613
import {
1714
GetPlanRequest,
1815
ListPlanStatusesRequest,
1916
MoveOnGlobeRequest,
2017
MoveOnGlobeResponse,
18+
MoveRequest,
2119
StopPlanRequest,
2220
} from '../../gen/service/motion/v1/motion_pb';
23-
import { GeoGeometry, GeoPoint, ResourceName } from '../../types';
21+
import {
22+
GeoGeometry,
23+
GeoPoint,
24+
Pose,
25+
PoseInFrame,
26+
ResourceName,
27+
} from '../../types';
2428
import { MotionClient } from './client';
2529
import {
30+
Constraints,
2631
GetPlanResponse,
2732
ListPlanStatusesResponse,
2833
MotionConfiguration,
2934
ObstacleDetector,
3035
PlanState,
36+
PseudolinearConstraint,
3137
} from './types';
3238

3339
const motionClientName = 'test-motion';
@@ -76,9 +82,7 @@ describe('moveOnGlobe', () => {
7682

7783
RobotClient.prototype.createServiceClient = vi
7884
.fn()
79-
.mockImplementation(() =>
80-
createPromiseClient(MotionService, mockTransport)
81-
);
85+
.mockImplementation(() => createClient(MotionService, mockTransport));
8286

8387
motion = new MotionClient(new RobotClient('host'), motionClientName);
8488

@@ -226,9 +230,7 @@ describe('moveOnGlobe', () => {
226230

227231
RobotClient.prototype.createServiceClient = vi
228232
.fn()
229-
.mockImplementation(() =>
230-
createPromiseClient(MotionService, mockTransport)
231-
);
233+
.mockImplementation(() => createClient(MotionService, mockTransport));
232234

233235
motion = new MotionClient(new RobotClient('host'), motionClientName);
234236

@@ -263,6 +265,64 @@ describe('moveOnGlobe', () => {
263265
});
264266
});
265267

268+
describe('move', () => {
269+
it('sends a move request with pseudolinear constraints', async () => {
270+
const expectedComponentName = new ResourceName({
271+
namespace: 'viam',
272+
type: 'component',
273+
subtype: 'base',
274+
name: 'myBase',
275+
});
276+
const expectedDestination = new PoseInFrame({
277+
referenceFrame: 'world',
278+
pose: new Pose({
279+
x: 1,
280+
y: 2,
281+
z: 3,
282+
oX: 0,
283+
oY: 0,
284+
oZ: 1,
285+
theta: 90,
286+
}),
287+
});
288+
const expectedPseudolinearConstraint = new PseudolinearConstraint({
289+
lineToleranceFactor: 5,
290+
orientationToleranceFactor: 10,
291+
});
292+
const expectedConstraints = new Constraints({
293+
pseudolinearConstraint: [expectedPseudolinearConstraint],
294+
});
295+
const expectedExtra = { some: 'extra' };
296+
let capturedReq: MoveRequest | undefined;
297+
const mockTransport = createRouterTransport(({ service }) => {
298+
service(MotionService, {
299+
move: (req) => {
300+
capturedReq = req;
301+
return { success: true };
302+
},
303+
});
304+
});
305+
RobotClient.prototype.createServiceClient = vi
306+
.fn()
307+
.mockImplementation(() => createClient(MotionService, mockTransport));
308+
motion = new MotionClient(new RobotClient('host'), motionClientName);
309+
await expect(
310+
motion.move(
311+
expectedDestination,
312+
expectedComponentName,
313+
undefined,
314+
expectedConstraints,
315+
expectedExtra
316+
)
317+
).resolves.toStrictEqual(true);
318+
expect(capturedReq?.name).toStrictEqual(motionClientName);
319+
expect(capturedReq?.destination).toStrictEqual(expectedDestination);
320+
expect(capturedReq?.componentName).toStrictEqual(expectedComponentName);
321+
expect(capturedReq?.constraints).toStrictEqual(expectedConstraints);
322+
expect(capturedReq?.extra).toStrictEqual(Struct.fromJson(expectedExtra));
323+
});
324+
});
325+
266326
describe('stopPlan', () => {
267327
it('return null', async () => {
268328
const expectedComponentName = new ResourceName({
@@ -285,9 +345,7 @@ describe('stopPlan', () => {
285345

286346
RobotClient.prototype.createServiceClient = vi
287347
.fn()
288-
.mockImplementation(() =>
289-
createPromiseClient(MotionService, mockTransport)
290-
);
348+
.mockImplementation(() => createClient(MotionService, mockTransport));
291349

292350
motion = new MotionClient(new RobotClient('host'), motionClientName);
293351

@@ -318,9 +376,7 @@ describe('stopPlan', () => {
318376

319377
RobotClient.prototype.createServiceClient = vi
320378
.fn()
321-
.mockImplementation(() =>
322-
createPromiseClient(MotionService, mockTransport)
323-
);
379+
.mockImplementation(() => createClient(MotionService, mockTransport));
324380

325381
motion = new MotionClient(new RobotClient('host'), motionClientName);
326382

@@ -393,9 +449,7 @@ describe('getPlan', () => {
393449

394450
RobotClient.prototype.createServiceClient = vi
395451
.fn()
396-
.mockImplementation(() =>
397-
createPromiseClient(MotionService, mockTransport)
398-
);
452+
.mockImplementation(() => createClient(MotionService, mockTransport));
399453

400454
motion = new MotionClient(new RobotClient('host'), motionClientName);
401455

@@ -430,9 +484,7 @@ describe('getPlan', () => {
430484

431485
RobotClient.prototype.createServiceClient = vi
432486
.fn()
433-
.mockImplementation(() =>
434-
createPromiseClient(MotionService, mockTransport)
435-
);
487+
.mockImplementation(() => createClient(MotionService, mockTransport));
436488

437489
motion = new MotionClient(new RobotClient('host'), motionClientName);
438490

@@ -485,9 +537,7 @@ describe('listPlanStatuses', () => {
485537

486538
RobotClient.prototype.createServiceClient = vi
487539
.fn()
488-
.mockImplementation(() =>
489-
createPromiseClient(MotionService, mockTransport)
490-
);
540+
.mockImplementation(() => createClient(MotionService, mockTransport));
491541

492542
motion = new MotionClient(new RobotClient('host'), motionClientName);
493543

@@ -513,9 +563,7 @@ describe('listPlanStatuses', () => {
513563

514564
RobotClient.prototype.createServiceClient = vi
515565
.fn()
516-
.mockImplementation(() =>
517-
createPromiseClient(MotionService, mockTransport)
518-
);
566+
.mockImplementation(() => createClient(MotionService, mockTransport));
519567

520568
motion = new MotionClient(new RobotClient('host'), motionClientName);
521569

src/services/motion/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export type CollisionSpecification =
66
export type Constraints = PlainMessage<motionApi.Constraints>;
77
export type GetPlanResponse = motionApi.GetPlanResponse;
88
export type LinearConstraint = PlainMessage<motionApi.LinearConstraint>;
9+
export type PseudolinearConstraint =
10+
PlainMessage<motionApi.PseudolinearConstraint>;
911
export type ListPlanStatusesResponse = motionApi.ListPlanStatusesResponse;
1012
export type MotionConfiguration = PlainMessage<motionApi.MotionConfiguration>;
1113
export type ObstacleDetector = PlainMessage<motionApi.ObstacleDetector>;
@@ -18,6 +20,7 @@ export const {
1820
Constraints,
1921
GetPlanResponse,
2022
LinearConstraint,
23+
PseudolinearConstraint,
2124
ListPlanStatusesResponse,
2225
MotionConfiguration,
2326
ObstacleDetector,

0 commit comments

Comments
 (0)