@deepagents/text2sql 0.17.1 → 0.19.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.
- package/dist/index.js +343 -18
- package/dist/index.js.map +2 -2
- package/dist/lib/agents/result-tools.d.ts +15 -10
- package/dist/lib/agents/result-tools.d.ts.map +1 -1
- package/dist/lib/agents/sql.agent.d.ts +2 -4
- package/dist/lib/agents/sql.agent.d.ts.map +1 -1
- package/dist/lib/sql.d.ts.map +1 -1
- package/dist/lib/synthesis/index.js +30 -20
- package/dist/lib/synthesis/index.js.map +2 -2
- package/dist/lib/synthesis/synthesizers/depth-evolver.d.ts.map +1 -1
- package/dist/lib/synthesis/synthesizers/schema-synthesizer.d.ts.map +1 -1
- package/package.json +8 -8
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { type IFileSystem } from 'just-bash';
|
|
2
2
|
import type { SkillPathMapping } from '@deepagents/context';
|
|
3
3
|
import type { Adapter } from '../adapters/adapter.ts';
|
|
4
|
+
interface CommandResult {
|
|
5
|
+
stdout: string;
|
|
6
|
+
stderr: string;
|
|
7
|
+
exitCode: number;
|
|
8
|
+
}
|
|
4
9
|
/**
|
|
5
10
|
* Options for creating result tools.
|
|
6
11
|
*/
|
|
@@ -19,17 +24,16 @@ export interface ResultToolsOptions {
|
|
|
19
24
|
* SQL is executed via: sql run "SELECT ..."
|
|
20
25
|
*/
|
|
21
26
|
export declare function createResultTools(options: ResultToolsOptions): Promise<{
|
|
22
|
-
sandbox:
|
|
27
|
+
sandbox: {
|
|
28
|
+
executeCommand: (command: string) => Promise<CommandResult>;
|
|
29
|
+
readFile(path: string): Promise<string>;
|
|
30
|
+
writeFiles(files: Array<{
|
|
31
|
+
path: string;
|
|
32
|
+
content: string | Buffer;
|
|
33
|
+
}>): Promise<void>;
|
|
34
|
+
};
|
|
23
35
|
tools: {
|
|
24
|
-
bash: import("ai").Tool<unknown,
|
|
25
|
-
meta: Record<string, unknown>;
|
|
26
|
-
stdout: string;
|
|
27
|
-
stderr: string;
|
|
28
|
-
exitCode: number;
|
|
29
|
-
} | {
|
|
30
|
-
meta: Record<string, unknown>;
|
|
31
|
-
[Symbol.asyncIterator](): AsyncIterator<import("bash-tool").CommandResult, any, any>;
|
|
32
|
-
}>;
|
|
36
|
+
bash: import("ai").Tool<unknown, CommandResult | AsyncIterable<import("bash-tool").CommandResult>>;
|
|
33
37
|
readFile: import("ai").Tool<{
|
|
34
38
|
path: string;
|
|
35
39
|
}, {
|
|
@@ -43,4 +47,5 @@ export declare function createResultTools(options: ResultToolsOptions): Promise<
|
|
|
43
47
|
}>;
|
|
44
48
|
};
|
|
45
49
|
}>;
|
|
50
|
+
export {};
|
|
46
51
|
//# sourceMappingURL=result-tools.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-tools.d.ts","sourceRoot":"","sources":["../../../src/lib/agents/result-tools.ts"],"names":[],"mappings":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"result-tools.d.ts","sourceRoot":"","sources":["../../../src/lib/agents/result-tools.ts"],"names":[],"mappings":"AAGA,OAAO,EAIL,KAAK,WAAW,EAOjB,MAAM,WAAW,CAAC;AAMnB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEtD,UAAU,aAAa;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB;AA+kBD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,iDAAiD;IACjD,OAAO,EAAE,OAAO,CAAC;IACjB,uDAAuD;IACvD,WAAW,EAAE,gBAAgB,EAAE,CAAC;IAChC,6BAA6B;IAC7B,UAAU,EAAE,WAAW,CAAC;CACzB;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,kBAAkB;;kCA4C/B,MAAM;;;;;;;;;;;;;;;;;;;;;GAoDzC"}
|
|
@@ -6,10 +6,8 @@ export interface ToSqlOptions {
|
|
|
6
6
|
input: string;
|
|
7
7
|
/** Database adapter for validation */
|
|
8
8
|
adapter: Adapter;
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
/** Instructions/teachings to include */
|
|
12
|
-
instructions: ContextFragment[];
|
|
9
|
+
/** Context fragments (schema + instructions/teachings) */
|
|
10
|
+
fragments: ContextFragment[];
|
|
13
11
|
/** Optional model override */
|
|
14
12
|
model: AgentModel;
|
|
15
13
|
/** Maximum retry attempts on validation failure (default: 3) */
|
|
@@ -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,
|
|
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,0DAA0D;IAC1D,SAAS,EAAE,eAAe,EAAE,CAAC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AAO,EAAE,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAE7E,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;AAElE,qBAAa,QAAQ;;gBAYP,MAAM,EAAE;QAClB,OAAO,EAAE,OAAO,CAAC;QACjB,OAAO,EAAE,CAAC,GAAG,SAAS,EAAE,eAAe,EAAE,KAAK,aAAa,CAAC;QAC5D,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,cAAc,CAAC;QACvB,KAAK,EAAE,UAAU,CAAC;QAClB,SAAS,CAAC,EAAE,mBAAmB,CAAC,OAAO,CAAC,GAAG,mBAAmB,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1E,4BAA4B;QAC5B,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;QACpC,UAAU,EAAE,WAAW,CAAC;KACzB;IAeY,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAWlD;;;OAGG;IACU,KAAK,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;IAUhD;;;;;;;;;;;;;;;;;;OAkBG;IACU,OAAO,CAAC,CAAC,SAAS,YAAY,EACzC,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,CAAC,GAC/B,OAAO,CAAC,aAAa,EAAE,CAAC;IAKd,IAAI,CAAC,QAAQ,EAAE,SAAS,EAAE;CAoHxC"}
|
|
@@ -889,8 +889,7 @@ async function toSql(options) {
|
|
|
889
889
|
role: "You are an expert SQL query generator. You translate natural language questions into precise, efficient SQL queries based on the provided database schema.",
|
|
890
890
|
objective: "Translate natural language questions into precise, efficient SQL queries"
|
|
891
891
|
}),
|
|
892
|
-
...options.
|
|
893
|
-
...options.schemaFragments
|
|
892
|
+
...options.fragments
|
|
894
893
|
);
|
|
895
894
|
if (errors.length) {
|
|
896
895
|
context.set(
|
|
@@ -911,19 +910,21 @@ async function toSql(options) {
|
|
|
911
910
|
const sqlOutput = structuredOutput5({
|
|
912
911
|
model,
|
|
913
912
|
context,
|
|
914
|
-
schema: z5.
|
|
915
|
-
z5.
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
913
|
+
schema: z5.object({
|
|
914
|
+
result: z5.union([
|
|
915
|
+
z5.object({
|
|
916
|
+
sql: z5.string().describe("The SQL query that answers the question"),
|
|
917
|
+
reasoning: z5.string().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
|
+
])
|
|
925
|
+
})
|
|
925
926
|
});
|
|
926
|
-
const output = await sqlOutput.generate();
|
|
927
|
+
const { result: output } = await sqlOutput.generate();
|
|
927
928
|
if ("error" in output) {
|
|
928
929
|
throw new UnanswerableSQLError(output.error);
|
|
929
930
|
}
|
|
@@ -953,6 +954,16 @@ function formatErrorMessage(error) {
|
|
|
953
954
|
}
|
|
954
955
|
return error.message;
|
|
955
956
|
}
|
|
957
|
+
function isModelUnavailableError(error) {
|
|
958
|
+
if (!APICallError.isInstance(error)) {
|
|
959
|
+
return false;
|
|
960
|
+
}
|
|
961
|
+
const message = error.message.toLowerCase();
|
|
962
|
+
const responseBody = (error.responseBody ?? "").toLowerCase();
|
|
963
|
+
const is404ModelError = error.statusCode === 404 && (message.includes("model") || responseBody.includes("model_not_found"));
|
|
964
|
+
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;
|
|
965
|
+
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");
|
|
966
|
+
}
|
|
956
967
|
async function withRetry(computation, options = { retries: 3 }) {
|
|
957
968
|
const errors = [];
|
|
958
969
|
let attempts = 0;
|
|
@@ -966,6 +977,9 @@ async function withRetry(computation, options = { retries: 3 }) {
|
|
|
966
977
|
if (UnanswerableSQLError.isInstance(context.error)) {
|
|
967
978
|
return false;
|
|
968
979
|
}
|
|
980
|
+
if (isModelUnavailableError(context.error)) {
|
|
981
|
+
return false;
|
|
982
|
+
}
|
|
969
983
|
if (SQLValidationError.isInstance(context.error)) {
|
|
970
984
|
return true;
|
|
971
985
|
}
|
|
@@ -1061,9 +1075,7 @@ Generate ${this.options.count} questions at ${complexity} complexity.` : void 0;
|
|
|
1061
1075
|
return await toSql({
|
|
1062
1076
|
input: question,
|
|
1063
1077
|
adapter: this.adapter,
|
|
1064
|
-
|
|
1065
|
-
// Placeholder - needs to pass actual fragments
|
|
1066
|
-
instructions: this.options.teachings ?? [],
|
|
1078
|
+
fragments: this.options.teachings ?? [],
|
|
1067
1079
|
model: this.options.model
|
|
1068
1080
|
});
|
|
1069
1081
|
} catch (error) {
|
|
@@ -1440,9 +1452,7 @@ var DepthEvolver = class extends PairProducer {
|
|
|
1440
1452
|
const sqlResult = await toSql({
|
|
1441
1453
|
input: evolvedQuestion,
|
|
1442
1454
|
adapter: this.adapter,
|
|
1443
|
-
|
|
1444
|
-
// Placeholder - needs to pass actual fragments
|
|
1445
|
-
instructions: [],
|
|
1455
|
+
fragments: [],
|
|
1446
1456
|
model: this.options?.model
|
|
1447
1457
|
});
|
|
1448
1458
|
return {
|