@copilotkit/runtime 1.9.2-next.17 → 1.9.2-next.19
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.
- package/CHANGELOG.md +18 -0
- package/dist/{chunk-CORCJNXR.mjs → chunk-BTV2RM2X.mjs} +2 -2
- package/dist/{chunk-H3ML2MWF.mjs → chunk-EEARRKK3.mjs} +28 -28
- package/dist/chunk-EEARRKK3.mjs.map +1 -0
- package/dist/{chunk-7EDOHCIU.mjs → chunk-OVIDH7IH.mjs} +2 -2
- package/dist/{chunk-JTFQ5GIL.mjs → chunk-QLLV2QVK.mjs} +2 -1
- package/dist/chunk-QLLV2QVK.mjs.map +1 -0
- package/dist/{chunk-WXNKOOVD.mjs → chunk-QPMGUSMZ.mjs} +2 -2
- package/dist/{chunk-6QK2NO6W.mjs → chunk-ZNDOT3YP.mjs} +2 -2
- package/dist/{groq-adapter-172a2ca4.d.ts → groq-adapter-098f97f6.d.ts} +4 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +27 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -6
- package/dist/lib/index.d.ts +2 -2
- package/dist/lib/index.js +27 -26
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +6 -6
- package/dist/lib/integrations/index.d.ts +2 -2
- package/dist/lib/integrations/index.js +2 -2
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +5 -5
- package/dist/lib/integrations/nest/index.d.ts +1 -1
- package/dist/lib/integrations/nest/index.js +2 -2
- package/dist/lib/integrations/nest/index.js.map +1 -1
- package/dist/lib/integrations/nest/index.mjs +3 -3
- package/dist/lib/integrations/node-express/index.d.ts +1 -1
- package/dist/lib/integrations/node-express/index.js +2 -2
- package/dist/lib/integrations/node-express/index.js.map +1 -1
- package/dist/lib/integrations/node-express/index.mjs +3 -3
- package/dist/lib/integrations/node-http/index.d.ts +1 -1
- package/dist/lib/integrations/node-http/index.js +2 -2
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +2 -2
- package/dist/service-adapters/index.d.ts +2 -2
- package/dist/service-adapters/index.js +1 -0
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +1 -1
- package/dist/{shared-4164c674.d.ts → shared-41d4988d.d.ts} +13 -13
- package/package.json +4 -4
- package/src/graphql/resolvers/copilot.resolver.ts +1 -2
- package/src/lib/runtime/__tests__/{copilot-runtime-trace.test.ts → copilot-runtime-error.test.ts} +27 -27
- package/src/lib/runtime/copilot-runtime.ts +41 -42
- package/src/service-adapters/google/google-genai-adapter.ts +5 -0
- package/dist/chunk-H3ML2MWF.mjs.map +0 -1
- package/dist/chunk-JTFQ5GIL.mjs.map +0 -1
- /package/dist/{chunk-CORCJNXR.mjs.map → chunk-BTV2RM2X.mjs.map} +0 -0
- /package/dist/{chunk-7EDOHCIU.mjs.map → chunk-OVIDH7IH.mjs.map} +0 -0
- /package/dist/{chunk-WXNKOOVD.mjs.map → chunk-QPMGUSMZ.mjs.map} +0 -0
- /package/dist/{chunk-6QK2NO6W.mjs.map → chunk-ZNDOT3YP.mjs.map} +0 -0
|
@@ -2,7 +2,7 @@ import * as graphql from 'graphql';
|
|
|
2
2
|
import * as createPinoLogger from 'pino';
|
|
3
3
|
import createPinoLogger__default from 'pino';
|
|
4
4
|
import { YogaInitialContext, createYoga } from 'graphql-yoga';
|
|
5
|
-
import { Parameter, Action,
|
|
5
|
+
import { Parameter, Action, CopilotErrorHandler } from '@copilotkit/shared';
|
|
6
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-fc5cac89.js';
|
|
7
7
|
import { M as MessageInput, a as Message } from './index-d4614f9b.js';
|
|
8
8
|
import { CopilotCloudOptions } from './lib/cloud/index.js';
|
|
@@ -340,23 +340,23 @@ interface CopilotRuntimeConstructorParams<T extends Parameter[] | [] = []> {
|
|
|
340
340
|
*/
|
|
341
341
|
createMCPClient?: CreateMCPClientFunction;
|
|
342
342
|
/**
|
|
343
|
-
* Optional
|
|
343
|
+
* Optional error handler for comprehensive debugging and observability.
|
|
344
344
|
*
|
|
345
|
-
* **Requires publicApiKey**:
|
|
345
|
+
* **Requires publicApiKey**: Error handling only works when requests include a valid publicApiKey.
|
|
346
346
|
* This is a premium CopilotKit Cloud feature.
|
|
347
347
|
*
|
|
348
|
-
* @param
|
|
348
|
+
* @param errorEvent - Structured error event with rich debugging context
|
|
349
349
|
*
|
|
350
350
|
* @example
|
|
351
351
|
* ```typescript
|
|
352
352
|
* const runtime = new CopilotRuntime({
|
|
353
|
-
*
|
|
354
|
-
* debugDashboard.capture(
|
|
353
|
+
* onError: (errorEvent) => {
|
|
354
|
+
* debugDashboard.capture(errorEvent);
|
|
355
355
|
* }
|
|
356
356
|
* });
|
|
357
357
|
* ```
|
|
358
358
|
*/
|
|
359
|
-
|
|
359
|
+
onError?: CopilotErrorHandler;
|
|
360
360
|
}
|
|
361
361
|
declare class CopilotRuntime<const T extends Parameter[] | [] = []> {
|
|
362
362
|
actions: ActionsConfiguration<T>;
|
|
@@ -368,8 +368,8 @@ declare class CopilotRuntime<const T extends Parameter[] | [] = []> {
|
|
|
368
368
|
private delegateAgentProcessingToServiceAdapter;
|
|
369
369
|
private observability?;
|
|
370
370
|
private availableAgents;
|
|
371
|
-
private
|
|
372
|
-
private
|
|
371
|
+
private onError?;
|
|
372
|
+
private hasWarnedAboutError;
|
|
373
373
|
private readonly mcpServersConfig?;
|
|
374
374
|
private mcpActionCache;
|
|
375
375
|
private readonly createMCPClientImpl?;
|
|
@@ -384,12 +384,12 @@ declare class CopilotRuntime<const T extends Parameter[] | [] = []> {
|
|
|
384
384
|
private getServerSideActions;
|
|
385
385
|
private detectProvider;
|
|
386
386
|
private convertStreamingErrorToStructured;
|
|
387
|
-
private
|
|
387
|
+
private error;
|
|
388
388
|
/**
|
|
389
|
-
* Public method to
|
|
390
|
-
* This allows the GraphQL resolver to send validation errors through the
|
|
389
|
+
* Public method to handle GraphQL validation errors
|
|
390
|
+
* This allows the GraphQL resolver to send validation errors through the error system
|
|
391
391
|
*/
|
|
392
|
-
|
|
392
|
+
errorGraphQLError(error: {
|
|
393
393
|
message: string;
|
|
394
394
|
code: string;
|
|
395
395
|
type: string;
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"access": "public"
|
|
11
11
|
},
|
|
12
|
-
"version": "1.9.2-next.
|
|
12
|
+
"version": "1.9.2-next.19",
|
|
13
13
|
"sideEffects": false,
|
|
14
14
|
"main": "./dist/index.js",
|
|
15
15
|
"module": "./dist/index.mjs",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"tsup": "^6.7.0",
|
|
34
34
|
"typescript": "^5.2.3",
|
|
35
35
|
"zod-to-json-schema": "^3.23.5",
|
|
36
|
-
"
|
|
37
|
-
"
|
|
36
|
+
"tsconfig": "1.4.6",
|
|
37
|
+
"eslint-config-custom": "1.4.6"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@ag-ui/client": "0.0.28",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"rxjs": "7.8.1",
|
|
67
67
|
"type-graphql": "2.0.0-rc.1",
|
|
68
68
|
"zod": "^3.23.3",
|
|
69
|
-
"@copilotkit/shared": "1.9.2-next.
|
|
69
|
+
"@copilotkit/shared": "1.9.2-next.19"
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
72
|
"@ag-ui/client": ">=0.0.28",
|
|
@@ -192,8 +192,7 @@ export class CopilotResolver {
|
|
|
192
192
|
if (!copilotCloudPublicApiKey) {
|
|
193
193
|
logger.error("Public API key not found in headers");
|
|
194
194
|
|
|
195
|
-
|
|
196
|
-
await copilotRuntime.traceGraphQLError(
|
|
195
|
+
await copilotRuntime.errorGraphQLError(
|
|
197
196
|
{
|
|
198
197
|
message: "X-CopilotCloud-Public-API-Key header is required",
|
|
199
198
|
code: "MISSING_PUBLIC_API_KEY",
|
package/src/lib/runtime/__tests__/{copilot-runtime-trace.test.ts → copilot-runtime-error.test.ts}
RENAMED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CopilotErrorEvent, CopilotRequestContext, CopilotErrorHandler } from "@copilotkit/shared";
|
|
2
2
|
|
|
3
|
-
describe("CopilotRuntime
|
|
3
|
+
describe("CopilotRuntime onError types", () => {
|
|
4
4
|
it("should have correct CopilotTraceEvent type structure", () => {
|
|
5
|
-
const
|
|
5
|
+
const errorEvent: CopilotErrorEvent = {
|
|
6
6
|
type: "error",
|
|
7
7
|
timestamp: Date.now(),
|
|
8
8
|
context: {
|
|
@@ -18,10 +18,10 @@ describe("CopilotRuntime onTrace types", () => {
|
|
|
18
18
|
error: new Error("Test error"),
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
expect(
|
|
22
|
-
expect(
|
|
23
|
-
expect(
|
|
24
|
-
expect(
|
|
21
|
+
expect(errorEvent.type).toBe("error");
|
|
22
|
+
expect(errorEvent.timestamp).toBeGreaterThan(0);
|
|
23
|
+
expect(errorEvent.context.threadId).toBe("test-123");
|
|
24
|
+
expect(errorEvent.error).toBeInstanceOf(Error);
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
it("should have correct CopilotRequestContext type structure", () => {
|
|
@@ -76,8 +76,8 @@ describe("CopilotRuntime onTrace types", () => {
|
|
|
76
76
|
expect(context.metadata?.testFlag).toBe(true);
|
|
77
77
|
});
|
|
78
78
|
|
|
79
|
-
it("should support all
|
|
80
|
-
const eventTypes:
|
|
79
|
+
it("should support all error event types", () => {
|
|
80
|
+
const eventTypes: CopilotErrorEvent["type"][] = [
|
|
81
81
|
"error",
|
|
82
82
|
"request",
|
|
83
83
|
"response",
|
|
@@ -88,7 +88,7 @@ describe("CopilotRuntime onTrace types", () => {
|
|
|
88
88
|
];
|
|
89
89
|
|
|
90
90
|
eventTypes.forEach((type) => {
|
|
91
|
-
const event:
|
|
91
|
+
const event: CopilotErrorEvent = {
|
|
92
92
|
type,
|
|
93
93
|
timestamp: Date.now(),
|
|
94
94
|
context: {
|
|
@@ -108,37 +108,37 @@ describe("CopilotRuntime onTrace types", () => {
|
|
|
108
108
|
});
|
|
109
109
|
|
|
110
110
|
describe("publicApiKey gating logic", () => {
|
|
111
|
-
type
|
|
111
|
+
type ShouldHandleError = (onError?: CopilotErrorHandler, publicApiKey?: string) => boolean;
|
|
112
112
|
|
|
113
|
-
const
|
|
114
|
-
return Boolean(
|
|
113
|
+
const shouldHandleError: ShouldHandleError = (onError, publicApiKey) => {
|
|
114
|
+
return Boolean(onError && publicApiKey);
|
|
115
115
|
};
|
|
116
116
|
|
|
117
|
-
it("should return true when both
|
|
118
|
-
const
|
|
119
|
-
const result =
|
|
117
|
+
it("should return true when both onError and publicApiKey are provided", () => {
|
|
118
|
+
const onError = jest.fn();
|
|
119
|
+
const result = shouldHandleError(onError, "valid-api-key");
|
|
120
120
|
expect(result).toBe(true);
|
|
121
121
|
});
|
|
122
122
|
|
|
123
|
-
it("should return false when
|
|
124
|
-
const result =
|
|
123
|
+
it("should return false when onError is missing", () => {
|
|
124
|
+
const result = shouldHandleError(undefined, "valid-api-key");
|
|
125
125
|
expect(result).toBe(false);
|
|
126
126
|
});
|
|
127
127
|
|
|
128
128
|
it("should return false when publicApiKey is missing", () => {
|
|
129
|
-
const
|
|
130
|
-
const result =
|
|
129
|
+
const onError = jest.fn();
|
|
130
|
+
const result = shouldHandleError(onError, undefined);
|
|
131
131
|
expect(result).toBe(false);
|
|
132
132
|
});
|
|
133
133
|
|
|
134
134
|
it("should return false when publicApiKey is empty string", () => {
|
|
135
|
-
const
|
|
136
|
-
const result =
|
|
135
|
+
const onError = jest.fn();
|
|
136
|
+
const result = shouldHandleError(onError, "");
|
|
137
137
|
expect(result).toBe(false);
|
|
138
138
|
});
|
|
139
139
|
|
|
140
140
|
it("should return false when both are missing", () => {
|
|
141
|
-
const result =
|
|
141
|
+
const result = shouldHandleError(undefined, undefined);
|
|
142
142
|
expect(result).toBe(false);
|
|
143
143
|
});
|
|
144
144
|
|
|
@@ -160,10 +160,10 @@ describe("CopilotRuntime onTrace types", () => {
|
|
|
160
160
|
const nonCloudKey = extractPublicApiKey(mockHeaders, false);
|
|
161
161
|
expect(nonCloudKey).toBe("test-key-123");
|
|
162
162
|
|
|
163
|
-
// Both should enable
|
|
164
|
-
const
|
|
165
|
-
expect(
|
|
166
|
-
expect(
|
|
163
|
+
// Both should enable error handling when onError is present
|
|
164
|
+
const onError = jest.fn();
|
|
165
|
+
expect(shouldHandleError(onError, cloudKey)).toBe(true);
|
|
166
|
+
expect(shouldHandleError(onError, nonCloudKey)).toBe(true);
|
|
167
167
|
});
|
|
168
168
|
});
|
|
169
169
|
});
|
|
@@ -20,13 +20,12 @@ import {
|
|
|
20
20
|
CopilotKitApiDiscoveryError,
|
|
21
21
|
randomId,
|
|
22
22
|
CopilotKitError,
|
|
23
|
-
CopilotKitRemoteEndpointDiscoveryError,
|
|
24
23
|
CopilotKitAgentDiscoveryError,
|
|
25
24
|
CopilotKitMisuseError,
|
|
26
25
|
CopilotKitErrorCode,
|
|
27
26
|
CopilotKitLowLevelError,
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
CopilotErrorHandler,
|
|
28
|
+
CopilotErrorEvent,
|
|
30
29
|
CopilotRequestContext,
|
|
31
30
|
ensureStructuredError,
|
|
32
31
|
} from "@copilotkit/shared";
|
|
@@ -66,7 +65,7 @@ import { ExtensionsInput } from "../../graphql/inputs/extensions.input";
|
|
|
66
65
|
import { ExtensionsResponse } from "../../graphql/types/extensions-response.type";
|
|
67
66
|
import { LoadAgentStateResponse } from "../../graphql/types/load-agent-state-response.type";
|
|
68
67
|
import { Client as LangGraphClient } from "@langchain/langgraph-sdk";
|
|
69
|
-
import { langchainMessagesToCopilotKit
|
|
68
|
+
import { langchainMessagesToCopilotKit } from "./remote-lg-action";
|
|
70
69
|
import { MetaEventInput } from "../../graphql/inputs/meta-event.input";
|
|
71
70
|
import {
|
|
72
71
|
CopilotObservabilityConfig,
|
|
@@ -283,23 +282,23 @@ export interface CopilotRuntimeConstructorParams<T extends Parameter[] | [] = []
|
|
|
283
282
|
createMCPClient?: CreateMCPClientFunction;
|
|
284
283
|
|
|
285
284
|
/**
|
|
286
|
-
* Optional
|
|
285
|
+
* Optional error handler for comprehensive debugging and observability.
|
|
287
286
|
*
|
|
288
|
-
* **Requires publicApiKey**:
|
|
287
|
+
* **Requires publicApiKey**: Error handling only works when requests include a valid publicApiKey.
|
|
289
288
|
* This is a premium CopilotKit Cloud feature.
|
|
290
289
|
*
|
|
291
|
-
* @param
|
|
290
|
+
* @param errorEvent - Structured error event with rich debugging context
|
|
292
291
|
*
|
|
293
292
|
* @example
|
|
294
293
|
* ```typescript
|
|
295
294
|
* const runtime = new CopilotRuntime({
|
|
296
|
-
*
|
|
297
|
-
* debugDashboard.capture(
|
|
295
|
+
* onError: (errorEvent) => {
|
|
296
|
+
* debugDashboard.capture(errorEvent);
|
|
298
297
|
* }
|
|
299
298
|
* });
|
|
300
299
|
* ```
|
|
301
300
|
*/
|
|
302
|
-
|
|
301
|
+
onError?: CopilotErrorHandler;
|
|
303
302
|
}
|
|
304
303
|
|
|
305
304
|
export class CopilotRuntime<const T extends Parameter[] | [] = []> {
|
|
@@ -312,8 +311,8 @@ export class CopilotRuntime<const T extends Parameter[] | [] = []> {
|
|
|
312
311
|
private delegateAgentProcessingToServiceAdapter: boolean;
|
|
313
312
|
private observability?: CopilotObservabilityConfig;
|
|
314
313
|
private availableAgents: Pick<AgentWithEndpoint, "name" | "id">[];
|
|
315
|
-
private
|
|
316
|
-
private
|
|
314
|
+
private onError?: CopilotErrorHandler;
|
|
315
|
+
private hasWarnedAboutError = false;
|
|
317
316
|
|
|
318
317
|
// +++ MCP Properties +++
|
|
319
318
|
private readonly mcpServersConfig?: MCPEndpointConfig[];
|
|
@@ -362,7 +361,7 @@ export class CopilotRuntime<const T extends Parameter[] | [] = []> {
|
|
|
362
361
|
params?.delegateAgentProcessingToServiceAdapter || false;
|
|
363
362
|
this.observability = params?.observability_c;
|
|
364
363
|
this.agents = params?.agents ?? {};
|
|
365
|
-
this.
|
|
364
|
+
this.onError = params?.onError;
|
|
366
365
|
// +++ MCP Initialization +++
|
|
367
366
|
this.mcpServersConfig = params?.mcpServers;
|
|
368
367
|
this.createMCPClientImpl = params?.createMCPClient;
|
|
@@ -495,8 +494,8 @@ export class CopilotRuntime<const T extends Parameter[] | [] = []> {
|
|
|
495
494
|
// For storing streamed chunks if progressive logging is enabled
|
|
496
495
|
const streamedChunks: any[] = [];
|
|
497
496
|
|
|
498
|
-
//
|
|
499
|
-
await this.
|
|
497
|
+
// Track request start
|
|
498
|
+
await this.error(
|
|
500
499
|
"request",
|
|
501
500
|
{
|
|
502
501
|
threadId,
|
|
@@ -755,8 +754,8 @@ please use an LLM adapter instead.`,
|
|
|
755
754
|
);
|
|
756
755
|
}
|
|
757
756
|
|
|
758
|
-
//
|
|
759
|
-
await this.
|
|
757
|
+
// Track the error
|
|
758
|
+
await this.error(
|
|
760
759
|
"error",
|
|
761
760
|
{
|
|
762
761
|
threadId,
|
|
@@ -1041,8 +1040,8 @@ please use an LLM adapter instead.`,
|
|
|
1041
1040
|
// for backwards compatibility, deal with the case when no threadId is provided
|
|
1042
1041
|
const threadId = threadIdFromRequest ?? agentSession.threadId;
|
|
1043
1042
|
|
|
1044
|
-
//
|
|
1045
|
-
await this.
|
|
1043
|
+
// Track agent request start
|
|
1044
|
+
await this.error(
|
|
1046
1045
|
"agent_state",
|
|
1047
1046
|
{
|
|
1048
1047
|
threadId,
|
|
@@ -1222,8 +1221,8 @@ please use an LLM adapter instead.`,
|
|
|
1222
1221
|
this.convertStreamingErrorToStructured(error),
|
|
1223
1222
|
);
|
|
1224
1223
|
|
|
1225
|
-
//
|
|
1226
|
-
await this.
|
|
1224
|
+
// Track streaming errors
|
|
1225
|
+
await this.error(
|
|
1227
1226
|
"error",
|
|
1228
1227
|
{
|
|
1229
1228
|
threadId,
|
|
@@ -1332,8 +1331,8 @@ please use an LLM adapter instead.`,
|
|
|
1332
1331
|
this.convertStreamingErrorToStructured(err),
|
|
1333
1332
|
);
|
|
1334
1333
|
|
|
1335
|
-
//
|
|
1336
|
-
await this.
|
|
1334
|
+
// Track the agent error
|
|
1335
|
+
await this.error(
|
|
1337
1336
|
"error",
|
|
1338
1337
|
{
|
|
1339
1338
|
threadId,
|
|
@@ -1506,45 +1505,45 @@ please use an LLM adapter instead.`,
|
|
|
1506
1505
|
});
|
|
1507
1506
|
}
|
|
1508
1507
|
|
|
1509
|
-
private async
|
|
1510
|
-
type:
|
|
1508
|
+
private async error(
|
|
1509
|
+
type: CopilotErrorEvent["type"],
|
|
1511
1510
|
context: CopilotRequestContext,
|
|
1512
1511
|
error?: any,
|
|
1513
1512
|
publicApiKey?: string,
|
|
1514
1513
|
): Promise<void> {
|
|
1515
|
-
if (!this.
|
|
1514
|
+
if (!this.onError) return;
|
|
1516
1515
|
|
|
1517
1516
|
// Just check if publicApiKey is defined (regardless of validity)
|
|
1518
1517
|
if (!publicApiKey) {
|
|
1519
|
-
if (!this.
|
|
1518
|
+
if (!this.hasWarnedAboutError) {
|
|
1520
1519
|
console.warn(
|
|
1521
|
-
"CopilotKit:
|
|
1520
|
+
"CopilotKit: onError handler provided but requires publicApiKey to be defined for error handling to work.",
|
|
1522
1521
|
);
|
|
1523
|
-
this.
|
|
1522
|
+
this.hasWarnedAboutError = true;
|
|
1524
1523
|
}
|
|
1525
1524
|
return;
|
|
1526
1525
|
}
|
|
1527
1526
|
|
|
1528
1527
|
try {
|
|
1529
|
-
const
|
|
1528
|
+
const errorEvent: CopilotErrorEvent = {
|
|
1530
1529
|
type,
|
|
1531
1530
|
timestamp: Date.now(),
|
|
1532
1531
|
context,
|
|
1533
1532
|
...(error && { error }),
|
|
1534
1533
|
};
|
|
1535
1534
|
|
|
1536
|
-
await this.
|
|
1537
|
-
} catch (
|
|
1538
|
-
// Don't let
|
|
1539
|
-
console.error("Error in
|
|
1535
|
+
await this.onError(errorEvent);
|
|
1536
|
+
} catch (errorHandlerError) {
|
|
1537
|
+
// Don't let error handler errors break the main flow
|
|
1538
|
+
console.error("Error in onError handler:", errorHandlerError);
|
|
1540
1539
|
}
|
|
1541
1540
|
}
|
|
1542
1541
|
|
|
1543
1542
|
/**
|
|
1544
|
-
* Public method to
|
|
1545
|
-
* This allows the GraphQL resolver to send validation errors through the
|
|
1543
|
+
* Public method to handle GraphQL validation errors
|
|
1544
|
+
* This allows the GraphQL resolver to send validation errors through the error system
|
|
1546
1545
|
*/
|
|
1547
|
-
public async
|
|
1546
|
+
public async errorGraphQLError(
|
|
1548
1547
|
error: { message: string; code: string; type: string },
|
|
1549
1548
|
context: {
|
|
1550
1549
|
operation: string;
|
|
@@ -1552,10 +1551,10 @@ please use an LLM adapter instead.`,
|
|
|
1552
1551
|
guardrailsEnabled: boolean;
|
|
1553
1552
|
},
|
|
1554
1553
|
): Promise<void> {
|
|
1555
|
-
if (!this.
|
|
1554
|
+
if (!this.onError) return;
|
|
1556
1555
|
|
|
1557
1556
|
try {
|
|
1558
|
-
await this.
|
|
1557
|
+
await this.onError({
|
|
1559
1558
|
type: "error",
|
|
1560
1559
|
timestamp: Date.now(),
|
|
1561
1560
|
context: {
|
|
@@ -1575,9 +1574,9 @@ please use an LLM adapter instead.`,
|
|
|
1575
1574
|
},
|
|
1576
1575
|
error,
|
|
1577
1576
|
});
|
|
1578
|
-
} catch (
|
|
1579
|
-
// Don't let
|
|
1580
|
-
console.error("Error in
|
|
1577
|
+
} catch (errorHandlerError) {
|
|
1578
|
+
// Don't let error handler errors break the main flow
|
|
1579
|
+
console.error("Error in onError handler:", errorHandlerError);
|
|
1581
1580
|
}
|
|
1582
1581
|
}
|
|
1583
1582
|
}
|
|
@@ -23,6 +23,10 @@ interface GoogleGenerativeAIAdapterOptions {
|
|
|
23
23
|
* A custom Google Generative AI model to use.
|
|
24
24
|
*/
|
|
25
25
|
model?: string;
|
|
26
|
+
/**
|
|
27
|
+
* The API key to use.
|
|
28
|
+
*/
|
|
29
|
+
apiKey?: string;
|
|
26
30
|
}
|
|
27
31
|
|
|
28
32
|
export class GoogleGenerativeAIAdapter extends LangChainAdapter {
|
|
@@ -46,6 +50,7 @@ export class GoogleGenerativeAIAdapter extends LangChainAdapter {
|
|
|
46
50
|
});
|
|
47
51
|
|
|
48
52
|
const model = new ChatGoogle({
|
|
53
|
+
apiKey: options?.apiKey ?? process.env.GOOGLE_API_KEY,
|
|
49
54
|
modelName: options?.model ?? "gemini-1.5-pro",
|
|
50
55
|
apiVersion: "v1beta",
|
|
51
56
|
}).bindTools(tools);
|