copilotkit 1.54.0 → 2.0.0

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 (146) hide show
  1. package/index.js +89779 -0
  2. package/package.json +4 -114
  3. package/src/commands/docs.d.ts +17 -0
  4. package/src/commands/docs.d.ts.map +1 -0
  5. package/src/commands/init.d.ts +103 -0
  6. package/src/commands/init.d.ts.map +1 -0
  7. package/src/commands/kite.d.ts +8 -0
  8. package/src/commands/kite.d.ts.map +1 -0
  9. package/src/commands/license.d.ts +17 -0
  10. package/src/commands/license.d.ts.map +1 -0
  11. package/src/commands/login.d.ts +13 -0
  12. package/src/commands/login.d.ts.map +1 -0
  13. package/src/commands/logs.d.ts +32 -0
  14. package/src/commands/logs.d.ts.map +1 -0
  15. package/src/commands/version.d.ts +8 -0
  16. package/src/commands/version.d.ts.map +1 -0
  17. package/src/config.d.ts +31 -0
  18. package/src/config.d.ts.map +1 -0
  19. package/src/index.d.ts +21 -0
  20. package/src/index.d.ts.map +1 -0
  21. package/src/services/api-client.d.ts +106 -0
  22. package/src/services/api-client.d.ts.map +1 -0
  23. package/src/services/auth.service.d.ts +107 -0
  24. package/src/services/auth.service.d.ts.map +1 -0
  25. package/src/services/cli-auth-diagnostics.d.ts +71 -0
  26. package/src/services/cli-auth-diagnostics.d.ts.map +1 -0
  27. package/src/services/cli-logs.d.ts +45 -0
  28. package/src/services/cli-logs.d.ts.map +1 -0
  29. package/src/services/config.service.d.ts +53 -0
  30. package/src/services/config.service.d.ts.map +1 -0
  31. package/src/services/feature-flags.d.ts +14 -0
  32. package/src/services/feature-flags.d.ts.map +1 -0
  33. package/src/services/kite-game-engine.d.ts +99 -0
  34. package/src/services/kite-game-engine.d.ts.map +1 -0
  35. package/src/services/kite-game-score.d.ts +33 -0
  36. package/src/services/kite-game-score.d.ts.map +1 -0
  37. package/src/services/project-scaffold.d.ts +49 -0
  38. package/src/services/project-scaffold.d.ts.map +1 -0
  39. package/src/types.d.ts +205 -0
  40. package/src/types.d.ts.map +1 -0
  41. package/src/ui/banner.d.ts +3 -0
  42. package/src/ui/banner.d.ts.map +1 -0
  43. package/src/ui/browser-login.d.ts +71 -0
  44. package/src/ui/browser-login.d.ts.map +1 -0
  45. package/src/ui/init-flow.d.ts +35 -0
  46. package/src/ui/init-flow.d.ts.map +1 -0
  47. package/src/ui/kite-game.d.ts +26 -0
  48. package/src/ui/kite-game.d.ts.map +1 -0
  49. package/src/ui/login-flow.d.ts +22 -0
  50. package/src/ui/login-flow.d.ts.map +1 -0
  51. package/src/ui/spinner.d.ts +9 -0
  52. package/src/ui/spinner.d.ts.map +1 -0
  53. package/LICENSE +0 -21
  54. package/README.md +0 -83
  55. package/bin/dev.cmd +0 -3
  56. package/bin/dev.js +0 -8
  57. package/bin/run.cmd +0 -3
  58. package/bin/run.js +0 -17
  59. package/dist/commands/base-command.d.ts +0 -12
  60. package/dist/commands/base-command.js +0 -65
  61. package/dist/commands/base-command.js.map +0 -1
  62. package/dist/commands/create.d.ts +0 -24
  63. package/dist/commands/create.js +0 -507
  64. package/dist/commands/create.js.map +0 -1
  65. package/dist/commands/dev.d.ts +0 -25
  66. package/dist/commands/dev.js +0 -776
  67. package/dist/commands/dev.js.map +0 -1
  68. package/dist/commands/init.d.ts +0 -11
  69. package/dist/commands/init.js +0 -523
  70. package/dist/commands/init.js.map +0 -1
  71. package/dist/commands/login.d.ts +0 -13
  72. package/dist/commands/login.js +0 -374
  73. package/dist/commands/login.js.map +0 -1
  74. package/dist/commands/logout.d.ts +0 -13
  75. package/dist/commands/logout.js +0 -375
  76. package/dist/commands/logout.js.map +0 -1
  77. package/dist/index.d.ts +0 -1
  78. package/dist/index.js +0 -6
  79. package/dist/index.js.map +0 -1
  80. package/dist/lib/init/ide-docs.d.ts +0 -25
  81. package/dist/lib/init/ide-docs.js +0 -170
  82. package/dist/lib/init/ide-docs.js.map +0 -1
  83. package/dist/lib/init/index.d.ts +0 -14
  84. package/dist/lib/init/index.js +0 -1104
  85. package/dist/lib/init/index.js.map +0 -1
  86. package/dist/lib/init/questions.d.ts +0 -9
  87. package/dist/lib/init/questions.js +0 -508
  88. package/dist/lib/init/questions.js.map +0 -1
  89. package/dist/lib/init/scaffold/agent.d.ts +0 -20
  90. package/dist/lib/init/scaffold/agent.js +0 -173
  91. package/dist/lib/init/scaffold/agent.js.map +0 -1
  92. package/dist/lib/init/scaffold/crew-inputs.d.ts +0 -3
  93. package/dist/lib/init/scaffold/crew-inputs.js +0 -59
  94. package/dist/lib/init/scaffold/crew-inputs.js.map +0 -1
  95. package/dist/lib/init/scaffold/env.d.ts +0 -7
  96. package/dist/lib/init/scaffold/env.js +0 -124
  97. package/dist/lib/init/scaffold/env.js.map +0 -1
  98. package/dist/lib/init/scaffold/github.d.ts +0 -17
  99. package/dist/lib/init/scaffold/github.js +0 -114
  100. package/dist/lib/init/scaffold/github.js.map +0 -1
  101. package/dist/lib/init/scaffold/index.d.ts +0 -10
  102. package/dist/lib/init/scaffold/index.js +0 -690
  103. package/dist/lib/init/scaffold/index.js.map +0 -1
  104. package/dist/lib/init/scaffold/langgraph-assistants.d.ts +0 -18
  105. package/dist/lib/init/scaffold/langgraph-assistants.js +0 -26
  106. package/dist/lib/init/scaffold/langgraph-assistants.js.map +0 -1
  107. package/dist/lib/init/scaffold/packages.d.ts +0 -7
  108. package/dist/lib/init/scaffold/packages.js +0 -62
  109. package/dist/lib/init/scaffold/packages.js.map +0 -1
  110. package/dist/lib/init/scaffold/shadcn.d.ts +0 -7
  111. package/dist/lib/init/scaffold/shadcn.js +0 -279
  112. package/dist/lib/init/scaffold/shadcn.js.map +0 -1
  113. package/dist/lib/init/types/index.d.ts +0 -4
  114. package/dist/lib/init/types/index.js +0 -238
  115. package/dist/lib/init/types/index.js.map +0 -1
  116. package/dist/lib/init/types/questions.d.ts +0 -209
  117. package/dist/lib/init/types/questions.js +0 -214
  118. package/dist/lib/init/types/questions.js.map +0 -1
  119. package/dist/lib/init/types/templates.d.ts +0 -17
  120. package/dist/lib/init/types/templates.js +0 -26
  121. package/dist/lib/init/types/templates.js.map +0 -1
  122. package/dist/lib/init/utils.d.ts +0 -3
  123. package/dist/lib/init/utils.js +0 -8
  124. package/dist/lib/init/utils.js.map +0 -1
  125. package/dist/services/analytics.service.d.ts +0 -38
  126. package/dist/services/analytics.service.js +0 -134
  127. package/dist/services/analytics.service.js.map +0 -1
  128. package/dist/services/auth.service.d.ts +0 -26
  129. package/dist/services/auth.service.js +0 -299
  130. package/dist/services/auth.service.js.map +0 -1
  131. package/dist/services/events.d.ts +0 -119
  132. package/dist/services/events.js +0 -1
  133. package/dist/services/events.js.map +0 -1
  134. package/dist/services/tunnel.service.d.ts +0 -15
  135. package/dist/services/tunnel.service.js +0 -21
  136. package/dist/services/tunnel.service.js.map +0 -1
  137. package/dist/utils/detect-endpoint-type.utils.d.ts +0 -15
  138. package/dist/utils/detect-endpoint-type.utils.js +0 -157
  139. package/dist/utils/detect-endpoint-type.utils.js.map +0 -1
  140. package/dist/utils/trpc.d.ts +0 -4
  141. package/dist/utils/trpc.js +0 -25
  142. package/dist/utils/trpc.js.map +0 -1
  143. package/dist/utils/version.d.ts +0 -3
  144. package/dist/utils/version.js +0 -6
  145. package/dist/utils/version.js.map +0 -1
  146. package/oclif.manifest.json +0 -208
@@ -1,690 +0,0 @@
1
- // src/lib/init/scaffold/shadcn.ts
2
- import spawn from "cross-spawn";
3
-
4
- // src/lib/init/types/questions.ts
5
- import { z } from "zod";
6
- import { Flags } from "@oclif/core";
7
-
8
- // src/lib/init/utils.ts
9
- var isLocalhost = (url) => {
10
- return url.includes("localhost") || url.includes("127.0.0.1") || url.includes("0.0.0.0");
11
- };
12
-
13
- // src/lib/init/types/questions.ts
14
- var MODES = [
15
- "LangGraph",
16
- "CrewAI",
17
- "Mastra",
18
- "LlamaIndex",
19
- "Agno",
20
- "AG2",
21
- "MCP",
22
- "Standard"
23
- ];
24
- var CREW_TYPES = ["Crews", "Flows"];
25
- var CHAT_COMPONENTS = [
26
- "CopilotChat",
27
- "CopilotSidebar",
28
- "Headless",
29
- "CopilotPopup"
30
- ];
31
- var LANGGRAPH_AGENTS = [
32
- "Python Starter",
33
- "TypeScript Starter"
34
- ];
35
- var CREW_FLOW_TEMPLATES = ["Starter"];
36
- var YES_NO = ["Yes", "No"];
37
- var DEPLOYMENT_CHOICES = ["Copilot Cloud", "Self-hosted"];
38
- var sanitizers = {
39
- // Remove trailing slash from URLs
40
- url: (value) => {
41
- if (!value) return value;
42
- return value.trim().replace(/\/+$/, "");
43
- },
44
- // Trim whitespace from strings
45
- trim: (value) => {
46
- if (!value) return value;
47
- return value.trim();
48
- },
49
- // Lowercase strings
50
- lowercase: (value) => {
51
- if (!value) return value;
52
- return value.toLowerCase().trim();
53
- },
54
- // Clean API keys (remove whitespace)
55
- apiKey: (value) => {
56
- if (!value) return value;
57
- return value.trim().replace(/\s/g, "");
58
- }
59
- };
60
- var ModeSchema = z.enum(MODES);
61
- var CrewTypeSchema = z.enum(CREW_TYPES);
62
- var ChatComponentSchema = z.enum(CHAT_COMPONENTS);
63
- var LangGraphAgentSchema = z.enum(LANGGRAPH_AGENTS);
64
- var CrewFlowTemplateSchema = z.enum(CREW_FLOW_TEMPLATES);
65
- var YesNoSchema = z.enum(YES_NO);
66
- var DeploymentChoiceSchema = z.enum(DEPLOYMENT_CHOICES);
67
- var UrlSchema = z.preprocess(
68
- (val) => sanitizers.url(String(val)),
69
- z.string().url("Please enter a valid URL").min(1, "URL is required")
70
- );
71
- var TokenSchema = z.preprocess(
72
- (val) => sanitizers.trim(String(val)),
73
- z.string().min(1, "Token is required")
74
- );
75
- var ApiKeySchema = z.preprocess(
76
- (val) => sanitizers.apiKey(String(val)),
77
- z.string().min(1, "API key is required")
78
- );
79
- var LLMApiKeySchema = z.preprocess(
80
- (val) => sanitizers.apiKey(String(val)),
81
- z.string().optional()
82
- );
83
- var NameSchema = z.preprocess(
84
- (val) => sanitizers.trim(String(val)),
85
- z.string().min(1, "Name is required")
86
- );
87
- var ConfigSchema = z.object({
88
- // Core fields
89
- copilotKitVersion: z.string().optional(),
90
- mode: ModeSchema,
91
- chatUi: ChatComponentSchema.optional(),
92
- // Yes/No fields
93
- alreadyDeployed: YesNoSchema.optional(),
94
- fastApiEnabled: YesNoSchema.optional(),
95
- // DEPRECATED: useCopilotCloud - consolidated with signupForCopilotCloud
96
- useCopilotCloud: YesNoSchema.optional(),
97
- // LangGraph specific fields
98
- langGraphAgent: LangGraphAgentSchema.optional(),
99
- langGraphPlatform: YesNoSchema.optional(),
100
- langGraphPlatformUrl: UrlSchema.optional(),
101
- langGraphRemoteEndpointURL: UrlSchema.optional(),
102
- // CrewAI specific fields
103
- crewType: CrewTypeSchema.optional(),
104
- crewName: NameSchema.optional(),
105
- crewUrl: UrlSchema.optional(),
106
- crewBearerToken: TokenSchema.optional(),
107
- // API keys and tokens
108
- copilotCloudPublicApiKey: z.string().optional(),
109
- langSmithApiKey: ApiKeySchema.optional(),
110
- llmToken: LLMApiKeySchema.optional(),
111
- // IDE Documentation setup fields
112
- setupIDEDocs: YesNoSchema.optional(),
113
- selectedIDE: z.union([z.enum(["cursor", "windsurf"]), z.literal("skip")]).optional(),
114
- // NEW: A/B/C test fields
115
- deploymentChoice: DeploymentChoiceSchema.optional()
116
- // For branch B only (Cloud vs Self-hosted)
117
- }).refine(
118
- (data) => {
119
- if (data.mode === "CrewAI") {
120
- return !!data.crewUrl && !!data.crewBearerToken;
121
- }
122
- return true;
123
- },
124
- {
125
- message: "Crew URL and bearer token are required for CrewAI",
126
- path: ["crewUrl", "crewBearerToken"]
127
- }
128
- ).refine(
129
- (data) => {
130
- if (data.mode === "LangGraph" && data.alreadyDeployed === "Yes" && data.langGraphPlatform === "Yes") {
131
- return !!data.langGraphPlatformUrl && !!data.langSmithApiKey || isLocalhost(data.langGraphPlatformUrl || "");
132
- }
133
- return true;
134
- },
135
- {
136
- message: "LangGraph Platform URL and LangSmith API key are required",
137
- path: ["langGraphPlatformUrl", "langSmithApiKey"]
138
- }
139
- );
140
- var ConfigFlags = {
141
- booth: Flags.boolean({
142
- description: "Use CopilotKit in booth mode",
143
- default: false,
144
- char: "b"
145
- }),
146
- mode: Flags.string({
147
- description: "How you will be interacting with AI",
148
- options: MODES,
149
- char: "m"
150
- }),
151
- "copilotkit-version": Flags.string({
152
- description: "CopilotKit version to use (e.g. 1.7.0)"
153
- }),
154
- "use-copilot-cloud": Flags.string({
155
- description: "Use Copilot Cloud for production-ready hosting",
156
- options: YES_NO
157
- }),
158
- "langgraph-agent": Flags.string({
159
- description: "LangGraph agent template to use",
160
- options: LANGGRAPH_AGENTS
161
- }),
162
- "crew-type": Flags.string({
163
- description: "CrewAI implementation type",
164
- options: CREW_TYPES
165
- }),
166
- "crew-name": Flags.string({ description: "Name for your CrewAI agent" }),
167
- "crew-url": Flags.string({
168
- description: "URL endpoint for your CrewAI agent"
169
- }),
170
- "crew-bearer-token": Flags.string({
171
- description: "Bearer token for CrewAI authentication"
172
- }),
173
- "langsmith-api-key": Flags.string({
174
- description: "LangSmith API key for LangGraph observability"
175
- }),
176
- "llm-token": Flags.string({
177
- description: "API key for your preferred LLM provider"
178
- }),
179
- "setup-ide-docs": Flags.string({
180
- description: "Setup IDE documentation rules for AI assistance",
181
- options: YES_NO
182
- }),
183
- "selected-ide": Flags.string({
184
- description: "IDE to configure with documentation rules",
185
- options: ["cursor", "windsurf", "skip"]
186
- }),
187
- // NEW: A/B/C test flags
188
- "deployment-choice": Flags.string({
189
- description: "Choose between Copilot Cloud or Self-hosted deployment",
190
- options: DEPLOYMENT_CHOICES
191
- })
192
- };
193
-
194
- // src/lib/init/types/templates.ts
195
- var BASE_URL = "https://registry.copilotkit.ai/r";
196
- var templateMapping = {
197
- // Runtimes
198
- RemoteEndpoint: `${BASE_URL}/remote-endpoint.json`,
199
- LangGraphPlatformRuntime: `${BASE_URL}/langgraph-platform-runtime.json`,
200
- // CrewAI
201
- CrewEnterprise: [`${BASE_URL}/coagents-crew-starter.json`],
202
- CrewFlowsEnterprise: [`${BASE_URL}/coagents-starter-crewai-flows.json`],
203
- // LangGraph
204
- LangGraphGeneric: `${BASE_URL}/generic-lg-starter.json`,
205
- LangGraphStarter: [
206
- `${BASE_URL}/langgraph-platform-starter.json`,
207
- `${BASE_URL}/coagents-starter-ui.json`
208
- ],
209
- // No Agent
210
- StandardStarter: `${BASE_URL}/standard-starter.json`,
211
- StandardRuntime: `${BASE_URL}/standard-runtime.json`,
212
- // MCP
213
- McpStarter: `${BASE_URL}/mcp-starter.json`,
214
- McpRuntime: `${BASE_URL}/mcp-starter-runtime.json`
215
- };
216
-
217
- // src/lib/init/scaffold/shadcn.ts
218
- async function scaffoldShadCN(flags, userAnswers) {
219
- try {
220
- const components = [];
221
- switch (userAnswers.mode) {
222
- case "LangGraph":
223
- components.push(templateMapping.LangGraphGeneric);
224
- if (userAnswers.langGraphPlatform === "Yes") {
225
- components.push(templateMapping.LangGraphPlatformRuntime);
226
- } else {
227
- components.push(templateMapping.RemoteEndpoint);
228
- }
229
- break;
230
- case "CrewAI":
231
- if (userAnswers.crewType === "Crews") {
232
- components.push(...templateMapping.CrewEnterprise);
233
- } else if (userAnswers.crewType === "Flows") {
234
- components.push(...templateMapping.CrewFlowsEnterprise);
235
- } else {
236
- components.push(templateMapping.RemoteEndpoint);
237
- }
238
- break;
239
- case "MCP":
240
- components.push(templateMapping.McpStarter);
241
- if (userAnswers.deploymentChoice === "Self-hosted" || userAnswers.useCopilotCloud === "No") {
242
- components.push(templateMapping.McpRuntime);
243
- }
244
- break;
245
- case "Standard":
246
- components.push(templateMapping.StandardStarter);
247
- if (userAnswers.deploymentChoice === "Self-hosted" || userAnswers.useCopilotCloud === "No") {
248
- components.push(templateMapping.StandardRuntime);
249
- }
250
- break;
251
- default:
252
- return;
253
- }
254
- await new Promise((resolve) => setTimeout(resolve, 100));
255
- try {
256
- const result = spawn.sync(
257
- "npx",
258
- ["shadcn@latest", "add", ...components],
259
- {
260
- stdio: "inherit"
261
- // This ensures stdin/stdout/stderr are all passed through
262
- }
263
- );
264
- if (result.status !== 0) {
265
- throw new Error(
266
- `The shadcn installation process exited with code ${result.status}`
267
- );
268
- }
269
- } catch (error) {
270
- throw error;
271
- }
272
- } catch (error) {
273
- throw error;
274
- }
275
- }
276
-
277
- // src/lib/init/scaffold/env.ts
278
- import path from "path";
279
- import fs from "fs";
280
-
281
- // src/lib/init/scaffold/langgraph-assistants.ts
282
- async function getLangGraphAgents(url, langSmithApiKey) {
283
- try {
284
- const response = await fetch(
285
- `${url.trim().replace(/\/$/, "")}/assistants/search`,
286
- {
287
- method: "POST",
288
- headers: {
289
- "Content-Type": "application/json",
290
- "X-Api-Key": langSmithApiKey
291
- },
292
- body: JSON.stringify({
293
- limit: 10,
294
- offset: 0
295
- })
296
- }
297
- );
298
- return await response.json();
299
- } catch (error) {
300
- throw new Error(`Failed to get LangGraph agents: ${error}`);
301
- }
302
- }
303
-
304
- // src/lib/init/scaffold/env.ts
305
- import inquirer from "inquirer";
306
- function needsCloudDeployment(userAnswers) {
307
- return userAnswers.deploymentChoice === "Copilot Cloud" || // Branch B choice
308
- userAnswers.useCopilotCloud === "Yes" || // Branch C choice
309
- userAnswers.mode === "CrewAI" || // CrewAI always needs cloud
310
- !userAnswers.deploymentChoice && !userAnswers.useCopilotCloud;
311
- }
312
- async function scaffoldEnv(flags, userAnswers) {
313
- try {
314
- const envFile = path.join(process.cwd(), ".env");
315
- if (!fs.existsSync(envFile)) {
316
- fs.writeFileSync(envFile, "", "utf8");
317
- } else {
318
- }
319
- let newEnvValues = "";
320
- const isCloudDeployment = needsCloudDeployment(userAnswers);
321
- if (userAnswers.copilotCloudPublicApiKey) {
322
- newEnvValues += `NEXT_PUBLIC_COPILOT_API_KEY=${userAnswers.copilotCloudPublicApiKey}
323
- `;
324
- }
325
- if (userAnswers.langSmithApiKey) {
326
- newEnvValues += `LANGSMITH_API_KEY=${userAnswers.langSmithApiKey}
327
- `;
328
- }
329
- if (userAnswers.llmToken) {
330
- newEnvValues += `OPENAI_API_KEY=${userAnswers.llmToken}
331
- `;
332
- }
333
- if (userAnswers.crewName) {
334
- newEnvValues += `NEXT_PUBLIC_COPILOTKIT_AGENT_NAME=${userAnswers.crewName}
335
- `;
336
- }
337
- if (userAnswers.langGraphAgent) {
338
- newEnvValues += `NEXT_PUBLIC_COPILOTKIT_AGENT_NAME=sample_agent
339
- `;
340
- newEnvValues += `LANGGRAPH_DEPLOYMENT_URL=http://localhost:8123
341
- `;
342
- } else if (userAnswers.langGraphPlatform === "Yes" && !isCloudDeployment) {
343
- newEnvValues += `LANGGRAPH_DEPLOYMENT_URL=${userAnswers.langGraphPlatformUrl}
344
- `;
345
- } else if (userAnswers.langGraphRemoteEndpointURL) {
346
- newEnvValues += `COPILOTKIT_REMOTE_ENDPOINT=${userAnswers.langGraphRemoteEndpointURL}
347
- `;
348
- }
349
- if (flags.runtimeUrl) {
350
- newEnvValues += `NEXT_PUBLIC_COPILOTKIT_RUNTIME_URL=${flags.runtimeUrl}
351
- `;
352
- } else if (!isCloudDeployment && userAnswers.crewType !== "Crews" && userAnswers.crewType !== "Flows") {
353
- newEnvValues += `NEXT_PUBLIC_COPILOTKIT_RUNTIME_URL=/api/copilotkit
354
- `;
355
- }
356
- if (userAnswers.langGraphPlatformUrl && (userAnswers.langSmithApiKey || isLocalhost(userAnswers.langGraphPlatformUrl))) {
357
- const langGraphAgents = await getLangGraphAgents(
358
- userAnswers.langGraphPlatformUrl,
359
- userAnswers.langSmithApiKey || ""
360
- );
361
- let langGraphAgent = "";
362
- if (langGraphAgents.length > 1) {
363
- const { langGraphAgentChoice } = await inquirer.prompt([
364
- {
365
- type: "list",
366
- name: "langGraphAgentChoice",
367
- message: "\u{1F99C}\u{1F517} Which agent from your graph would you like to use?",
368
- choices: langGraphAgents.map((agent) => ({
369
- name: agent.graph_id,
370
- value: agent.graph_id
371
- }))
372
- }
373
- ]);
374
- langGraphAgent = langGraphAgentChoice;
375
- } else if (langGraphAgents.length === 1) {
376
- langGraphAgent = langGraphAgents[0].graph_id;
377
- } else {
378
- throw new Error("No agents found in your LangGraph endpoint");
379
- }
380
- newEnvValues += `NEXT_PUBLIC_COPILOTKIT_AGENT_NAME=${langGraphAgent}
381
- `;
382
- }
383
- if (newEnvValues) {
384
- fs.appendFileSync(envFile, newEnvValues);
385
- }
386
- } catch (error) {
387
- throw error;
388
- }
389
- }
390
-
391
- // src/lib/init/scaffold/github.ts
392
- import { execSync } from "child_process";
393
- import * as fs2 from "fs";
394
- import * as path2 from "path";
395
- import * as os from "os";
396
- import chalk from "chalk";
397
- async function cloneGitHubSubdirectory(githubUrl, destinationPath, spinner) {
398
- try {
399
- const { owner, repo, branch, subdirectoryPath } = parseGitHubUrl(githubUrl);
400
- spinner.text = chalk.cyan(`Cloning from ${owner}/${repo}...`);
401
- return await sparseCheckout(
402
- owner,
403
- repo,
404
- branch,
405
- subdirectoryPath,
406
- destinationPath,
407
- spinner
408
- );
409
- } catch (error) {
410
- spinner.text = chalk.red(`Failed to clone from GitHub: ${error}`);
411
- return false;
412
- }
413
- }
414
- async function sparseCheckout(owner, repo, branch, subdirectoryPath, destinationPath, spinner) {
415
- const tempDir = fs2.mkdtempSync(path2.join(os.tmpdir(), "copilotkit-sparse-"));
416
- try {
417
- spinner.text = chalk.cyan("Creating temporary workspace...");
418
- execSync("git init", { cwd: tempDir, stdio: "pipe" });
419
- spinner.text = chalk.cyan("Connecting to repository...");
420
- execSync(`git remote add origin https://github.com/${owner}/${repo}.git`, {
421
- cwd: tempDir,
422
- stdio: "pipe"
423
- });
424
- execSync("git config core.sparseCheckout true", {
425
- cwd: tempDir,
426
- stdio: "pipe"
427
- });
428
- fs2.writeFileSync(
429
- path2.join(tempDir, ".git/info/sparse-checkout"),
430
- subdirectoryPath
431
- );
432
- spinner.text = chalk.cyan("Downloading agent files...");
433
- execSync(`git pull origin ${branch} --depth=1`, {
434
- cwd: tempDir,
435
- stdio: "pipe"
436
- });
437
- const sourcePath = path2.join(tempDir, subdirectoryPath);
438
- if (!fs2.existsSync(sourcePath)) {
439
- throw new Error(
440
- `Subdirectory '${subdirectoryPath}' not found in the repository.`
441
- );
442
- }
443
- fs2.mkdirSync(destinationPath, { recursive: true });
444
- spinner.text = chalk.cyan("Installing agent files...");
445
- await copyDirectoryAsync(sourcePath, destinationPath);
446
- return true;
447
- } finally {
448
- try {
449
- fs2.rmSync(tempDir, { recursive: true, force: true });
450
- } catch (error) {
451
- console.warn(`Failed to clean up temporary directory: ${error}`);
452
- }
453
- }
454
- }
455
- async function copyDirectoryAsync(source, destination) {
456
- if (!fs2.existsSync(destination)) {
457
- fs2.mkdirSync(destination, { recursive: true });
458
- }
459
- const entries = fs2.readdirSync(source, { withFileTypes: true });
460
- for (const entry of entries) {
461
- const srcPath = path2.join(source, entry.name);
462
- const destPath = path2.join(destination, entry.name);
463
- if (entry.isDirectory()) {
464
- await copyDirectoryAsync(srcPath, destPath);
465
- } else {
466
- fs2.copyFileSync(srcPath, destPath);
467
- }
468
- if (entries.length > 10) {
469
- await new Promise((resolve) => setTimeout(resolve, 1));
470
- }
471
- }
472
- }
473
- function parseGitHubUrl(githubUrl) {
474
- const url = new URL(githubUrl);
475
- if (url.hostname !== "github.com") {
476
- throw new Error("Only GitHub URLs are supported");
477
- }
478
- const pathParts = url.pathname.split("/").filter(Boolean);
479
- if (pathParts.length < 2) {
480
- throw new Error("Invalid GitHub URL format");
481
- }
482
- const owner = pathParts[0];
483
- const repo = pathParts[1];
484
- let branch = "main";
485
- let subdirectoryPath = "";
486
- if (pathParts.length > 3 && (pathParts[2] === "tree" || pathParts[2] === "blob")) {
487
- branch = pathParts[3];
488
- subdirectoryPath = pathParts.slice(4).join("/");
489
- }
490
- return { owner, repo, branch, subdirectoryPath };
491
- }
492
- function isValidGitHubUrl(url) {
493
- try {
494
- const parsedUrl = new URL(url);
495
- return parsedUrl.hostname === "github.com" && parsedUrl.pathname.split("/").filter(Boolean).length >= 2;
496
- } catch {
497
- return false;
498
- }
499
- }
500
-
501
- // src/lib/init/scaffold/packages.ts
502
- import spawn2 from "cross-spawn";
503
- import chalk2 from "chalk";
504
- import fs3 from "fs";
505
- import ora from "ora";
506
- async function scaffoldPackages(userAnswers) {
507
- const spinner = ora({
508
- text: chalk2.cyan("Preparing to install packages..."),
509
- color: "cyan"
510
- }).start();
511
- try {
512
- const packages = [
513
- `@copilotkit/react-ui@${userAnswers.copilotKitVersion}`,
514
- `@copilotkit/react-core@${userAnswers.copilotKitVersion}`,
515
- `@copilotkit/runtime@${userAnswers.copilotKitVersion}`
516
- ];
517
- await new Promise((resolve) => setTimeout(resolve, 50));
518
- const packageManager = detectPackageManager();
519
- const installCommand = detectInstallCommand(packageManager);
520
- spinner.text = chalk2.cyan(`Using ${packageManager} to install packages...`);
521
- spinner.stop();
522
- console.log(chalk2.cyan("\n\u2699\uFE0F Installing packages...\n"));
523
- const result = spawn2.sync(packageManager, [installCommand, ...packages], {
524
- stdio: "inherit"
525
- // This ensures stdin/stdout/stderr are all passed through
526
- });
527
- if (result.status !== 0) {
528
- throw new Error(
529
- `Package installation process exited with code ${result.status}`
530
- );
531
- }
532
- spinner.start();
533
- spinner.succeed(chalk2.green("CopilotKit packages installed successfully"));
534
- } catch (error) {
535
- if (!spinner.isSpinning) {
536
- spinner.start();
537
- }
538
- spinner.fail(chalk2.red("Failed to install CopilotKit packages"));
539
- throw error;
540
- }
541
- }
542
- function detectPackageManager() {
543
- const files = fs3.readdirSync(process.cwd());
544
- if (files.includes("bun.lockb")) return "bun";
545
- if (files.includes("pnpm-lock.yaml")) return "pnpm";
546
- if (files.includes("yarn.lock")) return "yarn";
547
- if (files.includes("package-lock.json")) return "npm";
548
- return "npm";
549
- }
550
- function detectInstallCommand(packageManager) {
551
- switch (packageManager) {
552
- case "yarn":
553
- case "pnpm":
554
- return "add";
555
- default:
556
- return "install";
557
- }
558
- }
559
-
560
- // src/lib/init/scaffold/agent.ts
561
- import ora2 from "ora";
562
- import chalk3 from "chalk";
563
- import path3 from "path";
564
- import fs4 from "fs";
565
- async function scaffoldAgent(userAnswers) {
566
- if (userAnswers.mode === "CrewAI" || userAnswers.mode === "LangGraph" && !userAnswers.langGraphAgent || userAnswers.mode === "Standard" || userAnswers.mode === "MCP") {
567
- return;
568
- }
569
- const spinner = ora2({
570
- text: chalk3.cyan("Setting up AI agent..."),
571
- color: "cyan"
572
- }).start();
573
- let template = "";
574
- switch (userAnswers.mode) {
575
- case "LangGraph":
576
- if (userAnswers.langGraphAgent === "Python Starter") {
577
- template = AgentTemplates.LangGraph.Starter.Python;
578
- } else {
579
- template = AgentTemplates.LangGraph.Starter.TypeScript;
580
- }
581
- break;
582
- }
583
- if (!template) {
584
- spinner.fail(chalk3.red("Failed to determine agent template"));
585
- throw new Error("Failed to determine agent template");
586
- }
587
- const agentDir = path3.join(process.cwd(), "agent");
588
- try {
589
- await cloneGitHubSubdirectory(template, agentDir, spinner);
590
- spinner.text = chalk3.cyan("Creating agent environment variables...");
591
- let envContent = "";
592
- if (userAnswers.llmToken) {
593
- envContent += `OPENAI_API_KEY=${userAnswers.llmToken}
594
- `;
595
- }
596
- if (userAnswers.mode === "LangGraph" && userAnswers.langSmithApiKey) {
597
- envContent += `LANGSMITH_API_KEY=${userAnswers.langSmithApiKey}
598
- `;
599
- }
600
- if (envContent) {
601
- const agentEnvFile = path3.join(agentDir, ".env");
602
- fs4.writeFileSync(agentEnvFile, envContent, "utf8");
603
- spinner.text = chalk3.cyan("Added API keys to agent .env file");
604
- }
605
- } catch (error) {
606
- spinner.fail(chalk3.red("Failed to clone agent template"));
607
- throw error;
608
- }
609
- spinner.succeed(`${userAnswers.mode} agent cloned successfully`);
610
- }
611
- var AgentTemplates = {
612
- LangGraph: {
613
- Starter: {
614
- Python: "https://github.com/CopilotKit/CopilotKit/tree/main/examples/starters/coagents-langgraph/agent-py",
615
- TypeScript: "https://github.com/CopilotKit/CopilotKit/tree/main/examples/starters/coagents-langgraph/agent-js"
616
- }
617
- },
618
- CrewAI: {
619
- Flows: {
620
- Starter: "https://github.com/CopilotKit/CopilotKit/tree/main/examples/starters/coagents-crewai-flows/agent-py"
621
- }
622
- }
623
- };
624
-
625
- // src/lib/init/scaffold/crew-inputs.ts
626
- import * as fs5 from "fs/promises";
627
- import ora3 from "ora";
628
- import * as path4 from "path";
629
- async function addCrewInputs(url, token) {
630
- try {
631
- const spinner = ora3("Analyzing crew inputs...").start();
632
- const inputs = await getCrewInputs(url, token);
633
- spinner.text = "Adding inputs to app/copilotkit/page.tsx...";
634
- let filePath = path4.join(process.cwd(), "app", "copilotkit", "page.tsx");
635
- try {
636
- await fs5.access(filePath);
637
- } catch {
638
- filePath = path4.join(
639
- process.cwd(),
640
- "src",
641
- "app",
642
- "copilotkit",
643
- "page.tsx"
644
- );
645
- }
646
- try {
647
- await fs5.access(filePath);
648
- } catch {
649
- throw new Error(
650
- "app/copilotkit/page.tsx and src/app/copilotkit/page.tsx not found"
651
- );
652
- }
653
- let fileContent = await fs5.readFile(filePath, "utf8");
654
- const inputsString = JSON.stringify(inputs);
655
- fileContent = fileContent.replace(
656
- /\[["']YOUR_INPUTS_HERE["']\]/g,
657
- inputsString
658
- );
659
- await fs5.writeFile(filePath, fileContent, "utf8");
660
- spinner.succeed(
661
- "Successfully added crew inputs to app/copilotkit/page.tsx"
662
- );
663
- } catch (error) {
664
- console.error("Error updating crew inputs:", error);
665
- throw error;
666
- }
667
- }
668
- async function getCrewInputs(url, token) {
669
- const response = await fetch(`${url.trim()}/inputs`, {
670
- headers: {
671
- Authorization: `Bearer ${token}`
672
- }
673
- });
674
- if (!response.ok) {
675
- throw new Error(`Failed to fetch inputs: ${response.statusText}`);
676
- }
677
- const data = await response.json();
678
- return data.inputs;
679
- }
680
- export {
681
- AgentTemplates,
682
- addCrewInputs,
683
- cloneGitHubSubdirectory,
684
- isValidGitHubUrl,
685
- scaffoldAgent,
686
- scaffoldEnv,
687
- scaffoldPackages,
688
- scaffoldShadCN
689
- };
690
- //# sourceMappingURL=index.js.map