diff --git a/mod.ts b/mod.ts new file mode 100644 index 0000000..148c52e --- /dev/null +++ b/mod.ts @@ -0,0 +1 @@ +export * from './src/index.ts' \ No newline at end of file diff --git a/src/cnb-core.ts b/src/cnb-core.ts index 5bb37d5..c947e7a 100644 --- a/src/cnb-core.ts +++ b/src/cnb-core.ts @@ -51,7 +51,7 @@ export class CNBCore { _headers['Cookie'] = this.cookie || ""; delete _headers.Authorization; } - console.log('Request URL:', url, data, _headers); + // console.log('Request URL:', url, data, _headers); const response = await fetch(url || '', { method, headers: _headers, diff --git a/src/index.ts b/src/index.ts index a65ce76..810dc53 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,10 +1,29 @@ -import { CNBCore, CNBCoreOptions } from "./cnb-core"; -import { Workspace } from "./workspace"; +import { CNBCore, CNBCoreOptions } from "./cnb-core.ts"; +import { Workspace } from "./workspace.ts"; +import { KnowledgeBase } from "./knowledge/index.ts"; +import { Repo } from "./repo/index.ts"; +import { User } from "./user/index.ts"; + type CNBOptions = CNBCoreOptions<{}>; + export class CNB extends CNBCore { - workspace: Workspace; + workspace!: Workspace; + knowledgeBase!: KnowledgeBase; + repo!: Repo; + user!: User; constructor(options: CNBOptions) { - super({ token: options.token }); - this.workspace = new Workspace(options.token); + super({ token: options.token, cookie: options.cookie }); + this.init(options); } -} \ No newline at end of file + init(options: CNBOptions) { + this.workspace = new Workspace(options.token); + this.knowledgeBase = new KnowledgeBase({ token: options.token, cookie: options.cookie }); + this.repo = new Repo({ token: options.token, cookie: options.cookie }); + this.user = new User({ token: options.token, cookie: options.cookie }); + } +} + +export * from './workspace.ts' +export * from './cnb-core.ts' +export * from './knowledge/index.ts' +export * from './repo/index.ts' diff --git a/src/knowledge/index.ts b/src/knowledge/index.ts new file mode 100644 index 0000000..f43263b --- /dev/null +++ b/src/knowledge/index.ts @@ -0,0 +1,55 @@ +import { CNBCore, CNBCoreOptions, RequestOptions, Result } from "../cnb-core.ts"; + +type RepoOptions = CNBCoreOptions<{ + group?: string; +}> +export class KnowledgeBase extends CNBCore { + group: string; + constructor(options: RepoOptions) { + super({ token: options.token, cookie: options.cookie }); + this.group = options.group || ''; + } + + queryKnowledgeBase(repo: string, data: { + query: string, + score_threshold?: number, + top_k?: number, + metadata_filtering_conditions?: MetadataFilteringConditions + }): Promise { + const group = this.group || ''; + const url = `/${group}/${repo}/-/knowledge/query`; + let postData = { + query: data.query, + }; + return this.post({ url, data: postData }); + } + getEmbeddingModels(repo: string): Promise>> { + const group = this.group || ''; + const url = `/${group}/${repo}/-/knowledge/embedding/models`; + // bg3-m3 1024 + // hunyuan 1024 + return this.get({ url }); + } + getBase(repo: string): Promise> { + const group = this.group || ''; + const url = `/${group}/${repo}/-/knowledge/base`; + return this.get({ url }); + } + deleteBase(repo: string): Promise> { + const group = this.group || ''; + const url = `/${group}/${repo}/-/knowledge/base`; + return this.request({ url, method: 'DELETE' }); + } +} + +type MetadataFilteringConditions = { + conditions: Array<{ + comparison_operator?: 'is' | 'is not' | 'contains' | 'not contains' | 'start with' | 'end with' | 'is empty' | 'is not empty'; + name?: "position" | "path" | "type", + /** + * "is empty" and "is not empty" 时候忽略该字段 + */ + value?: string + }> + logical_operator?: 'adn' | 'or' +} \ No newline at end of file diff --git a/src/repo/index.ts b/src/repo/index.ts index e0b999f..1aee95c 100644 --- a/src/repo/index.ts +++ b/src/repo/index.ts @@ -1,4 +1,4 @@ -import { CNBCore, CNBCoreOptions, RequestOptions, Result } from "../cnb-core"; +import { CNBCore, CNBCoreOptions, RequestOptions, Result } from "../cnb-core.ts"; type RepoOptions = CNBCoreOptions<{ group?: string; diff --git a/src/user/index.ts b/src/user/index.ts index 2b3aaff..182e8b8 100644 --- a/src/user/index.ts +++ b/src/user/index.ts @@ -1,4 +1,4 @@ -import { CNBCore, CNBCoreOptions } from "../cnb-core"; +import { CNBCore, CNBCoreOptions } from "../cnb-core.ts"; export class User extends CNBCore { constructor(options: CNBCoreOptions<{}>) { diff --git a/src/workspace.ts b/src/workspace.ts index 5077f5b..fef5467 100644 --- a/src/workspace.ts +++ b/src/workspace.ts @@ -5,7 +5,7 @@ * @createdAt 2025-12-04 */ -import { CNBCore } from "./cnb-core"; +import { CNBCore } from "./cnb-core.ts"; /** * 工作空间列表查询参数 diff --git a/test/knowledge.ts b/test/knowledge.ts new file mode 100644 index 0000000..aa7ba00 --- /dev/null +++ b/test/knowledge.ts @@ -0,0 +1,10 @@ +import { KnowledgeBase } from "../src/knowledge/index.ts"; + +import { token, showMore, cookie } from "./common.ts"; + +const repo = new KnowledgeBase({ group: "kevisual/demo", token: token, cookie: cookie }); +const repoName = "test-cnb"; + +const queryRes = await repo.getEmbeddingModels(repoName); + +console.log("queryRes", showMore(queryRes));