@copilotkit/runtime 1.50.0-beta.9 → 1.50.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. package/CHANGELOG.md +157 -0
  2. package/dist/chunk-27JKTS6P.mjs +1704 -0
  3. package/dist/chunk-27JKTS6P.mjs.map +1 -0
  4. package/dist/{chunk-FMU55SEU.mjs → chunk-2GPTVDTO.mjs} +2 -2
  5. package/dist/chunk-3AJVKDZX.mjs +3097 -0
  6. package/dist/chunk-3AJVKDZX.mjs.map +1 -0
  7. package/dist/{chunk-BJEYMRDD.mjs → chunk-45RCC3ZS.mjs} +2 -2
  8. package/dist/chunk-4EHJ4XFJ.mjs +25 -0
  9. package/dist/chunk-4EHJ4XFJ.mjs.map +1 -0
  10. package/dist/chunk-4IANB4TC.mjs +25 -0
  11. package/dist/chunk-4IANB4TC.mjs.map +1 -0
  12. package/dist/{chunk-Z752VE75.mjs → chunk-4KES76K3.mjs} +2 -2
  13. package/dist/chunk-4OGE3SLW.mjs +3100 -0
  14. package/dist/chunk-4OGE3SLW.mjs.map +1 -0
  15. package/dist/chunk-54YJBMCP.mjs +3097 -0
  16. package/dist/chunk-54YJBMCP.mjs.map +1 -0
  17. package/dist/chunk-6ER4SZYH.mjs +74 -0
  18. package/dist/chunk-6ER4SZYH.mjs.map +1 -0
  19. package/dist/chunk-6TNSLHVR.mjs +74 -0
  20. package/dist/chunk-6TNSLHVR.mjs.map +1 -0
  21. package/dist/chunk-7V4BK7TZ.mjs +25 -0
  22. package/dist/chunk-7V4BK7TZ.mjs.map +1 -0
  23. package/dist/chunk-7YZIEXD2.mjs +74 -0
  24. package/dist/chunk-7YZIEXD2.mjs.map +1 -0
  25. package/dist/chunk-A4XHOAFU.mjs +25 -0
  26. package/dist/chunk-A4XHOAFU.mjs.map +1 -0
  27. package/dist/chunk-A555KEAD.mjs +6020 -0
  28. package/dist/chunk-A555KEAD.mjs.map +1 -0
  29. package/dist/chunk-AF73TFTX.mjs +74 -0
  30. package/dist/chunk-AF73TFTX.mjs.map +1 -0
  31. package/dist/chunk-AQG2SVCA.mjs +25 -0
  32. package/dist/chunk-AQG2SVCA.mjs.map +1 -0
  33. package/dist/chunk-BJZHMXND.mjs +74 -0
  34. package/dist/chunk-BJZHMXND.mjs.map +1 -0
  35. package/dist/chunk-CB2OJXF6.mjs +25 -0
  36. package/dist/chunk-CB2OJXF6.mjs.map +1 -0
  37. package/dist/chunk-CEOMFPJU.mjs +6020 -0
  38. package/dist/chunk-CEOMFPJU.mjs.map +1 -0
  39. package/dist/chunk-CZVLR7CC.mjs +175 -0
  40. package/dist/chunk-CZVLR7CC.mjs.map +1 -0
  41. package/dist/{chunk-SBCOROE4.mjs → chunk-DCEEHMLJ.mjs} +16 -1
  42. package/dist/chunk-DCEEHMLJ.mjs.map +1 -0
  43. package/dist/chunk-DE3CLKUG.mjs +25 -0
  44. package/dist/chunk-DE3CLKUG.mjs.map +1 -0
  45. package/dist/chunk-DTPRUTNV.mjs +25 -0
  46. package/dist/chunk-DTPRUTNV.mjs.map +1 -0
  47. package/dist/{chunk-TTUAEJLD.mjs → chunk-ERUOA47O.mjs} +11 -2
  48. package/dist/chunk-ERUOA47O.mjs.map +1 -0
  49. package/dist/chunk-ESSRC64W.mjs +74 -0
  50. package/dist/chunk-ESSRC64W.mjs.map +1 -0
  51. package/dist/chunk-GRAN6K6N.mjs +25 -0
  52. package/dist/chunk-GRAN6K6N.mjs.map +1 -0
  53. package/dist/chunk-I27F2UPA.mjs +175 -0
  54. package/dist/chunk-I27F2UPA.mjs.map +1 -0
  55. package/dist/chunk-IAZKTOQW.mjs +25 -0
  56. package/dist/chunk-IAZKTOQW.mjs.map +1 -0
  57. package/dist/chunk-J6XZ5MFB.mjs +25 -0
  58. package/dist/chunk-J6XZ5MFB.mjs.map +1 -0
  59. package/dist/chunk-JJ32MA4C.mjs +73 -0
  60. package/dist/chunk-JJ32MA4C.mjs.map +1 -0
  61. package/dist/chunk-JJY4ZTHQ.mjs +25 -0
  62. package/dist/chunk-JJY4ZTHQ.mjs.map +1 -0
  63. package/dist/chunk-KEYLBFU2.mjs +3117 -0
  64. package/dist/chunk-KEYLBFU2.mjs.map +1 -0
  65. package/dist/chunk-KQ53L4WZ.mjs +3094 -0
  66. package/dist/chunk-KQ53L4WZ.mjs.map +1 -0
  67. package/dist/chunk-KTELVQ67.mjs +3098 -0
  68. package/dist/chunk-KTELVQ67.mjs.map +1 -0
  69. package/dist/chunk-LPEPX6NH.mjs +25 -0
  70. package/dist/chunk-LPEPX6NH.mjs.map +1 -0
  71. package/dist/chunk-MDXE55DK.mjs +3117 -0
  72. package/dist/chunk-MDXE55DK.mjs.map +1 -0
  73. package/dist/chunk-MMFUVOXH.mjs +73 -0
  74. package/dist/chunk-MMFUVOXH.mjs.map +1 -0
  75. package/dist/chunk-N3Y4U66N.mjs +253 -0
  76. package/dist/chunk-N3Y4U66N.mjs.map +1 -0
  77. package/dist/chunk-O7UYB4MH.mjs +25 -0
  78. package/dist/chunk-O7UYB4MH.mjs.map +1 -0
  79. package/dist/chunk-OFNVQHNM.mjs +3089 -0
  80. package/dist/chunk-OFNVQHNM.mjs.map +1 -0
  81. package/dist/{chunk-DZV4ZIAR.mjs → chunk-OFSV5GET.mjs} +17 -6
  82. package/dist/chunk-OFSV5GET.mjs.map +1 -0
  83. package/dist/chunk-OMRST67R.mjs +25 -0
  84. package/dist/chunk-OMRST67R.mjs.map +1 -0
  85. package/dist/chunk-PRZHE74A.mjs +25 -0
  86. package/dist/chunk-PRZHE74A.mjs.map +1 -0
  87. package/dist/chunk-PTYRVXXP.mjs +80 -0
  88. package/dist/chunk-PTYRVXXP.mjs.map +1 -0
  89. package/dist/chunk-R22B5CCO.mjs +25 -0
  90. package/dist/chunk-R22B5CCO.mjs.map +1 -0
  91. package/dist/chunk-SHBDMA63.mjs +141 -0
  92. package/dist/chunk-SHBDMA63.mjs.map +1 -0
  93. package/dist/chunk-SPVXBPRA.mjs +74 -0
  94. package/dist/chunk-SPVXBPRA.mjs.map +1 -0
  95. package/dist/chunk-T72G46ME.mjs +25 -0
  96. package/dist/chunk-T72G46ME.mjs.map +1 -0
  97. package/dist/chunk-TGELROPU.mjs +25 -0
  98. package/dist/chunk-TGELROPU.mjs.map +1 -0
  99. package/dist/chunk-UNX4IAAD.mjs +25 -0
  100. package/dist/chunk-UNX4IAAD.mjs.map +1 -0
  101. package/dist/chunk-V4DHVC7M.mjs +3085 -0
  102. package/dist/chunk-V4DHVC7M.mjs.map +1 -0
  103. package/dist/chunk-VVRFOB66.mjs +25 -0
  104. package/dist/chunk-VVRFOB66.mjs.map +1 -0
  105. package/dist/chunk-W6NVBYM6.mjs +80 -0
  106. package/dist/chunk-W6NVBYM6.mjs.map +1 -0
  107. package/dist/chunk-W7MBACGC.mjs +74 -0
  108. package/dist/chunk-W7MBACGC.mjs.map +1 -0
  109. package/dist/chunk-WMD4XZZS.mjs +25 -0
  110. package/dist/chunk-WMD4XZZS.mjs.map +1 -0
  111. package/dist/chunk-WX2ZNCRT.mjs +74 -0
  112. package/dist/chunk-WX2ZNCRT.mjs.map +1 -0
  113. package/dist/chunk-Y2Z62E2T.mjs +74 -0
  114. package/dist/chunk-Y2Z62E2T.mjs.map +1 -0
  115. package/dist/chunk-YO4I6RVI.mjs +25 -0
  116. package/dist/chunk-YO4I6RVI.mjs.map +1 -0
  117. package/dist/chunk-Z6Q5IW6I.mjs +3098 -0
  118. package/dist/chunk-Z6Q5IW6I.mjs.map +1 -0
  119. package/dist/chunk-Z726O3G2.mjs +25 -0
  120. package/dist/chunk-Z726O3G2.mjs.map +1 -0
  121. package/dist/chunk-ZE4SMZZR.mjs +3097 -0
  122. package/dist/chunk-ZE4SMZZR.mjs.map +1 -0
  123. package/dist/chunk-ZULZB33C.mjs +73 -0
  124. package/dist/chunk-ZULZB33C.mjs.map +1 -0
  125. package/dist/chunk-ZVRGXMY7.mjs +25 -0
  126. package/dist/chunk-ZVRGXMY7.mjs.map +1 -0
  127. package/dist/chunk-ZZ35WBYQ.mjs +25 -0
  128. package/dist/chunk-ZZ35WBYQ.mjs.map +1 -0
  129. package/dist/graphql/types/converted/index.d.ts +1 -1
  130. package/dist/graphql/types/converted/index.js +16 -110
  131. package/dist/graphql/types/converted/index.js.map +1 -1
  132. package/dist/graphql/types/converted/index.mjs +2 -3
  133. package/dist/{groq-adapter-50bc6e4a.d.ts → groq-adapter-540da9c3.d.ts} +6 -1
  134. package/dist/groq-adapter-a6f5e9d2.d.ts +331 -0
  135. package/dist/groq-adapter-c8aec5c5.d.ts +321 -0
  136. package/dist/index-96b330da.d.ts +119 -0
  137. package/dist/index.d.ts +67 -8
  138. package/dist/index.js +118 -28
  139. package/dist/index.js.map +1 -1
  140. package/dist/index.mjs +120 -31
  141. package/dist/index.mjs.map +1 -1
  142. package/dist/langserve-0c6100e3.d.ts +257 -0
  143. package/dist/langserve-978d5790.d.ts +243 -0
  144. package/dist/{langserve-74a52292.d.ts → langserve-9fc76ce5.d.ts} +1 -0
  145. package/dist/lib/index.d.ts +5 -59
  146. package/dist/lib/index.js +3702 -803
  147. package/dist/lib/index.js.map +1 -1
  148. package/dist/lib/index.mjs +20 -18
  149. package/dist/lib/integrations/index.d.ts +15 -9
  150. package/dist/lib/integrations/index.js +215 -187
  151. package/dist/lib/integrations/index.js.map +1 -1
  152. package/dist/lib/integrations/index.mjs +8 -7
  153. package/dist/lib/integrations/nest/index.d.ts +5 -6
  154. package/dist/lib/integrations/nest/index.js +197 -175
  155. package/dist/lib/integrations/nest/index.js.map +1 -1
  156. package/dist/lib/integrations/nest/index.mjs +6 -5
  157. package/dist/lib/integrations/node-express/index.d.ts +5 -6
  158. package/dist/lib/integrations/node-express/index.js +197 -175
  159. package/dist/lib/integrations/node-express/index.js.map +1 -1
  160. package/dist/lib/integrations/node-express/index.mjs +6 -5
  161. package/dist/lib/integrations/node-http/index.d.ts +5 -6
  162. package/dist/lib/integrations/node-http/index.js +197 -175
  163. package/dist/lib/integrations/node-http/index.js.map +1 -1
  164. package/dist/lib/integrations/node-http/index.mjs +5 -4
  165. package/dist/service-adapters/index.d.ts +7 -11
  166. package/dist/service-adapters/index.js +8 -21
  167. package/dist/service-adapters/index.js.map +1 -1
  168. package/dist/service-adapters/index.mjs +2 -4
  169. package/dist/shared-0a7346ce.d.ts +466 -0
  170. package/dist/{shared-f6d43ef8.d.ts → shared-35c6eb04.d.ts} +3 -1
  171. package/dist/shared-9ed1dc31.d.ts +414 -0
  172. package/dist/shared-da5708fe.d.ts +449 -0
  173. package/package.json +14 -20
  174. package/src/lib/index.ts +7 -6
  175. package/src/lib/runtime/copilot-runtime.ts +62 -26
  176. package/src/lib/runtime/telemetry-agent-runner.ts +139 -0
  177. package/dist/chunk-DZV4ZIAR.mjs.map +0 -1
  178. package/dist/chunk-SBCOROE4.mjs.map +0 -1
  179. package/dist/chunk-TTUAEJLD.mjs.map +0 -1
  180. /package/dist/{chunk-FMU55SEU.mjs.map → chunk-2GPTVDTO.mjs.map} +0 -0
  181. /package/dist/{chunk-BJEYMRDD.mjs.map → chunk-45RCC3ZS.mjs.map} +0 -0
  182. /package/dist/{chunk-Z752VE75.mjs.map → chunk-4KES76K3.mjs.map} +0 -0
@@ -4,16 +4,14 @@ import {
4
4
  EmptyAdapter,
5
5
  ExperimentalEmptyAdapter,
6
6
  ExperimentalOllamaAdapter,
7
- RemoteChain
8
- } from "../chunk-TTUAEJLD.mjs";
9
- import {
10
7
  GoogleGenerativeAIAdapter,
11
8
  GroqAdapter,
12
9
  LangChainAdapter,
13
10
  OpenAIAdapter,
14
11
  OpenAIAssistantAdapter,
12
+ RemoteChain,
15
13
  UnifyAdapter
16
- } from "../chunk-SBCOROE4.mjs";
14
+ } from "../chunk-27JKTS6P.mjs";
17
15
  import {
18
16
  convertServiceAdapterError
19
17
  } from "../chunk-AMUJQ6IR.mjs";
@@ -0,0 +1,466 @@
1
+ import * as graphql from 'graphql';
2
+ import * as createPinoLogger from 'pino';
3
+ import createPinoLogger__default from 'pino';
4
+ import { YogaInitialContext, createYoga } from 'graphql-yoga';
5
+ import { Parameter, Action, CopilotErrorHandler } from '@copilotkit/shared';
6
+ import { b as CopilotServiceAdapter, A as ActionInput, d as AgentSessionInput, e as AgentStateInput, F as ForwardedParametersInput, E as ExtensionsInput, R as RemoteChainParameters, f as RuntimeEventSource, g as ExtensionsResponse } from './langserve-0c6100e3.js';
7
+ import { b as MessageInput, M as Message } from './index-96b330da.js';
8
+ import { CopilotCloudOptions } from './lib/cloud/index.js';
9
+ import { AbstractAgent } from '@ag-ui/client';
10
+
11
+ declare enum MetaEventName {
12
+ LangGraphInterruptEvent = "LangGraphInterruptEvent",
13
+ CopilotKitLangGraphInterruptEvent = "CopilotKitLangGraphInterruptEvent"
14
+ }
15
+
16
+ declare class MetaEventInput {
17
+ name: MetaEventName;
18
+ value?: string;
19
+ response?: string;
20
+ messages?: MessageInput[];
21
+ }
22
+
23
+ declare class CopilotContextInput {
24
+ description: string;
25
+ value: string;
26
+ }
27
+
28
+ type EndpointDefinition = CopilotKitEndpoint | LangGraphPlatformEndpoint;
29
+ declare enum EndpointType {
30
+ CopilotKit = "copilotKit",
31
+ LangGraphPlatform = "langgraph-platform"
32
+ }
33
+ interface BaseEndpointDefinition<TActionType extends EndpointType> {
34
+ type?: TActionType;
35
+ }
36
+ interface CopilotKitEndpoint extends BaseEndpointDefinition<EndpointType.CopilotKit> {
37
+ url: string;
38
+ onBeforeRequest?: ({ ctx }: {
39
+ ctx: GraphQLContext;
40
+ }) => {
41
+ headers?: Record<string, string> | undefined;
42
+ };
43
+ }
44
+ interface LangGraphPlatformAgent {
45
+ name: string;
46
+ description: string;
47
+ assistantId?: string;
48
+ }
49
+ interface LangGraphPlatformEndpoint extends BaseEndpointDefinition<EndpointType.LangGraphPlatform> {
50
+ deploymentUrl: string;
51
+ langsmithApiKey?: string | null;
52
+ agents: LangGraphPlatformAgent[];
53
+ }
54
+
55
+ declare class Agent {
56
+ id: string;
57
+ name: string;
58
+ description?: string;
59
+ }
60
+
61
+ declare class LoadAgentStateResponse {
62
+ threadId: string;
63
+ threadExists: boolean;
64
+ state: string;
65
+ messages: string;
66
+ }
67
+
68
+ interface LLMRequestData {
69
+ threadId?: string;
70
+ runId?: string;
71
+ model?: string;
72
+ messages: any[];
73
+ actions?: any[];
74
+ forwardedParameters?: any;
75
+ timestamp: number;
76
+ provider?: string;
77
+ [key: string]: any;
78
+ }
79
+ interface LLMResponseData {
80
+ threadId: string;
81
+ runId?: string;
82
+ model?: string;
83
+ output: any;
84
+ latency: number;
85
+ timestamp: number;
86
+ provider?: string;
87
+ isProgressiveChunk?: boolean;
88
+ isFinalResponse?: boolean;
89
+ [key: string]: any;
90
+ }
91
+ interface LLMErrorData {
92
+ threadId?: string;
93
+ runId?: string;
94
+ model?: string;
95
+ error: Error | string;
96
+ timestamp: number;
97
+ provider?: string;
98
+ [key: string]: any;
99
+ }
100
+ interface CopilotObservabilityHooks {
101
+ handleRequest: (data: LLMRequestData) => void | Promise<void>;
102
+ handleResponse: (data: LLMResponseData) => void | Promise<void>;
103
+ handleError: (data: LLMErrorData) => void | Promise<void>;
104
+ }
105
+ /**
106
+ * Configuration for CopilotKit logging functionality.
107
+ *
108
+ * @remarks
109
+ * Custom logging handlers require a valid CopilotKit public API key.
110
+ * Sign up at https://docs.copilotkit.ai/quickstart#get-a-copilot-cloud-public-api-key to get your key.
111
+ */
112
+ interface CopilotObservabilityConfig {
113
+ /**
114
+ * Enable or disable logging functionality.
115
+ *
116
+ * @default false
117
+ */
118
+ enabled: boolean;
119
+ /**
120
+ * Controls whether logs are streamed progressively or buffered.
121
+ * - When true: Each token and update is logged as it's generated (real-time)
122
+ * - When false: Complete responses are logged after completion (batched)
123
+ *
124
+ * @default true
125
+ */
126
+ progressive: boolean;
127
+ /**
128
+ * Custom observability hooks for request, response, and error events.
129
+ *
130
+ * @remarks
131
+ * Using custom observability hooks requires a valid CopilotKit public API key.
132
+ */
133
+ hooks: CopilotObservabilityHooks;
134
+ }
135
+
136
+ /**
137
+ * Represents a tool provided by an MCP server.
138
+ */
139
+ interface MCPTool {
140
+ description?: string;
141
+ /** Schema defining parameters, mirroring the MCP structure. */
142
+ schema?: {
143
+ parameters?: {
144
+ properties?: Record<string, any>;
145
+ required?: string[];
146
+ jsonSchema?: Record<string, any>;
147
+ };
148
+ };
149
+ /** The function to call to execute the tool on the MCP server. */
150
+ execute(params: any): Promise<any>;
151
+ }
152
+ /**
153
+ * Defines the contract for *any* MCP client implementation the user might provide.
154
+ */
155
+ interface MCPClient {
156
+ /** A method that returns a map of tool names to MCPTool objects available from the connected MCP server. */
157
+ tools(): Promise<Record<string, MCPTool>>;
158
+ /** An optional method for cleanup if the underlying client requires explicit disconnection. */
159
+ close?(): Promise<void>;
160
+ }
161
+ /**
162
+ * Configuration for connecting to an MCP endpoint.
163
+ */
164
+ interface MCPEndpointConfig {
165
+ endpoint: string;
166
+ apiKey?: string;
167
+ }
168
+ /**
169
+ * Extracts CopilotKit-compatible parameters from an MCP tool schema.
170
+ * @param toolOrSchema The schema object from an MCPTool or the full MCPTool object.
171
+ * @returns An array of Parameter objects.
172
+ */
173
+ declare function extractParametersFromSchema(toolOrSchema?: MCPTool | MCPTool["schema"]): Parameter[];
174
+ /**
175
+ * Converts a map of MCPTools into an array of CopilotKit Actions.
176
+ * @param mcpTools A record mapping tool names to MCPTool objects.
177
+ * @param mcpEndpoint The endpoint URL from which these tools were fetched.
178
+ * @returns An array of Action<any> objects.
179
+ */
180
+ declare function convertMCPToolsToActions(mcpTools: Record<string, MCPTool>, mcpEndpoint: string): Action<any>[];
181
+ /**
182
+ * Generate better instructions for using MCP tools
183
+ * This is used to enhance the system prompt with tool documentation
184
+ */
185
+ declare function generateMcpToolInstructions(toolsMap: Record<string, MCPTool>): string;
186
+
187
+ /**
188
+ * <Callout type="info">
189
+ * This is the reference for the `CopilotRuntime` class. For more information and example code snippets, please see [Concept: Copilot Runtime](/concepts/copilot-runtime).
190
+ * </Callout>
191
+ *
192
+ * ## Usage
193
+ *
194
+ * ```tsx
195
+ * import { CopilotRuntime } from "@copilotkit/runtime";
196
+ *
197
+ * const copilotKit = new CopilotRuntime();
198
+ * ```
199
+ */
200
+
201
+ type CreateMCPClientFunction = (config: MCPEndpointConfig) => Promise<MCPClient>;
202
+
203
+ interface CopilotRuntimeRequest {
204
+ serviceAdapter: CopilotServiceAdapter;
205
+ messages: MessageInput[];
206
+ actions: ActionInput[];
207
+ agentSession?: AgentSessionInput;
208
+ agentStates?: AgentStateInput[];
209
+ outputMessagesPromise: Promise<Message[]>;
210
+ threadId?: string;
211
+ runId?: string;
212
+ publicApiKey?: string;
213
+ graphqlContext: GraphQLContext;
214
+ forwardedParameters?: ForwardedParametersInput;
215
+ url?: string;
216
+ extensions?: ExtensionsInput;
217
+ metaEvents?: MetaEventInput[];
218
+ context?: CopilotContextInput[];
219
+ }
220
+ interface CopilotRuntimeResponse {
221
+ threadId: string;
222
+ runId?: string;
223
+ eventSource: RuntimeEventSource;
224
+ serverSideActions: Action<any>[];
225
+ actionInputsWithoutAgents: ActionInput[];
226
+ extensions?: ExtensionsResponse;
227
+ }
228
+ type ActionsConfiguration<T extends Parameter[] | [] = []> = Action<T>[] | ((ctx: {
229
+ properties: any;
230
+ url?: string;
231
+ }) => Action<T>[]);
232
+ interface OnBeforeRequestOptions {
233
+ threadId?: string;
234
+ runId?: string;
235
+ inputMessages: Message[];
236
+ properties: any;
237
+ url?: string;
238
+ }
239
+ type OnBeforeRequestHandler = (options: OnBeforeRequestOptions) => void | Promise<void>;
240
+ interface OnAfterRequestOptions {
241
+ threadId: string;
242
+ runId?: string;
243
+ inputMessages: Message[];
244
+ outputMessages: Message[];
245
+ properties: any;
246
+ url?: string;
247
+ }
248
+ type OnAfterRequestHandler = (options: OnAfterRequestOptions) => void | Promise<void>;
249
+ interface OnStopGenerationOptions {
250
+ threadId: string;
251
+ runId?: string;
252
+ url?: string;
253
+ agentName?: string;
254
+ lastMessage: MessageInput;
255
+ }
256
+ type OnStopGenerationHandler = (options: OnStopGenerationOptions) => void | Promise<void>;
257
+ interface Middleware {
258
+ /**
259
+ * A function that is called before the request is processed.
260
+ */
261
+ onBeforeRequest?: OnBeforeRequestHandler;
262
+ /**
263
+ * A function that is called after the request is processed.
264
+ */
265
+ onAfterRequest?: OnAfterRequestHandler;
266
+ }
267
+ type AgentWithEndpoint = Agent & {
268
+ endpoint: EndpointDefinition;
269
+ };
270
+ interface CopilotRuntimeConstructorParams<T extends Parameter[] | [] = []> {
271
+ /**
272
+ * Middleware to be used by the runtime.
273
+ *
274
+ * ```ts
275
+ * onBeforeRequest: (options: {
276
+ * threadId?: string;
277
+ * runId?: string;
278
+ * inputMessages: Message[];
279
+ * properties: any;
280
+ * }) => void | Promise<void>;
281
+ * ```
282
+ *
283
+ * ```ts
284
+ * onAfterRequest: (options: {
285
+ * threadId?: string;
286
+ * runId?: string;
287
+ * inputMessages: Message[];
288
+ * outputMessages: Message[];
289
+ * properties: any;
290
+ * }) => void | Promise<void>;
291
+ * ```
292
+ */
293
+ middleware?: Middleware;
294
+ actions?: ActionsConfiguration<T>;
295
+ remoteActions?: CopilotKitEndpoint[];
296
+ remoteEndpoints?: EndpointDefinition[];
297
+ langserve?: RemoteChainParameters[];
298
+ agents?: Record<string, AbstractAgent>;
299
+ delegateAgentProcessingToServiceAdapter?: boolean;
300
+ /**
301
+ * Configuration for LLM request/response logging.
302
+ * Requires publicApiKey from CopilotKit component to be set:
303
+ *
304
+ * ```tsx
305
+ * <CopilotKit publicApiKey="ck_pub_..." />
306
+ * ```
307
+ *
308
+ * Example logging config:
309
+ * ```ts
310
+ * logging: {
311
+ * enabled: true, // Enable or disable logging
312
+ * progressive: true, // Set to false for buffered logging
313
+ * logger: {
314
+ * logRequest: (data) => langfuse.trace({ name: "LLM Request", input: data }),
315
+ * logResponse: (data) => langfuse.trace({ name: "LLM Response", output: data }),
316
+ * logError: (errorData) => langfuse.trace({ name: "LLM Error", metadata: errorData }),
317
+ * },
318
+ * }
319
+ * ```
320
+ */
321
+ observability_c?: CopilotObservabilityConfig;
322
+ /**
323
+ * Configuration for connecting to Model Context Protocol (MCP) servers.
324
+ * Allows fetching and using tools defined on external MCP-compliant servers.
325
+ * Requires providing the `createMCPClient` function during instantiation.
326
+ * @experimental
327
+ */
328
+ mcpServers?: MCPEndpointConfig[];
329
+ /**
330
+ * A function that creates an MCP client instance for a given endpoint configuration.
331
+ * This function is responsible for using the appropriate MCP client library
332
+ * (e.g., `@copilotkit/runtime`, `ai`) to establish a connection.
333
+ * Required if `mcpServers` is provided.
334
+ *
335
+ * ```typescript
336
+ * import { experimental_createMCPClient } from "ai"; // Import from vercel ai library
337
+ * // ...
338
+ * const runtime = new CopilotRuntime({
339
+ * mcpServers: [{ endpoint: "..." }],
340
+ * async createMCPClient(config) {
341
+ * return await experimental_createMCPClient({
342
+ * transport: {
343
+ * type: "sse",
344
+ * url: config.endpoint,
345
+ * headers: config.apiKey
346
+ * ? { Authorization: `Bearer ${config.apiKey}` }
347
+ * : undefined,
348
+ * },
349
+ * });
350
+ * }
351
+ * });
352
+ * ```
353
+ */
354
+ createMCPClient?: CreateMCPClientFunction;
355
+ /**
356
+ * Optional error handler for comprehensive debugging and observability.
357
+ *
358
+ * **Requires publicApiKey**: Error handling only works when requests include a valid publicApiKey.
359
+ * This is a premium Copilot Cloud feature.
360
+ *
361
+ * @param errorEvent - Structured error event with rich debugging context
362
+ *
363
+ * @example
364
+ * ```typescript
365
+ * const runtime = new CopilotRuntime({
366
+ * onError: (errorEvent) => {
367
+ * debugDashboard.capture(errorEvent);
368
+ * }
369
+ * });
370
+ * ```
371
+ */
372
+ onError?: CopilotErrorHandler;
373
+ onStopGeneration?: OnStopGenerationHandler;
374
+ }
375
+ declare class CopilotRuntime<const T extends Parameter[] | [] = []> {
376
+ actions: ActionsConfiguration<T>;
377
+ agents: Record<string, AbstractAgent>;
378
+ remoteEndpointDefinitions: EndpointDefinition[];
379
+ private langserve;
380
+ private onBeforeRequest?;
381
+ private onAfterRequest?;
382
+ private onStopGeneration?;
383
+ private delegateAgentProcessingToServiceAdapter;
384
+ private observability?;
385
+ private availableAgents;
386
+ private onError?;
387
+ private hasWarnedAboutError;
388
+ private readonly mcpServersConfig?;
389
+ private mcpActionCache;
390
+ private readonly createMCPClientImpl?;
391
+ constructor(params?: CopilotRuntimeConstructorParams<T>);
392
+ private injectMCPToolInstructions;
393
+ processRuntimeRequest(request: CopilotRuntimeRequest): Promise<CopilotRuntimeResponse>;
394
+ getAllAgents(graphqlContext: GraphQLContext): Promise<(AgentWithEndpoint | Agent)[]>;
395
+ discoverAgentsFromEndpoints(graphqlContext: GraphQLContext): Promise<AgentWithEndpoint[]>;
396
+ discoverAgentsFromAgui(): Agent[];
397
+ loadAgentState(graphqlContext: GraphQLContext, threadId: string, agentName: string): Promise<LoadAgentStateResponse>;
398
+ private processAgentRequest;
399
+ private getServerSideActions;
400
+ private detectProvider;
401
+ private convertStreamingErrorToStructured;
402
+ private error;
403
+ /**
404
+ * Public method to handle GraphQL validation errors
405
+ * This allows the GraphQL resolver to send validation errors through the error system
406
+ */
407
+ errorGraphQLError(error: {
408
+ message: string;
409
+ code: string;
410
+ type: string;
411
+ }, context: {
412
+ operation: string;
413
+ cloudConfigPresent: boolean;
414
+ guardrailsEnabled: boolean;
415
+ }): Promise<void>;
416
+ }
417
+ declare function flattenToolCallsNoDuplicates(toolsByPriority: ActionInput[]): ActionInput[];
418
+ declare function copilotKitEndpoint(config: Omit<CopilotKitEndpoint, "type">): CopilotKitEndpoint;
419
+ declare function langGraphPlatformEndpoint(config: Omit<LangGraphPlatformEndpoint, "type">): LangGraphPlatformEndpoint;
420
+ declare function resolveEndpointType(endpoint: EndpointDefinition): EndpointType;
421
+
422
+ type LogLevel = "debug" | "info" | "warn" | "error";
423
+ type CopilotRuntimeLogger = ReturnType<typeof createLogger>;
424
+ declare function createLogger(options?: {
425
+ level?: LogLevel;
426
+ component?: string;
427
+ }): createPinoLogger__default.Logger<never>;
428
+
429
+ declare const logger: createPinoLogger.default.Logger<never>;
430
+ declare const addCustomHeaderPlugin: {
431
+ onResponse({ response }: {
432
+ response: any;
433
+ }): void;
434
+ };
435
+ type AnyPrimitive = string | boolean | number | null;
436
+ type CopilotRequestContextProperties = Record<string, AnyPrimitive | Record<string, AnyPrimitive>>;
437
+ type GraphQLContext = YogaInitialContext & {
438
+ _copilotkit: CreateCopilotRuntimeServerOptions;
439
+ properties: CopilotRequestContextProperties;
440
+ logger: typeof logger;
441
+ };
442
+ interface CreateCopilotRuntimeServerOptions {
443
+ runtime: CopilotRuntime<any>;
444
+ serviceAdapter: CopilotServiceAdapter;
445
+ endpoint: string;
446
+ baseUrl?: string;
447
+ cloud?: CopilotCloudOptions;
448
+ properties?: CopilotRequestContextProperties;
449
+ logLevel?: LogLevel;
450
+ }
451
+ declare function createContext(initialContext: YogaInitialContext, copilotKitContext: CreateCopilotRuntimeServerOptions, contextLogger: typeof logger, properties?: CopilotRequestContextProperties): Promise<Partial<GraphQLContext>>;
452
+ declare function buildSchema(options?: {
453
+ emitSchemaFile?: string;
454
+ }): graphql.GraphQLSchema;
455
+ type CommonConfig = {
456
+ logging: typeof logger;
457
+ schema: ReturnType<typeof buildSchema>;
458
+ plugins: Parameters<typeof createYoga>[0]["plugins"];
459
+ context: (ctx: YogaInitialContext) => Promise<Partial<GraphQLContext>>;
460
+ maskedErrors: {
461
+ maskError: (error: any, message: string, isDev?: boolean) => any;
462
+ };
463
+ };
464
+ declare function getCommonConfig(options: CreateCopilotRuntimeServerOptions): CommonConfig;
465
+
466
+ export { CopilotRequestContextProperties as C, GraphQLContext as G, LogLevel as L, MCPTool as M, addCustomHeaderPlugin as a, CreateCopilotRuntimeServerOptions as b, createContext as c, buildSchema as d, CommonConfig as e, CopilotRuntimeLogger as f, getCommonConfig as g, createLogger as h, CopilotRuntimeRequest as i, CopilotRuntimeConstructorParams as j, CopilotRuntime as k, flattenToolCallsNoDuplicates as l, copilotKitEndpoint as m, langGraphPlatformEndpoint as n, MCPClient as o, MCPEndpointConfig as p, extractParametersFromSchema as q, resolveEndpointType as r, convertMCPToolsToActions as s, generateMcpToolInstructions as t };
@@ -2,7 +2,7 @@ import * as graphql from 'graphql';
2
2
  import * as pino from 'pino';
3
3
  import { YogaInitialContext, createYoga } from 'graphql-yoga';
4
4
  import { Parameter, Action, CopilotErrorHandler, PartialBy, MaybePromise, NonEmptyRecord } from '@copilotkit/shared';
5
- import { b as CopilotServiceAdapter, A as ActionInput, d as AgentSessionInput, e as AgentStateInput, F as ForwardedParametersInput, E as ExtensionsInput, R as RemoteChainParameters } from './langserve-74a52292.js';
5
+ import { b as CopilotServiceAdapter, A as ActionInput, d as AgentSessionInput, e as AgentStateInput, F as ForwardedParametersInput, E as ExtensionsInput, R as RemoteChainParameters } from './langserve-9fc76ce5.js';
6
6
  import { CopilotRuntime as CopilotRuntime$1, CopilotRuntimeOptions } from '@copilotkitnext/runtime';
7
7
  import { a as MessageInput, M as Message } from './index-adbd78f1.js';
8
8
  import { CopilotCloudOptions } from './lib/cloud/index.js';
@@ -362,6 +362,8 @@ interface CopilotRuntimeConstructorParams_BASE<T extends Parameter[] | [] = []>
362
362
  }
363
363
  interface CopilotRuntimeConstructorParams<T extends Parameter[] | [] = []> extends Omit<CopilotRuntimeConstructorParams_BASE<T>, "agents">, Omit<CopilotRuntimeOptions, "agents" | "transcriptionService"> {
364
364
  /**
365
+ * TODO: un-omit `transcriptionService` above once it's supported
366
+ *
365
367
  * This satisfies...
366
368
  * – the optional constraint in `CopilotRuntimeConstructorParams_BASE`
367
369
  * – the `MaybePromise<NonEmptyRecord<T>>` constraint in `CopilotRuntimeOptionsVNext`