@harrylabsj/kiwi 0.7.22 → 0.9.0
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/README.md +45 -10
- package/dist/a2a/negotiate.d.ts +6 -2
- package/dist/a2a/negotiate.js +10 -3
- package/dist/a2a/negotiate.js.map +1 -1
- package/dist/a2a/node.d.ts +4 -1
- package/dist/a2a/node.js +57 -4
- package/dist/a2a/node.js.map +1 -1
- package/dist/a2a/server/merchant-handler.d.ts +11 -3
- package/dist/a2a/server/merchant-handler.js +84 -26
- package/dist/a2a/server/merchant-handler.js.map +1 -1
- package/dist/agent/buyer/buyer-tools.js +17 -10
- package/dist/agent/buyer/buyer-tools.js.map +1 -1
- package/dist/agent/buyer/scheduler.d.ts +1 -0
- package/dist/agent/buyer/scheduler.js +5 -1
- package/dist/agent/buyer/scheduler.js.map +1 -1
- package/dist/agent/buyer/task-store.js +5 -2
- package/dist/agent/buyer/task-store.js.map +1 -1
- package/dist/agent/chat-tools.js +10 -3
- package/dist/agent/chat-tools.js.map +1 -1
- package/dist/agent/context/fencing.d.ts +27 -0
- package/dist/agent/context/fencing.js +126 -0
- package/dist/agent/context/fencing.js.map +1 -0
- package/dist/agent/context/grounding.d.ts +18 -0
- package/dist/agent/context/grounding.js +22 -0
- package/dist/agent/context/grounding.js.map +1 -0
- package/dist/agent/host/events.d.ts +31 -0
- package/dist/agent/host/events.js +62 -0
- package/dist/agent/host/events.js.map +1 -0
- package/dist/agent/host/tui-renderer.d.ts +17 -0
- package/dist/agent/host/tui-renderer.js +125 -0
- package/dist/agent/host/tui-renderer.js.map +1 -0
- package/dist/agent/host/web-renderer.d.ts +71 -0
- package/dist/agent/host/web-renderer.js +185 -0
- package/dist/agent/host/web-renderer.js.map +1 -0
- package/dist/agent/kernel-builder.d.ts +3 -1
- package/dist/agent/kernel-builder.js +4 -1
- package/dist/agent/kernel-builder.js.map +1 -1
- package/dist/agent/kernel.d.ts +20 -1
- package/dist/agent/kernel.js +255 -14
- package/dist/agent/kernel.js.map +1 -1
- package/dist/agent/memory/schema.d.ts +1 -1
- package/dist/agent/memory/schema.js +9 -1
- package/dist/agent/memory/schema.js.map +1 -1
- package/dist/agent/merchant/action-candidate.d.ts +18 -0
- package/dist/agent/merchant/action-candidate.js +51 -0
- package/dist/agent/merchant/action-candidate.js.map +1 -1
- package/dist/agent/merchant/fake-merchant-client.js +6 -1
- package/dist/agent/merchant/fake-merchant-client.js.map +1 -1
- package/dist/agent/merchant/intelligence/backend.d.ts +40 -0
- package/dist/agent/merchant/intelligence/backend.js +2 -0
- package/dist/agent/merchant/intelligence/backend.js.map +1 -0
- package/dist/agent/merchant/intelligence/default-backend.d.ts +38 -0
- package/dist/agent/merchant/intelligence/default-backend.js +477 -0
- package/dist/agent/merchant/intelligence/default-backend.js.map +1 -0
- package/dist/agent/merchant/intelligence/http-analytics-source.d.ts +55 -0
- package/dist/agent/merchant/intelligence/http-analytics-source.js +193 -0
- package/dist/agent/merchant/intelligence/http-analytics-source.js.map +1 -0
- package/dist/agent/merchant/intelligence/types.d.ts +109 -0
- package/dist/agent/merchant/intelligence/types.js +2 -0
- package/dist/agent/merchant/intelligence/types.js.map +1 -0
- package/dist/agent/merchant/merchant-client.d.ts +50 -1
- package/dist/agent/merchant/merchant-client.js +157 -8
- package/dist/agent/merchant/merchant-client.js.map +1 -1
- package/dist/agent/merchant/merchant-enrichment.d.ts +10 -0
- package/dist/agent/merchant/merchant-enrichment.js +38 -0
- package/dist/agent/merchant/merchant-enrichment.js.map +1 -0
- package/dist/agent/merchant/merchant-grounding.d.ts +5 -0
- package/dist/agent/merchant/merchant-grounding.js +76 -0
- package/dist/agent/merchant/merchant-grounding.js.map +1 -0
- package/dist/agent/merchant/merchant-presentations.d.ts +8 -0
- package/dist/agent/merchant/merchant-presentations.js +207 -0
- package/dist/agent/merchant/merchant-presentations.js.map +1 -0
- package/dist/agent/merchant/merchant-tools.d.ts +8 -0
- package/dist/agent/merchant/merchant-tools.js +291 -178
- package/dist/agent/merchant/merchant-tools.js.map +1 -1
- package/dist/agent/merchant/types.d.ts +6 -2
- package/dist/agent/merchant/types.js +45 -0
- package/dist/agent/merchant/types.js.map +1 -1
- package/dist/agent/presentation/registry.d.ts +14 -0
- package/dist/agent/presentation/registry.js +24 -0
- package/dist/agent/presentation/registry.js.map +1 -0
- package/dist/agent/presentation/runner.d.ts +11 -0
- package/dist/agent/presentation/runner.js +17 -0
- package/dist/agent/presentation/runner.js.map +1 -0
- package/dist/agent/presentation/sanitize.d.ts +16 -0
- package/dist/agent/presentation/sanitize.js +37 -0
- package/dist/agent/presentation/sanitize.js.map +1 -0
- package/dist/agent/presentation/types.d.ts +28 -0
- package/dist/agent/presentation/types.js +8 -0
- package/dist/agent/presentation/types.js.map +1 -0
- package/dist/agent/session.d.ts +1 -1
- package/dist/agent/session.js +2 -2
- package/dist/agent/session.js.map +1 -1
- package/dist/agent/skills/registry.d.ts +11 -0
- package/dist/agent/skills/registry.js +119 -0
- package/dist/agent/skills/registry.js.map +1 -0
- package/dist/agent/skills/tools.d.ts +6 -0
- package/dist/agent/skills/tools.js +36 -0
- package/dist/agent/skills/tools.js.map +1 -0
- package/dist/agent/skills/types.d.ts +9 -0
- package/dist/agent/skills/types.js +2 -0
- package/dist/agent/skills/types.js.map +1 -0
- package/dist/agent/supplier/scheduler.d.ts +2 -0
- package/dist/agent/supplier/scheduler.js +101 -22
- package/dist/agent/supplier/scheduler.js.map +1 -1
- package/dist/agent/supplier/store.d.ts +2 -0
- package/dist/agent/supplier/store.js +44 -0
- package/dist/agent/supplier/store.js.map +1 -1
- package/dist/agent/system-prompt.d.ts +5 -1
- package/dist/agent/system-prompt.js +20 -3
- package/dist/agent/system-prompt.js.map +1 -1
- package/dist/auth/merchant-authorization.d.ts +49 -0
- package/dist/auth/merchant-authorization.js +61 -0
- package/dist/auth/merchant-authorization.js.map +1 -0
- package/dist/auth/merchant-oauth.d.ts +255 -0
- package/dist/auth/merchant-oauth.js +764 -0
- package/dist/auth/merchant-oauth.js.map +1 -0
- package/dist/auth/merchant-pairing.d.ts +62 -0
- package/dist/auth/merchant-pairing.js +199 -0
- package/dist/auth/merchant-pairing.js.map +1 -0
- package/dist/auth/merchant-sessions.d.ts +71 -0
- package/dist/auth/merchant-sessions.js +168 -0
- package/dist/auth/merchant-sessions.js.map +1 -0
- package/dist/buyer-core/build-service.d.ts +5 -0
- package/dist/buyer-core/build-service.js +12 -0
- package/dist/buyer-core/build-service.js.map +1 -1
- package/dist/buyer-core/errors.d.ts +1 -1
- package/dist/buyer-core/errors.js +2 -0
- package/dist/buyer-core/errors.js.map +1 -1
- package/dist/buyer-core/merchant-index.d.ts +19 -4
- package/dist/buyer-core/merchant-index.js +137 -16
- package/dist/buyer-core/merchant-index.js.map +1 -1
- package/dist/buyer-core/negotiator.d.ts +0 -10
- package/dist/buyer-core/negotiator.js +12 -1
- package/dist/buyer-core/negotiator.js.map +1 -1
- package/dist/buyer-core/quote-fetcher.js +2 -1
- package/dist/buyer-core/quote-fetcher.js.map +1 -1
- package/dist/buyer-core/service.d.ts +104 -0
- package/dist/buyer-core/service.js +105 -1
- package/dist/buyer-core/service.js.map +1 -1
- package/dist/cli.d.ts +4 -2
- package/dist/cli.js +644 -32
- package/dist/cli.js.map +1 -1
- package/dist/config/profile.d.ts +51 -0
- package/dist/config/profile.js +185 -61
- package/dist/config/profile.js.map +1 -1
- package/dist/demo/demo-runner.js +12 -9
- package/dist/demo/demo-runner.js.map +1 -1
- package/dist/discovery/catalog-source/buyer-follows.d.ts +82 -0
- package/dist/discovery/catalog-source/buyer-follows.js +228 -0
- package/dist/discovery/catalog-source/buyer-follows.js.map +1 -0
- package/dist/discovery/catalog-source/connector-identity.d.ts +75 -0
- package/dist/discovery/catalog-source/connector-identity.js +175 -0
- package/dist/discovery/catalog-source/connector-identity.js.map +1 -0
- package/dist/discovery/catalog-source/errors.d.ts +1 -1
- package/dist/discovery/catalog-source/errors.js +2 -0
- package/dist/discovery/catalog-source/errors.js.map +1 -1
- package/dist/discovery/catalog-source/kiwi-record.d.ts +2 -0
- package/dist/discovery/catalog-source/kiwi-record.js.map +1 -1
- package/dist/discovery/catalog-source/kiwi-source.js +2 -0
- package/dist/discovery/catalog-source/kiwi-source.js.map +1 -1
- package/dist/discovery/catalog-source/merchant-publications.d.ts +65 -0
- package/dist/discovery/catalog-source/merchant-publications.js +207 -0
- package/dist/discovery/catalog-source/merchant-publications.js.map +1 -0
- package/dist/discovery/catalog-source/register.d.ts +24 -0
- package/dist/discovery/catalog-source/register.js +46 -0
- package/dist/discovery/catalog-source/register.js.map +1 -1
- package/dist/discovery/catalog-source/source.js +2 -1
- package/dist/discovery/catalog-source/source.js.map +1 -1
- package/dist/fs/atomic-write.d.ts +18 -0
- package/dist/fs/atomic-write.js +29 -0
- package/dist/fs/atomic-write.js.map +1 -0
- package/dist/handoff/authorization.js +1 -1
- package/dist/http/merchant-server.d.ts +65 -0
- package/dist/http/merchant-server.js +346 -0
- package/dist/http/merchant-server.js.map +1 -0
- package/dist/http/server.js +4 -1
- package/dist/http/server.js.map +1 -1
- package/dist/mcp/cli.d.ts +2 -0
- package/dist/mcp/cli.js +7 -6
- package/dist/mcp/cli.js.map +1 -1
- package/dist/mcp/merchant-auth.d.ts +78 -0
- package/dist/mcp/merchant-auth.js +146 -0
- package/dist/mcp/merchant-auth.js.map +1 -0
- package/dist/mcp/merchant-dirs.d.ts +26 -0
- package/dist/mcp/merchant-dirs.js +44 -0
- package/dist/mcp/merchant-dirs.js.map +1 -0
- package/dist/mcp/merchant-resources.d.ts +38 -0
- package/dist/mcp/merchant-resources.js +146 -0
- package/dist/mcp/merchant-resources.js.map +1 -0
- package/dist/mcp/merchant-server.d.ts +106 -0
- package/dist/mcp/merchant-server.js +615 -0
- package/dist/mcp/merchant-server.js.map +1 -0
- package/dist/mcp/merchant-tools.d.ts +103 -0
- package/dist/mcp/merchant-tools.js +517 -0
- package/dist/mcp/merchant-tools.js.map +1 -0
- package/dist/mcp/server.js +4 -3
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/tools.d.ts +5 -3
- package/dist/mcp/tools.js +102 -5
- package/dist/mcp/tools.js.map +1 -1
- package/dist/mcp/types.d.ts +1 -1
- package/dist/mcp/types.js +4 -0
- package/dist/mcp/types.js.map +1 -1
- package/dist/merchant/ops.d.ts +0 -11
- package/dist/merchant/ops.js +13 -1
- package/dist/merchant/ops.js.map +1 -1
- package/dist/merchant/stats-store.d.ts +7 -0
- package/dist/merchant/stats-store.js +11 -0
- package/dist/merchant/stats-store.js.map +1 -1
- package/dist/merchant/workbench-service.d.ts +189 -0
- package/dist/merchant/workbench-service.js +417 -0
- package/dist/merchant/workbench-service.js.map +1 -0
- package/dist/merchant-admin/pending-page.d.ts +35 -0
- package/dist/merchant-admin/pending-page.js +69 -0
- package/dist/merchant-admin/pending-page.js.map +1 -0
- package/dist/merchant-core/commands.d.ts +99 -0
- package/dist/merchant-core/commands.js +179 -0
- package/dist/merchant-core/commands.js.map +1 -0
- package/dist/merchant-core/executor.d.ts +69 -0
- package/dist/merchant-core/executor.js +218 -0
- package/dist/merchant-core/executor.js.map +1 -0
- package/dist/merchant-core/negotiation-adapters.d.ts +55 -0
- package/dist/merchant-core/negotiation-adapters.js +55 -0
- package/dist/merchant-core/negotiation-adapters.js.map +1 -0
- package/dist/merchant-core/network-checks.d.ts +65 -0
- package/dist/merchant-core/network-checks.js +111 -0
- package/dist/merchant-core/network-checks.js.map +1 -0
- package/dist/merchant-core/operations.d.ts +64 -0
- package/dist/merchant-core/operations.js +136 -0
- package/dist/merchant-core/operations.js.map +1 -0
- package/dist/merchant-core/policy-runtime.d.ts +70 -0
- package/dist/merchant-core/policy-runtime.js +181 -0
- package/dist/merchant-core/policy-runtime.js.map +1 -0
- package/dist/merchant-core/product-import.d.ts +67 -0
- package/dist/merchant-core/product-import.js +160 -0
- package/dist/merchant-core/product-import.js.map +1 -0
- package/dist/merchant-core/service.d.ts +203 -0
- package/dist/merchant-core/service.js +402 -0
- package/dist/merchant-core/service.js.map +1 -0
- package/dist/merchant-gateway/catalog-publications.d.ts +71 -0
- package/dist/merchant-gateway/catalog-publications.js +175 -0
- package/dist/merchant-gateway/catalog-publications.js.map +1 -0
- package/dist/merchant-gateway/catalog-tools.d.ts +46 -0
- package/dist/merchant-gateway/catalog-tools.js +277 -0
- package/dist/merchant-gateway/catalog-tools.js.map +1 -0
- package/dist/merchant-gateway/cli.d.ts +75 -0
- package/dist/merchant-gateway/cli.js +458 -0
- package/dist/merchant-gateway/cli.js.map +1 -0
- package/dist/merchant-gateway/credential-vault.d.ts +44 -0
- package/dist/merchant-gateway/credential-vault.js +111 -0
- package/dist/merchant-gateway/credential-vault.js.map +1 -0
- package/dist/merchant-gateway/entry-server.d.ts +117 -0
- package/dist/merchant-gateway/entry-server.js +710 -0
- package/dist/merchant-gateway/entry-server.js.map +1 -0
- package/dist/merchant-gateway/instance-registration.d.ts +143 -0
- package/dist/merchant-gateway/instance-registration.js +382 -0
- package/dist/merchant-gateway/instance-registration.js.map +1 -0
- package/dist/merchant-gateway/instance-tools.d.ts +58 -0
- package/dist/merchant-gateway/instance-tools.js +184 -0
- package/dist/merchant-gateway/instance-tools.js.map +1 -0
- package/dist/merchant-gateway/mcp-proxy.d.ts +25 -0
- package/dist/merchant-gateway/mcp-proxy.js +192 -0
- package/dist/merchant-gateway/mcp-proxy.js.map +1 -0
- package/dist/merchant-gateway/pinned-fetch.d.ts +52 -0
- package/dist/merchant-gateway/pinned-fetch.js +212 -0
- package/dist/merchant-gateway/pinned-fetch.js.map +1 -0
- package/dist/merchant-gateway/tenant-registry.d.ts +82 -0
- package/dist/merchant-gateway/tenant-registry.js +190 -0
- package/dist/merchant-gateway/tenant-registry.js.map +1 -0
- package/dist/merchant-gateway/tool-bundle.d.ts +26 -0
- package/dist/merchant-gateway/tool-bundle.js +56 -0
- package/dist/merchant-gateway/tool-bundle.js.map +1 -0
- package/dist/merchant-runtime/backup.d.ts +48 -0
- package/dist/merchant-runtime/backup.js +226 -0
- package/dist/merchant-runtime/backup.js.map +1 -0
- package/dist/merchant-runtime/health.d.ts +99 -0
- package/dist/merchant-runtime/health.js +206 -0
- package/dist/merchant-runtime/health.js.map +1 -0
- package/dist/merchant-runtime/jobs.d.ts +64 -0
- package/dist/merchant-runtime/jobs.js +107 -0
- package/dist/merchant-runtime/jobs.js.map +1 -0
- package/dist/merchant-runtime/manager.d.ts +94 -0
- package/dist/merchant-runtime/manager.js +305 -0
- package/dist/merchant-runtime/manager.js.map +1 -0
- package/dist/merchant-runtime/services.d.ts +30 -0
- package/dist/merchant-runtime/services.js +51 -0
- package/dist/merchant-runtime/services.js.map +1 -0
- package/dist/negotiation/action-candidate.js +1 -1
- package/dist/net/url.d.ts +26 -0
- package/dist/net/url.js +32 -0
- package/dist/net/url.js.map +1 -0
- package/dist/operator/types.d.ts +1 -1
- package/dist/product-cli.d.ts +2 -2
- package/dist/product-cli.js +27 -6
- package/dist/product-cli.js.map +1 -1
- package/dist/product-compat.d.ts +9 -1
- package/dist/product-compat.js +12 -1
- package/dist/product-compat.js.map +1 -1
- package/dist/product-init.js +17 -5
- package/dist/product-init.js.map +1 -1
- package/dist/product-publish.js +2 -1
- package/dist/product-publish.js.map +1 -1
- package/dist/product-supplier.d.ts +73 -0
- package/dist/product-supplier.js +224 -5
- package/dist/product-supplier.js.map +1 -1
- package/dist/runtime/fake-model.d.ts +1 -1
- package/dist/trust/identity/jwk.d.ts +11 -0
- package/dist/trust/identity/jwk.js +2 -0
- package/dist/trust/identity/jwk.js.map +1 -0
- package/dist/trust/identity/jws.d.ts +2 -1
- package/dist/trust/identity/jws.js.map +1 -1
- package/dist/trust/identity/keys.d.ts +2 -1
- package/dist/trust/identity/keys.js.map +1 -1
- package/dist/trust/identity/message-signature.d.ts +1 -14
- package/dist/trust/identity/message-signature.js.map +1 -1
- package/dist/weixin/channel.d.ts +3 -0
- package/dist/weixin/channel.js +18 -2
- package/dist/weixin/channel.js.map +1 -1
- package/examples/profiles/merchant.deepseek.yaml +6 -0
- package/examples/profiles/merchant.fake.yaml +6 -0
- package/examples/profiles/merchant.local.yaml +6 -0
- package/package.json +9 -7
- package/skills/kiwi-buyer/SKILL.md +68 -0
- package/skills/merchant/catalog-operations/SKILL.md +17 -0
- package/skills/merchant/change-approval/SKILL.md +16 -0
- package/skills/merchant/human-review/SKILL.md +17 -0
- package/skills/merchant/inventory-operations/SKILL.md +17 -0
- package/skills/merchant/negotiation-review/SKILL.md +18 -0
- package/skills/merchant/performance-insights/SKILL.md +19 -0
- package/contracts/candidate-agent-dto-1.0.README.md +0 -43
- package/contracts/conformance/python-service/README.md +0 -19
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 harrylabsj
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* CSV 商品导入闭环(V2 阶段四 F04:src/merchant-core/product-import.ts)。
|
|
18
|
+
*
|
|
19
|
+
* CSV 解析预览(新增/更新/错误逐行回执)→ 确认(命令记录)→ 执行(逐行
|
|
20
|
+
* 回执,部分成功 partially_failed;相同幂等键返回同一 operation,不重复
|
|
21
|
+
* 导入/发布)。撤回走同一闭环(listing 销售状态语义,F08)。
|
|
22
|
+
*
|
|
23
|
+
* CSV 列:sku,title,price,stock[,currency][,category][,description]
|
|
24
|
+
* (首行表头;分隔符逗号;空行跳过)。解析失败行进入错误回执,不阻塞其他行。
|
|
25
|
+
*/
|
|
26
|
+
import type { MerchantClient, MerchantProductInput } from "../agent/merchant/types.js";
|
|
27
|
+
import type { MerchantOperation, MerchantOperationStore } from "./operations.js";
|
|
28
|
+
export interface CsvImportRowPlan {
|
|
29
|
+
line: number;
|
|
30
|
+
sku: string;
|
|
31
|
+
action: "create" | "update";
|
|
32
|
+
ok: boolean;
|
|
33
|
+
error?: string;
|
|
34
|
+
}
|
|
35
|
+
export interface CsvImportPreview {
|
|
36
|
+
total_lines: number;
|
|
37
|
+
valid: number;
|
|
38
|
+
creates: number;
|
|
39
|
+
updates: number;
|
|
40
|
+
row_errors: Array<{
|
|
41
|
+
line: number;
|
|
42
|
+
error: string;
|
|
43
|
+
}>;
|
|
44
|
+
}
|
|
45
|
+
/** 解析 CSV → 行计划(逐行错误回执,不阻塞其他行)。 */
|
|
46
|
+
export declare function parseProductCsv(csv: string, existingSkus: ReadonlySet<string>): {
|
|
47
|
+
inputs: Array<{
|
|
48
|
+
line: number;
|
|
49
|
+
input: MerchantProductInput;
|
|
50
|
+
}>;
|
|
51
|
+
preview: CsvImportPreview;
|
|
52
|
+
};
|
|
53
|
+
export declare const PRODUCTS_IMPORT_OPERATION_KIND = "products_import";
|
|
54
|
+
/**
|
|
55
|
+
* 执行 CSV 导入(命令执行器调用):逐行 create/update + 逐项回执;
|
|
56
|
+
* 幂等键命中已完成 operation → 直接返回(不重复导入)。
|
|
57
|
+
*/
|
|
58
|
+
export declare function executeProductsImport(input: {
|
|
59
|
+
csv: string;
|
|
60
|
+
idempotencyKey: string;
|
|
61
|
+
merchantId: string;
|
|
62
|
+
merchantClient: MerchantClient;
|
|
63
|
+
operations: MerchantOperationStore;
|
|
64
|
+
}): Promise<MerchantOperation | {
|
|
65
|
+
ok: false;
|
|
66
|
+
operation: MerchantOperation;
|
|
67
|
+
}>;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 harrylabsj
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
const REQUIRED_COLUMNS = ["sku", "title", "price", "stock"];
|
|
17
|
+
/** 解析 CSV → 行计划(逐行错误回执,不阻塞其他行)。 */
|
|
18
|
+
export function parseProductCsv(csv, existingSkus) {
|
|
19
|
+
const lines = csv.split(/\r?\n/).filter((l) => l.trim() !== "");
|
|
20
|
+
const rowErrors = [];
|
|
21
|
+
const inputs = [];
|
|
22
|
+
if (lines.length === 0) {
|
|
23
|
+
return {
|
|
24
|
+
inputs,
|
|
25
|
+
preview: { total_lines: 0, valid: 0, creates: 0, updates: 0, row_errors: [] },
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const header = lines[0]?.split(",").map((c) => c.trim()) ?? [];
|
|
29
|
+
for (const col of REQUIRED_COLUMNS) {
|
|
30
|
+
if (!header.includes(col)) {
|
|
31
|
+
rowErrors.push({ line: 1, error: `表头缺列 ${col}` });
|
|
32
|
+
return {
|
|
33
|
+
inputs,
|
|
34
|
+
preview: {
|
|
35
|
+
total_lines: lines.length,
|
|
36
|
+
valid: 0,
|
|
37
|
+
creates: 0,
|
|
38
|
+
updates: 0,
|
|
39
|
+
row_errors: rowErrors,
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const idx = Object.fromEntries(header.map((c, i) => [c, i]));
|
|
45
|
+
for (let i = 1; i < lines.length; i += 1) {
|
|
46
|
+
const lineNo = i + 1;
|
|
47
|
+
const cells = (lines[i] ?? "").split(",").map((c) => c.trim());
|
|
48
|
+
const sku = cells[idx.sku ?? -1] ?? "";
|
|
49
|
+
const title = cells[idx.title ?? -1] ?? "";
|
|
50
|
+
const price = Number(cells[idx.price ?? -1]);
|
|
51
|
+
const stock = Number(cells[idx.stock ?? -1]);
|
|
52
|
+
if (sku === "" || title === "") {
|
|
53
|
+
rowErrors.push({ line: lineNo, error: "sku/title 为空" });
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (!Number.isFinite(price) || price < 0) {
|
|
57
|
+
rowErrors.push({ line: lineNo, error: `price 非法(${cells[idx.price ?? -1] ?? ""})` });
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (!Number.isInteger(stock) || stock < 0) {
|
|
61
|
+
rowErrors.push({
|
|
62
|
+
line: lineNo,
|
|
63
|
+
error: `stock 必须是非负整数(${cells[idx.stock ?? -1] ?? ""})`,
|
|
64
|
+
});
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
inputs.push({
|
|
68
|
+
line: lineNo,
|
|
69
|
+
input: {
|
|
70
|
+
sku,
|
|
71
|
+
merchant_id: "", // 由执行器补 owner
|
|
72
|
+
title,
|
|
73
|
+
price,
|
|
74
|
+
stock,
|
|
75
|
+
...(typeof idx.currency === "number" &&
|
|
76
|
+
cells[idx.currency] !== undefined &&
|
|
77
|
+
cells[idx.currency] !== ""
|
|
78
|
+
? { currency: cells[idx.currency] }
|
|
79
|
+
: {}),
|
|
80
|
+
...(typeof idx.category === "number" &&
|
|
81
|
+
cells[idx.category] !== undefined &&
|
|
82
|
+
cells[idx.category] !== ""
|
|
83
|
+
? { category: cells[idx.category] }
|
|
84
|
+
: {}),
|
|
85
|
+
...(typeof idx.description === "number" && cells[idx.description] !== undefined
|
|
86
|
+
? { description: cells[idx.description] }
|
|
87
|
+
: {}),
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
const creates = inputs.filter((r) => !existingSkus.has(r.input.sku)).length;
|
|
92
|
+
return {
|
|
93
|
+
inputs,
|
|
94
|
+
preview: {
|
|
95
|
+
total_lines: lines.length - 1,
|
|
96
|
+
valid: inputs.length,
|
|
97
|
+
creates,
|
|
98
|
+
updates: inputs.length - creates,
|
|
99
|
+
row_errors: rowErrors,
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
export const PRODUCTS_IMPORT_OPERATION_KIND = "products_import";
|
|
104
|
+
/**
|
|
105
|
+
* 执行 CSV 导入(命令执行器调用):逐行 create/update + 逐项回执;
|
|
106
|
+
* 幂等键命中已完成 operation → 直接返回(不重复导入)。
|
|
107
|
+
*/
|
|
108
|
+
export async function executeProductsImport(input) {
|
|
109
|
+
const existing = input.operations.createOrGet({
|
|
110
|
+
kind: PRODUCTS_IMPORT_OPERATION_KIND,
|
|
111
|
+
idempotencyKey: input.idempotencyKey,
|
|
112
|
+
});
|
|
113
|
+
if (!existing.created) {
|
|
114
|
+
// 幂等:相同幂等键返回同一 operation(已终态的不重复执行;queued/running
|
|
115
|
+
// 的先对账——本轮返回现状不盲目重发)。
|
|
116
|
+
return existing.operation;
|
|
117
|
+
}
|
|
118
|
+
const operation = input.operations.markRunning(existing.operation.operation_id);
|
|
119
|
+
try {
|
|
120
|
+
const current = await input.merchantClient.listProducts(input.merchantId);
|
|
121
|
+
const existingSkus = new Set(current.map((p) => p.sku));
|
|
122
|
+
const { inputs, preview } = parseProductCsv(input.csv, existingSkus);
|
|
123
|
+
const receipts = preview.row_errors.map((e) => ({
|
|
124
|
+
item: `line ${e.line}`,
|
|
125
|
+
ok: false,
|
|
126
|
+
detail: e.error,
|
|
127
|
+
}));
|
|
128
|
+
for (const { line, input: product } of inputs) {
|
|
129
|
+
try {
|
|
130
|
+
if (existingSkus.has(product.sku)) {
|
|
131
|
+
await input.merchantClient.updateProduct(product.sku, {
|
|
132
|
+
title: product.title,
|
|
133
|
+
price: product.price,
|
|
134
|
+
stock: product.stock,
|
|
135
|
+
});
|
|
136
|
+
receipts.push({ item: `line ${line}`, ok: true, detail: `update ${product.sku}` });
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
await input.merchantClient.createProduct({ ...product, merchant_id: input.merchantId });
|
|
140
|
+
receipts.push({ item: `line ${line}`, ok: true, detail: `create ${product.sku}` });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
receipts.push({
|
|
145
|
+
item: `line ${line}`,
|
|
146
|
+
ok: false,
|
|
147
|
+
detail: err instanceof Error ? err.message : String(err),
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const finished = input.operations.finish(operation.operation_id, receipts);
|
|
152
|
+
// 全部行失败 → ok:false(审查 P1:否则候选仍被标 executed,审计谎报成功)
|
|
153
|
+
return finished.status === "failed" ? { ok: false, operation: finished } : finished;
|
|
154
|
+
}
|
|
155
|
+
catch (err) {
|
|
156
|
+
const failed = input.operations.finish(operation.operation_id, [], err instanceof Error ? err.message : String(err));
|
|
157
|
+
return { ok: false, operation: failed };
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=product-import.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product-import.js","sourceRoot":"","sources":["../../src/merchant-core/product-import.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAgCH,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAU,CAAC;AAErE,mCAAmC;AACnC,MAAM,UAAU,eAAe,CAC7B,GAAW,EACX,YAAiC;IAEjC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,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CAAC;iBACzD,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QACD,MAAM,QAAQ,GAAG,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,SAAS,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;QAC3E,kDAAkD;QAClD,OAAO,QAAQ,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;IACtF,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,MAAM,GAAG,KAAK,CAAC,UAAU,CAAC,MAAM,CACpC,SAAS,CAAC,YAAY,EACtB,EAAE,EACF,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CACjD,CAAC;QACF,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;IAC1C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 harrylabsj
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { A2aNegotiationRow } from "../merchant/workbench-service.js";
|
|
17
|
+
import { MerchantWorkbenchService, type MerchantWorkbenchServiceDeps } from "../merchant/workbench-service.js";
|
|
18
|
+
import type { MerchantOAuthStore } from "../auth/merchant-oauth.js";
|
|
19
|
+
import { MerchantCommandLog } from "./commands.js";
|
|
20
|
+
import type { ApplyPolicyResult } from "./policy-runtime.js";
|
|
21
|
+
import type { MerchantPolicy } from "../config/profile.js";
|
|
22
|
+
import type { MerchantOperation, MerchantOperationStore } from "./operations.js";
|
|
23
|
+
import { type UnifiedNegotiationRow } from "./negotiation-adapters.js";
|
|
24
|
+
export interface MerchantCoreServiceDeps extends MerchantWorkbenchServiceDeps {
|
|
25
|
+
/** 私密阈值读取(Vault;仅管理面接缝调用,读取写审计)。 */
|
|
26
|
+
privateValues?: () => Array<{
|
|
27
|
+
key: string;
|
|
28
|
+
value: string;
|
|
29
|
+
}>;
|
|
30
|
+
/** 私密读取审计目录(jsonl 追加;缺省则私密读取拒绝——fail-closed 不裸读)。 */
|
|
31
|
+
auditDir?: string;
|
|
32
|
+
/** 命令记录的授权主体(批准/拒绝主体一致性校验;= 审批 store 的 principal)。 */
|
|
33
|
+
commandPrincipalId?: string;
|
|
34
|
+
/** F08 能力探测结果:listing_pause=false 时 prepare_listing_change fail-closed「不可得」。 */
|
|
35
|
+
capabilities?: {
|
|
36
|
+
listing_pause?: boolean;
|
|
37
|
+
};
|
|
38
|
+
/** F14:shopping 轨人工处理接口(可选;缺省执行时「不可得」)。 */
|
|
39
|
+
resolveShoppingReview?: (input: {
|
|
40
|
+
conversation_id: string;
|
|
41
|
+
resolution: string;
|
|
42
|
+
}) => Promise<unknown>;
|
|
43
|
+
/** F17:策略热更新写入接缝(可选;缺省执行时「不可得」)。BUG-07:实现
|
|
44
|
+
* 须校验+原子写完整生效策略并返回版本/digest(见 MerchantPolicyRuntime)。 */
|
|
45
|
+
applyPolicyOverride?: ((patch: Record<string, unknown>) => Promise<ApplyPolicyResult>) | ((patch: Record<string, unknown>) => ApplyPolicyResult);
|
|
46
|
+
/** 运行中策略读取(BUG-07):配置后执行器硬策略按当前生效策略执行。 */
|
|
47
|
+
currentPolicy?: () => MerchantPolicy | undefined;
|
|
48
|
+
/** 长任务 operation store(V2 阶段四;CSV 导入/撤回幂等与逐项回执)。 */
|
|
49
|
+
operations?: MerchantOperationStore;
|
|
50
|
+
/** merchantDataDir(F29 微信绑定状态读取等本地状态接缝)。 */
|
|
51
|
+
merchantDataDir?: string;
|
|
52
|
+
/** 一次性确认凭证存储(BUG-02;配置后 execute/reject 必须携带有效凭证)。 */
|
|
53
|
+
confirmations?: MerchantOAuthStore;
|
|
54
|
+
}
|
|
55
|
+
export declare class MerchantCoreService {
|
|
56
|
+
/** V1 facade(委托转发;facade 语义不变)。 */
|
|
57
|
+
readonly workbench: MerchantWorkbenchService;
|
|
58
|
+
private readonly intelligence?;
|
|
59
|
+
private readonly privateValues?;
|
|
60
|
+
private readonly auditDir?;
|
|
61
|
+
private readonly capabilities?;
|
|
62
|
+
private readonly resolveShoppingReview?;
|
|
63
|
+
private readonly applyPolicyOverride?;
|
|
64
|
+
private readonly currentPolicy?;
|
|
65
|
+
private readonly commandPrincipalId;
|
|
66
|
+
private readonly confirmationStore?;
|
|
67
|
+
private readonly operationsStore?;
|
|
68
|
+
private readonly merchantDataDir?;
|
|
69
|
+
private readonly now;
|
|
70
|
+
private readonly principalId;
|
|
71
|
+
private readonly approvalsRef;
|
|
72
|
+
private readonly profileRef;
|
|
73
|
+
private readonly modeRef;
|
|
74
|
+
constructor(deps: MerchantCoreServiceDeps);
|
|
75
|
+
listPublicProducts(): Promise<{
|
|
76
|
+
items: import("../merchant/workbench-service.js").PublicProductView[];
|
|
77
|
+
source: "data_source" | "merchant_client";
|
|
78
|
+
}>;
|
|
79
|
+
getPublicProduct(sku: string, merchantId?: string): Promise<import("../merchant/workbench-service.js").PublicProductView>;
|
|
80
|
+
getInventorySnapshot(sku: string): Promise<import("../agent/merchant/types.js").InventorySnapshot>;
|
|
81
|
+
listA2aNegotiations(limit?: unknown): Promise<{
|
|
82
|
+
total: number;
|
|
83
|
+
items: A2aNegotiationRow[];
|
|
84
|
+
}>;
|
|
85
|
+
listActiveConsultations(): Promise<A2aNegotiationRow[]>;
|
|
86
|
+
listHumanReviews(): Promise<import("../merchant/workbench-service.js").HumanReviewRow[]>;
|
|
87
|
+
getAnalytics(period?: string): Promise<import("../agent/merchant/intelligence/types.js").MerchantBusinessSnapshot>;
|
|
88
|
+
draftProductChange(input: Parameters<MerchantWorkbenchService["draftProductChange"]>[0]): Promise<import("../merchant/workbench-service.js").DraftProductChangeResult>;
|
|
89
|
+
recoverPendingDrafts(): number;
|
|
90
|
+
approveCandidate(candidateId: string): Promise<import("../agent/merchant/action-candidate.js").ApprovalExecutionResult>;
|
|
91
|
+
private commandLogInstance;
|
|
92
|
+
/** 持久命令记录(lazy;store 即 WriteApprovalCandidateStore,单 owner 写)。 */
|
|
93
|
+
get commands(): MerchantCommandLog;
|
|
94
|
+
/** prepare:商品创建(force_pending 候选,绝不直接执行)。入参白名单
|
|
95
|
+
* 校验 + merchant_id 钉死归属(审查 P1:否则批准后执行必然失败或可跨
|
|
96
|
+
* 商家写,白烧人工确认)。 */
|
|
97
|
+
prepareProductCreate(input: {
|
|
98
|
+
product: unknown;
|
|
99
|
+
reason?: string;
|
|
100
|
+
}): Promise<import("./commands.js").PreparedCommand>;
|
|
101
|
+
/** prepare:库存调整。 */
|
|
102
|
+
prepareInventoryUpdate(input: {
|
|
103
|
+
sku: string;
|
|
104
|
+
stock: number;
|
|
105
|
+
reason?: string;
|
|
106
|
+
}): Promise<import("./commands.js").PreparedCommand>;
|
|
107
|
+
/** prepare:listing 销售状态变更(F08 语义;上游不支持 → fail-closed「不可得」)。 */
|
|
108
|
+
prepareListingChange(input: {
|
|
109
|
+
sku: string;
|
|
110
|
+
paused: boolean;
|
|
111
|
+
reason?: string;
|
|
112
|
+
}): Promise<import("./commands.js").PreparedCommand>;
|
|
113
|
+
/** prepare:人工处理(F14 两轨;A2A 轨执行面 fail-closed「不可得」留后续)。 */
|
|
114
|
+
prepareReviewResolve(input: {
|
|
115
|
+
source_protocol: "a2a" | "shopping";
|
|
116
|
+
source_id: string;
|
|
117
|
+
resolution: string;
|
|
118
|
+
reason?: string;
|
|
119
|
+
}): Promise<import("./commands.js").PreparedCommand>;
|
|
120
|
+
/** prepare:策略变更(F17 热更新;执行器写入覆盖层即生效)。 */
|
|
121
|
+
preparePolicyChange(input: {
|
|
122
|
+
patch: Record<string, unknown>;
|
|
123
|
+
reason?: string;
|
|
124
|
+
}): Promise<import("./commands.js").PreparedCommand>;
|
|
125
|
+
/** 确认通道:批准并执行(确认凭证 + 重校验 + 幂等 + 回读)。单商家单主体
|
|
126
|
+
* 实例的便捷包装——主体恒为本实例 commandPrincipalId;跨主体校验在
|
|
127
|
+
* commands.executeApproved(管理页传入会话主体时真实生效)。 */
|
|
128
|
+
executeApproved(commandId: string, confirmationToken?: string): Promise<import("../agent/merchant/action-candidate.js").ApprovalExecutionResult>;
|
|
129
|
+
/** 确认通道:拒绝候选(同上:单主体便捷包装)。 */
|
|
130
|
+
rejectCandidate(commandId: string, confirmationToken?: string): Promise<import("../agent/merchant/action-candidate.js").WriteApprovalCandidate>;
|
|
131
|
+
/**
|
|
132
|
+
* 重启恢复(阶段三推广版):恢复全部已注册写工具的 pending 命令
|
|
133
|
+
* (覆盖 V1 recoverPendingDrafts 语义并推广);未注册工具的死候选标 expired。
|
|
134
|
+
*/
|
|
135
|
+
recoverPendingCommands(): {
|
|
136
|
+
recovered: number;
|
|
137
|
+
expiredUnknown: number;
|
|
138
|
+
};
|
|
139
|
+
listPendingCommands(): import("../agent/merchant/action-candidate.js").WriteApprovalCandidate[];
|
|
140
|
+
/** prepare:CSV 商品导入(预览逐行回执;幂等键缺省 = CSV 内容 hash)。 */
|
|
141
|
+
prepareProductsImport(input: {
|
|
142
|
+
csv: string;
|
|
143
|
+
idempotency_key?: string;
|
|
144
|
+
reason?: string;
|
|
145
|
+
}): Promise<import("./commands.js").PreparedCommand>;
|
|
146
|
+
/** prepare:批量撤回(listing 销售状态语义;幂等键缺省 = skus hash)。 */
|
|
147
|
+
prepareProductsWithdraw(input: {
|
|
148
|
+
skus: string[];
|
|
149
|
+
idempotency_key?: string;
|
|
150
|
+
reason?: string;
|
|
151
|
+
}): Promise<import("./commands.js").PreparedCommand>;
|
|
152
|
+
/** 长任务查询(read scope)。 */
|
|
153
|
+
getOperation(operationId: string): MerchantOperation;
|
|
154
|
+
/**
|
|
155
|
+
* 微信绑定状态与同步概况(只读)。脱敏:绝不返回 bot_token。
|
|
156
|
+
* 最近事件列表:当前微信通道无事件存储——明确「不可得」(不编造)。
|
|
157
|
+
*/
|
|
158
|
+
getWeixinStatus(): {
|
|
159
|
+
bound: boolean;
|
|
160
|
+
account?: {
|
|
161
|
+
bot_id: string;
|
|
162
|
+
user_id: string;
|
|
163
|
+
saved_at: string;
|
|
164
|
+
};
|
|
165
|
+
sync?: {
|
|
166
|
+
buffered: boolean;
|
|
167
|
+
seen_count: number;
|
|
168
|
+
};
|
|
169
|
+
recent_events: string;
|
|
170
|
+
note?: string;
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* 统一磋商列表:A2A 轨(Ledger)+ shopping 会话轨(merchantClient),每条带
|
|
174
|
+
* source_protocol/source_id,状态名保留各协议口径。needs_human_review:
|
|
175
|
+
* 有 intelligence 时用其权威口径,否则 A2A 轨退化相位判断。
|
|
176
|
+
* 单轨不可用(如未配置 ledger)不拖垮另一轨:tracks 标注 unavailable,
|
|
177
|
+
* 明确「不可得」而非静默缺半(V2 §4:缺失数据明确显示)。
|
|
178
|
+
*/
|
|
179
|
+
listUnifiedNegotiations(limit?: unknown): Promise<{
|
|
180
|
+
total: number;
|
|
181
|
+
items: UnifiedNegotiationRow[];
|
|
182
|
+
tracks: {
|
|
183
|
+
a2a: "ok" | "unavailable";
|
|
184
|
+
shopping: "ok" | "unavailable";
|
|
185
|
+
};
|
|
186
|
+
}>;
|
|
187
|
+
/** 人工处理目标列表(两轨;每条带路由标记,调用方必须按来源路由)。 */
|
|
188
|
+
listHumanReviewTargets(): Promise<UnifiedNegotiationRow[]>;
|
|
189
|
+
/**
|
|
190
|
+
* 人工处理路由守卫(V2 §5.2):A2A 来源走 a2a 通道,shopping 来源走
|
|
191
|
+
* shopping 通道;跨轨调用 fail-closed 抛错。
|
|
192
|
+
*/
|
|
193
|
+
assertReviewRoute(row: UnifiedNegotiationRow, channel: "a2a" | "shopping"): void;
|
|
194
|
+
/**
|
|
195
|
+
* 读取私密阈值(店主私密面板用;不挂 MCP 工具)。读取动作写审计记录
|
|
196
|
+
* (at/principal/keys 数量——绝不记值)。未配置审计目录时拒绝(fail-closed:
|
|
197
|
+
* 无审计不裸读私密值)。
|
|
198
|
+
*/
|
|
199
|
+
readPrivateThresholds(): Array<{
|
|
200
|
+
key: string;
|
|
201
|
+
value: string;
|
|
202
|
+
}>;
|
|
203
|
+
}
|