@getsupervisor/agents-studio-sdk 1.8.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,23 @@
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
+
1
21
  ## v1.7.0
2
22
 
3
23
  ## [1.7.0](https://github.com/julio-supervisor/agents-studio-be/compare/v1.6.0...v1.7.0) (2025-10-13)
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)
@@ -60,6 +64,8 @@ npx tsx examples/agents-crud.ts
60
64
  createClient({
61
65
  baseUrl: '...',
62
66
  headers: { Authorization: 'Bearer ...' },
67
+ // opcional: usa API Keys en lugar de Bearer
68
+ // apiKey: 'sk_live_...',
63
69
  timeoutMs: 35000,
64
70
  retry: { maxRetries: 2, baseDelayMs: 300 },
65
71
  workspaceId: 'ws-123',
@@ -92,13 +98,86 @@ const scoped = client.workspace.scoped('ws-789');
92
98
  await scoped.agents.get('agentId');
93
99
  ```
94
100
 
95
- ## 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)
96
177
 
97
- - **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.
98
- - **Instrucciones por versión**: ahora puedes gestionar instrucciones directamente sobre versiones (`client.agents.versions(...).instructions(...)`) incluyendo operaciones de listar, crear, actualizar y eliminar.
99
- - **Catálogo y recursos de tools**: soporte para listar tools filtrando por `agentType`, subir/eliminar/recargar recursos y establecer conexiones (`connect`) de manera tipada.
100
- - **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.
101
- - **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.
102
181
 
103
182
  ## Errores tipados y reintentos
104
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
 
@@ -1041,12 +1047,19 @@ function createClient(initialCfg) {
1041
1047
  ...initialCfg
1042
1048
  };
1043
1049
  const resolveWorkspaceId = () => runtimeCfg.workspaceId ?? runtimeCfg.getWorkspaceId?.();
1050
+ const resolveApiKey = () => runtimeCfg.apiKey ?? runtimeCfg.getApiKey?.();
1044
1051
  const setWorkspaceId = (workspaceId) => {
1045
1052
  runtimeCfg.workspaceId = workspaceId;
1046
1053
  };
1047
1054
  const setWorkspaceGetter = (getter) => {
1048
1055
  runtimeCfg.getWorkspaceId = getter;
1049
1056
  };
1057
+ const setApiKey = (apiKey) => {
1058
+ runtimeCfg.apiKey = apiKey;
1059
+ };
1060
+ const setApiKeyGetter = (getter) => {
1061
+ runtimeCfg.getApiKey = getter;
1062
+ };
1050
1063
  const instructionsApi = createAgentInstructionsApi(runtimeCfg);
1051
1064
  const tagsApi = createAgentTagsApi(runtimeCfg);
1052
1065
  const phonesApi = createAgentPhonesApi(runtimeCfg);
@@ -1060,14 +1073,34 @@ function createClient(initialCfg) {
1060
1073
  scheduleApi,
1061
1074
  versionsApi
1062
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
+ );
1063
1096
  const apis = {
1064
1097
  agents: {
1065
1098
  ...agentsApi,
1066
- instructions: instructionsApi,
1067
- tags: tagsApi,
1068
- phones: phonesApi,
1069
- schedule: scheduleApi,
1070
- versions: versionsApi
1099
+ instructions: instructionsNamespace,
1100
+ tags: tagsNamespace,
1101
+ phones: phonesNamespace,
1102
+ schedule: scheduleNamespace,
1103
+ versions: versionsNamespace
1071
1104
  },
1072
1105
  workspaces: createWorkspacesApi(runtimeCfg),
1073
1106
  tools: createToolsApi(runtimeCfg),
@@ -1075,6 +1108,20 @@ function createClient(initialCfg) {
1075
1108
  };
1076
1109
  return {
1077
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
+ },
1078
1125
  workspace: {
1079
1126
  get: resolveWorkspaceId,
1080
1127
  set(id) {
@@ -1092,7 +1139,9 @@ function createClient(initialCfg) {
1092
1139
  return createClient({
1093
1140
  ...initialCfg,
1094
1141
  workspaceId: id,
1095
- getWorkspaceId: void 0
1142
+ getWorkspaceId: void 0,
1143
+ apiKey: runtimeCfg.apiKey,
1144
+ getApiKey: runtimeCfg.getApiKey
1096
1145
  });
1097
1146
  }
1098
1147
  }