@fonoster/common 0.12.13 → 0.12.16
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/dist/assistants/assistantSchema.d.ts +1 -1
- package/dist/assistants/languageModelConfigSchema.d.ts +1 -1
- package/dist/assistants/tools/toolSchema.d.ts +1 -1
- package/dist/assistants/tools/toolSchema.js +7 -1
- package/dist/utils/sendHttpRequest.d.ts +2 -2
- package/dist/utils/sendHttpRequest.js +22 -11
- package/package.json +2 -2
|
@@ -189,7 +189,7 @@ declare const assistantSchema: z.ZodObject<{
|
|
|
189
189
|
method: z.ZodDefault<z.ZodNativeEnum<typeof import("..").AllowedHttpMethod>>;
|
|
190
190
|
url: z.ZodString;
|
|
191
191
|
waitForResponse: z.ZodDefault<z.ZodBoolean>;
|
|
192
|
-
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString
|
|
192
|
+
headers: z.ZodOptional<z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodString>, Record<string, string>, Record<string, string>>>;
|
|
193
193
|
}, "strip", z.ZodTypeAny, {
|
|
194
194
|
url?: string;
|
|
195
195
|
method?: import("..").AllowedHttpMethod;
|
|
@@ -87,7 +87,7 @@ declare const languageModelConfigSchema: z.ZodObject<{
|
|
|
87
87
|
method: z.ZodDefault<z.ZodNativeEnum<typeof import("..").AllowedHttpMethod>>;
|
|
88
88
|
url: z.ZodString;
|
|
89
89
|
waitForResponse: z.ZodDefault<z.ZodBoolean>;
|
|
90
|
-
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString
|
|
90
|
+
headers: z.ZodOptional<z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodString>, Record<string, string>, Record<string, string>>>;
|
|
91
91
|
}, "strip", z.ZodTypeAny, {
|
|
92
92
|
url?: string;
|
|
93
93
|
method?: import("..").AllowedHttpMethod;
|
|
@@ -67,7 +67,7 @@ declare const toolSchema: z.ZodObject<{
|
|
|
67
67
|
method: z.ZodDefault<z.ZodNativeEnum<typeof AllowedHttpMethod>>;
|
|
68
68
|
url: z.ZodString;
|
|
69
69
|
waitForResponse: z.ZodDefault<z.ZodBoolean>;
|
|
70
|
-
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString
|
|
70
|
+
headers: z.ZodOptional<z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodString>, Record<string, string>, Record<string, string>>>;
|
|
71
71
|
}, "strip", z.ZodTypeAny, {
|
|
72
72
|
url?: string;
|
|
73
73
|
method?: AllowedHttpMethod;
|
|
@@ -73,7 +73,13 @@ const toolSchema = zod_1.z.object({
|
|
|
73
73
|
.default(sendHttpRequest_1.AllowedHttpMethod.GET),
|
|
74
74
|
url: zod_1.z.string().url({ message: Messages.VALID_URL }),
|
|
75
75
|
waitForResponse: zod_1.z.boolean().default(true),
|
|
76
|
-
headers: zod_1.z
|
|
76
|
+
headers: zod_1.z
|
|
77
|
+
.record(zod_1.z.string(), zod_1.z.string())
|
|
78
|
+
.refine((headers) => !Object.keys(headers || {}).some((key) => key.toLowerCase() === "accept" ||
|
|
79
|
+
key.toLowerCase() === "content-type"), {
|
|
80
|
+
message: "Headers cannot include 'accept' or 'content-type' as they are set internally"
|
|
81
|
+
})
|
|
82
|
+
.optional()
|
|
77
83
|
})
|
|
78
84
|
});
|
|
79
85
|
exports.toolSchema = toolSchema;
|
|
@@ -2,12 +2,12 @@ declare enum AllowedHttpMethod {
|
|
|
2
2
|
GET = "get",
|
|
3
3
|
POST = "post"
|
|
4
4
|
}
|
|
5
|
-
declare function sendHttpRequest(
|
|
5
|
+
declare function sendHttpRequest(request: {
|
|
6
6
|
method: AllowedHttpMethod;
|
|
7
7
|
url: string;
|
|
8
8
|
waitForResponse: boolean;
|
|
9
9
|
headers?: Record<string, string>;
|
|
10
|
-
|
|
10
|
+
params?: Record<string, unknown>;
|
|
11
11
|
}): Promise<{
|
|
12
12
|
result: string;
|
|
13
13
|
}>;
|
|
@@ -29,6 +29,7 @@ exports.sendHttpRequest = sendHttpRequest;
|
|
|
29
29
|
* See the License for the specific language governing permissions and
|
|
30
30
|
* limitations under the License.
|
|
31
31
|
*/
|
|
32
|
+
const url_1 = require("url");
|
|
32
33
|
const logger_1 = require("@fonoster/logger");
|
|
33
34
|
const zod_1 = require("zod");
|
|
34
35
|
const responseSchema = zod_1.z.object({
|
|
@@ -40,25 +41,35 @@ var AllowedHttpMethod;
|
|
|
40
41
|
AllowedHttpMethod["GET"] = "get";
|
|
41
42
|
AllowedHttpMethod["POST"] = "post";
|
|
42
43
|
})(AllowedHttpMethod || (exports.AllowedHttpMethod = AllowedHttpMethod = {}));
|
|
43
|
-
function sendHttpRequest(
|
|
44
|
+
function sendHttpRequest(request) {
|
|
44
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
const { url, method,
|
|
46
|
+
const { url, method, params, headers, waitForResponse } = request;
|
|
46
47
|
const effectiveMethod = method.toLowerCase();
|
|
48
|
+
let effectiveUrl = url;
|
|
49
|
+
if (effectiveMethod === AllowedHttpMethod.GET && params) {
|
|
50
|
+
const queryParams = new url_1.URLSearchParams();
|
|
51
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
52
|
+
queryParams.append(key, String(value));
|
|
53
|
+
});
|
|
54
|
+
effectiveUrl = `${url}${url.includes("?") ? "&" : "?"}${queryParams.toString()}`;
|
|
55
|
+
}
|
|
47
56
|
const options = {
|
|
48
|
-
method,
|
|
49
|
-
headers: Object.assign({ "
|
|
50
|
-
body: effectiveMethod ===
|
|
57
|
+
method: effectiveMethod,
|
|
58
|
+
headers: Object.assign(Object.assign({}, headers), { accept: "application/json", "content-type": "application/json" }),
|
|
59
|
+
body: effectiveMethod === AllowedHttpMethod.POST
|
|
60
|
+
? JSON.stringify(params)
|
|
61
|
+
: undefined
|
|
51
62
|
};
|
|
52
|
-
logger.silly(`sending request to ${
|
|
53
|
-
|
|
63
|
+
logger.silly(`sending request to ${effectiveUrl}`, {
|
|
64
|
+
params,
|
|
54
65
|
method: effectiveMethod
|
|
55
66
|
});
|
|
56
|
-
if (waitForResponse && effectiveMethod ===
|
|
57
|
-
setTimeout(() => fetch(
|
|
58
|
-
return { result: "
|
|
67
|
+
if (!waitForResponse && effectiveMethod === AllowedHttpMethod.POST) {
|
|
68
|
+
setTimeout(() => fetch(effectiveUrl, options), 0);
|
|
69
|
+
return { result: "success" };
|
|
59
70
|
}
|
|
60
71
|
else {
|
|
61
|
-
const response = yield fetch(
|
|
72
|
+
const response = yield fetch(effectiveUrl, options);
|
|
62
73
|
const data = yield response.json();
|
|
63
74
|
try {
|
|
64
75
|
return responseSchema.parse(data);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fonoster/common",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.16",
|
|
4
4
|
"description": "Common library for Fonoster projects",
|
|
5
5
|
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
6
|
"homepage": "https://github.com/fonoster/fonoster#readme",
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@types/nodemailer": "^6.4.14"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "ec03d81daf288d40aee731c84391ad42025b1bd5"
|
|
53
53
|
}
|