@dimo-network/data-sdk 1.4.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,12 +29,17 @@ jobs:
29
29
  publish-npm:
30
30
  needs: build
31
31
  runs-on: ubuntu-latest
32
+ permissions:
33
+ id-token: write # Required for OIDC
34
+ contents: read
32
35
  steps:
33
36
  - uses: actions/checkout@v4
34
- - uses: actions/setup-node@v3
37
+ - uses: actions/setup-node@v4
35
38
  with:
36
39
  node-version: 20
37
40
  registry-url: https://registry.npmjs.org/
41
+ - name: Install latest npm
42
+ run: npm install -g npm@latest
38
43
  - name: Clear npm cache
39
44
  run: npm cache clean --force
40
45
  - name: Install dependencies
@@ -46,5 +51,3 @@ jobs:
46
51
  - name: Check dist directory
47
52
  run: ls dist/
48
53
  - run: npm publish --access public
49
- env:
50
- NODE_AUTH_TOKEN: ${{secrets.npm_token}}
package/README.md CHANGED
@@ -293,5 +293,87 @@ const totalNetworkVehicles = await dimo.identity.query({
293
293
 
294
294
  This GraphQL API query is equivalent to calling `dimo.identity.countDimoVehicles()`.
295
295
 
296
+ ### Agents API
297
+
298
+ The DIMO Agents API enables developers to create intelligent AI agents that can interact with vehicle data through natural language. These agents can query vehicle information, real-time telemetry, perform web searches to answer questions about vehicles and nearby services, and more.
299
+
300
+ #### Create an Agent
301
+
302
+ Create a new conversational AI agent with the specified configuration:
303
+
304
+ ```ts
305
+ const agent = await dimo.agents.createAgent({
306
+ ...developerJwt,
307
+ type: "driver_agent_v1", // Optional: defaults to "driver_agent_v1"
308
+ personality: "uncle_mechanic", // Optional: defaults to "uncle_mechanic"
309
+ secrets: {
310
+ DIMO_API_KEY: "<YOUR_API_KEY>"
311
+ },
312
+ variables: {
313
+ USER_WALLET: "0x1234567890abcdef1234567890abcdef12345678",
314
+ VEHICLE_IDS: "[872, 1234]"
315
+ }
316
+ });
317
+ ```
318
+
319
+ Available personalities: `uncle_mechanic`, `master_technician`, `concierge`, `driving_enthusiast`, `fleet_manager_pro`
320
+
321
+ #### Send a Message
322
+
323
+ Send a message to an agent and receive a complete response synchronously:
324
+
325
+ ```ts
326
+ const response = await dimo.agents.sendMessage({
327
+ ...developerJwt,
328
+ agentId: "agent-abc123def456",
329
+ message: "What's the make and model of my vehicle?"
330
+ });
331
+ ```
332
+
333
+ #### Stream a Message
334
+
335
+ Send a message and receive real-time token-by-token streaming response:
336
+
337
+ ```ts
338
+ const stream = await dimo.agents.streamMessage({
339
+ ...developerJwt,
340
+ agentId: "agent-abc123def456",
341
+ message: "What's my current speed?"
342
+ });
343
+
344
+ stream.on('token', (chunk) => {
345
+ console.log(chunk.content);
346
+ });
347
+
348
+ stream.on('done', (metadata) => {
349
+ console.log('Vehicles queried:', metadata.vehiclesQueried);
350
+ });
351
+ ```
352
+
353
+ #### Get Conversation History
354
+
355
+ Retrieve the complete conversation history for an agent:
356
+
357
+ ```ts
358
+ const history = await dimo.agents.getHistory({
359
+ ...developerJwt,
360
+ agentId: "agent-abc123def456",
361
+ limit: 50 // Optional
362
+ });
363
+ ```
364
+
365
+ #### Delete an Agent
366
+
367
+ Permanently delete an agent and all associated resources:
368
+
369
+ ```ts
370
+ await dimo.agents.deleteAgent({
371
+ ...developerJwt,
372
+ agentId: "agent-abc123def456"
373
+ });
374
+ ```
375
+
376
+ For more details, visit the [Agents API Documentation](https://www.dimo.org/docs/api-references/agents-api).
377
+
296
378
  ## How to Contribute to the SDK
297
379
  Read more about contributing [here](https://github.com/DIMO-Network/data-sdk/blob/master/CONTRIBUTING.md).
@@ -87,14 +87,19 @@ export const Method = async (resource, baseUrl, params = {}, env) => {
87
87
  let body = {};
88
88
  if (resource.body) {
89
89
  for (const key in resource.body) {
90
- if (typeof resource.body[key] === 'boolean') {
90
+ if (resource.body[key] === true) {
91
+ // Required field
91
92
  if (!params[key]) {
92
93
  console.error(`Missing required body parameter: ${key}`);
93
94
  throw new DimoError({
94
95
  message: `Missing required body parameter: ${key}`
95
96
  });
96
97
  }
97
- else {
98
+ body[key] = params[key];
99
+ }
100
+ else if (resource.body[key] === false) {
101
+ // Optional field - include only if provided
102
+ if (params[key] !== undefined) {
98
103
  body[key] = params[key];
99
104
  }
100
105
  }
@@ -2,6 +2,8 @@ import axios from 'axios';
2
2
  import { Method } from './Method'; // Import the Method function to be tested
3
3
  import { DimoError } from '../errors';
4
4
  import { DimoEnvironment } from '../environments';
5
+ jest.mock('axios');
6
+ const mockedAxios = axios;
5
7
  const PROD = 'Production';
6
8
  const DEV = 'Dev';
7
9
  const RESOURCE = {
@@ -11,8 +13,11 @@ const RESOURCE = {
11
13
  };
12
14
  const PARAM = { param1: 'value1' };
13
15
  describe('Method Function', () => {
16
+ beforeEach(() => {
17
+ jest.clearAllMocks();
18
+ });
14
19
  test('Valid API Call - Device Definitions API Server is up and returning data', async () => {
15
- jest.spyOn(axios, 'request').mockResolvedValue({ data: { key: 'value' } });
20
+ mockedAxios.mockResolvedValue({ data: 'device definitions api running!' });
16
21
  const devResponse = await Method(RESOURCE, DimoEnvironment.Dev.DeviceDefinitions, PARAM, DEV);
17
22
  const prodResponse = await Method(RESOURCE, DimoEnvironment.Production.DeviceDefinitions, PARAM, PROD);
18
23
  // Assertion - Check if the response data is returned correctly
@@ -20,7 +25,7 @@ describe('Method Function', () => {
20
25
  expect(prodResponse).toEqual('device definitions api running!');
21
26
  });
22
27
  test('Valid API Call - Devices API Server is up and returning data', async () => {
23
- jest.spyOn(axios, 'request').mockResolvedValue({ data: { key: 'value' } });
28
+ mockedAxios.mockResolvedValue({ data: { data: 'Server is up and running' } });
24
29
  const devResponse = await Method(RESOURCE, DimoEnvironment.Dev.Devices, PARAM, DEV);
25
30
  const prodResponse = await Method(RESOURCE, DimoEnvironment.Production.Devices, PARAM, PROD);
26
31
  // Assertion - Check if the response data is returned correctly
@@ -28,7 +33,7 @@ describe('Method Function', () => {
28
33
  expect(prodResponse).toEqual({ data: 'Server is up and running' });
29
34
  });
30
35
  test('Valid API Call - Token Exchange API Server is up and returning data', async () => {
31
- jest.spyOn(axios, 'request').mockResolvedValue({ data: { key: 'value' } });
36
+ mockedAxios.mockResolvedValue({ data: { data: 'Server is up and running' } });
32
37
  const devResponse = await Method(RESOURCE, DimoEnvironment.Dev.TokenExchange, PARAM, DEV);
33
38
  const prodResponse = await Method(RESOURCE, DimoEnvironment.Production.TokenExchange, PARAM, PROD);
34
39
  // Assertion - Check if the response data is returned correctly
@@ -36,7 +41,7 @@ describe('Method Function', () => {
36
41
  expect(prodResponse).toEqual({ data: 'Server is up and running' });
37
42
  });
38
43
  test('Valid API Call - Valuations API Server is up and returning data', async () => {
39
- jest.spyOn(axios, 'request').mockResolvedValue({ data: { key: 'value' } });
44
+ mockedAxios.mockResolvedValue({ data: { code: 200, message: 'Server is up.' } });
40
45
  const devResponse = await Method(RESOURCE, DimoEnvironment.Dev.Valuations, PARAM, DEV);
41
46
  const prodResponse = await Method(RESOURCE, DimoEnvironment.Production.Valuations, PARAM, PROD);
42
47
  // Assertion - Check if the response data is returned correctly
@@ -44,7 +49,7 @@ describe('Method Function', () => {
44
49
  expect(prodResponse).toEqual({ code: 200, message: 'Server is up.' });
45
50
  });
46
51
  test('Valid API Call - Vehicle Signal Decoding API Server is up and returning data', async () => {
47
- jest.spyOn(axios, 'request').mockResolvedValue({ data: { key: 'value' } });
52
+ mockedAxios.mockResolvedValue({ data: 'healthy' });
48
53
  const devResponse = await Method(RESOURCE, DimoEnvironment.Dev.VehicleSignalDecoding, PARAM, DEV);
49
54
  const prodResponse = await Method(RESOURCE, DimoEnvironment.Production.VehicleSignalDecoding, PARAM, PROD);
50
55
  // Assertion - Check if the response data is returned correctly
@@ -0,0 +1,5 @@
1
+ import { Resource } from '../../Resource';
2
+ import { DimoEnvironment } from '../../../environments';
3
+ export declare class Agents extends Resource {
4
+ constructor(api: any, env: keyof typeof DimoEnvironment);
5
+ }
@@ -0,0 +1,63 @@
1
+ import { Resource } from '../../Resource';
2
+ export class Agents extends Resource {
3
+ constructor(api, env) {
4
+ super(api, 'Agents', env);
5
+ this.setResource({
6
+ healthCheck: {
7
+ method: 'GET',
8
+ path: '/'
9
+ },
10
+ createAgent: {
11
+ method: 'POST',
12
+ path: '/agents',
13
+ body: {
14
+ 'type': false,
15
+ 'personality': false,
16
+ 'secrets': true,
17
+ 'variables': true,
18
+ },
19
+ auth: 'developer_jwt'
20
+ },
21
+ deleteAgent: {
22
+ method: 'DELETE',
23
+ path: '/agents/:agentId',
24
+ auth: 'developer_jwt'
25
+ },
26
+ sendMessage: {
27
+ method: 'POST',
28
+ path: '/agents/:agentId/message',
29
+ body: {
30
+ 'message': true,
31
+ 'vehicleIds': false,
32
+ 'user': false
33
+ },
34
+ auth: 'developer_jwt'
35
+ },
36
+ streamMessage: {
37
+ method: 'POST',
38
+ path: '/agents/:agentId/stream',
39
+ body: {
40
+ 'message': true,
41
+ 'vehicleIds': false,
42
+ 'user': false
43
+ },
44
+ auth: 'developer_jwt'
45
+ },
46
+ getHistory: {
47
+ method: 'GET',
48
+ path: '/agents/:agentId/history',
49
+ queryParams: {
50
+ 'limit': false
51
+ },
52
+ auth: 'developer_jwt'
53
+ }
54
+ });
55
+ const originalCreateAgent = this.createAgent;
56
+ this.createAgent = (params = {}) => {
57
+ return originalCreateAgent({
58
+ type: 'driver_agent_v1',
59
+ ...params
60
+ });
61
+ };
62
+ }
63
+ }
@@ -1,4 +1,5 @@
1
1
  /** @format */
2
+ import { Agents } from './Agents';
2
3
  import { Attestation } from './Attestation';
3
4
  import { Auth } from './Auth';
4
5
  import { DeviceDefinitions } from './DeviceDefinitions';
@@ -7,4 +8,4 @@ import { TokenExchange } from './TokenExchange';
7
8
  import { Trips } from './Trips';
8
9
  import { Valuations } from './Valuations';
9
10
  import { VehicleTriggers } from './VehicleTriggers';
10
- export { Attestation, Auth, DeviceDefinitions, Devices, TokenExchange, Trips, Valuations, VehicleTriggers, };
11
+ export { Agents, Attestation, Auth, DeviceDefinitions, Devices, TokenExchange, Trips, Valuations, VehicleTriggers, };
@@ -1,4 +1,5 @@
1
1
  /** @format */
2
+ import { Agents } from './Agents';
2
3
  import { Attestation } from './Attestation';
3
4
  import { Auth } from './Auth';
4
5
  import { DeviceDefinitions } from './DeviceDefinitions';
@@ -7,4 +8,4 @@ import { TokenExchange } from './TokenExchange';
7
8
  import { Trips } from './Trips';
8
9
  import { Valuations } from './Valuations';
9
10
  import { VehicleTriggers } from './VehicleTriggers';
10
- export { Attestation, Auth, DeviceDefinitions, Devices, TokenExchange, Trips, Valuations, VehicleTriggers, };
11
+ export { Agents, Attestation, Auth, DeviceDefinitions, Devices, TokenExchange, Trips, Valuations, VehicleTriggers, };
package/dist/cjs/index.js CHANGED
@@ -20164,6 +20164,7 @@ const {
20164
20164
  /** @format */
20165
20165
  const DimoEnvironment = {
20166
20166
  Production: {
20167
+ Agents: 'https://agents.dimo.zone',
20167
20168
  Attestation: 'https://attestation-api.dimo.zone',
20168
20169
  Auth: 'https://auth.dimo.zone',
20169
20170
  Identity: 'https://identity-api.dimo.zone/query',
@@ -20177,6 +20178,7 @@ const DimoEnvironment = {
20177
20178
  VehicleTriggers: 'https://vehicle-triggers-api.dimo.zone',
20178
20179
  },
20179
20180
  Dev: {
20181
+ Agents: 'https://agents.dev.dimo.zone',
20180
20182
  Attestation: 'https://attestation-api.dev.dimo.zone',
20181
20183
  Auth: 'https://auth.dev.dimo.zone',
20182
20184
  Identity: 'https://identity-api.dev.dimo.zone/query',
@@ -20632,6 +20634,7 @@ class Telemetry extends Resource$1 {
20632
20634
  /** @format */
20633
20635
  // import { Stream } from './streamr';
20634
20636
  class DIMO {
20637
+ agents;
20635
20638
  attestation;
20636
20639
  auth;
20637
20640
  devicedefinitions;
@@ -20648,6 +20651,7 @@ class DIMO {
20648
20651
  /**
20649
20652
  * Set up all REST Endpoints
20650
20653
  */
20654
+ this.agents = new Agents(DimoEnvironment[env].Agents, env);
20651
20655
  this.attestation = new Attestation(DimoEnvironment[env].Attestation, env);
20652
20656
  this.auth = new Auth(DimoEnvironment[env].Auth, env);
20653
20657
  this.devicedefinitions = new DeviceDefinitions(DimoEnvironment[env].DeviceDefinitions, env);
@@ -142422,14 +142426,19 @@ const Method = async (resource, baseUrl, params = {}, env) => {
142422
142426
  let body = {};
142423
142427
  if (resource.body) {
142424
142428
  for (const key in resource.body) {
142425
- if (typeof resource.body[key] === 'boolean') {
142429
+ if (resource.body[key] === true) {
142430
+ // Required field
142426
142431
  if (!params[key]) {
142427
142432
  console.error(`Missing required body parameter: ${key}`);
142428
142433
  throw new DimoError({
142429
142434
  message: `Missing required body parameter: ${key}`
142430
142435
  });
142431
142436
  }
142432
- else {
142437
+ body[key] = params[key];
142438
+ }
142439
+ else if (resource.body[key] === false) {
142440
+ // Optional field - include only if provided
142441
+ if (params[key] !== undefined) {
142433
142442
  body[key] = params[key];
142434
142443
  }
142435
142444
  }
@@ -142487,6 +142496,69 @@ class Resource {
142487
142496
  }
142488
142497
  }
142489
142498
 
142499
+ class Agents extends Resource {
142500
+ constructor(api, env) {
142501
+ super(api, 'Agents', env);
142502
+ this.setResource({
142503
+ healthCheck: {
142504
+ method: 'GET',
142505
+ path: '/'
142506
+ },
142507
+ createAgent: {
142508
+ method: 'POST',
142509
+ path: '/agents',
142510
+ body: {
142511
+ 'type': false,
142512
+ 'personality': false,
142513
+ 'secrets': true,
142514
+ 'variables': true,
142515
+ },
142516
+ auth: 'developer_jwt'
142517
+ },
142518
+ deleteAgent: {
142519
+ method: 'DELETE',
142520
+ path: '/agents/:agentId',
142521
+ auth: 'developer_jwt'
142522
+ },
142523
+ sendMessage: {
142524
+ method: 'POST',
142525
+ path: '/agents/:agentId/message',
142526
+ body: {
142527
+ 'message': true,
142528
+ 'vehicleIds': false,
142529
+ 'user': false
142530
+ },
142531
+ auth: 'developer_jwt'
142532
+ },
142533
+ streamMessage: {
142534
+ method: 'POST',
142535
+ path: '/agents/:agentId/stream',
142536
+ body: {
142537
+ 'message': true,
142538
+ 'vehicleIds': false,
142539
+ 'user': false
142540
+ },
142541
+ auth: 'developer_jwt'
142542
+ },
142543
+ getHistory: {
142544
+ method: 'GET',
142545
+ path: '/agents/:agentId/history',
142546
+ queryParams: {
142547
+ 'limit': false
142548
+ },
142549
+ auth: 'developer_jwt'
142550
+ }
142551
+ });
142552
+ const originalCreateAgent = this.createAgent;
142553
+ this.createAgent = (params = {}) => {
142554
+ return originalCreateAgent({
142555
+ type: 'driver_agent_v1',
142556
+ ...params
142557
+ });
142558
+ };
142559
+ }
142560
+ }
142561
+
142490
142562
  class Attestation extends Resource {
142491
142563
  constructor(api, env) {
142492
142564
  super(api, 'Attestation', env);
@@ -142743,6 +142815,7 @@ class VehicleTriggers extends Resource {
142743
142815
  }
142744
142816
  }
142745
142817
 
142818
+ exports.Agents = Agents;
142746
142819
  exports.Attestation = Attestation;
142747
142820
  exports.Auth = Auth;
142748
142821
  exports.DIMO = DIMO;