@kevisual/cnb 0.0.53 → 0.0.54

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/opencode.js CHANGED
@@ -2339,7 +2339,7 @@ var require_src = __commonJS((exports) => {
2339
2339
  };
2340
2340
  });
2341
2341
 
2342
- // ../../node_modules/.pnpm/@kevisual+router@0.1.3/node_modules/@kevisual/router/dist/router.js
2342
+ // ../../node_modules/.pnpm/@kevisual+router@0.1.6/node_modules/@kevisual/router/dist/router.js
2343
2343
  import { createRequire as createRequire2 } from "node:module";
2344
2344
  import { webcrypto as crypto } from "node:crypto";
2345
2345
  import url2 from "node:url";
@@ -19854,7 +19854,7 @@ class QueryRouter {
19854
19854
  console.error("=====debug====:", e);
19855
19855
  console.error("=====debug====:[path:key]:", `${route.path}-${route.key}`);
19856
19856
  }
19857
- if (e instanceof CustomError) {
19857
+ if (e instanceof CustomError || e?.code) {
19858
19858
  ctx.code = e.code;
19859
19859
  ctx.message = e.message;
19860
19860
  } else {
@@ -20117,6 +20117,39 @@ class QueryRouterServer extends QueryRouter {
20117
20117
  const { path, key, id } = api2;
20118
20118
  return this.run({ path, key, id, payload }, ctx);
20119
20119
  }
20120
+ async createAuth(fun) {
20121
+ this.route({
20122
+ path: "auth",
20123
+ key: "auth",
20124
+ id: "auth",
20125
+ description: "token验证"
20126
+ }).define(async (ctx) => {
20127
+ if (fun) {
20128
+ await fun(ctx, "auth");
20129
+ }
20130
+ }).addTo(this, { overwrite: false });
20131
+ this.route({
20132
+ path: "auth-admin",
20133
+ key: "auth-admin",
20134
+ id: "auth-admin",
20135
+ description: "admin token验证",
20136
+ middleware: ["auth"]
20137
+ }).define(async (ctx) => {
20138
+ if (fun) {
20139
+ await fun(ctx, "auth-admin");
20140
+ }
20141
+ }).addTo(this, { overwrite: false });
20142
+ this.route({
20143
+ path: "auth-can",
20144
+ key: "auth-can",
20145
+ id: "auth-can",
20146
+ description: "权限验证"
20147
+ }).define(async (ctx) => {
20148
+ if (fun) {
20149
+ await fun(ctx, "auth-can");
20150
+ }
20151
+ }).addTo(this, { overwrite: false });
20152
+ }
20120
20153
  }
20121
20154
  var isNode2 = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
20122
20155
  var isBrowser2 = typeof window !== "undefined" && typeof document !== "undefined" && typeof document.createElement === "function";
@@ -22927,6 +22960,22 @@ class Issue extends CNBCore {
22927
22960
  }
22928
22961
  }
22929
22962
 
22963
+ // src/mission/modules/resources.ts
22964
+ var queryResources = async (cnb, opts) => {
22965
+ const url3 = `${cnb.hackURL}/${opts?.repo || "kevisual/projects"}/-/mission-resource/resources`;
22966
+ return cnb.post({
22967
+ url: url3,
22968
+ data: {
22969
+ selectors: opts?.selectors,
22970
+ slugName: opts?.repo
22971
+ },
22972
+ headers: {
22973
+ Accept: "application/vnd.cnb.web+json"
22974
+ },
22975
+ useCookie: true
22976
+ });
22977
+ };
22978
+
22930
22979
  // src/mission/index.ts
22931
22980
  class Mission extends CNBCore {
22932
22981
  constructor(options) {
@@ -22989,6 +23038,9 @@ class Mission extends CNBCore {
22989
23038
  params: { visibility }
22990
23039
  });
22991
23040
  }
23041
+ queryResources(repo, selectors) {
23042
+ return queryResources(this, { repo, selectors });
23043
+ }
22992
23044
  }
22993
23045
 
22994
23046
  // src/ai/index.ts
@@ -44851,6 +44903,169 @@ app.route({
44851
44903
  const res = await cnb.repo.updateRepoInfo(name15, { description, license, site, topics });
44852
44904
  ctx.forward(res);
44853
44905
  }).addTo(app);
44906
+ app.route({
44907
+ path: "cnb",
44908
+ key: "update-repo-visibility",
44909
+ description: "更新代码仓库的可见性, 参数name, visibility",
44910
+ middleware: ["auth"],
44911
+ metadata: {
44912
+ args: {
44913
+ name: tool.schema.string().describe("代码仓库名称"),
44914
+ visibility: tool.schema.string().describe("代码仓库可见性, public 或 private 或 protected")
44915
+ }
44916
+ }
44917
+ }).define(async (ctx) => {
44918
+ const cnb = await cnbManager.getContext(ctx);
44919
+ const name15 = ctx.query?.name;
44920
+ const visibility = ctx.query?.visibility;
44921
+ if (!name15) {
44922
+ ctx.throw(400, "缺少参数 name");
44923
+ }
44924
+ if (!visibility) {
44925
+ ctx.throw(400, "缺少参数 visibility");
44926
+ }
44927
+ const res = await cnb.post({
44928
+ url: `/${name15}/-/settings/set_visibility`,
44929
+ data: { visibility }
44930
+ });
44931
+ ctx.forward(res);
44932
+ }).addTo(app);
44933
+
44934
+ // agent/routes/repo/repo-label.ts
44935
+ app.route({
44936
+ path: "cnb",
44937
+ key: "list-repo-labels",
44938
+ description: "查询仓库的标签列表",
44939
+ middleware: ["auth"],
44940
+ metadata: {
44941
+ tags: ["opencode"],
44942
+ ...createSkill({
44943
+ skill: "list-repo-labels",
44944
+ title: "查询仓库标签列表",
44945
+ summary: "查询仓库的标签列表",
44946
+ args: {
44947
+ repo: tool.schema.string().describe("仓库路径, 如 my-user/my-repo"),
44948
+ page: tool.schema.number().optional().describe("分页页码,默认 1"),
44949
+ pageSize: tool.schema.number().optional().describe("分页每页大小,默认 30"),
44950
+ keyword: tool.schema.string().optional().describe("标签搜索关键词")
44951
+ }
44952
+ })
44953
+ }
44954
+ }).define(async (ctx) => {
44955
+ const cnb = await cnbManager.getContext(ctx);
44956
+ const repo2 = ctx.query?.repo;
44957
+ const page = ctx.query?.page;
44958
+ const pageSize = ctx.query?.pageSize;
44959
+ const keyword = ctx.query?.keyword;
44960
+ if (!repo2) {
44961
+ ctx.throw(400, "缺少参数 repo");
44962
+ }
44963
+ const res = await cnb.labels.repoLabel.list(repo2, {
44964
+ page,
44965
+ page_size: pageSize,
44966
+ keyword
44967
+ });
44968
+ ctx.forward(res);
44969
+ }).addTo(app);
44970
+ app.route({
44971
+ path: "cnb",
44972
+ key: "create-repo-label",
44973
+ description: "创建仓库标签",
44974
+ middleware: ["auth"],
44975
+ metadata: {
44976
+ tags: ["opencode"],
44977
+ ...createSkill({
44978
+ skill: "create-repo-label",
44979
+ title: "创建仓库标签",
44980
+ summary: "创建一个仓库标签",
44981
+ args: {
44982
+ repo: tool.schema.string().describe("仓库路径, 如 my-user/my-repo"),
44983
+ name: tool.schema.string().describe("标签名称"),
44984
+ color: tool.schema.string().describe("标签颜色,十六进制颜色码,不含 # 前缀"),
44985
+ description: tool.schema.string().optional().describe("标签描述")
44986
+ }
44987
+ })
44988
+ }
44989
+ }).define(async (ctx) => {
44990
+ const cnb = await cnbManager.getContext(ctx);
44991
+ const repo2 = ctx.query?.repo;
44992
+ const name15 = ctx.query?.name;
44993
+ const color = ctx.query?.color;
44994
+ const description = ctx.query?.description;
44995
+ if (!repo2 || !name15 || !color) {
44996
+ ctx.throw(400, "缺少参数 repo, name 或 color");
44997
+ }
44998
+ const res = await cnb.labels.repoLabel.create(repo2, {
44999
+ name: name15,
45000
+ color,
45001
+ description
45002
+ });
45003
+ ctx.forward(res);
45004
+ }).addTo(app);
45005
+ app.route({
45006
+ path: "cnb",
45007
+ key: "update-repo-label",
45008
+ description: "更新仓库标签",
45009
+ middleware: ["auth"],
45010
+ metadata: {
45011
+ tags: ["opencode"],
45012
+ ...createSkill({
45013
+ skill: "update-repo-label",
45014
+ title: "更新仓库标签",
45015
+ summary: "更新仓库标签信息",
45016
+ args: {
45017
+ repo: tool.schema.string().describe("仓库路径, 如 my-user/my-repo"),
45018
+ name: tool.schema.string().describe("标签名称"),
45019
+ color: tool.schema.string().optional().describe("标签颜色,十六进制颜色码,不含 # 前缀"),
45020
+ description: tool.schema.string().optional().describe("标签描述"),
45021
+ newName: tool.schema.string().optional().describe("新标签名称")
45022
+ }
45023
+ })
45024
+ }
45025
+ }).define(async (ctx) => {
45026
+ const cnb = await cnbManager.getContext(ctx);
45027
+ const repo2 = ctx.query?.repo;
45028
+ const name15 = ctx.query?.name;
45029
+ const color = ctx.query?.color;
45030
+ const description = ctx.query?.description;
45031
+ const newName = ctx.query?.newName;
45032
+ if (!repo2 || !name15) {
45033
+ ctx.throw(400, "缺少参数 repo 或 name");
45034
+ }
45035
+ const res = await cnb.labels.repoLabel.update(repo2, name15, {
45036
+ color,
45037
+ description,
45038
+ new_name: newName
45039
+ });
45040
+ ctx.forward(res);
45041
+ }).addTo(app);
45042
+ app.route({
45043
+ path: "cnb",
45044
+ key: "delete-repo-label",
45045
+ description: "删除仓库标签",
45046
+ middleware: ["auth"],
45047
+ metadata: {
45048
+ tags: ["opencode"],
45049
+ ...createSkill({
45050
+ skill: "delete-repo-label",
45051
+ title: "删除仓库标签",
45052
+ summary: "删除指定的仓库标签",
45053
+ args: {
45054
+ repo: tool.schema.string().describe("仓库路径, 如 my-user/my-repo"),
45055
+ name: tool.schema.string().describe("标签名称")
45056
+ }
45057
+ })
45058
+ }
45059
+ }).define(async (ctx) => {
45060
+ const cnb = await cnbManager.getContext(ctx);
45061
+ const repo2 = ctx.query?.repo;
45062
+ const name15 = ctx.query?.name;
45063
+ if (!repo2 || !name15) {
45064
+ ctx.throw(400, "缺少参数 repo 或 name");
45065
+ }
45066
+ const res = await cnb.labels.repoLabel.remove(repo2, name15);
45067
+ ctx.forward(res);
45068
+ }).addTo(app);
44854
45069
 
44855
45070
  // agent/routes/workspace/skills.ts
44856
45071
  app.route({
@@ -53067,6 +53282,44 @@ app.route({
53067
53282
  ctx.body = result;
53068
53283
  }).addTo(app);
53069
53284
 
53285
+ // agent/routes/missions/list.ts
53286
+ app.route({
53287
+ path: "cnb",
53288
+ key: "missions-list",
53289
+ description: "查询missions列表",
53290
+ metadata: {
53291
+ args: {
53292
+ repo: zod_default.string().optional().describe("missions所在的仓库,例如 kevisual/projects"),
53293
+ selector: zod_default.array(zod_default.any()).optional().describe('查询条件,例如 [{field: "resource_type", operator: "contains", value: ["issues"]},…]')
53294
+ }
53295
+ }
53296
+ }).define(async (ctx) => {
53297
+ const cnb = await cnbManager.getContext(ctx);
53298
+ const repo2 = ctx.query?.repo || "kevisual/projects";
53299
+ const res = await cnb.mission.queryResources(repo2, ctx.query?.selector || [
53300
+ {
53301
+ field: "resource_type",
53302
+ operator: "contains",
53303
+ value: [
53304
+ "issues"
53305
+ ]
53306
+ },
53307
+ {
53308
+ field: "state",
53309
+ operator: "not_equals",
53310
+ value: [
53311
+ "closed"
53312
+ ]
53313
+ },
53314
+ {
53315
+ field: "label",
53316
+ operator: "contains",
53317
+ value: ["AICoding"]
53318
+ }
53319
+ ]);
53320
+ ctx.forward(res);
53321
+ }).addTo(app);
53322
+
53070
53323
  // agent/routes/index.ts
53071
53324
  var checkAppId = (ctx, appId) => {
53072
53325
  const _appId = ctx?.app?.appId;
@@ -53102,7 +53355,7 @@ app.route({
53102
53355
  }
53103
53356
  }).addTo(app, { overwrite: false });
53104
53357
 
53105
- // ../../node_modules/.pnpm/@kevisual+router@0.1.3/node_modules/@kevisual/router/dist/opencode.js
53358
+ // ../../node_modules/.pnpm/@kevisual+router@0.1.6/node_modules/@kevisual/router/dist/opencode.js
53106
53359
  import { createRequire as createRequire4 } from "node:module";
53107
53360
  import { webcrypto as crypto2 } from "node:crypto";
53108
53361
  var __create4 = Object.create;
package/dist/routes.d.ts CHANGED
@@ -701,6 +701,93 @@ type AliveMetadata = {
701
701
  }[];
702
702
  };
703
703
 
704
+ declare const fields: readonly [{
705
+ readonly name: "resource_type";
706
+ readonly interaction_type: "radio";
707
+ readonly operators: readonly [];
708
+ readonly value: readonly ["issues", "pull_requests"];
709
+ }, {
710
+ readonly name: "started_at";
711
+ readonly interaction_type: "time_selector";
712
+ readonly operators: readonly ["equals", "before", "after", "empty", "not_empty"];
713
+ readonly value: readonly [];
714
+ }, {
715
+ readonly name: "ended_at";
716
+ readonly interaction_type: "time_selector";
717
+ readonly operators: readonly ["equals", "before", "after", "empty", "not_empty"];
718
+ readonly value: readonly [];
719
+ }, {
720
+ readonly name: "closed_at";
721
+ readonly interaction_type: "time_selector";
722
+ readonly operators: readonly ["equals", "before", "after", "empty", "not_empty"];
723
+ readonly value: readonly [];
724
+ }, {
725
+ readonly name: "assignee";
726
+ readonly interaction_type: "checkbox";
727
+ readonly operators: readonly ["contains", "contains_all", "not_contains", "equals", "not_equals", "empty", "not_empty"];
728
+ readonly value: readonly [{
729
+ readonly id: "";
730
+ readonly user_name: "";
731
+ readonly nick_name: "";
732
+ readonly user_type: 0;
733
+ }, {
734
+ readonly id: "2026622946958528512";
735
+ readonly user_name: "cnb.cAiAVfFPgKA";
736
+ readonly nick_name: "里海暗红色";
737
+ readonly user_type: 0;
738
+ }, {
739
+ readonly id: "1915352477005254656";
740
+ readonly user_name: "kevisual";
741
+ readonly nick_name: "科学和哲学";
742
+ readonly user_type: 0;
743
+ }, {
744
+ readonly id: "1935321989751226368";
745
+ readonly user_name: "xiongxiao";
746
+ readonly nick_name: "小熊猫呜呜呜";
747
+ readonly user_type: 0;
748
+ }];
749
+ }, {
750
+ readonly name: "repo";
751
+ readonly interaction_type: "checkbox";
752
+ readonly operators: readonly ["contains", "not_contains"];
753
+ readonly value: readonly ["kevisual/kevisual", "kevisual/cnb", "abearxiong/blog", "abearxiong/abearxiong"];
754
+ }, {
755
+ readonly name: "created_at";
756
+ readonly interaction_type: "time_selector";
757
+ readonly operators: readonly ["equals", "before", "after"];
758
+ readonly value: readonly [];
759
+ }, {
760
+ readonly name: "last_acted_at";
761
+ readonly interaction_type: "time_selector";
762
+ readonly operators: readonly ["equals", "before", "after"];
763
+ readonly value: readonly [];
764
+ }, {
765
+ readonly name: "priority";
766
+ readonly interaction_type: "checkbox";
767
+ readonly operators: readonly ["contains", "not_contains", "empty", "not_empty"];
768
+ readonly value: readonly ["-2P", "-1P", "P0", "P1", "P2", "P3", ""];
769
+ }, {
770
+ readonly name: "state";
771
+ readonly interaction_type: "radio";
772
+ readonly operators: readonly ["equals", "not_equals"];
773
+ readonly value: readonly ["open", "closed"];
774
+ }, {
775
+ readonly name: "label";
776
+ readonly interaction_type: "radio";
777
+ readonly operators: readonly ["equals", "not_equals"];
778
+ readonly value: readonly ["AICoding"];
779
+ }];
780
+ type FieldName = typeof fields[number]['name'];
781
+
782
+ type Selector = {
783
+ /**
784
+ * 字段名称,例如 resource_type、state 等
785
+ */
786
+ field: FieldName;
787
+ operator: 'equals' | 'not_equals' | 'contains' | 'not_contains' | 'in' | 'not_in';
788
+ value: any;
789
+ };
790
+
704
791
  declare class Mission extends CNBCore {
705
792
  constructor(options: CNBCoreOptions);
706
793
  /**
@@ -763,6 +850,13 @@ declare class Mission extends CNBCore {
763
850
  * @returns 操作结果
764
851
  */
765
852
  setVisibility(mission: string, visibility: 'Private' | 'Public'): Promise<Result<any>>;
853
+ /**
854
+ * 查询任务集资源
855
+ * @param repo 仓库路径
856
+ * @param selectors 查询条件
857
+ * @returns 资源列表
858
+ */
859
+ queryResources(repo: string, selectors?: Selector[]): Promise<any>;
766
860
  }
767
861
  type GetMissionsParams = {
768
862
  page?: number;