mboaai-sdk 1.0.2 → 1.0.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/package.json +18 -9
- package/rollup.config.mjs +0 -20
- package/src/index.ts +0 -87
- package/tsconfig.json +0 -14
package/package.json
CHANGED
@@ -1,19 +1,24 @@
|
|
1
1
|
{
|
2
2
|
"name": "mboaai-sdk",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.3",
|
4
4
|
"description": "Lightweight JavaScript SDK for calling MboaAI agents",
|
5
|
-
"
|
6
|
-
"
|
5
|
+
"type": "module",
|
6
|
+
"main": "./dist/mboaai-sdk.umd.js",
|
7
|
+
"module": "./dist/mboaai-sdk.esm.js",
|
7
8
|
"exports": {
|
8
|
-
"
|
9
|
-
|
9
|
+
".": {
|
10
|
+
"import": "./dist/mboaai-sdk.esm.js",
|
11
|
+
"require": "./dist/mboaai-sdk.umd.js",
|
12
|
+
"default": "./dist/mboaai-sdk.esm.js"
|
13
|
+
},
|
14
|
+
"./package.json": "./package.json"
|
10
15
|
},
|
11
|
-
"types": "dist/index.d.ts",
|
16
|
+
"types": "./dist/index.d.ts",
|
12
17
|
"scripts": {
|
13
18
|
"build": "rollup -c",
|
14
19
|
"prepublishOnly": "npm run build"
|
15
20
|
},
|
16
|
-
"author": "
|
21
|
+
"author": "Jessica Nono",
|
17
22
|
"license": "MIT",
|
18
23
|
"dependencies": {
|
19
24
|
"mcp-client": "^1.2.0",
|
@@ -22,10 +27,14 @@
|
|
22
27
|
"devDependencies": {
|
23
28
|
"@rollup/plugin-commonjs": "^25",
|
24
29
|
"@rollup/plugin-node-resolve": "^15",
|
25
|
-
"@rollup/plugin-terser": "^0.4.4",
|
26
30
|
"@rollup/plugin-typescript": "^12.1.2",
|
27
31
|
"rollup": "^4",
|
28
32
|
"rollup-plugin-terser": "^7.0.2",
|
29
33
|
"typescript": "^5.8.3"
|
30
|
-
}
|
34
|
+
},
|
35
|
+
"files": [
|
36
|
+
"dist",
|
37
|
+
"README.md",
|
38
|
+
"LICENSE"
|
39
|
+
]
|
31
40
|
}
|
package/rollup.config.mjs
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
// rollup.config.mjs
|
2
|
-
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
3
|
-
import commonjs from "@rollup/plugin-commonjs";
|
4
|
-
import typescript from "@rollup/plugin-typescript";
|
5
|
-
import { terser } from "rollup-plugin-terser"; // ← new import
|
6
|
-
|
7
|
-
export default {
|
8
|
-
input: "src/index.ts",
|
9
|
-
output: [
|
10
|
-
{ file: "dist/mboaai-sdk.umd.js", format: "umd", name: "MboaAI" },
|
11
|
-
{ file: "dist/mboaai-sdk.esm.js", format: "esm" }
|
12
|
-
],
|
13
|
-
plugins: [
|
14
|
-
nodeResolve({ extensions: [".js", ".ts"] }),
|
15
|
-
commonjs(),
|
16
|
-
typescript({ tsconfig: "./tsconfig.json" }), // compile TS → JS
|
17
|
-
terser(), // ← minify the JS
|
18
|
-
],
|
19
|
-
external: ["mcp-client"],
|
20
|
-
};
|
package/src/index.ts
DELETED
@@ -1,87 +0,0 @@
|
|
1
|
-
/*─────────────────────────────────────────────────────────────
|
2
|
-
MboaAI JavaScript SDK
|
3
|
-
─────────────────────────────────────────────────────────────*/
|
4
|
-
import { MCPClient } from "mcp-client";
|
5
|
-
|
6
|
-
/* 1 · Translation “type” – default is "standard", but any string allowed */
|
7
|
-
type BuiltIn = "standard" | "website";
|
8
|
-
export type TranslateType = BuiltIn | (string & {});
|
9
|
-
|
10
|
-
/* 2 · Init options */
|
11
|
-
interface InitOptions {
|
12
|
-
apiKey: string; // required
|
13
|
-
mcpUrl?: string; // default prod URL
|
14
|
-
name?: string;
|
15
|
-
version?: string;
|
16
|
-
defaultType?: TranslateType; // default = "standard"
|
17
|
-
}
|
18
|
-
|
19
|
-
/* 3 · SDK class */
|
20
|
-
class T {
|
21
|
-
private static client: MCPClient;
|
22
|
-
private static ready = false;
|
23
|
-
private static defaultType: TranslateType = "standard";
|
24
|
-
|
25
|
-
/** Call once near app start */
|
26
|
-
static async init(opts: InitOptions) {
|
27
|
-
if (!opts?.apiKey) throw new Error("MboaAI-SDK: apiKey is required");
|
28
|
-
if (T.ready) return; // idempotent
|
29
|
-
|
30
|
-
const {
|
31
|
-
apiKey,
|
32
|
-
mcpUrl = "https://api.filparty.com:8001/mcp",
|
33
|
-
name = "MboaAI-SDK",
|
34
|
-
version = "1.0.0",
|
35
|
-
defaultType = "standard",
|
36
|
-
} = opts;
|
37
|
-
|
38
|
-
T.client = new MCPClient({ name, version });
|
39
|
-
await (T.client as any).connect({
|
40
|
-
type: "sse",
|
41
|
-
url: mcpUrl,
|
42
|
-
headers: { "x-api-key": apiKey },
|
43
|
-
});
|
44
|
-
T.defaultType = defaultType;
|
45
|
-
T.ready = true;
|
46
|
-
}
|
47
|
-
|
48
|
-
/** Translate text – returns original text on failure */
|
49
|
-
static async translate(
|
50
|
-
text: string,
|
51
|
-
targetLang: string,
|
52
|
-
type?: TranslateType,
|
53
|
-
): Promise<string> {
|
54
|
-
if (!T.ready) throw new Error("MboaAI-SDK: call init() first");
|
55
|
-
|
56
|
-
const pipeline = type ?? T.defaultType; // e.g. "standard" | "website"
|
57
|
-
const toolName = "run_translate"; // always the same tool
|
58
|
-
|
59
|
-
/* Prompt format requested */
|
60
|
-
const prompt = `Translate "${text}" into ${targetLang} for ${pipeline}`;
|
61
|
-
|
62
|
-
try {
|
63
|
-
const res = await T.client.callTool({
|
64
|
-
name: toolName,
|
65
|
-
arguments: { message: prompt },
|
66
|
-
});
|
67
|
-
|
68
|
-
/* … inside translate() … */
|
69
|
-
const rawText = String(res?.content?.[0]?.text ?? ""); // ← ensure string
|
70
|
-
const obj = JSON.parse(rawText); // now OK
|
71
|
-
return obj.reply || obj.text || text;
|
72
|
-
} catch (e) {
|
73
|
-
console.error("[MboaAI-SDK] translate error → returning source", e);
|
74
|
-
return text;
|
75
|
-
}
|
76
|
-
}
|
77
|
-
}
|
78
|
-
|
79
|
-
/* 4 · Expose global for <script> usage */
|
80
|
-
declare global { interface Window { MboaAI?: any } }
|
81
|
-
if (typeof window !== "undefined") {
|
82
|
-
window.MboaAI = window.MboaAI || {};
|
83
|
-
window.MboaAI.T = T;
|
84
|
-
}
|
85
|
-
|
86
|
-
export { T };
|
87
|
-
export default T;
|