@standardagents/cli 0.11.0-next.5d2e71b → 0.11.0-next.7005954
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/index.js +208 -161
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command } from 'commander';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { fileURLToPath } from 'url';
|
|
3
|
+
import path3 from 'path';
|
|
4
|
+
import fs3 from 'fs';
|
|
6
5
|
import crypto from 'crypto';
|
|
7
6
|
import readline from 'readline';
|
|
8
7
|
import { spawn } from 'child_process';
|
|
@@ -11,6 +10,7 @@ import { parse, modify, applyEdits } from 'jsonc-parser';
|
|
|
11
10
|
import { loadFile, writeFile, generateCode } from 'magicast';
|
|
12
11
|
import { addVitePlugin } from 'magicast/helpers';
|
|
13
12
|
import net from 'net';
|
|
13
|
+
import { fileURLToPath } from 'url';
|
|
14
14
|
|
|
15
15
|
var logger = {
|
|
16
16
|
success: (message) => {
|
|
@@ -116,30 +116,32 @@ agents/
|
|
|
116
116
|
|
|
117
117
|
Files are **auto-discovered** at runtime. No manual registration needed.
|
|
118
118
|
|
|
119
|
-
##
|
|
119
|
+
## ThreadState
|
|
120
120
|
|
|
121
|
-
\`
|
|
121
|
+
\`ThreadState\` is the state object available in tools and hooks:
|
|
122
122
|
|
|
123
123
|
\`\`\`typescript
|
|
124
|
-
interface
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
124
|
+
interface ThreadState {
|
|
125
|
+
// Identity (readonly)
|
|
126
|
+
threadId: string; // Thread identifier
|
|
127
|
+
agentId: string; // Agent identifier
|
|
128
|
+
userId: string | null; // User identifier (if set)
|
|
129
|
+
createdAt: number; // Creation timestamp
|
|
130
|
+
|
|
131
|
+
// Methods
|
|
132
|
+
getMessages(options?): Promise<MessagesResult>; // Get conversation history
|
|
133
|
+
injectMessage(input): Promise<Message>; // Add message to thread
|
|
134
|
+
loadModel(name): Promise<ModelConfig>; // Load model definition
|
|
135
|
+
loadPrompt(name): Promise<PromptConfig>; // Load prompt definition
|
|
136
|
+
loadAgent(name): Promise<AgentConfig>; // Load agent definition
|
|
135
137
|
}
|
|
136
138
|
\`\`\`
|
|
137
139
|
|
|
138
140
|
Access in tools:
|
|
139
141
|
\`\`\`typescript
|
|
140
142
|
export default defineTool('...', schema, async (flow, args) => {
|
|
141
|
-
const threadId = flow.
|
|
142
|
-
const messages = flow.
|
|
143
|
+
const threadId = flow.threadId;
|
|
144
|
+
const { messages } = await flow.getMessages();
|
|
143
145
|
// ...
|
|
144
146
|
});
|
|
145
147
|
\`\`\`
|
|
@@ -525,12 +527,12 @@ Tools extend agent capabilities beyond text generation. They allow LLMs to fetch
|
|
|
525
527
|
## Function Signature
|
|
526
528
|
|
|
527
529
|
\`\`\`typescript
|
|
528
|
-
defineTool(
|
|
530
|
+
defineTool({
|
|
529
531
|
description: string, // What the tool does (shown to LLM)
|
|
530
|
-
args
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
)
|
|
532
|
+
args?: z.ZodObject, // Input validation schema (optional)
|
|
533
|
+
execute: (state, args) => ToolResult, // Implementation
|
|
534
|
+
tenvs?: z.ZodObject, // Thread environment variables (optional)
|
|
535
|
+
})
|
|
534
536
|
\`\`\`
|
|
535
537
|
|
|
536
538
|
## Basic Example
|
|
@@ -539,20 +541,20 @@ defineTool(
|
|
|
539
541
|
import { defineTool } from '@standardagents/builder';
|
|
540
542
|
import { z } from 'zod';
|
|
541
543
|
|
|
542
|
-
export default defineTool(
|
|
543
|
-
'Search the knowledge base for articles matching a query',
|
|
544
|
-
z.object({
|
|
544
|
+
export default defineTool({
|
|
545
|
+
description: 'Search the knowledge base for articles matching a query',
|
|
546
|
+
args: z.object({
|
|
545
547
|
query: z.string().describe('Search query'),
|
|
546
548
|
limit: z.number().optional().default(10).describe('Max results'),
|
|
547
549
|
}),
|
|
548
|
-
async (
|
|
550
|
+
execute: async (state, args) => {
|
|
549
551
|
const results = await searchKB(args.query, args.limit);
|
|
550
552
|
return {
|
|
551
553
|
status: 'success',
|
|
552
554
|
result: JSON.stringify(results),
|
|
553
555
|
};
|
|
554
|
-
}
|
|
555
|
-
);
|
|
556
|
+
},
|
|
557
|
+
});
|
|
556
558
|
\`\`\`
|
|
557
559
|
|
|
558
560
|
## ToolResult Interface
|
|
@@ -562,44 +564,45 @@ export default defineTool(
|
|
|
562
564
|
| \`status\` | \`'success' \\| 'error'\` | Whether the tool succeeded |
|
|
563
565
|
| \`result\` | \`string\` | Tool output (required for success) |
|
|
564
566
|
| \`error\` | \`string\` | Error message (for error status) |
|
|
567
|
+
| \`attachments\` | \`ToolAttachment[]\` | Files to attach (images, etc.) |
|
|
565
568
|
|
|
566
|
-
##
|
|
569
|
+
## ThreadState Access
|
|
567
570
|
|
|
568
|
-
The \`
|
|
571
|
+
The \`state\` parameter provides access to:
|
|
569
572
|
|
|
570
573
|
\`\`\`typescript
|
|
571
|
-
async (
|
|
574
|
+
execute: async (state, args) => {
|
|
572
575
|
// Thread information
|
|
573
|
-
const threadId =
|
|
574
|
-
const thread =
|
|
576
|
+
const threadId = state.thread.id;
|
|
577
|
+
const thread = state.thread.instance;
|
|
575
578
|
|
|
576
579
|
// Configuration
|
|
577
|
-
const agentName =
|
|
578
|
-
const modelName =
|
|
580
|
+
const agentName = state.agent.name;
|
|
581
|
+
const modelName = state.model.name;
|
|
579
582
|
|
|
580
583
|
// Message history
|
|
581
|
-
const messages =
|
|
584
|
+
const messages = state.messages;
|
|
582
585
|
|
|
583
586
|
// Environment bindings
|
|
584
|
-
const env =
|
|
587
|
+
const env = state.env;
|
|
585
588
|
|
|
586
589
|
// Parent state (for sub-prompts)
|
|
587
|
-
const root =
|
|
590
|
+
const root = state.rootState;
|
|
588
591
|
}
|
|
589
592
|
\`\`\`
|
|
590
593
|
|
|
591
594
|
## Tool Without Arguments
|
|
592
595
|
|
|
593
596
|
\`\`\`typescript
|
|
594
|
-
export default defineTool(
|
|
595
|
-
'Get current server time',
|
|
596
|
-
async (
|
|
597
|
+
export default defineTool({
|
|
598
|
+
description: 'Get current server time',
|
|
599
|
+
execute: async (state) => {
|
|
597
600
|
return {
|
|
598
601
|
status: 'success',
|
|
599
602
|
result: new Date().toISOString(),
|
|
600
603
|
};
|
|
601
|
-
}
|
|
602
|
-
);
|
|
604
|
+
},
|
|
605
|
+
});
|
|
603
606
|
\`\`\`
|
|
604
607
|
|
|
605
608
|
## Error Handling
|
|
@@ -607,10 +610,10 @@ export default defineTool(
|
|
|
607
610
|
Return errors gracefully instead of throwing:
|
|
608
611
|
|
|
609
612
|
\`\`\`typescript
|
|
610
|
-
export default defineTool(
|
|
611
|
-
'Fetch user data',
|
|
612
|
-
z.object({ userId: z.string() }),
|
|
613
|
-
async (
|
|
613
|
+
export default defineTool({
|
|
614
|
+
description: 'Fetch user data',
|
|
615
|
+
args: z.object({ userId: z.string() }),
|
|
616
|
+
execute: async (state, args) => {
|
|
614
617
|
try {
|
|
615
618
|
const user = await fetchUser(args.userId);
|
|
616
619
|
return { status: 'success', result: JSON.stringify(user) };
|
|
@@ -620,8 +623,8 @@ export default defineTool(
|
|
|
620
623
|
error: \`Failed to fetch user: \${error.message}\`,
|
|
621
624
|
};
|
|
622
625
|
}
|
|
623
|
-
}
|
|
624
|
-
);
|
|
626
|
+
},
|
|
627
|
+
});
|
|
625
628
|
\`\`\`
|
|
626
629
|
|
|
627
630
|
## Queueing Additional Tools
|
|
@@ -631,21 +634,21 @@ Queue another tool to run after the current one:
|
|
|
631
634
|
\`\`\`typescript
|
|
632
635
|
import { queueTool } from '@standardagents/builder';
|
|
633
636
|
|
|
634
|
-
export default defineTool(
|
|
635
|
-
'Create order and send confirmation',
|
|
636
|
-
z.object({ items: z.array(z.string()) }),
|
|
637
|
-
async (
|
|
637
|
+
export default defineTool({
|
|
638
|
+
description: 'Create order and send confirmation',
|
|
639
|
+
args: z.object({ items: z.array(z.string()) }),
|
|
640
|
+
execute: async (state, args) => {
|
|
638
641
|
const order = await createOrder(args.items);
|
|
639
642
|
|
|
640
643
|
// Queue email tool to run next
|
|
641
|
-
queueTool(
|
|
644
|
+
queueTool(state, 'send_confirmation_email', {
|
|
642
645
|
orderId: order.id,
|
|
643
|
-
email:
|
|
646
|
+
email: state.thread.metadata.userEmail,
|
|
644
647
|
});
|
|
645
648
|
|
|
646
649
|
return { status: 'success', result: JSON.stringify(order) };
|
|
647
|
-
}
|
|
648
|
-
);
|
|
650
|
+
},
|
|
651
|
+
});
|
|
649
652
|
\`\`\`
|
|
650
653
|
|
|
651
654
|
## Injecting Messages
|
|
@@ -655,17 +658,61 @@ Add messages without triggering re-execution:
|
|
|
655
658
|
\`\`\`typescript
|
|
656
659
|
import { injectMessage } from '@standardagents/builder';
|
|
657
660
|
|
|
658
|
-
export default defineTool(
|
|
659
|
-
'Log audit event',
|
|
660
|
-
z.object({ event: z.string() }),
|
|
661
|
-
async (
|
|
662
|
-
await injectMessage(
|
|
661
|
+
export default defineTool({
|
|
662
|
+
description: 'Log audit event',
|
|
663
|
+
args: z.object({ event: z.string() }),
|
|
664
|
+
execute: async (state, args) => {
|
|
665
|
+
await injectMessage(state, {
|
|
663
666
|
role: 'system',
|
|
664
667
|
content: \`[AUDIT] \${args.event}\`,
|
|
665
668
|
});
|
|
666
669
|
return { status: 'success', result: 'Logged' };
|
|
667
|
-
}
|
|
668
|
-
);
|
|
670
|
+
},
|
|
671
|
+
});
|
|
672
|
+
\`\`\`
|
|
673
|
+
|
|
674
|
+
## Thread Environment Variables (tenvs)
|
|
675
|
+
|
|
676
|
+
Tools can declare required thread environment variables:
|
|
677
|
+
|
|
678
|
+
\`\`\`typescript
|
|
679
|
+
export default defineTool({
|
|
680
|
+
description: 'Search uploaded documents',
|
|
681
|
+
args: z.object({ query: z.string() }),
|
|
682
|
+
execute: async (state, args) => {
|
|
683
|
+
const vectorStoreId = state.tenvs.vectorStoreId;
|
|
684
|
+
const results = await searchVectorStore(vectorStoreId, args.query);
|
|
685
|
+
return { status: 'success', result: JSON.stringify(results) };
|
|
686
|
+
},
|
|
687
|
+
tenvs: z.object({
|
|
688
|
+
vectorStoreId: z.string().describe('OpenAI Vector Store ID'),
|
|
689
|
+
}),
|
|
690
|
+
});
|
|
691
|
+
\`\`\`
|
|
692
|
+
|
|
693
|
+
## Returning Attachments
|
|
694
|
+
|
|
695
|
+
Tools can return file attachments (e.g., generated images):
|
|
696
|
+
|
|
697
|
+
\`\`\`typescript
|
|
698
|
+
export default defineTool({
|
|
699
|
+
description: 'Generate a chart from data',
|
|
700
|
+
args: z.object({ data: z.array(z.number()) }),
|
|
701
|
+
execute: async (state, args) => {
|
|
702
|
+
const chartImage = await generateChart(args.data);
|
|
703
|
+
return {
|
|
704
|
+
status: 'success',
|
|
705
|
+
result: 'Chart generated successfully',
|
|
706
|
+
attachments: [{
|
|
707
|
+
name: 'chart.png',
|
|
708
|
+
mimeType: 'image/png',
|
|
709
|
+
data: chartImage.base64,
|
|
710
|
+
width: 800,
|
|
711
|
+
height: 600,
|
|
712
|
+
}],
|
|
713
|
+
};
|
|
714
|
+
},
|
|
715
|
+
});
|
|
669
716
|
\`\`\`
|
|
670
717
|
|
|
671
718
|
## Best Practices
|
|
@@ -675,7 +722,7 @@ export default defineTool(
|
|
|
675
722
|
- **Handle errors gracefully** - return error status, don't throw
|
|
676
723
|
- **Use snake_case** for file names (\`search_knowledge_base.ts\`)
|
|
677
724
|
- **Keep tools focused** - one task per tool
|
|
678
|
-
- **Use \`
|
|
725
|
+
- **Use \`state.rootState\`** when queueing from sub-prompts
|
|
679
726
|
|
|
680
727
|
## Supported Zod Types
|
|
681
728
|
|
|
@@ -1046,9 +1093,9 @@ function getProjectName(cwd) {
|
|
|
1046
1093
|
const packageJsonPath = path3.join(cwd, "package.json");
|
|
1047
1094
|
if (fs3.existsSync(packageJsonPath)) {
|
|
1048
1095
|
try {
|
|
1049
|
-
const
|
|
1050
|
-
if (
|
|
1051
|
-
return
|
|
1096
|
+
const pkg = JSON.parse(fs3.readFileSync(packageJsonPath, "utf-8"));
|
|
1097
|
+
if (pkg.name) {
|
|
1098
|
+
return pkg.name.replace(/^@[^/]+\//, "");
|
|
1052
1099
|
}
|
|
1053
1100
|
} catch {
|
|
1054
1101
|
}
|
|
@@ -1433,15 +1480,15 @@ async function prompt(question) {
|
|
|
1433
1480
|
input: process.stdin,
|
|
1434
1481
|
output: process.stdout
|
|
1435
1482
|
});
|
|
1436
|
-
return new Promise((
|
|
1483
|
+
return new Promise((resolve) => {
|
|
1437
1484
|
rl.question(question, (answer) => {
|
|
1438
1485
|
rl.close();
|
|
1439
|
-
|
|
1486
|
+
resolve(answer.trim());
|
|
1440
1487
|
});
|
|
1441
1488
|
});
|
|
1442
1489
|
}
|
|
1443
1490
|
async function promptPassword(question) {
|
|
1444
|
-
return new Promise((
|
|
1491
|
+
return new Promise((resolve) => {
|
|
1445
1492
|
const stdin = process.stdin;
|
|
1446
1493
|
const stdout = process.stdout;
|
|
1447
1494
|
stdout.write(question);
|
|
@@ -1462,7 +1509,7 @@ async function promptPassword(question) {
|
|
|
1462
1509
|
stdin.pause();
|
|
1463
1510
|
stdin.removeListener("data", onData);
|
|
1464
1511
|
stdout.write("\n");
|
|
1465
|
-
|
|
1512
|
+
resolve(password);
|
|
1466
1513
|
break;
|
|
1467
1514
|
case "":
|
|
1468
1515
|
stdout.write("\n");
|
|
@@ -1488,7 +1535,7 @@ async function promptPassword(question) {
|
|
|
1488
1535
|
});
|
|
1489
1536
|
}
|
|
1490
1537
|
function runCommand(command, args, cwd) {
|
|
1491
|
-
return new Promise((
|
|
1538
|
+
return new Promise((resolve, reject) => {
|
|
1492
1539
|
const child = spawn(command, args, {
|
|
1493
1540
|
cwd,
|
|
1494
1541
|
stdio: "inherit",
|
|
@@ -1496,7 +1543,7 @@ function runCommand(command, args, cwd) {
|
|
|
1496
1543
|
});
|
|
1497
1544
|
child.on("close", (code) => {
|
|
1498
1545
|
if (code === 0) {
|
|
1499
|
-
|
|
1546
|
+
resolve();
|
|
1500
1547
|
} else {
|
|
1501
1548
|
reject(new Error(`Command failed with exit code ${code}`));
|
|
1502
1549
|
}
|
|
@@ -1520,25 +1567,16 @@ function detectPackageManager() {
|
|
|
1520
1567
|
if (fs3.existsSync("package-lock.json")) return "npm";
|
|
1521
1568
|
return "npm";
|
|
1522
1569
|
}
|
|
1523
|
-
function
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
const pkgPath = path3.resolve(__dirname2, "../../package.json");
|
|
1527
|
-
const pkg2 = JSON.parse(fs3.readFileSync(pkgPath, "utf-8"));
|
|
1528
|
-
const version = pkg2.version;
|
|
1529
|
-
const prereleaseMatch = version.match(/-([a-z]+)\./i);
|
|
1530
|
-
if (prereleaseMatch) {
|
|
1531
|
-
return `@${prereleaseMatch[1]}`;
|
|
1532
|
-
}
|
|
1533
|
-
return `@^${version}`;
|
|
1534
|
-
} catch {
|
|
1535
|
-
return "";
|
|
1570
|
+
function getPackageVersion() {
|
|
1571
|
+
if (process.env.STANDARDAGENTS_WORKSPACE === "1") {
|
|
1572
|
+
return "workspace:*";
|
|
1536
1573
|
}
|
|
1574
|
+
return "0.11.0-next.7005954";
|
|
1537
1575
|
}
|
|
1538
1576
|
async function selectPackageManager(detected) {
|
|
1539
1577
|
const options = ["npm", "pnpm", "yarn", "bun"];
|
|
1540
1578
|
const detectedIndex = options.indexOf(detected);
|
|
1541
|
-
return new Promise((
|
|
1579
|
+
return new Promise((resolve) => {
|
|
1542
1580
|
const stdin = process.stdin;
|
|
1543
1581
|
const stdout = process.stdout;
|
|
1544
1582
|
let selectedIndex = detectedIndex;
|
|
@@ -1584,7 +1622,7 @@ async function selectPackageManager(detected) {
|
|
|
1584
1622
|
renderOptions();
|
|
1585
1623
|
} else if (key === "\r" || key === "\n") {
|
|
1586
1624
|
cleanup();
|
|
1587
|
-
|
|
1625
|
+
resolve(options[selectedIndex]);
|
|
1588
1626
|
} else if (key === "") {
|
|
1589
1627
|
cleanup();
|
|
1590
1628
|
stdout.write("\n");
|
|
@@ -1670,34 +1708,7 @@ export default defineConfig({
|
|
|
1670
1708
|
}
|
|
1671
1709
|
}
|
|
1672
1710
|
logger.log("");
|
|
1673
|
-
logger.info("Step 2:
|
|
1674
|
-
logger.log("");
|
|
1675
|
-
try {
|
|
1676
|
-
const installCmd = pm === "npm" ? "install" : "add";
|
|
1677
|
-
const devFlag = pm === "npm" ? "--save-dev" : "-D";
|
|
1678
|
-
const builderVersion = getBuilderPackageVersion();
|
|
1679
|
-
await runCommand(pm, [
|
|
1680
|
-
installCmd,
|
|
1681
|
-
devFlag,
|
|
1682
|
-
"@cloudflare/vite-plugin",
|
|
1683
|
-
"wrangler"
|
|
1684
|
-
], projectPath);
|
|
1685
|
-
await runCommand(pm, [
|
|
1686
|
-
installCmd,
|
|
1687
|
-
`@standardagents/builder${builderVersion}`,
|
|
1688
|
-
"zod"
|
|
1689
|
-
], projectPath);
|
|
1690
|
-
} catch (error) {
|
|
1691
|
-
logger.error("Failed to install dependencies");
|
|
1692
|
-
process.exit(1);
|
|
1693
|
-
}
|
|
1694
|
-
logger.log("");
|
|
1695
|
-
logger.info("Step 3: Configuring Standard Agents...");
|
|
1696
|
-
logger.log("");
|
|
1697
|
-
process.chdir(projectPath);
|
|
1698
|
-
await scaffold({ force: true });
|
|
1699
|
-
logger.log("");
|
|
1700
|
-
logger.info("Step 4: Configuring environment variables...");
|
|
1711
|
+
logger.info("Step 2: Configuring environment variables...");
|
|
1701
1712
|
logger.log("");
|
|
1702
1713
|
const encryptionKey = crypto.randomBytes(32).toString("hex");
|
|
1703
1714
|
let openrouterKey = "";
|
|
@@ -1732,6 +1743,44 @@ export default defineConfig({
|
|
|
1732
1743
|
if (!adminPassword) {
|
|
1733
1744
|
adminPassword = "admin";
|
|
1734
1745
|
}
|
|
1746
|
+
logger.log("");
|
|
1747
|
+
logger.info("Step 3: Installing Standard Agents dependencies...");
|
|
1748
|
+
logger.log("");
|
|
1749
|
+
try {
|
|
1750
|
+
const installCmd = pm === "npm" ? "install" : "add";
|
|
1751
|
+
const devFlag = pm === "npm" ? "--save-dev" : "-D";
|
|
1752
|
+
const packageVersion = getPackageVersion();
|
|
1753
|
+
await runCommand(pm, [
|
|
1754
|
+
installCmd,
|
|
1755
|
+
devFlag,
|
|
1756
|
+
"@cloudflare/vite-plugin",
|
|
1757
|
+
"wrangler"
|
|
1758
|
+
], projectPath);
|
|
1759
|
+
const deps = [
|
|
1760
|
+
`@standardagents/builder@${packageVersion}`,
|
|
1761
|
+
`@standardagents/spec@${packageVersion}`,
|
|
1762
|
+
`@standardagents/sip@${packageVersion}`,
|
|
1763
|
+
"zod"
|
|
1764
|
+
];
|
|
1765
|
+
if (openaiKey) {
|
|
1766
|
+
deps.push(`@standardagents/openai@${packageVersion}`);
|
|
1767
|
+
}
|
|
1768
|
+
if (openrouterKey) {
|
|
1769
|
+
deps.push(`@standardagents/openrouter@${packageVersion}`);
|
|
1770
|
+
}
|
|
1771
|
+
await runCommand(pm, [installCmd, ...deps], projectPath);
|
|
1772
|
+
} catch (error) {
|
|
1773
|
+
logger.error("Failed to install dependencies");
|
|
1774
|
+
process.exit(1);
|
|
1775
|
+
}
|
|
1776
|
+
logger.log("");
|
|
1777
|
+
logger.info("Step 4: Configuring Standard Agents...");
|
|
1778
|
+
logger.log("");
|
|
1779
|
+
process.chdir(projectPath);
|
|
1780
|
+
await scaffold({ force: true });
|
|
1781
|
+
logger.log("");
|
|
1782
|
+
logger.info("Writing environment configuration...");
|
|
1783
|
+
logger.log("");
|
|
1735
1784
|
const devVarsLines = [
|
|
1736
1785
|
"# Standard Agents Environment Variables",
|
|
1737
1786
|
"# This file contains secrets for local development only",
|
|
@@ -1788,10 +1837,10 @@ export default defineConfig({
|
|
|
1788
1837
|
}
|
|
1789
1838
|
function getReactPackageVersion() {
|
|
1790
1839
|
try {
|
|
1791
|
-
const
|
|
1792
|
-
const pkgPath = path3.resolve(
|
|
1793
|
-
const
|
|
1794
|
-
const version =
|
|
1840
|
+
const __dirname = path3.dirname(fileURLToPath(import.meta.url));
|
|
1841
|
+
const pkgPath = path3.resolve(__dirname, "../package.json");
|
|
1842
|
+
const pkg = JSON.parse(fs3.readFileSync(pkgPath, "utf-8"));
|
|
1843
|
+
const version = pkg.version;
|
|
1795
1844
|
const prereleaseMatch = version.match(/-([a-z]+)\./i);
|
|
1796
1845
|
if (prereleaseMatch) {
|
|
1797
1846
|
return prereleaseMatch[1];
|
|
@@ -1802,23 +1851,23 @@ function getReactPackageVersion() {
|
|
|
1802
1851
|
}
|
|
1803
1852
|
}
|
|
1804
1853
|
function getChatSourceDir() {
|
|
1805
|
-
const
|
|
1806
|
-
return path3.resolve(
|
|
1854
|
+
const __dirname = path3.dirname(fileURLToPath(import.meta.url));
|
|
1855
|
+
return path3.resolve(__dirname, "../chat");
|
|
1807
1856
|
}
|
|
1808
1857
|
async function prompt2(question) {
|
|
1809
1858
|
const rl = readline.createInterface({
|
|
1810
1859
|
input: process.stdin,
|
|
1811
1860
|
output: process.stdout
|
|
1812
1861
|
});
|
|
1813
|
-
return new Promise((
|
|
1862
|
+
return new Promise((resolve) => {
|
|
1814
1863
|
rl.question(question, (answer) => {
|
|
1815
1864
|
rl.close();
|
|
1816
|
-
|
|
1865
|
+
resolve(answer.trim());
|
|
1817
1866
|
});
|
|
1818
1867
|
});
|
|
1819
1868
|
}
|
|
1820
1869
|
function runCommand2(command, args, cwd) {
|
|
1821
|
-
return new Promise((
|
|
1870
|
+
return new Promise((resolve, reject) => {
|
|
1822
1871
|
const child = spawn(command, args, {
|
|
1823
1872
|
cwd,
|
|
1824
1873
|
stdio: "inherit",
|
|
@@ -1826,7 +1875,7 @@ function runCommand2(command, args, cwd) {
|
|
|
1826
1875
|
});
|
|
1827
1876
|
child.on("close", (code) => {
|
|
1828
1877
|
if (code === 0) {
|
|
1829
|
-
|
|
1878
|
+
resolve();
|
|
1830
1879
|
} else {
|
|
1831
1880
|
reject(new Error(`Command failed with exit code ${code}`));
|
|
1832
1881
|
}
|
|
@@ -1850,7 +1899,7 @@ function detectPackageManager2() {
|
|
|
1850
1899
|
async function selectPackageManager2(detected) {
|
|
1851
1900
|
const options = ["npm", "pnpm", "yarn", "bun"];
|
|
1852
1901
|
const detectedIndex = options.indexOf(detected);
|
|
1853
|
-
return new Promise((
|
|
1902
|
+
return new Promise((resolve) => {
|
|
1854
1903
|
const stdin = process.stdin;
|
|
1855
1904
|
const stdout = process.stdout;
|
|
1856
1905
|
let selectedIndex = detectedIndex;
|
|
@@ -1896,7 +1945,7 @@ async function selectPackageManager2(detected) {
|
|
|
1896
1945
|
renderOptions();
|
|
1897
1946
|
} else if (key === "\r" || key === "\n") {
|
|
1898
1947
|
cleanup();
|
|
1899
|
-
|
|
1948
|
+
resolve(options[selectedIndex]);
|
|
1900
1949
|
} else if (key === "") {
|
|
1901
1950
|
cleanup();
|
|
1902
1951
|
stdout.write("\n");
|
|
@@ -1911,7 +1960,7 @@ async function selectFramework() {
|
|
|
1911
1960
|
{ value: "vite", label: "Vite (React + TypeScript)" },
|
|
1912
1961
|
{ value: "nextjs", label: "Next.js (App Router)" }
|
|
1913
1962
|
];
|
|
1914
|
-
return new Promise((
|
|
1963
|
+
return new Promise((resolve) => {
|
|
1915
1964
|
const stdin = process.stdin;
|
|
1916
1965
|
const stdout = process.stdout;
|
|
1917
1966
|
let selectedIndex = 0;
|
|
@@ -1955,7 +2004,7 @@ async function selectFramework() {
|
|
|
1955
2004
|
renderOptions();
|
|
1956
2005
|
} else if (key === "\r" || key === "\n") {
|
|
1957
2006
|
cleanup();
|
|
1958
|
-
|
|
2007
|
+
resolve(options[selectedIndex].value);
|
|
1959
2008
|
} else if (key === "") {
|
|
1960
2009
|
cleanup();
|
|
1961
2010
|
stdout.write("\n");
|
|
@@ -1975,20 +2024,20 @@ function isValidUrl(url) {
|
|
|
1975
2024
|
}
|
|
1976
2025
|
async function isPortOpen(port) {
|
|
1977
2026
|
const tryConnect = (host) => {
|
|
1978
|
-
return new Promise((
|
|
2027
|
+
return new Promise((resolve) => {
|
|
1979
2028
|
const socket = new net.Socket();
|
|
1980
2029
|
socket.setTimeout(200);
|
|
1981
2030
|
socket.on("connect", () => {
|
|
1982
2031
|
socket.destroy();
|
|
1983
|
-
|
|
2032
|
+
resolve(true);
|
|
1984
2033
|
});
|
|
1985
2034
|
socket.on("timeout", () => {
|
|
1986
2035
|
socket.destroy();
|
|
1987
|
-
|
|
2036
|
+
resolve(false);
|
|
1988
2037
|
});
|
|
1989
2038
|
socket.on("error", () => {
|
|
1990
2039
|
socket.destroy();
|
|
1991
|
-
|
|
2040
|
+
resolve(false);
|
|
1992
2041
|
});
|
|
1993
2042
|
socket.connect(port, host);
|
|
1994
2043
|
});
|
|
@@ -2212,21 +2261,21 @@ export default defineConfig({
|
|
|
2212
2261
|
fs3.writeFileSync(path3.join(projectPath, "tsconfig.json"), JSON.stringify(tsconfig, null, 2) + "\n", "utf-8");
|
|
2213
2262
|
logger.success("Created tsconfig.json");
|
|
2214
2263
|
fs3.copyFileSync(path3.join(chatSourceDir, "package.json"), path3.join(projectPath, "package.json"));
|
|
2215
|
-
const
|
|
2216
|
-
|
|
2217
|
-
|
|
2264
|
+
const pkg = JSON.parse(fs3.readFileSync(path3.join(projectPath, "package.json"), "utf-8"));
|
|
2265
|
+
pkg.name = projectName;
|
|
2266
|
+
pkg.scripts = {
|
|
2218
2267
|
dev: "vite",
|
|
2219
2268
|
build: "vite build",
|
|
2220
2269
|
preview: "vite preview"
|
|
2221
2270
|
};
|
|
2222
|
-
delete
|
|
2223
|
-
if (
|
|
2224
|
-
|
|
2225
|
-
}
|
|
2226
|
-
delete
|
|
2227
|
-
delete
|
|
2228
|
-
delete
|
|
2229
|
-
fs3.writeFileSync(path3.join(projectPath, "package.json"), JSON.stringify(
|
|
2271
|
+
delete pkg.private;
|
|
2272
|
+
if (pkg.dependencies?.["@standardagents/react"]) {
|
|
2273
|
+
pkg.dependencies["@standardagents/react"] = reactVersion;
|
|
2274
|
+
}
|
|
2275
|
+
delete pkg.dependencies?.["next"];
|
|
2276
|
+
delete pkg.devDependencies?.["@tailwindcss/postcss"];
|
|
2277
|
+
delete pkg.devDependencies?.["postcss"];
|
|
2278
|
+
fs3.writeFileSync(path3.join(projectPath, "package.json"), JSON.stringify(pkg, null, 2) + "\n", "utf-8");
|
|
2230
2279
|
logger.success("Created package.json");
|
|
2231
2280
|
const envContent = `# Agentbuilder connection
|
|
2232
2281
|
VITE_AGENTBUILDER_URL=${serverUrl}
|
|
@@ -2281,21 +2330,21 @@ async function scaffoldNextjs(projectPath, chatSourceDir, projectName, serverUrl
|
|
|
2281
2330
|
};
|
|
2282
2331
|
fs3.writeFileSync(path3.join(projectPath, "tsconfig.json"), JSON.stringify(tsconfig, null, 2) + "\n", "utf-8");
|
|
2283
2332
|
logger.success("Created tsconfig.json");
|
|
2284
|
-
const
|
|
2285
|
-
|
|
2286
|
-
|
|
2333
|
+
const pkg = JSON.parse(fs3.readFileSync(path3.join(chatSourceDir, "package.json"), "utf-8"));
|
|
2334
|
+
pkg.name = projectName;
|
|
2335
|
+
pkg.scripts = {
|
|
2287
2336
|
dev: "next dev",
|
|
2288
2337
|
build: "next build",
|
|
2289
2338
|
start: "next start"
|
|
2290
2339
|
};
|
|
2291
|
-
delete
|
|
2292
|
-
if (
|
|
2293
|
-
|
|
2294
|
-
}
|
|
2295
|
-
delete
|
|
2296
|
-
delete
|
|
2297
|
-
delete
|
|
2298
|
-
fs3.writeFileSync(path3.join(projectPath, "package.json"), JSON.stringify(
|
|
2340
|
+
delete pkg.private;
|
|
2341
|
+
if (pkg.dependencies?.["@standardagents/react"]) {
|
|
2342
|
+
pkg.dependencies["@standardagents/react"] = reactVersion;
|
|
2343
|
+
}
|
|
2344
|
+
delete pkg.devDependencies?.["@tailwindcss/vite"];
|
|
2345
|
+
delete pkg.devDependencies?.["@vitejs/plugin-react"];
|
|
2346
|
+
delete pkg.devDependencies?.["vite"];
|
|
2347
|
+
fs3.writeFileSync(path3.join(projectPath, "package.json"), JSON.stringify(pkg, null, 2) + "\n", "utf-8");
|
|
2299
2348
|
logger.success("Created package.json");
|
|
2300
2349
|
const envContent = `# Agentbuilder connection
|
|
2301
2350
|
NEXT_PUBLIC_AGENTBUILDER_URL=${serverUrl}
|
|
@@ -2317,10 +2366,8 @@ out
|
|
|
2317
2366
|
}
|
|
2318
2367
|
|
|
2319
2368
|
// src/index.ts
|
|
2320
|
-
var __dirname$1 = dirname(fileURLToPath(import.meta.url));
|
|
2321
|
-
var pkg = JSON.parse(readFileSync(resolve(__dirname$1, "../package.json"), "utf-8"));
|
|
2322
2369
|
var program = new Command();
|
|
2323
|
-
program.name("agents").description("CLI tool for Standard Agents / AgentBuilder").version(
|
|
2370
|
+
program.name("agents").description("CLI tool for Standard Agents / AgentBuilder").version("0.11.0-next.7005954");
|
|
2324
2371
|
program.command("init [project-name]").description("Create a new Standard Agents project (runs create vite, then scaffold)").option("-y, --yes", "Skip prompts and use defaults").option("--template <template>", "Vite template to use", "vanilla-ts").action(init);
|
|
2325
2372
|
program.command("scaffold").description("Add Standard Agents to an existing Vite project").option("--force", "Overwrite existing configuration").action(scaffold);
|
|
2326
2373
|
program.command("init-chat [project-name]").description("Scaffold a frontend chat application").option("-y, --yes", "Skip prompts and use defaults").option("--framework <framework>", "Framework to use (vite or nextjs)").action(initChat);
|