/** * Publishes the cached service catalog into each request as a sourced context * message, on the `agent/pre-step` waterfall. * * Why a context message rather than the tool descriptions: a tool description is * fixed when the plugin loads, and a plugin loads once per PROCESS, not once per * session. In a long-running host the TTL would be evaluated exactly once at * `apply()` and a service created elsewhere would never be noticed until a * restart. Re-registering tools to refresh a description instead invalidates the * prompt prefix cache from the first changed schema token. Injecting context * keeps the tool schemas byte-stable forever and still refreshes per step. * * Two hard constraints follow from `agent/pre-step` semantics: * * 1. `pre-step` fires once per STEP, and a step is one model request — a turn with * five tool calls fires it six times. Re-injecting each time would insert six * copies into one turn and void the KV cache from the first insertion onward, * so change suppression is a correctness requirement, not an optimization. * 2. A throwing listener fails the proposed step, i.e. the user's turn stalls. * Everything here is therefore wrapped: any failure degrades to "inject * nothing this step". */ import type { Context } from "@deepseek-ai/cordis"; import type { ServiceCache } from "./service-cache.js"; /** Producer kind for this plugin's service-catalog context. */ export declare const KB_CATALOG_SOURCE_KIND = "bailian-kb-catalog"; /** Catalog context this plugin publishes into a session. */ export interface KbServiceCatalogSource { readonly kind: typeof KB_CATALOG_SOURCE_KIND; readonly form: "catalog"; } declare module "@deepseek-ai/dsh-llm" { interface MessageSourceMap { "bailian-kb-catalog": KbServiceCatalogSource; } } export interface ServiceContextOptions { cache: ServiceCache; /** Resolves the workspace being served; undefined means "not configured yet". */ resolveWorkspaceId: () => Promise; /** Resolves the configured default retrieval service (settings then credential). */ resolveDefaultRetrieveAgentId: () => Promise; /** Resolves the configured default chat service (settings then credential). */ resolveDefaultChatAgentId: () => Promise; warn: (message: string) => void; } /** * Install the pre-step listener that keeps the catalog present and current. * @param ctx - a context with `agents` available. * @param opts - the cache plus the deployment's resolved workspace and defaults. */ export declare function installServiceContext(ctx: Context, opts: ServiceContextOptions): void;