utopia-ia/elffuss-claw public
Changesets · Branches · Tags · Compare
| Changeset | badd8fcabf9c8091fe6213396e2e69221d71ead817fdd23b716ae054e9647d9c |
|---|---|
| Author | KikoCis <kikocisneros@gmail.com> · 2026-10-10 16:32 +02:00 |
| Committer | KikoCis <kikocisneros@gmail.com> · 2026-10-11 17:46 +02:00 |
| Parents | a677a77c12ff |
1 file changed
modified web/js/agent.js +17 −9
| @@ -354,16 +354,20 @@ | ||
| 354 | 354 | // CEO…—: abortarlo para este agente igual que stop(). Si ya llega abortado, |
| 355 | 355 | // ni se apunta el mensaje en el histórico ni se llama al modelo (igual que en |
| 356 | 356 | // Elffuss Code). |
| 357 | - async handle(userText, onEvent, { signal: deFuera = null } = {}) { | |
| 357 | + // | |
| 358 | + // `permitir` (opcional): (nombre de herramienta) => bool. Lo que no pasa no se | |
| 359 | + // ejecuta: el modelo recibe un ERROR que se lo explica. Lo usa el cerebro | |
| 360 | + // autónomo, que solo puede leer (ver ceo.js `allowTool`). | |
| 361 | + async handle(userText, onEvent, { signal: deFuera = null, permitir = null } = {}) { | |
| 358 | 362 | const aborter = (this._aborter = new AbortController()); |
| 359 | 363 | if (deFuera?.aborted) { onEvent({ type: 'aborted', text: t('stopped') }); return; } |
| 360 | 364 | const alAbortar = () => aborter.abort(); |
| 361 | 365 | deFuera?.addEventListener?.('abort', alAbortar, { once: true }); |
| 362 | - try { return await this._turno(userText, onEvent, aborter.signal); } | |
| 366 | + try { return await this._turno(userText, onEvent, aborter.signal, permitir); } | |
| 363 | 367 | finally { deFuera?.removeEventListener?.('abort', alAbortar); } |
| 364 | 368 | } |
| 365 | 369 | |
| 366 | - async _turno(userText, onEvent, signal) { | |
| 370 | + async _turno(userText, onEvent, signal, permitir = null) { | |
| 367 | 371 | const parado = () => onEvent({ type: 'aborted', text: t('stopped') }); |
| 368 | 372 | // La marca temporal se pone AL AÑADIR, que es el único momento en que se |
| 369 | 373 | // sabe: el gestor de contexto resuelve «ayer» con la fecha del turno en que |
| @@ -440,12 +444,16 @@ | ||
| 440 | 444 | |
| 441 | 445 | onEvent({ type: 'tool', call }); |
| 442 | 446 | let result; |
| 443 | - try { result = await hastaQueParen(runTool(call.tool, call.args), signal); } | |
| 444 | - catch (e) { | |
| 445 | - // Parado con la herramienta en marcha: el turno acaba aquí y no apunta | |
| 446 | - // nada de este paso (la herramienta puede acabar por detrás). | |
| 447 | - if (signal.aborted) return parado(); | |
| 448 | - result = 'ERROR: ' + e.message; | |
| 447 | + if (permitir && !permitir(call.tool)) { | |
| 448 | + result = `ERROR: aquí solo puedes leer; «${call.tool}» cambiaría cosas y no está permitida. Propón ese cambio en texto.`; | |
| 449 | + } else { | |
| 450 | + try { result = await hastaQueParen(runTool(call.tool, call.args), signal); } | |
| 451 | + catch (e) { | |
| 452 | + // Parado con la herramienta en marcha: el turno acaba aquí y no apunta | |
| 453 | + // nada de este paso (la herramienta puede acabar por detrás). | |
| 454 | + if (signal.aborted) return parado(); | |
| 455 | + result = 'ERROR: ' + e.message; | |
| 456 | + } | |
| 449 | 457 | } |
| 450 | 458 | const resultStr = typeof result === 'string' ? result : JSON.stringify(result); |
| 451 | 459 | lastResult = resultStr; |