Require confirmation and previews for Hose deployment
This commit is contained in:
1 parent
fa2be3a4e9
commit
22f4c87ecc
8 files changed
+250
-37
No files matched your search
@@ -1198,7 +1198,8 @@ describe("sealCapabilities", () => {
|
||||
apiSecret: "test-sk",
|
||||
apiOrigin: "custom",
|
||||
customApiUrl: "https://dd2.hosecloud.com",
|
||||
outboundName: "DingTalk AI Audit"
|
||||
outboundName: "DingTalk AI Audit",
|
||||
confirm: true
|
||||
},
|
||||
fakeContext()
|
||||
) as { integration: { corporationId: string; apiOrigin: string; customApiUrl: string; outboundName: string } };
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { KyInstance } from "ky";
|
||||
import { randomBytes } from "node:crypto";
|
||||
import * as api from "../api.js";
|
||||
import { probeHoseDomain } from "../../../core/auth/hose.js";
|
||||
import { validationError } from "../../../core/errors.js";
|
||||
import { confirmationRequired, validationError } from "../../../core/errors.js";
|
||||
import { type HosecloudConfigInput } from "../types.js";
|
||||
import {
|
||||
assertAssistedIntegration,
|
||||
@@ -115,12 +115,13 @@ export const deployCapabilities = [
|
||||
autoApproveNodeNames: z.array(z.string()).optional(),
|
||||
apiOrigin: z.string().default("production"),
|
||||
customApiUrl: z.string().optional(),
|
||||
dryRun: z.boolean().optional().describe("只返回前后配置 Diff,不执行写入")
|
||||
dryRun: z.boolean().optional().describe("只返回前后配置 Diff,不执行写入"),
|
||||
confirm: z.boolean().optional().describe("明确确认保存配置;CLI 使用 --yes 或 --confirm")
|
||||
}),
|
||||
handler: async (client: KyInstance, rawParams: HosecloudConfigInput, context: CapabilityContext) => {
|
||||
const { dryRun, ...inputParams } = rawParams;
|
||||
const apiKey = inputParams.apiKey ?? (inputParams as any).appKey;
|
||||
const apiSecret = inputParams.apiSecret ?? (inputParams as any).appSecurity;
|
||||
const { dryRun, confirm, appKey, appSecurity, ...inputParams } = rawParams;
|
||||
const apiKey = inputParams.apiKey ?? (typeof appKey === "string" ? appKey : undefined);
|
||||
const apiSecret = inputParams.apiSecret ?? (typeof appSecurity === "string" ? appSecurity : undefined);
|
||||
if (!apiKey || !apiSecret) {
|
||||
throw new Error("缺少合思凭证:apiKey (或 appKey) 与 apiSecret (或 appSecurity) 为必填项");
|
||||
}
|
||||
@@ -128,6 +129,16 @@ export const deployCapabilities = [
|
||||
let effectiveApiOrigin = params.apiOrigin ?? "production";
|
||||
let effectiveCustomApiUrl = params.customApiUrl;
|
||||
|
||||
if (effectiveApiOrigin === "custom" && !effectiveCustomApiUrl) {
|
||||
throw new Error("自定义合思环境必须提供 customApiUrl");
|
||||
}
|
||||
if (!dryRun && confirm !== true) {
|
||||
throw confirmationRequired(
|
||||
"Refusing to save Hose integration configuration without --yes or --confirm. Use --dry-run to preview first.",
|
||||
"seal-use help deploy hosecloud configure"
|
||||
);
|
||||
}
|
||||
|
||||
// 自动平台/域名探测:当未提供 customApiUrl 时,并发探测合思 6 大标准公共 SaaS 平台域名
|
||||
if (!effectiveCustomApiUrl && effectiveApiOrigin !== "custom") {
|
||||
try {
|
||||
@@ -146,17 +157,13 @@ export const deployCapabilities = [
|
||||
}
|
||||
}
|
||||
|
||||
if (effectiveApiOrigin === "custom" && !effectiveCustomApiUrl) {
|
||||
throw new Error("自定义合思环境必须提供 customApiUrl");
|
||||
}
|
||||
|
||||
const corpResult = await api.getHosecloudCorporation(client, {
|
||||
apiKey: params.apiKey,
|
||||
apiSecret: params.apiSecret,
|
||||
apiOrigin: effectiveApiOrigin,
|
||||
customApiUrl: effectiveCustomApiUrl
|
||||
});
|
||||
const config = await api.getApprovalStylePreferences(client);
|
||||
const config = await api.getApprovalStylePreferences(client, context.corp.seal.endpoints.approvalStylePreferences);
|
||||
const signKey = params.signKey ?? randomBytes(6).toString("hex");
|
||||
const nextIntegration = {
|
||||
type: "hosecloud",
|
||||
@@ -187,7 +194,7 @@ export const deployCapabilities = [
|
||||
await api.updateApprovalStylePreferences(client, nextConfig, context.corp.seal.endpoints.approvalStylePreferences);
|
||||
|
||||
console.error(`✓ 配置已保存 (signKey: ${signKey})`);
|
||||
console.error(`👉 Next action: seal-use deploy hosecloud sync ${signKey} --corp ${context.corp.id}`);
|
||||
console.error(`👉 Next action: seal-use deploy hosecloud sync ${signKey} --dry-run --corp ${context.corp.id}`);
|
||||
|
||||
return {
|
||||
integration: redactIntegrationSecrets(nextIntegration)
|
||||
@@ -198,10 +205,18 @@ export const deployCapabilities = [
|
||||
name: "sealDeployHosecloudSync",
|
||||
description: "一键将 Seal AI 审核配置同步发布到合思费控审批流",
|
||||
parameters: z.object({
|
||||
signKey: z.string().describe("合思集成 sign-key")
|
||||
signKey: z.string().describe("合思集成 sign-key"),
|
||||
dryRun: z.boolean().optional().describe("只预览待同步的消息名称、回调地址和模式,不执行同步"),
|
||||
confirm: z.boolean().optional().describe("明确确认同步到合思;CLI 使用 --yes 或 --confirm")
|
||||
}),
|
||||
handler: async (client: KyInstance, params: { signKey: string }, context: CapabilityContext) => {
|
||||
const config = await api.getApprovalStylePreferences(client);
|
||||
handler: async (client: KyInstance, params: { signKey: string; dryRun?: boolean; confirm?: boolean }, context: CapabilityContext) => {
|
||||
if (!params.dryRun && params.confirm !== true) {
|
||||
throw confirmationRequired(
|
||||
"Refusing to synchronize Hose outbound messages without --yes or --confirm. Use --dry-run to preview first.",
|
||||
`seal-use deploy hosecloud sync ${params.signKey} --dry-run --corp ${context.corp.id}`
|
||||
);
|
||||
}
|
||||
const config = await api.getApprovalStylePreferences(client, context.corp.seal.endpoints.approvalStylePreferences);
|
||||
const integration = listHoseIntegrations(config).find(
|
||||
(item) => item.signKey === params.signKey
|
||||
);
|
||||
@@ -210,13 +225,22 @@ export const deployCapabilities = [
|
||||
}
|
||||
const sealUrl = (context.corp.seal.url ?? `https://${context.corp.id.toLowerCase()}.sealai.cc`).replace(/\/+$/, "");
|
||||
const messageName = integration.outboundName ?? "SealAI 审批";
|
||||
const result = await api.syncHosecloudOutbound(client, {
|
||||
const payload = {
|
||||
signKey: params.signKey,
|
||||
webhookUrl: buildOutboundWebhookUrl(context.corp, params.signKey),
|
||||
completionWebhookUrl: `${sealUrl}/api/hosecloud/flow/completion?config_id=${encodeURIComponent(params.signKey)}`,
|
||||
messageName,
|
||||
mode: integration.mode ?? "assisted"
|
||||
});
|
||||
};
|
||||
if (params.dryRun) {
|
||||
return {
|
||||
...mutationPreview(context, "api/hosecloud/outbound-config/sync", null, payload, 1),
|
||||
signKey: params.signKey,
|
||||
remoteStateKnown: false,
|
||||
note: "仅预览将同步的消息名称、回调地址和模式;合思远端当前配置尚未读取。"
|
||||
};
|
||||
}
|
||||
const result = await api.syncHosecloudOutbound(client, payload);
|
||||
|
||||
console.error(`✓ 同步成功!出站消息已在合思开放平台创建/更新: "${messageName}"`);
|
||||
console.error(`👉 发布完成:请登录合思后台在审批流中添加【EBot】节点并选择 "${messageName}"。`);
|
||||
|
||||
@@ -598,6 +598,7 @@ export const ThinkingDepthPreferenceSchema = z.object({
|
||||
|
||||
export const HosecloudConfigInputSchema = z.object({
|
||||
dryRun: z.boolean().optional(),
|
||||
confirm: z.boolean().optional(),
|
||||
signKey: z.string().min(1).optional(),
|
||||
outboundName: z.string().optional(),
|
||||
specificationId: z.string().optional(),
|
||||
|
||||
Reference in new issue
Block a user