@tostudy-ai/cli 0.17.3 → 0.17.5

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
@@ -1153,10 +1153,10 @@ function createHttpProvider(apiUrl, token) {
1153
1153
  }
1154
1154
  },
1155
1155
  exercises: {
1156
- validate: async (lessonId, solution, _userId, enrollmentId) => {
1156
+ validate: async (lessonId, solution, _userId, enrollmentId, metadata) => {
1157
1157
  return cliApiFetch(`${base}/exercises/validate`, token, {
1158
1158
  method: "POST",
1159
- body: JSON.stringify({ lessonId, solution, enrollmentId })
1159
+ body: JSON.stringify({ lessonId, solution, enrollmentId, metadata })
1160
1160
  });
1161
1161
  },
1162
1162
  getEnrollmentLevels: async (enrollmentId) => {
@@ -2866,6 +2866,7 @@ var init_errors_pt_br = __esm({
2866
2866
  workspaceCommandDescription: "Gerenciar workspace de estudo local",
2867
2867
  workspaceSetupDescription: "Criar estrutura do workspace para o curso ativo",
2868
2868
  insufficientCredits: "\u274C Voc\xEA est\xE1 sem cr\xE9ditos. Cada resposta do tutor de IA consome cr\xE9ditos para cobrir o processamento. Recarregue em https://tostudy.ai/student/credits para continuar de onde parou.\n",
2869
+ dailyAiLimit: "\u274C Voc\xEA atingiu o teto di\xE1rio de gastos com IA da sua conta. N\xE3o \xE9 falta de cr\xE9ditos: o teto reinicia \xE0 meia-noite (UTC). Para um teto maior, fa\xE7a upgrade do plano em https://tostudy.ai/student/plan.\n",
2869
2870
  workspaceRefusedAtHome: "N\xE3o d\xE1 para configurar o estudo direto na sua pasta pessoal.\nCrie uma pasta para o curso e entre nela antes de continuar:\n\n mkdir ~/meus-cursos && cd ~/meus-cursos\n",
2870
2871
  courseArchived: "Este curso foi arquivado e est\xE1 dispon\xEDvel somente para leitura.\nUse `tostudy lesson` para revisar o conte\xFAdo j\xE1 estudado.\n",
2871
2872
  noActiveCourse: "Nenhum curso ativo nesta pasta.\nVeja seus cursos com `tostudy courses` e ative um com `tostudy select <n>`.\n",
@@ -2888,6 +2889,7 @@ var init_errors_en_us = __esm({
2888
2889
  workspaceCommandDescription: "Manage local study workspace",
2889
2890
  workspaceSetupDescription: "Create the workspace structure for the active course",
2890
2891
  insufficientCredits: "\u274C You're out of credits. Every reply from the AI tutor uses credits to cover processing. Top up at https://tostudy.ai/student/credits to continue from where you stopped.\n",
2892
+ dailyAiLimit: "\u274C You have reached your account's daily AI spending limit. This is not an empty wallet: the limit resets at midnight (UTC). For a higher limit, upgrade your plan at https://tostudy.ai/student/plan.\n",
2891
2893
  workspaceRefusedAtHome: "Study can't be set up directly in your home folder.\nCreate a folder for the course and switch into it first:\n\n mkdir ~/my-courses && cd ~/my-courses\n",
2892
2894
  courseArchived: "This course has been archived and is available for reading only.\nUse `tostudy lesson` to review the content you've already studied.\n",
2893
2895
  noActiveCourse: "No active course in this folder.\nList your courses with `tostudy courses` and activate one with `tostudy select <n>`.\n",
@@ -2934,6 +2936,9 @@ function resolveErrorCode(err) {
2934
2936
  function isInsufficientCreditsError(err) {
2935
2937
  return resolveErrorCode(err).includes("INSUFFICIENT_CREDITS");
2936
2938
  }
2939
+ function isDailyAiLimitError(err) {
2940
+ return resolveErrorCode(err).includes("DAILY_AI_COST_LIMIT_EXCEEDED");
2941
+ }
2937
2942
  function isCourseArchivedError(err) {
2938
2943
  return resolveErrorCode(err).includes("COURSE_ARCHIVED");
2939
2944
  }
@@ -3531,7 +3536,7 @@ var CLI_VERSION;
3531
3536
  var init_version = __esm({
3532
3537
  "src/version.ts"() {
3533
3538
  "use strict";
3534
- CLI_VERSION = true ? "0.17.3" : "0.7.1";
3539
+ CLI_VERSION = true ? "0.17.5" : "0.7.1";
3535
3540
  }
3536
3541
  });
3537
3542
 
@@ -5186,6 +5191,15 @@ var init_hint = __esm({
5186
5191
  // ../../packages/tostudy-core/src/exercises/validate-solution.ts
5187
5192
  async function validateSolution(input2, deps) {
5188
5193
  deps.logger.info("tostudy-core: validateSolution", { lessonId: input2.lessonId });
5194
+ if (input2.metadata !== void 0) {
5195
+ return deps.data.exercises.validate(
5196
+ input2.lessonId,
5197
+ input2.solution,
5198
+ input2.userId,
5199
+ input2.enrollmentId,
5200
+ input2.metadata
5201
+ );
5202
+ }
5189
5203
  return deps.data.exercises.validate(
5190
5204
  input2.lessonId,
5191
5205
  input2.solution,
@@ -20146,6 +20160,7 @@ var init_validate = __esm({
20146
20160
  init_formatter();
20147
20161
  init_init_template();
20148
20162
  init_errors();
20163
+ init_version();
20149
20164
  logger16 = createLogger("cli:validate");
20150
20165
  validateCommand = new Command14("validate").description("Validate your solution for the current exercise").argument("[file]", "Path to the solution file to read").option("--stdin", "Read solution from stdin instead of a file").option("--json", "Output structured JSON").action(async (file2, opts) => {
20151
20166
  try {
@@ -20229,7 +20244,8 @@ var init_validate = __esm({
20229
20244
  lessonId,
20230
20245
  solution,
20231
20246
  userId: session.userId,
20232
- enrollmentId: activeCourse.enrollmentId
20247
+ enrollmentId: activeCourse.enrollmentId,
20248
+ metadata: { clientVersion: CLI_VERSION }
20233
20249
  },
20234
20250
  deps
20235
20251
  );
@@ -20258,6 +20274,12 @@ var init_validate = __esm({
20258
20274
  error(friendly);
20259
20275
  return;
20260
20276
  }
20277
+ if (isDailyAiLimitError(err)) {
20278
+ const friendly = getErrors().dailyAiLimit;
20279
+ if (opts.json) jsonError("daily_ai_limit", { message: friendly });
20280
+ error(friendly);
20281
+ return;
20282
+ }
20261
20283
  const msg = err instanceof Error ? err.message : String(err);
20262
20284
  if (opts.json) jsonError(msg);
20263
20285
  error(msg);
@@ -22305,6 +22327,11 @@ var init_theory = __esm({
22305
22327
  if (opts.json) jsonError("insufficient_credits", { message: friendly });
22306
22328
  error(friendly);
22307
22329
  }
22330
+ if (body.error === "DAILY_AI_COST_LIMIT_EXCEEDED") {
22331
+ const friendly = getErrors().dailyAiLimit;
22332
+ if (opts.json) jsonError("daily_ai_limit", { message: friendly });
22333
+ error(friendly);
22334
+ }
22308
22335
  const msg = body.error ?? body.message ?? `Falha ao pedir teoria (${res.status})`;
22309
22336
  if (opts.json) jsonError("request_failed", { message: msg, code: res.status });
22310
22337
  error(msg);
@@ -22322,6 +22349,12 @@ var init_theory = __esm({
22322
22349
  error(friendly);
22323
22350
  return;
22324
22351
  }
22352
+ if (isDailyAiLimitError(err)) {
22353
+ const friendly = getErrors().dailyAiLimit;
22354
+ if (opts.json) jsonError("daily_ai_limit", { message: friendly });
22355
+ error(friendly);
22356
+ return;
22357
+ }
22325
22358
  const msg = err instanceof Error ? err.message : String(err);
22326
22359
  if (opts.json) jsonError("unexpected_error", { message: msg });
22327
22360
  error(msg);