@ddlqhd/agent-sdk 0.1.1 → 0.2.1
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/README.md +2 -1
- package/dist/{chunk-742JTNYI.js → chunk-D3UZNLZO.js} +570 -77
- package/dist/chunk-D3UZNLZO.js.map +1 -0
- package/dist/{chunk-AJD3DTL7.cjs → chunk-JXAJQGV5.cjs} +756 -107
- package/dist/chunk-JXAJQGV5.cjs.map +1 -0
- package/dist/{chunk-DQFTAD3I.cjs → chunk-NYZD3THB.cjs} +573 -76
- package/dist/chunk-NYZD3THB.cjs.map +1 -0
- package/dist/{chunk-Q3L4GIBG.cjs → chunk-P2X3AMDK.cjs} +115 -117
- package/dist/chunk-P2X3AMDK.cjs.map +1 -0
- package/dist/{chunk-THKEF32L.js → chunk-TKUPLTGJ.js} +110 -114
- package/dist/chunk-TKUPLTGJ.js.map +1 -0
- package/dist/{chunk-DXMVWGLJ.js → chunk-UHENMHUS.js} +744 -100
- package/dist/chunk-UHENMHUS.js.map +1 -0
- package/dist/cli/index.cjs +40 -31
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +14 -5
- package/dist/cli/index.js.map +1 -1
- package/dist/{index-DGPDMbW5.d.cts → index-CnrY1ZA2.d.ts} +36 -14
- package/dist/{index-nEfayAzD.d.ts → index-DzBt4ewK.d.cts} +36 -14
- package/dist/index.cjs +128 -88
- package/dist/index.d.cts +42 -22
- package/dist/index.d.ts +42 -22
- package/dist/index.js +3 -3
- package/dist/models/index.cjs +14 -10
- package/dist/models/index.d.cts +7 -2
- package/dist/models/index.d.ts +7 -2
- package/dist/models/index.js +1 -1
- package/dist/tools/index.cjs +65 -57
- package/dist/tools/index.d.cts +3 -3
- package/dist/tools/index.d.ts +3 -3
- package/dist/tools/index.js +1 -1
- package/dist/{types-BLf9IqRs.d.cts → types-BUwjMwNH.d.cts} +279 -13
- package/dist/{types-BLf9IqRs.d.ts → types-BUwjMwNH.d.ts} +279 -13
- package/package.json +11 -11
- package/dist/chunk-742JTNYI.js.map +0 -1
- package/dist/chunk-AJD3DTL7.cjs.map +0 -1
- package/dist/chunk-DQFTAD3I.cjs.map +0 -1
- package/dist/chunk-DXMVWGLJ.js.map +0 -1
- package/dist/chunk-Q3L4GIBG.cjs.map +0 -1
- package/dist/chunk-THKEF32L.js.map +0 -1
package/dist/cli/index.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
var
|
|
5
|
-
require('../chunk-
|
|
6
|
-
var
|
|
4
|
+
var chunkJXAJQGV5_cjs = require('../chunk-JXAJQGV5.cjs');
|
|
5
|
+
require('../chunk-NYZD3THB.cjs');
|
|
6
|
+
var chunkP2X3AMDK_cjs = require('../chunk-P2X3AMDK.cjs');
|
|
7
7
|
require('../chunk-OZO7D77N.cjs');
|
|
8
8
|
var commander = require('commander');
|
|
9
9
|
var chalk = require('chalk');
|
|
@@ -13,6 +13,7 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
13
13
|
|
|
14
14
|
var chalk__default = /*#__PURE__*/_interopDefault(chalk);
|
|
15
15
|
|
|
16
|
+
var STREAM_END_MAX_ITERATIONS_MESSAGE = "\n[stopped: reached maxIterations \u2014 increase AgentConfig.maxIterations if the task needs more tool rounds]";
|
|
16
17
|
function tokenUsageEqual(a, b) {
|
|
17
18
|
return a.promptTokens === b.promptTokens && a.completionTokens === b.completionTokens && a.totalTokens === b.totalTokens;
|
|
18
19
|
}
|
|
@@ -39,21 +40,26 @@ function createStreamFormatter(config = {}) {
|
|
|
39
40
|
return {
|
|
40
41
|
format(event) {
|
|
41
42
|
let output = "";
|
|
42
|
-
if (lastEventType === "thinking" && event.type !== "thinking") {
|
|
43
|
+
if (lastEventType === "thinking" && event.type !== "thinking" && event.type !== "thinking_end") {
|
|
43
44
|
output += "\n";
|
|
44
45
|
isFirstThinking = true;
|
|
45
46
|
}
|
|
46
|
-
if (needsGapAfterToolBlock && (event.type === "text_delta" || event.type === "thinking")) {
|
|
47
|
+
if (needsGapAfterToolBlock && (event.type === "text_delta" || event.type === "thinking" || event.type === "thinking_start")) {
|
|
47
48
|
output += "\n";
|
|
48
49
|
needsGapAfterToolBlock = false;
|
|
49
50
|
}
|
|
50
51
|
switch (event.type) {
|
|
51
52
|
case "text_start":
|
|
52
53
|
case "text_end":
|
|
54
|
+
case "thinking_start":
|
|
53
55
|
case "tool_call_start":
|
|
54
56
|
case "tool_call_delta":
|
|
55
57
|
case "tool_call_end":
|
|
56
58
|
break;
|
|
59
|
+
case "thinking_end":
|
|
60
|
+
output += "\n";
|
|
61
|
+
isFirstThinking = true;
|
|
62
|
+
break;
|
|
57
63
|
case "context_compressed":
|
|
58
64
|
if (verbose) {
|
|
59
65
|
output += chalk__default.default.gray(
|
|
@@ -127,6 +133,8 @@ ${formatUsage(usage)}`;
|
|
|
127
133
|
\u2717 ${event.error.message}`);
|
|
128
134
|
} else if (event.reason === "aborted") {
|
|
129
135
|
output += chalk__default.default.yellow("\n[interrupted]");
|
|
136
|
+
} else if (event.reason === "max_iterations") {
|
|
137
|
+
output += chalk__default.default.yellow(STREAM_END_MAX_ITERATIONS_MESSAGE);
|
|
130
138
|
}
|
|
131
139
|
break;
|
|
132
140
|
}
|
|
@@ -413,12 +421,12 @@ function createChatCommand() {
|
|
|
413
421
|
try {
|
|
414
422
|
let sessionId = options.session;
|
|
415
423
|
if (options.resume && !sessionId) {
|
|
416
|
-
sessionId = await
|
|
424
|
+
sessionId = await chunkJXAJQGV5_cjs.getLatestSessionId(options.userBasePath);
|
|
417
425
|
if (!sessionId) {
|
|
418
426
|
console.warn(chalk__default.default.yellow("No saved sessions found; starting a new session."));
|
|
419
427
|
}
|
|
420
428
|
}
|
|
421
|
-
const mcpResult =
|
|
429
|
+
const mcpResult = chunkJXAJQGV5_cjs.loadMCPConfig(options.mcpConfig, options.cwd || process.cwd(), options.userBasePath);
|
|
422
430
|
if (mcpResult.configPath) {
|
|
423
431
|
console.log(chalk__default.default.gray(`Loaded MCP config from: ${mcpResult.configPath}`));
|
|
424
432
|
if (mcpResult.servers.length > 0) {
|
|
@@ -426,7 +434,7 @@ function createChatCommand() {
|
|
|
426
434
|
}
|
|
427
435
|
}
|
|
428
436
|
const cwd = options.cwd || process.cwd();
|
|
429
|
-
const agent = new
|
|
437
|
+
const agent = new chunkJXAJQGV5_cjs.Agent({
|
|
430
438
|
modelConfig: modelConfigFromOptions(options),
|
|
431
439
|
cwd,
|
|
432
440
|
hookConfigDir: cwd,
|
|
@@ -443,7 +451,7 @@ function createChatCommand() {
|
|
|
443
451
|
const skills = skillRegistry.getUserInvocableSkills();
|
|
444
452
|
console.log(chalk__default.default.cyan("\u{1F916} Agent SDK Chat"));
|
|
445
453
|
console.log(chalk__default.default.gray(`Model: ${model.name}`));
|
|
446
|
-
console.log(chalk__default.default.gray(`Sessions: ${
|
|
454
|
+
console.log(chalk__default.default.gray(`Sessions: ${chunkJXAJQGV5_cjs.getSessionStoragePath(options.userBasePath)}`));
|
|
447
455
|
if (skills.length > 0) {
|
|
448
456
|
console.log(chalk__default.default.gray(`Skills: ${skills.map((s) => `/${s.name}`).join(", ")}`));
|
|
449
457
|
}
|
|
@@ -584,17 +592,17 @@ function createRunCommand() {
|
|
|
584
592
|
try {
|
|
585
593
|
let sessionId = options.session;
|
|
586
594
|
if (options.resume && !sessionId) {
|
|
587
|
-
sessionId = await
|
|
595
|
+
sessionId = await chunkJXAJQGV5_cjs.getLatestSessionId(options.userBasePath);
|
|
588
596
|
if (!sessionId) {
|
|
589
597
|
console.warn(chalk__default.default.yellow("No saved sessions found; starting a new session."));
|
|
590
598
|
}
|
|
591
599
|
}
|
|
592
|
-
const mcpResult =
|
|
600
|
+
const mcpResult = chunkJXAJQGV5_cjs.loadMCPConfig(options.mcpConfig, options.cwd || process.cwd(), options.userBasePath);
|
|
593
601
|
if (mcpResult.configPath) {
|
|
594
602
|
console.log(chalk__default.default.gray(`Loaded MCP config from: ${mcpResult.configPath}`));
|
|
595
603
|
}
|
|
596
604
|
const cwd = options.cwd || process.cwd();
|
|
597
|
-
const agent = new
|
|
605
|
+
const agent = new chunkJXAJQGV5_cjs.Agent({
|
|
598
606
|
modelConfig: modelConfigFromOptions(options),
|
|
599
607
|
cwd,
|
|
600
608
|
hookConfigDir: cwd,
|
|
@@ -638,9 +646,9 @@ ${formatUsage(result.usage)}`);
|
|
|
638
646
|
function createToolsCommand() {
|
|
639
647
|
const command = new commander.Command("tools").description("Manage agent tools");
|
|
640
648
|
command.command("list").description("List all available tools").option("-f, --format <format>", "Output format (table/json)", "table").option("-c, --category <category>", "Filter by category").action((options) => {
|
|
641
|
-
const registry = new
|
|
642
|
-
const skillRegistry =
|
|
643
|
-
registry.registerMany(
|
|
649
|
+
const registry = new chunkP2X3AMDK_cjs.ToolRegistry();
|
|
650
|
+
const skillRegistry = chunkJXAJQGV5_cjs.createSkillRegistry();
|
|
651
|
+
registry.registerMany(chunkP2X3AMDK_cjs.getAllBuiltinTools(skillRegistry));
|
|
644
652
|
let tools = registry.getAll();
|
|
645
653
|
if (options.category) {
|
|
646
654
|
tools = tools.filter(
|
|
@@ -675,9 +683,9 @@ Total: ${tools.length} tools`));
|
|
|
675
683
|
}
|
|
676
684
|
});
|
|
677
685
|
command.command("show <name>").description("Show tool details").action((name) => {
|
|
678
|
-
const registry = new
|
|
679
|
-
const skillRegistry =
|
|
680
|
-
registry.registerMany(
|
|
686
|
+
const registry = new chunkP2X3AMDK_cjs.ToolRegistry();
|
|
687
|
+
const skillRegistry = chunkJXAJQGV5_cjs.createSkillRegistry();
|
|
688
|
+
registry.registerMany(chunkP2X3AMDK_cjs.getAllBuiltinTools(skillRegistry));
|
|
681
689
|
const tool = registry.get(name);
|
|
682
690
|
if (!tool) {
|
|
683
691
|
console.error(chalk__default.default.red(`Tool "${name}" not found`));
|
|
@@ -696,9 +704,9 @@ Parameters Schema:`);
|
|
|
696
704
|
command.command("test <name>").description(
|
|
697
705
|
"Test a tool with arguments. Note: AskUserQuestion returns formatted text only unless the Agent is configured with askUserQuestion (e.g. CLI TTY)."
|
|
698
706
|
).option("-a, --args <json>", "Tool arguments as JSON").action(async (name, options) => {
|
|
699
|
-
const registry = new
|
|
700
|
-
const skillRegistry =
|
|
701
|
-
registry.registerMany(
|
|
707
|
+
const registry = new chunkP2X3AMDK_cjs.ToolRegistry();
|
|
708
|
+
const skillRegistry = chunkJXAJQGV5_cjs.createSkillRegistry();
|
|
709
|
+
registry.registerMany(chunkP2X3AMDK_cjs.getAllBuiltinTools(skillRegistry));
|
|
702
710
|
if (!registry.has(name)) {
|
|
703
711
|
console.error(chalk__default.default.red(`Tool "${name}" not found`));
|
|
704
712
|
process.exit(1);
|
|
@@ -736,9 +744,9 @@ function createSessionsCommand() {
|
|
|
736
744
|
addUserBasePathOption(
|
|
737
745
|
command.command("list").description("List all sessions").option("-l, --limit <n>", "Limit number of sessions", parseInt, 20).option("-f, --format <format>", "Output format (table/json)", "table")
|
|
738
746
|
).action(async (options) => {
|
|
739
|
-
const manager = new
|
|
747
|
+
const manager = new chunkJXAJQGV5_cjs.SessionManager({
|
|
740
748
|
type: "jsonl",
|
|
741
|
-
basePath:
|
|
749
|
+
basePath: chunkJXAJQGV5_cjs.getSessionStoragePath(options.userBasePath)
|
|
742
750
|
});
|
|
743
751
|
const sessions = await manager.listSessions();
|
|
744
752
|
const limited = sessions.slice(0, options.limit);
|
|
@@ -771,9 +779,9 @@ Total: ${sessions.length} sessions`));
|
|
|
771
779
|
addUserBasePathOption(
|
|
772
780
|
command.command("show <id>").description("Show session messages").option("-l, --limit <n>", "Limit number of messages", parseInt, 50)
|
|
773
781
|
).action(async (id, options) => {
|
|
774
|
-
const manager = new
|
|
782
|
+
const manager = new chunkJXAJQGV5_cjs.SessionManager({
|
|
775
783
|
type: "jsonl",
|
|
776
|
-
basePath:
|
|
784
|
+
basePath: chunkJXAJQGV5_cjs.getSessionStoragePath(options.userBasePath)
|
|
777
785
|
});
|
|
778
786
|
const exists = await manager.sessionExists(id);
|
|
779
787
|
if (!exists) {
|
|
@@ -796,9 +804,9 @@ Total: ${sessions.length} sessions`));
|
|
|
796
804
|
addUserBasePathOption(
|
|
797
805
|
command.command("delete <id>").description("Delete a session").option("-f, --force", "Skip confirmation")
|
|
798
806
|
).action(async (id, options) => {
|
|
799
|
-
const manager = new
|
|
807
|
+
const manager = new chunkJXAJQGV5_cjs.SessionManager({
|
|
800
808
|
type: "jsonl",
|
|
801
|
-
basePath:
|
|
809
|
+
basePath: chunkJXAJQGV5_cjs.getSessionStoragePath(options.userBasePath)
|
|
802
810
|
});
|
|
803
811
|
const exists = await manager.sessionExists(id);
|
|
804
812
|
if (!exists) {
|
|
@@ -826,9 +834,9 @@ Total: ${sessions.length} sessions`));
|
|
|
826
834
|
addUserBasePathOption(
|
|
827
835
|
command.command("clear").description("Delete all sessions").option("-f, --force", "Skip confirmation")
|
|
828
836
|
).action(async (options) => {
|
|
829
|
-
const manager = new
|
|
837
|
+
const manager = new chunkJXAJQGV5_cjs.SessionManager({
|
|
830
838
|
type: "jsonl",
|
|
831
|
-
basePath:
|
|
839
|
+
basePath: chunkJXAJQGV5_cjs.getSessionStoragePath(options.userBasePath)
|
|
832
840
|
});
|
|
833
841
|
const sessions = await manager.listSessions();
|
|
834
842
|
if (sessions.length === 0) {
|
|
@@ -862,7 +870,7 @@ function createMCPCommand() {
|
|
|
862
870
|
const command = new commander.Command("mcp").description("Manage MCP servers");
|
|
863
871
|
command.command("connect <command>").description("Connect to an MCP server and list available tools").option("-n, --name <name>", "Server name", "default").option("-a, --args <args>", "Command arguments (comma-separated)").option("-e, --env <env>", "Environment variables (KEY=VALUE,comma-separated)").action(async (cmd, options) => {
|
|
864
872
|
try {
|
|
865
|
-
const adapter = new
|
|
873
|
+
const adapter = new chunkJXAJQGV5_cjs.MCPAdapter();
|
|
866
874
|
const args = options.args ? options.args.split(",") : [];
|
|
867
875
|
const env = {};
|
|
868
876
|
if (options.env) {
|
|
@@ -878,6 +886,7 @@ function createMCPCommand() {
|
|
|
878
886
|
`));
|
|
879
887
|
const config = {
|
|
880
888
|
name: options.name,
|
|
889
|
+
transport: "stdio",
|
|
881
890
|
command: cmd,
|
|
882
891
|
args,
|
|
883
892
|
env: Object.keys(env).length > 0 ? env : void 0
|
|
@@ -907,7 +916,7 @@ function createMCPCommand() {
|
|
|
907
916
|
var isMainModule = process.argv[1]?.endsWith("cli/index.js") || process.argv[1]?.endsWith("cli\\index.js") || process.argv[1]?.includes("agent-sdk");
|
|
908
917
|
if (isMainModule) {
|
|
909
918
|
const program = new commander.Command();
|
|
910
|
-
program.name("agent-sdk").description("A TypeScript Agent SDK with multi-model support, MCP integration, and streaming").version(
|
|
919
|
+
program.name("agent-sdk").description("A TypeScript Agent SDK with multi-model support, MCP integration, and streaming").version(chunkJXAJQGV5_cjs.PACKAGE_VERSION);
|
|
911
920
|
program.addCommand(createChatCommand());
|
|
912
921
|
program.addCommand(createRunCommand());
|
|
913
922
|
program.addCommand(createToolsCommand());
|