import { NocoApi } from "@kevisual/noco"; import { columns } from "../common/base-table.ts"; type ReponseData = { code: number, message?: string, data?: T } export type CoreOptions = { nocoApi: NocoApi, baseId?: string } & T type CoreItem = { Id: number, 标题: string, 总结?: string, 启动时间?: string, 标签?: string, 任务?: string, // 运行中,已完成,未开始 链接?: string, 数据?: string, 类型?: string, 提示词?: string, 任务结果?: string, } export class Core { nocoApi: NocoApi; baseId?: string; key = 'core'; title = '默认表'; description = '默认表描述'; tableId?: string; constructor(opts: { nocoApi: NocoApi, baseId?: string, tableId?: string }) { this.nocoApi = opts.nocoApi; this.baseId = opts.baseId; this.tableId = opts.tableId; } async createTable(opts?: { columns?: any[], title?: string, description?: string, baseId?: string }): Promise> { const baseId = opts?.baseId ?? this.baseId!; const title = opts?.title ?? this.title; const description = opts?.description ?? this.description; const _columns = opts?.columns ?? columns; let tableId = ''; const res = await this.nocoApi.meta.tables.createTable(baseId, { title, description, columns: _columns, }) let code = 200; if (res.code !== 200) { const res = await this.nocoApi.meta.tables.list(baseId); const list = res.data?.list || []; const existTable = list.find(t => t.title === title); if (existTable) { tableId = existTable.id; } else { return { code: res.code, message: `创建表失败,且未找到同名表`, } } } else { tableId = res?.data?.id; } this.tableId = tableId; return { code, data: { id: tableId, title, } }; } getItem(id: number): Promise> { return this.nocoApi.record.read(id); } getList(params: any): Promise> { return this.nocoApi.record.list({ ...params, }); } updateItem(data: Partial) { return this.nocoApi.record.update(data); } }