deepagentsdk 0.14.0 → 0.16.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.
@@ -1,4 +1,4 @@
1
- const require_chunk = require('./chunk-C5azi7Hr.cjs');
1
+ const require_chunk = require('./chunk-DUZBydyJ.cjs');
2
2
  let ai = require("ai");
3
3
  let zod = require("zod");
4
4
  let micromatch = require("micromatch");
@@ -12,6 +12,7 @@ let jsdom = require("jsdom");
12
12
  let child_process = require("child_process");
13
13
  let _ai_sdk_anthropic = require("@ai-sdk/anthropic");
14
14
  let _ai_sdk_openai = require("@ai-sdk/openai");
15
+ let zhipu_ai_provider = require("zhipu-ai-provider");
15
16
  let node_fs = require("node:fs");
16
17
  let node_path = require("node:path");
17
18
 
@@ -200,7 +201,7 @@ var init_events = require_chunk.__esmMin((() => {}));
200
201
  * Type guard to check if a backend is a SandboxBackendProtocol.
201
202
  */
202
203
  function isSandboxBackend(backend) {
203
- return typeof backend.execute === "function" && typeof backend.id === "string";
204
+ return typeof backend.execute === "function" && typeof backend.uploadFiles === "function" && typeof backend.downloadFiles === "function" && typeof backend.id === "string";
204
205
  }
205
206
 
206
207
  //#endregion
@@ -2288,7 +2289,7 @@ var DeepAgent = class {
2288
2289
  * Supports both legacy skillsDir and new agentId modes.
2289
2290
  */
2290
2291
  async loadSkills(options) {
2291
- const { listSkills } = await Promise.resolve().then(() => require("./load-DqllBbDc.cjs"));
2292
+ const { listSkills } = await Promise.resolve().then(() => require("./load-CLVcFzo7.cjs"));
2292
2293
  this.skillsMetadata = (await listSkills(options.agentId ? { agentId: options.agentId } : { projectSkillsDir: options.skillsDir })).map((s) => ({
2293
2294
  name: s.name,
2294
2295
  description: s.description,
@@ -2887,6 +2888,18 @@ function createDeepAgent(params) {
2887
2888
  init_errors();
2888
2889
  init_limits();
2889
2890
  /**
2891
+ * Map error messages to FileOperationError literals.
2892
+ *
2893
+ * This provides structured error handling that LLMs can understand and potentially fix.
2894
+ */
2895
+ function mapErrorToOperationError(errorMessage, path$1) {
2896
+ const lowerError = errorMessage.toLowerCase();
2897
+ if (lowerError.includes("no such file") || lowerError.includes("not found") || lowerError.includes("cannot find")) return "file_not_found";
2898
+ if (lowerError.includes("permission denied") || lowerError.includes("access denied") || lowerError.includes("read-only")) return "permission_denied";
2899
+ if (lowerError.includes("is a directory") || lowerError.includes("directory not empty")) return "is_directory";
2900
+ return "invalid_path";
2901
+ }
2902
+ /**
2890
2903
  * Encode string to base64 for safe shell transmission.
2891
2904
  */
2892
2905
  function toBase64(str) {
@@ -2925,6 +2938,74 @@ function buildNodeScript(script, args) {
2925
2938
  * ```
2926
2939
  */
2927
2940
  var BaseSandbox = class {
2941
+ /**
2942
+ * Upload multiple files to the sandbox.
2943
+ *
2944
+ * Default implementation uses base64 encoding via shell commands.
2945
+ * Subclasses can override if they have a native file upload API.
2946
+ *
2947
+ * This API is designed to allow partial success - individual uploads may fail
2948
+ * without affecting others. Check the error field in each response.
2949
+ */
2950
+ async uploadFiles(files) {
2951
+ const responses = [];
2952
+ for (const [path$1, content] of files) try {
2953
+ const base64Content = Buffer.from(content).toString("base64");
2954
+ const escapedPath = path$1.replace(/'/g, "'\\''");
2955
+ const result = await this.execute(`echo '${base64Content}' | base64 -d > '${escapedPath}'`);
2956
+ if (result.exitCode !== 0) responses.push({
2957
+ path: path$1,
2958
+ error: mapErrorToOperationError(result.output, path$1)
2959
+ });
2960
+ else responses.push({
2961
+ path: path$1,
2962
+ error: null
2963
+ });
2964
+ } catch (error) {
2965
+ responses.push({
2966
+ path: path$1,
2967
+ error: "permission_denied"
2968
+ });
2969
+ }
2970
+ return responses;
2971
+ }
2972
+ /**
2973
+ * Download multiple files from the sandbox.
2974
+ *
2975
+ * Default implementation uses base64 encoding via shell commands.
2976
+ * Subclasses can override if they have a native file download API.
2977
+ *
2978
+ * This API is designed to allow partial success - individual downloads may fail
2979
+ * without affecting others. Check the error field in each response.
2980
+ */
2981
+ async downloadFiles(paths) {
2982
+ const responses = [];
2983
+ for (const path$1 of paths) try {
2984
+ const escapedPath = path$1.replace(/'/g, "'\\''");
2985
+ const result = await this.execute(`base64 '${escapedPath}'`);
2986
+ if (result.exitCode !== 0) responses.push({
2987
+ path: path$1,
2988
+ content: null,
2989
+ error: mapErrorToOperationError(result.output, path$1)
2990
+ });
2991
+ else {
2992
+ const base64Content = result.output.trim();
2993
+ const content = Buffer.from(base64Content, "base64");
2994
+ responses.push({
2995
+ path: path$1,
2996
+ content,
2997
+ error: null
2998
+ });
2999
+ }
3000
+ } catch (error) {
3001
+ responses.push({
3002
+ path: path$1,
3003
+ content: null,
3004
+ error: "permission_denied"
3005
+ });
3006
+ }
3007
+ return responses;
3008
+ }
2928
3009
  /**
2929
3010
  * List files and directories in a path.
2930
3011
  */
@@ -3444,16 +3525,47 @@ var LocalSandbox = class extends BaseSandbox {
3444
3525
  /**
3445
3526
  * Utility to parse model strings into LanguageModel instances.
3446
3527
  * Provides backward compatibility for CLI and other string-based model specifications.
3528
+ * Extended to support custom base URLs and API keys for providers.
3529
+ */
3530
+ /**
3531
+ * Global provider configuration for CLI session
3532
+ * Managed by CLI and used by parseModelString
3533
+ */
3534
+ let globalProvidersConfig = {};
3535
+ /**
3536
+ * Update global provider configuration
3537
+ * Called by /baseurl slash command and CLI flag parsing
3538
+ */
3539
+ function setProvidersConfig(config) {
3540
+ globalProvidersConfig = {
3541
+ ...globalProvidersConfig,
3542
+ ...config
3543
+ };
3544
+ }
3545
+ /**
3546
+ * Get current global provider configuration
3447
3547
  */
3548
+ function getProvidersConfig() {
3549
+ return { ...globalProvidersConfig };
3550
+ }
3551
+ const providerCache = /* @__PURE__ */ new Map();
3448
3552
  /**
3449
- * Parse a model string into a LanguageModel instance.
3553
+ * Get cache key for provider configuration
3554
+ */
3555
+ function getProviderCacheKey(provider, config) {
3556
+ return `${provider}:${config?.baseURL ?? ""}:${config?.apiKey ?? ""}`;
3557
+ }
3558
+ /**
3559
+ * Parse a model string into a LanguageModel instance with optional provider configuration.
3450
3560
  *
3451
3561
  * Supports formats like:
3452
3562
  * - "anthropic/claude-sonnet-4-20250514"
3453
3563
  * - "openai/gpt-4o"
3564
+ * - "zhipu/glm-4-plus"
3454
3565
  * - "claude-sonnet-4-20250514" (defaults to Anthropic)
3455
3566
  *
3456
3567
  * @param modelString - The model string to parse
3568
+ * @param options - Parse options including provider configuration
3457
3569
  * @returns A LanguageModel instance
3458
3570
  *
3459
3571
  * @example
@@ -3461,12 +3573,77 @@ var LocalSandbox = class extends BaseSandbox {
3461
3573
  * const model = parseModelString("anthropic/claude-sonnet-4-20250514");
3462
3574
  * const agent = createDeepAgent({ model });
3463
3575
  * ```
3576
+ *
3577
+ * @example
3578
+ * ```typescript
3579
+ * // Using Zhipu AI (Z.AI) models
3580
+ * const model = parseModelString("zhipu/glm-4-plus");
3581
+ * const agent = createDeepAgent({ model });
3582
+ * ```
3583
+ *
3584
+ * @example
3585
+ * ```typescript
3586
+ * // With custom base URL
3587
+ * const model = parseModelString("anthropic/claude-3", {
3588
+ * providers: {
3589
+ * anthropic: {
3590
+ * baseURL: "https://custom-endpoint.com/v1",
3591
+ * apiKey: "custom-key",
3592
+ * },
3593
+ * },
3594
+ * });
3595
+ * const agent = createDeepAgent({ model });
3596
+ * ```
3464
3597
  */
3465
- function parseModelString(modelString) {
3598
+ function parseModelString(modelString, options) {
3466
3599
  const [provider, modelName] = modelString.split("/");
3467
- if (provider === "anthropic") return (0, _ai_sdk_anthropic.anthropic)(modelName || "claude-sonnet-4-20250514");
3468
- else if (provider === "openai") return (0, _ai_sdk_openai.openai)(modelName || "gpt-5-mini");
3469
- return (0, _ai_sdk_anthropic.anthropic)(modelString);
3600
+ const providerName = provider || "anthropic";
3601
+ const globalConfig = globalProvidersConfig[providerName];
3602
+ const providerConfig = options?.providers?.[providerName] ?? globalConfig;
3603
+ if (providerName === "anthropic") {
3604
+ const cacheKey$1 = getProviderCacheKey("anthropic", providerConfig);
3605
+ let anthropicProvider$1 = providerCache.get(cacheKey$1);
3606
+ if (!anthropicProvider$1) {
3607
+ anthropicProvider$1 = (0, _ai_sdk_anthropic.createAnthropic)({
3608
+ baseURL: providerConfig?.baseURL,
3609
+ apiKey: providerConfig?.apiKey
3610
+ });
3611
+ providerCache.set(cacheKey$1, anthropicProvider$1);
3612
+ }
3613
+ return anthropicProvider$1(modelName || "claude-sonnet-4-20250514");
3614
+ } else if (providerName === "openai") {
3615
+ const cacheKey$1 = getProviderCacheKey("openai", providerConfig);
3616
+ let openaiProvider = providerCache.get(cacheKey$1);
3617
+ if (!openaiProvider) {
3618
+ openaiProvider = (0, _ai_sdk_openai.createOpenAI)({
3619
+ baseURL: providerConfig?.baseURL,
3620
+ apiKey: providerConfig?.apiKey
3621
+ });
3622
+ providerCache.set(cacheKey$1, openaiProvider);
3623
+ }
3624
+ return openaiProvider(modelName || "gpt-5-mini");
3625
+ } else if (providerName === "zhipu") {
3626
+ const cacheKey$1 = getProviderCacheKey("zhipu", providerConfig);
3627
+ let zhipuProvider = providerCache.get(cacheKey$1);
3628
+ if (!zhipuProvider) {
3629
+ zhipuProvider = (0, zhipu_ai_provider.createZhipu)({
3630
+ baseURL: providerConfig?.baseURL,
3631
+ apiKey: providerConfig?.apiKey
3632
+ });
3633
+ providerCache.set(cacheKey$1, zhipuProvider);
3634
+ }
3635
+ return zhipuProvider(modelName || "glm-4.7");
3636
+ }
3637
+ const cacheKey = getProviderCacheKey("anthropic", providerConfig);
3638
+ let anthropicProvider = providerCache.get(cacheKey);
3639
+ if (!anthropicProvider) {
3640
+ anthropicProvider = (0, _ai_sdk_anthropic.createAnthropic)({
3641
+ baseURL: providerConfig?.baseURL,
3642
+ apiKey: providerConfig?.apiKey
3643
+ });
3644
+ providerCache.set(cacheKey, anthropicProvider);
3645
+ }
3646
+ return anthropicProvider(modelString);
3470
3647
  }
3471
3648
 
3472
3649
  //#endregion
@@ -3837,6 +4014,12 @@ Object.defineProperty(exports, 'formatReadResponse', {
3837
4014
  return formatReadResponse;
3838
4015
  }
3839
4016
  });
4017
+ Object.defineProperty(exports, 'getProvidersConfig', {
4018
+ enumerable: true,
4019
+ get: function () {
4020
+ return getProvidersConfig;
4021
+ }
4022
+ });
3840
4023
  Object.defineProperty(exports, 'getTaskToolDescription', {
3841
4024
  enumerable: true,
3842
4025
  get: function () {
@@ -3951,6 +4134,12 @@ Object.defineProperty(exports, 'read_file', {
3951
4134
  return read_file;
3952
4135
  }
3953
4136
  });
4137
+ Object.defineProperty(exports, 'setProvidersConfig', {
4138
+ enumerable: true,
4139
+ get: function () {
4140
+ return setProvidersConfig;
4141
+ }
4142
+ });
3954
4143
  Object.defineProperty(exports, 'shouldEvict', {
3955
4144
  enumerable: true,
3956
4145
  get: function () {
@@ -3987,4 +4176,4 @@ Object.defineProperty(exports, 'write_todos', {
3987
4176
  return write_todos;
3988
4177
  }
3989
4178
  });
3990
- //# sourceMappingURL=file-saver-BYPKakT4.cjs.map
4179
+ //# sourceMappingURL=file-saver-BKNL0pg6.cjs.map