@copilotkit/runtime 0.0.0-test-custom-tag-prerelease-1-20250108200215
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/.eslintrc.js +7 -0
- package/CHANGELOG.md +729 -0
- package/README.md +46 -0
- package/__snapshots__/schema/schema.graphql +262 -0
- package/dist/chunk-2WXVJKUZ.mjs +25 -0
- package/dist/chunk-2WXVJKUZ.mjs.map +1 -0
- package/dist/chunk-44O2JGUY.mjs +12 -0
- package/dist/chunk-44O2JGUY.mjs.map +1 -0
- package/dist/chunk-CLGKEUOA.mjs +1408 -0
- package/dist/chunk-CLGKEUOA.mjs.map +1 -0
- package/dist/chunk-D2WLFQS6.mjs +43 -0
- package/dist/chunk-D2WLFQS6.mjs.map +1 -0
- package/dist/chunk-DFOKBSIS.mjs +1 -0
- package/dist/chunk-DFOKBSIS.mjs.map +1 -0
- package/dist/chunk-RFF5IIZJ.mjs +66 -0
- package/dist/chunk-RFF5IIZJ.mjs.map +1 -0
- package/dist/chunk-U3V2BCGI.mjs +152 -0
- package/dist/chunk-U3V2BCGI.mjs.map +1 -0
- package/dist/chunk-UYX3NHOI.mjs +25 -0
- package/dist/chunk-UYX3NHOI.mjs.map +1 -0
- package/dist/chunk-W3GSZTZR.mjs +3281 -0
- package/dist/chunk-W3GSZTZR.mjs.map +1 -0
- package/dist/chunk-WPNQ4AMN.mjs +80 -0
- package/dist/chunk-WPNQ4AMN.mjs.map +1 -0
- package/dist/copilot-runtime-6285d897.d.ts +189 -0
- package/dist/graphql/types/base/index.d.ts +6 -0
- package/dist/graphql/types/base/index.js +63 -0
- package/dist/graphql/types/base/index.js.map +1 -0
- package/dist/graphql/types/base/index.mjs +8 -0
- package/dist/graphql/types/base/index.mjs.map +1 -0
- package/dist/graphql/types/converted/index.d.ts +2 -0
- package/dist/graphql/types/converted/index.js +124 -0
- package/dist/graphql/types/converted/index.js.map +1 -0
- package/dist/graphql/types/converted/index.mjs +17 -0
- package/dist/graphql/types/converted/index.mjs.map +1 -0
- package/dist/groq-adapter-15d41154.d.ts +281 -0
- package/dist/index-ff3fbc33.d.ts +87 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +5039 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +76 -0
- package/dist/index.mjs.map +1 -0
- package/dist/langserve-48e976ac.d.ts +176 -0
- package/dist/lib/cloud/index.d.ts +6 -0
- package/dist/lib/cloud/index.js +18 -0
- package/dist/lib/cloud/index.js.map +1 -0
- package/dist/lib/cloud/index.mjs +1 -0
- package/dist/lib/cloud/index.mjs.map +1 -0
- package/dist/lib/index.d.ts +20 -0
- package/dist/lib/index.js +4687 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/index.mjs +58 -0
- package/dist/lib/index.mjs.map +1 -0
- package/dist/lib/integrations/index.d.ts +33 -0
- package/dist/lib/integrations/index.js +2091 -0
- package/dist/lib/integrations/index.js.map +1 -0
- package/dist/lib/integrations/index.mjs +34 -0
- package/dist/lib/integrations/index.mjs.map +1 -0
- package/dist/lib/integrations/nest/index.d.ts +14 -0
- package/dist/lib/integrations/nest/index.js +2000 -0
- package/dist/lib/integrations/nest/index.js.map +1 -0
- package/dist/lib/integrations/nest/index.mjs +13 -0
- package/dist/lib/integrations/nest/index.mjs.map +1 -0
- package/dist/lib/integrations/node-express/index.d.ts +14 -0
- package/dist/lib/integrations/node-express/index.js +2000 -0
- package/dist/lib/integrations/node-express/index.js.map +1 -0
- package/dist/lib/integrations/node-express/index.mjs +13 -0
- package/dist/lib/integrations/node-express/index.mjs.map +1 -0
- package/dist/lib/integrations/node-http/index.d.ts +14 -0
- package/dist/lib/integrations/node-http/index.js +1986 -0
- package/dist/lib/integrations/node-http/index.js.map +1 -0
- package/dist/lib/integrations/node-http/index.mjs +12 -0
- package/dist/lib/integrations/node-http/index.mjs.map +1 -0
- package/dist/service-adapters/index.d.ts +84 -0
- package/dist/service-adapters/index.js +1448 -0
- package/dist/service-adapters/index.js.map +1 -0
- package/dist/service-adapters/index.mjs +26 -0
- package/dist/service-adapters/index.mjs.map +1 -0
- package/dist/utils/index.d.ts +49 -0
- package/dist/utils/index.js +174 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/index.mjs +12 -0
- package/dist/utils/index.mjs.map +1 -0
- package/jest.config.js +5 -0
- package/package.json +85 -0
- package/scripts/generate-gql-schema.ts +13 -0
- package/src/agents/langgraph/event-source.ts +287 -0
- package/src/agents/langgraph/events.ts +338 -0
- package/src/graphql/inputs/action.input.ts +16 -0
- package/src/graphql/inputs/agent-session.input.ts +13 -0
- package/src/graphql/inputs/agent-state.input.ts +10 -0
- package/src/graphql/inputs/cloud-guardrails.input.ts +16 -0
- package/src/graphql/inputs/cloud.input.ts +8 -0
- package/src/graphql/inputs/context-property.input.ts +10 -0
- package/src/graphql/inputs/custom-property.input.ts +15 -0
- package/src/graphql/inputs/forwarded-parameters.input.ts +22 -0
- package/src/graphql/inputs/frontend.input.ts +14 -0
- package/src/graphql/inputs/generate-copilot-response.input.ts +47 -0
- package/src/graphql/inputs/message.input.ts +92 -0
- package/src/graphql/resolvers/copilot.resolver.ts +540 -0
- package/src/graphql/types/base/index.ts +10 -0
- package/src/graphql/types/converted/index.ts +70 -0
- package/src/graphql/types/copilot-response.type.ts +113 -0
- package/src/graphql/types/enums.ts +37 -0
- package/src/graphql/types/guardrails-result.type.ts +20 -0
- package/src/graphql/types/message-status.type.ts +40 -0
- package/src/graphql/types/response-status.type.ts +66 -0
- package/src/index.ts +4 -0
- package/src/lib/cloud/index.ts +4 -0
- package/src/lib/index.ts +8 -0
- package/src/lib/integrations/index.ts +6 -0
- package/src/lib/integrations/nest/index.ts +17 -0
- package/src/lib/integrations/nextjs/app-router.ts +40 -0
- package/src/lib/integrations/nextjs/pages-router.ts +49 -0
- package/src/lib/integrations/node-express/index.ts +17 -0
- package/src/lib/integrations/node-http/index.ts +34 -0
- package/src/lib/integrations/shared.ts +109 -0
- package/src/lib/logger.ts +28 -0
- package/src/lib/runtime/copilot-runtime.ts +412 -0
- package/src/lib/runtime/remote-action-constructors.ts +304 -0
- package/src/lib/runtime/remote-actions.ts +174 -0
- package/src/lib/runtime/remote-lg-action.ts +657 -0
- package/src/lib/telemetry-client.ts +52 -0
- package/src/service-adapters/anthropic/anthropic-adapter.ts +205 -0
- package/src/service-adapters/anthropic/utils.ts +144 -0
- package/src/service-adapters/conversion.ts +64 -0
- package/src/service-adapters/events.ts +377 -0
- package/src/service-adapters/experimental/empty/empty-adapter.ts +33 -0
- package/src/service-adapters/experimental/ollama/ollama-adapter.ts +79 -0
- package/src/service-adapters/google/google-genai-adapter.ts +39 -0
- package/src/service-adapters/groq/groq-adapter.ts +173 -0
- package/src/service-adapters/index.ts +16 -0
- package/src/service-adapters/langchain/langchain-adapter.ts +99 -0
- package/src/service-adapters/langchain/langserve.ts +87 -0
- package/src/service-adapters/langchain/types.ts +14 -0
- package/src/service-adapters/langchain/utils.ts +306 -0
- package/src/service-adapters/openai/openai-adapter.ts +210 -0
- package/src/service-adapters/openai/openai-assistant-adapter.ts +304 -0
- package/src/service-adapters/openai/utils.ts +161 -0
- package/src/service-adapters/service-adapter.ts +30 -0
- package/src/service-adapters/unify/unify-adapter.ts +145 -0
- package/src/utils/failed-response-status-reasons.ts +48 -0
- package/src/utils/index.ts +1 -0
- package/tsconfig.json +11 -0
- package/tsup.config.ts +16 -0
- package/typedoc.json +4 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { Action } from "@copilotkit/shared";
|
|
2
|
+
import { GraphQLContext } from "../integrations/shared";
|
|
3
|
+
import { Logger } from "pino";
|
|
4
|
+
import { Message } from "../../graphql/types/converted";
|
|
5
|
+
import { RuntimeEvent } from "../../service-adapters/events";
|
|
6
|
+
import { Observable } from "rxjs";
|
|
7
|
+
import { ActionInput } from "../../graphql/inputs/action.input";
|
|
8
|
+
import { AgentStateInput } from "../../graphql/inputs/agent-state.input";
|
|
9
|
+
import {
|
|
10
|
+
constructLGCRemoteAction,
|
|
11
|
+
constructRemoteActions,
|
|
12
|
+
createHeaders,
|
|
13
|
+
} from "./remote-action-constructors";
|
|
14
|
+
|
|
15
|
+
export type EndpointDefinition = CopilotKitEndpoint | LangGraphPlatformEndpoint;
|
|
16
|
+
|
|
17
|
+
export enum EndpointType {
|
|
18
|
+
CopilotKit = "copilotKit",
|
|
19
|
+
LangGraphPlatform = "langgraph-platform",
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface BaseEndpointDefinition<TActionType extends EndpointType> {
|
|
23
|
+
type?: TActionType;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface CopilotKitEndpoint extends BaseEndpointDefinition<EndpointType.CopilotKit> {
|
|
27
|
+
url: string;
|
|
28
|
+
onBeforeRequest?: ({ ctx }: { ctx: GraphQLContext }) => {
|
|
29
|
+
headers?: Record<string, string> | undefined;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface LangGraphPlatformAgent {
|
|
34
|
+
name: string;
|
|
35
|
+
description: string;
|
|
36
|
+
assistantId?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface LangGraphPlatformEndpoint
|
|
40
|
+
extends BaseEndpointDefinition<EndpointType.LangGraphPlatform> {
|
|
41
|
+
deploymentUrl: string;
|
|
42
|
+
langsmithApiKey: string;
|
|
43
|
+
agents: LangGraphPlatformAgent[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export type RemoteActionInfoResponse = {
|
|
47
|
+
actions: any[];
|
|
48
|
+
agents: any[];
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export type LangGraphAgentHandlerParams = {
|
|
52
|
+
name: string;
|
|
53
|
+
actionInputsWithoutAgents: ActionInput[];
|
|
54
|
+
threadId?: string;
|
|
55
|
+
nodeName?: string;
|
|
56
|
+
additionalMessages?: Message[];
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type LangGraphAgentAction = Action<any> & {
|
|
60
|
+
langGraphAgentHandler: (params: LangGraphAgentHandlerParams) => Promise<Observable<RuntimeEvent>>;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export function isLangGraphAgentAction(action: Action<any>): action is LangGraphAgentAction {
|
|
64
|
+
if (!action) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
return typeof (action as LangGraphAgentAction).langGraphAgentHandler === "function";
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function fetchRemoteInfo({
|
|
71
|
+
url,
|
|
72
|
+
onBeforeRequest,
|
|
73
|
+
graphqlContext,
|
|
74
|
+
logger,
|
|
75
|
+
frontendUrl,
|
|
76
|
+
}: {
|
|
77
|
+
url: string;
|
|
78
|
+
onBeforeRequest?: CopilotKitEndpoint["onBeforeRequest"];
|
|
79
|
+
graphqlContext: GraphQLContext;
|
|
80
|
+
logger: Logger;
|
|
81
|
+
frontendUrl?: string;
|
|
82
|
+
}): Promise<RemoteActionInfoResponse> {
|
|
83
|
+
logger.debug({ url }, "Fetching actions from url");
|
|
84
|
+
const headers = createHeaders(onBeforeRequest, graphqlContext);
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
const response = await fetch(`${url}/info`, {
|
|
88
|
+
method: "POST",
|
|
89
|
+
headers,
|
|
90
|
+
body: JSON.stringify({ properties: graphqlContext.properties, frontendUrl }),
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
if (!response.ok) {
|
|
94
|
+
logger.error(
|
|
95
|
+
{ url, status: response.status, body: await response.text() },
|
|
96
|
+
"Failed to fetch actions from url",
|
|
97
|
+
);
|
|
98
|
+
return { actions: [], agents: [] };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const json = await response.json();
|
|
102
|
+
logger.debug({ json }, "Fetched actions from url");
|
|
103
|
+
return json;
|
|
104
|
+
} catch (error) {
|
|
105
|
+
logger.error(
|
|
106
|
+
{ error: error.message ? error.message : error + "" },
|
|
107
|
+
"Failed to fetch actions from url",
|
|
108
|
+
);
|
|
109
|
+
return { actions: [], agents: [] };
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export async function setupRemoteActions({
|
|
114
|
+
remoteEndpointDefinitions,
|
|
115
|
+
graphqlContext,
|
|
116
|
+
messages,
|
|
117
|
+
agentStates,
|
|
118
|
+
frontendUrl,
|
|
119
|
+
}: {
|
|
120
|
+
remoteEndpointDefinitions: EndpointDefinition[];
|
|
121
|
+
graphqlContext: GraphQLContext;
|
|
122
|
+
messages: Message[];
|
|
123
|
+
agentStates?: AgentStateInput[];
|
|
124
|
+
frontendUrl?: string;
|
|
125
|
+
}): Promise<Action[]> {
|
|
126
|
+
const logger = graphqlContext.logger.child({ component: "remote-actions.fetchRemoteActions" });
|
|
127
|
+
logger.debug({ remoteEndpointDefinitions }, "Fetching from remote endpoints");
|
|
128
|
+
|
|
129
|
+
// Remove duplicates of remoteEndpointDefinitions.url
|
|
130
|
+
const filtered = remoteEndpointDefinitions.filter((value, index, self) => {
|
|
131
|
+
if (value.type === EndpointType.LangGraphPlatform) {
|
|
132
|
+
return value;
|
|
133
|
+
}
|
|
134
|
+
return index === self.findIndex((t: CopilotKitEndpoint) => t.url === value.url);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const result = await Promise.all(
|
|
138
|
+
filtered.map(async (endpoint) => {
|
|
139
|
+
// Check for properties that can distinguish LG platform from other actions
|
|
140
|
+
if (endpoint.type === EndpointType.LangGraphPlatform) {
|
|
141
|
+
return constructLGCRemoteAction({
|
|
142
|
+
endpoint,
|
|
143
|
+
messages,
|
|
144
|
+
graphqlContext,
|
|
145
|
+
logger: logger.child({
|
|
146
|
+
component: "remote-actions.constructLGCRemoteAction",
|
|
147
|
+
endpoint,
|
|
148
|
+
}),
|
|
149
|
+
agentStates,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const json = await fetchRemoteInfo({
|
|
154
|
+
url: endpoint.url,
|
|
155
|
+
onBeforeRequest: endpoint.onBeforeRequest,
|
|
156
|
+
graphqlContext,
|
|
157
|
+
logger: logger.child({ component: "remote-actions.fetchActionsFromUrl", endpoint }),
|
|
158
|
+
frontendUrl,
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
return constructRemoteActions({
|
|
162
|
+
json,
|
|
163
|
+
messages,
|
|
164
|
+
url: endpoint.url,
|
|
165
|
+
onBeforeRequest: endpoint.onBeforeRequest,
|
|
166
|
+
graphqlContext,
|
|
167
|
+
logger: logger.child({ component: "remote-actions.constructActions", endpoint }),
|
|
168
|
+
agentStates,
|
|
169
|
+
});
|
|
170
|
+
}),
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
return result.flat();
|
|
174
|
+
}
|