MCPcopy
hub / github.com/continuedev/continue / getStringArg

Function getStringArg

core/tools/parseArgs.ts:65–102  ·  view source on GitHub ↗
(
  args: any,
  argName: string,
  allowEmpty = false,
)

Source from the content-addressed store, hash-verified

63}
64
65export function getStringArg(
66 args: any,
67 argName: string,
68 allowEmpty = false,
69): string {
70 if (!args || !(argName in args)) {
71 throw new Error(
72 `\`${argName}\` argument is required${allowEmpty ? "" : " and must not be empty or whitespace-only"}. (type string)`,
73 );
74 }
75
76 let value = args[argName];
77
78 // Handle case where JSON was parsed into an object by the tool call parser.
79 // If the arguments to the tool call are valid JSON (e.g. the model attempts to create a .json file)
80 // the earlier call to JSON.parse() will have deeply parsed the returned arguments.
81 // If that has happened, convert back to string.
82 if (typeof value === "object" && value !== null) {
83 try {
84 value = JSON.stringify(value);
85 return value;
86 } catch (e) {
87 //Swallow this, because it might be fine later.
88 }
89 }
90
91 if (typeof value !== "string") {
92 throw new Error(
93 `\`${argName}\` argument is required${allowEmpty ? "" : " and must not be empty or whitespace-only"}. (type string)`,
94 );
95 }
96
97 if (!allowEmpty && !value.trim()) {
98 throw new Error(`Argument ${argName} must not be empty or whitespace-only`);
99 }
100
101 return value;
102}
103
104export function getOptionalStringArg(
105 args: any,

Callers 15

codebaseToolImplFunction · 0.90
fetchUrlContentImplFunction · 0.90
searchWebImplFunction · 0.90
runTerminalCommandImplFunction · 0.90
createRuleBlockImplFunction · 0.90
viewSubdirectoryImplFunction · 0.90
readSkillImplFunction · 0.90
grepSearchImplFunction · 0.90
fileGlobSearchImplFunction · 0.90
createNewFileImplFunction · 0.90
readFileRangeImplFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected