@ddlqhd/agent-sdk 0.1.0 → 0.1.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.
Files changed (48) hide show
  1. package/README.md +4 -2
  2. package/dist/{chunk-NDSL7NPN.js → chunk-742JTNYI.js} +224 -19
  3. package/dist/chunk-742JTNYI.js.map +1 -0
  4. package/dist/{chunk-5QMA2YBY.cjs → chunk-AJD3DTL7.cjs} +57 -28
  5. package/dist/chunk-AJD3DTL7.cjs.map +1 -0
  6. package/dist/{chunk-X35MHWXE.cjs → chunk-DQFTAD3I.cjs} +231 -24
  7. package/dist/chunk-DQFTAD3I.cjs.map +1 -0
  8. package/dist/{chunk-Q3SOMX26.js → chunk-DXMVWGLJ.js} +52 -25
  9. package/dist/chunk-DXMVWGLJ.js.map +1 -0
  10. package/dist/chunk-LOYIGOBZ.js +54 -0
  11. package/dist/chunk-LOYIGOBZ.js.map +1 -0
  12. package/dist/chunk-OZO7D77N.cjs +59 -0
  13. package/dist/chunk-OZO7D77N.cjs.map +1 -0
  14. package/dist/{chunk-JF5AJQMU.cjs → chunk-Q3L4GIBG.cjs} +211 -58
  15. package/dist/chunk-Q3L4GIBG.cjs.map +1 -0
  16. package/dist/{chunk-OHXW2YM6.js → chunk-THKEF32L.js} +210 -57
  17. package/dist/chunk-THKEF32L.js.map +1 -0
  18. package/dist/cli/index.cjs +36 -37
  19. package/dist/cli/index.cjs.map +1 -1
  20. package/dist/cli/index.js +11 -12
  21. package/dist/cli/index.js.map +1 -1
  22. package/dist/{index-DPsZ1zat.d.ts → index-DGPDMbW5.d.cts} +8 -21
  23. package/dist/{index-RTPmFjMp.d.cts → index-nEfayAzD.d.ts} +8 -21
  24. package/dist/index.cjs +91 -79
  25. package/dist/index.d.cts +26 -6
  26. package/dist/index.d.ts +26 -6
  27. package/dist/index.js +4 -4
  28. package/dist/models/index.cjs +15 -15
  29. package/dist/models/index.d.cts +50 -6
  30. package/dist/models/index.d.ts +50 -6
  31. package/dist/models/index.js +2 -2
  32. package/dist/tools/index.cjs +51 -51
  33. package/dist/tools/index.d.cts +3 -3
  34. package/dist/tools/index.d.ts +3 -3
  35. package/dist/tools/index.js +2 -2
  36. package/dist/{types-C0aX_Qdp.d.cts → types-BLf9IqRs.d.cts} +34 -49
  37. package/dist/{types-C0aX_Qdp.d.ts → types-BLf9IqRs.d.ts} +34 -49
  38. package/package.json +15 -4
  39. package/dist/chunk-5QMA2YBY.cjs.map +0 -1
  40. package/dist/chunk-CNSGZVRN.cjs +0 -152
  41. package/dist/chunk-CNSGZVRN.cjs.map +0 -1
  42. package/dist/chunk-JF5AJQMU.cjs.map +0 -1
  43. package/dist/chunk-NDSL7NPN.js.map +0 -1
  44. package/dist/chunk-OHXW2YM6.js.map +0 -1
  45. package/dist/chunk-Q3SOMX26.js.map +0 -1
  46. package/dist/chunk-WH3APNQ5.js +0 -147
  47. package/dist/chunk-WH3APNQ5.js.map +0 -1
  48. package/dist/chunk-X35MHWXE.cjs.map +0 -1
@@ -1,9 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- var chunkJF5AJQMU_cjs = require('./chunk-JF5AJQMU.cjs');
4
+ var chunkDQFTAD3I_cjs = require('./chunk-DQFTAD3I.cjs');
5
+ var chunkQ3L4GIBG_cjs = require('./chunk-Q3L4GIBG.cjs');
5
6
  var fs = require('fs');
6
7
  var path = require('path');
8
+ var url = require('url');
7
9
  var crypto = require('crypto');
8
10
  var os = require('os');
9
11
  var index_js = require('@modelcontextprotocol/sdk/client/index.js');
@@ -13,6 +15,10 @@ var zod = require('zod');
13
15
  var child_process = require('child_process');
14
16
  var util = require('util');
15
17
 
18
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
19
+ var pkgDir = path.dirname(url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-AJD3DTL7.cjs', document.baseURI).href))));
20
+ var pkgPath = path.join(pkgDir, "..", "package.json");
21
+ var PACKAGE_VERSION = JSON.parse(fs.readFileSync(pkgPath, "utf-8")).version;
16
22
  var JsonlStorage = class {
17
23
  basePath;
18
24
  constructor(config = {}) {
@@ -569,7 +575,7 @@ var MCPClient = class {
569
575
  constructor(config) {
570
576
  this._name = config.name;
571
577
  this.client = new index_js.Client(
572
- { name: "agent-sdk-client", version: "0.1.0" },
578
+ { name: "agent-sdk-client", version: PACKAGE_VERSION },
573
579
  { capabilities: {} }
574
580
  );
575
581
  if (isStdioConfig(config)) {
@@ -697,7 +703,7 @@ var MCPClient = class {
697
703
  }
698
704
  convertSchema(schema) {
699
705
  if (!schema || !schema.properties) {
700
- return zod.z.object({}).passthrough();
706
+ return zod.z.looseObject({});
701
707
  }
702
708
  const shape = {};
703
709
  for (const [key, value] of Object.entries(schema.properties)) {
@@ -718,7 +724,7 @@ var MCPClient = class {
718
724
  zodField = zod.z.array(zod.z.any());
719
725
  break;
720
726
  case "object":
721
- zodField = zod.z.object({}).passthrough();
727
+ zodField = zod.z.looseObject({});
722
728
  break;
723
729
  default:
724
730
  zodField = zod.z.any();
@@ -1801,7 +1807,7 @@ var ContextManager = class {
1801
1807
  };
1802
1808
 
1803
1809
  // src/core/agent.ts
1804
- function toMCPClientConfig(config) {
1810
+ function toMCPClientConfig(config, agentEnv) {
1805
1811
  if (config.transport === "http") {
1806
1812
  return {
1807
1813
  name: config.name,
@@ -1813,7 +1819,7 @@ function toMCPClientConfig(config) {
1813
1819
  name: config.name,
1814
1820
  command: config.command,
1815
1821
  args: config.args,
1816
- env: config.env
1822
+ env: chunkDQFTAD3I_cjs.mergeMcpStdioEnv(agentEnv, config.env)
1817
1823
  };
1818
1824
  }
1819
1825
  var Agent = class _Agent {
@@ -1833,17 +1839,32 @@ var Agent = class _Agent {
1833
1839
  // inputTokens/outputTokens: 累计消耗
1834
1840
  // totalTokens: 累计总消耗 (inputTokens + outputTokens)
1835
1841
  sessionUsage = _Agent.createEmptySessionUsage();
1842
+ static resolveModel(config) {
1843
+ if (config.model) {
1844
+ if (config.modelConfig) {
1845
+ throw new Error("AgentConfig: pass only one of `model` or `modelConfig`");
1846
+ }
1847
+ return config.model;
1848
+ }
1849
+ if (config.modelConfig) {
1850
+ return chunkDQFTAD3I_cjs.createModel(config.modelConfig, config.env);
1851
+ }
1852
+ throw new Error("AgentConfig: `model` or `modelConfig` is required");
1853
+ }
1836
1854
  constructor(config) {
1855
+ const resolvedModel = _Agent.resolveModel(config);
1837
1856
  this.config = {
1838
1857
  maxIterations: 200,
1839
1858
  streaming: true,
1840
- ...config
1859
+ ...config,
1860
+ model: resolvedModel,
1861
+ modelConfig: void 0
1841
1862
  };
1842
1863
  this.skillRegistry = createSkillRegistry({
1843
- cwd: config.cwd,
1844
- userBasePath: config.userBasePath
1864
+ cwd: this.config.cwd,
1865
+ userBasePath: this.config.userBasePath
1845
1866
  });
1846
- this.toolRegistry = new chunkJF5AJQMU_cjs.ToolRegistry({
1867
+ this.toolRegistry = new chunkQ3L4GIBG_cjs.ToolRegistry({
1847
1868
  executionPolicy: {
1848
1869
  disallowedTools: this.config.disallowedTools,
1849
1870
  allowedTools: this.config.allowedTools,
@@ -1856,26 +1877,26 @@ var Agent = class _Agent {
1856
1877
  if (this.toolRegistry.has("Agent")) {
1857
1878
  this.toolRegistry.unregister("Agent");
1858
1879
  }
1859
- this.toolRegistry.register(chunkJF5AJQMU_cjs.createAgentTool({
1880
+ this.toolRegistry.register(chunkQ3L4GIBG_cjs.createAgentTool({
1860
1881
  runner: (request, context) => this.runSubagent(request, context)
1861
1882
  }));
1862
1883
  } else if (this.toolRegistry.has("Agent")) {
1863
1884
  this.toolRegistry.unregister("Agent");
1864
1885
  }
1865
- if (config.hookManager) {
1866
- this.toolRegistry.setHookManager(config.hookManager);
1867
- } else if (config.hookConfigDir !== void 0) {
1868
- const hm = chunkJF5AJQMU_cjs.HookManager.create();
1886
+ if (this.config.hookManager) {
1887
+ this.toolRegistry.setHookManager(this.config.hookManager);
1888
+ } else if (this.config.hookConfigDir !== void 0) {
1889
+ const hm = chunkQ3L4GIBG_cjs.HookManager.create();
1869
1890
  this.toolRegistry.setHookManager(hm);
1870
- this.hookDiscoverPromise = hm.discoverAndLoad(config.hookConfigDir);
1891
+ this.hookDiscoverPromise = hm.discoverAndLoad(this.config.hookConfigDir);
1871
1892
  }
1872
1893
  this.sessionManager = new SessionManager({
1873
- type: config.storage?.type || "jsonl",
1874
- basePath: getSessionStoragePath(config.userBasePath)
1894
+ type: this.config.storage?.type || "jsonl",
1895
+ basePath: getSessionStoragePath(this.config.userBasePath)
1875
1896
  });
1876
- if (config.contextManagement !== false) {
1877
- const cmConfig = config.contextManagement === true ? {} : config.contextManagement ?? {};
1878
- this.contextManager = new ContextManager(config.model, cmConfig);
1897
+ if (this.config.contextManagement !== false) {
1898
+ const cmConfig = this.config.contextManagement === true ? {} : this.config.contextManagement ?? {};
1899
+ this.contextManager = new ContextManager(this.config.model, cmConfig);
1879
1900
  }
1880
1901
  this.initPromise = this.initializeAsync();
1881
1902
  }
@@ -1892,7 +1913,7 @@ var Agent = class _Agent {
1892
1913
  }
1893
1914
  return;
1894
1915
  }
1895
- const builtins = chunkJF5AJQMU_cjs.getAllBuiltinTools(this.skillRegistry, {
1916
+ const builtins = chunkQ3L4GIBG_cjs.getAllBuiltinTools(this.skillRegistry, {
1896
1917
  resolve: this.config.askUserQuestion
1897
1918
  }).filter((t) => !this.toolRegistry.isDisallowed(t.name));
1898
1919
  this.toolRegistry.registerMany(builtins);
@@ -1977,8 +1998,8 @@ var Agent = class _Agent {
1977
1998
  let envSection = "";
1978
1999
  if (shouldIncludeEnv) {
1979
2000
  const cwd = this.config.cwd || process.cwd();
1980
- const envInfo = chunkJF5AJQMU_cjs.getEnvironmentInfo(cwd);
1981
- envSection = chunkJF5AJQMU_cjs.formatEnvironmentSection(envInfo);
2001
+ const envInfo = chunkQ3L4GIBG_cjs.getEnvironmentInfo(cwd);
2002
+ envSection = chunkQ3L4GIBG_cjs.formatEnvironmentSection(envInfo);
1982
2003
  }
1983
2004
  if (!customPrompt) {
1984
2005
  let basePrompt = DEFAULT_SYSTEM_PROMPT;
@@ -2084,7 +2105,8 @@ ${content}`;
2084
2105
  temperature: this.config.temperature,
2085
2106
  maxTokens: this.config.maxTokens,
2086
2107
  signal,
2087
- includeRawStreamEvents: options?.includeRawStreamEvents
2108
+ includeRawStreamEvents: options?.includeRawStreamEvents,
2109
+ sessionId: this.sessionManager.sessionId ?? void 0
2088
2110
  };
2089
2111
  const stream = this.config.model.stream(modelParams);
2090
2112
  let hasToolCalls = false;
@@ -2350,6 +2372,12 @@ ${content}`;
2350
2372
  getSkillRegistry() {
2351
2373
  return this.skillRegistry;
2352
2374
  }
2375
+ /**
2376
+ * 解析后的模型适配器(`modelConfig` 已在构造时合并 `env` 并实例化)。
2377
+ */
2378
+ getModel() {
2379
+ return this.config.model;
2380
+ }
2353
2381
  /**
2354
2382
  * 处理用户输入,检测并处理 skill 调用
2355
2383
  * @param input 用户输入
@@ -2435,7 +2463,7 @@ ARGUMENTS: ${args}`;
2435
2463
  if (!this.mcpAdapter) {
2436
2464
  this.mcpAdapter = new MCPAdapter();
2437
2465
  }
2438
- await this.mcpAdapter.addServer(toMCPClientConfig(config));
2466
+ await this.mcpAdapter.addServer(toMCPClientConfig(config, this.config.env));
2439
2467
  const mcpTools = this.mcpAdapter.getToolDefinitions();
2440
2468
  for (const tool of mcpTools) {
2441
2469
  if (!tool.name.startsWith(`mcp_${config.name}__`)) {
@@ -2858,6 +2886,7 @@ exports.MCPAdapter = MCPAdapter;
2858
2886
  exports.MCPClient = MCPClient;
2859
2887
  exports.MemoryManager = MemoryManager;
2860
2888
  exports.MemoryStorage = MemoryStorage;
2889
+ exports.PACKAGE_VERSION = PACKAGE_VERSION;
2861
2890
  exports.SessionManager = SessionManager;
2862
2891
  exports.SkillLoader = SkillLoader;
2863
2892
  exports.SkillRegistry = SkillRegistry;
@@ -2876,5 +2905,5 @@ exports.getSessionStoragePath = getSessionStoragePath;
2876
2905
  exports.loadMCPConfig = loadMCPConfig;
2877
2906
  exports.parseSkillMd = parseSkillMd;
2878
2907
  exports.validateMCPConfig = validateMCPConfig;
2879
- //# sourceMappingURL=chunk-5QMA2YBY.cjs.map
2880
- //# sourceMappingURL=chunk-5QMA2YBY.cjs.map
2908
+ //# sourceMappingURL=chunk-AJD3DTL7.cjs.map
2909
+ //# sourceMappingURL=chunk-AJD3DTL7.cjs.map