This commit is contained in:
2026-02-05 19:37:55 +08:00
parent 9d811afeb4
commit ee56795461
5 changed files with 20 additions and 31 deletions

View File

@@ -1,24 +1,4 @@
import { resolvePath } from '@kevisual/use-config';
import { execSync } from 'node:child_process';
const buildFn = async (opts: { entry?: string, naming?: string }) => {
const entry = opts.entry || 'agent/opencode.ts';
const naming = opts.naming || 'opencode';
const external: string[] = ["bun", "ws"];
await Bun.build({
target: 'node',
format: 'esm',
entrypoints: [resolvePath(entry, { meta: import.meta })],
outdir: resolvePath('./dist', { meta: import.meta }),
naming: {
entry: `${naming}.js`,
},
external,
});
const cmd = `dts -i ${entry} -o ${naming}.d.ts`;
execSync(cmd);
};
await buildFn({ naming: 'opencode', entry: 'agent/opencode.ts' });
await buildFn({ naming: 'keep', entry: 'src/keep.ts' });
await buildFn({ naming: 'routes', entry: 'agent/index.ts' });
import { buildWithBun } from '@kevisual/code-builder'
await buildWithBun({ naming: 'opencode', entry: 'agent/opencode.ts', dts: true });
await buildWithBun({ naming: 'keep', entry: 'src/keep.ts', dts: true });
await buildWithBun({ naming: 'routes', entry: 'agent/index.ts', dts: true });

View File

@@ -1,6 +1,6 @@
{
"name": "@kevisual/cnb",
"version": "0.0.13",
"version": "0.0.14",
"description": "",
"main": "index.js",
"scripts": {
@@ -19,6 +19,7 @@
"type": "module",
"devDependencies": {
"@kevisual/ai": "^0.0.24",
"@kevisual/code-builder": "^0.0.6",
"@kevisual/context": "^0.0.4",
"@kevisual/types": "^0.0.12",
"@opencode-ai/plugin": "^1.1.44",

View File

@@ -5,6 +5,9 @@ export type CNBCoreOptions<T = {}> = {
*/
cookie?: string;
cnb?: CNBCore;
cors?: {
baseUrl?: string
}
} & T;
export type RequestOptions = {
@@ -19,6 +22,7 @@ export type RequestOptions = {
};
export class CNBCore {
baseURL = 'https://api.cnb.cool';
hackURL = 'https://cnb.cool'
public token: string;
public cookie?: string;
constructor(options: CNBCoreOptions) {
@@ -32,6 +36,10 @@ export class CNBCore {
this.cookie = options.cnb.cookie;
}
}
if (options?.cors?.baseUrl) {
this.baseURL = options.cors.baseUrl + '/' + this.baseURL;
this.hackURL = options.cors.baseUrl + '/' + this.hackURL;
}
}
async request({ url, method = 'GET', data, params, headers, body, useCookie, useOrigin }: RequestOptions): Promise<any> {

View File

@@ -23,7 +23,7 @@ export class Repo extends CNBCore {
return this.post({ url, data: postData });
}
deleteRepo(name: string): Promise<any> {
const url = `https://cnb.cool/${name}`;
const url = `${this.hackURL}/${name}`;
return this.delete({ url, useCookie: true });
}
async createCommit(repo: string, data: CreateCommitData): Promise<any> {
@@ -38,7 +38,7 @@ export class Repo extends CNBCore {
if (!data.parent_commit_sha && preCommitSha) {
data.parent_commit_sha = preCommitSha;
}
const url = `https://cnb.cool/${repo}/-/git/commits`;
const url = `${this.hackURL}/${repo}/-/git/commits`;
const postData: CreateCommitData = {
...data,
base_branch: data.base_branch || 'refs/heads/main',

View File

@@ -10,7 +10,7 @@ export class User extends CNBCore {
* @returns
*/
getCurrentUser(): Promise<Result<UserInfo>> {
const url = `https://cnb.cool/user`;
const url = `${this.hackURL}/user`;
return this.get({
url,
useCookie: true,
@@ -26,7 +26,7 @@ export class User extends CNBCore {
}
createAccessToken(data?: { description?: string, scope?: string }): Promise<AccessTokenResponse> {
const scope = data?.scope || 'mission-manage:rw,mission-delete:rw,group-delete:rw,group-manage:rw,group-resource:rw,account-engage:rw,account-email:r,account-profile:rw,registry-delete:rw,registry-manage:rw,registry-package-delete:rw,registry-package:rw,repo-security:r,repo-delete:rw,repo-manage:rw,repo-basic-info:r,repo-cnb-detail:rw,repo-cnb-history:r,repo-cnb-trigger:rw,repo-commit-status:rw,repo-contents:rw,repo-notes:rw,repo-issue:rw,repo-pr:rw,repo-code:rw'
const url = 'https://cnb.cool/user/personal_access_tokens'
const url = `${this.hackURL}/user/personal_access_tokens`
return this.post({
url,
useCookie: true,
@@ -37,7 +37,7 @@ export class User extends CNBCore {
})
}
getAccessTokens(params?: { page?: number, page_size?: number }): Promise<AccessTokenResponse[]> {
const url = 'https://cnb.cool/user/personal_access_tokens'
const url = `${this.hackURL}/user/personal_access_tokens`
return this.get({
url,
useCookie: true,
@@ -49,7 +49,7 @@ export class User extends CNBCore {
})
}
deleteAccessToken(tokenId: string): Promise<any> {
const url = `https://cnb.cool/user/personal_access_tokens/${tokenId}`
const url = `${this.hackURL}/user/personal_access_tokens/${tokenId}`
return this.delete({
url,
useCookie: true,