From 448212f8d2a580ca6d7f9f14a0ebf0dd4e397daa Mon Sep 17 00:00:00 2001 From: gengruilin Date: Wed, 14 Oct 2026 21:17:10 +0800 Subject: [PATCH] build(wecom): package the WeCom plugin on the CLI account kit Pin @wecom/cli 1.3.4, publish the bundled skills, register the three packages, and keep the account rules in WecomAccount like Feishu. --- THIRD_PARTY_NOTICES.md | 1 + package.json | 2 + packages/client/ui-wecom/locale/en.json | 6 + packages/client/ui-wecom/locale/zh.json | 6 + packages/client/ui-wecom/package.json | 77 ++++++++ .../ui-wecom/src/client/WecomConnection.tsx | 21 +++ .../client/ui-wecom/src/client/connection.ts | 22 ++- packages/client/ui-wecom/src/client/index.ts | 13 ++ .../client/ui-wecom/src/client/locales.ts | 5 + packages/client/ui-wecom/src/index.ts | 3 + packages/client/ui-wecom/tsconfig.json | 54 ++++++ packages/client/ui-wecom/tsdown.config.ts | 3 + packages/connector/wecom-cli/locale/en.json | 6 + packages/connector/wecom-cli/locale/zh.json | 6 + packages/connector/wecom-cli/package.json | 68 +++++++ packages/connector/wecom-cli/src/account.ts | 25 ++- packages/connector/wecom-cli/src/directory.ts | 9 + packages/connector/wecom-cli/src/index.ts | 52 ++++-- packages/connector/wecom-cli/src/types.ts | 7 + packages/connector/wecom-cli/tsconfig.json | 39 ++++ packages/connector/wecom/locale/en.json | 6 + packages/connector/wecom/locale/zh.json | 6 + packages/connector/wecom/package.json | 48 +++++ packages/connector/wecom/src/index.ts | 1 + packages/connector/wecom/tsconfig.json | 15 ++ pnpm-lock.yaml | 168 ++++++++++++++++++ scripts/check-workspace-constraints.ts | 2 + scripts/product-package-policy.ts | 3 + tsconfig.base.json | 3 + tsconfig.client.json | 1 + tsconfig.host.json | 3 + 31 files changed, 667 insertions(+), 14 deletions(-) create mode 100644 packages/client/ui-wecom/locale/en.json create mode 100644 packages/client/ui-wecom/locale/zh.json create mode 100644 packages/client/ui-wecom/package.json create mode 100644 packages/client/ui-wecom/tsconfig.json create mode 100644 packages/client/ui-wecom/tsdown.config.ts create mode 100644 packages/connector/wecom-cli/locale/en.json create mode 100644 packages/connector/wecom-cli/locale/zh.json create mode 100644 packages/connector/wecom-cli/package.json create mode 100644 packages/connector/wecom-cli/tsconfig.json create mode 100644 packages/connector/wecom/locale/en.json create mode 100644 packages/connector/wecom/locale/zh.json create mode 100644 packages/connector/wecom/package.json create mode 100644 packages/connector/wecom/tsconfig.json diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md index a1a13b2200..6cfe897b76 100644 --- a/THIRD_PARTY_NOTICES.md +++ b/THIRD_PARTY_NOTICES.md @@ -69,6 +69,7 @@ External packages installed for runtime use or embedded in distributed Host or b | [`@tanstack/react-virtual`](https://github.com/TanStack/virtual) | MIT | | [`@trycua/cua-driver`](https://github.com/trycua/cua) | MIT | | [`@vscode/ripgrep`](https://github.com/microsoft/vscode-ripgrep) | MIT | +| [`@wecom/cli`](https://github.com/WecomTeam/wecom-cli) | MIT | | [`@xterm/addon-fit`](https://github.com/xtermjs/xterm.js/tree/master/addons/addon-fit) | MIT | | [`@xterm/addon-serialize`](https://github.com/xtermjs/xterm.js/tree/master/addons/addon-serialize) | MIT | | [`@xterm/headless`](https://github.com/xtermjs/xterm.js) | MIT | diff --git a/package.json b/package.json index 229ba8880c..5c4cd319ef 100644 --- a/package.json +++ b/package.json @@ -243,6 +243,8 @@ "@deepseek-ai/dsh-llm-replay": "workspace:*", "@deepseek-ai/dsh-subagent-dsh-sdk": "workspace:*", "@deepseek-ai/dsh-llm": "workspace:*", + "@deepseek-ai/dsh-wecom": "workspace:*", + "@deepseek-ai/dsh-wecom-cli": "workspace:*", "@deepseek-ai/dsh-mcp-client": "workspace:*", "@deepseek-ai/dsh-tool-session-query": "workspace:*", "@deepseek-ai/dsh-web-fetch-http": "workspace:*", diff --git a/packages/client/ui-wecom/locale/en.json b/packages/client/ui-wecom/locale/en.json new file mode 100644 index 0000000000..2a422282b5 --- /dev/null +++ b/packages/client/ui-wecom/locale/en.json @@ -0,0 +1,6 @@ +{ + "meta": { + "title": "WeCom plugin page", + "description": "Authorize and check WeCom from the Plugins page" + } +} diff --git a/packages/client/ui-wecom/locale/zh.json b/packages/client/ui-wecom/locale/zh.json new file mode 100644 index 0000000000..9193df3ab5 --- /dev/null +++ b/packages/client/ui-wecom/locale/zh.json @@ -0,0 +1,6 @@ +{ + "meta": { + "title": "企业微信插件页面", + "description": "在插件页授权和检查企业微信" + } +} diff --git a/packages/client/ui-wecom/package.json b/packages/client/ui-wecom/package.json new file mode 100644 index 0000000000..ea93bae34c --- /dev/null +++ b/packages/client/ui-wecom/package.json @@ -0,0 +1,77 @@ +{ + "name": "@deepseek-ai/dsh-client-ui-wecom", + "description": "WeCom plugin page: authorize and check WeCom from the Plugins page", + "version": "0.2.1-alpha.2", + "publishConfig": { + "access": "public" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/deepseek-ai/deepseek-harness.git", + "directory": "packages/client/ui-wecom" + }, + "type": "module", + "main": "lib/index.js", + "types": "lib/types/index.d.ts", + "exports": { + ".": { + "types": "./lib/types/index.d.ts", + "default": "./lib/index.js" + }, + "./src/*": "./src/*", + "./package.json": "./package.json", + "./locale/*.json": "./locale/*.json", + "./client": { + "types": "./lib/types/client/index.d.ts", + "default": "./lib/client.js" + } + }, + "files": [ + "locale/*.json", + "lib/index.js", + "lib/client.js", + "lib/types/**/*.d.ts" + ], + "license": "MIT", + "dsh": { + "client": { + "inject": [ + "@deepseek-ai/dsh-api-remotes", + "@deepseek-ai/dsh-client-locale", + "@deepseek-ai/dsh-client-ui-layout", + "@deepseek-ai/dsh-client-ui-plugin-manager" + ], + "platform": "web", + "external": [ + "@deepseek-ai/dsh-client-ui-cli-account/client" + ] + } + }, + "scripts": { + "bundle": "tsdown", + "watch": "tsdown --watch" + }, + "peerDependencies": { + "@deepseek-ai/cordis": "workspace:~" + }, + "devDependencies": { + "@deepseek-ai/cordis": "workspace:~", + "@deepseek-ai/dsh-api-gateway": "workspace:*", + "@deepseek-ai/dsh-api-remotes": "workspace:*", + "@deepseek-ai/dsh-cli-account": "workspace:*", + "@deepseek-ai/dsh-client-locale": "workspace:*", + "@deepseek-ai/dsh-client-store": "workspace:*", + "@deepseek-ai/dsh-client-test-runtime": "workspace:*", + "@deepseek-ai/dsh-client-ui-cli-account": "workspace:*", + "@deepseek-ai/dsh-client-ui-layout": "workspace:*", + "@deepseek-ai/dsh-client-ui-plugin-manager": "workspace:*", + "@deepseek-ai/dsh-client-ui-renderer": "workspace:*", + "@deepseek-ai/dsh-client-ui-slots": "workspace:*", + "@deepseek-ai/dsh-typert-protocol": "workspace:*", + "@deepseek-ai/dsh-util-values": "workspace:*", + "@deepseek-ai/dsh-wecom-cli": "workspace:*", + "@testing-library/react": "^16.3.3", + "react": "^18.2.0", + "react-dom": "^18.2.0" + } +} diff --git a/packages/client/ui-wecom/src/client/WecomConnection.tsx b/packages/client/ui-wecom/src/client/WecomConnection.tsx index f3bd28dd55..ebf4485737 100644 --- a/packages/client/ui-wecom/src/client/WecomConnection.tsx +++ b/packages/client/ui-wecom/src/client/WecomConnection.tsx @@ -1,3 +1,4 @@ +/** WeCom authorization surfaces on the Plugins page: the bundle section, title tag, activation guidance, and notices. */ import type { ReactNode } from 'react' import { CliAccountActivation, CliAccountBadge, CliAccountSection, CliAccountToast, type CliAccountAction, @@ -9,6 +10,11 @@ import type { NS } from './locales.ts' type FaceProps = InjectFace & PropsLocale +/** + * The authorization section on the WeCom bundle's page. + * @param props - the shared connection face and the WeCom dictionary. + * @returns the status line and its actions. + */ export function WecomConnectionSection(props: FaceProps): ReactNode { const { useWecomConnection, check, connect, cancel, openAuthorization, retry, t } = props const snapshot = useWecomConnection(value => value) @@ -37,17 +43,32 @@ export function WecomConnectionSection(props: FaceProps): ReactNode { ) } +/** + * The authorization tag beside the WeCom bundle's title. + * @param props - the open detail page's subject, the connection face, and the dictionary. + * @returns the tag for the WeCom bundle, or null on any other page. + */ export function WecomConnectionBadge({ subject, useWecomConnection, t }: FaceProps & PropsRuntime<'plugins.detail.badge'>): ReactNode { const phase = useWecomConnection(value => presentConnection(value).phase) return } +/** + * Guidance after the user switches the WeCom bundle on while it is not authorized. + * @param props - activation callbacks, the connection face, and the dictionary. + * @returns a dismissible prompt that starts the authorization from the bundle's page. + */ export function WecomConnectionActivation(props: FaceProps & PropsRuntime<'plugins.bundle.activation'>): ReactNode { const { useWecomConnection, connect, onDismiss, onOpenDetails, t } = props const phase = useWecomConnection(value => presentConnection(value).phase) return { onOpenDetails(); connect() }} /> } +/** + * Authorization outcomes reported outside the Plugins panel's lifetime. + * @param props - the shared notice, its dismissal, and the dictionary. + * @returns the toast for the latest notice, or null. + */ export function WecomConnectionToast({ useWecomConnection, dismissNotice, t }: FaceProps): ReactNode { const notice = useWecomConnection(value => value.notice) return diff --git a/packages/client/ui-wecom/src/client/connection.ts b/packages/client/ui-wecom/src/client/connection.ts index 8dc225dc23..770c09fda8 100644 --- a/packages/client/ui-wecom/src/client/connection.ts +++ b/packages/client/ui-wecom/src/client/connection.ts @@ -1,3 +1,4 @@ +/** Browser mirror of the Host's WeCom authorization and the Plugins page's actions. */ import type { Context } from '@deepseek-ai/cordis' import type {} from '@deepseek-ai/dsh-api-remotes/client' import { CliAccountConnection, type CliAccountPhase, type CliAccountSnapshot } from '@deepseek-ai/dsh-client-ui-cli-account/client' @@ -5,27 +6,41 @@ import type { HostObservable } from '@deepseek-ai/dsh-client-ui-slots' import type { WecomState } from '@deepseek-ai/dsh-wecom-cli/types' import { assertNever } from '@deepseek-ai/dsh-util-values' +/** The npm package whose bundle page carries the authorization section. */ export const WECOM_PACKAGE = '@deepseek-ai/dsh-wecom' +/** Outcomes the page reports after an operation this browser started succeeds. */ export type WecomNotice = 'connected' +/** The page's whole view: the Host's authorization view plus this browser's stream, pending action, and notice. */ export type ConnectionSnapshot = CliAccountSnapshot +/** What the user sees about the authorization, derived from the Host's view alone. */ export type ConnectionPresentation = | { readonly phase: Exclude; readonly failed: WecomState['result'] } | { readonly phase: 'connecting'; readonly step: 'authorizing' | 'connecting'; readonly url: string | undefined; readonly cancellable: boolean } +/** Page-facing actions and the snapshot hook the slot entries inject. */ export interface ConnectionFace { hooks: { wecomConnection: HostObservable } + /** Read the authorization again. */ check(): void + /** Bind a bot through the QR-code page. */ connect(): void cancel(): void openAuthorization(): void + /** Reopen the Host stream after it stopped. */ retry(): void dismissNotice(): void } -export function presentConnection({ view, stopped }: Pick): ConnectionPresentation { +/** + * Derive the authorization the page shows from the Host's view. + * @param snapshot - the view as the Host last reported it, and whether the Host stream stopped. + * @returns the phase, with the operation in progress or the last failed result. + */ +export function presentConnection(snapshot: Pick): ConnectionPresentation { + const { view, stopped } = snapshot if (stopped) return { phase: 'stopped', failed: undefined } const operation = view?.operation if (view === undefined || operation?.kind === 'check') return { phase: 'checking', failed: undefined } @@ -47,6 +62,11 @@ export function presentConnection({ view, stopped }: Pick; face: ConnectionFace } { const connection = new CliAccountConnection(ctx, { name: 'WeCom connection', diff --git a/packages/client/ui-wecom/src/client/index.ts b/packages/client/ui-wecom/src/client/index.ts index 55199a136d..9c55b231bf 100644 --- a/packages/client/ui-wecom/src/client/index.ts +++ b/packages/client/ui-wecom/src/client/index.ts @@ -1,3 +1,10 @@ +/** + * WeCom plugin, browser half: the authorization section on the WeCom bundle's + * page, the tag beside its title, guidance after the bundle is switched on, and + * notices. The Host's `wecom` Remote owns the operations; this half mounts that + * Remote itself because the on-demand package stays out of the shipped Remote + * assembly. + */ import type { Context } from '@deepseek-ai/cordis' import type {} from '@deepseek-ai/dsh-api-remotes/client' import type {} from '@deepseek-ai/dsh-client-locale/client' @@ -9,6 +16,7 @@ import { WECOM_PACKAGE, createConnection } from './connection.ts' import { en, NS, zh } from './locales.ts' import { WecomConnectionActivation, WecomConnectionBadge, WecomConnectionSection, WecomConnectionToast } from './WecomConnection.tsx' +/** Services the Remote mount and the slot registrations need. */ export const inject = ['remote', 'slots', 'locale'] function registerUi(ctx: Context): void { @@ -29,6 +37,11 @@ function registerUi(ctx: Context): void { }, WecomConnectionToast)) } +/** + * Mount the WeCom Remote, then register the authorization surfaces for as long as the WeCom row is on. + * @param ctx - the browser plugin context. + * @returns a disposer that withdraws the surfaces, then the Remote. + */ export async function apply(ctx: Context): Promise<() => Promise> { const disposeRemote = await ctx.remote.$mount(wecomRemote) const ui = ctx.inject(['remote.wecom', 'slots', 'locale'], registerUi) diff --git a/packages/client/ui-wecom/src/client/locales.ts b/packages/client/ui-wecom/src/client/locales.ts index 8734294310..44cbfdf389 100644 --- a/packages/client/ui-wecom/src/client/locales.ts +++ b/packages/client/ui-wecom/src/client/locales.ts @@ -1,7 +1,10 @@ +/** Locale-owned copy for the WeCom plugin's authorization on the Plugins page. */ import type {} from '@deepseek-ai/dsh-client-ui-slots' +/** Dictionary namespace for every WeCom authorization surface. */ export const NS = 'wecom' +/** Chinese dictionary and key source. */ export const zh = { 'section.title': '企业微信授权', 'status.checking': '正在检查授权', @@ -37,8 +40,10 @@ export const zh = { close: '关闭', } +/** Every key the WeCom authorization surfaces translate. */ export type WecomKey = keyof typeof zh +/** English dictionary. */ export const en: Record = { 'section.title': 'WeCom authorization', 'status.checking': 'Checking authorization', diff --git a/packages/client/ui-wecom/src/index.ts b/packages/client/ui-wecom/src/index.ts index 355ced461a..25e1f59143 100644 --- a/packages/client/ui-wecom/src/index.ts +++ b/packages/client/ui-wecom/src/index.ts @@ -1 +1,4 @@ +/** Host marker for the WeCom plugin page; the browser behavior is the client export. */ + +/** The page has no Host behavior; the `wecom-cli` row owns the authorization operations. */ export function apply(): void {} diff --git a/packages/client/ui-wecom/tsconfig.json b/packages/client/ui-wecom/tsconfig.json new file mode 100644 index 0000000000..c15aaa6396 --- /dev/null +++ b/packages/client/ui-wecom/tsconfig.json @@ -0,0 +1,54 @@ +{ + "extends": "../../../tsconfig.base.client.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "lib/types" + }, + "include": [ + "src" + ], + "references": [ + { + "path": "../../../vendor/cordis" + }, + { + "path": "../../api/gateway/tsconfig.client.json" + }, + { + "path": "../../api/remotes/tsconfig.client.json" + }, + { + "path": "../locale/tsconfig.client.json" + }, + { + "path": "../store" + }, + { + "path": "../ui-layout" + }, + { + "path": "../ui-plugin-manager/tsconfig.client.json" + }, + { + "path": "../ui-renderer" + }, + { + "path": "../ui-slots" + }, + { + "path": "../../connector/wecom-cli" + }, + { + "path": "../../typert/protocol" + }, + { + "path": "../../util/values" + }, + { + "path": "../ui-cli-account" + }, + { + "path": "../../connector/cli-account" + } + ] +} diff --git a/packages/client/ui-wecom/tsdown.config.ts b/packages/client/ui-wecom/tsdown.config.ts new file mode 100644 index 0000000000..7aa03cebc1 --- /dev/null +++ b/packages/client/ui-wecom/tsdown.config.ts @@ -0,0 +1,3 @@ +import { clientBundle } from '../tsdown.client.ts' + +export default clientBundle(import.meta.dirname, ['lib/types/index.js']) diff --git a/packages/connector/wecom-cli/locale/en.json b/packages/connector/wecom-cli/locale/en.json new file mode 100644 index 0000000000..5d7f452951 --- /dev/null +++ b/packages/connector/wecom-cli/locale/en.json @@ -0,0 +1,6 @@ +{ + "meta": { + "title": "WeCom CLI and skills", + "description": "The official wecom-cli, its skills, and the authorization the Plugins page uses" + } +} diff --git a/packages/connector/wecom-cli/locale/zh.json b/packages/connector/wecom-cli/locale/zh.json new file mode 100644 index 0000000000..acd0a60680 --- /dev/null +++ b/packages/connector/wecom-cli/locale/zh.json @@ -0,0 +1,6 @@ +{ + "meta": { + "title": "企业微信 CLI 与技能", + "description": "官方 wecom-cli、它的技能,以及插件页使用的授权" + } +} diff --git a/packages/connector/wecom-cli/package.json b/packages/connector/wecom-cli/package.json new file mode 100644 index 0000000000..8219087d0d --- /dev/null +++ b/packages/connector/wecom-cli/package.json @@ -0,0 +1,68 @@ +{ + "name": "@deepseek-ai/dsh-wecom-cli", + "description": "WeCom through the official wecom-cli: the CLI on the Shell PATH, its skills, and authorization over Remote", + "version": "0.2.1-rc.2", + "publishConfig": { + "access": "public" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/deepseek-ai/deepseek-harness.git", + "directory": "packages/connector/wecom-cli" + }, + "type": "module", + "main": "lib/index.js", + "types": "lib/types/index.d.ts", + "exports": { + ".": { + "types": "./lib/types/index.d.ts", + "default": "./lib/index.js" + }, + "./remote": { + "types": "./lib/typert.remote-client.d.ts", + "default": "./lib/typert.remote-client.js" + }, + "./typert": { + "types": "./lib/typert.host.d.ts", + "default": "./lib/typert.host.js" + }, + "./types": { + "types": "./lib/types/types.d.ts" + }, + "./locale/*.json": "./locale/*.json", + "./src/*": "./src/*", + "./package.json": "./package.json" + }, + "files": [ + "locale/*.json", + "lib/index.js", + "skills", + "lib/types/**/*.d.ts", + "lib/typert.host.js", + "lib/typert.host.d.ts", + "lib/typert.remote-client.js", + "lib/typert.remote-client.d.ts" + ], + "license": "MIT", + "dependencies": { + "@deepseek-ai/dsh-cli-account": "workspace:*", + "@deepseek-ai/dsh-skill-filesystem": "workspace:*", + "@deepseek-ai/dsh-util-values": "workspace:*", + "@deepseek-ai/schemastery": "workspace:~", + "@wecom/cli": "1.3.4" + }, + "peerDependencies": { + "@deepseek-ai/cordis": "workspace:~", + "@deepseek-ai/dsh-shell-env": "workspace:*", + "@deepseek-ai/dsh-skill": "workspace:*", + "@deepseek-ai/dsh-subprocess": "workspace:*", + "@deepseek-ai/dsh-typert-protocol": "workspace:*" + }, + "devDependencies": { + "@deepseek-ai/cordis": "workspace:~", + "@deepseek-ai/dsh-shell-env": "workspace:*", + "@deepseek-ai/dsh-skill": "workspace:*", + "@deepseek-ai/dsh-subprocess": "workspace:*", + "@deepseek-ai/dsh-typert-protocol": "workspace:*" + } +} diff --git a/packages/connector/wecom-cli/src/account.ts b/packages/connector/wecom-cli/src/account.ts index 1a0b4c2122..e09c9111ca 100644 --- a/packages/connector/wecom-cli/src/account.ts +++ b/packages/connector/wecom-cli/src/account.ts @@ -1,4 +1,7 @@ -import { CliAccountRuntime, type CliOperationControl } from '@deepseek-ai/dsh-cli-account' +/** Host-owned check and QR-code authorization of the wecom-cli bot that the user's terminal shares. */ + +import type { Context } from '@deepseek-ai/cordis' +import { CliAccountRuntime, exitFailure, type CliCommandExecutor, type CliOperationControl } from '@deepseek-ai/dsh-cli-account' import { assertNever } from '@deepseek-ai/dsh-util-values' import type { WecomAccountState, WecomOperationFailure, WecomOperationKind, WecomPhase } from './types.ts' @@ -6,7 +9,25 @@ const AUTHORIZATION_LINK = /^\s*(https:\/\/\S+)\s*$/u type Control = CliOperationControl +/** Runs at most one authorization operation at a time; subscribers observe it without owning it. */ export class WecomAccount extends CliAccountRuntime { + /** + * @param cli - the wecom-cli executor the account runs commands with and disposes. + * @param logger - receives classified operation failures. + */ + constructor(cli: CliCommandExecutor, logger: Context['logger']) { + super({ + name: 'wecom', + cli, + logger, + account: { state: 'unchecked' }, + check: 'check', + cancellable: ['authorizing'], + authorizationHosts: ['work.weixin.qq.com'], + classify: exitFailure, + }) + } + protected async perform(kind: WecomOperationKind, control: Control, signal: AbortSignal): Promise { switch (kind) { case 'check': @@ -18,6 +39,7 @@ export class WecomAccount extends CliAccountRuntime { control.stage('authorizing') const init = await control.run('auth-init', ['auth', 'init', '--noninteractive', '--no-browser'], signal, { @@ -32,6 +54,7 @@ export class WecomAccount extends CliAccountRuntime { const result = await control.run('auth-status', ['auth', 'show', '--status'], signal) const state = result.stdout.trim() diff --git a/packages/connector/wecom-cli/src/directory.ts b/packages/connector/wecom-cli/src/directory.ts index b4bd92591f..625cf29435 100644 --- a/packages/connector/wecom-cli/src/directory.ts +++ b/packages/connector/wecom-cli/src/directory.ts @@ -1,7 +1,10 @@ +/** Managed wecom-cli location: the platform binary package that `@wecom/cli` installs. */ + import { accessSync, constants } from 'node:fs' import { createRequire } from 'node:module' import { dirname, join } from 'node:path' +/** The executable name the plugin resolves on its private PATH. */ export const PROGRAM = 'wecom-cli' function platformDirectory(): string { @@ -14,6 +17,12 @@ function platformDirectory(): string { } } +/** + * Locate the directory holding the managed executable. + * @param binDir - absolute override; defaults to the `bin` of the installed `@wecom/cli--` package. + * @returns the bin directory containing an executable `wecom-cli`. + * @throws when the platform package is missing or the executable is not executable. + */ export function resolveCliDirectory(binDir: string | undefined): string { const directory = binDir ?? platformDirectory() const program = join(directory, PROGRAM) diff --git a/packages/connector/wecom-cli/src/index.ts b/packages/connector/wecom-cli/src/index.ts index 84e988fa48..8f0ba30500 100644 --- a/packages/connector/wecom-cli/src/index.ts +++ b/packages/connector/wecom-cli/src/index.ts @@ -1,10 +1,18 @@ +/** + * WeCom plugin: puts the managed wecom-cli on the private Shell PATH, registers + * its bundled skills, and serves the Plugins page's authorization over Remote. + * The CLI's authorization is shared with the user's own terminal. + * @module @deepseek-ai/dsh-wecom-cli + */ + import { fileURLToPath } from 'node:url' import type { Context } from '@deepseek-ai/cordis' import type z from '@deepseek-ai/schemastery' -import { CliAccountConfig, CliCommandExecutor, exitFailure, type CliOperationId } from '@deepseek-ai/dsh-cli-account' +import { CliAccountConfig, CliCommandExecutor, type CliOperationId } from '@deepseek-ai/dsh-cli-account' import * as SkillFilesystem from '@deepseek-ai/dsh-skill-filesystem' import { Remote, TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol' import type {} from '@deepseek-ai/dsh-shell-env' +import type {} from '@deepseek-ai/dsh-skill' import type {} from '@deepseek-ai/dsh-subprocess' import { WecomAccount } from './account.ts' import { PROGRAM, resolveCliDirectory } from './directory.ts' @@ -14,34 +22,34 @@ export type * from './types.ts' declare module '@deepseek-ai/cordis' { interface Context { + /** WeCom authorization for the Plugins page. */ wecom: Wecom } } +/** Where wecom-cli is and how long a command that does not wait for the user may run. */ export type Config = CliAccountConfig +/** Registers the CLI and skills, and owns the authorization operations the Plugins page drives. */ export default class Wecom extends TypertRemoteService { static inject = ['skills', 'subprocess', 'shellEnv'] static Config: z = CliAccountConfig private readonly account: WecomAccount + /** + * @param ctx - Context carrying the skill registry, subprocess runtime, and Shell environment. + * @param config - CLI location and command deadline. + * @throws when the subprocess runtime does not run on this Host or `wecom-cli` is not executable. + */ constructor(ctx: Context, config: Config) { super(ctx, 'wecom') if (!ctx.subprocess.runsOnHost) { throw new Error('wecom: wecom-cli and its authorization are local to this Host; mount a Host subprocess runtime') } - ctx.shellEnv.registerPath({ name: 'wecom', directories: [resolveCliDirectory(config.binDir)] }) - this.account = new WecomAccount({ - name: 'wecom', - cli: new CliCommandExecutor(ctx.subprocess, ctx.shellEnv, { program: PROGRAM, commandTimeoutMs: config.commandTimeoutMs }), - logger: ctx.logger, - account: { state: 'unchecked' }, - check: 'check', - cancellable: ['authorizing'], - authorizationHosts: ['work.weixin.qq.com'], - classify: exitFailure, - }) + ctx.shellEnv.registerPath({ name: 'wecom', directories: [resolveCliDirectory(config.binDir)], programs: [PROGRAM] }) + const cli = new CliCommandExecutor(ctx.subprocess, ctx.shellEnv, { program: PROGRAM, commandTimeoutMs: config.commandTimeoutMs }) + this.account = new WecomAccount(cli, ctx.logger) ctx.effect(() => () => this.account.dispose()) ctx.plugin(SkillFilesystem, { providerName: 'wecom', @@ -51,21 +59,41 @@ export default class Wecom extends TypertRemoteService { }) } + /** + * Check the authorization again without changing it. + * @returns the operation identity. + * @throws while another operation runs. + */ @Remote check(): CliOperationId { return this.account.start('check') } + /** + * Bind a bot through the CLI's QR-code page. + * @returns the operation identity. + * @throws while another operation runs. + */ @Remote connect(): CliOperationId { return this.account.start('connect') } + /** + * Cancel one operation while it waits for the QR-code scan, and wait for its command to exit. + * @param id - the operation to cancel; a finished one or another step is ignored. + * @returns after the operation settles, or at once when nothing is cancelled. + */ @Remote cancel(id: CliOperationId): Promise { return this.account.cancel(id) } + /** + * Follow the authorization and its operations independently of any page; each new subscriber starts a check when none runs. + * @param signal - the Client's observation lifetime. + * @returns the current view, then each changed view. + */ @Remote({ mode: 'stream' }) async *follow(signal: AbortSignal): AsyncIterable { yield* this.account.follow(signal) diff --git a/packages/connector/wecom-cli/src/types.ts b/packages/connector/wecom-cli/src/types.ts index d7b0374ecc..a457123fcc 100644 --- a/packages/connector/wecom-cli/src/types.ts +++ b/packages/connector/wecom-cli/src/types.ts @@ -1,13 +1,20 @@ +/** Credential-free WeCom authorization and operation views for Remote clients. */ + import type { CliAccountView, CliCommandFailure } from '@deepseek-ai/dsh-cli-account/types' +/** The CLI's authorization as the latest `auth show --status` reported it. */ export interface WecomAccountState { readonly state: 'unchecked' | 'unauthorized' | 'authorized' } +/** The operations the Plugins page starts. */ export type WecomOperationKind = 'check' | 'connect' +/** The WeCom step of an operation, besides the runtime's `checking` and `cancelling`. */ export type WecomPhase = 'authorizing' +/** The command and exit code of a failed operation's last command. */ export type WecomOperationFailure = CliCommandFailure<'auth-init' | 'auth-status'> +/** The complete WeCom view a Remote client replaces on every change. */ export type WecomState = CliAccountView diff --git a/packages/connector/wecom-cli/tsconfig.json b/packages/connector/wecom-cli/tsconfig.json new file mode 100644 index 0000000000..c1a5ec1e1d --- /dev/null +++ b/packages/connector/wecom-cli/tsconfig.json @@ -0,0 +1,39 @@ +{ + "extends": "../../../tsconfig.base.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "lib/types" + }, + "include": [ + "src" + ], + "references": [ + { + "path": "../../../vendor/cordis" + }, + { + "path": "../../../vendor/schemastery" + }, + { + "path": "../../skill/skill-filesystem" + }, + { + "path": "../../util/values" + }, + { + "path": "../../typert/protocol" + }, + { + "path": "../../shell/shell-env" + }, + { + "path": "../../skill/skill" + }, + { + "path": "../../subprocess/subprocess" + }, + { + "path": "../cli-account" + } + ] +} diff --git a/packages/connector/wecom/locale/en.json b/packages/connector/wecom/locale/en.json new file mode 100644 index 0000000000..b8036d1782 --- /dev/null +++ b/packages/connector/wecom/locale/en.json @@ -0,0 +1,6 @@ +{ + "meta": { + "title": "WeCom Plugin", + "description": "Use WeCom docs, calendar, meetings, to-dos, and messages in conversations" + } +} diff --git a/packages/connector/wecom/locale/zh.json b/packages/connector/wecom/locale/zh.json new file mode 100644 index 0000000000..6e9b63f5a0 --- /dev/null +++ b/packages/connector/wecom/locale/zh.json @@ -0,0 +1,6 @@ +{ + "meta": { + "title": "企业微信插件", + "description": "在对话中使用企业微信的文档、日程、会议、待办和消息" + } +} diff --git a/packages/connector/wecom/package.json b/packages/connector/wecom/package.json new file mode 100644 index 0000000000..be84817dca --- /dev/null +++ b/packages/connector/wecom/package.json @@ -0,0 +1,48 @@ +{ + "name": "@deepseek-ai/dsh-wecom", + "description": "WeCom plugin: the official wecom-cli with its skills, and authorization from the Plugins page", + "version": "0.2.1-rc.2", + "publishConfig": { + "access": "public" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/deepseek-ai/deepseek-harness.git", + "directory": "packages/connector/wecom" + }, + "type": "module", + "main": "lib/index.js", + "types": "lib/types/index.d.ts", + "exports": { + ".": { + "types": "./lib/types/index.d.ts", + "default": "./lib/index.js" + }, + "./src/*": "./src/*", + "./package.json": "./package.json", + "./cordis.patch.yml": "./cordis.patch.yml", + "./locale/*.json": "./locale/*.json" + }, + "files": [ + "locale/*.json", + "lib/index.js", + "cordis.patch.yml", + "lib/types/**/*.d.ts" + ], + "license": "MIT", + "dependencies": { + "@deepseek-ai/dsh-wecom-cli": "workspace:*", + "@deepseek-ai/dsh-client-ui-wecom": "workspace:*" + }, + "peerDependencies": { + "@deepseek-ai/cordis": "workspace:~" + }, + "devDependencies": { + "@deepseek-ai/cordis": "workspace:~" + }, + "dsh": { + "bundle": { + "patch": "./cordis.patch.yml" + } + } +} diff --git a/packages/connector/wecom/src/index.ts b/packages/connector/wecom/src/index.ts index 336ce12bb9..10eed8663b 100644 --- a/packages/connector/wecom/src/index.ts +++ b/packages/connector/wecom/src/index.ts @@ -1 +1,2 @@ +/** WeCom plugin composition; runtime rows live in cordis.patch.yml. */ export {} diff --git a/packages/connector/wecom/tsconfig.json b/packages/connector/wecom/tsconfig.json new file mode 100644 index 0000000000..f1a449634c --- /dev/null +++ b/packages/connector/wecom/tsconfig.json @@ -0,0 +1,15 @@ +{ + "extends": "../../../tsconfig.base.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "lib/types" + }, + "include": [ + "src" + ], + "references": [ + { + "path": "../../../vendor/cordis" + } + ] +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 789d1ee6c4..585e16118a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -135,6 +135,12 @@ importers: '@deepseek-ai/dsh-web-fetch-http': specifier: workspace:* version: link:packages/web/web-fetch-http + '@deepseek-ai/dsh-wecom': + specifier: workspace:* + version: link:packages/connector/wecom + '@deepseek-ai/dsh-wecom-cli': + specifier: workspace:* + version: link:packages/connector/wecom-cli '@deepseek-ai/dsh-working-directory': specifier: workspace:* version: link:packages/session/working-directory @@ -6876,6 +6882,63 @@ importers: specifier: ^18.2.0 version: 18.3.1 + packages/client/ui-wecom: + devDependencies: + '@deepseek-ai/cordis': + specifier: workspace:~ + version: link:../../../vendor/cordis + '@deepseek-ai/dsh-api-gateway': + specifier: workspace:* + version: link:../../api/gateway + '@deepseek-ai/dsh-api-remotes': + specifier: workspace:* + version: link:../../api/remotes + '@deepseek-ai/dsh-cli-account': + specifier: workspace:* + version: link:../../connector/cli-account + '@deepseek-ai/dsh-client-locale': + specifier: workspace:* + version: link:../locale + '@deepseek-ai/dsh-client-store': + specifier: workspace:* + version: link:../store + '@deepseek-ai/dsh-client-test-runtime': + specifier: workspace:* + version: link:../../test-support/client-runtime + '@deepseek-ai/dsh-client-ui-cli-account': + specifier: workspace:* + version: link:../ui-cli-account + '@deepseek-ai/dsh-client-ui-layout': + specifier: workspace:* + version: link:../ui-layout + '@deepseek-ai/dsh-client-ui-plugin-manager': + specifier: workspace:* + version: link:../ui-plugin-manager + '@deepseek-ai/dsh-client-ui-renderer': + specifier: workspace:* + version: link:../ui-renderer + '@deepseek-ai/dsh-client-ui-slots': + specifier: workspace:* + version: link:../ui-slots + '@deepseek-ai/dsh-typert-protocol': + specifier: workspace:* + version: link:../../typert/protocol + '@deepseek-ai/dsh-util-values': + specifier: workspace:* + version: link:../../util/values + '@deepseek-ai/dsh-wecom-cli': + specifier: workspace:* + version: link:../../connector/wecom-cli + '@testing-library/react': + specifier: ^16.3.3 + version: 16.3.3(@testing-library/dom@10.4.2)(@types/react-dom@18.3.7(@types/react@18.3.31))(@types/react@18.3.31)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + react: + specifier: ^18.2.0 + version: 18.3.1 + react-dom: + specifier: ^18.2.0 + version: 18.3.1(react@18.3.1) + packages/client/ui-workflow-run: devDependencies: '@deepseek-ai/cordis': @@ -7307,6 +7370,53 @@ importers: specifier: workspace:* version: link:../../skill/skill + packages/connector/wecom: + dependencies: + '@deepseek-ai/dsh-client-ui-wecom': + specifier: workspace:* + version: link:../../client/ui-wecom + '@deepseek-ai/dsh-wecom-cli': + specifier: workspace:* + version: link:../wecom-cli + devDependencies: + '@deepseek-ai/cordis': + specifier: workspace:~ + version: link:../../../vendor/cordis + + packages/connector/wecom-cli: + dependencies: + '@deepseek-ai/dsh-cli-account': + specifier: workspace:* + version: link:../cli-account + '@deepseek-ai/dsh-skill-filesystem': + specifier: workspace:* + version: link:../../skill/skill-filesystem + '@deepseek-ai/dsh-util-values': + specifier: workspace:* + version: link:../../util/values + '@deepseek-ai/schemastery': + specifier: link:../../../vendor/schemastery + version: link:../../../vendor/schemastery + '@wecom/cli': + specifier: 1.3.4 + version: 1.3.4 + devDependencies: + '@deepseek-ai/cordis': + specifier: workspace:~ + version: link:../../../vendor/cordis + '@deepseek-ai/dsh-shell-env': + specifier: workspace:* + version: link:../../shell/shell-env + '@deepseek-ai/dsh-skill': + specifier: workspace:* + version: link:../../skill/skill + '@deepseek-ai/dsh-subprocess': + specifier: workspace:* + version: link:../../subprocess/subprocess + '@deepseek-ai/dsh-typert-protocol': + specifier: workspace:* + version: link:../../typert/protocol + packages/context/agent-instructions: dependencies: '@deepseek-ai/dsh-util-values': @@ -21550,6 +21660,41 @@ packages: '@vueuse/shared@12.8.2': resolution: {integrity: sha512-dznP38YzxZoNloI0qpEfpkms8knDtaoQ6Y/sfS0L7Yki4zh40LFHEhur0odJC6xTHG5dxWVPiUWBXn+wCG2s5w==} + '@wecom/cli-darwin-arm64@1.3.4': + resolution: {integrity: sha512-mktTGWYWqwE5exPs/vdiYcwas77G7DPEhAmj1Hl0LqQHUp6tfwplSfJQ/TaESZvmKtoqDglrywtIQeJ0ksFsWA==} + engines: {node: '>=18'} + cpu: [arm64] + os: [darwin] + + '@wecom/cli-darwin-x64@1.3.4': + resolution: {integrity: sha512-w9TuS95c06uyqbylxNjBCtC3GvR/6Vf6WK1zvsIcif7ivUq6Gu5scssagbD6rBWwhQUJ6o2MQKufpa439mL8bg==} + engines: {node: '>=18'} + cpu: [x64] + os: [darwin] + + '@wecom/cli-linux-arm64@1.3.4': + resolution: {integrity: sha512-BUvkJCMiM6aImK1MGjA6TuNslfay9eg/cOrmmvg3RLAlB9xTQUfqdq9YQxFog04wEpnlZSsgNXq6bWQaIvwX9w==} + engines: {node: '>=18'} + cpu: [arm64] + os: [linux] + + '@wecom/cli-linux-x64@1.3.4': + resolution: {integrity: sha512-Mguwa8AqwTM5hqKZXBs7lwMJ7AZLCJpu+usuHdQLQV9bzF3gM9e70khKHAQCS7focgMHvT/+mW++S7JvXKdL6Q==} + engines: {node: '>=18'} + cpu: [x64] + os: [linux] + + '@wecom/cli-win32-x64@1.3.4': + resolution: {integrity: sha512-FomGDkkDVZpKB9GZjAdMvR7491z9DMiaEzYQyDkA+3Yx6I100gJFnIJ31VZr6oMIRrZCT19GzNP+7c4DzuoPbg==} + engines: {node: '>=18'} + cpu: [x64] + os: [win32] + + '@wecom/cli@1.3.4': + resolution: {integrity: sha512-vz47EsT/BKkHBONVt94xhZtUWhvMR4uF9Y4TTNUwF7PnLETqyFyrNNHwG3aTLmhMNC/ecqRWUUqvNgP90nreaQ==} + engines: {node: '>=18'} + hasBin: true + '@xmldom/xmldom@0.8.15': resolution: {integrity: sha512-/5NV/vDALVFDXgLmfsy9TRCBlKwO2LNBFzpzvb9iIj+jR+eSc6DLYYvVOdivT/jm7MtU6TebYuRmzEOI7w40UA==} engines: {node: '>=10.0.0'} @@ -29026,6 +29171,29 @@ snapshots: transitivePeerDependencies: - typescript + '@wecom/cli-darwin-arm64@1.3.4': + optional: true + + '@wecom/cli-darwin-x64@1.3.4': + optional: true + + '@wecom/cli-linux-arm64@1.3.4': + optional: true + + '@wecom/cli-linux-x64@1.3.4': + optional: true + + '@wecom/cli-win32-x64@1.3.4': + optional: true + + '@wecom/cli@1.3.4': + optionalDependencies: + '@wecom/cli-darwin-arm64': 1.3.4 + '@wecom/cli-darwin-x64': 1.3.4 + '@wecom/cli-linux-arm64': 1.3.4 + '@wecom/cli-linux-x64': 1.3.4 + '@wecom/cli-win32-x64': 1.3.4 + '@xmldom/xmldom@0.8.15': {} '@xterm/addon-fit@0.11.0': {} diff --git a/scripts/check-workspace-constraints.ts b/scripts/check-workspace-constraints.ts index c3868da130..3948e4d20a 100644 --- a/scripts/check-workspace-constraints.ts +++ b/scripts/check-workspace-constraints.ts @@ -209,6 +209,8 @@ const packageFileExtras: Readonly> = { '@deepseek-ai/dsh-client-ui-theme': ['lib/styles'], // The physical-key protocol is a public entry usable without the browser service. '@deepseek-ai/dsh-client-shortcuts': ['lib/protocol.js'], + // The WeCom plugin ships the official skills upstream publishes only in its repository. + '@deepseek-ai/dsh-wecom-cli': ['skills'], // The CPython side ships as source .py files, published as-is rather than built. '@deepseek-ai/dsh-experimental-ptc-runtime-python': ['py/**/*.py'], '@deepseek-ai/dsh-experimental-speech-to-text-sensevoice': ['runtime/assets.json'], diff --git a/scripts/product-package-policy.ts b/scripts/product-package-policy.ts index 7003b0a158..f07cc18a34 100644 --- a/scripts/product-package-policy.ts +++ b/scripts/product-package-policy.ts @@ -32,6 +32,9 @@ export const PRODUCT_PACKAGE_POLICY: Readonly