@harrylabsj/kiwi 0.7.20 → 0.7.21
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/cli.d.ts +1 -0
- package/dist/cli.js +46 -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 +6 -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/package.json +1 -1
|
@@ -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,OAA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