@standardagents/builder 0.12.8 → 0.12.9

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/dist/index.js CHANGED
@@ -9344,49 +9344,55 @@ function transformModelData(data) {
9344
9344
  return transformed;
9345
9345
  }
9346
9346
  function validateModelData(data) {
9347
+ const errors = {};
9347
9348
  if (!data.name || typeof data.name !== "string") {
9348
- return "Model name is required and must be a string";
9349
+ errors["name"] = "Model name is required";
9349
9350
  }
9350
9351
  if (!data.provider || typeof data.provider !== "string") {
9351
- return "Model provider is required and must be a string";
9352
- }
9353
- const validProviders = Object.keys(PROVIDER_PACKAGE_MAP);
9354
- if (!validProviders.includes(data.provider)) {
9355
- return `Invalid provider '${data.provider}'. Must be one of: ${validProviders.join(", ")}`;
9352
+ errors["provider"] = "Provider is required";
9353
+ } else {
9354
+ const validProviders = Object.keys(PROVIDER_PACKAGE_MAP);
9355
+ if (!validProviders.includes(data.provider)) {
9356
+ errors["provider"] = `Invalid provider '${data.provider}'. Must be one of: ${validProviders.join(", ")}`;
9357
+ }
9356
9358
  }
9357
9359
  if (!data.model || typeof data.model !== "string") {
9358
- return "Model ID is required and must be a string";
9360
+ errors["model"] = "Model ID is required";
9359
9361
  }
9360
9362
  if (data.inputPrice !== void 0 && typeof data.inputPrice !== "number") {
9361
- return "inputPrice must be a number";
9363
+ errors["input_price"] = "Input price must be a number";
9362
9364
  }
9363
9365
  if (data.outputPrice !== void 0 && typeof data.outputPrice !== "number") {
9364
- return "outputPrice must be a number";
9366
+ errors["output_price"] = "Output price must be a number";
9365
9367
  }
9366
9368
  if (data.cachedPrice !== void 0 && typeof data.cachedPrice !== "number") {
9367
- return "cachedPrice must be a number";
9369
+ errors["cached_price"] = "Cached price must be a number";
9368
9370
  }
9369
9371
  if (data.fallbacks !== void 0) {
9370
9372
  if (!Array.isArray(data.fallbacks)) {
9371
- return "fallbacks must be an array";
9372
- }
9373
- for (const fallback of data.fallbacks) {
9374
- if (typeof fallback !== "string") {
9375
- return "Each fallback must be a string (model name)";
9373
+ errors["fallbacks"] = "Fallbacks must be an array";
9374
+ } else {
9375
+ for (const fallback of data.fallbacks) {
9376
+ if (typeof fallback !== "string") {
9377
+ errors["fallbacks"] = "Each fallback must be a string (model name)";
9378
+ break;
9379
+ }
9376
9380
  }
9377
9381
  }
9378
9382
  }
9379
9383
  if (data.includedProviders !== void 0) {
9380
9384
  if (!Array.isArray(data.includedProviders)) {
9381
- return "includedProviders must be an array";
9382
- }
9383
- for (const provider of data.includedProviders) {
9384
- if (typeof provider !== "string") {
9385
- return "Each includedProvider must be a string";
9385
+ errors["included_providers"] = "Included providers must be an array";
9386
+ } else {
9387
+ for (const provider of data.includedProviders) {
9388
+ if (typeof provider !== "string") {
9389
+ errors["included_providers"] = "Each included provider must be a string";
9390
+ break;
9391
+ }
9386
9392
  }
9387
9393
  }
9388
9394
  }
9389
- return null;
9395
+ return Object.keys(errors).length > 0 ? errors : null;
9390
9396
  }
9391
9397
  function transformPromptData(data) {
9392
9398
  const transformed = {};
@@ -9417,8 +9423,11 @@ function transformPromptData(data) {
9417
9423
  if (transformed.reasoningEffort) {
9418
9424
  transformed.reasoning.effort = transformed.reasoningEffort;
9419
9425
  }
9420
- if (transformed.reasoningMaxTokens) {
9421
- transformed.reasoning.maxTokens = transformed.reasoningMaxTokens;
9426
+ if (transformed.reasoningMaxTokens !== void 0 && transformed.reasoningMaxTokens !== null && transformed.reasoningMaxTokens !== "") {
9427
+ const num = Number(transformed.reasoningMaxTokens);
9428
+ if (!isNaN(num)) {
9429
+ transformed.reasoning.maxTokens = num;
9430
+ }
9422
9431
  }
9423
9432
  if (transformed.reasoningExclude !== void 0) {
9424
9433
  transformed.reasoning.exclude = transformed.reasoningExclude;
@@ -9522,51 +9531,56 @@ async function renamePrompt(promptsDir, oldName, newName) {
9522
9531
  }
9523
9532
  }
9524
9533
  function validatePromptData(data) {
9534
+ const errors = {};
9525
9535
  if (!data.name || typeof data.name !== "string") {
9526
- return "Prompt name is required and must be a string";
9527
- }
9528
- if (data.name.includes("/")) {
9529
- return "Prompt name cannot contain '/'. Reserved for namespace qualification.";
9536
+ errors["name"] = "Prompt name is required";
9537
+ } else if (data.name.includes("/")) {
9538
+ errors["name"] = "Prompt name cannot contain '/'";
9530
9539
  }
9531
9540
  if (!data.model || typeof data.model !== "string") {
9532
- return "Prompt model is required and must be a string";
9541
+ errors["model_id"] = "Model is required";
9533
9542
  }
9534
9543
  if (data.toolDescription !== void 0 && typeof data.toolDescription !== "string") {
9535
- return "toolDescription must be a string";
9544
+ errors["tool_description"] = "Tool description must be a string";
9536
9545
  }
9537
9546
  if (data.prompt !== void 0 && typeof data.prompt !== "string") {
9538
- return "prompt must be a string";
9547
+ errors["prompt"] = "Prompt must be a string";
9539
9548
  }
9540
- const booleanFields = ["includeChat", "includePastTools", "parallelToolCalls"];
9541
- for (const field of booleanFields) {
9542
- if (data[field] !== void 0 && typeof data[field] !== "boolean") {
9543
- return `${field} must be a boolean`;
9549
+ const booleanFieldMap = {
9550
+ includeChat: "include_chat",
9551
+ includePastTools: "include_past_tools",
9552
+ parallelToolCalls: "parallel_tool_calls"
9553
+ };
9554
+ for (const [camelField, snakeField] of Object.entries(booleanFieldMap)) {
9555
+ if (data[camelField] !== void 0 && typeof data[camelField] !== "boolean") {
9556
+ errors[snakeField] = `${snakeField} must be a boolean`;
9544
9557
  }
9545
9558
  }
9546
9559
  if (data.toolChoice !== void 0) {
9547
9560
  const validChoices = ["auto", "none", "required"];
9548
9561
  if (!validChoices.includes(data.toolChoice)) {
9549
- return `Invalid toolChoice '${data.toolChoice}'. Must be one of: ${validChoices.join(", ")}`;
9562
+ errors["tool_choice"] = `Invalid tool choice '${data.toolChoice}'. Must be one of: ${validChoices.join(", ")}`;
9550
9563
  }
9551
9564
  }
9552
9565
  if (data.tools !== void 0 && !Array.isArray(data.tools)) {
9553
- return "tools must be an array";
9566
+ errors["tools"] = "Tools must be an array";
9554
9567
  }
9555
9568
  if (data.reasoning !== void 0) {
9556
9569
  if (typeof data.reasoning !== "object") {
9557
- return "reasoning must be an object";
9558
- }
9559
- if (data.reasoning.effort !== void 0) {
9560
- const validEfforts = ["low", "medium", "high"];
9561
- if (!validEfforts.includes(data.reasoning.effort)) {
9562
- return `Invalid reasoning.effort '${data.reasoning.effort}'. Must be one of: ${validEfforts.join(", ")}`;
9570
+ errors["reasoning_effort"] = "Reasoning configuration is invalid";
9571
+ } else {
9572
+ if (data.reasoning.effort !== void 0) {
9573
+ const validEfforts = ["low", "medium", "high"];
9574
+ if (!validEfforts.includes(data.reasoning.effort)) {
9575
+ errors["reasoning_effort"] = `Invalid reasoning effort '${data.reasoning.effort}'. Must be one of: ${validEfforts.join(", ")}`;
9576
+ }
9577
+ }
9578
+ if (data.reasoning.maxTokens !== void 0 && typeof data.reasoning.maxTokens !== "number") {
9579
+ errors["reasoning_max_tokens"] = "Max reasoning tokens must be a number";
9563
9580
  }
9564
- }
9565
- if (data.reasoning.maxTokens !== void 0 && typeof data.reasoning.maxTokens !== "number") {
9566
- return "reasoning.maxTokens must be a number";
9567
9581
  }
9568
9582
  }
9569
- return null;
9583
+ return Object.keys(errors).length > 0 ? errors : null;
9570
9584
  }
9571
9585
  function transformAgentData(data) {
9572
9586
  const transformed = {
@@ -9826,69 +9840,65 @@ function escapeRegExp(string) {
9826
9840
  return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
9827
9841
  }
9828
9842
  function validateAgentData(data) {
9843
+ const errors = {};
9829
9844
  if (!data.name || typeof data.name !== "string") {
9830
- return "Agent name is required and must be a string";
9831
- }
9832
- if (data.name.includes("/")) {
9833
- return "Agent name cannot contain '/'. Reserved for namespace qualification.";
9845
+ errors["name"] = "Agent name is required";
9846
+ } else if (data.name.includes("/")) {
9847
+ errors["name"] = "Agent name cannot contain '/'";
9834
9848
  }
9835
9849
  if (data.title !== void 0 && typeof data.title !== "string") {
9836
- return "Agent title must be a string if provided";
9850
+ errors["title"] = "Agent title must be a string";
9837
9851
  }
9838
9852
  if (data.type !== void 0) {
9839
9853
  const validTypes = ["ai_human", "dual_ai"];
9840
9854
  if (!validTypes.includes(data.type)) {
9841
- return `Invalid type '${data.type}'. Must be one of: ${validTypes.join(", ")}`;
9855
+ errors["type"] = `Invalid type '${data.type}'. Must be one of: ${validTypes.join(", ")}`;
9842
9856
  }
9843
9857
  }
9844
9858
  if (!data.sideA || typeof data.sideA !== "object") {
9845
- return "sideA configuration is required";
9846
- }
9847
- if (!data.sideA.prompt || typeof data.sideA.prompt !== "string") {
9848
- return "sideA.prompt is required and must be a string";
9849
- }
9850
- if (data.sideA.label !== void 0 && typeof data.sideA.label !== "string") {
9851
- return "sideA.label must be a string";
9852
- }
9853
- if (data.sideA.stopOnResponse !== void 0 && typeof data.sideA.stopOnResponse !== "boolean") {
9854
- return "sideA.stopOnResponse must be a boolean";
9855
- }
9856
- if (data.sideA.stopTool !== void 0 && typeof data.sideA.stopTool !== "string") {
9857
- return "sideA.stopTool must be a string";
9858
- }
9859
- if (data.sideA.stopTool && !data.sideA.stopToolResponseProperty) {
9860
- return "sideA.stopToolResponseProperty is required when sideA.stopTool is set";
9861
- }
9862
- if (data.sideA.maxSteps !== void 0) {
9863
- if (typeof data.sideA.maxSteps !== "number" || data.sideA.maxSteps <= 0) {
9864
- return "sideA.maxSteps must be a positive number";
9859
+ errors["side_a_agent_prompt"] = "Side A configuration is required";
9860
+ } else {
9861
+ if (!data.sideA.prompt || typeof data.sideA.prompt !== "string") {
9862
+ errors["side_a_agent_prompt"] = "Side A prompt is required";
9865
9863
  }
9866
- }
9867
- if (data.type === "dual_ai") {
9868
- if (!data.sideB || typeof data.sideB !== "object") {
9869
- return "sideB configuration is required for dual_ai type";
9864
+ if (data.sideA.label !== void 0 && typeof data.sideA.label !== "string") {
9865
+ errors["side_a_label"] = "Side A label must be a string";
9870
9866
  }
9871
- if (!data.sideB.prompt || typeof data.sideB.prompt !== "string") {
9872
- return "sideB.prompt is required for dual_ai type";
9867
+ if (data.sideA.stopTool && !data.sideA.stopToolResponseProperty) {
9868
+ errors["side_a_stop_tool_response_property"] = "Response property is required when stop tool is set";
9873
9869
  }
9874
- if (data.sideB.stopTool && !data.sideB.stopToolResponseProperty) {
9875
- return "sideB.stopToolResponseProperty is required when sideB.stopTool is set";
9870
+ if (data.sideA.maxSteps !== void 0) {
9871
+ if (typeof data.sideA.maxSteps !== "number" || data.sideA.maxSteps <= 0) {
9872
+ errors["side_a_max_steps"] = "Max steps must be a positive number";
9873
+ }
9876
9874
  }
9877
- if (data.sideB.maxSteps !== void 0) {
9878
- if (typeof data.sideB.maxSteps !== "number" || data.sideB.maxSteps <= 0) {
9879
- return "sideB.maxSteps must be a positive number";
9875
+ }
9876
+ if (data.type === "dual_ai") {
9877
+ if (!data.sideB || typeof data.sideB !== "object") {
9878
+ errors["side_b_agent_prompt"] = "Side B configuration is required for dual_ai type";
9879
+ } else {
9880
+ if (!data.sideB.prompt || typeof data.sideB.prompt !== "string") {
9881
+ errors["side_b_agent_prompt"] = "Side B prompt is required for dual_ai type";
9882
+ }
9883
+ if (data.sideB.stopTool && !data.sideB.stopToolResponseProperty) {
9884
+ errors["side_b_stop_tool_response_property"] = "Response property is required when stop tool is set";
9885
+ }
9886
+ if (data.sideB.maxSteps !== void 0) {
9887
+ if (typeof data.sideB.maxSteps !== "number" || data.sideB.maxSteps <= 0) {
9888
+ errors["side_b_max_steps"] = "Max steps must be a positive number";
9889
+ }
9880
9890
  }
9881
9891
  }
9882
9892
  }
9883
9893
  if (data.exposeAsTool && !data.toolDescription) {
9884
- return "toolDescription is required when exposeAsTool is true";
9894
+ errors["tool_description"] = "Tool description is required when expose as tool is enabled";
9885
9895
  }
9886
9896
  if (data.maxSessionTurns !== void 0 && data.maxSessionTurns !== null) {
9887
9897
  if (typeof data.maxSessionTurns !== "number" || data.maxSessionTurns <= 0) {
9888
- return "maxSessionTurns must be a positive number";
9898
+ errors["max_session_turns"] = "Max session turns must be a positive number";
9889
9899
  }
9890
9900
  }
9891
- return null;
9901
+ return Object.keys(errors).length > 0 ? errors : null;
9892
9902
  }
9893
9903
  var MetadataService = class {
9894
9904
  metadataDir;
@@ -13891,11 +13901,11 @@ export class DurableAgentBuilder extends _BaseDurableAgentBuilder {
13891
13901
  try {
13892
13902
  const rawBody = await parseRequestBody(req);
13893
13903
  const body = transformModelData(rawBody);
13894
- const validationError = validateModelData(body);
13895
- if (validationError) {
13904
+ const fieldErrors = validateModelData(body);
13905
+ if (fieldErrors) {
13896
13906
  res.statusCode = 400;
13897
13907
  res.setHeader("Content-Type", "application/json");
13898
- res.end(JSON.stringify({ error: validationError }));
13908
+ res.end(JSON.stringify({ error: "Validation failed", fieldErrors }));
13899
13909
  return;
13900
13910
  }
13901
13911
  if (modelExists(modelsDir, body.name)) {
@@ -13936,11 +13946,11 @@ export class DurableAgentBuilder extends _BaseDurableAgentBuilder {
13936
13946
  const body = transformModelData(rawBody);
13937
13947
  const newName = body.name;
13938
13948
  const isNameChange = newName && newName !== urlModelName;
13939
- const validationError = validateModelData(body);
13940
- if (validationError) {
13949
+ const fieldErrors = validateModelData(body);
13950
+ if (fieldErrors) {
13941
13951
  res.statusCode = 400;
13942
13952
  res.setHeader("Content-Type", "application/json");
13943
- res.end(JSON.stringify({ error: validationError }));
13953
+ res.end(JSON.stringify({ error: "Validation failed", fieldErrors }));
13944
13954
  return;
13945
13955
  }
13946
13956
  let updatedPrompts = [];
@@ -14015,11 +14025,11 @@ export class DurableAgentBuilder extends _BaseDurableAgentBuilder {
14015
14025
  try {
14016
14026
  const rawBody = await parseRequestBody(req);
14017
14027
  const body = transformPromptData(rawBody);
14018
- const validationError = validatePromptData(body);
14019
- if (validationError) {
14028
+ const fieldErrors = validatePromptData(body);
14029
+ if (fieldErrors) {
14020
14030
  res.statusCode = 400;
14021
14031
  res.setHeader("Content-Type", "application/json");
14022
- res.end(JSON.stringify({ error: validationError }));
14032
+ res.end(JSON.stringify({ error: "Validation failed", fieldErrors }));
14023
14033
  return;
14024
14034
  }
14025
14035
  if (promptExists(promptsDir, body.name)) {
@@ -14060,11 +14070,11 @@ export class DurableAgentBuilder extends _BaseDurableAgentBuilder {
14060
14070
  const body = transformPromptData(rawBody);
14061
14071
  const newName = body.name;
14062
14072
  const isNameChange = newName && newName !== urlPromptName;
14063
- const validationError = validatePromptData(body);
14064
- if (validationError) {
14073
+ const fieldErrors = validatePromptData(body);
14074
+ if (fieldErrors) {
14065
14075
  res.statusCode = 400;
14066
14076
  res.setHeader("Content-Type", "application/json");
14067
- res.end(JSON.stringify({ error: validationError }));
14077
+ res.end(JSON.stringify({ error: "Validation failed", fieldErrors }));
14068
14078
  return;
14069
14079
  }
14070
14080
  let updatedPrompts = [];
@@ -14140,11 +14150,11 @@ export class DurableAgentBuilder extends _BaseDurableAgentBuilder {
14140
14150
  try {
14141
14151
  const rawBody = await parseRequestBody(req);
14142
14152
  const body = transformAgentData(rawBody);
14143
- const validationError = validateAgentData(body);
14144
- if (validationError) {
14153
+ const fieldErrors = validateAgentData(body);
14154
+ if (fieldErrors) {
14145
14155
  res.statusCode = 400;
14146
14156
  res.setHeader("Content-Type", "application/json");
14147
- res.end(JSON.stringify({ error: validationError }));
14157
+ res.end(JSON.stringify({ error: "Validation failed", fieldErrors }));
14148
14158
  return;
14149
14159
  }
14150
14160
  if (agentExists(agentsDir, body.name)) {
@@ -14184,11 +14194,11 @@ export class DurableAgentBuilder extends _BaseDurableAgentBuilder {
14184
14194
  const rawBody = await parseRequestBody(req);
14185
14195
  const body = transformAgentData(rawBody);
14186
14196
  body.name = agentName;
14187
- const validationError = validateAgentData(body);
14188
- if (validationError) {
14197
+ const fieldErrors = validateAgentData(body);
14198
+ if (fieldErrors) {
14189
14199
  res.statusCode = 400;
14190
14200
  res.setHeader("Content-Type", "application/json");
14191
- res.end(JSON.stringify({ error: validationError }));
14201
+ res.end(JSON.stringify({ error: "Validation failed", fieldErrors }));
14192
14202
  return;
14193
14203
  }
14194
14204
  const result = await saveAgent(agentsDir, body, true);
@@ -14612,7 +14622,7 @@ export class DurableAgentBuilder extends _BaseDurableAgentBuilder {
14612
14622
  let content = fs2__default.readFileSync(filePath);
14613
14623
  const ext = path8__default.extname(filePath).toLowerCase();
14614
14624
  if (ext === ".html") {
14615
- const configScript = `<script>window.__AGENTBUILDER_CONFIG__ = { mountPoint: "${mountPoint}" };</script>`;
14625
+ const configScript = `<script>window.__AGENTBUILDER_CONFIG__ = { mountPoint: "${mountPoint}", devMode: true };</script>`;
14616
14626
  let htmlContent = content.toString();
14617
14627
  const assetPrefix = mountPoint === "/" ? "/" : `${mountPoint}/`;
14618
14628
  htmlContent = htmlContent.replace(/\/agents\//g, assetPrefix);