@mindstudio-ai/agent 0.1.43 → 0.1.45

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/cli.js CHANGED
@@ -1541,6 +1541,12 @@ function deserializeRow(row, columns) {
1541
1541
  } else if (col?.type === "number" && typeof value === "string") {
1542
1542
  const num = Number(value);
1543
1543
  result[key] = Number.isNaN(num) ? value : num;
1544
+ } else if (!col && typeof value === "string" && (value[0] === "[" || value[0] === "{")) {
1545
+ try {
1546
+ result[key] = JSON.parse(value);
1547
+ } catch {
1548
+ result[key] = value;
1549
+ }
1544
1550
  } else {
1545
1551
  result[key] = value;
1546
1552
  }
@@ -3856,52 +3862,92 @@ var init_client = __esm({
3856
3862
  */
3857
3863
  async executeStepBatch(steps, options) {
3858
3864
  const threadId = options?.threadId ?? (this._reuseThreadId && !getRequestContext() ? this._threadId : void 0);
3859
- const { data } = await request(this._httpConfig, "POST", "/steps/execute-batch", {
3865
+ const { data: asyncData } = await request(this._currentHttpConfig, "POST", "/steps/execute-batch-async", {
3860
3866
  steps: steps.map((s) => ({ ...s, stepType: resolveStepType(s.stepType) })),
3861
3867
  ...options?.appId != null && { appId: options.appId },
3862
3868
  ...threadId != null && { threadId }
3863
3869
  });
3864
- const results = await Promise.all(
3865
- data.results.map(async (r) => {
3866
- if (r.output != null) {
3867
- return {
3868
- stepType: r.stepType,
3869
- output: r.output,
3870
- billingCost: r.billingCost,
3871
- error: r.error
3872
- };
3870
+ const pollUrl = `${this._currentHttpConfig.baseUrl}/developer/v2/steps/execute-batch-async/poll/${asyncData.batchToken}`;
3871
+ let pollDelay = 300;
3872
+ while (true) {
3873
+ await sleep2(pollDelay);
3874
+ pollDelay = Math.min(pollDelay * 1.5, 3e3);
3875
+ const res = await fetch(pollUrl, {
3876
+ headers: { "User-Agent": "@mindstudio-ai/agent" }
3877
+ });
3878
+ if (res.status === 404) {
3879
+ throw new MindStudioError(
3880
+ "Batch poll token not found or expired.",
3881
+ "poll_token_expired",
3882
+ 404
3883
+ );
3884
+ }
3885
+ if (!res.ok) {
3886
+ const errorBody = await res.json().catch(() => ({}));
3887
+ throw new MindStudioError(
3888
+ errorBody.message ?? errorBody.error ?? `Batch poll failed: ${res.status} ${res.statusText}`,
3889
+ errorBody.code ?? "poll_error",
3890
+ res.status,
3891
+ errorBody
3892
+ );
3893
+ }
3894
+ const poll = await res.json();
3895
+ if (poll.status === "pending") {
3896
+ if (options?.onProgress && poll.totalSteps != null && poll.completedSteps != null) {
3897
+ options.onProgress(poll.completedSteps, poll.totalSteps);
3873
3898
  }
3874
- if (r.outputUrl) {
3875
- const res = await fetch(r.outputUrl);
3876
- if (!res.ok) {
3899
+ continue;
3900
+ }
3901
+ if (poll.status === "error") {
3902
+ throw new MindStudioError(
3903
+ poll.error ?? "Batch execution failed.",
3904
+ "batch_execution_error",
3905
+ 500
3906
+ );
3907
+ }
3908
+ const results = await Promise.all(
3909
+ poll.results.map(async (r) => {
3910
+ if (r.output != null) {
3877
3911
  return {
3878
3912
  stepType: r.stepType,
3879
- error: `Failed to fetch output from S3: ${res.status} ${res.statusText}`
3913
+ output: r.output,
3914
+ billingCost: r.billingCost,
3915
+ error: r.error
3916
+ };
3917
+ }
3918
+ if (r.outputUrl) {
3919
+ const s3Res = await fetch(r.outputUrl);
3920
+ if (!s3Res.ok) {
3921
+ return {
3922
+ stepType: r.stepType,
3923
+ error: `Failed to fetch output from S3: ${s3Res.status} ${s3Res.statusText}`
3924
+ };
3925
+ }
3926
+ const envelope = await s3Res.json();
3927
+ return {
3928
+ stepType: r.stepType,
3929
+ output: envelope.value,
3930
+ billingCost: r.billingCost
3880
3931
  };
3881
3932
  }
3882
- const envelope = await res.json();
3883
3933
  return {
3884
3934
  stepType: r.stepType,
3885
- output: envelope.value,
3886
- billingCost: r.billingCost
3935
+ billingCost: r.billingCost,
3936
+ error: r.error
3887
3937
  };
3888
- }
3889
- return {
3890
- stepType: r.stepType,
3891
- billingCost: r.billingCost,
3892
- error: r.error
3893
- };
3894
- })
3895
- );
3896
- if (this._reuseThreadId && data.threadId && !getRequestContext()) {
3897
- this._threadId = data.threadId;
3938
+ })
3939
+ );
3940
+ const resultThreadId = poll.threadId ?? asyncData.threadId;
3941
+ if (this._reuseThreadId && resultThreadId && !getRequestContext()) {
3942
+ this._threadId = resultThreadId;
3943
+ }
3944
+ return {
3945
+ results,
3946
+ totalBillingCost: poll.totalBillingCost,
3947
+ appId: poll.appId,
3948
+ threadId: resultThreadId
3949
+ };
3898
3950
  }
3899
- return {
3900
- results,
3901
- totalBillingCost: data.totalBillingCost,
3902
- appId: data.appId,
3903
- threadId: data.threadId
3904
- };
3905
3951
  }
3906
3952
  /**
3907
3953
  * Get the authenticated user's identity and organization info.
@@ -4402,6 +4448,12 @@ var init_client = __esm({
4402
4448
  (d) => d.tables.some((t) => t.name === name)
4403
4449
  );
4404
4450
  }
4451
+ if (tableConfig.columns.length === 0 && targetDb) {
4452
+ const tableSchema = targetDb.tables.find((t) => t.name === name);
4453
+ if (tableSchema) {
4454
+ tableConfig.columns = tableSchema.schema;
4455
+ }
4456
+ }
4405
4457
  const databaseId = targetDb?.id ?? databases[0]?.id ?? "";
4406
4458
  return agent._executeDbBatch(databaseId, queries);
4407
4459
  }
@@ -5197,7 +5249,7 @@ async function startMcpServer(options) {
5197
5249
  capabilities: { tools: {} },
5198
5250
  serverInfo: {
5199
5251
  name: "mindstudio-agent",
5200
- version: "0.1.43"
5252
+ version: "0.1.45"
5201
5253
  },
5202
5254
  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.'
5203
5255
  });
@@ -6154,7 +6206,7 @@ function isNewerVersion(current, latest) {
6154
6206
  return false;
6155
6207
  }
6156
6208
  async function checkForUpdate() {
6157
- const currentVersion = "0.1.43";
6209
+ const currentVersion = "0.1.45";
6158
6210
  if (!currentVersion) return null;
6159
6211
  try {
6160
6212
  const { loadConfig: loadConfig2, saveConfig: saveConfig2 } = await Promise.resolve().then(() => (init_config(), config_exports));
@@ -6183,7 +6235,7 @@ async function checkForUpdate() {
6183
6235
  }
6184
6236
  }
6185
6237
  function printUpdateNotice(latestVersion) {
6186
- const currentVersion = "0.1.43";
6238
+ const currentVersion = "0.1.45";
6187
6239
  process.stderr.write(
6188
6240
  `
6189
6241
  ${ansi2.cyanBright("Update available")} ${ansi2.gray(currentVersion + " \u2192")} ${ansi2.cyanBold(latestVersion)}
@@ -6196,7 +6248,7 @@ function isStandaloneBinary() {
6196
6248
  return !argv1.includes("node_modules");
6197
6249
  }
6198
6250
  async function cmdUpdate() {
6199
- const currentVersion = "0.1.43";
6251
+ const currentVersion = "0.1.45";
6200
6252
  process.stderr.write(
6201
6253
  ` ${ansi2.gray("Current version:")} ${currentVersion}
6202
6254
  `
@@ -6331,7 +6383,7 @@ async function cmdLogin(options) {
6331
6383
  process.stderr.write("\n");
6332
6384
  printLogo();
6333
6385
  process.stderr.write("\n");
6334
- const ver = "0.1.43";
6386
+ const ver = "0.1.45";
6335
6387
  process.stderr.write(
6336
6388
  ` ${ansi2.bold("MindStudio Agent")} ${ver ? " " + ansi2.gray("v" + ver) : ""}
6337
6389
  `
@@ -6658,7 +6710,7 @@ async function main() {
6658
6710
  try {
6659
6711
  if (command === "version" || command === "-v") {
6660
6712
  process.stdout.write(
6661
- "0.1.43\n"
6713
+ "0.1.45\n"
6662
6714
  );
6663
6715
  return;
6664
6716
  }
package/dist/index.d.ts CHANGED
@@ -375,6 +375,8 @@ interface ExecuteStepBatchOptions {
375
375
  appId?: string;
376
376
  /** Thread ID for state persistence. If omitted, an ephemeral thread is created. */
377
377
  threadId?: string;
378
+ /** Progress callback, called on each poll while the batch is running. */
379
+ onProgress?: (completedSteps: number, totalSteps: number) => void;
378
380
  }
379
381
  /** Result of {@link MindStudioAgent.executeStepBatch}. */
380
382
  interface ExecuteStepBatchResult {
package/dist/index.js CHANGED
@@ -296,6 +296,12 @@ function deserializeRow(row, columns) {
296
296
  } else if (col?.type === "number" && typeof value === "string") {
297
297
  const num = Number(value);
298
298
  result[key] = Number.isNaN(num) ? value : num;
299
+ } else if (!col && typeof value === "string" && (value[0] === "[" || value[0] === "{")) {
300
+ try {
301
+ result[key] = JSON.parse(value);
302
+ } catch {
303
+ result[key] = value;
304
+ }
299
305
  } else {
300
306
  result[key] = value;
301
307
  }
@@ -3684,52 +3690,92 @@ var MindStudioAgent = class {
3684
3690
  */
3685
3691
  async executeStepBatch(steps, options) {
3686
3692
  const threadId = options?.threadId ?? (this._reuseThreadId && !getRequestContext() ? this._threadId : void 0);
3687
- const { data } = await request(this._httpConfig, "POST", "/steps/execute-batch", {
3693
+ const { data: asyncData } = await request(this._currentHttpConfig, "POST", "/steps/execute-batch-async", {
3688
3694
  steps: steps.map((s) => ({ ...s, stepType: resolveStepType(s.stepType) })),
3689
3695
  ...options?.appId != null && { appId: options.appId },
3690
3696
  ...threadId != null && { threadId }
3691
3697
  });
3692
- const results = await Promise.all(
3693
- data.results.map(async (r) => {
3694
- if (r.output != null) {
3695
- return {
3696
- stepType: r.stepType,
3697
- output: r.output,
3698
- billingCost: r.billingCost,
3699
- error: r.error
3700
- };
3698
+ const pollUrl = `${this._currentHttpConfig.baseUrl}/developer/v2/steps/execute-batch-async/poll/${asyncData.batchToken}`;
3699
+ let pollDelay = 300;
3700
+ while (true) {
3701
+ await sleep2(pollDelay);
3702
+ pollDelay = Math.min(pollDelay * 1.5, 3e3);
3703
+ const res = await fetch(pollUrl, {
3704
+ headers: { "User-Agent": "@mindstudio-ai/agent" }
3705
+ });
3706
+ if (res.status === 404) {
3707
+ throw new MindStudioError(
3708
+ "Batch poll token not found or expired.",
3709
+ "poll_token_expired",
3710
+ 404
3711
+ );
3712
+ }
3713
+ if (!res.ok) {
3714
+ const errorBody = await res.json().catch(() => ({}));
3715
+ throw new MindStudioError(
3716
+ errorBody.message ?? errorBody.error ?? `Batch poll failed: ${res.status} ${res.statusText}`,
3717
+ errorBody.code ?? "poll_error",
3718
+ res.status,
3719
+ errorBody
3720
+ );
3721
+ }
3722
+ const poll = await res.json();
3723
+ if (poll.status === "pending") {
3724
+ if (options?.onProgress && poll.totalSteps != null && poll.completedSteps != null) {
3725
+ options.onProgress(poll.completedSteps, poll.totalSteps);
3701
3726
  }
3702
- if (r.outputUrl) {
3703
- const res = await fetch(r.outputUrl);
3704
- if (!res.ok) {
3727
+ continue;
3728
+ }
3729
+ if (poll.status === "error") {
3730
+ throw new MindStudioError(
3731
+ poll.error ?? "Batch execution failed.",
3732
+ "batch_execution_error",
3733
+ 500
3734
+ );
3735
+ }
3736
+ const results = await Promise.all(
3737
+ poll.results.map(async (r) => {
3738
+ if (r.output != null) {
3705
3739
  return {
3706
3740
  stepType: r.stepType,
3707
- error: `Failed to fetch output from S3: ${res.status} ${res.statusText}`
3741
+ output: r.output,
3742
+ billingCost: r.billingCost,
3743
+ error: r.error
3744
+ };
3745
+ }
3746
+ if (r.outputUrl) {
3747
+ const s3Res = await fetch(r.outputUrl);
3748
+ if (!s3Res.ok) {
3749
+ return {
3750
+ stepType: r.stepType,
3751
+ error: `Failed to fetch output from S3: ${s3Res.status} ${s3Res.statusText}`
3752
+ };
3753
+ }
3754
+ const envelope = await s3Res.json();
3755
+ return {
3756
+ stepType: r.stepType,
3757
+ output: envelope.value,
3758
+ billingCost: r.billingCost
3708
3759
  };
3709
3760
  }
3710
- const envelope = await res.json();
3711
3761
  return {
3712
3762
  stepType: r.stepType,
3713
- output: envelope.value,
3714
- billingCost: r.billingCost
3763
+ billingCost: r.billingCost,
3764
+ error: r.error
3715
3765
  };
3716
- }
3717
- return {
3718
- stepType: r.stepType,
3719
- billingCost: r.billingCost,
3720
- error: r.error
3721
- };
3722
- })
3723
- );
3724
- if (this._reuseThreadId && data.threadId && !getRequestContext()) {
3725
- this._threadId = data.threadId;
3766
+ })
3767
+ );
3768
+ const resultThreadId = poll.threadId ?? asyncData.threadId;
3769
+ if (this._reuseThreadId && resultThreadId && !getRequestContext()) {
3770
+ this._threadId = resultThreadId;
3771
+ }
3772
+ return {
3773
+ results,
3774
+ totalBillingCost: poll.totalBillingCost,
3775
+ appId: poll.appId,
3776
+ threadId: resultThreadId
3777
+ };
3726
3778
  }
3727
- return {
3728
- results,
3729
- totalBillingCost: data.totalBillingCost,
3730
- appId: data.appId,
3731
- threadId: data.threadId
3732
- };
3733
3779
  }
3734
3780
  /**
3735
3781
  * Get the authenticated user's identity and organization info.
@@ -4230,6 +4276,12 @@ var MindStudioAgent = class {
4230
4276
  (d) => d.tables.some((t) => t.name === name)
4231
4277
  );
4232
4278
  }
4279
+ if (tableConfig.columns.length === 0 && targetDb) {
4280
+ const tableSchema = targetDb.tables.find((t) => t.name === name);
4281
+ if (tableSchema) {
4282
+ tableConfig.columns = tableSchema.schema;
4283
+ }
4284
+ }
4233
4285
  const databaseId = targetDb?.id ?? databases[0]?.id ?? "";
4234
4286
  return agent._executeDbBatch(databaseId, queries);
4235
4287
  }