@graphext/cuery 0.6.1 → 0.6.2
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/esm/mod.d.ts +1 -0
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +1 -0
- package/esm/src/schemas/index.d.ts +1 -0
- package/esm/src/schemas/index.d.ts.map +1 -1
- package/esm/src/schemas/prompt.schema.d.ts +59 -0
- package/esm/src/schemas/prompt.schema.d.ts.map +1 -0
- package/esm/src/schemas/prompt.schema.js +25 -0
- package/esm/src/tools/prompts.d.ts +53 -0
- package/esm/src/tools/prompts.d.ts.map +1 -0
- package/esm/src/tools/prompts.js +106 -0
- package/package.json +1 -1
- package/script/mod.d.ts +1 -0
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +1 -0
- package/script/src/schemas/index.d.ts +1 -0
- package/script/src/schemas/index.d.ts.map +1 -1
- package/script/src/schemas/prompt.schema.d.ts +59 -0
- package/script/src/schemas/prompt.schema.d.ts.map +1 -0
- package/script/src/schemas/prompt.schema.js +28 -0
- package/script/src/tools/prompts.d.ts +53 -0
- package/script/src/tools/prompts.d.ts.map +1 -0
- package/script/src/tools/prompts.js +114 -0
package/esm/mod.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export * from './src/tools/sentiment.js';
|
|
|
19
19
|
export * from './src/tools/summarize.js';
|
|
20
20
|
export * from './src/tools/sources.js';
|
|
21
21
|
export * from './src/tools/entities.js';
|
|
22
|
+
export * from './src/tools/prompts.js';
|
|
22
23
|
export * from './src/helpers/seedKeywords.js';
|
|
23
24
|
export * from './src/tools/generic.js';
|
|
24
25
|
export * from './src/api.js';
|
package/esm/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EACN,WAAW,EACX,mBAAmB,EACnB,eAAe,EACf,YAAY,EACZ,aAAa,EACb,KAAK,YAAY,EACjB,KAAK,SAAS,GACd,MAAM,0BAA0B,CAAC;AAGlC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,oCAAoC,CAAC;AACnD,cAAc,wCAAwC,CAAC;AACvD,cAAc,wBAAwB,CAAC"}
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EACN,WAAW,EACX,mBAAmB,EACnB,eAAe,EACf,YAAY,EACZ,aAAa,EACb,KAAK,YAAY,EACjB,KAAK,SAAS,GACd,MAAM,0BAA0B,CAAC;AAGlC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,oCAAoC,CAAC;AACnD,cAAc,wCAAwC,CAAC;AACvD,cAAc,wBAAwB,CAAC"}
|
package/esm/mod.js
CHANGED
|
@@ -21,6 +21,7 @@ export * from './src/tools/sentiment.js';
|
|
|
21
21
|
export * from './src/tools/summarize.js';
|
|
22
22
|
export * from './src/tools/sources.js';
|
|
23
23
|
export * from './src/tools/entities.js';
|
|
24
|
+
export * from './src/tools/prompts.js';
|
|
24
25
|
export * from './src/helpers/seedKeywords.js';
|
|
25
26
|
export * from './src/tools/generic.js';
|
|
26
27
|
export * from './src/api.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/schemas/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,mBAAmB,qBAAqB,CAAC;AACzC,mBAAmB,mBAAmB,CAAC;AACvC,mBAAmB,oBAAoB,CAAC;AACxC,mBAAmB,qBAAqB,CAAC;AACzC,mBAAmB,sBAAsB,CAAC;AAC1C,mBAAmB,oBAAoB,CAAC;AACxC,mBAAmB,yBAAyB,CAAC;AAC7C,mBAAmB,oBAAoB,CAAC;AACxC,mBAAmB,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/schemas/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,mBAAmB,qBAAqB,CAAC;AACzC,mBAAmB,mBAAmB,CAAC;AACvC,mBAAmB,oBAAoB,CAAC;AACxC,mBAAmB,qBAAqB,CAAC;AACzC,mBAAmB,sBAAsB,CAAC;AAC1C,mBAAmB,oBAAoB,CAAC;AACxC,mBAAmB,yBAAyB,CAAC;AAC7C,mBAAmB,oBAAoB,CAAC;AACxC,mBAAmB,qBAAqB,CAAC;AACzC,mBAAmB,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { z } from '../../deps/jsr.io/@zod/zod/4.3.6/src/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Zod schemas for AI visibility prompt generation.
|
|
4
|
+
*
|
|
5
|
+
* ⚠️ This file should contain ONLY schema definitions.
|
|
6
|
+
* No business logic, prompts, or function implementations.
|
|
7
|
+
*/
|
|
8
|
+
export declare const PromptIntentSchema: z.ZodEnum<{
|
|
9
|
+
local: "local";
|
|
10
|
+
comparison: "comparison";
|
|
11
|
+
informational: "informational";
|
|
12
|
+
navigational: "navigational";
|
|
13
|
+
transactional: "transactional";
|
|
14
|
+
commercial: "commercial";
|
|
15
|
+
troubleshooting: "troubleshooting";
|
|
16
|
+
}>;
|
|
17
|
+
export type PromptIntent = z.infer<typeof PromptIntentSchema>;
|
|
18
|
+
export declare const PromptIdeaSchema: z.ZodObject<{
|
|
19
|
+
prompt: z.ZodString;
|
|
20
|
+
intent: z.ZodEnum<{
|
|
21
|
+
local: "local";
|
|
22
|
+
comparison: "comparison";
|
|
23
|
+
informational: "informational";
|
|
24
|
+
navigational: "navigational";
|
|
25
|
+
transactional: "transactional";
|
|
26
|
+
commercial: "commercial";
|
|
27
|
+
troubleshooting: "troubleshooting";
|
|
28
|
+
}>;
|
|
29
|
+
}, z.core.$strip>;
|
|
30
|
+
export type PromptIdea = z.infer<typeof PromptIdeaSchema>;
|
|
31
|
+
export declare const PromptListSchema: z.ZodArray<z.ZodObject<{
|
|
32
|
+
prompt: z.ZodString;
|
|
33
|
+
intent: z.ZodEnum<{
|
|
34
|
+
local: "local";
|
|
35
|
+
comparison: "comparison";
|
|
36
|
+
informational: "informational";
|
|
37
|
+
navigational: "navigational";
|
|
38
|
+
transactional: "transactional";
|
|
39
|
+
commercial: "commercial";
|
|
40
|
+
troubleshooting: "troubleshooting";
|
|
41
|
+
}>;
|
|
42
|
+
}, z.core.$strip>>;
|
|
43
|
+
export type PromptList = z.infer<typeof PromptListSchema>;
|
|
44
|
+
export declare const PromptListResponseSchema: z.ZodObject<{
|
|
45
|
+
prompts: z.ZodArray<z.ZodObject<{
|
|
46
|
+
prompt: z.ZodString;
|
|
47
|
+
intent: z.ZodEnum<{
|
|
48
|
+
local: "local";
|
|
49
|
+
comparison: "comparison";
|
|
50
|
+
informational: "informational";
|
|
51
|
+
navigational: "navigational";
|
|
52
|
+
transactional: "transactional";
|
|
53
|
+
commercial: "commercial";
|
|
54
|
+
troubleshooting: "troubleshooting";
|
|
55
|
+
}>;
|
|
56
|
+
}, z.core.$strip>>;
|
|
57
|
+
}, z.core.$strip>;
|
|
58
|
+
export type PromptListResponse = z.infer<typeof PromptListResponseSchema>;
|
|
59
|
+
//# sourceMappingURL=prompt.schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.schema.d.ts","sourceRoot":"","sources":["../../../src/src/schemas/prompt.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,+CAA+C,CAAC;AAElE;;;;;GAKG;AAEH,eAAO,MAAM,kBAAkB;;;;;;;;EAQ7B,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE9D,eAAO,MAAM,gBAAgB;;;;;;;;;;;iBAG3B,CAAC;AAEH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE1D,eAAO,MAAM,gBAAgB;;;;;;;;;;;kBAC2B,CAAC;AAEzD,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE1D,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;iBAEnC,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from '../../deps/jsr.io/@zod/zod/4.3.6/src/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Zod schemas for AI visibility prompt generation.
|
|
4
|
+
*
|
|
5
|
+
* ⚠️ This file should contain ONLY schema definitions.
|
|
6
|
+
* No business logic, prompts, or function implementations.
|
|
7
|
+
*/
|
|
8
|
+
export const PromptIntentSchema = z.enum([
|
|
9
|
+
'informational',
|
|
10
|
+
'navigational',
|
|
11
|
+
'transactional',
|
|
12
|
+
'commercial',
|
|
13
|
+
'comparison',
|
|
14
|
+
'troubleshooting',
|
|
15
|
+
'local'
|
|
16
|
+
]);
|
|
17
|
+
export const PromptIdeaSchema = z.object({
|
|
18
|
+
prompt: z.string().min(3).describe('A realistic natural-language prompt a user would type into an LLM search engine.'),
|
|
19
|
+
intent: PromptIntentSchema.describe('Primary intent of the prompt.')
|
|
20
|
+
});
|
|
21
|
+
export const PromptListSchema = z.array(PromptIdeaSchema)
|
|
22
|
+
.describe('Generated prompt ideas with intent labels.');
|
|
23
|
+
export const PromptListResponseSchema = z.object({
|
|
24
|
+
prompts: PromptListSchema
|
|
25
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { z } from '../../deps/jsr.io/@zod/zod/4.3.6/src/index.js';
|
|
2
|
+
import { Tool, type ModelConfig } from '../tool.js';
|
|
3
|
+
import type { Message } from '../llm.js';
|
|
4
|
+
import { type PromptList, type PromptListResponse, type PromptIntent } from '../schemas/prompt.schema.js';
|
|
5
|
+
export interface PromptGeneratorConfig {
|
|
6
|
+
/** Minimum number of prompts to generate (default: 5) */
|
|
7
|
+
minPrompts?: number;
|
|
8
|
+
/** Maximum number of prompts to generate (default: 100) */
|
|
9
|
+
maxPrompts?: number;
|
|
10
|
+
/** Language for prompts (default: inferred from instructions) */
|
|
11
|
+
language?: string;
|
|
12
|
+
/** Optional topic context to guide prompt generation */
|
|
13
|
+
topics?: Array<string | {
|
|
14
|
+
topic: string;
|
|
15
|
+
subtopics?: Array<string>;
|
|
16
|
+
}>;
|
|
17
|
+
/** Optional persona context to guide prompt generation */
|
|
18
|
+
personas?: Array<string | {
|
|
19
|
+
name: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
}>;
|
|
22
|
+
/** Optional intent whitelist to focus generation */
|
|
23
|
+
intents?: Array<PromptIntent>;
|
|
24
|
+
/** Optional extra instructions to always apply */
|
|
25
|
+
instructions?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A tool that generates realistic LLM prompts for AI visibility analysis.
|
|
29
|
+
* Input is a single "instructions" string describing the topic and constraints.
|
|
30
|
+
*/
|
|
31
|
+
export declare class PromptGenerator extends Tool<string | null, PromptListResponse, PromptList> {
|
|
32
|
+
private readonly systemPrompt;
|
|
33
|
+
private readonly contextBlocks;
|
|
34
|
+
private readonly responseSchema;
|
|
35
|
+
constructor(config: PromptGeneratorConfig | undefined, modelConfig: ModelConfig);
|
|
36
|
+
protected schema(): z.ZodType<{
|
|
37
|
+
prompts: {
|
|
38
|
+
prompt: string;
|
|
39
|
+
intent: "local" | "comparison" | "informational" | "navigational" | "transactional" | "commercial" | "troubleshooting";
|
|
40
|
+
}[];
|
|
41
|
+
}, unknown, z.core.$ZodTypeInternals<{
|
|
42
|
+
prompts: {
|
|
43
|
+
prompt: string;
|
|
44
|
+
intent: "local" | "comparison" | "informational" | "navigational" | "transactional" | "commercial" | "troubleshooting";
|
|
45
|
+
}[];
|
|
46
|
+
}, unknown>>;
|
|
47
|
+
protected prompt(instructions: string | null): Message[];
|
|
48
|
+
protected isEmpty(instructions: string | null): boolean;
|
|
49
|
+
protected extractResult(parsed: PromptListResponse): PromptList;
|
|
50
|
+
}
|
|
51
|
+
export type { PromptList, PromptListResponse, PromptIdea, PromptIntent } from '../schemas/prompt.schema.js';
|
|
52
|
+
export { PromptListSchema, PromptListResponseSchema, PromptIdeaSchema, PromptIntentSchema } from '../schemas/prompt.schema.js';
|
|
53
|
+
//# sourceMappingURL=prompts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../../src/src/tools/prompts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,+CAA+C,CAAC;AACvE,OAAO,EAAE,IAAI,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAGN,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,MAAM,6BAA6B,CAAC;AA6BrC,MAAM,WAAW,qBAAqB;IACrC,yDAAyD;IACzD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,2DAA2D;IAC3D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iEAAiE;IACjE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wDAAwD;IACxD,MAAM,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;KAAE,CAAC,CAAC;IACtE,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAClE,oDAAoD;IACpD,OAAO,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;IAC9B,kDAAkD;IAClD,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,IAAI,CAAC,MAAM,GAAG,IAAI,EAAE,kBAAkB,EAAE,UAAU,CAAC;IACvF,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAgC;gBAEnD,MAAM,EAAE,qBAAqB,YAAK,EAAE,WAAW,EAAE,WAAW;cAiErD,MAAM;;;;;;;;;;;IAIzB,SAAS,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,EAAE;cAQrC,OAAO,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO;cAI7C,aAAa,CAAC,MAAM,EAAE,kBAAkB,GAAG,UAAU;CAGxE;AAED,YAAY,EAAE,UAAU,EAAE,kBAAkB,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC5G,OAAO,EACN,gBAAgB,EAChB,wBAAwB,EACxB,gBAAgB,EAChB,kBAAkB,EAClB,MAAM,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { Tool } from '../tool.js';
|
|
2
|
+
import { PromptListSchema, PromptListResponseSchema } from '../schemas/prompt.schema.js';
|
|
3
|
+
import { dedent } from '../helpers/utils.js';
|
|
4
|
+
const PROMPT_SYSTEM = dedent(`
|
|
5
|
+
You generate realistic natural-language prompts for AI visibility testing with LLM search engines.
|
|
6
|
+
|
|
7
|
+
Follow the user's instructions exactly and only use the context they provide.
|
|
8
|
+
|
|
9
|
+
Output requirements:
|
|
10
|
+
- Return a JSON object with a "prompts" array.
|
|
11
|
+
- Each object must include: prompt, intent.
|
|
12
|
+
- The "intent" must be one of: informational, navigational, transactional, commercial, comparison, troubleshooting, local.
|
|
13
|
+
- Generate between {min} and {max} prompts unless the instructions request a number within that range.
|
|
14
|
+
- If the instructions specify how many prompts to generate, follow that.
|
|
15
|
+
|
|
16
|
+
Quality rules:
|
|
17
|
+
- Prompts should read like real user questions or requests for an AI assistant, not keyword fragments.
|
|
18
|
+
- Cover a mix of intents and realistic personas; avoid repeating the same intent across many prompts.
|
|
19
|
+
- If topics or personas are provided, use them as context to shape prompts (but do not output them).
|
|
20
|
+
- Avoid brand names unless the instructions explicitly include them.
|
|
21
|
+
- Keep prompts focused on the topic and avoid hallucinated claims.
|
|
22
|
+
`);
|
|
23
|
+
const PROMPT_USER = dedent(`
|
|
24
|
+
# Instructions
|
|
25
|
+
|
|
26
|
+
{instructions}
|
|
27
|
+
`);
|
|
28
|
+
/**
|
|
29
|
+
* A tool that generates realistic LLM prompts for AI visibility analysis.
|
|
30
|
+
* Input is a single "instructions" string describing the topic and constraints.
|
|
31
|
+
*/
|
|
32
|
+
export class PromptGenerator extends Tool {
|
|
33
|
+
systemPrompt;
|
|
34
|
+
contextBlocks;
|
|
35
|
+
responseSchema;
|
|
36
|
+
constructor(config = {}, modelConfig) {
|
|
37
|
+
super(modelConfig);
|
|
38
|
+
const { minPrompts = 5, maxPrompts = 100, language, topics, personas, intents, instructions } = config;
|
|
39
|
+
if (minPrompts < 0) {
|
|
40
|
+
throw new Error('minPrompts must be >= 0');
|
|
41
|
+
}
|
|
42
|
+
if (maxPrompts < minPrompts) {
|
|
43
|
+
throw new Error('maxPrompts must be >= minPrompts');
|
|
44
|
+
}
|
|
45
|
+
const contextParts = [];
|
|
46
|
+
if (instructions && instructions.trim() !== '') {
|
|
47
|
+
contextParts.push(dedent(`
|
|
48
|
+
# Additional Instructions
|
|
49
|
+
|
|
50
|
+
${instructions}
|
|
51
|
+
`));
|
|
52
|
+
}
|
|
53
|
+
if (language) {
|
|
54
|
+
contextParts.push(dedent(`
|
|
55
|
+
# Language
|
|
56
|
+
|
|
57
|
+
Generate prompts in: ${language}
|
|
58
|
+
`));
|
|
59
|
+
}
|
|
60
|
+
if (topics && topics.length > 0) {
|
|
61
|
+
contextParts.push(dedent(`
|
|
62
|
+
# Topics (Optional Context)
|
|
63
|
+
|
|
64
|
+
${JSON.stringify(topics, null, 2)}
|
|
65
|
+
`));
|
|
66
|
+
}
|
|
67
|
+
if (personas && personas.length > 0) {
|
|
68
|
+
contextParts.push(dedent(`
|
|
69
|
+
# Personas (Optional Context)
|
|
70
|
+
|
|
71
|
+
${JSON.stringify(personas, null, 2)}
|
|
72
|
+
`));
|
|
73
|
+
}
|
|
74
|
+
if (intents && intents.length > 0) {
|
|
75
|
+
contextParts.push(dedent(`
|
|
76
|
+
# Intent Focus (Optional)
|
|
77
|
+
|
|
78
|
+
${JSON.stringify(intents, null, 2)}
|
|
79
|
+
`));
|
|
80
|
+
}
|
|
81
|
+
this.contextBlocks = contextParts.join('\n\n');
|
|
82
|
+
this.systemPrompt = PROMPT_SYSTEM
|
|
83
|
+
.replace('{min}', String(minPrompts))
|
|
84
|
+
.replace('{max}', String(maxPrompts));
|
|
85
|
+
this.responseSchema = PromptListResponseSchema.extend({
|
|
86
|
+
prompts: PromptListSchema.min(minPrompts).max(maxPrompts)
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
schema() {
|
|
90
|
+
return this.responseSchema;
|
|
91
|
+
}
|
|
92
|
+
prompt(instructions) {
|
|
93
|
+
const userPrompt = PROMPT_USER.replace('{instructions}', instructions ?? '');
|
|
94
|
+
return [
|
|
95
|
+
{ role: 'system', content: this.systemPrompt },
|
|
96
|
+
{ role: 'user', content: this.contextBlocks ? `${userPrompt}\n\n${this.contextBlocks}` : userPrompt }
|
|
97
|
+
];
|
|
98
|
+
}
|
|
99
|
+
isEmpty(instructions) {
|
|
100
|
+
return instructions == null || instructions.trim() === '';
|
|
101
|
+
}
|
|
102
|
+
extractResult(parsed) {
|
|
103
|
+
return parsed.prompts;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
export { PromptListSchema, PromptListResponseSchema, PromptIdeaSchema, PromptIntentSchema } from '../schemas/prompt.schema.js';
|
package/package.json
CHANGED
package/script/mod.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export * from './src/tools/sentiment.js';
|
|
|
19
19
|
export * from './src/tools/summarize.js';
|
|
20
20
|
export * from './src/tools/sources.js';
|
|
21
21
|
export * from './src/tools/entities.js';
|
|
22
|
+
export * from './src/tools/prompts.js';
|
|
22
23
|
export * from './src/helpers/seedKeywords.js';
|
|
23
24
|
export * from './src/tools/generic.js';
|
|
24
25
|
export * from './src/api.js';
|
package/script/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EACN,WAAW,EACX,mBAAmB,EACnB,eAAe,EACf,YAAY,EACZ,aAAa,EACb,KAAK,YAAY,EACjB,KAAK,SAAS,GACd,MAAM,0BAA0B,CAAC;AAGlC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,oCAAoC,CAAC;AACnD,cAAc,wCAAwC,CAAC;AACvD,cAAc,wBAAwB,CAAC"}
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EACN,WAAW,EACX,mBAAmB,EACnB,eAAe,EACf,YAAY,EACZ,aAAa,EACb,KAAK,YAAY,EACjB,KAAK,SAAS,GACd,MAAM,0BAA0B,CAAC;AAGlC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,oCAAoC,CAAC;AACnD,cAAc,wCAAwC,CAAC;AACvD,cAAc,wBAAwB,CAAC"}
|
package/script/mod.js
CHANGED
|
@@ -44,6 +44,7 @@ __exportStar(require("./src/tools/sentiment.js"), exports);
|
|
|
44
44
|
__exportStar(require("./src/tools/summarize.js"), exports);
|
|
45
45
|
__exportStar(require("./src/tools/sources.js"), exports);
|
|
46
46
|
__exportStar(require("./src/tools/entities.js"), exports);
|
|
47
|
+
__exportStar(require("./src/tools/prompts.js"), exports);
|
|
47
48
|
__exportStar(require("./src/helpers/seedKeywords.js"), exports);
|
|
48
49
|
__exportStar(require("./src/tools/generic.js"), exports);
|
|
49
50
|
__exportStar(require("./src/api.js"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/schemas/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,mBAAmB,qBAAqB,CAAC;AACzC,mBAAmB,mBAAmB,CAAC;AACvC,mBAAmB,oBAAoB,CAAC;AACxC,mBAAmB,qBAAqB,CAAC;AACzC,mBAAmB,sBAAsB,CAAC;AAC1C,mBAAmB,oBAAoB,CAAC;AACxC,mBAAmB,yBAAyB,CAAC;AAC7C,mBAAmB,oBAAoB,CAAC;AACxC,mBAAmB,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/schemas/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,mBAAmB,qBAAqB,CAAC;AACzC,mBAAmB,mBAAmB,CAAC;AACvC,mBAAmB,oBAAoB,CAAC;AACxC,mBAAmB,qBAAqB,CAAC;AACzC,mBAAmB,sBAAsB,CAAC;AAC1C,mBAAmB,oBAAoB,CAAC;AACxC,mBAAmB,yBAAyB,CAAC;AAC7C,mBAAmB,oBAAoB,CAAC;AACxC,mBAAmB,qBAAqB,CAAC;AACzC,mBAAmB,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { z } from '../../deps/jsr.io/@zod/zod/4.3.6/src/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Zod schemas for AI visibility prompt generation.
|
|
4
|
+
*
|
|
5
|
+
* ⚠️ This file should contain ONLY schema definitions.
|
|
6
|
+
* No business logic, prompts, or function implementations.
|
|
7
|
+
*/
|
|
8
|
+
export declare const PromptIntentSchema: z.ZodEnum<{
|
|
9
|
+
local: "local";
|
|
10
|
+
comparison: "comparison";
|
|
11
|
+
informational: "informational";
|
|
12
|
+
navigational: "navigational";
|
|
13
|
+
transactional: "transactional";
|
|
14
|
+
commercial: "commercial";
|
|
15
|
+
troubleshooting: "troubleshooting";
|
|
16
|
+
}>;
|
|
17
|
+
export type PromptIntent = z.infer<typeof PromptIntentSchema>;
|
|
18
|
+
export declare const PromptIdeaSchema: z.ZodObject<{
|
|
19
|
+
prompt: z.ZodString;
|
|
20
|
+
intent: z.ZodEnum<{
|
|
21
|
+
local: "local";
|
|
22
|
+
comparison: "comparison";
|
|
23
|
+
informational: "informational";
|
|
24
|
+
navigational: "navigational";
|
|
25
|
+
transactional: "transactional";
|
|
26
|
+
commercial: "commercial";
|
|
27
|
+
troubleshooting: "troubleshooting";
|
|
28
|
+
}>;
|
|
29
|
+
}, z.core.$strip>;
|
|
30
|
+
export type PromptIdea = z.infer<typeof PromptIdeaSchema>;
|
|
31
|
+
export declare const PromptListSchema: z.ZodArray<z.ZodObject<{
|
|
32
|
+
prompt: z.ZodString;
|
|
33
|
+
intent: z.ZodEnum<{
|
|
34
|
+
local: "local";
|
|
35
|
+
comparison: "comparison";
|
|
36
|
+
informational: "informational";
|
|
37
|
+
navigational: "navigational";
|
|
38
|
+
transactional: "transactional";
|
|
39
|
+
commercial: "commercial";
|
|
40
|
+
troubleshooting: "troubleshooting";
|
|
41
|
+
}>;
|
|
42
|
+
}, z.core.$strip>>;
|
|
43
|
+
export type PromptList = z.infer<typeof PromptListSchema>;
|
|
44
|
+
export declare const PromptListResponseSchema: z.ZodObject<{
|
|
45
|
+
prompts: z.ZodArray<z.ZodObject<{
|
|
46
|
+
prompt: z.ZodString;
|
|
47
|
+
intent: z.ZodEnum<{
|
|
48
|
+
local: "local";
|
|
49
|
+
comparison: "comparison";
|
|
50
|
+
informational: "informational";
|
|
51
|
+
navigational: "navigational";
|
|
52
|
+
transactional: "transactional";
|
|
53
|
+
commercial: "commercial";
|
|
54
|
+
troubleshooting: "troubleshooting";
|
|
55
|
+
}>;
|
|
56
|
+
}, z.core.$strip>>;
|
|
57
|
+
}, z.core.$strip>;
|
|
58
|
+
export type PromptListResponse = z.infer<typeof PromptListResponseSchema>;
|
|
59
|
+
//# sourceMappingURL=prompt.schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.schema.d.ts","sourceRoot":"","sources":["../../../src/src/schemas/prompt.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,+CAA+C,CAAC;AAElE;;;;;GAKG;AAEH,eAAO,MAAM,kBAAkB;;;;;;;;EAQ7B,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE9D,eAAO,MAAM,gBAAgB;;;;;;;;;;;iBAG3B,CAAC;AAEH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE1D,eAAO,MAAM,gBAAgB;;;;;;;;;;;kBAC2B,CAAC;AAEzD,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE1D,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;iBAEnC,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PromptListResponseSchema = exports.PromptListSchema = exports.PromptIdeaSchema = exports.PromptIntentSchema = void 0;
|
|
4
|
+
const index_js_1 = require("../../deps/jsr.io/@zod/zod/4.3.6/src/index.js");
|
|
5
|
+
/**
|
|
6
|
+
* Zod schemas for AI visibility prompt generation.
|
|
7
|
+
*
|
|
8
|
+
* ⚠️ This file should contain ONLY schema definitions.
|
|
9
|
+
* No business logic, prompts, or function implementations.
|
|
10
|
+
*/
|
|
11
|
+
exports.PromptIntentSchema = index_js_1.z.enum([
|
|
12
|
+
'informational',
|
|
13
|
+
'navigational',
|
|
14
|
+
'transactional',
|
|
15
|
+
'commercial',
|
|
16
|
+
'comparison',
|
|
17
|
+
'troubleshooting',
|
|
18
|
+
'local'
|
|
19
|
+
]);
|
|
20
|
+
exports.PromptIdeaSchema = index_js_1.z.object({
|
|
21
|
+
prompt: index_js_1.z.string().min(3).describe('A realistic natural-language prompt a user would type into an LLM search engine.'),
|
|
22
|
+
intent: exports.PromptIntentSchema.describe('Primary intent of the prompt.')
|
|
23
|
+
});
|
|
24
|
+
exports.PromptListSchema = index_js_1.z.array(exports.PromptIdeaSchema)
|
|
25
|
+
.describe('Generated prompt ideas with intent labels.');
|
|
26
|
+
exports.PromptListResponseSchema = index_js_1.z.object({
|
|
27
|
+
prompts: exports.PromptListSchema
|
|
28
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { z } from '../../deps/jsr.io/@zod/zod/4.3.6/src/index.js';
|
|
2
|
+
import { Tool, type ModelConfig } from '../tool.js';
|
|
3
|
+
import type { Message } from '../llm.js';
|
|
4
|
+
import { type PromptList, type PromptListResponse, type PromptIntent } from '../schemas/prompt.schema.js';
|
|
5
|
+
export interface PromptGeneratorConfig {
|
|
6
|
+
/** Minimum number of prompts to generate (default: 5) */
|
|
7
|
+
minPrompts?: number;
|
|
8
|
+
/** Maximum number of prompts to generate (default: 100) */
|
|
9
|
+
maxPrompts?: number;
|
|
10
|
+
/** Language for prompts (default: inferred from instructions) */
|
|
11
|
+
language?: string;
|
|
12
|
+
/** Optional topic context to guide prompt generation */
|
|
13
|
+
topics?: Array<string | {
|
|
14
|
+
topic: string;
|
|
15
|
+
subtopics?: Array<string>;
|
|
16
|
+
}>;
|
|
17
|
+
/** Optional persona context to guide prompt generation */
|
|
18
|
+
personas?: Array<string | {
|
|
19
|
+
name: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
}>;
|
|
22
|
+
/** Optional intent whitelist to focus generation */
|
|
23
|
+
intents?: Array<PromptIntent>;
|
|
24
|
+
/** Optional extra instructions to always apply */
|
|
25
|
+
instructions?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A tool that generates realistic LLM prompts for AI visibility analysis.
|
|
29
|
+
* Input is a single "instructions" string describing the topic and constraints.
|
|
30
|
+
*/
|
|
31
|
+
export declare class PromptGenerator extends Tool<string | null, PromptListResponse, PromptList> {
|
|
32
|
+
private readonly systemPrompt;
|
|
33
|
+
private readonly contextBlocks;
|
|
34
|
+
private readonly responseSchema;
|
|
35
|
+
constructor(config: PromptGeneratorConfig | undefined, modelConfig: ModelConfig);
|
|
36
|
+
protected schema(): z.ZodType<{
|
|
37
|
+
prompts: {
|
|
38
|
+
prompt: string;
|
|
39
|
+
intent: "local" | "comparison" | "informational" | "navigational" | "transactional" | "commercial" | "troubleshooting";
|
|
40
|
+
}[];
|
|
41
|
+
}, unknown, z.core.$ZodTypeInternals<{
|
|
42
|
+
prompts: {
|
|
43
|
+
prompt: string;
|
|
44
|
+
intent: "local" | "comparison" | "informational" | "navigational" | "transactional" | "commercial" | "troubleshooting";
|
|
45
|
+
}[];
|
|
46
|
+
}, unknown>>;
|
|
47
|
+
protected prompt(instructions: string | null): Message[];
|
|
48
|
+
protected isEmpty(instructions: string | null): boolean;
|
|
49
|
+
protected extractResult(parsed: PromptListResponse): PromptList;
|
|
50
|
+
}
|
|
51
|
+
export type { PromptList, PromptListResponse, PromptIdea, PromptIntent } from '../schemas/prompt.schema.js';
|
|
52
|
+
export { PromptListSchema, PromptListResponseSchema, PromptIdeaSchema, PromptIntentSchema } from '../schemas/prompt.schema.js';
|
|
53
|
+
//# sourceMappingURL=prompts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../../src/src/tools/prompts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,+CAA+C,CAAC;AACvE,OAAO,EAAE,IAAI,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAGN,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,MAAM,6BAA6B,CAAC;AA6BrC,MAAM,WAAW,qBAAqB;IACrC,yDAAyD;IACzD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,2DAA2D;IAC3D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iEAAiE;IACjE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wDAAwD;IACxD,MAAM,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;KAAE,CAAC,CAAC;IACtE,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAClE,oDAAoD;IACpD,OAAO,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;IAC9B,kDAAkD;IAClD,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,IAAI,CAAC,MAAM,GAAG,IAAI,EAAE,kBAAkB,EAAE,UAAU,CAAC;IACvF,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAgC;gBAEnD,MAAM,EAAE,qBAAqB,YAAK,EAAE,WAAW,EAAE,WAAW;cAiErD,MAAM;;;;;;;;;;;IAIzB,SAAS,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,EAAE;cAQrC,OAAO,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO;cAI7C,aAAa,CAAC,MAAM,EAAE,kBAAkB,GAAG,UAAU;CAGxE;AAED,YAAY,EAAE,UAAU,EAAE,kBAAkB,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC5G,OAAO,EACN,gBAAgB,EAChB,wBAAwB,EACxB,gBAAgB,EAChB,kBAAkB,EAClB,MAAM,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PromptIntentSchema = exports.PromptIdeaSchema = exports.PromptListResponseSchema = exports.PromptListSchema = exports.PromptGenerator = void 0;
|
|
4
|
+
const tool_js_1 = require("../tool.js");
|
|
5
|
+
const prompt_schema_js_1 = require("../schemas/prompt.schema.js");
|
|
6
|
+
const utils_js_1 = require("../helpers/utils.js");
|
|
7
|
+
const PROMPT_SYSTEM = (0, utils_js_1.dedent)(`
|
|
8
|
+
You generate realistic natural-language prompts for AI visibility testing with LLM search engines.
|
|
9
|
+
|
|
10
|
+
Follow the user's instructions exactly and only use the context they provide.
|
|
11
|
+
|
|
12
|
+
Output requirements:
|
|
13
|
+
- Return a JSON object with a "prompts" array.
|
|
14
|
+
- Each object must include: prompt, intent.
|
|
15
|
+
- The "intent" must be one of: informational, navigational, transactional, commercial, comparison, troubleshooting, local.
|
|
16
|
+
- Generate between {min} and {max} prompts unless the instructions request a number within that range.
|
|
17
|
+
- If the instructions specify how many prompts to generate, follow that.
|
|
18
|
+
|
|
19
|
+
Quality rules:
|
|
20
|
+
- Prompts should read like real user questions or requests for an AI assistant, not keyword fragments.
|
|
21
|
+
- Cover a mix of intents and realistic personas; avoid repeating the same intent across many prompts.
|
|
22
|
+
- If topics or personas are provided, use them as context to shape prompts (but do not output them).
|
|
23
|
+
- Avoid brand names unless the instructions explicitly include them.
|
|
24
|
+
- Keep prompts focused on the topic and avoid hallucinated claims.
|
|
25
|
+
`);
|
|
26
|
+
const PROMPT_USER = (0, utils_js_1.dedent)(`
|
|
27
|
+
# Instructions
|
|
28
|
+
|
|
29
|
+
{instructions}
|
|
30
|
+
`);
|
|
31
|
+
/**
|
|
32
|
+
* A tool that generates realistic LLM prompts for AI visibility analysis.
|
|
33
|
+
* Input is a single "instructions" string describing the topic and constraints.
|
|
34
|
+
*/
|
|
35
|
+
class PromptGenerator extends tool_js_1.Tool {
|
|
36
|
+
systemPrompt;
|
|
37
|
+
contextBlocks;
|
|
38
|
+
responseSchema;
|
|
39
|
+
constructor(config = {}, modelConfig) {
|
|
40
|
+
super(modelConfig);
|
|
41
|
+
const { minPrompts = 5, maxPrompts = 100, language, topics, personas, intents, instructions } = config;
|
|
42
|
+
if (minPrompts < 0) {
|
|
43
|
+
throw new Error('minPrompts must be >= 0');
|
|
44
|
+
}
|
|
45
|
+
if (maxPrompts < minPrompts) {
|
|
46
|
+
throw new Error('maxPrompts must be >= minPrompts');
|
|
47
|
+
}
|
|
48
|
+
const contextParts = [];
|
|
49
|
+
if (instructions && instructions.trim() !== '') {
|
|
50
|
+
contextParts.push((0, utils_js_1.dedent)(`
|
|
51
|
+
# Additional Instructions
|
|
52
|
+
|
|
53
|
+
${instructions}
|
|
54
|
+
`));
|
|
55
|
+
}
|
|
56
|
+
if (language) {
|
|
57
|
+
contextParts.push((0, utils_js_1.dedent)(`
|
|
58
|
+
# Language
|
|
59
|
+
|
|
60
|
+
Generate prompts in: ${language}
|
|
61
|
+
`));
|
|
62
|
+
}
|
|
63
|
+
if (topics && topics.length > 0) {
|
|
64
|
+
contextParts.push((0, utils_js_1.dedent)(`
|
|
65
|
+
# Topics (Optional Context)
|
|
66
|
+
|
|
67
|
+
${JSON.stringify(topics, null, 2)}
|
|
68
|
+
`));
|
|
69
|
+
}
|
|
70
|
+
if (personas && personas.length > 0) {
|
|
71
|
+
contextParts.push((0, utils_js_1.dedent)(`
|
|
72
|
+
# Personas (Optional Context)
|
|
73
|
+
|
|
74
|
+
${JSON.stringify(personas, null, 2)}
|
|
75
|
+
`));
|
|
76
|
+
}
|
|
77
|
+
if (intents && intents.length > 0) {
|
|
78
|
+
contextParts.push((0, utils_js_1.dedent)(`
|
|
79
|
+
# Intent Focus (Optional)
|
|
80
|
+
|
|
81
|
+
${JSON.stringify(intents, null, 2)}
|
|
82
|
+
`));
|
|
83
|
+
}
|
|
84
|
+
this.contextBlocks = contextParts.join('\n\n');
|
|
85
|
+
this.systemPrompt = PROMPT_SYSTEM
|
|
86
|
+
.replace('{min}', String(minPrompts))
|
|
87
|
+
.replace('{max}', String(maxPrompts));
|
|
88
|
+
this.responseSchema = prompt_schema_js_1.PromptListResponseSchema.extend({
|
|
89
|
+
prompts: prompt_schema_js_1.PromptListSchema.min(minPrompts).max(maxPrompts)
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
schema() {
|
|
93
|
+
return this.responseSchema;
|
|
94
|
+
}
|
|
95
|
+
prompt(instructions) {
|
|
96
|
+
const userPrompt = PROMPT_USER.replace('{instructions}', instructions ?? '');
|
|
97
|
+
return [
|
|
98
|
+
{ role: 'system', content: this.systemPrompt },
|
|
99
|
+
{ role: 'user', content: this.contextBlocks ? `${userPrompt}\n\n${this.contextBlocks}` : userPrompt }
|
|
100
|
+
];
|
|
101
|
+
}
|
|
102
|
+
isEmpty(instructions) {
|
|
103
|
+
return instructions == null || instructions.trim() === '';
|
|
104
|
+
}
|
|
105
|
+
extractResult(parsed) {
|
|
106
|
+
return parsed.prompts;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.PromptGenerator = PromptGenerator;
|
|
110
|
+
var prompt_schema_js_2 = require("../schemas/prompt.schema.js");
|
|
111
|
+
Object.defineProperty(exports, "PromptListSchema", { enumerable: true, get: function () { return prompt_schema_js_2.PromptListSchema; } });
|
|
112
|
+
Object.defineProperty(exports, "PromptListResponseSchema", { enumerable: true, get: function () { return prompt_schema_js_2.PromptListResponseSchema; } });
|
|
113
|
+
Object.defineProperty(exports, "PromptIdeaSchema", { enumerable: true, get: function () { return prompt_schema_js_2.PromptIdeaSchema; } });
|
|
114
|
+
Object.defineProperty(exports, "PromptIntentSchema", { enumerable: true, get: function () { return prompt_schema_js_2.PromptIntentSchema; } });
|