@copilotkit/runtime 0.0.0-feat-dynamic-copilotcloud-qa-20250117190454

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 (147) hide show
  1. package/.eslintrc.js +7 -0
  2. package/CHANGELOG.md +913 -0
  3. package/README.md +46 -0
  4. package/__snapshots__/schema/schema.graphql +273 -0
  5. package/dist/chunk-44O2JGUY.mjs +12 -0
  6. package/dist/chunk-44O2JGUY.mjs.map +1 -0
  7. package/dist/chunk-BETLEV37.mjs +25 -0
  8. package/dist/chunk-BETLEV37.mjs.map +1 -0
  9. package/dist/chunk-CLGKEUOA.mjs +1408 -0
  10. package/dist/chunk-CLGKEUOA.mjs.map +1 -0
  11. package/dist/chunk-D2WLFQS6.mjs +43 -0
  12. package/dist/chunk-D2WLFQS6.mjs.map +1 -0
  13. package/dist/chunk-DFOKBSIS.mjs +1 -0
  14. package/dist/chunk-DFOKBSIS.mjs.map +1 -0
  15. package/dist/chunk-FA5DJ2TZ.mjs +3437 -0
  16. package/dist/chunk-FA5DJ2TZ.mjs.map +1 -0
  17. package/dist/chunk-HNUNXFTW.mjs +129 -0
  18. package/dist/chunk-HNUNXFTW.mjs.map +1 -0
  19. package/dist/chunk-SFLMY3ES.mjs +80 -0
  20. package/dist/chunk-SFLMY3ES.mjs.map +1 -0
  21. package/dist/chunk-U3V2BCGI.mjs +152 -0
  22. package/dist/chunk-U3V2BCGI.mjs.map +1 -0
  23. package/dist/chunk-ZCU6UPCY.mjs +25 -0
  24. package/dist/chunk-ZCU6UPCY.mjs.map +1 -0
  25. package/dist/copilot-runtime-1a224a0f.d.ts +196 -0
  26. package/dist/graphql/types/base/index.d.ts +6 -0
  27. package/dist/graphql/types/base/index.js +63 -0
  28. package/dist/graphql/types/base/index.js.map +1 -0
  29. package/dist/graphql/types/base/index.mjs +8 -0
  30. package/dist/graphql/types/base/index.mjs.map +1 -0
  31. package/dist/graphql/types/converted/index.d.ts +2 -0
  32. package/dist/graphql/types/converted/index.js +187 -0
  33. package/dist/graphql/types/converted/index.js.map +1 -0
  34. package/dist/graphql/types/converted/index.mjs +17 -0
  35. package/dist/graphql/types/converted/index.mjs.map +1 -0
  36. package/dist/groq-adapter-c35c5374.d.ts +281 -0
  37. package/dist/index-24315d90.d.ts +103 -0
  38. package/dist/index.d.ts +23 -0
  39. package/dist/index.js +5258 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/index.mjs +76 -0
  42. package/dist/index.mjs.map +1 -0
  43. package/dist/langserve-a16ef8f4.d.ts +180 -0
  44. package/dist/lib/cloud/index.d.ts +6 -0
  45. package/dist/lib/cloud/index.js +18 -0
  46. package/dist/lib/cloud/index.js.map +1 -0
  47. package/dist/lib/cloud/index.mjs +1 -0
  48. package/dist/lib/cloud/index.mjs.map +1 -0
  49. package/dist/lib/index.d.ts +20 -0
  50. package/dist/lib/index.js +4906 -0
  51. package/dist/lib/index.js.map +1 -0
  52. package/dist/lib/index.mjs +58 -0
  53. package/dist/lib/index.mjs.map +1 -0
  54. package/dist/lib/integrations/index.d.ts +33 -0
  55. package/dist/lib/integrations/index.js +2229 -0
  56. package/dist/lib/integrations/index.js.map +1 -0
  57. package/dist/lib/integrations/index.mjs +34 -0
  58. package/dist/lib/integrations/index.mjs.map +1 -0
  59. package/dist/lib/integrations/nest/index.d.ts +14 -0
  60. package/dist/lib/integrations/nest/index.js +2138 -0
  61. package/dist/lib/integrations/nest/index.js.map +1 -0
  62. package/dist/lib/integrations/nest/index.mjs +13 -0
  63. package/dist/lib/integrations/nest/index.mjs.map +1 -0
  64. package/dist/lib/integrations/node-express/index.d.ts +14 -0
  65. package/dist/lib/integrations/node-express/index.js +2138 -0
  66. package/dist/lib/integrations/node-express/index.js.map +1 -0
  67. package/dist/lib/integrations/node-express/index.mjs +13 -0
  68. package/dist/lib/integrations/node-express/index.mjs.map +1 -0
  69. package/dist/lib/integrations/node-http/index.d.ts +14 -0
  70. package/dist/lib/integrations/node-http/index.js +2124 -0
  71. package/dist/lib/integrations/node-http/index.js.map +1 -0
  72. package/dist/lib/integrations/node-http/index.mjs +12 -0
  73. package/dist/lib/integrations/node-http/index.mjs.map +1 -0
  74. package/dist/service-adapters/index.d.ts +84 -0
  75. package/dist/service-adapters/index.js +1448 -0
  76. package/dist/service-adapters/index.js.map +1 -0
  77. package/dist/service-adapters/index.mjs +26 -0
  78. package/dist/service-adapters/index.mjs.map +1 -0
  79. package/dist/utils/index.d.ts +49 -0
  80. package/dist/utils/index.js +174 -0
  81. package/dist/utils/index.js.map +1 -0
  82. package/dist/utils/index.mjs +12 -0
  83. package/dist/utils/index.mjs.map +1 -0
  84. package/jest.config.js +5 -0
  85. package/package.json +85 -0
  86. package/scripts/generate-gql-schema.ts +13 -0
  87. package/src/agents/langgraph/event-source.ts +287 -0
  88. package/src/agents/langgraph/events.ts +338 -0
  89. package/src/graphql/inputs/action.input.ts +16 -0
  90. package/src/graphql/inputs/agent-session.input.ts +13 -0
  91. package/src/graphql/inputs/agent-state.input.ts +10 -0
  92. package/src/graphql/inputs/cloud-guardrails.input.ts +16 -0
  93. package/src/graphql/inputs/cloud.input.ts +8 -0
  94. package/src/graphql/inputs/context-property.input.ts +10 -0
  95. package/src/graphql/inputs/custom-property.input.ts +15 -0
  96. package/src/graphql/inputs/forwarded-parameters.input.ts +22 -0
  97. package/src/graphql/inputs/frontend.input.ts +14 -0
  98. package/src/graphql/inputs/generate-copilot-response.input.ts +47 -0
  99. package/src/graphql/inputs/message.input.ts +92 -0
  100. package/src/graphql/resolvers/copilot.resolver.ts +556 -0
  101. package/src/graphql/types/agents-response.type.ts +22 -0
  102. package/src/graphql/types/base/index.ts +10 -0
  103. package/src/graphql/types/converted/index.ts +136 -0
  104. package/src/graphql/types/copilot-response.type.ts +113 -0
  105. package/src/graphql/types/enums.ts +37 -0
  106. package/src/graphql/types/guardrails-result.type.ts +20 -0
  107. package/src/graphql/types/message-status.type.ts +40 -0
  108. package/src/graphql/types/response-status.type.ts +66 -0
  109. package/src/index.ts +4 -0
  110. package/src/lib/cloud/index.ts +4 -0
  111. package/src/lib/index.ts +8 -0
  112. package/src/lib/integrations/index.ts +6 -0
  113. package/src/lib/integrations/nest/index.ts +17 -0
  114. package/src/lib/integrations/nextjs/app-router.ts +40 -0
  115. package/src/lib/integrations/nextjs/pages-router.ts +49 -0
  116. package/src/lib/integrations/node-express/index.ts +17 -0
  117. package/src/lib/integrations/node-http/index.ts +34 -0
  118. package/src/lib/integrations/shared.ts +109 -0
  119. package/src/lib/logger.ts +28 -0
  120. package/src/lib/runtime/copilot-runtime.ts +466 -0
  121. package/src/lib/runtime/remote-action-constructors.ts +304 -0
  122. package/src/lib/runtime/remote-actions.ts +174 -0
  123. package/src/lib/runtime/remote-lg-action.ts +657 -0
  124. package/src/lib/telemetry-client.ts +52 -0
  125. package/src/service-adapters/anthropic/anthropic-adapter.ts +205 -0
  126. package/src/service-adapters/anthropic/utils.ts +144 -0
  127. package/src/service-adapters/conversion.ts +64 -0
  128. package/src/service-adapters/events.ts +419 -0
  129. package/src/service-adapters/experimental/empty/empty-adapter.ts +33 -0
  130. package/src/service-adapters/experimental/ollama/ollama-adapter.ts +79 -0
  131. package/src/service-adapters/google/google-genai-adapter.ts +39 -0
  132. package/src/service-adapters/groq/groq-adapter.ts +173 -0
  133. package/src/service-adapters/index.ts +16 -0
  134. package/src/service-adapters/langchain/langchain-adapter.ts +99 -0
  135. package/src/service-adapters/langchain/langserve.ts +87 -0
  136. package/src/service-adapters/langchain/types.ts +14 -0
  137. package/src/service-adapters/langchain/utils.ts +306 -0
  138. package/src/service-adapters/openai/openai-adapter.ts +210 -0
  139. package/src/service-adapters/openai/openai-assistant-adapter.ts +304 -0
  140. package/src/service-adapters/openai/utils.ts +161 -0
  141. package/src/service-adapters/service-adapter.ts +30 -0
  142. package/src/service-adapters/unify/unify-adapter.ts +145 -0
  143. package/src/utils/failed-response-status-reasons.ts +48 -0
  144. package/src/utils/index.ts +1 -0
  145. package/tsconfig.json +11 -0
  146. package/tsup.config.ts +16 -0
  147. package/typedoc.json +4 -0
@@ -0,0 +1,136 @@
1
+ import {
2
+ ActionExecutionMessageInput,
3
+ ResultMessageInput,
4
+ TextMessageInput,
5
+ AgentStateMessageInput,
6
+ } from "../../inputs/message.input";
7
+ import { BaseMessageInput } from "../base";
8
+ import { MessageRole } from "../enums";
9
+
10
+ export type MessageType =
11
+ | "TextMessage"
12
+ | "ActionExecutionMessage"
13
+ | "ResultMessage"
14
+ | "AgentStateMessage";
15
+
16
+ export class Message extends BaseMessageInput {
17
+ type: MessageType;
18
+
19
+ isTextMessage(): this is TextMessage {
20
+ return this.type === "TextMessage";
21
+ }
22
+
23
+ isActionExecutionMessage(): this is ActionExecutionMessage {
24
+ return this.type === "ActionExecutionMessage";
25
+ }
26
+
27
+ isResultMessage(): this is ResultMessage {
28
+ return this.type === "ResultMessage";
29
+ }
30
+
31
+ isAgentStateMessage(): this is AgentStateMessage {
32
+ return this.type === "AgentStateMessage";
33
+ }
34
+ }
35
+
36
+ export class TextMessage extends Message implements TextMessageInput {
37
+ type: MessageType = "TextMessage";
38
+ content: string;
39
+ role: MessageRole;
40
+ parentMessageId?: string;
41
+ }
42
+
43
+ export class ActionExecutionMessage
44
+ extends Message
45
+ implements Omit<ActionExecutionMessageInput, "arguments" | "scope">
46
+ {
47
+ type: MessageType = "ActionExecutionMessage";
48
+ name: string;
49
+ arguments: Record<string, any>;
50
+ parentMessageId?: string;
51
+ }
52
+
53
+ export class ResultMessage extends Message implements ResultMessageInput {
54
+ type: MessageType = "ResultMessage";
55
+ actionExecutionId: string;
56
+ actionName: string;
57
+ result: string;
58
+
59
+ static encodeResult(
60
+ result: any,
61
+ error?: { code: string; message: string } | string | Error,
62
+ ): string {
63
+ const errorObj = error
64
+ ? typeof error === "string"
65
+ ? { code: "ERROR", message: error }
66
+ : error instanceof Error
67
+ ? { code: "ERROR", message: error.message }
68
+ : error
69
+ : undefined;
70
+
71
+ if (errorObj) {
72
+ return JSON.stringify({
73
+ error: errorObj,
74
+ result: result || "",
75
+ });
76
+ }
77
+ if (result === undefined) {
78
+ return "";
79
+ }
80
+ return typeof result === "string" ? result : JSON.stringify(result);
81
+ }
82
+
83
+ static decodeResult(result: string): {
84
+ error?: { code: string; message: string };
85
+ result: string;
86
+ } {
87
+ if (!result) {
88
+ return { result: "" };
89
+ }
90
+ try {
91
+ const parsed = JSON.parse(result);
92
+ if (parsed && typeof parsed === "object") {
93
+ if ("error" in parsed) {
94
+ return {
95
+ error: parsed.error,
96
+ result: parsed.result || "",
97
+ };
98
+ }
99
+ return { result: JSON.stringify(parsed) };
100
+ }
101
+ return { result };
102
+ } catch (e) {
103
+ return { result };
104
+ }
105
+ }
106
+
107
+ hasError(): boolean {
108
+ try {
109
+ const { error } = ResultMessage.decodeResult(this.result);
110
+ return !!error;
111
+ } catch {
112
+ return false;
113
+ }
114
+ }
115
+
116
+ getError(): { code: string; message: string } | undefined {
117
+ try {
118
+ const { error } = ResultMessage.decodeResult(this.result);
119
+ return error;
120
+ } catch {
121
+ return undefined;
122
+ }
123
+ }
124
+ }
125
+
126
+ export class AgentStateMessage extends Message implements Omit<AgentStateMessageInput, "state"> {
127
+ type: MessageType = "AgentStateMessage";
128
+ threadId: string;
129
+ agentName: string;
130
+ nodeName: string;
131
+ runId: string;
132
+ active: boolean;
133
+ role: MessageRole;
134
+ state: any;
135
+ running: boolean;
136
+ }
@@ -0,0 +1,113 @@
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
+
6
+ @InterfaceType({
7
+ resolveType(value) {
8
+ if (value.hasOwnProperty("content")) {
9
+ return TextMessageOutput;
10
+ } else if (value.hasOwnProperty("name")) {
11
+ return ActionExecutionMessageOutput;
12
+ } else if (value.hasOwnProperty("result")) {
13
+ return ResultMessageOutput;
14
+ } else if (value.hasOwnProperty("state")) {
15
+ return AgentStateMessageOutput;
16
+ }
17
+ return undefined;
18
+ },
19
+ })
20
+ abstract class BaseMessageOutput {
21
+ @Field(() => String)
22
+ id: string;
23
+
24
+ @Field(() => Date)
25
+ createdAt: Date;
26
+
27
+ @Field(() => MessageStatusUnion)
28
+ status: typeof MessageStatusUnion;
29
+ }
30
+
31
+ @ObjectType({ implements: BaseMessageOutput })
32
+ export class TextMessageOutput {
33
+ @Field(() => MessageRole)
34
+ role: MessageRole;
35
+
36
+ @Field(() => [String])
37
+ content: string[];
38
+
39
+ @Field(() => String, { nullable: true })
40
+ parentMessageId?: string;
41
+ }
42
+
43
+ @ObjectType({ implements: BaseMessageOutput })
44
+ export class ActionExecutionMessageOutput {
45
+ @Field(() => String)
46
+ name: 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
+ @Field(() => [String])
55
+ arguments: string[];
56
+
57
+ @Field(() => String, { nullable: true })
58
+ parentMessageId?: string;
59
+ }
60
+
61
+ @ObjectType({ implements: BaseMessageOutput })
62
+ export class ResultMessageOutput {
63
+ @Field(() => String)
64
+ actionExecutionId: string;
65
+
66
+ @Field(() => String)
67
+ actionName: string;
68
+
69
+ @Field(() => String)
70
+ result: string;
71
+ }
72
+
73
+ @ObjectType({ implements: BaseMessageOutput })
74
+ export class AgentStateMessageOutput {
75
+ @Field(() => String)
76
+ threadId: string;
77
+
78
+ @Field(() => String)
79
+ agentName: string;
80
+
81
+ @Field(() => String)
82
+ nodeName: string;
83
+
84
+ @Field(() => String)
85
+ runId: string;
86
+
87
+ @Field(() => Boolean)
88
+ active: boolean;
89
+
90
+ @Field(() => MessageRole)
91
+ role: MessageRole;
92
+
93
+ @Field(() => String)
94
+ state: string;
95
+
96
+ @Field(() => Boolean)
97
+ running: boolean;
98
+ }
99
+
100
+ @ObjectType()
101
+ export class CopilotResponse {
102
+ @Field(() => String)
103
+ threadId!: string;
104
+
105
+ @Field(() => ResponseStatusUnion)
106
+ status: typeof ResponseStatusUnion;
107
+
108
+ @Field({ nullable: true })
109
+ runId?: string;
110
+
111
+ @Field(() => [BaseMessageOutput])
112
+ messages: (typeof BaseMessageOutput)[];
113
+ }
@@ -0,0 +1,37 @@
1
+ import { registerEnumType } from "type-graphql";
2
+
3
+ export enum MessageRole {
4
+ user = "user",
5
+ assistant = "assistant",
6
+ system = "system",
7
+ tool = "tool",
8
+ }
9
+
10
+ export enum CopilotRequestType {
11
+ Chat = "Chat",
12
+ Task = "Task",
13
+ TextareaCompletion = "TextareaCompletion",
14
+ TextareaPopover = "TextareaPopover",
15
+ Suggestion = "Suggestion",
16
+ }
17
+
18
+ export enum ActionInputAvailability {
19
+ disabled = "disabled",
20
+ enabled = "enabled",
21
+ remote = "remote",
22
+ }
23
+
24
+ registerEnumType(MessageRole, {
25
+ name: "MessageRole",
26
+ description: "The role of the message",
27
+ });
28
+
29
+ registerEnumType(CopilotRequestType, {
30
+ name: "CopilotRequestType",
31
+ description: "The type of Copilot request",
32
+ });
33
+
34
+ registerEnumType(ActionInputAvailability, {
35
+ name: "ActionInputAvailability",
36
+ description: "The availability of the frontend action",
37
+ });
@@ -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,40 @@
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
+ 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
+ });
@@ -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
@@ -0,0 +1,4 @@
1
+ import "reflect-metadata";
2
+ export * from "./lib";
3
+ export * from "./utils";
4
+ export * from "./service-adapters";
@@ -0,0 +1,4 @@
1
+ export interface CopilotCloudOptions {
2
+ baseUrl?: string;
3
+ publicApiKey?: string;
4
+ }
@@ -0,0 +1,8 @@
1
+ export * from "./runtime/copilot-runtime";
2
+ export * from "../service-adapters/openai/openai-adapter";
3
+ export * from "../service-adapters/langchain/langchain-adapter";
4
+ export * from "../service-adapters/google/google-genai-adapter";
5
+ export * from "../service-adapters/openai/openai-assistant-adapter";
6
+ export * from "../service-adapters/unify/unify-adapter";
7
+ export * from "../service-adapters/groq/groq-adapter";
8
+ export * from "./integrations";
@@ -0,0 +1,6 @@
1
+ export * from "./shared";
2
+ export * from "./nextjs/app-router";
3
+ export * from "./nextjs/pages-router";
4
+ export * from "./node-http";
5
+ export * from "./node-express";
6
+ export * from "./nest";
@@ -0,0 +1,17 @@
1
+ import { CreateCopilotRuntimeServerOptions } from "../shared";
2
+ import { copilotRuntimeNodeHttpEndpoint } from "../node-http";
3
+ import telemetry, { getRuntimeInstanceTelemetryInfo } from "../../telemetry-client";
4
+
5
+ export function copilotRuntimeNestEndpoint(options: CreateCopilotRuntimeServerOptions) {
6
+ telemetry.setGlobalProperties({
7
+ runtime: {
8
+ framework: "nest",
9
+ },
10
+ });
11
+
12
+ telemetry.capture(
13
+ "oss.runtime.instance_created",
14
+ getRuntimeInstanceTelemetryInfo(options.runtime),
15
+ );
16
+ return copilotRuntimeNodeHttpEndpoint(options);
17
+ }
@@ -0,0 +1,40 @@
1
+ import { createYoga } from "graphql-yoga";
2
+ import { CreateCopilotRuntimeServerOptions, getCommonConfig } from "../shared";
3
+ import telemetry, { getRuntimeInstanceTelemetryInfo } from "../../telemetry-client";
4
+
5
+ export function copilotRuntimeNextJSAppRouterEndpoint(options: CreateCopilotRuntimeServerOptions) {
6
+ const commonConfig = getCommonConfig(options);
7
+
8
+ telemetry.setGlobalProperties({
9
+ runtime: {
10
+ framework: "nextjs-app-router",
11
+ },
12
+ });
13
+
14
+ if (options.properties?._copilotkit) {
15
+ telemetry.setGlobalProperties({
16
+ _copilotkit: options.properties._copilotkit,
17
+ });
18
+ }
19
+
20
+ telemetry.capture(
21
+ "oss.runtime.instance_created",
22
+ getRuntimeInstanceTelemetryInfo(options.runtime),
23
+ );
24
+
25
+ const logger = commonConfig.logging;
26
+ logger.debug("Creating NextJS App Router endpoint");
27
+
28
+ const yoga = createYoga({
29
+ ...commonConfig,
30
+ graphqlEndpoint: options.endpoint,
31
+ fetchAPI: { Response: globalThis.Response },
32
+ });
33
+
34
+ return {
35
+ handleRequest: yoga,
36
+ GET: yoga as any,
37
+ POST: yoga as any,
38
+ OPTIONS: yoga as any,
39
+ };
40
+ }
@@ -0,0 +1,49 @@
1
+ import { YogaServerInstance, createYoga } from "graphql-yoga";
2
+ import { CreateCopilotRuntimeServerOptions, GraphQLContext, getCommonConfig } from "../shared";
3
+ import telemetry, { getRuntimeInstanceTelemetryInfo } from "../../telemetry-client";
4
+
5
+ export const config = {
6
+ api: {
7
+ bodyParser: false,
8
+ },
9
+ };
10
+
11
+ export type CopilotRuntimeServerInstance<T> = YogaServerInstance<T, Partial<GraphQLContext>>;
12
+
13
+ // This import is needed to fix the type error
14
+ // Fix is currently in TypeScript 5.5 beta, waiting for stable version
15
+ // https://github.com/microsoft/TypeScript/issues/42873#issuecomment-2066874644
16
+ export type {} from "@whatwg-node/server";
17
+
18
+ export function copilotRuntimeNextJSPagesRouterEndpoint(
19
+ options: CreateCopilotRuntimeServerOptions,
20
+ ): CopilotRuntimeServerInstance<GraphQLContext> {
21
+ const commonConfig = getCommonConfig(options);
22
+
23
+ telemetry.setGlobalProperties({
24
+ runtime: {
25
+ framework: "nextjs-pages-router",
26
+ },
27
+ });
28
+
29
+ if (options.properties?._copilotkit) {
30
+ telemetry.setGlobalProperties({
31
+ _copilotkit: options.properties._copilotkit,
32
+ });
33
+ }
34
+
35
+ telemetry.capture(
36
+ "oss.runtime.instance_created",
37
+ getRuntimeInstanceTelemetryInfo(options.runtime),
38
+ );
39
+
40
+ const logger = commonConfig.logging;
41
+ logger.debug("Creating NextJS Pages Router endpoint");
42
+
43
+ const yoga = createYoga({
44
+ ...commonConfig,
45
+ graphqlEndpoint: options.endpoint,
46
+ });
47
+
48
+ return yoga;
49
+ }
@@ -0,0 +1,17 @@
1
+ import { CreateCopilotRuntimeServerOptions } from "../shared";
2
+ import { copilotRuntimeNodeHttpEndpoint } from "../node-http";
3
+ import telemetry, { getRuntimeInstanceTelemetryInfo } from "../../telemetry-client";
4
+
5
+ export function copilotRuntimeNodeExpressEndpoint(options: CreateCopilotRuntimeServerOptions) {
6
+ telemetry.setGlobalProperties({
7
+ runtime: {
8
+ framework: "node-express",
9
+ },
10
+ });
11
+
12
+ telemetry.capture(
13
+ "oss.runtime.instance_created",
14
+ getRuntimeInstanceTelemetryInfo(options.runtime),
15
+ );
16
+ return copilotRuntimeNodeHttpEndpoint(options);
17
+ }
@@ -0,0 +1,34 @@
1
+ import { createYoga } from "graphql-yoga";
2
+ import { CreateCopilotRuntimeServerOptions, getCommonConfig } from "../shared";
3
+ import telemetry, { getRuntimeInstanceTelemetryInfo } from "../../telemetry-client";
4
+
5
+ export function copilotRuntimeNodeHttpEndpoint(options: CreateCopilotRuntimeServerOptions) {
6
+ const commonConfig = getCommonConfig(options);
7
+
8
+ telemetry.setGlobalProperties({
9
+ runtime: {
10
+ framework: "node-http",
11
+ },
12
+ });
13
+
14
+ if (options.properties?._copilotkit) {
15
+ telemetry.setGlobalProperties({
16
+ _copilotkit: options.properties._copilotkit,
17
+ });
18
+ }
19
+
20
+ telemetry.capture(
21
+ "oss.runtime.instance_created",
22
+ getRuntimeInstanceTelemetryInfo(options.runtime),
23
+ );
24
+
25
+ const logger = commonConfig.logging;
26
+ logger.debug("Creating Node HTTP endpoint");
27
+
28
+ const yoga = createYoga({
29
+ ...commonConfig,
30
+ graphqlEndpoint: options.endpoint,
31
+ });
32
+
33
+ return yoga;
34
+ }