copilotkit 0.0.23 → 0.0.24
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/dist/commands/base-command.js +1 -1
- package/dist/commands/base-command.js.map +1 -1
- package/dist/commands/dev.js +4 -3
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/init.js +231 -146
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/login.js +4 -3
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/logout.js +4 -3
- package/dist/commands/logout.js.map +1 -1
- package/dist/lib/init/index.js +138 -112
- package/dist/lib/init/index.js.map +1 -1
- package/dist/lib/init/questions.js +46 -54
- package/dist/lib/init/questions.js.map +1 -1
- package/dist/lib/init/scaffold/agent.js +2 -2
- package/dist/lib/init/scaffold/agent.js.map +1 -1
- package/dist/lib/init/scaffold/env.js +60 -30
- package/dist/lib/init/scaffold/env.js.map +1 -1
- package/dist/lib/init/scaffold/index.js +98 -59
- package/dist/lib/init/scaffold/index.js.map +1 -1
- package/dist/lib/init/scaffold/langgraph-assistants.d.ts +18 -0
- package/dist/lib/init/scaffold/langgraph-assistants.js +27 -0
- package/dist/lib/init/scaffold/langgraph-assistants.js.map +1 -0
- package/dist/lib/init/scaffold/shadcn.js +11 -2
- package/dist/lib/init/scaffold/shadcn.js.map +1 -1
- package/dist/lib/init/types/index.js +6 -1
- package/dist/lib/init/types/index.js.map +1 -1
- package/dist/lib/init/types/templates.d.ts +2 -0
- package/dist/lib/init/types/templates.js +6 -1
- package/dist/lib/init/types/templates.js.map +1 -1
- package/dist/services/auth.service.js +3 -2
- package/dist/services/auth.service.js.map +1 -1
- package/dist/utils/version.d.ts +1 -1
- package/dist/utils/version.js +1 -1
- package/dist/utils/version.js.map +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
package/dist/commands/init.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/commands/init.ts
|
|
2
2
|
import { Flags as Flags2 } from "@oclif/core";
|
|
3
|
-
import
|
|
3
|
+
import inquirer3 from "inquirer";
|
|
4
4
|
import path5 from "path";
|
|
5
5
|
import fs5 from "fs";
|
|
6
6
|
|
|
@@ -137,7 +137,7 @@ var AuthService = class {
|
|
|
137
137
|
{
|
|
138
138
|
name: "shouldLogin",
|
|
139
139
|
type: "confirm",
|
|
140
|
-
message: "You are not yet authenticated. Authenticate with Copilot Cloud? (press Enter to confirm)",
|
|
140
|
+
message: "\u{1FA81} You are not yet authenticated. Authenticate with Copilot Cloud? (press Enter to confirm)",
|
|
141
141
|
default: true
|
|
142
142
|
}
|
|
143
143
|
]);
|
|
@@ -169,6 +169,7 @@ var AuthService = class {
|
|
|
169
169
|
return { cliToken, user: me.user, organization: me.organization };
|
|
170
170
|
}
|
|
171
171
|
async login({ exitAfterLogin } = { exitAfterLogin: true }) {
|
|
172
|
+
const spinner = ora("\u{1FA81} Opening browser for authentication...").start();
|
|
172
173
|
let analytics;
|
|
173
174
|
analytics = new AnalyticsService();
|
|
174
175
|
const app = express();
|
|
@@ -184,7 +185,7 @@ var AuthService = class {
|
|
|
184
185
|
event: "cli.login.initiated",
|
|
185
186
|
properties: {}
|
|
186
187
|
});
|
|
187
|
-
|
|
188
|
+
spinner.text = "\u{1FA81} Waiting for browser authentication to complete...";
|
|
188
189
|
app.post("/callback", async (req, res) => {
|
|
189
190
|
const { cliToken, user, organization } = req.body;
|
|
190
191
|
analytics = new AnalyticsService({ userId: user.id, organizationId: organization.id, email: user.email });
|
|
@@ -221,7 +222,7 @@ import { Command } from "@oclif/core";
|
|
|
221
222
|
import Sentry, { consoleIntegration } from "@sentry/node";
|
|
222
223
|
|
|
223
224
|
// src/utils/version.ts
|
|
224
|
-
var LIB_VERSION = "0.0.
|
|
225
|
+
var LIB_VERSION = "0.0.24";
|
|
225
226
|
|
|
226
227
|
// src/commands/base-command.ts
|
|
227
228
|
import chalk2 from "chalk";
|
|
@@ -295,18 +296,23 @@ var ConfigFlags = {
|
|
|
295
296
|
};
|
|
296
297
|
|
|
297
298
|
// src/lib/init/types/templates.ts
|
|
298
|
-
var BASE_URL = "
|
|
299
|
+
var BASE_URL = "https://registry.copilotkit.ai/r";
|
|
299
300
|
var templateMapping = {
|
|
300
301
|
"LangGraphPlatform": `${BASE_URL}/langgraph-platform-starter.json`,
|
|
301
302
|
"RemoteEndpoint": `${BASE_URL}/remote-endpoint-starter.json`,
|
|
302
303
|
"CrewEnterprise": [
|
|
303
304
|
`${BASE_URL}/coagents-crew-starter.json`
|
|
304
305
|
],
|
|
306
|
+
"LangGraphGeneric": `${BASE_URL}/generic-lg-starter.json`,
|
|
305
307
|
"CrewFlowsStarter": [
|
|
306
308
|
`${BASE_URL}/coagents-starter-ui.json`,
|
|
307
309
|
`${BASE_URL}/agent-layout.json`,
|
|
308
310
|
`${BASE_URL}/remote-endpoint.json`
|
|
309
311
|
],
|
|
312
|
+
"LangGraphStarter": [
|
|
313
|
+
`${BASE_URL}/langgraph-platform-starter.json`,
|
|
314
|
+
`${BASE_URL}/coagents-starter-ui.json`
|
|
315
|
+
],
|
|
310
316
|
"Standard": `${BASE_URL}/standard-starter.json`,
|
|
311
317
|
"CopilotChat": `${BASE_URL}/chat.json`,
|
|
312
318
|
"CopilotPopup": `${BASE_URL}/popup.json`,
|
|
@@ -360,62 +366,50 @@ var questions = [
|
|
|
360
366
|
when: (answers) => answers.agentFramework === "CrewAI" && answers.crewType === "Flows"
|
|
361
367
|
},
|
|
362
368
|
// LangGraph specific questions - shown when LangGraph selected
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
// answers.agentFramework === 'LangGraph' &&
|
|
402
|
-
// answers.alreadyDeployed === 'No',
|
|
403
|
-
// },
|
|
404
|
-
// {
|
|
405
|
-
// type: 'input',
|
|
406
|
-
// name: 'langSmithApiKey',
|
|
407
|
-
// message: '🦜🔗 Enter your LangSmith API key (required by LangGraph Platform) :',
|
|
408
|
-
// when: (answers) =>
|
|
409
|
-
// answers.agentFramework === 'LangGraph' &&
|
|
410
|
-
// answers.alreadyDeployed === 'No',
|
|
411
|
-
// sensitive: true,
|
|
412
|
-
// },
|
|
369
|
+
{
|
|
370
|
+
type: "yes/no",
|
|
371
|
+
name: "alreadyDeployed",
|
|
372
|
+
message: "\u{1F680} Is your LangGraph agent already deployed?",
|
|
373
|
+
when: (answers) => answers.agentFramework === "LangGraph"
|
|
374
|
+
},
|
|
375
|
+
{
|
|
376
|
+
type: "yes/no",
|
|
377
|
+
name: "langGraphPlatform",
|
|
378
|
+
message: "\u{1F99C}\u{1F517} Is it hosted with LangGraph Platform (local or cloud)?",
|
|
379
|
+
when: (answers) => answers.agentFramework === "LangGraph" && answers.alreadyDeployed === "Yes"
|
|
380
|
+
},
|
|
381
|
+
{
|
|
382
|
+
type: "input",
|
|
383
|
+
name: "langGraphPlatformUrl",
|
|
384
|
+
message: "\u{1F99C}\u{1F517} Enter your LangGraph platform URL:",
|
|
385
|
+
when: (answers) => answers.agentFramework === "LangGraph" && answers.alreadyDeployed === "Yes" && answers.langGraphPlatform === "Yes"
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
type: "input",
|
|
389
|
+
name: "langGraphRemoteEndpointURL",
|
|
390
|
+
message: "\u{1F50C} Enter your LangGraph endpoint URL:",
|
|
391
|
+
when: (answers) => answers.agentFramework === "LangGraph" && answers.alreadyDeployed === "Yes" && answers.langGraphPlatform === "No"
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
type: "select",
|
|
395
|
+
name: "langGraphAgent",
|
|
396
|
+
message: "\u{1F4E6} Choose a LangGraph starter template:",
|
|
397
|
+
choices: Array.from(LANGGRAPH_AGENTS),
|
|
398
|
+
when: (answers) => answers.agentFramework === "LangGraph" && answers.alreadyDeployed === "No"
|
|
399
|
+
},
|
|
400
|
+
{
|
|
401
|
+
type: "input",
|
|
402
|
+
name: "langSmithApiKey",
|
|
403
|
+
message: "\u{1F99C}\u{1F517} Enter your LangSmith API key (required by LangGraph Platform) :",
|
|
404
|
+
when: (answers) => answers.agentFramework === "LangGraph" && answers.langGraphPlatform === "Yes",
|
|
405
|
+
sensitive: true
|
|
406
|
+
},
|
|
413
407
|
// Deployment options
|
|
414
408
|
{
|
|
415
409
|
type: "yes/no",
|
|
416
410
|
name: "useCopilotCloud",
|
|
417
411
|
message: "\u{1FA81} Deploy with Copilot Cloud? (recommended for production)",
|
|
418
|
-
when: (answers) => !(answers.agentFramework === "CrewAI" && answers.crewType === "Crews") && answers.
|
|
412
|
+
when: (answers) => !(answers.agentFramework === "CrewAI" && answers.crewType === "Crews") && answers.crewType !== "Flows" && answers.alreadyDeployed === "Yes"
|
|
419
413
|
},
|
|
420
414
|
// {
|
|
421
415
|
// type: 'yes/no',
|
|
@@ -440,8 +434,7 @@ var questions = [
|
|
|
440
434
|
type: "input",
|
|
441
435
|
name: "llmToken",
|
|
442
436
|
message: "\u{1F511} Enter your OpenAI API key (required for agent functionality):",
|
|
443
|
-
when: (answers) => answers.agentFramework
|
|
444
|
-
(answers.agentFramework === "CrewAI" && answers.crewType === "Flows"),
|
|
437
|
+
when: (answers) => answers.agentFramework === "LangGraph" && answers.alreadyDeployed === "No" || answers.agentFramework === "CrewAI" && answers.crewType === "Flows",
|
|
445
438
|
sensitive: true
|
|
446
439
|
}
|
|
447
440
|
];
|
|
@@ -454,7 +447,11 @@ async function scaffoldShadCN(userAnswers) {
|
|
|
454
447
|
if (userAnswers.agentFramework !== "None") {
|
|
455
448
|
switch (userAnswers.agentFramework) {
|
|
456
449
|
case "LangGraph":
|
|
457
|
-
|
|
450
|
+
if (userAnswers.langGraphAgent && userAnswers.langGraphAgent !== "None") {
|
|
451
|
+
components.push(...templateMapping.LangGraphStarter);
|
|
452
|
+
} else {
|
|
453
|
+
components.push(templateMapping.LangGraphGeneric);
|
|
454
|
+
}
|
|
458
455
|
break;
|
|
459
456
|
case "CrewAI":
|
|
460
457
|
if (userAnswers.crewType === "Crews") {
|
|
@@ -490,75 +487,105 @@ async function scaffoldShadCN(userAnswers) {
|
|
|
490
487
|
// src/lib/init/scaffold/env.ts
|
|
491
488
|
import path from "path";
|
|
492
489
|
import fs from "fs";
|
|
493
|
-
|
|
494
|
-
|
|
490
|
+
|
|
491
|
+
// src/lib/init/scaffold/langgraph-assistants.ts
|
|
492
|
+
async function getLangGraphAgents(url, langSmithApiKey) {
|
|
493
|
+
try {
|
|
494
|
+
const response = await fetch(
|
|
495
|
+
`${url}/assistants/search`,
|
|
496
|
+
{
|
|
497
|
+
method: "POST",
|
|
498
|
+
headers: {
|
|
499
|
+
"Content-Type": "application/json",
|
|
500
|
+
"X-Api-Key": langSmithApiKey
|
|
501
|
+
},
|
|
502
|
+
body: JSON.stringify({
|
|
503
|
+
limit: 10,
|
|
504
|
+
offset: 0
|
|
505
|
+
})
|
|
506
|
+
}
|
|
507
|
+
);
|
|
508
|
+
const result = await response.json();
|
|
509
|
+
return result;
|
|
510
|
+
} catch (error) {
|
|
511
|
+
throw new Error("Failed to get LangGraph agents");
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
// src/lib/init/scaffold/env.ts
|
|
516
|
+
import inquirer2 from "inquirer";
|
|
495
517
|
async function scaffoldEnv(flags, userAnswers) {
|
|
496
|
-
const spinner = ora2({
|
|
497
|
-
text: chalk3.cyan("Configuring environment variables..."),
|
|
498
|
-
color: "cyan"
|
|
499
|
-
}).start();
|
|
500
518
|
try {
|
|
501
519
|
const envFile = path.join(process.cwd(), ".env");
|
|
502
520
|
if (!fs.existsSync(envFile)) {
|
|
503
521
|
fs.writeFileSync(envFile, "", "utf8");
|
|
504
|
-
spinner.text = chalk3.cyan("Created .env file...");
|
|
505
522
|
} else {
|
|
506
|
-
spinner.text = chalk3.cyan("Updating existing .env file...");
|
|
507
523
|
}
|
|
508
524
|
let newEnvValues = "";
|
|
509
|
-
let varsAdded = false;
|
|
510
525
|
if (userAnswers.copilotCloudPublicApiKey) {
|
|
511
526
|
newEnvValues += `NEXT_PUBLIC_COPILOT_API_KEY=${userAnswers.copilotCloudPublicApiKey}
|
|
512
527
|
`;
|
|
513
|
-
spinner.text = chalk3.cyan("Adding Copilot Cloud API key...");
|
|
514
|
-
varsAdded = true;
|
|
515
528
|
}
|
|
516
529
|
if (userAnswers.langSmithApiKey) {
|
|
517
530
|
newEnvValues += `LANGSMITH_API_KEY=${userAnswers.langSmithApiKey}
|
|
518
531
|
`;
|
|
519
|
-
spinner.text = chalk3.cyan("Adding LangSmith API key...");
|
|
520
|
-
varsAdded = true;
|
|
521
532
|
}
|
|
522
533
|
if (userAnswers.llmToken) {
|
|
523
534
|
newEnvValues += `OPENAI_API_KEY=${userAnswers.llmToken}
|
|
524
535
|
`;
|
|
525
|
-
spinner.text = chalk3.cyan("Adding OpenAI API key...");
|
|
526
|
-
varsAdded = true;
|
|
527
536
|
}
|
|
528
537
|
if (userAnswers.crewName) {
|
|
529
538
|
newEnvValues += `NEXT_PUBLIC_COPILOTKIT_AGENT_NAME=${userAnswers.crewName}
|
|
530
539
|
`;
|
|
531
|
-
|
|
532
|
-
|
|
540
|
+
}
|
|
541
|
+
if (userAnswers.langGraphAgent !== "None" && userAnswers.langGraphPlatform !== "Yes") {
|
|
542
|
+
newEnvValues += `NEXT_PUBLIC_COPILOTKIT_AGENT_NAME=sample_agent
|
|
543
|
+
`;
|
|
544
|
+
newEnvValues += `LANGGRAPH_DEPLOYMENT_URL=http://localhost:8123
|
|
545
|
+
`;
|
|
546
|
+
} else if (userAnswers.langGraphPlatform === "Yes" && userAnswers.useCopilotCloud === "No") {
|
|
547
|
+
newEnvValues += `LANGGRAPH_DEPLOYMENT_URL=${userAnswers.langGraphPlatformUrl}
|
|
548
|
+
`;
|
|
533
549
|
}
|
|
534
550
|
if (flags.runtimeUrl) {
|
|
535
551
|
newEnvValues += `NEXT_PUBLIC_COPILOTKIT_RUNTIME_URL=${flags.runtimeUrl}
|
|
536
552
|
`;
|
|
537
|
-
|
|
538
|
-
varsAdded = true;
|
|
539
|
-
} else if (!userAnswers.useCopilotCloud && userAnswers.crewType !== "Crews") {
|
|
553
|
+
} else if (userAnswers.useCopilotCloud !== "Yes" && userAnswers.crewType !== "Crews") {
|
|
540
554
|
newEnvValues += `NEXT_PUBLIC_COPILOTKIT_RUNTIME_URL=/api/copilotkit
|
|
541
555
|
`;
|
|
542
|
-
spinner.text = chalk3.cyan("Adding CopilotKit runtime URL...");
|
|
543
|
-
varsAdded = true;
|
|
544
556
|
}
|
|
545
557
|
if (userAnswers.crewFlowAgent === "Starter") {
|
|
546
558
|
newEnvValues += `NEXT_PUBLIC_COPILOTKIT_AGENT_NAME=sample_agent
|
|
547
559
|
`;
|
|
548
|
-
spinner.text = chalk3.cyan("Adding Flow agent name...");
|
|
549
|
-
varsAdded = true;
|
|
550
560
|
}
|
|
551
|
-
if (
|
|
552
|
-
|
|
561
|
+
if (userAnswers.langGraphPlatformUrl && userAnswers.langSmithApiKey) {
|
|
562
|
+
const langGraphAgents = await getLangGraphAgents(userAnswers.langGraphPlatformUrl, userAnswers.langSmithApiKey);
|
|
563
|
+
let langGraphAgent = "";
|
|
564
|
+
if (langGraphAgents.length > 1) {
|
|
565
|
+
const { langGraphAgentChoice } = await inquirer2.prompt([
|
|
566
|
+
{
|
|
567
|
+
type: "list",
|
|
568
|
+
name: "langGraphAgentChoice",
|
|
569
|
+
message: "\u{1F99C}\u{1F517} Which agent from your graph would you like to use?",
|
|
570
|
+
choices: langGraphAgents.map((agent) => ({
|
|
571
|
+
name: agent.graph_id,
|
|
572
|
+
value: agent.graph_id
|
|
573
|
+
}))
|
|
574
|
+
}
|
|
575
|
+
]);
|
|
576
|
+
langGraphAgent = langGraphAgentChoice;
|
|
577
|
+
} else if (langGraphAgents.length === 1) {
|
|
578
|
+
langGraphAgent = langGraphAgents[0].graph_id;
|
|
579
|
+
} else {
|
|
580
|
+
throw new Error("No agents found in your LangGraph endpoint");
|
|
581
|
+
}
|
|
582
|
+
newEnvValues += `NEXT_PUBLIC_COPILOTKIT_AGENT_NAME=${langGraphAgent}
|
|
583
|
+
`;
|
|
553
584
|
}
|
|
554
585
|
if (newEnvValues) {
|
|
555
586
|
fs.appendFileSync(envFile, newEnvValues);
|
|
556
|
-
spinner.succeed(chalk3("Environment variables configured successfully"));
|
|
557
|
-
} else {
|
|
558
|
-
spinner.info(chalk3.yellow("No environment variables were added"));
|
|
559
587
|
}
|
|
560
588
|
} catch (error) {
|
|
561
|
-
spinner.fail(chalk3.red("Failed to update environment variables"));
|
|
562
589
|
throw error;
|
|
563
590
|
}
|
|
564
591
|
}
|
|
@@ -568,34 +595,34 @@ import { execSync } from "child_process";
|
|
|
568
595
|
import * as fs2 from "fs";
|
|
569
596
|
import * as path2 from "path";
|
|
570
597
|
import * as os from "os";
|
|
571
|
-
import
|
|
598
|
+
import chalk3 from "chalk";
|
|
572
599
|
async function cloneGitHubSubdirectory(githubUrl, destinationPath, spinner) {
|
|
573
600
|
try {
|
|
574
601
|
const { owner, repo, branch, subdirectoryPath } = parseGitHubUrl(githubUrl);
|
|
575
|
-
spinner.text =
|
|
602
|
+
spinner.text = chalk3.cyan(`Cloning from ${owner}/${repo}...`);
|
|
576
603
|
return await sparseCheckout(owner, repo, branch, subdirectoryPath, destinationPath, spinner);
|
|
577
604
|
} catch (error) {
|
|
578
|
-
spinner.text =
|
|
605
|
+
spinner.text = chalk3.red(`Failed to clone from GitHub: ${error}`);
|
|
579
606
|
return false;
|
|
580
607
|
}
|
|
581
608
|
}
|
|
582
609
|
async function sparseCheckout(owner, repo, branch, subdirectoryPath, destinationPath, spinner) {
|
|
583
610
|
const tempDir = fs2.mkdtempSync(path2.join(os.tmpdir(), "copilotkit-sparse-"));
|
|
584
611
|
try {
|
|
585
|
-
spinner.text =
|
|
612
|
+
spinner.text = chalk3.cyan("Creating temporary workspace...");
|
|
586
613
|
execSync("git init", { cwd: tempDir, stdio: "pipe" });
|
|
587
|
-
spinner.text =
|
|
614
|
+
spinner.text = chalk3.cyan("Connecting to repository...");
|
|
588
615
|
execSync(`git remote add origin https://github.com/${owner}/${repo}.git`, { cwd: tempDir, stdio: "pipe" });
|
|
589
616
|
execSync("git config core.sparseCheckout true", { cwd: tempDir, stdio: "pipe" });
|
|
590
617
|
fs2.writeFileSync(path2.join(tempDir, ".git/info/sparse-checkout"), subdirectoryPath);
|
|
591
|
-
spinner.text =
|
|
618
|
+
spinner.text = chalk3.cyan("Downloading agent files...");
|
|
592
619
|
execSync(`git pull origin ${branch} --depth=1`, { cwd: tempDir, stdio: "pipe" });
|
|
593
620
|
const sourcePath = path2.join(tempDir, subdirectoryPath);
|
|
594
621
|
if (!fs2.existsSync(sourcePath)) {
|
|
595
622
|
throw new Error(`Subdirectory '${subdirectoryPath}' not found in the repository.`);
|
|
596
623
|
}
|
|
597
624
|
fs2.mkdirSync(destinationPath, { recursive: true });
|
|
598
|
-
spinner.text =
|
|
625
|
+
spinner.text = chalk3.cyan("Installing agent files...");
|
|
599
626
|
await copyDirectoryAsync(sourcePath, destinationPath);
|
|
600
627
|
return true;
|
|
601
628
|
} finally {
|
|
@@ -646,20 +673,20 @@ function parseGitHubUrl(githubUrl) {
|
|
|
646
673
|
|
|
647
674
|
// src/lib/init/scaffold/packages.ts
|
|
648
675
|
import spawn2 from "cross-spawn";
|
|
649
|
-
import
|
|
650
|
-
import
|
|
676
|
+
import chalk4 from "chalk";
|
|
677
|
+
import ora2 from "ora";
|
|
651
678
|
|
|
652
679
|
// src/lib/init/scaffold/agent.ts
|
|
653
|
-
import
|
|
654
|
-
import
|
|
680
|
+
import ora3 from "ora";
|
|
681
|
+
import chalk5 from "chalk";
|
|
655
682
|
import path3 from "path";
|
|
656
683
|
import fs3 from "fs";
|
|
657
684
|
async function scaffoldAgent(userAnswers) {
|
|
658
685
|
if (userAnswers.agentFramework === "None" || userAnswers.agentFramework === "CrewAI" && userAnswers.crewType === "Crews" || userAnswers.agentFramework === "LangGraph" && (!userAnswers.langGraphAgent || userAnswers.langGraphAgent === "None")) {
|
|
659
686
|
return;
|
|
660
687
|
}
|
|
661
|
-
const spinner =
|
|
662
|
-
text:
|
|
688
|
+
const spinner = ora3({
|
|
689
|
+
text: chalk5.cyan("Setting up AI agent..."),
|
|
663
690
|
color: "cyan"
|
|
664
691
|
}).start();
|
|
665
692
|
let template = "";
|
|
@@ -678,7 +705,7 @@ async function scaffoldAgent(userAnswers) {
|
|
|
678
705
|
break;
|
|
679
706
|
}
|
|
680
707
|
if (!template) {
|
|
681
|
-
spinner.fail(
|
|
708
|
+
spinner.fail(chalk5.red("Failed to determine agent template"));
|
|
682
709
|
throw new Error("Failed to determine agent template");
|
|
683
710
|
}
|
|
684
711
|
const agentDir = path3.join(process.cwd(), "agent");
|
|
@@ -688,7 +715,7 @@ async function scaffoldAgent(userAnswers) {
|
|
|
688
715
|
agentDir,
|
|
689
716
|
spinner
|
|
690
717
|
);
|
|
691
|
-
spinner.text =
|
|
718
|
+
spinner.text = chalk5.cyan("Creating agent environment variables...");
|
|
692
719
|
let envContent = "";
|
|
693
720
|
if (userAnswers.llmToken) {
|
|
694
721
|
envContent += `OPENAI_API_KEY=${userAnswers.llmToken}
|
|
@@ -701,10 +728,10 @@ async function scaffoldAgent(userAnswers) {
|
|
|
701
728
|
if (envContent) {
|
|
702
729
|
const agentEnvFile = path3.join(agentDir, ".env");
|
|
703
730
|
fs3.writeFileSync(agentEnvFile, envContent, "utf8");
|
|
704
|
-
spinner.text =
|
|
731
|
+
spinner.text = chalk5.cyan("Added API keys to agent .env file");
|
|
705
732
|
}
|
|
706
733
|
} catch (error) {
|
|
707
|
-
spinner.fail(
|
|
734
|
+
spinner.fail(chalk5.red("Failed to clone agent template"));
|
|
708
735
|
throw error;
|
|
709
736
|
}
|
|
710
737
|
spinner.succeed(`${userAnswers.agentFramework} agent cloned successfully`);
|
|
@@ -712,8 +739,8 @@ async function scaffoldAgent(userAnswers) {
|
|
|
712
739
|
var AgentTemplates = {
|
|
713
740
|
LangGraph: {
|
|
714
741
|
Starter: {
|
|
715
|
-
Python: "https://github.com/CopilotKit/
|
|
716
|
-
TypeScript: "https://github.com/CopilotKit/
|
|
742
|
+
Python: "https://github.com/CopilotKit/coagents-starter-langgraph/tree/main/agent-py",
|
|
743
|
+
TypeScript: "https://github.com/CopilotKit/coagents-starter-langgraph/tree/main/agent-js"
|
|
717
744
|
}
|
|
718
745
|
},
|
|
719
746
|
CrewAI: {
|
|
@@ -725,11 +752,11 @@ var AgentTemplates = {
|
|
|
725
752
|
|
|
726
753
|
// src/lib/init/scaffold/crew-inputs.ts
|
|
727
754
|
import * as fs4 from "fs/promises";
|
|
728
|
-
import
|
|
755
|
+
import ora4 from "ora";
|
|
729
756
|
import * as path4 from "path";
|
|
730
757
|
async function addCrewInputs(url, token) {
|
|
731
758
|
try {
|
|
732
|
-
const spinner =
|
|
759
|
+
const spinner = ora4("Analyzing crew inputs...").start();
|
|
733
760
|
const inputs = await getCrewInputs(url, token);
|
|
734
761
|
spinner.text = "Adding inputs to app/copilotkit/page.tsx...";
|
|
735
762
|
let filePath = path4.join(process.cwd(), "app", "copilotkit", "page.tsx");
|
|
@@ -767,8 +794,8 @@ async function getCrewInputs(url, token) {
|
|
|
767
794
|
}
|
|
768
795
|
|
|
769
796
|
// src/commands/init.ts
|
|
770
|
-
import
|
|
771
|
-
import
|
|
797
|
+
import chalk6 from "chalk";
|
|
798
|
+
import ora5 from "ora";
|
|
772
799
|
var CloudInit = class _CloudInit extends BaseCommand {
|
|
773
800
|
constructor(argv, config, authService = new AuthService()) {
|
|
774
801
|
super(argv, config);
|
|
@@ -789,21 +816,15 @@ var CloudInit = class _CloudInit extends BaseCommand {
|
|
|
789
816
|
async run() {
|
|
790
817
|
const { flags } = await this.parse(_CloudInit);
|
|
791
818
|
try {
|
|
792
|
-
this.log(
|
|
793
|
-
this.log(
|
|
819
|
+
this.log(chalk6.magenta("\n\u{1FA81} Welcome to CopilotKit"));
|
|
820
|
+
this.log(chalk6.gray("Let's power up your Next.js project with AI capabilities\n"));
|
|
794
821
|
this.validateProjectCompatibility(flags);
|
|
795
822
|
const userAnswers = await this.getUserAnswers();
|
|
796
|
-
if (userAnswers.agentFramework === "LangGraph") {
|
|
797
|
-
this.log(chalk7.cyan("\n\u{1F99C}\u{1F517} LangGraph Integration"));
|
|
798
|
-
this.log(chalk7.gray("For detailed LangGraph setup instructions, please refer to:"));
|
|
799
|
-
this.log(chalk7.blue("https://docs.copilotkit.ai/coagents\n"));
|
|
800
|
-
process.exit(0);
|
|
801
|
-
}
|
|
802
823
|
const needsCloudSetup = userAnswers.useCopilotCloud === "Yes" || userAnswers.agentFramework === "CrewAI" && userAnswers.crewType === "Crews";
|
|
803
824
|
if (needsCloudSetup) await this.setupCloud(flags, userAnswers);
|
|
825
|
+
await scaffoldEnv(flags, userAnswers);
|
|
804
826
|
await scaffoldShadCN(userAnswers);
|
|
805
827
|
await scaffoldAgent(userAnswers);
|
|
806
|
-
await scaffoldEnv(flags, userAnswers);
|
|
807
828
|
if (userAnswers.crewType === "Crews" && userAnswers.crewUrl && userAnswers.crewBearerToken)
|
|
808
829
|
await addCrewInputs(userAnswers.crewUrl, userAnswers.crewBearerToken);
|
|
809
830
|
this.finalSummary(userAnswers);
|
|
@@ -841,32 +862,27 @@ var CloudInit = class _CloudInit extends BaseCommand {
|
|
|
841
862
|
};
|
|
842
863
|
}
|
|
843
864
|
});
|
|
844
|
-
const answers = await
|
|
865
|
+
const answers = await inquirer3.prompt(inquirerQuestions);
|
|
845
866
|
return { ...answers };
|
|
846
867
|
}
|
|
847
868
|
async setupCloud(flags, userAnswers) {
|
|
848
|
-
const { cliToken, organization
|
|
849
|
-
const analytics = new AnalyticsService({ userId: user.id, organizationId: organization.id, email: user.email });
|
|
850
|
-
await analytics.track({
|
|
851
|
-
event: "cli.init.cloud_used",
|
|
852
|
-
properties: { userId: user.id }
|
|
853
|
-
});
|
|
869
|
+
const { cliToken, organization } = await this.authService.requireLogin(this);
|
|
854
870
|
this.trpcClient = createTRPCClient(cliToken);
|
|
855
871
|
const availableProjects = await this.trpcClient.listOrgProjects.query({ orgId: organization.id });
|
|
856
872
|
let selectedProjectId;
|
|
857
873
|
if (flags.project) {
|
|
858
874
|
if (!availableProjects.some((project) => project.id === flags.project)) {
|
|
859
|
-
this.log(
|
|
875
|
+
this.log(chalk6.red(`\u{1F4C1} Project with ID ${flags.project} not found`));
|
|
860
876
|
process.exit(1);
|
|
861
877
|
}
|
|
862
878
|
selectedProjectId = flags.project;
|
|
863
|
-
this.log(
|
|
879
|
+
this.log(chalk6.green(`\u{1F4C1} Selected project ${selectedProjectId}`));
|
|
864
880
|
} else {
|
|
865
|
-
const { projectId } = await
|
|
881
|
+
const { projectId } = await inquirer3.prompt([
|
|
866
882
|
{
|
|
867
883
|
name: "projectId",
|
|
868
884
|
type: "list",
|
|
869
|
-
message: "Choose a project:",
|
|
885
|
+
message: "\u{1F4C1} Choose a project:",
|
|
870
886
|
choices: availableProjects.map((project) => ({
|
|
871
887
|
value: project.id,
|
|
872
888
|
name: `${project.name} (ID: ${project.id})${availableProjects.length === 1 ? " (press Enter to confirm)" : ""}`
|
|
@@ -878,8 +894,8 @@ var CloudInit = class _CloudInit extends BaseCommand {
|
|
|
878
894
|
const copilotCloudPublicApiKey = await this.trpcClient.getCopilotCloudPublicApiKey.query({ projectId: selectedProjectId });
|
|
879
895
|
userAnswers.copilotCloudPublicApiKey = copilotCloudPublicApiKey?.key;
|
|
880
896
|
if (userAnswers.crewUrl && userAnswers.crewName && userAnswers.crewBearerToken) {
|
|
881
|
-
const crewSpinner =
|
|
882
|
-
text:
|
|
897
|
+
const crewSpinner = ora5({
|
|
898
|
+
text: chalk6("\u{1F465} Adding Crew to Copilot Cloud..."),
|
|
883
899
|
color: "cyan"
|
|
884
900
|
}).start();
|
|
885
901
|
await this.trpcClient.createRemoteEndpoint.mutate({
|
|
@@ -893,7 +909,49 @@ var CloudInit = class _CloudInit extends BaseCommand {
|
|
|
893
909
|
crewApiBearerToken: userAnswers.crewBearerToken
|
|
894
910
|
}
|
|
895
911
|
});
|
|
896
|
-
crewSpinner.succeed(
|
|
912
|
+
crewSpinner.succeed(chalk6("\u{1F465} Crew added to Copilot Cloud"));
|
|
913
|
+
}
|
|
914
|
+
if (userAnswers.agentFramework === "LangGraph" && userAnswers.useCopilotCloud === "Yes" && userAnswers.alreadyDeployed === "Yes") {
|
|
915
|
+
const langGraphSpinner = ora5({
|
|
916
|
+
text: chalk6("\u{1F99C}\u{1F517} Adding LangGraph to Copilot Cloud..."),
|
|
917
|
+
color: "cyan"
|
|
918
|
+
}).start();
|
|
919
|
+
if (userAnswers.langGraphPlatform === "Yes" && userAnswers.langGraphPlatformUrl) {
|
|
920
|
+
try {
|
|
921
|
+
if (!userAnswers.langSmithApiKey) {
|
|
922
|
+
langGraphSpinner.fail(chalk6("\u{1F99C}\u{1F517} LangSmith API key not found. Please provide a valid LangSmith API key."));
|
|
923
|
+
process.exit(1);
|
|
924
|
+
}
|
|
925
|
+
await this.trpcClient.createLGCRemoteEndpoint.mutate({
|
|
926
|
+
type: "LangGraphCloud",
|
|
927
|
+
projectId: selectedProjectId,
|
|
928
|
+
config: {
|
|
929
|
+
deploymentUrl: userAnswers.langGraphPlatformUrl,
|
|
930
|
+
langsmithApiKey: userAnswers.langSmithApiKey,
|
|
931
|
+
agents: []
|
|
932
|
+
}
|
|
933
|
+
});
|
|
934
|
+
langGraphSpinner.succeed(chalk6("\u{1F99C}\u{1F517} LangGraph Cloud remote endpoint created"));
|
|
935
|
+
} catch (error) {
|
|
936
|
+
langGraphSpinner.fail(chalk6("\u{1F99C}\u{1F517} Failed to create LangGraph Cloud remote endpoint. Please try again."));
|
|
937
|
+
process.exit(1);
|
|
938
|
+
}
|
|
939
|
+
} else if (userAnswers.langGraphRemoteEndpointURL) {
|
|
940
|
+
try {
|
|
941
|
+
await this.trpcClient.createRemoteEndpoint.mutate({
|
|
942
|
+
type: "CopilotKit",
|
|
943
|
+
projectId: selectedProjectId,
|
|
944
|
+
config: {
|
|
945
|
+
type: "CopilotKit",
|
|
946
|
+
url: userAnswers.langGraphRemoteEndpointURL
|
|
947
|
+
}
|
|
948
|
+
});
|
|
949
|
+
langGraphSpinner.succeed(chalk6("\u{1F99C}\u{1F517} LangGraph remote endpoint created"));
|
|
950
|
+
} catch (error) {
|
|
951
|
+
langGraphSpinner.fail(chalk6("\u{1F99C}\u{1F517} Failed to create LangGraph remote endpoint. Please try again."));
|
|
952
|
+
process.exit(1);
|
|
953
|
+
}
|
|
954
|
+
}
|
|
897
955
|
}
|
|
898
956
|
}
|
|
899
957
|
validateProjectCompatibility(flags) {
|
|
@@ -912,7 +970,7 @@ var CloudInit = class _CloudInit extends BaseCommand {
|
|
|
912
970
|
this.gracefulError(`Directory ${projectPath} does not appear to be a Next.js project. Make sure it has next in dependencies.`);
|
|
913
971
|
process.exit(1);
|
|
914
972
|
}
|
|
915
|
-
this.log(
|
|
973
|
+
this.log(chalk6.green(`Valid Next.js project detected
|
|
916
974
|
`));
|
|
917
975
|
return true;
|
|
918
976
|
}
|
|
@@ -924,26 +982,53 @@ var CloudInit = class _CloudInit extends BaseCommand {
|
|
|
924
982
|
if (userAnswers.agentFramework === "CrewAI") {
|
|
925
983
|
agentType = "CrewAI";
|
|
926
984
|
if (userAnswers.crewType === "Crews") {
|
|
927
|
-
agentSetupMessage = `Using your Crew from ${
|
|
985
|
+
agentSetupMessage = `Using your Crew from ${chalk6.cyan(userAnswers.crewUrl || "the provided URL")}.`;
|
|
928
986
|
} else if (userAnswers.crewType === "Flows") {
|
|
929
|
-
agentSetupMessage = `We've scaffolded a ${
|
|
987
|
+
agentSetupMessage = `We've scaffolded a ${chalk6.cyan(userAnswers.crewFlowAgent || "CrewAI")} agent in the ${chalk6.cyan("./agent")} directory.`;
|
|
930
988
|
agentDevInstructions = "poetry install && poetry run demo";
|
|
931
989
|
}
|
|
932
990
|
}
|
|
933
991
|
}
|
|
992
|
+
switch (userAnswers.agentFramework) {
|
|
993
|
+
case "LangGraph":
|
|
994
|
+
switch (userAnswers.langGraphAgent) {
|
|
995
|
+
case "Python Starter":
|
|
996
|
+
agentSetupMessage = `We've scaffolded a ${chalk6.cyan(userAnswers.langGraphAgent || "LangGraph")} agent in the ${chalk6.cyan("./agent")} directory.`;
|
|
997
|
+
agentDevInstructions = "poetry install && npx @langchain/langgraph-cli dev --port 8123";
|
|
998
|
+
break;
|
|
999
|
+
case "TypeScript Starter":
|
|
1000
|
+
agentSetupMessage = `We've scaffolded a ${chalk6.cyan(userAnswers.langGraphAgent || "LangGraph")} agent in the ${chalk6.cyan("./agent")} directory.`;
|
|
1001
|
+
agentDevInstructions = "npm install && npm run dev";
|
|
1002
|
+
break;
|
|
1003
|
+
default:
|
|
1004
|
+
break;
|
|
1005
|
+
}
|
|
1006
|
+
break;
|
|
1007
|
+
case "CrewAI":
|
|
1008
|
+
switch (userAnswers.crewType) {
|
|
1009
|
+
case "Crews":
|
|
1010
|
+
agentSetupMessage = `Using your Crew from ${chalk6.cyan(userAnswers.crewUrl || "the provided URL")}.`;
|
|
1011
|
+
break;
|
|
1012
|
+
case "Flows":
|
|
1013
|
+
agentSetupMessage = `We've scaffolded a ${chalk6.cyan(userAnswers.crewFlowAgent || "CrewAI")} agent in the ${chalk6.cyan("./agent")} directory.`;
|
|
1014
|
+
break;
|
|
1015
|
+
}
|
|
1016
|
+
break;
|
|
1017
|
+
default:
|
|
1018
|
+
}
|
|
934
1019
|
this.log("\n-----\n");
|
|
935
|
-
this.log(
|
|
936
|
-
this.log(
|
|
1020
|
+
this.log(chalk6.magenta("\u{1F389} Your CopilotKit setup is complete! \u{1F389}\n"));
|
|
1021
|
+
this.log(chalk6.bold(`\u{1F4CB} Recap`));
|
|
937
1022
|
this.log(` - CopilotKit has been added to your Next.js app.`);
|
|
938
1023
|
if (agentSetupMessage) this.log(` - ${agentSetupMessage}`);
|
|
939
1024
|
if (userAnswers.useCopilotCloud || userAnswers.crewType === "Crews") this.log(` - With Copilot Cloud.`);
|
|
940
|
-
this.log(
|
|
941
|
-
this.log(` - Start your Next.js app: ${
|
|
942
|
-
if (agentDevInstructions) this.log(` - Start your agent: ${
|
|
943
|
-
this.log(` - Navigate to ${
|
|
1025
|
+
this.log(chalk6.bold("\n\u{1F680} Next steps:"));
|
|
1026
|
+
this.log(` - Start your Next.js app: ${chalk6.gray("$")} ${chalk6.cyan("npm run dev")}`);
|
|
1027
|
+
if (agentDevInstructions) this.log(` - Start your agent: ${chalk6.gray("$")} ${chalk6.cyan(`cd agent && ${agentDevInstructions}`)}`);
|
|
1028
|
+
this.log(` - Navigate to ${chalk6.blue("http://localhost:3000/copilotkit")}`);
|
|
944
1029
|
this.log(` - Talk to your ${userAnswers.agentFramework !== "None" ? "agent" : "application"}.`);
|
|
945
|
-
this.log(` - Read the docs: ${
|
|
946
|
-
this.log(
|
|
1030
|
+
this.log(` - Read the docs: ${chalk6.blue("https://docs.copilotkit.ai")}`);
|
|
1031
|
+
this.log(chalk6.magenta("\nEnjoy building with CopilotKit \u{1FA81}\n"));
|
|
947
1032
|
}
|
|
948
1033
|
};
|
|
949
1034
|
export {
|