@tbox.cn/app-module-mall-core 0.2.1 → 0.3.1

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.
Files changed (71) hide show
  1. package/README.md +12 -3
  2. package/dist/HomeActivityDetailDialog-2GJFYSMZ.less +178 -0
  3. package/dist/MallHome-PABCNS6D.less +623 -0
  4. package/dist/chunk-B7ZAK6VM.js +724 -0
  5. package/dist/chunk-HMQKNJEO.js +1722 -0
  6. package/dist/client/index.d.ts +22 -0
  7. package/dist/client/index.js +8 -0
  8. package/dist/home-slot-WBZ6ONDP.less +4 -0
  9. package/dist/index-ELJ55M66.less +256 -0
  10. package/dist/index-U5YRUY7P.less +352 -0
  11. package/dist/index.d.ts +6 -1
  12. package/dist/index.js +7 -1
  13. package/dist/member-service-icon-SIGSRKE3.svg +1 -0
  14. package/dist/parking-service-icon-3A2TGUUM.svg +1 -0
  15. package/dist/server/index.d.ts +338 -6
  16. package/dist/server/index.js +3 -1
  17. package/dist/welcome-sparkle-transparent-v07-75RL4QUU.png +0 -0
  18. package/package.json +24 -6
  19. package/src/client/HomeActivityDetailDialog.less +178 -0
  20. package/src/client/HomeActivityDetailDialog.tsx +256 -0
  21. package/src/client/MallHome.less +623 -0
  22. package/src/client/MallHome.tsx +667 -0
  23. package/src/client/assets/home/member-service-icon.svg +1 -0
  24. package/src/client/assets/home/parking-service-icon.svg +1 -0
  25. package/src/client/assets/home/welcome-sparkle-transparent-v07.png +0 -0
  26. package/src/client/assets.d.ts +13 -0
  27. package/src/client/cards/mall-home/index.tsx +32 -0
  28. package/src/client/cards/overrides/BumpInActivityChatCard.tsx +81 -0
  29. package/src/client/components/ActivityDetailPresentation/index.less +352 -0
  30. package/src/client/components/ActivityDetailPresentation/index.tsx +31 -0
  31. package/src/client/components/MemberGateSheet/index.less +256 -0
  32. package/src/client/components/MemberGateSheet/index.tsx +211 -0
  33. package/src/client/components/MemberGateSheet/model.ts +42 -0
  34. package/src/client/home-runtime.ts +493 -0
  35. package/src/client/home-slot.less +4 -0
  36. package/src/client/home-slot.tsx +345 -0
  37. package/src/client/index.ts +32 -0
  38. package/src/client/member-gate.ts +337 -0
  39. package/src/client/mock-direct-gate.ts +45 -0
  40. package/src/index.ts +2 -2
  41. package/src/server/assembly.ts +19 -7
  42. package/src/server/cards/mall-home/meta.ts +61 -0
  43. package/src/server/cards/mall-home/schema.ts +73 -0
  44. package/src/server/home-config.ts +36 -0
  45. package/src/server/index.ts +45 -4
  46. package/src/server/linked-panel-member.ts +65 -0
  47. package/src/server/linked-panel-parking.ts +124 -0
  48. package/src/server/module-ports.ts +67 -0
  49. package/src/server/routes.ts +286 -0
  50. package/src/vite-env.d.ts +1 -0
  51. package/tbox.module.json +15 -5
  52. package/tests/BumpInActivityChatCard.test.tsx +214 -0
  53. package/tests/MallHome.test.tsx +481 -0
  54. package/tests/MemberGateSheet-model.test.ts +65 -0
  55. package/tests/MemberGateSheet.test.tsx +173 -0
  56. package/tests/home-config.test.ts +43 -0
  57. package/tests/home-runtime.test.ts +545 -0
  58. package/tests/home-slot.test.tsx +718 -0
  59. package/tests/linked-panel-member.test.ts +78 -0
  60. package/tests/linked-panel-parking-presence.test.ts +117 -0
  61. package/tests/linked-panel-privacy.test.ts +79 -0
  62. package/tests/linked-panel-scope.test.ts +116 -0
  63. package/tests/mall-home-preview.test.tsx +71 -0
  64. package/tests/member-gate.test.ts +384 -0
  65. package/tests/mock-direct-gate.test.ts +136 -0
  66. package/tests/module-ports.test.ts +18 -0
  67. package/tests/route-paths.test.ts +70 -0
  68. package/tests/usePullDownHistory.test.tsx +191 -0
  69. package/tsconfig.json +1 -0
  70. package/tsup.config.ts +22 -1
  71. package/dist/chunk-WSJ2HA5F.js +0 -267
@@ -0,0 +1,191 @@
1
+ // @vitest-environment happy-dom
2
+ /**
3
+ * usePullDownHistory wrapper 冒烟(机器转移表全量回归在 SDK pull-down-machine.test.ts):
4
+ * - 触摸序列驱动状态镜像(idle → pulling → ready → loading → onLoad 完成 idle);
5
+ * - disabled(鉴权/运行时未就绪)三 handler 全短路;
6
+ * - G9:hasMore false→true 跃迁 → 机器复位(noMore 残留死区复活);
7
+ * - wheel 累积越阈触发 onLoad。
8
+ * 事件经合成对象直调 handler(hook 返回值经宿主组件镜像到 DOM 断言)。
9
+ */
10
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
11
+ import { createRoot } from 'react-dom/client';
12
+ import { flushSync } from 'react-dom';
13
+ // W2-3:宿主迁 kit(SDK client 导出退役)
14
+ import { usePullDownHistory } from '@tbox.cn/app-agent-ui-kit';
15
+ import type { UsePullDownHistoryOptions } from '@tbox.cn/app-agent-ui-kit';
16
+
17
+ type Pull = ReturnType<typeof usePullDownHistory>;
18
+ let captured: Pull | null = null;
19
+
20
+ function Host(props: UsePullDownHistoryOptions) {
21
+ const pull = usePullDownHistory(props);
22
+ captured = pull;
23
+ return <div data-test-root data-status={pull.pullStatus} data-distance={String(pull.pullDistance)} />;
24
+ }
25
+
26
+ /** 合成事件直调 handler(happy-dom 无需真实事件系统) */
27
+ const fire = (fn: (e: never) => void, e: unknown) => flushSync(() => fn(e as never));
28
+
29
+ function makeHarness() {
30
+ const container = document.createElement('div');
31
+ document.body.appendChild(container);
32
+ const root = createRoot(container);
33
+ const isAtTopRef = { current: true };
34
+ const render = (props: Partial<UsePullDownHistoryOptions> = {}) => {
35
+ flushSync(() => {
36
+ root.render(
37
+ <Host
38
+ isAtTopRef={isAtTopRef}
39
+ isLoadingHistory={false}
40
+ hasMore={true}
41
+ onLoad={() => Promise.resolve()}
42
+ {...props}
43
+ />,
44
+ );
45
+ });
46
+ };
47
+ const status = () => container.querySelector('[data-test-root]')!.getAttribute('data-status');
48
+ return {
49
+ container,
50
+ isAtTopRef,
51
+ render,
52
+ status,
53
+ teardown: () => {
54
+ flushSync(() => root.render(<div />));
55
+ root.unmount();
56
+ document.body.removeChild(container);
57
+ },
58
+ start: (y: number) => fire(captured!.handleTouchStart, { touches: [{ clientY: y }] }),
59
+ move: (y: number) =>
60
+ fire(captured!.handleTouchMove, { touches: [{ clientY: y }], preventDefault: vi.fn() }),
61
+ end: () => flushSync(() => { captured!.handleTouchEnd(); }),
62
+ cancel: () => flushSync(() => { captured!.handleTouchCancel(); }),
63
+ wheel: (deltaY: number) => fire(captured!.handleWheel, { deltaY }),
64
+ };
65
+ }
66
+
67
+ // 阈值按**内容位移**定义并对齐平台惯例(SDK PULL_TRIGGER_OFFSET=64;iOS UIRefreshControl
68
+ // 实际 60~80pt、Android SwipeRefreshLayout 默认 64dp)。手指行程 = 内容位移 / 阻尼(0.5)。
69
+ const TRIGGER_OFFSET = 64;
70
+ const DAMPING = 0.5;
71
+ const OVER = TRIGGER_OFFSET / DAMPING + 10; // 一次 move 越触发线
72
+ /** 滚轮累积触发线(SDK WHEEL_TRIGGER_ACCUM=128) */
73
+ const WHEEL_ACCUM = 128;
74
+
75
+ describe('usePullDownHistory wrapper(mall 场景)', () => {
76
+ let h: ReturnType<typeof makeHarness>;
77
+ beforeEach(() => {
78
+ h = makeHarness();
79
+ h.render();
80
+ });
81
+ afterEach(() => {
82
+ h.teardown(); // 卸载 root + 移除容器(防跨用例 DOM 堆积与遗留定时器)
83
+ });
84
+
85
+ it('触摸序列:idle → pulling → ready → loading(onLoad pending)→ 完成 idle', async () => {
86
+ let release!: () => void;
87
+ const onLoad = vi.fn(
88
+ () =>
89
+ new Promise<void>((resolve) => {
90
+ release = resolve;
91
+ }),
92
+ );
93
+ h.render({ onLoad });
94
+
95
+ h.start(100);
96
+ h.move(130);
97
+ expect(h.status()).toBe('pulling');
98
+
99
+ h.move(100 + OVER);
100
+ expect(h.status()).toBe('ready');
101
+
102
+ h.end();
103
+ expect(h.status()).toBe('loading');
104
+ expect(onLoad).toHaveBeenCalledTimes(1);
105
+
106
+ release();
107
+ await vi.waitFor(() => expect(h.status()).toBe('idle'));
108
+ });
109
+
110
+ it('disabled(运行时未就绪):touch 全短路(status 恒 idle)', () => {
111
+ h.render({ disabled: true });
112
+ h.start(100);
113
+ h.move(100 + OVER);
114
+ h.end();
115
+ expect(h.status()).toBe('idle');
116
+ });
117
+
118
+ it('touchcancel 只复位手势,不提交已 ready 的加载', () => {
119
+ const onLoad = vi.fn(() => Promise.resolve());
120
+ h.render({ onLoad });
121
+ h.start(100);
122
+ h.move(100 + OVER);
123
+ expect(h.status()).toBe('ready');
124
+
125
+ h.cancel();
126
+ expect(h.status()).toBe('idle');
127
+ expect(onLoad).not.toHaveBeenCalled();
128
+ });
129
+
130
+ it('G9:hasMore false→true 跃迁 → noMore 复位 idle(手势死区复活)', async () => {
131
+ h.render({ hasMore: false });
132
+ h.start(100);
133
+ h.move(100 + OVER);
134
+ expect(h.status()).toBe('noMore');
135
+ h.end();
136
+ expect(h.status()).toBe('noMore');
137
+
138
+ h.render({ hasMore: true }); // 跃迁 → useEffect reset(passive effect 异步)
139
+ await vi.waitFor(() => expect(h.status()).toBe('idle'));
140
+ });
141
+
142
+ it('wheel:顶部向上滚累积越阈触发 onLoad;未越阈不触发', () => {
143
+ const onLoad = vi.fn(() => Promise.resolve());
144
+ h.render({ onLoad });
145
+ const step = WHEEL_ACCUM / 2; // 两步到线不越,第三步越线
146
+ h.wheel(-step);
147
+ h.wheel(-step);
148
+ expect(onLoad).not.toHaveBeenCalled();
149
+ h.wheel(-10);
150
+ expect(onLoad).toHaveBeenCalledTimes(1);
151
+ h.wheel(-step);
152
+ h.wheel(-step);
153
+ expect(onLoad).toHaveBeenCalledTimes(1); // 触发后归零重计
154
+ });
155
+
156
+ it('快扫惯性只触发一次:加载已返回但滚动未停,仍不得二次触发', async () => {
157
+ const onLoad = vi.fn(() => Promise.resolve());
158
+ h.render({ onLoad });
159
+
160
+ // 一次快扫越阈 → 触发
161
+ h.wheel(-(WHEEL_ACCUM + 20));
162
+ expect(onLoad).toHaveBeenCalledTimes(1);
163
+
164
+ // 加载已完成(Promise 立即 resolve),但触控板惯性仍在送 wheel——
165
+ // 惯性可持续一两秒,远长于一次加载,这里是「扫得越猛触发越多次」的回归点
166
+ await vi.waitFor(() => expect(h.status()).toBe('idle'));
167
+ for (let i = 0; i < 6; i += 1) h.wheel(-(WHEEL_ACCUM + 20));
168
+ expect(onLoad).toHaveBeenCalledTimes(1);
169
+
170
+ // 滚动真正停止(静默超过空闲窗)后才解锁,下一次滑动可以再触发
171
+ await new Promise((resolve) => setTimeout(resolve, 300));
172
+ h.wheel(-(WHEEL_ACCUM + 20));
173
+ expect(onLoad).toHaveBeenCalledTimes(2);
174
+ });
175
+
176
+ it('加载未完成时重复 wheel 不会提前复位或重复触发', async () => {
177
+ let release!: () => void;
178
+ const onLoad = vi.fn(() => new Promise<void>((resolve) => { release = resolve; }));
179
+ h.render({ onLoad });
180
+
181
+ h.wheel(-(WHEEL_ACCUM + 20));
182
+ expect(onLoad).toHaveBeenCalledTimes(1);
183
+ // wheel 越阈即进 loading(无「松手」这一刻)——文案与拖拽一致地显示加载中
184
+ expect(h.status()).toBe('loading');
185
+ h.wheel(-(WHEEL_ACCUM + 20));
186
+ expect(onLoad).toHaveBeenCalledTimes(1); // 网络 in-flight 由 hook ref 守卫
187
+
188
+ release();
189
+ await vi.waitFor(() => expect(onLoad).toHaveBeenCalledTimes(1));
190
+ });
191
+ });
package/tsconfig.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "extends": "../../tsconfig.base.json",
3
3
  "compilerOptions": {
4
+ "jsx": "react-jsx",
4
5
  "types": ["node"]
5
6
  },
6
7
  "include": ["src", "tests"]
package/tsup.config.ts CHANGED
@@ -4,6 +4,7 @@ export default defineConfig({
4
4
  entry: {
5
5
  index: 'src/index.ts',
6
6
  'server/index': 'src/server/index.ts',
7
+ 'client/index': 'src/client/index.ts',
7
8
  },
8
9
  format: ['esm'],
9
10
  target: 'node20',
@@ -14,5 +15,25 @@ export default defineConfig({
14
15
  // dts worker 以命令行式传参会撞 TS5074(incremental 需单文件 emit 或 tsBuildInfoFile);
15
16
  // 声明产物一次性构建无需增量——仅 dts 关闭,typecheck 的增量缓存不受影响。
16
17
  dts: { compilerOptions: { incremental: false } },
17
- external: ['@tbox.cn/app-agent-sdk-client', '@tbox.cn/app-agent-sdk-server', '@tbox.cn/app-contracts', '@tbox.cn/app-contracts-mall', 'zod'],
18
+ external: [
19
+ '@tbox.cn/app-agent-sdk-client',
20
+ '@tbox.cn/app-agent-sdk-server',
21
+ '@tbox.cn/app-contracts',
22
+ '@tbox.cn/app-contracts-mall',
23
+ 'react',
24
+ 'react-dom',
25
+ 'zod',
26
+ 'express',
27
+ '@phosphor-icons/react',
28
+ ],
29
+ // 模块自持样式/素材出货链(kit 先例):顶层 loader 写法(esbuildOptions 内设被 tsup 覆盖失效)
30
+ loader: {
31
+ '.less': 'copy',
32
+ '.jpg': 'copy',
33
+ '.png': 'copy',
34
+ '.svg': 'copy',
35
+ },
36
+ esbuildOptions(options) {
37
+ options.jsx = 'automatic';
38
+ },
18
39
  });
@@ -1,267 +0,0 @@
1
- // src/server/index.ts
2
- import { SCOPE_ASSEMBLY_KIND as SCOPE_ASSEMBLY_KIND2 } from "@tbox.cn/app-contracts";
3
- import { MALL_INFO_CACHE_SERVICE } from "@tbox.cn/app-contracts-mall";
4
-
5
- // src/server/assembly.ts
6
- import { createLogger } from "@tbox.cn/app-agent-sdk-server";
7
- import { SCOPE_ASSEMBLY_KIND } from "@tbox.cn/app-contracts";
8
- import {
9
- createMallRuntimeAssembly,
10
- withMallName
11
- } from "@tbox.cn/app-contracts-mall";
12
- import { mallControlPlaneOf } from "@tbox.cn/app-contracts-mall/server";
13
-
14
- // src/server/mall-info-cache.ts
15
- var CACHE_TTL_MS = 30 * 60 * 1e3;
16
- var NEGATIVE_TTL_MS = 5 * 60 * 1e3;
17
- var CACHE_MAX_ENTRIES = 1024;
18
- var MALL_ID_RE = /^[\w-]{1,32}$/;
19
- var cache = /* @__PURE__ */ new Map();
20
- var inFlight = /* @__PURE__ */ new Map();
21
- var ANON_REQUEST = {
22
- identity: { userId: "", source: "anonymous" },
23
- credentials: { provider: "anonymous", token: "" },
24
- attributes: {}
25
- };
26
- function cachedMallName(mallId) {
27
- const entry = cache.get(mallId);
28
- if (!entry || entry.expiresAt <= Date.now()) {
29
- cache.delete(mallId);
30
- return void 0;
31
- }
32
- return entry.negative ? void 0 : entry.mallInfo?.name;
33
- }
34
- async function resolveMallInfoService(mallId, integrations) {
35
- if (!integrations) return null;
36
- try {
37
- const svc = await integrations.resolveService({
38
- service: "mall.info",
39
- scope: { mallId },
40
- request: ANON_REQUEST
41
- });
42
- return svc ?? null;
43
- } catch {
44
- return null;
45
- }
46
- }
47
- async function resolveMallInfo(mallId, integrations) {
48
- if (!MALL_ID_RE.test(mallId)) return void 0;
49
- const entry = cache.get(mallId);
50
- if (entry && entry.expiresAt > Date.now()) {
51
- return entry.negative ? void 0 : entry.mallInfo;
52
- }
53
- if (entry) cache.delete(mallId);
54
- const existing = inFlight.get(mallId);
55
- if (existing) return existing;
56
- const promise = (async () => {
57
- const service = await resolveMallInfoService(mallId, integrations);
58
- if (!service) {
59
- cache.set(mallId, { negative: true, expiresAt: Date.now() + NEGATIVE_TTL_MS });
60
- trimCache();
61
- return void 0;
62
- }
63
- try {
64
- const info = await service.getMallInfo(mallId);
65
- if (!info) {
66
- cache.set(mallId, { negative: true, expiresAt: Date.now() + NEGATIVE_TTL_MS });
67
- } else {
68
- cache.set(mallId, { mallInfo: info, expiresAt: Date.now() + CACHE_TTL_MS });
69
- }
70
- trimCache();
71
- return info;
72
- } catch {
73
- cache.set(mallId, { negative: true, expiresAt: Date.now() + NEGATIVE_TTL_MS });
74
- trimCache();
75
- return void 0;
76
- }
77
- })();
78
- inFlight.set(mallId, promise);
79
- try {
80
- return await promise;
81
- } finally {
82
- inFlight.delete(mallId);
83
- }
84
- }
85
- function trimCache() {
86
- while (cache.size > CACHE_MAX_ENTRIES) {
87
- const firstKey = cache.keys().next().value;
88
- if (firstKey === void 0) break;
89
- cache.delete(firstKey);
90
- }
91
- }
92
-
93
- // src/server/assembly.ts
94
- var deploymentLogger = createLogger("DEPLOYMENT");
95
- var WARM_TIMEOUT_MS = 2e3;
96
- var NO_DECLARATIONS = Object.freeze({});
97
- function resolveMallScopeAssembly(ctx) {
98
- return ctx.domainAssemblies.resolve(SCOPE_ASSEMBLY_KIND);
99
- }
100
- function createScopeAssembly(raw, ctx) {
101
- if (!raw) return void 0;
102
- const rootMiniAppId = typeof raw.config.config?.miniAppId === "string" && raw.config.config.miniAppId ? raw.config.config.miniAppId : void 0;
103
- let projectionRef;
104
- let projection;
105
- const project = () => {
106
- const declared = ctx.integrations?.providerInstanceDeclarations?.() ?? NO_DECLARATIONS;
107
- if (!projection || projectionRef !== declared) {
108
- const controlPlane = mallControlPlaneOf(raw.config, declared);
109
- const runtime = createMallRuntimeAssembly(controlPlane);
110
- projection = {
111
- controlPlane,
112
- runtime,
113
- buildScopeWithMallName: withMallName(runtime, controlPlane, cachedMallName)
114
- };
115
- projectionRef = declared;
116
- }
117
- return projection;
118
- };
119
- return {
120
- // 数据成员 getter:访问期读投影(mall-home routes / mall-directory 闭包自动生效)
121
- get controlPlane() {
122
- return project().controlPlane;
123
- },
124
- rootMiniAppId,
125
- // 函数成员稳定包装(register 期定型——消费方捕获引用恒安全;调用时才读投影)
126
- extractScopeKey: (c) => project().runtime.extractScopeKey(c),
127
- validateScope: (a) => project().runtime.validateScope(a),
128
- extractMallScope: (c) => project().runtime.extractMallScope(c),
129
- buildScope: (a) => project().runtime.buildScope(a),
130
- buildScopeWithMallName: (a) => project().buildScopeWithMallName(a),
131
- instanceIdOf: (scope) => scope["mallId"] ?? "",
132
- get scopeDefaults() {
133
- const defaultMallId = project().controlPlane.defaultMallId;
134
- return defaultMallId ? { defaultMallId } : void 0;
135
- },
136
- defaultMallContext() {
137
- return buildDefaultMallContext(project().controlPlane, rootMiniAppId);
138
- },
139
- async enhanceHelloContext(context) {
140
- const mall = context["mall"];
141
- const mallId = typeof mall?.mallId === "string" && mall.mallId ? mall.mallId : void 0;
142
- if (!mallId) return context;
143
- const nextMall = { ...mall };
144
- if (!nextMall.miniAppId && rootMiniAppId) {
145
- nextMall.miniAppId = rootMiniAppId;
146
- deploymentLogger.warn(`[MALL] HELLO context \u7F3A miniAppId\uFF0C\u6309 root config \u56DE\u586B\uFF08mallId=${mallId}\uFF09`);
147
- }
148
- if (!project().controlPlane.malls.some((m) => m.mallId === mallId)) {
149
- const warm = resolveMallInfo(mallId, ctx.integrations);
150
- await Promise.race([warm, new Promise((r) => setTimeout(r, WARM_TIMEOUT_MS))]).catch(
151
- () => void 0
152
- );
153
- }
154
- return { ...context, mall: nextMall };
155
- }
156
- };
157
- }
158
- function buildDefaultMallContext(controlPlane, rootMiniAppId) {
159
- if (!controlPlane.defaultMallId) return void 0;
160
- const mall = controlPlane.malls.find((m) => m.mallId === controlPlane.defaultMallId);
161
- const miniAppId = rootMiniAppId ?? mall?.miniAppId;
162
- if (!miniAppId) {
163
- deploymentLogger.warn(
164
- `defaultMallId=${controlPlane.defaultMallId} \u65E0 miniAppId \u771F\u6E90\uFF08root config \u4E0E\u53C2\u8003\u8868\u53CC\u7F3A\uFF09\u2014\u2014\u6309 mallId-only \u6CE8\u5165\u9ED8\u8BA4\u5546\u5708`
165
- );
166
- }
167
- return { mall: { mallId: controlPlane.defaultMallId, ...miniAppId ? { miniAppId } : {} } };
168
- }
169
-
170
- // src/server/mall-info-tool.ts
171
- import { createTool } from "@tbox.cn/app-agent-sdk-server";
172
- import { z } from "zod";
173
- var ctxRef;
174
- function bindMallInfoContext(ctx) {
175
- ctxRef = ctx;
176
- }
177
- var mallInfoTool = createTool({
178
- id: "mall-info",
179
- description: "\u67E5\u8BE2\u5546\u573A\u57FA\u672C\u4FE1\u606F\uFF08\u540D\u79F0/\u5730\u5740/\u7ECF\u7EAC\u5EA6\uFF09\u3002\u7528\u6237\u95EE\u67D0\u5546\u573A\u53EB\u4EC0\u4E48\u3001\u5728\u54EA\u513F\u3001\u5730\u5740\u65F6\u8C03\u7528\uFF1B\u5F53\u524D\u4F1A\u8BDD\u5546\u573A ID \u53EF\u4ECE mall-info \u6CE8\u5165\u5757\u53D6\u3002",
180
- // D11 参数规范:纯 string(preTool decide 注入 / 模型直传入参)
181
- inputSchema: z.object({ mallId: z.string().describe("\u5546\u573A ID") }),
182
- // 无 outputSchema:可选字段动态形状(对齐 mall-context;出卡工具建议省略的约定此处同理由)
183
- execute: async (input) => {
184
- const mallId = typeof input.mallId === "string" ? input.mallId.trim() : "";
185
- if (!mallId) return { found: false, reason: "mallId \u7F3A\u5931" };
186
- const info = await resolveMallInfo(mallId, ctxRef?.integrations);
187
- if (!info) {
188
- return {
189
- found: false,
190
- mallId,
191
- reason: "\u5546\u573A\u4FE1\u606F\u4E0D\u53EF\u7528\uFF08mall.info \u69FD\u672A\u88C5\u914D/\u672A\u914D\u7F6E/\u672A\u77E5 mallId\uFF09"
192
- };
193
- }
194
- return {
195
- found: true,
196
- mallId: info.mallId,
197
- name: info.name,
198
- ...info.address ? { address: info.address } : {},
199
- ...info.latitude != null ? { latitude: info.latitude } : {},
200
- ...info.longitude != null ? { longitude: info.longitude } : {},
201
- ...info.cityId ? { cityId: info.cityId } : {}
202
- };
203
- }
204
- });
205
-
206
- // src/server/pre-tools.ts
207
- import { definePreTool } from "@tbox.cn/app-agent-sdk-server";
208
- import { mallSlot } from "@tbox.cn/app-contracts-mall";
209
- var preTools = {
210
- "mall-info": definePreTool(mallInfoTool, {
211
- routing: { mode: "always" },
212
- // 上下文统一化:连接级领域属性经 decide 入参 attributes 判定(与 mall-context 同通道)
213
- decide: ({ attributes }) => {
214
- const scope = mallSlot.read(attributes);
215
- if (!scope) return { decision: "skip", reason: "\u65E0 mall scope\uFF08attributes \u7F3A\u5E2D/\u89E3\u6790\u5931\u8D25\uFF09" };
216
- return { decision: "run", args: { mallId: scope.mallId } };
217
- },
218
- silent: true,
219
- dedup: {
220
- accepts: (result) => result?.found === true
221
- }
222
- })
223
- };
224
-
225
- // src/server/index.ts
226
- var serverModule = {
227
- declaration: {
228
- moduleId: "mall-core"
229
- },
230
- cards: {},
231
- preTools,
232
- register(ctx) {
233
- bindMallInfoContext(ctx);
234
- const assembly = createScopeAssembly(ctx.integrations?.raw, ctx);
235
- if (assembly) {
236
- ctx.domainAssemblies.register(SCOPE_ASSEMBLY_KIND2, assembly);
237
- ctx.services.register("mall-directory", {
238
- nearbyMalls: () => assembly.controlPlane.malls.map((m) => ({
239
- mallId: m.mallId,
240
- name: m.name,
241
- address: `${m.name}\uFF08deployment \u914D\u7F6E\uFF09`,
242
- status: { code: "open", label: "\u8425\u4E1A\u4E2D" }
243
- })),
244
- contactPhone: (mallId) => assembly.controlPlane.malls.find((m) => m.mallId === mallId)?.contactPhone
245
- });
246
- }
247
- ctx.services.register(MALL_INFO_CACHE_SERVICE, {
248
- cachedMallName: (mallId) => cachedMallName(mallId),
249
- resolveMallInfo: (mallId) => resolveMallInfo(mallId, ctx.integrations)
250
- });
251
- ctx.tools.register(mallInfoTool);
252
- }
253
- };
254
- var server_default = serverModule;
255
-
256
- export {
257
- cachedMallName,
258
- resolveMallInfo,
259
- resolveMallScopeAssembly,
260
- createScopeAssembly,
261
- buildDefaultMallContext,
262
- bindMallInfoContext,
263
- mallInfoTool,
264
- preTools,
265
- serverModule,
266
- server_default
267
- };