@zhin.js/adapter-github 4.0.0 → 4.0.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,49 @@
1
1
  # @zhin.js/adapter-github
2
2
 
3
+ ## 4.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - d5cd4aa: Publish Plugin Runtime entry points and convention modules as JavaScript so
8
+ installed npm plugins load on Node without TypeScript stripping. Workspace
9
+ development continues to prefer TypeScript sources for local HMR.
10
+
11
+ Remove the unconsumed legacy game hub APIs from game-kit; game navigation and
12
+ records now use ordinary convention commands owned by the game hub plugin.
13
+
14
+ - Updated dependencies [d5cd4aa]
15
+ - @zhin.js/command@1.0.4
16
+ - zhin.js@5.0.2
17
+ - @zhin.js/adapter@1.1.2
18
+ - @zhin.js/core@1.4.2
19
+ - @zhin.js/agent@1.0.7
20
+
21
+ ## 4.0.1
22
+
23
+ ### Patch Changes
24
+
25
+ - 74b035c: endpoint 管理命令扩展至 18/20 适配器:kook / discord / github(private_key 支持内联文件路径)/ icqq(bindFlow 登记式 add + `icqq login` 引导)/ dingtalk / lark / line / satori / wechat-mp / wecom / weixin-ilink 接入 `endpoint list/add/remove`(字段对齐各自 schema,凭据写 `.env`)。email(smtp/imap 嵌套对象)与 sandbox(无凭据)暂不接。
26
+ - Updated dependencies [cdf64e7]
27
+ - Updated dependencies [2d0a159]
28
+ - Updated dependencies [5691aba]
29
+ - Updated dependencies [078e3f7]
30
+ - Updated dependencies [50497a5]
31
+ - Updated dependencies [9c997b2]
32
+ - Updated dependencies [09d4f25]
33
+ - Updated dependencies [43485a9]
34
+ - Updated dependencies [f0ec5ab]
35
+ - Updated dependencies [3e925d0]
36
+ - Updated dependencies [fa66c4c]
37
+ - Updated dependencies [fa66c4c]
38
+ - Updated dependencies [6cb6152]
39
+ - @zhin.js/command@1.0.3
40
+ - @zhin.js/agent@1.0.6
41
+ - @zhin.js/plugin-runtime@1.1.1
42
+ - @zhin.js/host-http@1.0.3
43
+ - zhin.js@5.0.1
44
+ - @zhin.js/adapter@1.1.1
45
+ - @zhin.js/core@1.4.1
46
+
3
47
  ## 4.0.0
4
48
 
5
49
  ### Patch Changes
@@ -0,0 +1,54 @@
1
+ // Generated by build-plugin-runtime-entries.mjs. Do not edit.
2
+ /**
3
+ * Convention entry: discover `adapters/github.ts` → defineAdapter.
4
+ * Implementation lives under `src/` (endpoint / webhook / oauth / protocol).
5
+ */
6
+ import { defineAdapter } from '@zhin.js/adapter';
7
+ import { messageGatewayToken } from '@zhin.js/core/runtime';
8
+ import { httpHostToken } from '@zhin.js/host-http';
9
+ import { databaseHostToken, } from '@zhin.js/plugin-runtime';
10
+ import { GithubEndpoint } from "../lib/endpoint.js";
11
+ import { githubRuntimeStateToken } from "../lib/github-runtime-state.js";
12
+ import { resolveGithubConfig, } from "../lib/protocol.js";
13
+ export { GithubEndpoint } from "../lib/endpoint.js";
14
+ function optionalDatabase(context) {
15
+ try {
16
+ return context.use(databaseHostToken);
17
+ }
18
+ catch {
19
+ return undefined;
20
+ }
21
+ }
22
+ export default defineAdapter({
23
+ capabilities: ['inbound', 'outbound'],
24
+ // Issue/PR 评论以 markdown 图片链接消费远程 URL;无交互面,交互段降级纯文本。
25
+ segments: {
26
+ outboundMedia: ['url'],
27
+ interactive: 'text',
28
+ },
29
+ create(context) {
30
+ const config = resolveGithubConfig(context.config);
31
+ const database = optionalDatabase(context);
32
+ // 注册到插件运行时状态(github endpoint list 的"运行中"数据源)
33
+ context.use(githubRuntimeStateToken).endpoints.set(config.name, {
34
+ name: config.name,
35
+ mode: config.webhookSecret ? 'webhook' : 'api',
36
+ });
37
+ if (config.webhookSecret) {
38
+ return new GithubEndpoint({
39
+ id: context.id,
40
+ gateway: context.use(messageGatewayToken),
41
+ http: context.use(httpHostToken),
42
+ database,
43
+ config,
44
+ });
45
+ }
46
+ // API-only: Issue/PR send + agent tools without webhook.
47
+ return new GithubEndpoint({
48
+ id: context.id,
49
+ gateway: context.use(messageGatewayToken),
50
+ database,
51
+ config,
52
+ });
53
+ },
54
+ });
@@ -10,6 +10,7 @@ import {
10
10
  type DatabaseHost,
11
11
  } from '@zhin.js/plugin-runtime';
12
12
  import { GithubEndpoint } from '../src/endpoint.js';
13
+ import { githubRuntimeStateToken } from '../src/github-runtime-state.js';
13
14
  import {
14
15
  resolveGithubConfig,
15
16
  type GithubAdapterConfig,
@@ -28,9 +29,19 @@ function optionalDatabase(context: AdapterContext): DatabaseHost | undefined {
28
29
 
29
30
  export default defineAdapter<GithubAdapterConfig>({
30
31
  capabilities: ['inbound', 'outbound'],
32
+ // Issue/PR 评论以 markdown 图片链接消费远程 URL;无交互面,交互段降级纯文本。
33
+ segments: {
34
+ outboundMedia: ['url'],
35
+ interactive: 'text',
36
+ },
31
37
  create(context) {
32
38
  const config = resolveGithubConfig(context.config);
33
39
  const database = optionalDatabase(context);
40
+ // 注册到插件运行时状态(github endpoint list 的"运行中"数据源)
41
+ context.use(githubRuntimeStateToken).endpoints.set(config.name, {
42
+ name: config.name,
43
+ mode: config.webhookSecret ? 'webhook' : 'api',
44
+ });
34
45
  if (config.webhookSecret) {
35
46
  return new GithubEndpoint({
36
47
  id: context.id,
@@ -0,0 +1,3 @@
1
+ // Generated by build-plugin-runtime-entries.mjs. Do not edit.
2
+ import { githubEndpointCommands } from "../../../lib/github-endpoint-commands.js";
3
+ export default githubEndpointCommands.add;
@@ -0,0 +1,3 @@
1
+ import { githubEndpointCommands } from '../../../src/github-endpoint-commands.js';
2
+
3
+ export default githubEndpointCommands.add;
@@ -0,0 +1,3 @@
1
+ // Generated by build-plugin-runtime-entries.mjs. Do not edit.
2
+ import { githubEndpointCommands } from "../../lib/github-endpoint-commands.js";
3
+ export default githubEndpointCommands.list;
@@ -0,0 +1,3 @@
1
+ import { githubEndpointCommands } from '../../src/github-endpoint-commands.js';
2
+
3
+ export default githubEndpointCommands.list;
@@ -0,0 +1,3 @@
1
+ // Generated by build-plugin-runtime-entries.mjs. Do not edit.
2
+ import { githubEndpointCommands } from "../../../lib/github-endpoint-commands.js";
3
+ export default githubEndpointCommands.remove;
@@ -0,0 +1,3 @@
1
+ import { githubEndpointCommands } from '../../../src/github-endpoint-commands.js';
2
+
3
+ export default githubEndpointCommands.remove;
package/lib/endpoint.d.ts CHANGED
@@ -13,6 +13,10 @@ export interface GithubEndpointOptions {
13
13
  readonly config: ResolvedGithubConfig;
14
14
  readonly createClient?: (config: ResolvedGithubConfig) => GhClient;
15
15
  }
16
+ /**
17
+ * GitHub 是代码协作面(issue/PR),无好友/群/频道等 IM 社交概念,
18
+ * 不适用 EndpointManagement 语义端口;本 endpoint 不暴露该端口。
19
+ */
16
20
  export declare class GithubEndpoint implements EndpointInstance {
17
21
  #private;
18
22
  readonly gh: GhClient;
package/lib/endpoint.js CHANGED
@@ -10,6 +10,10 @@ import { enrichInboundContent, formatInboundContent, formatOutboundBody, parseCh
10
10
  import { registerGithubWebhookRoutes } from './webhook.js';
11
11
  import { WorkspaceManager } from './workspace-manager.js';
12
12
  const logger = getLogger('github');
13
+ /**
14
+ * GitHub 是代码协作面(issue/PR),无好友/群/频道等 IM 社交概念,
15
+ * 不适用 EndpointManagement 语义端口;本 endpoint 不暴露该端口。
16
+ */
13
17
  export class GithubEndpoint {
14
18
  #options;
15
19
  gh;
@@ -0,0 +1 @@
1
+ export declare const githubEndpointCommands: import("@zhin.js/adapter").EndpointCommands<Readonly<import("@zhin.js/command").CommandDefinition<unknown, unknown, import("@zhin.js/command").CommandMessage>>>;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * `github endpoint` 命令族:由 @zhin.js/adapter 的 createEndpointCommands 套件生成。
3
+ * commands/endpoint/ 下的 list / add / remove 直接默认导出这三项。
4
+ *
5
+ * 字段说明:private_key 内容长且含换行,不适合 kv 直传——运行时(gh-client
6
+ * resolvePrivateKey)本就支持 PEM 内容或文件路径,故 add 采用**内联路径**形式:
7
+ * `github endpoint add mybot app_id=123456 private_key=./data/mybot.pem`。
8
+ */
9
+ import { createEndpointCommands } from '@zhin.js/adapter';
10
+ import { defineCommand } from '@zhin.js/command';
11
+ import { githubRuntimeStateToken } from './github-runtime-state.js';
12
+ export const githubEndpointCommands = createEndpointCommands({
13
+ adapterKey: 'github',
14
+ adapterDisplayName: 'GitHub',
15
+ fields: [
16
+ { key: 'app_id', required: true, env: true, description: 'GitHub App ID' },
17
+ { key: 'private_key', required: true, description: 'PEM 文件路径(推荐,如 ./data/xxx.pem)或 PEM 内容' },
18
+ { key: 'webhook_secret', env: true, description: 'webhook 签名密钥(不配则 API-only)' },
19
+ ],
20
+ running: (use) => use(githubRuntimeStateToken).endpoints.values(),
21
+ describeEntry: (entry) => `app_id: ${String(entry.app_id ?? entry.appId)}`,
22
+ }, defineCommand);
@@ -0,0 +1 @@
1
+ export declare const githubRuntimeStateToken: import("zhin.js").Token<import("@zhin.js/adapter").EndpointRuntimeState>;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * GitHub 插件实例的运行时状态:adapter create() 注册的 endpoint 列表。
3
+ * 由 plugin.ts setup() provide,adapter create 与 `github endpoint` 命令共享(同一 owner generation)。
4
+ */
5
+ import { defineEndpointRuntimeStateToken } from '@zhin.js/adapter';
6
+ export const githubRuntimeStateToken = defineEndpointRuntimeStateToken('github');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhin.js/adapter-github",
3
- "version": "4.0.0",
3
+ "version": "4.0.2",
4
4
  "description": "Zhin.js GitHub adapter for Plugin Runtime (App auth + webhook)",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -41,20 +41,21 @@
41
41
  "directory": "plugins/adapters/github"
42
42
  },
43
43
  "dependencies": {
44
- "@zhin.js/adapter": "1.1.0",
45
- "@zhin.js/core": "1.4.0",
46
- "@zhin.js/host-http": "1.0.2",
44
+ "@zhin.js/adapter": "1.1.2",
45
+ "@zhin.js/command": "1.0.4",
46
+ "@zhin.js/core": "1.4.2",
47
+ "@zhin.js/host-http": "1.0.3",
47
48
  "@zhin.js/logger": "1.0.75",
48
- "@zhin.js/plugin-runtime": "1.1.0"
49
+ "@zhin.js/plugin-runtime": "1.1.1"
49
50
  },
50
51
  "peerDependencies": {
51
52
  "zod": "^4.0.0",
52
- "@zhin.js/adapter": "1.1.0",
53
- "@zhin.js/agent": "1.0.5",
54
- "@zhin.js/core": "1.4.0",
55
- "@zhin.js/host-http": "1.0.2",
56
- "@zhin.js/plugin-runtime": "1.1.0",
57
- "zhin.js": "5.0.0"
53
+ "@zhin.js/adapter": "1.1.2",
54
+ "@zhin.js/agent": "1.0.7",
55
+ "@zhin.js/core": "1.4.2",
56
+ "@zhin.js/host-http": "1.0.3",
57
+ "@zhin.js/plugin-runtime": "1.1.1",
58
+ "zhin.js": "5.0.2"
58
59
  },
59
60
  "peerDependenciesMeta": {
60
61
  "zhin.js": {
@@ -72,12 +73,13 @@
72
73
  "typescript": "^6.0.3",
73
74
  "vitest": "^4.1.10",
74
75
  "zod": "^4.4.3",
75
- "@zhin.js/agent": "1.0.5",
76
- "zhin.js": "5.0.0"
76
+ "@zhin.js/agent": "1.0.7",
77
+ "zhin.js": "5.0.2"
77
78
  },
78
79
  "files": [
79
80
  "adapters",
80
- "plugin.ts",
81
+ "commands",
82
+ "plugin.js",
81
83
  "schema.json",
82
84
  "src",
83
85
  "lib",
@@ -95,13 +97,17 @@
95
97
  "zhin": {
96
98
  "protocol": 1,
97
99
  "type": "plugin",
98
- "entry": "./plugin.ts",
100
+ "entry": "./plugin.js",
99
101
  "engine": "^1.0.0",
100
102
  "runtime": "trusted",
101
103
  "features": [
102
104
  {
103
105
  "package": "@zhin.js/adapter",
104
106
  "api": "^1.0.0"
107
+ },
108
+ {
109
+ "package": "@zhin.js/command",
110
+ "api": "^1.0.0"
105
111
  }
106
112
  ],
107
113
  "plugins": []
package/plugin.js ADDED
@@ -0,0 +1,55 @@
1
+ // Generated by build-plugin-runtime-entries.mjs. Do not edit.
2
+ import { createEndpointRuntimeState } from '@zhin.js/adapter';
3
+ import { definePlugin, databaseHostToken } from '@zhin.js/plugin-runtime';
4
+ import { githubRuntimeStateToken } from "./lib/github-runtime-state.js";
5
+ import { defineGithubOauthUsersTable } from "./lib/oauth-users.js";
6
+ /**
7
+ * github_subscriptions — repo event subscriptions per chat channel
8
+ * (used by github_subscriptions agent tool; schema matches legacy defineModel).
9
+ */
10
+ const GITHUB_SUBSCRIPTIONS_SCHEMA = {
11
+ id: { type: 'integer', primary: true },
12
+ repo: { type: 'text', nullable: false },
13
+ events: { type: 'json', default: [] },
14
+ target_id: { type: 'text', nullable: false },
15
+ target_type: { type: 'text', nullable: false },
16
+ adapter: { type: 'text', nullable: false },
17
+ endpoint: { type: 'text', nullable: false },
18
+ };
19
+ /**
20
+ * Plugin Runtime GitHub adapter.
21
+ * - Endpoint: `adapters/github.ts`
22
+ * - OAuth user tokens: define `github_oauth_users` when DatabaseHost is present
23
+ */
24
+ export default definePlugin({
25
+ name: 'github',
26
+ metadata: {
27
+ displayName: 'GitHub Adapter',
28
+ },
29
+ setup(context) {
30
+ // 运行中 endpoint 注册表(github endpoint list 的"运行中"数据源)
31
+ context.resources.provide(githubRuntimeStateToken, createEndpointRuntimeState());
32
+ if (context.resources.has(databaseHostToken)) {
33
+ const host = context.resources.use(databaseHostToken);
34
+ defineGithubOauthUsersTable(host);
35
+ host.define('github_subscriptions', { ...GITHUB_SUBSCRIPTIONS_SCHEMA });
36
+ }
37
+ // Agent prompt contributor (orchestrator/deferred-worker GitHub guidance).
38
+ // `zhin.js/agent` is an optional peer — skip silently on IM-only installs.
39
+ let cancelled = false;
40
+ let unregister;
41
+ void Promise.all([
42
+ import('zhin.js/agent'),
43
+ import("./lib/agent-prompt.js"),
44
+ ]).then(([agent, prompt]) => {
45
+ if (cancelled)
46
+ return;
47
+ agent.registerAgentPromptContributor(prompt.createGithubAgentPromptContributor());
48
+ unregister = () => agent.unregisterAgentPromptContributor('github');
49
+ }).catch(() => { });
50
+ return () => {
51
+ cancelled = true;
52
+ unregister?.();
53
+ };
54
+ },
55
+ });
package/src/endpoint.ts CHANGED
@@ -32,6 +32,10 @@ export interface GithubEndpointOptions {
32
32
  readonly createClient?: (config: ResolvedGithubConfig) => GhClient;
33
33
  }
34
34
 
35
+ /**
36
+ * GitHub 是代码协作面(issue/PR),无好友/群/频道等 IM 社交概念,
37
+ * 不适用 EndpointManagement 语义端口;本 endpoint 不暴露该端口。
38
+ */
35
39
  export class GithubEndpoint implements EndpointInstance {
36
40
  readonly #options: GithubEndpointOptions;
37
41
  readonly gh: GhClient;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * `github endpoint` 命令族:由 @zhin.js/adapter 的 createEndpointCommands 套件生成。
3
+ * commands/endpoint/ 下的 list / add / remove 直接默认导出这三项。
4
+ *
5
+ * 字段说明:private_key 内容长且含换行,不适合 kv 直传——运行时(gh-client
6
+ * resolvePrivateKey)本就支持 PEM 内容或文件路径,故 add 采用**内联路径**形式:
7
+ * `github endpoint add mybot app_id=123456 private_key=./data/mybot.pem`。
8
+ */
9
+ import { createEndpointCommands } from '@zhin.js/adapter';
10
+ import { defineCommand } from '@zhin.js/command';
11
+ import { githubRuntimeStateToken } from './github-runtime-state.js';
12
+
13
+ export const githubEndpointCommands = createEndpointCommands({
14
+ adapterKey: 'github',
15
+ adapterDisplayName: 'GitHub',
16
+ fields: [
17
+ { key: 'app_id', required: true, env: true, description: 'GitHub App ID' },
18
+ { key: 'private_key', required: true, description: 'PEM 文件路径(推荐,如 ./data/xxx.pem)或 PEM 内容' },
19
+ { key: 'webhook_secret', env: true, description: 'webhook 签名密钥(不配则 API-only)' },
20
+ ],
21
+ running: (use) => use(githubRuntimeStateToken).endpoints.values(),
22
+ describeEntry: (entry) => `app_id: ${String(entry.app_id ?? entry.appId)}`,
23
+ }, defineCommand);
@@ -0,0 +1,7 @@
1
+ /**
2
+ * GitHub 插件实例的运行时状态:adapter create() 注册的 endpoint 列表。
3
+ * 由 plugin.ts setup() provide,adapter create 与 `github endpoint` 命令共享(同一 owner generation)。
4
+ */
5
+ import { defineEndpointRuntimeStateToken } from '@zhin.js/adapter';
6
+
7
+ export const githubRuntimeStateToken = defineEndpointRuntimeStateToken('github');
package/plugin.ts DELETED
@@ -1,52 +0,0 @@
1
- import { definePlugin, databaseHostToken } from '@zhin.js/plugin-runtime';
2
- import { defineGithubOauthUsersTable } from './src/oauth-users.js';
3
-
4
- /**
5
- * github_subscriptions — repo event subscriptions per chat channel
6
- * (used by github_subscriptions agent tool; schema matches legacy defineModel).
7
- */
8
- const GITHUB_SUBSCRIPTIONS_SCHEMA = {
9
- id: { type: 'integer', primary: true },
10
- repo: { type: 'text', nullable: false },
11
- events: { type: 'json', default: [] },
12
- target_id: { type: 'text', nullable: false },
13
- target_type: { type: 'text', nullable: false },
14
- adapter: { type: 'text', nullable: false },
15
- endpoint: { type: 'text', nullable: false },
16
- } as const;
17
-
18
- /**
19
- * Plugin Runtime GitHub adapter.
20
- * - Endpoint: `adapters/github.ts`
21
- * - OAuth user tokens: define `github_oauth_users` when DatabaseHost is present
22
- */
23
- export default definePlugin({
24
- name: 'github',
25
- metadata: {
26
- displayName: 'GitHub Adapter',
27
- },
28
- setup(context) {
29
- if (context.resources.has(databaseHostToken)) {
30
- const host = context.resources.use(databaseHostToken);
31
- defineGithubOauthUsersTable(host);
32
- host.define('github_subscriptions', { ...GITHUB_SUBSCRIPTIONS_SCHEMA });
33
- }
34
-
35
- // Agent prompt contributor (orchestrator/deferred-worker GitHub guidance).
36
- // `zhin.js/agent` is an optional peer — skip silently on IM-only installs.
37
- let cancelled = false;
38
- let unregister: (() => void) | undefined;
39
- void Promise.all([
40
- import('zhin.js/agent'),
41
- import('./src/agent-prompt.js'),
42
- ]).then(([agent, prompt]) => {
43
- if (cancelled) return;
44
- agent.registerAgentPromptContributor(prompt.createGithubAgentPromptContributor());
45
- unregister = () => agent.unregisterAgentPromptContributor('github');
46
- }).catch(() => { /* optional peer not installed */ });
47
- return () => {
48
- cancelled = true;
49
- unregister?.();
50
- };
51
- },
52
- });