@graphext/cuery 0.6.0 → 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.
Files changed (47) hide show
  1. package/esm/mod.d.ts +1 -0
  2. package/esm/mod.d.ts.map +1 -1
  3. package/esm/mod.js +1 -0
  4. package/esm/src/llm.d.ts.map +1 -1
  5. package/esm/src/llm.js +9 -5
  6. package/esm/src/providers/errors.d.ts +8 -0
  7. package/esm/src/providers/errors.d.ts.map +1 -0
  8. package/esm/src/providers/errors.js +11 -0
  9. package/esm/src/providers/google.d.ts.map +1 -1
  10. package/esm/src/providers/google.js +2 -1
  11. package/esm/src/providers/index.d.ts +1 -0
  12. package/esm/src/providers/index.d.ts.map +1 -1
  13. package/esm/src/providers/index.js +1 -0
  14. package/esm/src/providers/openai.d.ts.map +1 -1
  15. package/esm/src/providers/openai.js +7 -4
  16. package/esm/src/schemas/index.d.ts +1 -0
  17. package/esm/src/schemas/index.d.ts.map +1 -1
  18. package/esm/src/schemas/prompt.schema.d.ts +59 -0
  19. package/esm/src/schemas/prompt.schema.d.ts.map +1 -0
  20. package/esm/src/schemas/prompt.schema.js +25 -0
  21. package/esm/src/tools/prompts.d.ts +53 -0
  22. package/esm/src/tools/prompts.d.ts.map +1 -0
  23. package/esm/src/tools/prompts.js +106 -0
  24. package/package.json +1 -1
  25. package/script/mod.d.ts +1 -0
  26. package/script/mod.d.ts.map +1 -1
  27. package/script/mod.js +1 -0
  28. package/script/src/llm.d.ts.map +1 -1
  29. package/script/src/llm.js +8 -4
  30. package/script/src/providers/errors.d.ts +8 -0
  31. package/script/src/providers/errors.d.ts.map +1 -0
  32. package/script/src/providers/errors.js +15 -0
  33. package/script/src/providers/google.d.ts.map +1 -1
  34. package/script/src/providers/google.js +2 -1
  35. package/script/src/providers/index.d.ts +1 -0
  36. package/script/src/providers/index.d.ts.map +1 -1
  37. package/script/src/providers/index.js +3 -1
  38. package/script/src/providers/openai.d.ts.map +1 -1
  39. package/script/src/providers/openai.js +7 -4
  40. package/script/src/schemas/index.d.ts +1 -0
  41. package/script/src/schemas/index.d.ts.map +1 -1
  42. package/script/src/schemas/prompt.schema.d.ts +59 -0
  43. package/script/src/schemas/prompt.schema.d.ts.map +1 -0
  44. package/script/src/schemas/prompt.schema.js +28 -0
  45. package/script/src/tools/prompts.d.ts +53 -0
  46. package/script/src/tools/prompts.d.ts.map +1 -0
  47. 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":"llm.d.ts","sourceRoot":"","sources":["../../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E,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,YAAY,GAAG,SAAS,CAAC,GACrD,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAEzB"}
package/esm/src/llm.js CHANGED
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * Unified LLM interface - provider-agnostic API for making LLM calls.
3
3
  */
4
- import { getProviderForModel } from './providers/index.js';
4
+ import { SchemaValidationError } from './providers/errors.js';
5
+ import { getProviderForModel, } from './providers/index.js';
5
6
  export { calculateCost } from './providers/index.js';
6
7
  /**
7
8
  * Normalize a prompt to a message array.
@@ -32,9 +33,9 @@ export async function askLLMSafe({ prompt, model, schema, params, maxRetries = 3
32
33
  error: response.error ?? new Error('Unknown error'),
33
34
  };
34
35
  if (attempt < maxRetries && response.error) {
35
- // Add error context to messages for retry
36
- const errorMessage = `Previous attempt failed with error: ${response.error.message}`;
37
- if (response.text) {
36
+ let errorMessage;
37
+ if (response.error instanceof SchemaValidationError) {
38
+ errorMessage = `Previous attempt failed with Zod parsing error:\n${response.error.message}.`;
38
39
  messages = [
39
40
  ...messages,
40
41
  {
@@ -43,7 +44,10 @@ export async function askLLMSafe({ prompt, model, schema, params, maxRetries = 3
43
44
  },
44
45
  ];
45
46
  }
46
- console.log(`askLLMSafe retrying! Attempt ${attempt + 1} failed: ${response.error.message}`);
47
+ else {
48
+ errorMessage = `Previous attempt failed with error: ${response.error.message}`;
49
+ }
50
+ console.log(`askLLMSafe retrying! Attempt ${attempt + 1} failed with: ${errorMessage}`);
47
51
  }
48
52
  }
49
53
  if (onError === 'return') {
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Error indicating model output failed schema validation.
3
+ */
4
+ export declare class SchemaValidationError extends Error {
5
+ readonly cause?: unknown;
6
+ constructor(message: string, cause?: unknown);
7
+ }
8
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/src/providers/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;IAC/C,SAAkB,KAAK,CAAC,EAAE,OAAO,CAAC;gBAEtB,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAK5C"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Error indicating model output failed schema validation.
3
+ */
4
+ export class SchemaValidationError extends Error {
5
+ cause;
6
+ constructor(message, cause) {
7
+ super(message);
8
+ this.name = 'SchemaValidationError';
9
+ this.cause = cause;
10
+ }
11
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../../src/src/providers/google.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,CAAC,EAAE,MAAM,+CAA+C,CAAC;AAElE,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAuCpF;;GAEG;AACH,qBAAa,cAAe,YAAW,WAAW;IACjD,QAAQ,CAAC,IAAI,YAAY;IACzB,OAAO,CAAC,MAAM,CAAc;gBAEhB,MAAM,CAAC,EAAE,MAAM;IAUrB,QAAQ,CAAC,CAAC,EACf,QAAQ,EAAE,OAAO,EAAE,EACnB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,EAC3B,MAAM,CAAC,EAAE,cAAc,GACrB,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;CA8D1B"}
1
+ {"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../../src/src/providers/google.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,CAAC,EAAE,MAAM,+CAA+C,CAAC;AAGlE,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAuCpF;;GAEG;AACH,qBAAa,cAAe,YAAW,WAAW;IACjD,QAAQ,CAAC,IAAI,YAAY;IACzB,OAAO,CAAC,MAAM,CAAc;gBAEhB,MAAM,CAAC,EAAE,MAAM;IAUrB,QAAQ,CAAC,CAAC,EACf,QAAQ,EAAE,OAAO,EAAE,EACnB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,EAC3B,MAAM,CAAC,EAAE,cAAc,GACrB,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;CAiE1B"}
@@ -4,6 +4,7 @@
4
4
  import * as dntShim from "../../_dnt.shims.js";
5
5
  import { GoogleGenAI } from '@google/genai';
6
6
  import { z } from '../../deps/jsr.io/@zod/zod/4.3.6/src/index.js';
7
+ import { SchemaValidationError } from './errors.js';
7
8
  /**
8
9
  * Convert messages to Gemini content format.
9
10
  * Handles system prompts by prepending them as context.
@@ -88,7 +89,7 @@ export class GoogleProvider {
88
89
  parsed: null,
89
90
  text,
90
91
  usage,
91
- error: error instanceof Error ? error : new Error(String(error)),
92
+ error: new SchemaValidationError(error instanceof Error ? error.message : String(error), error),
92
93
  };
93
94
  }
94
95
  }
@@ -8,6 +8,7 @@
8
8
  export { getProvider, getProviderForModel } from './registry.js';
9
9
  export { OpenAIProvider } from './openai.js';
10
10
  export { GoogleProvider } from './google.js';
11
+ export { SchemaValidationError } from './errors.js';
11
12
  export { getModelPricing, getModelInfo, calculateCost, type ModelPricing, type ModelInfo, } from './pricing.js';
12
13
  export type { Message, LLMResponse, LLMProvider, ProviderParams, LLMConversation, } from './types.js';
13
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/providers/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAGjE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG7C,OAAO,EACN,eAAe,EACf,YAAY,EACZ,aAAa,EACb,KAAK,YAAY,EACjB,KAAK,SAAS,GACd,MAAM,cAAc,CAAC;AAGtB,YAAY,EACX,OAAO,EACP,WAAW,EACX,WAAW,EACX,cAAc,EACd,eAAe,GACf,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/providers/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAGjE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAGpD,OAAO,EACN,eAAe,EACf,YAAY,EACZ,aAAa,EACb,KAAK,YAAY,EACjB,KAAK,SAAS,GACd,MAAM,cAAc,CAAC;AAGtB,YAAY,EACX,OAAO,EACP,WAAW,EACX,WAAW,EACX,cAAc,EACd,eAAe,GACf,MAAM,YAAY,CAAC"}
@@ -10,5 +10,6 @@ export { getProvider, getProviderForModel } from './registry.js';
10
10
  // Re-export provider implementations
11
11
  export { OpenAIProvider } from './openai.js';
12
12
  export { GoogleProvider } from './google.js';
13
+ export { SchemaValidationError } from './errors.js';
13
14
  // Re-export pricing utilities
14
15
  export { getModelPricing, getModelInfo, calculateCost, } from './pricing.js';
@@ -1 +1 @@
1
- {"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../src/src/providers/openai.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,CAAC,EAAE,MAAM,+CAA+C,CAAC;AAElE,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAyFpF;;GAEG;AACH,qBAAa,cAAe,YAAW,WAAW;IACjD,QAAQ,CAAC,IAAI,YAAY;IACzB,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,CAAC,EAAE,MAAM;IAarB,QAAQ,CAAC,CAAC,EACf,QAAQ,EAAE,OAAO,EAAE,EACnB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,EAC3B,MAAM,CAAC,EAAE,cAAc,GACrB,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;CAkD1B"}
1
+ {"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../src/src/providers/openai.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,CAAC,EAAE,MAAM,+CAA+C,CAAC;AAGlE,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AA0FpF;;GAEG;AACH,qBAAa,cAAe,YAAW,WAAW;IACjD,QAAQ,CAAC,IAAI,YAAY;IACzB,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,CAAC,EAAE,MAAM;IAarB,QAAQ,CAAC,CAAC,EACf,QAAQ,EAAE,OAAO,EAAE,EACnB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,EAC3B,MAAM,CAAC,EAAE,cAAc,GACrB,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;CAuD1B"}
@@ -4,9 +4,8 @@
4
4
  import * as dntShim from "../../_dnt.shims.js";
5
5
  import OpenAI from 'openai';
6
6
  import { z } from '../../deps/jsr.io/@zod/zod/4.3.6/src/index.js';
7
+ import { SchemaValidationError } from './errors.js';
7
8
  const zodTextFormatCache = new Map();
8
- class ZodValidationError extends Error {
9
- }
10
9
  /**
11
10
  * Sanitizes a JSON schema for OpenAI compatibility.
12
11
  * OpenAI's structured output has strict requirements:
@@ -67,7 +66,7 @@ function zodTextFormat(zodObject, name) {
67
66
  return zodObject.parse(JSON.parse(content));
68
67
  }
69
68
  catch (error) {
70
- return new ZodValidationError(error instanceof Error ? error.message : String(error));
69
+ return new SchemaValidationError(error instanceof Error ? error.message : String(error), error);
71
70
  }
72
71
  },
73
72
  __output: undefined,
@@ -115,11 +114,15 @@ export class OpenAIProvider {
115
114
  }
116
115
  : null;
117
116
  if (response.output_parsed instanceof Error) {
117
+ const parseError = response.output_parsed;
118
+ const error = parseError instanceof SchemaValidationError
119
+ ? parseError
120
+ : new SchemaValidationError(parseError.message, parseError);
118
121
  return {
119
122
  parsed: null,
120
123
  text: response.output_text,
121
124
  usage,
122
- error: response.output_parsed,
125
+ error,
123
126
  };
124
127
  }
125
128
  return {
@@ -19,4 +19,5 @@ export type * from './models.schema.js';
19
19
  export type * from './seedKeyword.schema.js';
20
20
  export type * from './topics.schema.js';
21
21
  export type * from './summary.schema.js';
22
+ export type * from './prompt.schema.js';
22
23
  //# sourceMappingURL=index.d.ts.map
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphext/cuery",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "Cuery tools for AI-powered keyword research and brand analysis",
5
5
  "repository": {
6
6
  "type": "git",
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';
@@ -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;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c,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":"llm.d.ts","sourceRoot":"","sources":["../../src/src/llm.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,4CAA4C,CAAC;AACpE,OAAO,EAAuB,KAAK,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAGhH,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAG/G,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD;;GAEG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,MAAM;IACvC,2CAA2C;IAC3C,MAAM,EAAE,MAAM,GAAG,OAAO,EAAE,CAAC;IAC3B,kEAAkE;IAClE,KAAK,EAAE,MAAM,CAAC;IACd,gDAAgD;IAChD,MAAM,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAC7B,mCAAmC;IACnC,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,0CAA0C;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kE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,CAAC,EAAE,cAAc,CAAC;IACxB,0CAA0C;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kEAAkE;IAClE,OAAO,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;CAC7B;AAYD;;;GAGG;AACH,wBAAsB,UAAU,CAAC,CAAC,GAAG,MAAM,EAAE,EAC5C,MAAM,EACN,KAAK,EACL,MAAM,EACN,MAAM,EACN,UAAc,EACd,OAAiB,GACjB,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CA4C3C;AAED;;GAEG;AACH,wBAAsB,MAAM,CAAC,CAAC,GAAG,MAAM,EACtC,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,YAAY,GAAG,SAAS,CAAC,GACrD,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAEzB"}
package/script/src/llm.js CHANGED
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.calculateCost = void 0;
7
7
  exports.askLLMSafe = askLLMSafe;
8
8
  exports.askLLM = askLLM;
9
+ const errors_js_1 = require("./providers/errors.js");
9
10
  const index_js_1 = require("./providers/index.js");
10
11
  var index_js_2 = require("./providers/index.js");
11
12
  Object.defineProperty(exports, "calculateCost", { enumerable: true, get: function () { return index_js_2.calculateCost; } });
@@ -38,9 +39,9 @@ async function askLLMSafe({ prompt, model, schema, params, maxRetries = 3, onErr
38
39
  error: response.error ?? new Error('Unknown error'),
39
40
  };
40
41
  if (attempt < maxRetries && response.error) {
41
- // Add error context to messages for retry
42
- const errorMessage = `Previous attempt failed with error: ${response.error.message}`;
43
- if (response.text) {
42
+ let errorMessage;
43
+ if (response.error instanceof errors_js_1.SchemaValidationError) {
44
+ errorMessage = `Previous attempt failed with Zod parsing error:\n${response.error.message}.`;
44
45
  messages = [
45
46
  ...messages,
46
47
  {
@@ -49,7 +50,10 @@ async function askLLMSafe({ prompt, model, schema, params, maxRetries = 3, onErr
49
50
  },
50
51
  ];
51
52
  }
52
- console.log(`askLLMSafe retrying! Attempt ${attempt + 1} failed: ${response.error.message}`);
53
+ else {
54
+ errorMessage = `Previous attempt failed with error: ${response.error.message}`;
55
+ }
56
+ console.log(`askLLMSafe retrying! Attempt ${attempt + 1} failed with: ${errorMessage}`);
53
57
  }
54
58
  }
55
59
  if (onError === 'return') {
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Error indicating model output failed schema validation.
3
+ */
4
+ export declare class SchemaValidationError extends Error {
5
+ readonly cause?: unknown;
6
+ constructor(message: string, cause?: unknown);
7
+ }
8
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/src/providers/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;IAC/C,SAAkB,KAAK,CAAC,EAAE,OAAO,CAAC;gBAEtB,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAK5C"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SchemaValidationError = void 0;
4
+ /**
5
+ * Error indicating model output failed schema validation.
6
+ */
7
+ class SchemaValidationError extends Error {
8
+ cause;
9
+ constructor(message, cause) {
10
+ super(message);
11
+ this.name = 'SchemaValidationError';
12
+ this.cause = cause;
13
+ }
14
+ }
15
+ exports.SchemaValidationError = SchemaValidationError;
@@ -1 +1 @@
1
- {"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../../src/src/providers/google.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,CAAC,EAAE,MAAM,+CAA+C,CAAC;AAElE,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAuCpF;;GAEG;AACH,qBAAa,cAAe,YAAW,WAAW;IACjD,QAAQ,CAAC,IAAI,YAAY;IACzB,OAAO,CAAC,MAAM,CAAc;gBAEhB,MAAM,CAAC,EAAE,MAAM;IAUrB,QAAQ,CAAC,CAAC,EACf,QAAQ,EAAE,OAAO,EAAE,EACnB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,EAC3B,MAAM,CAAC,EAAE,cAAc,GACrB,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;CA8D1B"}
1
+ {"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../../src/src/providers/google.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,CAAC,EAAE,MAAM,+CAA+C,CAAC;AAGlE,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAuCpF;;GAEG;AACH,qBAAa,cAAe,YAAW,WAAW;IACjD,QAAQ,CAAC,IAAI,YAAY;IACzB,OAAO,CAAC,MAAM,CAAc;gBAEhB,MAAM,CAAC,EAAE,MAAM;IAUrB,QAAQ,CAAC,CAAC,EACf,QAAQ,EAAE,OAAO,EAAE,EACnB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,EAC3B,MAAM,CAAC,EAAE,cAAc,GACrB,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;CAiE1B"}
@@ -40,6 +40,7 @@ exports.GoogleProvider = void 0;
40
40
  const dntShim = __importStar(require("../../_dnt.shims.js"));
41
41
  const genai_1 = require("@google/genai");
42
42
  const index_js_1 = require("../../deps/jsr.io/@zod/zod/4.3.6/src/index.js");
43
+ const errors_js_1 = require("./errors.js");
43
44
  /**
44
45
  * Convert messages to Gemini content format.
45
46
  * Handles system prompts by prepending them as context.
@@ -124,7 +125,7 @@ class GoogleProvider {
124
125
  parsed: null,
125
126
  text,
126
127
  usage,
127
- error: error instanceof Error ? error : new Error(String(error)),
128
+ error: new errors_js_1.SchemaValidationError(error instanceof Error ? error.message : String(error), error),
128
129
  };
129
130
  }
130
131
  }
@@ -8,6 +8,7 @@
8
8
  export { getProvider, getProviderForModel } from './registry.js';
9
9
  export { OpenAIProvider } from './openai.js';
10
10
  export { GoogleProvider } from './google.js';
11
+ export { SchemaValidationError } from './errors.js';
11
12
  export { getModelPricing, getModelInfo, calculateCost, type ModelPricing, type ModelInfo, } from './pricing.js';
12
13
  export type { Message, LLMResponse, LLMProvider, ProviderParams, LLMConversation, } from './types.js';
13
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/providers/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAGjE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG7C,OAAO,EACN,eAAe,EACf,YAAY,EACZ,aAAa,EACb,KAAK,YAAY,EACjB,KAAK,SAAS,GACd,MAAM,cAAc,CAAC;AAGtB,YAAY,EACX,OAAO,EACP,WAAW,EACX,WAAW,EACX,cAAc,EACd,eAAe,GACf,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/providers/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAGjE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAGpD,OAAO,EACN,eAAe,EACf,YAAY,EACZ,aAAa,EACb,KAAK,YAAY,EACjB,KAAK,SAAS,GACd,MAAM,cAAc,CAAC;AAGtB,YAAY,EACX,OAAO,EACP,WAAW,EACX,WAAW,EACX,cAAc,EACd,eAAe,GACf,MAAM,YAAY,CAAC"}
@@ -7,7 +7,7 @@
7
7
  * - Cost calculation utilities
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.calculateCost = exports.getModelInfo = exports.getModelPricing = exports.GoogleProvider = exports.OpenAIProvider = exports.getProviderForModel = exports.getProvider = void 0;
10
+ exports.calculateCost = exports.getModelInfo = exports.getModelPricing = exports.SchemaValidationError = exports.GoogleProvider = exports.OpenAIProvider = exports.getProviderForModel = exports.getProvider = void 0;
11
11
  // Re-export provider registry functions
12
12
  var registry_js_1 = require("./registry.js");
13
13
  Object.defineProperty(exports, "getProvider", { enumerable: true, get: function () { return registry_js_1.getProvider; } });
@@ -17,6 +17,8 @@ var openai_js_1 = require("./openai.js");
17
17
  Object.defineProperty(exports, "OpenAIProvider", { enumerable: true, get: function () { return openai_js_1.OpenAIProvider; } });
18
18
  var google_js_1 = require("./google.js");
19
19
  Object.defineProperty(exports, "GoogleProvider", { enumerable: true, get: function () { return google_js_1.GoogleProvider; } });
20
+ var errors_js_1 = require("./errors.js");
21
+ Object.defineProperty(exports, "SchemaValidationError", { enumerable: true, get: function () { return errors_js_1.SchemaValidationError; } });
20
22
  // Re-export pricing utilities
21
23
  var pricing_js_1 = require("./pricing.js");
22
24
  Object.defineProperty(exports, "getModelPricing", { enumerable: true, get: function () { return pricing_js_1.getModelPricing; } });
@@ -1 +1 @@
1
- {"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../src/src/providers/openai.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,CAAC,EAAE,MAAM,+CAA+C,CAAC;AAElE,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAyFpF;;GAEG;AACH,qBAAa,cAAe,YAAW,WAAW;IACjD,QAAQ,CAAC,IAAI,YAAY;IACzB,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,CAAC,EAAE,MAAM;IAarB,QAAQ,CAAC,CAAC,EACf,QAAQ,EAAE,OAAO,EAAE,EACnB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,EAC3B,MAAM,CAAC,EAAE,cAAc,GACrB,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;CAkD1B"}
1
+ {"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../src/src/providers/openai.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,CAAC,EAAE,MAAM,+CAA+C,CAAC;AAGlE,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AA0FpF;;GAEG;AACH,qBAAa,cAAe,YAAW,WAAW;IACjD,QAAQ,CAAC,IAAI,YAAY;IACzB,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,CAAC,EAAE,MAAM;IAarB,QAAQ,CAAC,CAAC,EACf,QAAQ,EAAE,OAAO,EAAE,EACnB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,EAC3B,MAAM,CAAC,EAAE,cAAc,GACrB,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;CAuD1B"}
@@ -43,9 +43,8 @@ exports.OpenAIProvider = void 0;
43
43
  const dntShim = __importStar(require("../../_dnt.shims.js"));
44
44
  const openai_1 = __importDefault(require("openai"));
45
45
  const index_js_1 = require("../../deps/jsr.io/@zod/zod/4.3.6/src/index.js");
46
+ const errors_js_1 = require("./errors.js");
46
47
  const zodTextFormatCache = new Map();
47
- class ZodValidationError extends Error {
48
- }
49
48
  /**
50
49
  * Sanitizes a JSON schema for OpenAI compatibility.
51
50
  * OpenAI's structured output has strict requirements:
@@ -106,7 +105,7 @@ function zodTextFormat(zodObject, name) {
106
105
  return zodObject.parse(JSON.parse(content));
107
106
  }
108
107
  catch (error) {
109
- return new ZodValidationError(error instanceof Error ? error.message : String(error));
108
+ return new errors_js_1.SchemaValidationError(error instanceof Error ? error.message : String(error), error);
110
109
  }
111
110
  },
112
111
  __output: undefined,
@@ -154,11 +153,15 @@ class OpenAIProvider {
154
153
  }
155
154
  : null;
156
155
  if (response.output_parsed instanceof Error) {
156
+ const parseError = response.output_parsed;
157
+ const error = parseError instanceof errors_js_1.SchemaValidationError
158
+ ? parseError
159
+ : new errors_js_1.SchemaValidationError(parseError.message, parseError);
157
160
  return {
158
161
  parsed: null,
159
162
  text: response.output_text,
160
163
  usage,
161
- error: response.output_parsed,
164
+ error,
162
165
  };
163
166
  }
164
167
  return {
@@ -19,4 +19,5 @@ export type * from './models.schema.js';
19
19
  export type * from './seedKeyword.schema.js';
20
20
  export type * from './topics.schema.js';
21
21
  export type * from './summary.schema.js';
22
+ export type * from './prompt.schema.js';
22
23
  //# sourceMappingURL=index.d.ts.map
@@ -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; } });