@copilotkit/runtime 0.0.0-0.0.0-max-changeset-10101010101010-20260109191632
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 +2905 -0
- package/LICENSE +21 -0
- package/README.md +76 -0
- package/__snapshots__/schema/schema.graphql +371 -0
- package/dist/index.d.ts +1495 -0
- package/dist/index.js +5644 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +5601 -0
- package/dist/index.mjs.map +1 -0
- package/dist/langgraph.d.ts +284 -0
- package/dist/langgraph.js +211 -0
- package/dist/langgraph.js.map +1 -0
- package/dist/langgraph.mjs +206 -0
- 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/jest.config.js +10 -0
- package/package.json +143 -0
- package/scripts/generate-gql-schema.ts +13 -0
- package/src/agents/langgraph/event-source.ts +329 -0
- package/src/agents/langgraph/events.ts +377 -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 +13 -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/copilot-context.input.ts +10 -0
- package/src/graphql/inputs/custom-property.input.ts +15 -0
- package/src/graphql/inputs/extensions.input.ts +21 -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 +59 -0
- package/src/graphql/inputs/load-agent-state.input.ts +10 -0
- package/src/graphql/inputs/message.input.ts +110 -0
- package/src/graphql/inputs/meta-event.input.ts +18 -0
- 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 +708 -0
- package/src/graphql/resolvers/state.resolver.ts +27 -0
- package/src/graphql/types/agents-response.type.ts +19 -0
- package/src/graphql/types/base/index.ts +10 -0
- package/src/graphql/types/converted/index.ts +176 -0
- package/src/graphql/types/copilot-response.type.ts +138 -0
- package/src/graphql/types/enums.ts +38 -0
- package/src/graphql/types/extensions-response.type.ts +23 -0
- package/src/graphql/types/guardrails-result.type.ts +20 -0
- package/src/graphql/types/load-agent-state-response.type.ts +17 -0
- package/src/graphql/types/message-status.type.ts +42 -0
- package/src/graphql/types/meta-events.type.ts +71 -0
- package/src/graphql/types/response-status.type.ts +66 -0
- package/src/index.ts +4 -0
- package/src/langgraph.ts +1 -0
- package/src/lib/cloud/index.ts +4 -0
- package/src/lib/error-messages.ts +200 -0
- package/src/lib/index.ts +52 -0
- package/src/lib/integrations/index.ts +6 -0
- package/src/lib/integrations/nest/index.ts +14 -0
- package/src/lib/integrations/nextjs/app-router.ts +38 -0
- package/src/lib/integrations/nextjs/pages-router.ts +39 -0
- package/src/lib/integrations/node-express/index.ts +14 -0
- package/src/lib/integrations/node-http/index.ts +143 -0
- package/src/lib/integrations/node-http/request-handler.ts +111 -0
- package/src/lib/integrations/shared.ts +161 -0
- package/src/lib/logger.ts +28 -0
- package/src/lib/observability.ts +160 -0
- package/src/lib/runtime/__tests__/copilot-runtime-error.test.ts +169 -0
- package/src/lib/runtime/__tests__/mcp-tools-utils.test.ts +464 -0
- package/src/lib/runtime/agent-integrations/langgraph/agent.ts +209 -0
- 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 +710 -0
- package/src/lib/runtime/mcp-tools-utils.ts +254 -0
- package/src/lib/runtime/retry-utils.ts +96 -0
- 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/streaming.ts +202 -0
- package/src/lib/telemetry-client.ts +64 -0
- package/src/service-adapters/anthropic/anthropic-adapter.ts +452 -0
- package/src/service-adapters/anthropic/utils.ts +152 -0
- package/src/service-adapters/bedrock/bedrock-adapter.ts +73 -0
- package/src/service-adapters/conversion.ts +67 -0
- package/src/service-adapters/empty/empty-adapter.ts +38 -0
- package/src/service-adapters/events.ts +294 -0
- package/src/service-adapters/experimental/ollama/ollama-adapter.ts +84 -0
- package/src/service-adapters/google/google-genai-adapter.test.ts +104 -0
- package/src/service-adapters/google/google-genai-adapter.ts +88 -0
- package/src/service-adapters/groq/groq-adapter.ts +203 -0
- package/src/service-adapters/index.ts +18 -0
- package/src/service-adapters/langchain/langchain-adapter.ts +111 -0
- package/src/service-adapters/langchain/langserve.ts +88 -0
- package/src/service-adapters/langchain/types.ts +14 -0
- package/src/service-adapters/langchain/utils.ts +313 -0
- package/src/service-adapters/openai/openai-adapter.ts +283 -0
- package/src/service-adapters/openai/openai-assistant-adapter.ts +344 -0
- package/src/service-adapters/openai/utils.ts +199 -0
- package/src/service-adapters/service-adapter.ts +41 -0
- package/src/service-adapters/shared/error-utils.ts +61 -0
- package/src/service-adapters/shared/index.ts +1 -0
- package/src/service-adapters/unify/unify-adapter.ts +151 -0
- package/src/utils/failed-response-status-reasons.ts +70 -0
- package/src/utils/index.ts +1 -0
- package/src/v2/index.ts +3 -0
- package/tests/global.d.ts +13 -0
- package/tests/service-adapters/anthropic/allowlist-approach.test.ts +226 -0
- package/tests/service-adapters/anthropic/anthropic-adapter.test.ts +389 -0
- package/tests/service-adapters/openai/allowlist-approach.test.ts +238 -0
- package/tests/service-adapters/openai/openai-adapter.test.ts +301 -0
- package/tests/setup.jest.ts +21 -0
- package/tests/tsconfig.json +10 -0
- package/tsconfig.json +13 -0
- package/tsup.config.ts +20 -0
- package/typedoc.json +4 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Arg, Resolver } from "type-graphql";
|
|
2
|
+
import { Ctx } from "type-graphql";
|
|
3
|
+
import { Query } from "type-graphql";
|
|
4
|
+
import { LoadAgentStateResponse } from "../types/load-agent-state-response.type";
|
|
5
|
+
import type { GraphQLContext } from "../../lib/integrations";
|
|
6
|
+
import { LoadAgentStateInput } from "../inputs/load-agent-state.input";
|
|
7
|
+
import { CopilotKitAgentDiscoveryError } from "@copilotkit/shared";
|
|
8
|
+
import { CopilotRuntime } from "../../lib";
|
|
9
|
+
|
|
10
|
+
@Resolver(() => LoadAgentStateResponse)
|
|
11
|
+
export class StateResolver {
|
|
12
|
+
@Query(() => LoadAgentStateResponse)
|
|
13
|
+
async loadAgentState(@Ctx() ctx: GraphQLContext, @Arg("data") data: LoadAgentStateInput) {
|
|
14
|
+
const agents = [];
|
|
15
|
+
const hasAgent = agents.some((agent) => agent.name === data.agentName);
|
|
16
|
+
if (!hasAgent) {
|
|
17
|
+
throw new CopilotKitAgentDiscoveryError({
|
|
18
|
+
agentName: data.agentName,
|
|
19
|
+
availableAgents: agents.map((a) => ({ name: a.name, id: a.name })),
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const state = {};
|
|
24
|
+
|
|
25
|
+
return state;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Field, ObjectType } from "type-graphql";
|
|
2
|
+
|
|
3
|
+
@ObjectType()
|
|
4
|
+
export class Agent {
|
|
5
|
+
@Field(() => String)
|
|
6
|
+
id: string;
|
|
7
|
+
|
|
8
|
+
@Field(() => String)
|
|
9
|
+
name: string;
|
|
10
|
+
|
|
11
|
+
@Field(() => String)
|
|
12
|
+
description?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@ObjectType()
|
|
16
|
+
export class AgentsResponse {
|
|
17
|
+
@Field(() => [Agent])
|
|
18
|
+
agents: Agent[];
|
|
19
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { randomId } from "@copilotkit/shared";
|
|
2
|
+
import {
|
|
3
|
+
ActionExecutionMessageInput,
|
|
4
|
+
ResultMessageInput,
|
|
5
|
+
TextMessageInput,
|
|
6
|
+
AgentStateMessageInput,
|
|
7
|
+
ImageMessageInput,
|
|
8
|
+
} from "../../inputs/message.input";
|
|
9
|
+
import { BaseMessageInput } from "../base";
|
|
10
|
+
import { BaseMessageOutput } from "../copilot-response.type";
|
|
11
|
+
import { MessageRole } from "../enums";
|
|
12
|
+
import { MessageStatus, MessageStatusCode } from "../message-status.type";
|
|
13
|
+
|
|
14
|
+
export type MessageType =
|
|
15
|
+
| "TextMessage"
|
|
16
|
+
| "ActionExecutionMessage"
|
|
17
|
+
| "ResultMessage"
|
|
18
|
+
| "AgentStateMessage"
|
|
19
|
+
| "ImageMessage";
|
|
20
|
+
|
|
21
|
+
export class Message {
|
|
22
|
+
type: MessageType;
|
|
23
|
+
id: BaseMessageOutput["id"];
|
|
24
|
+
createdAt: BaseMessageOutput["createdAt"];
|
|
25
|
+
status: MessageStatus;
|
|
26
|
+
|
|
27
|
+
constructor(props: any) {
|
|
28
|
+
props.id ??= randomId();
|
|
29
|
+
props.status ??= { code: MessageStatusCode.Success };
|
|
30
|
+
props.createdAt ??= new Date();
|
|
31
|
+
Object.assign(this, props);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
isTextMessage(): this is TextMessage {
|
|
35
|
+
return this.type === "TextMessage";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
isActionExecutionMessage(): this is ActionExecutionMessage {
|
|
39
|
+
return this.type === "ActionExecutionMessage";
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
isResultMessage(): this is ResultMessage {
|
|
43
|
+
return this.type === "ResultMessage";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
isAgentStateMessage(): this is AgentStateMessage {
|
|
47
|
+
return this.type === "AgentStateMessage";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
isImageMessage(): this is ImageMessage {
|
|
51
|
+
return this.type === "ImageMessage";
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// alias Role to MessageRole
|
|
56
|
+
export const Role = MessageRole;
|
|
57
|
+
|
|
58
|
+
// when constructing any message, the base fields are optional
|
|
59
|
+
type MessageConstructorOptions = Partial<Message>;
|
|
60
|
+
|
|
61
|
+
type TextMessageConstructorOptions = MessageConstructorOptions & TextMessageInput;
|
|
62
|
+
|
|
63
|
+
export class TextMessage extends Message implements TextMessageConstructorOptions {
|
|
64
|
+
content: TextMessageInput["content"];
|
|
65
|
+
parentMessageId: TextMessageInput["parentMessageId"];
|
|
66
|
+
role: TextMessageInput["role"];
|
|
67
|
+
type = "TextMessage" as const;
|
|
68
|
+
|
|
69
|
+
constructor(props: TextMessageConstructorOptions) {
|
|
70
|
+
super(props);
|
|
71
|
+
this.type = "TextMessage";
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export class ActionExecutionMessage
|
|
76
|
+
extends Message
|
|
77
|
+
implements Omit<ActionExecutionMessageInput, "arguments" | "scope">
|
|
78
|
+
{
|
|
79
|
+
type: MessageType = "ActionExecutionMessage";
|
|
80
|
+
name: string;
|
|
81
|
+
arguments: Record<string, any>;
|
|
82
|
+
parentMessageId?: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export class ResultMessage extends Message implements ResultMessageInput {
|
|
86
|
+
type: MessageType = "ResultMessage";
|
|
87
|
+
actionExecutionId: string;
|
|
88
|
+
actionName: string;
|
|
89
|
+
result: string;
|
|
90
|
+
|
|
91
|
+
static encodeResult(
|
|
92
|
+
result: any,
|
|
93
|
+
error?: { code: string; message: string } | string | Error,
|
|
94
|
+
): string {
|
|
95
|
+
const errorObj = error
|
|
96
|
+
? typeof error === "string"
|
|
97
|
+
? { code: "ERROR", message: error }
|
|
98
|
+
: error instanceof Error
|
|
99
|
+
? { code: "ERROR", message: error.message }
|
|
100
|
+
: error
|
|
101
|
+
: undefined;
|
|
102
|
+
|
|
103
|
+
if (errorObj) {
|
|
104
|
+
return JSON.stringify({
|
|
105
|
+
error: errorObj,
|
|
106
|
+
result: result || "",
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
if (result === undefined) {
|
|
110
|
+
return "";
|
|
111
|
+
}
|
|
112
|
+
return typeof result === "string" ? result : JSON.stringify(result);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
static decodeResult(result: string): {
|
|
116
|
+
error?: { code: string; message: string };
|
|
117
|
+
result: string;
|
|
118
|
+
} {
|
|
119
|
+
if (!result) {
|
|
120
|
+
return { result: "" };
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
const parsed = JSON.parse(result);
|
|
124
|
+
if (parsed && typeof parsed === "object") {
|
|
125
|
+
if ("error" in parsed) {
|
|
126
|
+
return {
|
|
127
|
+
error: parsed.error,
|
|
128
|
+
result: parsed.result || "",
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
return { result: JSON.stringify(parsed) };
|
|
132
|
+
}
|
|
133
|
+
return { result };
|
|
134
|
+
} catch (e) {
|
|
135
|
+
return { result };
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
hasError(): boolean {
|
|
140
|
+
try {
|
|
141
|
+
const { error } = ResultMessage.decodeResult(this.result);
|
|
142
|
+
return !!error;
|
|
143
|
+
} catch {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
getError(): { code: string; message: string } | undefined {
|
|
149
|
+
try {
|
|
150
|
+
const { error } = ResultMessage.decodeResult(this.result);
|
|
151
|
+
return error;
|
|
152
|
+
} catch {
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export class AgentStateMessage extends Message implements Omit<AgentStateMessageInput, "state"> {
|
|
159
|
+
type: MessageType = "AgentStateMessage";
|
|
160
|
+
threadId: string;
|
|
161
|
+
agentName: string;
|
|
162
|
+
nodeName: string;
|
|
163
|
+
runId: string;
|
|
164
|
+
active: boolean;
|
|
165
|
+
role: MessageRole;
|
|
166
|
+
state: any;
|
|
167
|
+
running: boolean;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export class ImageMessage extends Message implements ImageMessageInput {
|
|
171
|
+
type: MessageType = "ImageMessage";
|
|
172
|
+
format: string;
|
|
173
|
+
bytes: string;
|
|
174
|
+
role: MessageRole;
|
|
175
|
+
parentMessageId?: string;
|
|
176
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { Field, InterfaceType, ObjectType } from "type-graphql";
|
|
2
|
+
import { MessageRole } from "./enums";
|
|
3
|
+
import { MessageStatusUnion } from "./message-status.type";
|
|
4
|
+
import { ResponseStatusUnion } from "./response-status.type";
|
|
5
|
+
import { ExtensionsResponse } from "./extensions-response.type";
|
|
6
|
+
import { BaseMetaEvent } from "./meta-events.type";
|
|
7
|
+
|
|
8
|
+
@InterfaceType({
|
|
9
|
+
resolveType(value) {
|
|
10
|
+
if (value.hasOwnProperty("content")) {
|
|
11
|
+
return TextMessageOutput;
|
|
12
|
+
} else if (value.hasOwnProperty("name")) {
|
|
13
|
+
return ActionExecutionMessageOutput;
|
|
14
|
+
} else if (value.hasOwnProperty("result")) {
|
|
15
|
+
return ResultMessageOutput;
|
|
16
|
+
} else if (value.hasOwnProperty("state")) {
|
|
17
|
+
return AgentStateMessageOutput;
|
|
18
|
+
} else if (value.hasOwnProperty("format") && value.hasOwnProperty("bytes")) {
|
|
19
|
+
return ImageMessageOutput;
|
|
20
|
+
}
|
|
21
|
+
return undefined;
|
|
22
|
+
},
|
|
23
|
+
})
|
|
24
|
+
export abstract class BaseMessageOutput {
|
|
25
|
+
@Field(() => String)
|
|
26
|
+
id: string;
|
|
27
|
+
|
|
28
|
+
@Field(() => Date)
|
|
29
|
+
createdAt: Date;
|
|
30
|
+
|
|
31
|
+
@Field(() => MessageStatusUnion)
|
|
32
|
+
status: typeof MessageStatusUnion;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@ObjectType({ implements: BaseMessageOutput })
|
|
36
|
+
export class TextMessageOutput {
|
|
37
|
+
@Field(() => MessageRole)
|
|
38
|
+
role: MessageRole;
|
|
39
|
+
|
|
40
|
+
@Field(() => [String])
|
|
41
|
+
content: string[];
|
|
42
|
+
|
|
43
|
+
@Field(() => String, { nullable: true })
|
|
44
|
+
parentMessageId?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@ObjectType({ implements: BaseMessageOutput })
|
|
48
|
+
export class ActionExecutionMessageOutput {
|
|
49
|
+
@Field(() => String)
|
|
50
|
+
name: string;
|
|
51
|
+
|
|
52
|
+
@Field(() => String, {
|
|
53
|
+
nullable: true,
|
|
54
|
+
deprecationReason: "This field will be removed in a future version",
|
|
55
|
+
})
|
|
56
|
+
scope?: string;
|
|
57
|
+
|
|
58
|
+
@Field(() => [String])
|
|
59
|
+
arguments: string[];
|
|
60
|
+
|
|
61
|
+
@Field(() => String, { nullable: true })
|
|
62
|
+
parentMessageId?: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@ObjectType({ implements: BaseMessageOutput })
|
|
66
|
+
export class ResultMessageOutput {
|
|
67
|
+
@Field(() => String)
|
|
68
|
+
actionExecutionId: string;
|
|
69
|
+
|
|
70
|
+
@Field(() => String)
|
|
71
|
+
actionName: string;
|
|
72
|
+
|
|
73
|
+
@Field(() => String)
|
|
74
|
+
result: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
@ObjectType({ implements: BaseMessageOutput })
|
|
78
|
+
export class AgentStateMessageOutput {
|
|
79
|
+
@Field(() => String)
|
|
80
|
+
threadId: string;
|
|
81
|
+
|
|
82
|
+
@Field(() => String)
|
|
83
|
+
agentName: string;
|
|
84
|
+
|
|
85
|
+
@Field(() => String)
|
|
86
|
+
nodeName: string;
|
|
87
|
+
|
|
88
|
+
@Field(() => String)
|
|
89
|
+
runId: string;
|
|
90
|
+
|
|
91
|
+
@Field(() => Boolean)
|
|
92
|
+
active: boolean;
|
|
93
|
+
|
|
94
|
+
@Field(() => MessageRole)
|
|
95
|
+
role: MessageRole;
|
|
96
|
+
|
|
97
|
+
@Field(() => String)
|
|
98
|
+
state: string;
|
|
99
|
+
|
|
100
|
+
@Field(() => Boolean)
|
|
101
|
+
running: boolean;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@ObjectType({ implements: BaseMessageOutput })
|
|
105
|
+
export class ImageMessageOutput {
|
|
106
|
+
@Field(() => String)
|
|
107
|
+
format: string;
|
|
108
|
+
|
|
109
|
+
@Field(() => String)
|
|
110
|
+
bytes: string;
|
|
111
|
+
|
|
112
|
+
@Field(() => MessageRole)
|
|
113
|
+
role: MessageRole;
|
|
114
|
+
|
|
115
|
+
@Field(() => String, { nullable: true })
|
|
116
|
+
parentMessageId?: string;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
@ObjectType()
|
|
120
|
+
export class CopilotResponse {
|
|
121
|
+
@Field(() => String)
|
|
122
|
+
threadId!: string;
|
|
123
|
+
|
|
124
|
+
@Field(() => ResponseStatusUnion)
|
|
125
|
+
status: typeof ResponseStatusUnion;
|
|
126
|
+
|
|
127
|
+
@Field({ nullable: true })
|
|
128
|
+
runId?: string;
|
|
129
|
+
|
|
130
|
+
@Field(() => [BaseMessageOutput])
|
|
131
|
+
messages: (typeof BaseMessageOutput)[];
|
|
132
|
+
|
|
133
|
+
@Field(() => ExtensionsResponse, { nullable: true })
|
|
134
|
+
extensions?: ExtensionsResponse;
|
|
135
|
+
|
|
136
|
+
@Field(() => [BaseMetaEvent], { nullable: true })
|
|
137
|
+
metaEvents?: (typeof BaseMetaEvent)[];
|
|
138
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { registerEnumType } from "type-graphql";
|
|
2
|
+
|
|
3
|
+
export enum MessageRole {
|
|
4
|
+
assistant = "assistant",
|
|
5
|
+
developer = "developer",
|
|
6
|
+
system = "system",
|
|
7
|
+
tool = "tool",
|
|
8
|
+
user = "user",
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export enum CopilotRequestType {
|
|
12
|
+
Chat = "Chat",
|
|
13
|
+
Task = "Task",
|
|
14
|
+
TextareaCompletion = "TextareaCompletion",
|
|
15
|
+
TextareaPopover = "TextareaPopover",
|
|
16
|
+
Suggestion = "Suggestion",
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export enum ActionInputAvailability {
|
|
20
|
+
disabled = "disabled",
|
|
21
|
+
enabled = "enabled",
|
|
22
|
+
remote = "remote",
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
registerEnumType(MessageRole, {
|
|
26
|
+
name: "MessageRole",
|
|
27
|
+
description: "The role of the message",
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
registerEnumType(CopilotRequestType, {
|
|
31
|
+
name: "CopilotRequestType",
|
|
32
|
+
description: "The type of Copilot request",
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
registerEnumType(ActionInputAvailability, {
|
|
36
|
+
name: "ActionInputAvailability",
|
|
37
|
+
description: "The availability of the frontend action",
|
|
38
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Field, ObjectType } from "type-graphql";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The extensions response is used to receive additional information from the copilot runtime, specific to a
|
|
5
|
+
* service adapter or agent framework.
|
|
6
|
+
*
|
|
7
|
+
* Next time a request to the runtime is made, the extensions response will be included in the request as input.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
@ObjectType()
|
|
11
|
+
export class ExtensionsResponse {
|
|
12
|
+
@Field(() => OpenAIApiAssistantAPIResponse, { nullable: true })
|
|
13
|
+
openaiAssistantAPI?: OpenAIApiAssistantAPIResponse;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@ObjectType()
|
|
17
|
+
export class OpenAIApiAssistantAPIResponse {
|
|
18
|
+
@Field(() => String, { nullable: true })
|
|
19
|
+
runId?: string;
|
|
20
|
+
|
|
21
|
+
@Field(() => String, { nullable: true })
|
|
22
|
+
threadId?: string;
|
|
23
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Field, ObjectType, registerEnumType } from "type-graphql";
|
|
2
|
+
|
|
3
|
+
export enum GuardrailsResultStatus {
|
|
4
|
+
ALLOWED = "allowed",
|
|
5
|
+
DENIED = "denied",
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
registerEnumType(GuardrailsResultStatus, {
|
|
9
|
+
name: "GuardrailsResultStatus",
|
|
10
|
+
description: "The status of the guardrails check",
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
@ObjectType()
|
|
14
|
+
export class GuardrailsResult {
|
|
15
|
+
@Field(() => GuardrailsResultStatus)
|
|
16
|
+
status: GuardrailsResultStatus;
|
|
17
|
+
|
|
18
|
+
@Field(() => String, { nullable: true })
|
|
19
|
+
reason?: string;
|
|
20
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Field, ObjectType } from "type-graphql";
|
|
2
|
+
import { BaseMessageOutput } from "./copilot-response.type";
|
|
3
|
+
|
|
4
|
+
@ObjectType()
|
|
5
|
+
export class LoadAgentStateResponse {
|
|
6
|
+
@Field(() => String)
|
|
7
|
+
threadId: string;
|
|
8
|
+
|
|
9
|
+
@Field(() => Boolean)
|
|
10
|
+
threadExists: boolean;
|
|
11
|
+
|
|
12
|
+
@Field(() => String)
|
|
13
|
+
state: string;
|
|
14
|
+
|
|
15
|
+
@Field(() => String)
|
|
16
|
+
messages: string;
|
|
17
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Field, ObjectType, createUnionType, registerEnumType } from "type-graphql";
|
|
2
|
+
|
|
3
|
+
export enum MessageStatusCode {
|
|
4
|
+
Pending = "pending",
|
|
5
|
+
Success = "success",
|
|
6
|
+
Failed = "failed",
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
registerEnumType(MessageStatusCode, {
|
|
10
|
+
name: "MessageStatusCode",
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
@ObjectType()
|
|
14
|
+
export class BaseMessageStatus {
|
|
15
|
+
@Field(() => MessageStatusCode)
|
|
16
|
+
code: MessageStatusCode;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@ObjectType()
|
|
20
|
+
export class PendingMessageStatus extends BaseMessageStatus {
|
|
21
|
+
code: MessageStatusCode = MessageStatusCode.Pending;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@ObjectType()
|
|
25
|
+
export class SuccessMessageStatus extends BaseMessageStatus {
|
|
26
|
+
code: MessageStatusCode = MessageStatusCode.Success;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@ObjectType()
|
|
30
|
+
export class FailedMessageStatus extends BaseMessageStatus {
|
|
31
|
+
code: MessageStatusCode = MessageStatusCode.Failed;
|
|
32
|
+
|
|
33
|
+
@Field(() => String)
|
|
34
|
+
reason: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const MessageStatusUnion = createUnionType({
|
|
38
|
+
name: "MessageStatus",
|
|
39
|
+
types: () => [PendingMessageStatus, SuccessMessageStatus, FailedMessageStatus] as const,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export type MessageStatus = typeof MessageStatusUnion;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { createUnionType, Field, InterfaceType, ObjectType, registerEnumType } from "type-graphql";
|
|
2
|
+
import {
|
|
3
|
+
ActionExecutionMessageOutput,
|
|
4
|
+
AgentStateMessageOutput,
|
|
5
|
+
BaseMessageOutput,
|
|
6
|
+
ResultMessageOutput,
|
|
7
|
+
TextMessageOutput,
|
|
8
|
+
} from "./copilot-response.type";
|
|
9
|
+
|
|
10
|
+
export enum MetaEventName {
|
|
11
|
+
LangGraphInterruptEvent = "LangGraphInterruptEvent",
|
|
12
|
+
CopilotKitLangGraphInterruptEvent = "CopilotKitLangGraphInterruptEvent",
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
registerEnumType(MetaEventName, {
|
|
16
|
+
name: "MetaEventName",
|
|
17
|
+
description: "Meta event types",
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
@InterfaceType({
|
|
21
|
+
resolveType(value) {
|
|
22
|
+
if (value.name === MetaEventName.LangGraphInterruptEvent) {
|
|
23
|
+
return LangGraphInterruptEvent;
|
|
24
|
+
} else if (value.name === MetaEventName.CopilotKitLangGraphInterruptEvent) {
|
|
25
|
+
return CopilotKitLangGraphInterruptEvent;
|
|
26
|
+
}
|
|
27
|
+
return undefined;
|
|
28
|
+
},
|
|
29
|
+
})
|
|
30
|
+
@InterfaceType()
|
|
31
|
+
export abstract class BaseMetaEvent {
|
|
32
|
+
@Field(() => String)
|
|
33
|
+
type: "MetaEvent" = "MetaEvent";
|
|
34
|
+
|
|
35
|
+
@Field(() => MetaEventName)
|
|
36
|
+
name: MetaEventName;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@ObjectType()
|
|
40
|
+
export class CopilotKitLangGraphInterruptEventData {
|
|
41
|
+
@Field(() => String)
|
|
42
|
+
value: string;
|
|
43
|
+
|
|
44
|
+
@Field(() => [BaseMessageOutput])
|
|
45
|
+
messages: (typeof BaseMessageOutput)[];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@ObjectType({ implements: BaseMetaEvent })
|
|
49
|
+
export class LangGraphInterruptEvent {
|
|
50
|
+
@Field(() => MetaEventName)
|
|
51
|
+
name: MetaEventName.LangGraphInterruptEvent = MetaEventName.LangGraphInterruptEvent;
|
|
52
|
+
|
|
53
|
+
@Field(() => String)
|
|
54
|
+
value: string;
|
|
55
|
+
|
|
56
|
+
@Field(() => String, { nullable: true })
|
|
57
|
+
response?: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@ObjectType({ implements: BaseMetaEvent })
|
|
61
|
+
export class CopilotKitLangGraphInterruptEvent {
|
|
62
|
+
@Field(() => MetaEventName)
|
|
63
|
+
name: MetaEventName.CopilotKitLangGraphInterruptEvent =
|
|
64
|
+
MetaEventName.CopilotKitLangGraphInterruptEvent;
|
|
65
|
+
|
|
66
|
+
@Field(() => CopilotKitLangGraphInterruptEventData)
|
|
67
|
+
data: CopilotKitLangGraphInterruptEventData;
|
|
68
|
+
|
|
69
|
+
@Field(() => String, { nullable: true })
|
|
70
|
+
response?: string;
|
|
71
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { GraphQLJSON } from "graphql-scalars";
|
|
2
|
+
import { Field, InterfaceType, ObjectType, createUnionType, registerEnumType } from "type-graphql";
|
|
3
|
+
|
|
4
|
+
export enum ResponseStatusCode {
|
|
5
|
+
Pending = "pending",
|
|
6
|
+
Success = "success",
|
|
7
|
+
Failed = "failed",
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
registerEnumType(ResponseStatusCode, {
|
|
11
|
+
name: "ResponseStatusCode",
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
@InterfaceType({
|
|
15
|
+
resolveType(value) {
|
|
16
|
+
if (value.code === ResponseStatusCode.Success) {
|
|
17
|
+
return SuccessResponseStatus;
|
|
18
|
+
} else if (value.code === ResponseStatusCode.Failed) {
|
|
19
|
+
return FailedResponseStatus;
|
|
20
|
+
} else if (value.code === ResponseStatusCode.Pending) {
|
|
21
|
+
return PendingResponseStatus;
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
},
|
|
25
|
+
})
|
|
26
|
+
@ObjectType()
|
|
27
|
+
abstract class BaseResponseStatus {
|
|
28
|
+
@Field(() => ResponseStatusCode)
|
|
29
|
+
code: ResponseStatusCode;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@ObjectType({ implements: BaseResponseStatus })
|
|
33
|
+
export class PendingResponseStatus extends BaseResponseStatus {
|
|
34
|
+
code: ResponseStatusCode = ResponseStatusCode.Pending;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@ObjectType({ implements: BaseResponseStatus })
|
|
38
|
+
export class SuccessResponseStatus extends BaseResponseStatus {
|
|
39
|
+
code: ResponseStatusCode = ResponseStatusCode.Success;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export enum FailedResponseStatusReason {
|
|
43
|
+
GUARDRAILS_VALIDATION_FAILED = "GUARDRAILS_VALIDATION_FAILED",
|
|
44
|
+
MESSAGE_STREAM_INTERRUPTED = "MESSAGE_STREAM_INTERRUPTED",
|
|
45
|
+
UNKNOWN_ERROR = "UNKNOWN_ERROR",
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
registerEnumType(FailedResponseStatusReason, {
|
|
49
|
+
name: "FailedResponseStatusReason",
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
@ObjectType({ implements: BaseResponseStatus })
|
|
53
|
+
export class FailedResponseStatus extends BaseResponseStatus {
|
|
54
|
+
code: ResponseStatusCode = ResponseStatusCode.Failed;
|
|
55
|
+
|
|
56
|
+
@Field(() => FailedResponseStatusReason)
|
|
57
|
+
reason: FailedResponseStatusReason;
|
|
58
|
+
|
|
59
|
+
@Field(() => GraphQLJSON, { nullable: true })
|
|
60
|
+
details?: Record<string, any> = null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const ResponseStatusUnion = createUnionType({
|
|
64
|
+
name: "ResponseStatus",
|
|
65
|
+
types: () => [PendingResponseStatus, SuccessResponseStatus, FailedResponseStatus] as const,
|
|
66
|
+
});
|
package/src/index.ts
ADDED
package/src/langgraph.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./lib/runtime/agent-integrations/langgraph";
|