@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/dist/index.js CHANGED
@@ -1217,21 +1217,167 @@ function createToolsApi(cfg) {
1217
1217
  };
1218
1218
  }
1219
1219
 
1220
+ // src/utils/catalog-voices.ts
1221
+ var FALLBACK_LOCALE = "und";
1222
+ var FALLBACK_PROVIDER = "catalog";
1223
+ function catalogItemToVoice(item) {
1224
+ const metadata = normalizeVoiceMetadata(item.metadata);
1225
+ const locale = metadata.locale ?? metadata.language ?? FALLBACK_LOCALE;
1226
+ return {
1227
+ id: item.id,
1228
+ providerVoiceId: metadata.providerVoiceId ?? item.systemIdentifier,
1229
+ name: item.name,
1230
+ gender: metadata.gender,
1231
+ locale,
1232
+ tags: metadata.tags ?? [],
1233
+ previewUrl: metadata.previewUrl ?? void 0,
1234
+ provider: metadata.provider ?? FALLBACK_PROVIDER
1235
+ };
1236
+ }
1237
+ function normalizeVoiceMetadata(metadata) {
1238
+ if (!metadata || typeof metadata !== "object") {
1239
+ return {};
1240
+ }
1241
+ const raw = metadata;
1242
+ return {
1243
+ language: pickString(raw.language),
1244
+ locale: pickString(raw.locale, true),
1245
+ gender: pickGender(raw.gender),
1246
+ provider: pickString(raw.provider, true),
1247
+ previewUrl: pickString(raw.previewUrl, true),
1248
+ tags: pickStringArray(raw.tags),
1249
+ providerVoiceId: pickString(raw.providerVoiceId)
1250
+ };
1251
+ }
1252
+ function pickString(value, allowNull = false) {
1253
+ if (typeof value === "string") {
1254
+ return value;
1255
+ }
1256
+ if (allowNull && value === null) {
1257
+ return null;
1258
+ }
1259
+ return void 0;
1260
+ }
1261
+ function pickStringArray(value) {
1262
+ if (!Array.isArray(value)) {
1263
+ return void 0;
1264
+ }
1265
+ const items = value.filter(
1266
+ (item) => typeof item === "string"
1267
+ );
1268
+ return items.length > 0 ? items : void 0;
1269
+ }
1270
+ function pickGender(value) {
1271
+ if (value === "female" || value === "male" || value === "neutral") {
1272
+ return value;
1273
+ }
1274
+ return void 0;
1275
+ }
1276
+
1277
+ // src/utils/catalog-filter.ts
1278
+ import { Query } from "@getsupervisor/api-query-builder";
1279
+ function createCatalogTypeQuery(type) {
1280
+ return new Query((qb) => qb.eq("type", type));
1281
+ }
1282
+ function ensureCatalogTypeFilter(filter, type) {
1283
+ const requiredQuery = createCatalogTypeQuery(type);
1284
+ const requiredExpression = requiredQuery.build();
1285
+ if (filter === void 0 || filter === null) {
1286
+ return requiredQuery;
1287
+ }
1288
+ if (typeof filter === "string") {
1289
+ return ensureTypeForString(filter, requiredQuery, requiredExpression);
1290
+ }
1291
+ if (isQueryBuilderLike(filter)) {
1292
+ return ensureTypeForBuilder(filter, requiredQuery, requiredExpression);
1293
+ }
1294
+ if (isPlainObject2(filter)) {
1295
+ return ensureTypeForObject(filter, type);
1296
+ }
1297
+ return filter;
1298
+ }
1299
+ function ensureTypeForString(value, requiredQuery, requiredExpression) {
1300
+ const normalized = value.trim();
1301
+ if (!normalized.length) {
1302
+ return requiredQuery;
1303
+ }
1304
+ return containsTypePredicate(normalized, requiredExpression) ? normalized : `and(${requiredExpression},${normalized})`;
1305
+ }
1306
+ function ensureTypeForBuilder(builder, requiredQuery, requiredExpression) {
1307
+ const normalized = builder.build().trim();
1308
+ if (!normalized.length) {
1309
+ return requiredQuery;
1310
+ }
1311
+ if (containsTypePredicate(normalized, requiredExpression)) {
1312
+ return builder;
1313
+ }
1314
+ const combined = `and(${requiredExpression},${normalized})`;
1315
+ return {
1316
+ build: () => combined
1317
+ };
1318
+ }
1319
+ function ensureTypeForObject(candidate, type) {
1320
+ if (hasTypeEquality(candidate, type)) {
1321
+ return candidate;
1322
+ }
1323
+ const typeConfig = candidate.type;
1324
+ const normalizedType = isPlainObject2(typeConfig) ? { ...typeConfig, eq: type } : { eq: type };
1325
+ return {
1326
+ ...candidate,
1327
+ type: normalizedType
1328
+ };
1329
+ }
1330
+ function hasTypeEquality(candidate, type) {
1331
+ const typeConfig = candidate.type;
1332
+ if (typeof typeConfig === "string") {
1333
+ return typeConfig === type;
1334
+ }
1335
+ if (!isPlainObject2(typeConfig)) {
1336
+ return false;
1337
+ }
1338
+ return typeConfig.eq === type;
1339
+ }
1340
+ function containsTypePredicate(expression, required) {
1341
+ const normalizedExpression = expression.replace(/\s+/g, "").toLowerCase();
1342
+ const normalizedRequired = required.replace(/\s+/g, "").toLowerCase();
1343
+ return normalizedExpression.includes(normalizedRequired);
1344
+ }
1345
+ function isQueryBuilderLike(candidate) {
1346
+ return !!candidate && typeof candidate === "object" && typeof candidate.build === "function";
1347
+ }
1348
+ function isPlainObject2(value) {
1349
+ if (value === null || typeof value !== "object") {
1350
+ return false;
1351
+ }
1352
+ const proto = Object.getPrototypeOf(value);
1353
+ return proto === Object.prototype || proto === null;
1354
+ }
1355
+
1220
1356
  // src/api/voices.ts
1357
+ function mapCatalogResponseToVoiceList(response) {
1358
+ return {
1359
+ data: response.data.filter((item) => item.type === "voice").map(catalogItemToVoice),
1360
+ meta: response.meta
1361
+ };
1362
+ }
1221
1363
  function createVoicesApi(cfg) {
1222
1364
  const { base, doFetch } = createHttp(cfg);
1223
1365
  const fetchVoicesPage = async (options = {}) => {
1224
- const { agentId, agentVersionId, gender, locale } = options;
1366
+ const normalizedOptions = {
1367
+ ...options,
1368
+ filter: ensureCatalogTypeFilter(options.filter, "voice")
1369
+ };
1370
+ const { agentId, agentVersionId, gender, locale } = normalizedOptions;
1225
1371
  const query = serializeListOptions(
1226
1372
  {
1227
- page: options.page,
1228
- limit: options.limit ?? options.pageSize,
1229
- sort: options.sort,
1230
- fields: options.fields,
1231
- include: options.include,
1232
- search: options.search,
1233
- filter: options.filter,
1234
- or: options.or
1373
+ page: normalizedOptions.page,
1374
+ limit: normalizedOptions.limit ?? normalizedOptions.pageSize,
1375
+ sort: normalizedOptions.sort,
1376
+ fields: normalizedOptions.fields,
1377
+ include: normalizedOptions.include,
1378
+ search: normalizedOptions.search,
1379
+ filter: normalizedOptions.filter,
1380
+ or: normalizedOptions.or
1235
1381
  },
1236
1382
  {
1237
1383
  agentId,
@@ -1240,11 +1386,12 @@ function createVoicesApi(cfg) {
1240
1386
  locale
1241
1387
  }
1242
1388
  );
1243
- const res = await doFetch(`${base}/voices`, {
1389
+ const res = await doFetch(`${base}/catalogs/items`, {
1244
1390
  method: "GET",
1245
1391
  query
1246
1392
  });
1247
- return res.json();
1393
+ const raw = await res.json();
1394
+ return mapCatalogResponseToVoiceList(raw);
1248
1395
  };
1249
1396
  return {
1250
1397
  async list(options = {}) {