@botonic/plugin-knowledge-bases 0.23.0-alpha.1 → 0.23.1-alpha.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 +73 -0
- package/lib/cjs/hubtype-knowledge-api-service.d.ts +8 -2
- package/lib/cjs/hubtype-knowledge-api-service.js +1 -0
- package/lib/cjs/hubtype-knowledge-api-service.js.map +1 -1
- package/lib/cjs/index.d.ts +2 -2
- package/lib/cjs/index.js +14 -6
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/types.d.ts +6 -3
- package/lib/esm/hubtype-knowledge-api-service.d.ts +8 -2
- package/lib/esm/hubtype-knowledge-api-service.js +1 -0
- package/lib/esm/hubtype-knowledge-api-service.js.map +1 -1
- package/lib/esm/index.d.ts +2 -2
- package/lib/esm/index.js +14 -6
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/types.d.ts +6 -3
- package/package.json +2 -2
- package/src/hubtype-knowledge-api-service.ts +11 -3
- package/src/index.ts +18 -7
- package/src/types.ts +6 -3
package/README.md
CHANGED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Botonic Plugin Knowledge Bases
|
|
2
|
+
|
|
3
|
+
## What Does This Plugin Do?
|
|
4
|
+
|
|
5
|
+
This plugin allows you to integrate Hubtype Knowledge bases in your Botonic project. It works like any other AI services plugin, like Hubtype Babel, Dialogflow, Watson, etc.
|
|
6
|
+
|
|
7
|
+
## Setup
|
|
8
|
+
|
|
9
|
+
1. Install the plugin from npm (or yarn):
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
npm i --save @botonic/plugin-hubtype-knowledge-bases
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
2. Add it to the `src/plugins.js` file defining the projectId of the Project you want to use:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
export const plugins = [
|
|
19
|
+
{
|
|
20
|
+
id: 'hubtype-knowledge-bases',
|
|
21
|
+
resolve: require('@botonic/plugin-hubtype-knowledge-bases'),
|
|
22
|
+
options: {
|
|
23
|
+
knowledgeBaseId: '6800762a-03b5-419e-be97-67feac7bc5b9',
|
|
24
|
+
host: 'https://www.api.hubtype.com'
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
]
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Use
|
|
31
|
+
|
|
32
|
+
The plugin response contains 3 attributes ai, hasKnowledge, sources. If hasKnowledge is true the response will be in ai and source will be the name of the document from which the response was obtained. If the hasKnowledge parameter is false then it does not have enough knowledge to answer and in that case the answer should not be shown to the user.
|
|
33
|
+
|
|
34
|
+
You can use it in your actions:
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import React from 'react'
|
|
38
|
+
import { Text } from '@botonic/react'
|
|
39
|
+
|
|
40
|
+
export default class OrderLocation extends React.Component {
|
|
41
|
+
static async botonicInit(request) {
|
|
42
|
+
const knowledgePlugin = request.plugins.knwoledgePlugin
|
|
43
|
+
const response = await knowladgeBasePlugin.getIaResponse(request.session)
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
text: response.hasKnowledge
|
|
47
|
+
? response.ai
|
|
48
|
+
: "I don't know what you're talking about",
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
render() {
|
|
52
|
+
return <Text>{this.props.text}</Text>
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Plugin Options
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
interface PluginKnowledgeBaseOptions {
|
|
61
|
+
knowledgeBaseId: string
|
|
62
|
+
host: string
|
|
63
|
+
authToken?: string
|
|
64
|
+
timeout?: number
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
- **`knowledgeBaseId`**: Id of the knowledge base previously uploaded to the desk under ai/knowledgebases.
|
|
69
|
+
- **`[host]`**: Host uri where to request inference.
|
|
70
|
+
- Default: *https://api.hubtype.com.*
|
|
71
|
+
- **`[authToken]`**: Authorization Token to being able to run inference. Only needed when using the plugin locally.
|
|
72
|
+
- **`[timeout]`**: timeout of the call to the knowledgebases inferrence endpoint.
|
|
73
|
+
- Default: 10 seconds
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
|
-
import { KnowledgebaseResppnse } from './types';
|
|
3
2
|
export declare class HubtypeApiService {
|
|
4
3
|
private knowledgeBaseId;
|
|
5
4
|
private host;
|
|
6
5
|
private timeout;
|
|
7
6
|
constructor(knowledgeBaseId: string, host: string, timeout?: number);
|
|
8
|
-
inference(authToken: string, chatId: string): Promise<AxiosResponse<
|
|
7
|
+
inference(authToken: string, chatId: string): Promise<AxiosResponse<{
|
|
8
|
+
ai: string;
|
|
9
|
+
has_knowledge: boolean;
|
|
10
|
+
sources: {
|
|
11
|
+
knowledge_source_id: string;
|
|
12
|
+
page?: number;
|
|
13
|
+
}[];
|
|
14
|
+
}>>;
|
|
9
15
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HubtypeApiService = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
5
6
|
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
6
7
|
const DEFAULT_TIMEOUT = 10000;
|
|
7
8
|
class HubtypeApiService {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hubtype-knowledge-api-service.js","sourceRoot":"","sources":["../../src/hubtype-knowledge-api-service.ts"],"names":[],"mappings":";;;;AAAA,0DAA4C;
|
|
1
|
+
{"version":3,"file":"hubtype-knowledge-api-service.js","sourceRoot":"","sources":["../../src/hubtype-knowledge-api-service.ts"],"names":[],"mappings":";;;;AAAA,yDAAyD;AACzD,0DAA4C;AAE5C,MAAM,eAAe,GAAG,KAAK,CAAA;AAE7B,MAAa,iBAAiB;IAK5B,YAAY,eAAuB,EAAE,IAAY,EAAE,OAAgB;QACjE,IAAI,CAAC,eAAe,GAAG,eAAe,CAAA;QACtC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,eAAe,CAAA;IAC3C,CAAC;IAED,KAAK,CAAC,SAAS,CACb,SAAiB,EACjB,MAAc;QAWd,OAAO,MAAM,IAAA,eAAK,EAAC;YACjB,MAAM,EAAE,MAAM;YACd,GAAG,EAAE,GAAG,IAAI,CAAC,IAAI,0BAA0B,IAAI,CAAC,eAAe,aAAa;YAC5E,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,SAAS,EAAE;gBACpC,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE;YACzB,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC,CAAA;IACJ,CAAC;CACF;AAnCD,8CAmCC"}
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { HubtypeSession, Plugin, PluginPreRequest } from '@botonic/core';
|
|
2
|
-
import {
|
|
2
|
+
import { KnowledgeBaseResponse, PluginKnowledgeBaseOptions } from './types';
|
|
3
3
|
export default class BotonicPluginKnowledgeBases implements Plugin {
|
|
4
4
|
private readonly apiService;
|
|
5
5
|
private readonly authToken;
|
|
6
6
|
constructor(options: PluginKnowledgeBaseOptions);
|
|
7
7
|
pre(_request: PluginPreRequest): Promise<void>;
|
|
8
|
-
|
|
8
|
+
getInference(session: HubtypeSession): Promise<KnowledgeBaseResponse>;
|
|
9
9
|
}
|
|
10
10
|
export { PluginKnowledgeBaseOptions } from './types';
|
package/lib/cjs/index.js
CHANGED
|
@@ -10,18 +10,26 @@ class BotonicPluginKnowledgeBases {
|
|
|
10
10
|
async pre(_request) {
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
|
-
async
|
|
13
|
+
async getInference(session) {
|
|
14
14
|
try {
|
|
15
|
-
console.log({ isProd });
|
|
16
15
|
const authToken = isProd ? session._access_token : this.authToken;
|
|
17
16
|
const response = await this.apiService.inference(authToken, session.user.id);
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
const sources = response.data.sources.map(source => {
|
|
18
|
+
return {
|
|
19
|
+
knowledgeSourceId: source.knowledge_source_id,
|
|
20
|
+
page: source.page,
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
return {
|
|
24
|
+
ai: response.data.ai,
|
|
25
|
+
hasKnowledge: response.data.has_knowledge,
|
|
26
|
+
sources,
|
|
27
|
+
};
|
|
20
28
|
}
|
|
21
29
|
catch (e) {
|
|
22
|
-
console.
|
|
30
|
+
console.error(e);
|
|
23
31
|
return {
|
|
24
|
-
|
|
32
|
+
ai: '',
|
|
25
33
|
hasKnowledge: false,
|
|
26
34
|
sources: [],
|
|
27
35
|
};
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;AAEA,mFAAmE;AAGnE,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAA;AAEpD,MAAqB,2BAA2B;IAI9C,YAAY,OAAmC;QAC7C,IAAI,CAAC,UAAU,GAAG,IAAI,iDAAiB,CACrC,OAAO,CAAC,eAAe,EACvB,OAAO,CAAC,IAAI,EACZ,OAAO,CAAC,OAAO,CAChB,CAAA;QACD,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,EAAE,CAAA;IAC1C,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,QAA0B;QAClC,OAAM;IACR,CAAC;IAED,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;AAEA,mFAAmE;AAGnE,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAA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geBaseOptions {
|
|
|
4
4
|
authToken?: string;
|
|
5
5
|
timeout?: number;
|
|
6
6
|
}
|
|
7
|
-
export interface
|
|
8
|
-
|
|
7
|
+
export interface KnowledgeBaseResponse {
|
|
8
|
+
ai: string;
|
|
9
9
|
hasKnowledge: boolean;
|
|
10
|
-
sources:
|
|
10
|
+
sources: {
|
|
11
|
+
knowledgeSourceId: string;
|
|
12
|
+
page?: number;
|
|
13
|
+
}[];
|
|
11
14
|
}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
|
-
import { KnowledgebaseResppnse } from './types';
|
|
3
2
|
export declare class HubtypeApiService {
|
|
4
3
|
private knowledgeBaseId;
|
|
5
4
|
private host;
|
|
6
5
|
private timeout;
|
|
7
6
|
constructor(knowledgeBaseId: string, host: string, timeout?: number);
|
|
8
|
-
inference(authToken: string, chatId: string): Promise<AxiosResponse<
|
|
7
|
+
inference(authToken: string, chatId: string): Promise<AxiosResponse<{
|
|
8
|
+
ai: string;
|
|
9
|
+
has_knowledge: boolean;
|
|
10
|
+
sources: {
|
|
11
|
+
knowledge_source_id: string;
|
|
12
|
+
page?: number;
|
|
13
|
+
}[];
|
|
14
|
+
}>>;
|
|
9
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hubtype-knowledge-api-service.js","sourceRoot":"","sources":["../../src/hubtype-knowledge-api-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAwB,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"hubtype-knowledge-api-service.js","sourceRoot":"","sources":["../../src/hubtype-knowledge-api-service.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,OAAO,KAAwB,MAAM,OAAO,CAAA;AAE5C,MAAM,eAAe,GAAG,KAAK,CAAA;AAE7B,MAAM,OAAO,iBAAiB;IAK5B,YAAY,eAAuB,EAAE,IAAY,EAAE,OAAgB;QACjE,IAAI,CAAC,eAAe,GAAG,eAAe,CAAA;QACtC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,eAAe,CAAA;IAC3C,CAAC;IAED,KAAK,CAAC,SAAS,CACb,SAAiB,EACjB,MAAc;QAWd,OAAO,MAAM,KAAK,CAAC;YACjB,MAAM,EAAE,MAAM;YACd,GAAG,EAAE,GAAG,IAAI,CAAC,IAAI,0BAA0B,IAAI,CAAC,eAAe,aAAa;YAC5E,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,SAAS,EAAE;gBACpC,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE;YACzB,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC,CAAA;IACJ,CAAC;CACF"}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { HubtypeSession, Plugin, PluginPreRequest } from '@botonic/core';
|
|
2
|
-
import {
|
|
2
|
+
import { KnowledgeBaseResponse, PluginKnowledgeBaseOptions } from './types';
|
|
3
3
|
export default class BotonicPluginKnowledgeBases implements Plugin {
|
|
4
4
|
private readonly apiService;
|
|
5
5
|
private readonly authToken;
|
|
6
6
|
constructor(options: PluginKnowledgeBaseOptions);
|
|
7
7
|
pre(_request: PluginPreRequest): Promise<void>;
|
|
8
|
-
|
|
8
|
+
getInference(session: HubtypeSession): Promise<KnowledgeBaseResponse>;
|
|
9
9
|
}
|
|
10
10
|
export { PluginKnowledgeBaseOptions } from './types';
|
package/lib/esm/index.js
CHANGED
|
@@ -8,18 +8,26 @@ export default class BotonicPluginKnowledgeBases {
|
|
|
8
8
|
async pre(_request) {
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
|
-
async
|
|
11
|
+
async getInference(session) {
|
|
12
12
|
try {
|
|
13
|
-
console.log({ isProd });
|
|
14
13
|
const authToken = isProd ? session._access_token : this.authToken;
|
|
15
14
|
const response = await this.apiService.inference(authToken, session.user.id);
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
const sources = response.data.sources.map(source => {
|
|
16
|
+
return {
|
|
17
|
+
knowledgeSourceId: source.knowledge_source_id,
|
|
18
|
+
page: source.page,
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
return {
|
|
22
|
+
ai: response.data.ai,
|
|
23
|
+
hasKnowledge: response.data.has_knowledge,
|
|
24
|
+
sources,
|
|
25
|
+
};
|
|
18
26
|
}
|
|
19
27
|
catch (e) {
|
|
20
|
-
console.
|
|
28
|
+
console.error(e);
|
|
21
29
|
return {
|
|
22
|
-
|
|
30
|
+
ai: '',
|
|
23
31
|
hasKnowledge: false,
|
|
24
32
|
sources: [],
|
|
25
33
|
};
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AAGnE,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAA;AAEpD,MAAM,CAAC,OAAO,OAAO,2BAA2B;IAI9C,YAAY,OAAmC;QAC7C,IAAI,CAAC,UAAU,GAAG,IAAI,iBAAiB,CACrC,OAAO,CAAC,eAAe,EACvB,OAAO,CAAC,IAAI,EACZ,OAAO,CAAC,OAAO,CAChB,CAAA;QACD,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,EAAE,CAAA;IAC1C,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,QAA0B;QAClC,OAAM;IACR,CAAC;IAED,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AAGnE,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,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BaseOptions {
|
|
|
4
4
|
authToken?: string;
|
|
5
5
|
timeout?: number;
|
|
6
6
|
}
|
|
7
|
-
export interface
|
|
8
|
-
|
|
7
|
+
export interface KnowledgeBaseResponse {
|
|
8
|
+
ai: string;
|
|
9
9
|
hasKnowledge: boolean;
|
|
10
|
-
sources:
|
|
10
|
+
sources: {
|
|
11
|
+
knowledgeSourceId: string;
|
|
12
|
+
page?: number;
|
|
13
|
+
}[];
|
|
11
14
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botonic/plugin-knowledge-bases",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.1-alpha.0",
|
|
4
4
|
"description": "Use a Hubtype to make the bot respond through a knowledge base.",
|
|
5
5
|
"main": "./lib/cjs/index.js",
|
|
6
6
|
"module": "./lib/esm/index.js",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@babel/runtime": "^7.22.5",
|
|
32
|
-
"@botonic/core": "
|
|
32
|
+
"@botonic/core": "0.23.1-alpha.0",
|
|
33
33
|
"axios": "^1.4.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
1
2
|
import axios, { AxiosResponse } from 'axios'
|
|
2
3
|
|
|
3
|
-
import { KnowledgebaseResppnse } from './types'
|
|
4
|
-
|
|
5
4
|
const DEFAULT_TIMEOUT = 10000
|
|
6
5
|
|
|
7
6
|
export class HubtypeApiService {
|
|
@@ -18,7 +17,16 @@ export class HubtypeApiService {
|
|
|
18
17
|
async inference(
|
|
19
18
|
authToken: string,
|
|
20
19
|
chatId: string
|
|
21
|
-
): Promise<
|
|
20
|
+
): Promise<
|
|
21
|
+
AxiosResponse<{
|
|
22
|
+
ai: string
|
|
23
|
+
has_knowledge: boolean
|
|
24
|
+
sources: {
|
|
25
|
+
knowledge_source_id: string
|
|
26
|
+
page?: number
|
|
27
|
+
}[]
|
|
28
|
+
}>
|
|
29
|
+
> {
|
|
22
30
|
return await axios({
|
|
23
31
|
method: 'POST',
|
|
24
32
|
url: `${this.host}/v1/ai/knowledge_bases/${this.knowledgeBaseId}/inference/`,
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HubtypeSession, Plugin, PluginPreRequest } from '@botonic/core'
|
|
2
2
|
|
|
3
3
|
import { HubtypeApiService } from './hubtype-knowledge-api-service'
|
|
4
|
-
import {
|
|
4
|
+
import { KnowledgeBaseResponse, PluginKnowledgeBaseOptions } from './types'
|
|
5
5
|
|
|
6
6
|
const isProd = process.env.NODE_ENV === 'production'
|
|
7
7
|
|
|
@@ -22,20 +22,31 @@ export default class BotonicPluginKnowledgeBases implements Plugin {
|
|
|
22
22
|
return
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
async
|
|
25
|
+
async getInference(session: HubtypeSession): Promise<KnowledgeBaseResponse> {
|
|
26
26
|
try {
|
|
27
|
-
console.log({ isProd })
|
|
28
27
|
const authToken = isProd ? session._access_token : this.authToken
|
|
28
|
+
|
|
29
29
|
const response = await this.apiService.inference(
|
|
30
30
|
authToken,
|
|
31
31
|
session.user.id
|
|
32
32
|
)
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
|
|
34
|
+
const sources = response.data.sources.map(source => {
|
|
35
|
+
return {
|
|
36
|
+
knowledgeSourceId: source.knowledge_source_id,
|
|
37
|
+
page: source.page,
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
ai: response.data.ai,
|
|
43
|
+
hasKnowledge: response.data.has_knowledge,
|
|
44
|
+
sources,
|
|
45
|
+
}
|
|
35
46
|
} catch (e) {
|
|
36
|
-
console.
|
|
47
|
+
console.error(e)
|
|
37
48
|
return {
|
|
38
|
-
|
|
49
|
+
ai: '',
|
|
39
50
|
hasKnowledge: false,
|
|
40
51
|
sources: [],
|
|
41
52
|
}
|
package/src/types.ts
CHANGED
|
@@ -5,8 +5,11 @@ export interface PluginKnowledgeBaseOptions {
|
|
|
5
5
|
timeout?: number
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
export interface
|
|
9
|
-
|
|
8
|
+
export interface KnowledgeBaseResponse {
|
|
9
|
+
ai: string
|
|
10
10
|
hasKnowledge: boolean
|
|
11
|
-
sources:
|
|
11
|
+
sources: {
|
|
12
|
+
knowledgeSourceId: string
|
|
13
|
+
page?: number
|
|
14
|
+
}[]
|
|
12
15
|
}
|