Skip to content

🐛 Bug: Unknown GraphQL Error #2368

@sudo-vaibhav

Description

@sudo-vaibhav

♻️ Reproduction Steps

import {
  CopilotRuntime,
  GoogleGenerativeAIAdapter,
  copilotRuntimeNodeHttpEndpoint,
} from "@copilotkit/runtime";

import {
  createPartFromUri,
  createUserContent,
  GoogleGenAI,
} from "@google/genai";
import express from "express";

const GEMINI_API_KEY = process.env.AI_API_KEY;

const googleAI = new GoogleGenAI({ apiKey: GEMINI_API_KEY });

const serviceAdapter = new GoogleGenerativeAIAdapter({
  model: "gemini-2.0-flash",
  apiKey: GEMINI_API_KEY,
});

export function configureCopilotRuntimeMiddleware(apiPath = "/api/ai") {
  return {
    middleware: async (
      req: express.Request,
      res: express.Response,
      next: express.NextFunction,
    ) => {
      const runtime = new CopilotRuntime({});
      const handler = copilotRuntimeNodeHttpEndpoint({
        endpoint: apiPath,
        runtime,
        serviceAdapter,
        logLevel: "error",
      });

      try {
        await handler(req, res);
      } catch (err) {
        next(err);
      }
    },
    apiPath: apiPath,
  };
}

Frontend

import {
  CopilotKit,
  useCopilotAction,
  useCopilotReadable,
} from "@copilotkit/react-core";

export const CopilotProvider = (props: {
  children: React.ReactNode;
  runtimeUrl?: string;
  headers?: Record<string, string>;
}) => {
  return (
    <CopilotKit
      // publicApiKey="ck_pub_d4fbbcc340cbe5bace584b3766d2971e"
      runtimeUrl={props.runtimeUrl || "/api/ai"}
      headers={props.headers}
    >
      {props.children}
    </CopilotKit>
  );
};

export const useCopilotClientSideAction = useCopilotAction;
export const useCopilotClientSideContext = useCopilotReadable;
export const CopilotPopup = () => {
  return (
    <div
      style={
        {
          "--copilot-kit-primary-color": "var(--color-primary)", // Primary Blue (theme.colors.primary)
          "--copilot-kit-secondary-color": "var(--color-secondary)", // Secondary Yellow (theme.colors.secondary)
          "--copilot-kit-background-color": "var(--color-surface)", // White background (theme.colors.white)
          "--copilot-kit-text-color": "var(--color-content)", // Dark grey text (theme.colors.grey[800])
          "--copilot-kit-border-radius": "6px", // Medium border radius (theme.borderRadius.medium)
        } as CopilotKitCSSProperties
      }
    >
      <CopilotPopupComponent
        instructions={systemPrompt}
        labels={{
          title: "Intelligence App",
          initial: "Need any help?",
        }}
      />
    </div>
  );
};

✅ Expected Behavior

a response from copilotkit copilot

❌ Actual Behavior

Application error: GraphQLError: An unexpected error occurred. Please check the logs for more details. ║
at CopilotResolver.generateCopilotResponse (/Users/sudomakes/code/nx-monorepo/dist/apps/backend-core/webpack:/node_modules/@copilotkit/ru ║
ntime/dist/index.js:7267:1) ║
at processTicksAndRejections (node:internal/process/task_queues:105:5) { ║
path: [ 'generateCopilotResponse' ], ║
locations: [ { line: 2, column: 3 } ], ║
extensions: { ║
name: 'CopilotError', ║
statusCode: 500, ║
code: 'UNKNOWN', ║
visibility: 'toast', ║
severity: 'critical', ║
troubleshootingUrl: null, ║
originalError: CopilotKitError [GraphQLError] [CopilotError]: An unexpected error occurred. Please check the logs for more details. ║
at new CopilotKitError (/Users/sudomakes/code/nx-monorepo/dist/apps/backend-core/webpack:/node_modules/@copilotkit/shared/dist/index. ║
js:349:1) ║
at CopilotRuntime.convertStreamingErrorToStructured (/Users/sudomakes/code/nx-monorepo/dist/apps/backend-core/webpack:/node_modules/@ ║
copilotkit/runtime/dist/index.js:5743:1) ║
at /Users/sudomakes/code/nx-monorepo/dist/apps/backend-core/webpack:/node_modules/@copilotkit/runtime/dist/index.js:5115:1 ║
at ensureStructuredError (/Users/sudomakes/code/nx-monorepo/dist/apps/backend-core/webpack:/node_modules/@copilotkit/shared/dist/inde ║
x.js:518:1) ║
at CopilotRuntime.processRuntimeRequest (/Users/sudomakes/code/nx-monorepo/dist/apps/backend-core/webpack:/node_modules/@copilotkit/r ║
untime/dist/index.js:5115:1) ║
at processTicksAndRejections (node:internal/process/task_queues:105:5) ║
at CopilotResolver.generateCopilotResponse (/Users/sudomakes/code/nx-monorepo/dist/apps/backend-core/webpack:/node_modules/@copilotki ║
t/runtime/dist/index.js:7249:1) { ║
path: undefined, ║
locations: undefined, ║
extensions: [Object], ║
code: 'UNKNOWN', ║
statusCode: 500, ║
severity: 'critical', ║
visibility: 'toast' ║
} █
} █
}

𝌚 CopilotKit Version

^1.10.3

📄 Logs (Optional)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions