@mindstudio-ai/agent 0.1.163 → 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.
@@ -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, {
@@ -2413,6 +2438,25 @@ function nestedComparison(node, negated, params) {
2413
2438
  function withNulls(core, field, nullsMatch) {
2414
2439
  return nullsMatch ? `(${core} OR ${field.sql} IS NULL)` : core;
2415
2440
  }
2441
+ function readsBackAsWritten(value) {
2442
+ if (typeof value !== "string") {
2443
+ return false;
2444
+ }
2445
+ try {
2446
+ JSON.parse(value);
2447
+ return false;
2448
+ } catch {
2449
+ return true;
2450
+ }
2451
+ }
2452
+ function jsonColumnIn(field, values, negated, params) {
2453
+ params.push(JSON.stringify(values.flatMap((v) => [v, JSON.stringify(v)])));
2454
+ return withNulls(
2455
+ `${field.sql} ${negated ? "NOT IN" : "IN"} (SELECT value FROM json_each(?))`,
2456
+ field,
2457
+ negated
2458
+ );
2459
+ }
2416
2460
  function compileNode(node, negated, columns, params) {
2417
2461
  const column = (field) => field.nested ? void 0 : columns.find((c) => c.name === field.column);
2418
2462
  const stored = (field, value) => field.nested ? serializeColumnParam(value, "", []) : serializeColumnParam(value, field.column, columns);
@@ -2430,6 +2474,10 @@ function compileNode(node, negated, columns, params) {
2430
2474
  return nestedComparison(node, negated, params);
2431
2475
  }
2432
2476
  const type = column(node.field)?.type;
2477
+ if (type === "json") {
2478
+ const strictEquals = node.op === "===" ? !negated : node.op === "!==" ? negated : null;
2479
+ return strictEquals !== null && readsBackAsWritten(node.value) ? jsonColumnIn(node.field, [node.value], !strictEquals, params) : null;
2480
+ }
2433
2481
  if (!type || typeof node.value !== VALUE_KIND[type]) {
2434
2482
  return null;
2435
2483
  }
@@ -2450,10 +2498,16 @@ function compileNode(node, negated, columns, params) {
2450
2498
  return null;
2451
2499
  }
2452
2500
  const isNull = negated ? !node.isNull : node.isNull;
2501
+ if (column(node.field)?.type === "json") {
2502
+ return isNull ? `(${node.field.sql} IS NULL OR ${node.field.sql} = 'null')` : `(${node.field.sql} IS NOT NULL AND ${node.field.sql} <> 'null')`;
2503
+ }
2453
2504
  return `${node.field.sql} ${isNull ? "IS NULL" : "IS NOT NULL"}`;
2454
2505
  }
2455
2506
  case "in": {
2456
2507
  const type = column(node.field)?.type;
2508
+ if (type === "json") {
2509
+ return node.values.every(readsBackAsWritten) ? jsonColumnIn(node.field, node.values, negated, params) : null;
2510
+ }
2457
2511
  if (!type || node.values.some(
2458
2512
  (v) => v !== null && v !== void 0 && typeof v !== VALUE_KIND[type]
2459
2513
  )) {
@@ -2473,6 +2527,7 @@ function compileNode(node, negated, columns, params) {
2473
2527
  case "includes": {
2474
2528
  const type = column(node.field)?.type;
2475
2529
  if (type === "json") {
2530
+ const col = node.field.sql;
2476
2531
  let element;
2477
2532
  if (typeof node.needle === "boolean") {
2478
2533
  element = `type = '${node.needle}'`;
@@ -2480,7 +2535,9 @@ function compileNode(node, negated, columns, params) {
2480
2535
  params.push(node.needle);
2481
2536
  element = `type IN ${JSON_TYPES[typeof node.needle]} AND value = ?`;
2482
2537
  }
2483
- return `(json_type(${node.field.sql}) = 'array' AND ${negated ? "NOT EXISTS" : "EXISTS"} (SELECT 1 FROM json_each(${node.field.sql}) WHERE ${element}))`;
2538
+ const substring = `${negated ? "=" : ">"} 0`;
2539
+ params.push(String(node.needle), String(node.needle));
2540
+ return `(CASE WHEN json_valid(${col}) THEN CASE json_type(${col}) WHEN 'array' THEN ${negated ? "NOT EXISTS" : "EXISTS"} (SELECT 1 FROM json_each(${col}) WHERE ${element}) WHEN 'text' THEN instr(${col} ->> '$', ?) ${substring} ELSE 0 END ELSE instr(${col}, ?) ${substring} END)`;
2484
2541
  }
2485
2542
  if ((type === "text" || type === "user") && typeof node.needle === "string") {
2486
2543
  params.push(node.needle);
@@ -9275,6 +9332,7 @@ function summarizeInput(input) {
9275
9332
  async function cmdAsk(question, options) {
9276
9333
  try {
9277
9334
  let lineBuffer = "";
9335
+ const startedAt = Date.now();
9278
9336
  const result = await runAsk(question, options, (event) => {
9279
9337
  switch (event.type) {
9280
9338
  case "text":
@@ -9304,6 +9362,12 @@ async function cmdAsk(question, options) {
9304
9362
  if (lineBuffer) {
9305
9363
  process.stderr.write(lineBuffer);
9306
9364
  }
9365
+ logUsage({
9366
+ action: "ask",
9367
+ billingCost: result.billingCost,
9368
+ billingEvents: result.billingEvents,
9369
+ startedAt
9370
+ });
9307
9371
  if (options.json) {
9308
9372
  process.stdout.write(
9309
9373
  JSON.stringify({
@@ -9328,6 +9392,7 @@ var init_ask = __esm({
9328
9392
  async "src/ask/index.ts"() {
9329
9393
  "use strict";
9330
9394
  await init_client();
9395
+ init_usageLog();
9331
9396
  init_context2();
9332
9397
  init_sse();
9333
9398
  init_tools();
@@ -9402,7 +9467,7 @@ async function startMcpServer(options) {
9402
9467
  capabilities: { tools: {} },
9403
9468
  serverInfo: {
9404
9469
  name: "mindstudio-agent",
9405
- version: "0.1.163"
9470
+ version: "0.1.165"
9406
9471
  },
9407
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.'
9408
9473
  });
@@ -10102,11 +10167,18 @@ async function cmdExec(method, input, options) {
10102
10167
  `);
10103
10168
  };
10104
10169
  }
10170
+ const startedAt = Date.now();
10105
10171
  const result = await agent.executeStep(meta.stepType, input, {
10106
10172
  appId: options.appId,
10107
10173
  threadId: options.threadId,
10108
10174
  onLog
10109
10175
  });
10176
+ logUsage({
10177
+ action: camelToKebab(method),
10178
+ billingCost: result.$billingCost,
10179
+ billingEvents: result.$billingEvents,
10180
+ startedAt
10181
+ });
10110
10182
  if (options.outputKey) {
10111
10183
  const val = result[options.outputKey];
10112
10184
  if (typeof val === "string") {
@@ -10282,10 +10354,18 @@ Example: mindstudio batch '[{"stepType":"generateImage","step":{"prompt":"a cat"
10282
10354
  return { stepType: item.stepType, step: item.step };
10283
10355
  });
10284
10356
  const agent = await createAgent(options);
10357
+ const startedAt = Date.now();
10285
10358
  const result = await agent.executeStepBatch(steps, {
10286
10359
  appId: options.appId,
10287
10360
  threadId: options.threadId
10288
10361
  });
10362
+ for (const step of result.results) {
10363
+ logUsage({
10364
+ action: `batch:${step.stepType}`,
10365
+ billingCost: step.billingCost,
10366
+ startedAt
10367
+ });
10368
+ }
10289
10369
  if (options.noMeta) {
10290
10370
  process.stdout.write(JSON.stringify(result.results, null, 2) + "\n");
10291
10371
  } else {
@@ -10329,7 +10409,7 @@ function isNewerVersion(current, latest) {
10329
10409
  return false;
10330
10410
  }
10331
10411
  async function checkForUpdate() {
10332
- const currentVersion = "0.1.163";
10412
+ const currentVersion = "0.1.165";
10333
10413
  if (!currentVersion || process.env.MINDSTUDIO_NO_UPDATE_CHECK) {
10334
10414
  return null;
10335
10415
  }
@@ -10364,7 +10444,7 @@ async function checkForUpdate() {
10364
10444
  }
10365
10445
  }
10366
10446
  function printUpdateNotice(latestVersion) {
10367
- const currentVersion = "0.1.163";
10447
+ const currentVersion = "0.1.165";
10368
10448
  process.stderr.write(
10369
10449
  `
10370
10450
  ${ansi2.cyanBright("Update available")} ${ansi2.gray(currentVersion + " \u2192")} ${ansi2.cyanBold(latestVersion)}
@@ -10377,7 +10457,7 @@ function isStandaloneBinary() {
10377
10457
  return !argv1.includes("node_modules");
10378
10458
  }
10379
10459
  async function cmdUpdate() {
10380
- const currentVersion = "0.1.163";
10460
+ const currentVersion = "0.1.165";
10381
10461
  process.stderr.write(
10382
10462
  ` ${ansi2.gray("Current version:")} ${currentVersion}
10383
10463
  `
@@ -10498,7 +10578,7 @@ async function cmdLogin(options) {
10498
10578
  process.stderr.write("\n");
10499
10579
  printLogo();
10500
10580
  process.stderr.write("\n");
10501
- const ver = "0.1.163";
10581
+ const ver = "0.1.165";
10502
10582
  process.stderr.write(
10503
10583
  ` ${ansi2.bold("MindStudio Agent")} ${ver ? " " + ansi2.gray("v" + ver) : ""}
10504
10584
  `
@@ -10810,7 +10890,7 @@ async function main() {
10810
10890
  const updatePromise = command !== "mcp" && command !== "login" && command !== "update" ? checkForUpdate() : Promise.resolve(null);
10811
10891
  try {
10812
10892
  if (command === "version" || command === "-v") {
10813
- process.stdout.write("0.1.163\n");
10893
+ process.stdout.write("0.1.165\n");
10814
10894
  return;
10815
10895
  }
10816
10896
  if (command === "login") {
@@ -11270,6 +11350,7 @@ var HELP, MIME_TYPES2, ansi2, UPDATE_CHECK_INTERVAL, LOGO, DEFAULT_BASE_URL2, SP
11270
11350
  var init_cli = __esm({
11271
11351
  "src/cli.ts"() {
11272
11352
  "use strict";
11353
+ init_usageLog();
11273
11354
  HELP = `Usage: mindstudio <command> [options]
11274
11355
 
11275
11356
  Ask:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mindstudio-ai/agent",
3
- "version": "0.1.163",
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",
@@ -17,7 +17,8 @@
17
17
  },
18
18
  "files": [
19
19
  "dist",
20
- "llms.txt"
20
+ "llms.txt",
21
+ "CHANGELOG.md"
21
22
  ],
22
23
  "scripts": {
23
24
  "build": "npm run codegen && tsup",