@copilotkit/runtime 1.7.0-next.1 → 1.7.1-next.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 (40) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/{chunk-RQS3BGAT.mjs → chunk-5PFBYGDX.mjs} +2 -2
  3. package/dist/{chunk-QTRO3GPV.mjs → chunk-ANTSN7W3.mjs} +136 -20
  4. package/dist/chunk-ANTSN7W3.mjs.map +1 -0
  5. package/dist/{chunk-QZ6X33MR.mjs → chunk-LOGYVH7X.mjs} +2 -2
  6. package/dist/{chunk-D6YNY2XB.mjs → chunk-SJPSYQ4P.mjs} +2 -2
  7. package/dist/{copilot-runtime-5103c7e7.d.ts → copilot-runtime-eb953402.d.ts} +78 -46
  8. package/dist/index.d.ts +1 -1
  9. package/dist/index.js +135 -19
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +4 -4
  12. package/dist/lib/index.d.ts +1 -1
  13. package/dist/lib/index.js +135 -19
  14. package/dist/lib/index.js.map +1 -1
  15. package/dist/lib/index.mjs +4 -4
  16. package/dist/lib/integrations/index.d.ts +2 -2
  17. package/dist/lib/integrations/index.js +2 -2
  18. package/dist/lib/integrations/index.js.map +1 -1
  19. package/dist/lib/integrations/index.mjs +4 -4
  20. package/dist/lib/integrations/nest/index.d.ts +1 -1
  21. package/dist/lib/integrations/nest/index.js +2 -2
  22. package/dist/lib/integrations/nest/index.js.map +1 -1
  23. package/dist/lib/integrations/nest/index.mjs +2 -2
  24. package/dist/lib/integrations/node-express/index.d.ts +1 -1
  25. package/dist/lib/integrations/node-express/index.js +2 -2
  26. package/dist/lib/integrations/node-express/index.js.map +1 -1
  27. package/dist/lib/integrations/node-express/index.mjs +2 -2
  28. package/dist/lib/integrations/node-http/index.d.ts +1 -1
  29. package/dist/lib/integrations/node-http/index.js +2 -2
  30. package/dist/lib/integrations/node-http/index.js.map +1 -1
  31. package/dist/lib/integrations/node-http/index.mjs +1 -1
  32. package/package.json +2 -2
  33. package/src/graphql/resolvers/copilot.resolver.ts +1 -1
  34. package/src/lib/logger.ts +0 -48
  35. package/src/lib/observability.ts +73 -0
  36. package/src/lib/runtime/copilot-runtime.ts +182 -22
  37. package/dist/chunk-QTRO3GPV.mjs.map +0 -1
  38. /package/dist/{chunk-RQS3BGAT.mjs.map → chunk-5PFBYGDX.mjs.map} +0 -0
  39. /package/dist/{chunk-QZ6X33MR.mjs.map → chunk-LOGYVH7X.mjs.map} +0 -0
  40. /package/dist/{chunk-D6YNY2XB.mjs.map → chunk-SJPSYQ4P.mjs.map} +0 -0
@@ -2,7 +2,7 @@ import {
2
2
  copilotRuntimeNodeHttpEndpoint,
3
3
  getRuntimeInstanceTelemetryInfo,
4
4
  telemetry_client_default
5
- } from "./chunk-QTRO3GPV.mjs";
5
+ } from "./chunk-ANTSN7W3.mjs";
6
6
  import {
7
7
  __name
8
8
  } from "./chunk-FHD4JECV.mjs";
@@ -22,4 +22,4 @@ __name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
22
22
  export {
23
23
  copilotRuntimeNestEndpoint
24
24
  };
25
- //# sourceMappingURL=chunk-QZ6X33MR.mjs.map
25
+ //# sourceMappingURL=chunk-LOGYVH7X.mjs.map
@@ -2,7 +2,7 @@ import {
2
2
  getCommonConfig,
3
3
  getRuntimeInstanceTelemetryInfo,
4
4
  telemetry_client_default
5
- } from "./chunk-QTRO3GPV.mjs";
5
+ } from "./chunk-ANTSN7W3.mjs";
6
6
  import {
7
7
  __name
8
8
  } from "./chunk-FHD4JECV.mjs";
@@ -77,4 +77,4 @@ export {
77
77
  config,
78
78
  copilotRuntimeNextJSPagesRouterEndpoint
79
79
  };
80
- //# sourceMappingURL=chunk-D6YNY2XB.mjs.map
80
+ //# sourceMappingURL=chunk-SJPSYQ4P.mjs.map
@@ -12,48 +12,6 @@ declare function createLogger(options?: {
12
12
  level?: LogLevel;
13
13
  component?: string;
14
14
  }): pino.Logger<never>;
15
- interface LogLLMRequestData {
16
- threadId?: string;
17
- runId?: string;
18
- model?: string;
19
- messages: any[];
20
- actions?: any[];
21
- forwardedParameters?: any;
22
- timestamp: number;
23
- provider?: string;
24
- [key: string]: any;
25
- }
26
- interface LogLLMResponseData {
27
- threadId: string;
28
- runId?: string;
29
- model?: string;
30
- output: any;
31
- latency: number;
32
- timestamp: number;
33
- provider?: string;
34
- isProgressiveChunk?: boolean;
35
- isFinalResponse?: boolean;
36
- [key: string]: any;
37
- }
38
- interface LogLLMErrorData {
39
- threadId?: string;
40
- runId?: string;
41
- model?: string;
42
- error: Error | string;
43
- timestamp: number;
44
- provider?: string;
45
- [key: string]: any;
46
- }
47
- interface CopilotLoggerHooks {
48
- logRequest: (data: LogLLMRequestData) => void | Promise<void>;
49
- logResponse: (data: LogLLMResponseData) => void | Promise<void>;
50
- logError: (data: LogLLMErrorData) => void | Promise<void>;
51
- }
52
- interface CopilotLoggingConfig {
53
- enabled: boolean;
54
- progressive: boolean;
55
- logger: CopilotLoggerHooks;
56
- }
57
15
 
58
16
  declare const logger: pino.Logger<never>;
59
17
  declare const addCustomHeaderPlugin: {
@@ -141,6 +99,74 @@ declare class LoadAgentStateResponse {
141
99
  messages: string;
142
100
  }
143
101
 
102
+ interface LLMRequestData {
103
+ threadId?: string;
104
+ runId?: string;
105
+ model?: string;
106
+ messages: any[];
107
+ actions?: any[];
108
+ forwardedParameters?: any;
109
+ timestamp: number;
110
+ provider?: string;
111
+ [key: string]: any;
112
+ }
113
+ interface LLMResponseData {
114
+ threadId: string;
115
+ runId?: string;
116
+ model?: string;
117
+ output: any;
118
+ latency: number;
119
+ timestamp: number;
120
+ provider?: string;
121
+ isProgressiveChunk?: boolean;
122
+ isFinalResponse?: boolean;
123
+ [key: string]: any;
124
+ }
125
+ interface LLMErrorData {
126
+ threadId?: string;
127
+ runId?: string;
128
+ model?: string;
129
+ error: Error | string;
130
+ timestamp: number;
131
+ provider?: string;
132
+ [key: string]: any;
133
+ }
134
+ interface CopilotObservabilityHooks {
135
+ handleRequest: (data: LLMRequestData) => void | Promise<void>;
136
+ handleResponse: (data: LLMResponseData) => void | Promise<void>;
137
+ handleError: (data: LLMErrorData) => void | Promise<void>;
138
+ }
139
+ /**
140
+ * Configuration for CopilotKit logging functionality.
141
+ *
142
+ * @remarks
143
+ * Custom logging handlers require a valid CopilotKit public API key.
144
+ * Sign up at https://docs.copilotkit.ai/quickstart#get-a-copilot-cloud-public-api-key to get your key.
145
+ */
146
+ interface CopilotObservabilityConfig {
147
+ /**
148
+ * Enable or disable logging functionality.
149
+ *
150
+ * @default false
151
+ */
152
+ enabled: boolean;
153
+ /**
154
+ * Controls whether logs are streamed progressively or buffered.
155
+ * - When true: Each token and update is logged as it's generated (real-time)
156
+ * - When false: Complete responses are logged after completion (batched)
157
+ *
158
+ * @default true
159
+ */
160
+ progressive: boolean;
161
+ /**
162
+ * Custom observability hooks for request, response, and error events.
163
+ *
164
+ * @remarks
165
+ * Using custom observability hooks requires a valid CopilotKit public API key.
166
+ */
167
+ hooks: CopilotObservabilityHooks;
168
+ }
169
+
144
170
  /**
145
171
  * <Callout type="info">
146
172
  * This is the reference for the `CopilotRuntime` class. For more information and example code snippets, please see [Concept: Copilot Runtime](/concepts/copilot-runtime).
@@ -243,8 +269,14 @@ interface CopilotRuntimeConstructorParams<T extends Parameter[] | [] = []> {
243
269
  langserve?: RemoteChainParameters[];
244
270
  delegateAgentProcessingToServiceAdapter?: boolean;
245
271
  /**
246
- * Configuration for LLM request/response logging
272
+ * Configuration for LLM request/response logging.
273
+ * Requires publicApiKey from CopilotKit component to be set:
274
+ *
275
+ * ```tsx
276
+ * <CopilotKit publicApiKey="ck_pub_..." />
277
+ * ```
247
278
  *
279
+ * Example logging config:
248
280
  * ```ts
249
281
  * logging: {
250
282
  * enabled: true, // Enable or disable logging
@@ -257,7 +289,7 @@ interface CopilotRuntimeConstructorParams<T extends Parameter[] | [] = []> {
257
289
  * }
258
290
  * ```
259
291
  */
260
- logging?: CopilotLoggingConfig;
292
+ observability_c?: CopilotObservabilityConfig;
261
293
  }
262
294
  declare class CopilotRuntime<const T extends Parameter[] | [] = []> {
263
295
  actions: ActionsConfiguration<T>;
@@ -266,7 +298,7 @@ declare class CopilotRuntime<const T extends Parameter[] | [] = []> {
266
298
  private onBeforeRequest?;
267
299
  private onAfterRequest?;
268
300
  private delegateAgentProcessingToServiceAdapter;
269
- private logging?;
301
+ private observability?;
270
302
  constructor(params?: CopilotRuntimeConstructorParams<T>);
271
303
  processRuntimeRequest(request: CopilotRuntimeRequest): Promise<CopilotRuntimeResponse>;
272
304
  discoverAgentsFromEndpoints(graphqlContext: GraphQLContext): Promise<AgentWithEndpoint[]>;
@@ -280,4 +312,4 @@ declare function copilotKitEndpoint(config: Omit<CopilotKitEndpoint, "type">): C
280
312
  declare function langGraphPlatformEndpoint(config: Omit<LangGraphPlatformEndpoint, "type">): LangGraphPlatformEndpoint;
281
313
  declare function resolveEndpointType(endpoint: EndpointDefinition): EndpointType;
282
314
 
283
- export { CopilotRuntimeConstructorParams as C, GraphQLContext as G, LogLevel as L, CopilotRuntime as a, addCustomHeaderPlugin as b, copilotKitEndpoint as c, CopilotRequestContextProperties as d, CreateCopilotRuntimeServerOptions as e, flattenToolCallsNoDuplicates as f, createContext as g, buildSchema as h, CommonConfig as i, getCommonConfig as j, CopilotRuntimeLogger as k, langGraphPlatformEndpoint as l, createLogger as m, LogLLMRequestData as n, LogLLMResponseData as o, LogLLMErrorData as p, CopilotLoggerHooks as q, resolveEndpointType as r, CopilotLoggingConfig as s };
315
+ export { CopilotRuntimeConstructorParams as C, GraphQLContext as G, LogLevel as L, CopilotRuntime as a, addCustomHeaderPlugin as b, copilotKitEndpoint as c, CopilotRequestContextProperties as d, CreateCopilotRuntimeServerOptions as e, flattenToolCallsNoDuplicates as f, createContext as g, buildSchema as h, CommonConfig as i, getCommonConfig as j, CopilotRuntimeLogger as k, langGraphPlatformEndpoint as l, createLogger as m, resolveEndpointType as r };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { i as CommonConfig, q as CopilotLoggerHooks, s as CopilotLoggingConfig, d as CopilotRequestContextProperties, a as CopilotRuntime, C as CopilotRuntimeConstructorParams, k as CopilotRuntimeLogger, e as CreateCopilotRuntimeServerOptions, G as GraphQLContext, p as LogLLMErrorData, n as LogLLMRequestData, o as LogLLMResponseData, L as LogLevel, b as addCustomHeaderPlugin, h as buildSchema, c as copilotKitEndpoint, g as createContext, m as createLogger, f as flattenToolCallsNoDuplicates, j as getCommonConfig, l as langGraphPlatformEndpoint, r as resolveEndpointType } from './copilot-runtime-5103c7e7.js';
1
+ export { i as CommonConfig, d as CopilotRequestContextProperties, a as CopilotRuntime, C as CopilotRuntimeConstructorParams, k as CopilotRuntimeLogger, e as CreateCopilotRuntimeServerOptions, G as GraphQLContext, L as LogLevel, b as addCustomHeaderPlugin, h as buildSchema, c as copilotKitEndpoint, g as createContext, m as createLogger, f as flattenToolCallsNoDuplicates, j as getCommonConfig, l as langGraphPlatformEndpoint, r as resolveEndpointType } from './copilot-runtime-eb953402.js';
2
2
  export { G as GoogleGenerativeAIAdapter, f as GroqAdapter, e as GroqAdapterParams, L as LangChainAdapter, a as OpenAIAdapter, O as OpenAIAdapterParams, c as OpenAIAssistantAdapter, b as OpenAIAssistantAdapterParams, d as UnifyAdapter, U as UnifyAdapterParams } from './groq-adapter-fb9aa3ab.js';
3
3
  export { CopilotRuntimeServerInstance, config, copilotRuntimeNextJSAppRouterEndpoint, copilotRuntimeNextJSPagesRouterEndpoint } from './lib/integrations/index.js';
4
4
  export { copilotRuntimeNodeHttpEndpoint } from './lib/integrations/node-http/index.js';
package/dist/index.js CHANGED
@@ -44,7 +44,7 @@ var require_package = __commonJS({
44
44
  publishConfig: {
45
45
  access: "public"
46
46
  },
47
- version: "1.7.0-next.1",
47
+ version: "1.7.1-next.0",
48
48
  sideEffects: false,
49
49
  main: "./dist/index.js",
50
50
  module: "./dist/index.mjs",
@@ -4009,7 +4009,7 @@ var CopilotRuntime = class {
4009
4009
  onBeforeRequest;
4010
4010
  onAfterRequest;
4011
4011
  delegateAgentProcessingToServiceAdapter;
4012
- logging;
4012
+ observability;
4013
4013
  constructor(params) {
4014
4014
  var _a, _b;
4015
4015
  if ((params == null ? void 0 : params.actions) && (params == null ? void 0 : params.remoteEndpoints)) {
@@ -4026,11 +4026,11 @@ var CopilotRuntime = class {
4026
4026
  this.onBeforeRequest = (_a = params == null ? void 0 : params.middleware) == null ? void 0 : _a.onBeforeRequest;
4027
4027
  this.onAfterRequest = (_b = params == null ? void 0 : params.middleware) == null ? void 0 : _b.onAfterRequest;
4028
4028
  this.delegateAgentProcessingToServiceAdapter = (params == null ? void 0 : params.delegateAgentProcessingToServiceAdapter) || false;
4029
- this.logging = params == null ? void 0 : params.logging;
4029
+ this.observability = params == null ? void 0 : params.observability_c;
4030
4030
  }
4031
4031
  async processRuntimeRequest(request) {
4032
4032
  var _a, _b, _c, _d, _e;
4033
- const { serviceAdapter, messages: rawMessages, actions: clientSideActionsInput, threadId, runId, outputMessagesPromise, graphqlContext, forwardedParameters, url, extensions, agentSession, agentStates } = request;
4033
+ const { serviceAdapter, messages: rawMessages, actions: clientSideActionsInput, threadId, runId, outputMessagesPromise, graphqlContext, forwardedParameters, url, extensions, agentSession, agentStates, publicApiKey } = request;
4034
4034
  const eventSource = new RuntimeEventSource();
4035
4035
  const requestStartTime = Date.now();
4036
4036
  const streamedChunks = [];
@@ -4048,7 +4048,7 @@ please use an LLM adapter instead.`
4048
4048
  const messages = rawMessages.filter((message) => !message.agentStateMessage);
4049
4049
  const inputMessages = convertGqlInputToMessages(messages);
4050
4050
  const serverSideActions = await this.getServerSideActions(request);
4051
- if ((_a = this.logging) == null ? void 0 : _a.enabled) {
4051
+ if (((_a = this.observability) == null ? void 0 : _a.enabled) && publicApiKey) {
4052
4052
  try {
4053
4053
  const requestData = {
4054
4054
  threadId,
@@ -4060,7 +4060,7 @@ please use an LLM adapter instead.`
4060
4060
  timestamp: requestStartTime,
4061
4061
  provider: this.detectProvider(serviceAdapter)
4062
4062
  };
4063
- await this.logging.logger.logRequest(requestData);
4063
+ await this.observability.hooks.handleRequest(requestData);
4064
4064
  } catch (error) {
4065
4065
  console.error("Error logging LLM request:", error);
4066
4066
  }
@@ -4108,16 +4108,15 @@ please use an LLM adapter instead.`
4108
4108
  });
4109
4109
  }).catch((_error) => {
4110
4110
  });
4111
- if ((_c = this.logging) == null ? void 0 : _c.enabled) {
4111
+ if (((_c = this.observability) == null ? void 0 : _c.enabled) && publicApiKey) {
4112
4112
  try {
4113
4113
  outputMessagesPromise.then((outputMessages) => {
4114
- var _a2;
4115
4114
  const responseData = {
4116
4115
  threadId: result.threadId,
4117
4116
  runId: result.runId,
4118
4117
  model: forwardedParameters == null ? void 0 : forwardedParameters.model,
4119
4118
  // Use collected chunks for progressive mode or outputMessages for regular mode
4120
- output: this.logging.progressive ? streamedChunks : outputMessages,
4119
+ output: this.observability.progressive ? streamedChunks : outputMessages,
4121
4120
  latency: Date.now() - requestStartTime,
4122
4121
  timestamp: Date.now(),
4123
4122
  provider: this.detectProvider(serviceAdapter),
@@ -4125,7 +4124,7 @@ please use an LLM adapter instead.`
4125
4124
  isFinalResponse: true
4126
4125
  };
4127
4126
  try {
4128
- (_a2 = this.logging) == null ? void 0 : _a2.logger.logResponse(responseData);
4127
+ this.observability.hooks.handleResponse(responseData);
4129
4128
  } catch (logError) {
4130
4129
  console.error("Error logging LLM response:", logError);
4131
4130
  }
@@ -4136,7 +4135,7 @@ please use an LLM adapter instead.`
4136
4135
  console.error("Error setting up logging for LLM response:", error);
4137
4136
  }
4138
4137
  }
4139
- if (((_d = this.logging) == null ? void 0 : _d.enabled) && this.logging.progressive) {
4138
+ if (((_d = this.observability) == null ? void 0 : _d.enabled) && this.observability.progressive && publicApiKey) {
4140
4139
  const originalStream = eventSource.stream.bind(eventSource);
4141
4140
  eventSource.stream = async (callback) => {
4142
4141
  await originalStream(async (eventStream$) => {
@@ -4156,8 +4155,7 @@ please use an LLM adapter instead.`
4156
4155
  isProgressiveChunk: true
4157
4156
  };
4158
4157
  Promise.resolve().then(() => {
4159
- var _a2;
4160
- (_a2 = this.logging) == null ? void 0 : _a2.logger.logResponse(progressiveData);
4158
+ this.observability.hooks.handleResponse(progressiveData);
4161
4159
  }).catch((error) => {
4162
4160
  console.error("Error in progressive logging:", error);
4163
4161
  });
@@ -4183,7 +4181,7 @@ please use an LLM adapter instead.`
4183
4181
  extensions: result.extensions
4184
4182
  };
4185
4183
  } catch (error) {
4186
- if ((_e = this.logging) == null ? void 0 : _e.enabled) {
4184
+ if (((_e = this.observability) == null ? void 0 : _e.enabled) && publicApiKey) {
4187
4185
  try {
4188
4186
  const errorData = {
4189
4187
  threadId,
@@ -4194,7 +4192,7 @@ please use an LLM adapter instead.`
4194
4192
  latency: Date.now() - requestStartTime,
4195
4193
  provider: this.detectProvider(serviceAdapter)
4196
4194
  };
4197
- await this.logging.logger.logError(errorData);
4195
+ await this.observability.hooks.handleError(errorData);
4198
4196
  } catch (logError) {
4199
4197
  console.error("Error logging LLM error:", logError);
4200
4198
  }
@@ -4362,9 +4360,11 @@ please use an LLM adapter instead.`
4362
4360
  }
4363
4361
  }
4364
4362
  async processAgentRequest(request) {
4365
- var _a;
4366
- const { messages: rawMessages, outputMessagesPromise, graphqlContext, agentSession, threadId: threadIdFromRequest, metaEvents } = request;
4363
+ var _a, _b, _c, _d, _e;
4364
+ const { messages: rawMessages, outputMessagesPromise, graphqlContext, agentSession, threadId: threadIdFromRequest, metaEvents, publicApiKey, forwardedParameters } = request;
4367
4365
  const { agentName, nodeName } = agentSession;
4366
+ const requestStartTime = Date.now();
4367
+ const streamedChunks = [];
4368
4368
  const threadId = threadIdFromRequest ?? agentSession.threadId;
4369
4369
  const serverSideActions = await this.getServerSideActions(request);
4370
4370
  const messages = convertGqlInputToMessages(rawMessages);
@@ -4387,7 +4387,26 @@ please use an LLM adapter instead.`
4387
4387
  ...availableActionsForCurrentAgent,
4388
4388
  ...request.actions
4389
4389
  ]);
4390
- await ((_a = this.onBeforeRequest) == null ? void 0 : _a.call(this, {
4390
+ if (((_a = this.observability) == null ? void 0 : _a.enabled) && publicApiKey) {
4391
+ try {
4392
+ const requestData = {
4393
+ threadId,
4394
+ runId: void 0,
4395
+ model: forwardedParameters == null ? void 0 : forwardedParameters.model,
4396
+ messages,
4397
+ actions: allAvailableActions,
4398
+ forwardedParameters,
4399
+ timestamp: requestStartTime,
4400
+ provider: "agent",
4401
+ agentName,
4402
+ nodeName
4403
+ };
4404
+ await this.observability.hooks.handleRequest(requestData);
4405
+ } catch (error) {
4406
+ console.error("Error logging agent request:", error);
4407
+ }
4408
+ }
4409
+ await ((_b = this.onBeforeRequest) == null ? void 0 : _b.call(this, {
4391
4410
  threadId,
4392
4411
  runId: void 0,
4393
4412
  inputMessages: messages,
@@ -4402,17 +4421,96 @@ please use an LLM adapter instead.`
4402
4421
  metaEvents,
4403
4422
  actionInputsWithoutAgents: allAvailableActions
4404
4423
  });
4424
+ if (((_c = this.observability) == null ? void 0 : _c.enabled) && this.observability.progressive && publicApiKey) {
4425
+ const originalStream = eventSource.stream.bind(eventSource);
4426
+ eventSource.stream = async (callback) => {
4427
+ await originalStream(async (eventStream$) => {
4428
+ eventStream$.subscribe({
4429
+ next: (event) => {
4430
+ if (event.type === RuntimeEventTypes.TextMessageContent) {
4431
+ streamedChunks.push(event.content);
4432
+ try {
4433
+ const progressiveData = {
4434
+ threadId: threadId || "",
4435
+ runId: void 0,
4436
+ model: forwardedParameters == null ? void 0 : forwardedParameters.model,
4437
+ output: event.content,
4438
+ latency: Date.now() - requestStartTime,
4439
+ timestamp: Date.now(),
4440
+ provider: "agent",
4441
+ isProgressiveChunk: true,
4442
+ agentName,
4443
+ nodeName
4444
+ };
4445
+ Promise.resolve().then(() => {
4446
+ this.observability.hooks.handleResponse(progressiveData);
4447
+ }).catch((error) => {
4448
+ console.error("Error in progressive agent logging:", error);
4449
+ });
4450
+ } catch (error) {
4451
+ console.error("Error preparing progressive agent log data:", error);
4452
+ }
4453
+ }
4454
+ }
4455
+ });
4456
+ await callback(eventStream$);
4457
+ });
4458
+ };
4459
+ }
4405
4460
  eventSource.stream(async (eventStream$) => {
4406
4461
  (0, import_rxjs3.from)(stream).subscribe({
4407
4462
  next: (event) => eventStream$.next(event),
4408
4463
  error: (err) => {
4464
+ var _a2;
4409
4465
  console.error("Error in stream", err);
4466
+ if (((_a2 = this.observability) == null ? void 0 : _a2.enabled) && publicApiKey) {
4467
+ try {
4468
+ const errorData = {
4469
+ threadId,
4470
+ runId: void 0,
4471
+ model: forwardedParameters == null ? void 0 : forwardedParameters.model,
4472
+ error: err instanceof Error ? err : String(err),
4473
+ timestamp: Date.now(),
4474
+ latency: Date.now() - requestStartTime,
4475
+ provider: "agent",
4476
+ agentName,
4477
+ nodeName
4478
+ };
4479
+ this.observability.hooks.handleError(errorData);
4480
+ } catch (logError) {
4481
+ console.error("Error logging agent error:", logError);
4482
+ }
4483
+ }
4410
4484
  eventStream$.error(err);
4411
4485
  eventStream$.complete();
4412
4486
  },
4413
4487
  complete: () => eventStream$.complete()
4414
4488
  });
4415
4489
  });
4490
+ if (((_d = this.observability) == null ? void 0 : _d.enabled) && publicApiKey) {
4491
+ outputMessagesPromise.then((outputMessages) => {
4492
+ const responseData = {
4493
+ threadId,
4494
+ runId: void 0,
4495
+ model: forwardedParameters == null ? void 0 : forwardedParameters.model,
4496
+ // Use collected chunks for progressive mode or outputMessages for regular mode
4497
+ output: this.observability.progressive ? streamedChunks : outputMessages,
4498
+ latency: Date.now() - requestStartTime,
4499
+ timestamp: Date.now(),
4500
+ provider: "agent",
4501
+ isFinalResponse: true,
4502
+ agentName,
4503
+ nodeName
4504
+ };
4505
+ try {
4506
+ this.observability.hooks.handleResponse(responseData);
4507
+ } catch (logError) {
4508
+ console.error("Error logging agent response:", logError);
4509
+ }
4510
+ }).catch((error) => {
4511
+ console.error("Failed to get output messages for agent logging:", error);
4512
+ });
4513
+ }
4416
4514
  outputMessagesPromise.then((outputMessages) => {
4417
4515
  var _a2;
4418
4516
  (_a2 = this.onAfterRequest) == null ? void 0 : _a2.call(this, {
@@ -4432,6 +4530,24 @@ please use an LLM adapter instead.`
4432
4530
  actionInputsWithoutAgents: allAvailableActions
4433
4531
  };
4434
4532
  } catch (error) {
4533
+ if (((_e = this.observability) == null ? void 0 : _e.enabled) && publicApiKey) {
4534
+ try {
4535
+ const errorData = {
4536
+ threadId,
4537
+ runId: void 0,
4538
+ model: forwardedParameters == null ? void 0 : forwardedParameters.model,
4539
+ error: error instanceof Error ? error : String(error),
4540
+ timestamp: Date.now(),
4541
+ latency: Date.now() - requestStartTime,
4542
+ provider: "agent",
4543
+ agentName,
4544
+ nodeName
4545
+ };
4546
+ await this.observability.hooks.handleError(errorData);
4547
+ } catch (logError) {
4548
+ console.error("Error logging agent error:", logError);
4549
+ }
4550
+ }
4435
4551
  console.error("Error getting response:", error);
4436
4552
  throw error;
4437
4553
  }
@@ -5513,7 +5629,7 @@ var CopilotResolver = class {
5513
5629
  actions: data.frontend.actions.filter((action) => action.available !== ActionInputAvailability.disabled),
5514
5630
  threadId: data.threadId,
5515
5631
  runId: data.runId,
5516
- publicApiKey: void 0,
5632
+ publicApiKey: copilotCloudPublicApiKey,
5517
5633
  outputMessagesPromise,
5518
5634
  graphqlContext: ctx,
5519
5635
  forwardedParameters: data.forwardedParameters,