import { ChatLifecycleContext, AgentCapabilityContext, Logger, AgentCapabilityMcpToolContribution, MCPServerStatus, MessageRole, Message, AgentMiddleware, AgentCapabilityProvider, MCPConfig } from '@cuylabs/agent-core'; type MaybePromise = T | Promise; type A365McpTools = NonNullable; type A365ToolingUtility = { GetToolRequestHeaders?: (authToken?: string, turnContext?: A365TurnContextLike, options?: A365ToolingToolOptions) => Record; }; type A365ChatHistoryService = { sendChatHistory(turnContext: A365TurnContextLike, chatHistoryMessages: A365ChatHistoryMessage[], options?: A365ToolingToolOptions): Promise; }; type A365TurnContextLike = { activity?: unknown; [key: string]: unknown; }; type A365AuthorizationLike = object; interface A365McpServerConfig { mcpServerName: string; url: string; headers?: Record; audience?: string; scope?: string; publisher?: string; } interface A365ToolingToolOptions { orchestratorName?: string; [key: string]: unknown; } interface A365ToolingProviderContext { agentContext: AgentCapabilityContext; turnContext: A365TurnContextLike; } interface A365ChatHistoryContext { chatContext: ChatLifecycleContext; turnContext: A365TurnContextLike; } interface A365ToolingConnectorContext extends A365ToolingProviderContext { providerName: string; serverTimeoutMs: number; logger?: Logger; } interface A365ToolingMcpConnection { mcpTools: A365McpTools; cleanup?: () => void | Promise; statuses?: Map; } type A365ToolingMcpConnector = (servers: A365McpServerConfig[], context: A365ToolingConnectorContext) => Promise; type A365ToolingServerFilter = (servers: A365McpServerConfig[], context: A365ToolingProviderContext) => MaybePromise; type A365ToolingValueResolver = (context: A365ToolingProviderContext) => MaybePromise; type A365ChatHistoryValueResolver = (context: A365ChatHistoryContext) => MaybePromise; interface A365ChatHistoryMessage { id: string; role: string; content: string; timestamp: string; } interface A365OperationResultLike { succeeded: boolean; errors?: readonly unknown[]; toString?: () => string; } interface A365ToolingModule { Utility?: A365ToolingUtility; McpToolServerConfigurationService: new (configurationProvider?: unknown) => { listToolServers(turnContext: A365TurnContextLike, authorization: A365AuthorizationLike, authHandlerName: string, authToken?: string, options?: A365ToolingToolOptions): Promise; sendChatHistory?(turnContext: A365TurnContextLike, chatHistoryMessages: A365ChatHistoryMessage[], options?: A365ToolingToolOptions): Promise; }; } type A365ChatHistoryFailureMode = "warn" | "ignore"; type A365MissingTurnContextMode = "skip" | "warn"; type A365ChatHistoryTiming = "after-turn"; interface ConvertAgentMessagesToA365ChatHistoryOptions { /** * Restrict converted messages to these roles. Defaults to all roles. */ roles?: readonly MessageRole[]; /** * Include tool messages in the RTP context. * * Defaults to true to match Microsoft's PRD, which expects standard tool and * function messages to be submitted unless the host explicitly filters them. */ includeTools?: boolean; } interface SendA365ChatHistoryOptions { turnContext: A365TurnContextLike; chatHistoryMessages: A365ChatHistoryMessage[]; toolOptions?: A365ToolingToolOptions; configurationProvider?: unknown; getToolingModule?: () => Promise; serviceFactory?: (module: A365ToolingModule, configurationProvider: unknown) => A365ChatHistoryService; } interface CreateA365ChatHistoryMiddlewareOptions { /** * Middleware name used in agent-core middleware logs. * * @default "a365-chat-history" */ name?: string; /** * When to submit chat history. v0 supports post-turn submission only. * * @default "after-turn" */ timing?: A365ChatHistoryTiming; /** * Maximum recent messages to submit as context. * * Empty context is still submitted to register the current Microsoft * activity with RTP. * * @default 20 */ limit?: number; /** * Maximum combined characters from submitted chat history message content. * * The middleware keeps the most recent converted messages within this * budget. If the oldest included message is too large, its content is * truncated to fit. Empty context is still submitted when the budget is 0. * * @default 32000 */ maxContentChars?: number; /** * Restrict submitted history to these roles. Defaults to all roles. */ roles?: readonly MessageRole[]; /** * Include tool messages in the submitted history. * * @default true */ includeTools?: boolean; /** * Optional A365 tooling request options, such as `orchestratorName`. */ toolOptions?: A365ToolingToolOptions | A365ChatHistoryValueResolver; /** * Gets the active Microsoft TurnContext. * * Defaults to reading `currentM365TurnContext()?.turnContext` from * `@cuylabs/channel-m365-agent-core`. Non-M365 hosts are skipped by default. */ getTurnContext?: () => MaybePromise; /** * What to do when no Microsoft TurnContext is available. * * @default "skip" */ onMissingTurnContext?: A365MissingTurnContextMode; /** * How to handle transport/module/conversion failures. * * @default "warn" */ failureMode?: A365ChatHistoryFailureMode; /** * Optional Microsoft A365 tooling configuration provider. */ configurationProvider?: unknown; /** * Test seam for loading `@microsoft/agents-a365-tooling`. */ getToolingModule?: () => Promise; /** * Advanced service factory override for tests or custom Microsoft SDK wiring. */ serviceFactory?: SendA365ChatHistoryOptions["serviceFactory"]; logger?: Logger; } interface CreateA365ToolingCapabilityProviderOptions { /** * Provider name used in duplicate-tool errors and logs. * * @default "a365-tooling" */ name?: string; /** * Microsoft Agent 365 Authorization object, or a resolver for request-scoped * Authorization. The concrete object comes from `@microsoft/agents-hosting`. */ authorization: A365AuthorizationLike | A365ToolingValueResolver; /** * Auth handler name configured in the Microsoft Agents SDK application. */ authHandlerName: string; /** * Optional bearer token for the A365 tooling gateway. Omit this in normal * production use so Microsoft's SDK performs token exchange from the * Authorization object and active TurnContext. */ authToken?: string | A365ToolingValueResolver; /** * Optional A365 tooling request options, such as `orchestratorName`. */ toolOptions?: A365ToolingToolOptions | A365ToolingValueResolver; /** * Gets the active Microsoft TurnContext. * * Defaults to reading `currentM365TurnContext()?.turnContext` from * `@cuylabs/channel-m365-agent-core`. Pass this in tests or in hosts that bind * TurnContext differently. Custom hosts should return a real Microsoft * TurnContext or a compatible object with the activity fields required by * Microsoft's A365 tooling SDK, including conversation and agent identity * metadata. */ getTurnContext?: () => MaybePromise; /** * Optional Microsoft A365 tooling configuration provider. */ configurationProvider?: unknown; /** * Optional server filter/gate before MCP connection. * * The input array is freshly resolved for the active turn. Returning a new * array is recommended when filtering or reordering. */ filterServers?: A365ToolingServerFilter; /** * Advanced connector override. The default connector creates one * agent-core MCPManager per turn and closes it during turn cleanup. */ connectMcpServers?: A365ToolingMcpConnector; /** * Test seam for loading `@microsoft/agents-a365-tooling`. */ getToolingModule?: () => Promise; /** * Per-server MCP connect/list timeout. * * @default 5000 */ serverTimeoutMs?: number; /** * Reserved for future pooling modes. v0 supports per-turn connections only. * * @default "per-turn" */ mode?: "per-turn"; logger?: Logger; } interface ToAgentCoreMcpConfigOptions { timeoutMs?: number; } declare class A365ToolingTurnContextError extends Error { constructor(message?: string, options?: ErrorOptions); } declare class A365ToolingModuleLoadError extends Error { constructor(packageName: string, cause: unknown); } declare function createA365ToolingCapabilityProvider(options: CreateA365ToolingCapabilityProviderOptions): AgentCapabilityProvider; declare function convertAgentMessagesToA365ChatHistory(messages: readonly Message[], options?: ConvertAgentMessagesToA365ChatHistoryOptions): A365ChatHistoryMessage[]; declare function sendA365ChatHistory(options: SendA365ChatHistoryOptions): Promise; declare function createA365ChatHistoryMiddleware(options?: CreateA365ChatHistoryMiddlewareOptions): AgentMiddleware; declare function connectA365McpServers(servers: A365McpServerConfig[], context: A365ToolingConnectorContext): Promise; declare function toAgentCoreMcpConfig(servers: A365McpServerConfig[], options?: ToAgentCoreMcpConfigOptions): MCPConfig; export { type A365AuthorizationLike, type A365ChatHistoryContext, type A365ChatHistoryFailureMode, type A365ChatHistoryMessage, type A365ChatHistoryTiming, type A365ChatHistoryValueResolver, type A365McpServerConfig, type A365MissingTurnContextMode, type A365OperationResultLike, type A365ToolingConnectorContext, type A365ToolingMcpConnection, type A365ToolingMcpConnector, type A365ToolingModule, A365ToolingModuleLoadError, type A365ToolingProviderContext, type A365ToolingServerFilter, type A365ToolingToolOptions, A365ToolingTurnContextError, type A365ToolingValueResolver, type A365TurnContextLike, type ConvertAgentMessagesToA365ChatHistoryOptions, type CreateA365ChatHistoryMiddlewareOptions, type CreateA365ToolingCapabilityProviderOptions, type SendA365ChatHistoryOptions, type ToAgentCoreMcpConfigOptions, connectA365McpServers, convertAgentMessagesToA365ChatHistory, createA365ChatHistoryMiddleware, createA365ToolingCapabilityProvider, sendA365ChatHistory, toAgentCoreMcpConfig };