@ddlqhd/agent-sdk 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/dist/{chunk-5QMA2YBY.cjs → chunk-6X7EYQLS.cjs} +782 -114
- package/dist/chunk-6X7EYQLS.cjs.map +1 -0
- package/dist/{chunk-NDSL7NPN.js → chunk-D3UZNLZO.js} +769 -71
- package/dist/chunk-D3UZNLZO.js.map +1 -0
- package/dist/{chunk-Q3SOMX26.js → chunk-EQ5CXH44.js} +772 -111
- package/dist/chunk-EQ5CXH44.js.map +1 -0
- package/dist/chunk-LOYIGOBZ.js +54 -0
- package/dist/chunk-LOYIGOBZ.js.map +1 -0
- package/dist/{chunk-OHXW2YM6.js → chunk-MEJHTQJM.js} +289 -166
- package/dist/chunk-MEJHTQJM.js.map +1 -0
- package/dist/chunk-NYZD3THB.cjs +1521 -0
- package/dist/chunk-NYZD3THB.cjs.map +1 -0
- package/dist/chunk-OZO7D77N.cjs +59 -0
- package/dist/chunk-OZO7D77N.cjs.map +1 -0
- package/dist/{chunk-JF5AJQMU.cjs → chunk-Z45DHTDX.cjs} +291 -170
- package/dist/chunk-Z45DHTDX.cjs.map +1 -0
- package/dist/cli/index.cjs +47 -39
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +22 -14
- package/dist/cli/index.js.map +1 -1
- package/dist/{index-DPsZ1zat.d.ts → index-Cw3SfEAB.d.ts} +20 -34
- package/dist/{index-RTPmFjMp.d.cts → index-D2Qntkn_.d.cts} +20 -34
- package/dist/index.cjs +125 -89
- package/dist/index.d.cts +62 -22
- package/dist/index.d.ts +62 -22
- package/dist/index.js +4 -4
- package/dist/models/index.cjs +19 -15
- package/dist/models/index.d.cts +55 -6
- package/dist/models/index.d.ts +55 -6
- package/dist/models/index.js +2 -2
- package/dist/tools/index.cjs +53 -61
- package/dist/tools/index.d.cts +3 -3
- package/dist/tools/index.d.ts +3 -3
- package/dist/tools/index.js +2 -2
- package/dist/{types-C0aX_Qdp.d.cts → types-CWPAYWzr.d.cts} +307 -61
- package/dist/{types-C0aX_Qdp.d.ts → types-CWPAYWzr.d.ts} +307 -61
- package/package.json +25 -14
- package/dist/chunk-5QMA2YBY.cjs.map +0 -1
- package/dist/chunk-CNSGZVRN.cjs +0 -152
- package/dist/chunk-CNSGZVRN.cjs.map +0 -1
- package/dist/chunk-JF5AJQMU.cjs.map +0 -1
- package/dist/chunk-NDSL7NPN.js.map +0 -1
- package/dist/chunk-OHXW2YM6.js.map +0 -1
- package/dist/chunk-Q3SOMX26.js.map +0 -1
- package/dist/chunk-WH3APNQ5.js +0 -147
- package/dist/chunk-WH3APNQ5.js.map +0 -1
- package/dist/chunk-X35MHWXE.cjs +0 -817
- package/dist/chunk-X35MHWXE.cjs.map +0 -1
package/dist/cli/index.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
require('../chunk-
|
|
4
|
+
var chunk6X7EYQLS_cjs = require('../chunk-6X7EYQLS.cjs');
|
|
5
|
+
require('../chunk-NYZD3THB.cjs');
|
|
6
|
+
var chunkZ45DHTDX_cjs = require('../chunk-Z45DHTDX.cjs');
|
|
7
|
+
require('../chunk-OZO7D77N.cjs');
|
|
8
8
|
var commander = require('commander');
|
|
9
9
|
var chalk = require('chalk');
|
|
10
10
|
var promises = require('readline/promises');
|
|
@@ -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
|
}
|
|
@@ -396,15 +404,15 @@ function addModelOptions(cmd) {
|
|
|
396
404
|
(v) => parseOllamaThinkCli(v)
|
|
397
405
|
);
|
|
398
406
|
}
|
|
399
|
-
function
|
|
407
|
+
function modelConfigFromOptions(options) {
|
|
400
408
|
const provider = options.model || "openai";
|
|
401
|
-
return
|
|
409
|
+
return {
|
|
402
410
|
provider,
|
|
403
411
|
apiKey: options.apiKey,
|
|
404
412
|
baseUrl: options.baseUrl,
|
|
405
413
|
model: options.modelName,
|
|
406
414
|
...provider === "ollama" && options.ollamaThink !== void 0 ? { think: options.ollamaThink } : {}
|
|
407
|
-
}
|
|
415
|
+
};
|
|
408
416
|
}
|
|
409
417
|
function createChatCommand() {
|
|
410
418
|
return addModelOptions(
|
|
@@ -413,13 +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 chunk6X7EYQLS_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
|
|
422
|
-
const mcpResult = chunk5QMA2YBY_cjs.loadMCPConfig(options.mcpConfig, options.cwd || process.cwd(), options.userBasePath);
|
|
429
|
+
const mcpResult = chunk6X7EYQLS_cjs.loadMCPConfig(options.mcpConfig, options.cwd || process.cwd(), options.userBasePath);
|
|
423
430
|
if (mcpResult.configPath) {
|
|
424
431
|
console.log(chalk__default.default.gray(`Loaded MCP config from: ${mcpResult.configPath}`));
|
|
425
432
|
if (mcpResult.servers.length > 0) {
|
|
@@ -427,8 +434,8 @@ function createChatCommand() {
|
|
|
427
434
|
}
|
|
428
435
|
}
|
|
429
436
|
const cwd = options.cwd || process.cwd();
|
|
430
|
-
const agent = new
|
|
431
|
-
|
|
437
|
+
const agent = new chunk6X7EYQLS_cjs.Agent({
|
|
438
|
+
modelConfig: modelConfigFromOptions(options),
|
|
432
439
|
cwd,
|
|
433
440
|
hookConfigDir: cwd,
|
|
434
441
|
systemPrompt: options.system,
|
|
@@ -439,11 +446,12 @@ function createChatCommand() {
|
|
|
439
446
|
askUserQuestion: process.stdin.isTTY ? createTtyAskUserQuestionResolver() : void 0
|
|
440
447
|
});
|
|
441
448
|
await agent.waitForInit();
|
|
449
|
+
const model = agent.getModel();
|
|
442
450
|
const skillRegistry = agent.getSkillRegistry();
|
|
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: ${chunk6X7EYQLS_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,19 +592,18 @@ function createRunCommand() {
|
|
|
584
592
|
try {
|
|
585
593
|
let sessionId = options.session;
|
|
586
594
|
if (options.resume && !sessionId) {
|
|
587
|
-
sessionId = await
|
|
595
|
+
sessionId = await chunk6X7EYQLS_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
|
|
593
|
-
const mcpResult = chunk5QMA2YBY_cjs.loadMCPConfig(options.mcpConfig, options.cwd || process.cwd(), options.userBasePath);
|
|
600
|
+
const mcpResult = chunk6X7EYQLS_cjs.loadMCPConfig(options.mcpConfig, options.cwd || process.cwd(), options.userBasePath);
|
|
594
601
|
if (mcpResult.configPath) {
|
|
595
602
|
console.log(chalk__default.default.gray(`Loaded MCP config from: ${mcpResult.configPath}`));
|
|
596
603
|
}
|
|
597
604
|
const cwd = options.cwd || process.cwd();
|
|
598
|
-
const agent = new
|
|
599
|
-
|
|
605
|
+
const agent = new chunk6X7EYQLS_cjs.Agent({
|
|
606
|
+
modelConfig: modelConfigFromOptions(options),
|
|
600
607
|
cwd,
|
|
601
608
|
hookConfigDir: cwd,
|
|
602
609
|
systemPrompt: options.system,
|
|
@@ -639,9 +646,9 @@ ${formatUsage(result.usage)}`);
|
|
|
639
646
|
function createToolsCommand() {
|
|
640
647
|
const command = new commander.Command("tools").description("Manage agent tools");
|
|
641
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) => {
|
|
642
|
-
const registry = new
|
|
643
|
-
const skillRegistry =
|
|
644
|
-
registry.registerMany(
|
|
649
|
+
const registry = new chunkZ45DHTDX_cjs.ToolRegistry();
|
|
650
|
+
const skillRegistry = chunk6X7EYQLS_cjs.createSkillRegistry();
|
|
651
|
+
registry.registerMany(chunkZ45DHTDX_cjs.getAllBuiltinTools(skillRegistry));
|
|
645
652
|
let tools = registry.getAll();
|
|
646
653
|
if (options.category) {
|
|
647
654
|
tools = tools.filter(
|
|
@@ -676,9 +683,9 @@ Total: ${tools.length} tools`));
|
|
|
676
683
|
}
|
|
677
684
|
});
|
|
678
685
|
command.command("show <name>").description("Show tool details").action((name) => {
|
|
679
|
-
const registry = new
|
|
680
|
-
const skillRegistry =
|
|
681
|
-
registry.registerMany(
|
|
686
|
+
const registry = new chunkZ45DHTDX_cjs.ToolRegistry();
|
|
687
|
+
const skillRegistry = chunk6X7EYQLS_cjs.createSkillRegistry();
|
|
688
|
+
registry.registerMany(chunkZ45DHTDX_cjs.getAllBuiltinTools(skillRegistry));
|
|
682
689
|
const tool = registry.get(name);
|
|
683
690
|
if (!tool) {
|
|
684
691
|
console.error(chalk__default.default.red(`Tool "${name}" not found`));
|
|
@@ -697,9 +704,9 @@ Parameters Schema:`);
|
|
|
697
704
|
command.command("test <name>").description(
|
|
698
705
|
"Test a tool with arguments. Note: AskUserQuestion returns formatted text only unless the Agent is configured with askUserQuestion (e.g. CLI TTY)."
|
|
699
706
|
).option("-a, --args <json>", "Tool arguments as JSON").action(async (name, options) => {
|
|
700
|
-
const registry = new
|
|
701
|
-
const skillRegistry =
|
|
702
|
-
registry.registerMany(
|
|
707
|
+
const registry = new chunkZ45DHTDX_cjs.ToolRegistry();
|
|
708
|
+
const skillRegistry = chunk6X7EYQLS_cjs.createSkillRegistry();
|
|
709
|
+
registry.registerMany(chunkZ45DHTDX_cjs.getAllBuiltinTools(skillRegistry));
|
|
703
710
|
if (!registry.has(name)) {
|
|
704
711
|
console.error(chalk__default.default.red(`Tool "${name}" not found`));
|
|
705
712
|
process.exit(1);
|
|
@@ -737,9 +744,9 @@ function createSessionsCommand() {
|
|
|
737
744
|
addUserBasePathOption(
|
|
738
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")
|
|
739
746
|
).action(async (options) => {
|
|
740
|
-
const manager = new
|
|
747
|
+
const manager = new chunk6X7EYQLS_cjs.SessionManager({
|
|
741
748
|
type: "jsonl",
|
|
742
|
-
basePath:
|
|
749
|
+
basePath: chunk6X7EYQLS_cjs.getSessionStoragePath(options.userBasePath)
|
|
743
750
|
});
|
|
744
751
|
const sessions = await manager.listSessions();
|
|
745
752
|
const limited = sessions.slice(0, options.limit);
|
|
@@ -772,9 +779,9 @@ Total: ${sessions.length} sessions`));
|
|
|
772
779
|
addUserBasePathOption(
|
|
773
780
|
command.command("show <id>").description("Show session messages").option("-l, --limit <n>", "Limit number of messages", parseInt, 50)
|
|
774
781
|
).action(async (id, options) => {
|
|
775
|
-
const manager = new
|
|
782
|
+
const manager = new chunk6X7EYQLS_cjs.SessionManager({
|
|
776
783
|
type: "jsonl",
|
|
777
|
-
basePath:
|
|
784
|
+
basePath: chunk6X7EYQLS_cjs.getSessionStoragePath(options.userBasePath)
|
|
778
785
|
});
|
|
779
786
|
const exists = await manager.sessionExists(id);
|
|
780
787
|
if (!exists) {
|
|
@@ -797,9 +804,9 @@ Total: ${sessions.length} sessions`));
|
|
|
797
804
|
addUserBasePathOption(
|
|
798
805
|
command.command("delete <id>").description("Delete a session").option("-f, --force", "Skip confirmation")
|
|
799
806
|
).action(async (id, options) => {
|
|
800
|
-
const manager = new
|
|
807
|
+
const manager = new chunk6X7EYQLS_cjs.SessionManager({
|
|
801
808
|
type: "jsonl",
|
|
802
|
-
basePath:
|
|
809
|
+
basePath: chunk6X7EYQLS_cjs.getSessionStoragePath(options.userBasePath)
|
|
803
810
|
});
|
|
804
811
|
const exists = await manager.sessionExists(id);
|
|
805
812
|
if (!exists) {
|
|
@@ -827,9 +834,9 @@ Total: ${sessions.length} sessions`));
|
|
|
827
834
|
addUserBasePathOption(
|
|
828
835
|
command.command("clear").description("Delete all sessions").option("-f, --force", "Skip confirmation")
|
|
829
836
|
).action(async (options) => {
|
|
830
|
-
const manager = new
|
|
837
|
+
const manager = new chunk6X7EYQLS_cjs.SessionManager({
|
|
831
838
|
type: "jsonl",
|
|
832
|
-
basePath:
|
|
839
|
+
basePath: chunk6X7EYQLS_cjs.getSessionStoragePath(options.userBasePath)
|
|
833
840
|
});
|
|
834
841
|
const sessions = await manager.listSessions();
|
|
835
842
|
if (sessions.length === 0) {
|
|
@@ -863,7 +870,7 @@ function createMCPCommand() {
|
|
|
863
870
|
const command = new commander.Command("mcp").description("Manage MCP servers");
|
|
864
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) => {
|
|
865
872
|
try {
|
|
866
|
-
const adapter = new
|
|
873
|
+
const adapter = new chunk6X7EYQLS_cjs.MCPAdapter();
|
|
867
874
|
const args = options.args ? options.args.split(",") : [];
|
|
868
875
|
const env = {};
|
|
869
876
|
if (options.env) {
|
|
@@ -879,6 +886,7 @@ function createMCPCommand() {
|
|
|
879
886
|
`));
|
|
880
887
|
const config = {
|
|
881
888
|
name: options.name,
|
|
889
|
+
transport: "stdio",
|
|
882
890
|
command: cmd,
|
|
883
891
|
args,
|
|
884
892
|
env: Object.keys(env).length > 0 ? env : void 0
|
|
@@ -908,7 +916,7 @@ function createMCPCommand() {
|
|
|
908
916
|
var isMainModule = process.argv[1]?.endsWith("cli/index.js") || process.argv[1]?.endsWith("cli\\index.js") || process.argv[1]?.includes("agent-sdk");
|
|
909
917
|
if (isMainModule) {
|
|
910
918
|
const program = new commander.Command();
|
|
911
|
-
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(chunk6X7EYQLS_cjs.PACKAGE_VERSION);
|
|
912
920
|
program.addCommand(createChatCommand());
|
|
913
921
|
program.addCommand(createRunCommand());
|
|
914
922
|
program.addCommand(createToolsCommand());
|