@harrylabsj/kiwi 0.7.8 → 0.7.10
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/contracts/commerce-intent/1.0/schema.json +124 -0
- package/contracts/delegation-policy/1.0/schema.json +143 -0
- package/contracts/effective-authorization/1.0/schema.json +167 -0
- package/contracts/kiwi-contracts.lock.json +1 -1
- package/contracts/manifest.json +25 -1
- package/contracts/persistent-task/1.0/schema.json +191 -0
- package/contracts/vectors/commerce-intent.invalid-no-items.json +7 -0
- package/contracts/vectors/commerce-intent.valid.json +32 -0
- package/contracts/vectors/delegation-policy.invalid-payment-auto.json +15 -0
- package/contracts/vectors/delegation-policy.valid.json +25 -0
- package/contracts/vectors/effective-authorization.invalid-deny-wins.json +20 -0
- package/contracts/vectors/effective-authorization.valid.json +23 -0
- package/contracts/vectors/persistent-task.invalid-no-idempotency.json +7 -0
- package/contracts/vectors/persistent-task.valid.json +45 -0
- package/dist/a2a/client/url-policy.js +52 -14
- package/dist/a2a/client/url-policy.js.map +1 -1
- package/dist/a2a/node.js +4 -1
- package/dist/a2a/node.js.map +1 -1
- package/dist/a2a/signing-key.js +18 -0
- package/dist/a2a/signing-key.js.map +1 -1
- package/dist/buyer-core/build-service.d.ts +28 -0
- package/dist/buyer-core/build-service.js +58 -0
- package/dist/buyer-core/build-service.js.map +1 -0
- package/dist/buyer-core/errors.d.ts +31 -0
- package/dist/buyer-core/errors.js +52 -0
- package/dist/buyer-core/errors.js.map +1 -0
- package/dist/buyer-core/merchant-index.d.ts +53 -0
- package/dist/buyer-core/merchant-index.js +138 -0
- package/dist/buyer-core/merchant-index.js.map +1 -0
- package/dist/buyer-core/negotiator.d.ts +51 -0
- package/dist/buyer-core/negotiator.js +181 -0
- package/dist/buyer-core/negotiator.js.map +1 -0
- package/dist/buyer-core/quote-fetcher.d.ts +46 -0
- package/dist/buyer-core/quote-fetcher.js +166 -0
- package/dist/buyer-core/quote-fetcher.js.map +1 -0
- package/dist/buyer-core/service.d.ts +192 -0
- package/dist/buyer-core/service.js +510 -0
- package/dist/buyer-core/service.js.map +1 -0
- package/dist/buyer-core/store.d.ts +84 -0
- package/dist/buyer-core/store.js +256 -0
- package/dist/buyer-core/store.js.map +1 -0
- package/dist/cli.js +25 -0
- package/dist/cli.js.map +1 -1
- package/dist/contracts/northbound-schema.d.ts +27 -0
- package/dist/contracts/northbound-schema.js +102 -0
- package/dist/contracts/northbound-schema.js.map +1 -0
- package/dist/handoff/destination.js +16 -5
- package/dist/handoff/destination.js.map +1 -1
- package/dist/http/cli.d.ts +16 -0
- package/dist/http/cli.js +111 -0
- package/dist/http/cli.js.map +1 -0
- package/dist/http/server.d.ts +39 -0
- package/dist/http/server.js +297 -0
- package/dist/http/server.js.map +1 -0
- package/dist/mcp/cli.d.ts +61 -0
- package/dist/mcp/cli.js +125 -0
- package/dist/mcp/cli.js.map +1 -0
- package/dist/mcp/server.d.ts +41 -0
- package/dist/mcp/server.js +141 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/tools.d.ts +28 -0
- package/dist/mcp/tools.js +230 -0
- package/dist/mcp/tools.js.map +1 -0
- package/dist/mcp/types.d.ts +107 -0
- package/dist/mcp/types.js +50 -0
- package/dist/mcp/types.js.map +1 -0
- package/dist/merchant/ops.d.ts +80 -0
- package/dist/merchant/ops.js +75 -0
- package/dist/merchant/ops.js.map +1 -0
- package/dist/merchant/ucp-profile.d.ts +39 -0
- package/dist/merchant/ucp-profile.js +55 -0
- package/dist/merchant/ucp-profile.js.map +1 -0
- package/dist/product-cli.d.ts +1 -1
- package/dist/product-cli.js +1 -1
- package/dist/product-cli.js.map +1 -1
- package/dist/trust/identity/auth-verifier.d.ts +2 -0
- package/dist/trust/identity/auth-verifier.js +30 -2
- package/dist/trust/identity/auth-verifier.js.map +1 -1
- package/dist/trust/identity/message-signature.js +14 -8
- package/dist/trust/identity/message-signature.js.map +1 -1
- package/package.json +4 -2
|
@@ -0,0 +1 @@
|
|
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AI,CAAC,CAAC,CAAC;QACxD,cAAc,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACrC,CAAC;IACD,IAAI,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAC/B,OAAO,YAAY,CAAC,QAAQ,CAAC,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,KAAc;IACnD,OAAO,0BAA0B,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;AAC9D,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,KAAc;IACrD,OAAO,0BAA0B,CAAC,mBAAmB,EAAE,KAAK,CAAC,CAAC;AAChE,CAAC;AAED,MAAM,UAAU,8BAA8B,CAAC,KAAc;IAC3D,OAAO,0BAA0B,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;AACtE,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,KAAc;IACnD,OAAO,0BAA0B,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;AAC9D,CAAC;AAED,kBAAkB;AAClB,MAAM,UAAU,6BAA6B,CAC3C,IAA4B,EAC5B,KAAc,EACd,IAAY;IAEZ,MAAM,MAAM,GAAG,0BAA0B,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACvD,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,WAAW,IAAI,uBAAuB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACpF,CAAC;AACH,CAAC"}
|
|
@@ -59,6 +59,16 @@ const DOCUMENT_DESTINATION_TYPES = new Set([
|
|
|
59
59
|
"merchant_contact",
|
|
60
60
|
"sales_handoff",
|
|
61
61
|
]);
|
|
62
|
+
// fail-closed 词表分区不变量:每个 destination_type 必须恰好落在 URL/SESSION/
|
|
63
|
+
// DOCUMENT 三类之一——漏分会让校验静默失效(安全策略不生效),多分造成语义冲突。
|
|
64
|
+
for (const type of DESTINATION_TYPES) {
|
|
65
|
+
const membership = Number(URL_DESTINATION_TYPES.has(type))
|
|
66
|
+
+ Number(SESSION_DESTINATION_TYPES.has(type))
|
|
67
|
+
+ Number(DOCUMENT_DESTINATION_TYPES.has(type));
|
|
68
|
+
if (membership !== 1) {
|
|
69
|
+
throw new Error(`destination_type "${type}" must belong to exactly one of URL/SESSION/DOCUMENT sets`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
62
72
|
/** URL 承载类目的地(external checkout / deep link)——URL 安全策略适用。 */
|
|
63
73
|
export function isUrlDestinationType(type) {
|
|
64
74
|
return URL_DESTINATION_TYPES.has(type);
|
|
@@ -83,11 +93,12 @@ export function validateDestination(input, path = "destination") {
|
|
|
83
93
|
if (URL_DESTINATION_TYPES.has(type) && !/^https?:\/\/\S+$/.test(ref)) {
|
|
84
94
|
throw schemaError(`${path}/ref`, `destination type "${type}" requires an http(s) URL ref`);
|
|
85
95
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
96
|
+
// 审查 M3:会话类目的地(ucp_checkout / ucp_order / merchant_checkout_session)
|
|
97
|
+
// 是 opaque 会话/订单 id,不得携带 URL——否则绕过 URL 安全策略,把 URL 直接
|
|
98
|
+
// 呈现给买家(钓鱼 / 内部地址面)。文档类目的地(buyer_erp_request 等)仍允许
|
|
99
|
+
// URL 形 ref(ERP 端点引用,ref 语义由 destination type 决定,不做 URL 探测)。
|
|
100
|
+
if (SESSION_DESTINATION_TYPES.has(type) && /^https?:\/\//.test(ref)) {
|
|
101
|
+
throw schemaError(`${path}/ref`, `destination type "${type}" requires an opaque session ref, not a URL`);
|
|
91
102
|
}
|
|
92
103
|
let payload;
|
|
93
104
|
if (obj.payload !== undefined) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"destination.js","sourceRoot":"","sources":["../../src/handoff/destination.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAEpG,0CAA0C;AAC1C,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,cAAc;IACd,WAAW;IACX,uBAAuB;IACvB,2BAA2B;IAC3B,oBAAoB;IACpB,mBAAmB;IACnB,qBAAqB;IACrB,sBAAsB;IACtB,gBAAgB;IAChB,kBAAkB;IAClB,eAAe;CACP,CAAC;AAIX,iEAAiE;AACjE,MAAM,qBAAqB,GAAiC,IAAI,GAAG,CAAkB;IACnF,uBAAuB;IACvB,oBAAoB;CACrB,CAAC,CAAC;AAEH,uCAAuC;AACvC,MAAM,yBAAyB,GAAiC,IAAI,GAAG,CAAkB;IACvF,cAAc;IACd,WAAW;IACX,2BAA2B;CAC5B,CAAC,CAAC;AAEH,oDAAoD;AACpD,MAAM,0BAA0B,GAAiC,IAAI,GAAG,CAAkB;IACxF,mBAAmB;IACnB,qBAAqB;IACrB,sBAAsB;IACtB,gBAAgB;IAChB,kBAAkB;IAClB,eAAe;CAChB,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"destination.js","sourceRoot":"","sources":["../../src/handoff/destination.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAEpG,0CAA0C;AAC1C,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,cAAc;IACd,WAAW;IACX,uBAAuB;IACvB,2BAA2B;IAC3B,oBAAoB;IACpB,mBAAmB;IACnB,qBAAqB;IACrB,sBAAsB;IACtB,gBAAgB;IAChB,kBAAkB;IAClB,eAAe;CACP,CAAC;AAIX,iEAAiE;AACjE,MAAM,qBAAqB,GAAiC,IAAI,GAAG,CAAkB;IACnF,uBAAuB;IACvB,oBAAoB;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
/**
|
|
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
|
+
export declare function runHttpServe(args: string[]): Promise<number>;
|
package/dist/http/cli.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
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
|
+
* `kiwi buyer-api serve` —— Buyer Core 的 HTTP 包装(战略 v2.5 §6.3/Appendix A)。
|
|
18
|
+
*
|
|
19
|
+
* 与 MCP 同一 buyer-core(buildBuyerService),不同传输。参数与 `kiwi mcp serve`
|
|
20
|
+
* 一致,另加 --port / --host。
|
|
21
|
+
*/
|
|
22
|
+
import { readFileSync } from "node:fs";
|
|
23
|
+
import path from "node:path";
|
|
24
|
+
import { DEFAULT_DELEGATION_POLICY } from "../mcp/cli.js";
|
|
25
|
+
import { buildBuyerService } from "../buyer-core/build-service.js";
|
|
26
|
+
import { MerchantOpsService } from "../merchant/ops.js";
|
|
27
|
+
import { createBuyerHttpServer } from "./server.js";
|
|
28
|
+
export async function runHttpServe(args) {
|
|
29
|
+
const opts = {};
|
|
30
|
+
let ucpConfigPath;
|
|
31
|
+
let merchantTokensPath;
|
|
32
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
33
|
+
const flag = args[i];
|
|
34
|
+
const value = args[i + 1];
|
|
35
|
+
if (value === undefined)
|
|
36
|
+
continue;
|
|
37
|
+
if (flag === "--db")
|
|
38
|
+
opts.db = value;
|
|
39
|
+
else if (flag === "--principal")
|
|
40
|
+
opts.principal = value;
|
|
41
|
+
else if (flag === "--agent")
|
|
42
|
+
opts.buyerAgentId = value;
|
|
43
|
+
else if (flag === "--session")
|
|
44
|
+
opts.sessionId = value;
|
|
45
|
+
else if (flag === "--catalog-url")
|
|
46
|
+
opts.catalogUrl = value;
|
|
47
|
+
else if (flag === "--marketplace-url")
|
|
48
|
+
opts.marketplaceUrl = value;
|
|
49
|
+
else if (flag === "--buyer-bootstrap-token")
|
|
50
|
+
opts.buyerBootstrapToken = value;
|
|
51
|
+
else if (flag === "--port")
|
|
52
|
+
opts.port = Number(value);
|
|
53
|
+
else if (flag === "--host")
|
|
54
|
+
opts.host = value;
|
|
55
|
+
else if (flag === "--ucp-config")
|
|
56
|
+
ucpConfigPath = value;
|
|
57
|
+
else if (flag === "--merchant-tokens")
|
|
58
|
+
merchantTokensPath = value;
|
|
59
|
+
else if (flag === "--policy") {
|
|
60
|
+
try {
|
|
61
|
+
opts.policy = JSON.parse(readFileSync(value, "utf-8"));
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
process.stderr.write(`cannot read --policy file ${value}\n`);
|
|
65
|
+
return 2;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
const principal = opts.principal ?? process.env.KIWI_PRINCIPAL ?? "principal:local";
|
|
70
|
+
const policy = opts.policy ?? { ...DEFAULT_DELEGATION_POLICY, principal };
|
|
71
|
+
const dbPath = opts.db ?? path.join(".kiwi", "mcp", "state.sqlite");
|
|
72
|
+
const service = buildBuyerService({
|
|
73
|
+
dbPath,
|
|
74
|
+
principal,
|
|
75
|
+
buyerAgentId: opts.buyerAgentId ?? process.env.KIWI_BUYER_AGENT ?? "buyer-agent:kiwi-http",
|
|
76
|
+
sessionId: opts.sessionId ?? process.env.KIWI_SESSION ?? `session-${process.pid}`,
|
|
77
|
+
policy,
|
|
78
|
+
catalogUrl: opts.catalogUrl,
|
|
79
|
+
marketplaceUrl: opts.marketplaceUrl,
|
|
80
|
+
buyerBootstrapToken: opts.buyerBootstrapToken ?? process.env.SHOPPING_BUYER_BOOTSTRAP_TOKEN,
|
|
81
|
+
});
|
|
82
|
+
const port = opts.port ?? 8787;
|
|
83
|
+
const host = opts.host ?? "127.0.0.1";
|
|
84
|
+
const merchantUcp = ucpConfigPath !== undefined
|
|
85
|
+
? JSON.parse(readFileSync(ucpConfigPath, "utf-8"))
|
|
86
|
+
: undefined;
|
|
87
|
+
// Merchant Ops(§7.6):从 merchant-tokens.env(merchantId=token 每行)构建,
|
|
88
|
+
// 命名空间隔离——merchant token 只访问 kiwi.merchant.*。
|
|
89
|
+
const merchantOps = {};
|
|
90
|
+
if (merchantTokensPath !== undefined && opts.marketplaceUrl !== undefined) {
|
|
91
|
+
for (const line of readFileSync(merchantTokensPath, "utf-8").split("\n")) {
|
|
92
|
+
const idx = line.indexOf("=");
|
|
93
|
+
if (idx <= 0)
|
|
94
|
+
continue;
|
|
95
|
+
const merchantId = line.slice(0, idx).trim();
|
|
96
|
+
const token = line.slice(idx + 1).trim();
|
|
97
|
+
if (merchantId === "" || token === "")
|
|
98
|
+
continue;
|
|
99
|
+
merchantOps[merchantId] = new MerchantOpsService({ baseUrl: opts.marketplaceUrl, merchantToken: token });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const server = createBuyerHttpServer({
|
|
103
|
+
service,
|
|
104
|
+
...(merchantUcp !== undefined ? { merchantUcp } : {}),
|
|
105
|
+
...(Object.keys(merchantOps).length > 0 ? { merchantOps } : {}),
|
|
106
|
+
});
|
|
107
|
+
await new Promise((resolve) => server.listen(port, host, resolve));
|
|
108
|
+
process.stderr.write(`kiwi-buyer-http listening on http://${host}:${port}\n`);
|
|
109
|
+
return 0;
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/http/cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,yBAAyB,EAAwB,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAOpD,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,IAAc;IAC/C,MAAM,IAAI,GAAuD,EAAE,CAAC;IACpE,IAAI,aAAiC,CAAC;IACtC,IAAI,kBAAsC,CAAC;IAC3C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACrB,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAC1B,IAAI,KAAK,KAAK,SAAS;YAAE,SAAS;QAClC,IAAI,IAAI,KA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YAC9B,IAAI,GAAG,IAAI,CAAC;gBAAE,SAAS;YACvB,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;YAC7C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YACzC,IAAI,UAAU,KAAK,EAAE,IAAI,KAAK,KAAK,EAAE;gBAAE,SAAS;YAChD,WAAW,CAAC,UAAU,CAAC,GAAG,IAAI,kBAAkB,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,CAAC;QAC3G,CAAC;IACH,CAAC;IACD,MAAM,MAAM,GAAG,qBAAqB,CAAC;QACnC,OAAO;QACP,GAAG,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrD,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAChE,CAAC,CAAC;IACH,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;IACzE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,uCAAuC,IAAI,IAAI,IAAI,IAAI,CAAC,CAAC;IAC9E,OAAO,CAAC,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
* kiwi-buyer-http —— Buyer Core 的 HTTP 包装(战略 v2.5 §6.3/§6.5/Appendix A)。
|
|
18
|
+
*
|
|
19
|
+
* 与 MCP 同一 buyer-core(KiwiBuyerService),不同包装:证明"单核心、多包装"——
|
|
20
|
+
* 未来新宿主出现时接入从"重写产品"降为"写一个薄适配器"(§6.3)。
|
|
21
|
+
*
|
|
22
|
+
* 暴露与 7 个 MCP 工具一一对应的 HTTP 端点(同一语义不变量:schema/授权门/
|
|
23
|
+
* 幂等/错误分类)。本 server 不持有任何商业状态——状态唯一权威在持久 store。
|
|
24
|
+
*/
|
|
25
|
+
import { type Server } from "node:http";
|
|
26
|
+
import { KiwiBuyerService } from "../buyer-core/service.js";
|
|
27
|
+
import type { MerchantOpsService } from "../merchant/ops.js";
|
|
28
|
+
export interface HttpAdapterOptions {
|
|
29
|
+
service: KiwiBuyerService;
|
|
30
|
+
/** 商家 UCP Profile 发布配置:merchantId → { domain, catalogEndpoint }(§7.1)。 */
|
|
31
|
+
merchantUcp?: Record<string, {
|
|
32
|
+
domain: string;
|
|
33
|
+
catalogEndpoint: string;
|
|
34
|
+
}>;
|
|
35
|
+
/** Merchant Ops(§7.6):merchantId → MerchantOpsService(merchant token 作用域)。 */
|
|
36
|
+
merchantOps?: Record<string, MerchantOpsService>;
|
|
37
|
+
}
|
|
38
|
+
export declare function createBuyerHttpServer(options: HttpAdapterOptions): Server;
|
|
39
|
+
export type { Server };
|
|
@@ -0,0 +1,297 @@
|
|
|
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
|
+
* kiwi-buyer-http —— Buyer Core 的 HTTP 包装(战略 v2.5 §6.3/§6.5/Appendix A)。
|
|
18
|
+
*
|
|
19
|
+
* 与 MCP 同一 buyer-core(KiwiBuyerService),不同包装:证明"单核心、多包装"——
|
|
20
|
+
* 未来新宿主出现时接入从"重写产品"降为"写一个薄适配器"(§6.3)。
|
|
21
|
+
*
|
|
22
|
+
* 暴露与 7 个 MCP 工具一一对应的 HTTP 端点(同一语义不变量:schema/授权门/
|
|
23
|
+
* 幂等/错误分类)。本 server 不持有任何商业状态——状态唯一权威在持久 store。
|
|
24
|
+
*/
|
|
25
|
+
import { createServer } from "node:http";
|
|
26
|
+
import { KiwiBuyerService } from "../buyer-core/service.js";
|
|
27
|
+
import { McpError } from "../buyer-core/errors.js";
|
|
28
|
+
import { buildMerchantUcpProfile } from "../merchant/ucp-profile.js";
|
|
29
|
+
export function createBuyerHttpServer(options) {
|
|
30
|
+
const { service, merchantUcp, merchantOps } = options;
|
|
31
|
+
const readJson = (req) => new Promise((resolve, reject) => {
|
|
32
|
+
let data = "";
|
|
33
|
+
req.on("data", (chunk) => {
|
|
34
|
+
data += chunk.toString();
|
|
35
|
+
if (data.length > 256 * 1024)
|
|
36
|
+
reject(new Error("request body too large"));
|
|
37
|
+
});
|
|
38
|
+
req.on("end", () => {
|
|
39
|
+
if (data.trim() === "")
|
|
40
|
+
return resolve({});
|
|
41
|
+
try {
|
|
42
|
+
resolve(JSON.parse(data));
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
reject(new Error("invalid JSON body"));
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
req.on("error", reject);
|
|
49
|
+
});
|
|
50
|
+
const send = (res, status, body) => {
|
|
51
|
+
res.writeHead(status, { "content-type": "application/json" });
|
|
52
|
+
res.end(JSON.stringify(body));
|
|
53
|
+
};
|
|
54
|
+
const sendError = (res, error) => {
|
|
55
|
+
if (error instanceof McpError) {
|
|
56
|
+
return send(res, 400, { ok: false, error: { code: error.code, message: error.message } });
|
|
57
|
+
}
|
|
58
|
+
return send(res, 500, {
|
|
59
|
+
ok: false,
|
|
60
|
+
error: { code: "internal_error", message: error instanceof Error ? error.message : String(error) },
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
const routes = [
|
|
64
|
+
{ method: "GET", path: "/health", handler: async (_b, _p, res) => send(res, 200, { ok: true, service: "kiwi-buyer-http" }) },
|
|
65
|
+
{
|
|
66
|
+
method: "POST", path: "/search", handler: async (b, _p, res) => {
|
|
67
|
+
try {
|
|
68
|
+
const result = await service.search({
|
|
69
|
+
query: String(b.query ?? ""),
|
|
70
|
+
category: b.category === undefined ? undefined : String(b.category),
|
|
71
|
+
region: b.region === undefined ? undefined : String(b.region),
|
|
72
|
+
});
|
|
73
|
+
send(res, 200, { ok: true, result });
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
sendError(res, e);
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
method: "POST", path: "/tasks", handler: async (b, _p, res) => {
|
|
82
|
+
try {
|
|
83
|
+
const result = await service.requestQuotes({
|
|
84
|
+
intent: (b.intent ?? {}),
|
|
85
|
+
idempotency_key: b.idempotency_key === undefined ? undefined : String(b.idempotency_key),
|
|
86
|
+
merchant_ids: b.merchant_ids === undefined ? undefined : b.merchant_ids.map(String),
|
|
87
|
+
});
|
|
88
|
+
send(res, 201, { ok: true, result });
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
sendError(res, e);
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
method: "GET", path: "/tasks/:id", handler: async (_b, p, res) => {
|
|
97
|
+
try {
|
|
98
|
+
send(res, 200, { ok: true, result: service.getTask(p.id ?? "") });
|
|
99
|
+
}
|
|
100
|
+
catch (e) {
|
|
101
|
+
sendError(res, e);
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
method: "POST", path: "/tasks/:id/negotiate", handler: async (b, p, res) => {
|
|
107
|
+
try {
|
|
108
|
+
const result = await service.negotiate({
|
|
109
|
+
task_id: p.id ?? "",
|
|
110
|
+
action: b.action === "clarification" ? "clarification" : "counter_offer",
|
|
111
|
+
summary: String(b.summary ?? ""),
|
|
112
|
+
});
|
|
113
|
+
send(res, 200, { ok: true, result });
|
|
114
|
+
}
|
|
115
|
+
catch (e) {
|
|
116
|
+
sendError(res, e);
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
method: "POST", path: "/tasks/:id/agreement", handler: async (b, p, res) => {
|
|
122
|
+
try {
|
|
123
|
+
const result = await service.acceptAgreement({
|
|
124
|
+
task_id: p.id ?? "",
|
|
125
|
+
candidate_id: String(b.candidate_id ?? ""),
|
|
126
|
+
approval_id: b.approval_id === undefined ? undefined : String(b.approval_id),
|
|
127
|
+
});
|
|
128
|
+
send(res, 201, {
|
|
129
|
+
ok: true,
|
|
130
|
+
result: { agreement: result.agreement, authorization: result.authorization },
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
catch (e) {
|
|
134
|
+
sendError(res, e);
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
method: "GET", path: "/agreements/:id", handler: async (_b, p, res) => {
|
|
140
|
+
try {
|
|
141
|
+
send(res, 200, { ok: true, result: service.getAgreement(p.id ?? "") });
|
|
142
|
+
}
|
|
143
|
+
catch (e) {
|
|
144
|
+
sendError(res, e);
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
method: "POST", path: "/agreements/:id/handoff", handler: async (b, p, res) => {
|
|
150
|
+
try {
|
|
151
|
+
const result = await service.handoff({
|
|
152
|
+
agreement_id: p.id ?? "",
|
|
153
|
+
approval_id: String(b.approval_id ?? ""),
|
|
154
|
+
destination_type: String(b.destination_type ?? ""),
|
|
155
|
+
url: b.url === undefined ? undefined : String(b.url),
|
|
156
|
+
});
|
|
157
|
+
send(res, 200, { ok: true, result });
|
|
158
|
+
}
|
|
159
|
+
catch (e) {
|
|
160
|
+
sendError(res, e);
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
method: "POST", path: "/approvals", handler: async (b, _p, res) => {
|
|
166
|
+
try {
|
|
167
|
+
const result = service.requestApproval({
|
|
168
|
+
task_id: String(b.task_id ?? ""),
|
|
169
|
+
action: b.action,
|
|
170
|
+
candidate_digest: b.candidate_digest === undefined ? undefined : String(b.candidate_digest),
|
|
171
|
+
});
|
|
172
|
+
send(res, 201, { ok: true, result });
|
|
173
|
+
}
|
|
174
|
+
catch (e) {
|
|
175
|
+
sendError(res, e);
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
// Merchant Ops RFQ 队列(§7.6):kiwi.merchant.rfqs。
|
|
181
|
+
method: "GET", path: "/merchant/:id/rfqs", handler: async (_b, p, res) => {
|
|
182
|
+
const ops = merchantOps?.[p.id ?? ""];
|
|
183
|
+
if (ops === undefined)
|
|
184
|
+
return send(res, 404, { ok: false, error: { code: "merchant_not_found", message: `no ops for ${p.id}` } });
|
|
185
|
+
try {
|
|
186
|
+
send(res, 200, { ok: true, result: await ops.listRfqQueue(p.id ?? "") });
|
|
187
|
+
}
|
|
188
|
+
catch (e) {
|
|
189
|
+
sendError(res, e);
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
// Merchant Ops human_required(§7.6):kiwi.merchant.reviews。
|
|
195
|
+
method: "GET", path: "/merchant/:id/human-review", handler: async (_b, p, res) => {
|
|
196
|
+
const ops = merchantOps?.[p.id ?? ""];
|
|
197
|
+
if (ops === undefined)
|
|
198
|
+
return send(res, 404, { ok: false, error: { code: "merchant_not_found", message: `no ops for ${p.id}` } });
|
|
199
|
+
try {
|
|
200
|
+
send(res, 200, { ok: true, result: await ops.listHumanReview(p.id ?? "") });
|
|
201
|
+
}
|
|
202
|
+
catch (e) {
|
|
203
|
+
sendError(res, e);
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
// Merchant Ops analytics(§7.6):kiwi.merchant.analytics。
|
|
209
|
+
method: "GET", path: "/merchant/:id/analytics", handler: async (_b, p, res) => {
|
|
210
|
+
const ops = merchantOps?.[p.id ?? ""];
|
|
211
|
+
if (ops === undefined)
|
|
212
|
+
return send(res, 404, { ok: false, error: { code: "merchant_not_found", message: `no ops for ${p.id}` } });
|
|
213
|
+
try {
|
|
214
|
+
send(res, 200, { ok: true, result: await ops.analytics(p.id ?? "") });
|
|
215
|
+
}
|
|
216
|
+
catch (e) {
|
|
217
|
+
sendError(res, e);
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
// Merchant Ops 处理 human_required(§7.6):kiwi.merchant.approve。
|
|
223
|
+
method: "POST", path: "/merchant/:id/resolve-review", handler: async (b, p, res) => {
|
|
224
|
+
const ops = merchantOps?.[p.id ?? ""];
|
|
225
|
+
if (ops === undefined)
|
|
226
|
+
return send(res, 404, { ok: false, error: { code: "merchant_not_found", message: `no ops for ${p.id}` } });
|
|
227
|
+
try {
|
|
228
|
+
const result = await ops.resolveReview(p.id ?? "", String(b.conversation_id ?? ""), String(b.decision ?? "approve"));
|
|
229
|
+
send(res, 200, { ok: true, result });
|
|
230
|
+
}
|
|
231
|
+
catch (e) {
|
|
232
|
+
sendError(res, e);
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
// Merchant UCP Profile 发布(§7.1 Protocol Publishing):返回 `/.well-known/ucp`。
|
|
238
|
+
method: "GET", path: "/merchants/:id/ucp", handler: async (_b, p, res) => {
|
|
239
|
+
const mid = p.id ?? "";
|
|
240
|
+
const config = merchantUcp?.[mid];
|
|
241
|
+
if (config === undefined) {
|
|
242
|
+
return send(res, 404, { ok: false, error: { code: "merchant_not_found", message: `no UCP config for ${mid}` } });
|
|
243
|
+
}
|
|
244
|
+
try {
|
|
245
|
+
const profile = buildMerchantUcpProfile({ domain: config.domain, merchantId: mid, catalogEndpoint: config.catalogEndpoint });
|
|
246
|
+
send(res, 200, { ok: true, ucp: profile });
|
|
247
|
+
}
|
|
248
|
+
catch (e) {
|
|
249
|
+
sendError(res, e);
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
method: "POST", path: "/approvals/:id/approve", handler: async (b, p, res) => {
|
|
255
|
+
try {
|
|
256
|
+
service.approveApproval({
|
|
257
|
+
approval_id: p.id ?? "",
|
|
258
|
+
authorization: (b.authorization ?? {}),
|
|
259
|
+
});
|
|
260
|
+
send(res, 200, { ok: true });
|
|
261
|
+
}
|
|
262
|
+
catch (e) {
|
|
263
|
+
sendError(res, e);
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
];
|
|
268
|
+
return createServer(async (req, res) => {
|
|
269
|
+
const url = new URL(req.url ?? "/", `http://${req.headers.host ?? "localhost"}`);
|
|
270
|
+
const segments = url.pathname.split("/").filter(Boolean);
|
|
271
|
+
const method = req.method ?? "GET";
|
|
272
|
+
for (const route of routes) {
|
|
273
|
+
const routeSegments = route.path.split("/").filter(Boolean);
|
|
274
|
+
if (routeSegments.length !== segments.length || route.method !== method)
|
|
275
|
+
continue;
|
|
276
|
+
let match = true;
|
|
277
|
+
const params = {};
|
|
278
|
+
for (let i = 0; i < routeSegments.length; i += 1) {
|
|
279
|
+
const rs = routeSegments[i];
|
|
280
|
+
const ss = segments[i];
|
|
281
|
+
if (rs.startsWith(":"))
|
|
282
|
+
params[rs.slice(1)] = ss;
|
|
283
|
+
else if (rs !== ss) {
|
|
284
|
+
match = false;
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if (!match)
|
|
289
|
+
continue;
|
|
290
|
+
const body = await readJson(req).catch(() => ({}));
|
|
291
|
+
await route.handler(body, params, res);
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
send(res, 404, { ok: false, error: { code: "not_found", message: `${method} ${url.pathname}` } });
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/http/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;GAQG;AAEH,OAAO,EAAE,YAAY,EAAe,MAAM,WAAW,CAAC;AAEtD,OAAO,EAAE,gBAAgB,EAA4B,MAAM,0BAA0B,CAAC;AACtF,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAiBrE,MAAM,UAAU,qBAAqB,CAAC,OAA2B;IAC/D,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAEtD,MAAM,QAAQ,GAAG,CAAC,GAAoB,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+
*
|
|
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
|
+
export declare const KIWI_MCP_VERSION = "0.1.0";
|
|
17
|
+
/** 内置安全默认 DelegationPolicy(§5.3 默认映射)。 */
|
|
18
|
+
export declare const DEFAULT_DELEGATION_POLICY: {
|
|
19
|
+
readonly policy_id: "dp-default";
|
|
20
|
+
readonly version: "1.0";
|
|
21
|
+
readonly principal: "principal:unset";
|
|
22
|
+
readonly expires_at: "2099-12-31T23:59:59Z";
|
|
23
|
+
readonly actions: {
|
|
24
|
+
readonly discover: {
|
|
25
|
+
readonly mode: "auto";
|
|
26
|
+
};
|
|
27
|
+
readonly inquiry_rfq: {
|
|
28
|
+
readonly mode: "auto";
|
|
29
|
+
};
|
|
30
|
+
readonly compare_offers: {
|
|
31
|
+
readonly mode: "auto";
|
|
32
|
+
};
|
|
33
|
+
readonly counter_offer: {
|
|
34
|
+
readonly mode: "auto";
|
|
35
|
+
readonly note: "受限 AUTO:受 limits 约束";
|
|
36
|
+
};
|
|
37
|
+
readonly accept_nonbinding: {
|
|
38
|
+
readonly mode: "ask";
|
|
39
|
+
};
|
|
40
|
+
readonly handoff: {
|
|
41
|
+
readonly mode: "ask";
|
|
42
|
+
};
|
|
43
|
+
readonly payment: {
|
|
44
|
+
readonly mode: "never";
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
readonly limits: {
|
|
48
|
+
readonly max_rounds: 3;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
export interface McpServeOptions {
|
|
52
|
+
db?: string;
|
|
53
|
+
principal?: string;
|
|
54
|
+
buyerAgentId?: string;
|
|
55
|
+
sessionId?: string;
|
|
56
|
+
policy?: Record<string, unknown>;
|
|
57
|
+
catalogUrl?: string;
|
|
58
|
+
marketplaceUrl?: string;
|
|
59
|
+
buyerBootstrapToken?: string;
|
|
60
|
+
}
|
|
61
|
+
export declare function runMcpServe(args: string[]): Promise<number>;
|