@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.
Files changed (122) hide show
  1. package/.eslintrc.js +7 -0
  2. package/CHANGELOG.md +2905 -0
  3. package/LICENSE +21 -0
  4. package/README.md +76 -0
  5. package/__snapshots__/schema/schema.graphql +371 -0
  6. package/dist/index.d.ts +1495 -0
  7. package/dist/index.js +5644 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/index.mjs +5601 -0
  10. package/dist/index.mjs.map +1 -0
  11. package/dist/langgraph.d.ts +284 -0
  12. package/dist/langgraph.js +211 -0
  13. package/dist/langgraph.js.map +1 -0
  14. package/dist/langgraph.mjs +206 -0
  15. package/dist/langgraph.mjs.map +1 -0
  16. package/dist/v2/index.d.ts +2 -0
  17. package/dist/v2/index.js +22 -0
  18. package/dist/v2/index.js.map +1 -0
  19. package/dist/v2/index.mjs +5 -0
  20. package/dist/v2/index.mjs.map +1 -0
  21. package/jest.config.js +10 -0
  22. package/package.json +143 -0
  23. package/scripts/generate-gql-schema.ts +13 -0
  24. package/src/agents/langgraph/event-source.ts +329 -0
  25. package/src/agents/langgraph/events.ts +377 -0
  26. package/src/graphql/inputs/action.input.ts +16 -0
  27. package/src/graphql/inputs/agent-session.input.ts +13 -0
  28. package/src/graphql/inputs/agent-state.input.ts +13 -0
  29. package/src/graphql/inputs/cloud-guardrails.input.ts +16 -0
  30. package/src/graphql/inputs/cloud.input.ts +8 -0
  31. package/src/graphql/inputs/context-property.input.ts +10 -0
  32. package/src/graphql/inputs/copilot-context.input.ts +10 -0
  33. package/src/graphql/inputs/custom-property.input.ts +15 -0
  34. package/src/graphql/inputs/extensions.input.ts +21 -0
  35. package/src/graphql/inputs/forwarded-parameters.input.ts +22 -0
  36. package/src/graphql/inputs/frontend.input.ts +14 -0
  37. package/src/graphql/inputs/generate-copilot-response.input.ts +59 -0
  38. package/src/graphql/inputs/load-agent-state.input.ts +10 -0
  39. package/src/graphql/inputs/message.input.ts +110 -0
  40. package/src/graphql/inputs/meta-event.input.ts +18 -0
  41. package/src/graphql/message-conversion/agui-to-gql.test.ts +1263 -0
  42. package/src/graphql/message-conversion/agui-to-gql.ts +333 -0
  43. package/src/graphql/message-conversion/gql-to-agui.test.ts +1580 -0
  44. package/src/graphql/message-conversion/gql-to-agui.ts +278 -0
  45. package/src/graphql/message-conversion/index.ts +2 -0
  46. package/src/graphql/message-conversion/roundtrip-conversion.test.ts +526 -0
  47. package/src/graphql/resolvers/copilot.resolver.ts +708 -0
  48. package/src/graphql/resolvers/state.resolver.ts +27 -0
  49. package/src/graphql/types/agents-response.type.ts +19 -0
  50. package/src/graphql/types/base/index.ts +10 -0
  51. package/src/graphql/types/converted/index.ts +176 -0
  52. package/src/graphql/types/copilot-response.type.ts +138 -0
  53. package/src/graphql/types/enums.ts +38 -0
  54. package/src/graphql/types/extensions-response.type.ts +23 -0
  55. package/src/graphql/types/guardrails-result.type.ts +20 -0
  56. package/src/graphql/types/load-agent-state-response.type.ts +17 -0
  57. package/src/graphql/types/message-status.type.ts +42 -0
  58. package/src/graphql/types/meta-events.type.ts +71 -0
  59. package/src/graphql/types/response-status.type.ts +66 -0
  60. package/src/index.ts +4 -0
  61. package/src/langgraph.ts +1 -0
  62. package/src/lib/cloud/index.ts +4 -0
  63. package/src/lib/error-messages.ts +200 -0
  64. package/src/lib/index.ts +52 -0
  65. package/src/lib/integrations/index.ts +6 -0
  66. package/src/lib/integrations/nest/index.ts +14 -0
  67. package/src/lib/integrations/nextjs/app-router.ts +38 -0
  68. package/src/lib/integrations/nextjs/pages-router.ts +39 -0
  69. package/src/lib/integrations/node-express/index.ts +14 -0
  70. package/src/lib/integrations/node-http/index.ts +143 -0
  71. package/src/lib/integrations/node-http/request-handler.ts +111 -0
  72. package/src/lib/integrations/shared.ts +161 -0
  73. package/src/lib/logger.ts +28 -0
  74. package/src/lib/observability.ts +160 -0
  75. package/src/lib/runtime/__tests__/copilot-runtime-error.test.ts +169 -0
  76. package/src/lib/runtime/__tests__/mcp-tools-utils.test.ts +464 -0
  77. package/src/lib/runtime/agent-integrations/langgraph/agent.ts +209 -0
  78. package/src/lib/runtime/agent-integrations/langgraph/consts.ts +34 -0
  79. package/src/lib/runtime/agent-integrations/langgraph/index.ts +2 -0
  80. package/src/lib/runtime/copilot-runtime.ts +710 -0
  81. package/src/lib/runtime/mcp-tools-utils.ts +254 -0
  82. package/src/lib/runtime/retry-utils.ts +96 -0
  83. package/src/lib/runtime/telemetry-agent-runner.ts +139 -0
  84. package/src/lib/runtime/types.ts +49 -0
  85. package/src/lib/runtime/utils.ts +87 -0
  86. package/src/lib/streaming.ts +202 -0
  87. package/src/lib/telemetry-client.ts +64 -0
  88. package/src/service-adapters/anthropic/anthropic-adapter.ts +452 -0
  89. package/src/service-adapters/anthropic/utils.ts +152 -0
  90. package/src/service-adapters/bedrock/bedrock-adapter.ts +73 -0
  91. package/src/service-adapters/conversion.ts +67 -0
  92. package/src/service-adapters/empty/empty-adapter.ts +38 -0
  93. package/src/service-adapters/events.ts +294 -0
  94. package/src/service-adapters/experimental/ollama/ollama-adapter.ts +84 -0
  95. package/src/service-adapters/google/google-genai-adapter.test.ts +104 -0
  96. package/src/service-adapters/google/google-genai-adapter.ts +88 -0
  97. package/src/service-adapters/groq/groq-adapter.ts +203 -0
  98. package/src/service-adapters/index.ts +18 -0
  99. package/src/service-adapters/langchain/langchain-adapter.ts +111 -0
  100. package/src/service-adapters/langchain/langserve.ts +88 -0
  101. package/src/service-adapters/langchain/types.ts +14 -0
  102. package/src/service-adapters/langchain/utils.ts +313 -0
  103. package/src/service-adapters/openai/openai-adapter.ts +283 -0
  104. package/src/service-adapters/openai/openai-assistant-adapter.ts +344 -0
  105. package/src/service-adapters/openai/utils.ts +199 -0
  106. package/src/service-adapters/service-adapter.ts +41 -0
  107. package/src/service-adapters/shared/error-utils.ts +61 -0
  108. package/src/service-adapters/shared/index.ts +1 -0
  109. package/src/service-adapters/unify/unify-adapter.ts +151 -0
  110. package/src/utils/failed-response-status-reasons.ts +70 -0
  111. package/src/utils/index.ts +1 -0
  112. package/src/v2/index.ts +3 -0
  113. package/tests/global.d.ts +13 -0
  114. package/tests/service-adapters/anthropic/allowlist-approach.test.ts +226 -0
  115. package/tests/service-adapters/anthropic/anthropic-adapter.test.ts +389 -0
  116. package/tests/service-adapters/openai/allowlist-approach.test.ts +238 -0
  117. package/tests/service-adapters/openai/openai-adapter.test.ts +301 -0
  118. package/tests/setup.jest.ts +21 -0
  119. package/tests/tsconfig.json +10 -0
  120. package/tsconfig.json +13 -0
  121. package/tsup.config.ts +20 -0
  122. package/typedoc.json +4 -0
@@ -0,0 +1,16 @@
1
+ import { Field, InputType } from "type-graphql";
2
+ import { ActionInputAvailability } from "../types/enums";
3
+ @InputType()
4
+ export class ActionInput {
5
+ @Field(() => String)
6
+ name: string;
7
+
8
+ @Field(() => String)
9
+ description: string;
10
+
11
+ @Field(() => String)
12
+ jsonSchema: string;
13
+
14
+ @Field(() => ActionInputAvailability, { nullable: true })
15
+ available?: ActionInputAvailability;
16
+ }
@@ -0,0 +1,13 @@
1
+ import { Field, InputType } from "type-graphql";
2
+
3
+ @InputType()
4
+ export class AgentSessionInput {
5
+ @Field(() => String)
6
+ agentName: string;
7
+
8
+ @Field(() => String, { nullable: true })
9
+ threadId?: string;
10
+
11
+ @Field(() => String, { nullable: true })
12
+ nodeName?: string;
13
+ }
@@ -0,0 +1,13 @@
1
+ import { Field, InputType } from "type-graphql";
2
+
3
+ @InputType()
4
+ export class AgentStateInput {
5
+ @Field(() => String)
6
+ agentName: string;
7
+
8
+ @Field(() => String)
9
+ state: string;
10
+
11
+ @Field(() => String, { nullable: true })
12
+ config?: string;
13
+ }
@@ -0,0 +1,16 @@
1
+ import { Field, InputType } from "type-graphql";
2
+
3
+ @InputType()
4
+ export class GuardrailsRuleInput {
5
+ @Field(() => [String], { nullable: true })
6
+ allowList?: string[] = [];
7
+
8
+ @Field(() => [String], { nullable: true })
9
+ denyList?: string[] = [];
10
+ }
11
+
12
+ @InputType()
13
+ export class GuardrailsInput {
14
+ @Field(() => GuardrailsRuleInput, { nullable: false })
15
+ inputValidationRules: GuardrailsRuleInput;
16
+ }
@@ -0,0 +1,8 @@
1
+ import { Field, InputType } from "type-graphql";
2
+ import { GuardrailsInput } from "./cloud-guardrails.input";
3
+
4
+ @InputType()
5
+ export class CloudInput {
6
+ @Field(() => GuardrailsInput, { nullable: true })
7
+ guardrails?: GuardrailsInput;
8
+ }
@@ -0,0 +1,10 @@
1
+ import { Field, InputType } from "type-graphql";
2
+
3
+ @InputType()
4
+ export class ContextPropertyInput {
5
+ @Field(() => String)
6
+ value: string;
7
+
8
+ @Field(() => String)
9
+ description: string;
10
+ }
@@ -0,0 +1,10 @@
1
+ import { Field, InputType } from "type-graphql";
2
+
3
+ @InputType()
4
+ export class CopilotContextInput {
5
+ @Field(() => String)
6
+ description: string;
7
+
8
+ @Field(() => String)
9
+ value: string;
10
+ }
@@ -0,0 +1,15 @@
1
+ import { Field, InputType, Int, createUnionType } from "type-graphql";
2
+
3
+ const PrimitiveUnion = createUnionType({
4
+ name: "Primitive",
5
+ types: () => [String, Number, Boolean] as const,
6
+ });
7
+
8
+ @InputType()
9
+ export class CustomPropertyInput {
10
+ @Field(() => String)
11
+ key: string;
12
+
13
+ @Field(() => PrimitiveUnion)
14
+ value: string;
15
+ }
@@ -0,0 +1,21 @@
1
+ import { Field, InputType } from "type-graphql";
2
+
3
+ /**
4
+ * The extensions input is used to pass additional information to the copilot runtime, specific to a
5
+ * service adapter or agent framework.
6
+ */
7
+
8
+ @InputType()
9
+ export class ExtensionsInput {
10
+ @Field(() => OpenAIApiAssistantAPIInput, { nullable: true })
11
+ openaiAssistantAPI?: OpenAIApiAssistantAPIInput;
12
+ }
13
+
14
+ @InputType()
15
+ export class OpenAIApiAssistantAPIInput {
16
+ @Field(() => String, { nullable: true })
17
+ runId?: string;
18
+
19
+ @Field(() => String, { nullable: true })
20
+ threadId?: string;
21
+ }
@@ -0,0 +1,22 @@
1
+ import { Field, InputType } from "type-graphql";
2
+
3
+ @InputType()
4
+ export class ForwardedParametersInput {
5
+ @Field(() => String, { nullable: true })
6
+ model?: string;
7
+
8
+ @Field(() => Number, { nullable: true })
9
+ maxTokens?: number;
10
+
11
+ @Field(() => [String], { nullable: true })
12
+ stop?: string[];
13
+
14
+ @Field(() => String, { nullable: true })
15
+ toolChoice?: String;
16
+
17
+ @Field(() => String, { nullable: true })
18
+ toolChoiceFunctionName?: string;
19
+
20
+ @Field(() => Number, { nullable: true })
21
+ temperature?: number;
22
+ }
@@ -0,0 +1,14 @@
1
+ import { Field, InputType } from "type-graphql";
2
+ import { ActionInput } from "./action.input";
3
+
4
+ @InputType()
5
+ export class FrontendInput {
6
+ @Field(() => String, { nullable: true })
7
+ toDeprecate_fullContext?: string;
8
+
9
+ @Field(() => [ActionInput])
10
+ actions: ActionInput[];
11
+
12
+ @Field(() => String, { nullable: true })
13
+ url?: string;
14
+ }
@@ -0,0 +1,59 @@
1
+ import { Field, InputType } from "type-graphql";
2
+ import { MessageInput } from "./message.input";
3
+ import { FrontendInput } from "./frontend.input";
4
+ import { CloudInput } from "./cloud.input";
5
+ import { CopilotRequestType } from "../types/enums";
6
+ import { ForwardedParametersInput } from "./forwarded-parameters.input";
7
+ import { AgentSessionInput } from "./agent-session.input";
8
+ import { AgentStateInput } from "./agent-state.input";
9
+ import { ExtensionsInput } from "./extensions.input";
10
+ import { MetaEventInput } from "./meta-event.input";
11
+ import { CopilotContextInput } from "./copilot-context.input";
12
+
13
+ @InputType()
14
+ export class GenerateCopilotResponseMetadataInput {
15
+ @Field(() => CopilotRequestType, { nullable: true })
16
+ requestType: CopilotRequestType;
17
+ }
18
+
19
+ @InputType()
20
+ export class GenerateCopilotResponseInput {
21
+ @Field(() => GenerateCopilotResponseMetadataInput, { nullable: false })
22
+ metadata: GenerateCopilotResponseMetadataInput;
23
+
24
+ @Field(() => String, { nullable: true })
25
+ threadId?: string;
26
+
27
+ @Field(() => String, { nullable: true })
28
+ runId?: string;
29
+
30
+ @Field(() => [MessageInput])
31
+ messages: MessageInput[];
32
+
33
+ @Field(() => FrontendInput)
34
+ frontend: FrontendInput;
35
+
36
+ @Field(() => CloudInput, { nullable: true })
37
+ cloud?: CloudInput;
38
+
39
+ @Field(() => ForwardedParametersInput, { nullable: true })
40
+ forwardedParameters?: ForwardedParametersInput;
41
+
42
+ @Field(() => AgentSessionInput, { nullable: true })
43
+ agentSession?: AgentSessionInput;
44
+
45
+ @Field(() => AgentStateInput, { nullable: true })
46
+ agentState?: AgentStateInput;
47
+
48
+ @Field(() => [AgentStateInput], { nullable: true })
49
+ agentStates?: AgentStateInput[];
50
+
51
+ @Field(() => ExtensionsInput, { nullable: true })
52
+ extensions?: ExtensionsInput;
53
+
54
+ @Field(() => [MetaEventInput], { nullable: true })
55
+ metaEvents?: MetaEventInput[];
56
+
57
+ @Field(() => [CopilotContextInput], { nullable: true })
58
+ context?: CopilotContextInput[];
59
+ }
@@ -0,0 +1,10 @@
1
+ import { Field, InputType } from "type-graphql";
2
+
3
+ @InputType()
4
+ export class LoadAgentStateInput {
5
+ @Field(() => String)
6
+ threadId: string;
7
+
8
+ @Field(() => String)
9
+ agentName: string;
10
+ }
@@ -0,0 +1,110 @@
1
+ import { Field, InputType } from "type-graphql";
2
+ import { MessageRole } from "../types/enums";
3
+ import { BaseMessageInput } from "../types/base";
4
+
5
+ // GraphQL does not support union types in inputs, so we need to use
6
+ // optional fields for the different subtypes.
7
+ @InputType()
8
+ export class MessageInput extends BaseMessageInput {
9
+ @Field(() => TextMessageInput, { nullable: true })
10
+ textMessage?: TextMessageInput;
11
+
12
+ @Field(() => ActionExecutionMessageInput, { nullable: true })
13
+ actionExecutionMessage?: ActionExecutionMessageInput;
14
+
15
+ @Field(() => ResultMessageInput, { nullable: true })
16
+ resultMessage?: ResultMessageInput;
17
+
18
+ @Field(() => AgentStateMessageInput, { nullable: true })
19
+ agentStateMessage?: AgentStateMessageInput;
20
+
21
+ @Field(() => ImageMessageInput, { nullable: true })
22
+ imageMessage?: ImageMessageInput;
23
+ }
24
+
25
+ @InputType()
26
+ export class TextMessageInput {
27
+ @Field(() => String)
28
+ content: string;
29
+
30
+ @Field(() => String, { nullable: true })
31
+ parentMessageId?: string;
32
+
33
+ @Field(() => MessageRole)
34
+ role: MessageRole;
35
+ }
36
+
37
+ @InputType()
38
+ export class ActionExecutionMessageInput {
39
+ @Field(() => String)
40
+ name: string;
41
+
42
+ @Field(() => String)
43
+ arguments: string;
44
+
45
+ @Field(() => String, { nullable: true })
46
+ parentMessageId?: string;
47
+
48
+ @Field(() => String, {
49
+ nullable: true,
50
+ deprecationReason: "This field will be removed in a future version",
51
+ })
52
+ scope?: String;
53
+ }
54
+
55
+ @InputType()
56
+ export class ResultMessageInput {
57
+ @Field(() => String)
58
+ actionExecutionId: string;
59
+
60
+ @Field(() => String)
61
+ actionName: string;
62
+
63
+ @Field(() => String, { nullable: true })
64
+ parentMessageId?: string;
65
+
66
+ @Field(() => String)
67
+ result: string;
68
+ }
69
+
70
+ @InputType()
71
+ export class AgentStateMessageInput {
72
+ @Field(() => String)
73
+ threadId: string;
74
+
75
+ @Field(() => String)
76
+ agentName: string;
77
+
78
+ @Field(() => MessageRole)
79
+ role: MessageRole;
80
+
81
+ @Field(() => String)
82
+ state: string;
83
+
84
+ @Field(() => Boolean)
85
+ running: boolean;
86
+
87
+ @Field(() => String)
88
+ nodeName: string;
89
+
90
+ @Field(() => String)
91
+ runId: string;
92
+
93
+ @Field(() => Boolean)
94
+ active: boolean;
95
+ }
96
+
97
+ @InputType()
98
+ export class ImageMessageInput {
99
+ @Field(() => String)
100
+ format: string;
101
+
102
+ @Field(() => String)
103
+ bytes: string;
104
+
105
+ @Field(() => String, { nullable: true })
106
+ parentMessageId?: string;
107
+
108
+ @Field(() => MessageRole)
109
+ role: MessageRole;
110
+ }
@@ -0,0 +1,18 @@
1
+ import { Field, InputType } from "type-graphql";
2
+ import { MetaEventName } from "../types/meta-events.type";
3
+ import { MessageInput } from "./message.input";
4
+
5
+ @InputType()
6
+ export class MetaEventInput {
7
+ @Field(() => MetaEventName)
8
+ name: MetaEventName;
9
+
10
+ @Field(() => String)
11
+ value?: string;
12
+
13
+ @Field(() => String, { nullable: true })
14
+ response?: string;
15
+
16
+ @Field(() => [MessageInput], { nullable: true })
17
+ messages?: MessageInput[];
18
+ }