@getsupervisor/agents-studio-sdk 1.22.1 → 1.22.2
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/CHANGELOG.md +56 -225
- package/README.md +4 -4
- package/dist/index.cjs +158 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +158 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1268,21 +1268,167 @@ function createToolsApi(cfg) {
|
|
|
1268
1268
|
};
|
|
1269
1269
|
}
|
|
1270
1270
|
|
|
1271
|
+
// src/utils/catalog-voices.ts
|
|
1272
|
+
var FALLBACK_LOCALE = "und";
|
|
1273
|
+
var FALLBACK_PROVIDER = "catalog";
|
|
1274
|
+
function catalogItemToVoice(item) {
|
|
1275
|
+
const metadata = normalizeVoiceMetadata(item.metadata);
|
|
1276
|
+
const locale = metadata.locale ?? metadata.language ?? FALLBACK_LOCALE;
|
|
1277
|
+
return {
|
|
1278
|
+
id: item.id,
|
|
1279
|
+
providerVoiceId: metadata.providerVoiceId ?? item.systemIdentifier,
|
|
1280
|
+
name: item.name,
|
|
1281
|
+
gender: metadata.gender,
|
|
1282
|
+
locale,
|
|
1283
|
+
tags: metadata.tags ?? [],
|
|
1284
|
+
previewUrl: metadata.previewUrl ?? void 0,
|
|
1285
|
+
provider: metadata.provider ?? FALLBACK_PROVIDER
|
|
1286
|
+
};
|
|
1287
|
+
}
|
|
1288
|
+
function normalizeVoiceMetadata(metadata) {
|
|
1289
|
+
if (!metadata || typeof metadata !== "object") {
|
|
1290
|
+
return {};
|
|
1291
|
+
}
|
|
1292
|
+
const raw = metadata;
|
|
1293
|
+
return {
|
|
1294
|
+
language: pickString(raw.language),
|
|
1295
|
+
locale: pickString(raw.locale, true),
|
|
1296
|
+
gender: pickGender(raw.gender),
|
|
1297
|
+
provider: pickString(raw.provider, true),
|
|
1298
|
+
previewUrl: pickString(raw.previewUrl, true),
|
|
1299
|
+
tags: pickStringArray(raw.tags),
|
|
1300
|
+
providerVoiceId: pickString(raw.providerVoiceId)
|
|
1301
|
+
};
|
|
1302
|
+
}
|
|
1303
|
+
function pickString(value, allowNull = false) {
|
|
1304
|
+
if (typeof value === "string") {
|
|
1305
|
+
return value;
|
|
1306
|
+
}
|
|
1307
|
+
if (allowNull && value === null) {
|
|
1308
|
+
return null;
|
|
1309
|
+
}
|
|
1310
|
+
return void 0;
|
|
1311
|
+
}
|
|
1312
|
+
function pickStringArray(value) {
|
|
1313
|
+
if (!Array.isArray(value)) {
|
|
1314
|
+
return void 0;
|
|
1315
|
+
}
|
|
1316
|
+
const items = value.filter(
|
|
1317
|
+
(item) => typeof item === "string"
|
|
1318
|
+
);
|
|
1319
|
+
return items.length > 0 ? items : void 0;
|
|
1320
|
+
}
|
|
1321
|
+
function pickGender(value) {
|
|
1322
|
+
if (value === "female" || value === "male" || value === "neutral") {
|
|
1323
|
+
return value;
|
|
1324
|
+
}
|
|
1325
|
+
return void 0;
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
// src/utils/catalog-filter.ts
|
|
1329
|
+
var import_api_query_builder = require("@getsupervisor/api-query-builder");
|
|
1330
|
+
function createCatalogTypeQuery(type) {
|
|
1331
|
+
return new import_api_query_builder.Query((qb) => qb.eq("type", type));
|
|
1332
|
+
}
|
|
1333
|
+
function ensureCatalogTypeFilter(filter, type) {
|
|
1334
|
+
const requiredQuery = createCatalogTypeQuery(type);
|
|
1335
|
+
const requiredExpression = requiredQuery.build();
|
|
1336
|
+
if (filter === void 0 || filter === null) {
|
|
1337
|
+
return requiredQuery;
|
|
1338
|
+
}
|
|
1339
|
+
if (typeof filter === "string") {
|
|
1340
|
+
return ensureTypeForString(filter, requiredQuery, requiredExpression);
|
|
1341
|
+
}
|
|
1342
|
+
if (isQueryBuilderLike(filter)) {
|
|
1343
|
+
return ensureTypeForBuilder(filter, requiredQuery, requiredExpression);
|
|
1344
|
+
}
|
|
1345
|
+
if (isPlainObject2(filter)) {
|
|
1346
|
+
return ensureTypeForObject(filter, type);
|
|
1347
|
+
}
|
|
1348
|
+
return filter;
|
|
1349
|
+
}
|
|
1350
|
+
function ensureTypeForString(value, requiredQuery, requiredExpression) {
|
|
1351
|
+
const normalized = value.trim();
|
|
1352
|
+
if (!normalized.length) {
|
|
1353
|
+
return requiredQuery;
|
|
1354
|
+
}
|
|
1355
|
+
return containsTypePredicate(normalized, requiredExpression) ? normalized : `and(${requiredExpression},${normalized})`;
|
|
1356
|
+
}
|
|
1357
|
+
function ensureTypeForBuilder(builder, requiredQuery, requiredExpression) {
|
|
1358
|
+
const normalized = builder.build().trim();
|
|
1359
|
+
if (!normalized.length) {
|
|
1360
|
+
return requiredQuery;
|
|
1361
|
+
}
|
|
1362
|
+
if (containsTypePredicate(normalized, requiredExpression)) {
|
|
1363
|
+
return builder;
|
|
1364
|
+
}
|
|
1365
|
+
const combined = `and(${requiredExpression},${normalized})`;
|
|
1366
|
+
return {
|
|
1367
|
+
build: () => combined
|
|
1368
|
+
};
|
|
1369
|
+
}
|
|
1370
|
+
function ensureTypeForObject(candidate, type) {
|
|
1371
|
+
if (hasTypeEquality(candidate, type)) {
|
|
1372
|
+
return candidate;
|
|
1373
|
+
}
|
|
1374
|
+
const typeConfig = candidate.type;
|
|
1375
|
+
const normalizedType = isPlainObject2(typeConfig) ? { ...typeConfig, eq: type } : { eq: type };
|
|
1376
|
+
return {
|
|
1377
|
+
...candidate,
|
|
1378
|
+
type: normalizedType
|
|
1379
|
+
};
|
|
1380
|
+
}
|
|
1381
|
+
function hasTypeEquality(candidate, type) {
|
|
1382
|
+
const typeConfig = candidate.type;
|
|
1383
|
+
if (typeof typeConfig === "string") {
|
|
1384
|
+
return typeConfig === type;
|
|
1385
|
+
}
|
|
1386
|
+
if (!isPlainObject2(typeConfig)) {
|
|
1387
|
+
return false;
|
|
1388
|
+
}
|
|
1389
|
+
return typeConfig.eq === type;
|
|
1390
|
+
}
|
|
1391
|
+
function containsTypePredicate(expression, required) {
|
|
1392
|
+
const normalizedExpression = expression.replace(/\s+/g, "").toLowerCase();
|
|
1393
|
+
const normalizedRequired = required.replace(/\s+/g, "").toLowerCase();
|
|
1394
|
+
return normalizedExpression.includes(normalizedRequired);
|
|
1395
|
+
}
|
|
1396
|
+
function isQueryBuilderLike(candidate) {
|
|
1397
|
+
return !!candidate && typeof candidate === "object" && typeof candidate.build === "function";
|
|
1398
|
+
}
|
|
1399
|
+
function isPlainObject2(value) {
|
|
1400
|
+
if (value === null || typeof value !== "object") {
|
|
1401
|
+
return false;
|
|
1402
|
+
}
|
|
1403
|
+
const proto = Object.getPrototypeOf(value);
|
|
1404
|
+
return proto === Object.prototype || proto === null;
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1271
1407
|
// src/api/voices.ts
|
|
1408
|
+
function mapCatalogResponseToVoiceList(response) {
|
|
1409
|
+
return {
|
|
1410
|
+
data: response.data.filter((item) => item.type === "voice").map(catalogItemToVoice),
|
|
1411
|
+
meta: response.meta
|
|
1412
|
+
};
|
|
1413
|
+
}
|
|
1272
1414
|
function createVoicesApi(cfg) {
|
|
1273
1415
|
const { base, doFetch } = createHttp(cfg);
|
|
1274
1416
|
const fetchVoicesPage = async (options = {}) => {
|
|
1275
|
-
const
|
|
1417
|
+
const normalizedOptions = {
|
|
1418
|
+
...options,
|
|
1419
|
+
filter: ensureCatalogTypeFilter(options.filter, "voice")
|
|
1420
|
+
};
|
|
1421
|
+
const { agentId, agentVersionId, gender, locale } = normalizedOptions;
|
|
1276
1422
|
const query = serializeListOptions(
|
|
1277
1423
|
{
|
|
1278
|
-
page:
|
|
1279
|
-
limit:
|
|
1280
|
-
sort:
|
|
1281
|
-
fields:
|
|
1282
|
-
include:
|
|
1283
|
-
search:
|
|
1284
|
-
filter:
|
|
1285
|
-
or:
|
|
1424
|
+
page: normalizedOptions.page,
|
|
1425
|
+
limit: normalizedOptions.limit ?? normalizedOptions.pageSize,
|
|
1426
|
+
sort: normalizedOptions.sort,
|
|
1427
|
+
fields: normalizedOptions.fields,
|
|
1428
|
+
include: normalizedOptions.include,
|
|
1429
|
+
search: normalizedOptions.search,
|
|
1430
|
+
filter: normalizedOptions.filter,
|
|
1431
|
+
or: normalizedOptions.or
|
|
1286
1432
|
},
|
|
1287
1433
|
{
|
|
1288
1434
|
agentId,
|
|
@@ -1291,11 +1437,12 @@ function createVoicesApi(cfg) {
|
|
|
1291
1437
|
locale
|
|
1292
1438
|
}
|
|
1293
1439
|
);
|
|
1294
|
-
const res = await doFetch(`${base}/
|
|
1440
|
+
const res = await doFetch(`${base}/catalogs/items`, {
|
|
1295
1441
|
method: "GET",
|
|
1296
1442
|
query
|
|
1297
1443
|
});
|
|
1298
|
-
|
|
1444
|
+
const raw = await res.json();
|
|
1445
|
+
return mapCatalogResponseToVoiceList(raw);
|
|
1299
1446
|
};
|
|
1300
1447
|
return {
|
|
1301
1448
|
async list(options = {}) {
|