agentfootprint
Version:
The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.
40 lines • 1.78 kB
JavaScript
;
/**
* thinkingHandlerFor — the thinking handler a provider DECLARES.
*
* Pattern: capability declaration (the `promptCaching` / `cacheStrategyFor`
* twin). The adapter knows the shape its wire's thinking arrives in
* and declares the handler that normalizes it
* (`LLMProvider.thinkingHandler`); a wrapper forwards the field like
* `carriesInMessages`. Never chosen by `provider.name`.
* Role: the ONE place `Agent` and `LLMCall` resolve their handler when the
* builder did not set one.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.thinkingHandlerFor = void 0;
/**
* The thinking handler `provider` declares, or `undefined` when it declares
* none (the agent then mounts no thinking stage).
*
* @throws TypeError when the declaration is not a handler (no string `id`, no
* `normalize` function) — refused at agent build, by provider name, rather
* than failing on the first response that carries thinking.
*
* @example
* ```ts
* thinkingHandlerFor(withRetry(anthropic()))?.id; // 'anthropic' — the wrapper forwards it
* ```
*/
function thinkingHandlerFor(provider) {
const declared = provider.thinkingHandler;
if (declared === undefined)
return undefined;
if (typeof declared.id !== 'string' || typeof declared.normalize !== 'function') {
throw new TypeError(`the '${provider.name}' provider declares a thinkingHandler that is not one ` +
'(a ThinkingHandler needs a string `id` and a `normalize(raw)` function). ' +
'Leave thinkingHandler out if the provider emits no thinking.');
}
return declared;
}
exports.thinkingHandlerFor = thinkingHandlerFor;
//# sourceMappingURL=thinkingHandlerFor.js.map