@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,7 +1,9 @@
1
1
  #!/usr/bin/env node
2
- import { ToolRegistry, createAgentTool, HookManager, getAllBuiltinTools, getEnvironmentInfo, formatEnvironmentSection } from './chunk-OHXW2YM6.js';
3
- import { promises, existsSync, readFileSync } from 'fs';
4
- import { join, resolve } from 'path';
2
+ import { createModel, mergeMcpStdioEnv } from './chunk-742JTNYI.js';
3
+ import { ToolRegistry, createAgentTool, HookManager, getAllBuiltinTools, getEnvironmentInfo, formatEnvironmentSection } from './chunk-THKEF32L.js';
4
+ import { readFileSync, promises, existsSync } from 'fs';
5
+ import { dirname, join, resolve } from 'path';
6
+ import { fileURLToPath } from 'url';
5
7
  import { randomUUID } from 'crypto';
6
8
  import { homedir } from 'os';
7
9
  import { Client } from '@modelcontextprotocol/sdk/client/index.js';
@@ -11,6 +13,9 @@ import { z } from 'zod';
11
13
  import { exec } from 'child_process';
12
14
  import { promisify } from 'util';
13
15
 
16
+ var pkgDir = dirname(fileURLToPath(import.meta.url));
17
+ var pkgPath = join(pkgDir, "..", "package.json");
18
+ var PACKAGE_VERSION = JSON.parse(readFileSync(pkgPath, "utf-8")).version;
14
19
  var JsonlStorage = class {
15
20
  basePath;
16
21
  constructor(config = {}) {
@@ -567,7 +572,7 @@ var MCPClient = class {
567
572
  constructor(config) {
568
573
  this._name = config.name;
569
574
  this.client = new Client(
570
- { name: "agent-sdk-client", version: "0.1.0" },
575
+ { name: "agent-sdk-client", version: PACKAGE_VERSION },
571
576
  { capabilities: {} }
572
577
  );
573
578
  if (isStdioConfig(config)) {
@@ -695,7 +700,7 @@ var MCPClient = class {
695
700
  }
696
701
  convertSchema(schema) {
697
702
  if (!schema || !schema.properties) {
698
- return z.object({}).passthrough();
703
+ return z.looseObject({});
699
704
  }
700
705
  const shape = {};
701
706
  for (const [key, value] of Object.entries(schema.properties)) {
@@ -716,7 +721,7 @@ var MCPClient = class {
716
721
  zodField = z.array(z.any());
717
722
  break;
718
723
  case "object":
719
- zodField = z.object({}).passthrough();
724
+ zodField = z.looseObject({});
720
725
  break;
721
726
  default:
722
727
  zodField = z.any();
@@ -1799,7 +1804,7 @@ var ContextManager = class {
1799
1804
  };
1800
1805
 
1801
1806
  // src/core/agent.ts
1802
- function toMCPClientConfig(config) {
1807
+ function toMCPClientConfig(config, agentEnv) {
1803
1808
  if (config.transport === "http") {
1804
1809
  return {
1805
1810
  name: config.name,
@@ -1811,7 +1816,7 @@ function toMCPClientConfig(config) {
1811
1816
  name: config.name,
1812
1817
  command: config.command,
1813
1818
  args: config.args,
1814
- env: config.env
1819
+ env: mergeMcpStdioEnv(agentEnv, config.env)
1815
1820
  };
1816
1821
  }
1817
1822
  var Agent = class _Agent {
@@ -1831,15 +1836,30 @@ var Agent = class _Agent {
1831
1836
  // inputTokens/outputTokens: 累计消耗
1832
1837
  // totalTokens: 累计总消耗 (inputTokens + outputTokens)
1833
1838
  sessionUsage = _Agent.createEmptySessionUsage();
1839
+ static resolveModel(config) {
1840
+ if (config.model) {
1841
+ if (config.modelConfig) {
1842
+ throw new Error("AgentConfig: pass only one of `model` or `modelConfig`");
1843
+ }
1844
+ return config.model;
1845
+ }
1846
+ if (config.modelConfig) {
1847
+ return createModel(config.modelConfig, config.env);
1848
+ }
1849
+ throw new Error("AgentConfig: `model` or `modelConfig` is required");
1850
+ }
1834
1851
  constructor(config) {
1852
+ const resolvedModel = _Agent.resolveModel(config);
1835
1853
  this.config = {
1836
1854
  maxIterations: 200,
1837
1855
  streaming: true,
1838
- ...config
1856
+ ...config,
1857
+ model: resolvedModel,
1858
+ modelConfig: void 0
1839
1859
  };
1840
1860
  this.skillRegistry = createSkillRegistry({
1841
- cwd: config.cwd,
1842
- userBasePath: config.userBasePath
1861
+ cwd: this.config.cwd,
1862
+ userBasePath: this.config.userBasePath
1843
1863
  });
1844
1864
  this.toolRegistry = new ToolRegistry({
1845
1865
  executionPolicy: {
@@ -1860,20 +1880,20 @@ var Agent = class _Agent {
1860
1880
  } else if (this.toolRegistry.has("Agent")) {
1861
1881
  this.toolRegistry.unregister("Agent");
1862
1882
  }
1863
- if (config.hookManager) {
1864
- this.toolRegistry.setHookManager(config.hookManager);
1865
- } else if (config.hookConfigDir !== void 0) {
1883
+ if (this.config.hookManager) {
1884
+ this.toolRegistry.setHookManager(this.config.hookManager);
1885
+ } else if (this.config.hookConfigDir !== void 0) {
1866
1886
  const hm = HookManager.create();
1867
1887
  this.toolRegistry.setHookManager(hm);
1868
- this.hookDiscoverPromise = hm.discoverAndLoad(config.hookConfigDir);
1888
+ this.hookDiscoverPromise = hm.discoverAndLoad(this.config.hookConfigDir);
1869
1889
  }
1870
1890
  this.sessionManager = new SessionManager({
1871
- type: config.storage?.type || "jsonl",
1872
- basePath: getSessionStoragePath(config.userBasePath)
1891
+ type: this.config.storage?.type || "jsonl",
1892
+ basePath: getSessionStoragePath(this.config.userBasePath)
1873
1893
  });
1874
- if (config.contextManagement !== false) {
1875
- const cmConfig = config.contextManagement === true ? {} : config.contextManagement ?? {};
1876
- this.contextManager = new ContextManager(config.model, cmConfig);
1894
+ if (this.config.contextManagement !== false) {
1895
+ const cmConfig = this.config.contextManagement === true ? {} : this.config.contextManagement ?? {};
1896
+ this.contextManager = new ContextManager(this.config.model, cmConfig);
1877
1897
  }
1878
1898
  this.initPromise = this.initializeAsync();
1879
1899
  }
@@ -2082,7 +2102,8 @@ ${content}`;
2082
2102
  temperature: this.config.temperature,
2083
2103
  maxTokens: this.config.maxTokens,
2084
2104
  signal,
2085
- includeRawStreamEvents: options?.includeRawStreamEvents
2105
+ includeRawStreamEvents: options?.includeRawStreamEvents,
2106
+ sessionId: this.sessionManager.sessionId ?? void 0
2086
2107
  };
2087
2108
  const stream = this.config.model.stream(modelParams);
2088
2109
  let hasToolCalls = false;
@@ -2348,6 +2369,12 @@ ${content}`;
2348
2369
  getSkillRegistry() {
2349
2370
  return this.skillRegistry;
2350
2371
  }
2372
+ /**
2373
+ * 解析后的模型适配器(`modelConfig` 已在构造时合并 `env` 并实例化)。
2374
+ */
2375
+ getModel() {
2376
+ return this.config.model;
2377
+ }
2351
2378
  /**
2352
2379
  * 处理用户输入,检测并处理 skill 调用
2353
2380
  * @param input 用户输入
@@ -2433,7 +2460,7 @@ ARGUMENTS: ${args}`;
2433
2460
  if (!this.mcpAdapter) {
2434
2461
  this.mcpAdapter = new MCPAdapter();
2435
2462
  }
2436
- await this.mcpAdapter.addServer(toMCPClientConfig(config));
2463
+ await this.mcpAdapter.addServer(toMCPClientConfig(config, this.config.env));
2437
2464
  const mcpTools = this.mcpAdapter.getToolDefinitions();
2438
2465
  for (const tool of mcpTools) {
2439
2466
  if (!tool.name.startsWith(`mcp_${config.name}__`)) {
@@ -2849,6 +2876,6 @@ function validateMCPConfig(config) {
2849
2876
  return errors;
2850
2877
  }
2851
2878
 
2852
- export { Agent, DEFAULT_SYSTEM_PROMPT, JsonlStorage, MCPAdapter, MCPClient, MemoryManager, MemoryStorage, SessionManager, SkillLoader, SkillRegistry, StreamChunkProcessor, createAgent, createJsonlStorage, createMCPAdapter, createMCPClient, createMemoryStorage, createSessionManager, createSkillLoader, createSkillRegistry, createStorage, getLatestSessionId, getSessionStoragePath, loadMCPConfig, parseSkillMd, validateMCPConfig };
2853
- //# sourceMappingURL=chunk-Q3SOMX26.js.map
2854
- //# sourceMappingURL=chunk-Q3SOMX26.js.map
2879
+ export { Agent, DEFAULT_SYSTEM_PROMPT, JsonlStorage, MCPAdapter, MCPClient, MemoryManager, MemoryStorage, PACKAGE_VERSION, SessionManager, SkillLoader, SkillRegistry, StreamChunkProcessor, createAgent, createJsonlStorage, createMCPAdapter, createMCPClient, createMemoryStorage, createSessionManager, createSkillLoader, createSkillRegistry, createStorage, getLatestSessionId, getSessionStoragePath, loadMCPConfig, parseSkillMd, validateMCPConfig };
2880
+ //# sourceMappingURL=chunk-DXMVWGLJ.js.map
2881
+ //# sourceMappingURL=chunk-DXMVWGLJ.js.map