@mindstudio-ai/agent 0.1.164 → 0.1.165

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/CHANGELOG.md CHANGED
@@ -4,6 +4,12 @@ What changed in `@mindstudio-ai/agent`, newest first, each version under its own
4
4
 
5
5
  Versions before 0.1.163 aren't recorded here.
6
6
 
7
+ ## 0.1.165
8
+
9
+ ### New
10
+
11
+ - The CLI can log what each call costs. When `MINDSTUDIO_USAGE_LOG` names a file, every billed call from an action, `batch` (a line per step) or `ask` appends one JSON line to it: `{ ts, action, billingCost, billingEvents?, durationMs }`, with `billingCost` in nano-dollars. It's for a tool that runs the CLI and keeps its own record of spend, whatever happens to the command's output. App code isn't affected.
12
+
7
13
  ## 0.1.164
8
14
 
9
15
  ### New
package/dist/cli.js CHANGED
@@ -9,6 +9,31 @@ var __export = (target, all) => {
9
9
  __defProp(target, name, { get: all[name], enumerable: true });
10
10
  };
11
11
 
12
+ // src/usageLog.ts
13
+ import { appendFileSync } from "fs";
14
+ function logUsage(entry) {
15
+ const file = process.env.MINDSTUDIO_USAGE_LOG;
16
+ if (!file || typeof entry.billingCost !== "number") {
17
+ return;
18
+ }
19
+ const line = {
20
+ ts: Date.now(),
21
+ action: entry.action,
22
+ billingCost: entry.billingCost,
23
+ ...entry.billingEvents?.length && { billingEvents: entry.billingEvents },
24
+ durationMs: Date.now() - entry.startedAt
25
+ };
26
+ try {
27
+ appendFileSync(file, JSON.stringify(line) + "\n");
28
+ } catch {
29
+ }
30
+ }
31
+ var init_usageLog = __esm({
32
+ "src/usageLog.ts"() {
33
+ "use strict";
34
+ }
35
+ });
36
+
12
37
  // src/generated/metadata.ts
13
38
  var metadata_exports = {};
14
39
  __export(metadata_exports, {
@@ -9307,6 +9332,7 @@ function summarizeInput(input) {
9307
9332
  async function cmdAsk(question, options) {
9308
9333
  try {
9309
9334
  let lineBuffer = "";
9335
+ const startedAt = Date.now();
9310
9336
  const result = await runAsk(question, options, (event) => {
9311
9337
  switch (event.type) {
9312
9338
  case "text":
@@ -9336,6 +9362,12 @@ async function cmdAsk(question, options) {
9336
9362
  if (lineBuffer) {
9337
9363
  process.stderr.write(lineBuffer);
9338
9364
  }
9365
+ logUsage({
9366
+ action: "ask",
9367
+ billingCost: result.billingCost,
9368
+ billingEvents: result.billingEvents,
9369
+ startedAt
9370
+ });
9339
9371
  if (options.json) {
9340
9372
  process.stdout.write(
9341
9373
  JSON.stringify({
@@ -9360,6 +9392,7 @@ var init_ask = __esm({
9360
9392
  async "src/ask/index.ts"() {
9361
9393
  "use strict";
9362
9394
  await init_client();
9395
+ init_usageLog();
9363
9396
  init_context2();
9364
9397
  init_sse();
9365
9398
  init_tools();
@@ -9434,7 +9467,7 @@ async function startMcpServer(options) {
9434
9467
  capabilities: { tools: {} },
9435
9468
  serverInfo: {
9436
9469
  name: "mindstudio-agent",
9437
- version: "0.1.164"
9470
+ version: "0.1.165"
9438
9471
  },
9439
9472
  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, pass its public image URL to `changeProfilePicture`.\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.'
9440
9473
  });
@@ -9885,6 +9918,7 @@ var init_mcp = __esm({
9885
9918
  });
9886
9919
 
9887
9920
  // src/cli.ts
9921
+ init_usageLog();
9888
9922
  import { parseArgs } from "util";
9889
9923
  import { execSync } from "child_process";
9890
9924
  import { readFileSync as readFileSync3 } from "fs";
@@ -10204,11 +10238,18 @@ async function cmdExec(method, input, options) {
10204
10238
  `);
10205
10239
  };
10206
10240
  }
10241
+ const startedAt = Date.now();
10207
10242
  const result = await agent.executeStep(meta.stepType, input, {
10208
10243
  appId: options.appId,
10209
10244
  threadId: options.threadId,
10210
10245
  onLog
10211
10246
  });
10247
+ logUsage({
10248
+ action: camelToKebab(method),
10249
+ billingCost: result.$billingCost,
10250
+ billingEvents: result.$billingEvents,
10251
+ startedAt
10252
+ });
10212
10253
  if (options.outputKey) {
10213
10254
  const val = result[options.outputKey];
10214
10255
  if (typeof val === "string") {
@@ -10384,10 +10425,18 @@ Example: mindstudio batch '[{"stepType":"generateImage","step":{"prompt":"a cat"
10384
10425
  return { stepType: item.stepType, step: item.step };
10385
10426
  });
10386
10427
  const agent = await createAgent(options);
10428
+ const startedAt = Date.now();
10387
10429
  const result = await agent.executeStepBatch(steps, {
10388
10430
  appId: options.appId,
10389
10431
  threadId: options.threadId
10390
10432
  });
10433
+ for (const step of result.results) {
10434
+ logUsage({
10435
+ action: `batch:${step.stepType}`,
10436
+ billingCost: step.billingCost,
10437
+ startedAt
10438
+ });
10439
+ }
10391
10440
  if (options.noMeta) {
10392
10441
  process.stdout.write(JSON.stringify(result.results, null, 2) + "\n");
10393
10442
  } else {
@@ -10458,7 +10507,7 @@ function isNewerVersion(current, latest) {
10458
10507
  return false;
10459
10508
  }
10460
10509
  async function checkForUpdate() {
10461
- const currentVersion = "0.1.164";
10510
+ const currentVersion = "0.1.165";
10462
10511
  if (!currentVersion || process.env.MINDSTUDIO_NO_UPDATE_CHECK) {
10463
10512
  return null;
10464
10513
  }
@@ -10493,7 +10542,7 @@ async function checkForUpdate() {
10493
10542
  }
10494
10543
  }
10495
10544
  function printUpdateNotice(latestVersion) {
10496
- const currentVersion = "0.1.164";
10545
+ const currentVersion = "0.1.165";
10497
10546
  process.stderr.write(
10498
10547
  `
10499
10548
  ${ansi2.cyanBright("Update available")} ${ansi2.gray(currentVersion + " \u2192")} ${ansi2.cyanBold(latestVersion)}
@@ -10506,7 +10555,7 @@ function isStandaloneBinary() {
10506
10555
  return !argv1.includes("node_modules");
10507
10556
  }
10508
10557
  async function cmdUpdate() {
10509
- const currentVersion = "0.1.164";
10558
+ const currentVersion = "0.1.165";
10510
10559
  process.stderr.write(
10511
10560
  ` ${ansi2.gray("Current version:")} ${currentVersion}
10512
10561
  `
@@ -10647,7 +10696,7 @@ async function cmdLogin(options) {
10647
10696
  process.stderr.write("\n");
10648
10697
  printLogo();
10649
10698
  process.stderr.write("\n");
10650
- const ver = "0.1.164";
10699
+ const ver = "0.1.165";
10651
10700
  process.stderr.write(
10652
10701
  ` ${ansi2.bold("MindStudio Agent")} ${ver ? " " + ansi2.gray("v" + ver) : ""}
10653
10702
  `
@@ -10975,7 +11024,7 @@ async function main() {
10975
11024
  const updatePromise = command !== "mcp" && command !== "login" && command !== "update" ? checkForUpdate() : Promise.resolve(null);
10976
11025
  try {
10977
11026
  if (command === "version" || command === "-v") {
10978
- process.stdout.write("0.1.164\n");
11027
+ process.stdout.write("0.1.165\n");
10979
11028
  return;
10980
11029
  }
10981
11030
  if (command === "login") {
@@ -9,6 +9,31 @@ var __export = (target, all) => {
9
9
  __defProp(target, name, { get: all[name], enumerable: true });
10
10
  };
11
11
 
12
+ // src/usageLog.ts
13
+ import { appendFileSync } from "fs";
14
+ function logUsage(entry) {
15
+ const file = process.env.MINDSTUDIO_USAGE_LOG;
16
+ if (!file || typeof entry.billingCost !== "number") {
17
+ return;
18
+ }
19
+ const line = {
20
+ ts: Date.now(),
21
+ action: entry.action,
22
+ billingCost: entry.billingCost,
23
+ ...entry.billingEvents?.length && { billingEvents: entry.billingEvents },
24
+ durationMs: Date.now() - entry.startedAt
25
+ };
26
+ try {
27
+ appendFileSync(file, JSON.stringify(line) + "\n");
28
+ } catch {
29
+ }
30
+ }
31
+ var init_usageLog = __esm({
32
+ "src/usageLog.ts"() {
33
+ "use strict";
34
+ }
35
+ });
36
+
12
37
  // src/generated/metadata.ts
13
38
  var metadata_exports = {};
14
39
  __export(metadata_exports, {
@@ -9307,6 +9332,7 @@ function summarizeInput(input) {
9307
9332
  async function cmdAsk(question, options) {
9308
9333
  try {
9309
9334
  let lineBuffer = "";
9335
+ const startedAt = Date.now();
9310
9336
  const result = await runAsk(question, options, (event) => {
9311
9337
  switch (event.type) {
9312
9338
  case "text":
@@ -9336,6 +9362,12 @@ async function cmdAsk(question, options) {
9336
9362
  if (lineBuffer) {
9337
9363
  process.stderr.write(lineBuffer);
9338
9364
  }
9365
+ logUsage({
9366
+ action: "ask",
9367
+ billingCost: result.billingCost,
9368
+ billingEvents: result.billingEvents,
9369
+ startedAt
9370
+ });
9339
9371
  if (options.json) {
9340
9372
  process.stdout.write(
9341
9373
  JSON.stringify({
@@ -9360,6 +9392,7 @@ var init_ask = __esm({
9360
9392
  async "src/ask/index.ts"() {
9361
9393
  "use strict";
9362
9394
  await init_client();
9395
+ init_usageLog();
9363
9396
  init_context2();
9364
9397
  init_sse();
9365
9398
  init_tools();
@@ -9434,7 +9467,7 @@ async function startMcpServer(options) {
9434
9467
  capabilities: { tools: {} },
9435
9468
  serverInfo: {
9436
9469
  name: "mindstudio-agent",
9437
- version: "0.1.164"
9470
+ version: "0.1.165"
9438
9471
  },
9439
9472
  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, pass its public image URL to `changeProfilePicture`.\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.'
9440
9473
  });
@@ -10134,11 +10167,18 @@ async function cmdExec(method, input, options) {
10134
10167
  `);
10135
10168
  };
10136
10169
  }
10170
+ const startedAt = Date.now();
10137
10171
  const result = await agent.executeStep(meta.stepType, input, {
10138
10172
  appId: options.appId,
10139
10173
  threadId: options.threadId,
10140
10174
  onLog
10141
10175
  });
10176
+ logUsage({
10177
+ action: camelToKebab(method),
10178
+ billingCost: result.$billingCost,
10179
+ billingEvents: result.$billingEvents,
10180
+ startedAt
10181
+ });
10142
10182
  if (options.outputKey) {
10143
10183
  const val = result[options.outputKey];
10144
10184
  if (typeof val === "string") {
@@ -10314,10 +10354,18 @@ Example: mindstudio batch '[{"stepType":"generateImage","step":{"prompt":"a cat"
10314
10354
  return { stepType: item.stepType, step: item.step };
10315
10355
  });
10316
10356
  const agent = await createAgent(options);
10357
+ const startedAt = Date.now();
10317
10358
  const result = await agent.executeStepBatch(steps, {
10318
10359
  appId: options.appId,
10319
10360
  threadId: options.threadId
10320
10361
  });
10362
+ for (const step of result.results) {
10363
+ logUsage({
10364
+ action: `batch:${step.stepType}`,
10365
+ billingCost: step.billingCost,
10366
+ startedAt
10367
+ });
10368
+ }
10321
10369
  if (options.noMeta) {
10322
10370
  process.stdout.write(JSON.stringify(result.results, null, 2) + "\n");
10323
10371
  } else {
@@ -10361,7 +10409,7 @@ function isNewerVersion(current, latest) {
10361
10409
  return false;
10362
10410
  }
10363
10411
  async function checkForUpdate() {
10364
- const currentVersion = "0.1.164";
10412
+ const currentVersion = "0.1.165";
10365
10413
  if (!currentVersion || process.env.MINDSTUDIO_NO_UPDATE_CHECK) {
10366
10414
  return null;
10367
10415
  }
@@ -10396,7 +10444,7 @@ async function checkForUpdate() {
10396
10444
  }
10397
10445
  }
10398
10446
  function printUpdateNotice(latestVersion) {
10399
- const currentVersion = "0.1.164";
10447
+ const currentVersion = "0.1.165";
10400
10448
  process.stderr.write(
10401
10449
  `
10402
10450
  ${ansi2.cyanBright("Update available")} ${ansi2.gray(currentVersion + " \u2192")} ${ansi2.cyanBold(latestVersion)}
@@ -10409,7 +10457,7 @@ function isStandaloneBinary() {
10409
10457
  return !argv1.includes("node_modules");
10410
10458
  }
10411
10459
  async function cmdUpdate() {
10412
- const currentVersion = "0.1.164";
10460
+ const currentVersion = "0.1.165";
10413
10461
  process.stderr.write(
10414
10462
  ` ${ansi2.gray("Current version:")} ${currentVersion}
10415
10463
  `
@@ -10530,7 +10578,7 @@ async function cmdLogin(options) {
10530
10578
  process.stderr.write("\n");
10531
10579
  printLogo();
10532
10580
  process.stderr.write("\n");
10533
- const ver = "0.1.164";
10581
+ const ver = "0.1.165";
10534
10582
  process.stderr.write(
10535
10583
  ` ${ansi2.bold("MindStudio Agent")} ${ver ? " " + ansi2.gray("v" + ver) : ""}
10536
10584
  `
@@ -10842,7 +10890,7 @@ async function main() {
10842
10890
  const updatePromise = command !== "mcp" && command !== "login" && command !== "update" ? checkForUpdate() : Promise.resolve(null);
10843
10891
  try {
10844
10892
  if (command === "version" || command === "-v") {
10845
- process.stdout.write("0.1.164\n");
10893
+ process.stdout.write("0.1.165\n");
10846
10894
  return;
10847
10895
  }
10848
10896
  if (command === "login") {
@@ -11302,6 +11350,7 @@ var HELP, MIME_TYPES2, ansi2, UPDATE_CHECK_INTERVAL, LOGO, DEFAULT_BASE_URL2, SP
11302
11350
  var init_cli = __esm({
11303
11351
  "src/cli.ts"() {
11304
11352
  "use strict";
11353
+ init_usageLog();
11305
11354
  HELP = `Usage: mindstudio <command> [options]
11306
11355
 
11307
11356
  Ask:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mindstudio-ai/agent",
3
- "version": "0.1.164",
3
+ "version": "0.1.165",
4
4
  "description": "TypeScript SDK for MindStudio direct step execution",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",