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
|
@@ -1,75 +1,105 @@
|
|
|
1
1
|
// src/lib/init/scaffold/env.ts
|
|
2
2
|
import path from "path";
|
|
3
3
|
import fs from "fs";
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
|
|
5
|
+
// src/lib/init/scaffold/langgraph-assistants.ts
|
|
6
|
+
async function getLangGraphAgents(url, langSmithApiKey) {
|
|
7
|
+
try {
|
|
8
|
+
const response = await fetch(
|
|
9
|
+
`${url}/assistants/search`,
|
|
10
|
+
{
|
|
11
|
+
method: "POST",
|
|
12
|
+
headers: {
|
|
13
|
+
"Content-Type": "application/json",
|
|
14
|
+
"X-Api-Key": langSmithApiKey
|
|
15
|
+
},
|
|
16
|
+
body: JSON.stringify({
|
|
17
|
+
limit: 10,
|
|
18
|
+
offset: 0
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
);
|
|
22
|
+
const result = await response.json();
|
|
23
|
+
return result;
|
|
24
|
+
} catch (error) {
|
|
25
|
+
throw new Error("Failed to get LangGraph agents");
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// src/lib/init/scaffold/env.ts
|
|
30
|
+
import inquirer from "inquirer";
|
|
6
31
|
async function scaffoldEnv(flags, userAnswers) {
|
|
7
|
-
const spinner = ora({
|
|
8
|
-
text: chalk.cyan("Configuring environment variables..."),
|
|
9
|
-
color: "cyan"
|
|
10
|
-
}).start();
|
|
11
32
|
try {
|
|
12
33
|
const envFile = path.join(process.cwd(), ".env");
|
|
13
34
|
if (!fs.existsSync(envFile)) {
|
|
14
35
|
fs.writeFileSync(envFile, "", "utf8");
|
|
15
|
-
spinner.text = chalk.cyan("Created .env file...");
|
|
16
36
|
} else {
|
|
17
|
-
spinner.text = chalk.cyan("Updating existing .env file...");
|
|
18
37
|
}
|
|
19
38
|
let newEnvValues = "";
|
|
20
|
-
let varsAdded = false;
|
|
21
39
|
if (userAnswers.copilotCloudPublicApiKey) {
|
|
22
40
|
newEnvValues += `NEXT_PUBLIC_COPILOT_API_KEY=${userAnswers.copilotCloudPublicApiKey}
|
|
23
41
|
`;
|
|
24
|
-
spinner.text = chalk.cyan("Adding Copilot Cloud API key...");
|
|
25
|
-
varsAdded = true;
|
|
26
42
|
}
|
|
27
43
|
if (userAnswers.langSmithApiKey) {
|
|
28
44
|
newEnvValues += `LANGSMITH_API_KEY=${userAnswers.langSmithApiKey}
|
|
29
45
|
`;
|
|
30
|
-
spinner.text = chalk.cyan("Adding LangSmith API key...");
|
|
31
|
-
varsAdded = true;
|
|
32
46
|
}
|
|
33
47
|
if (userAnswers.llmToken) {
|
|
34
48
|
newEnvValues += `OPENAI_API_KEY=${userAnswers.llmToken}
|
|
35
49
|
`;
|
|
36
|
-
spinner.text = chalk.cyan("Adding OpenAI API key...");
|
|
37
|
-
varsAdded = true;
|
|
38
50
|
}
|
|
39
51
|
if (userAnswers.crewName) {
|
|
40
52
|
newEnvValues += `NEXT_PUBLIC_COPILOTKIT_AGENT_NAME=${userAnswers.crewName}
|
|
41
53
|
`;
|
|
42
|
-
|
|
43
|
-
|
|
54
|
+
}
|
|
55
|
+
if (userAnswers.langGraphAgent !== "None" && userAnswers.langGraphPlatform !== "Yes") {
|
|
56
|
+
newEnvValues += `NEXT_PUBLIC_COPILOTKIT_AGENT_NAME=sample_agent
|
|
57
|
+
`;
|
|
58
|
+
newEnvValues += `LANGGRAPH_DEPLOYMENT_URL=http://localhost:8123
|
|
59
|
+
`;
|
|
60
|
+
} else if (userAnswers.langGraphPlatform === "Yes" && userAnswers.useCopilotCloud === "No") {
|
|
61
|
+
newEnvValues += `LANGGRAPH_DEPLOYMENT_URL=${userAnswers.langGraphPlatformUrl}
|
|
62
|
+
`;
|
|
44
63
|
}
|
|
45
64
|
if (flags.runtimeUrl) {
|
|
46
65
|
newEnvValues += `NEXT_PUBLIC_COPILOTKIT_RUNTIME_URL=${flags.runtimeUrl}
|
|
47
66
|
`;
|
|
48
|
-
|
|
49
|
-
varsAdded = true;
|
|
50
|
-
} else if (!userAnswers.useCopilotCloud && userAnswers.crewType !== "Crews") {
|
|
67
|
+
} else if (userAnswers.useCopilotCloud !== "Yes" && userAnswers.crewType !== "Crews") {
|
|
51
68
|
newEnvValues += `NEXT_PUBLIC_COPILOTKIT_RUNTIME_URL=/api/copilotkit
|
|
52
69
|
`;
|
|
53
|
-
spinner.text = chalk.cyan("Adding CopilotKit runtime URL...");
|
|
54
|
-
varsAdded = true;
|
|
55
70
|
}
|
|
56
71
|
if (userAnswers.crewFlowAgent === "Starter") {
|
|
57
72
|
newEnvValues += `NEXT_PUBLIC_COPILOTKIT_AGENT_NAME=sample_agent
|
|
58
73
|
`;
|
|
59
|
-
spinner.text = chalk.cyan("Adding Flow agent name...");
|
|
60
|
-
varsAdded = true;
|
|
61
74
|
}
|
|
62
|
-
if (
|
|
63
|
-
|
|
75
|
+
if (userAnswers.langGraphPlatformUrl && userAnswers.langSmithApiKey) {
|
|
76
|
+
const langGraphAgents = await getLangGraphAgents(userAnswers.langGraphPlatformUrl, userAnswers.langSmithApiKey);
|
|
77
|
+
let langGraphAgent = "";
|
|
78
|
+
if (langGraphAgents.length > 1) {
|
|
79
|
+
const { langGraphAgentChoice } = await inquirer.prompt([
|
|
80
|
+
{
|
|
81
|
+
type: "list",
|
|
82
|
+
name: "langGraphAgentChoice",
|
|
83
|
+
message: "\u{1F99C}\u{1F517} Which agent from your graph would you like to use?",
|
|
84
|
+
choices: langGraphAgents.map((agent) => ({
|
|
85
|
+
name: agent.graph_id,
|
|
86
|
+
value: agent.graph_id
|
|
87
|
+
}))
|
|
88
|
+
}
|
|
89
|
+
]);
|
|
90
|
+
langGraphAgent = langGraphAgentChoice;
|
|
91
|
+
} else if (langGraphAgents.length === 1) {
|
|
92
|
+
langGraphAgent = langGraphAgents[0].graph_id;
|
|
93
|
+
} else {
|
|
94
|
+
throw new Error("No agents found in your LangGraph endpoint");
|
|
95
|
+
}
|
|
96
|
+
newEnvValues += `NEXT_PUBLIC_COPILOTKIT_AGENT_NAME=${langGraphAgent}
|
|
97
|
+
`;
|
|
64
98
|
}
|
|
65
99
|
if (newEnvValues) {
|
|
66
100
|
fs.appendFileSync(envFile, newEnvValues);
|
|
67
|
-
spinner.succeed(chalk("Environment variables configured successfully"));
|
|
68
|
-
} else {
|
|
69
|
-
spinner.info(chalk.yellow("No environment variables were added"));
|
|
70
101
|
}
|
|
71
102
|
} catch (error) {
|
|
72
|
-
spinner.fail(chalk.red("Failed to update environment variables"));
|
|
73
103
|
throw error;
|
|
74
104
|
}
|
|
75
105
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/init/scaffold/env.ts"],"sourcesContent":["import path from \"path\"\nimport fs from \"fs\"\nimport { Config } from \"../types/index.js\"\nimport
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/init/scaffold/env.ts","../../../../src/lib/init/scaffold/langgraph-assistants.ts"],"sourcesContent":["import path from \"path\"\nimport fs from \"fs\"\nimport { Config } from \"../types/index.js\"\nimport { getLangGraphAgents } from \"./langgraph-assistants.js\"\nimport inquirer from \"inquirer\"\n\nexport async function scaffoldEnv(flags: any, userAnswers: Config) {\n try {\n // Define the env file path\n const envFile = path.join(process.cwd(), '.env')\n \n // Create the env file if it doesn't exist\n if (!fs.existsSync(envFile)) {\n fs.writeFileSync(envFile, '', 'utf8')\n } else {\n }\n \n // Build environment variables based on user selections\n let newEnvValues = ''\n \n // Copilot Cloud API key\n if (userAnswers.copilotCloudPublicApiKey) {\n newEnvValues += `NEXT_PUBLIC_COPILOT_API_KEY=${userAnswers.copilotCloudPublicApiKey}\\n`\n }\n \n // LangSmith API key (for LangGraph)\n if (userAnswers.langSmithApiKey) {\n // Add both formats for compatibility\n newEnvValues += `LANGSMITH_API_KEY=${userAnswers.langSmithApiKey}\\n`\n }\n \n // LLM API key - set as both LLM_TOKEN and OPENAI_API_KEY for compatibility\n if (userAnswers.llmToken) {\n newEnvValues += `OPENAI_API_KEY=${userAnswers.llmToken}\\n`\n }\n \n // CrewAI name\n if (userAnswers.crewName) {\n newEnvValues += `NEXT_PUBLIC_COPILOTKIT_AGENT_NAME=${userAnswers.crewName}\\n`\n }\n\n if (userAnswers.langGraphAgent !== 'None' && userAnswers.langGraphPlatform !== 'Yes') {\n newEnvValues += `NEXT_PUBLIC_COPILOTKIT_AGENT_NAME=sample_agent\\n`\n newEnvValues += `LANGGRAPH_DEPLOYMENT_URL=http://localhost:8123\\n`\n } else if (userAnswers.langGraphPlatform === 'Yes' && userAnswers.useCopilotCloud === 'No') {\n newEnvValues += `LANGGRAPH_DEPLOYMENT_URL=${userAnswers.langGraphPlatformUrl}\\n`\n }\n\n // Runtime URL if provided via flags\n if (flags.runtimeUrl) {\n newEnvValues += `NEXT_PUBLIC_COPILOTKIT_RUNTIME_URL=${flags.runtimeUrl}\\n`\n } else if (userAnswers.useCopilotCloud !== 'Yes' && userAnswers.crewType !== 'Crews') {\n newEnvValues += `NEXT_PUBLIC_COPILOTKIT_RUNTIME_URL=/api/copilotkit\\n`\n }\n\n if (userAnswers.crewFlowAgent === 'Starter') {\n newEnvValues += `NEXT_PUBLIC_COPILOTKIT_AGENT_NAME=sample_agent\\n`\n }\n\n if (userAnswers.langGraphPlatformUrl && userAnswers.langSmithApiKey) {\n const langGraphAgents = await getLangGraphAgents(userAnswers.langGraphPlatformUrl, userAnswers.langSmithApiKey);\n let langGraphAgent = '';\n if (langGraphAgents.length > 1) {\n const { langGraphAgentChoice } = await inquirer.prompt([\n {\n type: 'list',\n name: 'langGraphAgentChoice',\n message: '🦜🔗 Which agent from your graph would you like to use?',\n choices: langGraphAgents.map((agent: any) => ({\n name: agent.graph_id,\n value: agent.graph_id,\n }))\n }\n ]);\n langGraphAgent = langGraphAgentChoice;\n } else if (langGraphAgents.length === 1) {\n langGraphAgent = langGraphAgents[0].graph_id;\n } else {\n throw new Error('No agents found in your LangGraph endpoint');\n }\n\n newEnvValues += `NEXT_PUBLIC_COPILOTKIT_AGENT_NAME=${langGraphAgent}\\n`\n }\n\n // Append the variables to the .env file\n if (newEnvValues) {\n fs.appendFileSync(envFile, newEnvValues)\n }\n } catch (error) {\n throw error;\n }\n}\n","export type LangGraphAgent = {\n assistant_id: string;\n graph_id: string;\n config: {\n tags: string[];\n recursion_limit: number;\n configurable: Record<string, any>;\n };\n created_at: string;\n updated_at: string;\n metadata: Record<string, any>;\n version: number;\n name: string;\n description: string;\n}\n\nexport async function getLangGraphAgents(url: string, langSmithApiKey: string) {\n try {\n const response = await fetch(`${url}/assistants/search`, \n {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'X-Api-Key': langSmithApiKey\n },\n body: JSON.stringify({\n limit: 10,\n offset: 0\n })\n })\n\n const result = await response.json() as LangGraphAgent[];\n return result;\n } catch (error) {\n throw new Error('Failed to get LangGraph agents');\n }\n}"],"mappings":";AAAA,OAAO,UAAU;AACjB,OAAO,QAAQ;;;ACef,eAAsB,mBAAmB,KAAa,iBAAyB;AAC7E,MAAI;AACF,UAAM,WAAW,MAAM;AAAA,MAAM,GAAG,GAAG;AAAA,MACjC;AAAA,QACE,QAAQ;AAAA,QACR,SAAS;AAAA,UACT,gBAAgB;AAAA,UAChB,aAAa;AAAA,QACf;AAAA,QACA,MAAM,KAAK,UAAU;AAAA,UACnB,OAAO;AAAA,UACP,QAAQ;AAAA,QACV,CAAC;AAAA,MACH;AAAA,IAAC;AAED,UAAM,SAAS,MAAM,SAAS,KAAK;AACnC,WAAO;AAAA,EACT,SAAS,OAAO;AACd,UAAM,IAAI,MAAM,gCAAgC;AAAA,EAClD;AACF;;;ADhCA,OAAO,cAAc;AAErB,eAAsB,YAAY,OAAY,aAAqB;AACjE,MAAI;AAEF,UAAM,UAAU,KAAK,KAAK,QAAQ,IAAI,GAAG,MAAM;AAG/C,QAAI,CAAC,GAAG,WAAW,OAAO,GAAG;AAC3B,SAAG,cAAc,SAAS,IAAI,MAAM;AAAA,IACtC,OAAO;AAAA,IACP;AAGA,QAAI,eAAe;AAGnB,QAAI,YAAY,0BAA0B;AACxC,sBAAgB,+BAA+B,YAAY,wBAAwB;AAAA;AAAA,IACrF;AAGA,QAAI,YAAY,iBAAiB;AAE/B,sBAAgB,qBAAqB,YAAY,eAAe;AAAA;AAAA,IAClE;AAGA,QAAI,YAAY,UAAU;AACxB,sBAAgB,kBAAkB,YAAY,QAAQ;AAAA;AAAA,IACxD;AAGA,QAAI,YAAY,UAAU;AACxB,sBAAgB,qCAAqC,YAAY,QAAQ;AAAA;AAAA,IAC3E;AAEA,QAAI,YAAY,mBAAmB,UAAU,YAAY,sBAAsB,OAAO;AACpF,sBAAgB;AAAA;AAChB,sBAAgB;AAAA;AAAA,IAClB,WAAW,YAAY,sBAAsB,SAAS,YAAY,oBAAoB,MAAM;AAC1F,sBAAgB,4BAA4B,YAAY,oBAAoB;AAAA;AAAA,IAC9E;AAGA,QAAI,MAAM,YAAY;AACpB,sBAAgB,sCAAsC,MAAM,UAAU;AAAA;AAAA,IACxE,WAAW,YAAY,oBAAoB,SAAS,YAAY,aAAa,SAAS;AACpF,sBAAgB;AAAA;AAAA,IAClB;AAEA,QAAI,YAAY,kBAAkB,WAAW;AAC3C,sBAAgB;AAAA;AAAA,IAClB;AAEA,QAAI,YAAY,wBAAwB,YAAY,iBAAiB;AACnE,YAAM,kBAAkB,MAAM,mBAAmB,YAAY,sBAAsB,YAAY,eAAe;AAC9G,UAAI,iBAAiB;AACrB,UAAI,gBAAgB,SAAS,GAAG;AAC9B,cAAM,EAAE,qBAAqB,IAAI,MAAM,SAAS,OAAO;AAAA,UACrD;AAAA,YACE,MAAM;AAAA,YACN,MAAM;AAAA,YACN,SAAS;AAAA,YACT,SAAS,gBAAgB,IAAI,CAAC,WAAgB;AAAA,cAC5C,MAAM,MAAM;AAAA,cACZ,OAAO,MAAM;AAAA,YACf,EAAE;AAAA,UACJ;AAAA,QACF,CAAC;AACD,yBAAiB;AAAA,MACnB,WAAW,gBAAgB,WAAW,GAAG;AACvC,yBAAiB,gBAAgB,CAAC,EAAE;AAAA,MACtC,OAAO;AACL,cAAM,IAAI,MAAM,4CAA4C;AAAA,MAC9D;AAEA,sBAAgB,qCAAqC,cAAc;AAAA;AAAA,IACrE;AAGA,QAAI,cAAc;AAChB,SAAG,eAAe,SAAS,YAAY;AAAA,IACzC;AAAA,EACF,SAAS,OAAO;AACd,UAAM;AAAA,EACR;AACF;","names":[]}
|
|
@@ -25,18 +25,23 @@ var ConfigFlags = {
|
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
// src/lib/init/types/templates.ts
|
|
28
|
-
var BASE_URL = "
|
|
28
|
+
var BASE_URL = "https://registry.copilotkit.ai/r";
|
|
29
29
|
var templateMapping = {
|
|
30
30
|
"LangGraphPlatform": `${BASE_URL}/langgraph-platform-starter.json`,
|
|
31
31
|
"RemoteEndpoint": `${BASE_URL}/remote-endpoint-starter.json`,
|
|
32
32
|
"CrewEnterprise": [
|
|
33
33
|
`${BASE_URL}/coagents-crew-starter.json`
|
|
34
34
|
],
|
|
35
|
+
"LangGraphGeneric": `${BASE_URL}/generic-lg-starter.json`,
|
|
35
36
|
"CrewFlowsStarter": [
|
|
36
37
|
`${BASE_URL}/coagents-starter-ui.json`,
|
|
37
38
|
`${BASE_URL}/agent-layout.json`,
|
|
38
39
|
`${BASE_URL}/remote-endpoint.json`
|
|
39
40
|
],
|
|
41
|
+
"LangGraphStarter": [
|
|
42
|
+
`${BASE_URL}/langgraph-platform-starter.json`,
|
|
43
|
+
`${BASE_URL}/coagents-starter-ui.json`
|
|
44
|
+
],
|
|
40
45
|
"Standard": `${BASE_URL}/standard-starter.json`,
|
|
41
46
|
"CopilotChat": `${BASE_URL}/chat.json`,
|
|
42
47
|
"CopilotPopup": `${BASE_URL}/popup.json`,
|
|
@@ -50,7 +55,11 @@ async function scaffoldShadCN(userAnswers) {
|
|
|
50
55
|
if (userAnswers.agentFramework !== "None") {
|
|
51
56
|
switch (userAnswers.agentFramework) {
|
|
52
57
|
case "LangGraph":
|
|
53
|
-
|
|
58
|
+
if (userAnswers.langGraphAgent && userAnswers.langGraphAgent !== "None") {
|
|
59
|
+
components.push(...templateMapping.LangGraphStarter);
|
|
60
|
+
} else {
|
|
61
|
+
components.push(templateMapping.LangGraphGeneric);
|
|
62
|
+
}
|
|
54
63
|
break;
|
|
55
64
|
case "CrewAI":
|
|
56
65
|
if (userAnswers.crewType === "Crews") {
|
|
@@ -86,75 +95,105 @@ async function scaffoldShadCN(userAnswers) {
|
|
|
86
95
|
// src/lib/init/scaffold/env.ts
|
|
87
96
|
import path from "path";
|
|
88
97
|
import fs from "fs";
|
|
89
|
-
|
|
90
|
-
|
|
98
|
+
|
|
99
|
+
// src/lib/init/scaffold/langgraph-assistants.ts
|
|
100
|
+
async function getLangGraphAgents(url, langSmithApiKey) {
|
|
101
|
+
try {
|
|
102
|
+
const response = await fetch(
|
|
103
|
+
`${url}/assistants/search`,
|
|
104
|
+
{
|
|
105
|
+
method: "POST",
|
|
106
|
+
headers: {
|
|
107
|
+
"Content-Type": "application/json",
|
|
108
|
+
"X-Api-Key": langSmithApiKey
|
|
109
|
+
},
|
|
110
|
+
body: JSON.stringify({
|
|
111
|
+
limit: 10,
|
|
112
|
+
offset: 0
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
const result = await response.json();
|
|
117
|
+
return result;
|
|
118
|
+
} catch (error) {
|
|
119
|
+
throw new Error("Failed to get LangGraph agents");
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// src/lib/init/scaffold/env.ts
|
|
124
|
+
import inquirer from "inquirer";
|
|
91
125
|
async function scaffoldEnv(flags, userAnswers) {
|
|
92
|
-
const spinner = ora({
|
|
93
|
-
text: chalk.cyan("Configuring environment variables..."),
|
|
94
|
-
color: "cyan"
|
|
95
|
-
}).start();
|
|
96
126
|
try {
|
|
97
127
|
const envFile = path.join(process.cwd(), ".env");
|
|
98
128
|
if (!fs.existsSync(envFile)) {
|
|
99
129
|
fs.writeFileSync(envFile, "", "utf8");
|
|
100
|
-
spinner.text = chalk.cyan("Created .env file...");
|
|
101
130
|
} else {
|
|
102
|
-
spinner.text = chalk.cyan("Updating existing .env file...");
|
|
103
131
|
}
|
|
104
132
|
let newEnvValues = "";
|
|
105
|
-
let varsAdded = false;
|
|
106
133
|
if (userAnswers.copilotCloudPublicApiKey) {
|
|
107
134
|
newEnvValues += `NEXT_PUBLIC_COPILOT_API_KEY=${userAnswers.copilotCloudPublicApiKey}
|
|
108
135
|
`;
|
|
109
|
-
spinner.text = chalk.cyan("Adding Copilot Cloud API key...");
|
|
110
|
-
varsAdded = true;
|
|
111
136
|
}
|
|
112
137
|
if (userAnswers.langSmithApiKey) {
|
|
113
138
|
newEnvValues += `LANGSMITH_API_KEY=${userAnswers.langSmithApiKey}
|
|
114
139
|
`;
|
|
115
|
-
spinner.text = chalk.cyan("Adding LangSmith API key...");
|
|
116
|
-
varsAdded = true;
|
|
117
140
|
}
|
|
118
141
|
if (userAnswers.llmToken) {
|
|
119
142
|
newEnvValues += `OPENAI_API_KEY=${userAnswers.llmToken}
|
|
120
143
|
`;
|
|
121
|
-
spinner.text = chalk.cyan("Adding OpenAI API key...");
|
|
122
|
-
varsAdded = true;
|
|
123
144
|
}
|
|
124
145
|
if (userAnswers.crewName) {
|
|
125
146
|
newEnvValues += `NEXT_PUBLIC_COPILOTKIT_AGENT_NAME=${userAnswers.crewName}
|
|
126
147
|
`;
|
|
127
|
-
|
|
128
|
-
|
|
148
|
+
}
|
|
149
|
+
if (userAnswers.langGraphAgent !== "None" && userAnswers.langGraphPlatform !== "Yes") {
|
|
150
|
+
newEnvValues += `NEXT_PUBLIC_COPILOTKIT_AGENT_NAME=sample_agent
|
|
151
|
+
`;
|
|
152
|
+
newEnvValues += `LANGGRAPH_DEPLOYMENT_URL=http://localhost:8123
|
|
153
|
+
`;
|
|
154
|
+
} else if (userAnswers.langGraphPlatform === "Yes" && userAnswers.useCopilotCloud === "No") {
|
|
155
|
+
newEnvValues += `LANGGRAPH_DEPLOYMENT_URL=${userAnswers.langGraphPlatformUrl}
|
|
156
|
+
`;
|
|
129
157
|
}
|
|
130
158
|
if (flags.runtimeUrl) {
|
|
131
159
|
newEnvValues += `NEXT_PUBLIC_COPILOTKIT_RUNTIME_URL=${flags.runtimeUrl}
|
|
132
160
|
`;
|
|
133
|
-
|
|
134
|
-
varsAdded = true;
|
|
135
|
-
} else if (!userAnswers.useCopilotCloud && userAnswers.crewType !== "Crews") {
|
|
161
|
+
} else if (userAnswers.useCopilotCloud !== "Yes" && userAnswers.crewType !== "Crews") {
|
|
136
162
|
newEnvValues += `NEXT_PUBLIC_COPILOTKIT_RUNTIME_URL=/api/copilotkit
|
|
137
163
|
`;
|
|
138
|
-
spinner.text = chalk.cyan("Adding CopilotKit runtime URL...");
|
|
139
|
-
varsAdded = true;
|
|
140
164
|
}
|
|
141
165
|
if (userAnswers.crewFlowAgent === "Starter") {
|
|
142
166
|
newEnvValues += `NEXT_PUBLIC_COPILOTKIT_AGENT_NAME=sample_agent
|
|
143
167
|
`;
|
|
144
|
-
spinner.text = chalk.cyan("Adding Flow agent name...");
|
|
145
|
-
varsAdded = true;
|
|
146
168
|
}
|
|
147
|
-
if (
|
|
148
|
-
|
|
169
|
+
if (userAnswers.langGraphPlatformUrl && userAnswers.langSmithApiKey) {
|
|
170
|
+
const langGraphAgents = await getLangGraphAgents(userAnswers.langGraphPlatformUrl, userAnswers.langSmithApiKey);
|
|
171
|
+
let langGraphAgent = "";
|
|
172
|
+
if (langGraphAgents.length > 1) {
|
|
173
|
+
const { langGraphAgentChoice } = await inquirer.prompt([
|
|
174
|
+
{
|
|
175
|
+
type: "list",
|
|
176
|
+
name: "langGraphAgentChoice",
|
|
177
|
+
message: "\u{1F99C}\u{1F517} Which agent from your graph would you like to use?",
|
|
178
|
+
choices: langGraphAgents.map((agent) => ({
|
|
179
|
+
name: agent.graph_id,
|
|
180
|
+
value: agent.graph_id
|
|
181
|
+
}))
|
|
182
|
+
}
|
|
183
|
+
]);
|
|
184
|
+
langGraphAgent = langGraphAgentChoice;
|
|
185
|
+
} else if (langGraphAgents.length === 1) {
|
|
186
|
+
langGraphAgent = langGraphAgents[0].graph_id;
|
|
187
|
+
} else {
|
|
188
|
+
throw new Error("No agents found in your LangGraph endpoint");
|
|
189
|
+
}
|
|
190
|
+
newEnvValues += `NEXT_PUBLIC_COPILOTKIT_AGENT_NAME=${langGraphAgent}
|
|
191
|
+
`;
|
|
149
192
|
}
|
|
150
193
|
if (newEnvValues) {
|
|
151
194
|
fs.appendFileSync(envFile, newEnvValues);
|
|
152
|
-
spinner.succeed(chalk("Environment variables configured successfully"));
|
|
153
|
-
} else {
|
|
154
|
-
spinner.info(chalk.yellow("No environment variables were added"));
|
|
155
195
|
}
|
|
156
196
|
} catch (error) {
|
|
157
|
-
spinner.fail(chalk.red("Failed to update environment variables"));
|
|
158
197
|
throw error;
|
|
159
198
|
}
|
|
160
199
|
}
|
|
@@ -164,34 +203,34 @@ import { execSync } from "child_process";
|
|
|
164
203
|
import * as fs2 from "fs";
|
|
165
204
|
import * as path2 from "path";
|
|
166
205
|
import * as os from "os";
|
|
167
|
-
import
|
|
206
|
+
import chalk from "chalk";
|
|
168
207
|
async function cloneGitHubSubdirectory(githubUrl, destinationPath, spinner) {
|
|
169
208
|
try {
|
|
170
209
|
const { owner, repo, branch, subdirectoryPath } = parseGitHubUrl(githubUrl);
|
|
171
|
-
spinner.text =
|
|
210
|
+
spinner.text = chalk.cyan(`Cloning from ${owner}/${repo}...`);
|
|
172
211
|
return await sparseCheckout(owner, repo, branch, subdirectoryPath, destinationPath, spinner);
|
|
173
212
|
} catch (error) {
|
|
174
|
-
spinner.text =
|
|
213
|
+
spinner.text = chalk.red(`Failed to clone from GitHub: ${error}`);
|
|
175
214
|
return false;
|
|
176
215
|
}
|
|
177
216
|
}
|
|
178
217
|
async function sparseCheckout(owner, repo, branch, subdirectoryPath, destinationPath, spinner) {
|
|
179
218
|
const tempDir = fs2.mkdtempSync(path2.join(os.tmpdir(), "copilotkit-sparse-"));
|
|
180
219
|
try {
|
|
181
|
-
spinner.text =
|
|
220
|
+
spinner.text = chalk.cyan("Creating temporary workspace...");
|
|
182
221
|
execSync("git init", { cwd: tempDir, stdio: "pipe" });
|
|
183
|
-
spinner.text =
|
|
222
|
+
spinner.text = chalk.cyan("Connecting to repository...");
|
|
184
223
|
execSync(`git remote add origin https://github.com/${owner}/${repo}.git`, { cwd: tempDir, stdio: "pipe" });
|
|
185
224
|
execSync("git config core.sparseCheckout true", { cwd: tempDir, stdio: "pipe" });
|
|
186
225
|
fs2.writeFileSync(path2.join(tempDir, ".git/info/sparse-checkout"), subdirectoryPath);
|
|
187
|
-
spinner.text =
|
|
226
|
+
spinner.text = chalk.cyan("Downloading agent files...");
|
|
188
227
|
execSync(`git pull origin ${branch} --depth=1`, { cwd: tempDir, stdio: "pipe" });
|
|
189
228
|
const sourcePath = path2.join(tempDir, subdirectoryPath);
|
|
190
229
|
if (!fs2.existsSync(sourcePath)) {
|
|
191
230
|
throw new Error(`Subdirectory '${subdirectoryPath}' not found in the repository.`);
|
|
192
231
|
}
|
|
193
232
|
fs2.mkdirSync(destinationPath, { recursive: true });
|
|
194
|
-
spinner.text =
|
|
233
|
+
spinner.text = chalk.cyan("Installing agent files...");
|
|
195
234
|
await copyDirectoryAsync(sourcePath, destinationPath);
|
|
196
235
|
return true;
|
|
197
236
|
} finally {
|
|
@@ -250,12 +289,12 @@ function isValidGitHubUrl(url) {
|
|
|
250
289
|
|
|
251
290
|
// src/lib/init/scaffold/packages.ts
|
|
252
291
|
import spawn2 from "cross-spawn";
|
|
253
|
-
import
|
|
292
|
+
import chalk2 from "chalk";
|
|
254
293
|
import fs3 from "fs";
|
|
255
|
-
import
|
|
294
|
+
import ora from "ora";
|
|
256
295
|
async function scaffoldPackages(userAnswers) {
|
|
257
|
-
const spinner =
|
|
258
|
-
text:
|
|
296
|
+
const spinner = ora({
|
|
297
|
+
text: chalk2.cyan("Preparing to install packages..."),
|
|
259
298
|
color: "cyan"
|
|
260
299
|
}).start();
|
|
261
300
|
try {
|
|
@@ -267,9 +306,9 @@ async function scaffoldPackages(userAnswers) {
|
|
|
267
306
|
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
268
307
|
const packageManager = detectPackageManager();
|
|
269
308
|
const installCommand = detectInstallCommand(packageManager);
|
|
270
|
-
spinner.text =
|
|
309
|
+
spinner.text = chalk2.cyan(`Using ${packageManager} to install packages...`);
|
|
271
310
|
spinner.stop();
|
|
272
|
-
console.log(
|
|
311
|
+
console.log(chalk2.cyan("\n\u2699\uFE0F Installing packages...\n"));
|
|
273
312
|
const result = spawn2.sync(packageManager, [installCommand, ...packages], {
|
|
274
313
|
stdio: "inherit"
|
|
275
314
|
// This ensures stdin/stdout/stderr are all passed through
|
|
@@ -278,12 +317,12 @@ async function scaffoldPackages(userAnswers) {
|
|
|
278
317
|
throw new Error(`Package installation process exited with code ${result.status}`);
|
|
279
318
|
}
|
|
280
319
|
spinner.start();
|
|
281
|
-
spinner.succeed(
|
|
320
|
+
spinner.succeed(chalk2.green("CopilotKit packages installed successfully"));
|
|
282
321
|
} catch (error) {
|
|
283
322
|
if (!spinner.isSpinning) {
|
|
284
323
|
spinner.start();
|
|
285
324
|
}
|
|
286
|
-
spinner.fail(
|
|
325
|
+
spinner.fail(chalk2.red("Failed to install CopilotKit packages"));
|
|
287
326
|
throw error;
|
|
288
327
|
}
|
|
289
328
|
}
|
|
@@ -306,16 +345,16 @@ function detectInstallCommand(packageManager) {
|
|
|
306
345
|
}
|
|
307
346
|
|
|
308
347
|
// src/lib/init/scaffold/agent.ts
|
|
309
|
-
import
|
|
310
|
-
import
|
|
348
|
+
import ora2 from "ora";
|
|
349
|
+
import chalk3 from "chalk";
|
|
311
350
|
import path3 from "path";
|
|
312
351
|
import fs4 from "fs";
|
|
313
352
|
async function scaffoldAgent(userAnswers) {
|
|
314
353
|
if (userAnswers.agentFramework === "None" || userAnswers.agentFramework === "CrewAI" && userAnswers.crewType === "Crews" || userAnswers.agentFramework === "LangGraph" && (!userAnswers.langGraphAgent || userAnswers.langGraphAgent === "None")) {
|
|
315
354
|
return;
|
|
316
355
|
}
|
|
317
|
-
const spinner =
|
|
318
|
-
text:
|
|
356
|
+
const spinner = ora2({
|
|
357
|
+
text: chalk3.cyan("Setting up AI agent..."),
|
|
319
358
|
color: "cyan"
|
|
320
359
|
}).start();
|
|
321
360
|
let template = "";
|
|
@@ -334,7 +373,7 @@ async function scaffoldAgent(userAnswers) {
|
|
|
334
373
|
break;
|
|
335
374
|
}
|
|
336
375
|
if (!template) {
|
|
337
|
-
spinner.fail(
|
|
376
|
+
spinner.fail(chalk3.red("Failed to determine agent template"));
|
|
338
377
|
throw new Error("Failed to determine agent template");
|
|
339
378
|
}
|
|
340
379
|
const agentDir = path3.join(process.cwd(), "agent");
|
|
@@ -344,7 +383,7 @@ async function scaffoldAgent(userAnswers) {
|
|
|
344
383
|
agentDir,
|
|
345
384
|
spinner
|
|
346
385
|
);
|
|
347
|
-
spinner.text =
|
|
386
|
+
spinner.text = chalk3.cyan("Creating agent environment variables...");
|
|
348
387
|
let envContent = "";
|
|
349
388
|
if (userAnswers.llmToken) {
|
|
350
389
|
envContent += `OPENAI_API_KEY=${userAnswers.llmToken}
|
|
@@ -357,10 +396,10 @@ async function scaffoldAgent(userAnswers) {
|
|
|
357
396
|
if (envContent) {
|
|
358
397
|
const agentEnvFile = path3.join(agentDir, ".env");
|
|
359
398
|
fs4.writeFileSync(agentEnvFile, envContent, "utf8");
|
|
360
|
-
spinner.text =
|
|
399
|
+
spinner.text = chalk3.cyan("Added API keys to agent .env file");
|
|
361
400
|
}
|
|
362
401
|
} catch (error) {
|
|
363
|
-
spinner.fail(
|
|
402
|
+
spinner.fail(chalk3.red("Failed to clone agent template"));
|
|
364
403
|
throw error;
|
|
365
404
|
}
|
|
366
405
|
spinner.succeed(`${userAnswers.agentFramework} agent cloned successfully`);
|
|
@@ -368,8 +407,8 @@ async function scaffoldAgent(userAnswers) {
|
|
|
368
407
|
var AgentTemplates = {
|
|
369
408
|
LangGraph: {
|
|
370
409
|
Starter: {
|
|
371
|
-
Python: "https://github.com/CopilotKit/
|
|
372
|
-
TypeScript: "https://github.com/CopilotKit/
|
|
410
|
+
Python: "https://github.com/CopilotKit/coagents-starter-langgraph/tree/main/agent-py",
|
|
411
|
+
TypeScript: "https://github.com/CopilotKit/coagents-starter-langgraph/tree/main/agent-js"
|
|
373
412
|
}
|
|
374
413
|
},
|
|
375
414
|
CrewAI: {
|
|
@@ -381,11 +420,11 @@ var AgentTemplates = {
|
|
|
381
420
|
|
|
382
421
|
// src/lib/init/scaffold/crew-inputs.ts
|
|
383
422
|
import * as fs5 from "fs/promises";
|
|
384
|
-
import
|
|
423
|
+
import ora3 from "ora";
|
|
385
424
|
import * as path4 from "path";
|
|
386
425
|
async function addCrewInputs(url, token) {
|
|
387
426
|
try {
|
|
388
|
-
const spinner =
|
|
427
|
+
const spinner = ora3("Analyzing crew inputs...").start();
|
|
389
428
|
const inputs = await getCrewInputs(url, token);
|
|
390
429
|
spinner.text = "Adding inputs to app/copilotkit/page.tsx...";
|
|
391
430
|
let filePath = path4.join(process.cwd(), "app", "copilotkit", "page.tsx");
|