@mindstudio-ai/agent 0.1.22 → 0.1.24
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/README.md +9 -0
- package/dist/cli.js +188 -8
- package/dist/index.d.ts +25 -1
- package/dist/index.js +161 -0
- package/dist/index.js.map +1 -1
- package/dist/postinstall.js +188 -8
- package/package.json +1 -1
package/dist/postinstall.js
CHANGED
|
@@ -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.
|
|
4809
|
+
version: "0.1.24"
|
|
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
|
});
|
|
@@ -5275,9 +5436,25 @@ async function cmdExec(method, input, options) {
|
|
|
5275
5436
|
`Unknown action: ${method}. Run 'mindstudio list-actions' to see available actions.`
|
|
5276
5437
|
);
|
|
5277
5438
|
}
|
|
5439
|
+
let onLog;
|
|
5440
|
+
if (options.jsonLogs) {
|
|
5441
|
+
onLog = (log) => {
|
|
5442
|
+
process.stderr.write(
|
|
5443
|
+
JSON.stringify({ type: "log", value: log.value, tag: log.tag, ts: log.ts }) + "\n"
|
|
5444
|
+
);
|
|
5445
|
+
};
|
|
5446
|
+
} else if (process.stderr.isTTY) {
|
|
5447
|
+
onLog = (log) => {
|
|
5448
|
+
process.stderr.write(
|
|
5449
|
+
` ${ansi2.cyan("\u27E1")} ${ansi2.gray(log.value)}
|
|
5450
|
+
`
|
|
5451
|
+
);
|
|
5452
|
+
};
|
|
5453
|
+
}
|
|
5278
5454
|
const result = await agent.executeStep(meta.stepType, input, {
|
|
5279
5455
|
appId: options.appId,
|
|
5280
|
-
threadId: options.threadId
|
|
5456
|
+
threadId: options.threadId,
|
|
5457
|
+
onLog
|
|
5281
5458
|
});
|
|
5282
5459
|
if (options.outputKey) {
|
|
5283
5460
|
const val = result[options.outputKey];
|
|
@@ -5485,7 +5662,7 @@ function isNewerVersion(current, latest) {
|
|
|
5485
5662
|
return false;
|
|
5486
5663
|
}
|
|
5487
5664
|
async function checkForUpdate() {
|
|
5488
|
-
const currentVersion = "0.1.
|
|
5665
|
+
const currentVersion = "0.1.24";
|
|
5489
5666
|
if (!currentVersion) return null;
|
|
5490
5667
|
try {
|
|
5491
5668
|
const { loadConfig: loadConfig2, saveConfig: saveConfig2 } = await Promise.resolve().then(() => (init_config(), config_exports));
|
|
@@ -5514,7 +5691,7 @@ async function checkForUpdate() {
|
|
|
5514
5691
|
}
|
|
5515
5692
|
}
|
|
5516
5693
|
function printUpdateNotice(latestVersion) {
|
|
5517
|
-
const currentVersion = "0.1.
|
|
5694
|
+
const currentVersion = "0.1.24";
|
|
5518
5695
|
process.stderr.write(
|
|
5519
5696
|
`
|
|
5520
5697
|
${ansi2.cyanBright("Update available")} ${ansi2.gray(currentVersion + " \u2192")} ${ansi2.cyanBold(latestVersion)}
|
|
@@ -5527,7 +5704,7 @@ function isStandaloneBinary() {
|
|
|
5527
5704
|
return !argv1.includes("node_modules");
|
|
5528
5705
|
}
|
|
5529
5706
|
async function cmdUpdate() {
|
|
5530
|
-
const currentVersion = "0.1.
|
|
5707
|
+
const currentVersion = "0.1.24";
|
|
5531
5708
|
process.stderr.write(
|
|
5532
5709
|
` ${ansi2.gray("Current version:")} ${currentVersion}
|
|
5533
5710
|
`
|
|
@@ -5642,7 +5819,7 @@ async function cmdLogin(options) {
|
|
|
5642
5819
|
process.stderr.write("\n");
|
|
5643
5820
|
printLogo();
|
|
5644
5821
|
process.stderr.write("\n");
|
|
5645
|
-
const ver = "0.1.
|
|
5822
|
+
const ver = "0.1.24";
|
|
5646
5823
|
process.stderr.write(
|
|
5647
5824
|
` ${ansi2.bold("MindStudio Agent")} ${ver ? " " + ansi2.gray("v" + ver) : ""}
|
|
5648
5825
|
`
|
|
@@ -5914,6 +6091,7 @@ async function main() {
|
|
|
5914
6091
|
"thread-id": { type: "string" },
|
|
5915
6092
|
"output-key": { type: "string" },
|
|
5916
6093
|
"no-meta": { type: "boolean", default: false },
|
|
6094
|
+
"json-logs": { type: "boolean", default: false },
|
|
5917
6095
|
workflow: { type: "string" },
|
|
5918
6096
|
version: { type: "string" },
|
|
5919
6097
|
type: { type: "string" },
|
|
@@ -5946,7 +6124,7 @@ async function main() {
|
|
|
5946
6124
|
try {
|
|
5947
6125
|
if (command === "version" || command === "-v") {
|
|
5948
6126
|
process.stdout.write(
|
|
5949
|
-
"0.1.
|
|
6127
|
+
"0.1.24\n"
|
|
5950
6128
|
);
|
|
5951
6129
|
return;
|
|
5952
6130
|
}
|
|
@@ -6367,7 +6545,8 @@ async function main() {
|
|
|
6367
6545
|
appId: values["app-id"],
|
|
6368
6546
|
threadId: values["thread-id"],
|
|
6369
6547
|
outputKey: values["output-key"],
|
|
6370
|
-
noMeta: values["no-meta"]
|
|
6548
|
+
noMeta: values["no-meta"],
|
|
6549
|
+
jsonLogs: values["json-logs"]
|
|
6371
6550
|
});
|
|
6372
6551
|
} catch (err) {
|
|
6373
6552
|
const message = err instanceof Error ? err.message : String(err);
|
|
@@ -6427,6 +6606,7 @@ Options:
|
|
|
6427
6606
|
--thread-id <id> Thread ID for state persistence
|
|
6428
6607
|
--output-key <key> Extract a single field from the result
|
|
6429
6608
|
--no-meta Strip $-prefixed metadata from output
|
|
6609
|
+
--json-logs Stream debug logs as JSONL to stderr
|
|
6430
6610
|
--workflow <name> Workflow to execute (run-agent only)
|
|
6431
6611
|
--version <ver> App version, e.g. "draft" (run-agent only)
|
|
6432
6612
|
--json Output as JSON
|