@mindstudio-ai/agent 0.1.141 → 0.1.142

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.
@@ -5169,9 +5169,11 @@ function logTaskResult(result) {
5169
5169
  if (!isDevMode()) {
5170
5170
  return;
5171
5171
  }
5172
- const toolSummary = result.toolCalls.map((tc) => `${tc.name} (${tc.durationMs}ms) ${tc.success ? "\u2713" : "\u2717"}`).join(", ");
5172
+ const toolSummary = result.toolCalls.map(
5173
+ (tc) => `${tc.name} (${tc.durationMs}ms) ${tc.success ? "\u2713" : "\u2717"}` + (tc.truncated ? " \u26A0 result cut" : "")
5174
+ ).join(", ");
5173
5175
  console.log(
5174
- `[task] ${result.turns} turn${result.turns === 1 ? "" : "s"}` + (toolSummary ? `: ${toolSummary}` : "") + ` | ${result.parsedSuccessfully ? "output OK" : "\u26A0 output not valid JSON"} | cost: ${result.usage.totalBillingCost} | trace: ${result.traceId}`
5176
+ `[task] ${result.turns} turn${result.turns === 1 ? "" : "s"}` + (toolSummary ? `: ${toolSummary}` : "") + (result.hitMaxTurns ? " | \u26A0 ran out of turns" : "") + (result.stopReason === "max_tokens" ? " | \u26A0 answer cut at the output limit" : "") + ` | ${result.parsedSuccessfully ? "output OK" : "\u26A0 output not valid JSON"} | cost: ${result.usage.totalBillingCost} | trace: ${result.traceId}`
5175
5177
  );
5176
5178
  }
5177
5179
  var init_task = __esm({
@@ -5356,9 +5358,20 @@ function mergeToolInput(modelInput, defaults) {
5356
5358
  }
5357
5359
  return merged;
5358
5360
  }
5359
- function truncateToolOutput(output) {
5361
+ function truncateToolOutput(output, maxChars) {
5360
5362
  const serialized = JSON.stringify(output);
5361
- return serialized && serialized.length > MAX_TOOL_OUTPUT_CHARS ? serialized.slice(0, MAX_TOOL_OUTPUT_CHARS) + "... [truncated]" : output;
5363
+ if (!serialized || serialized.length <= maxChars) {
5364
+ return { output, truncated: false };
5365
+ }
5366
+ return {
5367
+ output: {
5368
+ truncated: true,
5369
+ totalChars: serialized.length,
5370
+ shownChars: maxChars,
5371
+ content: serialized.slice(0, maxChars)
5372
+ },
5373
+ truncated: true
5374
+ };
5362
5375
  }
5363
5376
  async function attemptTurn(httpConfig, body) {
5364
5377
  const url = `${httpConfig.baseUrl}/developer/v2/task/turn`;
@@ -5569,6 +5582,7 @@ ${structuredOutputExample}
5569
5582
  Math.max(options.maxTurns || DEFAULT_MAX_TURNS, 1),
5570
5583
  MAX_TURNS_LIMIT
5571
5584
  );
5585
+ const maxToolOutputChars = options.maxToolOutputChars ?? MAX_TOOL_OUTPUT_CHARS;
5572
5586
  const traceId = randomUUID2();
5573
5587
  const messages = [
5574
5588
  { role: "user", content: JSON.stringify(options.input) }
@@ -5583,11 +5597,13 @@ ${structuredOutputExample}
5583
5597
  cacheReadTokens: 0,
5584
5598
  totalBillingCost: 0
5585
5599
  };
5586
- const buildResult = (output2, outputRaw, parsedSuccessfully2, turns) => ({
5600
+ const buildResult = (output2, outputRaw, parsedSuccessfully2, turns, stopReason, hitMaxTurns = false) => ({
5587
5601
  output: output2,
5588
5602
  outputRaw,
5589
5603
  parsedSuccessfully: parsedSuccessfully2,
5590
5604
  turns,
5605
+ hitMaxTurns,
5606
+ stopReason,
5591
5607
  usage: totalUsage,
5592
5608
  toolCalls: toolCallLog,
5593
5609
  traceId
@@ -5645,7 +5661,7 @@ ${structuredOutputExample}
5645
5661
  }
5646
5662
  );
5647
5663
  }
5648
- return finish(buildResult(null, "", false, loopCount));
5664
+ return finish(buildResult(null, "", false, loopCount, null));
5649
5665
  }
5650
5666
  if (err instanceof TurnError) {
5651
5667
  throw new MindStudioError(
@@ -5692,11 +5708,11 @@ ${structuredOutputExample}
5692
5708
  let result;
5693
5709
  if (kind === "function") {
5694
5710
  try {
5695
- const output3 = await functionTools.get(toolCall.name)(
5711
+ const output4 = await functionTools.get(toolCall.name)(
5696
5712
  mergedInput
5697
5713
  );
5698
5714
  result = {
5699
- output: output3 ?? null,
5715
+ output: output4 ?? null,
5700
5716
  billingCost: 0,
5701
5717
  isError: false
5702
5718
  };
@@ -5717,29 +5733,40 @@ ${structuredOutputExample}
5717
5733
  } else {
5718
5734
  result = await deps.executeStepTool(toolCall.name, mergedInput);
5719
5735
  }
5736
+ const { output: output3, truncated } = truncateToolOutput(
5737
+ result.output,
5738
+ maxToolOutputChars
5739
+ );
5720
5740
  toolCallLog.push({
5721
5741
  name: toolCall.name,
5722
5742
  success: !result.isError,
5723
- durationMs: Date.now() - startTime
5743
+ durationMs: Date.now() - startTime,
5744
+ truncated
5724
5745
  });
5725
- return { toolCall, ...result };
5746
+ return { toolCall, ...result, output: output3, truncated };
5726
5747
  })
5727
5748
  );
5728
- for (const { toolCall, output: output3, billingCost, isError } of results) {
5749
+ for (const {
5750
+ toolCall,
5751
+ output: output3,
5752
+ truncated,
5753
+ billingCost,
5754
+ isError
5755
+ } of results) {
5729
5756
  if (billingCost) {
5730
5757
  totalUsage.totalBillingCost += billingCost;
5731
5758
  }
5732
- const truncated = truncateToolOutput(output3);
5733
5759
  messages.push({
5734
5760
  role: "user",
5735
- content: JSON.stringify(truncated),
5761
+ content: JSON.stringify(output3),
5736
5762
  toolCallId: toolCall.id,
5737
5763
  ...isError && { isToolError: true }
5738
5764
  });
5739
5765
  onEvent?.({
5740
5766
  type: "tool_call_result",
5741
5767
  id: toolCall.id,
5742
- output: truncated
5768
+ output: output3,
5769
+ ...truncated && { truncated: true }
5743
5770
  });
5744
5771
  }
5745
5772
  if (isDevMode()) {
@@ -5759,11 +5786,15 @@ ${structuredOutputExample}
5759
5786
  }
5760
5787
  if (parseOk) {
5761
5788
  if (!outputSchema) {
5762
- return finish(buildResult(output2, turn.text, true, loopCount));
5789
+ return finish(
5790
+ buildResult(output2, turn.text, true, loopCount, turn.stopReason)
5791
+ );
5763
5792
  }
5764
5793
  const errors = validateAgainstSchema(output2, outputSchema);
5765
5794
  if (errors.length === 0) {
5766
- return finish(buildResult(output2, turn.text, true, loopCount));
5795
+ return finish(
5796
+ buildResult(output2, turn.text, true, loopCount, turn.stopReason)
5797
+ );
5767
5798
  }
5768
5799
  if (loopCount < maxTurns && schemaRepairCount < MAX_SCHEMA_REPAIR_ATTEMPTS) {
5769
5800
  schemaRepairCount++;
@@ -5788,13 +5819,16 @@ ${formatValidationErrors(errors)}`
5788
5819
  { path: "$", message: "output was not valid JSON" }
5789
5820
  ]);
5790
5821
  }
5791
- return finish(buildResult(turn.text, turn.text, false, loopCount));
5822
+ return finish(
5823
+ buildResult(turn.text, turn.text, false, loopCount, turn.stopReason)
5824
+ );
5792
5825
  }
5793
5826
  messages.push({
5794
5827
  role: "user",
5795
5828
  content: "You have reached the maximum number of turns. Please provide your final output now as JSON."
5796
5829
  });
5797
5830
  let finalText = "";
5831
+ let finalStopReason = null;
5798
5832
  try {
5799
5833
  const turn = await runTurnWithRetry(httpConfig, {
5800
5834
  model: options.model,
@@ -5805,6 +5839,7 @@ ${formatValidationErrors(errors)}`
5805
5839
  });
5806
5840
  accumulate(turn);
5807
5841
  finalText = turn.text;
5842
+ finalStopReason = turn.stopReason;
5808
5843
  } catch (err) {
5809
5844
  if (err instanceof TurnError && err.phase === "model") {
5810
5845
  if (isDevMode()) {
@@ -5834,7 +5869,14 @@ ${formatValidationErrors(errors)}`
5834
5869
  }
5835
5870
  }
5836
5871
  return finish(
5837
- buildResult(output, finalText, parsedSuccessfully, loopCount + 1)
5872
+ buildResult(
5873
+ output,
5874
+ finalText,
5875
+ parsedSuccessfully,
5876
+ loopCount + 1,
5877
+ finalStopReason,
5878
+ true
5879
+ )
5838
5880
  );
5839
5881
  }
5840
5882
  var DEFAULT_MAX_TURNS, MAX_TURNS_LIMIT, MAX_SCHEMA_REPAIR_ATTEMPTS, MAX_TOOL_OUTPUT_CHARS, MAX_TURN_ATTEMPTS, INITIAL_BACKOFF_MS, STALL_TIMEOUT_MS, UNSAFE_KEYS, TurnError;
@@ -9156,7 +9198,7 @@ async function startMcpServer(options) {
9156
9198
  capabilities: { tools: {} },
9157
9199
  serverInfo: {
9158
9200
  name: "mindstudio-agent",
9159
- version: "0.1.141"
9201
+ version: "0.1.142"
9160
9202
  },
9161
9203
  instructions: 'Welcome to MindStudio \u2014 a platform with 200+ AI models, 850+ third-party integrations, and pre-built agents.\n\nGetting started:\n1. Call `ask` with any question about the SDK \u2014 it knows every action, model, and connector and returns working code with real model IDs and config options. Examples: ask("generate an image with FLUX"), ask("what models support vision?"), ask("how do I send a Slack message?").\n2. Call `changeName` to set your display name \u2014 use your name or whatever your user calls you. This is how you\'ll appear in MindStudio request logs.\n3. If you have a profile picture, pass its public image URL to `changeProfilePicture`.\n4. For manual browsing, call `listActions` to discover all available actions.\n\nThen use the tools to generate text, images, video, audio, search the web, work with data sources, run agents, and more.\n\nImportant:\n- AI-powered actions (text generation, image generation, video, audio, etc.) cost money. Before running these, call `estimateActionCost` and confirm with the user before proceeding \u2014 unless they\'ve explicitly told you to go ahead.\n- Not all agents from `listAgents` are configured for API use. Do not try to run an agent just because it appears in the list \u2014 it will likely fail. Only run agents the user specifically asks you to run.'
9162
9204
  });
@@ -10071,7 +10113,7 @@ function isNewerVersion(current, latest) {
10071
10113
  return false;
10072
10114
  }
10073
10115
  async function checkForUpdate() {
10074
- const currentVersion = "0.1.141";
10116
+ const currentVersion = "0.1.142";
10075
10117
  if (!currentVersion || process.env.MINDSTUDIO_NO_UPDATE_CHECK) {
10076
10118
  return null;
10077
10119
  }
@@ -10106,7 +10148,7 @@ async function checkForUpdate() {
10106
10148
  }
10107
10149
  }
10108
10150
  function printUpdateNotice(latestVersion) {
10109
- const currentVersion = "0.1.141";
10151
+ const currentVersion = "0.1.142";
10110
10152
  process.stderr.write(
10111
10153
  `
10112
10154
  ${ansi2.cyanBright("Update available")} ${ansi2.gray(currentVersion + " \u2192")} ${ansi2.cyanBold(latestVersion)}
@@ -10119,7 +10161,7 @@ function isStandaloneBinary() {
10119
10161
  return !argv1.includes("node_modules");
10120
10162
  }
10121
10163
  async function cmdUpdate() {
10122
- const currentVersion = "0.1.141";
10164
+ const currentVersion = "0.1.142";
10123
10165
  process.stderr.write(
10124
10166
  ` ${ansi2.gray("Current version:")} ${currentVersion}
10125
10167
  `
@@ -10240,7 +10282,7 @@ async function cmdLogin(options) {
10240
10282
  process.stderr.write("\n");
10241
10283
  printLogo();
10242
10284
  process.stderr.write("\n");
10243
- const ver = "0.1.141";
10285
+ const ver = "0.1.142";
10244
10286
  process.stderr.write(
10245
10287
  ` ${ansi2.bold("MindStudio Agent")} ${ver ? " " + ansi2.gray("v" + ver) : ""}
10246
10288
  `
@@ -10552,7 +10594,7 @@ async function main() {
10552
10594
  const updatePromise = command !== "mcp" && command !== "login" && command !== "update" ? checkForUpdate() : Promise.resolve(null);
10553
10595
  try {
10554
10596
  if (command === "version" || command === "-v") {
10555
- process.stdout.write("0.1.141\n");
10597
+ process.stdout.write("0.1.142\n");
10556
10598
  return;
10557
10599
  }
10558
10600
  if (command === "login") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mindstudio-ai/agent",
3
- "version": "0.1.141",
3
+ "version": "0.1.142",
4
4
  "description": "TypeScript SDK for MindStudio direct step execution",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",