@xpert-ai/plugin-sdk 3.8.1 → 3.8.4
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/index.cjs.js +238 -70
- package/index.esm.js +218 -71
- package/package.json +1 -1
- package/src/index.d.ts +1 -0
- package/src/lib/ai-model/llm.d.ts +9 -0
- package/src/lib/core/index.d.ts +1 -0
- package/src/lib/core/permissions/general.d.ts +2 -1
- package/src/lib/core/plugin-config.d.ts +9 -0
- package/src/lib/file/file-storage/index.d.ts +3 -0
- package/src/lib/file/file-storage/provider.decorator.d.ts +2 -0
- package/src/lib/file/file-storage/provider.interface.d.ts +14 -0
- package/src/lib/file/file-storage/provider.registry.d.ts +6 -0
- package/src/lib/file/file-upload/index.d.ts +3 -0
- package/src/lib/file/file-upload/strategy.decorator.d.ts +2 -0
- package/src/lib/file/file-upload/strategy.interface.d.ts +25 -0
- package/src/lib/file/file-upload/strategy.registry.d.ts +6 -0
- package/src/lib/file/index.d.ts +2 -0
- package/src/lib/integration/strategy.interface.d.ts +15 -3
- package/src/lib/sandbox/execution.d.ts +27 -0
- package/src/lib/sandbox/index.d.ts +1 -0
- package/src/lib/sandbox/protocol.d.ts +8 -3
- package/src/lib/sandbox/sandbox.d.ts +10 -3
- package/src/lib/sandbox/sandbox.interface.d.ts +7 -11
- package/src/lib/types.d.ts +3 -1
package/index.cjs.js
CHANGED
|
@@ -956,6 +956,8 @@ BuiltinToolset.provider = '';
|
|
|
956
956
|
}
|
|
957
957
|
}
|
|
958
958
|
|
|
959
|
+
const PLUGIN_CONFIG_RESOLVER_TOKEN = 'XPERT_PLUGIN_CONFIG_RESOLVER';
|
|
960
|
+
|
|
959
961
|
/**
|
|
960
962
|
* System token for resolving integration read service from plugin context.
|
|
961
963
|
*/ const INTEGRATION_PERMISSION_SERVICE_TOKEN = 'XPERT_PLUGIN_INTEGRATION_PERMISSION_SERVICE';
|
|
@@ -2009,11 +2011,11 @@ class LLMUsage {
|
|
|
2009
2011
|
}
|
|
2010
2012
|
plus(other) {
|
|
2011
2013
|
/**
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2014
|
+
* Add two LLMUsage instances together.
|
|
2015
|
+
*
|
|
2016
|
+
* @param other: Another LLMUsage instance to add
|
|
2017
|
+
* @return: A new LLMUsage instance with summed values
|
|
2018
|
+
*/ if (this.totalTokens === 0) {
|
|
2017
2019
|
return other;
|
|
2018
2020
|
} else {
|
|
2019
2021
|
return new LLMUsage(this.promptTokens + other.promptTokens, other.promptUnitPrice, other.promptPriceUnit, this.promptPrice + other.promptPrice, this.completionTokens + other.completionTokens, other.completionUnitPrice, other.completionPriceUnit, this.completionPrice + other.completionPrice, this.totalTokens + other.totalTokens, this.totalPrice + other.totalPrice, other.currency, this.latency + other.latency);
|
|
@@ -2021,11 +2023,11 @@ class LLMUsage {
|
|
|
2021
2023
|
}
|
|
2022
2024
|
add(other) {
|
|
2023
2025
|
/**
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2026
|
+
* Overload the + operator to add two LLMUsage instances.
|
|
2027
|
+
*
|
|
2028
|
+
* @param other: Another LLMUsage instance to add
|
|
2029
|
+
* @return: A new LLMUsage instance with summed values
|
|
2030
|
+
*/ return this.plus(other);
|
|
2029
2031
|
}
|
|
2030
2032
|
constructor(promptTokens, promptUnitPrice, promptPriceUnit, promptPrice, completionTokens, completionUnitPrice, completionPriceUnit, completionPrice, totalTokens, totalPrice, currency, latency){
|
|
2031
2033
|
this.promptTokens = promptTokens;
|
|
@@ -2145,6 +2147,78 @@ class LargeLanguageModel extends AIModel {
|
|
|
2145
2147
|
}
|
|
2146
2148
|
};
|
|
2147
2149
|
}
|
|
2150
|
+
createHandleVerboseCallbacks(enabled, logger) {
|
|
2151
|
+
if (!enabled) {
|
|
2152
|
+
return [];
|
|
2153
|
+
}
|
|
2154
|
+
const targetLogger = logger != null ? logger : _class_private_field_loose_base(this, _logger)[_logger];
|
|
2155
|
+
return [
|
|
2156
|
+
{
|
|
2157
|
+
handleChatModelStart: (llm, messages, runId, parentRunId, extraParams, tags, metadata, runName)=>{
|
|
2158
|
+
targetLogger.verbose(this.formatVerboseLog('chat_model/start', {
|
|
2159
|
+
runId,
|
|
2160
|
+
parentRunId,
|
|
2161
|
+
runName,
|
|
2162
|
+
model: llm,
|
|
2163
|
+
messages,
|
|
2164
|
+
extraParams,
|
|
2165
|
+
tags,
|
|
2166
|
+
metadata
|
|
2167
|
+
}));
|
|
2168
|
+
},
|
|
2169
|
+
handleLLMStart: (llm, prompts, runId, parentRunId, extraParams, tags, metadata, runName)=>{
|
|
2170
|
+
targetLogger.verbose(this.formatVerboseLog('llm/start', {
|
|
2171
|
+
runId,
|
|
2172
|
+
parentRunId,
|
|
2173
|
+
runName,
|
|
2174
|
+
model: llm,
|
|
2175
|
+
prompts,
|
|
2176
|
+
extraParams,
|
|
2177
|
+
tags,
|
|
2178
|
+
metadata
|
|
2179
|
+
}));
|
|
2180
|
+
},
|
|
2181
|
+
handleLLMEnd: (output, runId, parentRunId, tags, extraParams)=>{
|
|
2182
|
+
targetLogger.verbose(this.formatVerboseLog('llm/end', {
|
|
2183
|
+
runId,
|
|
2184
|
+
parentRunId,
|
|
2185
|
+
output,
|
|
2186
|
+
tags,
|
|
2187
|
+
extraParams
|
|
2188
|
+
}));
|
|
2189
|
+
},
|
|
2190
|
+
handleLLMError: (err, runId, parentRunId, tags, extraParams)=>{
|
|
2191
|
+
targetLogger.verbose(this.formatVerboseLog('llm/error', {
|
|
2192
|
+
runId,
|
|
2193
|
+
parentRunId,
|
|
2194
|
+
error: this.formatError(err),
|
|
2195
|
+
tags,
|
|
2196
|
+
extraParams
|
|
2197
|
+
}));
|
|
2198
|
+
}
|
|
2199
|
+
}
|
|
2200
|
+
];
|
|
2201
|
+
}
|
|
2202
|
+
formatVerboseLog(event, payload) {
|
|
2203
|
+
return `[langchain][${event}] ${this.stringifyLogPayload(payload)}`;
|
|
2204
|
+
}
|
|
2205
|
+
stringifyLogPayload(payload) {
|
|
2206
|
+
try {
|
|
2207
|
+
return JSON.stringify(payload, null, 2);
|
|
2208
|
+
} catch (error) {
|
|
2209
|
+
return `[unserializable payload: ${this.formatError(error)}]`;
|
|
2210
|
+
}
|
|
2211
|
+
}
|
|
2212
|
+
formatError(error) {
|
|
2213
|
+
if (error instanceof Error) {
|
|
2214
|
+
return {
|
|
2215
|
+
name: error.name,
|
|
2216
|
+
message: error.message,
|
|
2217
|
+
stack: error.stack
|
|
2218
|
+
};
|
|
2219
|
+
}
|
|
2220
|
+
return error;
|
|
2221
|
+
}
|
|
2148
2222
|
constructor(...args){
|
|
2149
2223
|
super(...args);
|
|
2150
2224
|
Object.defineProperty(this, _logger, {
|
|
@@ -2635,34 +2709,100 @@ class CancelConversationCommand {
|
|
|
2635
2709
|
}
|
|
2636
2710
|
CancelConversationCommand.type = '[Chat Conversation] Cancel';
|
|
2637
2711
|
|
|
2712
|
+
const FILE_STORAGE_PROVIDER = 'FILE_STORAGE_PROVIDER';
|
|
2713
|
+
const FileStorageProvider = (provider)=>common.applyDecorators(common.SetMetadata(FILE_STORAGE_PROVIDER, provider), common.SetMetadata(STRATEGY_META_KEY, FILE_STORAGE_PROVIDER));
|
|
2714
|
+
|
|
2715
|
+
exports.FileStorageProviderRegistry = class FileStorageProviderRegistry extends BaseStrategyRegistry {
|
|
2716
|
+
constructor(discoveryService, reflector){
|
|
2717
|
+
super(FILE_STORAGE_PROVIDER, discoveryService, reflector);
|
|
2718
|
+
}
|
|
2719
|
+
};
|
|
2720
|
+
exports.FileStorageProviderRegistry = __decorate([
|
|
2721
|
+
common.Injectable(),
|
|
2722
|
+
__metadata("design:type", Function),
|
|
2723
|
+
__metadata("design:paramtypes", [
|
|
2724
|
+
typeof core.DiscoveryService === "undefined" ? Object : core.DiscoveryService,
|
|
2725
|
+
typeof core.Reflector === "undefined" ? Object : core.Reflector
|
|
2726
|
+
])
|
|
2727
|
+
], exports.FileStorageProviderRegistry);
|
|
2728
|
+
|
|
2729
|
+
const FILE_UPLOAD_TARGET_STRATEGY = 'FILE_UPLOAD_TARGET_STRATEGY';
|
|
2730
|
+
const FileUploadTargetStrategy = (type)=>common.applyDecorators(common.SetMetadata(FILE_UPLOAD_TARGET_STRATEGY, type), common.SetMetadata(STRATEGY_META_KEY, FILE_UPLOAD_TARGET_STRATEGY));
|
|
2731
|
+
|
|
2732
|
+
exports.FileUploadTargetRegistry = class FileUploadTargetRegistry extends BaseStrategyRegistry {
|
|
2733
|
+
constructor(discoveryService, reflector){
|
|
2734
|
+
super(FILE_UPLOAD_TARGET_STRATEGY, discoveryService, reflector);
|
|
2735
|
+
}
|
|
2736
|
+
};
|
|
2737
|
+
exports.FileUploadTargetRegistry = __decorate([
|
|
2738
|
+
common.Injectable(),
|
|
2739
|
+
__metadata("design:type", Function),
|
|
2740
|
+
__metadata("design:paramtypes", [
|
|
2741
|
+
typeof core.DiscoveryService === "undefined" ? Object : core.DiscoveryService,
|
|
2742
|
+
typeof core.Reflector === "undefined" ? Object : core.Reflector
|
|
2743
|
+
])
|
|
2744
|
+
], exports.FileUploadTargetRegistry);
|
|
2745
|
+
|
|
2746
|
+
const SANDBOX_SHELL_TIMEOUT_LIMITS_SEC = {
|
|
2747
|
+
min: 1,
|
|
2748
|
+
max: 3600
|
|
2749
|
+
};
|
|
2750
|
+
const DEFAULT_SANDBOX_SHELL_TIMEOUT_SEC = 600;
|
|
2751
|
+
const DEFAULT_SANDBOX_FILE_SEARCH_TIMEOUT_SEC = 120;
|
|
2752
|
+
const DEFAULT_SANDBOX_FILE_OPERATION_TIMEOUT_SEC = 120;
|
|
2753
|
+
const DEFAULT_SANDBOX_SHELL_TIMEOUT_MS = DEFAULT_SANDBOX_SHELL_TIMEOUT_SEC * 1000;
|
|
2754
|
+
const DEFAULT_SANDBOX_FILE_SEARCH_TIMEOUT_MS = DEFAULT_SANDBOX_FILE_SEARCH_TIMEOUT_SEC * 1000;
|
|
2755
|
+
const DEFAULT_SANDBOX_FILE_OPERATION_TIMEOUT_MS = DEFAULT_SANDBOX_FILE_OPERATION_TIMEOUT_SEC * 1000;
|
|
2756
|
+
const DEFAULT_SANDBOX_EXECUTION_MAX_OUTPUT_BYTES = 1024 * 1024;
|
|
2757
|
+
const DEFAULT_SANDBOX_SHELL_EXECUTION_OPTIONS = {
|
|
2758
|
+
timeoutMs: DEFAULT_SANDBOX_SHELL_TIMEOUT_MS,
|
|
2759
|
+
maxOutputBytes: DEFAULT_SANDBOX_EXECUTION_MAX_OUTPUT_BYTES
|
|
2760
|
+
};
|
|
2761
|
+
const DEFAULT_SANDBOX_FILE_SEARCH_EXECUTION_OPTIONS = {
|
|
2762
|
+
timeoutMs: DEFAULT_SANDBOX_FILE_SEARCH_TIMEOUT_MS,
|
|
2763
|
+
maxOutputBytes: DEFAULT_SANDBOX_EXECUTION_MAX_OUTPUT_BYTES
|
|
2764
|
+
};
|
|
2765
|
+
const DEFAULT_SANDBOX_FILE_OPERATION_EXECUTION_OPTIONS = {
|
|
2766
|
+
timeoutMs: DEFAULT_SANDBOX_FILE_OPERATION_TIMEOUT_MS,
|
|
2767
|
+
maxOutputBytes: DEFAULT_SANDBOX_EXECUTION_MAX_OUTPUT_BYTES
|
|
2768
|
+
};
|
|
2769
|
+
function secondsToMilliseconds(seconds) {
|
|
2770
|
+
return Math.trunc(seconds * 1000);
|
|
2771
|
+
}
|
|
2772
|
+
function formatSandboxTimeout(timeoutMs) {
|
|
2773
|
+
const timeoutSeconds = timeoutMs / 1000;
|
|
2774
|
+
const secondsLabel = Number.isInteger(timeoutSeconds) ? String(timeoutSeconds) : Number(timeoutSeconds.toFixed(3)).toString();
|
|
2775
|
+
return `${secondsLabel}s (${timeoutMs}ms)`;
|
|
2776
|
+
}
|
|
2777
|
+
function buildSandboxTimeoutMessage(subject, timeoutMs) {
|
|
2778
|
+
return `${subject} timed out after ${formatSandboxTimeout(timeoutMs)}`;
|
|
2779
|
+
}
|
|
2780
|
+
function appendSandboxMessage(output, message) {
|
|
2781
|
+
return output ? `${output}\n${message}` : message;
|
|
2782
|
+
}
|
|
2783
|
+
function resolveSandboxExecutionOptions(options, defaults = DEFAULT_SANDBOX_SHELL_EXECUTION_OPTIONS) {
|
|
2784
|
+
const timeoutMs = typeof (options == null ? void 0 : options.timeoutMs) === 'number' && Number.isFinite(options.timeoutMs) && options.timeoutMs > 0 ? Math.trunc(options.timeoutMs) : typeof defaults.timeoutMs === 'number' && Number.isFinite(defaults.timeoutMs) && defaults.timeoutMs > 0 ? Math.trunc(defaults.timeoutMs) : DEFAULT_SANDBOX_SHELL_TIMEOUT_MS;
|
|
2785
|
+
const maxOutputBytes = typeof (options == null ? void 0 : options.maxOutputBytes) === 'number' && Number.isFinite(options.maxOutputBytes) && options.maxOutputBytes > 0 ? Math.trunc(options.maxOutputBytes) : typeof defaults.maxOutputBytes === 'number' && Number.isFinite(defaults.maxOutputBytes) && defaults.maxOutputBytes > 0 ? Math.trunc(defaults.maxOutputBytes) : DEFAULT_SANDBOX_EXECUTION_MAX_OUTPUT_BYTES;
|
|
2786
|
+
return {
|
|
2787
|
+
timeoutMs,
|
|
2788
|
+
maxOutputBytes
|
|
2789
|
+
};
|
|
2790
|
+
}
|
|
2791
|
+
|
|
2638
2792
|
/**
|
|
2639
|
-
* Protocol definition for pluggable memory backends.
|
|
2640
|
-
*
|
|
2641
|
-
* This module defines the BackendProtocol that all backend implementations
|
|
2642
|
-
* must follow. Backends can store files in different locations (state, filesystem,
|
|
2643
|
-
* database, etc.) and provide a uniform interface for file operations.
|
|
2644
|
-
*/ /**
|
|
2645
2793
|
* Type guard to check if a backend supports execution.
|
|
2646
2794
|
*
|
|
2647
2795
|
* @param backend - Backend instance to check
|
|
2648
2796
|
* @returns True if the backend implements SandboxBackendProtocol
|
|
2649
2797
|
*/ function isSandboxBackend(backend) {
|
|
2650
|
-
return typeof backend.execute ===
|
|
2798
|
+
return typeof backend.execute === 'function' && typeof backend.id === 'string';
|
|
2651
2799
|
}
|
|
2652
2800
|
|
|
2653
|
-
|
|
2654
|
-
* BaseSandbox: Abstract base class for sandbox backends with command execution.
|
|
2655
|
-
*
|
|
2656
|
-
* This class provides default implementations for all SandboxBackendProtocol
|
|
2657
|
-
* methods using shell commands executed via execute(). Concrete implementations
|
|
2658
|
-
* only need to implement the execute() method.
|
|
2659
|
-
*
|
|
2660
|
-
* Requires Node.js 20+ on the sandbox host.
|
|
2661
|
-
*/ const MAX_LINE_LENGTH = 500;
|
|
2801
|
+
const MAX_LINE_LENGTH = 500;
|
|
2662
2802
|
const MAX_GREP_LINE_LENGTH = 2000;
|
|
2663
2803
|
const GREP_RESULT_LIMIT = 100;
|
|
2664
2804
|
const GLOB_RESULT_LIMIT = 100;
|
|
2665
|
-
const WRITE_EXISTS_OUTPUT =
|
|
2805
|
+
const WRITE_EXISTS_OUTPUT = 'Error: File already exists';
|
|
2666
2806
|
/**
|
|
2667
2807
|
* UTF-8 safe Base64 encoding function.
|
|
2668
2808
|
* Replaces btoa() which only supports Latin1 characters.
|
|
@@ -2676,17 +2816,17 @@ const WRITE_EXISTS_OUTPUT = "Error: File already exists";
|
|
|
2676
2816
|
const truncated = files.length > limit;
|
|
2677
2817
|
const finalFiles = truncated ? files.slice(0, limit) : files;
|
|
2678
2818
|
if (finalFiles.length === 0) {
|
|
2679
|
-
return
|
|
2819
|
+
return 'No files found';
|
|
2680
2820
|
}
|
|
2681
2821
|
const lines = [];
|
|
2682
2822
|
for (const file of finalFiles){
|
|
2683
2823
|
lines.push(file.path);
|
|
2684
2824
|
}
|
|
2685
2825
|
if (truncated) {
|
|
2686
|
-
lines.push(
|
|
2687
|
-
lines.push(
|
|
2826
|
+
lines.push('');
|
|
2827
|
+
lines.push('(Results truncated. Consider using a more specific path or pattern.)');
|
|
2688
2828
|
}
|
|
2689
|
-
return lines.join(
|
|
2829
|
+
return lines.join('\n');
|
|
2690
2830
|
}
|
|
2691
2831
|
/**
|
|
2692
2832
|
* Format grep matches into human-readable output grouped by file.
|
|
@@ -2695,28 +2835,28 @@ const WRITE_EXISTS_OUTPUT = "Error: File already exists";
|
|
|
2695
2835
|
const truncated = matches.length > limit;
|
|
2696
2836
|
const finalMatches = truncated ? matches.slice(0, limit) : matches;
|
|
2697
2837
|
if (finalMatches.length === 0) {
|
|
2698
|
-
return
|
|
2838
|
+
return 'No matches found';
|
|
2699
2839
|
}
|
|
2700
2840
|
const lines = [
|
|
2701
2841
|
`Found ${finalMatches.length} matches`
|
|
2702
2842
|
];
|
|
2703
|
-
let currentFile =
|
|
2843
|
+
let currentFile = '';
|
|
2704
2844
|
for (const match of finalMatches){
|
|
2705
2845
|
if (currentFile !== match.path) {
|
|
2706
|
-
if (currentFile !==
|
|
2707
|
-
lines.push(
|
|
2846
|
+
if (currentFile !== '') {
|
|
2847
|
+
lines.push('');
|
|
2708
2848
|
}
|
|
2709
2849
|
currentFile = match.path;
|
|
2710
2850
|
lines.push(`${match.path}:`);
|
|
2711
2851
|
}
|
|
2712
|
-
const text = match.text.length > MAX_GREP_LINE_LENGTH ? match.text.substring(0, MAX_GREP_LINE_LENGTH) +
|
|
2852
|
+
const text = match.text.length > MAX_GREP_LINE_LENGTH ? match.text.substring(0, MAX_GREP_LINE_LENGTH) + '...' : match.text;
|
|
2713
2853
|
lines.push(` Line ${match.line}: ${text}`);
|
|
2714
2854
|
}
|
|
2715
2855
|
if (truncated) {
|
|
2716
|
-
lines.push(
|
|
2717
|
-
lines.push(
|
|
2856
|
+
lines.push('');
|
|
2857
|
+
lines.push('(Results truncated. Consider using a more specific path or pattern.)');
|
|
2718
2858
|
}
|
|
2719
|
-
return lines.join(
|
|
2859
|
+
return lines.join('\n');
|
|
2720
2860
|
}
|
|
2721
2861
|
/**
|
|
2722
2862
|
* Node.js command template for glob operations.
|
|
@@ -3197,14 +3337,14 @@ console.log(count);
|
|
|
3197
3337
|
*/ function buildGrepCommand(pattern, searchPath, globPattern) {
|
|
3198
3338
|
const patternB64 = utf8ToBase64(pattern);
|
|
3199
3339
|
const pathB64 = utf8ToBase64(searchPath);
|
|
3200
|
-
const globB64 = globPattern ? utf8ToBase64(globPattern) :
|
|
3340
|
+
const globB64 = globPattern ? utf8ToBase64(globPattern) : '';
|
|
3201
3341
|
return `node -e "
|
|
3202
3342
|
const fs = require('fs');
|
|
3203
3343
|
const path = require('path');
|
|
3204
3344
|
|
|
3205
3345
|
const pattern = Buffer.from('${patternB64}', 'base64').toString('utf-8');
|
|
3206
3346
|
const searchPath = Buffer.from('${pathB64}', 'base64').toString('utf-8');
|
|
3207
|
-
const globPattern = ${globPattern ? `Buffer.from('${globB64}', 'base64').toString('utf-8')` :
|
|
3347
|
+
const globPattern = ${globPattern ? `Buffer.from('${globB64}', 'base64').toString('utf-8')` : 'null'};
|
|
3208
3348
|
|
|
3209
3349
|
let regex;
|
|
3210
3350
|
try {
|
|
@@ -3273,8 +3413,15 @@ try {
|
|
|
3273
3413
|
*
|
|
3274
3414
|
* Requires Node.js 20+ on the sandbox host.
|
|
3275
3415
|
*/ class BaseSandbox {
|
|
3276
|
-
|
|
3277
|
-
|
|
3416
|
+
/**
|
|
3417
|
+
* Internal hook for file/search operations. Concrete backends can override
|
|
3418
|
+
* this to distinguish "background helper commands" from user-facing shell
|
|
3419
|
+
* execute calls.
|
|
3420
|
+
*/ executeOperation(command, options) {
|
|
3421
|
+
return this.execute(command, options);
|
|
3422
|
+
}
|
|
3423
|
+
async streamExecute(command, onLine, options) {
|
|
3424
|
+
const result = await this.execute(command, options);
|
|
3278
3425
|
if (result.output) {
|
|
3279
3426
|
onLine(result.output);
|
|
3280
3427
|
}
|
|
@@ -3287,12 +3434,12 @@ try {
|
|
|
3287
3434
|
* @returns List of FileInfo objects for files and directories directly in the directory.
|
|
3288
3435
|
*/ async lsInfo(path) {
|
|
3289
3436
|
const command = buildLsCommand(path);
|
|
3290
|
-
const result = await this.
|
|
3437
|
+
const result = await this.executeOperation(command, DEFAULT_SANDBOX_FILE_OPERATION_EXECUTION_OPTIONS);
|
|
3291
3438
|
if (result.exitCode !== 0) {
|
|
3292
3439
|
return [];
|
|
3293
3440
|
}
|
|
3294
3441
|
const infos = [];
|
|
3295
|
-
const lines = result.output.trim().split(
|
|
3442
|
+
const lines = result.output.trim().split('\n').filter(Boolean);
|
|
3296
3443
|
for (const line of lines){
|
|
3297
3444
|
try {
|
|
3298
3445
|
const parsed = JSON.parse(line);
|
|
@@ -3318,16 +3465,16 @@ try {
|
|
|
3318
3465
|
* @returns Human-readable directory tree with indentation
|
|
3319
3466
|
*/ async listDir(dirPath, offset = 1, limit = 25, depth = 2) {
|
|
3320
3467
|
if (offset < 1) {
|
|
3321
|
-
return
|
|
3468
|
+
return 'Error: offset must be a 1-indexed entry number';
|
|
3322
3469
|
}
|
|
3323
3470
|
if (limit < 1) {
|
|
3324
|
-
return
|
|
3471
|
+
return 'Error: limit must be greater than zero';
|
|
3325
3472
|
}
|
|
3326
3473
|
if (depth < 1) {
|
|
3327
|
-
return
|
|
3474
|
+
return 'Error: depth must be greater than zero';
|
|
3328
3475
|
}
|
|
3329
3476
|
const command = buildListDirCommand(dirPath, offset, limit, depth);
|
|
3330
|
-
const result = await this.
|
|
3477
|
+
const result = await this.executeOperation(command, DEFAULT_SANDBOX_FILE_OPERATION_EXECUTION_OPTIONS);
|
|
3331
3478
|
if (result.exitCode !== 0) {
|
|
3332
3479
|
return result.output || `Error: Failed to list directory '${dirPath}'`;
|
|
3333
3480
|
}
|
|
@@ -3344,7 +3491,7 @@ try {
|
|
|
3344
3491
|
* @returns Formatted file content with line numbers, or error message
|
|
3345
3492
|
*/ async read(filePath, offset = 1, limit = 2000, mode = 'slice', indentation) {
|
|
3346
3493
|
const command = mode === 'indentation' ? buildIndentationReadCommand(filePath, offset, limit, indentation != null ? indentation : {}) : buildSliceReadCommand(filePath, offset, limit);
|
|
3347
|
-
const result = await this.
|
|
3494
|
+
const result = await this.executeOperation(command, DEFAULT_SANDBOX_FILE_OPERATION_EXECUTION_OPTIONS);
|
|
3348
3495
|
if (result.exitCode !== 0) {
|
|
3349
3496
|
return result.output || `Error: File '${filePath}' not found`;
|
|
3350
3497
|
}
|
|
@@ -3352,17 +3499,17 @@ try {
|
|
|
3352
3499
|
}
|
|
3353
3500
|
/**
|
|
3354
3501
|
* Structured search results or error string for invalid input.
|
|
3355
|
-
*/ async grepRaw(pattern, path =
|
|
3502
|
+
*/ async grepRaw(pattern, path = '/', include = null) {
|
|
3356
3503
|
const command = buildGrepCommand(pattern, path, include);
|
|
3357
|
-
const result = await this.
|
|
3504
|
+
const result = await this.executeOperation(command, DEFAULT_SANDBOX_FILE_SEARCH_EXECUTION_OPTIONS);
|
|
3358
3505
|
if (result.exitCode === 1) {
|
|
3359
3506
|
// Check if it's a regex error
|
|
3360
|
-
if (result.output.includes(
|
|
3507
|
+
if (result.output.includes('Invalid regex:')) {
|
|
3361
3508
|
return result.output.trim();
|
|
3362
3509
|
}
|
|
3363
3510
|
}
|
|
3364
3511
|
const matches = [];
|
|
3365
|
-
const lines = result.output.trim().split(
|
|
3512
|
+
const lines = result.output.trim().split('\n').filter(Boolean);
|
|
3366
3513
|
for (const line of lines){
|
|
3367
3514
|
try {
|
|
3368
3515
|
const parsed = JSON.parse(line);
|
|
@@ -3379,23 +3526,23 @@ try {
|
|
|
3379
3526
|
}
|
|
3380
3527
|
/**
|
|
3381
3528
|
* Search file contents for a regex pattern, returning human-readable output.
|
|
3382
|
-
*/ async grep(pattern, path =
|
|
3529
|
+
*/ async grep(pattern, path = '/', include = null) {
|
|
3383
3530
|
const result = await this.grepRaw(pattern, path, include);
|
|
3384
|
-
if (typeof result ===
|
|
3531
|
+
if (typeof result === 'string') {
|
|
3385
3532
|
return result;
|
|
3386
3533
|
}
|
|
3387
3534
|
if (result.length === 0) {
|
|
3388
|
-
return
|
|
3535
|
+
return 'No matches found';
|
|
3389
3536
|
}
|
|
3390
3537
|
return formatGrepOutput(result);
|
|
3391
3538
|
}
|
|
3392
3539
|
/**
|
|
3393
3540
|
* Structured glob matching returning FileInfo objects.
|
|
3394
|
-
*/ async globInfo(pattern, path =
|
|
3541
|
+
*/ async globInfo(pattern, path = '/') {
|
|
3395
3542
|
const command = buildGlobCommand(path, pattern);
|
|
3396
|
-
const result = await this.
|
|
3543
|
+
const result = await this.executeOperation(command, DEFAULT_SANDBOX_FILE_SEARCH_EXECUTION_OPTIONS);
|
|
3397
3544
|
const infos = [];
|
|
3398
|
-
const lines = result.output.trim().split(
|
|
3545
|
+
const lines = result.output.trim().split('\n').filter(Boolean);
|
|
3399
3546
|
for (const line of lines){
|
|
3400
3547
|
try {
|
|
3401
3548
|
const parsed = JSON.parse(line);
|
|
@@ -3413,10 +3560,10 @@ try {
|
|
|
3413
3560
|
}
|
|
3414
3561
|
/**
|
|
3415
3562
|
* Find files matching a glob pattern, returning human-readable output.
|
|
3416
|
-
*/ async glob(pattern, path =
|
|
3563
|
+
*/ async glob(pattern, path = '/') {
|
|
3417
3564
|
const files = await this.globInfo(pattern, path);
|
|
3418
3565
|
if (files.length === 0) {
|
|
3419
|
-
return
|
|
3566
|
+
return 'No files found';
|
|
3420
3567
|
}
|
|
3421
3568
|
return formatGlobOutput(files);
|
|
3422
3569
|
}
|
|
@@ -3424,9 +3571,9 @@ try {
|
|
|
3424
3571
|
* Create a new file with content.
|
|
3425
3572
|
*/ async write(filePath, content) {
|
|
3426
3573
|
const command = buildWriteCommand(filePath, content);
|
|
3427
|
-
const result = await this.
|
|
3574
|
+
const result = await this.executeOperation(command, DEFAULT_SANDBOX_FILE_OPERATION_EXECUTION_OPTIONS);
|
|
3428
3575
|
if (result.exitCode !== 0) {
|
|
3429
|
-
const output = (result.output ||
|
|
3576
|
+
const output = (result.output || '').trim();
|
|
3430
3577
|
if (output.includes(WRITE_EXISTS_OUTPUT)) {
|
|
3431
3578
|
return {
|
|
3432
3579
|
error: `Cannot write to ${filePath} because it already exists. Read and then make an edit, or write to a new path.`
|
|
@@ -3446,7 +3593,7 @@ try {
|
|
|
3446
3593
|
};
|
|
3447
3594
|
}
|
|
3448
3595
|
async writeViaUpload(filePath, content) {
|
|
3449
|
-
const existsCheck = await this.
|
|
3596
|
+
const existsCheck = await this.executeOperation(buildExistsCommand(filePath), DEFAULT_SANDBOX_FILE_OPERATION_EXECUTION_OPTIONS);
|
|
3450
3597
|
if (existsCheck.exitCode === 0) {
|
|
3451
3598
|
return {
|
|
3452
3599
|
error: `Cannot write to ${filePath} because it already exists. Read and then make an edit, or write to a new path.`
|
|
@@ -3455,7 +3602,7 @@ try {
|
|
|
3455
3602
|
const uploads = await this.uploadFiles([
|
|
3456
3603
|
[
|
|
3457
3604
|
filePath,
|
|
3458
|
-
Buffer.from(content,
|
|
3605
|
+
Buffer.from(content, 'utf-8')
|
|
3459
3606
|
]
|
|
3460
3607
|
]);
|
|
3461
3608
|
const first = uploads[0];
|
|
@@ -3478,9 +3625,9 @@ try {
|
|
|
3478
3625
|
* Append content to a file. Creates the file if it doesn't exist.
|
|
3479
3626
|
*/ async append(filePath, content) {
|
|
3480
3627
|
const command = buildAppendCommand(filePath, content);
|
|
3481
|
-
const result = await this.
|
|
3628
|
+
const result = await this.executeOperation(command, DEFAULT_SANDBOX_FILE_OPERATION_EXECUTION_OPTIONS);
|
|
3482
3629
|
if (result.exitCode !== 0) {
|
|
3483
|
-
const output = (result.output ||
|
|
3630
|
+
const output = (result.output || '').trim();
|
|
3484
3631
|
return {
|
|
3485
3632
|
error: output ? `Failed to append to file '${filePath}': ${output}` : `Failed to append to file '${filePath}'.`
|
|
3486
3633
|
};
|
|
@@ -3494,7 +3641,7 @@ try {
|
|
|
3494
3641
|
* Edit a file by replacing string occurrences.
|
|
3495
3642
|
*/ async edit(filePath, oldString, newString, replaceAll = false) {
|
|
3496
3643
|
const command = buildEditCommand(filePath, oldString, newString, replaceAll);
|
|
3497
|
-
const result = await this.
|
|
3644
|
+
const result = await this.executeOperation(command, DEFAULT_SANDBOX_FILE_OPERATION_EXECUTION_OPTIONS);
|
|
3498
3645
|
switch(result.exitCode){
|
|
3499
3646
|
case 0:
|
|
3500
3647
|
{
|
|
@@ -3530,7 +3677,7 @@ try {
|
|
|
3530
3677
|
*/ async multiEdit(filePath, edits) {
|
|
3531
3678
|
if (!edits || edits.length === 0) {
|
|
3532
3679
|
return {
|
|
3533
|
-
error:
|
|
3680
|
+
error: 'No edits provided'
|
|
3534
3681
|
};
|
|
3535
3682
|
}
|
|
3536
3683
|
const results = [];
|
|
@@ -3617,11 +3764,25 @@ exports.CreateModelClientCommand = CreateModelClientCommand;
|
|
|
3617
3764
|
exports.CredentialsValidateFailedError = CredentialsValidateFailedError;
|
|
3618
3765
|
exports.DATASOURCE_STRATEGY = DATASOURCE_STRATEGY;
|
|
3619
3766
|
exports.DEFAULT_EXECUTION_CONFIG = DEFAULT_EXECUTION_CONFIG;
|
|
3767
|
+
exports.DEFAULT_SANDBOX_EXECUTION_MAX_OUTPUT_BYTES = DEFAULT_SANDBOX_EXECUTION_MAX_OUTPUT_BYTES;
|
|
3768
|
+
exports.DEFAULT_SANDBOX_FILE_OPERATION_EXECUTION_OPTIONS = DEFAULT_SANDBOX_FILE_OPERATION_EXECUTION_OPTIONS;
|
|
3769
|
+
exports.DEFAULT_SANDBOX_FILE_OPERATION_TIMEOUT_MS = DEFAULT_SANDBOX_FILE_OPERATION_TIMEOUT_MS;
|
|
3770
|
+
exports.DEFAULT_SANDBOX_FILE_OPERATION_TIMEOUT_SEC = DEFAULT_SANDBOX_FILE_OPERATION_TIMEOUT_SEC;
|
|
3771
|
+
exports.DEFAULT_SANDBOX_FILE_SEARCH_EXECUTION_OPTIONS = DEFAULT_SANDBOX_FILE_SEARCH_EXECUTION_OPTIONS;
|
|
3772
|
+
exports.DEFAULT_SANDBOX_FILE_SEARCH_TIMEOUT_MS = DEFAULT_SANDBOX_FILE_SEARCH_TIMEOUT_MS;
|
|
3773
|
+
exports.DEFAULT_SANDBOX_FILE_SEARCH_TIMEOUT_SEC = DEFAULT_SANDBOX_FILE_SEARCH_TIMEOUT_SEC;
|
|
3774
|
+
exports.DEFAULT_SANDBOX_SHELL_EXECUTION_OPTIONS = DEFAULT_SANDBOX_SHELL_EXECUTION_OPTIONS;
|
|
3775
|
+
exports.DEFAULT_SANDBOX_SHELL_TIMEOUT_MS = DEFAULT_SANDBOX_SHELL_TIMEOUT_MS;
|
|
3776
|
+
exports.DEFAULT_SANDBOX_SHELL_TIMEOUT_SEC = DEFAULT_SANDBOX_SHELL_TIMEOUT_SEC;
|
|
3620
3777
|
exports.DOCUMENT_SOURCE_STRATEGY = DOCUMENT_SOURCE_STRATEGY;
|
|
3621
3778
|
exports.DOCUMENT_TRANSFORMER_STRATEGY = DOCUMENT_TRANSFORMER_STRATEGY;
|
|
3622
3779
|
exports.DataSourceStrategy = DataSourceStrategy;
|
|
3623
3780
|
exports.DocumentSourceStrategy = DocumentSourceStrategy;
|
|
3624
3781
|
exports.DocumentTransformerStrategy = DocumentTransformerStrategy;
|
|
3782
|
+
exports.FILE_STORAGE_PROVIDER = FILE_STORAGE_PROVIDER;
|
|
3783
|
+
exports.FILE_UPLOAD_TARGET_STRATEGY = FILE_UPLOAD_TARGET_STRATEGY;
|
|
3784
|
+
exports.FileStorageProvider = FileStorageProvider;
|
|
3785
|
+
exports.FileUploadTargetStrategy = FileUploadTargetStrategy;
|
|
3625
3786
|
exports.GLOBAL_ORGANIZATION_SCOPE = GLOBAL_ORGANIZATION_SCOPE;
|
|
3626
3787
|
exports.HANDOFF_PERMISSION_SERVICE_TOKEN = HANDOFF_PERMISSION_SERVICE_TOKEN;
|
|
3627
3788
|
exports.HANDOFF_PROCESSOR_STRATEGY = HANDOFF_PROCESSOR_STRATEGY;
|
|
@@ -3641,6 +3802,7 @@ exports.LargeLanguageModel = LargeLanguageModel;
|
|
|
3641
3802
|
exports.ORGANIZATION_METADATA_KEY = ORGANIZATION_METADATA_KEY;
|
|
3642
3803
|
exports.OpenAICompatibleReranker = OpenAICompatibleReranker;
|
|
3643
3804
|
exports.PERMISSION_OPERATION_METADATA_KEY = PERMISSION_OPERATION_METADATA_KEY;
|
|
3805
|
+
exports.PLUGIN_CONFIG_RESOLVER_TOKEN = PLUGIN_CONFIG_RESOLVER_TOKEN;
|
|
3644
3806
|
exports.PLUGIN_METADATA = PLUGIN_METADATA;
|
|
3645
3807
|
exports.PLUGIN_METADATA_KEY = PLUGIN_METADATA_KEY;
|
|
3646
3808
|
exports.PROVIDE_AI_MODEL_LLM = PROVIDE_AI_MODEL_LLM;
|
|
@@ -3655,6 +3817,7 @@ exports.RequirePermissionOperation = RequirePermissionOperation;
|
|
|
3655
3817
|
exports.RerankModel = RerankModel;
|
|
3656
3818
|
exports.RetrieverStrategy = RetrieverStrategy;
|
|
3657
3819
|
exports.SANDBOX_PROVIDER = SANDBOX_PROVIDER;
|
|
3820
|
+
exports.SANDBOX_SHELL_TIMEOUT_LIMITS_SEC = SANDBOX_SHELL_TIMEOUT_LIMITS_SEC;
|
|
3658
3821
|
exports.STRATEGY_META_KEY = STRATEGY_META_KEY;
|
|
3659
3822
|
exports.SandboxProviderStrategy = SandboxProviderStrategy;
|
|
3660
3823
|
exports.Speech2TextChatModel = Speech2TextChatModel;
|
|
@@ -3676,6 +3839,8 @@ exports.WrapWorkflowNodeExecutionCommand = WrapWorkflowNodeExecutionCommand;
|
|
|
3676
3839
|
exports.XpFileSystem = XpFileSystem;
|
|
3677
3840
|
exports.XpertServerPlugin = XpertServerPlugin;
|
|
3678
3841
|
exports.als = als;
|
|
3842
|
+
exports.appendSandboxMessage = appendSandboxMessage;
|
|
3843
|
+
exports.buildSandboxTimeoutMessage = buildSandboxTimeoutMessage;
|
|
3679
3844
|
exports.calcTokenUsage = calcTokenUsage;
|
|
3680
3845
|
exports.chunkText = chunkText;
|
|
3681
3846
|
exports.countTokensSafe = countTokensSafe;
|
|
@@ -3684,6 +3849,7 @@ exports.createPluginLogger = createPluginLogger;
|
|
|
3684
3849
|
exports.defineAgentMessageType = defineAgentMessageType;
|
|
3685
3850
|
exports.defineChannelMessageType = defineChannelMessageType;
|
|
3686
3851
|
exports.downloadRemoteFile = downloadRemoteFile;
|
|
3852
|
+
exports.formatSandboxTimeout = formatSandboxTimeout;
|
|
3687
3853
|
exports.getErrorMessage = getErrorMessage;
|
|
3688
3854
|
exports.getModelContextSize = getModelContextSize;
|
|
3689
3855
|
exports.getPermissionOperationMetadata = getPermissionOperationMetadata;
|
|
@@ -3698,5 +3864,7 @@ exports.loadYamlFile = loadYamlFile;
|
|
|
3698
3864
|
exports.mergeCredentials = mergeCredentials;
|
|
3699
3865
|
exports.mergeParentChildChunks = mergeParentChildChunks;
|
|
3700
3866
|
exports.normalizeContextSize = normalizeContextSize;
|
|
3867
|
+
exports.resolveSandboxExecutionOptions = resolveSandboxExecutionOptions;
|
|
3701
3868
|
exports.runWithRequestContext = runWithRequestContext;
|
|
3869
|
+
exports.secondsToMilliseconds = secondsToMilliseconds;
|
|
3702
3870
|
exports.sumTokenUsage = sumTokenUsage;
|