@copilotkit/runtime 0.0.0-fix-debug-infosys-20251107151227 → 0.0.0-fix-restore-handle-method-node-http-20251222114321
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 +259 -3
- package/dist/index.d.ts +1493 -28
- package/dist/index.js +2568 -5467
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5429 -99
- package/dist/index.mjs.map +1 -1
- package/dist/{lib/index.d.ts → langgraph.d.ts} +104 -32
- package/dist/langgraph.js +211 -0
- package/dist/langgraph.js.map +1 -0
- package/dist/{chunk-XPALJ76U.mjs → langgraph.mjs} +57 -26
- package/dist/langgraph.mjs.map +1 -0
- package/dist/v2/index.d.ts +2 -0
- package/dist/v2/index.js +22 -0
- package/dist/v2/index.js.map +1 -0
- package/dist/v2/index.mjs +5 -0
- package/dist/v2/index.mjs.map +1 -0
- package/package.json +64 -20
- package/src/graphql/message-conversion/agui-to-gql.test.ts +1263 -0
- package/src/graphql/message-conversion/agui-to-gql.ts +333 -0
- package/src/graphql/message-conversion/gql-to-agui.test.ts +1580 -0
- package/src/graphql/message-conversion/gql-to-agui.ts +278 -0
- package/src/graphql/message-conversion/index.ts +2 -0
- package/src/graphql/message-conversion/roundtrip-conversion.test.ts +526 -0
- package/src/graphql/resolvers/copilot.resolver.ts +3 -51
- package/src/graphql/resolvers/state.resolver.ts +3 -2
- package/src/graphql/types/converted/index.ts +32 -6
- package/src/graphql/types/enums.ts +2 -2
- package/src/graphql/types/message-status.type.ts +3 -1
- package/src/langgraph.ts +1 -0
- package/src/lib/index.ts +42 -1
- package/src/lib/integrations/nextjs/app-router.ts +12 -11
- package/src/lib/integrations/nextjs/pages-router.ts +4 -11
- package/src/lib/integrations/node-http/index.ts +10 -5
- package/src/lib/integrations/shared.ts +1 -1
- package/src/lib/observability.ts +87 -0
- package/src/lib/runtime/{langgraph/langgraph-agent.ts → agent-integrations/langgraph/agent.ts} +10 -30
- package/src/lib/runtime/agent-integrations/langgraph/consts.ts +34 -0
- package/src/lib/runtime/agent-integrations/langgraph/index.ts +2 -0
- package/src/lib/runtime/copilot-runtime.ts +387 -1360
- package/src/lib/runtime/telemetry-agent-runner.ts +139 -0
- package/src/lib/runtime/types.ts +49 -0
- package/src/lib/runtime/utils.ts +87 -0
- package/src/lib/telemetry-client.ts +6 -5
- package/src/service-adapters/anthropic/anthropic-adapter.ts +21 -4
- package/src/service-adapters/bedrock/bedrock-adapter.ts +10 -2
- package/src/service-adapters/empty/empty-adapter.ts +3 -0
- package/src/service-adapters/events.ts +0 -254
- package/src/service-adapters/experimental/ollama/ollama-adapter.ts +7 -2
- package/src/service-adapters/google/google-genai-adapter.ts +33 -7
- package/src/service-adapters/groq/groq-adapter.ts +21 -4
- package/src/service-adapters/langchain/langchain-adapter.ts +8 -3
- package/src/service-adapters/langchain/langserve.ts +2 -1
- package/src/service-adapters/openai/openai-adapter.ts +22 -4
- package/src/service-adapters/openai/openai-assistant-adapter.ts +30 -11
- package/src/service-adapters/service-adapter.ts +3 -0
- package/src/service-adapters/unify/unify-adapter.ts +9 -2
- package/src/v2/index.ts +3 -0
- package/tsup.config.ts +6 -2
- package/dist/chunk-27JKTS6P.mjs +0 -1704
- package/dist/chunk-27JKTS6P.mjs.map +0 -1
- package/dist/chunk-2DHC2YFK.mjs +0 -6026
- package/dist/chunk-2DHC2YFK.mjs.map +0 -1
- package/dist/chunk-2OZAGFV3.mjs +0 -43
- package/dist/chunk-2OZAGFV3.mjs.map +0 -1
- package/dist/chunk-5HHH4SZ3.mjs +0 -25
- package/dist/chunk-5HHH4SZ3.mjs.map +0 -1
- package/dist/chunk-AMUJQ6IR.mjs +0 -50
- package/dist/chunk-AMUJQ6IR.mjs.map +0 -1
- package/dist/chunk-FHD4JECV.mjs +0 -33
- package/dist/chunk-FHD4JECV.mjs.map +0 -1
- package/dist/chunk-FVG3IQG7.mjs +0 -25
- package/dist/chunk-FVG3IQG7.mjs.map +0 -1
- package/dist/chunk-QU2FLIQB.mjs +0 -80
- package/dist/chunk-QU2FLIQB.mjs.map +0 -1
- package/dist/chunk-SHBDMA63.mjs +0 -141
- package/dist/chunk-SHBDMA63.mjs.map +0 -1
- package/dist/chunk-XPALJ76U.mjs.map +0 -1
- package/dist/chunk-XWBDEXDA.mjs +0 -153
- package/dist/chunk-XWBDEXDA.mjs.map +0 -1
- package/dist/graphql/types/base/index.d.ts +0 -6
- package/dist/graphql/types/base/index.js +0 -63
- package/dist/graphql/types/base/index.js.map +0 -1
- package/dist/graphql/types/base/index.mjs +0 -8
- package/dist/graphql/types/base/index.mjs.map +0 -1
- package/dist/graphql/types/converted/index.d.ts +0 -2
- package/dist/graphql/types/converted/index.js +0 -200
- package/dist/graphql/types/converted/index.js.map +0 -1
- package/dist/graphql/types/converted/index.mjs +0 -19
- package/dist/graphql/types/converted/index.mjs.map +0 -1
- package/dist/groq-adapter-c8aec5c5.d.ts +0 -321
- package/dist/index-96b330da.d.ts +0 -119
- package/dist/langserve-0c6100e3.d.ts +0 -257
- package/dist/lib/cloud/index.d.ts +0 -6
- package/dist/lib/cloud/index.js +0 -18
- package/dist/lib/cloud/index.js.map +0 -1
- package/dist/lib/cloud/index.mjs +0 -1
- package/dist/lib/cloud/index.mjs.map +0 -1
- package/dist/lib/index.js +0 -7849
- package/dist/lib/index.js.map +0 -1
- package/dist/lib/index.mjs +0 -76
- package/dist/lib/index.mjs.map +0 -1
- package/dist/lib/integrations/index.d.ts +0 -34
- package/dist/lib/integrations/index.js +0 -3055
- package/dist/lib/integrations/index.js.map +0 -1
- package/dist/lib/integrations/index.mjs +0 -37
- package/dist/lib/integrations/index.mjs.map +0 -1
- package/dist/lib/integrations/nest/index.d.ts +0 -15
- package/dist/lib/integrations/nest/index.js +0 -2962
- package/dist/lib/integrations/nest/index.js.map +0 -1
- package/dist/lib/integrations/nest/index.mjs +0 -14
- package/dist/lib/integrations/nest/index.mjs.map +0 -1
- package/dist/lib/integrations/node-express/index.d.ts +0 -15
- package/dist/lib/integrations/node-express/index.js +0 -2962
- package/dist/lib/integrations/node-express/index.js.map +0 -1
- package/dist/lib/integrations/node-express/index.mjs +0 -14
- package/dist/lib/integrations/node-express/index.mjs.map +0 -1
- package/dist/lib/integrations/node-http/index.d.ts +0 -15
- package/dist/lib/integrations/node-http/index.js +0 -2948
- package/dist/lib/integrations/node-http/index.js.map +0 -1
- package/dist/lib/integrations/node-http/index.mjs +0 -13
- package/dist/lib/integrations/node-http/index.mjs.map +0 -1
- package/dist/service-adapters/index.d.ts +0 -162
- package/dist/service-adapters/index.js +0 -1787
- package/dist/service-adapters/index.js.map +0 -1
- package/dist/service-adapters/index.mjs +0 -34
- package/dist/service-adapters/index.mjs.map +0 -1
- package/dist/service-adapters/shared/index.d.ts +0 -9
- package/dist/service-adapters/shared/index.js +0 -72
- package/dist/service-adapters/shared/index.js.map +0 -1
- package/dist/service-adapters/shared/index.mjs +0 -8
- package/dist/service-adapters/shared/index.mjs.map +0 -1
- package/dist/shared-0a7346ce.d.ts +0 -466
- package/dist/utils/index.d.ts +0 -65
- package/dist/utils/index.js +0 -175
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/index.mjs +0 -12
- package/dist/utils/index.mjs.map +0 -1
- package/src/lib/runtime/__tests__/remote-action-constructors.test.ts +0 -246
- package/src/lib/runtime/agui-action.ts +0 -180
- package/src/lib/runtime/remote-action-constructors.ts +0 -331
- package/src/lib/runtime/remote-actions.ts +0 -217
- package/src/lib/runtime/remote-lg-action.ts +0 -1006
|
@@ -23,7 +23,6 @@ import {
|
|
|
23
23
|
CopilotRuntimeChatCompletionRequest,
|
|
24
24
|
CopilotRuntimeChatCompletionResponse,
|
|
25
25
|
} from "../../service-adapter";
|
|
26
|
-
import { Ollama } from "@langchain/community/llms/ollama";
|
|
27
26
|
import { randomId, randomUUID } from "@copilotkit/shared";
|
|
28
27
|
|
|
29
28
|
const DEFAULT_MODEL = "llama3:latest";
|
|
@@ -33,7 +32,11 @@ interface OllamaAdapterOptions {
|
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
export class ExperimentalOllamaAdapter implements CopilotServiceAdapter {
|
|
36
|
-
|
|
35
|
+
public model: string;
|
|
36
|
+
public provider = "ollama";
|
|
37
|
+
public get name() {
|
|
38
|
+
return "OllamaAdapter";
|
|
39
|
+
}
|
|
37
40
|
|
|
38
41
|
constructor(options?: OllamaAdapterOptions) {
|
|
39
42
|
if (options?.model) {
|
|
@@ -49,6 +52,8 @@ export class ExperimentalOllamaAdapter implements CopilotServiceAdapter {
|
|
|
49
52
|
const { messages, actions, eventSource } = request;
|
|
50
53
|
// const messages = this.transformMessages(forwardedProps.messages);
|
|
51
54
|
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
56
|
+
const { Ollama } = require("@langchain/community/llms/ollama");
|
|
52
57
|
const ollama = new Ollama({
|
|
53
58
|
model: this.model,
|
|
54
59
|
});
|
|
@@ -11,28 +11,52 @@
|
|
|
11
11
|
*
|
|
12
12
|
* const copilotKit = new CopilotRuntime();
|
|
13
13
|
*
|
|
14
|
-
* return new GoogleGenerativeAIAdapter({ model: "gemini-
|
|
14
|
+
* return new GoogleGenerativeAIAdapter({ model: "gemini-2.5-flash", apiVersion: "v1" });
|
|
15
15
|
* ```
|
|
16
16
|
*/
|
|
17
|
-
import { ChatGoogle } from "@langchain/google-gauth";
|
|
18
17
|
import { LangChainAdapter } from "../langchain/langchain-adapter";
|
|
19
|
-
import { AIMessage } from "@langchain/core/messages";
|
|
20
18
|
|
|
21
19
|
interface GoogleGenerativeAIAdapterOptions {
|
|
22
20
|
/**
|
|
23
21
|
* A custom Google Generative AI model to use.
|
|
24
22
|
*/
|
|
25
23
|
model?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The API version to use (e.g. "v1" or "v1beta"). Defaults to "v1".
|
|
26
|
+
*/
|
|
27
|
+
apiVersion?: "v1" | "v1beta";
|
|
26
28
|
/**
|
|
27
29
|
* The API key to use.
|
|
28
30
|
*/
|
|
29
31
|
apiKey?: string;
|
|
30
32
|
}
|
|
31
33
|
|
|
34
|
+
const DEFAULT_MODEL = "gemini-2.5-flash";
|
|
35
|
+
const DEFAULT_API_VERSION: GoogleGenerativeAIAdapterOptions["apiVersion"] = "v1";
|
|
36
|
+
let hasWarnedDefaultGoogleModel = false;
|
|
37
|
+
|
|
32
38
|
export class GoogleGenerativeAIAdapter extends LangChainAdapter {
|
|
39
|
+
public provider = "google";
|
|
40
|
+
public model: string = DEFAULT_MODEL;
|
|
41
|
+
|
|
33
42
|
constructor(options?: GoogleGenerativeAIAdapterOptions) {
|
|
43
|
+
if (!hasWarnedDefaultGoogleModel && !options?.model && !options?.apiVersion) {
|
|
44
|
+
console.warn(
|
|
45
|
+
`You are using the GoogleGenerativeAIAdapter without explicitly setting a model or apiVersion. ` +
|
|
46
|
+
`CopilotKit will default to apiVersion="v1" and model="${DEFAULT_MODEL}". ` +
|
|
47
|
+
`To silence this warning, pass model and apiVersion when constructing the adapter.`,
|
|
48
|
+
);
|
|
49
|
+
hasWarnedDefaultGoogleModel = true;
|
|
50
|
+
}
|
|
51
|
+
|
|
34
52
|
super({
|
|
35
53
|
chainFn: async ({ messages, tools, threadId }) => {
|
|
54
|
+
// Lazy require for optional peer dependencies
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
56
|
+
const { ChatGoogle } = require("@langchain/google-gauth");
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
58
|
+
const { AIMessage } = require("@langchain/core/messages");
|
|
59
|
+
|
|
36
60
|
// Filter out empty assistant messages to prevent Gemini validation errors
|
|
37
61
|
// Gemini specifically rejects conversations containing AIMessages with empty content
|
|
38
62
|
const filteredMessages = messages.filter((message) => {
|
|
@@ -43,16 +67,18 @@ export class GoogleGenerativeAIAdapter extends LangChainAdapter {
|
|
|
43
67
|
|
|
44
68
|
// For AIMessages, only keep those with non-empty content
|
|
45
69
|
// Also keep AIMessages with tool_calls even if content is empty
|
|
70
|
+
const aiMsg = message as any;
|
|
46
71
|
return (
|
|
47
|
-
(
|
|
48
|
-
(
|
|
72
|
+
(aiMsg.content && String(aiMsg.content).trim().length > 0) ||
|
|
73
|
+
(aiMsg.tool_calls && aiMsg.tool_calls.length > 0)
|
|
49
74
|
);
|
|
50
75
|
});
|
|
51
76
|
|
|
77
|
+
this.model = options?.model ?? DEFAULT_MODEL;
|
|
52
78
|
const model = new ChatGoogle({
|
|
53
79
|
apiKey: options?.apiKey ?? process.env.GOOGLE_API_KEY,
|
|
54
|
-
modelName:
|
|
55
|
-
apiVersion:
|
|
80
|
+
modelName: this.model,
|
|
81
|
+
apiVersion: options?.apiVersion ?? DEFAULT_API_VERSION,
|
|
56
82
|
}).bindTools(tools);
|
|
57
83
|
|
|
58
84
|
return model.stream(filteredMessages, { metadata: { conversation_id: threadId } });
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* return new GroqAdapter({ groq, model: "<model-name>" });
|
|
15
15
|
* ```
|
|
16
16
|
*/
|
|
17
|
-
import { Groq } from "groq-sdk";
|
|
17
|
+
import type { Groq } from "groq-sdk";
|
|
18
18
|
import type { ChatCompletionMessageParam } from "groq-sdk/resources/chat";
|
|
19
19
|
import {
|
|
20
20
|
CopilotServiceAdapter,
|
|
@@ -54,22 +54,38 @@ export interface GroqAdapterParams {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
export class GroqAdapter implements CopilotServiceAdapter {
|
|
57
|
-
|
|
57
|
+
public model: string = DEFAULT_MODEL;
|
|
58
|
+
public provider = "groq";
|
|
58
59
|
|
|
59
60
|
private disableParallelToolCalls: boolean = false;
|
|
60
61
|
private _groq: Groq;
|
|
61
62
|
public get groq(): Groq {
|
|
62
63
|
return this._groq;
|
|
63
64
|
}
|
|
65
|
+
public get name() {
|
|
66
|
+
return "GroqAdapter";
|
|
67
|
+
}
|
|
64
68
|
|
|
65
69
|
constructor(params?: GroqAdapterParams) {
|
|
66
|
-
|
|
70
|
+
if (params?.groq) {
|
|
71
|
+
this._groq = params.groq;
|
|
72
|
+
}
|
|
73
|
+
// If no instance provided, we'll lazy-load in ensureGroq()
|
|
67
74
|
if (params?.model) {
|
|
68
75
|
this.model = params.model;
|
|
69
76
|
}
|
|
70
77
|
this.disableParallelToolCalls = params?.disableParallelToolCalls || false;
|
|
71
78
|
}
|
|
72
79
|
|
|
80
|
+
private ensureGroq(): Groq {
|
|
81
|
+
if (!this._groq) {
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
83
|
+
const { Groq } = require("groq-sdk");
|
|
84
|
+
this._groq = new Groq({});
|
|
85
|
+
}
|
|
86
|
+
return this._groq;
|
|
87
|
+
}
|
|
88
|
+
|
|
73
89
|
async process(
|
|
74
90
|
request: CopilotRuntimeChatCompletionRequest,
|
|
75
91
|
): Promise<CopilotRuntimeChatCompletionResponse> {
|
|
@@ -97,7 +113,8 @@ export class GroqAdapter implements CopilotServiceAdapter {
|
|
|
97
113
|
}
|
|
98
114
|
let stream;
|
|
99
115
|
try {
|
|
100
|
-
|
|
116
|
+
const groq = this.ensureGroq();
|
|
117
|
+
stream = await groq.chat.completions.create({
|
|
101
118
|
model: model,
|
|
102
119
|
stream: true,
|
|
103
120
|
messages: openaiMessages as unknown as ChatCompletionMessageParam[],
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
* - A LangChain `AIMessage` object
|
|
32
32
|
*/
|
|
33
33
|
|
|
34
|
-
import { BaseMessage } from "@langchain/core/messages";
|
|
34
|
+
import type { BaseMessage } from "@langchain/core/messages";
|
|
35
35
|
import { CopilotServiceAdapter } from "../service-adapter";
|
|
36
36
|
import {
|
|
37
37
|
CopilotRuntimeChatCompletionRequest,
|
|
@@ -42,10 +42,9 @@ import {
|
|
|
42
42
|
convertMessageToLangChainMessage,
|
|
43
43
|
streamLangChainResponse,
|
|
44
44
|
} from "./utils";
|
|
45
|
-
import { DynamicStructuredTool } from "@langchain/core/tools";
|
|
45
|
+
import type { DynamicStructuredTool } from "@langchain/core/tools";
|
|
46
46
|
import { LangChainReturnType } from "./types";
|
|
47
47
|
import { randomUUID } from "@copilotkit/shared";
|
|
48
|
-
import { awaitAllCallbacks } from "@langchain/core/callbacks/promises";
|
|
49
48
|
|
|
50
49
|
interface ChainFnParameters {
|
|
51
50
|
model: string;
|
|
@@ -66,6 +65,9 @@ export class LangChainAdapter implements CopilotServiceAdapter {
|
|
|
66
65
|
/**
|
|
67
66
|
* To use LangChain as a backend, provide a handler function to the adapter with your custom LangChain logic.
|
|
68
67
|
*/
|
|
68
|
+
public get name() {
|
|
69
|
+
return "LangChainAdapter";
|
|
70
|
+
}
|
|
69
71
|
constructor(private options: LangChainAdapterOptions) {}
|
|
70
72
|
|
|
71
73
|
async process(
|
|
@@ -100,6 +102,9 @@ export class LangChainAdapter implements CopilotServiceAdapter {
|
|
|
100
102
|
threadId,
|
|
101
103
|
};
|
|
102
104
|
} finally {
|
|
105
|
+
// Lazy require for optional peer dependency
|
|
106
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
107
|
+
const { awaitAllCallbacks } = require("@langchain/core/callbacks/promises");
|
|
103
108
|
await awaitAllCallbacks();
|
|
104
109
|
}
|
|
105
110
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Parameter, Action } from "@copilotkit/shared";
|
|
2
|
-
import { RemoteRunnable } from "langchain/runnables/remote";
|
|
3
2
|
|
|
4
3
|
export interface RemoteChainParameters {
|
|
5
4
|
name: string;
|
|
@@ -34,6 +33,8 @@ export class RemoteChain {
|
|
|
34
33
|
description: this.description,
|
|
35
34
|
parameters: this.parameters!,
|
|
36
35
|
handler: async (args: any) => {
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
37
|
+
const { RemoteRunnable } = require("langchain/runnables/remote");
|
|
37
38
|
const runnable = new RemoteRunnable({ url: this.chainUrl });
|
|
38
39
|
let input: any;
|
|
39
40
|
if (this.parameterType === "single") {
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
* return new OpenAIAdapter({ openai });
|
|
49
49
|
* ```
|
|
50
50
|
*/
|
|
51
|
-
import OpenAI from "openai";
|
|
51
|
+
import type OpenAI from "openai";
|
|
52
52
|
import {
|
|
53
53
|
CopilotServiceAdapter,
|
|
54
54
|
CopilotRuntimeChatCompletionRequest,
|
|
@@ -96,7 +96,8 @@ export interface OpenAIAdapterParams {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
export class OpenAIAdapter implements CopilotServiceAdapter {
|
|
99
|
-
|
|
99
|
+
public model: string = DEFAULT_MODEL;
|
|
100
|
+
public provider = "openai";
|
|
100
101
|
|
|
101
102
|
private disableParallelToolCalls: boolean = false;
|
|
102
103
|
private _openai: OpenAI;
|
|
@@ -105,9 +106,16 @@ export class OpenAIAdapter implements CopilotServiceAdapter {
|
|
|
105
106
|
public get openai(): OpenAI {
|
|
106
107
|
return this._openai;
|
|
107
108
|
}
|
|
109
|
+
public get name() {
|
|
110
|
+
return "OpenAIAdapter";
|
|
111
|
+
}
|
|
108
112
|
|
|
109
113
|
constructor(params?: OpenAIAdapterParams) {
|
|
110
|
-
|
|
114
|
+
if (params?.openai) {
|
|
115
|
+
this._openai = params.openai;
|
|
116
|
+
}
|
|
117
|
+
// If no instance provided, we'll lazy-load in ensureOpenAI()
|
|
118
|
+
|
|
111
119
|
if (params?.model) {
|
|
112
120
|
this.model = params.model;
|
|
113
121
|
}
|
|
@@ -115,6 +123,15 @@ export class OpenAIAdapter implements CopilotServiceAdapter {
|
|
|
115
123
|
this.keepSystemRole = params?.keepSystemRole ?? false;
|
|
116
124
|
}
|
|
117
125
|
|
|
126
|
+
private ensureOpenAI(): OpenAI {
|
|
127
|
+
if (!this._openai) {
|
|
128
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
129
|
+
const OpenAI = require("openai").default;
|
|
130
|
+
this._openai = new OpenAI();
|
|
131
|
+
}
|
|
132
|
+
return this._openai;
|
|
133
|
+
}
|
|
134
|
+
|
|
118
135
|
async process(
|
|
119
136
|
request: CopilotRuntimeChatCompletionRequest,
|
|
120
137
|
): Promise<CopilotRuntimeChatCompletionResponse> {
|
|
@@ -170,7 +187,8 @@ export class OpenAIAdapter implements CopilotServiceAdapter {
|
|
|
170
187
|
}
|
|
171
188
|
|
|
172
189
|
try {
|
|
173
|
-
const
|
|
190
|
+
const openai = this.ensureOpenAI();
|
|
191
|
+
const stream = openai.beta.chat.completions.stream({
|
|
174
192
|
model: model,
|
|
175
193
|
stream: true,
|
|
176
194
|
messages: openaiMessages,
|
|
@@ -22,7 +22,10 @@
|
|
|
22
22
|
* });
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
|
-
import OpenAI from "openai";
|
|
25
|
+
import type OpenAI from "openai";
|
|
26
|
+
import type { RunSubmitToolOutputsStreamParams } from "openai/resources/beta/threads/runs/runs";
|
|
27
|
+
import type { AssistantStream } from "openai/lib/AssistantStream";
|
|
28
|
+
import type { AssistantStreamEvent, AssistantTool } from "openai/resources/beta/assistants";
|
|
26
29
|
import {
|
|
27
30
|
CopilotServiceAdapter,
|
|
28
31
|
CopilotRuntimeChatCompletionRequest,
|
|
@@ -34,11 +37,8 @@ import {
|
|
|
34
37
|
convertMessageToOpenAIMessage,
|
|
35
38
|
convertSystemMessageToAssistantAPI,
|
|
36
39
|
} from "./utils";
|
|
37
|
-
import { RunSubmitToolOutputsStreamParams } from "openai/resources/beta/threads/runs/runs";
|
|
38
|
-
import { AssistantStream } from "openai/lib/AssistantStream";
|
|
39
40
|
import { RuntimeEventSource } from "../events";
|
|
40
41
|
import { ActionInput } from "../../graphql/inputs/action.input";
|
|
41
|
-
import { AssistantStreamEvent, AssistantTool } from "openai/resources/beta/assistants";
|
|
42
42
|
import { ForwardedParametersInput } from "../../graphql/inputs/forwarded-parameters.input";
|
|
43
43
|
|
|
44
44
|
export interface OpenAIAssistantAdapterParams {
|
|
@@ -84,15 +84,22 @@ export interface OpenAIAssistantAdapterParams {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
export class OpenAIAssistantAdapter implements CopilotServiceAdapter {
|
|
87
|
-
private
|
|
87
|
+
private _openai: OpenAI;
|
|
88
88
|
private codeInterpreterEnabled: boolean;
|
|
89
89
|
private assistantId: string;
|
|
90
90
|
private fileSearchEnabled: boolean;
|
|
91
91
|
private disableParallelToolCalls: boolean;
|
|
92
92
|
private keepSystemRole: boolean = false;
|
|
93
93
|
|
|
94
|
+
public get name() {
|
|
95
|
+
return "OpenAIAssistantAdapter";
|
|
96
|
+
}
|
|
97
|
+
|
|
94
98
|
constructor(params: OpenAIAssistantAdapterParams) {
|
|
95
|
-
|
|
99
|
+
if (params.openai) {
|
|
100
|
+
this._openai = params.openai;
|
|
101
|
+
}
|
|
102
|
+
// If no instance provided, we'll lazy-load in ensureOpenAI()
|
|
96
103
|
this.codeInterpreterEnabled = params.codeInterpreterEnabled === false || true;
|
|
97
104
|
this.fileSearchEnabled = params.fileSearchEnabled === false || true;
|
|
98
105
|
this.assistantId = params.assistantId;
|
|
@@ -100,6 +107,15 @@ export class OpenAIAssistantAdapter implements CopilotServiceAdapter {
|
|
|
100
107
|
this.keepSystemRole = params?.keepSystemRole ?? false;
|
|
101
108
|
}
|
|
102
109
|
|
|
110
|
+
private ensureOpenAI(): OpenAI {
|
|
111
|
+
if (!this._openai) {
|
|
112
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
113
|
+
const OpenAI = require("openai").default;
|
|
114
|
+
this._openai = new OpenAI({});
|
|
115
|
+
}
|
|
116
|
+
return this._openai;
|
|
117
|
+
}
|
|
118
|
+
|
|
103
119
|
async process(
|
|
104
120
|
request: CopilotRuntimeChatCompletionRequest,
|
|
105
121
|
): Promise<CopilotRuntimeChatCompletionResponse> {
|
|
@@ -107,9 +123,10 @@ export class OpenAIAssistantAdapter implements CopilotServiceAdapter {
|
|
|
107
123
|
|
|
108
124
|
// if we don't have a threadId, create a new thread
|
|
109
125
|
let threadId = request.extensions?.openaiAssistantAPI?.threadId;
|
|
126
|
+
const openai = this.ensureOpenAI();
|
|
110
127
|
|
|
111
128
|
if (!threadId) {
|
|
112
|
-
threadId = (await
|
|
129
|
+
threadId = (await openai.beta.threads.create()).id;
|
|
113
130
|
}
|
|
114
131
|
|
|
115
132
|
const lastMessage = messages.at(-1);
|
|
@@ -154,7 +171,8 @@ export class OpenAIAssistantAdapter implements CopilotServiceAdapter {
|
|
|
154
171
|
messages: Message[],
|
|
155
172
|
eventSource: RuntimeEventSource,
|
|
156
173
|
) {
|
|
157
|
-
|
|
174
|
+
const openai = this.ensureOpenAI();
|
|
175
|
+
let run = await openai.beta.threads.runs.retrieve(threadId, runId);
|
|
158
176
|
|
|
159
177
|
if (!run.required_action) {
|
|
160
178
|
throw new Error("No tool outputs required");
|
|
@@ -184,7 +202,7 @@ export class OpenAIAssistantAdapter implements CopilotServiceAdapter {
|
|
|
184
202
|
},
|
|
185
203
|
);
|
|
186
204
|
|
|
187
|
-
const stream =
|
|
205
|
+
const stream = openai.beta.threads.runs.submitToolOutputsStream(threadId, runId, {
|
|
188
206
|
tool_outputs: toolOutputs,
|
|
189
207
|
...(this.disableParallelToolCalls && { parallel_tool_calls: false }),
|
|
190
208
|
});
|
|
@@ -200,6 +218,7 @@ export class OpenAIAssistantAdapter implements CopilotServiceAdapter {
|
|
|
200
218
|
eventSource: RuntimeEventSource,
|
|
201
219
|
forwardedParameters: ForwardedParametersInput,
|
|
202
220
|
) {
|
|
221
|
+
const openai = this.ensureOpenAI();
|
|
203
222
|
messages = [...messages];
|
|
204
223
|
|
|
205
224
|
// get the instruction message
|
|
@@ -216,7 +235,7 @@ export class OpenAIAssistantAdapter implements CopilotServiceAdapter {
|
|
|
216
235
|
throw new Error("No user message found");
|
|
217
236
|
}
|
|
218
237
|
|
|
219
|
-
await
|
|
238
|
+
await openai.beta.threads.messages.create(threadId, {
|
|
220
239
|
role: "user",
|
|
221
240
|
content: userMessage.content,
|
|
222
241
|
});
|
|
@@ -229,7 +248,7 @@ export class OpenAIAssistantAdapter implements CopilotServiceAdapter {
|
|
|
229
248
|
...(this.fileSearchEnabled ? [{ type: "file_search" } as AssistantTool] : []),
|
|
230
249
|
];
|
|
231
250
|
|
|
232
|
-
let stream =
|
|
251
|
+
let stream = openai.beta.threads.runs.stream(threadId, {
|
|
233
252
|
assistant_id: this.assistantId,
|
|
234
253
|
instructions,
|
|
235
254
|
tools: tools,
|
|
@@ -32,7 +32,10 @@ export interface CopilotRuntimeChatCompletionResponse {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
export interface CopilotServiceAdapter {
|
|
35
|
+
provider?: string;
|
|
36
|
+
model?: string;
|
|
35
37
|
process(
|
|
36
38
|
request: CopilotRuntimeChatCompletionRequest,
|
|
37
39
|
): Promise<CopilotRuntimeChatCompletionResponse>;
|
|
40
|
+
name?: string;
|
|
38
41
|
}
|
|
@@ -22,7 +22,6 @@ import {
|
|
|
22
22
|
CopilotRuntimeChatCompletionResponse,
|
|
23
23
|
CopilotServiceAdapter,
|
|
24
24
|
} from "../service-adapter";
|
|
25
|
-
import OpenAI from "openai";
|
|
26
25
|
import { randomId, randomUUID } from "@copilotkit/shared";
|
|
27
26
|
import { convertActionInputToOpenAITool, convertMessageToOpenAIMessage } from "../openai/utils";
|
|
28
27
|
|
|
@@ -33,8 +32,13 @@ export interface UnifyAdapterParams {
|
|
|
33
32
|
|
|
34
33
|
export class UnifyAdapter implements CopilotServiceAdapter {
|
|
35
34
|
private apiKey: string;
|
|
36
|
-
|
|
35
|
+
public model: string;
|
|
37
36
|
private start: boolean;
|
|
37
|
+
public provider = "unify";
|
|
38
|
+
|
|
39
|
+
public get name() {
|
|
40
|
+
return "UnifyAdapter";
|
|
41
|
+
}
|
|
38
42
|
|
|
39
43
|
constructor(options?: UnifyAdapterParams) {
|
|
40
44
|
if (options?.apiKey) {
|
|
@@ -50,6 +54,9 @@ export class UnifyAdapter implements CopilotServiceAdapter {
|
|
|
50
54
|
request: CopilotRuntimeChatCompletionRequest,
|
|
51
55
|
): Promise<CopilotRuntimeChatCompletionResponse> {
|
|
52
56
|
const tools = request.actions.map(convertActionInputToOpenAITool);
|
|
57
|
+
// Lazy require for optional peer dependency
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
59
|
+
const OpenAI = require("openai").default;
|
|
53
60
|
const openai = new OpenAI({
|
|
54
61
|
apiKey: this.apiKey,
|
|
55
62
|
baseURL: "https://api.unify.ai/v0/",
|
package/src/v2/index.ts
ADDED
package/tsup.config.ts
CHANGED
|
@@ -2,15 +2,19 @@ import { defineConfig, Options } from "tsup";
|
|
|
2
2
|
|
|
3
3
|
export default defineConfig((options: Options) => ({
|
|
4
4
|
...options,
|
|
5
|
-
entry: ["src
|
|
5
|
+
entry: ["src/index.ts", "src/v2/index.ts", "src/langgraph.ts"],
|
|
6
6
|
format: ["esm", "cjs"],
|
|
7
7
|
dts: true,
|
|
8
8
|
minify: false,
|
|
9
|
-
external: [],
|
|
9
|
+
external: ["@ag-ui/langgraph"],
|
|
10
10
|
sourcemap: true,
|
|
11
11
|
exclude: [
|
|
12
12
|
"**/*.test.ts", // Exclude TypeScript test files
|
|
13
13
|
"**/*.test.tsx", // Exclude TypeScript React test files
|
|
14
14
|
"**/__tests__/*", // Exclude any files inside a __tests__ directory
|
|
15
15
|
],
|
|
16
|
+
treeshake: true,
|
|
17
|
+
// Disable code splitting so each entry point is fully independent
|
|
18
|
+
// This prevents @ag-ui/langgraph from being pulled into index.mjs via shared chunks
|
|
19
|
+
splitting: false,
|
|
16
20
|
}));
|