@getsupervisor/agents-studio-sdk 1.10.0 → 1.12.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/CHANGELOG.md +30 -0
- package/README.md +71 -31
- package/dist/index.cjs +244 -97
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +130 -1
- package/dist/index.d.ts +130 -1
- package/dist/index.js +241 -97
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
+
## v1.11.0
|
|
2
|
+
|
|
3
|
+
## [1.11.0](https://github.com/julio-supervisor/agents-studio-be/compare/v1.10.0...v1.11.0) (2025-10-19)
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* **agent-blueprints:** add module implementation and tests ([d631ce5](https://github.com/julio-supervisor/agents-studio-be/commit/d631ce59cf439306020d7e06fe561a808d1f2753))
|
|
8
|
+
* **blueprints:** implement agent blueprints API and integrate with client ([d166104](https://github.com/julio-supervisor/agents-studio-be/commit/d166104f04951d434f5cf89d068babff76ceb42d))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
## v1.10.0
|
|
12
|
+
|
|
13
|
+
## [1.10.0](https://github.com/julio-supervisor/agents-studio-be/compare/v1.9.0...v1.10.0) (2025-10-17)
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* **badges:** agregar archivo SVG de badge de cobertura ([9a880d4](https://github.com/julio-supervisor/agents-studio-be/commit/9a880d4e5f6983ab441aa04371ee5c49ee69de16))
|
|
18
|
+
* **ci:** add coverage badge generation and update README with coverage metrics ([ce21547](https://github.com/julio-supervisor/agents-studio-be/commit/ce21547440a70536fb461526dc8673c8e91ca1fc))
|
|
19
|
+
* **ci:** add NODE_AUTH_TOKEN build argument for Docker image ([5711a10](https://github.com/julio-supervisor/agents-studio-be/commit/5711a106667262e83b3598c71a7aa85b7468d3d2))
|
|
20
|
+
* **ci:** update coverage badge generation and enhance README with CI badges ([f65f7df](https://github.com/julio-supervisor/agents-studio-be/commit/f65f7df6d6eb40f401bbee0e9c9cc25dbce98476))
|
|
21
|
+
* **instructions:** implement instruction management module ([48f2a5e](https://github.com/julio-supervisor/agents-studio-be/commit/48f2a5e6549606707b2571a0844d433d8b8a8dc9))
|
|
22
|
+
|
|
23
|
+
### Bug Fixes
|
|
24
|
+
|
|
25
|
+
* **ci:** update coverage badge generation action and README to reflect new badge path ([0ba765c](https://github.com/julio-supervisor/agents-studio-be/commit/0ba765c67c7bba37aa5fbb2f75f0e0eb2d53cd93))
|
|
26
|
+
* **ci:** update coverage badge generation paths for consistency ([fec0e57](https://github.com/julio-supervisor/agents-studio-be/commit/fec0e57bd7e1f2e9de01058da89271b0a542a7b4))
|
|
27
|
+
* **docs:** actualizar descripciones de instrucciones en la especificación OpenAPI ([5f8a36f](https://github.com/julio-supervisor/agents-studio-be/commit/5f8a36f9ceab3b39d6f81a51ef9500d33eb5713a))
|
|
28
|
+
* **docs:** corregir la ruta del badge de cobertura en el README ([049c28f](https://github.com/julio-supervisor/agents-studio-be/commit/049c28fa4323f82b43616d92fd262309f8d84efa))
|
|
29
|
+
|
|
30
|
+
|
|
1
31
|
## v1.9.0
|
|
2
32
|
|
|
3
33
|
## [1.9.0](https://github.com/julio-supervisor/agents-studio-be/compare/v1.8.0...v1.9.0) (2025-10-16)
|
package/README.md
CHANGED
|
@@ -32,6 +32,29 @@ await client.agents
|
|
|
32
32
|
.instructions('version-1')
|
|
33
33
|
.create({ order: 1, content: 'Saluda con empatía' });
|
|
34
34
|
|
|
35
|
+
// administrar blueprints por versión
|
|
36
|
+
const blueprints = client.agents.blueprints(agent.agentId);
|
|
37
|
+
await blueprints
|
|
38
|
+
.version('version-1')
|
|
39
|
+
.create({
|
|
40
|
+
languageId: 'es-MX',
|
|
41
|
+
personalityName: 'Embajador de marca',
|
|
42
|
+
personalityRole: 'Consultor de adopción',
|
|
43
|
+
targetAudience: 'Usuarios nuevos',
|
|
44
|
+
mainGoal: 'Incrementar la activación',
|
|
45
|
+
personalityInitialGreeting: '¡Hola! Soy tu asistente de onboarding.',
|
|
46
|
+
personalityMessageStyleId: 'style-uuid',
|
|
47
|
+
personalityToneStyleId: 'tone-uuid',
|
|
48
|
+
requiredData: [{ key: 'industry', label: 'Industria' }],
|
|
49
|
+
criticalRules: ['Nunca compartas precios internos'],
|
|
50
|
+
topicsAllowed: ['onboarding', 'soporte'],
|
|
51
|
+
topicsForbidden: ['facturación'],
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// los helpers del entity también exponen blueprints
|
|
55
|
+
const agentBlueprint = await agent.blueprints.version('version-1').get();
|
|
56
|
+
console.log(agentBlueprint.personalityName);
|
|
57
|
+
|
|
35
58
|
// catálogo y recursos de tools
|
|
36
59
|
const tools = await client.tools.list({ agentType: 'chat' });
|
|
37
60
|
await client.tools.uploadResource(tools.data[0].identifier, formData);
|
|
@@ -100,60 +123,77 @@ await scoped.agents.get('agentId');
|
|
|
100
123
|
|
|
101
124
|
## Gestión de API Keys
|
|
102
125
|
|
|
103
|
-
Los endpoints `/v1/api-keys` permiten listar, crear y revocar credenciales por workspace.
|
|
126
|
+
Los endpoints `/v1/api-keys` permiten listar, crear y revocar credenciales por workspace. Desde la versión 1.10 el SDK expone un namespace dedicado para gestionar el ciclo de vida completo de las claves sin escribir boilerplate adicional.
|
|
104
127
|
|
|
105
128
|
> También puedes consumir el CRUD de agentes con API Keys pasando `apiKey` a `createClient` o usando `client.auth.setApiKey('sk_...')`. El SDK enviará el header `X-API-Key` automáticamente en cada llamada.
|
|
106
129
|
|
|
130
|
+
### Cliente dedicado: `client.apiKeys`
|
|
131
|
+
|
|
107
132
|
```ts
|
|
108
|
-
import {
|
|
133
|
+
import { createClient } from '@getsupervisor/agents-studio-sdk';
|
|
109
134
|
|
|
110
|
-
const
|
|
135
|
+
const client = createClient({
|
|
111
136
|
baseUrl: 'https://public-api.getsupervisor.ai',
|
|
112
137
|
headers: { Authorization: `Bearer ${token}` },
|
|
113
138
|
workspaceId: 'ws-123',
|
|
114
139
|
});
|
|
115
|
-
```
|
|
116
140
|
|
|
117
|
-
|
|
141
|
+
// 1. Listar credenciales activas
|
|
142
|
+
const keys = await client.apiKeys.list();
|
|
118
143
|
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
|
|
144
|
+
// 2. Emitir una nueva credencial (recuerda guardar el valor completo)
|
|
145
|
+
const created = await client.apiKeys.create({
|
|
146
|
+
name: 'Backend Integration',
|
|
147
|
+
environment: 'production',
|
|
148
|
+
scopes: ['agents:read', 'api-keys:read'],
|
|
149
|
+
});
|
|
150
|
+
console.log(created.key); // sólo se entrega una vez
|
|
122
151
|
|
|
123
|
-
//
|
|
152
|
+
// 3. Revelar el valor completo cuando necesites consultarlo de nuevo
|
|
153
|
+
const revealed = await client.apiKeys.show(created.id);
|
|
154
|
+
console.log(revealed.key); // también incluye metadatos actualizados
|
|
155
|
+
|
|
156
|
+
// 4. Revocar cuando deje de ser necesaria
|
|
157
|
+
await client.apiKeys.revoke(created.id);
|
|
124
158
|
```
|
|
125
159
|
|
|
126
|
-
Cada entrada incluye `id`, `name`, `environment`, `scopes`, fechas de auditoría y un `keyPreview` para
|
|
160
|
+
Cada entrada (`ApiKeySummary`) incluye `id`, `name`, `environment`, `scopes`, fechas de auditoría y un `keyPreview` para identificar la credencial sin exponerla por completo.
|
|
161
|
+
|
|
162
|
+
### Usar API Keys dinámicas
|
|
127
163
|
|
|
128
|
-
|
|
164
|
+
Puedes rotar claves en caliente con los helpers de autenticación:
|
|
129
165
|
|
|
130
166
|
```ts
|
|
131
|
-
|
|
132
|
-
method: 'POST',
|
|
133
|
-
headers: { 'Content-Type': 'application/json' },
|
|
134
|
-
body: JSON.stringify({
|
|
135
|
-
name: 'Backend Integration',
|
|
136
|
-
description: 'Sincronización nocturna de métricas',
|
|
137
|
-
environment: 'production',
|
|
138
|
-
scopes: ['agents:read', 'api-keys:read'],
|
|
139
|
-
}),
|
|
140
|
-
});
|
|
167
|
+
client.auth.setApiKey('sk_prod_live');
|
|
141
168
|
|
|
142
|
-
|
|
143
|
-
|
|
169
|
+
client.auth.useApiKey(() => readSecretFromVault());
|
|
170
|
+
|
|
171
|
+
client.auth.clearApiKey();
|
|
144
172
|
```
|
|
145
173
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
174
|
+
El SDK enviará siempre el header `X-API-Key`; si lo borras, retomará la autenticación configurada en `headers`.
|
|
175
|
+
|
|
176
|
+
### Alternativa low-level con `createHttp`
|
|
149
177
|
|
|
150
|
-
|
|
178
|
+
Si necesitas controlar manualmente las peticiones (por ejemplo, en un entorno con fetch custom), puedes reutilizar la misma librería interna:
|
|
151
179
|
|
|
152
180
|
```ts
|
|
153
|
-
|
|
154
|
-
```
|
|
181
|
+
import { createHttp } from '@getsupervisor/agents-studio-sdk';
|
|
155
182
|
|
|
156
|
-
|
|
183
|
+
const http = createHttp({
|
|
184
|
+
baseUrl: 'https://public-api.getsupervisor.ai',
|
|
185
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
186
|
+
workspaceId: 'ws-123',
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
const { key, ...metadata } = await http
|
|
190
|
+
.doFetch(`${http.base}/v1/api-keys`, {
|
|
191
|
+
method: 'POST',
|
|
192
|
+
headers: { 'content-type': 'application/json' },
|
|
193
|
+
body: JSON.stringify({ name: 'Automation', scopes: ['agents:read'] }),
|
|
194
|
+
})
|
|
195
|
+
.then((res) => res.json());
|
|
196
|
+
```
|
|
157
197
|
|
|
158
198
|
### Buenas prácticas
|
|
159
199
|
|
|
@@ -175,7 +215,7 @@ Consulta el OpenAPI (`docs/api-spec/openapi.yaml`) para revisar nuevos scopes co
|
|
|
175
215
|
|
|
176
216
|
## Novedades (octubre 2025)
|
|
177
217
|
|
|
178
|
-
- **Gestión de API Keys desde el SDK**:
|
|
218
|
+
- **Gestión de API Keys desde el SDK**: `client.apiKeys` expone helpers tipados para listar, crear y revocar credenciales con el mismo manejo de cabeceras, timeouts y reintentos del resto del cliente.
|
|
179
219
|
- **Scopes documentados**: tabla de scopes disponibles y recomendaciones para definir permisos mínimos por workspace.
|
|
180
220
|
- **Mejoras de gobernanza**: se incorporaron pautas de rotación, almacenamiento seguro y segmentación por entorno directamente en la guía del SDK.
|
|
181
221
|
|
package/dist/index.cjs
CHANGED
|
@@ -22,11 +22,13 @@ __export(index_exports, {
|
|
|
22
22
|
HttpError: () => HttpError,
|
|
23
23
|
NetworkError: () => NetworkError,
|
|
24
24
|
TimeoutError: () => TimeoutError,
|
|
25
|
+
bindAgentBlueprints: () => bindAgentBlueprints,
|
|
25
26
|
bindAgentInstructions: () => bindAgentInstructions,
|
|
26
27
|
bindAgentPhones: () => bindAgentPhones,
|
|
27
28
|
bindAgentSchedule: () => bindAgentSchedule,
|
|
28
29
|
bindAgentTags: () => bindAgentTags,
|
|
29
30
|
bindAgentVersions: () => bindAgentVersions,
|
|
31
|
+
createAgentBlueprintsApi: () => createAgentBlueprintsApi,
|
|
30
32
|
createAgentEntity: () => createAgentEntity,
|
|
31
33
|
createAgentInstructionsApi: () => createAgentInstructionsApi,
|
|
32
34
|
createAgentPhonesApi: () => createAgentPhonesApi,
|
|
@@ -34,6 +36,7 @@ __export(index_exports, {
|
|
|
34
36
|
createAgentTagsApi: () => createAgentTagsApi,
|
|
35
37
|
createAgentVersionsApi: () => createAgentVersionsApi,
|
|
36
38
|
createAgentsApi: () => createAgentsApi,
|
|
39
|
+
createApiKeysApi: () => createApiKeysApi,
|
|
37
40
|
createClient: () => createClient,
|
|
38
41
|
createHttp: () => createHttp,
|
|
39
42
|
createToolsApi: () => createToolsApi,
|
|
@@ -42,98 +45,6 @@ __export(index_exports, {
|
|
|
42
45
|
});
|
|
43
46
|
module.exports = __toCommonJS(index_exports);
|
|
44
47
|
|
|
45
|
-
// src/utils/pagination.ts
|
|
46
|
-
var toNumber = (value) => {
|
|
47
|
-
return typeof value === "number" ? value : void 0;
|
|
48
|
-
};
|
|
49
|
-
var toBoolean = (value) => {
|
|
50
|
-
return typeof value === "boolean" ? value : void 0;
|
|
51
|
-
};
|
|
52
|
-
function cloneOptions(options, overrides) {
|
|
53
|
-
return {
|
|
54
|
-
...options ?? {},
|
|
55
|
-
...overrides ?? {}
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
function normalizeMeta(meta) {
|
|
59
|
-
if (!meta) {
|
|
60
|
-
return void 0;
|
|
61
|
-
}
|
|
62
|
-
const metaRecord = meta;
|
|
63
|
-
return {
|
|
64
|
-
...metaRecord,
|
|
65
|
-
page: toNumber(metaRecord.page),
|
|
66
|
-
limit: toNumber(metaRecord.limit) ?? toNumber(metaRecord.pageSize),
|
|
67
|
-
total: toNumber(metaRecord.total) ?? toNumber(metaRecord.totalItems),
|
|
68
|
-
hasNext: toBoolean(metaRecord.hasNext),
|
|
69
|
-
hasPrevious: toBoolean(metaRecord.hasPrevious),
|
|
70
|
-
totalPages: toNumber(metaRecord.totalPages)
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
function resolveHasNext(meta, limit) {
|
|
74
|
-
if (typeof meta?.hasNext === "boolean") {
|
|
75
|
-
return meta.hasNext;
|
|
76
|
-
}
|
|
77
|
-
if (typeof meta?.total === "number" && typeof meta?.page === "number" && typeof limit === "number") {
|
|
78
|
-
return meta.page * limit < meta.total;
|
|
79
|
-
}
|
|
80
|
-
if (typeof meta?.totalPages === "number" && typeof meta?.page === "number") {
|
|
81
|
-
return meta.page < meta.totalPages;
|
|
82
|
-
}
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
function resolveHasPrevious(meta) {
|
|
86
|
-
if (typeof meta?.hasPrevious === "boolean") {
|
|
87
|
-
return meta.hasPrevious;
|
|
88
|
-
}
|
|
89
|
-
if (typeof meta?.page === "number") {
|
|
90
|
-
return meta.page > 1;
|
|
91
|
-
}
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
function attachPaginator(response, fetchPage, options) {
|
|
95
|
-
const baseOptions = options ?? {};
|
|
96
|
-
const meta = normalizeMeta(response.meta);
|
|
97
|
-
const currentPage = typeof meta?.page === "number" ? meta.page : typeof baseOptions.page === "number" ? baseOptions.page : 1;
|
|
98
|
-
const currentLimit = typeof meta?.limit === "number" ? meta.limit : typeof baseOptions.limit === "number" ? baseOptions.limit : void 0;
|
|
99
|
-
const getNextResponse = async (page, overrides) => {
|
|
100
|
-
const nextOptions = cloneOptions(baseOptions, {
|
|
101
|
-
...overrides,
|
|
102
|
-
page
|
|
103
|
-
});
|
|
104
|
-
const nextResponse = await fetchPage(nextOptions);
|
|
105
|
-
return attachPaginator(nextResponse, fetchPage, nextOptions);
|
|
106
|
-
};
|
|
107
|
-
return Object.assign(response, {
|
|
108
|
-
async next() {
|
|
109
|
-
if (!resolveHasNext(meta, currentLimit)) {
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
return getNextResponse(currentPage + 1);
|
|
113
|
-
},
|
|
114
|
-
async prev() {
|
|
115
|
-
if (!resolveHasPrevious(meta)) {
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
return getNextResponse(Math.max(1, currentPage - 1));
|
|
119
|
-
},
|
|
120
|
-
async page(pageNumber) {
|
|
121
|
-
if (typeof pageNumber !== "number" || Number.isNaN(pageNumber)) {
|
|
122
|
-
throw new TypeError("page(pageNumber) requires a numeric value.");
|
|
123
|
-
}
|
|
124
|
-
if (pageNumber < 1) {
|
|
125
|
-
throw new RangeError(
|
|
126
|
-
"Page numbers must be greater than or equal to 1."
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
return getNextResponse(pageNumber);
|
|
130
|
-
},
|
|
131
|
-
async reload() {
|
|
132
|
-
return getNextResponse(currentPage);
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
|
|
137
48
|
// src/errors.ts
|
|
138
49
|
var HttpError = class extends Error {
|
|
139
50
|
constructor(status, statusText, body, url) {
|
|
@@ -237,8 +148,10 @@ function createHttp(cfg) {
|
|
|
237
148
|
const retry = cfg.retry;
|
|
238
149
|
const WORKSPACE_HEADER = "x-workspace-id";
|
|
239
150
|
const API_KEY_HEADER = "x-api-key";
|
|
151
|
+
const AUTHORIZATION_HEADER = "authorization";
|
|
240
152
|
const resolveWorkspaceId = () => cfg.getWorkspaceId?.() ?? cfg.workspaceId ?? void 0;
|
|
241
153
|
const resolveApiKey = () => cfg.getApiKey?.() ?? cfg.apiKey ?? void 0;
|
|
154
|
+
const resolveAccessToken = () => cfg.getAccessToken?.() ?? cfg.accessToken ?? void 0;
|
|
242
155
|
const normalizeHeaders = (headers) => {
|
|
243
156
|
if (!headers) {
|
|
244
157
|
return {};
|
|
@@ -264,10 +177,15 @@ function createHttp(cfg) {
|
|
|
264
177
|
const headersWithWorkspace = workspaceId ? { [WORKSPACE_HEADER]: workspaceId } : {};
|
|
265
178
|
const apiKey = resolveApiKey();
|
|
266
179
|
const headersWithApiKey = apiKey ? { [API_KEY_HEADER]: apiKey } : {};
|
|
180
|
+
const accessToken = resolveAccessToken();
|
|
181
|
+
const headersWithAuthorization = accessToken ? {
|
|
182
|
+
[AUTHORIZATION_HEADER]: accessToken.startsWith("Bearer ") ? accessToken : `Bearer ${accessToken}`
|
|
183
|
+
} : {};
|
|
267
184
|
return {
|
|
268
185
|
...baseHeaders,
|
|
269
186
|
...headersWithWorkspace,
|
|
270
187
|
...headersWithApiKey,
|
|
188
|
+
...headersWithAuthorization,
|
|
271
189
|
...normalizedExtra
|
|
272
190
|
};
|
|
273
191
|
};
|
|
@@ -309,7 +227,8 @@ function createHttp(cfg) {
|
|
|
309
227
|
doFetch,
|
|
310
228
|
buildHeaders,
|
|
311
229
|
resolveWorkspaceId,
|
|
312
|
-
resolveApiKey
|
|
230
|
+
resolveApiKey,
|
|
231
|
+
resolveAccessToken
|
|
313
232
|
};
|
|
314
233
|
}
|
|
315
234
|
|
|
@@ -424,6 +343,149 @@ function getQueryBuilderString(value) {
|
|
|
424
343
|
return String(result);
|
|
425
344
|
}
|
|
426
345
|
|
|
346
|
+
// src/api/agent-blueprints.ts
|
|
347
|
+
function createAgentBlueprintsApi(cfg) {
|
|
348
|
+
const { base, doFetch } = createHttp(cfg);
|
|
349
|
+
const jsonHeaders = { "content-type": "application/json" };
|
|
350
|
+
const list = async (agentId, options = {}) => {
|
|
351
|
+
const query = serializeListOptions({ filter: options.filter });
|
|
352
|
+
const res = await doFetch(`${base}/v1/agents/${agentId}/blueprints`, {
|
|
353
|
+
method: "GET",
|
|
354
|
+
query
|
|
355
|
+
});
|
|
356
|
+
return res.json();
|
|
357
|
+
};
|
|
358
|
+
const get = async (agentId, versionId) => {
|
|
359
|
+
const res = await doFetch(
|
|
360
|
+
`${base}/v1/agents/${agentId}/versions/${versionId}/blueprint`,
|
|
361
|
+
{
|
|
362
|
+
method: "GET"
|
|
363
|
+
}
|
|
364
|
+
);
|
|
365
|
+
return res.json();
|
|
366
|
+
};
|
|
367
|
+
const create = async (agentId, versionId, payload) => {
|
|
368
|
+
const res = await doFetch(
|
|
369
|
+
`${base}/v1/agents/${agentId}/versions/${versionId}/blueprint`,
|
|
370
|
+
{
|
|
371
|
+
method: "POST",
|
|
372
|
+
body: JSON.stringify(payload),
|
|
373
|
+
headers: jsonHeaders
|
|
374
|
+
}
|
|
375
|
+
);
|
|
376
|
+
return res.json();
|
|
377
|
+
};
|
|
378
|
+
const update = async (agentId, versionId, payload) => {
|
|
379
|
+
const res = await doFetch(
|
|
380
|
+
`${base}/v1/agents/${agentId}/versions/${versionId}/blueprint`,
|
|
381
|
+
{
|
|
382
|
+
method: "PATCH",
|
|
383
|
+
body: JSON.stringify(payload),
|
|
384
|
+
headers: jsonHeaders
|
|
385
|
+
}
|
|
386
|
+
);
|
|
387
|
+
return res.json();
|
|
388
|
+
};
|
|
389
|
+
return {
|
|
390
|
+
list,
|
|
391
|
+
get,
|
|
392
|
+
create,
|
|
393
|
+
update
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// src/utils/pagination.ts
|
|
398
|
+
var toNumber = (value) => {
|
|
399
|
+
return typeof value === "number" ? value : void 0;
|
|
400
|
+
};
|
|
401
|
+
var toBoolean = (value) => {
|
|
402
|
+
return typeof value === "boolean" ? value : void 0;
|
|
403
|
+
};
|
|
404
|
+
function cloneOptions(options, overrides) {
|
|
405
|
+
return {
|
|
406
|
+
...options ?? {},
|
|
407
|
+
...overrides ?? {}
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
function normalizeMeta(meta) {
|
|
411
|
+
if (!meta) {
|
|
412
|
+
return void 0;
|
|
413
|
+
}
|
|
414
|
+
const metaRecord = meta;
|
|
415
|
+
return {
|
|
416
|
+
...metaRecord,
|
|
417
|
+
page: toNumber(metaRecord.page),
|
|
418
|
+
limit: toNumber(metaRecord.limit) ?? toNumber(metaRecord.pageSize),
|
|
419
|
+
total: toNumber(metaRecord.total) ?? toNumber(metaRecord.totalItems),
|
|
420
|
+
hasNext: toBoolean(metaRecord.hasNext),
|
|
421
|
+
hasPrevious: toBoolean(metaRecord.hasPrevious),
|
|
422
|
+
totalPages: toNumber(metaRecord.totalPages)
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
function resolveHasNext(meta, limit) {
|
|
426
|
+
if (typeof meta?.hasNext === "boolean") {
|
|
427
|
+
return meta.hasNext;
|
|
428
|
+
}
|
|
429
|
+
if (typeof meta?.total === "number" && typeof meta?.page === "number" && typeof limit === "number") {
|
|
430
|
+
return meta.page * limit < meta.total;
|
|
431
|
+
}
|
|
432
|
+
if (typeof meta?.totalPages === "number" && typeof meta?.page === "number") {
|
|
433
|
+
return meta.page < meta.totalPages;
|
|
434
|
+
}
|
|
435
|
+
return false;
|
|
436
|
+
}
|
|
437
|
+
function resolveHasPrevious(meta) {
|
|
438
|
+
if (typeof meta?.hasPrevious === "boolean") {
|
|
439
|
+
return meta.hasPrevious;
|
|
440
|
+
}
|
|
441
|
+
if (typeof meta?.page === "number") {
|
|
442
|
+
return meta.page > 1;
|
|
443
|
+
}
|
|
444
|
+
return false;
|
|
445
|
+
}
|
|
446
|
+
function attachPaginator(response, fetchPage, options) {
|
|
447
|
+
const baseOptions = options ?? {};
|
|
448
|
+
const meta = normalizeMeta(response.meta);
|
|
449
|
+
const currentPage = typeof meta?.page === "number" ? meta.page : typeof baseOptions.page === "number" ? baseOptions.page : 1;
|
|
450
|
+
const currentLimit = typeof meta?.limit === "number" ? meta.limit : typeof baseOptions.limit === "number" ? baseOptions.limit : void 0;
|
|
451
|
+
const getNextResponse = async (page, overrides) => {
|
|
452
|
+
const nextOptions = cloneOptions(baseOptions, {
|
|
453
|
+
...overrides,
|
|
454
|
+
page
|
|
455
|
+
});
|
|
456
|
+
const nextResponse = await fetchPage(nextOptions);
|
|
457
|
+
return attachPaginator(nextResponse, fetchPage, nextOptions);
|
|
458
|
+
};
|
|
459
|
+
return Object.assign(response, {
|
|
460
|
+
async next() {
|
|
461
|
+
if (!resolveHasNext(meta, currentLimit)) {
|
|
462
|
+
return null;
|
|
463
|
+
}
|
|
464
|
+
return getNextResponse(currentPage + 1);
|
|
465
|
+
},
|
|
466
|
+
async prev() {
|
|
467
|
+
if (!resolveHasPrevious(meta)) {
|
|
468
|
+
return null;
|
|
469
|
+
}
|
|
470
|
+
return getNextResponse(Math.max(1, currentPage - 1));
|
|
471
|
+
},
|
|
472
|
+
async page(pageNumber) {
|
|
473
|
+
if (typeof pageNumber !== "number" || Number.isNaN(pageNumber)) {
|
|
474
|
+
throw new TypeError("page(pageNumber) requires a numeric value.");
|
|
475
|
+
}
|
|
476
|
+
if (pageNumber < 1) {
|
|
477
|
+
throw new RangeError(
|
|
478
|
+
"Page numbers must be greater than or equal to 1."
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
return getNextResponse(pageNumber);
|
|
482
|
+
},
|
|
483
|
+
async reload() {
|
|
484
|
+
return getNextResponse(currentPage);
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
|
|
427
489
|
// src/api/agent-instructions.ts
|
|
428
490
|
function createAgentInstructionsApi(cfg) {
|
|
429
491
|
const { base, doFetch } = createHttp(cfg);
|
|
@@ -714,6 +776,24 @@ var bindAgentVersions = (api, agentId) => ({
|
|
|
714
776
|
};
|
|
715
777
|
}
|
|
716
778
|
});
|
|
779
|
+
var bindAgentBlueprints = (api, agentId) => ({
|
|
780
|
+
list(opts) {
|
|
781
|
+
return api.list(agentId, opts);
|
|
782
|
+
},
|
|
783
|
+
version(versionId) {
|
|
784
|
+
return {
|
|
785
|
+
get() {
|
|
786
|
+
return api.get(agentId, versionId);
|
|
787
|
+
},
|
|
788
|
+
create(payload) {
|
|
789
|
+
return api.create(agentId, versionId, payload);
|
|
790
|
+
},
|
|
791
|
+
update(payload) {
|
|
792
|
+
return api.update(agentId, versionId, payload);
|
|
793
|
+
}
|
|
794
|
+
};
|
|
795
|
+
}
|
|
796
|
+
});
|
|
717
797
|
var createAgentEntity = (dto, options) => {
|
|
718
798
|
const {
|
|
719
799
|
instructionsApi,
|
|
@@ -721,6 +801,7 @@ var createAgentEntity = (dto, options) => {
|
|
|
721
801
|
phonesApi,
|
|
722
802
|
scheduleApi,
|
|
723
803
|
versionsApi,
|
|
804
|
+
blueprintsApi,
|
|
724
805
|
reload,
|
|
725
806
|
updateAgent,
|
|
726
807
|
deleteAgent
|
|
@@ -732,6 +813,7 @@ var createAgentEntity = (dto, options) => {
|
|
|
732
813
|
phones: bindAgentPhones(phonesApi, dto.agentId),
|
|
733
814
|
schedule: bindAgentSchedule(scheduleApi, dto.agentId),
|
|
734
815
|
versions: bindAgentVersions(versionsApi, dto.agentId),
|
|
816
|
+
blueprints: bindAgentBlueprints(blueprintsApi, dto.agentId),
|
|
735
817
|
async save(patch) {
|
|
736
818
|
return updateAgent(dto.agentId, patch);
|
|
737
819
|
},
|
|
@@ -814,6 +896,7 @@ function createAgentsApi(cfg, relatedApis) {
|
|
|
814
896
|
phonesApi: relatedApis.phonesApi,
|
|
815
897
|
scheduleApi: relatedApis.scheduleApi,
|
|
816
898
|
versionsApi: relatedApis.versionsApi,
|
|
899
|
+
blueprintsApi: relatedApis.blueprintsApi,
|
|
817
900
|
reload: async (agentId) => {
|
|
818
901
|
const latest = await getAgentDetail(agentId);
|
|
819
902
|
return wrapAgent(latest);
|
|
@@ -856,6 +939,37 @@ function createAgentsApi(cfg, relatedApis) {
|
|
|
856
939
|
};
|
|
857
940
|
}
|
|
858
941
|
|
|
942
|
+
// src/api/api-keys.ts
|
|
943
|
+
function createApiKeysApi(cfg) {
|
|
944
|
+
const { base, doFetch } = createHttp(cfg);
|
|
945
|
+
const jsonHeaders = { "content-type": "application/json" };
|
|
946
|
+
return {
|
|
947
|
+
async list() {
|
|
948
|
+
const res = await doFetch(`${base}/v1/api-keys`, { method: "GET" });
|
|
949
|
+
return res.json();
|
|
950
|
+
},
|
|
951
|
+
async create(payload) {
|
|
952
|
+
const res = await doFetch(`${base}/v1/api-keys`, {
|
|
953
|
+
method: "POST",
|
|
954
|
+
headers: jsonHeaders,
|
|
955
|
+
body: JSON.stringify(payload)
|
|
956
|
+
});
|
|
957
|
+
return res.json();
|
|
958
|
+
},
|
|
959
|
+
async revoke(apiKeyId) {
|
|
960
|
+
await doFetch(`${base}/v1/api-keys/${apiKeyId}`, {
|
|
961
|
+
method: "DELETE"
|
|
962
|
+
});
|
|
963
|
+
},
|
|
964
|
+
async show(apiKeyId) {
|
|
965
|
+
const res = await doFetch(`${base}/v1/api-keys/${apiKeyId}/show`, {
|
|
966
|
+
method: "GET"
|
|
967
|
+
});
|
|
968
|
+
return res.json();
|
|
969
|
+
}
|
|
970
|
+
};
|
|
971
|
+
}
|
|
972
|
+
|
|
859
973
|
// src/api/tools.ts
|
|
860
974
|
var isFormData = (value) => {
|
|
861
975
|
return typeof FormData !== "undefined" && value instanceof FormData;
|
|
@@ -1048,6 +1162,7 @@ function createClient(initialCfg) {
|
|
|
1048
1162
|
};
|
|
1049
1163
|
const resolveWorkspaceId = () => runtimeCfg.workspaceId ?? runtimeCfg.getWorkspaceId?.();
|
|
1050
1164
|
const resolveApiKey = () => runtimeCfg.apiKey ?? runtimeCfg.getApiKey?.();
|
|
1165
|
+
const resolveAccessToken = () => runtimeCfg.accessToken ?? runtimeCfg.getAccessToken?.();
|
|
1051
1166
|
const setWorkspaceId = (workspaceId) => {
|
|
1052
1167
|
runtimeCfg.workspaceId = workspaceId;
|
|
1053
1168
|
};
|
|
@@ -1060,18 +1175,27 @@ function createClient(initialCfg) {
|
|
|
1060
1175
|
const setApiKeyGetter = (getter) => {
|
|
1061
1176
|
runtimeCfg.getApiKey = getter;
|
|
1062
1177
|
};
|
|
1178
|
+
const setAccessToken = (token) => {
|
|
1179
|
+
runtimeCfg.accessToken = token;
|
|
1180
|
+
};
|
|
1181
|
+
const setAccessTokenGetter = (getter) => {
|
|
1182
|
+
runtimeCfg.getAccessToken = getter;
|
|
1183
|
+
};
|
|
1063
1184
|
const instructionsApi = createAgentInstructionsApi(runtimeCfg);
|
|
1064
1185
|
const tagsApi = createAgentTagsApi(runtimeCfg);
|
|
1065
1186
|
const phonesApi = createAgentPhonesApi(runtimeCfg);
|
|
1066
1187
|
const scheduleApi = createAgentScheduleApi(runtimeCfg);
|
|
1067
1188
|
const versionsApi = createAgentVersionsApi(runtimeCfg);
|
|
1189
|
+
const blueprintsApi = createAgentBlueprintsApi(runtimeCfg);
|
|
1068
1190
|
const voicesApi = createVoicesApi(runtimeCfg);
|
|
1191
|
+
const apiKeysApi = createApiKeysApi(runtimeCfg);
|
|
1069
1192
|
const agentsApi = createAgentsApi(runtimeCfg, {
|
|
1070
1193
|
instructionsApi,
|
|
1071
1194
|
tagsApi,
|
|
1072
1195
|
phonesApi,
|
|
1073
1196
|
scheduleApi,
|
|
1074
|
-
versionsApi
|
|
1197
|
+
versionsApi,
|
|
1198
|
+
blueprintsApi
|
|
1075
1199
|
});
|
|
1076
1200
|
const instructionsNamespace = Object.assign(
|
|
1077
1201
|
(agentId) => bindAgentInstructions(instructionsApi, agentId),
|
|
@@ -1093,6 +1217,10 @@ function createClient(initialCfg) {
|
|
|
1093
1217
|
(agentId) => bindAgentVersions(versionsApi, agentId),
|
|
1094
1218
|
versionsApi
|
|
1095
1219
|
);
|
|
1220
|
+
const blueprintsNamespace = Object.assign(
|
|
1221
|
+
(agentId) => bindAgentBlueprints(blueprintsApi, agentId),
|
|
1222
|
+
blueprintsApi
|
|
1223
|
+
);
|
|
1096
1224
|
const apis = {
|
|
1097
1225
|
agents: {
|
|
1098
1226
|
...agentsApi,
|
|
@@ -1100,11 +1228,13 @@ function createClient(initialCfg) {
|
|
|
1100
1228
|
tags: tagsNamespace,
|
|
1101
1229
|
phones: phonesNamespace,
|
|
1102
1230
|
schedule: scheduleNamespace,
|
|
1103
|
-
versions: versionsNamespace
|
|
1231
|
+
versions: versionsNamespace,
|
|
1232
|
+
blueprints: blueprintsNamespace
|
|
1104
1233
|
},
|
|
1105
1234
|
workspaces: createWorkspacesApi(runtimeCfg),
|
|
1106
1235
|
tools: createToolsApi(runtimeCfg),
|
|
1107
|
-
voices: voicesApi
|
|
1236
|
+
voices: voicesApi,
|
|
1237
|
+
apiKeys: apiKeysApi
|
|
1108
1238
|
};
|
|
1109
1239
|
return {
|
|
1110
1240
|
...apis,
|
|
@@ -1120,6 +1250,18 @@ function createClient(initialCfg) {
|
|
|
1120
1250
|
clearApiKey() {
|
|
1121
1251
|
setApiKeyGetter(void 0);
|
|
1122
1252
|
setApiKey(void 0);
|
|
1253
|
+
},
|
|
1254
|
+
getAccessToken: resolveAccessToken,
|
|
1255
|
+
setAccessToken(token) {
|
|
1256
|
+
setAccessTokenGetter(void 0);
|
|
1257
|
+
setAccessToken(token);
|
|
1258
|
+
},
|
|
1259
|
+
useAccessToken(getter) {
|
|
1260
|
+
setAccessTokenGetter(getter);
|
|
1261
|
+
},
|
|
1262
|
+
clearAccessToken() {
|
|
1263
|
+
setAccessTokenGetter(void 0);
|
|
1264
|
+
setAccessToken(void 0);
|
|
1123
1265
|
}
|
|
1124
1266
|
},
|
|
1125
1267
|
workspace: {
|
|
@@ -1141,7 +1283,9 @@ function createClient(initialCfg) {
|
|
|
1141
1283
|
workspaceId: id,
|
|
1142
1284
|
getWorkspaceId: void 0,
|
|
1143
1285
|
apiKey: runtimeCfg.apiKey,
|
|
1144
|
-
getApiKey: runtimeCfg.getApiKey
|
|
1286
|
+
getApiKey: runtimeCfg.getApiKey,
|
|
1287
|
+
accessToken: runtimeCfg.accessToken,
|
|
1288
|
+
getAccessToken: runtimeCfg.getAccessToken
|
|
1145
1289
|
});
|
|
1146
1290
|
}
|
|
1147
1291
|
}
|
|
@@ -1152,11 +1296,13 @@ function createClient(initialCfg) {
|
|
|
1152
1296
|
HttpError,
|
|
1153
1297
|
NetworkError,
|
|
1154
1298
|
TimeoutError,
|
|
1299
|
+
bindAgentBlueprints,
|
|
1155
1300
|
bindAgentInstructions,
|
|
1156
1301
|
bindAgentPhones,
|
|
1157
1302
|
bindAgentSchedule,
|
|
1158
1303
|
bindAgentTags,
|
|
1159
1304
|
bindAgentVersions,
|
|
1305
|
+
createAgentBlueprintsApi,
|
|
1160
1306
|
createAgentEntity,
|
|
1161
1307
|
createAgentInstructionsApi,
|
|
1162
1308
|
createAgentPhonesApi,
|
|
@@ -1164,6 +1310,7 @@ function createClient(initialCfg) {
|
|
|
1164
1310
|
createAgentTagsApi,
|
|
1165
1311
|
createAgentVersionsApi,
|
|
1166
1312
|
createAgentsApi,
|
|
1313
|
+
createApiKeysApi,
|
|
1167
1314
|
createClient,
|
|
1168
1315
|
createHttp,
|
|
1169
1316
|
createToolsApi,
|