@harrylabsj/kiwi 0.7.21 → 0.8.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/node.js +1 -1
- package/dist/a2a/node.js.map +1 -1
- package/dist/agent/buyer/buyer-tools.d.ts +7 -0
- package/dist/agent/buyer/buyer-tools.js +53 -0
- package/dist/agent/buyer/buyer-tools.js.map +1 -1
- package/dist/agent/buyer/scheduler.d.ts +4 -0
- package/dist/agent/buyer/scheduler.js +5 -1
- 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 +13 -0
- 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 +22 -1
- package/dist/agent/kernel.js +294 -22
- 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/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 +454 -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-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 +184 -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 +208 -9
- package/dist/agent/merchant/merchant-tools.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 +86 -0
- package/dist/agent/supplier/scheduler.js +618 -0
- package/dist/agent/supplier/scheduler.js.map +1 -0
- package/dist/agent/supplier/store.d.ts +173 -0
- package/dist/agent/supplier/store.js +387 -0
- package/dist/agent/supplier/store.js.map +1 -0
- 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/cli.d.ts +5 -0
- package/dist/cli.js +177 -12
- package/dist/cli.js.map +1 -1
- package/dist/config/profile.d.ts +21 -0
- package/dist/config/profile.js +59 -0
- package/dist/config/profile.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/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/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/negotiation/action-candidate.js +1 -1
- package/dist/operator/types.d.ts +1 -1
- package/dist/product-cli.d.ts +2 -2
- package/dist/product-cli.js +14 -2
- package/dist/product-cli.js.map +1 -1
- package/dist/product-supplier.d.ts +148 -0
- package/dist/product-supplier.js +452 -0
- package/dist/product-supplier.js.map +1 -0
- 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 +7 -6
- package/skills/kiwi-buyer/SKILL.md +66 -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,193 @@
|
|
|
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
|
+
*/
|
|
7
|
+
import { readJsonBody, SafeHttpError, isRedirectResponse } from "../../../net/safe-http.js";
|
|
8
|
+
const DEFAULT_TIMEOUT_MS = 15_000;
|
|
9
|
+
const DEFAULT_MAX_RESPONSE_BYTES = 512 * 1024;
|
|
10
|
+
export class MerchantAnalyticsHttpError extends Error {
|
|
11
|
+
status;
|
|
12
|
+
code;
|
|
13
|
+
constructor(code, message, status) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = "MerchantAnalyticsHttpError";
|
|
16
|
+
this.code = code;
|
|
17
|
+
this.status = status;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function assertBaseUrl(value) {
|
|
21
|
+
let url;
|
|
22
|
+
try {
|
|
23
|
+
url = new URL(value);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
throw new MerchantAnalyticsHttpError("configuration", "analytics baseUrl must be a valid URL");
|
|
27
|
+
}
|
|
28
|
+
if (url.username !== "" || url.password !== "") {
|
|
29
|
+
throw new MerchantAnalyticsHttpError("configuration", "analytics baseUrl must not contain credentials");
|
|
30
|
+
}
|
|
31
|
+
if (url.protocol !== "https:" && url.protocol !== "http:") {
|
|
32
|
+
throw new MerchantAnalyticsHttpError("configuration", "analytics baseUrl must use http or https");
|
|
33
|
+
}
|
|
34
|
+
if (url.protocol === "http:" && !["localhost", "127.0.0.1", "[::1]", "::1"].includes(url.hostname.toLowerCase())) {
|
|
35
|
+
throw new MerchantAnalyticsHttpError("configuration", "analytics baseUrl must use HTTPS for remote hosts");
|
|
36
|
+
}
|
|
37
|
+
return value.replace(/\/+$/, "");
|
|
38
|
+
}
|
|
39
|
+
function object(value, message) {
|
|
40
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
41
|
+
throw new MerchantAnalyticsHttpError("protocol", message);
|
|
42
|
+
}
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
function requireMerchant(value, expected) {
|
|
46
|
+
if (value !== expected) {
|
|
47
|
+
throw new MerchantAnalyticsHttpError("protocol", "analytics response merchant_id mismatch");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function limitations(value) {
|
|
51
|
+
if (value === undefined)
|
|
52
|
+
return undefined;
|
|
53
|
+
if (!Array.isArray(value))
|
|
54
|
+
throw new MerchantAnalyticsHttpError("protocol", "analytics limitations must be an array");
|
|
55
|
+
const result = value.filter((item) => item !== null && typeof item === "object" &&
|
|
56
|
+
typeof item.source === "string" &&
|
|
57
|
+
typeof item.note === "string");
|
|
58
|
+
if (result.length !== value.length)
|
|
59
|
+
throw new MerchantAnalyticsHttpError("protocol", "analytics limitation item is invalid");
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
function metricValues(value) {
|
|
63
|
+
if (!Array.isArray(value))
|
|
64
|
+
throw new MerchantAnalyticsHttpError("protocol", "analytics metrics must be an array");
|
|
65
|
+
if (value.length > 1_000)
|
|
66
|
+
throw new MerchantAnalyticsHttpError("protocol", "analytics metrics exceed 1000 items");
|
|
67
|
+
const names = new Set();
|
|
68
|
+
return value.map((item) => {
|
|
69
|
+
const metric = object(item, "analytics metric must be an object");
|
|
70
|
+
if (typeof metric.name !== "string" || metric.name.length === 0 || metric.name.length > 80 ||
|
|
71
|
+
(metric.value !== null && (typeof metric.value !== "number" || !Number.isFinite(metric.value))) ||
|
|
72
|
+
(metric.unit !== "count" && metric.unit !== "percent" && metric.unit !== "minor_currency") ||
|
|
73
|
+
typeof metric.observed_at !== "string" || metric.observed_at.length === 0 ||
|
|
74
|
+
(metric.currency !== undefined && typeof metric.currency !== "string") ||
|
|
75
|
+
(metric.note !== undefined && typeof metric.note !== "string"))
|
|
76
|
+
throw new MerchantAnalyticsHttpError("protocol", `analytics metric ${String(metric.name)} is invalid`);
|
|
77
|
+
if (names.has(metric.name))
|
|
78
|
+
throw new MerchantAnalyticsHttpError("protocol", `analytics metric ${metric.name} is duplicated`);
|
|
79
|
+
names.add(metric.name);
|
|
80
|
+
return metric;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
function metricSeries(value, expected) {
|
|
84
|
+
const series = object(value, "analytics series must be an object");
|
|
85
|
+
if (series.metric !== expected.metric || series.period !== expected.period || series.granularity !== expected.granularity ||
|
|
86
|
+
(series.unit !== "count" && series.unit !== "percent" && series.unit !== "minor_currency") ||
|
|
87
|
+
!Array.isArray(series.points) || series.points.length > 10_000 ||
|
|
88
|
+
(series.currency !== undefined && typeof series.currency !== "string") ||
|
|
89
|
+
(series.note !== undefined && typeof series.note !== "string"))
|
|
90
|
+
throw new MerchantAnalyticsHttpError("protocol", "analytics series metadata is invalid");
|
|
91
|
+
for (const point of series.points) {
|
|
92
|
+
const item = object(point, "analytics series point must be an object");
|
|
93
|
+
if (typeof item.date !== "string" || item.date.length === 0 || item.date.length > 32 ||
|
|
94
|
+
typeof item.value !== "number" || !Number.isFinite(item.value)) {
|
|
95
|
+
throw new MerchantAnalyticsHttpError("protocol", "analytics series point is invalid");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return series;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Generic server-side adapter for order, sales, campaign or advertising
|
|
102
|
+
* services. The remote service is never exposed to the model as a tool.
|
|
103
|
+
*
|
|
104
|
+
* Contract:
|
|
105
|
+
* GET /v1/merchant/analytics/metrics?merchant_id=...&period=7d
|
|
106
|
+
* -> { ok: true, merchant_id, metrics, limitations? }
|
|
107
|
+
* GET /v1/merchant/analytics/series?merchant_id=...&metric=...&period=7d&granularity=day
|
|
108
|
+
* -> { ok: true, merchant_id, series: MetricSeries }
|
|
109
|
+
* A 404 on the series endpoint means the source does not provide that metric.
|
|
110
|
+
*/
|
|
111
|
+
export class HttpMerchantAnalyticsSource {
|
|
112
|
+
baseUrl;
|
|
113
|
+
token;
|
|
114
|
+
fetchImpl;
|
|
115
|
+
timeoutMs;
|
|
116
|
+
maxResponseBytes;
|
|
117
|
+
constructor(options) {
|
|
118
|
+
this.baseUrl = assertBaseUrl(options.baseUrl);
|
|
119
|
+
this.token = options.token;
|
|
120
|
+
this.fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
121
|
+
this.timeoutMs = Math.max(100, Math.min(options.timeoutMs ?? DEFAULT_TIMEOUT_MS, 120_000));
|
|
122
|
+
this.maxResponseBytes = Math.max(1_024, Math.min(options.maxResponseBytes ?? DEFAULT_MAX_RESPONSE_BYTES, 8 * 1024 * 1024));
|
|
123
|
+
}
|
|
124
|
+
async request(path, query) {
|
|
125
|
+
const controller = new AbortController();
|
|
126
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
127
|
+
const url = new URL(`${this.baseUrl}${path}`);
|
|
128
|
+
for (const [key, value] of Object.entries(query))
|
|
129
|
+
url.searchParams.set(key, value);
|
|
130
|
+
try {
|
|
131
|
+
let response;
|
|
132
|
+
try {
|
|
133
|
+
response = await this.fetchImpl(url, {
|
|
134
|
+
method: "GET",
|
|
135
|
+
redirect: "manual",
|
|
136
|
+
headers: {
|
|
137
|
+
accept: "application/json",
|
|
138
|
+
...(this.token === undefined ? {} : { authorization: `Bearer ${this.token}` }),
|
|
139
|
+
},
|
|
140
|
+
signal: controller.signal,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
throw new MerchantAnalyticsHttpError("transport", `analytics request failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
145
|
+
}
|
|
146
|
+
if (isRedirectResponse(response)) {
|
|
147
|
+
throw new MerchantAnalyticsHttpError("transport", "analytics endpoint must not redirect", response.status);
|
|
148
|
+
}
|
|
149
|
+
if (response.status === 401 || response.status === 403) {
|
|
150
|
+
throw new MerchantAnalyticsHttpError("auth", "analytics authorization failed", response.status);
|
|
151
|
+
}
|
|
152
|
+
if (response.status === 404)
|
|
153
|
+
return { status: response.status, payload: {} };
|
|
154
|
+
let payload;
|
|
155
|
+
try {
|
|
156
|
+
payload = await readJsonBody(response, { maxBytes: this.maxResponseBytes, signal: controller.signal });
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
if (controller.signal.aborted)
|
|
160
|
+
throw new MerchantAnalyticsHttpError("transport", "analytics request timed out while reading response");
|
|
161
|
+
if (error instanceof SafeHttpError && error.code === "response_too_large") {
|
|
162
|
+
throw new MerchantAnalyticsHttpError("protocol", "analytics response exceeds the configured size limit");
|
|
163
|
+
}
|
|
164
|
+
throw new MerchantAnalyticsHttpError("protocol", "analytics response is not valid JSON");
|
|
165
|
+
}
|
|
166
|
+
const body = object(payload, "analytics response must be an object");
|
|
167
|
+
if (!response.ok || body.ok === false)
|
|
168
|
+
throw new MerchantAnalyticsHttpError("unavailable", "analytics service returned an error", response.status);
|
|
169
|
+
if (body.ok !== true)
|
|
170
|
+
throw new MerchantAnalyticsHttpError("protocol", "analytics response must set ok=true", response.status);
|
|
171
|
+
return { status: response.status, payload: body };
|
|
172
|
+
}
|
|
173
|
+
finally {
|
|
174
|
+
clearTimeout(timer);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
async getMetrics(input) {
|
|
178
|
+
const { payload } = await this.request("/v1/merchant/analytics/metrics", input);
|
|
179
|
+
requireMerchant(payload.merchant_id, input.merchant_id);
|
|
180
|
+
return {
|
|
181
|
+
metrics: metricValues(payload.metrics),
|
|
182
|
+
...(payload.limitations === undefined ? {} : { limitations: limitations(payload.limitations) }),
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
async queryMetric(input) {
|
|
186
|
+
const { status, payload } = await this.request("/v1/merchant/analytics/series", input);
|
|
187
|
+
if (status === 404)
|
|
188
|
+
return undefined;
|
|
189
|
+
requireMerchant(payload.merchant_id, input.merchant_id);
|
|
190
|
+
return metricSeries(payload.series, input);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=http-analytics-source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-analytics-source.js","sourceRoot":"","sources":["../../../../src/agent/merchant/intelligence/http-analytics-source.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAI5F,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAClC,MAAM,0BAA0B,GAAG,GAAG,GAAG,IAAI,CAAC;AAY9C,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IA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,CAAC,WAAW,CAAC,CAAC;QACxD,OAAO;YACL,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC;YACtC,GAAG,CAAC,OAAO,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,WAAW,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;SAChG,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,KAAqG;QACrH,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,+BAA+B,EAAE,KAAK,CAAC,CAAC;QACvF,IAAI,MAAM,KAAK,GAAG;YAAE,OAAO,SAAS,CAAC;QACrC,eAAe,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;QACxD,OAAO,YAAY,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC7C,CAAC;CACF"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
export interface DataLimitation {
|
|
2
|
+
source: string;
|
|
3
|
+
note: string;
|
|
4
|
+
}
|
|
5
|
+
export type MetricUnit = "count" | "percent" | "minor_currency";
|
|
6
|
+
/** Formal analytics metric names understood by the optional commerce source. */
|
|
7
|
+
export type FormalAnalyticsMetric = "gross_sales" | "orders" | "ad_spend" | "roas" | "campaign_conversions";
|
|
8
|
+
export interface MetricValue {
|
|
9
|
+
name: string;
|
|
10
|
+
value: number | null;
|
|
11
|
+
unit: MetricUnit;
|
|
12
|
+
currency?: string;
|
|
13
|
+
observed_at: string;
|
|
14
|
+
note?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface MetricPoint {
|
|
17
|
+
date: string;
|
|
18
|
+
value: number;
|
|
19
|
+
}
|
|
20
|
+
export interface MetricSeries {
|
|
21
|
+
metric: string;
|
|
22
|
+
unit: MetricUnit;
|
|
23
|
+
period: string;
|
|
24
|
+
/** Points use UTC dates; week = Monday, month = first day of month. */
|
|
25
|
+
granularity: "day" | "week" | "month";
|
|
26
|
+
points: MetricPoint[];
|
|
27
|
+
note?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Optional authoritative sales/marketing adapter. It is deliberately
|
|
31
|
+
* separate from MerchantClient and MerchantStatsStore: deployments can wire
|
|
32
|
+
* an ERP, order service or ad platform without granting the model direct
|
|
33
|
+
* access to that system.
|
|
34
|
+
*/
|
|
35
|
+
export interface MerchantAnalyticsSource {
|
|
36
|
+
getMetrics(input: {
|
|
37
|
+
merchant_id: string;
|
|
38
|
+
period: string;
|
|
39
|
+
}): Promise<{
|
|
40
|
+
metrics: MetricValue[];
|
|
41
|
+
limitations?: DataLimitation[];
|
|
42
|
+
}>;
|
|
43
|
+
queryMetric(input: {
|
|
44
|
+
merchant_id: string;
|
|
45
|
+
metric: string;
|
|
46
|
+
period: string;
|
|
47
|
+
granularity: "day" | "week" | "month";
|
|
48
|
+
}): Promise<MetricSeries | undefined>;
|
|
49
|
+
}
|
|
50
|
+
export interface MerchantChangePreview {
|
|
51
|
+
candidate_id: string;
|
|
52
|
+
tool: string;
|
|
53
|
+
status: string;
|
|
54
|
+
risk: string;
|
|
55
|
+
expires_at: string;
|
|
56
|
+
stale_sensitive: true;
|
|
57
|
+
changes: Array<{
|
|
58
|
+
field: string;
|
|
59
|
+
before: unknown;
|
|
60
|
+
after: unknown;
|
|
61
|
+
}>;
|
|
62
|
+
}
|
|
63
|
+
export interface CatalogHealth {
|
|
64
|
+
total: number;
|
|
65
|
+
active: number;
|
|
66
|
+
paused: number;
|
|
67
|
+
out_of_stock: number | null;
|
|
68
|
+
observed_at: string;
|
|
69
|
+
}
|
|
70
|
+
export interface MerchantBusinessSnapshot {
|
|
71
|
+
merchant_id: string;
|
|
72
|
+
period: string;
|
|
73
|
+
generated_at: string;
|
|
74
|
+
metrics: MetricValue[];
|
|
75
|
+
alerts: {
|
|
76
|
+
active_negotiations: number;
|
|
77
|
+
human_reviews: number;
|
|
78
|
+
pending_actions: number;
|
|
79
|
+
low_stock: number | null;
|
|
80
|
+
};
|
|
81
|
+
top_sku_contacts?: Array<{
|
|
82
|
+
sku: string;
|
|
83
|
+
contact_events: number;
|
|
84
|
+
distinct_buyers: number;
|
|
85
|
+
negotiations: number;
|
|
86
|
+
}>;
|
|
87
|
+
limitations: DataLimitation[];
|
|
88
|
+
}
|
|
89
|
+
export interface NegotiationDigestItem {
|
|
90
|
+
negotiation_id: string;
|
|
91
|
+
phase: string;
|
|
92
|
+
buyer_identity: string;
|
|
93
|
+
skus: string[];
|
|
94
|
+
quantity?: number;
|
|
95
|
+
latest_price_minor?: number;
|
|
96
|
+
currency?: string;
|
|
97
|
+
needs_human_review: boolean;
|
|
98
|
+
updated_at: string;
|
|
99
|
+
agreement_id?: string;
|
|
100
|
+
}
|
|
101
|
+
export interface PendingActionSummary {
|
|
102
|
+
candidate_id: string;
|
|
103
|
+
tool: string;
|
|
104
|
+
risk: string;
|
|
105
|
+
status: string;
|
|
106
|
+
expires_at: string;
|
|
107
|
+
/** Literal invariant: every approval must revalidate current preconditions. */
|
|
108
|
+
stale_sensitive: true;
|
|
109
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/agent/merchant/intelligence/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
*/
|
|
7
|
+
import type { WriteApprovalCandidateStore } from "./action-candidate.js";
|
|
8
|
+
import type { MerchantChangePreview } from "./intelligence/types.js";
|
|
9
|
+
/** Public, server-enriched projection of an approval candidate. */
|
|
10
|
+
export declare function publicCandidatePreview(candidate: ReturnType<WriteApprovalCandidateStore["get"]>): MerchantChangePreview | undefined;
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
*/
|
|
7
|
+
/** Public, server-enriched projection of an approval candidate. */
|
|
8
|
+
export function publicCandidatePreview(candidate) {
|
|
9
|
+
if (candidate === undefined)
|
|
10
|
+
return undefined;
|
|
11
|
+
const args = candidate.arguments;
|
|
12
|
+
const before = candidate.preconditions;
|
|
13
|
+
const changes = [];
|
|
14
|
+
const patch = args.changes;
|
|
15
|
+
if (patch !== null && typeof patch === "object" && !Array.isArray(patch)) {
|
|
16
|
+
for (const [field, after] of Object.entries(patch)) {
|
|
17
|
+
if (/token|secret|credential|password|floor|cost|vault|private/i.test(field))
|
|
18
|
+
continue;
|
|
19
|
+
changes.push({ field, before: before[field], after });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (typeof args.stock === "number")
|
|
23
|
+
changes.push({ field: "stock", before: before.stock, after: args.stock });
|
|
24
|
+
if (typeof args.paused === "boolean")
|
|
25
|
+
changes.push({ field: "paused", before: before.paused, after: args.paused });
|
|
26
|
+
if (changes.length === 0)
|
|
27
|
+
changes.push({ field: "operation", before: "not_applied", after: candidate.tool });
|
|
28
|
+
return {
|
|
29
|
+
candidate_id: candidate.candidate_id,
|
|
30
|
+
tool: candidate.tool,
|
|
31
|
+
status: candidate.status,
|
|
32
|
+
risk: candidate.risk,
|
|
33
|
+
expires_at: candidate.expires_at,
|
|
34
|
+
stale_sensitive: true,
|
|
35
|
+
changes,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=merchant-enrichment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merchant-enrichment.js","sourceRoot":"","sources":["../../../src/agent/merchant/merchant-enrichment.ts"],"names":[],"mappings":"AAAA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AE,aAAa,EAAE,KAAK,EAAE,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7G,OAAO;QACL,YAAY,EAAE,SAAS,CAAC,YAAY;QACpC,IAAI,EAAE,SAAS,CAAC,IAAI;QACpB,MAAM,EAAE,SAAS,CAAC,MAAM;QACxB,IAAI,EAAE,SAAS,CAAC,IAAI;QACpB,UAAU,EAAE,SAAS,CAAC,UAAU;QAChC,eAAe,EAAE,IAAI;QACrB,OAAO;KACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AgentProfile } from "../../config/profile.js";
|
|
2
|
+
import type { GroundingContext, GroundingRule } from "../context/grounding.js";
|
|
3
|
+
/** Rules are intentionally read-only; write tools can never be a grounding target. */
|
|
4
|
+
export declare const MERCHANT_GROUNDING_RULES: readonly GroundingRule[];
|
|
5
|
+
export declare function merchantGroundingContext(profile: AgentProfile, latestUserText: string): GroundingContext;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
function has(text, terms) {
|
|
2
|
+
const lowered = text.toLowerCase();
|
|
3
|
+
return terms.some((term) => lowered.includes(term));
|
|
4
|
+
}
|
|
5
|
+
function enabled(profile) {
|
|
6
|
+
return profile.merchant_experience?.enabled !== false &&
|
|
7
|
+
profile.merchant_experience?.grounding !== false;
|
|
8
|
+
}
|
|
9
|
+
/** Rules are intentionally read-only; write tools can never be a grounding target. */
|
|
10
|
+
export const MERCHANT_GROUNDING_RULES = [
|
|
11
|
+
{
|
|
12
|
+
name: "pending-actions",
|
|
13
|
+
priority: 10,
|
|
14
|
+
match: ({ latestUserText, sessionState }) => {
|
|
15
|
+
const profile = sessionState.profile;
|
|
16
|
+
if (profile !== undefined && !enabled(profile))
|
|
17
|
+
return undefined;
|
|
18
|
+
if (!has(latestUserText, ["待审批", "等待批准", "pending", "approve", "批准", "执行"])) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
return { tool: "get_pending_actions", arguments: {}, reason: "approval state must be current" };
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: "negotiations",
|
|
26
|
+
priority: 20,
|
|
27
|
+
match: ({ latestUserText }) => {
|
|
28
|
+
if (!has(latestUserText, ["磋商", "询价", "报价", "还价", "buyer", "negotiation"])) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
return { tool: "get_negotiation_digest", arguments: { status: "active" }, reason: "read current A2A negotiations first" };
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: "human-review",
|
|
36
|
+
priority: 30,
|
|
37
|
+
match: ({ latestUserText }) => {
|
|
38
|
+
if (!has(latestUserText, ["人工", "审核", "转人工", "human review"]))
|
|
39
|
+
return undefined;
|
|
40
|
+
return { tool: "get_human_review_queue", arguments: {}, reason: "read the current review queue first" };
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: "inventory-health",
|
|
45
|
+
priority: 40,
|
|
46
|
+
match: ({ latestUserText }) => {
|
|
47
|
+
if (!has(latestUserText, ["库存", "缺货", "有货", "补货", "stock", "inventory"])) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
return { tool: "get_catalog_health", arguments: {}, reason: "inventory answers require current catalog facts" };
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: "catalog",
|
|
55
|
+
priority: 50,
|
|
56
|
+
match: ({ latestUserText }) => {
|
|
57
|
+
if (!has(latestUserText, ["商品", "目录", "sku", "listing", "catalog"]))
|
|
58
|
+
return undefined;
|
|
59
|
+
return { tool: "list_catalog_products", arguments: {}, reason: "catalog answers require current owned listings" };
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: "business-snapshot",
|
|
64
|
+
priority: 60,
|
|
65
|
+
match: ({ latestUserText }) => {
|
|
66
|
+
if (!has(latestUserText, ["经营", "生意", "销售", "业绩", "指标", "收入", "最近怎么样"])) {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
return { tool: "get_business_snapshot", arguments: {}, reason: "business answers require current metrics" };
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
];
|
|
73
|
+
export function merchantGroundingContext(profile, latestUserText) {
|
|
74
|
+
return { latestUserText, sessionState: { profile } };
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=merchant-grounding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merchant-grounding.js","sourceRoot":"","sources":["../../../src/agent/merchant/merchant-grounding.ts"],"names":[],"mappings":"AAGA,SAAS,GAAG,CAAC,IAAY,EAAE,KAAwB;IACjD,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IACnC,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;AACtD,CAAC;AAED,SAAS,OAAO,CAAC,OAAqB;IACpC,OAAO,OAAO,CAAC,mBAAmB,EAAE,OAAO,KAAK,KAAK;QACnD,OAAO,CAAC,mBAAmB,EAAE,SAAS,KAAK,KAAK,CAAC;AACrD,CAAC;AAED,sFAAsF;AACtF,MAAM,CAAC,MAAM,wBAAwB,GAA6B;IAChE;QACE,IAAI,EAAE,iBAAiB;QACvB,QAAQ,EAAE,EAAE;QACZ,KAAK,EAAE,CAAC,EAAE,cAAc,EAAE,YAAY,EAAoB,EAAE,EAAE;YAC5D,MAAM,OAAO,GAAG,YAAY,CAAC,OAAmC,CAAC;YACjE,IAAI,OAAO,KAAK,SAAS,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;gBAAE,OAAO,SAAS,CAAC;YACjE,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC;gB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AAO,EAAE,IAAI,EAAE,oBAAoB,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,iDAAiD,EAAE,CAAC;QAClH,CAAC;KACF;IACD;QACE,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,EAAE;QACZ,KAAK,EAAE,CAAC,EAAE,cAAc,EAAoB,EAAE,EAAE;YAC9C,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;gBAAE,OAAO,SAAS,CAAC;YACtF,OAAO,EAAE,IAAI,EAAE,uBAAuB,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,gDAAgD,EAAE,CAAC;QACpH,CAAC;KACF;IACD;QACE,IAAI,EAAE,mBAAmB;QACzB,QAAQ,EAAE,EAAE;QACZ,KAAK,EAAE,CAAC,EAAE,cAAc,EAAoB,EAAE,EAAE;YAC9C,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC;gBACxE,OAAO,SAAS,CAAC;YACnB,CAAC;YACD,OAAO,EAAE,IAAI,EAAE,uBAAuB,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,0CAA0C,EAAE,CAAC;QAC9G,CAAC;KACF;CACF,CAAC;AAEF,MAAM,UAAU,wBAAwB,CACtC,OAAqB,EACrB,cAAsB;IAEtB,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,EAAE,OAAO,EAAE,EAAE,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
+
*/
|
|
7
|
+
import { PresentationRegistry } from "../presentation/registry.js";
|
|
8
|
+
export declare function createMerchantPresentationRegistry(): PresentationRegistry;
|