@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.
- package/README.md +9 -0
- package/dist/cli.js +174 -7
- package/dist/index.d.ts +25 -1
- package/dist/index.js +161 -0
- package/dist/index.js.map +1 -1
- package/dist/postinstall.js +174 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -87,6 +87,15 @@ mindstudio info generate-image
|
|
|
87
87
|
echo '{"query": "TypeScript best practices"}' | mindstudio search-google
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
+
Steps stream real-time progress when run from a terminal:
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
$ mindstudio generate-image --prompt "A mountain landscape at sunset"
|
|
94
|
+
⟡ Generating image with DALL·E 3...
|
|
95
|
+
⟡ Image generated successfully
|
|
96
|
+
{"imageUrl":"https://...","$billingCost":5000000}
|
|
97
|
+
```
|
|
98
|
+
|
|
90
99
|
Run via `npx` without installing:
|
|
91
100
|
|
|
92
101
|
```bash
|
package/dist/cli.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.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
|
});
|
|
@@ -5345,7 +5506,13 @@ async function cmdExec(method, input, options) {
|
|
|
5345
5506
|
}
|
|
5346
5507
|
const result = await agent.executeStep(meta.stepType, input, {
|
|
5347
5508
|
appId: options.appId,
|
|
5348
|
-
threadId: options.threadId
|
|
5509
|
+
threadId: options.threadId,
|
|
5510
|
+
onLog: process.stderr.isTTY ? (log) => {
|
|
5511
|
+
process.stderr.write(
|
|
5512
|
+
` ${ansi2.cyan("\u27E1")} ${ansi2.gray(log.value)}
|
|
5513
|
+
`
|
|
5514
|
+
);
|
|
5515
|
+
} : void 0
|
|
5349
5516
|
});
|
|
5350
5517
|
if (options.outputKey) {
|
|
5351
5518
|
const val = result[options.outputKey];
|
|
@@ -5580,7 +5747,7 @@ function isNewerVersion(current, latest) {
|
|
|
5580
5747
|
return false;
|
|
5581
5748
|
}
|
|
5582
5749
|
async function checkForUpdate() {
|
|
5583
|
-
const currentVersion = "0.1.
|
|
5750
|
+
const currentVersion = "0.1.23";
|
|
5584
5751
|
if (!currentVersion) return null;
|
|
5585
5752
|
try {
|
|
5586
5753
|
const { loadConfig: loadConfig2, saveConfig: saveConfig2 } = await Promise.resolve().then(() => (init_config(), config_exports));
|
|
@@ -5609,7 +5776,7 @@ async function checkForUpdate() {
|
|
|
5609
5776
|
}
|
|
5610
5777
|
}
|
|
5611
5778
|
function printUpdateNotice(latestVersion) {
|
|
5612
|
-
const currentVersion = "0.1.
|
|
5779
|
+
const currentVersion = "0.1.23";
|
|
5613
5780
|
process.stderr.write(
|
|
5614
5781
|
`
|
|
5615
5782
|
${ansi2.cyanBright("Update available")} ${ansi2.gray(currentVersion + " \u2192")} ${ansi2.cyanBold(latestVersion)}
|
|
@@ -5622,7 +5789,7 @@ function isStandaloneBinary() {
|
|
|
5622
5789
|
return !argv1.includes("node_modules");
|
|
5623
5790
|
}
|
|
5624
5791
|
async function cmdUpdate() {
|
|
5625
|
-
const currentVersion = "0.1.
|
|
5792
|
+
const currentVersion = "0.1.23";
|
|
5626
5793
|
process.stderr.write(
|
|
5627
5794
|
` ${ansi2.gray("Current version:")} ${currentVersion}
|
|
5628
5795
|
`
|
|
@@ -5757,7 +5924,7 @@ async function cmdLogin(options) {
|
|
|
5757
5924
|
process.stderr.write("\n");
|
|
5758
5925
|
printLogo();
|
|
5759
5926
|
process.stderr.write("\n");
|
|
5760
|
-
const ver = "0.1.
|
|
5927
|
+
const ver = "0.1.23";
|
|
5761
5928
|
process.stderr.write(
|
|
5762
5929
|
` ${ansi2.bold("MindStudio Agent")} ${ver ? " " + ansi2.gray("v" + ver) : ""}
|
|
5763
5930
|
`
|
|
@@ -6070,7 +6237,7 @@ async function main() {
|
|
|
6070
6237
|
try {
|
|
6071
6238
|
if (command === "version" || command === "-v") {
|
|
6072
6239
|
process.stdout.write(
|
|
6073
|
-
"0.1.
|
|
6240
|
+
"0.1.23\n"
|
|
6074
6241
|
);
|
|
6075
6242
|
return;
|
|
6076
6243
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -50,6 +50,15 @@ interface AgentOptions {
|
|
|
50
50
|
*/
|
|
51
51
|
reuseThreadId?: boolean;
|
|
52
52
|
}
|
|
53
|
+
/** A debug log event emitted during streaming step execution. */
|
|
54
|
+
interface StepLogEvent {
|
|
55
|
+
/** Log message text. */
|
|
56
|
+
value: string;
|
|
57
|
+
/** Step display name, e.g. "Generate Image", "Scrape URL". */
|
|
58
|
+
tag: string;
|
|
59
|
+
/** Unix timestamp in milliseconds. */
|
|
60
|
+
ts: number;
|
|
61
|
+
}
|
|
53
62
|
/** Options for a single step execution call. */
|
|
54
63
|
interface StepExecutionOptions {
|
|
55
64
|
/**
|
|
@@ -64,6 +73,16 @@ interface StepExecutionOptions {
|
|
|
64
73
|
* history or variable state.
|
|
65
74
|
*/
|
|
66
75
|
threadId?: string;
|
|
76
|
+
/**
|
|
77
|
+
* Called for each debug log event during step execution. When set, the SDK
|
|
78
|
+
* uses SSE streaming to receive real-time progress updates from the API.
|
|
79
|
+
* When omitted, the endpoint returns a single JSON response as before.
|
|
80
|
+
*
|
|
81
|
+
* Log content and frequency varies by step type — image generation emits
|
|
82
|
+
* 2-3 logs, scrape steps emit per-URL progress, LLM steps may emit model
|
|
83
|
+
* selection and token info.
|
|
84
|
+
*/
|
|
85
|
+
onLog?: (event: StepLogEvent) => void;
|
|
67
86
|
}
|
|
68
87
|
/** Execution metadata returned alongside every step result. */
|
|
69
88
|
interface StepExecutionMeta {
|
|
@@ -1127,6 +1146,11 @@ declare class MindStudioAgent$1 {
|
|
|
1127
1146
|
* ```
|
|
1128
1147
|
*/
|
|
1129
1148
|
executeStep<TOutput = unknown>(stepType: string, step: Record<string, unknown>, options?: StepExecutionOptions): Promise<StepExecutionResult<TOutput>>;
|
|
1149
|
+
/**
|
|
1150
|
+
* @internal Streaming step execution — sends `Accept: text/event-stream`
|
|
1151
|
+
* and parses SSE events for real-time debug logs.
|
|
1152
|
+
*/
|
|
1153
|
+
private _executeStepStreaming;
|
|
1130
1154
|
/**
|
|
1131
1155
|
* Execute multiple steps in parallel in a single request.
|
|
1132
1156
|
*
|
|
@@ -7920,4 +7944,4 @@ declare const stream: (data: string | Record<string, unknown>) => Promise<void>;
|
|
|
7920
7944
|
*/
|
|
7921
7945
|
declare const resolveUser: (userId: string) => Promise<ResolvedUser | null>;
|
|
7922
7946
|
|
|
7923
|
-
export { type Accessor, type ActiveCampaignAddNoteStepInput, type ActiveCampaignAddNoteStepOutput, type ActiveCampaignCreateContactStepInput, type ActiveCampaignCreateContactStepOutput, type AddSubtitlesToVideoStepInput, type AddSubtitlesToVideoStepOutput, type AgentInfo, type AgentOptions, type AirtableCreateUpdateRecordStepInput, type AirtableCreateUpdateRecordStepOutput, type AirtableDeleteRecordStepInput, type AirtableDeleteRecordStepOutput, type AirtableGetRecordStepInput, type AirtableGetRecordStepOutput, type AirtableGetTableRecordsStepInput, type AirtableGetTableRecordsStepOutput, type AnalyzeImageStepInput, type AnalyzeImageStepOutput, type AnalyzeVideoStepInput, type AnalyzeVideoStepOutput, type AppAuthContext, type AppContextResult, type AppDatabase, type AppDatabaseColumnSchema, type AppDatabaseTable, type AppRoleAssignment, AuthContext, type BatchStepInput, type BatchStepResult, type CaptureThumbnailStepInput, type CaptureThumbnailStepOutput, type CheckAppRoleStepInput, type CheckAppRoleStepOutput, type CodaCreateUpdatePageStepInput, type CodaCreateUpdatePageStepOutput, type CodaCreateUpdateRowStepInput, type CodaCreateUpdateRowStepOutput, type CodaFindRowStepInput, type CodaFindRowStepOutput, type CodaGetPageStepInput, type CodaGetPageStepOutput, type CodaGetTableRowsStepInput, type CodaGetTableRowsStepOutput, type Connection, type ConnectorActionDetail, type ConnectorService, type ConvertPdfToImagesStepInput, type ConvertPdfToImagesStepOutput, type CreateDataSourceStepInput, type CreateDataSourceStepOutput, type CreateGmailDraftStepInput, type CreateGmailDraftStepOutput, type CreateGoogleCalendarEventStepInput, type CreateGoogleCalendarEventStepOutput, type CreateGoogleDocStepInput, type CreateGoogleDocStepOutput, type CreateGoogleSheetStepInput, type CreateGoogleSheetStepOutput, type Db, type DefineTableOptions, type DeleteDataSourceDocumentStepInput, type DeleteDataSourceDocumentStepOutput, type DeleteDataSourceStepInput, type DeleteDataSourceStepOutput, type DeleteGmailEmailStepInput, type DeleteGmailEmailStepOutput, type DeleteGoogleCalendarEventStepInput, type DeleteGoogleCalendarEventStepOutput, type DeleteGoogleSheetRowsStepInput, type DeleteGoogleSheetRowsStepOutput, type DetectChangesStepInput, type DetectChangesStepOutput, type DetectPIIStepInput, type DetectPIIStepOutput, type DiscordEditMessageStepInput, type DiscordEditMessageStepOutput, type DiscordSendFollowUpStepInput, type DiscordSendFollowUpStepOutput, type DiscordSendMessageStepInput, type DiscordSendMessageStepOutput, type DownloadVideoStepInput, type DownloadVideoStepOutput, type EnhanceImageGenerationPromptStepInput, type EnhanceImageGenerationPromptStepOutput, type EnhanceVideoGenerationPromptStepInput, type EnhanceVideoGenerationPromptStepOutput, type EnrichPersonStepInput, type EnrichPersonStepOutput, type ExecuteStepBatchOptions, type ExecuteStepBatchResult, type ExtractAudioFromVideoStepInput, type ExtractAudioFromVideoStepOutput, type ExtractTextStepInput, type ExtractTextStepOutput, type FetchDataSourceDocumentStepInput, type FetchDataSourceDocumentStepOutput, type FetchGoogleDocStepInput, type FetchGoogleDocStepOutput, type FetchGoogleSheetStepInput, type FetchGoogleSheetStepOutput, type FetchSlackChannelHistoryStepInput, type FetchSlackChannelHistoryStepOutput, type FetchYoutubeCaptionsStepInput, type FetchYoutubeCaptionsStepOutput, type FetchYoutubeChannelStepInput, type FetchYoutubeChannelStepOutput, type FetchYoutubeCommentsStepInput, type FetchYoutubeCommentsStepOutput, type FetchYoutubeVideoStepInput, type FetchYoutubeVideoStepOutput, type GenerateAssetStepInput, type GenerateAssetStepOutput, type GenerateChartStepInput, type GenerateChartStepOutput, type GenerateImageStepInput, type GenerateImageStepOutput, type GenerateLipsyncStepInput, type GenerateLipsyncStepOutput, type GenerateMusicStepInput, type GenerateMusicStepOutput, type GeneratePdfStepInput, type GeneratePdfStepOutput, type GenerateStaticVideoFromImageStepInput, type GenerateStaticVideoFromImageStepOutput, type GenerateTextStepInput, type GenerateTextStepOutput, type GenerateVideoStepInput, type GenerateVideoStepOutput, type GetGmailAttachmentsStepInput, type GetGmailAttachmentsStepOutput, type GetGmailDraftStepInput, type GetGmailDraftStepOutput, type GetGmailEmailStepInput, type GetGmailEmailStepOutput, type GetGmailUnreadCountStepInput, type GetGmailUnreadCountStepOutput, type GetGoogleCalendarEventStepInput, type GetGoogleCalendarEventStepOutput, type GetGoogleDriveFileStepInput, type GetGoogleDriveFileStepOutput, type GetGoogleSheetInfoStepInput, type GetGoogleSheetInfoStepOutput, type GetMediaMetadataStepInput, type GetMediaMetadataStepOutput, type HttpRequestStepInput, type HttpRequestStepOutput, type HubspotCreateCompanyStepInput, type HubspotCreateCompanyStepOutput, type HubspotCreateContactStepInput, type HubspotCreateContactStepOutput, type HubspotGetCompanyStepInput, type HubspotGetCompanyStepOutput, type HubspotGetContactStepInput, type HubspotGetContactStepOutput, type HunterApiCompanyEnrichmentStepInput, type HunterApiCompanyEnrichmentStepOutput, type HunterApiDomainSearchStepInput, type HunterApiDomainSearchStepOutput, type HunterApiEmailFinderStepInput, type HunterApiEmailFinderStepOutput, type HunterApiEmailVerificationStepInput, type HunterApiEmailVerificationStepOutput, type HunterApiPersonEnrichmentStepInput, type HunterApiPersonEnrichmentStepOutput, type ImageFaceSwapStepInput, type ImageFaceSwapStepOutput, type ImageRemoveWatermarkStepInput, type ImageRemoveWatermarkStepOutput, type InsertVideoClipsStepInput, type InsertVideoClipsStepOutput, type ListAgentsResult, type ListDataSourcesStepInput, type ListDataSourcesStepOutput, type ListGmailDraftsStepInput, type ListGmailDraftsStepOutput, type ListGmailLabelsStepInput, type ListGmailLabelsStepOutput, type ListGoogleCalendarEventsStepInput, type ListGoogleCalendarEventsStepOutput, type ListGoogleDriveFilesStepInput, type ListGoogleDriveFilesStepOutput, type ListRecentGmailEmailsStepInput, type ListRecentGmailEmailsStepOutput, type LogicStepInput, type LogicStepOutput, type MakeDotComRunScenarioStepInput, type MakeDotComRunScenarioStepOutput, type MergeAudioStepInput, type MergeAudioStepOutput, type MergeVideosStepInput, type MergeVideosStepOutput, MindStudioAgent, MindStudioError, type MindStudioModel, type MindStudioModelSummary, type MixAudioIntoVideoStepInput, type MixAudioIntoVideoStepOutput, type ModelType, type MonacoSnippet, type MonacoSnippetField, type MonacoSnippetFieldType, type MuteVideoStepInput, type MuteVideoStepOutput, type N8nRunNodeStepInput, type N8nRunNodeStepOutput, type NotionCreatePageStepInput, type NotionCreatePageStepOutput, type NotionUpdatePageStepInput, type NotionUpdatePageStepOutput, type PeopleSearchStepInput, type PeopleSearchStepOutput, type PostToLinkedInStepInput, type PostToLinkedInStepOutput, type PostToSlackChannelStepInput, type PostToSlackChannelStepOutput, type PostToXStepInput, type PostToXStepOutput, type PostToZapierStepInput, type PostToZapierStepOutput, type Predicate, type PushInput, Query, type QueryAppDatabaseStepInput, type QueryAppDatabaseStepOutput, type QueryDataSourceStepInput, type QueryDataSourceStepOutput, type QueryExternalDatabaseStepInput, type QueryExternalDatabaseStepOutput, type RedactPIIStepInput, type RedactPIIStepOutput, type RemoveBackgroundFromImageStepInput, type RemoveBackgroundFromImageStepOutput, type ReplyToGmailEmailStepInput, type ReplyToGmailEmailStepOutput, type ResizeVideoStepInput, type ResizeVideoStepOutput, type ResolvedUser, Roles, type RunAgentOptions, type RunAgentResult, type RunFromConnectorRegistryStepInput, type RunFromConnectorRegistryStepOutput, type RunPackagedWorkflowStepInput, type RunPackagedWorkflowStepOutput, type ScrapeFacebookPageStepInput, type ScrapeFacebookPageStepOutput, type ScrapeFacebookPostsStepInput, type ScrapeFacebookPostsStepOutput, type ScrapeInstagramCommentsStepInput, type ScrapeInstagramCommentsStepOutput, type ScrapeInstagramMentionsStepInput, type ScrapeInstagramMentionsStepOutput, type ScrapeInstagramPostsStepInput, type ScrapeInstagramPostsStepOutput, type ScrapeInstagramProfileStepInput, type ScrapeInstagramProfileStepOutput, type ScrapeInstagramReelsStepInput, type ScrapeInstagramReelsStepOutput, type ScrapeLinkedInCompanyStepInput, type ScrapeLinkedInCompanyStepOutput, type ScrapeLinkedInProfileStepInput, type ScrapeLinkedInProfileStepOutput, type ScrapeMetaThreadsProfileStepInput, type ScrapeMetaThreadsProfileStepOutput, type ScrapeUrlStepInput, type ScrapeUrlStepOutput, type ScrapeXPostStepInput, type ScrapeXPostStepOutput, type ScrapeXProfileStepInput, type ScrapeXProfileStepOutput, type ScreenshotUrlStepInput, type ScreenshotUrlStepOutput, type SearchGmailEmailsStepInput, type SearchGmailEmailsStepOutput, type SearchGoogleCalendarEventsStepInput, type SearchGoogleCalendarEventsStepOutput, type SearchGoogleDriveStepInput, type SearchGoogleDriveStepOutput, type SearchGoogleImagesStepInput, type SearchGoogleImagesStepOutput, type SearchGoogleNewsStepInput, type SearchGoogleNewsStepOutput, type SearchGoogleStepInput, type SearchGoogleStepOutput, type SearchGoogleTrendsStepInput, type SearchGoogleTrendsStepOutput, type SearchPerplexityStepInput, type SearchPerplexityStepOutput, type SearchXPostsStepInput, type SearchXPostsStepOutput, type SearchYoutubeStepInput, type SearchYoutubeStepOutput, type SearchYoutubeTrendsStepInput, type SearchYoutubeTrendsStepOutput, type SendEmailStepInput, type SendEmailStepOutput, type SendGmailDraftStepInput, type SendGmailDraftStepOutput, type SendGmailMessageStepInput, type SendGmailMessageStepOutput, type SendSMSStepInput, type SendSMSStepOutput, type SetGmailReadStatusStepInput, type SetGmailReadStatusStepOutput, type SetRunTitleStepInput, type SetRunTitleStepOutput, type SetVariableStepInput, type SetVariableStepOutput, type StepCostEstimateEntry, type StepExecutionMeta, type StepExecutionOptions, type StepExecutionResult, type StepInputMap, type StepMetadata, type StepMethods, type StepName, type StepOutputMap, type SystemFields, Table, type TelegramEditMessageStepInput, type TelegramEditMessageStepOutput, type TelegramReplyToMessageStepInput, type TelegramReplyToMessageStepOutput, type TelegramSendAudioStepInput, type TelegramSendAudioStepOutput, type TelegramSendFileStepInput, type TelegramSendFileStepOutput, type TelegramSendImageStepInput, type TelegramSendImageStepOutput, type TelegramSendMessageStepInput, type TelegramSendMessageStepOutput, type TelegramSendVideoStepInput, type TelegramSendVideoStepOutput, type TelegramSetTypingStepInput, type TelegramSetTypingStepOutput, type TextToSpeechStepInput, type TextToSpeechStepOutput, type TranscribeAudioStepInput, type TranscribeAudioStepOutput, type TrimMediaStepInput, type TrimMediaStepOutput, type UpdateGmailLabelsStepInput, type UpdateGmailLabelsStepOutput, type UpdateGoogleCalendarEventStepInput, type UpdateGoogleCalendarEventStepOutput, type UpdateGoogleDocStepInput, type UpdateGoogleDocStepOutput, type UpdateGoogleSheetStepInput, type UpdateGoogleSheetStepOutput, type UpdateInput, type UploadDataSourceDocumentStepInput, type UploadDataSourceDocumentStepOutput, type UploadFileResult, type UpscaleImageStepInput, type UpscaleImageStepOutput, type UpscaleVideoStepInput, type UpscaleVideoStepOutput, type User, type UserInfoResult, type UserMessageStepInput, type UserMessageStepOutput, type VideoFaceSwapStepInput, type VideoFaceSwapStepOutput, type VideoRemoveBackgroundStepInput, type VideoRemoveBackgroundStepOutput, type VideoRemoveWatermarkStepInput, type VideoRemoveWatermarkStepOutput, type WatermarkImageStepInput, type WatermarkImageStepOutput, type WatermarkVideoStepInput, type WatermarkVideoStepOutput, auth, blockTypeAliases, db, mindstudio as default, mindstudio, monacoSnippets, resolveUser, stepMetadata, stream };
|
|
7947
|
+
export { type Accessor, type ActiveCampaignAddNoteStepInput, type ActiveCampaignAddNoteStepOutput, type ActiveCampaignCreateContactStepInput, type ActiveCampaignCreateContactStepOutput, type AddSubtitlesToVideoStepInput, type AddSubtitlesToVideoStepOutput, type AgentInfo, type AgentOptions, type AirtableCreateUpdateRecordStepInput, type AirtableCreateUpdateRecordStepOutput, type AirtableDeleteRecordStepInput, type AirtableDeleteRecordStepOutput, type AirtableGetRecordStepInput, type AirtableGetRecordStepOutput, type AirtableGetTableRecordsStepInput, type AirtableGetTableRecordsStepOutput, type AnalyzeImageStepInput, type AnalyzeImageStepOutput, type AnalyzeVideoStepInput, type AnalyzeVideoStepOutput, type AppAuthContext, type AppContextResult, type AppDatabase, type AppDatabaseColumnSchema, type AppDatabaseTable, type AppRoleAssignment, AuthContext, type BatchStepInput, type BatchStepResult, type CaptureThumbnailStepInput, type CaptureThumbnailStepOutput, type CheckAppRoleStepInput, type CheckAppRoleStepOutput, type CodaCreateUpdatePageStepInput, type CodaCreateUpdatePageStepOutput, type CodaCreateUpdateRowStepInput, type CodaCreateUpdateRowStepOutput, type CodaFindRowStepInput, type CodaFindRowStepOutput, type CodaGetPageStepInput, type CodaGetPageStepOutput, type CodaGetTableRowsStepInput, type CodaGetTableRowsStepOutput, type Connection, type ConnectorActionDetail, type ConnectorService, type ConvertPdfToImagesStepInput, type ConvertPdfToImagesStepOutput, type CreateDataSourceStepInput, type CreateDataSourceStepOutput, type CreateGmailDraftStepInput, type CreateGmailDraftStepOutput, type CreateGoogleCalendarEventStepInput, type CreateGoogleCalendarEventStepOutput, type CreateGoogleDocStepInput, type CreateGoogleDocStepOutput, type CreateGoogleSheetStepInput, type CreateGoogleSheetStepOutput, type Db, type DefineTableOptions, type DeleteDataSourceDocumentStepInput, type DeleteDataSourceDocumentStepOutput, type DeleteDataSourceStepInput, type DeleteDataSourceStepOutput, type DeleteGmailEmailStepInput, type DeleteGmailEmailStepOutput, type DeleteGoogleCalendarEventStepInput, type DeleteGoogleCalendarEventStepOutput, type DeleteGoogleSheetRowsStepInput, type DeleteGoogleSheetRowsStepOutput, type DetectChangesStepInput, type DetectChangesStepOutput, type DetectPIIStepInput, type DetectPIIStepOutput, type DiscordEditMessageStepInput, type DiscordEditMessageStepOutput, type DiscordSendFollowUpStepInput, type DiscordSendFollowUpStepOutput, type DiscordSendMessageStepInput, type DiscordSendMessageStepOutput, type DownloadVideoStepInput, type DownloadVideoStepOutput, type EnhanceImageGenerationPromptStepInput, type EnhanceImageGenerationPromptStepOutput, type EnhanceVideoGenerationPromptStepInput, type EnhanceVideoGenerationPromptStepOutput, type EnrichPersonStepInput, type EnrichPersonStepOutput, type ExecuteStepBatchOptions, type ExecuteStepBatchResult, type ExtractAudioFromVideoStepInput, type ExtractAudioFromVideoStepOutput, type ExtractTextStepInput, type ExtractTextStepOutput, type FetchDataSourceDocumentStepInput, type FetchDataSourceDocumentStepOutput, type FetchGoogleDocStepInput, type FetchGoogleDocStepOutput, type FetchGoogleSheetStepInput, type FetchGoogleSheetStepOutput, type FetchSlackChannelHistoryStepInput, type FetchSlackChannelHistoryStepOutput, type FetchYoutubeCaptionsStepInput, type FetchYoutubeCaptionsStepOutput, type FetchYoutubeChannelStepInput, type FetchYoutubeChannelStepOutput, type FetchYoutubeCommentsStepInput, type FetchYoutubeCommentsStepOutput, type FetchYoutubeVideoStepInput, type FetchYoutubeVideoStepOutput, type GenerateAssetStepInput, type GenerateAssetStepOutput, type GenerateChartStepInput, type GenerateChartStepOutput, type GenerateImageStepInput, type GenerateImageStepOutput, type GenerateLipsyncStepInput, type GenerateLipsyncStepOutput, type GenerateMusicStepInput, type GenerateMusicStepOutput, type GeneratePdfStepInput, type GeneratePdfStepOutput, type GenerateStaticVideoFromImageStepInput, type GenerateStaticVideoFromImageStepOutput, type GenerateTextStepInput, type GenerateTextStepOutput, type GenerateVideoStepInput, type GenerateVideoStepOutput, type GetGmailAttachmentsStepInput, type GetGmailAttachmentsStepOutput, type GetGmailDraftStepInput, type GetGmailDraftStepOutput, type GetGmailEmailStepInput, type GetGmailEmailStepOutput, type GetGmailUnreadCountStepInput, type GetGmailUnreadCountStepOutput, type GetGoogleCalendarEventStepInput, type GetGoogleCalendarEventStepOutput, type GetGoogleDriveFileStepInput, type GetGoogleDriveFileStepOutput, type GetGoogleSheetInfoStepInput, type GetGoogleSheetInfoStepOutput, type GetMediaMetadataStepInput, type GetMediaMetadataStepOutput, type HttpRequestStepInput, type HttpRequestStepOutput, type HubspotCreateCompanyStepInput, type HubspotCreateCompanyStepOutput, type HubspotCreateContactStepInput, type HubspotCreateContactStepOutput, type HubspotGetCompanyStepInput, type HubspotGetCompanyStepOutput, type HubspotGetContactStepInput, type HubspotGetContactStepOutput, type HunterApiCompanyEnrichmentStepInput, type HunterApiCompanyEnrichmentStepOutput, type HunterApiDomainSearchStepInput, type HunterApiDomainSearchStepOutput, type HunterApiEmailFinderStepInput, type HunterApiEmailFinderStepOutput, type HunterApiEmailVerificationStepInput, type HunterApiEmailVerificationStepOutput, type HunterApiPersonEnrichmentStepInput, type HunterApiPersonEnrichmentStepOutput, type ImageFaceSwapStepInput, type ImageFaceSwapStepOutput, type ImageRemoveWatermarkStepInput, type ImageRemoveWatermarkStepOutput, type InsertVideoClipsStepInput, type InsertVideoClipsStepOutput, type ListAgentsResult, type ListDataSourcesStepInput, type ListDataSourcesStepOutput, type ListGmailDraftsStepInput, type ListGmailDraftsStepOutput, type ListGmailLabelsStepInput, type ListGmailLabelsStepOutput, type ListGoogleCalendarEventsStepInput, type ListGoogleCalendarEventsStepOutput, type ListGoogleDriveFilesStepInput, type ListGoogleDriveFilesStepOutput, type ListRecentGmailEmailsStepInput, type ListRecentGmailEmailsStepOutput, type LogicStepInput, type LogicStepOutput, type MakeDotComRunScenarioStepInput, type MakeDotComRunScenarioStepOutput, type MergeAudioStepInput, type MergeAudioStepOutput, type MergeVideosStepInput, type MergeVideosStepOutput, MindStudioAgent, MindStudioError, type MindStudioModel, type MindStudioModelSummary, type MixAudioIntoVideoStepInput, type MixAudioIntoVideoStepOutput, type ModelType, type MonacoSnippet, type MonacoSnippetField, type MonacoSnippetFieldType, type MuteVideoStepInput, type MuteVideoStepOutput, type N8nRunNodeStepInput, type N8nRunNodeStepOutput, type NotionCreatePageStepInput, type NotionCreatePageStepOutput, type NotionUpdatePageStepInput, type NotionUpdatePageStepOutput, type PeopleSearchStepInput, type PeopleSearchStepOutput, type PostToLinkedInStepInput, type PostToLinkedInStepOutput, type PostToSlackChannelStepInput, type PostToSlackChannelStepOutput, type PostToXStepInput, type PostToXStepOutput, type PostToZapierStepInput, type PostToZapierStepOutput, type Predicate, type PushInput, Query, type QueryAppDatabaseStepInput, type QueryAppDatabaseStepOutput, type QueryDataSourceStepInput, type QueryDataSourceStepOutput, type QueryExternalDatabaseStepInput, type QueryExternalDatabaseStepOutput, type RedactPIIStepInput, type RedactPIIStepOutput, type RemoveBackgroundFromImageStepInput, type RemoveBackgroundFromImageStepOutput, type ReplyToGmailEmailStepInput, type ReplyToGmailEmailStepOutput, type ResizeVideoStepInput, type ResizeVideoStepOutput, type ResolvedUser, Roles, type RunAgentOptions, type RunAgentResult, type RunFromConnectorRegistryStepInput, type RunFromConnectorRegistryStepOutput, type RunPackagedWorkflowStepInput, type RunPackagedWorkflowStepOutput, type ScrapeFacebookPageStepInput, type ScrapeFacebookPageStepOutput, type ScrapeFacebookPostsStepInput, type ScrapeFacebookPostsStepOutput, type ScrapeInstagramCommentsStepInput, type ScrapeInstagramCommentsStepOutput, type ScrapeInstagramMentionsStepInput, type ScrapeInstagramMentionsStepOutput, type ScrapeInstagramPostsStepInput, type ScrapeInstagramPostsStepOutput, type ScrapeInstagramProfileStepInput, type ScrapeInstagramProfileStepOutput, type ScrapeInstagramReelsStepInput, type ScrapeInstagramReelsStepOutput, type ScrapeLinkedInCompanyStepInput, type ScrapeLinkedInCompanyStepOutput, type ScrapeLinkedInProfileStepInput, type ScrapeLinkedInProfileStepOutput, type ScrapeMetaThreadsProfileStepInput, type ScrapeMetaThreadsProfileStepOutput, type ScrapeUrlStepInput, type ScrapeUrlStepOutput, type ScrapeXPostStepInput, type ScrapeXPostStepOutput, type ScrapeXProfileStepInput, type ScrapeXProfileStepOutput, type ScreenshotUrlStepInput, type ScreenshotUrlStepOutput, type SearchGmailEmailsStepInput, type SearchGmailEmailsStepOutput, type SearchGoogleCalendarEventsStepInput, type SearchGoogleCalendarEventsStepOutput, type SearchGoogleDriveStepInput, type SearchGoogleDriveStepOutput, type SearchGoogleImagesStepInput, type SearchGoogleImagesStepOutput, type SearchGoogleNewsStepInput, type SearchGoogleNewsStepOutput, type SearchGoogleStepInput, type SearchGoogleStepOutput, type SearchGoogleTrendsStepInput, type SearchGoogleTrendsStepOutput, type SearchPerplexityStepInput, type SearchPerplexityStepOutput, type SearchXPostsStepInput, type SearchXPostsStepOutput, type SearchYoutubeStepInput, type SearchYoutubeStepOutput, type SearchYoutubeTrendsStepInput, type SearchYoutubeTrendsStepOutput, type SendEmailStepInput, type SendEmailStepOutput, type SendGmailDraftStepInput, type SendGmailDraftStepOutput, type SendGmailMessageStepInput, type SendGmailMessageStepOutput, type SendSMSStepInput, type SendSMSStepOutput, type SetGmailReadStatusStepInput, type SetGmailReadStatusStepOutput, type SetRunTitleStepInput, type SetRunTitleStepOutput, type SetVariableStepInput, type SetVariableStepOutput, type StepCostEstimateEntry, type StepExecutionMeta, type StepExecutionOptions, type StepExecutionResult, type StepInputMap, type StepLogEvent, type StepMetadata, type StepMethods, type StepName, type StepOutputMap, type SystemFields, Table, type TelegramEditMessageStepInput, type TelegramEditMessageStepOutput, type TelegramReplyToMessageStepInput, type TelegramReplyToMessageStepOutput, type TelegramSendAudioStepInput, type TelegramSendAudioStepOutput, type TelegramSendFileStepInput, type TelegramSendFileStepOutput, type TelegramSendImageStepInput, type TelegramSendImageStepOutput, type TelegramSendMessageStepInput, type TelegramSendMessageStepOutput, type TelegramSendVideoStepInput, type TelegramSendVideoStepOutput, type TelegramSetTypingStepInput, type TelegramSetTypingStepOutput, type TextToSpeechStepInput, type TextToSpeechStepOutput, type TranscribeAudioStepInput, type TranscribeAudioStepOutput, type TrimMediaStepInput, type TrimMediaStepOutput, type UpdateGmailLabelsStepInput, type UpdateGmailLabelsStepOutput, type UpdateGoogleCalendarEventStepInput, type UpdateGoogleCalendarEventStepOutput, type UpdateGoogleDocStepInput, type UpdateGoogleDocStepOutput, type UpdateGoogleSheetStepInput, type UpdateGoogleSheetStepOutput, type UpdateInput, type UploadDataSourceDocumentStepInput, type UploadDataSourceDocumentStepOutput, type UploadFileResult, type UpscaleImageStepInput, type UpscaleImageStepOutput, type UpscaleVideoStepInput, type UpscaleVideoStepOutput, type User, type UserInfoResult, type UserMessageStepInput, type UserMessageStepOutput, type VideoFaceSwapStepInput, type VideoFaceSwapStepOutput, type VideoRemoveBackgroundStepInput, type VideoRemoveBackgroundStepOutput, type VideoRemoveWatermarkStepInput, type VideoRemoveWatermarkStepOutput, type WatermarkImageStepInput, type WatermarkImageStepOutput, type WatermarkVideoStepInput, type WatermarkVideoStepOutput, auth, blockTypeAliases, db, mindstudio as default, mindstudio, monacoSnippets, resolveUser, stepMetadata, stream };
|
package/dist/index.js
CHANGED
|
@@ -2063,6 +2063,13 @@ var MindStudioAgent = class {
|
|
|
2063
2063
|
* ```
|
|
2064
2064
|
*/
|
|
2065
2065
|
async executeStep(stepType, step, options) {
|
|
2066
|
+
if (options?.onLog) {
|
|
2067
|
+
return this._executeStepStreaming(
|
|
2068
|
+
stepType,
|
|
2069
|
+
step,
|
|
2070
|
+
options
|
|
2071
|
+
);
|
|
2072
|
+
}
|
|
2066
2073
|
const threadId = options?.threadId ?? (this._reuseThreadId ? this._threadId : void 0);
|
|
2067
2074
|
const { data, headers } = await request(this._httpConfig, "POST", `/steps/${stepType}/execute`, {
|
|
2068
2075
|
step,
|
|
@@ -2107,6 +2114,160 @@ var MindStudioAgent = class {
|
|
|
2107
2114
|
$billingEvents: billingEvents != null ? JSON.parse(billingEvents) : void 0
|
|
2108
2115
|
};
|
|
2109
2116
|
}
|
|
2117
|
+
/**
|
|
2118
|
+
* @internal Streaming step execution — sends `Accept: text/event-stream`
|
|
2119
|
+
* and parses SSE events for real-time debug logs.
|
|
2120
|
+
*/
|
|
2121
|
+
async _executeStepStreaming(stepType, step, options) {
|
|
2122
|
+
const threadId = options.threadId ?? (this._reuseThreadId ? this._threadId : void 0);
|
|
2123
|
+
const url = `${this._httpConfig.baseUrl}/developer/v2/steps/${stepType}/execute`;
|
|
2124
|
+
const body = {
|
|
2125
|
+
step,
|
|
2126
|
+
...options.appId != null && { appId: options.appId },
|
|
2127
|
+
...threadId != null && { threadId },
|
|
2128
|
+
...this._streamId != null && { streamId: this._streamId }
|
|
2129
|
+
};
|
|
2130
|
+
await this._httpConfig.rateLimiter.acquire();
|
|
2131
|
+
let res;
|
|
2132
|
+
try {
|
|
2133
|
+
res = await fetch(url, {
|
|
2134
|
+
method: "POST",
|
|
2135
|
+
headers: {
|
|
2136
|
+
Authorization: `Bearer ${this._httpConfig.token}`,
|
|
2137
|
+
"Content-Type": "application/json",
|
|
2138
|
+
"User-Agent": "@mindstudio-ai/agent",
|
|
2139
|
+
Accept: "text/event-stream"
|
|
2140
|
+
},
|
|
2141
|
+
body: JSON.stringify(body)
|
|
2142
|
+
});
|
|
2143
|
+
} catch (err) {
|
|
2144
|
+
this._httpConfig.rateLimiter.release();
|
|
2145
|
+
throw err;
|
|
2146
|
+
}
|
|
2147
|
+
this._httpConfig.rateLimiter.updateFromHeaders(res.headers);
|
|
2148
|
+
if (!res.ok) {
|
|
2149
|
+
this._httpConfig.rateLimiter.release();
|
|
2150
|
+
const errorBody = await res.json().catch(() => ({}));
|
|
2151
|
+
throw new MindStudioError(
|
|
2152
|
+
errorBody.message || `${res.status} ${res.statusText}`,
|
|
2153
|
+
errorBody.code || "api_error",
|
|
2154
|
+
res.status,
|
|
2155
|
+
errorBody
|
|
2156
|
+
);
|
|
2157
|
+
}
|
|
2158
|
+
const headers = res.headers;
|
|
2159
|
+
try {
|
|
2160
|
+
const reader = res.body.getReader();
|
|
2161
|
+
const decoder = new TextDecoder();
|
|
2162
|
+
let buffer = "";
|
|
2163
|
+
let doneEvent = null;
|
|
2164
|
+
while (true) {
|
|
2165
|
+
const { done, value } = await reader.read();
|
|
2166
|
+
if (done) break;
|
|
2167
|
+
buffer += decoder.decode(value, { stream: true });
|
|
2168
|
+
const lines = buffer.split("\n");
|
|
2169
|
+
buffer = lines.pop() ?? "";
|
|
2170
|
+
for (const line of lines) {
|
|
2171
|
+
if (!line.startsWith("data: ")) continue;
|
|
2172
|
+
try {
|
|
2173
|
+
const event = JSON.parse(line.slice(6));
|
|
2174
|
+
if (event.type === "log") {
|
|
2175
|
+
options.onLog({
|
|
2176
|
+
value: event.value,
|
|
2177
|
+
tag: event.tag,
|
|
2178
|
+
ts: event.ts
|
|
2179
|
+
});
|
|
2180
|
+
} else if (event.type === "done") {
|
|
2181
|
+
doneEvent = {
|
|
2182
|
+
output: event.output,
|
|
2183
|
+
outputUrl: event.outputUrl,
|
|
2184
|
+
billingCost: event.billingCost,
|
|
2185
|
+
billingEvents: event.billingEvents
|
|
2186
|
+
};
|
|
2187
|
+
} else if (event.type === "error") {
|
|
2188
|
+
throw new MindStudioError(
|
|
2189
|
+
event.error || "Step execution failed",
|
|
2190
|
+
"step_error",
|
|
2191
|
+
500
|
|
2192
|
+
);
|
|
2193
|
+
}
|
|
2194
|
+
} catch (err) {
|
|
2195
|
+
if (err instanceof MindStudioError) throw err;
|
|
2196
|
+
}
|
|
2197
|
+
}
|
|
2198
|
+
}
|
|
2199
|
+
if (buffer.startsWith("data: ")) {
|
|
2200
|
+
try {
|
|
2201
|
+
const event = JSON.parse(buffer.slice(6));
|
|
2202
|
+
if (event.type === "done") {
|
|
2203
|
+
doneEvent = {
|
|
2204
|
+
output: event.output,
|
|
2205
|
+
outputUrl: event.outputUrl,
|
|
2206
|
+
billingCost: event.billingCost,
|
|
2207
|
+
billingEvents: event.billingEvents
|
|
2208
|
+
};
|
|
2209
|
+
} else if (event.type === "error") {
|
|
2210
|
+
throw new MindStudioError(
|
|
2211
|
+
event.error || "Step execution failed",
|
|
2212
|
+
"step_error",
|
|
2213
|
+
500
|
|
2214
|
+
);
|
|
2215
|
+
} else if (event.type === "log") {
|
|
2216
|
+
options.onLog({
|
|
2217
|
+
value: event.value,
|
|
2218
|
+
tag: event.tag,
|
|
2219
|
+
ts: event.ts
|
|
2220
|
+
});
|
|
2221
|
+
}
|
|
2222
|
+
} catch (err) {
|
|
2223
|
+
if (err instanceof MindStudioError) throw err;
|
|
2224
|
+
}
|
|
2225
|
+
}
|
|
2226
|
+
if (!doneEvent) {
|
|
2227
|
+
throw new MindStudioError(
|
|
2228
|
+
"Stream ended without a done event",
|
|
2229
|
+
"stream_error",
|
|
2230
|
+
500
|
|
2231
|
+
);
|
|
2232
|
+
}
|
|
2233
|
+
let output;
|
|
2234
|
+
if (doneEvent.output != null) {
|
|
2235
|
+
output = doneEvent.output;
|
|
2236
|
+
} else if (doneEvent.outputUrl) {
|
|
2237
|
+
const s3Res = await fetch(doneEvent.outputUrl);
|
|
2238
|
+
if (!s3Res.ok) {
|
|
2239
|
+
throw new MindStudioError(
|
|
2240
|
+
`Failed to fetch output from S3: ${s3Res.status} ${s3Res.statusText}`,
|
|
2241
|
+
"output_fetch_error",
|
|
2242
|
+
s3Res.status
|
|
2243
|
+
);
|
|
2244
|
+
}
|
|
2245
|
+
const envelope = await s3Res.json();
|
|
2246
|
+
output = envelope.value;
|
|
2247
|
+
} else {
|
|
2248
|
+
output = void 0;
|
|
2249
|
+
}
|
|
2250
|
+
const returnedThreadId = headers.get("x-mindstudio-thread-id") ?? "";
|
|
2251
|
+
if (this._reuseThreadId && returnedThreadId) {
|
|
2252
|
+
this._threadId = returnedThreadId;
|
|
2253
|
+
}
|
|
2254
|
+
const returnedAppId = headers.get("x-mindstudio-app-id");
|
|
2255
|
+
if (!this._appId && returnedAppId) {
|
|
2256
|
+
this._appId = returnedAppId;
|
|
2257
|
+
}
|
|
2258
|
+
const remaining = headers.get("x-ratelimit-remaining");
|
|
2259
|
+
return {
|
|
2260
|
+
...output,
|
|
2261
|
+
$appId: headers.get("x-mindstudio-app-id") ?? "",
|
|
2262
|
+
$threadId: returnedThreadId,
|
|
2263
|
+
$rateLimitRemaining: remaining != null ? parseInt(remaining, 10) : void 0,
|
|
2264
|
+
$billingCost: doneEvent.billingCost,
|
|
2265
|
+
$billingEvents: doneEvent.billingEvents
|
|
2266
|
+
};
|
|
2267
|
+
} finally {
|
|
2268
|
+
this._httpConfig.rateLimiter.release();
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2110
2271
|
/**
|
|
2111
2272
|
* Execute multiple steps in parallel in a single request.
|
|
2112
2273
|
*
|