mboaai-sdk 1.0.0

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 ADDED
File without changes
@@ -0,0 +1,25 @@
1
+ type BuiltIn = "standard" | "website";
2
+ export type TranslateType = BuiltIn | (string & {});
3
+ interface InitOptions {
4
+ apiKey: string;
5
+ mcpUrl?: string;
6
+ name?: string;
7
+ version?: string;
8
+ defaultType?: TranslateType;
9
+ }
10
+ declare class T {
11
+ private static client;
12
+ private static ready;
13
+ private static defaultType;
14
+ /** Call once near app start */
15
+ static init(opts: InitOptions): Promise<void>;
16
+ /** Translate text – returns original text on failure */
17
+ static translate(text: string, targetLang: string, type?: TranslateType): Promise<string>;
18
+ }
19
+ declare global {
20
+ interface Window {
21
+ MboaAI?: any;
22
+ }
23
+ }
24
+ export { T };
25
+ export default T;
@@ -0,0 +1 @@
1
+ import{MCPClient as e}from"mcp-client";class a{static async init(t){if(!(null==t?void 0:t.apiKey))throw new Error("MboaAI-SDK: apiKey is required");if(a.ready)return;const{apiKey:r,mcpUrl:n="https://api.filparty.com:8001/mcp",name:o="MboaAI-SDK",version:i="1.0.0",defaultType:l="standard"}=t;a.client=new e({name:o,version:i}),await a.client.connect({type:"sse",url:n,headers:{"x-api-key":r}}),a.defaultType=l,a.ready=!0}static async translate(e,t,r){var n,o,i;if(!a.ready)throw new Error("MboaAI-SDK: call init() first");const l=`Translate "${e}" into ${t} for ${null!=r?r:a.defaultType}`;try{const t=await a.client.callTool({name:"run_translate",arguments:{message:l}}),r=String(null!==(i=null===(o=null===(n=null==t?void 0:t.content)||void 0===n?void 0:n[0])||void 0===o?void 0:o.text)&&void 0!==i?i:""),s=JSON.parse(r);return s.reply||s.text||e}catch(a){return console.error("[MboaAI-SDK] translate error → returning source",a),e}}}a.ready=!1,a.defaultType="standard","undefined"!=typeof window&&(window.MboaAI=window.MboaAI||{},window.MboaAI.T=a);export{a as T,a as default};
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("mcp-client")):"function"==typeof define&&define.amd?define(["exports","mcp-client"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).MboaAI={},e.mcpClient)}(this,(function(e,t){"use strict";class n{static async init(e){if(!(null==e?void 0:e.apiKey))throw new Error("MboaAI-SDK: apiKey is required");if(n.ready)return;const{apiKey:a,mcpUrl:i="https://api.filparty.com:8001/mcp",name:r="MboaAI-SDK",version:o="1.0.0",defaultType:l="standard"}=e;n.client=new t.MCPClient({name:r,version:o}),await n.client.connect({type:"sse",url:i,headers:{"x-api-key":a}}),n.defaultType=l,n.ready=!0}static async translate(e,t,a){var i,r,o;if(!n.ready)throw new Error("MboaAI-SDK: call init() first");const l=`Translate "${e}" into ${t} for ${null!=a?a:n.defaultType}`;try{const t=await n.client.callTool({name:"run_translate",arguments:{message:l}}),a=String(null!==(o=null===(r=null===(i=null==t?void 0:t.content)||void 0===i?void 0:i[0])||void 0===r?void 0:r.text)&&void 0!==o?o:""),d=JSON.parse(a);return d.reply||d.text||e}catch(t){return console.error("[MboaAI-SDK] translate error → returning source",t),e}}}n.ready=!1,n.defaultType="standard","undefined"!=typeof window&&(window.MboaAI=window.MboaAI||{},window.MboaAI.T=n),e.T=n,e.default=n,Object.defineProperty(e,"__esModule",{value:!0})}));
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "mboaai-sdk",
3
+ "version": "1.0.0",
4
+ "description": "Lightweight JavaScript SDK for calling MboaAI agents",
5
+ "main": "dist/mboaai-sdk.umd.js",
6
+ "module": "dist/mboaai-sdk.esm.js",
7
+ "types": "dist/index.d.ts",
8
+ "scripts": {
9
+ "build": "rollup -c",
10
+ "prepublishOnly": "npm run build"
11
+ },
12
+ "author": "Your Name",
13
+ "license": "MIT",
14
+ "dependencies": {
15
+ "mcp-client": "^1.2.0",
16
+ "tslib": "^2.8.1"
17
+ },
18
+ "devDependencies": {
19
+ "@rollup/plugin-commonjs": "^25",
20
+ "@rollup/plugin-node-resolve": "^15",
21
+ "@rollup/plugin-terser": "^0.4.4",
22
+ "@rollup/plugin-typescript": "^12.1.2",
23
+ "rollup": "^4",
24
+ "rollup-plugin-terser": "^7.0.2",
25
+ "typescript": "^5.8.3"
26
+ }
27
+ }
@@ -0,0 +1,20 @@
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 ADDED
@@ -0,0 +1,87 @@
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;
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2018",
4
+ "module": "ESNext",
5
+ "declaration": true,
6
+ "outDir": "dist",
7
+ "strict": true,
8
+ "esModuleInterop": true,
9
+ "skipLibCheck": true
10
+ },
11
+ "include": [
12
+ "src"
13
+ ]
14
+ }