agentfootprint
Version:
The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.
44 lines • 1.96 kB
JavaScript
;
/**
* staticTokens — a dev/test {@link CredentialProvider} backed by canned credentials.
*
* No network, no SDK. Use it to develop tools that need credentials without
* standing up AgentCore Identity (or any IdP). Production swaps it for
* `agentCoreIdentity()` — the tool code never changes.
*
* // a plain string is treated as a bearer token (the common case):
* const credentials = staticTokens({ github: 'ghp_dev_xxx' });
* // …or give an explicit kind:
* const credentials = staticTokens({ internal: apiKey('k', 'x-internal-key') });
*
* const r = await credentials.getCredential({ service: 'github' });
* if (isCredentialIssued(r)) callGithub({ headers: r.credential.toHeaders() });
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.staticTokens = void 0;
const kinds_js_1 = require("./kinds.js");
/**
* Build a {@link CredentialProvider} from a `service → credential` map. A plain
* string value is treated as a bearer token; a {@link Credential} is used as-is.
* Always 2-legged (issues directly); throws if a requested service has none.
*/
function staticTokens(creds, options = {}) {
return {
id: options.id ?? 'static-tokens',
getCredential(req) {
const entry = creds[req.service];
if (entry === undefined) {
return Promise.reject(new Error(`staticTokens: no credential configured for service '${req.service}'. ` +
`Known services: ${Object.keys(creds).join(', ') || '(none)'}.`));
}
const credential = typeof entry === 'string' ? (0, kinds_js_1.bearer)(entry) : entry;
return Promise.resolve({
status: 'issued',
credential,
...(options.expiresAt !== undefined && { expiresAt: options.expiresAt }),
});
},
};
}
exports.staticTokens = staticTokens;
//# sourceMappingURL=staticTokens.js.map