@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
@@ -0,0 +1,414 @@
1
+ import * as graphql from 'graphql';
2
+ import * as pino from 'pino';
3
+ import { YogaInitialContext, createYoga } from 'graphql-yoga';
4
+ import { Parameter, Action, CopilotErrorHandler, PartialBy, MaybePromise, NonEmptyRecord } from '@copilotkit/shared';
5
+ import { R as RemoteChainParameters, b as CopilotServiceAdapter } from './langserve-978d5790.js';
6
+ import { CopilotRuntimeOptions, CopilotRuntime as CopilotRuntime$1 } from '@copilotkitnext/runtime';
7
+ import { a as MessageInput, M as Message } from './index-adbd78f1.js';
8
+ import { CopilotCloudOptions } from './lib/cloud/index.js';
9
+ import { AbstractAgent } from '@ag-ui/client';
10
+
11
+ interface BaseEndpointDefinition<TActionType extends EndpointType> {
12
+ type?: TActionType;
13
+ }
14
+ interface CopilotKitEndpoint extends BaseEndpointDefinition<EndpointType.CopilotKit> {
15
+ url: string;
16
+ onBeforeRequest?: ({ ctx }: {
17
+ ctx: GraphQLContext;
18
+ }) => {
19
+ headers?: Record<string, string> | undefined;
20
+ };
21
+ }
22
+ interface LangGraphPlatformAgent {
23
+ name: string;
24
+ description: string;
25
+ assistantId?: string;
26
+ }
27
+ interface LangGraphPlatformEndpoint extends BaseEndpointDefinition<EndpointType.LangGraphPlatform> {
28
+ deploymentUrl: string;
29
+ langsmithApiKey?: string | null;
30
+ agents: LangGraphPlatformAgent[];
31
+ }
32
+ type EndpointDefinition = CopilotKitEndpoint | LangGraphPlatformEndpoint;
33
+ declare enum EndpointType {
34
+ CopilotKit = "copilotKit",
35
+ LangGraphPlatform = "langgraph-platform"
36
+ }
37
+
38
+ interface LLMRequestData {
39
+ threadId?: string;
40
+ runId?: string;
41
+ model?: string;
42
+ messages: any[];
43
+ actions?: any[];
44
+ forwardedParameters?: any;
45
+ timestamp: number;
46
+ provider?: string;
47
+ [key: string]: any;
48
+ }
49
+ interface LLMResponseData {
50
+ threadId: string;
51
+ runId?: string;
52
+ model?: string;
53
+ output: any;
54
+ latency: number;
55
+ timestamp: number;
56
+ provider?: string;
57
+ isProgressiveChunk?: boolean;
58
+ isFinalResponse?: boolean;
59
+ [key: string]: any;
60
+ }
61
+ interface LLMErrorData {
62
+ threadId?: string;
63
+ runId?: string;
64
+ model?: string;
65
+ error: Error | string;
66
+ timestamp: number;
67
+ provider?: string;
68
+ [key: string]: any;
69
+ }
70
+ interface CopilotObservabilityHooks {
71
+ handleRequest: (data: LLMRequestData) => void | Promise<void>;
72
+ handleResponse: (data: LLMResponseData) => void | Promise<void>;
73
+ handleError: (data: LLMErrorData) => void | Promise<void>;
74
+ }
75
+ /**
76
+ * Configuration for CopilotKit logging functionality.
77
+ *
78
+ * @remarks
79
+ * Custom logging handlers require a valid CopilotKit public API key.
80
+ * Sign up at https://docs.copilotkit.ai/quickstart#get-a-copilot-cloud-public-api-key to get your key.
81
+ */
82
+ interface CopilotObservabilityConfig {
83
+ /**
84
+ * Enable or disable logging functionality.
85
+ *
86
+ * @default false
87
+ */
88
+ enabled: boolean;
89
+ /**
90
+ * Controls whether logs are streamed progressively or buffered.
91
+ * - When true: Each token and update is logged as it's generated (real-time)
92
+ * - When false: Complete responses are logged after completion (batched)
93
+ *
94
+ * @default true
95
+ */
96
+ progressive: boolean;
97
+ /**
98
+ * Custom observability hooks for request, response, and error events.
99
+ *
100
+ * @remarks
101
+ * Using custom observability hooks requires a valid CopilotKit public API key.
102
+ */
103
+ hooks: CopilotObservabilityHooks;
104
+ }
105
+
106
+ /**
107
+ * Represents a tool provided by an MCP server.
108
+ */
109
+ interface MCPTool {
110
+ description?: string;
111
+ /** Schema defining parameters, mirroring the MCP structure. */
112
+ schema?: {
113
+ parameters?: {
114
+ properties?: Record<string, any>;
115
+ required?: string[];
116
+ jsonSchema?: Record<string, any>;
117
+ };
118
+ };
119
+ /** The function to call to execute the tool on the MCP server. */
120
+ execute(params: any): Promise<any>;
121
+ }
122
+ /**
123
+ * Defines the contract for *any* MCP client implementation the user might provide.
124
+ */
125
+ interface MCPClient {
126
+ /** A method that returns a map of tool names to MCPTool objects available from the connected MCP server. */
127
+ tools(): Promise<Record<string, MCPTool>>;
128
+ /** An optional method for cleanup if the underlying client requires explicit disconnection. */
129
+ close?(): Promise<void>;
130
+ }
131
+ /**
132
+ * Configuration for connecting to an MCP endpoint.
133
+ */
134
+ interface MCPEndpointConfig {
135
+ endpoint: string;
136
+ apiKey?: string;
137
+ }
138
+ /**
139
+ * Extracts CopilotKit-compatible parameters from an MCP tool schema.
140
+ * @param toolOrSchema The schema object from an MCPTool or the full MCPTool object.
141
+ * @returns An array of Parameter objects.
142
+ */
143
+ declare function extractParametersFromSchema(toolOrSchema?: MCPTool | MCPTool["schema"]): Parameter[];
144
+ /**
145
+ * Converts a map of MCPTools into an array of CopilotKit Actions.
146
+ * @param mcpTools A record mapping tool names to MCPTool objects.
147
+ * @param mcpEndpoint The endpoint URL from which these tools were fetched.
148
+ * @returns An array of Action<any> objects.
149
+ */
150
+ declare function convertMCPToolsToActions(mcpTools: Record<string, MCPTool>, mcpEndpoint: string): Action<any>[];
151
+ /**
152
+ * Generate better instructions for using MCP tools
153
+ * This is used to enhance the system prompt with tool documentation
154
+ */
155
+ declare function generateMcpToolInstructions(toolsMap: Record<string, MCPTool>): string;
156
+
157
+ /**
158
+ * <Callout type="info">
159
+ * This is the reference for the `CopilotRuntime` class. For more information and example code snippets, please see [Concept: Copilot Runtime](/concepts/copilot-runtime).
160
+ * </Callout>
161
+ *
162
+ * ## Usage
163
+ *
164
+ * ```tsx
165
+ * import { CopilotRuntime } from "@copilotkit/runtime";
166
+ *
167
+ * const copilotKit = new CopilotRuntime();
168
+ * ```
169
+ */
170
+
171
+ type CreateMCPClientFunction = (config: MCPEndpointConfig) => Promise<MCPClient>;
172
+ type ActionsConfiguration<T extends Parameter[] | [] = []> = Action<T>[] | ((ctx: {
173
+ properties: any;
174
+ url?: string;
175
+ }) => Action<T>[]);
176
+ interface OnBeforeRequestOptions {
177
+ threadId?: string;
178
+ runId?: string;
179
+ inputMessages: Message[];
180
+ properties: any;
181
+ url?: string;
182
+ }
183
+ type OnBeforeRequestHandler = (options: OnBeforeRequestOptions) => void | Promise<void>;
184
+ interface OnAfterRequestOptions {
185
+ threadId: string;
186
+ runId?: string;
187
+ inputMessages: Message[];
188
+ outputMessages: Message[];
189
+ properties: any;
190
+ url?: string;
191
+ }
192
+ type OnAfterRequestHandler = (options: OnAfterRequestOptions) => void | Promise<void>;
193
+ interface OnStopGenerationOptions {
194
+ threadId: string;
195
+ runId?: string;
196
+ url?: string;
197
+ agentName?: string;
198
+ lastMessage: MessageInput;
199
+ }
200
+ type OnStopGenerationHandler = (options: OnStopGenerationOptions) => void | Promise<void>;
201
+ interface Middleware {
202
+ /**
203
+ * A function that is called before the request is processed.
204
+ */
205
+ /**
206
+ * @deprecated This middleware hook is deprecated and will be removed in a future version.
207
+ * Use updated middleware integration methods in CopilotRuntimeVNext instead.
208
+ */
209
+ onBeforeRequest?: OnBeforeRequestHandler;
210
+ /**
211
+ * A function that is called after the request is processed.
212
+ */
213
+ /**
214
+ * @deprecated This middleware hook is deprecated and will be removed in a future version.
215
+ * Use updated middleware integration methods in CopilotRuntimeVNext instead.
216
+ */
217
+ onAfterRequest?: OnAfterRequestHandler;
218
+ }
219
+ interface CopilotRuntimeConstructorParams_BASE<T extends Parameter[] | [] = []> {
220
+ /**
221
+ * Middleware to be used by the runtime.
222
+ *
223
+ * ```ts
224
+ * onBeforeRequest: (options: {
225
+ * threadId?: string;
226
+ * runId?: string;
227
+ * inputMessages: Message[];
228
+ * properties: any;
229
+ * }) => void | Promise<void>;
230
+ * ```
231
+ *
232
+ * ```ts
233
+ * onAfterRequest: (options: {
234
+ * threadId?: string;
235
+ * runId?: string;
236
+ * inputMessages: Message[];
237
+ * outputMessages: Message[];
238
+ * properties: any;
239
+ * }) => void | Promise<void>;
240
+ * ```
241
+ */
242
+ /**
243
+ * @deprecated This middleware hook is deprecated and will be removed in a future version.
244
+ * Use updated middleware integration methods in CopilotRuntimeVNext instead.
245
+ */
246
+ middleware?: Middleware;
247
+ actions?: ActionsConfiguration<T>;
248
+ remoteActions?: CopilotKitEndpoint[];
249
+ remoteEndpoints?: EndpointDefinition[];
250
+ langserve?: RemoteChainParameters[];
251
+ agents?: Record<string, AbstractAgent>;
252
+ delegateAgentProcessingToServiceAdapter?: boolean;
253
+ /**
254
+ * Configuration for LLM request/response logging.
255
+ * Requires publicApiKey from CopilotKit component to be set:
256
+ *
257
+ * ```tsx
258
+ * <CopilotKit publicApiKey="ck_pub_..." />
259
+ * ```
260
+ *
261
+ * Example logging config:
262
+ * ```ts
263
+ * logging: {
264
+ * enabled: true, // Enable or disable logging
265
+ * progressive: true, // Set to false for buffered logging
266
+ * logger: {
267
+ * logRequest: (data) => langfuse.trace({ name: "LLM Request", input: data }),
268
+ * logResponse: (data) => langfuse.trace({ name: "LLM Response", output: data }),
269
+ * logError: (errorData) => langfuse.trace({ name: "LLM Error", metadata: errorData }),
270
+ * },
271
+ * }
272
+ * ```
273
+ */
274
+ observability_c?: CopilotObservabilityConfig;
275
+ /**
276
+ * Configuration for connecting to Model Context Protocol (MCP) servers.
277
+ * Allows fetching and using tools defined on external MCP-compliant servers.
278
+ * Requires providing the `createMCPClient` function during instantiation.
279
+ * @experimental
280
+ */
281
+ mcpServers?: MCPEndpointConfig[];
282
+ /**
283
+ * A function that creates an MCP client instance for a given endpoint configuration.
284
+ * This function is responsible for using the appropriate MCP client library
285
+ * (e.g., `@copilotkit/runtime`, `ai`) to establish a connection.
286
+ * Required if `mcpServers` is provided.
287
+ *
288
+ * ```typescript
289
+ * import { experimental_createMCPClient } from "ai"; // Import from vercel ai library
290
+ * // ...
291
+ * const runtime = new CopilotRuntime({
292
+ * mcpServers: [{ endpoint: "..." }],
293
+ * async createMCPClient(config) {
294
+ * return await experimental_createMCPClient({
295
+ * transport: {
296
+ * type: "sse",
297
+ * url: config.endpoint,
298
+ * headers: config.apiKey
299
+ * ? { Authorization: `Bearer ${config.apiKey}` }
300
+ * : undefined,
301
+ * },
302
+ * });
303
+ * }
304
+ * });
305
+ * ```
306
+ */
307
+ createMCPClient?: CreateMCPClientFunction;
308
+ /**
309
+ * Optional error handler for comprehensive debugging and observability.
310
+ *
311
+ * **Requires publicApiKey**: Error handling only works when requests include a valid publicApiKey.
312
+ * This is a premium Copilot Cloud feature.
313
+ *
314
+ * @param errorEvent - Structured error event with rich debugging context
315
+ *
316
+ * @example
317
+ * ```typescript
318
+ * const runtime = new CopilotRuntime({
319
+ * onError: (errorEvent) => {
320
+ * debugDashboard.capture(errorEvent);
321
+ * }
322
+ * });
323
+ * ```
324
+ */
325
+ onError?: CopilotErrorHandler;
326
+ onStopGeneration?: OnStopGenerationHandler;
327
+ }
328
+ interface CopilotRuntimeConstructorParams<T extends Parameter[] | [] = []> extends Omit<CopilotRuntimeConstructorParams_BASE<T>, "agents">, Omit<CopilotRuntimeOptions, "agents" | "transcriptionService"> {
329
+ /**
330
+ * TODO: un-omit `transcriptionService` above once it's supported
331
+ *
332
+ * This satisfies...
333
+ * – the optional constraint in `CopilotRuntimeConstructorParams_BASE`
334
+ * – the `MaybePromise<NonEmptyRecord<T>>` constraint in `CopilotRuntimeOptionsVNext`
335
+ * – the `Record<string, AbstractAgent>` constraint in `both
336
+ */
337
+ agents?: MaybePromise<NonEmptyRecord<Record<string, AbstractAgent>>>;
338
+ }
339
+ /**
340
+ * Central runtime object passed to all request handlers.
341
+ */
342
+ declare class CopilotRuntime {
343
+ params?: CopilotRuntimeConstructorParams;
344
+ private observability?;
345
+ private mcpToolsCache;
346
+ private runtimeArgs;
347
+ private _instance;
348
+ constructor(params?: CopilotRuntimeConstructorParams & PartialBy<CopilotRuntimeOptions, "agents">);
349
+ get instance(): CopilotRuntime$1;
350
+ private assignEndpointsToAgents;
351
+ handleServiceAdapter(serviceAdapter: CopilotServiceAdapter): void;
352
+ private getToolsFromActions;
353
+ private assignToolsToAgents;
354
+ private createOnBeforeRequestHandler;
355
+ private createOnAfterRequestHandler;
356
+ /**
357
+ * Log LLM request if observability is enabled
358
+ */
359
+ private logObservabilityBeforeRequest;
360
+ /**
361
+ * Log final LLM response after request completes
362
+ */
363
+ private logObservabilityAfterRequest;
364
+ private getToolsFromMCP;
365
+ }
366
+ declare function copilotKitEndpoint(config: Omit<CopilotKitEndpoint, "type">): CopilotKitEndpoint;
367
+ declare function langGraphPlatformEndpoint(config: Omit<LangGraphPlatformEndpoint, "type">): LangGraphPlatformEndpoint;
368
+ declare function resolveEndpointType(endpoint: EndpointDefinition): EndpointType;
369
+
370
+ type LogLevel = "debug" | "info" | "warn" | "error";
371
+ type CopilotRuntimeLogger = ReturnType<typeof createLogger>;
372
+ declare function createLogger(options?: {
373
+ level?: LogLevel;
374
+ component?: string;
375
+ }): pino.Logger<never>;
376
+
377
+ declare const logger: pino.Logger<never>;
378
+ declare const addCustomHeaderPlugin: {
379
+ onResponse({ response }: {
380
+ response: any;
381
+ }): void;
382
+ };
383
+ type AnyPrimitive = string | boolean | number | null;
384
+ type CopilotRequestContextProperties = Record<string, AnyPrimitive | Record<string, AnyPrimitive>>;
385
+ type GraphQLContext = YogaInitialContext & {
386
+ _copilotkit: CreateCopilotRuntimeServerOptions;
387
+ properties: CopilotRequestContextProperties;
388
+ logger: typeof logger;
389
+ };
390
+ interface CreateCopilotRuntimeServerOptions {
391
+ runtime: CopilotRuntime;
392
+ serviceAdapter: CopilotServiceAdapter;
393
+ endpoint: string;
394
+ baseUrl?: string;
395
+ cloud?: CopilotCloudOptions;
396
+ properties?: CopilotRequestContextProperties;
397
+ logLevel?: LogLevel;
398
+ }
399
+ declare function createContext(initialContext: YogaInitialContext, copilotKitContext: CreateCopilotRuntimeServerOptions, contextLogger: typeof logger, properties?: CopilotRequestContextProperties): Promise<Partial<GraphQLContext>>;
400
+ declare function buildSchema(options?: {
401
+ emitSchemaFile?: string;
402
+ }): graphql.GraphQLSchema;
403
+ type CommonConfig = {
404
+ logging: typeof logger;
405
+ schema: ReturnType<typeof buildSchema>;
406
+ plugins: Parameters<typeof createYoga>[0]["plugins"];
407
+ context: (ctx: YogaInitialContext) => Promise<Partial<GraphQLContext>>;
408
+ maskedErrors: {
409
+ maskError: (error: any, message: string, isDev?: boolean) => any;
410
+ };
411
+ };
412
+ declare function getCommonConfig(options: CreateCopilotRuntimeServerOptions): CommonConfig;
413
+
414
+ 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, CopilotRuntimeConstructorParams_BASE as i, CopilotRuntime as j, copilotKitEndpoint as k, langGraphPlatformEndpoint as l, MCPClient as m, MCPEndpointConfig as n, extractParametersFromSchema as o, convertMCPToolsToActions as p, generateMcpToolInstructions as q, resolveEndpointType as r };