@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,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
package/src/lib/index.ts
ADDED
|
@@ -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,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
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { YogaInitialContext } from "graphql-yoga";
|
|
2
|
+
import { buildSchemaSync } from "type-graphql";
|
|
3
|
+
import { CopilotResolver } from "../../graphql/resolvers/copilot.resolver";
|
|
4
|
+
import { useDeferStream } from "@graphql-yoga/plugin-defer-stream";
|
|
5
|
+
import { CopilotRuntime } from "../runtime/copilot-runtime";
|
|
6
|
+
import { CopilotServiceAdapter } from "../../service-adapters";
|
|
7
|
+
import { CopilotCloudOptions } from "../cloud";
|
|
8
|
+
import { LogLevel, createLogger } from "../../lib/logger";
|
|
9
|
+
import { createYoga } from "graphql-yoga";
|
|
10
|
+
import telemetry from "../telemetry-client";
|
|
11
|
+
|
|
12
|
+
const logger = createLogger();
|
|
13
|
+
|
|
14
|
+
type AnyPrimitive = string | boolean | number | null;
|
|
15
|
+
export type CopilotRequestContextProperties = Record<
|
|
16
|
+
string,
|
|
17
|
+
AnyPrimitive | Record<string, AnyPrimitive>
|
|
18
|
+
>;
|
|
19
|
+
|
|
20
|
+
export type GraphQLContext = YogaInitialContext & {
|
|
21
|
+
_copilotkit: CreateCopilotRuntimeServerOptions;
|
|
22
|
+
properties: CopilotRequestContextProperties;
|
|
23
|
+
logger: typeof logger;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export interface CreateCopilotRuntimeServerOptions {
|
|
27
|
+
runtime: CopilotRuntime<any>;
|
|
28
|
+
serviceAdapter: CopilotServiceAdapter;
|
|
29
|
+
endpoint: string;
|
|
30
|
+
baseUrl?: string;
|
|
31
|
+
cloud?: CopilotCloudOptions;
|
|
32
|
+
properties?: CopilotRequestContextProperties;
|
|
33
|
+
logLevel?: LogLevel;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function createContext(
|
|
37
|
+
initialContext: YogaInitialContext,
|
|
38
|
+
copilotKitContext: CreateCopilotRuntimeServerOptions,
|
|
39
|
+
contextLogger: typeof logger,
|
|
40
|
+
properties: CopilotRequestContextProperties = {},
|
|
41
|
+
): Promise<Partial<GraphQLContext>> {
|
|
42
|
+
logger.debug({ copilotKitContext }, "Creating GraphQL context");
|
|
43
|
+
const ctx: GraphQLContext = {
|
|
44
|
+
...initialContext,
|
|
45
|
+
_copilotkit: {
|
|
46
|
+
...copilotKitContext,
|
|
47
|
+
},
|
|
48
|
+
properties: { ...properties },
|
|
49
|
+
logger: contextLogger,
|
|
50
|
+
};
|
|
51
|
+
return ctx;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function buildSchema(
|
|
55
|
+
options: {
|
|
56
|
+
emitSchemaFile?: string;
|
|
57
|
+
} = {},
|
|
58
|
+
) {
|
|
59
|
+
logger.debug("Building GraphQL schema...");
|
|
60
|
+
const schema = buildSchemaSync({
|
|
61
|
+
resolvers: [CopilotResolver],
|
|
62
|
+
emitSchemaFile: options.emitSchemaFile,
|
|
63
|
+
});
|
|
64
|
+
logger.debug("GraphQL schema built successfully");
|
|
65
|
+
return schema;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export type CommonConfig = {
|
|
69
|
+
logging: typeof logger;
|
|
70
|
+
schema: ReturnType<typeof buildSchema>;
|
|
71
|
+
plugins: Parameters<typeof createYoga>[0]["plugins"];
|
|
72
|
+
context: (ctx: YogaInitialContext) => Promise<Partial<GraphQLContext>>;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export function getCommonConfig(options: CreateCopilotRuntimeServerOptions): CommonConfig {
|
|
76
|
+
const logLevel = (process.env.LOG_LEVEL as LogLevel) || (options.logLevel as LogLevel) || "error";
|
|
77
|
+
const logger = createLogger({ level: logLevel, component: "getCommonConfig" });
|
|
78
|
+
|
|
79
|
+
const contextLogger = createLogger({ level: logLevel });
|
|
80
|
+
|
|
81
|
+
if (options.cloud) {
|
|
82
|
+
telemetry.setCloudConfiguration({
|
|
83
|
+
publicApiKey: options.cloud.publicApiKey,
|
|
84
|
+
baseUrl: options.cloud.baseUrl,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (options.properties?._copilotkit) {
|
|
89
|
+
telemetry.setGlobalProperties({
|
|
90
|
+
_copilotkit: {
|
|
91
|
+
...(options.properties._copilotkit as Record<string, any>),
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
telemetry.setGlobalProperties({
|
|
97
|
+
runtime: {
|
|
98
|
+
serviceAdapter: options.serviceAdapter.constructor.name,
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
logging: createLogger({ component: "Yoga GraphQL", level: logLevel }),
|
|
104
|
+
schema: buildSchema(),
|
|
105
|
+
plugins: [useDeferStream()],
|
|
106
|
+
context: (ctx: YogaInitialContext): Promise<Partial<GraphQLContext>> =>
|
|
107
|
+
createContext(ctx, options, contextLogger, options.properties),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import createPinoLogger from "pino";
|
|
2
|
+
import pretty from "pino-pretty";
|
|
3
|
+
|
|
4
|
+
export type LogLevel = "debug" | "info" | "warn" | "error";
|
|
5
|
+
|
|
6
|
+
export type CopilotRuntimeLogger = ReturnType<typeof createLogger>;
|
|
7
|
+
|
|
8
|
+
export function createLogger(options?: { level?: LogLevel; component?: string }) {
|
|
9
|
+
const { level, component } = options || {};
|
|
10
|
+
const stream = pretty({ colorize: true });
|
|
11
|
+
|
|
12
|
+
const logger = createPinoLogger(
|
|
13
|
+
{
|
|
14
|
+
level: process.env.LOG_LEVEL || level || "error",
|
|
15
|
+
redact: {
|
|
16
|
+
paths: ["pid", "hostname"],
|
|
17
|
+
remove: true,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
stream,
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
if (component) {
|
|
24
|
+
return logger.child({ component });
|
|
25
|
+
} else {
|
|
26
|
+
return logger;
|
|
27
|
+
}
|
|
28
|
+
}
|