@copilotkit/runtime 1.50.0-beta.2 → 1.50.0-beta.3

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 (35) hide show
  1. package/dist/index.d.ts +71 -281
  2. package/dist/index.js +291 -274
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.mjs +284 -263
  5. package/dist/index.mjs.map +1 -1
  6. package/dist/langgraph.d.ts +284 -0
  7. package/dist/langgraph.js +211 -0
  8. package/dist/langgraph.js.map +1 -0
  9. package/dist/langgraph.mjs +206 -0
  10. package/dist/langgraph.mjs.map +1 -0
  11. package/dist/v2/index.d.ts +1 -0
  12. package/dist/v2/index.js +7 -0
  13. package/dist/v2/index.js.map +1 -1
  14. package/dist/v2/index.mjs +1 -0
  15. package/dist/v2/index.mjs.map +1 -1
  16. package/package.json +48 -15
  17. package/src/langgraph.ts +1 -0
  18. package/src/lib/index.ts +41 -1
  19. package/src/lib/integrations/node-http/index.ts +129 -10
  20. package/src/lib/runtime/agent-integrations/{langgraph.agent.ts → langgraph/agent.ts} +5 -30
  21. package/src/lib/runtime/agent-integrations/langgraph/consts.ts +34 -0
  22. package/src/lib/runtime/agent-integrations/langgraph/index.ts +2 -0
  23. package/src/lib/runtime/copilot-runtime.ts +17 -40
  24. package/src/service-adapters/anthropic/anthropic-adapter.ts +16 -3
  25. package/src/service-adapters/bedrock/bedrock-adapter.ts +4 -1
  26. package/src/service-adapters/experimental/ollama/ollama-adapter.ts +2 -1
  27. package/src/service-adapters/google/google-genai-adapter.ts +9 -4
  28. package/src/service-adapters/groq/groq-adapter.ts +16 -3
  29. package/src/service-adapters/langchain/langchain-adapter.ts +5 -3
  30. package/src/service-adapters/langchain/langserve.ts +2 -1
  31. package/src/service-adapters/openai/openai-adapter.ts +17 -3
  32. package/src/service-adapters/openai/openai-assistant-adapter.ts +26 -11
  33. package/src/service-adapters/unify/unify-adapter.ts +3 -1
  34. package/src/v2/index.ts +1 -0
  35. package/tsup.config.ts +5 -2
package/dist/index.d.ts CHANGED
@@ -1,23 +1,19 @@
1
- import OpenAI from 'openai';
2
- import * as rxjs from 'rxjs';
3
1
  import { ReplaySubject } from 'rxjs';
2
+ import { Parameter, Action, CopilotKitLowLevelError, CopilotErrorHandler, PartialBy, MaybePromise, NonEmptyRecord } from '@copilotkit/shared';
3
+ import OpenAI from 'openai';
4
4
  import { BaseMessageChunk, AIMessage, AIMessageChunk, BaseMessage } from '@langchain/core/messages';
5
5
  import { DynamicStructuredTool } from '@langchain/core/tools';
6
6
  import { IterableReadableStream, IterableReadableStreamInterface } from '@langchain/core/utils/stream';
7
7
  import { Groq } from 'groq-sdk';
8
+ import Anthropic from '@anthropic-ai/sdk';
8
9
  import * as graphql from 'graphql';
9
10
  import * as pino from 'pino';
10
11
  import { YogaInitialContext, createYoga } from 'graphql-yoga';
11
- import { Parameter, Action, CopilotKitLowLevelError, CopilotErrorHandler, PartialBy, MaybePromise, NonEmptyRecord } from '@copilotkit/shared';
12
12
  import { CopilotRuntimeOptions, CopilotRuntime as CopilotRuntime$1 } from '@copilotkitnext/runtime';
13
- import { AbstractAgent, TextMessageStartEvent, TextMessageContentEvent, TextMessageEndEvent, ToolCallStartEvent, ToolCallArgsEvent, ToolCallEndEvent, RunAgentInput, EventType } from '@ag-ui/client';
13
+ import { AbstractAgent } from '@ag-ui/client';
14
14
  import * as http from 'http';
15
- import { IncomingMessage, ServerResponse } from 'http';
15
+ import { ServerResponse, IncomingMessage } from 'http';
16
16
  import { Readable } from 'node:stream';
17
- import { LangGraphAgent as LangGraphAgent$1, LangGraphAgentConfig, ProcessedEvents, State, StateEnrichment, SchemaKeys } from '@ag-ui/langgraph';
18
- export { LangGraphHttpAgent } from '@ag-ui/langgraph';
19
- import { Message as Message$1 } from '@langchain/langgraph-sdk/dist/types.messages';
20
- import Anthropic from '@anthropic-ai/sdk';
21
17
 
22
18
  declare enum MessageRole {
23
19
  assistant = "assistant",
@@ -500,6 +496,7 @@ declare class OpenAIAdapter implements CopilotServiceAdapter {
500
496
  get openai(): OpenAI;
501
497
  get name(): string;
502
498
  constructor(params?: OpenAIAdapterParams);
499
+ private ensureOpenAI;
503
500
  process(request: CopilotRuntimeChatCompletionRequest): Promise<CopilotRuntimeChatCompletionResponse>;
504
501
  }
505
502
 
@@ -563,6 +560,23 @@ declare class LangChainAdapter implements CopilotServiceAdapter {
563
560
  process(request: CopilotRuntimeChatCompletionRequest): Promise<CopilotRuntimeChatCompletionResponse>;
564
561
  }
565
562
 
563
+ /**
564
+ * Copilot Runtime adapter for Google Generative AI (e.g. Gemini).
565
+ *
566
+ * ## Example
567
+ *
568
+ * ```ts
569
+ * import { CopilotRuntime, GoogleGenerativeAIAdapter } from "@copilotkit/runtime";
570
+ * const { GoogleGenerativeAI } = require("@google/generative-ai");
571
+ *
572
+ * const genAI = new GoogleGenerativeAI(process.env["GOOGLE_API_KEY"]);
573
+ *
574
+ * const copilotKit = new CopilotRuntime();
575
+ *
576
+ * return new GoogleGenerativeAIAdapter({ model: "gemini-1.5-pro" });
577
+ * ```
578
+ */
579
+
566
580
  interface GoogleGenerativeAIAdapterOptions {
567
581
  /**
568
582
  * A custom Google Generative AI model to use.
@@ -641,7 +655,7 @@ interface OpenAIAssistantAdapterParams {
641
655
  keepSystemRole?: boolean;
642
656
  }
643
657
  declare class OpenAIAssistantAdapter implements CopilotServiceAdapter {
644
- private openai;
658
+ private _openai;
645
659
  private codeInterpreterEnabled;
646
660
  private assistantId;
647
661
  private fileSearchEnabled;
@@ -649,6 +663,7 @@ declare class OpenAIAssistantAdapter implements CopilotServiceAdapter {
649
663
  private keepSystemRole;
650
664
  get name(): string;
651
665
  constructor(params: OpenAIAssistantAdapterParams);
666
+ private ensureOpenAI;
652
667
  process(request: CopilotRuntimeChatCompletionRequest): Promise<CopilotRuntimeChatCompletionResponse>;
653
668
  private submitToolOutputs;
654
669
  private submitUserMessage;
@@ -733,6 +748,7 @@ declare class GroqAdapter implements CopilotServiceAdapter {
733
748
  get groq(): Groq;
734
749
  get name(): string;
735
750
  constructor(params?: GroqAdapterParams);
751
+ private ensureGroq;
736
752
  process(request: CopilotRuntimeChatCompletionRequest): Promise<CopilotRuntimeChatCompletionResponse>;
737
753
  }
738
754
 
@@ -819,6 +835,7 @@ declare class AnthropicAdapter implements CopilotServiceAdapter {
819
835
  get anthropic(): Anthropic;
820
836
  get name(): string;
821
837
  constructor(params?: AnthropicAdapterParams);
838
+ private ensureAnthropic;
822
839
  /**
823
840
  * Adds cache control to system prompt
824
841
  */
@@ -1330,283 +1347,56 @@ declare const config: {
1330
1347
  };
1331
1348
  };
1332
1349
 
1333
- declare function copilotRuntimeNextJSPagesRouterEndpoint(options: CreateCopilotRuntimeServerOptions): (req: http.IncomingMessage, res: http.ServerResponse) => Promise<void>;
1350
+ declare function copilotRuntimeNextJSPagesRouterEndpoint(options: CreateCopilotRuntimeServerOptions): (req: http.IncomingMessage & {
1351
+ body?: unknown;
1352
+ complete?: boolean;
1353
+ }, res: http.ServerResponse) => Promise<void>;
1334
1354
 
1355
+ type IncomingWithBody = IncomingMessage & {
1356
+ body?: unknown;
1357
+ complete?: boolean;
1358
+ };
1335
1359
  declare function readableStreamToNodeStream(webStream: ReadableStream): Readable;
1336
- declare function copilotRuntimeNodeHttpEndpoint(options: CreateCopilotRuntimeServerOptions): (req: IncomingMessage, res: ServerResponse) => Promise<void>;
1360
+ declare function copilotRuntimeNodeHttpEndpoint(options: CreateCopilotRuntimeServerOptions): (req: IncomingWithBody, res: ServerResponse) => Promise<void>;
1337
1361
 
1338
- declare function copilotRuntimeNodeExpressEndpoint(options: CreateCopilotRuntimeServerOptions): (req: http.IncomingMessage, res: http.ServerResponse) => Promise<void>;
1362
+ declare function copilotRuntimeNodeExpressEndpoint(options: CreateCopilotRuntimeServerOptions): (req: http.IncomingMessage & {
1363
+ body?: unknown;
1364
+ complete?: boolean;
1365
+ }, res: http.ServerResponse) => Promise<void>;
1339
1366
 
1340
- declare function copilotRuntimeNestEndpoint(options: CreateCopilotRuntimeServerOptions): (req: http.IncomingMessage, res: http.ServerResponse) => Promise<void>;
1367
+ declare function copilotRuntimeNestEndpoint(options: CreateCopilotRuntimeServerOptions): (req: http.IncomingMessage & {
1368
+ body?: unknown;
1369
+ complete?: boolean;
1370
+ }, res: http.ServerResponse) => Promise<void>;
1341
1371
 
1342
- interface CopilotKitStateEnrichment {
1343
- copilotkit: {
1344
- actions: StateEnrichment["ag-ui"]["tools"];
1345
- context: StateEnrichment["ag-ui"]["context"];
1346
- };
1372
+ /**
1373
+ * @deprecated LangGraphAgent import from @copilotkit/runtime is deprecated. Please import it from @copilotkit/runtime/langgraph instead
1374
+ */
1375
+ declare class LangGraphAgent {
1376
+ constructor();
1347
1377
  }
1348
- interface PredictStateTool {
1349
- tool: string;
1350
- state_key: string;
1351
- tool_argument: string;
1352
- }
1353
- type TextMessageEvents = TextMessageStartEvent | TextMessageContentEvent | TextMessageEndEvent;
1354
- type ToolCallEvents = ToolCallStartEvent | ToolCallArgsEvent | ToolCallEndEvent;
1355
- declare enum CustomEventNames {
1356
- CopilotKitManuallyEmitMessage = "copilotkit_manually_emit_message",
1357
- CopilotKitManuallyEmitToolCall = "copilotkit_manually_emit_tool_call",
1358
- CopilotKitManuallyEmitIntermediateState = "copilotkit_manually_emit_intermediate_state",
1359
- CopilotKitExit = "copilotkit_exit"
1360
- }
1361
- declare class LangGraphAgent extends LangGraphAgent$1 {
1362
- constructor(config: LangGraphAgentConfig);
1363
- clone(): LangGraphAgent;
1364
- dispatchEvent(event: ProcessedEvents): boolean;
1365
- run(input: RunAgentInput): rxjs.Observable<{
1366
- type: EventType.TEXT_MESSAGE_START;
1367
- role: "developer" | "system" | "assistant" | "user";
1368
- messageId: string;
1369
- timestamp?: number | undefined;
1370
- rawEvent?: any;
1371
- } | {
1372
- type: EventType.TEXT_MESSAGE_CONTENT;
1373
- messageId: string;
1374
- delta: string;
1375
- timestamp?: number | undefined;
1376
- rawEvent?: any;
1377
- } | {
1378
- type: EventType.TEXT_MESSAGE_END;
1379
- messageId: string;
1380
- timestamp?: number | undefined;
1381
- rawEvent?: any;
1382
- } | {
1383
- type: EventType.TOOL_CALL_START;
1384
- toolCallId: string;
1385
- toolCallName: string;
1386
- timestamp?: number | undefined;
1387
- rawEvent?: any;
1388
- parentMessageId?: string | undefined;
1389
- } | {
1390
- type: EventType.TOOL_CALL_ARGS;
1391
- toolCallId: string;
1392
- delta: string;
1393
- timestamp?: number | undefined;
1394
- rawEvent?: any;
1395
- } | {
1396
- type: EventType.TOOL_CALL_END;
1397
- toolCallId: string;
1398
- timestamp?: number | undefined;
1399
- rawEvent?: any;
1400
- } | {
1401
- type: EventType.THINKING_TEXT_MESSAGE_START;
1402
- timestamp?: number | undefined;
1403
- rawEvent?: any;
1404
- } | {
1405
- type: EventType.THINKING_TEXT_MESSAGE_CONTENT;
1406
- delta: string;
1407
- timestamp?: number | undefined;
1408
- rawEvent?: any;
1409
- } | {
1410
- type: EventType.THINKING_TEXT_MESSAGE_END;
1411
- timestamp?: number | undefined;
1412
- rawEvent?: any;
1413
- } | {
1414
- type: EventType.TOOL_CALL_RESULT;
1415
- content: string;
1416
- toolCallId: string;
1417
- messageId: string;
1418
- role?: "tool" | undefined;
1419
- timestamp?: number | undefined;
1420
- rawEvent?: any;
1421
- } | {
1422
- type: EventType.THINKING_START;
1423
- timestamp?: number | undefined;
1424
- rawEvent?: any;
1425
- title?: string | undefined;
1426
- } | {
1427
- type: EventType.THINKING_END;
1428
- timestamp?: number | undefined;
1429
- rawEvent?: any;
1430
- } | {
1431
- type: EventType.STATE_SNAPSHOT;
1432
- timestamp?: number | undefined;
1433
- rawEvent?: any;
1434
- snapshot?: any;
1435
- } | {
1436
- type: EventType.STATE_DELTA;
1437
- delta: any[];
1438
- timestamp?: number | undefined;
1439
- rawEvent?: any;
1440
- } | {
1441
- type: EventType.MESSAGES_SNAPSHOT;
1442
- messages: ({
1443
- id: string;
1444
- role: "developer";
1445
- content: string;
1446
- name?: string | undefined;
1447
- } | {
1448
- id: string;
1449
- role: "system";
1450
- content: string;
1451
- name?: string | undefined;
1452
- } | {
1453
- id: string;
1454
- role: "assistant";
1455
- name?: string | undefined;
1456
- content?: string | undefined;
1457
- toolCalls?: {
1458
- function: {
1459
- name: string;
1460
- arguments: string;
1461
- };
1462
- type: "function";
1463
- id: string;
1464
- }[] | undefined;
1465
- } | {
1466
- id: string;
1467
- role: "user";
1468
- content: string | ({
1469
- type: "text";
1470
- text: string;
1471
- } | {
1472
- type: "binary";
1473
- mimeType: string;
1474
- id?: string | undefined;
1475
- url?: string | undefined;
1476
- data?: string | undefined;
1477
- filename?: string | undefined;
1478
- })[];
1479
- name?: string | undefined;
1480
- } | {
1481
- id: string;
1482
- role: "tool";
1483
- content: string;
1484
- toolCallId: string;
1485
- error?: string | undefined;
1486
- } | {
1487
- id: string;
1488
- role: "activity";
1489
- content: Record<string, any>;
1490
- activityType: string;
1491
- })[];
1492
- timestamp?: number | undefined;
1493
- rawEvent?: any;
1494
- } | {
1495
- type: EventType.RAW;
1496
- timestamp?: number | undefined;
1497
- rawEvent?: any;
1498
- event?: any;
1499
- source?: string | undefined;
1500
- } | {
1501
- name: string;
1502
- type: EventType.CUSTOM;
1503
- value?: any;
1504
- timestamp?: number | undefined;
1505
- rawEvent?: any;
1506
- } | {
1507
- type: EventType.RUN_STARTED;
1508
- threadId: string;
1509
- runId: string;
1510
- parentRunId?: string | undefined;
1511
- timestamp?: number | undefined;
1512
- rawEvent?: any;
1513
- input?: {
1514
- threadId: string;
1515
- runId: string;
1516
- messages: ({
1517
- id: string;
1518
- role: "developer";
1519
- content: string;
1520
- name?: string | undefined;
1521
- } | {
1522
- id: string;
1523
- role: "system";
1524
- content: string;
1525
- name?: string | undefined;
1526
- } | {
1527
- id: string;
1528
- role: "assistant";
1529
- name?: string | undefined;
1530
- content?: string | undefined;
1531
- toolCalls?: {
1532
- function: {
1533
- name: string;
1534
- arguments: string;
1535
- };
1536
- type: "function";
1537
- id: string;
1538
- }[] | undefined;
1539
- } | {
1540
- id: string;
1541
- role: "user";
1542
- content: string | ({
1543
- type: "text";
1544
- text: string;
1545
- } | {
1546
- type: "binary";
1547
- mimeType: string;
1548
- id?: string | undefined;
1549
- url?: string | undefined;
1550
- data?: string | undefined;
1551
- filename?: string | undefined;
1552
- })[];
1553
- name?: string | undefined;
1554
- } | {
1555
- id: string;
1556
- role: "tool";
1557
- content: string;
1558
- toolCallId: string;
1559
- error?: string | undefined;
1560
- } | {
1561
- id: string;
1562
- role: "activity";
1563
- content: Record<string, any>;
1564
- activityType: string;
1565
- })[];
1566
- tools: {
1567
- name: string;
1568
- description: string;
1569
- parameters?: any;
1570
- }[];
1571
- context: {
1572
- value: string;
1573
- description: string;
1574
- }[];
1575
- parentRunId?: string | undefined;
1576
- state?: any;
1577
- forwardedProps?: any;
1578
- } | undefined;
1579
- } | {
1580
- type: EventType.RUN_FINISHED;
1581
- threadId: string;
1582
- runId: string;
1583
- timestamp?: number | undefined;
1584
- rawEvent?: any;
1585
- result?: any;
1586
- } | {
1587
- message: string;
1588
- type: EventType.RUN_ERROR;
1589
- code?: string | undefined;
1590
- timestamp?: number | undefined;
1591
- rawEvent?: any;
1592
- } | {
1593
- type: EventType.STEP_STARTED;
1594
- stepName: string;
1595
- timestamp?: number | undefined;
1596
- rawEvent?: any;
1597
- } | {
1598
- type: EventType.STEP_FINISHED;
1599
- stepName: string;
1600
- timestamp?: number | undefined;
1601
- rawEvent?: any;
1602
- } | {
1603
- type: EventType;
1604
- name: string;
1605
- value: any;
1606
- }>;
1607
- langGraphDefaultMergeState(state: State, messages: Message$1[], input: RunAgentInput): State<StateEnrichment & CopilotKitStateEnrichment>;
1608
- getSchemaKeys(): Promise<SchemaKeys>;
1378
+ /**
1379
+ * @deprecated LangGraphHttpAgent import from @copilotkit/runtime is deprecated. Please import it from @copilotkit/runtime/langgraph instead
1380
+ */
1381
+ declare class LangGraphHttpAgent {
1382
+ constructor();
1609
1383
  }
1384
+ /**
1385
+ * @deprecated TextMessageEvents import from @copilotkit/runtime is deprecated. Please import it from @copilotkit/runtime/langgraph instead
1386
+ */
1387
+ type TextMessageEvents = any;
1388
+ /**
1389
+ * @deprecated ToolCallEvents import from @copilotkit/runtime is deprecated. Please import it from @copilotkit/runtime/langgraph instead
1390
+ */
1391
+ type ToolCallEvents = any;
1392
+ /**
1393
+ * @deprecated CustomEventNames import from @copilotkit/runtime is deprecated. Please import it from @copilotkit/runtime/langgraph instead
1394
+ */
1395
+ type CustomEventNames = any;
1396
+ /**
1397
+ * @deprecated PredictStateTool import from @copilotkit/runtime is deprecated. Please import it from @copilotkit/runtime/langgraph instead
1398
+ */
1399
+ type PredictStateTool = any;
1610
1400
 
1611
1401
  declare class GuardrailsValidationFailureResponse extends FailedResponseStatus {
1612
1402
  reason: FailedResponseStatusReason;
@@ -1653,4 +1443,4 @@ declare class UnknownErrorResponse extends FailedResponseStatus {
1653
1443
  });
1654
1444
  }
1655
1445
 
1656
- export { AnthropicAdapter, AnthropicAdapterParams, AnthropicPromptCachingConfig, BedrockAdapter, BedrockAdapterParams, CommonConfig, CopilotRequestContextProperties, CopilotRuntime, CopilotRuntimeChatCompletionRequest, CopilotRuntimeChatCompletionResponse, CopilotRuntimeConstructorParams_BASE, CopilotRuntimeLogger, CopilotServiceAdapter, CreateCopilotRuntimeServerOptions, CustomEventNames, EmptyAdapter, ExperimentalEmptyAdapter, ExperimentalOllamaAdapter, GoogleGenerativeAIAdapter, GraphQLContext, GroqAdapter, GroqAdapterParams, GuardrailsValidationFailureResponse, LangChainAdapter, LangGraphAgent, LogLevel, MCPClient, MCPEndpointConfig, MCPTool, MessageStreamInterruptedResponse, OpenAIAdapter, OpenAIAdapterParams, OpenAIAssistantAdapter, OpenAIAssistantAdapterParams, PredictStateTool, RemoteChain, RemoteChainParameters, TextMessageEvents, ToolCallEvents, UnifyAdapter, UnifyAdapterParams, UnknownErrorResponse, addCustomHeaderPlugin, buildSchema, config, convertMCPToolsToActions, convertServiceAdapterError, copilotKitEndpoint, copilotRuntimeNestEndpoint, copilotRuntimeNextJSAppRouterEndpoint, copilotRuntimeNextJSPagesRouterEndpoint, copilotRuntimeNodeExpressEndpoint, copilotRuntimeNodeHttpEndpoint, createContext, createLogger, extractParametersFromSchema, generateMcpToolInstructions, getCommonConfig, langGraphPlatformEndpoint, readableStreamToNodeStream, resolveEndpointType };
1446
+ export { AnthropicAdapter, AnthropicAdapterParams, AnthropicPromptCachingConfig, BedrockAdapter, BedrockAdapterParams, CommonConfig, CopilotRequestContextProperties, CopilotRuntime, CopilotRuntimeChatCompletionRequest, CopilotRuntimeChatCompletionResponse, CopilotRuntimeConstructorParams_BASE, CopilotRuntimeLogger, CopilotServiceAdapter, CreateCopilotRuntimeServerOptions, CustomEventNames, EmptyAdapter, ExperimentalEmptyAdapter, ExperimentalOllamaAdapter, GoogleGenerativeAIAdapter, GraphQLContext, GroqAdapter, GroqAdapterParams, GuardrailsValidationFailureResponse, LangChainAdapter, LangGraphAgent, LangGraphHttpAgent, LogLevel, MCPClient, MCPEndpointConfig, MCPTool, MessageStreamInterruptedResponse, OpenAIAdapter, OpenAIAdapterParams, OpenAIAssistantAdapter, OpenAIAssistantAdapterParams, PredictStateTool, RemoteChain, RemoteChainParameters, TextMessageEvents, ToolCallEvents, UnifyAdapter, UnifyAdapterParams, UnknownErrorResponse, addCustomHeaderPlugin, buildSchema, config, convertMCPToolsToActions, convertServiceAdapterError, copilotKitEndpoint, copilotRuntimeNestEndpoint, copilotRuntimeNextJSAppRouterEndpoint, copilotRuntimeNextJSPagesRouterEndpoint, copilotRuntimeNodeExpressEndpoint, copilotRuntimeNodeHttpEndpoint, createContext, createLogger, extractParametersFromSchema, generateMcpToolInstructions, getCommonConfig, langGraphPlatformEndpoint, readableStreamToNodeStream, resolveEndpointType };