env-ai
Version:
AI Assistant for Your Local Environment
347 lines (331 loc) • 11 kB
text/typescript
import { CommandModule, Options, Argv } from 'yargs';
import * as zod from 'zod';
import { ZodType, z } from 'zod';
import * as prompts from '@clack/prompts';
import { log } from '@clack/prompts';
function _mergeNamespaces(n, m) {
m.forEach(function (e) {
e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function (k) {
if (k !== 'default' && !(k in n)) {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
});
return Object.freeze(n);
}
declare let version: string;
declare const projectDesc: string;
declare const bugsUrl: string;
declare const projectName: string;
declare const overwrite: {
readonly always: "always";
readonly ask: "ask";
readonly last: "last";
};
declare const theme: {
readonly custom: "custom";
readonly explain: "explain";
readonly docs: "docs";
readonly fix: "fix";
readonly performance: "performance";
readonly refactor: "refactor";
readonly test: "tests";
};
declare const themeDesc: {
readonly custom: "Adapt the system to your needs.";
readonly explain: "Provide clear explanations of code and functionality.";
readonly docs: "Generate user guides and technical documentation.";
readonly fix: "Identify and resolve bugs for accurate output.";
readonly performance: "Improve the efficiency of your code and reduce response times.";
readonly refactor: "Improve code structure for better readability and maintainability.";
readonly test: "Create tests and ensure quality.";
};
declare const PROMPT_VARS: {
readonly CONTENT: "content";
};
declare const consts_PROMPT_VARS: typeof PROMPT_VARS;
declare const consts_bugsUrl: typeof bugsUrl;
declare const consts_overwrite: typeof overwrite;
declare const consts_projectDesc: typeof projectDesc;
declare const consts_projectName: typeof projectName;
declare const consts_theme: typeof theme;
declare const consts_themeDesc: typeof themeDesc;
declare const consts_version: typeof version;
declare namespace consts {
export {
consts_PROMPT_VARS as PROMPT_VARS,
consts_bugsUrl as bugsUrl,
consts_overwrite as overwrite,
consts_projectDesc as projectDesc,
consts_projectName as projectName,
consts_theme as theme,
consts_themeDesc as themeDesc,
consts_version as version,
};
}
declare const argvSchema: zod.ZodObject<{
output: zod.ZodOptional<zod.ZodString>;
input: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
overwrite: zod.ZodOptional<zod.ZodUnion<[zod.ZodLiteral<"always" | "ask" | "last">, ...zod.ZodLiteral<"always" | "ask" | "last">[]]>>;
model: zod.ZodOptional<zod.ZodString>;
prompt: zod.ZodOptional<zod.ZodString>;
system: zod.ZodOptional<zod.ZodString>;
theme: zod.ZodOptional<zod.ZodUnion<[zod.ZodLiteral<"docs" | "custom" | "explain" | "fix" | "performance" | "refactor" | "tests">, ...zod.ZodLiteral<"docs" | "custom" | "explain" | "fix" | "performance" | "refactor" | "tests">[]]>>;
single: zod.ZodOptional<zod.ZodBoolean>;
debug: zod.ZodOptional<zod.ZodBoolean>;
config: zod.ZodOptional<zod.ZodString>;
}, "strip", zod.ZodTypeAny, {
output?: string | undefined;
input?: string[] | undefined;
overwrite?: "always" | "ask" | "last" | undefined;
model?: string | undefined;
prompt?: string | undefined;
system?: string | undefined;
theme?: "docs" | "custom" | "explain" | "fix" | "performance" | "refactor" | "tests" | undefined;
single?: boolean | undefined;
debug?: boolean | undefined;
config?: string | undefined;
}, {
output?: string | undefined;
input?: string[] | undefined;
overwrite?: "always" | "ask" | "last" | undefined;
model?: string | undefined;
prompt?: string | undefined;
system?: string | undefined;
theme?: "docs" | "custom" | "explain" | "fix" | "performance" | "refactor" | "tests" | undefined;
single?: boolean | undefined;
debug?: boolean | undefined;
config?: string | undefined;
}>;
declare const dim: (v: string) => string;
declare const bold: (v: string) => string;
declare const white: (v: string) => string;
declare const green: (v: string) => string;
declare const italic: (v: string) => string;
declare const yellow: (v: string) => string;
declare const red: (v: string) => string;
declare const magenta: (v: string) => string;
declare const blue: (v: string) => string;
declare const underline: (v: string) => string;
declare const grayBright: (v: string) => string;
declare const black: (v: string) => string;
declare const gray: (v: string) => string;
declare const blackBold: (v: string) => string;
declare const introColor: (v: string) => string;
declare const error: (v: string) => string;
declare const warn: (v: string) => string;
declare const success: (v: string) => string;
declare const debug: (v: string) => string;
declare const section: (v: string) => string;
declare const link: (v: string) => string;
declare const c_black: typeof black;
declare const c_blackBold: typeof blackBold;
declare const c_blue: typeof blue;
declare const c_bold: typeof bold;
declare const c_debug: typeof debug;
declare const c_dim: typeof dim;
declare const c_error: typeof error;
declare const c_gray: typeof gray;
declare const c_grayBright: typeof grayBright;
declare const c_green: typeof green;
declare const c_introColor: typeof introColor;
declare const c_italic: typeof italic;
declare const c_link: typeof link;
declare const c_magenta: typeof magenta;
declare const c_red: typeof red;
declare const c_section: typeof section;
declare const c_success: typeof success;
declare const c_underline: typeof underline;
declare const c_warn: typeof warn;
declare const c_white: typeof white;
declare const c_yellow: typeof yellow;
declare namespace c {
export {
c_black as black,
c_blackBold as blackBold,
c_blue as blue,
c_bold as bold,
c_debug as debug,
c_dim as dim,
c_error as error,
c_gray as gray,
c_grayBright as grayBright,
c_green as green,
c_introColor as introColor,
c_italic as italic,
c_link as link,
c_magenta as magenta,
c_red as red,
c_section as section,
c_success as success,
c_underline as underline,
c_warn as warn,
c_white as white,
c_yellow as yellow,
};
}
/**
* Spinner custom. Output is in blue.
* Copy of https://github.com/bombshell-dev/clack/blob/main/packages/prompts/src/index.ts
*
* @returns {void}
*/
declare const spinnerCustom: () => {
start: (msg?: string) => void;
stop: (msg?: string, code?: number) => void;
message: (msg?: string) => void;
};
var p = /*#__PURE__*/_mergeNamespaces({
__proto__: null,
spinnerCustom: spinnerCustom
}, [prompts]);
type ValidateSchema = ZodType<any, any, any>;
type ValidateInfer<O extends ValidateSchema> = z.infer<O>;
type Exact<A, B> = A extends B ? (B extends A ? A : never) : never;
type CmdProps = CommandModule;
type CliInterface<C extends CmdProps> = {
name: string;
desc: string;
options: Record<string, Options>;
run: () => C;
};
type ArgvSchema = ValidateInfer<typeof argvSchema>;
/**Type for check argv schema */
type SetArgv<Opts> = Exact<Opts, ArgvSchema>;
type CoreParams = {
argv: SetArgv<{
/**
* Output path for generated response.
*/
output?: ArgvSchema['output'];
/**
* Glob patterns to input files and URLs.
*/
input?: ArgvSchema['input'];
/**
* Behavior when output file exists.
*/
overwrite?: ArgvSchema['overwrite'];
/**
* Ollama model name to be used for AI interactions.
*/
model?: ArgvSchema['model'];
/**
* Custom prompt text string or path.
*/
prompt?: ArgvSchema['prompt'];
/**
* Custom system text string or path.
*/
system?: ArgvSchema['system'];
/**
* Theme for CLI interface.
*/
theme?: ArgvSchema['theme'];
/**
* Only one response should be generated.
*
* @default false
*/
single?: ArgvSchema['single'];
/**
* Debug mode for additional logging and debugging.
*
* @default false
*/
debug?: ArgvSchema['debug'];
/**
* Path to config file.
* files supported: [.mjs|.js|.json|.yml|.yaml|.toml|.tml]
*/
config?: ArgvSchema['config'];
}>;
c: typeof c;
p: typeof p & {
log: typeof log & {
debug: (title: string, msg: string) => void;
};
};
};
type CliParams = {
argv: Argv;
};
type FnParams = Omit<CoreParams['argv'], 'config'>;
declare class CLI<C extends CmdProps = CmdProps> implements CliInterface<C> {
#private;
protected c: typeof c;
protected p: typeof p;
protected _const: typeof consts;
name: string;
desc: string;
options: CliInterface<C>['options'];
message: {
intro: string;
outro: string;
cancel: string;
error: {
general: string;
debug: string;
debugFlag: (flag: string) => string;
debugContact: (url: string) => string;
unexpected: string;
};
};
constructor(argv: CliParams['argv']);
fn(params: FnParams): Promise<void>;
run(): C;
}
type CLIParams = ConstructorParameters<typeof CLI>[0];
declare class chatCLI extends CLI {
constructor(cli: CLIParams);
}
/**
* The configuration options for the CLI.
*/
type Config = Parameters<chatCLI['fn']>[0];
/**
* Run envai with the given configuration.
*
* @param {object} config - The configuration to use.
* @returns {Promise<void>} The promise that resolves when the CLI is finished.
* @example
* import { run } from 'env-ai'
*
* run({
* input: ['./src/*', '!src/../*', 'https://example.com'],
* theme: 'docs',
* output: 'README.md',
* })
*/
declare const run: (config: Config) => Promise<void>;
/**
* Define a configuration for the CLI.
*
* @param {object} config - The configuration to use.
* @returns {object} The configuration object.
* @example
* import { defineConfig } from 'env-ai'
*
* export default defineConfig({
* input: ['./src/*', '!src/../*', 'https://example.com'],
* theme: 'docs',
* output: 'README.md',
* })
*/
declare const defineConfig: (config: Config) => {
output?: string | undefined;
input?: string[] | undefined;
overwrite?: "always" | "ask" | "last" | undefined;
model?: string | undefined;
prompt?: string | undefined;
system?: string | undefined;
theme?: "custom" | "explain" | "docs" | "fix" | "performance" | "refactor" | "tests" | undefined;
single?: boolean | undefined;
debug?: boolean | undefined;
};
export { chatCLI as CLI, defineConfig, run };
export type { Config };