@mindstudio-ai/agent 0.1.47 → 0.1.48

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
@@ -2776,15 +2776,16 @@ var init_table = __esm({
2776
2776
  // -------------------------------------------------------------------------
2777
2777
  // Internal helpers
2778
2778
  // -------------------------------------------------------------------------
2779
- /** @internal Throw if data includes a platform-managed email/phone column. */
2779
+ /** @internal Throw if data includes a platform-managed read-only column. */
2780
2780
  _checkManagedColumns(data) {
2781
2781
  const mc = this._config.managedColumns;
2782
2782
  if (!mc) return;
2783
2783
  const keys = Object.keys(data);
2784
2784
  for (const key of keys) {
2785
- if (mc.email && key === mc.email || mc.phone && key === mc.phone) {
2785
+ if (mc.email && key === mc.email || mc.phone && key === mc.phone || mc.apiKey && key === mc.apiKey) {
2786
+ const friendly = key === mc.email ? "email" : key === mc.phone ? "phone" : "API key";
2786
2787
  throw new MindStudioError(
2787
- `Cannot write to "${key}" \u2014 this column is managed by auth. Use the auth API to change a user's ${key === mc.email ? "email" : "phone"}.`,
2788
+ `Cannot write to "${key}" \u2014 this column is managed by auth. Use the auth API to change a user's ${friendly}.`,
2788
2789
  "managed_column_write",
2789
2790
  400
2790
2791
  );
@@ -3854,48 +3855,80 @@ var init_client = __esm({
3854
3855
  );
3855
3856
  }
3856
3857
  const threadId = options?.threadId ?? (this._reuseThreadId && !getRequestContext() ? this._threadId : void 0);
3857
- const { data, headers } = await request(this._httpConfig, "POST", `/steps/${stepType}/execute`, {
3858
+ const { data: asyncData, headers } = await request(this._currentHttpConfig, "POST", `/steps/${stepType}/execute-async`, {
3858
3859
  step,
3859
3860
  ...options?.appId != null && { appId: options.appId },
3860
3861
  ...threadId != null && { threadId },
3861
3862
  ...this._currentStreamId != null && { streamId: this._currentStreamId }
3862
3863
  });
3863
- let output;
3864
- if (data.output != null) {
3865
- output = data.output;
3866
- } else if (data.outputUrl) {
3867
- const res = await fetch(data.outputUrl);
3864
+ const remaining = headers.get("x-ratelimit-remaining");
3865
+ const returnedThreadId = asyncData.threadId ?? "";
3866
+ if (this._reuseThreadId && returnedThreadId && !getRequestContext()) {
3867
+ this._threadId = returnedThreadId;
3868
+ }
3869
+ if (!this._appId && asyncData.appId && !getRequestContext()) {
3870
+ this._appId = asyncData.appId;
3871
+ }
3872
+ const pollUrl = `${this._currentHttpConfig.baseUrl}/developer/v2/steps/${stepType}/execute-async/poll/${asyncData.executionToken}`;
3873
+ let pollDelay = 100;
3874
+ while (true) {
3875
+ await sleep3(pollDelay);
3876
+ pollDelay = Math.min(pollDelay * 2, 5e3);
3877
+ const res = await fetch(pollUrl, {
3878
+ headers: { "User-Agent": "@mindstudio-ai/agent" }
3879
+ });
3880
+ if (res.status === 502 || res.status === 503 || res.status === 504) continue;
3881
+ if (res.status === 404) {
3882
+ throw new MindStudioError(
3883
+ `[${stepType}] Execution token expired.`,
3884
+ "poll_token_expired",
3885
+ 404
3886
+ );
3887
+ }
3868
3888
  if (!res.ok) {
3889
+ const errorBody = await res.json().catch(() => ({}));
3869
3890
  throw new MindStudioError(
3870
- `Failed to fetch ${stepType} output from S3: ${res.status} ${res.statusText}`,
3871
- "output_fetch_error",
3872
- res.status
3891
+ errorBody.message ?? errorBody.error ?? `[${stepType}] Poll failed: ${res.status} ${res.statusText}`,
3892
+ errorBody.code ?? "poll_error",
3893
+ res.status,
3894
+ errorBody
3873
3895
  );
3874
3896
  }
3875
- const envelope = await res.json();
3876
- output = envelope.value;
3877
- } else {
3878
- output = void 0;
3879
- }
3880
- const returnedThreadId = headers.get("x-mindstudio-thread-id") ?? "";
3881
- if (this._reuseThreadId && returnedThreadId && !getRequestContext()) {
3882
- this._threadId = returnedThreadId;
3883
- }
3884
- const returnedAppId = headers.get("x-mindstudio-app-id");
3885
- if (!this._appId && returnedAppId && !getRequestContext()) {
3886
- this._appId = returnedAppId;
3897
+ const poll = await res.json();
3898
+ if (poll.status === "pending") continue;
3899
+ if (poll.status === "error") {
3900
+ throw new MindStudioError(
3901
+ `[${stepType}] ${poll.error ?? "Step execution failed."}`,
3902
+ "step_error",
3903
+ 500
3904
+ );
3905
+ }
3906
+ let output;
3907
+ if (poll.output != null) {
3908
+ output = poll.output;
3909
+ } else if (poll.outputUrl) {
3910
+ const s3Res = await fetch(poll.outputUrl);
3911
+ if (!s3Res.ok) {
3912
+ throw new MindStudioError(
3913
+ `Failed to fetch ${stepType} output from S3: ${s3Res.status} ${s3Res.statusText}`,
3914
+ "output_fetch_error",
3915
+ s3Res.status
3916
+ );
3917
+ }
3918
+ const envelope = await s3Res.json();
3919
+ output = envelope.value;
3920
+ } else {
3921
+ output = void 0;
3922
+ }
3923
+ return {
3924
+ ...output,
3925
+ $appId: poll.appId ?? asyncData.appId ?? "",
3926
+ $threadId: poll.threadId ?? returnedThreadId,
3927
+ $rateLimitRemaining: remaining != null ? parseInt(remaining, 10) : void 0,
3928
+ $billingCost: poll.billingCost,
3929
+ $billingEvents: poll.billingEvents
3930
+ };
3887
3931
  }
3888
- const remaining = headers.get("x-ratelimit-remaining");
3889
- const billingCost = headers.get("x-mindstudio-billing-cost");
3890
- const billingEvents = headers.get("x-mindstudio-billing-events");
3891
- return {
3892
- ...output,
3893
- $appId: headers.get("x-mindstudio-app-id") ?? "",
3894
- $threadId: returnedThreadId,
3895
- $rateLimitRemaining: remaining != null ? parseInt(remaining, 10) : void 0,
3896
- $billingCost: billingCost != null ? parseFloat(billingCost) : void 0,
3897
- $billingEvents: billingEvents != null ? JSON.parse(billingEvents) : void 0
3898
- };
3899
3932
  }
3900
3933
  /**
3901
3934
  * @internal Streaming step execution — sends `Accept: text/event-stream`
@@ -5525,7 +5558,7 @@ async function startMcpServer(options) {
5525
5558
  capabilities: { tools: {} },
5526
5559
  serverInfo: {
5527
5560
  name: "mindstudio-agent",
5528
- version: "0.1.47"
5561
+ version: "0.1.48"
5529
5562
  },
5530
5563
  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.'
5531
5564
  });
@@ -6482,7 +6515,7 @@ function isNewerVersion(current, latest) {
6482
6515
  return false;
6483
6516
  }
6484
6517
  async function checkForUpdate() {
6485
- const currentVersion = "0.1.47";
6518
+ const currentVersion = "0.1.48";
6486
6519
  if (!currentVersion) return null;
6487
6520
  try {
6488
6521
  const { loadConfig: loadConfig2, saveConfig: saveConfig2 } = await Promise.resolve().then(() => (init_config(), config_exports));
@@ -6511,7 +6544,7 @@ async function checkForUpdate() {
6511
6544
  }
6512
6545
  }
6513
6546
  function printUpdateNotice(latestVersion) {
6514
- const currentVersion = "0.1.47";
6547
+ const currentVersion = "0.1.48";
6515
6548
  process.stderr.write(
6516
6549
  `
6517
6550
  ${ansi2.cyanBright("Update available")} ${ansi2.gray(currentVersion + " \u2192")} ${ansi2.cyanBold(latestVersion)}
@@ -6524,7 +6557,7 @@ function isStandaloneBinary() {
6524
6557
  return !argv1.includes("node_modules");
6525
6558
  }
6526
6559
  async function cmdUpdate() {
6527
- const currentVersion = "0.1.47";
6560
+ const currentVersion = "0.1.48";
6528
6561
  process.stderr.write(
6529
6562
  ` ${ansi2.gray("Current version:")} ${currentVersion}
6530
6563
  `
@@ -6659,7 +6692,7 @@ async function cmdLogin(options) {
6659
6692
  process.stderr.write("\n");
6660
6693
  printLogo();
6661
6694
  process.stderr.write("\n");
6662
- const ver = "0.1.47";
6695
+ const ver = "0.1.48";
6663
6696
  process.stderr.write(
6664
6697
  ` ${ansi2.bold("MindStudio Agent")} ${ver ? " " + ansi2.gray("v" + ver) : ""}
6665
6698
  `
@@ -6986,7 +7019,7 @@ async function main() {
6986
7019
  try {
6987
7020
  if (command === "version" || command === "-v") {
6988
7021
  process.stdout.write(
6989
- "0.1.47\n"
7022
+ "0.1.48\n"
6990
7023
  );
6991
7024
  return;
6992
7025
  }
package/dist/index.d.ts CHANGED
@@ -656,12 +656,13 @@ interface TableConfig {
656
656
  defaults?: Record<string, unknown>;
657
657
  /**
658
658
  * Platform-managed auth columns. Set when this table is the app's auth
659
- * table. Writes to email/phone columns throw; roles writes are allowed.
659
+ * table. Writes to email/phone/apiKey columns throw; roles writes are allowed.
660
660
  */
661
661
  managedColumns?: {
662
662
  email?: string;
663
663
  phone?: string;
664
664
  roles?: string;
665
+ apiKey?: string;
665
666
  };
666
667
  /**
667
668
  * Sync role changes to the platform after a successful auth table write.
@@ -956,7 +957,7 @@ declare class Table<T> {
956
957
  * @param data - Row data to insert (or update on conflict). Defaults apply.
957
958
  */
958
959
  upsert(conflictKey: (keyof Omit<T, SystemFields> & string) | (keyof Omit<T, SystemFields> & string)[], data: PushInput<T>): Mutation<T>;
959
- /** @internal Throw if data includes a platform-managed email/phone column. */
960
+ /** @internal Throw if data includes a platform-managed read-only column. */
960
961
  private _checkManagedColumns;
961
962
  /**
962
963
  * @internal Fire role sync for rows that wrote to the roles column.
package/dist/index.js CHANGED
@@ -1493,15 +1493,16 @@ var Table = class {
1493
1493
  // -------------------------------------------------------------------------
1494
1494
  // Internal helpers
1495
1495
  // -------------------------------------------------------------------------
1496
- /** @internal Throw if data includes a platform-managed email/phone column. */
1496
+ /** @internal Throw if data includes a platform-managed read-only column. */
1497
1497
  _checkManagedColumns(data) {
1498
1498
  const mc = this._config.managedColumns;
1499
1499
  if (!mc) return;
1500
1500
  const keys = Object.keys(data);
1501
1501
  for (const key of keys) {
1502
- if (mc.email && key === mc.email || mc.phone && key === mc.phone) {
1502
+ if (mc.email && key === mc.email || mc.phone && key === mc.phone || mc.apiKey && key === mc.apiKey) {
1503
+ const friendly = key === mc.email ? "email" : key === mc.phone ? "phone" : "API key";
1503
1504
  throw new MindStudioError(
1504
- `Cannot write to "${key}" \u2014 this column is managed by auth. Use the auth API to change a user's ${key === mc.email ? "email" : "phone"}.`,
1505
+ `Cannot write to "${key}" \u2014 this column is managed by auth. Use the auth API to change a user's ${friendly}.`,
1505
1506
  "managed_column_write",
1506
1507
  400
1507
1508
  );
@@ -3672,48 +3673,80 @@ var MindStudioAgent = class {
3672
3673
  );
3673
3674
  }
3674
3675
  const threadId = options?.threadId ?? (this._reuseThreadId && !getRequestContext() ? this._threadId : void 0);
3675
- const { data, headers } = await request(this._httpConfig, "POST", `/steps/${stepType}/execute`, {
3676
+ const { data: asyncData, headers } = await request(this._currentHttpConfig, "POST", `/steps/${stepType}/execute-async`, {
3676
3677
  step,
3677
3678
  ...options?.appId != null && { appId: options.appId },
3678
3679
  ...threadId != null && { threadId },
3679
3680
  ...this._currentStreamId != null && { streamId: this._currentStreamId }
3680
3681
  });
3681
- let output;
3682
- if (data.output != null) {
3683
- output = data.output;
3684
- } else if (data.outputUrl) {
3685
- const res = await fetch(data.outputUrl);
3682
+ const remaining = headers.get("x-ratelimit-remaining");
3683
+ const returnedThreadId = asyncData.threadId ?? "";
3684
+ if (this._reuseThreadId && returnedThreadId && !getRequestContext()) {
3685
+ this._threadId = returnedThreadId;
3686
+ }
3687
+ if (!this._appId && asyncData.appId && !getRequestContext()) {
3688
+ this._appId = asyncData.appId;
3689
+ }
3690
+ const pollUrl = `${this._currentHttpConfig.baseUrl}/developer/v2/steps/${stepType}/execute-async/poll/${asyncData.executionToken}`;
3691
+ let pollDelay = 100;
3692
+ while (true) {
3693
+ await sleep3(pollDelay);
3694
+ pollDelay = Math.min(pollDelay * 2, 5e3);
3695
+ const res = await fetch(pollUrl, {
3696
+ headers: { "User-Agent": "@mindstudio-ai/agent" }
3697
+ });
3698
+ if (res.status === 502 || res.status === 503 || res.status === 504) continue;
3699
+ if (res.status === 404) {
3700
+ throw new MindStudioError(
3701
+ `[${stepType}] Execution token expired.`,
3702
+ "poll_token_expired",
3703
+ 404
3704
+ );
3705
+ }
3686
3706
  if (!res.ok) {
3707
+ const errorBody = await res.json().catch(() => ({}));
3687
3708
  throw new MindStudioError(
3688
- `Failed to fetch ${stepType} output from S3: ${res.status} ${res.statusText}`,
3689
- "output_fetch_error",
3690
- res.status
3709
+ errorBody.message ?? errorBody.error ?? `[${stepType}] Poll failed: ${res.status} ${res.statusText}`,
3710
+ errorBody.code ?? "poll_error",
3711
+ res.status,
3712
+ errorBody
3691
3713
  );
3692
3714
  }
3693
- const envelope = await res.json();
3694
- output = envelope.value;
3695
- } else {
3696
- output = void 0;
3697
- }
3698
- const returnedThreadId = headers.get("x-mindstudio-thread-id") ?? "";
3699
- if (this._reuseThreadId && returnedThreadId && !getRequestContext()) {
3700
- this._threadId = returnedThreadId;
3701
- }
3702
- const returnedAppId = headers.get("x-mindstudio-app-id");
3703
- if (!this._appId && returnedAppId && !getRequestContext()) {
3704
- this._appId = returnedAppId;
3715
+ const poll = await res.json();
3716
+ if (poll.status === "pending") continue;
3717
+ if (poll.status === "error") {
3718
+ throw new MindStudioError(
3719
+ `[${stepType}] ${poll.error ?? "Step execution failed."}`,
3720
+ "step_error",
3721
+ 500
3722
+ );
3723
+ }
3724
+ let output;
3725
+ if (poll.output != null) {
3726
+ output = poll.output;
3727
+ } else if (poll.outputUrl) {
3728
+ const s3Res = await fetch(poll.outputUrl);
3729
+ if (!s3Res.ok) {
3730
+ throw new MindStudioError(
3731
+ `Failed to fetch ${stepType} output from S3: ${s3Res.status} ${s3Res.statusText}`,
3732
+ "output_fetch_error",
3733
+ s3Res.status
3734
+ );
3735
+ }
3736
+ const envelope = await s3Res.json();
3737
+ output = envelope.value;
3738
+ } else {
3739
+ output = void 0;
3740
+ }
3741
+ return {
3742
+ ...output,
3743
+ $appId: poll.appId ?? asyncData.appId ?? "",
3744
+ $threadId: poll.threadId ?? returnedThreadId,
3745
+ $rateLimitRemaining: remaining != null ? parseInt(remaining, 10) : void 0,
3746
+ $billingCost: poll.billingCost,
3747
+ $billingEvents: poll.billingEvents
3748
+ };
3705
3749
  }
3706
- const remaining = headers.get("x-ratelimit-remaining");
3707
- const billingCost = headers.get("x-mindstudio-billing-cost");
3708
- const billingEvents = headers.get("x-mindstudio-billing-events");
3709
- return {
3710
- ...output,
3711
- $appId: headers.get("x-mindstudio-app-id") ?? "",
3712
- $threadId: returnedThreadId,
3713
- $rateLimitRemaining: remaining != null ? parseInt(remaining, 10) : void 0,
3714
- $billingCost: billingCost != null ? parseFloat(billingCost) : void 0,
3715
- $billingEvents: billingEvents != null ? JSON.parse(billingEvents) : void 0
3716
- };
3717
3750
  }
3718
3751
  /**
3719
3752
  * @internal Streaming step execution — sends `Accept: text/event-stream`