@dimo-network/data-sdk 1.3.3 → 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.
- package/.github/workflows/npm-publish.yml +6 -3
- package/README.md +82 -0
- package/dist/api/Method.js +7 -2
- package/dist/api/Method.test.js +10 -5
- package/dist/api/resources/Agents/index.d.ts +5 -0
- package/dist/api/resources/Agents/index.js +63 -0
- package/dist/api/resources/DimoRestResources.d.ts +3 -2
- package/dist/api/resources/DimoRestResources.js +3 -2
- package/dist/api/resources/{VehicleEvents → VehicleTriggers}/index.d.ts +2 -2
- package/dist/api/resources/{VehicleEvents → VehicleTriggers}/index.js +13 -19
- package/dist/cjs/index.js +607 -503
- package/dist/cjs/index.js.map +1 -1
- package/dist/dimo.d.ts +3 -2
- package/dist/dimo.js +5 -3
- package/dist/dimo.test.js +4 -0
- package/dist/environments/index.d.ts +4 -2
- package/dist/environments/index.js +4 -2
- package/dist/esm/index.js +606 -503
- package/dist/esm/index.js.map +1 -1
- package/dist/types/api/resources/Agents/index.d.ts +5 -0
- package/dist/types/api/resources/DimoRestResources.d.ts +3 -2
- package/dist/types/api/resources/{VehicleEvents → VehicleTriggers}/index.d.ts +2 -2
- package/dist/types/dimo.d.ts +3 -2
- package/dist/types/environments/index.d.ts +4 -2
- package/package.json +4 -3
|
@@ -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@
|
|
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).
|
package/dist/api/Method.js
CHANGED
|
@@ -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 (
|
|
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
|
-
|
|
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
|
}
|
package/dist/api/Method.test.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,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';
|
|
@@ -6,5 +7,5 @@ import { Devices } from './Devices';
|
|
|
6
7
|
import { TokenExchange } from './TokenExchange';
|
|
7
8
|
import { Trips } from './Trips';
|
|
8
9
|
import { Valuations } from './Valuations';
|
|
9
|
-
import {
|
|
10
|
-
export { Attestation, Auth, DeviceDefinitions, Devices, TokenExchange, Trips, Valuations,
|
|
10
|
+
import { VehicleTriggers } from './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';
|
|
@@ -6,5 +7,5 @@ import { Devices } from './Devices';
|
|
|
6
7
|
import { TokenExchange } from './TokenExchange';
|
|
7
8
|
import { Trips } from './Trips';
|
|
8
9
|
import { Valuations } from './Valuations';
|
|
9
|
-
import {
|
|
10
|
-
export { Attestation, Auth, DeviceDefinitions, Devices, TokenExchange, Trips, Valuations,
|
|
10
|
+
import { VehicleTriggers } from './VehicleTriggers';
|
|
11
|
+
export { Agents, Attestation, Auth, DeviceDefinitions, Devices, TokenExchange, Trips, Valuations, VehicleTriggers, };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** @format */
|
|
2
2
|
import { Resource } from '../../Resource';
|
|
3
3
|
import { DimoEnvironment } from '../../../environments';
|
|
4
|
-
declare class
|
|
4
|
+
declare class VehicleTriggers extends Resource {
|
|
5
5
|
constructor(api: any, env: keyof typeof DimoEnvironment);
|
|
6
6
|
}
|
|
7
|
-
export {
|
|
7
|
+
export { VehicleTriggers };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/** @format */
|
|
2
2
|
import { Resource } from '../../Resource';
|
|
3
|
-
class
|
|
3
|
+
class VehicleTriggers extends Resource {
|
|
4
4
|
constructor(api, env) {
|
|
5
|
-
super(api, '
|
|
5
|
+
super(api, 'VehicleTriggers', env);
|
|
6
6
|
this.setResource({
|
|
7
7
|
listWebhooks: {
|
|
8
8
|
method: 'GET',
|
|
@@ -14,13 +14,14 @@ class VehicleEvents extends Resource {
|
|
|
14
14
|
path: '/v1/webhooks',
|
|
15
15
|
body: {
|
|
16
16
|
service: true,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
metricName: true,
|
|
18
|
+
condition: true,
|
|
19
|
+
coolDownPeriod: true,
|
|
20
20
|
description: false,
|
|
21
|
-
|
|
21
|
+
targetURL: true,
|
|
22
22
|
status: true,
|
|
23
|
-
|
|
23
|
+
verificationToken: true,
|
|
24
|
+
displayName: false
|
|
24
25
|
},
|
|
25
26
|
auth: 'developer_jwt',
|
|
26
27
|
},
|
|
@@ -28,14 +29,7 @@ class VehicleEvents extends Resource {
|
|
|
28
29
|
method: 'PUT',
|
|
29
30
|
path: '/v1/webhooks/:webhookId',
|
|
30
31
|
body: {
|
|
31
|
-
|
|
32
|
-
data: true,
|
|
33
|
-
trigger: true,
|
|
34
|
-
setup: true,
|
|
35
|
-
description: false,
|
|
36
|
-
target_uri: true,
|
|
37
|
-
status: true,
|
|
38
|
-
verification_token: true,
|
|
32
|
+
request: true
|
|
39
33
|
},
|
|
40
34
|
auth: 'developer_jwt',
|
|
41
35
|
},
|
|
@@ -56,12 +50,12 @@ class VehicleEvents extends Resource {
|
|
|
56
50
|
},
|
|
57
51
|
listVehicleSubscriptions: {
|
|
58
52
|
method: 'GET',
|
|
59
|
-
path: '/v1/webhooks/vehicles/:
|
|
53
|
+
path: '/v1/webhooks/vehicles/:tokenDID',
|
|
60
54
|
auth: 'developer_jwt',
|
|
61
55
|
},
|
|
62
56
|
subscribeVehicle: {
|
|
63
57
|
method: 'POST',
|
|
64
|
-
path: '/v1/webhooks/:webhookId/subscribe/:
|
|
58
|
+
path: '/v1/webhooks/:webhookId/subscribe/:tokenDID',
|
|
65
59
|
auth: 'developer_jwt',
|
|
66
60
|
},
|
|
67
61
|
subscribeAllVehicles: {
|
|
@@ -71,7 +65,7 @@ class VehicleEvents extends Resource {
|
|
|
71
65
|
},
|
|
72
66
|
unsubscribeVehicle: {
|
|
73
67
|
method: 'DELETE',
|
|
74
|
-
path: '/v1/webhooks/:webhookId/unsubscribe/:
|
|
68
|
+
path: '/v1/webhooks/:webhookId/unsubscribe/:tokenDID',
|
|
75
69
|
auth: 'developer_jwt',
|
|
76
70
|
},
|
|
77
71
|
unsubscribeAllVehicles: {
|
|
@@ -82,4 +76,4 @@ class VehicleEvents extends Resource {
|
|
|
82
76
|
});
|
|
83
77
|
}
|
|
84
78
|
}
|
|
85
|
-
export {
|
|
79
|
+
export { VehicleTriggers };
|