@mindstudio-ai/agent 0.1.35 → 0.1.36

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/dist/cli.js CHANGED
@@ -1233,8 +1233,11 @@ async function requestWithRetry(config, method, url, body, attempt) {
1233
1233
  try {
1234
1234
  const body2 = JSON.parse(text);
1235
1235
  details = body2;
1236
- const errMsg = body2.error ?? body2.message ?? body2.details;
1236
+ const errMsg = (typeof body2.error === "string" ? body2.error : void 0) ?? (typeof body2.message === "string" ? body2.message : void 0) ?? (typeof body2.details === "string" ? body2.details : void 0);
1237
1237
  if (errMsg) message = errMsg;
1238
+ else if (body2.error || body2.message || body2.details) {
1239
+ message = JSON.stringify(body2.error ?? body2.message ?? body2.details);
1240
+ }
1238
1241
  if (body2.code) code = body2.code;
1239
1242
  } catch {
1240
1243
  if (text && text.length < 500) message = text;
@@ -1474,6 +1477,7 @@ function escapeValue(val) {
1474
1477
  return `'${json.replace(/'/g, "''")}'`;
1475
1478
  }
1476
1479
  function deserializeRow(row, columns) {
1480
+ if (row == null) return row;
1477
1481
  const result = {};
1478
1482
  for (const [key, value] of Object.entries(row)) {
1479
1483
  const col = columns.find((c) => c.name === key);
@@ -2095,6 +2099,8 @@ var init_query = __esm({
2095
2099
  _limit;
2096
2100
  _offset;
2097
2101
  _config;
2102
+ /** @internal Post-process transform applied after row deserialization. */
2103
+ _postProcess;
2098
2104
  constructor(config, options) {
2099
2105
  this._config = config;
2100
2106
  this._predicates = options?.predicates ?? [];
@@ -2102,6 +2108,7 @@ var init_query = __esm({
2102
2108
  this._reversed = options?.reversed ?? false;
2103
2109
  this._limit = options?.limit;
2104
2110
  this._offset = options?.offset;
2111
+ this._postProcess = options?.postProcess;
2105
2112
  }
2106
2113
  _clone(overrides) {
2107
2114
  return new _Query(this._config, {
@@ -2109,7 +2116,8 @@ var init_query = __esm({
2109
2116
  sortAccessor: overrides.sortAccessor ?? this._sortAccessor,
2110
2117
  reversed: overrides.reversed ?? this._reversed,
2111
2118
  limit: overrides.limit ?? this._limit,
2112
- offset: overrides.offset ?? this._offset
2119
+ offset: overrides.offset ?? this._offset,
2120
+ postProcess: overrides.postProcess
2113
2121
  });
2114
2122
  }
2115
2123
  // -------------------------------------------------------------------------
@@ -2133,13 +2141,18 @@ var init_query = __esm({
2133
2141
  // -------------------------------------------------------------------------
2134
2142
  // Terminal methods
2135
2143
  // -------------------------------------------------------------------------
2136
- async first() {
2137
- const rows = await this._clone({ limit: 1 })._execute();
2138
- return rows[0] ?? null;
2144
+ first() {
2145
+ return this._clone({
2146
+ limit: 1,
2147
+ postProcess: (rows) => rows[0] ?? null
2148
+ });
2139
2149
  }
2140
- async last() {
2141
- const rows = await this._clone({ limit: 1, reversed: !this._reversed })._execute();
2142
- return rows[0] ?? null;
2150
+ last() {
2151
+ return this._clone({
2152
+ limit: 1,
2153
+ reversed: !this._reversed,
2154
+ postProcess: (rows) => rows[0] ?? null
2155
+ });
2143
2156
  }
2144
2157
  async count() {
2145
2158
  const compiled = this._compilePredicates();
@@ -2188,10 +2201,10 @@ var init_query = __esm({
2188
2201
  (row) => this._predicates.every((pred) => pred(row))
2189
2202
  );
2190
2203
  }
2191
- async min(accessor) {
2204
+ min(accessor) {
2192
2205
  return this.sortBy(accessor).first();
2193
2206
  }
2194
- async max(accessor) {
2207
+ max(accessor) {
2195
2208
  return this.sortBy(accessor).reverse().first();
2196
2209
  }
2197
2210
  async groupBy(accessor) {
@@ -2230,7 +2243,7 @@ var init_query = __esm({
2230
2243
  limit: this._limit,
2231
2244
  offset: this._offset
2232
2245
  });
2233
- return { type: "query", query, fallbackQuery: null, config: this._config };
2246
+ return { type: "query", query, fallbackQuery: null, config: this._config, postProcess: this._postProcess };
2234
2247
  }
2235
2248
  const fallbackQuery = buildSelect(this._config.tableName);
2236
2249
  return {
@@ -2242,7 +2255,8 @@ var init_query = __esm({
2242
2255
  sortAccessor: this._sortAccessor,
2243
2256
  reversed: this._reversed,
2244
2257
  limit: this._limit,
2245
- offset: this._offset
2258
+ offset: this._offset,
2259
+ postProcess: this._postProcess
2246
2260
  };
2247
2261
  }
2248
2262
  /**
@@ -2259,7 +2273,9 @@ var init_query = __esm({
2259
2273
  compiled.config.columns
2260
2274
  )
2261
2275
  );
2262
- if (compiled.query) return rows;
2276
+ if (compiled.query) {
2277
+ return compiled.postProcess ? compiled.postProcess(rows) : rows;
2278
+ }
2263
2279
  let filtered = compiled.predicates ? rows.filter((row) => compiled.predicates.every((pred) => pred(row))) : rows;
2264
2280
  if (compiled.sortAccessor) {
2265
2281
  const accessor = compiled.sortAccessor;
@@ -2277,16 +2293,19 @@ var init_query = __esm({
2277
2293
  const end = compiled.limit != null ? start + compiled.limit : void 0;
2278
2294
  filtered = filtered.slice(start, end);
2279
2295
  }
2280
- return filtered;
2296
+ return compiled.postProcess ? compiled.postProcess(filtered) : filtered;
2281
2297
  }
2282
2298
  // -------------------------------------------------------------------------
2283
2299
  // PromiseLike
2284
2300
  // -------------------------------------------------------------------------
2285
2301
  then(onfulfilled, onrejected) {
2286
- return this._execute().then(onfulfilled, onrejected);
2302
+ const promise = this._execute().then(
2303
+ (rows) => this._postProcess ? this._postProcess(rows) : rows
2304
+ );
2305
+ return promise.then(onfulfilled, onrejected);
2287
2306
  }
2288
2307
  catch(onrejected) {
2289
- return this._execute().catch(onrejected);
2308
+ return this.then(void 0, onrejected);
2290
2309
  }
2291
2310
  // -------------------------------------------------------------------------
2292
2311
  // Execution internals
@@ -3990,6 +4009,12 @@ var init_client = __esm({
3990
4009
  * ```
3991
4010
  */
3992
4011
  get auth() {
4012
+ if (this._authType === "internal") {
4013
+ const ai = globalThis.ai;
4014
+ if (ai?.auth) {
4015
+ return new AuthContext(ai.auth);
4016
+ }
4017
+ }
3993
4018
  if (!this._auth) {
3994
4019
  this._trySandboxHydration();
3995
4020
  }
@@ -4126,8 +4151,11 @@ var init_client = __esm({
4126
4151
  const text = await res.text();
4127
4152
  try {
4128
4153
  const body = JSON.parse(text);
4129
- const errMsg = body.error ?? body.message ?? body.details;
4154
+ const errMsg = (typeof body.error === "string" ? body.error : void 0) ?? (typeof body.message === "string" ? body.message : void 0) ?? (typeof body.details === "string" ? body.details : void 0);
4130
4155
  if (errMsg) message = errMsg;
4156
+ else if (body.error || body.message || body.details) {
4157
+ message = JSON.stringify(body.error ?? body.message ?? body.details);
4158
+ }
4131
4159
  if (body.code) code = body.code;
4132
4160
  } catch {
4133
4161
  if (text && text.length < 500) message = text;
@@ -4998,7 +5026,7 @@ async function startMcpServer(options) {
4998
5026
  capabilities: { tools: {} },
4999
5027
  serverInfo: {
5000
5028
  name: "mindstudio-agent",
5001
- version: "0.1.35"
5029
+ version: "0.1.36"
5002
5030
  },
5003
5031
  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.'
5004
5032
  });
@@ -5954,7 +5982,7 @@ function isNewerVersion(current, latest) {
5954
5982
  return false;
5955
5983
  }
5956
5984
  async function checkForUpdate() {
5957
- const currentVersion = "0.1.35";
5985
+ const currentVersion = "0.1.36";
5958
5986
  if (!currentVersion) return null;
5959
5987
  try {
5960
5988
  const { loadConfig: loadConfig2, saveConfig: saveConfig2 } = await Promise.resolve().then(() => (init_config(), config_exports));
@@ -5983,7 +6011,7 @@ async function checkForUpdate() {
5983
6011
  }
5984
6012
  }
5985
6013
  function printUpdateNotice(latestVersion) {
5986
- const currentVersion = "0.1.35";
6014
+ const currentVersion = "0.1.36";
5987
6015
  process.stderr.write(
5988
6016
  `
5989
6017
  ${ansi2.cyanBright("Update available")} ${ansi2.gray(currentVersion + " \u2192")} ${ansi2.cyanBold(latestVersion)}
@@ -5996,7 +6024,7 @@ function isStandaloneBinary() {
5996
6024
  return !argv1.includes("node_modules");
5997
6025
  }
5998
6026
  async function cmdUpdate() {
5999
- const currentVersion = "0.1.35";
6027
+ const currentVersion = "0.1.36";
6000
6028
  process.stderr.write(
6001
6029
  ` ${ansi2.gray("Current version:")} ${currentVersion}
6002
6030
  `
@@ -6131,7 +6159,7 @@ async function cmdLogin(options) {
6131
6159
  process.stderr.write("\n");
6132
6160
  printLogo();
6133
6161
  process.stderr.write("\n");
6134
- const ver = "0.1.35";
6162
+ const ver = "0.1.36";
6135
6163
  process.stderr.write(
6136
6164
  ` ${ansi2.bold("MindStudio Agent")} ${ver ? " " + ansi2.gray("v" + ver) : ""}
6137
6165
  `
@@ -6458,7 +6486,7 @@ async function main() {
6458
6486
  try {
6459
6487
  if (command === "version" || command === "-v") {
6460
6488
  process.stdout.write(
6461
- "0.1.35\n"
6489
+ "0.1.36\n"
6462
6490
  );
6463
6491
  return;
6464
6492
  }
package/dist/index.d.ts CHANGED
@@ -725,19 +725,22 @@ interface SqlResult {
725
725
  * performance optimization.
726
726
  */
727
727
 
728
- declare class Query<T> implements PromiseLike<T[]> {
728
+ declare class Query<T, TResult = T[]> implements PromiseLike<TResult> {
729
729
  private readonly _predicates;
730
730
  private readonly _sortAccessor;
731
731
  private readonly _reversed;
732
732
  private readonly _limit;
733
733
  private readonly _offset;
734
734
  private readonly _config;
735
+ /** @internal Post-process transform applied after row deserialization. */
736
+ readonly _postProcess: ((rows: T[]) => TResult) | undefined;
735
737
  constructor(config: TableConfig, options?: {
736
738
  predicates?: Predicate<T>[];
737
739
  sortAccessor?: Accessor<T>;
738
740
  reversed?: boolean;
739
741
  limit?: number;
740
742
  offset?: number;
743
+ postProcess?: (rows: T[]) => TResult;
741
744
  });
742
745
  private _clone;
743
746
  filter(predicate: Predicate<T>): Query<T>;
@@ -745,13 +748,13 @@ declare class Query<T> implements PromiseLike<T[]> {
745
748
  reverse(): Query<T>;
746
749
  take(n: number): Query<T>;
747
750
  skip(n: number): Query<T>;
748
- first(): Promise<T | null>;
749
- last(): Promise<T | null>;
751
+ first(): Query<T, T | null>;
752
+ last(): Query<T, T | null>;
750
753
  count(): Promise<number>;
751
754
  some(): Promise<boolean>;
752
755
  every(): Promise<boolean>;
753
- min(accessor: Accessor<T, number>): Promise<T | null>;
754
- max(accessor: Accessor<T, number>): Promise<T | null>;
756
+ min(accessor: Accessor<T, number>): Query<T, T | null>;
757
+ max(accessor: Accessor<T, number>): Query<T, T | null>;
755
758
  groupBy<K extends string | number>(accessor: Accessor<T, K>): Promise<Map<K, T[]>>;
756
759
  /**
757
760
  * @internal Compile this query into a SqlQuery for batch execution.
@@ -761,7 +764,7 @@ declare class Query<T> implements PromiseLike<T[]> {
761
764
  * `SELECT *` is returned as `fallbackQuery` so the batch can fetch
762
765
  * all rows and this query can filter them in JS post-fetch.
763
766
  */
764
- _compile(): CompiledQuery<T>;
767
+ _compile(): CompiledQuery<T, TResult>;
765
768
  /**
766
769
  * @internal Process raw SQL results into typed rows. Used by db.batch()
767
770
  * after executing the compiled query.
@@ -769,9 +772,9 @@ declare class Query<T> implements PromiseLike<T[]> {
769
772
  * For SQL-compiled queries: just deserialize the rows.
770
773
  * For JS-fallback queries: filter, sort, and slice in JS.
771
774
  */
772
- static _processResults<T>(result: SqlResult, compiled: CompiledQuery<T>): T[];
773
- then<TResult1 = T[], TResult2 = never>(onfulfilled?: ((value: T[]) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
774
- catch<TResult2 = never>(onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<T[] | TResult2>;
775
+ static _processResults<T, R = T[]>(result: SqlResult, compiled: CompiledQuery<T, R>): R;
776
+ then<TResult1 = TResult, TResult2 = never>(onfulfilled?: ((value: TResult) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
777
+ catch<TResult2 = never>(onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult | TResult2>;
775
778
  private _execute;
776
779
  private _compilePredicates;
777
780
  private _fetchAndFilterInJs;
@@ -781,7 +784,7 @@ declare class Query<T> implements PromiseLike<T[]> {
781
784
  * Result of Query._compile(). Contains either a compiled SQL query
782
785
  * (fast path) or a fallback SELECT * with JS processing metadata.
783
786
  */
784
- interface CompiledQuery<T> {
787
+ interface CompiledQuery<T, TResult = T[]> {
785
788
  type: 'query';
786
789
  /** Compiled SQL query, or null if JS fallback needed. */
787
790
  query: SqlQuery | null;
@@ -799,6 +802,8 @@ interface CompiledQuery<T> {
799
802
  limit?: number;
800
803
  /** Offset (only for fallback). */
801
804
  offset?: number;
805
+ /** Post-process transform (e.g. first() extracts [0] ?? null). */
806
+ postProcess?: (rows: T[]) => TResult;
802
807
  }
803
808
 
804
809
  /**
package/dist/index.js CHANGED
@@ -45,8 +45,11 @@ async function requestWithRetry(config, method, url, body, attempt) {
45
45
  try {
46
46
  const body2 = JSON.parse(text);
47
47
  details = body2;
48
- const errMsg = body2.error ?? body2.message ?? body2.details;
48
+ const errMsg = (typeof body2.error === "string" ? body2.error : void 0) ?? (typeof body2.message === "string" ? body2.message : void 0) ?? (typeof body2.details === "string" ? body2.details : void 0);
49
49
  if (errMsg) message = errMsg;
50
+ else if (body2.error || body2.message || body2.details) {
51
+ message = JSON.stringify(body2.error ?? body2.message ?? body2.details);
52
+ }
50
53
  if (body2.code) code = body2.code;
51
54
  } catch {
52
55
  if (text && text.length < 500) message = text;
@@ -244,6 +247,7 @@ function escapeValue(val) {
244
247
  }
245
248
  var USER_PREFIX = "@@user@@";
246
249
  function deserializeRow(row, columns) {
250
+ if (row == null) return row;
247
251
  const result = {};
248
252
  for (const [key, value] of Object.entries(row)) {
249
253
  const col = columns.find((c) => c.name === key);
@@ -838,6 +842,8 @@ var Query = class _Query {
838
842
  _limit;
839
843
  _offset;
840
844
  _config;
845
+ /** @internal Post-process transform applied after row deserialization. */
846
+ _postProcess;
841
847
  constructor(config, options) {
842
848
  this._config = config;
843
849
  this._predicates = options?.predicates ?? [];
@@ -845,6 +851,7 @@ var Query = class _Query {
845
851
  this._reversed = options?.reversed ?? false;
846
852
  this._limit = options?.limit;
847
853
  this._offset = options?.offset;
854
+ this._postProcess = options?.postProcess;
848
855
  }
849
856
  _clone(overrides) {
850
857
  return new _Query(this._config, {
@@ -852,7 +859,8 @@ var Query = class _Query {
852
859
  sortAccessor: overrides.sortAccessor ?? this._sortAccessor,
853
860
  reversed: overrides.reversed ?? this._reversed,
854
861
  limit: overrides.limit ?? this._limit,
855
- offset: overrides.offset ?? this._offset
862
+ offset: overrides.offset ?? this._offset,
863
+ postProcess: overrides.postProcess
856
864
  });
857
865
  }
858
866
  // -------------------------------------------------------------------------
@@ -876,13 +884,18 @@ var Query = class _Query {
876
884
  // -------------------------------------------------------------------------
877
885
  // Terminal methods
878
886
  // -------------------------------------------------------------------------
879
- async first() {
880
- const rows = await this._clone({ limit: 1 })._execute();
881
- return rows[0] ?? null;
887
+ first() {
888
+ return this._clone({
889
+ limit: 1,
890
+ postProcess: (rows) => rows[0] ?? null
891
+ });
882
892
  }
883
- async last() {
884
- const rows = await this._clone({ limit: 1, reversed: !this._reversed })._execute();
885
- return rows[0] ?? null;
893
+ last() {
894
+ return this._clone({
895
+ limit: 1,
896
+ reversed: !this._reversed,
897
+ postProcess: (rows) => rows[0] ?? null
898
+ });
886
899
  }
887
900
  async count() {
888
901
  const compiled = this._compilePredicates();
@@ -931,10 +944,10 @@ var Query = class _Query {
931
944
  (row) => this._predicates.every((pred) => pred(row))
932
945
  );
933
946
  }
934
- async min(accessor) {
947
+ min(accessor) {
935
948
  return this.sortBy(accessor).first();
936
949
  }
937
- async max(accessor) {
950
+ max(accessor) {
938
951
  return this.sortBy(accessor).reverse().first();
939
952
  }
940
953
  async groupBy(accessor) {
@@ -973,7 +986,7 @@ var Query = class _Query {
973
986
  limit: this._limit,
974
987
  offset: this._offset
975
988
  });
976
- return { type: "query", query, fallbackQuery: null, config: this._config };
989
+ return { type: "query", query, fallbackQuery: null, config: this._config, postProcess: this._postProcess };
977
990
  }
978
991
  const fallbackQuery = buildSelect(this._config.tableName);
979
992
  return {
@@ -985,7 +998,8 @@ var Query = class _Query {
985
998
  sortAccessor: this._sortAccessor,
986
999
  reversed: this._reversed,
987
1000
  limit: this._limit,
988
- offset: this._offset
1001
+ offset: this._offset,
1002
+ postProcess: this._postProcess
989
1003
  };
990
1004
  }
991
1005
  /**
@@ -1002,7 +1016,9 @@ var Query = class _Query {
1002
1016
  compiled.config.columns
1003
1017
  )
1004
1018
  );
1005
- if (compiled.query) return rows;
1019
+ if (compiled.query) {
1020
+ return compiled.postProcess ? compiled.postProcess(rows) : rows;
1021
+ }
1006
1022
  let filtered = compiled.predicates ? rows.filter((row) => compiled.predicates.every((pred) => pred(row))) : rows;
1007
1023
  if (compiled.sortAccessor) {
1008
1024
  const accessor = compiled.sortAccessor;
@@ -1020,16 +1036,19 @@ var Query = class _Query {
1020
1036
  const end = compiled.limit != null ? start + compiled.limit : void 0;
1021
1037
  filtered = filtered.slice(start, end);
1022
1038
  }
1023
- return filtered;
1039
+ return compiled.postProcess ? compiled.postProcess(filtered) : filtered;
1024
1040
  }
1025
1041
  // -------------------------------------------------------------------------
1026
1042
  // PromiseLike
1027
1043
  // -------------------------------------------------------------------------
1028
1044
  then(onfulfilled, onrejected) {
1029
- return this._execute().then(onfulfilled, onrejected);
1045
+ const promise = this._execute().then(
1046
+ (rows) => this._postProcess ? this._postProcess(rows) : rows
1047
+ );
1048
+ return promise.then(onfulfilled, onrejected);
1030
1049
  }
1031
1050
  catch(onrejected) {
1032
- return this._execute().catch(onrejected);
1051
+ return this.then(void 0, onrejected);
1033
1052
  }
1034
1053
  // -------------------------------------------------------------------------
1035
1054
  // Execution internals
@@ -3826,6 +3845,12 @@ var MindStudioAgent = class {
3826
3845
  * ```
3827
3846
  */
3828
3847
  get auth() {
3848
+ if (this._authType === "internal") {
3849
+ const ai = globalThis.ai;
3850
+ if (ai?.auth) {
3851
+ return new AuthContext(ai.auth);
3852
+ }
3853
+ }
3829
3854
  if (!this._auth) {
3830
3855
  this._trySandboxHydration();
3831
3856
  }
@@ -3962,8 +3987,11 @@ var MindStudioAgent = class {
3962
3987
  const text = await res.text();
3963
3988
  try {
3964
3989
  const body = JSON.parse(text);
3965
- const errMsg = body.error ?? body.message ?? body.details;
3990
+ const errMsg = (typeof body.error === "string" ? body.error : void 0) ?? (typeof body.message === "string" ? body.message : void 0) ?? (typeof body.details === "string" ? body.details : void 0);
3966
3991
  if (errMsg) message = errMsg;
3992
+ else if (body.error || body.message || body.details) {
3993
+ message = JSON.stringify(body.error ?? body.message ?? body.details);
3994
+ }
3967
3995
  if (body.code) code = body.code;
3968
3996
  } catch {
3969
3997
  if (text && text.length < 500) message = text;