@amigo-ai/platform-sdk 0.4.0 → 0.4.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/README.md +60 -55
- package/dist/core/webhooks.js +8 -2
- package/dist/core/webhooks.js.map +1 -1
- package/dist/index.cjs +10 -2
- package/dist/index.cjs.map +2 -2
- package/dist/index.mjs +10 -2
- package/dist/index.mjs.map +2 -2
- package/dist/types/core/webhooks.d.ts.map +1 -1
- package/package.json +9 -4
package/README.md
CHANGED
|
@@ -23,29 +23,38 @@ const client = new AmigoClient({
|
|
|
23
23
|
})
|
|
24
24
|
|
|
25
25
|
// List agents
|
|
26
|
-
const { items: agents } = await client.agents.list()
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
const { items: agents } = await client.agents.list({ limit: 10 })
|
|
27
|
+
console.log(agents.map((agent) => agent.name))
|
|
28
|
+
|
|
29
|
+
// Search entities in the world model
|
|
30
|
+
const entityResults = await client.world.listEntities({
|
|
31
|
+
q: 'Jane Doe',
|
|
32
|
+
entity_type: ['patient'],
|
|
33
|
+
limit: 5,
|
|
33
34
|
})
|
|
35
|
+
console.log(entityResults.entities[0]?.display_name)
|
|
34
36
|
|
|
35
37
|
// Get call analytics for the last 30 days
|
|
36
|
-
const stats = await client.analytics.getCalls({
|
|
38
|
+
const stats = await client.analytics.getCalls({ days: 30 })
|
|
37
39
|
console.log(stats.total_calls, stats.avg_duration_seconds)
|
|
38
40
|
```
|
|
39
41
|
|
|
42
|
+
## Examples and Docs
|
|
43
|
+
|
|
44
|
+
- Product docs and API reference: [docs.amigo.ai](https://docs.amigo.ai/)
|
|
45
|
+
- Repo-local SDK examples: [examples/README.md](./examples/README.md)
|
|
46
|
+
|
|
47
|
+
The docs site remains the primary reference. The examples in this repo stay close to the package surface and are typechecked in CI to reduce drift.
|
|
48
|
+
|
|
40
49
|
## Configuration
|
|
41
50
|
|
|
42
|
-
| Option
|
|
43
|
-
|
|
44
|
-
| `apiKey`
|
|
45
|
-
| `workspaceId` | `string`
|
|
46
|
-
| `baseUrl`
|
|
47
|
-
| `retry`
|
|
48
|
-
| `fetch`
|
|
51
|
+
| Option | Type | Required | Description |
|
|
52
|
+
| ------------- | -------------- | -------- | -------------------------------------------------------------------- |
|
|
53
|
+
| `apiKey` | `string` | Yes | Your Platform API key — create one at Workspace Settings > API Keys |
|
|
54
|
+
| `workspaceId` | `string` | Yes | Your workspace ID — all resource operations are scoped to this |
|
|
55
|
+
| `baseUrl` | `string` | No | Override the API base URL (default: `https://api.platform.amigo.ai`) |
|
|
56
|
+
| `retry` | `RetryOptions` | No | Retry configuration for transient failures |
|
|
57
|
+
| `fetch` | `typeof fetch` | No | Custom fetch for BFF proxy, cookie forwarding, or test mocking |
|
|
49
58
|
|
|
50
59
|
### Retry options
|
|
51
60
|
|
|
@@ -54,8 +63,8 @@ const client = new AmigoClient({
|
|
|
54
63
|
apiKey: 'your-key',
|
|
55
64
|
workspaceId: 'your-workspace-id',
|
|
56
65
|
retry: {
|
|
57
|
-
maxAttempts: 3,
|
|
58
|
-
baseDelayMs: 250,
|
|
66
|
+
maxAttempts: 3, // Total attempts including first. Default: 3
|
|
67
|
+
baseDelayMs: 250, // Base delay for exponential backoff. Default: 250
|
|
59
68
|
maxDelayMs: 30000, // Cap on delay. Default: 30_000
|
|
60
69
|
},
|
|
61
70
|
})
|
|
@@ -71,8 +80,7 @@ The SDK ships with generated OpenAPI types and re-exports them for direct use:
|
|
|
71
80
|
import type { components, operations, paths } from '@amigo-ai/platform-sdk'
|
|
72
81
|
|
|
73
82
|
type Agent = components['schemas']['AgentResponse']
|
|
74
|
-
type ListAgentsQuery =
|
|
75
|
-
operations['list_agents_v1__workspace_id__agents_get']['parameters']['query']
|
|
83
|
+
type ListAgentsQuery = operations['list_agents_v1__workspace_id__agents_get']['parameters']['query']
|
|
76
84
|
```
|
|
77
85
|
|
|
78
86
|
Public builds are generated from the committed [`openapi.json`](./openapi.json) snapshot in this repo so type output stays deterministic across machines and CI runs. When you need to refresh that snapshot, run:
|
|
@@ -157,25 +165,27 @@ console.log(service.agent_name, service.channel_type, service.version_sets)
|
|
|
157
165
|
The world model tracks entities (patients, contacts, appointments) and the events that flow through them.
|
|
158
166
|
|
|
159
167
|
```typescript
|
|
160
|
-
//
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
168
|
+
// Filter entities with simple list queries
|
|
169
|
+
const patients = await client.world.listEntities({
|
|
170
|
+
q: 'Jane Doe',
|
|
171
|
+
entity_type: ['patient'],
|
|
172
|
+
limit: 10,
|
|
165
173
|
})
|
|
174
|
+
console.log(patients.entities.length)
|
|
166
175
|
|
|
167
|
-
//
|
|
168
|
-
await client.world.
|
|
169
|
-
|
|
170
|
-
event_type: 'call_completed',
|
|
171
|
-
data: { duration_seconds: 180, outcome: 'appointment_scheduled' },
|
|
172
|
-
})
|
|
176
|
+
// Get a single entity
|
|
177
|
+
const patient = await client.world.getEntity('entity-id')
|
|
178
|
+
console.log(patient.display_name, patient.entity_type)
|
|
173
179
|
|
|
174
180
|
// Query timeline
|
|
175
|
-
const timeline = await client.world.getTimeline(
|
|
181
|
+
const timeline = await client.world.getTimeline('entity-id', { limit: 20 })
|
|
176
182
|
|
|
177
|
-
//
|
|
178
|
-
const results = await client.world.search(
|
|
183
|
+
// Semantic search over the world model
|
|
184
|
+
const results = await client.world.search({
|
|
185
|
+
q: 'Jane Doe',
|
|
186
|
+
entity_type: 'patient',
|
|
187
|
+
limit: 5,
|
|
188
|
+
})
|
|
179
189
|
|
|
180
190
|
// View sync status from connectors
|
|
181
191
|
const syncStatus = await client.world.getSyncStatusBySink()
|
|
@@ -209,7 +219,7 @@ console.log(dashboard.call_volume.value, dashboard.call_volume.delta_pct)
|
|
|
209
219
|
console.log(dashboard.avg_quality.value)
|
|
210
220
|
|
|
211
221
|
// Call volume time series
|
|
212
|
-
const calls = await client.analytics.getCalls({
|
|
222
|
+
const calls = await client.analytics.getCalls({ days: 30, interval: '1d' })
|
|
213
223
|
console.log(calls.total_calls, calls.calls_by_date)
|
|
214
224
|
|
|
215
225
|
// Per-agent performance
|
|
@@ -247,11 +257,9 @@ console.log(analytics.coverage_rate, analytics.total_facts)
|
|
|
247
257
|
const { items: integrations } = await client.integrations.list({ enabled: true })
|
|
248
258
|
|
|
249
259
|
// Test a specific endpoint
|
|
250
|
-
const result = await client.integrations.testEndpoint(
|
|
251
|
-
'
|
|
252
|
-
|
|
253
|
-
{ textQuery: '123 Main St, Springfield' },
|
|
254
|
-
)
|
|
260
|
+
const result = await client.integrations.testEndpoint('integration-id', 'geocode', {
|
|
261
|
+
textQuery: '123 Main St, Springfield',
|
|
262
|
+
})
|
|
255
263
|
```
|
|
256
264
|
|
|
257
265
|
### Data Sources
|
|
@@ -390,10 +398,7 @@ const deliveries = await client.webhookDestinations.listDeliveries(dest.id)
|
|
|
390
398
|
Use the raw request body when verifying webhook deliveries. Timestamped signatures are replay-protected by default.
|
|
391
399
|
|
|
392
400
|
```typescript
|
|
393
|
-
import {
|
|
394
|
-
parseWebhookEvent,
|
|
395
|
-
WebhookVerificationError,
|
|
396
|
-
} from '@amigo-ai/platform-sdk'
|
|
401
|
+
import { parseWebhookEvent, WebhookVerificationError } from '@amigo-ai/platform-sdk'
|
|
397
402
|
|
|
398
403
|
const body = await request.text()
|
|
399
404
|
|
|
@@ -482,18 +487,18 @@ Webhook verification errors are separate from API transport errors and throw `We
|
|
|
482
487
|
|
|
483
488
|
### Error classes
|
|
484
489
|
|
|
485
|
-
| Class
|
|
486
|
-
|
|
487
|
-
| `BadRequestError`
|
|
488
|
-
| `AuthenticationError` | 401
|
|
489
|
-
| `PermissionError`
|
|
490
|
-
| `NotFoundError`
|
|
491
|
-
| `ConflictError`
|
|
492
|
-
| `ValidationError`
|
|
493
|
-
| `RateLimitError`
|
|
494
|
-
| `ServerError`
|
|
495
|
-
| `ConfigurationError`
|
|
496
|
-
| `NetworkError`
|
|
490
|
+
| Class | HTTP Status | Description |
|
|
491
|
+
| --------------------- | ----------- | --------------------------------------- |
|
|
492
|
+
| `BadRequestError` | 400 | Malformed request |
|
|
493
|
+
| `AuthenticationError` | 401 | Invalid or expired API key |
|
|
494
|
+
| `PermissionError` | 403 | Insufficient permissions |
|
|
495
|
+
| `NotFoundError` | 404 | Resource does not exist |
|
|
496
|
+
| `ConflictError` | 409 | Duplicate slug or version conflict |
|
|
497
|
+
| `ValidationError` | 422 | Request body validation failure |
|
|
498
|
+
| `RateLimitError` | 429 | Too many requests — check `.retryAfter` |
|
|
499
|
+
| `ServerError` | 5xx | Server-side error |
|
|
500
|
+
| `ConfigurationError` | — | SDK misconfiguration at init time |
|
|
501
|
+
| `NetworkError` | — | Fetch/network failure |
|
|
497
502
|
|
|
498
503
|
## CommonJS (CJS) usage
|
|
499
504
|
|
package/dist/core/webhooks.js
CHANGED
|
@@ -63,7 +63,9 @@ function normalizeVerificationOptions(payloadOrOptions, signature, secret) {
|
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
65
|
function normalizeParseOptions(payloadOrOptions, signature, secret) {
|
|
66
|
-
if (typeof payloadOrOptions === 'object' &&
|
|
66
|
+
if (typeof payloadOrOptions === 'object' &&
|
|
67
|
+
payloadOrOptions !== null &&
|
|
68
|
+
'payload' in payloadOrOptions) {
|
|
67
69
|
return payloadOrOptions;
|
|
68
70
|
}
|
|
69
71
|
if (!signature || !secret) {
|
|
@@ -92,7 +94,7 @@ async function signWebhookPayload(payload, secret, timestamp) {
|
|
|
92
94
|
const message = timestamp
|
|
93
95
|
? concatUint8Arrays(textEncoder.encode(`v1:${timestamp}:`), payload)
|
|
94
96
|
: payload;
|
|
95
|
-
const mac = await crypto.subtle.sign('HMAC', key, message);
|
|
97
|
+
const mac = await crypto.subtle.sign('HMAC', key, toCryptoBuffer(message));
|
|
96
98
|
return new Uint8Array(mac);
|
|
97
99
|
}
|
|
98
100
|
function normalizeSignature(signature) {
|
|
@@ -128,4 +130,8 @@ function concatUint8Arrays(left, right) {
|
|
|
128
130
|
combined.set(right, left.length);
|
|
129
131
|
return combined;
|
|
130
132
|
}
|
|
133
|
+
function toCryptoBuffer(bytes) {
|
|
134
|
+
const copy = Uint8Array.from(bytes);
|
|
135
|
+
return copy.buffer;
|
|
136
|
+
}
|
|
131
137
|
//# sourceMappingURL=webhooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../../src/core/webhooks.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAA;AACrC,MAAM,qBAAqB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAA;AAwB3C,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACjD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAA;QACtC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;IACnD,CAAC;CACF;
|
|
1
|
+
{"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../../src/core/webhooks.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAA;AACrC,MAAM,qBAAqB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAA;AAwB3C,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACjD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAA;QACtC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;IACnD,CAAC;CACF;AAQD,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,gBAAgF,EAChF,SAAkB,EAClB,MAAe;IAEf,MAAM,OAAO,GAAG,4BA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,GAAG,MAAM,CAAC,SAAS,CAAC,CAAA;IACjC,IAAI,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QAC7B,OAAO,OAAO,GAAG,iBAAiB,CAAC,CAAC,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,OAAO,CAAA;IAC/D,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;IACpC,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAA;AAClD,CAAC;AAED,SAAS,iBAAiB,CAAC,IAAgB,EAAE,KAAiB;IAC5D,MAAM,QAAQ,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAA;IAC3D,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;IACrB,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;IAChC,OAAO,QAAQ,CAAA;AACjB,CAAC;AAED,SAAS,cAAc,CAAC,KAAiB;IACvC,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACnC,OAAO,IAAI,CAAC,MAAM,CAAA;AACpB,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -2211,7 +2211,11 @@ var WebhookVerificationError = class extends Error {
|
|
|
2211
2211
|
async function verifyWebhookSignature(payloadOrOptions, signature, secret) {
|
|
2212
2212
|
const options = normalizeVerificationOptions(payloadOrOptions, signature, secret);
|
|
2213
2213
|
const payloadBytes = toUint8Array(options.payload);
|
|
2214
|
-
const expectedSignature = await signWebhookPayload(
|
|
2214
|
+
const expectedSignature = await signWebhookPayload(
|
|
2215
|
+
payloadBytes,
|
|
2216
|
+
options.secret,
|
|
2217
|
+
options.timestamp
|
|
2218
|
+
);
|
|
2215
2219
|
const actualSignature = normalizeSignature(options.signature);
|
|
2216
2220
|
if (!actualSignature || !constantTimeEqual(expectedSignature, actualSignature)) {
|
|
2217
2221
|
return false;
|
|
@@ -2292,7 +2296,7 @@ async function signWebhookPayload(payload, secret, timestamp) {
|
|
|
2292
2296
|
["sign"]
|
|
2293
2297
|
);
|
|
2294
2298
|
const message = timestamp ? concatUint8Arrays(textEncoder.encode(`v1:${timestamp}:`), payload) : payload;
|
|
2295
|
-
const mac = await crypto.subtle.sign("HMAC", key, message);
|
|
2299
|
+
const mac = await crypto.subtle.sign("HMAC", key, toCryptoBuffer(message));
|
|
2296
2300
|
return new Uint8Array(mac);
|
|
2297
2301
|
}
|
|
2298
2302
|
function normalizeSignature(signature) {
|
|
@@ -2328,6 +2332,10 @@ function concatUint8Arrays(left, right) {
|
|
|
2328
2332
|
combined.set(right, left.length);
|
|
2329
2333
|
return combined;
|
|
2330
2334
|
}
|
|
2335
|
+
function toCryptoBuffer(bytes) {
|
|
2336
|
+
const copy = Uint8Array.from(bytes);
|
|
2337
|
+
return copy.buffer;
|
|
2338
|
+
}
|
|
2331
2339
|
|
|
2332
2340
|
// src/index.ts
|
|
2333
2341
|
var DEFAULT_BASE_URL = "https://api.platform.amigo.ai";
|