@harrylabsj/kiwi 0.7.20 → 0.7.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/a2a/node.js +9 -0
- package/dist/a2a/node.js.map +1 -1
- package/dist/a2a/server/index.d.ts +2 -1
- package/dist/a2a/server/index.js +1 -1
- package/dist/a2a/server/index.js.map +1 -1
- package/dist/a2a/server/pipeline.d.ts +25 -0
- package/dist/a2a/server/pipeline.js +50 -0
- package/dist/a2a/server/pipeline.js.map +1 -1
- package/dist/a2a/server/server.js +1 -0
- package/dist/a2a/server/server.js.map +1 -1
- package/dist/a2a/server/types.d.ts +6 -0
- package/dist/agent/buyer/buyer-tools.d.ts +7 -0
- package/dist/agent/buyer/buyer-tools.js +46 -0
- package/dist/agent/buyer/buyer-tools.js.map +1 -1
- package/dist/agent/buyer/scheduler.d.ts +3 -0
- package/dist/agent/buyer/scheduler.js.map +1 -1
- package/dist/agent/buyer/task-store.d.ts +5 -0
- package/dist/agent/buyer/task-store.js +10 -0
- package/dist/agent/buyer/task-store.js.map +1 -1
- package/dist/agent/kernel.d.ts +2 -0
- package/dist/agent/kernel.js +44 -9
- package/dist/agent/kernel.js.map +1 -1
- package/dist/agent/memory/schema.d.ts +1 -1
- package/dist/agent/memory/schema.js +67 -1
- package/dist/agent/memory/schema.js.map +1 -1
- package/dist/agent/supplier/scheduler.d.ts +84 -0
- package/dist/agent/supplier/scheduler.js +539 -0
- package/dist/agent/supplier/scheduler.js.map +1 -0
- package/dist/agent/supplier/store.d.ts +171 -0
- package/dist/agent/supplier/store.js +343 -0
- package/dist/agent/supplier/store.js.map +1 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.js +191 -0
- package/dist/cli.js.map +1 -1
- package/dist/discovery/catalog-source/kiwi-source.js +4 -0
- package/dist/discovery/catalog-source/kiwi-source.js.map +1 -1
- package/dist/merchant/stats-store.d.ts +74 -0
- package/dist/merchant/stats-store.js +147 -0
- package/dist/merchant/stats-store.js.map +1 -0
- package/dist/product-cli.d.ts +1 -1
- package/dist/product-cli.js +16 -1
- package/dist/product-cli.js.map +1 -1
- package/dist/product-merchant.d.ts +43 -0
- package/dist/product-merchant.js +75 -0
- package/dist/product-merchant.js.map +1 -0
- package/dist/product-supplier.d.ts +75 -0
- package/dist/product-supplier.js +233 -0
- package/dist/product-supplier.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,74 @@
|
|
|
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 { DatabaseSync } from "node:sqlite";
|
|
17
|
+
/** 一次买家触达事实(来自入站 KNP envelope,已经过了 schema/digest/幂等校验)。 */
|
|
18
|
+
export interface BuyerContactEvent {
|
|
19
|
+
/** envelope.message_id(幂等主键)。 */
|
|
20
|
+
message_id: string;
|
|
21
|
+
/** 传输层认证身份(signature 模式 = 真实买家;其余模式可能坍缩)。 */
|
|
22
|
+
buyer_identity: string;
|
|
23
|
+
negotiation_id: string;
|
|
24
|
+
exchange_id: string;
|
|
25
|
+
/** envelope.action(inquiry/rfq/offer/counter_offer/...)。 */
|
|
26
|
+
action: string;
|
|
27
|
+
/** 从 payload 提取的 SKU(inquiry 等无 SKU 动作为空数组)。 */
|
|
28
|
+
skus: string[];
|
|
29
|
+
/** envelope.created_at(RFC 3339)。 */
|
|
30
|
+
occurred_at: string;
|
|
31
|
+
}
|
|
32
|
+
/** 窗口总量。 */
|
|
33
|
+
export interface ContactTotals {
|
|
34
|
+
distinct_buyers: number;
|
|
35
|
+
contact_events: number;
|
|
36
|
+
negotiations: number;
|
|
37
|
+
}
|
|
38
|
+
/** 单日聚合(day 为 UTC `YYYY-MM-DD`)。 */
|
|
39
|
+
export interface DailyBucket {
|
|
40
|
+
day: string;
|
|
41
|
+
distinct_buyers: number;
|
|
42
|
+
contact_events: number;
|
|
43
|
+
negotiations: number;
|
|
44
|
+
}
|
|
45
|
+
/** 单 SKU 聚合。 */
|
|
46
|
+
export interface SkuStat {
|
|
47
|
+
sku: string;
|
|
48
|
+
contact_events: number;
|
|
49
|
+
distinct_buyers: number;
|
|
50
|
+
negotiations: number;
|
|
51
|
+
}
|
|
52
|
+
/** 本地存储:目录 0700 / 数据库文件 0600(对齐 agent 数据布局)。 */
|
|
53
|
+
export interface MerchantStatsStoreOptions {
|
|
54
|
+
dbPath: string;
|
|
55
|
+
}
|
|
56
|
+
/** 商家买家触达统计存储。写入面只有 recordBuyerContact;其余为聚合查询。 */
|
|
57
|
+
export declare class MerchantStatsStore {
|
|
58
|
+
private readonly db;
|
|
59
|
+
constructor(db: DatabaseSync);
|
|
60
|
+
/**
|
|
61
|
+
* 记录一次买家触达(INSERT OR IGNORE:同 message_id 幂等去重——协议层已
|
|
62
|
+
* 保证恰好一次调用,这里是崩溃/重试窗口的兜底)。
|
|
63
|
+
*/
|
|
64
|
+
recordBuyerContact(event: BuyerContactEvent): void;
|
|
65
|
+
/** 窗口总量(sinceDay 含当天,UTC `YYYY-MM-DD`)。 */
|
|
66
|
+
totalsSince(sinceDay: string): ContactTotals;
|
|
67
|
+
/** 按日聚合(只返回有数据的天;零填充由调用方做)。 */
|
|
68
|
+
dailySince(sinceDay: string): DailyBucket[];
|
|
69
|
+
/** SKU 热度榜(按触达事件数降序,sku 升序兜底,截断 limit)。 */
|
|
70
|
+
topSkus(sinceDay: string, limit: number): SkuStat[];
|
|
71
|
+
close(): void;
|
|
72
|
+
}
|
|
73
|
+
/** 打开(必要时创建)本地统计存储;目录 0700 / 文件 0600。 */
|
|
74
|
+
export declare function openMerchantStatsStore(options: MerchantStatsStoreOptions): MerchantStatsStore;
|
|
@@ -0,0 +1,147 @@
|
|
|
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
|
+
* 商家侧运营统计(merchant stats)——本地买家触达事实。
|
|
18
|
+
*
|
|
19
|
+
* 数据来源唯一:merchant 自己的 A2A 入站管线(InboundPipeline)在
|
|
20
|
+
* `message_received` 落账成功后写入一条 buyer_contact_events。数据只落
|
|
21
|
+
* 商家本地 DB(<dataDir>/a2a/stats.sqlite),永不上报任何远端。
|
|
22
|
+
*
|
|
23
|
+
* 语义:
|
|
24
|
+
* - 主键 message_id(INSERT OR IGNORE):与协议幂等(§20)对齐,
|
|
25
|
+
* 同一消息重放不重复计数;
|
|
26
|
+
* - distinct_buyers 仅在 KIWI_A2A_AUTH=signature 下有真实去重语义——
|
|
27
|
+
* loopback/none/bearer 模式下 buyer 身份坍缩(loopback 地址、
|
|
28
|
+
* "anonymous"、静态 token 身份),CLI 输出附带 identity_note 说明;
|
|
29
|
+
* - 天数一律 UTC(occurred_at ISO 串切前 10 位),与全仓时间处理一致。
|
|
30
|
+
*/
|
|
31
|
+
import { chmodSync, existsSync, mkdirSync } from "node:fs";
|
|
32
|
+
import path from "node:path";
|
|
33
|
+
import { DatabaseSync } from "node:sqlite";
|
|
34
|
+
import { requireIsoTimestamp, requireNonEmptyString } from "../negotiation/domain/common.js";
|
|
35
|
+
const STATS_SCHEMA = `
|
|
36
|
+
CREATE TABLE IF NOT EXISTS buyer_contact_events (
|
|
37
|
+
message_id TEXT PRIMARY KEY,
|
|
38
|
+
buyer_identity TEXT NOT NULL,
|
|
39
|
+
negotiation_id TEXT NOT NULL,
|
|
40
|
+
exchange_id TEXT,
|
|
41
|
+
action TEXT NOT NULL,
|
|
42
|
+
skus_json TEXT NOT NULL DEFAULT '[]',
|
|
43
|
+
occurred_at TEXT NOT NULL
|
|
44
|
+
);
|
|
45
|
+
CREATE INDEX IF NOT EXISTS idx_buyer_contact_buyer ON buyer_contact_events(buyer_identity);
|
|
46
|
+
CREATE INDEX IF NOT EXISTS idx_buyer_contact_time ON buyer_contact_events(occurred_at);
|
|
47
|
+
`;
|
|
48
|
+
/** 商家买家触达统计存储。写入面只有 recordBuyerContact;其余为聚合查询。 */
|
|
49
|
+
export class MerchantStatsStore {
|
|
50
|
+
db;
|
|
51
|
+
constructor(db) {
|
|
52
|
+
this.db = db;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* 记录一次买家触达(INSERT OR IGNORE:同 message_id 幂等去重——协议层已
|
|
56
|
+
* 保证恰好一次调用,这里是崩溃/重试窗口的兜底)。
|
|
57
|
+
*/
|
|
58
|
+
recordBuyerContact(event) {
|
|
59
|
+
const messageId = requireNonEmptyString(event.message_id, "message_id");
|
|
60
|
+
const buyerIdentity = requireNonEmptyString(event.buyer_identity, "buyer_identity");
|
|
61
|
+
const negotiationId = requireNonEmptyString(event.negotiation_id, "negotiation_id");
|
|
62
|
+
const action = requireNonEmptyString(event.action, "action");
|
|
63
|
+
const occurredAt = requireIsoTimestamp(event.occurred_at, "occurred_at");
|
|
64
|
+
// SKU 去重(单条事件内同 SKU 重复出现只计一次触达)。
|
|
65
|
+
const skus = [...new Set(event.skus.filter((s) => typeof s === "string" && s !== ""))];
|
|
66
|
+
this.db
|
|
67
|
+
.prepare(`INSERT OR IGNORE INTO buyer_contact_events
|
|
68
|
+
(message_id, buyer_identity, negotiation_id, exchange_id, action, skus_json, occurred_at)
|
|
69
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)`)
|
|
70
|
+
.run(messageId, buyerIdentity, negotiationId, event.exchange_id === "" ? null : event.exchange_id, action, JSON.stringify(skus), occurredAt);
|
|
71
|
+
}
|
|
72
|
+
/** 窗口总量(sinceDay 含当天,UTC `YYYY-MM-DD`)。 */
|
|
73
|
+
totalsSince(sinceDay) {
|
|
74
|
+
const row = this.db
|
|
75
|
+
.prepare(`SELECT COUNT(DISTINCT buyer_identity) AS distinct_buyers,
|
|
76
|
+
COUNT(*) AS contact_events,
|
|
77
|
+
COUNT(DISTINCT negotiation_id) AS negotiations
|
|
78
|
+
FROM buyer_contact_events
|
|
79
|
+
WHERE substr(occurred_at, 1, 10) >= ?`)
|
|
80
|
+
.get(sinceDay);
|
|
81
|
+
return {
|
|
82
|
+
distinct_buyers: row.distinct_buyers,
|
|
83
|
+
contact_events: row.contact_events,
|
|
84
|
+
negotiations: row.negotiations,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/** 按日聚合(只返回有数据的天;零填充由调用方做)。 */
|
|
88
|
+
dailySince(sinceDay) {
|
|
89
|
+
const rows = this.db
|
|
90
|
+
.prepare(`SELECT substr(occurred_at, 1, 10) AS day,
|
|
91
|
+
COUNT(DISTINCT buyer_identity) AS distinct_buyers,
|
|
92
|
+
COUNT(*) AS contact_events,
|
|
93
|
+
COUNT(DISTINCT negotiation_id) AS negotiations
|
|
94
|
+
FROM buyer_contact_events
|
|
95
|
+
WHERE substr(occurred_at, 1, 10) >= ?
|
|
96
|
+
GROUP BY day
|
|
97
|
+
ORDER BY day`)
|
|
98
|
+
.all(sinceDay);
|
|
99
|
+
return rows.map((r) => ({
|
|
100
|
+
day: r.day,
|
|
101
|
+
distinct_buyers: r.distinct_buyers,
|
|
102
|
+
contact_events: r.contact_events,
|
|
103
|
+
negotiations: r.negotiations,
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
/** SKU 热度榜(按触达事件数降序,sku 升序兜底,截断 limit)。 */
|
|
107
|
+
topSkus(sinceDay, limit) {
|
|
108
|
+
const rows = this.db
|
|
109
|
+
.prepare(`SELECT je.value AS sku,
|
|
110
|
+
COUNT(*) AS contact_events,
|
|
111
|
+
COUNT(DISTINCT buyer_identity) AS distinct_buyers,
|
|
112
|
+
COUNT(DISTINCT negotiation_id) AS negotiations
|
|
113
|
+
FROM buyer_contact_events,
|
|
114
|
+
json_each(buyer_contact_events.skus_json) AS je
|
|
115
|
+
WHERE substr(occurred_at, 1, 10) >= ?
|
|
116
|
+
GROUP BY je.value
|
|
117
|
+
ORDER BY contact_events DESC, sku ASC
|
|
118
|
+
LIMIT ?`)
|
|
119
|
+
.all(sinceDay, limit);
|
|
120
|
+
return rows.map((r) => ({
|
|
121
|
+
sku: r.sku,
|
|
122
|
+
contact_events: r.contact_events,
|
|
123
|
+
distinct_buyers: r.distinct_buyers,
|
|
124
|
+
negotiations: r.negotiations,
|
|
125
|
+
}));
|
|
126
|
+
}
|
|
127
|
+
close() {
|
|
128
|
+
this.db.close();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/** 打开(必要时创建)本地统计存储;目录 0700 / 文件 0600。 */
|
|
132
|
+
export function openMerchantStatsStore(options) {
|
|
133
|
+
if (options.dbPath === ":memory:") {
|
|
134
|
+
const db = new DatabaseSync(":memory:");
|
|
135
|
+
db.exec(STATS_SCHEMA);
|
|
136
|
+
return new MerchantStatsStore(db);
|
|
137
|
+
}
|
|
138
|
+
const dir = path.dirname(options.dbPath);
|
|
139
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
140
|
+
chmodSync(dir, 0o700);
|
|
141
|
+
const db = new DatabaseSync(options.dbPath);
|
|
142
|
+
if (existsSync(options.dbPath))
|
|
143
|
+
chmodSync(options.dbPath, 0o600);
|
|
144
|
+
db.exec(STATS_SCHEMA);
|
|
145
|
+
return new MerchantStatsStore(db);
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=stats-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stats-store.js","sourceRoot":"","sources":["../../src/merchant/stats-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC3D,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAsD7F,MAAM,YAAY,GAAG;;;;;;;;;;;;CAYpB,CAAC;AAmBF,mDAAmD;AACnD,MAAM,OAAO,kBAAkB;IACZ,EAAE,CAAe;IAElC,YAAY,EAAgB;QAC1B,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACf,CAAC;IAED;;;OAGG;IACH,kBAAkB,CAAC,KAAwB;QACzC,MAAM,SAAS,GAAG,qBAAqB,CAAC,KAAK,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;QACxE,MAAM,aAAa,GAAG,qBAAqB,CAAC,KAAK,CAAC,cAAc,EAAE,gBAAgB,CAAC,CAAC;QACpF,MAAM,aAAa,GAAG,qBAAqB,CAAC,KAAK,CAAC,cAAc,EAAE,gBAAgB,CAAC,CAAC;QACpF,MAAM,MAAM,GAAG,qBAAqB,CAAC,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAC7D,MAAM,UAAU,GAAG,mBAAmB,CAAC,KAAK,CAAC,WAAW,EAAE,aAAa,CAAC,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kB,CAAC,EAAE,CAAC,CAAC;AACpC,CAAC"}
|
package/dist/product-cli.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ export declare const DEFAULT_PROFILE_PATH: string;
|
|
|
42
42
|
*/
|
|
43
43
|
export declare function writeDefaultProfile(yaml: string, profilePath?: string): void;
|
|
44
44
|
/** 与 package.json / USAGE 同步的产品版本。 */
|
|
45
|
-
export declare const PRODUCT_VERSION = "0.7.
|
|
45
|
+
export declare const PRODUCT_VERSION = "0.7.22";
|
|
46
46
|
/**
|
|
47
47
|
* 缺省 kiwi-catalog 地址(单一来源,cli.ts 各处解析一致)。
|
|
48
48
|
*
|
package/dist/product-cli.js
CHANGED
|
@@ -51,7 +51,7 @@ export function writeDefaultProfile(yaml, profilePath) {
|
|
|
51
51
|
writeFileSync(target, yaml, { mode: 0o600 });
|
|
52
52
|
}
|
|
53
53
|
/** 与 package.json / USAGE 同步的产品版本。 */
|
|
54
|
-
export const PRODUCT_VERSION = "0.7.
|
|
54
|
+
export const PRODUCT_VERSION = "0.7.22";
|
|
55
55
|
/**
|
|
56
56
|
* 缺省 kiwi-catalog 地址(单一来源,cli.ts 各处解析一致)。
|
|
57
57
|
*
|
|
@@ -72,6 +72,16 @@ Usage:
|
|
|
72
72
|
kiwi buyer search <需求描述> [D4] Product-first 搜索(listing → Merchant
|
|
73
73
|
Agent;--catalog/--limit/--category/--region)
|
|
74
74
|
kiwi buyer tasks [--data-dir <dir>] [D4] 查看 Buyer 任务(start 运行后)
|
|
75
|
+
kiwi buyer supplier save <merchant-id> [M1] 保存供应商(不轮询;经 --catalog 解析)
|
|
76
|
+
kiwi buyer supplier watch <merchant-id> [--query <词>] [--region <区域>] [--interval <秒≥3600>]
|
|
77
|
+
[M1] 建立观察关系(人类确认;非交互需 --yes)
|
|
78
|
+
kiwi buyer supplier prefer <merchant-id> [--scope <范围>] [--expires 90d]
|
|
79
|
+
[M1] 设为偏好供应商(人类确认;非交互需 --yes)
|
|
80
|
+
kiwi buyer supplier list [M1] 查看本地供应商关系
|
|
81
|
+
kiwi buyer supplier pause <relationship-id>
|
|
82
|
+
[M1] 暂停观察
|
|
83
|
+
kiwi buyer supplier remove <relationship-id>
|
|
84
|
+
[M1] 删除关系(软删:立即停止拉取)
|
|
75
85
|
|
|
76
86
|
Buyer 只需要 Kiwi;不感知 shopping-cli / kiwi-catalog。
|
|
77
87
|
`;
|
|
@@ -101,6 +111,11 @@ Usage:
|
|
|
101
111
|
反代 → 起 A2A 节点,退出时清理 Caddy
|
|
102
112
|
(需已安装 Caddy)
|
|
103
113
|
kiwi merchant listings [D2] 已发布 Listing 查看 —— 尚未实现
|
|
114
|
+
kiwi merchant stats [--days N] [--data-dir <dir>]
|
|
115
|
+
商家侧运营统计:去重买家数 / 触达事件 /
|
|
116
|
+
磋商数 / SKU 热度(本地 stats.sqlite,
|
|
117
|
+
数据只在商家本机,不上报;天数 UTC,
|
|
118
|
+
缺省 14 天,1-90)
|
|
104
119
|
kiwi merchant status [D1] Merchant 运行时状态 —— 尚未实现
|
|
105
120
|
kiwi merchant doctor [D3] Merchant 侧组件健康 —— 尚未实现
|
|
106
121
|
|
package/dist/product-cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-cli.js","sourceRoot":"","sources":["../src/product-cli.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE3F;;;GAGG;AACH,MAAM,CAAC,MAAM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C,KAAK,KAAK,SAAS,EAAE,CAAC;QACxC,YAAY,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;IACtC,CAAC;IAED,MAAM,UAAU,GAAG;QACjB,IAAI,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,eAAe,EAAE;QAC5C,YAAY,EAAE,YAAY;QAC1B,YAAY,EAAE,MAAM,aAAa,EAAE;KACpC,CAAC;IACF,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,CAAC;IACjE,SAAS,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;IAC9B,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Copyright 2026 harrylabsj
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import { type ContactTotals, type DailyBucket, type SkuStat } from "./merchant/stats-store.js";
|
|
18
|
+
export interface MerchantStatsOptions {
|
|
19
|
+
/** merchant agent_id(报告标识,不参与查询)。 */
|
|
20
|
+
agentId: string;
|
|
21
|
+
/** 节点数据目录(resolveServeDataDir 解析后的 dataDir;统计库在 <dataDir>/a2a/)。 */
|
|
22
|
+
dataDir: string;
|
|
23
|
+
/** 回看天数(缺省 14,clamp 1..90;天数一律 UTC)。 */
|
|
24
|
+
days?: number;
|
|
25
|
+
/** 可注入时钟(RFC 3339);缺省 new Date().toISOString()。 */
|
|
26
|
+
now?: () => string;
|
|
27
|
+
}
|
|
28
|
+
export interface MerchantStatsReport {
|
|
29
|
+
ok: true;
|
|
30
|
+
agent_id: string;
|
|
31
|
+
days: number;
|
|
32
|
+
identity_note: string;
|
|
33
|
+
totals: ContactTotals;
|
|
34
|
+
today: {
|
|
35
|
+
distinct_buyers: number;
|
|
36
|
+
contact_events: number;
|
|
37
|
+
};
|
|
38
|
+
/** 零填充的 N 天窗口(升序,含今天)。 */
|
|
39
|
+
daily: DailyBucket[];
|
|
40
|
+
top_skus: SkuStat[];
|
|
41
|
+
}
|
|
42
|
+
/** 读本地买家触达统计(merchant start 运行并收到买家消息后才有数据;缺省报错)。 */
|
|
43
|
+
export declare function merchantStats(options: MerchantStatsOptions): MerchantStatsReport;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Copyright 2026 harrylabsj
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* `kiwi merchant` 命令面(product-strategy rev1.1 §2.3/§19)。
|
|
19
|
+
*
|
|
20
|
+
* - stats:商家侧运营统计(本地 <dataDir>/a2a/stats.sqlite,由 merchant A2A
|
|
21
|
+
* 节点在收到买家 KNP 消息时自动收集;数据只在商家本机,永不上报)。
|
|
22
|
+
* 回答两个问题:多少个不同的买家联系过我、讨论了哪些商品(SKU)。
|
|
23
|
+
*/
|
|
24
|
+
import { existsSync } from "node:fs";
|
|
25
|
+
import path from "node:path";
|
|
26
|
+
import { openMerchantStatsStore, } from "./merchant/stats-store.js";
|
|
27
|
+
/** 身份语义说明:distinct_buyers 只在 signature 模式下是真实去重买家。 */
|
|
28
|
+
const IDENTITY_NOTE = "买家身份依赖传输层认证:signature 模式下为真实去重买家;loopback/none/bearer 模式会聚合买家";
|
|
29
|
+
const DEFAULT_DAYS = 14;
|
|
30
|
+
const MAX_DAYS = 90;
|
|
31
|
+
const TOP_SKU_LIMIT = 20;
|
|
32
|
+
/** UTC 日串加减天数(`YYYY-MM-DD`)。 */
|
|
33
|
+
function shiftDay(day, delta) {
|
|
34
|
+
return new Date(Date.parse(`${day}T00:00:00Z`) + delta * 86_400_000).toISOString().slice(0, 10);
|
|
35
|
+
}
|
|
36
|
+
/** 读本地买家触达统计(merchant start 运行并收到买家消息后才有数据;缺省报错)。 */
|
|
37
|
+
export function merchantStats(options) {
|
|
38
|
+
const now = (options.now ?? (() => new Date().toISOString()))();
|
|
39
|
+
const today = now.slice(0, 10);
|
|
40
|
+
const requested = options.days ?? DEFAULT_DAYS;
|
|
41
|
+
const days = Math.max(1, Math.min(MAX_DAYS, Math.trunc(requested)));
|
|
42
|
+
const sinceDay = shiftDay(today, -(days - 1));
|
|
43
|
+
const dbPath = path.join(options.dataDir, "a2a", "stats.sqlite");
|
|
44
|
+
if (!existsSync(dbPath)) {
|
|
45
|
+
throw new Error(`尚无买家沟通数据(${dbPath} 不存在)——商家服务启动并收到买家消息后会自动收集(kiwi merchant start)`);
|
|
46
|
+
}
|
|
47
|
+
const store = openMerchantStatsStore({ dbPath });
|
|
48
|
+
try {
|
|
49
|
+
const totals = store.totalsSince(sinceDay);
|
|
50
|
+
const todayTotals = store.totalsSince(today);
|
|
51
|
+
const byDay = new Map(store.dailySince(sinceDay).map((d) => [d.day, d]));
|
|
52
|
+
const daily = [];
|
|
53
|
+
for (let i = 0; i < days; i++) {
|
|
54
|
+
const day = shiftDay(sinceDay, i);
|
|
55
|
+
daily.push(byDay.get(day) ?? { day, distinct_buyers: 0, contact_events: 0, negotiations: 0 });
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
ok: true,
|
|
59
|
+
agent_id: options.agentId,
|
|
60
|
+
days,
|
|
61
|
+
identity_note: IDENTITY_NOTE,
|
|
62
|
+
totals,
|
|
63
|
+
today: {
|
|
64
|
+
distinct_buyers: todayTotals.distinct_buyers,
|
|
65
|
+
contact_events: todayTotals.contact_events,
|
|
66
|
+
},
|
|
67
|
+
daily,
|
|
68
|
+
top_skus: store.topSkus(sinceDay, TOP_SKU_LIMIT),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
store.close();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=product-merchant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product-merchant.js","sourceRoot":"","sources":["../src/product-merchant.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EACL,sBAAsB,GAIvB,MAAM,2BAA2B,CAAC;AAEnC,sDAAsD;AACtD,MAAM,aAAa,GACjB,+DAA+D,CAAC;AAElE,MAAM,YAAY,GAAG,EAAE,CAAC;AACxB,MAAM,QAAQ,GAAG,EAAE,CAAC;AACpB,MAAM,aAAa,GAAG,EAAE,CAAC;AAy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KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAC7C,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QACzE,MAAM,KAAK,GAAkB,EAAE,CAAC;QAChC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC;YAC9B,MAAM,GAAG,GAAG,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;YAClC,KAAK,CAAC,IAAI,CACR,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,EAAE,eAAe,EAAE,CAAC,EAAE,cAAc,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,CAClF,CAAC;QACJ,CAAC;QACD,OAAO;YACL,EAAE,EAAE,IAAI;YACR,QAAQ,EAAE,OAAO,CAAC,OAAO;YACzB,IAAI;YACJ,aAAa,EAAE,aAAa;YAC5B,MAAM;YACN,KAAK,EAAE;gBACL,eAAe,EAAE,WAAW,CAAC,eAAe;gBAC5C,cAAc,EAAE,WAAW,CAAC,cAAc;aAC3C;YACD,KAAK;YACL,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,aAAa,CAAC;SACjD,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,KAAK,CAAC,KAAK,EAAE,CAAC;IAChB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
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 SupplierRelationshipType } from "./agent/supplier/store.js";
|
|
17
|
+
export interface SupplierCommandOptions {
|
|
18
|
+
dataDir?: string;
|
|
19
|
+
agentId?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface SupplierSummary {
|
|
22
|
+
relationship_id: string;
|
|
23
|
+
merchant_id: string;
|
|
24
|
+
canonical_domain: string;
|
|
25
|
+
relationship_type: SupplierRelationshipType;
|
|
26
|
+
status: string;
|
|
27
|
+
consent_source: string;
|
|
28
|
+
scope: Record<string, unknown>;
|
|
29
|
+
policy: Record<string, unknown>;
|
|
30
|
+
created_at: string;
|
|
31
|
+
updated_at: string;
|
|
32
|
+
expires_at?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface SupplierSaveOptions extends SupplierCommandOptions {
|
|
35
|
+
merchantId: string;
|
|
36
|
+
catalogUrl?: string;
|
|
37
|
+
}
|
|
38
|
+
/** `kiwi buyer supplier save <merchant-id>`:保存身份,不轮询(§2.1)。 */
|
|
39
|
+
export declare function supplierSave(options: SupplierSaveOptions): Promise<SupplierSummary>;
|
|
40
|
+
export interface SupplierWatchOptions extends SupplierCommandOptions {
|
|
41
|
+
merchantId: string;
|
|
42
|
+
catalogUrl?: string;
|
|
43
|
+
query?: string;
|
|
44
|
+
region?: string;
|
|
45
|
+
/** 轮询间隔(秒);缺省 6h,下限 1h(§8:不做分钟级轮询)。 */
|
|
46
|
+
intervalSeconds?: number;
|
|
47
|
+
yes?: boolean;
|
|
48
|
+
confirm?: () => Promise<boolean>;
|
|
49
|
+
}
|
|
50
|
+
/** `kiwi buyer supplier watch <merchant-id>`:建立主动观察规则(§2.2)。 */
|
|
51
|
+
export declare function supplierWatch(options: SupplierWatchOptions): Promise<SupplierSummary>;
|
|
52
|
+
export interface SupplierPreferOptions extends SupplierCommandOptions {
|
|
53
|
+
merchantId: string;
|
|
54
|
+
catalogUrl?: string;
|
|
55
|
+
scope?: string;
|
|
56
|
+
/** 如 "90d"(§11 CLI 形式)。 */
|
|
57
|
+
expires?: string;
|
|
58
|
+
yes?: boolean;
|
|
59
|
+
confirm?: () => Promise<boolean>;
|
|
60
|
+
}
|
|
61
|
+
/** `kiwi buyer supplier prefer <merchant-id>`:采购范围内的软偏好(§2.3)。 */
|
|
62
|
+
export declare function supplierPrefer(options: SupplierPreferOptions): Promise<SupplierSummary>;
|
|
63
|
+
/** `kiwi buyer supplier list`。 */
|
|
64
|
+
export declare function supplierList(options: SupplierCommandOptions): Promise<SupplierSummary[]>;
|
|
65
|
+
export interface SupplierIdOptions extends SupplierCommandOptions {
|
|
66
|
+
relationshipId: string;
|
|
67
|
+
}
|
|
68
|
+
/** `kiwi buyer supplier pause <relationship-id>`。 */
|
|
69
|
+
export declare function supplierPause(options: SupplierIdOptions): Promise<SupplierSummary>;
|
|
70
|
+
/**
|
|
71
|
+
* `kiwi buyer supplier remove <relationship-id>`:软删——立即停止后续拉取并
|
|
72
|
+
* 清除未来调度(§11)。M3 之前 receipt_status 恒为 none,无需远端 revoke;
|
|
73
|
+
* 若将来存在有效 receipt,先 best-effort revoke 但远端不可达不阻塞本地删除。
|
|
74
|
+
*/
|
|
75
|
+
export declare function supplierRemove(options: SupplierIdOptions): Promise<SupplierSummary>;
|