@future-explorer/lib 1.0.10 → 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,10 +87,9 @@ const SentimentSchema = z.object({
87
87
  });
88
88
 
89
89
  // Generate structured response
90
- const result = await client.generateStructuredResponse({
91
- schema: SentimentSchema,
92
- userPrompt: 'I absolutely love this product!',
93
- systemMessage: 'You are a sentiment analysis expert.',
90
+ const result = await client.generateStructuredResponse(SentimentSchema, {
91
+ prompt: 'I absolutely love this product!',
92
+ system: 'You are a sentiment analysis expert.',
94
93
  });
95
94
 
96
95
  console.log(result.sentiment); // 'positive'
@@ -108,7 +107,7 @@ console.log(result.summary); // '...'
108
107
 
109
108
  ### Methods
110
109
 
111
- - `generateStructuredResponse<T>(params: GenerateObjectParams<T>)`: Generates a structured response matching the Zod schema. Accepts `schema`, `userPrompt`, `systemMessage`, plus any additional `generateObject()` options
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,4 +1,5 @@
1
1
  import { LanguageModel } from 'ai';
2
+ import { ZodSchema } from 'zod';
2
3
  import { GenerateObjectParams, Provider } from './unified-ai-client.model';
3
4
  /**
4
5
  * Unified AI Client that supports multiple AI providers (OpenAI, XAI, Gemini)
@@ -12,8 +13,10 @@ export declare class UnifiedAiClient {
12
13
  *
13
14
  * @template T - The type inferred from the Zod schema
14
15
  *
15
- * @param params - Configuration object for the structured response generation.
16
- * See {@link GenerateObjectParams} for all available options.
16
+ * @param schema - Zod schema defining the expected response structure.
17
+ * The AI model will be constrained to return data matching this schema.
18
+ * @param params - Configuration object with prompt, system message, and any additional options.
19
+ * See {@link GenerateObjectParams} for all available options.
17
20
  *
18
21
  * @returns Promise resolving to the validated object matching the schema type T
19
22
  *
@@ -29,16 +32,15 @@ export declare class UnifiedAiClient {
29
32
  * });
30
33
  *
31
34
  * // Generate structured response
32
- * const result = await service.generateStructuredResponse({
33
- * schema: SentimentSchema,
34
- * userPrompt: 'I absolutely love this product!',
35
- * systemMessage: 'You are a sentiment analysis expert. Be precise with confidence scores.',
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.',
36
38
  * });
37
39
  *
38
40
  * console.log(result.sentiment); // 'positive'
39
41
  * console.log(result.confidence); // 0.95
40
42
  */
41
- generateStructuredResponse<T>(params: GenerateObjectParams<T>): Promise<T>;
43
+ generateStructuredResponse<T>(schema: ZodSchema<T>, params: GenerateObjectParams<T>): Promise<T>;
42
44
  /**
43
45
  * Retrieves the underlying LanguageModel instance.
44
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,oBAAoB,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAE3E;;;GAGG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,KAAK,CAAgB;gBAEjB,QAAQ,EAAE,QAAQ;IAI9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACG,0BAA0B,CAAC,CAAC,EAAE,MAAM,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAchF;;;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"}
@@ -20,8 +20,10 @@ class UnifiedAiClient {
20
20
  *
21
21
  * @template T - The type inferred from the Zod schema
22
22
  *
23
- * @param params - Configuration object for the structured response generation.
24
- * See {@link GenerateObjectParams} for all available options.
23
+ * @param schema - Zod schema defining the expected response structure.
24
+ * The AI model will be constrained to return data matching this schema.
25
+ * @param params - Configuration object with prompt, system message, and any additional options.
26
+ * See {@link GenerateObjectParams} for all available options.
25
27
  *
26
28
  * @returns Promise resolving to the validated object matching the schema type T
27
29
  *
@@ -37,23 +39,22 @@ class UnifiedAiClient {
37
39
  * });
38
40
  *
39
41
  * // Generate structured response
40
- * const result = await service.generateStructuredResponse({
41
- * schema: SentimentSchema,
42
- * userPrompt: 'I absolutely love this product!',
43
- * systemMessage: 'You are a sentiment analysis expert. Be precise with confidence scores.',
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.',
44
45
  * });
45
46
  *
46
47
  * console.log(result.sentiment); // 'positive'
47
48
  * console.log(result.confidence); // 0.95
48
49
  */
49
- async generateStructuredResponse(params) {
50
- const { schema, userPrompt, systemMessage, ...rest } = params;
50
+ async generateStructuredResponse(schema, params) {
51
+ const { prompt, system, ...rest } = params;
51
52
  const result = await (0, ai_1.generateObject)({
52
53
  ...rest,
53
54
  model: this.model,
54
55
  schema: schema, // Option 2: Use jsonSchema instead of Zod directly: schema: jsonSchema<T>(zodToJsonSchema(schema) as any),
55
- prompt: userPrompt,
56
- system: systemMessage,
56
+ prompt: prompt,
57
+ system: system,
57
58
  });
58
59
  return result.object;
59
60
  }
@@ -1,21 +1,19 @@
1
- import { generateObject } from 'ai';
2
- import { ZodSchema } from 'zod';
3
1
  /**
4
2
  * Options for generating a structured response from the AI model.
5
3
  *
6
- * @template T - The type inferred from the Zod schema
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
7
  *
8
- * Includes the core params (schema, userPrompt, systemMessage) plus
9
- * any additional options supported by the underlying `generateObject()` call
10
- * (e.g. mode, schemaName, schemaDescription, maxTokens, temperature, etc.).
8
+ * Note: The Zod `schema` is passed as a separate argument to `generateStructuredResponse()`.
11
9
  */
12
- export interface GenerateObjectParams<T> extends Omit<Parameters<typeof generateObject>[0], 'model' | 'schema' | 'prompt' | 'system' | 'messages'> {
13
- /** Zod schema defining the expected response structure. */
14
- schema: ZodSchema<T>;
10
+ export interface GenerateObjectParams<T> {
15
11
  /** User input/message to send to the AI model (role: user). */
16
- userPrompt: string;
12
+ prompt: string;
17
13
  /** Optional system instructions that define the AI's behavior, persona, and task context (role: system). */
18
- systemMessage?: string;
14
+ system?: string;
15
+ /** Any additional options are passed through to the underlying AI call. */
16
+ [key: string]: unknown;
19
17
  }
20
18
  /**
21
19
  * Enum representing supported AI providers.
@@ -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,OAAO,EAAE,cAAc,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAEhC;;;;;;;;GAQG;AACH,MAAM,WAAW,oBAAoB,CAAC,CAAC,CACrC,SAAQ,IAAI,CACV,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,EACpC,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,UAAU,CACtD;IACD,2DAA2D;IAC3D,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IACrB,+DAA+D;IAC/D,UAAU,EAAE,MAAM,CAAC;IACnB,4GAA4G;IAC5G,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;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.10",
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
  }