langchain 0.0.200 → 0.0.202
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/agents/toolkits/connery.cjs +1 -0
- package/agents/toolkits/connery.d.ts +1 -0
- package/agents/toolkits/connery.js +1 -0
- package/dist/agents/toolkits/connery/index.cjs +39 -0
- package/dist/agents/toolkits/connery/index.d.ts +23 -0
- package/dist/agents/toolkits/connery/index.js +35 -0
- package/dist/document_loaders/fs/obsidian.cjs +240 -0
- package/dist/document_loaders/fs/obsidian.d.ts +26 -0
- package/dist/document_loaders/fs/obsidian.js +233 -0
- package/dist/embeddings/gradient_ai.cjs +1 -0
- package/dist/embeddings/gradient_ai.js +1 -0
- package/dist/load/import_constants.cjs +2 -0
- package/dist/load/import_constants.js +2 -0
- package/dist/load/import_map.cjs +5 -3
- package/dist/load/import_map.d.ts +2 -0
- package/dist/load/import_map.js +2 -0
- package/dist/tools/connery.cjs +279 -0
- package/dist/tools/connery.d.ts +145 -0
- package/dist/tools/connery.js +274 -0
- package/dist/tools/gmail/base.cjs +69 -0
- package/dist/tools/gmail/base.d.ts +19 -0
- package/dist/tools/gmail/base.js +65 -0
- package/dist/tools/gmail/create_draft.cjs +62 -0
- package/dist/tools/gmail/create_draft.d.ts +35 -0
- package/dist/tools/gmail/create_draft.js +58 -0
- package/dist/tools/gmail/descriptions.cjs +118 -0
- package/dist/tools/gmail/descriptions.d.ts +5 -0
- package/dist/tools/gmail/descriptions.js +115 -0
- package/dist/tools/gmail/get_message.cjs +83 -0
- package/dist/tools/gmail/get_message.d.ts +18 -0
- package/dist/tools/gmail/get_message.js +79 -0
- package/dist/tools/gmail/get_thread.cjs +89 -0
- package/dist/tools/gmail/get_thread.d.ts +18 -0
- package/dist/tools/gmail/get_thread.js +85 -0
- package/dist/tools/gmail/index.cjs +13 -0
- package/dist/tools/gmail/index.d.ts +11 -0
- package/dist/tools/gmail/index.js +5 -0
- package/dist/tools/gmail/search.cjs +118 -0
- package/dist/tools/gmail/search.d.ts +29 -0
- package/dist/tools/gmail/search.js +114 -0
- package/dist/tools/gmail/send_message.cjs +74 -0
- package/dist/tools/gmail/send_message.d.ts +35 -0
- package/dist/tools/gmail/send_message.js +70 -0
- package/dist/tools/wolframalpha.cjs +1 -1
- package/dist/tools/wolframalpha.js +1 -1
- package/dist/util/stream.cjs +15 -85
- package/dist/util/stream.d.ts +1 -15
- package/dist/util/stream.js +1 -83
- package/dist/vectorstores/xata.cjs +1 -1
- package/dist/vectorstores/xata.js +1 -1
- package/document_loaders/fs/obsidian.cjs +1 -0
- package/document_loaders/fs/obsidian.d.ts +1 -0
- package/document_loaders/fs/obsidian.js +1 -0
- package/package.json +37 -5
- package/tools/connery.cjs +1 -0
- package/tools/connery.d.ts +1 -0
- package/tools/connery.js +1 -0
- package/tools/gmail.cjs +1 -0
- package/tools/gmail.d.ts +1 -0
- package/tools/gmail.js +1 -0
package/dist/load/import_map.cjs
CHANGED
|
@@ -24,12 +24,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
return result;
|
|
25
25
|
};
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.
|
|
28
|
-
exports.
|
|
29
|
-
exports.runnables__remote = exports.runnables = exports.evaluation = exports.experimental__chains__violation_of_expectations = void 0;
|
|
27
|
+
exports.document_transformers__openai_functions = exports.document_loaders__web__sort_xyz_blockchain = exports.document_loaders__web__serpapi = exports.document_loaders__web__searchapi = exports.document_loaders__base = exports.document = exports.memory = exports.text_splitter = exports.vectorstores__xata = exports.vectorstores__vectara = exports.vectorstores__prisma = exports.vectorstores__memory = exports.vectorstores__base = exports.prompts = exports.llms__fake = exports.llms__yandex = exports.llms__fireworks = exports.llms__ollama = exports.llms__cloudflare_workersai = exports.llms__aleph_alpha = exports.llms__ai21 = exports.llms__openai = exports.llms__base = exports.embeddings__voyage = exports.embeddings__minimax = exports.embeddings__openai = exports.embeddings__ollama = exports.embeddings__fake = exports.embeddings__cache_backed = exports.embeddings__base = exports.chains__openai_functions = exports.chains__combine_documents__reduce = exports.chains = exports.tools__google_places = exports.tools__render = exports.tools__connery = exports.tools = exports.base_language = exports.agents__openai__output_parser = exports.agents__xml__output_parser = exports.agents__react__output_parser = exports.agents__format_scratchpad__log_to_message = exports.agents__format_scratchpad__xml = exports.agents__format_scratchpad__log = exports.agents__format_scratchpad__openai_tools = exports.agents__format_scratchpad = exports.agents__toolkits__connery = exports.agents__toolkits = exports.agents = exports.load__serializable = void 0;
|
|
28
|
+
exports.experimental__plan_and_execute = exports.experimental__generative_agents = exports.experimental__babyagi = exports.experimental__openai_files = exports.experimental__openai_assistant = exports.experimental__autogpt = exports.util__time = exports.util__math = exports.util__document = exports.storage__in_memory = exports.storage__encoder_backed = exports.stores__message__in_memory = exports.stores__file__in_memory = exports.stores__doc__in_memory = exports.cache = exports.retrievers__vespa = exports.retrievers__score_threshold = exports.retrievers__hyde = exports.retrievers__document_compressors__embeddings_filter = exports.retrievers__document_compressors__chain_extract = exports.retrievers__time_weighted = exports.retrievers__tavily_search_api = exports.retrievers__parent_document = exports.retrievers__multi_vector = exports.retrievers__multi_query = exports.retrievers__document_compressors = exports.retrievers__contextual_compression = exports.retrievers__databerry = exports.retrievers__chaindesk = exports.retrievers__remote = exports.output_parsers = exports.callbacks = exports.schema__storage = exports.schema__runnable = exports.schema__retriever = exports.schema__query_constructor = exports.schema__prompt_template = exports.schema__output_parser = exports.schema__document = exports.schema = exports.chat_models__fake = exports.chat_models__yandex = exports.chat_models__minimax = exports.chat_models__ollama = exports.chat_models__baiduwenxin = exports.chat_models__fireworks = exports.chat_models__cloudflare_workersai = exports.chat_models__anthropic = exports.chat_models__openai = exports.chat_models__base = void 0;
|
|
29
|
+
exports.runnables__remote = exports.runnables = exports.evaluation = exports.experimental__chains__violation_of_expectations = exports.experimental__chat_models__ollama_functions = exports.experimental__chat_models__bittensor = void 0;
|
|
30
30
|
exports.load__serializable = __importStar(require("../load/serializable.cjs"));
|
|
31
31
|
exports.agents = __importStar(require("../agents/index.cjs"));
|
|
32
32
|
exports.agents__toolkits = __importStar(require("../agents/toolkits/index.cjs"));
|
|
33
|
+
exports.agents__toolkits__connery = __importStar(require("../agents/toolkits/connery/index.cjs"));
|
|
33
34
|
exports.agents__format_scratchpad = __importStar(require("../agents/format_scratchpad/openai_functions.cjs"));
|
|
34
35
|
exports.agents__format_scratchpad__openai_tools = __importStar(require("../agents/format_scratchpad/openai_tools.cjs"));
|
|
35
36
|
exports.agents__format_scratchpad__log = __importStar(require("../agents/format_scratchpad/log.cjs"));
|
|
@@ -40,6 +41,7 @@ exports.agents__xml__output_parser = __importStar(require("../agents/xml/output_
|
|
|
40
41
|
exports.agents__openai__output_parser = __importStar(require("../agents/openai/output_parser.cjs"));
|
|
41
42
|
exports.base_language = __importStar(require("../base_language/index.cjs"));
|
|
42
43
|
exports.tools = __importStar(require("../tools/index.cjs"));
|
|
44
|
+
exports.tools__connery = __importStar(require("../tools/connery.cjs"));
|
|
43
45
|
exports.tools__render = __importStar(require("../tools/render.cjs"));
|
|
44
46
|
exports.tools__google_places = __importStar(require("../tools/google_places.cjs"));
|
|
45
47
|
exports.chains = __importStar(require("../chains/index.cjs"));
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * as load__serializable from "../load/serializable.js";
|
|
2
2
|
export * as agents from "../agents/index.js";
|
|
3
3
|
export * as agents__toolkits from "../agents/toolkits/index.js";
|
|
4
|
+
export * as agents__toolkits__connery from "../agents/toolkits/connery/index.js";
|
|
4
5
|
export * as agents__format_scratchpad from "../agents/format_scratchpad/openai_functions.js";
|
|
5
6
|
export * as agents__format_scratchpad__openai_tools from "../agents/format_scratchpad/openai_tools.js";
|
|
6
7
|
export * as agents__format_scratchpad__log from "../agents/format_scratchpad/log.js";
|
|
@@ -11,6 +12,7 @@ export * as agents__xml__output_parser from "../agents/xml/output_parser.js";
|
|
|
11
12
|
export * as agents__openai__output_parser from "../agents/openai/output_parser.js";
|
|
12
13
|
export * as base_language from "../base_language/index.js";
|
|
13
14
|
export * as tools from "../tools/index.js";
|
|
15
|
+
export * as tools__connery from "../tools/connery.js";
|
|
14
16
|
export * as tools__render from "../tools/render.js";
|
|
15
17
|
export * as tools__google_places from "../tools/google_places.js";
|
|
16
18
|
export * as chains from "../chains/index.js";
|
package/dist/load/import_map.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
export * as load__serializable from "../load/serializable.js";
|
|
3
3
|
export * as agents from "../agents/index.js";
|
|
4
4
|
export * as agents__toolkits from "../agents/toolkits/index.js";
|
|
5
|
+
export * as agents__toolkits__connery from "../agents/toolkits/connery/index.js";
|
|
5
6
|
export * as agents__format_scratchpad from "../agents/format_scratchpad/openai_functions.js";
|
|
6
7
|
export * as agents__format_scratchpad__openai_tools from "../agents/format_scratchpad/openai_tools.js";
|
|
7
8
|
export * as agents__format_scratchpad__log from "../agents/format_scratchpad/log.js";
|
|
@@ -12,6 +13,7 @@ export * as agents__xml__output_parser from "../agents/xml/output_parser.js";
|
|
|
12
13
|
export * as agents__openai__output_parser from "../agents/openai/output_parser.js";
|
|
13
14
|
export * as base_language from "../base_language/index.js";
|
|
14
15
|
export * as tools from "../tools/index.js";
|
|
16
|
+
export * as tools__connery from "../tools/connery.js";
|
|
15
17
|
export * as tools__render from "../tools/render.js";
|
|
16
18
|
export * as tools__google_places from "../tools/google_places.js";
|
|
17
19
|
export * as chains from "../chains/index.js";
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConneryService = exports.ConneryAction = void 0;
|
|
4
|
+
const async_caller_js_1 = require("../util/async_caller.cjs");
|
|
5
|
+
const env_js_1 = require("../util/env.cjs");
|
|
6
|
+
const base_js_1 = require("./base.cjs");
|
|
7
|
+
/**
|
|
8
|
+
* A LangChain Tool object wrapping a Connery action.
|
|
9
|
+
* @extends Tool
|
|
10
|
+
*/
|
|
11
|
+
class ConneryAction extends base_js_1.Tool {
|
|
12
|
+
/**
|
|
13
|
+
* Creates a ConneryAction instance based on the provided Connery action.
|
|
14
|
+
* @param _action The Connery action.
|
|
15
|
+
* @param _service The ConneryService instance.
|
|
16
|
+
* @returns A ConneryAction instance.
|
|
17
|
+
*/
|
|
18
|
+
constructor(_action, _service) {
|
|
19
|
+
super();
|
|
20
|
+
Object.defineProperty(this, "_action", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
configurable: true,
|
|
23
|
+
writable: true,
|
|
24
|
+
value: _action
|
|
25
|
+
});
|
|
26
|
+
Object.defineProperty(this, "_service", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
configurable: true,
|
|
29
|
+
writable: true,
|
|
30
|
+
value: _service
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(this, "name", {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
writable: true,
|
|
36
|
+
value: void 0
|
|
37
|
+
});
|
|
38
|
+
Object.defineProperty(this, "description", {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
configurable: true,
|
|
41
|
+
writable: true,
|
|
42
|
+
value: void 0
|
|
43
|
+
});
|
|
44
|
+
this.name = this._action.title;
|
|
45
|
+
this.description = this.getDescription();
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Runs the Connery action.
|
|
49
|
+
* @param prompt This is a plain English prompt with all the information needed to run the action.
|
|
50
|
+
* @returns A promise that resolves to a JSON string containing the output of the action.
|
|
51
|
+
*/
|
|
52
|
+
_call(prompt) {
|
|
53
|
+
return this._service.runAction(this._action.id, prompt);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Returns the description of the Connery action.
|
|
57
|
+
* @returns A string containing the description of the Connery action together with the instructions on how to use it.
|
|
58
|
+
*/
|
|
59
|
+
getDescription() {
|
|
60
|
+
const { title, description } = this._action;
|
|
61
|
+
const inputParameters = this.prepareJsonForTemplate(this._action.inputParameters);
|
|
62
|
+
const example1InputParametersSchema = this.prepareJsonForTemplate([
|
|
63
|
+
{
|
|
64
|
+
key: "recipient",
|
|
65
|
+
title: "Email Recipient",
|
|
66
|
+
description: "Email address of the email recipient.",
|
|
67
|
+
type: "string",
|
|
68
|
+
validation: {
|
|
69
|
+
required: true,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
key: "subject",
|
|
74
|
+
title: "Email Subject",
|
|
75
|
+
description: "Subject of the email.",
|
|
76
|
+
type: "string",
|
|
77
|
+
validation: {
|
|
78
|
+
required: true,
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
key: "body",
|
|
83
|
+
title: "Email Body",
|
|
84
|
+
description: "Body of the email.",
|
|
85
|
+
type: "string",
|
|
86
|
+
validation: {
|
|
87
|
+
required: true,
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
]);
|
|
91
|
+
const descriptionTemplate = "# Instructions about tool input:\n" +
|
|
92
|
+
"The input to this tool is a plain English prompt with all the input parameters needed to call it. " +
|
|
93
|
+
"The input parameters schema of this tool is provided below. " +
|
|
94
|
+
"Use the input parameters schema to construct the prompt for the tool. " +
|
|
95
|
+
"If the input parameter is required in the schema, it must be provided in the prompt. " +
|
|
96
|
+
"Do not come up with the values for the input parameters yourself. " +
|
|
97
|
+
"If you do not have enough information to fill in the input parameter, ask the user to provide it. " +
|
|
98
|
+
"See examples below on how to construct the prompt based on the provided tool information. " +
|
|
99
|
+
"\n\n" +
|
|
100
|
+
"# Instructions about tool output:\n" +
|
|
101
|
+
"The output of this tool is a JSON string. " +
|
|
102
|
+
"Retrieve the output parameters from the JSON string and use them in the next tool. " +
|
|
103
|
+
"Do not return the JSON string as the output of the tool. " +
|
|
104
|
+
"\n\n" +
|
|
105
|
+
"# Example:\n" +
|
|
106
|
+
"Tool information:\n" +
|
|
107
|
+
"- Title: Send email\n" +
|
|
108
|
+
"- Description: Send an email to a recipient.\n" +
|
|
109
|
+
`- Input parameters schema in JSON fromat: ${example1InputParametersSchema}\n` +
|
|
110
|
+
"The tool input prompt:\n" +
|
|
111
|
+
"recipient: test@example.com, subject: 'Test email', body: 'This is a test email sent from Langchain Connery tool.'\n" +
|
|
112
|
+
"\n\n" +
|
|
113
|
+
"# The tool information\n" +
|
|
114
|
+
`- Title: ${title}\n` +
|
|
115
|
+
`- Description: ${description}\n` +
|
|
116
|
+
`- Input parameters schema in JSON fromat: ${inputParameters}\n`;
|
|
117
|
+
return descriptionTemplate;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Converts the provided object to a JSON string and escapes '{' and '}' characters.
|
|
121
|
+
* @param obj The object to convert to a JSON string.
|
|
122
|
+
* @returns A string containing the JSON representation of the provided object with '{' and '}' characters escaped.
|
|
123
|
+
*/
|
|
124
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
125
|
+
prepareJsonForTemplate(obj) {
|
|
126
|
+
// Convert the object to a JSON string
|
|
127
|
+
const jsonString = JSON.stringify(obj);
|
|
128
|
+
// Replace '{' with '{{' and '}' with '}}'
|
|
129
|
+
const escapedJSON = jsonString.replace(/{/g, "{{").replace(/}/g, "}}");
|
|
130
|
+
return escapedJSON;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
exports.ConneryAction = ConneryAction;
|
|
134
|
+
/**
|
|
135
|
+
* A service for working with Connery actions.
|
|
136
|
+
*
|
|
137
|
+
* Connery is an open-source plugin infrastructure for AI.
|
|
138
|
+
* Source code: https://github.com/connery-io/connery-platform
|
|
139
|
+
*/
|
|
140
|
+
class ConneryService {
|
|
141
|
+
/**
|
|
142
|
+
* Creates a ConneryService instance.
|
|
143
|
+
* @param params A ConneryServiceParams object.
|
|
144
|
+
* If not provided, the values are retrieved from the CONNERY_RUNNER_URL
|
|
145
|
+
* and CONNERY_RUNNER_API_KEY environment variables.
|
|
146
|
+
* @returns A ConneryService instance.
|
|
147
|
+
*/
|
|
148
|
+
constructor(params) {
|
|
149
|
+
Object.defineProperty(this, "runnerUrl", {
|
|
150
|
+
enumerable: true,
|
|
151
|
+
configurable: true,
|
|
152
|
+
writable: true,
|
|
153
|
+
value: void 0
|
|
154
|
+
});
|
|
155
|
+
Object.defineProperty(this, "apiKey", {
|
|
156
|
+
enumerable: true,
|
|
157
|
+
configurable: true,
|
|
158
|
+
writable: true,
|
|
159
|
+
value: void 0
|
|
160
|
+
});
|
|
161
|
+
Object.defineProperty(this, "asyncCaller", {
|
|
162
|
+
enumerable: true,
|
|
163
|
+
configurable: true,
|
|
164
|
+
writable: true,
|
|
165
|
+
value: void 0
|
|
166
|
+
});
|
|
167
|
+
const runnerUrl = params?.runnerUrl ?? (0, env_js_1.getEnvironmentVariable)("CONNERY_RUNNER_URL");
|
|
168
|
+
const apiKey = params?.apiKey ?? (0, env_js_1.getEnvironmentVariable)("CONNERY_RUNNER_API_KEY");
|
|
169
|
+
if (!runnerUrl || !apiKey) {
|
|
170
|
+
throw new Error("CONNERY_RUNNER_URL and CONNERY_RUNNER_API_KEY environment variables must be set.");
|
|
171
|
+
}
|
|
172
|
+
this.runnerUrl = runnerUrl;
|
|
173
|
+
this.apiKey = apiKey;
|
|
174
|
+
this.asyncCaller = new async_caller_js_1.AsyncCaller(params ?? {});
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Returns the list of Connery actions wrapped as a LangChain Tool objects.
|
|
178
|
+
* @returns A promise that resolves to an array of ConneryAction objects.
|
|
179
|
+
*/
|
|
180
|
+
async listActions() {
|
|
181
|
+
const actions = await this._listActions();
|
|
182
|
+
return actions.map((action) => new ConneryAction(action, this));
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Returns the specified Connery action wrapped as a LangChain Tool object.
|
|
186
|
+
* @param actionId The ID of the action to return.
|
|
187
|
+
* @returns A promise that resolves to a ConneryAction object.
|
|
188
|
+
*/
|
|
189
|
+
async getAction(actionId) {
|
|
190
|
+
const action = await this._getAction(actionId);
|
|
191
|
+
return new ConneryAction(action, this);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Runs the specified Connery action with the provided input.
|
|
195
|
+
* @param actionId The ID of the action to run.
|
|
196
|
+
* @param prompt This is a plain English prompt with all the information needed to run the action.
|
|
197
|
+
* @param input The input expected by the action.
|
|
198
|
+
* If provided together with the prompt, the input takes precedence over the input specified in the prompt.
|
|
199
|
+
* @returns A promise that resolves to a JSON string containing the output of the action.
|
|
200
|
+
*/
|
|
201
|
+
async runAction(actionId, prompt, input) {
|
|
202
|
+
const result = await this._runAction(actionId, prompt, input);
|
|
203
|
+
return JSON.stringify(result);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Returns the list of actions available in the Connery runner.
|
|
207
|
+
* @returns A promise that resolves to an array of Action objects.
|
|
208
|
+
*/
|
|
209
|
+
async _listActions() {
|
|
210
|
+
const response = await this.asyncCaller.call(fetch, `${this.runnerUrl}/v1/actions`, {
|
|
211
|
+
method: "GET",
|
|
212
|
+
headers: this._getHeaders(),
|
|
213
|
+
});
|
|
214
|
+
await this._handleError(response, "Failed to list actions");
|
|
215
|
+
const apiResponse = await response.json();
|
|
216
|
+
return apiResponse.data;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Returns the specified action available in the Connery runner.
|
|
220
|
+
* @param actionId The ID of the action to return.
|
|
221
|
+
* @returns A promise that resolves to an Action object.
|
|
222
|
+
* @throws An error if the action with the specified ID is not found.
|
|
223
|
+
*/
|
|
224
|
+
async _getAction(actionId) {
|
|
225
|
+
const actions = await this._listActions();
|
|
226
|
+
const action = actions.find((a) => a.id === actionId);
|
|
227
|
+
if (!action) {
|
|
228
|
+
throw new Error(`The action with ID "${actionId}" was not found in the list of available actions in the Connery runner.`);
|
|
229
|
+
}
|
|
230
|
+
return action;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Runs the specified Connery action with the provided input.
|
|
234
|
+
* @param actionId The ID of the action to run.
|
|
235
|
+
* @param prompt This is a plain English prompt with all the information needed to run the action.
|
|
236
|
+
* @param input The input object expected by the action.
|
|
237
|
+
* If provided together with the prompt, the input takes precedence over the input specified in the prompt.
|
|
238
|
+
* @returns A promise that resolves to a RunActionResult object.
|
|
239
|
+
*/
|
|
240
|
+
async _runAction(actionId, prompt, input) {
|
|
241
|
+
const response = await this.asyncCaller.call(fetch, `${this.runnerUrl}/v1/actions/${actionId}/run`, {
|
|
242
|
+
method: "POST",
|
|
243
|
+
headers: this._getHeaders(),
|
|
244
|
+
body: JSON.stringify({
|
|
245
|
+
prompt,
|
|
246
|
+
input,
|
|
247
|
+
}),
|
|
248
|
+
});
|
|
249
|
+
await this._handleError(response, "Failed to run action");
|
|
250
|
+
const apiResponse = await response.json();
|
|
251
|
+
return apiResponse.data.output;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Returns a standard set of HTTP headers to be used in API calls to the Connery runner.
|
|
255
|
+
* @returns An object containing the standard set of HTTP headers.
|
|
256
|
+
*/
|
|
257
|
+
_getHeaders() {
|
|
258
|
+
return {
|
|
259
|
+
"Content-Type": "application/json",
|
|
260
|
+
"x-api-key": this.apiKey,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Shared error handler for API calls to the Connery runner.
|
|
265
|
+
* If the response is not ok, an error is thrown containing the error message returned by the Connery runner.
|
|
266
|
+
* Otherwise, the promise resolves to void.
|
|
267
|
+
* @param response The response object returned by the Connery runner.
|
|
268
|
+
* @param errorMessage The error message to be used in the error thrown if the response is not ok.
|
|
269
|
+
* @returns A promise that resolves to void.
|
|
270
|
+
* @throws An error containing the error message returned by the Connery runner.
|
|
271
|
+
*/
|
|
272
|
+
async _handleError(response, errorMessage) {
|
|
273
|
+
if (response.ok)
|
|
274
|
+
return;
|
|
275
|
+
const apiErrorResponse = await response.json();
|
|
276
|
+
throw new Error(`${errorMessage}. Status code: ${response.status}. Error message: ${apiErrorResponse.error.message}`);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
exports.ConneryService = ConneryService;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { AsyncCaller, AsyncCallerParams } from "../util/async_caller.js";
|
|
2
|
+
import { Tool } from "./base.js";
|
|
3
|
+
/**
|
|
4
|
+
* An object containing configuration parameters for the ConneryService class.
|
|
5
|
+
* @extends AsyncCallerParams
|
|
6
|
+
*/
|
|
7
|
+
export interface ConneryServiceParams extends AsyncCallerParams {
|
|
8
|
+
runnerUrl: string;
|
|
9
|
+
apiKey: string;
|
|
10
|
+
}
|
|
11
|
+
type Parameter = {
|
|
12
|
+
key: string;
|
|
13
|
+
title: string;
|
|
14
|
+
description: string;
|
|
15
|
+
type: string;
|
|
16
|
+
validation?: {
|
|
17
|
+
required?: boolean;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
type Action = {
|
|
21
|
+
id: string;
|
|
22
|
+
key: string;
|
|
23
|
+
title: string;
|
|
24
|
+
description: string;
|
|
25
|
+
type: string;
|
|
26
|
+
inputParameters: Parameter[];
|
|
27
|
+
outputParameters: Parameter[];
|
|
28
|
+
pluginId: string;
|
|
29
|
+
};
|
|
30
|
+
type Input = {
|
|
31
|
+
[key: string]: string;
|
|
32
|
+
};
|
|
33
|
+
type Output = {
|
|
34
|
+
[key: string]: string;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* A LangChain Tool object wrapping a Connery action.
|
|
38
|
+
* @extends Tool
|
|
39
|
+
*/
|
|
40
|
+
export declare class ConneryAction extends Tool {
|
|
41
|
+
protected _action: Action;
|
|
42
|
+
protected _service: ConneryService;
|
|
43
|
+
name: string;
|
|
44
|
+
description: string;
|
|
45
|
+
/**
|
|
46
|
+
* Creates a ConneryAction instance based on the provided Connery action.
|
|
47
|
+
* @param _action The Connery action.
|
|
48
|
+
* @param _service The ConneryService instance.
|
|
49
|
+
* @returns A ConneryAction instance.
|
|
50
|
+
*/
|
|
51
|
+
constructor(_action: Action, _service: ConneryService);
|
|
52
|
+
/**
|
|
53
|
+
* Runs the Connery action.
|
|
54
|
+
* @param prompt This is a plain English prompt with all the information needed to run the action.
|
|
55
|
+
* @returns A promise that resolves to a JSON string containing the output of the action.
|
|
56
|
+
*/
|
|
57
|
+
protected _call(prompt: string): Promise<string>;
|
|
58
|
+
/**
|
|
59
|
+
* Returns the description of the Connery action.
|
|
60
|
+
* @returns A string containing the description of the Connery action together with the instructions on how to use it.
|
|
61
|
+
*/
|
|
62
|
+
protected getDescription(): string;
|
|
63
|
+
/**
|
|
64
|
+
* Converts the provided object to a JSON string and escapes '{' and '}' characters.
|
|
65
|
+
* @param obj The object to convert to a JSON string.
|
|
66
|
+
* @returns A string containing the JSON representation of the provided object with '{' and '}' characters escaped.
|
|
67
|
+
*/
|
|
68
|
+
protected prepareJsonForTemplate(obj: any): string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A service for working with Connery actions.
|
|
72
|
+
*
|
|
73
|
+
* Connery is an open-source plugin infrastructure for AI.
|
|
74
|
+
* Source code: https://github.com/connery-io/connery-platform
|
|
75
|
+
*/
|
|
76
|
+
export declare class ConneryService {
|
|
77
|
+
protected runnerUrl: string;
|
|
78
|
+
protected apiKey: string;
|
|
79
|
+
protected asyncCaller: AsyncCaller;
|
|
80
|
+
/**
|
|
81
|
+
* Creates a ConneryService instance.
|
|
82
|
+
* @param params A ConneryServiceParams object.
|
|
83
|
+
* If not provided, the values are retrieved from the CONNERY_RUNNER_URL
|
|
84
|
+
* and CONNERY_RUNNER_API_KEY environment variables.
|
|
85
|
+
* @returns A ConneryService instance.
|
|
86
|
+
*/
|
|
87
|
+
constructor(params?: ConneryServiceParams);
|
|
88
|
+
/**
|
|
89
|
+
* Returns the list of Connery actions wrapped as a LangChain Tool objects.
|
|
90
|
+
* @returns A promise that resolves to an array of ConneryAction objects.
|
|
91
|
+
*/
|
|
92
|
+
listActions(): Promise<ConneryAction[]>;
|
|
93
|
+
/**
|
|
94
|
+
* Returns the specified Connery action wrapped as a LangChain Tool object.
|
|
95
|
+
* @param actionId The ID of the action to return.
|
|
96
|
+
* @returns A promise that resolves to a ConneryAction object.
|
|
97
|
+
*/
|
|
98
|
+
getAction(actionId: string): Promise<ConneryAction>;
|
|
99
|
+
/**
|
|
100
|
+
* Runs the specified Connery action with the provided input.
|
|
101
|
+
* @param actionId The ID of the action to run.
|
|
102
|
+
* @param prompt This is a plain English prompt with all the information needed to run the action.
|
|
103
|
+
* @param input The input expected by the action.
|
|
104
|
+
* If provided together with the prompt, the input takes precedence over the input specified in the prompt.
|
|
105
|
+
* @returns A promise that resolves to a JSON string containing the output of the action.
|
|
106
|
+
*/
|
|
107
|
+
runAction(actionId: string, prompt?: string, input?: Input): Promise<string>;
|
|
108
|
+
/**
|
|
109
|
+
* Returns the list of actions available in the Connery runner.
|
|
110
|
+
* @returns A promise that resolves to an array of Action objects.
|
|
111
|
+
*/
|
|
112
|
+
protected _listActions(): Promise<Action[]>;
|
|
113
|
+
/**
|
|
114
|
+
* Returns the specified action available in the Connery runner.
|
|
115
|
+
* @param actionId The ID of the action to return.
|
|
116
|
+
* @returns A promise that resolves to an Action object.
|
|
117
|
+
* @throws An error if the action with the specified ID is not found.
|
|
118
|
+
*/
|
|
119
|
+
protected _getAction(actionId: string): Promise<Action>;
|
|
120
|
+
/**
|
|
121
|
+
* Runs the specified Connery action with the provided input.
|
|
122
|
+
* @param actionId The ID of the action to run.
|
|
123
|
+
* @param prompt This is a plain English prompt with all the information needed to run the action.
|
|
124
|
+
* @param input The input object expected by the action.
|
|
125
|
+
* If provided together with the prompt, the input takes precedence over the input specified in the prompt.
|
|
126
|
+
* @returns A promise that resolves to a RunActionResult object.
|
|
127
|
+
*/
|
|
128
|
+
protected _runAction(actionId: string, prompt?: string, input?: Input): Promise<Output>;
|
|
129
|
+
/**
|
|
130
|
+
* Returns a standard set of HTTP headers to be used in API calls to the Connery runner.
|
|
131
|
+
* @returns An object containing the standard set of HTTP headers.
|
|
132
|
+
*/
|
|
133
|
+
protected _getHeaders(): Record<string, string>;
|
|
134
|
+
/**
|
|
135
|
+
* Shared error handler for API calls to the Connery runner.
|
|
136
|
+
* If the response is not ok, an error is thrown containing the error message returned by the Connery runner.
|
|
137
|
+
* Otherwise, the promise resolves to void.
|
|
138
|
+
* @param response The response object returned by the Connery runner.
|
|
139
|
+
* @param errorMessage The error message to be used in the error thrown if the response is not ok.
|
|
140
|
+
* @returns A promise that resolves to void.
|
|
141
|
+
* @throws An error containing the error message returned by the Connery runner.
|
|
142
|
+
*/
|
|
143
|
+
protected _handleError(response: Response, errorMessage: string): Promise<void>;
|
|
144
|
+
}
|
|
145
|
+
export {};
|