import type { DispatchQueue } from './dispatch.js'; import type { DeliveredMessage } from './delivered-message.js'; import type { McpServerConnection, McpServerOptions } from './mcp.js'; import type { ThinkingLevel } from './model.js'; import type { Schema } from './schema.js'; import type { SandboxEnv, SandboxFactory } from './sandbox.js'; import type { HookToolDefinition, SecretRef, ToolDef, ToolHarness, ToolProgressLogger } from './tools.js'; import type { AgentInit, DynamicAgentExecutionDescriptor, FabricActor, JsonObject, JsonValue, SandboxBackend, SessionEntry, SessionStore, Skill } from './types.js'; /** * Dynamic persistent-agent composition. * * The runtime keeps Fabric's builders, policies, persistence contracts, and * backend-neutral types while allowing capabilities to evolve per interaction. */ export interface DynamicAgentProps> { readonly id: string; readonly env: TEnv; } export type DynamicAgentFunction> = (props: DynamicAgentProps) => string | undefined | import('./persistent-agent.js').PersistentAgentConfig | Promise; export interface DynamicStateWrite { readonly name: string; readonly value: JsonValue; } export interface DynamicAgentRenderOptions { store?: SessionStore; storeSessionId?: string; /** Instance-scoped metadata store, shared across named sessions. */ instanceStoreSessionId?: string; agentName?: string; delivery?: DeliveredMessage; initialData?: unknown; tenantId?: string; actor?: FabricActor; /** Host-scoped durable queue. Avoids process-global dispatch state across bundled SDK copies. */ dispatchQueue?: DispatchQueue; /** Static creation-data schema copied from the persistent-agent definition. */ initialDataSchema?: Schema; } export interface DynamicAgentRefreshInput { delivery?: DeliveredMessage; } export interface DynamicAgentResponse { /** Durable entry anchoring this response/continuation cycle. */ readonly responseId?: string; readonly result?: unknown; readonly toolCalls: ReadonlyArray<{ tool: string; toolCallId?: string; output?: unknown; error?: string; }>; readonly usage?: JsonObject; } export interface DynamicLifecycleContext { readonly delivery?: DeliveredMessage; readonly metadata: Readonly; readonly response: DynamicAgentResponse; } export interface DynamicAgentStartContext extends DynamicLifecycleContext { readonly signal: AbortSignal; readonly sandbox: SandboxEnv; readonly harness: ToolHarness; readonly log: ToolProgressLogger; /** Buffer a signal into this delivery before the model's next turn. */ append(message: Extract): void; } export interface DynamicAgentFinishContext extends DynamicLifecycleContext { readonly signal: AbortSignal; readonly sandbox: SandboxEnv; readonly harness: ToolHarness; readonly log: ToolProgressLogger; /** Queue a validated signal for one bounded continuation cycle. */ append(message: Extract): void; } export type DynamicMetadataCallback = (context: DynamicLifecycleContext) => JsonObject | undefined; export interface DynamicAgentRuntime { readonly dataNames: readonly string[]; readonly resourceFingerprint: string; /** Build the JSON-safe descriptor handed to a trusted durable runtime. */ executionDescriptor(): DynamicAgentExecutionDescriptor; /** Re-render hook declarations from current durable state before a model turn. */ refresh(input?: DynamicAgentRefreshInput): Promise; runResponseStart(response?: DynamicAgentResponse, correlation?: { submissionId?: string; attemptId?: string; }): Promise; /** * Run start callbacks concurrently and commit their collected state and signals atomically. * Signal ordering follows callback declaration order. Concurrent writes to the same state key * follow callback scheduling, so dependent or conflicting writes belong in one callback. */ runAgentStart(input: { signal?: AbortSignal; sandbox?: SandboxEnv; /** Delivery-specific durable marker for a message joined into the host response. */ submissionId?: string; attemptId?: string; }): Promise>>; runAgentFinish(response: DynamicAgentResponse, correlation?: { submissionId?: string; attemptId?: string; }): Promise>>; runResponseFinish(response: DynamicAgentResponse, correlation?: { submissionId?: string; attemptId?: string; }): Promise; /** Advance the render-local state view after an atomic tool commit. */ acknowledgeStateWrites(writes: readonly DynamicStateWrite[]): void; close(): Promise; } export interface McpConnectionDefinition extends Omit { name: string; url?: string | URL; /** Provider-specific lazy connector. Invoked inside submission context. */ connect?: () => Promise; /** Secret reference or a per-request resolver. Raw values are never persisted. */ auth?: SecretRef | (() => string | undefined | Promise); /** Resolve an auth SecretRef at the narrow render/runtime boundary. */ resolveSecret?: (ref: SecretRef) => string | undefined | Promise; /** Allowlist using the MCP server's original tool names. */ tools?: string[]; /** Skip a failed connection rather than failing the submission. */ optional?: boolean; } export interface SubagentDefinition { name: string; description: string; agent: (props?: never) => string | undefined; model?: string; thinkingLevel?: ThinkingLevel; } export interface UseModelOptions { thinkingLevel?: ThinkingLevel; compaction?: false | NonNullable; } export interface UseSandboxOptions { cwd?: string; } export type StateSetter = (value: T | ((previous: T) => T)) => void; export declare function unwrapDynamicToolResult(value: unknown): { output: unknown; stateWrites: readonly DynamicStateWrite[]; }; export declare function isDynamicAgentRendering(): boolean; export declare function renderDynamicAgent(render: DynamicAgentFunction, props: DynamicAgentProps, options?: DynamicAgentRenderOptions, staticConfig?: Readonly): Promise; export declare function useInstruction(text: string): void; export declare function useModel(model: NonNullable, options?: UseModelOptions): void; export declare function useSandbox(sandbox: SandboxBackend | SandboxFactory | SandboxEnv, options?: UseSandboxOptions): void; export declare function useSkill(skill: Skill): void; export declare function useTool(tool: ToolDef | HookToolDefinition): void; export declare function usePersistentState(name: string, defaultValue: T, options?: { schema?: Schema; }): [T, StateSetter]; export declare function useDelivery(): DeliveredMessage; export declare function useInitialData(): T; export declare function useDispatchMessage(): (message: DeliveredMessage | string) => Promise; export declare function useDataWriter(name: string, options?: { schema?: Schema; }): (data: T) => void; export declare function useResponseStart(run: DynamicMetadataCallback): void; export declare function useResponseFinish(run: DynamicMetadataCallback): void; export declare function useAgentStart(run: (context: DynamicAgentStartContext) => void | Promise): void; export declare function useAgentFinish(run: (context: DynamicAgentFinishContext) => void | Promise): void; export declare function defineMcpConnection(definition: McpConnectionDefinition): McpConnectionDefinition; export declare function useMcpConnection(definition: McpConnectionDefinition): void; export declare function defineSubagent(definition: SubagentDefinition): SubagentDefinition; export declare const GeneralSubagent: SubagentDefinition; export declare function useSubagent(definition: SubagentDefinition): void; /** Build an atomic agent-state entry batch for a successful tool outcome. */ export declare function dynamicStateEntriesForTool(input: { sessionId: string; toolCallId: string; parentId?: string; timestamp: string; actor?: FabricActor; tenantId?: string; }, writes: readonly DynamicStateWrite[]): SessionEntry[]; //# sourceMappingURL=dynamic-agent.d.ts.map