@hypercli/gen 0.1.1
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/LICENSE +21 -0
- package/README.md +24 -0
- package/dist/actions/communication.d.ts +201 -0
- package/dist/actions/communication.d.ts.map +1 -0
- package/dist/actions/communication.js +515 -0
- package/dist/actions/communication.js.map +1 -0
- package/dist/actions/decorator.d.ts +22 -0
- package/dist/actions/decorator.d.ts.map +1 -0
- package/dist/actions/decorator.js +110 -0
- package/dist/actions/decorator.js.map +1 -0
- package/dist/actions/executor.d.ts +85 -0
- package/dist/actions/executor.d.ts.map +1 -0
- package/dist/actions/executor.js +289 -0
- package/dist/actions/executor.js.map +1 -0
- package/dist/actions/index.d.ts +14 -0
- package/dist/actions/index.d.ts.map +1 -0
- package/dist/actions/index.js +15 -0
- package/dist/actions/index.js.map +1 -0
- package/dist/actions/parameter-resolver.d.ts +54 -0
- package/dist/actions/parameter-resolver.d.ts.map +1 -0
- package/dist/actions/parameter-resolver.js +300 -0
- package/dist/actions/parameter-resolver.js.map +1 -0
- package/dist/actions/registry.d.ts +78 -0
- package/dist/actions/registry.d.ts.map +1 -0
- package/dist/actions/registry.js +221 -0
- package/dist/actions/registry.js.map +1 -0
- package/dist/actions/types.d.ts +109 -0
- package/dist/actions/types.d.ts.map +1 -0
- package/dist/actions/types.js +31 -0
- package/dist/actions/types.js.map +1 -0
- package/dist/actions/utils.d.ts +42 -0
- package/dist/actions/utils.d.ts.map +1 -0
- package/dist/actions/utils.js +144 -0
- package/dist/actions/utils.js.map +1 -0
- package/dist/ai/ai-collector.d.ts +52 -0
- package/dist/ai/ai-collector.d.ts.map +1 -0
- package/dist/ai/ai-collector.js +64 -0
- package/dist/ai/ai-collector.js.map +1 -0
- package/dist/ai/ai-config.d.ts +230 -0
- package/dist/ai/ai-config.d.ts.map +1 -0
- package/dist/ai/ai-config.js +8 -0
- package/dist/ai/ai-config.js.map +1 -0
- package/dist/ai/ai-service.d.ts +66 -0
- package/dist/ai/ai-service.d.ts.map +1 -0
- package/dist/ai/ai-service.js +198 -0
- package/dist/ai/ai-service.js.map +1 -0
- package/dist/ai/ai-variable-resolver.d.ts +59 -0
- package/dist/ai/ai-variable-resolver.d.ts.map +1 -0
- package/dist/ai/ai-variable-resolver.js +219 -0
- package/dist/ai/ai-variable-resolver.js.map +1 -0
- package/dist/ai/context-collector.d.ts +30 -0
- package/dist/ai/context-collector.d.ts.map +1 -0
- package/dist/ai/context-collector.js +158 -0
- package/dist/ai/context-collector.js.map +1 -0
- package/dist/ai/cost-tracker.d.ts +41 -0
- package/dist/ai/cost-tracker.d.ts.map +1 -0
- package/dist/ai/cost-tracker.js +131 -0
- package/dist/ai/cost-tracker.js.map +1 -0
- package/dist/ai/env.d.ts +36 -0
- package/dist/ai/env.d.ts.map +1 -0
- package/dist/ai/env.js +100 -0
- package/dist/ai/env.js.map +1 -0
- package/dist/ai/index.d.ts +17 -0
- package/dist/ai/index.d.ts.map +1 -0
- package/dist/ai/index.js +25 -0
- package/dist/ai/index.js.map +1 -0
- package/dist/ai/model-router.d.ts +32 -0
- package/dist/ai/model-router.d.ts.map +1 -0
- package/dist/ai/model-router.js +113 -0
- package/dist/ai/model-router.js.map +1 -0
- package/dist/ai/output-validator.d.ts +24 -0
- package/dist/ai/output-validator.d.ts.map +1 -0
- package/dist/ai/output-validator.js +279 -0
- package/dist/ai/output-validator.js.map +1 -0
- package/dist/ai/prompt-assembler.d.ts +30 -0
- package/dist/ai/prompt-assembler.d.ts.map +1 -0
- package/dist/ai/prompt-assembler.js +93 -0
- package/dist/ai/prompt-assembler.js.map +1 -0
- package/dist/ai/prompt-pipeline.d.ts +63 -0
- package/dist/ai/prompt-pipeline.d.ts.map +1 -0
- package/dist/ai/prompt-pipeline.js +119 -0
- package/dist/ai/prompt-pipeline.js.map +1 -0
- package/dist/ai/prompt-template.jig +88 -0
- package/dist/ai/transports/api-transport.d.ts +12 -0
- package/dist/ai/transports/api-transport.d.ts.map +1 -0
- package/dist/ai/transports/api-transport.js +86 -0
- package/dist/ai/transports/api-transport.js.map +1 -0
- package/dist/ai/transports/command-transport.d.ts +20 -0
- package/dist/ai/transports/command-transport.d.ts.map +1 -0
- package/dist/ai/transports/command-transport.js +203 -0
- package/dist/ai/transports/command-transport.js.map +1 -0
- package/dist/ai/transports/index.d.ts +11 -0
- package/dist/ai/transports/index.d.ts.map +1 -0
- package/dist/ai/transports/index.js +10 -0
- package/dist/ai/transports/index.js.map +1 -0
- package/dist/ai/transports/resolve-transport.d.ts +15 -0
- package/dist/ai/transports/resolve-transport.d.ts.map +1 -0
- package/dist/ai/transports/resolve-transport.js +96 -0
- package/dist/ai/transports/resolve-transport.js.map +1 -0
- package/dist/ai/transports/stdout-transport.d.ts +14 -0
- package/dist/ai/transports/stdout-transport.d.ts.map +1 -0
- package/dist/ai/transports/stdout-transport.js +27 -0
- package/dist/ai/transports/stdout-transport.js.map +1 -0
- package/dist/ai/transports/types.d.ts +77 -0
- package/dist/ai/transports/types.d.ts.map +1 -0
- package/dist/ai/transports/types.js +8 -0
- package/dist/ai/transports/types.js.map +1 -0
- package/dist/commands/cookbook/info.d.ts +22 -0
- package/dist/commands/cookbook/info.d.ts.map +1 -0
- package/dist/commands/cookbook/info.js +217 -0
- package/dist/commands/cookbook/info.js.map +1 -0
- package/dist/commands/cookbook/list.d.ts +20 -0
- package/dist/commands/cookbook/list.d.ts.map +1 -0
- package/dist/commands/cookbook/list.js +133 -0
- package/dist/commands/cookbook/list.js.map +1 -0
- package/dist/commands/gen.d.ts +65 -0
- package/dist/commands/gen.d.ts.map +1 -0
- package/dist/commands/gen.js +478 -0
- package/dist/commands/gen.js.map +1 -0
- package/dist/commands/recipe/info.d.ts +18 -0
- package/dist/commands/recipe/info.d.ts.map +1 -0
- package/dist/commands/recipe/info.js +89 -0
- package/dist/commands/recipe/info.js.map +1 -0
- package/dist/commands/recipe/list.d.ts +29 -0
- package/dist/commands/recipe/list.d.ts.map +1 -0
- package/dist/commands/recipe/list.js +215 -0
- package/dist/commands/recipe/list.js.map +1 -0
- package/dist/commands/recipe/run.d.ts +44 -0
- package/dist/commands/recipe/run.d.ts.map +1 -0
- package/dist/commands/recipe/run.js +239 -0
- package/dist/commands/recipe/run.js.map +1 -0
- package/dist/commands/recipe/validate.d.ts +19 -0
- package/dist/commands/recipe/validate.d.ts.map +1 -0
- package/dist/commands/recipe/validate.js +66 -0
- package/dist/commands/recipe/validate.js.map +1 -0
- package/dist/discovery/generator-discovery.d.ts +130 -0
- package/dist/discovery/generator-discovery.d.ts.map +1 -0
- package/dist/discovery/generator-discovery.js +674 -0
- package/dist/discovery/generator-discovery.js.map +1 -0
- package/dist/discovery/index.d.ts +8 -0
- package/dist/discovery/index.d.ts.map +1 -0
- package/dist/discovery/index.js +7 -0
- package/dist/discovery/index.js.map +1 -0
- package/dist/hooks/command-not-found.d.ts +18 -0
- package/dist/hooks/command-not-found.d.ts.map +1 -0
- package/dist/hooks/command-not-found.js +182 -0
- package/dist/hooks/command-not-found.js.map +1 -0
- package/dist/hooks/suggest.d.ts +13 -0
- package/dist/hooks/suggest.d.ts.map +1 -0
- package/dist/hooks/suggest.js +28 -0
- package/dist/hooks/suggest.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/base-command.d.ts +26 -0
- package/dist/lib/base-command.d.ts.map +1 -0
- package/dist/lib/base-command.js +24 -0
- package/dist/lib/base-command.js.map +1 -0
- package/dist/lib/flags.d.ts +33 -0
- package/dist/lib/flags.d.ts.map +1 -0
- package/dist/lib/flags.js +64 -0
- package/dist/lib/flags.js.map +1 -0
- package/dist/ops/add.d.ts +4 -0
- package/dist/ops/add.d.ts.map +1 -0
- package/dist/ops/add.js +85 -0
- package/dist/ops/add.js.map +1 -0
- package/dist/ops/inject.d.ts +4 -0
- package/dist/ops/inject.d.ts.map +1 -0
- package/dist/ops/inject.js +28 -0
- package/dist/ops/inject.js.map +1 -0
- package/dist/ops/injector.d.ts +4 -0
- package/dist/ops/injector.d.ts.map +1 -0
- package/dist/ops/injector.js +68 -0
- package/dist/ops/injector.js.map +1 -0
- package/dist/ops/result.d.ts +3 -0
- package/dist/ops/result.d.ts.map +1 -0
- package/dist/ops/result.js +8 -0
- package/dist/ops/result.js.map +1 -0
- package/dist/prompts/interactive-prompts.d.ts +152 -0
- package/dist/prompts/interactive-prompts.d.ts.map +1 -0
- package/dist/prompts/interactive-prompts.js +574 -0
- package/dist/prompts/interactive-prompts.js.map +1 -0
- package/dist/recipe-engine/group-executor.d.ts +97 -0
- package/dist/recipe-engine/group-executor.d.ts.map +1 -0
- package/dist/recipe-engine/group-executor.js +293 -0
- package/dist/recipe-engine/group-executor.js.map +1 -0
- package/dist/recipe-engine/index.d.ts +112 -0
- package/dist/recipe-engine/index.d.ts.map +1 -0
- package/dist/recipe-engine/index.js +223 -0
- package/dist/recipe-engine/index.js.map +1 -0
- package/dist/recipe-engine/output-evaluator.d.ts +28 -0
- package/dist/recipe-engine/output-evaluator.d.ts.map +1 -0
- package/dist/recipe-engine/output-evaluator.js +78 -0
- package/dist/recipe-engine/output-evaluator.js.map +1 -0
- package/dist/recipe-engine/recipe-engine.d.ts +227 -0
- package/dist/recipe-engine/recipe-engine.d.ts.map +1 -0
- package/dist/recipe-engine/recipe-engine.js +1036 -0
- package/dist/recipe-engine/recipe-engine.js.map +1 -0
- package/dist/recipe-engine/step-executor.d.ts +172 -0
- package/dist/recipe-engine/step-executor.d.ts.map +1 -0
- package/dist/recipe-engine/step-executor.js +802 -0
- package/dist/recipe-engine/step-executor.js.map +1 -0
- package/dist/recipe-engine/tools/action-tool.d.ts +103 -0
- package/dist/recipe-engine/tools/action-tool.d.ts.map +1 -0
- package/dist/recipe-engine/tools/action-tool.js +473 -0
- package/dist/recipe-engine/tools/action-tool.js.map +1 -0
- package/dist/recipe-engine/tools/ai-tool.d.ts +26 -0
- package/dist/recipe-engine/tools/ai-tool.d.ts.map +1 -0
- package/dist/recipe-engine/tools/ai-tool.js +233 -0
- package/dist/recipe-engine/tools/ai-tool.js.map +1 -0
- package/dist/recipe-engine/tools/base.d.ts +214 -0
- package/dist/recipe-engine/tools/base.d.ts.map +1 -0
- package/dist/recipe-engine/tools/base.js +397 -0
- package/dist/recipe-engine/tools/base.js.map +1 -0
- package/dist/recipe-engine/tools/codemod-tool.d.ts +130 -0
- package/dist/recipe-engine/tools/codemod-tool.d.ts.map +1 -0
- package/dist/recipe-engine/tools/codemod-tool.js +786 -0
- package/dist/recipe-engine/tools/codemod-tool.js.map +1 -0
- package/dist/recipe-engine/tools/ensure-dirs-tool.d.ts +21 -0
- package/dist/recipe-engine/tools/ensure-dirs-tool.d.ts.map +1 -0
- package/dist/recipe-engine/tools/ensure-dirs-tool.js +130 -0
- package/dist/recipe-engine/tools/ensure-dirs-tool.js.map +1 -0
- package/dist/recipe-engine/tools/index.d.ts +126 -0
- package/dist/recipe-engine/tools/index.d.ts.map +1 -0
- package/dist/recipe-engine/tools/index.js +290 -0
- package/dist/recipe-engine/tools/index.js.map +1 -0
- package/dist/recipe-engine/tools/install-tool.d.ts +20 -0
- package/dist/recipe-engine/tools/install-tool.d.ts.map +1 -0
- package/dist/recipe-engine/tools/install-tool.js +194 -0
- package/dist/recipe-engine/tools/install-tool.js.map +1 -0
- package/dist/recipe-engine/tools/parallel-tool.d.ts +21 -0
- package/dist/recipe-engine/tools/parallel-tool.d.ts.map +1 -0
- package/dist/recipe-engine/tools/parallel-tool.js +134 -0
- package/dist/recipe-engine/tools/parallel-tool.js.map +1 -0
- package/dist/recipe-engine/tools/patch-tool.d.ts +21 -0
- package/dist/recipe-engine/tools/patch-tool.d.ts.map +1 -0
- package/dist/recipe-engine/tools/patch-tool.js +248 -0
- package/dist/recipe-engine/tools/patch-tool.js.map +1 -0
- package/dist/recipe-engine/tools/prompt-tool.d.ts +25 -0
- package/dist/recipe-engine/tools/prompt-tool.d.ts.map +1 -0
- package/dist/recipe-engine/tools/prompt-tool.js +162 -0
- package/dist/recipe-engine/tools/prompt-tool.js.map +1 -0
- package/dist/recipe-engine/tools/query-tool.d.ts +21 -0
- package/dist/recipe-engine/tools/query-tool.d.ts.map +1 -0
- package/dist/recipe-engine/tools/query-tool.js +249 -0
- package/dist/recipe-engine/tools/query-tool.js.map +1 -0
- package/dist/recipe-engine/tools/recipe-tool.d.ts +103 -0
- package/dist/recipe-engine/tools/recipe-tool.d.ts.map +1 -0
- package/dist/recipe-engine/tools/recipe-tool.js +617 -0
- package/dist/recipe-engine/tools/recipe-tool.js.map +1 -0
- package/dist/recipe-engine/tools/registry.d.ts +151 -0
- package/dist/recipe-engine/tools/registry.d.ts.map +1 -0
- package/dist/recipe-engine/tools/registry.js +244 -0
- package/dist/recipe-engine/tools/registry.js.map +1 -0
- package/dist/recipe-engine/tools/sequence-tool.d.ts +22 -0
- package/dist/recipe-engine/tools/sequence-tool.d.ts.map +1 -0
- package/dist/recipe-engine/tools/sequence-tool.js +122 -0
- package/dist/recipe-engine/tools/sequence-tool.js.map +1 -0
- package/dist/recipe-engine/tools/shell-tool.d.ts +25 -0
- package/dist/recipe-engine/tools/shell-tool.d.ts.map +1 -0
- package/dist/recipe-engine/tools/shell-tool.js +149 -0
- package/dist/recipe-engine/tools/shell-tool.js.map +1 -0
- package/dist/recipe-engine/tools/template-tool.d.ts +88 -0
- package/dist/recipe-engine/tools/template-tool.d.ts.map +1 -0
- package/dist/recipe-engine/tools/template-tool.js +613 -0
- package/dist/recipe-engine/tools/template-tool.js.map +1 -0
- package/dist/recipe-engine/types.d.ts +963 -0
- package/dist/recipe-engine/types.d.ts.map +1 -0
- package/dist/recipe-engine/types.js +94 -0
- package/dist/recipe-engine/types.js.map +1 -0
- package/dist/template-engines/ai-tags.d.ts +26 -0
- package/dist/template-engines/ai-tags.d.ts.map +1 -0
- package/dist/template-engines/ai-tags.js +233 -0
- package/dist/template-engines/ai-tags.js.map +1 -0
- package/dist/template-engines/index.d.ts +8 -0
- package/dist/template-engines/index.d.ts.map +1 -0
- package/dist/template-engines/index.js +8 -0
- package/dist/template-engines/index.js.map +1 -0
- package/dist/template-engines/jig-engine.d.ts +47 -0
- package/dist/template-engines/jig-engine.d.ts.map +1 -0
- package/dist/template-engines/jig-engine.js +173 -0
- package/dist/template-engines/jig-engine.js.map +1 -0
- package/dist/utils/coerce-value.d.ts +7 -0
- package/dist/utils/coerce-value.d.ts.map +1 -0
- package/dist/utils/coerce-value.js +18 -0
- package/dist/utils/coerce-value.js.map +1 -0
- package/dist/utils/diff.d.ts +8 -0
- package/dist/utils/diff.d.ts.map +1 -0
- package/dist/utils/diff.js +10 -0
- package/dist/utils/diff.js.map +1 -0
- package/dist/utils/global-packages.d.ts +11 -0
- package/dist/utils/global-packages.d.ts.map +1 -0
- package/dist/utils/global-packages.js +88 -0
- package/dist/utils/global-packages.js.map +1 -0
- package/dist/utils/pager.d.ts +6 -0
- package/dist/utils/pager.d.ts.map +1 -0
- package/dist/utils/pager.js +41 -0
- package/dist/utils/pager.js.map +1 -0
- package/help/cookbook/info.md +35 -0
- package/help/cookbook/list.md +37 -0
- package/help/gen.md +26 -0
- package/help/recipe/run.md +52 -0
- package/help/recipe/validate.md +51 -0
- package/oclif.manifest.json +580 -0
- package/package.json +120 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt Assembler
|
|
3
|
+
*
|
|
4
|
+
* Takes AiCollector data and produces a self-contained markdown document
|
|
5
|
+
* that an AI agent (or human) can read, answer, and save as JSON.
|
|
6
|
+
*
|
|
7
|
+
* Uses a Jig template internally — the same engine Hypergen users write
|
|
8
|
+
* templates in. A custom template path can be provided via the
|
|
9
|
+
* `ai.promptTemplate` config key or `--prompt-template` CLI flag.
|
|
10
|
+
*/
|
|
11
|
+
import type { AiCollector } from "./ai-collector.js";
|
|
12
|
+
import type { PromptVariable } from "./transports/types.js";
|
|
13
|
+
export interface AssemblerOptions {
|
|
14
|
+
/** The original command that was run (for the callback instruction) */
|
|
15
|
+
originalCommand: string;
|
|
16
|
+
/** Suggested path for the answers JSON file */
|
|
17
|
+
answersPath?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Path to a custom Jig prompt template.
|
|
20
|
+
* When provided, this template is used instead of the built-in one.
|
|
21
|
+
*/
|
|
22
|
+
promptTemplate?: string;
|
|
23
|
+
/** Recipe variables with definitions and current values */
|
|
24
|
+
variables?: PromptVariable[];
|
|
25
|
+
}
|
|
26
|
+
export declare class PromptAssembler {
|
|
27
|
+
assemble(collector: AiCollector, options: AssemblerOptions): string;
|
|
28
|
+
private loadTemplate;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=prompt-assembler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-assembler.d.ts","sourceRoot":"","sources":["../../src/ai/prompt-assembler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAOH,OAAO,KAAK,EAAgB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAS5D,MAAM,WAAW,gBAAgB;IAChC,uEAAuE;IACvE,eAAe,EAAE,MAAM,CAAC;IAExB,+CAA+C;IAC/C,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,2DAA2D;IAC3D,SAAS,CAAC,EAAE,cAAc,EAAE,CAAC;CAC7B;AAED,qBAAa,eAAe;IAC3B,QAAQ,CAAC,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,gBAAgB,GAAG,MAAM;IAsEnE,OAAO,CAAC,YAAY;CAYpB"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt Assembler
|
|
3
|
+
*
|
|
4
|
+
* Takes AiCollector data and produces a self-contained markdown document
|
|
5
|
+
* that an AI agent (or human) can read, answer, and save as JSON.
|
|
6
|
+
*
|
|
7
|
+
* Uses a Jig template internally — the same engine Hypergen users write
|
|
8
|
+
* templates in. A custom template path can be provided via the
|
|
9
|
+
* `ai.promptTemplate` config key or `--prompt-template` CLI flag.
|
|
10
|
+
*/
|
|
11
|
+
import fs from "node:fs";
|
|
12
|
+
import path from "node:path";
|
|
13
|
+
import { fileURLToPath } from "node:url";
|
|
14
|
+
import createDebug from "debug";
|
|
15
|
+
import { renderTemplateSync } from "#template-engines/jig-engine";
|
|
16
|
+
const debug = createDebug("hypergen:ai:prompt-assembler");
|
|
17
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
18
|
+
/** Path to the built-in prompt template shipped with Hypergen */
|
|
19
|
+
const DEFAULT_TEMPLATE_PATH = path.join(__dirname, "prompt-template.jig");
|
|
20
|
+
export class PromptAssembler {
|
|
21
|
+
assemble(collector, options) {
|
|
22
|
+
const globalContexts = collector.getGlobalContexts();
|
|
23
|
+
const entriesMap = collector.getEntries();
|
|
24
|
+
const answersPath = options.answersPath || "./ai-answers.json";
|
|
25
|
+
// Convert Map to array for Jig @each iteration
|
|
26
|
+
const entries = [];
|
|
27
|
+
for (const [, entry] of entriesMap) {
|
|
28
|
+
entries.push({
|
|
29
|
+
...entry,
|
|
30
|
+
hasOutputDesc: !!entry.outputDescription.trim(),
|
|
31
|
+
hasExamples: (entry.examples && entry.examples.length > 0) || false,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
// Separate variables into unprovided (need answers) and provided (for context)
|
|
35
|
+
const allVariables = options.variables || [];
|
|
36
|
+
const unprovidedVariables = allVariables
|
|
37
|
+
.filter((v) => !v.provided)
|
|
38
|
+
.map((v, i) => ({
|
|
39
|
+
...v,
|
|
40
|
+
index: i + 1,
|
|
41
|
+
prompt: v.prompt?.replace(/\n/g, " ").trim(),
|
|
42
|
+
}));
|
|
43
|
+
const providedVariables = allVariables.filter((v) => v.provided);
|
|
44
|
+
// Build the JSON response schema
|
|
45
|
+
const schema = {};
|
|
46
|
+
for (const entry of entries) {
|
|
47
|
+
schema[entry.key] =
|
|
48
|
+
entry.hasOutputDesc || entry.hasExamples ? "<see format above>" : "<your answer>";
|
|
49
|
+
}
|
|
50
|
+
for (const v of unprovidedVariables) {
|
|
51
|
+
schema[v.name] =
|
|
52
|
+
v.default !== undefined
|
|
53
|
+
? `<optional, default: ${JSON.stringify(v.default)}>`
|
|
54
|
+
: "<your answer>";
|
|
55
|
+
}
|
|
56
|
+
const responseSchema = JSON.stringify(schema, null, 2);
|
|
57
|
+
const hasContext = globalContexts.length > 0 || entries.some((e) => e.contexts.length > 0);
|
|
58
|
+
const hasVariables = unprovidedVariables.length > 0;
|
|
59
|
+
const templatePath = options.promptTemplate || DEFAULT_TEMPLATE_PATH;
|
|
60
|
+
const templateSource = this.loadTemplate(templatePath, !!options.promptTemplate);
|
|
61
|
+
const context = {
|
|
62
|
+
globalContexts,
|
|
63
|
+
entries,
|
|
64
|
+
responseSchema,
|
|
65
|
+
hasContext,
|
|
66
|
+
hasVariables,
|
|
67
|
+
unprovidedVariables,
|
|
68
|
+
providedVariables,
|
|
69
|
+
originalCommand: options.originalCommand,
|
|
70
|
+
answersPath,
|
|
71
|
+
};
|
|
72
|
+
try {
|
|
73
|
+
const result = renderTemplateSync(templateSource, context);
|
|
74
|
+
debug("Assembled prompt (%d chars, %d entries)", result.length, entries.length);
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
throw new Error(`Failed to render prompt template: ${error.message}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
loadTemplate(templatePath, isCustom) {
|
|
82
|
+
try {
|
|
83
|
+
return fs.readFileSync(templatePath, "utf-8");
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
if (isCustom) {
|
|
87
|
+
throw new Error(`Custom prompt template not found: ${templatePath}\nProvide an absolute path or a path relative to the working directory.`);
|
|
88
|
+
}
|
|
89
|
+
throw new Error(`Built-in prompt template missing: ${templatePath}`);
|
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ACF,CAAC;CACD"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt Pipeline
|
|
3
|
+
*
|
|
4
|
+
* 5-stage pipeline that transforms user prompts into fully assembled
|
|
5
|
+
* AI requests ready for the Vercel AI SDK.
|
|
6
|
+
*
|
|
7
|
+
* Stages:
|
|
8
|
+
* 1. Liquid rendering — resolve {{ variables }} in prompt text
|
|
9
|
+
* 2. Context collection — read files, configs, step results
|
|
10
|
+
* 3. Token budgeting — estimate, truncate if needed
|
|
11
|
+
* 4. Prompt assembly — system + context + examples + user prompt
|
|
12
|
+
* 5. Pre-flight check — fits context window? budget allows?
|
|
13
|
+
*/
|
|
14
|
+
import type { StepResult } from "#recipe-engine/types";
|
|
15
|
+
import type { AIContextConfig, AIExample, AIGuardrailConfig } from "./ai-config.js";
|
|
16
|
+
import { type ContextBundle } from "./context-collector.js";
|
|
17
|
+
/**
|
|
18
|
+
* Assembled prompt ready for the AI SDK
|
|
19
|
+
*/
|
|
20
|
+
export interface AssembledPrompt {
|
|
21
|
+
/** System message */
|
|
22
|
+
system: string;
|
|
23
|
+
/** User message (context + examples + task prompt) */
|
|
24
|
+
user: string;
|
|
25
|
+
/** Estimated total token count */
|
|
26
|
+
estimatedTokens: number;
|
|
27
|
+
/** Context bundle used */
|
|
28
|
+
contextBundle: ContextBundle;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Options for the prompt pipeline
|
|
32
|
+
*/
|
|
33
|
+
export interface PromptPipelineOptions {
|
|
34
|
+
/** Global system prompt from config */
|
|
35
|
+
globalSystemPrompt?: string;
|
|
36
|
+
/** Step-level system prompt override */
|
|
37
|
+
stepSystemPrompt?: string;
|
|
38
|
+
/** Guardrail rules to inject into system prompt */
|
|
39
|
+
guardrails?: AIGuardrailConfig;
|
|
40
|
+
/** User prompt text (already Liquid-rendered) */
|
|
41
|
+
prompt: string;
|
|
42
|
+
/** Context configuration */
|
|
43
|
+
context?: AIContextConfig;
|
|
44
|
+
/** Few-shot examples */
|
|
45
|
+
examples?: AIExample[];
|
|
46
|
+
/** Project root for file resolution */
|
|
47
|
+
projectRoot: string;
|
|
48
|
+
/** Results from previous steps */
|
|
49
|
+
stepResults: Map<string, StepResult>;
|
|
50
|
+
/** Max output tokens (reserved from context window) */
|
|
51
|
+
maxOutputTokens?: number;
|
|
52
|
+
}
|
|
53
|
+
export declare class PromptPipeline {
|
|
54
|
+
private readonly contextCollector;
|
|
55
|
+
/**
|
|
56
|
+
* Execute the full 5-stage pipeline
|
|
57
|
+
*/
|
|
58
|
+
assemble(options: PromptPipelineOptions): Promise<AssembledPrompt>;
|
|
59
|
+
private assembleSystemPrompt;
|
|
60
|
+
private assembleUserPrompt;
|
|
61
|
+
private buildGuardrailInstructions;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=prompt-pipeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-pipeline.d.ts","sourceRoot":"","sources":["../../src/ai/prompt-pipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACpF,OAAO,EAAE,KAAK,aAAa,EAAoB,MAAM,wBAAwB,CAAC;AAI9E;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B,qBAAqB;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,eAAe,EAAE,MAAM,CAAC;IACxB,0BAA0B;IAC1B,aAAa,EAAE,aAAa,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACrC,uCAAuC;IACvC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,wCAAwC;IACxC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mDAAmD;IACnD,UAAU,CAAC,EAAE,iBAAiB,CAAC;IAC/B,iDAAiD;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,4BAA4B;IAC5B,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,wBAAwB;IACxB,QAAQ,CAAC,EAAE,SAAS,EAAE,CAAC;IACvB,uCAAuC;IACvC,WAAW,EAAE,MAAM,CAAC;IACpB,kCAAkC;IAClC,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACrC,uDAAuD;IACvD,eAAe,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,qBAAa,cAAc;IAC1B,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAA0B;IAE3D;;OAEG;IACG,QAAQ,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,eAAe,CAAC;IAqCxE,OAAO,CAAC,oBAAoB;IAwB5B,OAAO,CAAC,kBAAkB;IA4C1B,OAAO,CAAC,0BAA0B;CA+BlC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt Pipeline
|
|
3
|
+
*
|
|
4
|
+
* 5-stage pipeline that transforms user prompts into fully assembled
|
|
5
|
+
* AI requests ready for the Vercel AI SDK.
|
|
6
|
+
*
|
|
7
|
+
* Stages:
|
|
8
|
+
* 1. Liquid rendering — resolve {{ variables }} in prompt text
|
|
9
|
+
* 2. Context collection — read files, configs, step results
|
|
10
|
+
* 3. Token budgeting — estimate, truncate if needed
|
|
11
|
+
* 4. Prompt assembly — system + context + examples + user prompt
|
|
12
|
+
* 5. Pre-flight check — fits context window? budget allows?
|
|
13
|
+
*/
|
|
14
|
+
import createDebug from "debug";
|
|
15
|
+
import { ContextCollector } from "./context-collector.js";
|
|
16
|
+
const debug = createDebug("hypergen:ai:prompt-pipeline");
|
|
17
|
+
export class PromptPipeline {
|
|
18
|
+
contextCollector = new ContextCollector();
|
|
19
|
+
/**
|
|
20
|
+
* Execute the full 5-stage pipeline
|
|
21
|
+
*/
|
|
22
|
+
async assemble(options) {
|
|
23
|
+
debug("Starting prompt pipeline");
|
|
24
|
+
// Stage 1: Template rendering is done before this pipeline is called
|
|
25
|
+
// (by the AiTool or @ai template tags, which have access to the Jig engine)
|
|
26
|
+
// Stage 2: Context collection
|
|
27
|
+
const contextBundle = await this.contextCollector.collect(options.context, options.projectRoot, options.stepResults);
|
|
28
|
+
// Stage 3: Token budgeting (already handled by ContextCollector's maxContextTokens)
|
|
29
|
+
// We just track the total here
|
|
30
|
+
// Stage 4: Prompt assembly
|
|
31
|
+
const system = this.assembleSystemPrompt(options);
|
|
32
|
+
const user = this.assembleUserPrompt(options, contextBundle);
|
|
33
|
+
const estimatedTokens = Math.ceil(system.length / 4) + Math.ceil(user.length / 4);
|
|
34
|
+
debug("Prompt assembled: system=%d chars, user=%d chars, ~%d tokens", system.length, user.length, estimatedTokens);
|
|
35
|
+
// Stage 5: Pre-flight check
|
|
36
|
+
// Context window limits are model-specific; we log a warning if suspiciously large
|
|
37
|
+
if (estimatedTokens > 100_000) {
|
|
38
|
+
debug("Warning: estimated prompt size (%d tokens) is very large", estimatedTokens);
|
|
39
|
+
}
|
|
40
|
+
return { system, user, estimatedTokens, contextBundle };
|
|
41
|
+
}
|
|
42
|
+
assembleSystemPrompt(options) {
|
|
43
|
+
const parts = [];
|
|
44
|
+
// Global system prompt
|
|
45
|
+
if (options.globalSystemPrompt) {
|
|
46
|
+
parts.push(options.globalSystemPrompt);
|
|
47
|
+
}
|
|
48
|
+
// Step-level system prompt (overrides or appends)
|
|
49
|
+
if (options.stepSystemPrompt) {
|
|
50
|
+
parts.push(options.stepSystemPrompt);
|
|
51
|
+
}
|
|
52
|
+
// Guardrail instructions
|
|
53
|
+
if (options.guardrails) {
|
|
54
|
+
const rules = this.buildGuardrailInstructions(options.guardrails);
|
|
55
|
+
if (rules) {
|
|
56
|
+
parts.push(rules);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return parts.join("\n\n");
|
|
60
|
+
}
|
|
61
|
+
assembleUserPrompt(options, context) {
|
|
62
|
+
const parts = [];
|
|
63
|
+
// Context section
|
|
64
|
+
if (context.configs.size > 0 || context.files.size > 0 || context.stepOutputs.size > 0) {
|
|
65
|
+
parts.push("## Context\n");
|
|
66
|
+
for (const [name, content] of context.configs) {
|
|
67
|
+
parts.push(`### ${name}\n\`\`\`json\n${content}\n\`\`\`\n`);
|
|
68
|
+
}
|
|
69
|
+
for (const [name, content] of context.stepOutputs) {
|
|
70
|
+
parts.push(`### Output from step "${name}"\n\`\`\`\n${content}\n\`\`\`\n`);
|
|
71
|
+
}
|
|
72
|
+
for (const [filePath, content] of context.files) {
|
|
73
|
+
const ext = filePath.split(".").pop() || "";
|
|
74
|
+
parts.push(`### ${filePath}\n\`\`\`${ext}\n${content}\n\`\`\`\n`);
|
|
75
|
+
}
|
|
76
|
+
if (context.truncated) {
|
|
77
|
+
parts.push("> Note: Some context was truncated to fit token budget.\n");
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// Examples section
|
|
81
|
+
if (options.examples && options.examples.length > 0) {
|
|
82
|
+
parts.push("## Examples\n");
|
|
83
|
+
for (const example of options.examples) {
|
|
84
|
+
if (example.label) {
|
|
85
|
+
parts.push(`### ${example.label}`);
|
|
86
|
+
}
|
|
87
|
+
parts.push(`**Input:**\n${example.input}\n`);
|
|
88
|
+
parts.push(`**Output:**\n${example.output}\n`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// Task prompt
|
|
92
|
+
parts.push("## Task\n");
|
|
93
|
+
parts.push(options.prompt);
|
|
94
|
+
return parts.join("\n");
|
|
95
|
+
}
|
|
96
|
+
buildGuardrailInstructions(guardrails) {
|
|
97
|
+
const rules = [];
|
|
98
|
+
if (guardrails.validateSyntax) {
|
|
99
|
+
const lang = guardrails.validateSyntax === true ? "the target language" : guardrails.validateSyntax;
|
|
100
|
+
rules.push(`- Output MUST be valid ${lang} syntax.`);
|
|
101
|
+
}
|
|
102
|
+
if (guardrails.allowedImports && guardrails.allowedImports.length > 0) {
|
|
103
|
+
rules.push(`- Only use imports from these packages: ${guardrails.allowedImports.join(", ")}.`);
|
|
104
|
+
}
|
|
105
|
+
if (guardrails.blockedImports && guardrails.blockedImports.length > 0) {
|
|
106
|
+
rules.push(`- Do NOT import from: ${guardrails.blockedImports.join(", ")}.`);
|
|
107
|
+
}
|
|
108
|
+
if (guardrails.requireKnownImports) {
|
|
109
|
+
rules.push("- Only import packages that exist in the project's package.json.");
|
|
110
|
+
}
|
|
111
|
+
if (guardrails.maxOutputLength) {
|
|
112
|
+
rules.push(`- Output must be at most ${guardrails.maxOutputLength} characters.`);
|
|
113
|
+
}
|
|
114
|
+
if (rules.length === 0)
|
|
115
|
+
return null;
|
|
116
|
+
return `## Rules\n\n${rules.join("\n")}`;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=prompt-pipeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-pipeline.js","sourceRoot":"","sources":["../../src/ai/prompt-pipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,WAAW,MAAM,OAAO,CAAC;AAGhC,OAAO,EAAsB,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE9E,MAAM,KAAK,GAAG,WAAW,CAAC,6BAA6B,CAAC,CAAC;AAwCzD,MAAM,OAAO,cAAc;IACT,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAC;IAE3D;;OAEG;IACH,KAAK,CAAC,QAAQ,CAAC,OAA8B;QAC5C,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAElC,qEAAqE;QACrE,4EAA4E;QAE5E,8BAA8B;QAC9B,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO,CACxD,OAAO,CAAC,OAAO,EACf,OAAO,CAAC,WAAW,EACnB,OAAO,C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IAAI,CAAC,yBAAyB,UAAU,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC9E,CAAC;QAED,IAAI,UAAU,CAAC,mBAAmB,EAAE,CAAC;YACpC,KAAK,CAAC,IAAI,CAAC,kEAAkE,CAAC,CAAC;QAChF,CAAC;QAED,IAAI,UAAU,CAAC,eAAe,EAAE,CAAC;YAChC,KAAK,CAAC,IAAI,CAAC,4BAA4B,UAAU,CAAC,eAAe,cAAc,CAAC,CAAC;QAClF,CAAC;QAED,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QAEpC,OAAO,eAAe,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;IAC1C,CAAC;CACD"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Hypergen AI Generation Request
|
|
2
|
+
@if(hasContext)
|
|
3
|
+
|
|
4
|
+
## Context
|
|
5
|
+
@if(globalContexts.length > 0)
|
|
6
|
+
|
|
7
|
+
### Global Context
|
|
8
|
+
@each(ctx in globalContexts)
|
|
9
|
+
|
|
10
|
+
{{ ctx }}
|
|
11
|
+
@end
|
|
12
|
+
@end
|
|
13
|
+
@each(entry in entries)
|
|
14
|
+
@if(entry.contexts.length > 0)
|
|
15
|
+
|
|
16
|
+
### Context for `{{ entry.key }}`
|
|
17
|
+
@each(ctx in entry.contexts)
|
|
18
|
+
|
|
19
|
+
{{ ctx }}
|
|
20
|
+
@end
|
|
21
|
+
@end
|
|
22
|
+
@end
|
|
23
|
+
@end
|
|
24
|
+
|
|
25
|
+
## Answer the following questions
|
|
26
|
+
@if(hasVariables)
|
|
27
|
+
@if(providedVariables.length > 0)
|
|
28
|
+
|
|
29
|
+
The following values have already been provided (for reference, do NOT include in your response):
|
|
30
|
+
@each(v in providedVariables)
|
|
31
|
+
- `{{ v.name }}` = {{ JSON.stringify(v.providedValue) }}
|
|
32
|
+
@end
|
|
33
|
+
@end
|
|
34
|
+
@each(v in unprovidedVariables)
|
|
35
|
+
|
|
36
|
+
### {{ v.index }}. {{ v.prompt || v.name }}
|
|
37
|
+
@if(v.description)
|
|
38
|
+
{{ v.description }}
|
|
39
|
+
@end
|
|
40
|
+
- Type: {{ v.type }}
|
|
41
|
+
- Required: {{ v.required ? 'yes' : 'no' }}
|
|
42
|
+
@if(v.default !== undefined)
|
|
43
|
+
- Default: `{{ JSON.stringify(v.default) }}` (omit from response to use default)
|
|
44
|
+
@end
|
|
45
|
+
@if(v.values && v.values.length > 0)
|
|
46
|
+
- Allowed values: {{ v.values.map(val => '`' + val + '`').join(', ') }}
|
|
47
|
+
@end
|
|
48
|
+
- Response key: `{{ v.name }}`
|
|
49
|
+
@end
|
|
50
|
+
@end
|
|
51
|
+
@each(entry in entries)
|
|
52
|
+
|
|
53
|
+
### `{{ entry.key }}`
|
|
54
|
+
|
|
55
|
+
{{ entry.prompt }}
|
|
56
|
+
@if(entry.outputDescription.trim())
|
|
57
|
+
|
|
58
|
+
**Expected output format:**
|
|
59
|
+
|
|
60
|
+
{{ entry.outputDescription }}
|
|
61
|
+
@end
|
|
62
|
+
@if(entry.examples.length > 0)
|
|
63
|
+
|
|
64
|
+
**Example{{ entry.examples.length > 1 ? 's' : '' }}:**
|
|
65
|
+
@each(ex in entry.examples)
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
{{ ex }}
|
|
69
|
+
```
|
|
70
|
+
@end
|
|
71
|
+
@end
|
|
72
|
+
@end
|
|
73
|
+
|
|
74
|
+
## Response Format
|
|
75
|
+
|
|
76
|
+
Respond with a JSON object:
|
|
77
|
+
|
|
78
|
+
```json
|
|
79
|
+
{{ responseSchema }}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Instructions
|
|
83
|
+
|
|
84
|
+
Save your response as JSON to a file and run:
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
{{ originalCommand }} --answers {{ answersPath }}
|
|
88
|
+
```
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API Transport
|
|
3
|
+
*
|
|
4
|
+
* Resolves @ai blocks by calling an LLM via Vercel AI SDK (through AiService).
|
|
5
|
+
* Sends a single batched prompt with all blocks and parses a JSON response.
|
|
6
|
+
*/
|
|
7
|
+
import type { AiTransport, TransportContext, TransportResult } from "./types.js";
|
|
8
|
+
export declare class ApiTransport implements AiTransport {
|
|
9
|
+
readonly name = "api";
|
|
10
|
+
resolve(ctx: TransportContext): Promise<TransportResult>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=api-transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-transport.d.ts","sourceRoot":"","sources":["../../../src/ai/transports/api-transport.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAIjF,qBAAa,YAAa,YAAW,WAAW;IAC/C,QAAQ,CAAC,IAAI,SAAS;IAEhB,OAAO,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC;CA+C9D"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API Transport
|
|
3
|
+
*
|
|
4
|
+
* Resolves @ai blocks by calling an LLM via Vercel AI SDK (through AiService).
|
|
5
|
+
* Sends a single batched prompt with all blocks and parses a JSON response.
|
|
6
|
+
*/
|
|
7
|
+
import { ErrorCode, ErrorHandler } from "@hypercli/core";
|
|
8
|
+
import createDebug from "debug";
|
|
9
|
+
import { AiService } from "#ai/ai-service";
|
|
10
|
+
import { PromptAssembler } from "#ai/prompt-assembler";
|
|
11
|
+
const debug = createDebug("hypergen:ai:transport:api");
|
|
12
|
+
export class ApiTransport {
|
|
13
|
+
name = "api";
|
|
14
|
+
async resolve(ctx) {
|
|
15
|
+
const assembler = new PromptAssembler();
|
|
16
|
+
// Build the prompt for the LLM (same prompt document, but with JSON-only instructions)
|
|
17
|
+
const prompt = assembler.assemble(ctx.collector, {
|
|
18
|
+
originalCommand: ctx.originalCommand,
|
|
19
|
+
answersPath: ctx.answersPath,
|
|
20
|
+
promptTemplate: ctx.promptTemplate,
|
|
21
|
+
});
|
|
22
|
+
// Build the expected keys list for validation
|
|
23
|
+
const entries = ctx.collector.getEntries();
|
|
24
|
+
const expectedKeys = [...entries.keys()];
|
|
25
|
+
debug("Resolving %d AI blocks via API", expectedKeys.length);
|
|
26
|
+
// Use AiService for generation (reuses retry, cost tracking, model routing)
|
|
27
|
+
const aiService = AiService.getInstance(ctx.config);
|
|
28
|
+
const systemPrompt = [
|
|
29
|
+
"You are a code generation assistant.",
|
|
30
|
+
"You MUST respond with ONLY a valid JSON object — no markdown fences, no explanation, no text outside the JSON.",
|
|
31
|
+
`The JSON object must have exactly these keys: ${expectedKeys.map((k) => `"${k}"`).join(", ")}.`,
|
|
32
|
+
"Each value must be a string containing the generated code or content for that key.",
|
|
33
|
+
].join("\n");
|
|
34
|
+
const result = await aiService.generate({
|
|
35
|
+
prompt,
|
|
36
|
+
system: systemPrompt,
|
|
37
|
+
temperature: ctx.config.temperature ?? 0.2,
|
|
38
|
+
maxTokens: ctx.config.maxTokens,
|
|
39
|
+
model: ctx.config.model,
|
|
40
|
+
provider: ctx.config.provider,
|
|
41
|
+
projectRoot: ctx.projectRoot,
|
|
42
|
+
stepName: "ai-transport-api",
|
|
43
|
+
});
|
|
44
|
+
// Parse JSON response
|
|
45
|
+
const answers = parseJsonResponse(result.output, expectedKeys);
|
|
46
|
+
debug("API resolved %d keys (cost: $%s)", Object.keys(answers).length, result.costUsd.toFixed(4));
|
|
47
|
+
return { status: "resolved", answers };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Parse a JSON response from the LLM, stripping common artifacts.
|
|
52
|
+
*/
|
|
53
|
+
function parseJsonResponse(raw, expectedKeys) {
|
|
54
|
+
let text = raw.trim();
|
|
55
|
+
// Strip markdown code fences (common LLM quirk)
|
|
56
|
+
const fenceMatch = text.match(/^```(?:json)?\s*\n?([\s\S]*?)\n?\s*```$/m);
|
|
57
|
+
if (fenceMatch) {
|
|
58
|
+
text = fenceMatch[1].trim();
|
|
59
|
+
}
|
|
60
|
+
let parsed;
|
|
61
|
+
try {
|
|
62
|
+
parsed = JSON.parse(text);
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
throw ErrorHandler.createError(ErrorCode.AI_TRANSPORT_FAILED, `Failed to parse JSON response from AI provider. Response starts with: "${text.slice(0, 100)}..."`, { cause: err });
|
|
66
|
+
}
|
|
67
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
68
|
+
throw ErrorHandler.createError(ErrorCode.AI_TRANSPORT_FAILED, `AI response is not a JSON object. Got: ${typeof parsed}`, {});
|
|
69
|
+
}
|
|
70
|
+
// Validate all expected keys are present
|
|
71
|
+
const missing = expectedKeys.filter((k) => !(k in parsed));
|
|
72
|
+
if (missing.length > 0) {
|
|
73
|
+
throw ErrorHandler.createError(ErrorCode.AI_TRANSPORT_FAILED, `AI response missing expected keys: ${missing.join(", ")}`, {
|
|
74
|
+
expected: expectedKeys.join(", "),
|
|
75
|
+
received: Object.keys(parsed).join(", "),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
// Coerce all values to strings
|
|
79
|
+
const answers = {};
|
|
80
|
+
for (const key of expectedKeys) {
|
|
81
|
+
const val = parsed[key];
|
|
82
|
+
answers[key] = typeof val === "string" ? val : JSON.stringify(val);
|
|
83
|
+
}
|
|
84
|
+
return answers;
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=api-transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-transport.js","sourceRoot":"","sources":["../../../src/ai/transports/api-transport.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,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
* - 'batched' (default): one invocation, JSON response with all keys
|
|
7
|
+
* - 'per-block': one invocation per @ai block, raw text response per key
|
|
8
|
+
*
|
|
9
|
+
* Command template:
|
|
10
|
+
* - Contains {prompt} → shell-escape and substitute into args
|
|
11
|
+
* - No {prompt} → pipe prompt to subprocess stdin
|
|
12
|
+
*/
|
|
13
|
+
import type { AiTransport, TransportContext, TransportResult } from "./types.js";
|
|
14
|
+
export declare class CommandTransport implements AiTransport {
|
|
15
|
+
readonly name = "command";
|
|
16
|
+
resolve(ctx: TransportContext): Promise<TransportResult>;
|
|
17
|
+
private resolveBatched;
|
|
18
|
+
private resolvePerBlock;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=command-transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-transport.d.ts","sourceRoot":"","sources":["../../../src/ai/transports/command-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAOH,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAIjF,qBAAa,gBAAiB,YAAW,WAAW;IACnD,QAAQ,CAAC,IAAI,aAAa;IAEpB,OAAO,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC;YA4BhD,cAAc;YAsBd,eAAe;CAwC7B"}
|