@mindstudio-ai/agent 0.1.46 → 0.1.47

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.
@@ -1242,9 +1242,9 @@ async function requestWithRetry(config, method, url, body, attempt) {
1242
1242
  body: body != null ? JSON.stringify(body) : void 0
1243
1243
  });
1244
1244
  config.rateLimiter.updateFromHeaders(res.headers);
1245
- if (res.status === 429 && attempt < config.maxRetries) {
1245
+ if (attempt < config.maxRetries && (res.status === 429 || res.status === 502 || res.status === 503 || res.status === 504)) {
1246
1246
  const retryAfter = res.headers.get("retry-after");
1247
- const waitMs = retryAfter ? parseFloat(retryAfter) * 1e3 : 1e3;
1247
+ const waitMs = retryAfter ? parseFloat(retryAfter) * 1e3 : Math.min(1e3 * Math.pow(2, attempt), 1e4);
1248
1248
  await sleep(waitMs);
1249
1249
  return requestWithRetry(config, method, url, body, attempt + 1);
1250
1250
  }
@@ -3006,7 +3006,7 @@ function buildTaskRequestBody(options) {
3006
3006
  prompt: options.prompt,
3007
3007
  input: options.input,
3008
3008
  tools: mapTools(options.tools),
3009
- structuredOutputExample: options.structuredOutputExample,
3009
+ structuredOutputExample: typeof options.structuredOutputExample === "string" ? options.structuredOutputExample : JSON.stringify(options.structuredOutputExample),
3010
3010
  model: options.model,
3011
3011
  ...options.maxTurns != null && { maxTurns: options.maxTurns },
3012
3012
  ...options.appId != null && { appId: options.appId },
@@ -3016,6 +3016,16 @@ function buildTaskRequestBody(options) {
3016
3016
  function sleep2(ms) {
3017
3017
  return new Promise((resolve) => setTimeout(resolve, ms));
3018
3018
  }
3019
+ function isDevMode() {
3020
+ return !!(process.env.CALLBACK_TOKEN || getRequestContext()?.callbackToken);
3021
+ }
3022
+ function logTaskResult(result) {
3023
+ if (!isDevMode()) return;
3024
+ const toolSummary = result.toolCalls.map((tc) => `${tc.name} (${tc.durationMs}ms) ${tc.success ? "\u2713" : "\u2717"}`).join(", ");
3025
+ console.log(
3026
+ `[task] ${result.turns} turn${result.turns === 1 ? "" : "s"}` + (toolSummary ? `: ${toolSummary}` : "") + ` | ${result.parsedSuccessfully ? "output OK" : "\u26A0 output not valid JSON"} | cost: ${result.usage.totalBillingCost}`
3027
+ );
3028
+ }
3019
3029
  async function runTaskPoll(httpConfig, body) {
3020
3030
  const { data } = await request(
3021
3031
  httpConfig,
@@ -3031,6 +3041,7 @@ async function runTaskPoll(httpConfig, body) {
3031
3041
  const res = await fetch(pollUrl, {
3032
3042
  headers: { "User-Agent": "@mindstudio-ai/agent" }
3033
3043
  });
3044
+ if (res.status === 502 || res.status === 503 || res.status === 504) continue;
3034
3045
  if (res.status === 404) {
3035
3046
  throw new MindStudioError(
3036
3047
  "Task poll token not found or expired.",
@@ -3048,7 +3059,12 @@ async function runTaskPoll(httpConfig, body) {
3048
3059
  );
3049
3060
  }
3050
3061
  const poll = await res.json();
3051
- if (poll.status === "pending") continue;
3062
+ if (poll.status === "pending") {
3063
+ if (isDevMode() && poll.currentTurn != null) {
3064
+ console.log(`[task] running... turn ${poll.currentTurn}/${poll.maxTurns ?? "?"}`);
3065
+ }
3066
+ continue;
3067
+ }
3052
3068
  if (poll.status === "error") {
3053
3069
  throw new MindStudioError(
3054
3070
  poll.error ?? "Task execution failed.",
@@ -3056,11 +3072,16 @@ async function runTaskPoll(httpConfig, body) {
3056
3072
  500
3057
3073
  );
3058
3074
  }
3059
- return {
3075
+ const result = {
3060
3076
  output: poll.output,
3077
+ outputRaw: poll.outputRaw ?? "",
3078
+ parsedSuccessfully: poll.parsedSuccessfully ?? true,
3061
3079
  turns: poll.turns ?? 0,
3062
- usage: poll.usage ?? { inputTokens: 0, outputTokens: 0, totalBillingCost: 0 }
3080
+ usage: poll.usage ?? { inputTokens: 0, outputTokens: 0, totalBillingCost: 0 },
3081
+ toolCalls: poll.toolCalls ?? []
3063
3082
  };
3083
+ logTaskResult(result);
3084
+ return result;
3064
3085
  }
3065
3086
  }
3066
3087
  async function runTaskStream(httpConfig, body, onEvent) {
@@ -3120,12 +3141,15 @@ async function runTaskStream(httpConfig, body, onEvent) {
3120
3141
  if (event.type === "done") {
3121
3142
  result = {
3122
3143
  output: event.output,
3144
+ outputRaw: event.outputRaw ?? "",
3145
+ parsedSuccessfully: event.parsedSuccessfully ?? true,
3123
3146
  turns: event.turns ?? 0,
3124
3147
  usage: event.usage ?? {
3125
3148
  inputTokens: 0,
3126
3149
  outputTokens: 0,
3127
3150
  totalBillingCost: 0
3128
- }
3151
+ },
3152
+ toolCalls: event.toolCalls ?? []
3129
3153
  };
3130
3154
  }
3131
3155
  } catch (err) {
@@ -3147,12 +3171,15 @@ async function runTaskStream(httpConfig, body, onEvent) {
3147
3171
  if (event.type === "done") {
3148
3172
  result = {
3149
3173
  output: event.output,
3174
+ outputRaw: event.outputRaw ?? "",
3175
+ parsedSuccessfully: event.parsedSuccessfully ?? true,
3150
3176
  turns: event.turns ?? 0,
3151
3177
  usage: event.usage ?? {
3152
3178
  inputTokens: 0,
3153
3179
  outputTokens: 0,
3154
3180
  totalBillingCost: 0
3155
- }
3181
+ },
3182
+ toolCalls: event.toolCalls ?? []
3156
3183
  };
3157
3184
  }
3158
3185
  } catch (err) {
@@ -3166,6 +3193,7 @@ async function runTaskStream(httpConfig, body, onEvent) {
3166
3193
  500
3167
3194
  );
3168
3195
  }
3196
+ logTaskResult(result);
3169
3197
  return result;
3170
3198
  }
3171
3199
  var init_task = __esm({
@@ -3173,6 +3201,7 @@ var init_task = __esm({
3173
3201
  "use strict";
3174
3202
  init_http();
3175
3203
  init_errors();
3204
+ init_context();
3176
3205
  init_metadata();
3177
3206
  }
3178
3207
  });
@@ -4065,6 +4094,7 @@ var init_client = __esm({
4065
4094
  const res = await fetch(pollUrl, {
4066
4095
  headers: { "User-Agent": "@mindstudio-ai/agent" }
4067
4096
  });
4097
+ if (res.status === 502 || res.status === 503 || res.status === 504) continue;
4068
4098
  if (res.status === 404) {
4069
4099
  throw new MindStudioError(
4070
4100
  "Batch poll token not found or expired.",
@@ -4228,6 +4258,7 @@ var init_client = __esm({
4228
4258
  const res = await fetch(pollUrl, {
4229
4259
  headers: { "User-Agent": "@mindstudio-ai/agent" }
4230
4260
  });
4261
+ if (res.status === 502 || res.status === 503 || res.status === 504) continue;
4231
4262
  if (res.status === 404) {
4232
4263
  throw new MindStudioError(
4233
4264
  "Poll token not found or expired.",
@@ -5494,7 +5525,7 @@ async function startMcpServer(options) {
5494
5525
  capabilities: { tools: {} },
5495
5526
  serverInfo: {
5496
5527
  name: "mindstudio-agent",
5497
- version: "0.1.46"
5528
+ version: "0.1.47"
5498
5529
  },
5499
5530
  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 or icon, call `uploadFile` to upload it, then `changeProfilePicture` with the returned URL.\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.'
5500
5531
  });
@@ -6355,7 +6386,7 @@ function isNewerVersion(current, latest) {
6355
6386
  return false;
6356
6387
  }
6357
6388
  async function checkForUpdate() {
6358
- const currentVersion = "0.1.46";
6389
+ const currentVersion = "0.1.47";
6359
6390
  if (!currentVersion) return null;
6360
6391
  try {
6361
6392
  const { loadConfig: loadConfig2, saveConfig: saveConfig2 } = await Promise.resolve().then(() => (init_config(), config_exports));
@@ -6384,7 +6415,7 @@ async function checkForUpdate() {
6384
6415
  }
6385
6416
  }
6386
6417
  function printUpdateNotice(latestVersion) {
6387
- const currentVersion = "0.1.46";
6418
+ const currentVersion = "0.1.47";
6388
6419
  process.stderr.write(
6389
6420
  `
6390
6421
  ${ansi2.cyanBright("Update available")} ${ansi2.gray(currentVersion + " \u2192")} ${ansi2.cyanBold(latestVersion)}
@@ -6397,7 +6428,7 @@ function isStandaloneBinary() {
6397
6428
  return !argv1.includes("node_modules");
6398
6429
  }
6399
6430
  async function cmdUpdate() {
6400
- const currentVersion = "0.1.46";
6431
+ const currentVersion = "0.1.47";
6401
6432
  process.stderr.write(
6402
6433
  ` ${ansi2.gray("Current version:")} ${currentVersion}
6403
6434
  `
@@ -6512,7 +6543,7 @@ async function cmdLogin(options) {
6512
6543
  process.stderr.write("\n");
6513
6544
  printLogo();
6514
6545
  process.stderr.write("\n");
6515
- const ver = "0.1.46";
6546
+ const ver = "0.1.47";
6516
6547
  process.stderr.write(
6517
6548
  ` ${ansi2.bold("MindStudio Agent")} ${ver ? " " + ansi2.gray("v" + ver) : ""}
6518
6549
  `
@@ -6823,7 +6854,7 @@ async function main() {
6823
6854
  try {
6824
6855
  if (command === "version" || command === "-v") {
6825
6856
  process.stdout.write(
6826
- "0.1.46\n"
6857
+ "0.1.47\n"
6827
6858
  );
6828
6859
  return;
6829
6860
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mindstudio-ai/agent",
3
- "version": "0.1.46",
3
+ "version": "0.1.47",
4
4
  "description": "TypeScript SDK for MindStudio direct step execution",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",