feat: --prompt flag
This commit is contained in:
parent
2f45640211
commit
ea2fac7c2c
17 changed files with 300 additions and 26 deletions
1
extensions/cli/package-lock.json
generated
1
extensions/cli/package-lock.json
generated
|
|
@ -276,6 +276,7 @@
|
|||
"@types/follow-redirects": "^1.14.4",
|
||||
"@types/jest": "^29.5.14",
|
||||
"@types/json-schema": "^7.0.15",
|
||||
"@types/node": "^24.3.0",
|
||||
"cross-env": "^7.0.3",
|
||||
"semantic-release": "^24.2.7",
|
||||
"ts-jest": "^29.2.3",
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import { vi } from "vitest";
|
||||
|
||||
export const processPromptOrRule = vi.fn<(spec: string) => Promise<string>>();
|
||||
export const processRule = vi.fn<(rule: string) => Promise<string>>();
|
||||
export const processPrompt = vi.fn<(prompt: string) => Promise<string>>();
|
||||
|
|
|
|||
49
extensions/cli/src/args.prompt.test.ts
Normal file
49
extensions/cli/src/args.prompt.test.ts
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import { describe, it, expect, beforeEach } from "vitest";
|
||||
|
||||
import { parseArgs, processPrompt } from "./args.js";
|
||||
|
||||
describe("args --prompt flag", () => {
|
||||
beforeEach(() => {
|
||||
// Reset process.argv for each test
|
||||
process.argv = ["node", "script.js"];
|
||||
});
|
||||
|
||||
it("should parse single prompt from --prompt flag", () => {
|
||||
process.argv = ["node", "script.js", "--prompt", "my-prompt"];
|
||||
const result = parseArgs();
|
||||
expect(result.prompts).toEqual(["my-prompt"]);
|
||||
});
|
||||
|
||||
it("should parse multiple prompts from multiple --prompt flags", () => {
|
||||
process.argv = ["node", "script.js", "--prompt", "prompt1", "--prompt", "prompt2"];
|
||||
const result = parseArgs();
|
||||
expect(result.prompts).toEqual(["prompt1", "prompt2"]);
|
||||
});
|
||||
|
||||
it("should handle mixed flags including --prompt", () => {
|
||||
process.argv = ["node", "script.js", "--config", "myconfig", "--prompt", "myprompt", "--resume"];
|
||||
const result = parseArgs();
|
||||
expect(result.configPath).toBe("myconfig");
|
||||
expect(result.prompts).toEqual(["myprompt"]);
|
||||
expect(result.resume).toBe(true);
|
||||
});
|
||||
|
||||
it("should not include --prompt value in non-flag arguments", () => {
|
||||
process.argv = ["node", "script.js", "--prompt", "prompt-value", "actual-prompt"];
|
||||
const result = parseArgs();
|
||||
expect(result.prompts).toEqual(["prompt-value"]);
|
||||
expect(result.prompt).toBe("actual-prompt");
|
||||
});
|
||||
|
||||
it("should handle both --rule and --prompt flags", () => {
|
||||
process.argv = ["node", "script.js", "--rule", "my-rule", "--prompt", "my-prompt"];
|
||||
const result = parseArgs();
|
||||
expect(result.rules).toEqual(["my-rule"]);
|
||||
expect(result.prompts).toEqual(["my-prompt"]);
|
||||
});
|
||||
|
||||
it("should process direct string content", async () => {
|
||||
const result = await processPrompt("This is a direct prompt");
|
||||
expect(result).toBe("This is a direct prompt");
|
||||
});
|
||||
});
|
||||
|
|
@ -12,6 +12,7 @@ export interface CommandLineArgs {
|
|||
resume?: boolean; // Resume from last session
|
||||
readonly?: boolean; // Start in plan mode (backward compatibility)
|
||||
rules?: string[]; // Array of rule specifications
|
||||
prompts?: string[]; // Array of prompt specifications
|
||||
format?: "json"; // Output format for headless mode
|
||||
}
|
||||
|
||||
|
|
@ -83,31 +84,31 @@ async function loadRuleFromHub(slug: string): Promise<string> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Process a rule specification and return its content
|
||||
* @param ruleSpec - Can be a file path, hub slug, or direct string content
|
||||
* @returns The processed rule content
|
||||
* Process a specification (rule or prompt) and return its content
|
||||
* @param spec - Can be a file path, hub slug, or direct string content
|
||||
* @returns The processed content
|
||||
*/
|
||||
export async function processRule(ruleSpec: string): Promise<string> {
|
||||
export async function processPromptOrRule(spec: string): Promise<string> {
|
||||
// If it looks like a hub slug (contains / but doesn't start with . or /)
|
||||
if (
|
||||
ruleSpec.includes("/") &&
|
||||
!ruleSpec.startsWith(".") &&
|
||||
!ruleSpec.startsWith("/")
|
||||
spec.includes("/") &&
|
||||
!spec.startsWith(".") &&
|
||||
!spec.startsWith("/")
|
||||
) {
|
||||
return await loadRuleFromHub(ruleSpec);
|
||||
return await loadRuleFromHub(spec);
|
||||
}
|
||||
|
||||
// If it looks like a file path (contains . or / or ends with common file extensions)
|
||||
if (
|
||||
ruleSpec.includes(".") ||
|
||||
ruleSpec.includes("/") ||
|
||||
ruleSpec.includes("\\")
|
||||
spec.includes(".") ||
|
||||
spec.includes("/") ||
|
||||
spec.includes("\\")
|
||||
) {
|
||||
return loadRuleFromFile(ruleSpec);
|
||||
return loadRuleFromFile(spec);
|
||||
}
|
||||
|
||||
// Otherwise, treat it as direct string content
|
||||
return ruleSpec;
|
||||
return spec;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -115,6 +116,7 @@ export async function processRule(ruleSpec: string): Promise<string> {
|
|||
* @deprecated Most functionality has been moved to services. This is only kept for backward compatibility.
|
||||
* @returns Parsed command line arguments
|
||||
*/
|
||||
/* eslint-disable */
|
||||
export function parseArgs(): CommandLineArgs {
|
||||
const args = process.argv.slice(2);
|
||||
|
||||
|
|
@ -170,8 +172,25 @@ export function parseArgs(): CommandLineArgs {
|
|||
}
|
||||
}
|
||||
|
||||
// Get prompts from --prompt flags (can be specified multiple times)
|
||||
const promptIndices: number[] = [];
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
if (args[i] === "--prompt") {
|
||||
promptIndices.push(i);
|
||||
}
|
||||
}
|
||||
|
||||
if (promptIndices.length > 0) {
|
||||
result.prompts = [];
|
||||
for (const promptIndex of promptIndices) {
|
||||
if (promptIndex + 1 < args.length) {
|
||||
result.prompts.push(args[promptIndex + 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Find the last argument that's not a flag or a flag value
|
||||
const flagsWithValues = ["--config", "--org", "--rule", "--format"];
|
||||
const flagsWithValues = ["--config", "--org", "--rule", "--prompt", "--format"];
|
||||
const nonFlagArgs = args.filter((arg, index) => {
|
||||
// Skip flags (starting with --)
|
||||
if (arg.startsWith("--") || arg === "-p") return false;
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@ export interface ChatOptions extends ExtendedCommandOptions {
|
|||
headless?: boolean;
|
||||
resume?: boolean;
|
||||
rule?: string[]; // Array of rule specifications
|
||||
prompt?: string[]; // Array of prompt specifications
|
||||
format?: "json"; // Output format for headless mode
|
||||
silent?: boolean; // Strip <think></think> tags and excess whitespace
|
||||
org?: string; // Organization slug to use for this session
|
||||
|
|
@ -388,17 +389,21 @@ async function runHeadlessMode(
|
|||
compactionIndex = findCompactionIndex(chatHistory);
|
||||
}
|
||||
|
||||
// Handle additional prompts from --prompt flags
|
||||
const { processAndCombinePrompts } = await import("../util/promptProcessor.js");
|
||||
const initialUserInput = await processAndCombinePrompts(options.prompt, prompt);
|
||||
|
||||
let isFirstMessage = true;
|
||||
while (true) {
|
||||
// When in headless mode, don't ask for user input
|
||||
if (!isFirstMessage && prompt && options.headless) {
|
||||
if (!isFirstMessage && initialUserInput && options.headless) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Get user input
|
||||
const userInput =
|
||||
isFirstMessage && prompt
|
||||
? prompt
|
||||
isFirstMessage && initialUserInput
|
||||
? initialUserInput
|
||||
: readlineSync.question(`\n${chalk.bold.green("You:")} `);
|
||||
|
||||
isFirstMessage = false;
|
||||
|
|
@ -465,6 +470,7 @@ export async function chat(prompt?: string, options: ChatOptions = {}) {
|
|||
configPath: options.config,
|
||||
organizationSlug: options.org,
|
||||
additionalRules: options.rule,
|
||||
additionalPrompts: options.prompt,
|
||||
toolPermissionOverrides: permissionOverrides,
|
||||
skipOnboarding: true,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ describe("E2E: Basic Commands", () => {
|
|||
expect(result.stdout).toContain("--readonly");
|
||||
expect(result.stdout).toContain("--auto");
|
||||
expect(result.stdout).toContain("--rule <rule>");
|
||||
expect(result.stdout).toContain("--prompt <prompt>");
|
||||
});
|
||||
|
||||
it("should show available commands", async () => {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import { DefaultApiInterface } from "@continuedev/sdk/dist/api/dist/index.js";
|
|||
import chalk from "chalk";
|
||||
import * as readlineSync from "readline-sync";
|
||||
|
||||
import { processRule } from "./args.js";
|
||||
import { processPromptOrRule } from "./args.js";
|
||||
import { AuthConfig, isAuthenticated, login } from "./auth/workos.js";
|
||||
import { initialize } from "./config.js";
|
||||
import { env } from "./env.js";
|
||||
|
|
@ -239,7 +239,7 @@ async function injectRulesIntoConfig(
|
|||
const processedRules: string[] = [];
|
||||
for (const ruleSpec of rules) {
|
||||
try {
|
||||
const processedRule = await processRule(ruleSpec);
|
||||
const processedRule = await processPromptOrRule(ruleSpec);
|
||||
processedRules.push(processedRule);
|
||||
} catch (error: any) {
|
||||
console.warn(
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { AssistantUnrolled } from "@continuedev/config-yaml";
|
||||
import { DefaultApiInterface } from "@continuedev/sdk/dist/api/dist/index.js";
|
||||
|
||||
import { processRule } from "../args.js";
|
||||
import { processPromptOrRule } from "../args.js";
|
||||
import { AuthConfig, loadAuthConfig } from "../auth/workos.js";
|
||||
import { logger } from "../util/logger.js";
|
||||
|
||||
|
|
@ -155,7 +155,7 @@ export class ConfigService
|
|||
|
||||
for (const ruleSpec of rules) {
|
||||
try {
|
||||
const processedRule = await processRule(ruleSpec);
|
||||
const processedRule = await processPromptOrRule(ruleSpec);
|
||||
processedRules.push(processedRule);
|
||||
} catch (error: any) {
|
||||
logger.warn(`Failed to process rule "${ruleSpec}": ${error.message}`);
|
||||
|
|
|
|||
|
|
@ -24,6 +24,16 @@ export function addCommonOptions(command: Command): Command {
|
|||
},
|
||||
[] as string[],
|
||||
)
|
||||
.option(
|
||||
"--prompt <prompt>",
|
||||
"Add to the initial user message (can be a file path, hub slug, or string content). Can be specified multiple times.",
|
||||
(value: string, previous: string[] | undefined) => {
|
||||
const array = Array.isArray(previous) ? previous : [];
|
||||
array.push(value);
|
||||
return array;
|
||||
},
|
||||
[] as string[],
|
||||
)
|
||||
.option(
|
||||
"--allow <tool>",
|
||||
"Allow specified tool (overrides default policies). Can be specified multiple times.",
|
||||
|
|
@ -70,6 +80,7 @@ export function mergeParentOptions(parentCommand: Command, options: any): any {
|
|||
"tools",
|
||||
"verbose",
|
||||
"rule",
|
||||
"prompt",
|
||||
"allow",
|
||||
"ask",
|
||||
"exclude",
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import * as path from "path";
|
|||
import pkg from "ignore-walk";
|
||||
import { Minimatch } from "minimatch";
|
||||
|
||||
import { processRule } from "./args.js";
|
||||
import { processPromptOrRule } from "./args.js";
|
||||
import { serviceContainer } from "./services/ServiceContainer.js";
|
||||
import { ConfigServiceState, SERVICE_NAMES } from "./services/types.js";
|
||||
const { WalkerSync } = pkg;
|
||||
|
|
@ -150,7 +150,7 @@ export async function constructSystemMessage(
|
|||
if (additionalRules && additionalRules.length > 0) {
|
||||
for (const ruleSpec of additionalRules) {
|
||||
try {
|
||||
const processedRule = await processRule(ruleSpec);
|
||||
const processedRule = await processPromptOrRule(ruleSpec);
|
||||
processedRules.push(processedRule);
|
||||
} catch (error: any) {
|
||||
console.warn(
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ interface AppRootProps {
|
|||
initialPrompt?: string;
|
||||
resume?: boolean;
|
||||
additionalRules?: string[];
|
||||
additionalPrompts?: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ interface TUIChatProps {
|
|||
initialPrompt?: string;
|
||||
resume?: boolean;
|
||||
additionalRules?: string[];
|
||||
additionalPrompts?: string[];
|
||||
}
|
||||
|
||||
const TUIChat: React.FC<TUIChatProps> = ({
|
||||
|
|
@ -44,6 +45,7 @@ const TUIChat: React.FC<TUIChatProps> = ({
|
|||
initialPrompt,
|
||||
resume,
|
||||
additionalRules,
|
||||
additionalPrompts,
|
||||
}) => {
|
||||
// Check if we're in remote mode
|
||||
const isRemoteMode = useMemo(() => {
|
||||
|
|
@ -126,6 +128,7 @@ const TUIChat: React.FC<TUIChatProps> = ({
|
|||
initialPrompt,
|
||||
resume,
|
||||
additionalRules,
|
||||
additionalPrompts,
|
||||
onShowConfigSelector: () => navigateTo("config"),
|
||||
onShowModelSelector: () => navigateTo("model"),
|
||||
onShowMCPSelector: () => navigateTo("mcp"),
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ export function useChat({
|
|||
initialPrompt,
|
||||
resume,
|
||||
additionalRules,
|
||||
additionalPrompts,
|
||||
onShowConfigSelector,
|
||||
onShowModelSelector,
|
||||
onShowMCPSelector,
|
||||
|
|
@ -163,10 +164,19 @@ export function useChat({
|
|||
useEffect(() => {
|
||||
// Only handle initial prompt after chat history is initialized
|
||||
// This prevents race conditions where the prompt runs before system message is loaded
|
||||
if (initialPrompt && isChatHistoryInitialized) {
|
||||
handleUserMessage(initialPrompt);
|
||||
if ((initialPrompt || (additionalPrompts && additionalPrompts.length > 0)) && isChatHistoryInitialized) {
|
||||
const processPrompts = async () => {
|
||||
const { processAndCombinePrompts } = await import("../../util/promptProcessor.js");
|
||||
const finalMessage = await processAndCombinePrompts(additionalPrompts, initialPrompt);
|
||||
|
||||
if (finalMessage) {
|
||||
handleUserMessage(finalMessage);
|
||||
}
|
||||
};
|
||||
|
||||
processPrompts();
|
||||
}
|
||||
}, [initialPrompt, isChatHistoryInitialized]);
|
||||
}, [initialPrompt, additionalPrompts, isChatHistoryInitialized]);
|
||||
|
||||
const executeStreamingResponse = async (
|
||||
newHistory: ChatCompletionMessageParam[],
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ export interface UseChatProps {
|
|||
initialPrompt?: string;
|
||||
resume?: boolean;
|
||||
additionalRules?: string[];
|
||||
additionalPrompts?: string[];
|
||||
onShowConfigSelector: () => void;
|
||||
onShowMCPSelector: () => void;
|
||||
onShowModelSelector?: () => void;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ interface StartTUIChatOptions {
|
|||
configPath?: string;
|
||||
organizationSlug?: string;
|
||||
additionalRules?: string[];
|
||||
additionalPrompts?: string[];
|
||||
toolPermissionOverrides?: {
|
||||
allow?: string[];
|
||||
ask?: string[];
|
||||
|
|
@ -33,6 +34,7 @@ export async function startTUIChat(
|
|||
configPath,
|
||||
organizationSlug,
|
||||
additionalRules,
|
||||
additionalPrompts,
|
||||
toolPermissionOverrides,
|
||||
skipOnboarding,
|
||||
customStdin,
|
||||
|
|
@ -64,6 +66,7 @@ export async function startTUIChat(
|
|||
initialPrompt,
|
||||
resume,
|
||||
additionalRules,
|
||||
additionalPrompts,
|
||||
}),
|
||||
}),
|
||||
renderOptions,
|
||||
|
|
|
|||
128
extensions/cli/src/util/promptProcessor.test.ts
Normal file
128
extensions/cli/src/util/promptProcessor.test.ts
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
|
||||
import * as args from "../args.js";
|
||||
|
||||
import { processAndCombinePrompts } from "./promptProcessor.js";
|
||||
|
||||
// Mock the args module
|
||||
vi.mock("../args.js", () => ({
|
||||
processPromptOrRule: vi.fn(),
|
||||
}));
|
||||
|
||||
// Mock the logger
|
||||
vi.mock("./logger.js", () => ({
|
||||
logger: {
|
||||
warn: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
describe("promptProcessor", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe("processAndCombinePrompts", () => {
|
||||
it("should return initial prompt when no additional prompts", async () => {
|
||||
const result = await processAndCombinePrompts(undefined, "initial");
|
||||
expect(result).toBe("initial");
|
||||
});
|
||||
|
||||
it("should return initial prompt when empty additional prompts array", async () => {
|
||||
const result = await processAndCombinePrompts([], "initial");
|
||||
expect(result).toBe("initial");
|
||||
});
|
||||
|
||||
it("should return undefined when no prompts at all", async () => {
|
||||
const result = await processAndCombinePrompts();
|
||||
expect(result).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should process single additional prompt without initial", async () => {
|
||||
const mockProcessPromptOrRule = vi.mocked(args.processPromptOrRule);
|
||||
mockProcessPromptOrRule.mockResolvedValue("processed prompt");
|
||||
|
||||
const result = await processAndCombinePrompts(["prompt1"]);
|
||||
|
||||
expect(mockProcessPromptOrRule).toHaveBeenCalledWith("prompt1");
|
||||
expect(result).toBe("processed prompt");
|
||||
});
|
||||
|
||||
it("should combine multiple processed prompts", async () => {
|
||||
const mockProcessPromptOrRule = vi.mocked(args.processPromptOrRule);
|
||||
mockProcessPromptOrRule
|
||||
.mockResolvedValueOnce("first prompt")
|
||||
.mockResolvedValueOnce("second prompt");
|
||||
|
||||
const result = await processAndCombinePrompts(["prompt1", "prompt2"]);
|
||||
|
||||
expect(mockProcessPromptOrRule).toHaveBeenCalledTimes(2);
|
||||
expect(mockProcessPromptOrRule).toHaveBeenNthCalledWith(1, "prompt1");
|
||||
expect(mockProcessPromptOrRule).toHaveBeenNthCalledWith(2, "prompt2");
|
||||
expect(result).toBe("first prompt\n\nsecond prompt");
|
||||
});
|
||||
|
||||
it("should combine processed prompts with initial prompt", async () => {
|
||||
const mockProcessPromptOrRule = vi.mocked(args.processPromptOrRule);
|
||||
mockProcessPromptOrRule
|
||||
.mockResolvedValueOnce("processed1")
|
||||
.mockResolvedValueOnce("processed2");
|
||||
|
||||
const result = await processAndCombinePrompts(
|
||||
["prompt1", "prompt2"],
|
||||
"initial",
|
||||
);
|
||||
|
||||
expect(result).toBe("processed1\n\nprocessed2\n\ninitial");
|
||||
});
|
||||
|
||||
it("should handle processing errors and continue with successful ones", async () => {
|
||||
const mockProcessPromptOrRule = vi.mocked(args.processPromptOrRule);
|
||||
mockProcessPromptOrRule
|
||||
.mockResolvedValueOnce("success1")
|
||||
.mockRejectedValueOnce(new Error("processing failed"))
|
||||
.mockResolvedValueOnce("success2");
|
||||
|
||||
const result = await processAndCombinePrompts([
|
||||
"good1",
|
||||
"bad",
|
||||
"good2",
|
||||
]);
|
||||
|
||||
expect(mockProcessPromptOrRule).toHaveBeenCalledTimes(3);
|
||||
expect(result).toBe("success1\n\nsuccess2");
|
||||
});
|
||||
|
||||
it("should return initial prompt when all processing fails", async () => {
|
||||
const mockProcessPromptOrRule = vi.mocked(args.processPromptOrRule);
|
||||
mockProcessPromptOrRule
|
||||
.mockRejectedValueOnce(new Error("fail1"))
|
||||
.mockRejectedValueOnce(new Error("fail2"));
|
||||
|
||||
const result = await processAndCombinePrompts(["bad1", "bad2"], "initial");
|
||||
|
||||
expect(result).toBe("initial");
|
||||
});
|
||||
|
||||
it("should return undefined when all processing fails and no initial", async () => {
|
||||
const mockProcessPromptOrRule = vi.mocked(args.processPromptOrRule);
|
||||
mockProcessPromptOrRule.mockRejectedValue(new Error("processing failed"));
|
||||
|
||||
const result = await processAndCombinePrompts(["bad"]);
|
||||
|
||||
expect(result).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should warn when processing fails", async () => {
|
||||
const mockProcessPromptOrRule = vi.mocked(args.processPromptOrRule);
|
||||
mockProcessPromptOrRule.mockRejectedValue(new Error("test error"));
|
||||
|
||||
const { logger } = await import("./logger.js");
|
||||
|
||||
await processAndCombinePrompts(["bad-prompt"]);
|
||||
|
||||
expect(logger.warn).toHaveBeenCalledWith(
|
||||
'Failed to process prompt "bad-prompt": test error',
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
39
extensions/cli/src/util/promptProcessor.ts
Normal file
39
extensions/cli/src/util/promptProcessor.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import { processPromptOrRule } from "../args.js";
|
||||
import { logger } from "./logger.js";
|
||||
|
||||
/**
|
||||
* Process additional prompts from --prompt flags and combine with initial prompt
|
||||
* @param additionalPrompts - Array of prompt specifications to process
|
||||
* @param initialPrompt - Optional initial prompt to combine with
|
||||
* @returns Combined prompt string or undefined if no prompts
|
||||
*/
|
||||
export async function processAndCombinePrompts(
|
||||
additionalPrompts?: string[],
|
||||
initialPrompt?: string,
|
||||
): Promise<string | undefined> {
|
||||
if (!additionalPrompts || additionalPrompts.length === 0) {
|
||||
return initialPrompt;
|
||||
}
|
||||
|
||||
const processedPrompts: string[] = [];
|
||||
|
||||
for (const promptSpec of additionalPrompts) {
|
||||
try {
|
||||
const processed = await processPromptOrRule(promptSpec);
|
||||
processedPrompts.push(processed);
|
||||
} catch (error: any) {
|
||||
logger.warn(
|
||||
`Failed to process prompt "${promptSpec}": ${error.message}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (processedPrompts.length === 0) {
|
||||
return initialPrompt;
|
||||
}
|
||||
|
||||
const combinedPrompts = processedPrompts.join("\n\n");
|
||||
return initialPrompt
|
||||
? `${combinedPrompts}\n\n${initialPrompt}`
|
||||
: combinedPrompts;
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue