@amigo-ai/platform-sdk 0.6.0 → 0.7.0
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/api.md +9 -0
- package/dist/core/utils.js +17 -6
- package/dist/core/utils.js.map +1 -1
- package/dist/index.cjs +63 -6
- package/dist/index.cjs.map +3 -3
- package/dist/index.js +9 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +63 -6
- package/dist/index.mjs.map +3 -3
- package/dist/resources/metrics.js +37 -0
- package/dist/resources/metrics.js.map +1 -0
- package/dist/types/core/utils.d.ts +13 -10
- package/dist/types/core/utils.d.ts.map +1 -1
- package/dist/types/generated/api.d.ts +641 -29
- package/dist/types/generated/api.d.ts.map +1 -1
- package/dist/types/index.d.cts +165 -0
- package/dist/types/index.d.cts.map +1 -0
- package/dist/types/index.d.ts +27 -8
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/resources/functions.d.ts.map +1 -1
- package/dist/types/resources/metrics.d.ts +136 -0
- package/dist/types/resources/metrics.d.ts.map +1 -0
- package/dist/types/resources/settings.d.ts.map +1 -1
- package/package.json +15 -9
package/api.md
CHANGED
|
@@ -52,6 +52,8 @@ Notes:
|
|
|
52
52
|
- Pagination and response helpers: `paginate`, `buildLastResponse`, `extractRequestId`
|
|
53
53
|
- Response and hook types: `PaginatedList`, `ListParams`, `LastResponseInfo`, `ResponseMetadata`, `WithResponseMetadata`, `AmigoResponse`, `RetryOptions`, `RateLimitInfo`, `ClientHooks`, `RequestHookContext`, `ResponseHookContext`, `ErrorHookContext`
|
|
54
54
|
- Generated OpenAPI types: `paths`, `components`, `operations`
|
|
55
|
+
- Generated API types are produced with `npm run gen-types` from the committed `openapi.json` snapshot.
|
|
56
|
+
- The generated OpenAPI types may include spec-only endpoints that do not yet have resource wrappers; use the low-level `GET`/`POST`/`PUT`/`PATCH`/`DELETE` helpers for those operations until a dedicated resource is added. Current spec-only groups include `/use-cases` and `/voicemail`.
|
|
55
57
|
|
|
56
58
|
## Resources
|
|
57
59
|
|
|
@@ -271,6 +273,13 @@ All workspace-scoped resources also expose `withOptions(options)`.
|
|
|
271
273
|
- `recommend`
|
|
272
274
|
- `getIntelligence`
|
|
273
275
|
|
|
276
|
+
### `metrics`
|
|
277
|
+
|
|
278
|
+
- `listLatest`
|
|
279
|
+
- `getCatalog`
|
|
280
|
+
- `getValues`
|
|
281
|
+
- `getTrend`
|
|
282
|
+
|
|
274
283
|
### `settings`
|
|
275
284
|
|
|
276
285
|
- `voice.get`
|
package/dist/core/utils.js
CHANGED
|
@@ -15,17 +15,25 @@ export function buildLastResponse(response) {
|
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
|
-
* Extracts the data payload from an openapi-fetch response
|
|
19
|
-
*
|
|
18
|
+
* Extracts the data payload from an openapi-fetch response.
|
|
19
|
+
* Empty-body success responses return undefined; other empty responses throw.
|
|
20
20
|
*/
|
|
21
|
-
export function extractData(result) {
|
|
21
|
+
export function extractData(result, options = {}) {
|
|
22
22
|
if (result.data !== undefined) {
|
|
23
23
|
return attachResponseMetadata(result.data, result.response);
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
if (isEmptyBodySuccess(result.response) || options.allowEmptyBody) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
// Degenerate openapi-fetch results with both data and error keep the SDK's
|
|
29
|
+
// original data-first behavior; without data, errors stay fatal.
|
|
30
|
+
if (result.error !== undefined) {
|
|
31
|
+
throw new ParseError('Unexpected error response from API', JSON.stringify(result.error));
|
|
32
|
+
}
|
|
33
|
+
throw new ParseError('Unexpected empty response from API', result.response ? `status=${result.response.status}` : undefined);
|
|
26
34
|
}
|
|
27
|
-
export function withResponse(result) {
|
|
28
|
-
const data = extractData(result);
|
|
35
|
+
export function withResponse(result, options = {}) {
|
|
36
|
+
const data = extractData(result, options);
|
|
29
37
|
const lastResponse = buildLastResponse(result.response);
|
|
30
38
|
return {
|
|
31
39
|
data,
|
|
@@ -65,6 +73,9 @@ function attachResponseMetadata(data, response) {
|
|
|
65
73
|
defineHiddenMetadata(target, 'lastResponse', lastResponse);
|
|
66
74
|
return target;
|
|
67
75
|
}
|
|
76
|
+
function isEmptyBodySuccess(response) {
|
|
77
|
+
return response?.status === 204 || response?.status === 205;
|
|
78
|
+
}
|
|
68
79
|
function defineHiddenMetadata(target, key, value) {
|
|
69
80
|
try {
|
|
70
81
|
Object.defineProperty(target, key, {
|
package/dist/core/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/core/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,qBAAqB,EAAsB,MAAM,iBAAiB,CAAA;AAuB3E,MAAM,UAAU,gBAAgB,CAAC,QAAkB;IACjD,OAAO,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAA;AAC7C,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,QAAkB;IAClD,OAAO;QACL,SAAS,EAAE,gBAAgB,CAAC,QAAQ,CAAC;QACrC,UAAU,EAAE,QAAQ,CAAC,MAAM;QAC3B,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,SAAS,EAAE,qBAAqB,CAAC,QAAQ,CAAC,OAAO,CAAC;KACnD,CAAA;AACH,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/core/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,qBAAqB,EAAsB,MAAM,iBAAiB,CAAA;AAuB3E,MAAM,UAAU,gBAAgB,CAAC,QAAkB;IACjD,OAAO,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAA;AAC7C,CAAC;AAED,MAAM,UAAU,iB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,GAAG,EAAE;YACjC,KAAK;YACL,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,IAAI;YAClB,QAAQ,EAAE,KAAK;SAChB,CAAC,CAAA;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,uCAAuC;IACzC,CAAC;AACH,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -478,17 +478,23 @@ function buildLastResponse(response) {
|
|
|
478
478
|
rateLimit: parseRateLimitHeaders(response.headers)
|
|
479
479
|
};
|
|
480
480
|
}
|
|
481
|
-
function extractData(result) {
|
|
481
|
+
function extractData(result, options = {}) {
|
|
482
482
|
if (result.data !== void 0) {
|
|
483
483
|
return attachResponseMetadata(result.data, result.response);
|
|
484
484
|
}
|
|
485
|
+
if (isEmptyBodySuccess(result.response) || options.allowEmptyBody) {
|
|
486
|
+
return void 0;
|
|
487
|
+
}
|
|
488
|
+
if (result.error !== void 0) {
|
|
489
|
+
throw new ParseError("Unexpected error response from API", JSON.stringify(result.error));
|
|
490
|
+
}
|
|
485
491
|
throw new ParseError(
|
|
486
492
|
"Unexpected empty response from API",
|
|
487
|
-
result.
|
|
493
|
+
result.response ? `status=${result.response.status}` : void 0
|
|
488
494
|
);
|
|
489
495
|
}
|
|
490
|
-
function withResponse(result) {
|
|
491
|
-
const data = extractData(result);
|
|
496
|
+
function withResponse(result, options = {}) {
|
|
497
|
+
const data = extractData(result, options);
|
|
492
498
|
const lastResponse = buildLastResponse(result.response);
|
|
493
499
|
return {
|
|
494
500
|
data,
|
|
@@ -518,6 +524,9 @@ function attachResponseMetadata(data, response) {
|
|
|
518
524
|
defineHiddenMetadata(target, "lastResponse", lastResponse);
|
|
519
525
|
return target;
|
|
520
526
|
}
|
|
527
|
+
function isEmptyBodySuccess(response) {
|
|
528
|
+
return response?.status === 204 || response?.status === 205;
|
|
529
|
+
}
|
|
521
530
|
function defineHiddenMetadata(target, key, value) {
|
|
522
531
|
try {
|
|
523
532
|
Object.defineProperty(target, key, {
|
|
@@ -2203,6 +2212,48 @@ var SimulationsResource = class extends WorkspaceScopedResource {
|
|
|
2203
2212
|
}
|
|
2204
2213
|
};
|
|
2205
2214
|
|
|
2215
|
+
// src/resources/metrics.ts
|
|
2216
|
+
var MetricsResource = class extends WorkspaceScopedResource {
|
|
2217
|
+
/** List the latest value for each metric in the workspace */
|
|
2218
|
+
async listLatest() {
|
|
2219
|
+
return extractData(
|
|
2220
|
+
await this.client.GET("/v1/{workspace_id}/metrics", {
|
|
2221
|
+
params: { path: { workspace_id: this.workspaceId } }
|
|
2222
|
+
})
|
|
2223
|
+
);
|
|
2224
|
+
}
|
|
2225
|
+
/** List available built-in and custom metric definitions */
|
|
2226
|
+
async getCatalog() {
|
|
2227
|
+
return extractData(
|
|
2228
|
+
await this.client.GET("/v1/{workspace_id}/metrics/catalog", {
|
|
2229
|
+
params: { path: { workspace_id: this.workspaceId } }
|
|
2230
|
+
})
|
|
2231
|
+
);
|
|
2232
|
+
}
|
|
2233
|
+
/** Get stored values for one metric key, optionally bounded by time range */
|
|
2234
|
+
async getValues(metricKey, params) {
|
|
2235
|
+
return extractData(
|
|
2236
|
+
await this.client.GET("/v1/{workspace_id}/metrics/{metric_key}", {
|
|
2237
|
+
params: {
|
|
2238
|
+
path: { workspace_id: this.workspaceId, metric_key: metricKey },
|
|
2239
|
+
query: params
|
|
2240
|
+
}
|
|
2241
|
+
})
|
|
2242
|
+
);
|
|
2243
|
+
}
|
|
2244
|
+
/** Get a recent time-series trend for one metric key */
|
|
2245
|
+
async getTrend(metricKey, params) {
|
|
2246
|
+
return extractData(
|
|
2247
|
+
await this.client.GET("/v1/{workspace_id}/metrics/{metric_key}/trend", {
|
|
2248
|
+
params: {
|
|
2249
|
+
path: { workspace_id: this.workspaceId, metric_key: metricKey },
|
|
2250
|
+
query: params
|
|
2251
|
+
}
|
|
2252
|
+
})
|
|
2253
|
+
);
|
|
2254
|
+
}
|
|
2255
|
+
};
|
|
2256
|
+
|
|
2206
2257
|
// src/resources/settings.ts
|
|
2207
2258
|
var SettingsResource = class extends WorkspaceScopedResource {
|
|
2208
2259
|
voice = {
|
|
@@ -3106,6 +3157,7 @@ var AmigoClient = class _AmigoClient {
|
|
|
3106
3157
|
integrations;
|
|
3107
3158
|
analytics;
|
|
3108
3159
|
simulations;
|
|
3160
|
+
metrics;
|
|
3109
3161
|
settings;
|
|
3110
3162
|
billing;
|
|
3111
3163
|
memory;
|
|
@@ -3162,10 +3214,14 @@ var AmigoClient = class _AmigoClient {
|
|
|
3162
3214
|
return withResponse(await this.resolveApiRequest(path, "DELETE", init));
|
|
3163
3215
|
}
|
|
3164
3216
|
async HEAD(path, ...[init]) {
|
|
3165
|
-
return withResponse(await this.resolveApiRequest(path, "HEAD", init)
|
|
3217
|
+
return withResponse(await this.resolveApiRequest(path, "HEAD", init), {
|
|
3218
|
+
allowEmptyBody: true
|
|
3219
|
+
});
|
|
3166
3220
|
}
|
|
3167
3221
|
async OPTIONS(path, ...[init]) {
|
|
3168
|
-
return withResponse(await this.resolveApiRequest(path, "OPTIONS", init)
|
|
3222
|
+
return withResponse(await this.resolveApiRequest(path, "OPTIONS", init), {
|
|
3223
|
+
allowEmptyBody: true
|
|
3224
|
+
});
|
|
3169
3225
|
}
|
|
3170
3226
|
static fromPlatformClient(client, workspaceId2, baseUrl) {
|
|
3171
3227
|
const instance = Object.create(_AmigoClient.prototype);
|
|
@@ -3193,6 +3249,7 @@ var AmigoClient = class _AmigoClient {
|
|
|
3193
3249
|
mutable.integrations = new IntegrationsResource(client, workspaceId2);
|
|
3194
3250
|
mutable.analytics = new AnalyticsResource(client, workspaceId2);
|
|
3195
3251
|
mutable.simulations = new SimulationsResource(client, workspaceId2);
|
|
3252
|
+
mutable.metrics = new MetricsResource(client, workspaceId2);
|
|
3196
3253
|
mutable.settings = new SettingsResource(client, workspaceId2);
|
|
3197
3254
|
mutable.billing = new BillingResource(client, workspaceId2);
|
|
3198
3255
|
mutable.memory = new MemoryResource(client, workspaceId2);
|