@mindstudio-ai/agent 0.1.22 → 0.1.23

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.
@@ -3383,6 +3383,13 @@ var init_client = __esm({
3383
3383
  * ```
3384
3384
  */
3385
3385
  async executeStep(stepType, step, options) {
3386
+ if (options?.onLog) {
3387
+ return this._executeStepStreaming(
3388
+ stepType,
3389
+ step,
3390
+ options
3391
+ );
3392
+ }
3386
3393
  const threadId = options?.threadId ?? (this._reuseThreadId ? this._threadId : void 0);
3387
3394
  const { data, headers } = await request(this._httpConfig, "POST", `/steps/${stepType}/execute`, {
3388
3395
  step,
@@ -3427,6 +3434,160 @@ var init_client = __esm({
3427
3434
  $billingEvents: billingEvents != null ? JSON.parse(billingEvents) : void 0
3428
3435
  };
3429
3436
  }
3437
+ /**
3438
+ * @internal Streaming step execution — sends `Accept: text/event-stream`
3439
+ * and parses SSE events for real-time debug logs.
3440
+ */
3441
+ async _executeStepStreaming(stepType, step, options) {
3442
+ const threadId = options.threadId ?? (this._reuseThreadId ? this._threadId : void 0);
3443
+ const url = `${this._httpConfig.baseUrl}/developer/v2/steps/${stepType}/execute`;
3444
+ const body = {
3445
+ step,
3446
+ ...options.appId != null && { appId: options.appId },
3447
+ ...threadId != null && { threadId },
3448
+ ...this._streamId != null && { streamId: this._streamId }
3449
+ };
3450
+ await this._httpConfig.rateLimiter.acquire();
3451
+ let res;
3452
+ try {
3453
+ res = await fetch(url, {
3454
+ method: "POST",
3455
+ headers: {
3456
+ Authorization: `Bearer ${this._httpConfig.token}`,
3457
+ "Content-Type": "application/json",
3458
+ "User-Agent": "@mindstudio-ai/agent",
3459
+ Accept: "text/event-stream"
3460
+ },
3461
+ body: JSON.stringify(body)
3462
+ });
3463
+ } catch (err) {
3464
+ this._httpConfig.rateLimiter.release();
3465
+ throw err;
3466
+ }
3467
+ this._httpConfig.rateLimiter.updateFromHeaders(res.headers);
3468
+ if (!res.ok) {
3469
+ this._httpConfig.rateLimiter.release();
3470
+ const errorBody = await res.json().catch(() => ({}));
3471
+ throw new MindStudioError(
3472
+ errorBody.message || `${res.status} ${res.statusText}`,
3473
+ errorBody.code || "api_error",
3474
+ res.status,
3475
+ errorBody
3476
+ );
3477
+ }
3478
+ const headers = res.headers;
3479
+ try {
3480
+ const reader = res.body.getReader();
3481
+ const decoder = new TextDecoder();
3482
+ let buffer = "";
3483
+ let doneEvent = null;
3484
+ while (true) {
3485
+ const { done, value } = await reader.read();
3486
+ if (done) break;
3487
+ buffer += decoder.decode(value, { stream: true });
3488
+ const lines = buffer.split("\n");
3489
+ buffer = lines.pop() ?? "";
3490
+ for (const line of lines) {
3491
+ if (!line.startsWith("data: ")) continue;
3492
+ try {
3493
+ const event = JSON.parse(line.slice(6));
3494
+ if (event.type === "log") {
3495
+ options.onLog({
3496
+ value: event.value,
3497
+ tag: event.tag,
3498
+ ts: event.ts
3499
+ });
3500
+ } else if (event.type === "done") {
3501
+ doneEvent = {
3502
+ output: event.output,
3503
+ outputUrl: event.outputUrl,
3504
+ billingCost: event.billingCost,
3505
+ billingEvents: event.billingEvents
3506
+ };
3507
+ } else if (event.type === "error") {
3508
+ throw new MindStudioError(
3509
+ event.error || "Step execution failed",
3510
+ "step_error",
3511
+ 500
3512
+ );
3513
+ }
3514
+ } catch (err) {
3515
+ if (err instanceof MindStudioError) throw err;
3516
+ }
3517
+ }
3518
+ }
3519
+ if (buffer.startsWith("data: ")) {
3520
+ try {
3521
+ const event = JSON.parse(buffer.slice(6));
3522
+ if (event.type === "done") {
3523
+ doneEvent = {
3524
+ output: event.output,
3525
+ outputUrl: event.outputUrl,
3526
+ billingCost: event.billingCost,
3527
+ billingEvents: event.billingEvents
3528
+ };
3529
+ } else if (event.type === "error") {
3530
+ throw new MindStudioError(
3531
+ event.error || "Step execution failed",
3532
+ "step_error",
3533
+ 500
3534
+ );
3535
+ } else if (event.type === "log") {
3536
+ options.onLog({
3537
+ value: event.value,
3538
+ tag: event.tag,
3539
+ ts: event.ts
3540
+ });
3541
+ }
3542
+ } catch (err) {
3543
+ if (err instanceof MindStudioError) throw err;
3544
+ }
3545
+ }
3546
+ if (!doneEvent) {
3547
+ throw new MindStudioError(
3548
+ "Stream ended without a done event",
3549
+ "stream_error",
3550
+ 500
3551
+ );
3552
+ }
3553
+ let output;
3554
+ if (doneEvent.output != null) {
3555
+ output = doneEvent.output;
3556
+ } else if (doneEvent.outputUrl) {
3557
+ const s3Res = await fetch(doneEvent.outputUrl);
3558
+ if (!s3Res.ok) {
3559
+ throw new MindStudioError(
3560
+ `Failed to fetch output from S3: ${s3Res.status} ${s3Res.statusText}`,
3561
+ "output_fetch_error",
3562
+ s3Res.status
3563
+ );
3564
+ }
3565
+ const envelope = await s3Res.json();
3566
+ output = envelope.value;
3567
+ } else {
3568
+ output = void 0;
3569
+ }
3570
+ const returnedThreadId = headers.get("x-mindstudio-thread-id") ?? "";
3571
+ if (this._reuseThreadId && returnedThreadId) {
3572
+ this._threadId = returnedThreadId;
3573
+ }
3574
+ const returnedAppId = headers.get("x-mindstudio-app-id");
3575
+ if (!this._appId && returnedAppId) {
3576
+ this._appId = returnedAppId;
3577
+ }
3578
+ const remaining = headers.get("x-ratelimit-remaining");
3579
+ return {
3580
+ ...output,
3581
+ $appId: headers.get("x-mindstudio-app-id") ?? "",
3582
+ $threadId: returnedThreadId,
3583
+ $rateLimitRemaining: remaining != null ? parseInt(remaining, 10) : void 0,
3584
+ $billingCost: doneEvent.billingCost,
3585
+ $billingEvents: doneEvent.billingEvents
3586
+ };
3587
+ } finally {
3588
+ this._httpConfig.rateLimiter.release();
3589
+ }
3590
+ }
3430
3591
  /**
3431
3592
  * Execute multiple steps in parallel in a single request.
3432
3593
  *
@@ -4645,7 +4806,7 @@ async function startMcpServer(options) {
4645
4806
  capabilities: { tools: {} },
4646
4807
  serverInfo: {
4647
4808
  name: "mindstudio-agent",
4648
- version: "0.1.22"
4809
+ version: "0.1.23"
4649
4810
  },
4650
4811
  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.'
4651
4812
  });
@@ -5277,7 +5438,13 @@ async function cmdExec(method, input, options) {
5277
5438
  }
5278
5439
  const result = await agent.executeStep(meta.stepType, input, {
5279
5440
  appId: options.appId,
5280
- threadId: options.threadId
5441
+ threadId: options.threadId,
5442
+ onLog: process.stderr.isTTY ? (log) => {
5443
+ process.stderr.write(
5444
+ ` ${ansi2.cyan("\u27E1")} ${ansi2.gray(log.value)}
5445
+ `
5446
+ );
5447
+ } : void 0
5281
5448
  });
5282
5449
  if (options.outputKey) {
5283
5450
  const val = result[options.outputKey];
@@ -5485,7 +5652,7 @@ function isNewerVersion(current, latest) {
5485
5652
  return false;
5486
5653
  }
5487
5654
  async function checkForUpdate() {
5488
- const currentVersion = "0.1.22";
5655
+ const currentVersion = "0.1.23";
5489
5656
  if (!currentVersion) return null;
5490
5657
  try {
5491
5658
  const { loadConfig: loadConfig2, saveConfig: saveConfig2 } = await Promise.resolve().then(() => (init_config(), config_exports));
@@ -5514,7 +5681,7 @@ async function checkForUpdate() {
5514
5681
  }
5515
5682
  }
5516
5683
  function printUpdateNotice(latestVersion) {
5517
- const currentVersion = "0.1.22";
5684
+ const currentVersion = "0.1.23";
5518
5685
  process.stderr.write(
5519
5686
  `
5520
5687
  ${ansi2.cyanBright("Update available")} ${ansi2.gray(currentVersion + " \u2192")} ${ansi2.cyanBold(latestVersion)}
@@ -5527,7 +5694,7 @@ function isStandaloneBinary() {
5527
5694
  return !argv1.includes("node_modules");
5528
5695
  }
5529
5696
  async function cmdUpdate() {
5530
- const currentVersion = "0.1.22";
5697
+ const currentVersion = "0.1.23";
5531
5698
  process.stderr.write(
5532
5699
  ` ${ansi2.gray("Current version:")} ${currentVersion}
5533
5700
  `
@@ -5642,7 +5809,7 @@ async function cmdLogin(options) {
5642
5809
  process.stderr.write("\n");
5643
5810
  printLogo();
5644
5811
  process.stderr.write("\n");
5645
- const ver = "0.1.22";
5812
+ const ver = "0.1.23";
5646
5813
  process.stderr.write(
5647
5814
  ` ${ansi2.bold("MindStudio Agent")} ${ver ? " " + ansi2.gray("v" + ver) : ""}
5648
5815
  `
@@ -5946,7 +6113,7 @@ async function main() {
5946
6113
  try {
5947
6114
  if (command === "version" || command === "-v") {
5948
6115
  process.stdout.write(
5949
- "0.1.22\n"
6116
+ "0.1.23\n"
5950
6117
  );
5951
6118
  return;
5952
6119
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mindstudio-ai/agent",
3
- "version": "0.1.22",
3
+ "version": "0.1.23",
4
4
  "description": "TypeScript SDK for MindStudio direct step execution",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",