@tekibo/feedpulse-sdk 0.7.0 → 0.7.3
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/bin/feedpulse-bot-build.mjs +121 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +171 -93
- package/dist/nuxt.js +2 -2
- package/dist/nuxt.mjs +345 -284
- package/dist/react.js +3 -3
- package/dist/react.mjs +315 -275
- package/dist/server.js +1 -0
- package/dist/server.mjs +18 -0
- package/package.json +11 -2
- package/templates/nuxt-bot-proxy.ts +39 -2
- package/templates/nuxt-config-id-route.ts +15 -0
package/dist/server.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("node:crypto");function i(t){if(t.length<16)throw new Error("FEEDPULSE_ENCRYPT_KEY must be at least 16 characters.");return c.createHash("sha256").update(t).digest()}function f(t,a){const e=i(a),n=c.randomBytes(12),r=c.createCipheriv("aes-256-gcm",e,n),o=Buffer.concat([r.update(t,"utf8"),r.final()]),s=r.getAuthTag();return Buffer.concat([n,s,o]).toString("base64url")}function d(t,a){const e=Buffer.from(t,"base64url"),n=e.subarray(0,12),r=e.subarray(12,28),o=e.subarray(28),s=i(a),u=c.createDecipheriv("aes-256-gcm",s,n);return u.setAuthTag(r),u.update(o,void 0,"utf8")+u.final("utf8")}exports.decryptConfigId=d;exports.encryptConfigId=f;
|
package/dist/server.mjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createDecipheriv as i, randomBytes as f, createCipheriv as d, createHash as g } from "node:crypto";
|
|
2
|
+
function u(t) {
|
|
3
|
+
if (t.length < 16)
|
|
4
|
+
throw new Error("FEEDPULSE_ENCRYPT_KEY must be at least 16 characters.");
|
|
5
|
+
return g("sha256").update(t).digest();
|
|
6
|
+
}
|
|
7
|
+
function h(t, n) {
|
|
8
|
+
const e = u(n), a = f(12), r = d("aes-256-gcm", e, a), c = Buffer.concat([r.update(t, "utf8"), r.final()]), o = r.getAuthTag();
|
|
9
|
+
return Buffer.concat([a, o, c]).toString("base64url");
|
|
10
|
+
}
|
|
11
|
+
function y(t, n) {
|
|
12
|
+
const e = Buffer.from(t, "base64url"), a = e.subarray(0, 12), r = e.subarray(12, 28), c = e.subarray(28), o = u(n), s = i("aes-256-gcm", o, a);
|
|
13
|
+
return s.setAuthTag(r), s.update(c, void 0, "utf8") + s.final("utf8");
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
y as decryptConfigId,
|
|
17
|
+
h as encryptConfigId
|
|
18
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tekibo/feedpulse-sdk",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"description": "Embeddable analytics and feedback SDK for FeedPulse",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
"./react": {
|
|
15
15
|
"import": "./dist/react.mjs",
|
|
16
16
|
"require": "./dist/react.js"
|
|
17
|
+
},
|
|
18
|
+
"./server": {
|
|
19
|
+
"import": "./dist/server.mjs",
|
|
20
|
+
"require": "./dist/server.js"
|
|
17
21
|
}
|
|
18
22
|
},
|
|
19
23
|
"main": "./dist/index.js",
|
|
@@ -21,8 +25,12 @@
|
|
|
21
25
|
"types": "./dist/index.d.ts",
|
|
22
26
|
"files": [
|
|
23
27
|
"dist",
|
|
28
|
+
"bin",
|
|
24
29
|
"templates"
|
|
25
30
|
],
|
|
31
|
+
"bin": {
|
|
32
|
+
"feedpulse-bot-build": "./bin/feedpulse-bot-build.mjs"
|
|
33
|
+
},
|
|
26
34
|
"scripts": {
|
|
27
35
|
"build": "vite build",
|
|
28
36
|
"dev": "vite build --watch"
|
|
@@ -40,7 +48,8 @@
|
|
|
40
48
|
}
|
|
41
49
|
},
|
|
42
50
|
"dependencies": {
|
|
43
|
-
"js-cookie": "^3.0.5"
|
|
51
|
+
"js-cookie": "^3.0.5",
|
|
52
|
+
"zod": "^4.3.5"
|
|
44
53
|
},
|
|
45
54
|
"devDependencies": {
|
|
46
55
|
"@types/js-cookie": "^3.0.6",
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
export const chatProxyRoute = `
|
|
1
|
+
export const chatProxyRoute = `import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
5
|
+
import type { FeedPulseTool } from "@tekibo/feedpulse-sdk";
|
|
6
|
+
|
|
7
|
+
export default defineEventHandler(async (event) => {
|
|
2
8
|
const config = useRuntimeConfig(event);
|
|
3
9
|
const apiKey = config.feedpulseApiKey;
|
|
4
10
|
const feedpulseBaseUrl = config.feedpulseApiBaseUrl || "http://localhost:3000";
|
|
@@ -6,10 +12,27 @@ export const chatProxyRoute = `export default defineEventHandler(async (event) =
|
|
|
6
12
|
throw createError({ statusCode: 500, statusMessage: "FEEDPULSE_API_KEY is not configured" });
|
|
7
13
|
|
|
8
14
|
const body = await readBody<Record<string, unknown>>(event);
|
|
15
|
+
const page = typeof body.page === "string" ? body.page : "/";
|
|
16
|
+
const mapKey = page.replace(/\\//g, "_").replace(/^_/, "") || "index";
|
|
17
|
+
const mapPath = join(process.cwd(), "feedpulse", "page-maps", \`\${mapKey}.json\`);
|
|
18
|
+
const pageMap = existsSync(mapPath) ? JSON.parse(readFileSync(mapPath, "utf8")) : null;
|
|
19
|
+
let toolsPayload: Array<Record<string, unknown>> = [];
|
|
20
|
+
try {
|
|
21
|
+
const module = await import("~~/feedpulse/tools") as { feedpulseTools?: FeedPulseTool[] };
|
|
22
|
+
const tools = module.feedpulseTools || [];
|
|
23
|
+
toolsPayload = tools.map(item => ({
|
|
24
|
+
name: item.name,
|
|
25
|
+
description: item.description,
|
|
26
|
+
inputSchema: zodToJsonSchema(item.inputSchema, item.name),
|
|
27
|
+
endpoint: item.endpoint,
|
|
28
|
+
method: item.method ?? "POST",
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
catch {}
|
|
9
32
|
const response = await fetch(\`\${feedpulseBaseUrl}/api/bot/chat\`, {
|
|
10
33
|
method: "POST",
|
|
11
34
|
headers: { "content-type": "application/json" },
|
|
12
|
-
body: JSON.stringify({ ...body, projectApiKey: apiKey }),
|
|
35
|
+
body: JSON.stringify({ ...body, projectApiKey: apiKey, developerTools: toolsPayload, pageMap }),
|
|
13
36
|
});
|
|
14
37
|
|
|
15
38
|
return new Response(response.body, {
|
|
@@ -54,3 +77,17 @@ export const sessionEndProxyRoute = `export default defineEventHandler(async (ev
|
|
|
54
77
|
throw createError({ statusCode: response.status, statusMessage: payload?.error || "Session end proxy failed", data: payload });
|
|
55
78
|
return payload;
|
|
56
79
|
});`;
|
|
80
|
+
|
|
81
|
+
export const configIdRoute = `import { encryptConfigId } from "@tekibo/feedpulse-sdk/server";
|
|
82
|
+
|
|
83
|
+
export default defineEventHandler(async (event) => {
|
|
84
|
+
const query = getQuery(event);
|
|
85
|
+
const key = String(query.key || "");
|
|
86
|
+
if (!key)
|
|
87
|
+
throw createError({ statusCode: 400, statusMessage: "key is required" });
|
|
88
|
+
const config = useRuntimeConfig(event);
|
|
89
|
+
const secret = config.feedpulseEncryptKey;
|
|
90
|
+
if (!secret || secret.length < 16)
|
|
91
|
+
throw createError({ statusCode: 500, statusMessage: "FEEDPULSE_ENCRYPT_KEY must be at least 16 characters." });
|
|
92
|
+
return { encryptedId: encryptConfigId(key, secret) };
|
|
93
|
+
});`;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const configIdRoute = `import { encryptConfigId } from "@tekibo/feedpulse-sdk/server";
|
|
2
|
+
|
|
3
|
+
export default defineEventHandler(async (event) => {
|
|
4
|
+
const query = getQuery(event);
|
|
5
|
+
const key = String(query.key || "");
|
|
6
|
+
if (!key)
|
|
7
|
+
throw createError({ statusCode: 400, statusMessage: "key is required" });
|
|
8
|
+
const config = useRuntimeConfig(event);
|
|
9
|
+
const secret = config.feedpulseEncryptKey;
|
|
10
|
+
if (!secret || secret.length < 16)
|
|
11
|
+
throw createError({ statusCode: 500, statusMessage: "FEEDPULSE_ENCRYPT_KEY must be at least 16 characters." });
|
|
12
|
+
return {
|
|
13
|
+
encryptedId: encryptConfigId(key, secret),
|
|
14
|
+
};
|
|
15
|
+
});`;
|