@stackfactor/agent-utils 1.0.22 → 1.0.23

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
@@ -62,32 +62,6 @@ const result = await langChain.runPromptWithModel(
62
62
 
63
63
  ---
64
64
 
65
- ### `langChain.runChatPromptWithModel(modelName, config, prompt, onProgressReport?)`
66
-
67
- Sends a conversational chat prompt to an LLM and returns a plain HTML response. Built for the StackFactor Mentor chat feature — system messages are wrapped with topic-constraint instructions that decline off-topic questions.
68
-
69
- | Parameter | Type | Default | Description |
70
- | ------------------ | -------------------- | ------- | ----------------------------------------------------- |
71
- | `modelName` | `string` | — | Model identifier |
72
- | `config` | `object` | — | API keys and optional `temperature` |
73
- | `prompt` | `string \| object[]` | — | Plain string or array of `{ role, content }` messages |
74
- | `onProgressReport` | `function \| null` | `null` | Streaming progress callback |
75
-
76
- **Returns:** Raw HTML string.
77
-
78
- ```typescript
79
- const html = await langChain.runChatPromptWithModel(
80
- "claude-3-5-sonnet",
81
- { anthropicAPIKey: "sk-ant-..." },
82
- [
83
- { role: "system", content: "Topic: JavaScript closures" },
84
- { role: "user", content: "Explain closures with an example" },
85
- ],
86
- );
87
- ```
88
-
89
- ---
90
-
91
65
  ### `langChain.createAIAgent(name, modelName, systemPrompt, tools?, responseFormat?, config, onReportProgress?, minPercent?, maxPercent?)`
92
66
 
93
67
  Constructs a LangChain agent with a model, system prompt, and tools. When `onReportProgress` is provided, a `report_progress` tool is automatically added.
@@ -1,7 +1,7 @@
1
1
  declare const _default: {
2
+ checkIfAIProviderConfigured: (config: any) => void;
2
3
  createAgent: (name: string, modelName: string, systemPrompt: string, tools: any[], responseFormat: any, config: any) => any;
3
4
  runAgent: (agent: any, prompt: string, config: any, onProgress?: Function | null) => Promise<any>;
4
- runChatPromptWithModel: (modelName: string, config: any, prompt: any, onProgressReport: any) => any;
5
5
  runPromptWithModel: (modelName: string, config: any, prompt: any, onProgressReport: any, minPercent?: number, maxPercent?: number, expectsJsonResponse?: boolean, schema?: any, agentName?: string, tools?: any[]) => Promise<any>;
6
6
  runPromptWithModelForImageGeneration: (modelName: string, config: any, prompt: string, options?: any) => Promise<any>;
7
7
  throwErrorIfNotSuccessful: (response: any) => string;
@@ -1 +1 @@
1
- {"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":";wBAogBQ,MAAM,aACD,MAAM,gBACH,MAAM,SACb,GAAG,EAAE,kBACI,GAAG,UACX,GAAG,KACV,GAAG;sBAyBG,GAAG,UACF,MAAM,UACN,GAAG,eACC,QAAQ,GAAG,IAAI,KAC1B,OAAO,CAAC,GAAG,CAAC;wCA2xBF,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,KACpB,GAAG;oCA1bO,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,eACT,MAAM,eACN,MAAM,wBACG,OAAO,WACpB,GAAG,cACA,MAAM,UACV,GAAG,EAAE,KACX,OAAO,CAAC,GAAG,CAAC;sDAsvBF,MAAM,UACT,GAAG,UACH,MAAM,YACL,GAAG,KACX,OAAO,CAAC,GAAG,CAAC;0CAngC8B,GAAG,KAAG,MAAM;;AA8jCzD,wBAOE"}
1
+ {"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":";0CAgD6C,GAAG,KAAG,IAAI;wBAke/C,MAAM,aACD,MAAM,gBACH,MAAM,SACb,GAAG,EAAE,kBACI,GAAG,UACX,GAAG,KACV,GAAG;sBAyBG,GAAG,UACF,MAAM,UACN,GAAG,eACC,QAAQ,GAAG,IAAI,KAC1B,OAAO,CAAC,GAAG,CAAC;oCAqWF,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,eACT,MAAM,eACN,MAAM,wBACG,OAAO,WACpB,GAAG,cACA,MAAM,UACV,GAAG,EAAE,KACX,OAAO,CAAC,GAAG,CAAC;sDA6rBF,MAAM,UACT,GAAG,UACH,MAAM,YACL,GAAG,KACX,OAAO,CAAC,GAAG,CAAC;0CA18B8B,GAAG,KAAG,MAAM;;AAqgCzD,wBAOE"}
@@ -36,6 +36,14 @@ const assertQuotaAvailable = () => {
36
36
  throw errorHandling_js_1.default.create(const_js_1.default.HTTP_CODES.PAYMENT_REQUIRED, const_js_1.default.ERROR.QUOTA_EXHAUSTED);
37
37
  }
38
38
  };
39
+ const checkIfAIProviderConfigured = (config) => {
40
+ if (!config ||
41
+ !config.openAIAPIKey ||
42
+ !config.googleAPIKey ||
43
+ !config.anthropicAPIKey) {
44
+ throw errorHandling_js_1.default.create(const_js_1.default.HTTP_CODES.INTERNAL_SERVER_ERROR, "The integration is not properly configured with all AI providers.");
45
+ }
46
+ };
39
47
  /**
40
48
  * Subtracts the given USD cost from `global.quota.remaining` and adds it to
41
49
  * `global.quota.usedThisSession`. Silently no-ops when the quota globals are not
@@ -1137,47 +1145,6 @@ const runPromptWithModel = async (modelName, config, prompt, onProgressReport, m
1137
1145
  }
1138
1146
  }
1139
1147
  };
1140
- /**
1141
- * Sends a conversational chat prompt to an LLM and returns a plain HTML response
1142
- * intended for end-user display. This function is purpose-built for the StackFactor
1143
- * Mentor chat feature: when the prompt is an array of messages, each `system` message
1144
- * is wrapped in an enhanced system prompt that instructs the model to answer only
1145
- * questions related to the provided topic, decline off-topic questions, and return
1146
- * results as simple HTML without markdown code-block notation. The call is delegated to
1147
- * `runPromptWithModel` with `expectsJsonResponse` set to `false`.
1148
- * @param modelName - The model identifier, e.g. `"gpt-4o"`, `"claude-3-5-sonnet"`
1149
- * @param config - Configuration object with API keys and optional `temperature`
1150
- * @param prompt - A plain string user message, or an array of `{ role, content }`
1151
- * message objects; `system` messages have the topic-constraint wrapper applied
1152
- * @param onProgressReport - Optional callback for streaming progress updates passed
1153
- * through to `runPromptWithModel`
1154
- * @returns The model's response as a raw HTML string
1155
- */
1156
- const runChatPromptWithModel = (modelName, config, prompt, onProgressReport) => {
1157
- let messages = prompt;
1158
- // If prompt is an array, check for system message and enhance it
1159
- if (Array.isArray(prompt)) {
1160
- messages = prompt.map((msg) => {
1161
- if (msg.role === "system") {
1162
- return {
1163
- ...msg,
1164
- content: `You are StackFactor Mentor, an AI assistant that helps users by providing information related to the specified topic.
1165
-
1166
- ### Objective:
1167
- Respond to the user question considering just related to the selected topic and all previous interactions:
1168
- - If the question is unrelated decline to respond.
1169
- - Return the results as a simple HMTL but don't include notations for formatting blocks.
1170
-
1171
- ### TOPIC INFORMATION:\n
1172
- ${msg.content}
1173
- `,
1174
- };
1175
- }
1176
- return msg;
1177
- });
1178
- }
1179
- return runPromptWithModel(modelName, config, messages, onProgressReport, 0, 100, false);
1180
- };
1181
1148
  /**
1182
1149
  * Determines the image generation provider for a given model name based on its prefix.
1183
1150
  * `dall-e-` and `gpt-image-` prefixes map to `"openai"`. `gemini-` and `imagen-`
@@ -1439,9 +1406,9 @@ const runPromptWithModelForImageGeneration = async (modelName, config, prompt, o
1439
1406
  }
1440
1407
  };
1441
1408
  exports.default = {
1409
+ checkIfAIProviderConfigured,
1442
1410
  createAgent,
1443
1411
  runAgent,
1444
- runChatPromptWithModel,
1445
1412
  runPromptWithModel,
1446
1413
  runPromptWithModelForImageGeneration,
1447
1414
  throwErrorIfNotSuccessful,
@@ -1,7 +1,7 @@
1
1
  declare const _default: {
2
+ checkIfAIProviderConfigured: (config: any) => void;
2
3
  createAgent: (name: string, modelName: string, systemPrompt: string, tools: any[], responseFormat: any, config: any) => any;
3
4
  runAgent: (agent: any, prompt: string, config: any, onProgress?: Function | null) => Promise<any>;
4
- runChatPromptWithModel: (modelName: string, config: any, prompt: any, onProgressReport: any) => any;
5
5
  runPromptWithModel: (modelName: string, config: any, prompt: any, onProgressReport: any, minPercent?: number, maxPercent?: number, expectsJsonResponse?: boolean, schema?: any, agentName?: string, tools?: any[]) => Promise<any>;
6
6
  runPromptWithModelForImageGeneration: (modelName: string, config: any, prompt: string, options?: any) => Promise<any>;
7
7
  throwErrorIfNotSuccessful: (response: any) => string;
@@ -1 +1 @@
1
- {"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":";wBAogBQ,MAAM,aACD,MAAM,gBACH,MAAM,SACb,GAAG,EAAE,kBACI,GAAG,UACX,GAAG,KACV,GAAG;sBAyBG,GAAG,UACF,MAAM,UACN,GAAG,eACC,QAAQ,GAAG,IAAI,KAC1B,OAAO,CAAC,GAAG,CAAC;wCA2xBF,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,KACpB,GAAG;oCA1bO,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,eACT,MAAM,eACN,MAAM,wBACG,OAAO,WACpB,GAAG,cACA,MAAM,UACV,GAAG,EAAE,KACX,OAAO,CAAC,GAAG,CAAC;sDAsvBF,MAAM,UACT,GAAG,UACH,MAAM,YACL,GAAG,KACX,OAAO,CAAC,GAAG,CAAC;0CAngC8B,GAAG,KAAG,MAAM;;AA8jCzD,wBAOE"}
1
+ {"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":";0CAgD6C,GAAG,KAAG,IAAI;wBAke/C,MAAM,aACD,MAAM,gBACH,MAAM,SACb,GAAG,EAAE,kBACI,GAAG,UACX,GAAG,KACV,GAAG;sBAyBG,GAAG,UACF,MAAM,UACN,GAAG,eACC,QAAQ,GAAG,IAAI,KAC1B,OAAO,CAAC,GAAG,CAAC;oCAqWF,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,eACT,MAAM,eACN,MAAM,wBACG,OAAO,WACpB,GAAG,cACA,MAAM,UACV,GAAG,EAAE,KACX,OAAO,CAAC,GAAG,CAAC;sDA6rBF,MAAM,UACT,GAAG,UACH,MAAM,YACL,GAAG,KACX,OAAO,CAAC,GAAG,CAAC;0CA18B8B,GAAG,KAAG,MAAM;;AAqgCzD,wBAOE"}
@@ -31,6 +31,14 @@ const assertQuotaAvailable = () => {
31
31
  throw errorHandlingHelper.create(constants.HTTP_CODES.PAYMENT_REQUIRED, constants.ERROR.QUOTA_EXHAUSTED);
32
32
  }
33
33
  };
34
+ const checkIfAIProviderConfigured = (config) => {
35
+ if (!config ||
36
+ !config.openAIAPIKey ||
37
+ !config.googleAPIKey ||
38
+ !config.anthropicAPIKey) {
39
+ throw errorHandlingHelper.create(constants.HTTP_CODES.INTERNAL_SERVER_ERROR, "The integration is not properly configured with all AI providers.");
40
+ }
41
+ };
34
42
  /**
35
43
  * Subtracts the given USD cost from `global.quota.remaining` and adds it to
36
44
  * `global.quota.usedThisSession`. Silently no-ops when the quota globals are not
@@ -1132,47 +1140,6 @@ const runPromptWithModel = async (modelName, config, prompt, onProgressReport, m
1132
1140
  }
1133
1141
  }
1134
1142
  };
1135
- /**
1136
- * Sends a conversational chat prompt to an LLM and returns a plain HTML response
1137
- * intended for end-user display. This function is purpose-built for the StackFactor
1138
- * Mentor chat feature: when the prompt is an array of messages, each `system` message
1139
- * is wrapped in an enhanced system prompt that instructs the model to answer only
1140
- * questions related to the provided topic, decline off-topic questions, and return
1141
- * results as simple HTML without markdown code-block notation. The call is delegated to
1142
- * `runPromptWithModel` with `expectsJsonResponse` set to `false`.
1143
- * @param modelName - The model identifier, e.g. `"gpt-4o"`, `"claude-3-5-sonnet"`
1144
- * @param config - Configuration object with API keys and optional `temperature`
1145
- * @param prompt - A plain string user message, or an array of `{ role, content }`
1146
- * message objects; `system` messages have the topic-constraint wrapper applied
1147
- * @param onProgressReport - Optional callback for streaming progress updates passed
1148
- * through to `runPromptWithModel`
1149
- * @returns The model's response as a raw HTML string
1150
- */
1151
- const runChatPromptWithModel = (modelName, config, prompt, onProgressReport) => {
1152
- let messages = prompt;
1153
- // If prompt is an array, check for system message and enhance it
1154
- if (Array.isArray(prompt)) {
1155
- messages = prompt.map((msg) => {
1156
- if (msg.role === "system") {
1157
- return {
1158
- ...msg,
1159
- content: `You are StackFactor Mentor, an AI assistant that helps users by providing information related to the specified topic.
1160
-
1161
- ### Objective:
1162
- Respond to the user question considering just related to the selected topic and all previous interactions:
1163
- - If the question is unrelated decline to respond.
1164
- - Return the results as a simple HMTL but don't include notations for formatting blocks.
1165
-
1166
- ### TOPIC INFORMATION:\n
1167
- ${msg.content}
1168
- `,
1169
- };
1170
- }
1171
- return msg;
1172
- });
1173
- }
1174
- return runPromptWithModel(modelName, config, messages, onProgressReport, 0, 100, false);
1175
- };
1176
1143
  /**
1177
1144
  * Determines the image generation provider for a given model name based on its prefix.
1178
1145
  * `dall-e-` and `gpt-image-` prefixes map to `"openai"`. `gemini-` and `imagen-`
@@ -1434,9 +1401,9 @@ const runPromptWithModelForImageGeneration = async (modelName, config, prompt, o
1434
1401
  }
1435
1402
  };
1436
1403
  export default {
1404
+ checkIfAIProviderConfigured,
1437
1405
  createAgent,
1438
1406
  runAgent,
1439
- runChatPromptWithModel,
1440
1407
  runPromptWithModel,
1441
1408
  runPromptWithModelForImageGeneration,
1442
1409
  throwErrorIfNotSuccessful,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "restricted"
5
5
  },
6
- "version": "1.0.22",
6
+ "version": "1.0.23",
7
7
  "description": "",
8
8
  "main": "dist/cjs/index.js",
9
9
  "module": "dist/esm/index.js",