@future-explorer/lib 1.0.9 → 1.0.11

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/README.md CHANGED
@@ -87,11 +87,10 @@ const SentimentSchema = z.object({
87
87
  });
88
88
 
89
89
  // Generate structured response
90
- const result = await client.generateStructuredResponse(
91
- SentimentSchema,
92
- 'I absolutely love this product!',
93
- 'You are a sentiment analysis expert.'
94
- );
90
+ const result = await client.generateStructuredResponse(SentimentSchema, {
91
+ prompt: 'I absolutely love this product!',
92
+ system: 'You are a sentiment analysis expert.',
93
+ });
95
94
 
96
95
  console.log(result.sentiment); // 'positive'
97
96
  console.log(result.confidence); // 0.95
@@ -108,7 +107,7 @@ console.log(result.summary); // '...'
108
107
 
109
108
  ### Methods
110
109
 
111
- - `generateStructuredResponse<T>(schema, userPrompt, systemMessage?)`: Generates a structured response matching the Zod schema
110
+ - `generateStructuredResponse<T>(schema: ZodSchema<T>, params: GenerateObjectParams<T>)`: Generates a structured response matching the Zod schema. Accepts `prompt`, `system`, plus any additional options
112
111
  - `getModel()`: Returns the underlying LanguageModel instance
113
112
 
114
113
  ## Development
@@ -1,6 +1,6 @@
1
1
  import { LanguageModel } from 'ai';
2
2
  import { ZodSchema } from 'zod';
3
- import { Provider } from './unified-ai-client.model';
3
+ import { GenerateObjectParams, Provider } from './unified-ai-client.model';
4
4
  /**
5
5
  * Unified AI Client that supports multiple AI providers (OpenAI, XAI, Gemini)
6
6
  * and allows generating structured responses based on Zod schemas.
@@ -15,9 +15,8 @@ export declare class UnifiedAiClient {
15
15
  *
16
16
  * @param schema - Zod schema defining the expected response structure.
17
17
  * The AI model will be constrained to return data matching this schema.
18
- * @param prompt - User input/message to send to the AI model (role: user)
19
- * @param system - Optional system instructions that define the AI's behavior,
20
- * persona, and task context (role: system)
18
+ * @param params - Configuration object with prompt, system message, and any additional options.
19
+ * See {@link GenerateObjectParams} for all available options.
21
20
  *
22
21
  * @returns Promise resolving to the validated object matching the schema type T
23
22
  *
@@ -33,16 +32,15 @@ export declare class UnifiedAiClient {
33
32
  * });
34
33
  *
35
34
  * // Generate structured response
36
- * const result = await service.generateStructuredResponse(
37
- * SentimentSchema,
38
- * 'I absolutely love this product!',
39
- * 'You are a sentiment analysis expert. Be precise with confidence scores.'
40
- * );
35
+ * const result = await service.generateStructuredResponse(SentimentSchema, {
36
+ * prompt: 'I absolutely love this product!',
37
+ * system: 'You are a sentiment analysis expert. Be precise with confidence scores.',
38
+ * });
41
39
  *
42
40
  * console.log(result.sentiment); // 'positive'
43
41
  * console.log(result.confidence); // 0.95
44
42
  */
45
- generateStructuredResponse<T>(schema: ZodSchema<T>, userPrompt: string, systemMessage?: string): Promise<T>;
43
+ generateStructuredResponse<T>(schema: ZodSchema<T>, params: GenerateObjectParams<T>): Promise<T>;
46
44
  /**
47
45
  * Retrieves the underlying LanguageModel instance.
48
46
  * @returns The LanguageModel instance used by the UnifiedAiClient.
@@ -1 +1 @@
1
- {"version":3,"file":"unified-ai-client.d.ts","sourceRoot":"","sources":["../../../../src/clients/ai/unified/unified-ai-client.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,aAAa,EAAE,MAAM,IAAI,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAErD;;;GAGG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,KAAK,CAAgB;gBAEjB,QAAQ,EAAE,QAAQ;IAI9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACG,0BAA0B,CAAC,CAAC,EAChC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,EACpB,UAAU,EAAE,MAAM,EAClB,aAAa,CAAC,EAAE,MAAM,GACrB,OAAO,CAAC,CAAC,CAAC;IAWb;;;OAGG;IACH,QAAQ,IAAI,aAAa;IAIzB,OAAO,CAAC,WAAW;CAYpB"}
1
+ {"version":3,"file":"unified-ai-client.d.ts","sourceRoot":"","sources":["../../../../src/clients/ai/unified/unified-ai-client.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,aAAa,EAAE,MAAM,IAAI,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAChC,OAAO,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAE3E;;;GAGG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,KAAK,CAAgB;gBAEjB,QAAQ,EAAE,QAAQ;IAI9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACG,0BAA0B,CAAC,CAAC,EAChC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,EACpB,MAAM,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAC9B,OAAO,CAAC,CAAC,CAAC;IAcb;;;OAGG;IACH,QAAQ,IAAI,aAAa;IAIzB,OAAO,CAAC,WAAW;CAYpB"}
@@ -22,9 +22,8 @@ class UnifiedAiClient {
22
22
  *
23
23
  * @param schema - Zod schema defining the expected response structure.
24
24
  * The AI model will be constrained to return data matching this schema.
25
- * @param prompt - User input/message to send to the AI model (role: user)
26
- * @param system - Optional system instructions that define the AI's behavior,
27
- * persona, and task context (role: system)
25
+ * @param params - Configuration object with prompt, system message, and any additional options.
26
+ * See {@link GenerateObjectParams} for all available options.
28
27
  *
29
28
  * @returns Promise resolving to the validated object matching the schema type T
30
29
  *
@@ -40,21 +39,22 @@ class UnifiedAiClient {
40
39
  * });
41
40
  *
42
41
  * // Generate structured response
43
- * const result = await service.generateStructuredResponse(
44
- * SentimentSchema,
45
- * 'I absolutely love this product!',
46
- * 'You are a sentiment analysis expert. Be precise with confidence scores.'
47
- * );
42
+ * const result = await service.generateStructuredResponse(SentimentSchema, {
43
+ * prompt: 'I absolutely love this product!',
44
+ * system: 'You are a sentiment analysis expert. Be precise with confidence scores.',
45
+ * });
48
46
  *
49
47
  * console.log(result.sentiment); // 'positive'
50
48
  * console.log(result.confidence); // 0.95
51
49
  */
52
- async generateStructuredResponse(schema, userPrompt, systemMessage) {
50
+ async generateStructuredResponse(schema, params) {
51
+ const { prompt, system, ...rest } = params;
53
52
  const result = await (0, ai_1.generateObject)({
53
+ ...rest,
54
54
  model: this.model,
55
55
  schema: schema, // Option 2: Use jsonSchema instead of Zod directly: schema: jsonSchema<T>(zodToJsonSchema(schema) as any),
56
- prompt: userPrompt,
57
- system: systemMessage,
56
+ prompt: prompt,
57
+ system: system,
58
58
  });
59
59
  return result.object;
60
60
  }
@@ -1,3 +1,20 @@
1
+ /**
2
+ * Options for generating a structured response from the AI model.
3
+ *
4
+ * Includes the core params (`prompt`, `system`) plus any additional options
5
+ * (e.g. `mode`, `schemaName`, `schemaDescription`, `maxTokens`, `temperature`, etc.).
6
+ * Extra properties are passed through as-is.
7
+ *
8
+ * Note: The Zod `schema` is passed as a separate argument to `generateStructuredResponse()`.
9
+ */
10
+ export interface GenerateObjectParams<T> {
11
+ /** User input/message to send to the AI model (role: user). */
12
+ prompt: string;
13
+ /** Optional system instructions that define the AI's behavior, persona, and task context (role: system). */
14
+ system?: string;
15
+ /** Any additional options are passed through to the underlying AI call. */
16
+ [key: string]: unknown;
17
+ }
1
18
  /**
2
19
  * Enum representing supported AI providers.
3
20
  */
@@ -1 +1 @@
1
- {"version":3,"file":"unified-ai-client.model.d.ts","sourceRoot":"","sources":["../../../../src/clients/ai/unified/unified-ai-client.model.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,QAAQ;IAClB;;OAEG;IACH,MAAM,WAAW;IACjB;;OAEG;IACH,GAAG,QAAQ;IACX;;OAEG;IACH,MAAM,WAAW;CAClB"}
1
+ {"version":3,"file":"unified-ai-client.model.d.ts","sourceRoot":"","sources":["../../../../src/clients/ai/unified/unified-ai-client.model.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,WAAW,oBAAoB,CAAC,CAAC;IACrC,+DAA+D;IAC/D,MAAM,EAAE,MAAM,CAAC;IACf,4GAA4G;IAC5G,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2EAA2E;IAC3E,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,oBAAY,QAAQ;IAClB;;OAEG;IACH,MAAM,WAAW;IACjB;;OAEG;IACH,GAAG,QAAQ;IACX;;OAEG;IACH,MAAM,WAAW;CAClB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@future-explorer/lib",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "Shared utilities and clients for Future Explorer projects",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -52,14 +52,17 @@
52
52
  "zod": "^4.2.0"
53
53
  },
54
54
  "devDependencies": {
55
- "@types/node": "^24.5.2",
55
+ "@types/node": "^24.10.12",
56
56
  "@typescript-eslint/eslint-plugin": "^8.0.0",
57
57
  "@typescript-eslint/parser": "^8.0.0",
58
+ "dotenv": "^17.2.4",
58
59
  "eslint": "^9.20.1",
59
60
  "eslint-config-prettier": "^10.0.1",
60
61
  "eslint-plugin-prettier": "^5.2.3",
61
62
  "prettier": "^3.5.1",
62
63
  "rimraf": "^6.0.1",
63
- "typescript": "^5.6.3"
64
+ "ts-node": "^10.9.2",
65
+ "typescript": "^5.6.3",
66
+ "zod": "4.2.0"
64
67
  }
65
68
  }