@adonis-agora/agent
Version:
Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.
21 lines • 928 B
JavaScript
import { AgentClient } from './core/client.js';
import { csrfHeaders } from './csrf.js';
/** The CSRF header first, then the caller's own — so an app can still override it. */
export async function withCsrf(own) {
return { ...csrfHeaders(), ...((await own?.()) ?? {}) };
}
/**
* An {@link AgentClient} on this package's routes: the session cookie rides every request
* (`credentials: 'same-origin'`, or whatever you pass for an API on another origin) and the CSRF
* header is read from the page per request. For code outside React, or to hand one hook a
* connection of its own (`useAgentChat({ backend })`). Under React prefer `AgentProvider`.
*/
export function createAgentClient(options = {}) {
const { getHeaders, ...rest } = options;
return new AgentClient({
credentials: 'same-origin',
...rest,
getHeaders: () => withCsrf(getHeaders),
});
}
//# sourceMappingURL=client.js.map