UNPKG

agentfootprint

Version:

The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.

76 lines • 3.47 kB
"use strict"; /** * servingConversation — WHICH conversation a run's self-explain evidence is * kept and served under, and which run that was. Internal: nothing here is on * the `Agent` class's public surface. * * THE KEY SPACES ARE DISJOINT BY CONSTRUCTION (recheck RB1). A session id is a * string a client chose — any visible ASCII, `#` included — so it can never be * compared against a key the library minted. Every key is namespaced: * * - `session:<sessionId>` — a run with a session ({@link sessionConversationKey}); * - `hosted:<uuid>` — a HOSTED run with no session: `standingAgent` mints a * random UUID per request and hands it in through * {@link withHostedConversation}; unguessable, and in a space no session id * can enter, so no other caller — signed in or not — can name it; * - `undefined` — a DIRECT, unhosted run with no session: the single-user * path, where "the previous run with no session" is the caller's own. * * Why not a session id for the hosted case: a session id also decides the * memory namespace (seed's session rung), `EventMeta.sessionId` and * tool-session teardown, and a request that named no session changes none of * those. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.servingConversationOf = exports.registerServingConversation = exports.hostedConversationOf = exports.hostedConversationKey = exports.sessionConversationKey = exports.withHostedConversation = void 0; /** The option key a host sets its per-request key under. Not a public option. */ const HOSTED_CONVERSATION = Symbol('agentfootprint.hostedConversation'); /** * `options` plus the host's key for a run that has no session — a copy; the * caller's object is not touched. * * @example * ```ts * runner.run(input, withHostedConversation(runOptions, sessionKey)); * ``` */ function withHostedConversation(options, key) { return Object.assign({}, options, { [HOSTED_CONVERSATION]: key }); } exports.withHostedConversation = withHostedConversation; /** The evidence key of a run with a session. */ function sessionConversationKey(sessionId) { return `session:${sessionId}`; } exports.sessionConversationKey = sessionConversationKey; /** The evidence key of a hosted run with no session, from the host's minted id. */ function hostedConversationKey(minted) { return `hosted:${minted}`; } exports.hostedConversationKey = hostedConversationKey; /** The host's minted id a run's options carry, if any. */ function hostedConversationOf(options) { if (options === null || typeof options !== 'object') return undefined; const key = options[HOSTED_CONVERSATION]; return typeof key === 'string' ? key : undefined; } exports.hostedConversationOf = hostedConversationOf; const registry = new WeakMap(); /** Called once by the agent's constructor. */ function registerServingConversation(agent, read) { registry.set(agent, read); } exports.registerServingConversation = registerServingConversation; /** * The conversation `agent` is serving (or served last). Throws for an object * that never registered — a wiring bug, never a runtime condition. */ function servingConversationOf(agent) { const read = registry.get(agent); if (read === undefined) throw new Error('servingConversationOf: not an Agent'); return read(); } exports.servingConversationOf = servingConversationOf; //# sourceMappingURL=servingConversation.js.map