* Update an agent context
(id: string, input: UpdateAgentContextInput)
| 329 | * Update an agent context |
| 330 | */ |
| 331 | async update(id: string, input: UpdateAgentContextInput): Promise<AgentContext | null> { |
| 332 | const updates: string[] = []; |
| 333 | const values: any[] = []; |
| 334 | let paramIndex = 1; |
| 335 | |
| 336 | if (input.agent_name !== undefined) { |
| 337 | updates.push(`agent_name = $${paramIndex++}`); |
| 338 | values.push(input.agent_name); |
| 339 | } |
| 340 | if (input.agent_type !== undefined) { |
| 341 | updates.push(`agent_type = $${paramIndex++}`); |
| 342 | values.push(input.agent_type); |
| 343 | } |
| 344 | if (input.protocol !== undefined) { |
| 345 | updates.push(`protocol = $${paramIndex++}`); |
| 346 | values.push(input.protocol); |
| 347 | } |
| 348 | if (input.tools_discovered !== undefined) { |
| 349 | updates.push(`tools_discovered = $${paramIndex++}`); |
| 350 | updates.push(`last_discovered_at = NOW()`); |
| 351 | values.push(input.tools_discovered); |
| 352 | } |
| 353 | if (input.last_test_scenario !== undefined) { |
| 354 | updates.push(`last_test_scenario = $${paramIndex++}`); |
| 355 | values.push(input.last_test_scenario); |
| 356 | } |
| 357 | if (input.last_test_passed !== undefined) { |
| 358 | updates.push(`last_test_passed = $${paramIndex++}`); |
| 359 | values.push(input.last_test_passed); |
| 360 | } |
| 361 | if (input.last_test_summary !== undefined) { |
| 362 | updates.push(`last_test_summary = $${paramIndex++}`); |
| 363 | values.push(input.last_test_summary); |
| 364 | } |
| 365 | |
| 366 | if (updates.length === 0) { |
| 367 | return this.getById(id); |
| 368 | } |
| 369 | |
| 370 | updates.push('updated_at = NOW()'); |
| 371 | values.push(id); |
| 372 | |
| 373 | const result = await query( |
| 374 | `UPDATE agent_contexts |
| 375 | SET ${updates.join(', ')} |
| 376 | WHERE id = $${paramIndex} |
| 377 | RETURNING |
| 378 | id, |
| 379 | organization_id, |
| 380 | agent_url, |
| 381 | agent_name, |
| 382 | agent_type, |
| 383 | protocol, |
| 384 | auth_token_encrypted IS NOT NULL as has_auth_token, |
| 385 | auth_token_hint, |
| 386 | auth_type, |
| 387 | oauth_access_token_encrypted IS NOT NULL as has_oauth_token, |
| 388 | oauth_refresh_token_encrypted IS NOT NULL as has_oauth_refresh_token, |