@xyd-js/ask-ai-widget 0.0.0-build-be800ef-20251021211339 → 0.0.0-build-66ba948-20251024195101
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/server-standalone.js +7 -7
- package/dist/server.js +86615 -45570
- package/dist/widget.js +41 -41
- package/package.json +3 -3
- package/server.ts +9 -7
- package/src/Widget.tsx +3 -1
- package/src/index.ts +2 -2
- package/src/settings.ts +3 -3
- package/src/utils.ts +4 -4
- package/widget.tsx +6 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyd-js/ask-ai-widget",
|
|
3
|
-
"version": "0.0.0-build-
|
|
3
|
+
"version": "0.0.0-build-66ba948-20251024195101",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/server.js",
|
|
6
6
|
"files": [
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"express": "^4.18.2",
|
|
18
18
|
"react": "^19.0.0",
|
|
19
19
|
"react-dom": "^19.0.0",
|
|
20
|
-
"@xyd-js/ask-ai": "0.0.0-build-
|
|
20
|
+
"@xyd-js/ask-ai": "0.0.0-build-66ba948-20251024195101",
|
|
21
21
|
"@xyd-js/cli-sdk": "0.1.0-build.0",
|
|
22
|
-
"@xyd-js/mcp-server": "0.0.0-build-
|
|
22
|
+
"@xyd-js/mcp-server": "0.0.0-build-66ba948-20251024195101"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"openapi-typescript": "^7.9.1"
|
package/server.ts
CHANGED
|
@@ -5,16 +5,18 @@ import { loadSetting } from "./src/utils";
|
|
|
5
5
|
|
|
6
6
|
loadSetting()
|
|
7
7
|
.then((settings) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
8
|
+
const openApiSource = settings.sources?.openapi || "";
|
|
9
|
+
const llmsTxtSource = settings.sources?.llmsTxt || "";
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
console.warn("Open API source is not set");
|
|
11
|
+
if (!llmsTxtSource && !openApiSource) {
|
|
12
|
+
console.warn("llms txt or open api source is not set");
|
|
15
13
|
}
|
|
16
14
|
|
|
17
|
-
const mcpServer = new MCPServer(
|
|
15
|
+
const mcpServer = new MCPServer({
|
|
16
|
+
uniformSources: openApiSource,
|
|
17
|
+
llmsSources: llmsTxtSource,
|
|
18
|
+
openAIApiKey: process.env.OPENAI_API_KEY || "", // TODO: configurable
|
|
19
|
+
});
|
|
18
20
|
|
|
19
21
|
return startServer(settings, mcpServer);
|
|
20
22
|
})
|
package/src/Widget.tsx
CHANGED
|
@@ -6,6 +6,7 @@ import { AskAI, useAskAI } from "@xyd-js/ask-ai/react";
|
|
|
6
6
|
|
|
7
7
|
interface WidgetConfig {
|
|
8
8
|
endpointURL?: string;
|
|
9
|
+
dockInput: boolean;
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
interface AskWidgetProps {
|
|
@@ -50,6 +51,7 @@ export function AskWidget({ config = {} }: AskWidgetProps) {
|
|
|
50
51
|
onSubmit={submit as any}
|
|
51
52
|
disabled={disabled}
|
|
52
53
|
placeholder={getPlaceholder()}
|
|
54
|
+
dockInput={config?.dockInput || undefined}
|
|
53
55
|
ref={ref}
|
|
54
56
|
>
|
|
55
57
|
<div slot="title">
|
|
@@ -80,5 +82,5 @@ export function AskWidget({ config = {} }: AskWidgetProps) {
|
|
|
80
82
|
}
|
|
81
83
|
|
|
82
84
|
function _Message({ message }: { message: string }) {
|
|
83
|
-
return <ProseMd content={message} />;
|
|
85
|
+
return <ProseMd languges={['javascript', 'jsx', 'tsx', 'ts', 'txt', 'md', 'mdx', 'bash']} content={message} />;
|
|
84
86
|
}
|
package/src/index.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { join, dirname } from "node:path";
|
|
|
3
3
|
import { createServer } from "node:http";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
|
|
6
|
-
import { Router } from 'express';
|
|
7
6
|
import express from "express";
|
|
8
7
|
|
|
9
8
|
import { handler as askAiHandler } from "@xyd-js/ask-ai/node";
|
|
@@ -66,7 +65,8 @@ export async function startServer(
|
|
|
66
65
|
body: body,
|
|
67
66
|
});
|
|
68
67
|
|
|
69
|
-
|
|
68
|
+
// TODO: check if it works
|
|
69
|
+
let mcpUrl = settings.mcp?.url || request.url + "/mcp";
|
|
70
70
|
if (Array.isArray(mcpUrl)) {
|
|
71
71
|
console.warn("MCP as array is not supported, using the first one");
|
|
72
72
|
mcpUrl = mcpUrl[0];
|
package/src/settings.ts
CHANGED
|
@@ -61,12 +61,12 @@ export interface Sources {
|
|
|
61
61
|
* @example "http://localhost:3000/openapi.yaml"
|
|
62
62
|
* @example ["http://localhost:3000/openapi.yaml", "./openapi.yaml"]
|
|
63
63
|
*/
|
|
64
|
-
openapi
|
|
64
|
+
openapi?: string | string[];
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
|
-
* The LLMs sources to use
|
|
67
|
+
* The LLMs txt sources to use
|
|
68
68
|
* @example "http://localhost:3000/llms.tx"
|
|
69
69
|
* @example ["http://localhost:3000/llms.txt", "./llms.txt"]
|
|
70
70
|
*/
|
|
71
|
-
|
|
71
|
+
llmsTxt?: string | string[];
|
|
72
72
|
}
|
package/src/utils.ts
CHANGED
|
@@ -61,7 +61,7 @@ function ensureSettings(settings: Settings) {
|
|
|
61
61
|
if (!settings.sources) {
|
|
62
62
|
settings.sources = {
|
|
63
63
|
openapi: "",
|
|
64
|
-
|
|
64
|
+
llmsTxt: "",
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
67
|
|
|
@@ -70,9 +70,9 @@ function ensureSettings(settings: Settings) {
|
|
|
70
70
|
console.log("(env settings): using OPENAPI_SOURCE");
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
if (process.env.
|
|
74
|
-
settings.sources.
|
|
75
|
-
console.log("(env settings): using
|
|
73
|
+
if (process.env.LLMS_TXT_SOURCE) {
|
|
74
|
+
settings.sources.llmsTxt = process.env.LLMS_TXT_SOURCE;
|
|
75
|
+
console.log("(env settings): using LLMS_TXT_SOURCE");
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
if (process.env.MCP_URL) {
|
package/widget.tsx
CHANGED
|
@@ -9,8 +9,13 @@ import { AskWidget } from "./src/Widget";
|
|
|
9
9
|
// Extract data attributes
|
|
10
10
|
const config = {
|
|
11
11
|
askAiServer: resolveServerUrl(currentScript),
|
|
12
|
+
dockInput: true,
|
|
12
13
|
};
|
|
13
14
|
|
|
15
|
+
if (currentScript?.dataset["dockInput"] === "false") {
|
|
16
|
+
config.dockInput = false;
|
|
17
|
+
}
|
|
18
|
+
|
|
14
19
|
// Create a container div and append it to body
|
|
15
20
|
const container = document.createElement("div");
|
|
16
21
|
container.id = "xyd-ask-ai-widget";
|
|
@@ -22,6 +27,7 @@ import { AskWidget } from "./src/Widget";
|
|
|
22
27
|
<AskWidget
|
|
23
28
|
config={{
|
|
24
29
|
endpointURL: `${config.askAiServer}/ask`,
|
|
30
|
+
dockInput: config.dockInput,
|
|
25
31
|
}}
|
|
26
32
|
/>
|
|
27
33
|
);
|