@getsupervisor/agents-studio-sdk 1.7.0 → 1.9.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 CHANGED
@@ -1,3 +1,48 @@
1
+ ## v1.8.0
2
+
3
+ ## [1.8.0](https://github.com/julio-supervisor/agents-studio-be/compare/v1.7.0...v1.8.0) (2025-10-15)
4
+
5
+ ### Features
6
+
7
+ * add complete CRUD example for agents in the SDK ([4e07584](https://github.com/julio-supervisor/agents-studio-be/commit/4e07584aac8537c5050cdaac20722c5d23d4e841))
8
+ * agent module ([6ba4512](https://github.com/julio-supervisor/agents-studio-be/commit/6ba4512a07d2deda71d24a448bef5523e8e06542))
9
+ * agregar argumento de construcción NODE_AUTH_TOKEN en el flujo de trabajo de despliegue ([f2d4923](https://github.com/julio-supervisor/agents-studio-be/commit/f2d4923a3e332fc3c660033f63d24bd0907beb85))
10
+ * agregar configuración de Node.js en flujos de trabajo de despliegue ([dd7a194](https://github.com/julio-supervisor/agents-studio-be/commit/dd7a194d168a1ceb71731cf572f069eb838d1ae1))
11
+ * agregar depuración de autenticación npm y visibilidad de paquetes en los flujos de trabajo de despliegue ([9e25cd9](https://github.com/julio-supervisor/agents-studio-be/commit/9e25cd989123f8b9640a8e51973f9ee6a8abd5df))
12
+ * agregar guía de despliegue con GitHub Actions para el backend de Agents Studio ([0196448](https://github.com/julio-supervisor/agents-studio-be/commit/01964486b7c038ee46bd014379842d8e5c28c754))
13
+ * agregar soporte para NODE_AUTH_TOKEN en el Dockerfile para la instalación de dependencias ([d47a299](https://github.com/julio-supervisor/agents-studio-be/commit/d47a2996d9f89d3860cc7d7c54f61fe71a0e6e9d))
14
+ * **ci:** agregar pasos de depuración para la autenticación de npm y visibilidad de paquetes ([17c8aed](https://github.com/julio-supervisor/agents-studio-be/commit/17c8aed6d071a6b0c034bd88588b930fdd26ab05))
15
+
16
+ ### Bug Fixes
17
+
18
+ * **tsconfig:** corregir la ruta del dominio de agentes en la configuración de TypeScript ([d3480c8](https://github.com/julio-supervisor/agents-studio-be/commit/d3480c815c220491061d8e44debcab4ffdd40f96))
19
+
20
+
21
+ ## v1.7.0
22
+
23
+ ## [1.7.0](https://github.com/julio-supervisor/agents-studio-be/compare/v1.6.0...v1.7.0) (2025-10-13)
24
+
25
+ ### Features
26
+
27
+ * **migrations:** agregar migraciones para renombrar tablas y actualizar esquemas de agentes ([04353a2](https://github.com/julio-supervisor/agents-studio-be/commit/04353a27ec0a8f3a14ebf1c86a80dc37e2b6ad81))
28
+
29
+ ## v1.6.0
30
+
31
+ ## [1.6.0](https://github.com/julio-supervisor/agents-studio-be/compare/v1.5.0...v1.6.0) (2025-10-13)
32
+
33
+ ### Features
34
+
35
+ * **api:** add endpoints for managing agents, agent versions, instructions, and tools ([60a5b8f](https://github.com/julio-supervisor/agents-studio-be/commit/60a5b8f18bbd315b5caeb2191240c28a1540bb62))
36
+
37
+ ## v1.5.0
38
+
39
+ ## [1.5.0](https://github.com/julio-supervisor/agents-studio-be/compare/v1.4.0...v1.5.0) (2025-10-13)
40
+
41
+ ### Features
42
+
43
+ * add agent tags management API for associating and removing tags from agents ([88e5b87](https://github.com/julio-supervisor/agents-studio-be/commit/88e5b87c256d3671ad27d503c954bc41c6175811))
44
+
45
+
1
46
  ## v1.4.0
2
47
 
3
48
  ## [1.4.0](https://github.com/julio-supervisor/agents-studio-be/compare/v1.3.0...v1.4.0) (2025-10-12)
package/README.md CHANGED
@@ -22,6 +22,10 @@ const client = createClient({
22
22
  const { data: agents } = await client.agents.list({ limit: 10 });
23
23
  const agent = await client.agents.get('agent-123');
24
24
 
25
+ // helpers de agente sin repetir IDs
26
+ const instructions = client.agents.instructions(agent.agentId);
27
+ await instructions.create({ order: 1, content: 'Responde en español neutro' });
28
+
25
29
  // administrar versiones e instrucciones
26
30
  await client.agents
27
31
  .versions(agent.agentId)
@@ -36,12 +40,32 @@ await client.tools.uploadResource(tools.data[0].identifier, formData);
36
40
  await client.agents.delete(agent.agentId);
37
41
  ```
38
42
 
43
+ ### Ejemplo de CRUD completo
44
+
45
+ Consulta el archivo `examples/agents-crud.ts` para ver un flujo end-to-end que:
46
+
47
+ - crea un agente temporal,
48
+ - lista agentes con paginación,
49
+ - actualiza los campos con `save` y `update`, y
50
+ - elimina el recurso al finalizar.
51
+
52
+ Ejecuta el ejemplo definiendo `API_BASE_URL`, `WORKSPACE_ID` y `API_TOKEN`:
53
+
54
+ ```bash
55
+ API_BASE_URL=https://public-api.getsupervisor.ai \
56
+ WORKSPACE_ID=ws-123 \
57
+ API_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9... \
58
+ npx tsx examples/agents-crud.ts
59
+ ```
60
+
39
61
  ## Configuración
40
62
 
41
63
  ```ts
42
64
  createClient({
43
65
  baseUrl: '...',
44
66
  headers: { Authorization: 'Bearer ...' },
67
+ // opcional: usa API Keys en lugar de Bearer
68
+ // apiKey: 'sk_live_...',
45
69
  timeoutMs: 35000,
46
70
  retry: { maxRetries: 2, baseDelayMs: 300 },
47
71
  workspaceId: 'ws-123',
@@ -74,13 +98,86 @@ const scoped = client.workspace.scoped('ws-789');
74
98
  await scoped.agents.get('agentId');
75
99
  ```
76
100
 
77
- ## Novedades (septiembre 2024)
101
+ ## Gestión de API Keys
102
+
103
+ Los endpoints `/v1/api-keys` permiten listar, crear y revocar credenciales por workspace. Mientras publicamos helpers específicos en el cliente, puedes usar la utilidad `createHttp` para firmar peticiones con el mismo manejo de cabeceras, timeouts y reintentos del SDK.
104
+
105
+ > 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
+
107
+ ```ts
108
+ import { createHttp } from '@getsupervisor/agents-studio-sdk';
109
+
110
+ const http = createHttp({
111
+ baseUrl: 'https://public-api.getsupervisor.ai',
112
+ headers: { Authorization: `Bearer ${token}` },
113
+ workspaceId: 'ws-123',
114
+ });
115
+ ```
116
+
117
+ ### Listar API Keys activas
118
+
119
+ ```ts
120
+ const res = await http.doFetch(`${http.base}/v1/api-keys`, { method: 'GET' });
121
+ const apiKeys = await res.json();
122
+
123
+ // apiKeys: ApiKeySummary[]
124
+ ```
125
+
126
+ Cada entrada incluye `id`, `name`, `environment`, `scopes`, fechas de auditoría y un `keyPreview` para validar qué credencial usas en producción o sandbox.
127
+
128
+ ### Crear una API Key con scopes personalizados
129
+
130
+ ```ts
131
+ const res = await http.doFetch(`${http.base}/v1/api-keys`, {
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
+ });
141
+
142
+ const { key, ...metadata } = await res.json();
143
+ // Guarda "key" inmediatamente; no vuelve a enviarse en respuestas posteriores.
144
+ ```
145
+
146
+ - Si omites `environment`, se usa la configuración por defecto (`production` salvo que sobrescribas `API_KEYS_ENVIRONMENT`).
147
+ - Si omites `scopes`, el servicio aplica los scopes configurados como `API_KEYS_DEFAULT_SCOPES` (p. ej. `api-keys:read`).
148
+ - Combina scopes mínimos necesarios para limitar el alcance siguiendo el principio de menor privilegio.
149
+
150
+ ### Revocar una API Key
151
+
152
+ ```ts
153
+ await http.doFetch(`${http.base}/v1/api-keys/${apiKeyId}`, { method: 'DELETE' });
154
+ ```
155
+
156
+ La revocación invalida la credencial de forma inmediata. Cualquier uso posterior regresará `401 Unauthorized`.
157
+
158
+ ### Buenas prácticas
159
+
160
+ - Segmenta las API Keys por entorno (`production`, `sandbox`, `staging`, `development`) y flujo de negocio.
161
+ - Registra un owner o nota descriptiva en `name` para acelerar auditorías.
162
+ - Almacena el valor completo (`key`) en un gestor de secretos y evita incluirlo en logs o repositorios.
163
+ - Programa rotaciones periódicas y revoca claves cuando detectes inactividad o incidentes.
164
+
165
+ ### Scopes disponibles (octubre 2025)
166
+
167
+ | Scope | Permiso |
168
+ |-------|---------|
169
+ | `agents:read` | Lectura de catálogos de agentes, versiones e instrucciones. |
170
+ | `workspaces:read` | Lectura de metadatos y recursos de workspace. |
171
+ | `api-keys:read` | Listar y consultar API Keys activas. |
172
+ | `api-keys:write` | Crear o revocar API Keys. |
173
+
174
+ Consulta el OpenAPI (`docs/api-spec/openapi.yaml`) para revisar nuevos scopes conforme se publiquen más operaciones protegidas.
175
+
176
+ ## Novedades (octubre 2025)
78
177
 
79
- - **Sincronización completa con el OpenAPI más reciente**: se regeneraron los tipos `openapi-types.ts` y se actualizó la superficie pública para reflejar nuevos contratos.
80
- - **Instrucciones por versión**: ahora puedes gestionar instrucciones directamente sobre versiones (`client.agents.versions(...).instructions(...)`) incluyendo operaciones de listar, crear, actualizar y eliminar.
81
- - **Catálogo y recursos de tools**: soporte para listar tools filtrando por `agentType`, subir/eliminar/recargar recursos y establecer conexiones (`connect`) de manera tipada.
82
- - **Deprecación de knowledge en agentes**: las rutas de knowledge fueron removidas del API. El helper anterior arroja un error explícito y los tipos asociados ya no se exportan.
83
- - **Pruebas actualizadas**: la suite de Vitest se ajustó para cubrir helpers de versiones e instrucciones; `npm test` reporta 11 pruebas exitosas.
178
+ - **Gestión de API Keys desde el SDK**: ejemplos oficiales para listar, emitir y revocar claves con `createHttp`, alineados con los endpoints `/v1/api-keys`.
179
+ - **Scopes documentados**: tabla de scopes disponibles y recomendaciones para definir permisos mínimos por workspace.
180
+ - **Mejoras de gobernanza**: se incorporaron pautas de rotación, almacenamiento seguro y segmentación por entorno directamente en la guía del SDK.
84
181
 
85
182
  ## Errores tipados y reintentos
86
183
 
package/dist/index.cjs CHANGED
@@ -236,7 +236,9 @@ function createHttp(cfg) {
236
236
  const log = cfg.logger ?? {};
237
237
  const retry = cfg.retry;
238
238
  const WORKSPACE_HEADER = "x-workspace-id";
239
+ const API_KEY_HEADER = "x-api-key";
239
240
  const resolveWorkspaceId = () => cfg.getWorkspaceId?.() ?? cfg.workspaceId ?? void 0;
241
+ const resolveApiKey = () => cfg.getApiKey?.() ?? cfg.apiKey ?? void 0;
240
242
  const normalizeHeaders = (headers) => {
241
243
  if (!headers) {
242
244
  return {};
@@ -260,9 +262,12 @@ function createHttp(cfg) {
260
262
  const workspaceId = resolveWorkspaceId();
261
263
  const normalizedExtra = normalizeHeaders(extra);
262
264
  const headersWithWorkspace = workspaceId ? { [WORKSPACE_HEADER]: workspaceId } : {};
265
+ const apiKey = resolveApiKey();
266
+ const headersWithApiKey = apiKey ? { [API_KEY_HEADER]: apiKey } : {};
263
267
  return {
264
268
  ...baseHeaders,
265
269
  ...headersWithWorkspace,
270
+ ...headersWithApiKey,
266
271
  ...normalizedExtra
267
272
  };
268
273
  };
@@ -303,7 +308,8 @@ function createHttp(cfg) {
303
308
  retry,
304
309
  doFetch,
305
310
  buildHeaders,
306
- resolveWorkspaceId
311
+ resolveWorkspaceId,
312
+ resolveApiKey
307
313
  };
308
314
  }
309
315
 
@@ -744,7 +750,12 @@ function createAgentsApi(cfg, relatedApis) {
744
750
  const { base, doFetch } = createHttp(cfg);
745
751
  const jsonHeaders = { "content-type": "application/json" };
746
752
  const fetchAgentsPage = async (options = {}) => {
747
- const query = serializeListOptions(options);
753
+ const sanitizedOptions = {
754
+ page: options.page,
755
+ limit: options.limit,
756
+ filter: options.filter
757
+ };
758
+ const query = serializeListOptions(sanitizedOptions);
748
759
  const res = await doFetch(`${base}/v1/agents`, {
749
760
  method: "GET",
750
761
  query
@@ -1036,12 +1047,19 @@ function createClient(initialCfg) {
1036
1047
  ...initialCfg
1037
1048
  };
1038
1049
  const resolveWorkspaceId = () => runtimeCfg.workspaceId ?? runtimeCfg.getWorkspaceId?.();
1050
+ const resolveApiKey = () => runtimeCfg.apiKey ?? runtimeCfg.getApiKey?.();
1039
1051
  const setWorkspaceId = (workspaceId) => {
1040
1052
  runtimeCfg.workspaceId = workspaceId;
1041
1053
  };
1042
1054
  const setWorkspaceGetter = (getter) => {
1043
1055
  runtimeCfg.getWorkspaceId = getter;
1044
1056
  };
1057
+ const setApiKey = (apiKey) => {
1058
+ runtimeCfg.apiKey = apiKey;
1059
+ };
1060
+ const setApiKeyGetter = (getter) => {
1061
+ runtimeCfg.getApiKey = getter;
1062
+ };
1045
1063
  const instructionsApi = createAgentInstructionsApi(runtimeCfg);
1046
1064
  const tagsApi = createAgentTagsApi(runtimeCfg);
1047
1065
  const phonesApi = createAgentPhonesApi(runtimeCfg);
@@ -1055,14 +1073,34 @@ function createClient(initialCfg) {
1055
1073
  scheduleApi,
1056
1074
  versionsApi
1057
1075
  });
1076
+ const instructionsNamespace = Object.assign(
1077
+ (agentId) => bindAgentInstructions(instructionsApi, agentId),
1078
+ instructionsApi
1079
+ );
1080
+ const tagsNamespace = Object.assign(
1081
+ (agentId) => bindAgentTags(tagsApi, agentId),
1082
+ tagsApi
1083
+ );
1084
+ const phonesNamespace = Object.assign(
1085
+ (agentId) => bindAgentPhones(phonesApi, agentId),
1086
+ phonesApi
1087
+ );
1088
+ const scheduleNamespace = Object.assign(
1089
+ (agentId) => bindAgentSchedule(scheduleApi, agentId),
1090
+ scheduleApi
1091
+ );
1092
+ const versionsNamespace = Object.assign(
1093
+ (agentId) => bindAgentVersions(versionsApi, agentId),
1094
+ versionsApi
1095
+ );
1058
1096
  const apis = {
1059
1097
  agents: {
1060
1098
  ...agentsApi,
1061
- instructions: instructionsApi,
1062
- tags: tagsApi,
1063
- phones: phonesApi,
1064
- schedule: scheduleApi,
1065
- versions: versionsApi
1099
+ instructions: instructionsNamespace,
1100
+ tags: tagsNamespace,
1101
+ phones: phonesNamespace,
1102
+ schedule: scheduleNamespace,
1103
+ versions: versionsNamespace
1066
1104
  },
1067
1105
  workspaces: createWorkspacesApi(runtimeCfg),
1068
1106
  tools: createToolsApi(runtimeCfg),
@@ -1070,6 +1108,20 @@ function createClient(initialCfg) {
1070
1108
  };
1071
1109
  return {
1072
1110
  ...apis,
1111
+ auth: {
1112
+ getApiKey: resolveApiKey,
1113
+ setApiKey(key) {
1114
+ setApiKeyGetter(void 0);
1115
+ setApiKey(key);
1116
+ },
1117
+ useApiKey(getter) {
1118
+ setApiKeyGetter(getter);
1119
+ },
1120
+ clearApiKey() {
1121
+ setApiKeyGetter(void 0);
1122
+ setApiKey(void 0);
1123
+ }
1124
+ },
1073
1125
  workspace: {
1074
1126
  get: resolveWorkspaceId,
1075
1127
  set(id) {
@@ -1087,7 +1139,9 @@ function createClient(initialCfg) {
1087
1139
  return createClient({
1088
1140
  ...initialCfg,
1089
1141
  workspaceId: id,
1090
- getWorkspaceId: void 0
1142
+ getWorkspaceId: void 0,
1143
+ apiKey: runtimeCfg.apiKey,
1144
+ getApiKey: runtimeCfg.getApiKey
1091
1145
  });
1092
1146
  }
1093
1147
  }