@deepagents/text2sql 0.17.1 → 0.18.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"sql.agent.d.ts","sourceRoot":"","sources":["../../../src/lib/agents/sql.agent.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAEL,KAAK,eAAe,EAKrB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEtD,MAAM,WAAW,YAAY;IAC3B,mDAAmD;IACnD,KAAK,EAAE,MAAM,CAAC;IACd,sCAAsC;IACtC,OAAO,EAAE,OAAO,CAAC;IACjB,kDAAkD;IAClD,eAAe,EAAE,eAAe,EAAE,CAAC;IACnC,wCAAwC;IACxC,YAAY,EAAE,eAAe,EAAE,CAAC;IAChC,8BAA8B;IAC9B,KAAK,EAAE,UAAU,CAAC;IAClB,gEAAgE;IAChE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B,8BAA8B;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,8BAA8B;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,8DAA8D;IAC9D,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAWD,QAAA,MAAM,MAAM,eAA+B,CAAC;AAC5C;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC;gBACH,OAAO,EAAE,MAAM;IAK3B,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,kBAAkB;CAG/D;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;gBACjC,OAAO,EAAE,MAAM;IAI3B,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,O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,GAAG,KAAK,IAAI,oBAAoB;CAGjE;AAED,wBAAsB,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,CAyFvE"}
@@ -911,19 +911,21 @@ async function toSql(options) {
911
911
  const sqlOutput = structuredOutput5({
912
912
  model,
913
913
  context,
914
- schema: z5.union([
915
- z5.object({
916
- sql: z5.string().describe("The SQL query that answers the question"),
917
- reasoning: z5.string().optional().describe("The reasoning steps taken to generate the SQL")
918
- }),
919
- z5.object({
920
- error: z5.string().describe(
921
- "Error message explaining why the question cannot be answered with the given schema"
922
- )
923
- })
924
- ])
914
+ schema: z5.object({
915
+ result: z5.union([
916
+ z5.object({
917
+ sql: z5.string().describe("The SQL query that answers the question"),
918
+ reasoning: z5.string().describe("The reasoning steps taken to generate the SQL")
919
+ }),
920
+ z5.object({
921
+ error: z5.string().describe(
922
+ "Error message explaining why the question cannot be answered with the given schema"
923
+ )
924
+ })
925
+ ])
926
+ })
925
927
  });
926
- const output = await sqlOutput.generate();
928
+ const { result: output } = await sqlOutput.generate();
927
929
  if ("error" in output) {
928
930
  throw new UnanswerableSQLError(output.error);
929
931
  }
@@ -953,6 +955,16 @@ function formatErrorMessage(error) {
953
955
  }
954
956
  return error.message;
955
957
  }
958
+ function isModelUnavailableError(error) {
959
+ if (!APICallError.isInstance(error)) {
960
+ return false;
961
+ }
962
+ const message = error.message.toLowerCase();
963
+ const responseBody = (error.responseBody ?? "").toLowerCase();
964
+ const is404ModelError = error.statusCode === 404 && (message.includes("model") || responseBody.includes("model_not_found"));
965
+ const errorCode = typeof error.data === "object" && error.data !== null && "error" in error.data && typeof error.data.error === "object" && error.data.error !== null && "code" in error.data.error && typeof error.data.error.code === "string" ? error.data.error.code.toLowerCase() : void 0;
966
+ return is404ModelError || errorCode === "model_not_found" || responseBody.includes('"code":"model_not_found"') || message.includes("model") && message.includes("does not exist or you do not have access to it");
967
+ }
956
968
  async function withRetry(computation, options = { retries: 3 }) {
957
969
  const errors = [];
958
970
  let attempts = 0;
@@ -966,6 +978,9 @@ async function withRetry(computation, options = { retries: 3 }) {
966
978
  if (UnanswerableSQLError.isInstance(context.error)) {
967
979
  return false;
968
980
  }
981
+ if (isModelUnavailableError(context.error)) {
982
+ return false;
983
+ }
969
984
  if (SQLValidationError.isInstance(context.error)) {
970
985
  return true;
971
986
  }