@deepagents/text2sql 1.0.0 → 2.2.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.
@@ -0,0 +1,32 @@
1
+ import type { Command } from 'just-bash';
2
+ import { Text2Sql } from './sql.ts';
3
+ export interface CreateSqlCommandOptions {
4
+ /**
5
+ * Default directory for `sql run` / `sql index` artifacts when no `--out-dir`
6
+ * is passed and `$TEXT2SQL_OUT_DIR` is unset. Defaults to `/sql`.
7
+ */
8
+ outputDir?: string;
9
+ }
10
+ export interface CreateSqlCommandResult {
11
+ command: Command;
12
+ repair: (raw: string) => string;
13
+ }
14
+ /**
15
+ * Wrap a {@link Text2Sql} instance as a just-bash custom command, exposing
16
+ * `sql run`, `sql validate`, and `sql index` inside any sandbox that accepts
17
+ * `customCommands` (e.g. `createVirtualSandbox`). Argv matches the standalone
18
+ * `sql` CLI exactly, so prompts written against one work against the other.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * const text2Sql = new Text2Sql({ adapters: { pagila } });
23
+ * const { command } = createSqlCommand(text2Sql);
24
+ * const sandbox = await createVirtualSandbox({
25
+ * fs: new InMemoryFs(),
26
+ * customCommands: [command],
27
+ * });
28
+ * await sandbox.executeCommand('sql run pagila "SELECT 1"');
29
+ * ```
30
+ */
31
+ export declare function createSqlCommand(text2Sql: Text2Sql, options?: CreateSqlCommandOptions): CreateSqlCommandResult;
32
+ //# sourceMappingURL=sql-command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql-command.d.ts","sourceRoot":"","sources":["../../src/lib/sql-command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAA8B,MAAM,WAAW,CAAC;AAYrE,OAAO,EACL,QAAQ,EAGT,MAAM,UAAU,CAAC;AAclB,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;CACjC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,QAAQ,EAClB,OAAO,GAAE,uBAA4B,GACpC,sBAAsB,CA6BxB"}
package/dist/lib/sql.d.ts CHANGED
@@ -1,21 +1,45 @@
1
1
  import { type AgentModel } from '@deepagents/agent';
2
+ import type { ContextFragment } from '@deepagents/context';
3
+ import { type Text2SqlIndexProgressHandler } from './adapter-index.ts';
2
4
  import { type Adapter } from './adapters/adapter.ts';
3
5
  import { type ExtractedPair, type PairProducer } from './synthesis/types.ts';
4
6
  export interface Text2SqlConfig {
5
7
  adapters: Record<string, Adapter>;
6
- version: string;
7
- model: AgentModel;
8
+ version?: string;
9
+ model?: AgentModel;
10
+ }
11
+ export interface Text2SqlRunResult {
12
+ rows: unknown[];
13
+ columns: string[];
14
+ }
15
+ export interface Text2SqlIndexOptions {
16
+ names?: readonly string[];
17
+ onProgress?: Text2SqlIndexProgressHandler;
18
+ }
19
+ declare const text2SqlValidationMarker: unique symbol;
20
+ declare const text2SqlUnknownAdapterMarker: unique symbol;
21
+ export declare class Text2SqlValidationError extends Error {
22
+ [text2SqlValidationMarker]: true;
23
+ constructor(message: string);
24
+ static isInstance(error: unknown): error is Text2SqlValidationError;
25
+ }
26
+ export declare class Text2SqlUnknownAdapterError extends Error {
27
+ [text2SqlUnknownAdapterMarker]: true;
28
+ readonly adapter: string;
29
+ readonly available: readonly string[];
30
+ constructor(adapter: string, available: readonly string[]);
31
+ static isInstance(error: unknown): error is Text2SqlUnknownAdapterError;
8
32
  }
9
- /**
10
- * Stateless `toSql` for one or more configured adapters.
11
- * Build the streaming chat agent yourself with `agent` + `chat` from
12
- * `@deepagents/context`, passing `instructions()` and fragments from
13
- * `AdapterIndexer` into the engine.
14
- */
15
33
  export declare class Text2Sql {
16
34
  #private;
17
35
  constructor(config: Text2SqlConfig);
36
+ adapterNames(): string[];
37
+ hasAdapter(name: string): boolean;
38
+ validate(name: string, sql: string): Promise<string>;
39
+ run(name: string, sql: string): Promise<Text2SqlRunResult>;
40
+ index(options?: Text2SqlIndexOptions): Promise<ContextFragment[]>;
18
41
  toSql(input: string, adapterName: string): Promise<string>;
19
42
  toPairs<T extends PairProducer>(adapterName: string, factory: (adapter: Adapter) => T): Promise<ExtractedPair[]>;
20
43
  }
44
+ export {};
21
45
  //# sourceMappingURL=sql.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["../../src/lib/sql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAIpD,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAE7E,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,UAAU,CAAC;CACnB;AAED;;;;;GAKG;AACH,qBAAa,QAAQ;;gBAIP,MAAM,EAAE,cAAc;IAsBrB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAY1D,OAAO,CAAC,CAAC,SAAS,YAAY,EACzC,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,CAAC,GAC/B,OAAO,CAAC,aAAa,EAAE,CAAC;CAK5B"}
1
+ {"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["../../src/lib/sql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM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