Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 558c4ef2ee | |||
| 53b0d2c62f | |||
| fdc234e5d0 | |||
| 6542a43495 | |||
| e9ea55cf5e | |||
| 421e204711 | |||
| e9cecf8733 | |||
| dedf8833d3 | |||
| 6b586e0951 |
@@ -72,6 +72,49 @@ export function shouldScheduleMissingActiveRequestGrace({
|
||||
return allowMissingGrace && !agentRunPending;
|
||||
}
|
||||
|
||||
export const QUEUED_CHAT_SUBMIT_NOTICE =
|
||||
'已收到你的消息,将在当前任务完成后自动继续执行。';
|
||||
|
||||
/**
|
||||
* @param {string | undefined | null} chatState
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isChatSubmitBusy(chatState) {
|
||||
return (
|
||||
chatState === 'streaming' ||
|
||||
chatState === 'loading' ||
|
||||
chatState === 'connecting' ||
|
||||
chatState === 'waiting'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number | undefined | null} queueLength
|
||||
* @returns {string}
|
||||
*/
|
||||
export function buildQueuedChatSubmitNotice(queueLength = 1) {
|
||||
const length = Math.max(1, Number(queueLength) || 1);
|
||||
if (length <= 1) return QUEUED_CHAT_SUBMIT_NOTICE;
|
||||
return `已收到你的消息,当前还有 ${length} 条待执行,将在任务完成后按顺序继续。`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {{ chatState?: string; agentRunPending?: boolean; pendingTool?: boolean; queueLength?: number }} input
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function canFlushQueuedChatSubmit({
|
||||
chatState = 'idle',
|
||||
agentRunPending = false,
|
||||
pendingTool = false,
|
||||
queueLength = 0,
|
||||
} = {}) {
|
||||
if (!queueLength || queueLength <= 0) return false;
|
||||
if (isChatSubmitBusy(chatState)) return false;
|
||||
if (agentRunPending) return false;
|
||||
if (pendingTool) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only transport uncertainty may continue a run after submit fails. A
|
||||
* deterministic gateway error already has a terminal outcome and must return
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
buildQueuedChatSubmitNotice,
|
||||
canFlushQueuedChatSubmit,
|
||||
isChatSubmitBusy,
|
||||
reconcileSessionEventRequestContext,
|
||||
resolvePostAgentRunChatState,
|
||||
shouldIgnoreZeroActivityFinish,
|
||||
@@ -145,6 +148,52 @@ test('missing ActiveRequests cannot unlock while the Portal agent-run is pending
|
||||
);
|
||||
});
|
||||
|
||||
test('isChatSubmitBusy covers active composer states', () => {
|
||||
assert.equal(isChatSubmitBusy('idle'), false);
|
||||
assert.equal(isChatSubmitBusy('error'), false);
|
||||
assert.equal(isChatSubmitBusy('waiting'), true);
|
||||
assert.equal(isChatSubmitBusy('streaming'), true);
|
||||
assert.equal(isChatSubmitBusy('connecting'), true);
|
||||
});
|
||||
|
||||
test('buildQueuedChatSubmitNotice reflects queue depth', () => {
|
||||
assert.match(buildQueuedChatSubmitNotice(1), /当前任务完成后/);
|
||||
assert.match(buildQueuedChatSubmitNotice(2), /2 条待执行/);
|
||||
});
|
||||
|
||||
test('canFlushQueuedChatSubmit waits for idle composer without pending tool or run', () => {
|
||||
assert.equal(
|
||||
canFlushQueuedChatSubmit({
|
||||
chatState: 'idle',
|
||||
queueLength: 1,
|
||||
}),
|
||||
true,
|
||||
);
|
||||
assert.equal(
|
||||
canFlushQueuedChatSubmit({
|
||||
chatState: 'waiting',
|
||||
queueLength: 1,
|
||||
}),
|
||||
false,
|
||||
);
|
||||
assert.equal(
|
||||
canFlushQueuedChatSubmit({
|
||||
chatState: 'idle',
|
||||
agentRunPending: true,
|
||||
queueLength: 1,
|
||||
}),
|
||||
false,
|
||||
);
|
||||
assert.equal(
|
||||
canFlushQueuedChatSubmit({
|
||||
chatState: 'idle',
|
||||
pendingTool: true,
|
||||
queueLength: 1,
|
||||
}),
|
||||
false,
|
||||
);
|
||||
});
|
||||
|
||||
test('reconcileSessionEventRequestContext adopts Goose request id while agent-run gate waits', () => {
|
||||
assert.deepEqual(
|
||||
reconcileSessionEventRequestContext({
|
||||
|
||||
@@ -506,3 +506,24 @@ Portal,避免在线修改稳定 `.env`,并确保稳定 8081 与其他用户
|
||||
- **不要** merge、cherry-pick 或从该分支继续开发。
|
||||
- 后续 Analytics 发布以 `docs/analytics-release-runbook.md` 为准。
|
||||
|
||||
## `feature/subscription-usage-records`
|
||||
|
||||
**状态:禁止再次引用。改动已提交并进入 `origin/main`,该分支保留仅用于只读追溯。**
|
||||
|
||||
审计日期:2026-08-12
|
||||
分支 HEAD:`6b586e0`
|
||||
`origin/main` 对应提交:`dedf883`(merge)
|
||||
|
||||
### 原始用途
|
||||
|
||||
订阅额度全额覆盖 token 消耗时,仍写入 usage record,便于审计与对账。
|
||||
|
||||
### 验证摘要
|
||||
|
||||
- `node --test user-auth.test.mjs`:19/19 通过
|
||||
|
||||
### 最终处置
|
||||
|
||||
- 保留本地分支名用于审计追溯。
|
||||
- **不要** merge、cherry-pick 或从该分支继续开发。
|
||||
|
||||
|
||||
@@ -62,6 +62,22 @@ function matchHostRule(hostname, rules = []) {
|
||||
return '';
|
||||
}
|
||||
|
||||
export function classifyReferrerHost(hostname) {
|
||||
const host = normalizeHostname(hostname);
|
||||
if (!host) {
|
||||
return { discovery_channel: 'direct', discovery_source: 'direct' };
|
||||
}
|
||||
const geoSource = matchHostRule(host, GEO_HOST_RULES);
|
||||
if (geoSource) {
|
||||
return { discovery_channel: 'geo', discovery_source: geoSource };
|
||||
}
|
||||
const seoSource = matchHostRule(host, SEO_HOST_RULES);
|
||||
if (seoSource) {
|
||||
return { discovery_channel: 'seo', discovery_source: seoSource };
|
||||
}
|
||||
return { discovery_channel: 'referral', discovery_source: 'other' };
|
||||
}
|
||||
|
||||
function normalizeDiscoveryChannel(value) {
|
||||
const channel = String(value ?? '').trim().toLowerCase();
|
||||
return channel === 'seo' || channel === 'geo' ? channel : '';
|
||||
|
||||
@@ -46,3 +46,34 @@ export async function markPageDeliveryContractReady({ pool, userId, relativePath
|
||||
);
|
||||
return Number(result?.affectedRows ?? 0) > 0;
|
||||
}
|
||||
|
||||
export async function releaseMaterializedPageDeliveryContracts({
|
||||
pool,
|
||||
userId,
|
||||
relativePaths = [],
|
||||
allowPgRequired = false,
|
||||
} = {}) {
|
||||
if (!pool || !userId) return [];
|
||||
const released = [];
|
||||
for (const rawPath of relativePaths) {
|
||||
const workspaceRelativePath = normalizeDeliveryRelativePath(rawPath);
|
||||
if (!workspaceRelativePath) continue;
|
||||
const contract = await getPageDeliveryContract({
|
||||
pool,
|
||||
userId,
|
||||
relativePath: workspaceRelativePath,
|
||||
});
|
||||
if (!contract || contract.status === 'ready') continue;
|
||||
if (contract.data_mode === 'pg_required' && !allowPgRequired) continue;
|
||||
if (
|
||||
await markPageDeliveryContractReady({
|
||||
pool,
|
||||
userId,
|
||||
relativePath: workspaceRelativePath,
|
||||
})
|
||||
) {
|
||||
released.push(workspaceRelativePath);
|
||||
}
|
||||
}
|
||||
return released;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
markPageDeliveryContractReady,
|
||||
normalizeDeliveryRelativePath,
|
||||
preparePageDeliveryContract,
|
||||
releaseMaterializedPageDeliveryContracts,
|
||||
} from './mindspace-delivery-contract.mjs';
|
||||
|
||||
test('normalizes only safe public HTML delivery paths', () => {
|
||||
@@ -40,3 +41,43 @@ test('contract lifecycle writes preparing then ready against the same route key'
|
||||
assert.equal(await markPageDeliveryContractReady({ pool, userId: 'user-1', relativePath: 'public/form.html' }), true);
|
||||
assert.ok(calls.some((call) => call.sql.includes("status = 'ready'")));
|
||||
});
|
||||
|
||||
test('releaseMaterializedPageDeliveryContracts skips pg_required until allowed', async () => {
|
||||
const calls = [];
|
||||
const pool = {
|
||||
async query(sql, params) {
|
||||
calls.push({ sql, params });
|
||||
if (sql.includes('SELECT id, data_mode')) {
|
||||
const path = params?.[1];
|
||||
if (path === 'public/form.html') {
|
||||
return [[{ id: 'c1', data_mode: 'pg_required', status: 'preparing' }]];
|
||||
}
|
||||
if (path === 'public/report.html') {
|
||||
return [[{ id: 'c2', data_mode: 'static', status: 'preparing' }]];
|
||||
}
|
||||
return [[]];
|
||||
}
|
||||
if (sql.includes("status = 'ready'")) return [{ affectedRows: 1 }];
|
||||
return [{ affectedRows: 0 }];
|
||||
},
|
||||
};
|
||||
|
||||
assert.deepEqual(
|
||||
await releaseMaterializedPageDeliveryContracts({
|
||||
pool,
|
||||
userId: 'user-1',
|
||||
relativePaths: ['public/form.html', 'public/report.html'],
|
||||
allowPgRequired: false,
|
||||
}),
|
||||
['public/report.html'],
|
||||
);
|
||||
assert.deepEqual(
|
||||
await releaseMaterializedPageDeliveryContracts({
|
||||
pool,
|
||||
userId: 'user-1',
|
||||
relativePaths: ['public/form.html'],
|
||||
allowPgRequired: true,
|
||||
}),
|
||||
['public/form.html'],
|
||||
);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import { enrichPagesWithAchievementStats } from './mindspace-page-achievement-stats.mjs';
|
||||
|
||||
export const DEFAULT_ACHIEVEMENT_LIMIT = 20;
|
||||
|
||||
export function parseAchievementQuery(query = {}) {
|
||||
const limit = Number.parseInt(String(query.limit ?? ''), 10);
|
||||
const offset = Number.parseInt(String(query.offset ?? ''), 10);
|
||||
const includeStatsRaw = String(query.include_stats ?? '0').trim().toLowerCase();
|
||||
const includeStats = includeStatsRaw === '1' || includeStatsRaw === 'true';
|
||||
|
||||
return {
|
||||
status: typeof query.status === 'string' ? query.status : undefined,
|
||||
categoryCode: typeof query.category_code === 'string' ? query.category_code : undefined,
|
||||
limit: Number.isFinite(limit) ? Math.min(Math.max(limit, 1), 100) : DEFAULT_ACHIEVEMENT_LIMIT,
|
||||
offset: Number.isFinite(offset) ? Math.max(offset, 0) : 0,
|
||||
includeStats,
|
||||
};
|
||||
}
|
||||
|
||||
export async function listAchievementPagesForUser({
|
||||
pages,
|
||||
userId,
|
||||
query = {},
|
||||
pool = null,
|
||||
logger = console,
|
||||
} = {}) {
|
||||
if (!pages || typeof pages.listPages !== 'function') {
|
||||
throw new Error('MindSpace page service unavailable');
|
||||
}
|
||||
|
||||
const parsed = parseAchievementQuery(query);
|
||||
const result = await pages.listPages(userId, {
|
||||
status: parsed.status,
|
||||
categoryCode: parsed.categoryCode,
|
||||
limit: parsed.limit,
|
||||
offset: parsed.offset,
|
||||
});
|
||||
|
||||
const items = await enrichPagesWithAchievementStats(result.items, {
|
||||
ownerUserId: userId,
|
||||
pool,
|
||||
logger,
|
||||
skipUmami: !parsed.includeStats,
|
||||
});
|
||||
|
||||
return {
|
||||
items,
|
||||
total: result.total,
|
||||
limit: result.limit,
|
||||
offset: result.offset,
|
||||
hasMore: Boolean(result.hasMore ?? result.offset + result.items.length < result.total),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
|
||||
import { parseAchievementQuery } from './mindspace-page-achievement-list.mjs';
|
||||
|
||||
test('parseAchievementQuery defaults to fast paginated listing', () => {
|
||||
const parsed = parseAchievementQuery({});
|
||||
assert.equal(parsed.limit, 20);
|
||||
assert.equal(parsed.offset, 0);
|
||||
assert.equal(parsed.includeStats, false);
|
||||
});
|
||||
@@ -0,0 +1,275 @@
|
||||
import crypto from 'node:crypto';
|
||||
|
||||
import {
|
||||
pseudonymizeAnalyticsId,
|
||||
resolveAnalyticsIdentity,
|
||||
resolveMindSpaceAnalyticsConfig,
|
||||
} from './mindspace-analytics.mjs';
|
||||
|
||||
const TOKEN_TTL_MS = 55 * 60 * 1000;
|
||||
let cachedToken = '';
|
||||
let cachedTokenAt = 0;
|
||||
let cachedBaseUrl = '';
|
||||
|
||||
function normalizeBaseUrl(value = '') {
|
||||
return String(value ?? '').trim().replace(/\/$/, '');
|
||||
}
|
||||
|
||||
function resolveUmamiCredentials(env = process.env, analyticsConfig = resolveMindSpaceAnalyticsConfig(env)) {
|
||||
const baseUrl = normalizeBaseUrl(analyticsConfig?.analyticsUrl || env.MEMIND_ANALYTICS_URL || 'http://127.0.0.1:3100');
|
||||
const username = String(env.UMAMI_SSO_USERNAME || env.UMAMI_ADMIN_USERNAME || 'admin').trim();
|
||||
const password = String(env.UMAMI_ADMIN_PASSWORD || '').trim();
|
||||
const sharedSecret = String(env.MEMIND_UMAMI_SSO_SECRET || '').trim();
|
||||
const websiteId = String(analyticsConfig?.websiteId || env.MEMIND_ANALYTICS_WEBSITE_ID || '').trim();
|
||||
return { baseUrl, username, password, sharedSecret, websiteId };
|
||||
}
|
||||
|
||||
async function loginUmamiViaSso({ baseUrl, username, sharedSecret }) {
|
||||
const encoded = Buffer.from(
|
||||
JSON.stringify({
|
||||
username,
|
||||
exp: Math.floor(Date.now() / 1000) + 60,
|
||||
nonce: crypto.randomUUID(),
|
||||
}),
|
||||
).toString('base64url');
|
||||
const signature = crypto.createHmac('sha256', sharedSecret).update(encoded).digest('base64url');
|
||||
const ticket = `${encoded}.${signature}`;
|
||||
const response = await fetch(`${baseUrl}/api/auth/memind?ticket=${encodeURIComponent(ticket)}`, {
|
||||
signal: AbortSignal.timeout(10_000),
|
||||
});
|
||||
const body = await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
throw new Error(body?.error?.message || body?.message || `Umami SSO 登录失败 (${response.status})`);
|
||||
}
|
||||
const token = String(body?.token ?? '').trim();
|
||||
if (!token) throw new Error('Umami SSO 登录响应缺少 token');
|
||||
return token;
|
||||
}
|
||||
|
||||
async function loginUmami(credentials) {
|
||||
if (credentials.sharedSecret) {
|
||||
return loginUmamiViaSso(credentials);
|
||||
}
|
||||
if (!credentials.password) {
|
||||
throw new Error('未配置 Umami 凭据');
|
||||
}
|
||||
const response = await fetch(`${credentials.baseUrl}/api/auth/login`, {
|
||||
method: 'POST',
|
||||
headers: { 'content-type': 'application/json' },
|
||||
body: JSON.stringify({ username: credentials.username, password: credentials.password }),
|
||||
signal: AbortSignal.timeout(10_000),
|
||||
});
|
||||
const body = await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
throw new Error(body?.message || `Umami 登录失败 (${response.status})`);
|
||||
}
|
||||
const token = String(body?.token ?? '').trim();
|
||||
if (!token) throw new Error('Umami 登录响应缺少 token');
|
||||
return token;
|
||||
}
|
||||
|
||||
async function getUmamiAuthToken(credentials) {
|
||||
const now = Date.now();
|
||||
if (cachedToken && cachedBaseUrl === credentials.baseUrl && now - cachedTokenAt < TOKEN_TTL_MS) {
|
||||
return cachedToken;
|
||||
}
|
||||
cachedToken = await loginUmami(credentials);
|
||||
cachedTokenAt = now;
|
||||
cachedBaseUrl = credentials.baseUrl;
|
||||
return cachedToken;
|
||||
}
|
||||
|
||||
function pathnameFromUrl(value) {
|
||||
const raw = String(value ?? '').trim();
|
||||
if (!raw) return '';
|
||||
try {
|
||||
return new URL(raw, 'https://m.tkmind.cn').pathname.replace(/\/$/, '') || '/';
|
||||
} catch {
|
||||
return raw.startsWith('/') ? raw.replace(/\/$/, '') || '/' : '';
|
||||
}
|
||||
}
|
||||
|
||||
function buildPageMatchKeys(page, userId) {
|
||||
const keys = new Set();
|
||||
if (page?.id) keys.add(String(page.id));
|
||||
const workspacePath = String(page?.workspaceRelativePath ?? '').trim().replace(/^\/+/, '');
|
||||
if (workspacePath) {
|
||||
keys.add(`/MindSpace/${userId}/${workspacePath}`.replace(/\/$/, ''));
|
||||
}
|
||||
for (const candidate of [page?.publicationUrl, page?.workspacePublicUrl]) {
|
||||
const pathname = pathnameFromUrl(candidate);
|
||||
if (pathname) keys.add(pathname);
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
export function mergeAchievementStatsForPage(page, umamiByPath, userId) {
|
||||
const publicationViews = Number(page?.viewCount ?? 0);
|
||||
const keys = buildPageMatchKeys(page, userId);
|
||||
let umamiViews = 0;
|
||||
let umamiClicks = 0;
|
||||
let matched = false;
|
||||
for (const key of keys) {
|
||||
const stats = umamiByPath.get(key);
|
||||
if (!stats) continue;
|
||||
matched = true;
|
||||
umamiViews = Math.max(umamiViews, Number(stats.views ?? 0));
|
||||
umamiClicks = Math.max(umamiClicks, Number(stats.clicks ?? 0));
|
||||
}
|
||||
const viewCount = matched ? Math.max(publicationViews, umamiViews) : publicationViews;
|
||||
const clickCount = matched ? umamiClicks : null;
|
||||
let statsSource = 'none';
|
||||
if (matched && (umamiViews > 0 || umamiClicks > 0)) statsSource = 'umami';
|
||||
else if (publicationViews > 0) statsSource = 'publication';
|
||||
return {
|
||||
...page,
|
||||
viewCount,
|
||||
clickCount,
|
||||
statsSource,
|
||||
};
|
||||
}
|
||||
|
||||
export async function fetchUmamiPageStatsByPath({
|
||||
ownerUserId,
|
||||
env = process.env,
|
||||
analyticsConfig = resolveMindSpaceAnalyticsConfig(env),
|
||||
logger = console,
|
||||
} = {}) {
|
||||
if (!analyticsConfig?.enabled || !ownerUserId) return new Map();
|
||||
const credentials = resolveUmamiCredentials(env, analyticsConfig);
|
||||
if (!credentials.websiteId) return new Map();
|
||||
if (!credentials.sharedSecret && !credentials.password) return new Map();
|
||||
|
||||
const ownerIdentity = resolveAnalyticsIdentity(ownerUserId, analyticsConfig);
|
||||
if (!ownerIdentity) return new Map();
|
||||
|
||||
try {
|
||||
const token = await getUmamiAuthToken(credentials);
|
||||
const params = new URLSearchParams();
|
||||
params.set('page', '1');
|
||||
params.set('pageSize', '100');
|
||||
params.set('sortBy', 'generatedAt');
|
||||
params.set('sortOrder', 'desc');
|
||||
const endAt = Date.now();
|
||||
const startAt = endAt - 365 * 24 * 60 * 60 * 1000;
|
||||
params.set('startAt', String(startAt));
|
||||
params.set('endAt', String(endAt));
|
||||
|
||||
const response = await fetch(
|
||||
`${credentials.baseUrl}/api/websites/${encodeURIComponent(credentials.websiteId)}/memind-pages?${params.toString()}`,
|
||||
{
|
||||
headers: {
|
||||
authorization: `Bearer ${token}`,
|
||||
'content-type': 'application/json',
|
||||
},
|
||||
signal: AbortSignal.timeout(15_000),
|
||||
},
|
||||
);
|
||||
const body = await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
throw new Error(body?.message || `Umami memind-pages 请求失败 (${response.status})`);
|
||||
}
|
||||
|
||||
const rows = Array.isArray(body?.data) ? body.data : [];
|
||||
const map = new Map();
|
||||
for (const row of rows) {
|
||||
if (String(row?.ownerId ?? '') !== ownerIdentity) continue;
|
||||
const urlPath = pathnameFromUrl(row?.urlPath);
|
||||
const pageUrlPath = pathnameFromUrl(row?.pageUrl);
|
||||
const stats = {
|
||||
views: Number(row?.views ?? 0),
|
||||
clicks: Number(row?.clicks ?? 0),
|
||||
};
|
||||
if (urlPath) map.set(urlPath, stats);
|
||||
if (pageUrlPath) map.set(pageUrlPath, stats);
|
||||
}
|
||||
return map;
|
||||
} catch (error) {
|
||||
logger?.warn?.(
|
||||
'[MindSpace] Umami achievement stats unavailable:',
|
||||
error instanceof Error ? error.message : error,
|
||||
);
|
||||
return new Map();
|
||||
}
|
||||
}
|
||||
|
||||
export async function loadPublicationStatsByPageIds(pool, userId, pageIds) {
|
||||
if (!pool || !userId || !Array.isArray(pageIds) || pageIds.length === 0) {
|
||||
return new Map();
|
||||
}
|
||||
const ids = [...new Set(pageIds.map((id) => String(id ?? '').trim()).filter(Boolean))];
|
||||
if (ids.length === 0) return new Map();
|
||||
const placeholders = ids.map(() => '?').join(',');
|
||||
const [rows] = await pool.query(
|
||||
`SELECT page_id,
|
||||
SUM(view_count) AS total_view_count,
|
||||
SUBSTRING_INDEX(
|
||||
GROUP_CONCAT(id ORDER BY COALESCE(published_at, 0) DESC, updated_at DESC),
|
||||
',',
|
||||
1
|
||||
) AS latest_publish_id
|
||||
FROM h5_publish_records
|
||||
WHERE user_id = ? AND page_id IN (${placeholders})
|
||||
GROUP BY page_id`,
|
||||
[userId, ...ids],
|
||||
);
|
||||
const map = new Map();
|
||||
for (const row of rows) {
|
||||
map.set(String(row.page_id), {
|
||||
viewCount: Number(row.total_view_count ?? 0),
|
||||
publicationId: row.latest_publish_id ?? null,
|
||||
});
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
function applyPublicationStats(pages, pubStatsByPageId) {
|
||||
if (!pubStatsByPageId?.size) return pages;
|
||||
return pages.map((page) => {
|
||||
const pubStats = pubStatsByPageId.get(String(page?.id ?? ''));
|
||||
if (!pubStats) return page;
|
||||
const existingViews = Number(page?.viewCount ?? 0);
|
||||
const mergedViews = Math.max(existingViews, pubStats.viewCount);
|
||||
if (mergedViews === existingViews && (page?.publicationId || !pubStats.publicationId)) {
|
||||
return page;
|
||||
}
|
||||
return {
|
||||
...page,
|
||||
viewCount: mergedViews,
|
||||
...(page?.publicationId ? {} : pubStats.publicationId ? { publicationId: pubStats.publicationId } : {}),
|
||||
...(mergedViews > 0 && page?.statsSource === 'none' ? { statsSource: 'publication' } : {}),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export async function enrichPagesWithAchievementStats(pages, {
|
||||
ownerUserId,
|
||||
env = process.env,
|
||||
analyticsConfig = resolveMindSpaceAnalyticsConfig(env),
|
||||
pool = null,
|
||||
logger = console,
|
||||
skipUmami = false,
|
||||
} = {}) {
|
||||
const pageIds = pages.map((page) => page?.id).filter(Boolean);
|
||||
const pubStatsByPageId = await loadPublicationStatsByPageIds(pool, ownerUserId, pageIds);
|
||||
const pagesWithPublicationStats = applyPublicationStats(pages, pubStatsByPageId);
|
||||
if (skipUmami) {
|
||||
return pagesWithPublicationStats.map((page) =>
|
||||
mergeAchievementStatsForPage(page, new Map(), ownerUserId),
|
||||
);
|
||||
}
|
||||
const umamiByPath = await fetchUmamiPageStatsByPath({
|
||||
ownerUserId,
|
||||
env,
|
||||
analyticsConfig,
|
||||
logger,
|
||||
});
|
||||
return pagesWithPublicationStats.map((page) => mergeAchievementStatsForPage(page, umamiByPath, ownerUserId));
|
||||
}
|
||||
|
||||
export const achievementStatsInternals = {
|
||||
buildPageMatchKeys,
|
||||
mergeAchievementStatsForPage,
|
||||
pathnameFromUrl,
|
||||
pseudonymizeAnalyticsId,
|
||||
};
|
||||
@@ -0,0 +1,63 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
|
||||
import {
|
||||
achievementStatsInternals,
|
||||
mergeAchievementStatsForPage,
|
||||
} from './mindspace-page-achievement-stats.mjs';
|
||||
|
||||
const { buildPageMatchKeys, mergeAchievementStatsForPage: mergePage, pathnameFromUrl } =
|
||||
achievementStatsInternals;
|
||||
|
||||
test('buildPageMatchKeys includes workspace and publication paths', () => {
|
||||
const keys = buildPageMatchKeys(
|
||||
{
|
||||
id: 'page-1',
|
||||
workspaceRelativePath: 'public/demo.html',
|
||||
publicationUrl: 'https://m.tkmind.cn/u/john/pages/demo',
|
||||
},
|
||||
'user-1',
|
||||
);
|
||||
assert.ok(keys.has('page-1'));
|
||||
assert.ok(keys.has('/MindSpace/user-1/public/demo.html'));
|
||||
assert.ok(keys.has('/u/john/pages/demo'));
|
||||
});
|
||||
|
||||
test('mergeAchievementStatsForPage prefers umami metrics when matched', () => {
|
||||
const umamiByPath = new Map([
|
||||
['/MindSpace/user-1/public/demo.html', { views: 12, clicks: 3 }],
|
||||
]);
|
||||
const merged = mergePage(
|
||||
{
|
||||
id: 'page-1',
|
||||
title: 'Demo',
|
||||
workspaceRelativePath: 'public/demo.html',
|
||||
viewCount: 5,
|
||||
},
|
||||
umamiByPath,
|
||||
'user-1',
|
||||
);
|
||||
assert.equal(merged.viewCount, 12);
|
||||
assert.equal(merged.clickCount, 3);
|
||||
assert.equal(merged.statsSource, 'umami');
|
||||
});
|
||||
|
||||
test('mergeAchievementStatsForPage keeps publication views without umami match', () => {
|
||||
const merged = mergeAchievementStatsForPage(
|
||||
{
|
||||
id: 'page-2',
|
||||
title: 'Draft',
|
||||
viewCount: 7,
|
||||
},
|
||||
new Map(),
|
||||
'user-2',
|
||||
);
|
||||
assert.equal(merged.viewCount, 7);
|
||||
assert.equal(merged.clickCount, null);
|
||||
assert.equal(merged.statsSource, 'publication');
|
||||
});
|
||||
|
||||
test('pathnameFromUrl normalizes absolute and relative urls', () => {
|
||||
assert.equal(pathnameFromUrl('https://m.tkmind.cn/u/john/pages/demo/'), '/u/john/pages/demo');
|
||||
assert.equal(pathnameFromUrl('/MindSpace/u/public/page.html'), '/MindSpace/u/public/page.html');
|
||||
});
|
||||
+73
-8
@@ -135,6 +135,12 @@ function pageResponse(row, { includeContent = true, h5Root = null, env = process
|
||||
status: row.status,
|
||||
visibility: row.visibility,
|
||||
publicationAccessMode: row.pub_access_mode ?? null,
|
||||
publicationId: row.pub_id ?? null,
|
||||
publicationStatus: row.pub_status ?? null,
|
||||
viewCount: asNumber(row.total_view_count ?? row.pub_view_count ?? 0),
|
||||
clickCount: null,
|
||||
statsSource: asNumber(row.total_view_count ?? row.pub_view_count ?? 0) > 0 ? 'publication' : 'none',
|
||||
publishedAt: row.pub_published_at != null ? asNumber(row.pub_published_at) : null,
|
||||
publicationUrl: workspacePublicUrl ?? row.pub_public_url ?? null,
|
||||
workspaceRelativePath: workspaceRelativePath ?? null,
|
||||
workspacePublicUrl,
|
||||
@@ -727,21 +733,42 @@ export function createPageService(pool, options = {}) {
|
||||
clauses.push(`c.category_code = ?`);
|
||||
params.push(filters.categoryCode);
|
||||
}
|
||||
if (Number.isFinite(filters.createdAfter)) {
|
||||
clauses.push(`p.created_at >= ?`);
|
||||
params.push(filters.createdAfter);
|
||||
}
|
||||
if (Number.isFinite(filters.createdBefore)) {
|
||||
clauses.push(`p.created_at < ?`);
|
||||
params.push(filters.createdBefore);
|
||||
}
|
||||
const where = clauses.join(' AND ');
|
||||
const { limit, offset } = normalizeListPageFilters(filters);
|
||||
const queryParams = [userId, ...params];
|
||||
const baseFrom = `FROM h5_page_records p
|
||||
JOIN h5_space_categories c ON c.id = p.category_id AND c.user_id = p.user_id
|
||||
LEFT JOIN h5_page_versions pv ON pv.id = p.current_version_id
|
||||
LEFT JOIN h5_publish_records pr ON pr.id = p.current_publish_id AND pr.status = 'online'`;
|
||||
LEFT JOIN (
|
||||
SELECT page_id,
|
||||
SUM(view_count) AS total_view_count,
|
||||
MAX(published_at) AS last_published_at,
|
||||
SUBSTRING_INDEX(GROUP_CONCAT(id ORDER BY COALESCE(published_at, 0) DESC, updated_at DESC), ',', 1) AS latest_publish_id
|
||||
FROM h5_publish_records
|
||||
WHERE user_id = ?
|
||||
GROUP BY page_id
|
||||
) pub_stats ON pub_stats.page_id = p.id
|
||||
LEFT JOIN h5_publish_records pr ON pr.id = COALESCE(p.current_publish_id, pub_stats.latest_publish_id)`;
|
||||
const [[countRows], [rows]] = await Promise.all([
|
||||
pool.query(`SELECT COUNT(*) AS total ${baseFrom} WHERE ${where}`, params),
|
||||
pool.query(`SELECT COUNT(*) AS total ${baseFrom} WHERE ${where}`, queryParams),
|
||||
pool.query(
|
||||
`SELECT p.*, c.category_code, pv.version_no, pr.access_mode AS pub_access_mode, pr.public_url AS pub_public_url
|
||||
`SELECT p.*, c.category_code, pv.version_no,
|
||||
pr.id AS pub_id, pr.access_mode AS pub_access_mode, pr.public_url AS pub_public_url,
|
||||
pr.view_count AS pub_view_count, pr.published_at AS pub_published_at, pr.status AS pub_status,
|
||||
COALESCE(pub_stats.total_view_count, 0) AS total_view_count
|
||||
${baseFrom}
|
||||
WHERE ${where}
|
||||
ORDER BY p.created_at DESC, p.updated_at DESC
|
||||
LIMIT ? OFFSET ?`,
|
||||
[...params, limit, offset],
|
||||
[...queryParams, limit, offset],
|
||||
),
|
||||
]);
|
||||
const total = asNumber(countRows[0]?.total);
|
||||
@@ -754,6 +781,28 @@ export function createPageService(pool, options = {}) {
|
||||
};
|
||||
};
|
||||
|
||||
const listPageCreatedDateBuckets = async (userId, { limit = 3 } = {}) => {
|
||||
const safeLimit = Math.min(Math.max(Number(limit) || 3, 1), 31);
|
||||
const [rows] = await pool.query(
|
||||
`SELECT DATE(FROM_UNIXTIME(p.created_at / 1000)) AS date_key,
|
||||
MIN(p.created_at) AS min_created_at,
|
||||
MAX(p.created_at) AS max_created_at,
|
||||
COUNT(*) AS page_count
|
||||
FROM h5_page_records p
|
||||
WHERE p.user_id = ? AND p.status <> 'deleted'
|
||||
GROUP BY date_key
|
||||
ORDER BY date_key DESC
|
||||
LIMIT ?`,
|
||||
[userId, safeLimit],
|
||||
);
|
||||
return rows.map((row) => ({
|
||||
dateKey: String(row.date_key),
|
||||
minCreatedAt: asNumber(row.min_created_at),
|
||||
maxCreatedAt: asNumber(row.max_created_at),
|
||||
pageCount: asNumber(row.page_count),
|
||||
}));
|
||||
};
|
||||
|
||||
async function getPage(userId, pageId) {
|
||||
const [rows] = await pool.query(
|
||||
`SELECT p.*, c.category_code, pv.version_no, av.storage_key, pv.source_snapshot_json
|
||||
@@ -1241,13 +1290,27 @@ export function createPageService(pool, options = {}) {
|
||||
|
||||
const deletePage = async (userId, pageId, options = {}) => {
|
||||
const removeFromPlaza = Boolean(options.removeFromPlaza);
|
||||
const page = await getPage(userId, pageId);
|
||||
const [metaRows] = await pool.query(
|
||||
`SELECT p.id, p.title, p.page_type, p.space_id, p.source_asset_id
|
||||
FROM h5_page_records p
|
||||
WHERE p.id = ? AND p.user_id = ? AND p.status <> 'deleted'
|
||||
LIMIT 1`,
|
||||
[pageId, userId],
|
||||
);
|
||||
const pageMeta = metaRows[0];
|
||||
if (!pageMeta) throw pageError('页面不存在', 'page_not_found');
|
||||
|
||||
const pageDetail = await getPage(userId, pageId).catch(() => null);
|
||||
const contentFormat =
|
||||
pageDetail?.contentFormat ?? (pageMeta.page_type === 'html' ? 'html' : 'markdown');
|
||||
const pageContent = pageDetail?.content ?? '';
|
||||
|
||||
let workspaceHtmlRelativePath = null;
|
||||
try {
|
||||
const [rows] = await pool.query(
|
||||
`SELECT pv.source_snapshot_json
|
||||
FROM h5_page_records p
|
||||
JOIN h5_page_versions pv ON pv.id = p.current_version_id
|
||||
LEFT JOIN h5_page_versions pv ON pv.id = p.current_version_id
|
||||
WHERE p.id = ? AND p.user_id = ? AND p.status <> 'deleted'
|
||||
LIMIT 1`,
|
||||
[pageId, userId],
|
||||
@@ -1258,7 +1321,7 @@ export function createPageService(pool, options = {}) {
|
||||
workspaceHtmlRelativePath = null;
|
||||
}
|
||||
const embeddedAssetIds =
|
||||
page.contentFormat === 'html' ? extractAssetIdsFromHtml(page.content ?? '') : [];
|
||||
contentFormat === 'html' ? extractAssetIdsFromHtml(pageContent) : [];
|
||||
|
||||
const conn = await pool.getConnection();
|
||||
let result;
|
||||
@@ -1333,7 +1396,7 @@ export function createPageService(pool, options = {}) {
|
||||
const purgeResult = await purgeWorkspacePageArtifacts({
|
||||
publishDir: workspacePublishDir,
|
||||
htmlRelativePath: workspaceHtmlRelativePath,
|
||||
html: page.content ?? '',
|
||||
html: pageContent,
|
||||
}).catch((error) => {
|
||||
console.warn('[MindSpace] workspace purge failed:', error?.message ?? error);
|
||||
return { removed: [], skipped: [] };
|
||||
@@ -1494,6 +1557,7 @@ export function createPageService(pool, options = {}) {
|
||||
redactPage,
|
||||
createRedactedCopy: redactPage,
|
||||
listPages,
|
||||
listPageCreatedDateBuckets,
|
||||
findPageBySourceAsset,
|
||||
findPageBySourceMessage,
|
||||
findPageByRelativePath,
|
||||
@@ -1602,6 +1666,7 @@ export const pageInternals = {
|
||||
normalizePageInput,
|
||||
normalizeListPageFilters,
|
||||
parseJsonColumn,
|
||||
pageResponse,
|
||||
renderContent,
|
||||
renderPreviewHtml,
|
||||
renderHtmlPreview,
|
||||
|
||||
@@ -88,6 +88,45 @@ test('normalizeListPageFilters clamps limit and offset', () => {
|
||||
});
|
||||
});
|
||||
|
||||
test('pageResponse includes publication metrics when publish row is present', () => {
|
||||
const response = pageInternals.pageResponse(
|
||||
{
|
||||
id: 'page-1',
|
||||
user_id: 'user-1',
|
||||
category_id: 'cat-1',
|
||||
category_code: 'public',
|
||||
source_session_id: null,
|
||||
source_message_id: null,
|
||||
source_asset_id: null,
|
||||
title: '成果页面',
|
||||
summary: '摘要',
|
||||
page_type: 'html',
|
||||
template_id: 'static-html',
|
||||
status: 'published',
|
||||
visibility: 'public',
|
||||
current_version_id: 'ver-1',
|
||||
version_no: 3,
|
||||
pub_access_mode: 'public',
|
||||
pub_public_url: 'https://m.tkmind.cn/u/john/pages/demo',
|
||||
pub_id: 'pub-1',
|
||||
pub_status: 'online',
|
||||
pub_view_count: 128,
|
||||
pub_published_at: 1_700_000_000_000,
|
||||
created_at: 1_699_000_000_000,
|
||||
updated_at: 1_700_100_000_000,
|
||||
},
|
||||
{ includeContent: false },
|
||||
);
|
||||
|
||||
assert.equal(response.publicationId, 'pub-1');
|
||||
assert.equal(response.publicationStatus, 'online');
|
||||
assert.equal(response.viewCount, 128);
|
||||
assert.equal(response.clickCount, null);
|
||||
assert.equal(response.statsSource, 'publication');
|
||||
assert.equal(response.publishedAt, 1_700_000_000_000);
|
||||
assert.equal(response.publicationUrl, 'https://m.tkmind.cn/u/john/pages/demo');
|
||||
});
|
||||
|
||||
test('preview rendering escapes active HTML and emits a restrictive CSP', () => {
|
||||
const html = pageInternals.renderPreviewHtml({
|
||||
title: '<script>alert(1)</script>',
|
||||
@@ -295,3 +334,70 @@ test('getPage falls back to workspace html when storage asset is missing', async
|
||||
assert.equal(page.title, 'Page Demo');
|
||||
assert.match(page.content, /<h1>Body<\/h1>/);
|
||||
});
|
||||
|
||||
test('deletePage succeeds when page content asset chain is incomplete', async () => {
|
||||
const userId = 'user-1';
|
||||
const pageId = 'page-broken';
|
||||
let deletedPage = false;
|
||||
const conn = {
|
||||
async beginTransaction() {},
|
||||
async commit() {},
|
||||
async rollback() {},
|
||||
async release() {},
|
||||
query: async (sql) => {
|
||||
const normalized = String(sql);
|
||||
if (normalized.includes('FOR UPDATE') && normalized.includes('h5_page_records')) {
|
||||
return [[{ id: pageId, space_id: 'space-1', title: 'test', source_asset_id: null }]];
|
||||
}
|
||||
if (normalized.includes('FROM h5_page_versions pv')) {
|
||||
return [[]];
|
||||
}
|
||||
if (normalized.includes('FROM h5_publish_records') && normalized.includes("status = 'online'")) {
|
||||
return [[]];
|
||||
}
|
||||
if (normalized.includes('FROM h5_agent_jobs')) {
|
||||
return [[{ job_count: 0 }]];
|
||||
}
|
||||
if (normalized.includes("SET status = 'deleted'") && normalized.includes('h5_page_records')) {
|
||||
deletedPage = true;
|
||||
return [{ affectedRows: 1 }];
|
||||
}
|
||||
if (normalized.includes('UPDATE h5_agent_jobs')) {
|
||||
return [{ affectedRows: 0 }];
|
||||
}
|
||||
return [[]];
|
||||
},
|
||||
};
|
||||
const pool = {
|
||||
getConnection: async () => conn,
|
||||
query: async (sql) => {
|
||||
const normalized = String(sql);
|
||||
if (
|
||||
normalized.includes('FROM h5_page_records p') &&
|
||||
normalized.includes('page_type')
|
||||
) {
|
||||
return [[{
|
||||
id: pageId,
|
||||
title: 'test',
|
||||
page_type: 'markdown',
|
||||
space_id: 'space-1',
|
||||
source_asset_id: null,
|
||||
}]];
|
||||
}
|
||||
if (normalized.includes('JOIN h5_asset_versions')) {
|
||||
return [[]];
|
||||
}
|
||||
if (normalized.includes('source_snapshot_json')) {
|
||||
return [[{ source_snapshot_json: null }]];
|
||||
}
|
||||
return [[]];
|
||||
},
|
||||
};
|
||||
|
||||
const pageService = createPageService(pool, { storageRoot: '/tmp/unused', h5Root: null });
|
||||
const result = await pageService.deletePage(userId, pageId);
|
||||
assert.equal(result.deleted, true);
|
||||
assert.equal(result.pageId, pageId);
|
||||
assert.equal(result.title, 'test');
|
||||
assert.equal(deletedPage, true);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,243 @@
|
||||
import { classifyReferrerHost } from './mindspace-analytics-discovery.mjs';
|
||||
import { isPublicationIndexable, normalizePublicationSnapshot } from './mindspace-index-policy.mjs';
|
||||
|
||||
const DEFAULT_PUBLIC_HOST = 'm.tkmind.cn';
|
||||
const SORT_COLUMNS = new Set([
|
||||
'publishedAt',
|
||||
'pageTitle',
|
||||
'ownerLabel',
|
||||
'totalViews',
|
||||
'seoViews',
|
||||
'geoViews',
|
||||
'crawlerViews',
|
||||
'lifetimeViewCount',
|
||||
]);
|
||||
|
||||
function asPositiveInt(value, fallback) {
|
||||
const parsed = Number(value);
|
||||
if (!Number.isFinite(parsed) || parsed < 1) return fallback;
|
||||
return Math.floor(parsed);
|
||||
}
|
||||
|
||||
function normalizeSortBy(value, fallback = 'publishedAt') {
|
||||
const sortBy = String(value ?? '').trim();
|
||||
return SORT_COLUMNS.has(sortBy) ? sortBy : fallback;
|
||||
}
|
||||
|
||||
function normalizeSortOrder(value, fallback = 'desc') {
|
||||
return String(value ?? '').trim().toLowerCase() === 'asc' ? 'asc' : fallback;
|
||||
}
|
||||
|
||||
export function resolveAdminCatalogPublicUrl(publicUrl, { publicHost = DEFAULT_PUBLIC_HOST } = {}) {
|
||||
const raw = String(publicUrl ?? '').trim();
|
||||
if (!raw) return '';
|
||||
if (/^https?:\/\//i.test(raw)) return raw.split('#')[0];
|
||||
if (raw.startsWith('/')) return `https://${publicHost}${raw}`.split('#')[0];
|
||||
return raw.split('#')[0];
|
||||
}
|
||||
|
||||
function compareRows(a, b, sortBy, sortOrder) {
|
||||
const direction = sortOrder === 'asc' ? 1 : -1;
|
||||
const left = a[sortBy];
|
||||
const right = b[sortBy];
|
||||
if (typeof left === 'string' || typeof right === 'string') {
|
||||
return String(left ?? '').localeCompare(String(right ?? ''), 'zh-CN') * direction;
|
||||
}
|
||||
return ((Number(left) || 0) - (Number(right) || 0)) * direction;
|
||||
}
|
||||
|
||||
function aggregateViewStats(rows = []) {
|
||||
const stats = {
|
||||
totalViews: 0,
|
||||
seoViews: 0,
|
||||
geoViews: 0,
|
||||
crawlerViews: 0,
|
||||
};
|
||||
for (const row of rows) {
|
||||
const views = Number(row.views) || 0;
|
||||
if (views <= 0) continue;
|
||||
stats.totalViews += views;
|
||||
if (String(row.device_type ?? '') === 'bot') {
|
||||
stats.crawlerViews += views;
|
||||
continue;
|
||||
}
|
||||
const discovery = classifyReferrerHost(row.referrer_host);
|
||||
if (discovery.discovery_channel === 'seo') stats.seoViews += views;
|
||||
if (discovery.discovery_channel === 'geo') stats.geoViews += views;
|
||||
}
|
||||
return stats;
|
||||
}
|
||||
|
||||
export async function listAdminSeoGeoPublicationCatalog(
|
||||
pool,
|
||||
{
|
||||
page = 1,
|
||||
pageSize = 20,
|
||||
sortBy = 'publishedAt',
|
||||
sortOrder = 'desc',
|
||||
startAt = null,
|
||||
endAt = null,
|
||||
search = '',
|
||||
publicHost = DEFAULT_PUBLIC_HOST,
|
||||
now = Date.now(),
|
||||
} = {},
|
||||
) {
|
||||
if (!pool) {
|
||||
return { data: [], total: 0, page: 1, pageSize: 20, totals: emptyTotals() };
|
||||
}
|
||||
|
||||
const safePage = asPositiveInt(page, 1);
|
||||
const safePageSize = Math.min(asPositiveInt(pageSize, 20), 100);
|
||||
const normalizedSortBy = normalizeSortBy(sortBy);
|
||||
const normalizedSortOrder = normalizeSortOrder(sortOrder);
|
||||
const searchTerm = String(search ?? '').trim();
|
||||
const rangeStart = Number(startAt);
|
||||
const rangeEnd = Number(endAt);
|
||||
const hasRange = Number.isFinite(rangeStart) && Number.isFinite(rangeEnd) && rangeEnd >= rangeStart;
|
||||
|
||||
const params = [];
|
||||
let whereSql = `WHERE pr.status = 'online'`;
|
||||
if (searchTerm) {
|
||||
whereSql += ` AND (
|
||||
p.title LIKE ?
|
||||
OR u.username LIKE ?
|
||||
OR u.display_name LIKE ?
|
||||
OR pr.public_url LIKE ?
|
||||
)`;
|
||||
const like = `%${searchTerm}%`;
|
||||
params.push(like, like, like, like);
|
||||
}
|
||||
|
||||
const [countRows] = await pool.query(
|
||||
`SELECT COUNT(*) AS total
|
||||
FROM h5_publish_records pr
|
||||
JOIN h5_page_records p ON p.id = pr.page_id
|
||||
JOIN h5_users u ON u.id = pr.user_id
|
||||
${whereSql}`,
|
||||
params,
|
||||
);
|
||||
const total = Number(countRows[0]?.total ?? 0);
|
||||
|
||||
const [publicationRows] = await pool.query(
|
||||
`SELECT
|
||||
pr.id AS publicationId,
|
||||
pr.page_id AS pageId,
|
||||
pr.user_id AS userId,
|
||||
pr.public_url AS publicUrl,
|
||||
pr.access_mode AS accessMode,
|
||||
pr.status,
|
||||
pr.user_confirmed_at AS userConfirmedAt,
|
||||
pr.expires_at AS expiresAt,
|
||||
pr.published_at AS publishedAt,
|
||||
pr.view_count AS lifetimeViewCount,
|
||||
p.title AS pageTitle,
|
||||
p.summary AS pageSummary,
|
||||
u.username,
|
||||
u.display_name AS displayName
|
||||
FROM h5_publish_records pr
|
||||
JOIN h5_page_records p ON p.id = pr.page_id
|
||||
JOIN h5_users u ON u.id = pr.user_id
|
||||
${whereSql}`,
|
||||
params,
|
||||
);
|
||||
|
||||
const publicationIds = publicationRows.map((row) => row.publicationId);
|
||||
const statsByPublication = new Map();
|
||||
if (publicationIds.length > 0 && hasRange) {
|
||||
const placeholders = publicationIds.map(() => '?').join(', ');
|
||||
const [viewRows] = await pool.query(
|
||||
`SELECT publish_id AS publicationId,
|
||||
device_type,
|
||||
referrer_host,
|
||||
COUNT(*) AS views
|
||||
FROM h5_publication_views
|
||||
WHERE publish_id IN (${placeholders})
|
||||
AND viewed_at >= ?
|
||||
AND viewed_at <= ?
|
||||
GROUP BY publish_id, device_type, referrer_host`,
|
||||
[...publicationIds, rangeStart, rangeEnd],
|
||||
);
|
||||
for (const row of viewRows) {
|
||||
const key = String(row.publicationId);
|
||||
const bucket = statsByPublication.get(key) ?? [];
|
||||
bucket.push(row);
|
||||
statsByPublication.set(key, bucket);
|
||||
}
|
||||
}
|
||||
|
||||
const rows = publicationRows.map((row) => {
|
||||
const publication = normalizePublicationSnapshot({
|
||||
id: row.publicationId,
|
||||
pageId: row.pageId,
|
||||
publicUrl: row.publicUrl,
|
||||
accessMode: row.accessMode,
|
||||
status: row.status,
|
||||
userConfirmedAt: row.userConfirmedAt,
|
||||
expiresAt: row.expiresAt,
|
||||
title: row.pageTitle,
|
||||
summary: row.pageSummary,
|
||||
});
|
||||
const stats = hasRange
|
||||
? aggregateViewStats(statsByPublication.get(String(row.publicationId)) ?? [])
|
||||
: {
|
||||
totalViews: 0,
|
||||
seoViews: 0,
|
||||
geoViews: 0,
|
||||
crawlerViews: 0,
|
||||
};
|
||||
const ownerLabel =
|
||||
String(row.displayName ?? '').trim() ||
|
||||
String(row.username ?? '').trim() ||
|
||||
'未命名用户';
|
||||
return {
|
||||
publicationId: row.publicationId,
|
||||
pageId: row.pageId,
|
||||
userId: row.userId,
|
||||
ownerLabel,
|
||||
username: String(row.username ?? '').trim(),
|
||||
pageTitle: String(row.pageTitle ?? '').trim() || '未命名页面',
|
||||
pageSummary: String(row.pageSummary ?? '').trim(),
|
||||
publicUrl: resolveAdminCatalogPublicUrl(row.publicUrl, { publicHost }),
|
||||
accessMode: row.accessMode,
|
||||
indexable: isPublicationIndexable(publication, { now }),
|
||||
publishedAt: Number(row.publishedAt) || null,
|
||||
lifetimeViewCount: Number(row.lifetimeViewCount) || 0,
|
||||
...stats,
|
||||
};
|
||||
});
|
||||
|
||||
rows.sort((a, b) => {
|
||||
const primary = compareRows(a, b, normalizedSortBy, normalizedSortOrder);
|
||||
if (primary !== 0) return primary;
|
||||
return compareRows(a, b, 'pageTitle', 'asc');
|
||||
});
|
||||
|
||||
const offset = (safePage - 1) * safePageSize;
|
||||
const pageRows = rows.slice(offset, offset + safePageSize);
|
||||
const totals = rows.reduce(
|
||||
(acc, row) => ({
|
||||
totalViews: acc.totalViews + row.totalViews,
|
||||
seoViews: acc.seoViews + row.seoViews,
|
||||
geoViews: acc.geoViews + row.geoViews,
|
||||
crawlerViews: acc.crawlerViews + row.crawlerViews,
|
||||
}),
|
||||
emptyTotals(),
|
||||
);
|
||||
|
||||
return {
|
||||
data: pageRows,
|
||||
total,
|
||||
page: safePage,
|
||||
pageSize: safePageSize,
|
||||
totals,
|
||||
};
|
||||
}
|
||||
|
||||
function emptyTotals() {
|
||||
return {
|
||||
totalViews: 0,
|
||||
seoViews: 0,
|
||||
geoViews: 0,
|
||||
crawlerViews: 0,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
|
||||
import { classifyReferrerHost } from './mindspace-analytics-discovery.mjs';
|
||||
import {
|
||||
listAdminSeoGeoPublicationCatalog,
|
||||
resolveAdminCatalogPublicUrl,
|
||||
} from './mindspace-seo-geo-admin-catalog.mjs';
|
||||
|
||||
test('classifyReferrerHost maps search and ai referrers', () => {
|
||||
assert.deepEqual(classifyReferrerHost('www.google.com'), {
|
||||
discovery_channel: 'seo',
|
||||
discovery_source: 'google',
|
||||
});
|
||||
assert.deepEqual(classifyReferrerHost('chatgpt.com'), {
|
||||
discovery_channel: 'geo',
|
||||
discovery_source: 'chatgpt',
|
||||
});
|
||||
});
|
||||
|
||||
test('resolveAdminCatalogPublicUrl normalizes relative public urls', () => {
|
||||
assert.equal(
|
||||
resolveAdminCatalogPublicUrl('/u/john/pages/demo'),
|
||||
'https://m.tkmind.cn/u/john/pages/demo',
|
||||
);
|
||||
});
|
||||
|
||||
test('listAdminSeoGeoPublicationCatalog merges zero-traffic pages with view stats', async () => {
|
||||
const calls = [];
|
||||
const pool = {
|
||||
async query(sql, params = []) {
|
||||
calls.push({ sql, params });
|
||||
const normalized = String(sql).replace(/\s+/g, ' ').trim();
|
||||
if (normalized.startsWith('SELECT COUNT(*) AS total')) {
|
||||
return [[{ total: 2 }]];
|
||||
}
|
||||
if (normalized.includes('FROM h5_publish_records pr') && normalized.includes('JOIN h5_users')) {
|
||||
return [[
|
||||
{
|
||||
publicationId: 'pub-1',
|
||||
pageId: 'page-1',
|
||||
userId: 'user-1',
|
||||
publicUrl: '/u/john/pages/demo',
|
||||
accessMode: 'public',
|
||||
status: 'online',
|
||||
userConfirmedAt: 1000,
|
||||
expiresAt: null,
|
||||
publishedAt: 2000,
|
||||
lifetimeViewCount: 12,
|
||||
pageTitle: 'Demo',
|
||||
pageSummary: 'Summary',
|
||||
username: 'john',
|
||||
displayName: 'John',
|
||||
},
|
||||
{
|
||||
publicationId: 'pub-2',
|
||||
pageId: 'page-2',
|
||||
userId: 'user-2',
|
||||
publicUrl: '/u/jane/pages/empty',
|
||||
accessMode: 'public',
|
||||
status: 'online',
|
||||
userConfirmedAt: null,
|
||||
expiresAt: null,
|
||||
publishedAt: 1500,
|
||||
lifetimeViewCount: 0,
|
||||
pageTitle: 'Empty',
|
||||
pageSummary: '',
|
||||
username: 'jane',
|
||||
displayName: 'Jane',
|
||||
},
|
||||
]];
|
||||
}
|
||||
if (normalized.includes('FROM h5_publication_views')) {
|
||||
return [[
|
||||
{
|
||||
publicationId: 'pub-1',
|
||||
device_type: 'desktop',
|
||||
referrer_host: 'www.google.com',
|
||||
views: 3,
|
||||
},
|
||||
{
|
||||
publicationId: 'pub-1',
|
||||
device_type: 'bot',
|
||||
referrer_host: null,
|
||||
views: 2,
|
||||
},
|
||||
]];
|
||||
}
|
||||
return [[]];
|
||||
},
|
||||
};
|
||||
|
||||
const result = await listAdminSeoGeoPublicationCatalog(pool, {
|
||||
page: 1,
|
||||
pageSize: 10,
|
||||
startAt: 1,
|
||||
endAt: 9_999_999_999_999,
|
||||
sortBy: 'totalViews',
|
||||
sortOrder: 'desc',
|
||||
});
|
||||
|
||||
assert.equal(result.total, 2);
|
||||
assert.equal(result.data.length, 2);
|
||||
assert.equal(result.data[0].publicationId, 'pub-1');
|
||||
assert.equal(result.data[0].seoViews, 3);
|
||||
assert.equal(result.data[0].crawlerViews, 2);
|
||||
assert.equal(result.data[0].totalViews, 5);
|
||||
assert.equal(result.data[0].indexable, true);
|
||||
assert.equal(result.data[1].publicationId, 'pub-2');
|
||||
assert.equal(result.data[1].totalViews, 0);
|
||||
assert.equal(result.data[1].indexable, false);
|
||||
assert.match(result.data[1].publicUrl, /^https:\/\/m\.tkmind\.cn\//);
|
||||
});
|
||||
@@ -81,6 +81,7 @@ export const MINDSPACE_SERVER_ADAPTER_BINDINGS = Object.freeze({
|
||||
'getDeletePreview',
|
||||
'getPage',
|
||||
'listPages',
|
||||
'listPageCreatedDateBuckets',
|
||||
'listVersions',
|
||||
'localizePrivateResources',
|
||||
'redactPage',
|
||||
|
||||
@@ -47,7 +47,7 @@ if [[ -n "${EXPLICIT_H5_USERS_ROOT}" ]]; then
|
||||
fi
|
||||
|
||||
export NODE_ENV=production
|
||||
export MINDSPACE_MEMIND_ROOT="${MINDSPACE_MEMIND_ROOT:-${ROOT}/memind-source}"
|
||||
export MINDSPACE_MEMIND_ROOT="${MINDSPACE_MEMIND_ROOT:-${MEMIND_ROOT}}"
|
||||
export MINDSPACE_SERVICE_H5_ROOT="${MINDSPACE_SERVICE_H5_ROOT:-${MEMIND_ROOT}}"
|
||||
export MINDSPACE_STORAGE_ROOT="${MINDSPACE_STORAGE_ROOT:-${ROOT}/data/mindspace}"
|
||||
export H5_USERS_ROOT="${H5_USERS_ROOT:-${ROOT}/users}"
|
||||
|
||||
@@ -21,6 +21,7 @@ export const REQUIRED_PORTAL_RUNTIME_PATHS = Object.freeze([
|
||||
'scripts/goosed-canary.compose.yml',
|
||||
'scripts/check-mindspace-public-links.mjs',
|
||||
'scripts/load-env.mjs',
|
||||
'scripts/memind-runtime-profile.mjs',
|
||||
'scripts/wechat-mp-menu.mjs',
|
||||
'scripts/memind-portal-tunnel.sh',
|
||||
]);
|
||||
|
||||
+16
-16
@@ -1,7 +1,7 @@
|
||||
import crypto from 'node:crypto';
|
||||
import path from 'node:path';
|
||||
import { buildChatSkillPrompt, SCHEDULED_TASK_AUTOMATION_SKILL_NAME } from './chat-skills.mjs';
|
||||
import { markPageDeliveryContractReady } from './mindspace-delivery-contract.mjs';
|
||||
import { releaseMaterializedPageDeliveryContracts } from './mindspace-delivery-contract.mjs';
|
||||
import {
|
||||
collectOwnPublicHtmlRelativePaths,
|
||||
materializeMissingPublicHtmlWrites,
|
||||
@@ -126,29 +126,29 @@ export async function finalizeScheduledTaskPageDelivery({
|
||||
const [rows] = await pool.query(
|
||||
`SELECT workspace_relative_path
|
||||
FROM h5_page_delivery_contracts
|
||||
WHERE user_id = ? AND request_id = ? AND status = 'preparing'`,
|
||||
[userId, sessionId],
|
||||
WHERE user_id = ? AND status = 'preparing'`,
|
||||
[userId],
|
||||
);
|
||||
for (const row of rows ?? []) {
|
||||
if (row?.workspace_relative_path) relativePaths.add(row.workspace_relative_path);
|
||||
}
|
||||
}
|
||||
|
||||
const readyPaths = [];
|
||||
for (const relativePath of relativePaths) {
|
||||
const ready = await markPageDeliveryContractReady({
|
||||
pool,
|
||||
const readyPaths = await releaseMaterializedPageDeliveryContracts({
|
||||
pool,
|
||||
userId,
|
||||
relativePaths: [...relativePaths],
|
||||
allowPgRequired: true,
|
||||
}).catch((error) => {
|
||||
logger.warn?.('[ScheduledTask] release delivery contracts failed:', error);
|
||||
return [];
|
||||
});
|
||||
for (const relativePath of readyPaths) {
|
||||
logger.info?.('[ScheduledTask] delivery contract ready', {
|
||||
userId,
|
||||
sessionId,
|
||||
relativePath,
|
||||
}).catch(() => false);
|
||||
if (ready) readyPaths.push(relativePath);
|
||||
else {
|
||||
logger.warn?.('[ScheduledTask] delivery contract not ready', {
|
||||
userId,
|
||||
sessionId,
|
||||
relativePath,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
return readyPaths;
|
||||
}
|
||||
|
||||
@@ -447,6 +447,10 @@ async function writeMetadata() {
|
||||
path.join(root, 'scripts', 'load-env.mjs'),
|
||||
path.join(runtimeRoot, 'scripts', 'load-env.mjs'),
|
||||
);
|
||||
await fs.copyFile(
|
||||
path.join(root, 'scripts', 'memind-runtime-profile.mjs'),
|
||||
path.join(runtimeRoot, 'scripts', 'memind-runtime-profile.mjs'),
|
||||
);
|
||||
await fs.copyFile(
|
||||
path.join(root, 'scripts', 'wechat-mp-menu.mjs'),
|
||||
path.join(runtimeRoot, 'scripts', 'wechat-mp-menu.mjs'),
|
||||
|
||||
@@ -92,7 +92,7 @@ fi
|
||||
|
||||
verify_runtime_artifact() {
|
||||
local missing=0
|
||||
for required in server.mjs mindspace-sandbox-mcp.mjs tkmind-excel-mcp.mjs dist package.json scripts/run-memind-portal-prod.sh scripts/load-env.mjs scripts/wechat-mp-menu.mjs; do
|
||||
for required in server.mjs mindspace-sandbox-mcp.mjs tkmind-excel-mcp.mjs dist package.json scripts/run-memind-portal-prod.sh scripts/load-env.mjs scripts/memind-runtime-profile.mjs scripts/wechat-mp-menu.mjs; do
|
||||
if [[ ! -e "${RUNTIME_ROOT}/${required}" ]]; then
|
||||
echo "runtime 产物缺失: ${RUNTIME_ROOT}/${required}" >&2
|
||||
missing=1
|
||||
|
||||
@@ -177,7 +177,7 @@ fi
|
||||
|
||||
verify_runtime_artifact() {
|
||||
local missing=0
|
||||
for required in server.mjs memind-canary-proxy.mjs deepseek-no-think-proxy.mjs wechat-mp.bundle.mjs mindspace-sandbox-mcp.mjs tkmind-search-mcp.mjs tkmind-excel-mcp.mjs mindspace-public-links.mjs dist package.json scripts/run-memind-portal-prod.sh scripts/run-memind-portal-candidate.sh scripts/run-memind-canary-proxy-prod.sh scripts/run-deepseek-compat-proxy-candidate.sh scripts/goosed-canary.compose.yml scripts/check-mindspace-public-links.mjs scripts/load-env.mjs scripts/wechat-mp-menu.mjs scripts/memind-portal-tunnel.sh; do
|
||||
for required in server.mjs memind-canary-proxy.mjs deepseek-no-think-proxy.mjs wechat-mp.bundle.mjs mindspace-sandbox-mcp.mjs tkmind-search-mcp.mjs tkmind-excel-mcp.mjs mindspace-public-links.mjs dist package.json scripts/run-memind-portal-prod.sh scripts/run-memind-portal-candidate.sh scripts/run-memind-canary-proxy-prod.sh scripts/run-deepseek-compat-proxy-candidate.sh scripts/goosed-canary.compose.yml scripts/check-mindspace-public-links.mjs scripts/load-env.mjs scripts/memind-runtime-profile.mjs scripts/wechat-mp-menu.mjs scripts/memind-portal-tunnel.sh; do
|
||||
if [[ ! -e "${RUNTIME_ROOT}/${required}" ]]; then
|
||||
echo "runtime 产物缺失: ${RUNTIME_ROOT}/${required}" >&2
|
||||
missing=1
|
||||
|
||||
@@ -22,13 +22,23 @@ const MENU = {
|
||||
button: [
|
||||
{
|
||||
type: 'view',
|
||||
name: 'TKMind',
|
||||
name: 'Memind',
|
||||
url: 'https://m.tkmind.cn',
|
||||
},
|
||||
{
|
||||
type: 'view',
|
||||
name: 'M空间',
|
||||
url: 'https://m.tkmind.cn/space',
|
||||
sub_button: [
|
||||
{
|
||||
type: 'view',
|
||||
name: '空间首页',
|
||||
url: 'https://m.tkmind.cn/space',
|
||||
},
|
||||
{
|
||||
type: 'view',
|
||||
name: 'M成果',
|
||||
url: 'https://m.tkmind.cn/space/achievements',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'view',
|
||||
|
||||
@@ -1334,6 +1334,7 @@ attachPortalMindSpacePageCoreRoutes(api, {
|
||||
getMindSpacePageLiveEdit: () => mindSpacePageLiveEdit,
|
||||
getMindSpacePageEditSession: () => mindSpacePageEditSession,
|
||||
getUserAuth: () => userAuth,
|
||||
getAuthPool: () => authPool,
|
||||
syncUserGeneratedPages,
|
||||
ownsAgentSession,
|
||||
ensureMindSpaceEnabled,
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { listAchievementPagesForUser } from '../mindspace-page-achievement-list.mjs';
|
||||
|
||||
function assertRouter(api) {
|
||||
if (
|
||||
!api ||
|
||||
@@ -72,6 +74,7 @@ export function attachPortalMindSpacePageCoreRoutes(
|
||||
getMindSpacePageLiveEdit = () => null,
|
||||
getMindSpacePageEditSession = () => null,
|
||||
getUserAuth = () => null,
|
||||
getAuthPool = () => null,
|
||||
syncUserGeneratedPages,
|
||||
ownsAgentSession,
|
||||
ensureMindSpaceEnabled,
|
||||
@@ -161,6 +164,35 @@ export function attachPortalMindSpacePageCoreRoutes(
|
||||
}
|
||||
});
|
||||
|
||||
api.get('/mindspace/v1/pages/achievements', async (req, res) => {
|
||||
const pages = getMindSpacePages();
|
||||
if (!pages) {
|
||||
return res.status(503).json({ message: 'MindSpace 未启用' });
|
||||
}
|
||||
try {
|
||||
schedulePageListSync(req.currentUser.id);
|
||||
const result = await listAchievementPagesForUser({
|
||||
pages,
|
||||
userId: req.currentUser.id,
|
||||
query: req.query,
|
||||
pool: getAuthPool?.() ?? null,
|
||||
logger,
|
||||
});
|
||||
return res.json({
|
||||
data: result.items,
|
||||
page: {
|
||||
total: result.total,
|
||||
limit: result.limit,
|
||||
offset: result.offset,
|
||||
has_more: result.hasMore,
|
||||
next_cursor: null,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
return handleMindSpaceError(res, req, error);
|
||||
}
|
||||
});
|
||||
|
||||
api.get('/mindspace/v1/pages/:pageId', async (req, res) => {
|
||||
const pages = getMindSpacePages();
|
||||
if (!pages) {
|
||||
|
||||
@@ -102,6 +102,7 @@ test('page core module preserves route inventory and order', () => {
|
||||
assert.deepEqual([...api.routes.keys()], [
|
||||
'POST /mindspace/v1/pages',
|
||||
'GET /mindspace/v1/pages',
|
||||
'GET /mindspace/v1/pages/achievements',
|
||||
'GET /mindspace/v1/pages/:pageId',
|
||||
'DELETE /mindspace/v1/pages/:pageId',
|
||||
'GET /mindspace/v1/pages/:pageId/delete-preview',
|
||||
@@ -522,3 +523,31 @@ test('page core routes preserve unavailable and mapped error responses', async (
|
||||
assert.equal(failureRes.statusCode, 418);
|
||||
assert.equal(failure.calls.routeErrors[0].error.message, 'list failed');
|
||||
});
|
||||
|
||||
test('achievements route uses listPages and enriches stats before page detail route', async () => {
|
||||
const api = createRouterRecorder();
|
||||
const setup = createDependencies({
|
||||
getMindSpacePages: () => ({
|
||||
async listPages(userId, input) {
|
||||
return {
|
||||
items: [{ id: 'page-1', title: 'Demo', viewCount: 3, clickCount: null, statsSource: 'publication' }],
|
||||
total: 1,
|
||||
limit: input.limit ?? 20,
|
||||
offset: input.offset ?? 0,
|
||||
hasMore: false,
|
||||
};
|
||||
},
|
||||
}),
|
||||
getAuthPool: () => null,
|
||||
});
|
||||
attachPortalMindSpacePageCoreRoutes(api, setup.dependencies);
|
||||
|
||||
const res = createResponseRecorder();
|
||||
await api.routes.get('GET /mindspace/v1/pages/achievements')(
|
||||
createRequest({ query: { limit: '20', offset: '0' } }),
|
||||
res,
|
||||
);
|
||||
assert.equal(res.statusCode, 200);
|
||||
assert.equal(res.body.data[0].viewCount, 3);
|
||||
assert.equal(res.body.page.total, 1);
|
||||
});
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
import {
|
||||
markPageDeliveryContractReady,
|
||||
preparePageDeliveryContract,
|
||||
releaseMaterializedPageDeliveryContracts,
|
||||
} from '../mindspace-delivery-contract.mjs';
|
||||
import { maybeRepairH5HtmlAfterFinish } from '../mindspace-h5-html-finish-guard.mjs';
|
||||
import { maybeRepairPageDataAfterFinish } from '../mindspace-page-data-finish-guard.mjs';
|
||||
@@ -79,6 +80,8 @@ export function attachPortalSessionRoutes(
|
||||
maybeRepairPageDataAfterFinish,
|
||||
markPageDeliveryContractReadyFn =
|
||||
markPageDeliveryContractReady,
|
||||
releaseMaterializedPageDeliveryContractsFn =
|
||||
releaseMaterializedPageDeliveryContracts,
|
||||
finishDeliveryRetryDelaysMs = [250, 1_000],
|
||||
finishDeliveryRetryWaitFn = (delayMs) =>
|
||||
new Promise((resolve) =>
|
||||
@@ -477,6 +480,8 @@ export function attachPortalSessionRoutes(
|
||||
// workspace from DB-backed assets only.
|
||||
const finalizeAfterFinishOnce = async (sid, uid) => {
|
||||
beginSessionPageDelivery(sid);
|
||||
let releaseCandidatePaths = [];
|
||||
let allowPgRequiredRelease = false;
|
||||
try {
|
||||
const apiFetchFn = async (pathname, init) => {
|
||||
const target = await tkmindProxy.resolveTarget(sid);
|
||||
@@ -616,6 +621,8 @@ export function attachPortalSessionRoutes(
|
||||
...deliveryContractWrites.keys(),
|
||||
]),
|
||||
].sort();
|
||||
releaseCandidatePaths = publicHtmlRelativePaths;
|
||||
allowPgRequiredRelease = htmlReady && pageDataReady;
|
||||
const pgRequired = [
|
||||
...(Array.isArray(messages) ? messages : []),
|
||||
].some(
|
||||
@@ -660,11 +667,6 @@ export function attachPortalSessionRoutes(
|
||||
pgRequired,
|
||||
});
|
||||
}
|
||||
await markPageDeliveryContractReadyFn({
|
||||
pool: authPool,
|
||||
userId: uid,
|
||||
relativePath,
|
||||
}).catch(() => false);
|
||||
}
|
||||
}
|
||||
const memoryV2 = getMemoryV2();
|
||||
@@ -685,6 +687,20 @@ export function attachPortalSessionRoutes(
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
if (releaseCandidatePaths.length > 0) {
|
||||
await releaseMaterializedPageDeliveryContractsFn({
|
||||
pool: authPool,
|
||||
userId: uid,
|
||||
relativePaths: releaseCandidatePaths,
|
||||
allowPgRequired: allowPgRequiredRelease,
|
||||
}).catch((error) => {
|
||||
logger.warn(
|
||||
`[MindSpace] delivery contract release failed for session ${sid}: ${
|
||||
error instanceof Error ? error.message : error
|
||||
}`,
|
||||
);
|
||||
});
|
||||
}
|
||||
endSessionPageDelivery(sid);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -112,7 +112,7 @@ function createDependencies(overrides = {}) {
|
||||
return { sessionId, hooks };
|
||||
},
|
||||
};
|
||||
return {
|
||||
const setup = {
|
||||
calls,
|
||||
proxy,
|
||||
dependencies: {
|
||||
@@ -203,6 +203,30 @@ function createDependencies(overrides = {}) {
|
||||
...overrides,
|
||||
},
|
||||
};
|
||||
if (
|
||||
!Object.prototype.hasOwnProperty.call(
|
||||
overrides,
|
||||
'releaseMaterializedPageDeliveryContractsFn',
|
||||
)
|
||||
) {
|
||||
setup.dependencies.releaseMaterializedPageDeliveryContractsFn =
|
||||
async (input) => {
|
||||
const released = [];
|
||||
for (const relativePath of input.relativePaths ?? []) {
|
||||
if (
|
||||
await setup.dependencies.markPageDeliveryContractReadyFn({
|
||||
pool: input.pool,
|
||||
userId: input.userId,
|
||||
relativePath,
|
||||
})
|
||||
) {
|
||||
released.push(relativePath);
|
||||
}
|
||||
}
|
||||
return released;
|
||||
};
|
||||
}
|
||||
return setup;
|
||||
}
|
||||
|
||||
test('session module preserves route inventory and order', () => {
|
||||
@@ -709,8 +733,8 @@ test('Finish hook preserves refresh, sync, delivery readiness, memory, and lock
|
||||
'prepare-page-data',
|
||||
'repair-page-data',
|
||||
'prepare-contract',
|
||||
'ready',
|
||||
'memory',
|
||||
'ready',
|
||||
],
|
||||
);
|
||||
assert.equal(
|
||||
@@ -957,5 +981,73 @@ test('Finish retries when a delivery guard is initially not ready', async () =>
|
||||
assert.equal(pageDataChecks, 2);
|
||||
assert.deepEqual(setup.calls.begin, ['session-1', 'session-1']);
|
||||
assert.deepEqual(setup.calls.end, ['session-1', 'session-1']);
|
||||
assert.deepEqual(readyPaths, ['public/survey.html']);
|
||||
assert.deepEqual(readyPaths, ['public/survey.html', 'public/survey.html']);
|
||||
});
|
||||
|
||||
test('Finish finally releases static HTML contracts when delivery guards fail', async () => {
|
||||
let hooks = null;
|
||||
const releasedPaths = [];
|
||||
const setup = createDependencies({
|
||||
finishDeliveryRetryDelaysMs: [],
|
||||
getAuthPool: () => ({ id: 'pool' }),
|
||||
getTkmindProxy: () => ({
|
||||
async resolveTarget(sessionId) {
|
||||
return `target:${sessionId}`;
|
||||
},
|
||||
async apiFetchTo() {
|
||||
return createUpstream({
|
||||
body: {
|
||||
id: 'session-1',
|
||||
conversation: [
|
||||
{
|
||||
id: 'user-1',
|
||||
role: 'user',
|
||||
content: 'update page',
|
||||
metadata: { userVisible: true },
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
},
|
||||
proxySessionEvents(_req, _res, _sessionId, receivedHooks) {
|
||||
hooks = receivedHooks;
|
||||
},
|
||||
}),
|
||||
getMindSpacePublicFinish: () => ({
|
||||
async syncAfterFinish() {
|
||||
return {
|
||||
publicHtmlRelativePaths: ['public/daily-news-0813.html'],
|
||||
docxSync: { missing: [] },
|
||||
};
|
||||
},
|
||||
async preparePageDataAfterFinish() {
|
||||
return {
|
||||
autoBind: { bound: [], skipped: [], errors: [] },
|
||||
evaluation: { structuralPageData: false, relevantFiles: [] },
|
||||
};
|
||||
},
|
||||
}),
|
||||
async maybeRepairH5HtmlAfterFinishFn() {
|
||||
return { skipped: 'limit' };
|
||||
},
|
||||
async releaseMaterializedPageDeliveryContractsFn(input) {
|
||||
releasedPaths.push(...(input.relativePaths ?? []));
|
||||
return input.relativePaths ?? [];
|
||||
},
|
||||
});
|
||||
const api = createRouterRecorder();
|
||||
attachPortalSessionRoutes(api, setup.dependencies);
|
||||
await api.routes.get('GET /sessions/:sessionId/events')(
|
||||
createRequest(),
|
||||
createResponseRecorder(),
|
||||
() => {},
|
||||
);
|
||||
|
||||
await assert.rejects(
|
||||
() => hooks.onAfterFinish('session-1', 'user-1'),
|
||||
/page delivery guards are not ready/,
|
||||
);
|
||||
|
||||
assert.deepEqual(releasedPaths, ['public/daily-news-0813.html']);
|
||||
assert.deepEqual(setup.calls.end, ['session-1']);
|
||||
});
|
||||
|
||||
@@ -54,6 +54,7 @@ export function normalizeProductRoute(pathname: string, search = '') {
|
||||
export function resolveProductRouteName(pathname: string) {
|
||||
if (pathname === '/') return 'chat';
|
||||
if (pathname === '/space') return 'mindspace_home';
|
||||
if (pathname === '/space/achievements') return 'mindspace_achievements';
|
||||
if (pathname.startsWith('/space/page/')) return 'mindspace_page';
|
||||
if (pathname.startsWith('/feedback/')) return 'feedback_detail';
|
||||
if (pathname === '/feedback') return 'feedback';
|
||||
|
||||
@@ -88,7 +88,9 @@ export {
|
||||
getMindSpacePage,
|
||||
getMindSpacePageDeletePreview,
|
||||
getMindSpacePageLiveRevision,
|
||||
isMindSpacePageNotFoundError,
|
||||
listMindSpacePages,
|
||||
listMindSpaceAchievementPages,
|
||||
openMindSpaceDraftPreviewWindow,
|
||||
regenerateMindSpacePageThumbnail,
|
||||
rewriteMindSpacePageDownloadLinks,
|
||||
|
||||
@@ -29,6 +29,14 @@ export async function getMindSpacePageDeletePreview(
|
||||
return result.data;
|
||||
}
|
||||
|
||||
export function isMindSpacePageNotFoundError(err: unknown): boolean {
|
||||
return (
|
||||
err instanceof ApiError &&
|
||||
err.status === 404 &&
|
||||
(err.code === 'page_not_found' || err.message === '页面不存在')
|
||||
);
|
||||
}
|
||||
|
||||
export async function deleteMindSpacePage(
|
||||
pageId: string,
|
||||
options?: { removeFromPlaza?: boolean },
|
||||
@@ -61,6 +69,26 @@ export async function listMindSpacePages(options?: {
|
||||
return { items: result.data, page: result.page ?? {} };
|
||||
}
|
||||
|
||||
export async function listMindSpaceAchievementPages(options?: {
|
||||
status?: string;
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
categoryCode?: string;
|
||||
includeStats?: boolean;
|
||||
}): Promise<{ items: MindSpacePage[]; page: MindSpaceListPage }> {
|
||||
const params = new URLSearchParams();
|
||||
if (options?.status) params.set('status', options.status);
|
||||
if (options?.limit != null) params.set('limit', String(options.limit));
|
||||
if (options?.offset != null) params.set('offset', String(options.offset));
|
||||
if (options?.categoryCode) params.set('category_code', options.categoryCode);
|
||||
if (options?.includeStats) params.set('include_stats', '1');
|
||||
const query = params.toString() ? `?${params.toString()}` : '';
|
||||
const result = await apiFetch<{ data: MindSpacePage[]; page?: MindSpaceListPage }>(
|
||||
`/mindspace/v1/pages/achievements${query}`,
|
||||
);
|
||||
return { items: result.data, page: result.page ?? {} };
|
||||
}
|
||||
|
||||
export async function getMindSpacePage(pageId: string): Promise<MindSpacePage> {
|
||||
const result = await apiFetch<{ data: MindSpacePage }>(
|
||||
`/mindspace/v1/pages/${encodeURIComponent(pageId)}`,
|
||||
|
||||
@@ -492,6 +492,7 @@ export function ChatPanel({
|
||||
chatState === 'connecting' ||
|
||||
chatState === 'waiting';
|
||||
const offlineBlocked = !online;
|
||||
const inputBlocked = !!pendingTool || chatState === 'error' || offlineBlocked;
|
||||
const publishSkillName = user?.publishSkillName ?? 'static-page-publish';
|
||||
const hasPublishSkill = grantedSkills?.includes(publishSkillName) ?? false;
|
||||
const hasPageDataCollectSkill = grantedSkills?.includes('page-data-collect') ?? false;
|
||||
@@ -525,9 +526,9 @@ export function ChatPanel({
|
||||
? '上传中…'
|
||||
: chatState === 'connecting'
|
||||
? '连接中…'
|
||||
: chatState === 'waiting'
|
||||
? '提交中…'
|
||||
: null;
|
||||
: busy && canSubmit
|
||||
? '排队发送'
|
||||
: null;
|
||||
|
||||
const applyTemplatePrefill = useCallback((prompt: string, skillId: string, label: string) => {
|
||||
pendingSkillRef.current = skillId;
|
||||
@@ -577,7 +578,7 @@ export function ChatPanel({
|
||||
setVoiceNotice('已识别,可编辑后发送');
|
||||
};
|
||||
|
||||
const voiceDisabled = busy || !!pendingTool || chatState === 'error' || offlineBlocked;
|
||||
const voiceDisabled = inputBlocked || uploadingImage || uploadingFile;
|
||||
const canSubmit = input.trim() || pendingImages.length > 0 || pendingFiles.length > 0;
|
||||
const uploadDisabled = !canUpload || busy || uploadingImage || uploadingFile || offlineBlocked || !!pendingTool;
|
||||
|
||||
@@ -719,7 +720,7 @@ export function ChatPanel({
|
||||
skillIdOverride ?? pendingSkillRef.current ?? templateSelection?.skillId ?? undefined;
|
||||
pendingSkillRef.current = null;
|
||||
setActiveTemplatePrefill(null);
|
||||
if ((!trimmed && pendingImages.length === 0 && pendingFiles.length === 0) || voiceDisabled) return;
|
||||
if ((!trimmed && pendingImages.length === 0 && pendingFiles.length === 0) || inputBlocked) return;
|
||||
if (pendingImages.length > 0 && !onUploadImage) {
|
||||
setImageError('当前会话暂不支持图片发送');
|
||||
return;
|
||||
@@ -1462,16 +1463,15 @@ export function ChatPanel({
|
||||
<button type="button" className="danger-btn chat-input-action" onClick={() => void onStop()}>
|
||||
停止
|
||||
</button>
|
||||
) : (
|
||||
<button
|
||||
type="button"
|
||||
className={`send-btn chat-input-action${showHomeWelcome ? ' chat-input-action-home' : ''}`}
|
||||
disabled={!canSubmit || voiceDisabled || uploadingImage || uploadingFile}
|
||||
onClick={() => void handleSubmit()}
|
||||
>
|
||||
{sendButtonLabel ?? '发送'}
|
||||
</button>
|
||||
)}
|
||||
) : null}
|
||||
<button
|
||||
type="button"
|
||||
className={`send-btn chat-input-action${showHomeWelcome ? ' chat-input-action-home' : ''}`}
|
||||
disabled={!canSubmit || inputBlocked || uploadingImage || uploadingFile}
|
||||
onClick={() => void handleSubmit()}
|
||||
>
|
||||
{sendButtonLabel ?? '发送'}
|
||||
</button>
|
||||
</div>
|
||||
{compact && onClose && (
|
||||
<button type="button" className="space-chat-panel-dismiss" onClick={onClose}>
|
||||
|
||||
@@ -0,0 +1,299 @@
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import type { MindSpacePage } from '../types';
|
||||
|
||||
const PAGE_STATUS_LABELS: Record<string, string> = {
|
||||
draft: '草稿',
|
||||
reviewing: '待检查',
|
||||
risk_found: '发现风险',
|
||||
ready: '可发布',
|
||||
published: '已公开',
|
||||
protected: '受保护',
|
||||
expired: '已过期',
|
||||
offline: '已下线',
|
||||
};
|
||||
|
||||
function formatDateTime(timestamp: number) {
|
||||
return new Date(timestamp).toLocaleString('zh-CN', {
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
});
|
||||
}
|
||||
|
||||
const ACHIEVEMENTS_DATE_TIMEZONE = 'Asia/Shanghai';
|
||||
|
||||
function localCreatedDateKey(timestamp: number) {
|
||||
const parts = new Intl.DateTimeFormat('en-CA', {
|
||||
timeZone: ACHIEVEMENTS_DATE_TIMEZONE,
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
}).formatToParts(new Date(timestamp));
|
||||
const year = parts.find((part) => part.type === 'year')?.value ?? '0000';
|
||||
const month = parts.find((part) => part.type === 'month')?.value ?? '01';
|
||||
const day = parts.find((part) => part.type === 'day')?.value ?? '01';
|
||||
return `${year}-${month}-${day}`;
|
||||
}
|
||||
|
||||
function formatDateHeading(timestamp: number) {
|
||||
return new Date(timestamp).toLocaleDateString('zh-CN', {
|
||||
timeZone: ACHIEVEMENTS_DATE_TIMEZONE,
|
||||
year: 'numeric',
|
||||
month: 'long',
|
||||
day: 'numeric',
|
||||
weekday: 'short',
|
||||
});
|
||||
}
|
||||
|
||||
function formatMetric(value: number | null | undefined) {
|
||||
if (value == null) return '—';
|
||||
return value.toLocaleString('zh-CN');
|
||||
}
|
||||
|
||||
function formatClickMetric(page: MindSpacePage) {
|
||||
if (page.clickCount == null) return '—';
|
||||
return formatMetric(page.clickCount);
|
||||
}
|
||||
|
||||
function groupPagesByCreatedDate(pages: MindSpacePage[]) {
|
||||
const groups = new Map<string, MindSpacePage[]>();
|
||||
for (const page of pages) {
|
||||
const key = localCreatedDateKey(page.createdAt);
|
||||
const bucket = groups.get(key);
|
||||
if (bucket) bucket.push(page);
|
||||
else groups.set(key, [page]);
|
||||
}
|
||||
return [...groups.entries()]
|
||||
.sort(([left], [right]) => right.localeCompare(left))
|
||||
.map(([dateKey, items]) => ({
|
||||
dateKey,
|
||||
heading: formatDateHeading(items[0]?.createdAt ?? Date.parse(`${dateKey}T12:00:00+08:00`)),
|
||||
items,
|
||||
}));
|
||||
}
|
||||
|
||||
type MindSpaceAchievementsPanelProps = {
|
||||
items: MindSpacePage[];
|
||||
total: number;
|
||||
loading: boolean;
|
||||
pageIndex: number;
|
||||
pageSize: number;
|
||||
selectedIds: string[];
|
||||
deleting: boolean;
|
||||
deletingPageId?: string | null;
|
||||
onBack: () => void;
|
||||
onOpenPage: (page: MindSpacePage) => void;
|
||||
onShowPage: (pageId: string) => void;
|
||||
onTogglePage: (pageId: string, checked: boolean) => void;
|
||||
onToggleDateGroup: (pageIds: string[], checked: boolean) => void;
|
||||
onToggleAll: () => void;
|
||||
onClearSelection: () => void;
|
||||
onDeleteSelected: () => void;
|
||||
onDeletePage: (page: MindSpacePage) => void;
|
||||
onPrevPage: () => void;
|
||||
onNextPage: () => void;
|
||||
onFirstPage: () => void;
|
||||
};
|
||||
|
||||
export function MindSpaceAchievementsPanel({
|
||||
items,
|
||||
total,
|
||||
loading,
|
||||
pageIndex,
|
||||
pageSize,
|
||||
selectedIds,
|
||||
deleting,
|
||||
deletingPageId,
|
||||
onBack,
|
||||
onOpenPage,
|
||||
onShowPage,
|
||||
onTogglePage,
|
||||
onToggleDateGroup,
|
||||
onToggleAll,
|
||||
onClearSelection,
|
||||
onDeleteSelected,
|
||||
onDeletePage,
|
||||
onPrevPage,
|
||||
onNextPage,
|
||||
onFirstPage,
|
||||
}: MindSpaceAchievementsPanelProps) {
|
||||
const selectedSet = useMemo(() => new Set(selectedIds), [selectedIds]);
|
||||
const grouped = useMemo(() => groupPagesByCreatedDate(items), [items]);
|
||||
const allVisibleSelected =
|
||||
items.length > 0 && items.every((page) => selectedSet.has(page.id));
|
||||
const pageCount = Math.max(1, Math.ceil(total / pageSize));
|
||||
|
||||
return (
|
||||
<section className="mindspace-independent-page mindspace-achievements">
|
||||
<div className="mindspace-section-heading">
|
||||
<div>
|
||||
<button type="button" className="mindspace-inline-back" onClick={onBack}>
|
||||
返回空间首页
|
||||
</button>
|
||||
<p className="mindspace-eyebrow">MY ACHIEVEMENTS</p>
|
||||
<h2>我的成果展示</h2>
|
||||
</div>
|
||||
<span>{total} 个页面</span>
|
||||
</div>
|
||||
|
||||
<p className="mindspace-achievements-intro">
|
||||
按创建日期汇总你制作过的页面,每页 {pageSize} 条。浏览量来自公开页访问统计;点击量需开启 Umami 后才会显示。
|
||||
</p>
|
||||
|
||||
{items.length > 0 && (
|
||||
<div className="mindspace-asset-bulkbar mindspace-achievements-bulkbar">
|
||||
<button type="button" onClick={onToggleAll} disabled={deleting || items.length === 0}>
|
||||
{allVisibleSelected ? '取消全选' : '全选本页'}
|
||||
</button>
|
||||
<span>已选 {selectedIds.length} 项</span>
|
||||
{selectedIds.length > 0 && (
|
||||
<button type="button" onClick={onClearSelection} disabled={deleting}>
|
||||
清空
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
className="mindspace-asset-bulk-delete"
|
||||
onClick={onDeleteSelected}
|
||||
disabled={selectedIds.length === 0 || deleting}
|
||||
>
|
||||
{deleting ? '删除中…' : '删除选中'}
|
||||
</button>
|
||||
{total > pageSize && pageIndex > 0 && (
|
||||
<button
|
||||
type="button"
|
||||
className="mindspace-achievements-back-page"
|
||||
disabled={loading}
|
||||
onClick={onFirstPage}
|
||||
>
|
||||
返回
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{loading && items.length === 0 ? (
|
||||
<div className="mindspace-state">正在加载成果列表…</div>
|
||||
) : total > 0 ? (
|
||||
<>
|
||||
<div className="mindspace-achievements-groups">
|
||||
{grouped.map((group) => {
|
||||
const groupIds = group.items.map((page) => page.id);
|
||||
const groupSelected =
|
||||
groupIds.length > 0 && groupIds.every((id) => selectedSet.has(id));
|
||||
return (
|
||||
<section className="mindspace-achievements-group" key={group.dateKey}>
|
||||
<div className="mindspace-achievements-group-heading">
|
||||
<h3>{group.heading}</h3>
|
||||
<label className="mindspace-achievements-group-select">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={groupSelected}
|
||||
disabled={deleting}
|
||||
onChange={(event) =>
|
||||
onToggleDateGroup(groupIds, event.currentTarget.checked)
|
||||
}
|
||||
/>
|
||||
<span>{groupSelected ? '取消全选本日' : '全选本日'}</span>
|
||||
</label>
|
||||
</div>
|
||||
<div className="mindspace-achievements-table-wrap">
|
||||
<table className="mindspace-achievements-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col" className="mindspace-achievements-col-select">
|
||||
选择
|
||||
</th>
|
||||
<th scope="col">标题</th>
|
||||
<th scope="col">状态</th>
|
||||
<th scope="col">创建时间</th>
|
||||
<th scope="col">最后修改</th>
|
||||
<th scope="col">浏览量</th>
|
||||
<th scope="col">点击量</th>
|
||||
<th scope="col">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{group.items.map((page) => (
|
||||
<tr key={page.id}>
|
||||
<td className="mindspace-achievements-col-select">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={selectedSet.has(page.id)}
|
||||
disabled={deleting}
|
||||
aria-label={`选择 ${page.title}`}
|
||||
onChange={(event) =>
|
||||
onTogglePage(page.id, event.currentTarget.checked)
|
||||
}
|
||||
/>
|
||||
</td>
|
||||
<td className="mindspace-achievements-title">
|
||||
<button
|
||||
type="button"
|
||||
className="mindspace-achievements-title-link"
|
||||
onClick={() => void onOpenPage(page)}
|
||||
>
|
||||
{page.title}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="mindspace-achievements-detail-link"
|
||||
onClick={() => onShowPage(page.id)}
|
||||
>
|
||||
详情
|
||||
</button>
|
||||
</td>
|
||||
<td>{PAGE_STATUS_LABELS[page.status] ?? page.status}</td>
|
||||
<td>{formatDateTime(page.createdAt)}</td>
|
||||
<td>{formatDateTime(page.updatedAt)}</td>
|
||||
<td>{formatMetric(page.viewCount ?? 0)}</td>
|
||||
<td>{formatClickMetric(page)}</td>
|
||||
<td>
|
||||
<button
|
||||
type="button"
|
||||
className="mindspace-achievements-delete-link"
|
||||
disabled={deleting || deletingPageId === page.id}
|
||||
onClick={() => onDeletePage(page)}
|
||||
>
|
||||
{deletingPageId === page.id ? '删除中…' : '删除'}
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
{total > pageSize && (
|
||||
<div className="mindspace-pagination mindspace-achievements-pagination">
|
||||
<button type="button" disabled={pageIndex <= 0 || loading} onClick={onPrevPage}>
|
||||
上一页
|
||||
</button>
|
||||
<span>
|
||||
第 {pageIndex + 1} / {pageCount} 页
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
disabled={loading || (pageIndex + 1) * pageSize >= total}
|
||||
onClick={onNextPage}
|
||||
>
|
||||
下一页
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<div className="mindspace-recent-work-empty">
|
||||
<p>上传资料或从聊天保存页面后,你的成果会按日期集中展示在这里。</p>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -15,10 +15,12 @@ import {
|
||||
getMindSpacePage,
|
||||
getMindSpacePageDeletePreview,
|
||||
ignoreMindSpaceScheduleReminder,
|
||||
isMindSpacePageNotFoundError,
|
||||
listMindSpaceAgentJobs,
|
||||
listMindSpaceAssets,
|
||||
listMindSpaceCleanupItems,
|
||||
listMindSpacePages,
|
||||
listMindSpaceAchievementPages,
|
||||
retryMindSpaceAgentJob,
|
||||
runMindSpaceAgentJob,
|
||||
runMindSpaceCleanup,
|
||||
@@ -55,6 +57,7 @@ import {
|
||||
} from '../utils/mindspaceCards';
|
||||
import { PREVIEW_ASSETS, PREVIEW_PAGES, PREVIEW_SPACE } from '../dev/mindspacePreviewData';
|
||||
import { MindSpaceFeedCard } from './MindSpaceFeedCard';
|
||||
import { MindSpaceAchievementsPanel } from './MindSpaceAchievementsPanel';
|
||||
import { MindSpacePageDetail } from './MindSpacePageDetail';
|
||||
import { MindSpaceModal } from './MindSpaceModal';
|
||||
import { MindSpaceDeletePlazaOption } from './MindSpaceDeletePlazaOption';
|
||||
@@ -83,6 +86,7 @@ const CATEGORY_ACTIONS: Partial<Record<MindSpaceCategory['code'], string>> = {
|
||||
const AGENT_JOBS_PAGE_SIZE = 10;
|
||||
const RECENT_PAGES_PAGE_SIZE = 6;
|
||||
const ALL_PAGES_PAGE_SIZE = 15;
|
||||
const ACHIEVEMENTS_PAGE_SIZE = 20;
|
||||
|
||||
function sortPagesByCreatedAt(pages: MindSpacePage[]) {
|
||||
return [...pages].sort((left, right) => {
|
||||
@@ -499,6 +503,7 @@ function canGenerateWithAgent(asset: MindSpaceAsset) {
|
||||
|
||||
type MindSpaceRouteSync = {
|
||||
pushHome: () => void;
|
||||
pushAchievements: () => void;
|
||||
pushCategory: (code: MindSpaceSaveCategory | MindSpaceCategory['code']) => void;
|
||||
pushPage: (pageId: string) => void;
|
||||
};
|
||||
@@ -528,6 +533,7 @@ export function MindSpaceView({
|
||||
previewMode = false,
|
||||
initialPageId,
|
||||
initialCategoryCode,
|
||||
initialAchievementsOpen = false,
|
||||
onBack,
|
||||
onLogout,
|
||||
onOpenFeedback,
|
||||
@@ -537,6 +543,7 @@ export function MindSpaceView({
|
||||
previewMode?: boolean;
|
||||
initialPageId?: string | null;
|
||||
initialCategoryCode?: MindSpaceSaveCategory | null;
|
||||
initialAchievementsOpen?: boolean;
|
||||
onBack: () => void;
|
||||
onLogout: () => void;
|
||||
onOpenFeedback?: () => void;
|
||||
@@ -589,6 +596,13 @@ export function MindSpaceView({
|
||||
const [allPagesTotal, setAllPagesTotal] = useState(0);
|
||||
const [allPagesPageIndex, setAllPagesPageIndex] = useState(0);
|
||||
const [allPagesLoading, setAllPagesLoading] = useState(false);
|
||||
const [achievementsOpen, setAchievementsOpen] = useState(initialAchievementsOpen);
|
||||
const [achievementsItems, setAchievementsItems] = useState<MindSpacePage[]>([]);
|
||||
const [achievementsTotal, setAchievementsTotal] = useState(0);
|
||||
const [achievementsPageIndex, setAchievementsPageIndex] = useState(0);
|
||||
const [achievementsLoading, setAchievementsLoading] = useState(false);
|
||||
const [selectedAchievementPageIds, setSelectedAchievementPageIds] = useState<string[]>([]);
|
||||
const [bulkDeletingAchievements, setBulkDeletingAchievements] = useState(false);
|
||||
const [selectedAllPageIds, setSelectedAllPageIds] = useState<string[]>([]);
|
||||
const [bulkDeletingAllPages, setBulkDeletingAllPages] = useState(false);
|
||||
const [selectedScheduleReminderIds, setSelectedScheduleReminderIds] = useState<string[]>([]);
|
||||
@@ -605,7 +619,7 @@ export function MindSpaceView({
|
||||
const [pageDeleteRemoveFromPlaza, setPageDeleteRemoveFromPlaza] = useState(false);
|
||||
const [deletingPageId, setDeletingPageId] = useState<string | null>(null);
|
||||
const [bulkPageDeleteOpen, setBulkPageDeleteOpen] = useState(false);
|
||||
const [bulkPageDeleteSource, setBulkPageDeleteSource] = useState<'all' | 'draft'>('all');
|
||||
const [bulkPageDeleteSource, setBulkPageDeleteSource] = useState<'all' | 'draft' | 'achievements'>('all');
|
||||
const [bulkPageDeletePreviews, setBulkPageDeletePreviews] = useState<
|
||||
MindSpacePageDeletePreview[] | null
|
||||
>(null);
|
||||
@@ -649,11 +663,11 @@ export function MindSpaceView({
|
||||
}, [selectedPageId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!allPagesOpen && !selectedPageId) return;
|
||||
if (!allPagesOpen && !achievementsOpen && !selectedPageId) return;
|
||||
window.requestAnimationFrame(() => {
|
||||
window.scrollTo({ top: 0, left: 0 });
|
||||
});
|
||||
}, [allPagesOpen, selectedPageId]);
|
||||
}, [allPagesOpen, achievementsOpen, selectedPageId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!selectedPageId || !session?.id || previewMode || pageFullscreenPreviewOpen) return;
|
||||
@@ -802,8 +816,30 @@ export function MindSpaceView({
|
||||
setPageDeleteTarget(null);
|
||||
setPageDeletePreview(null);
|
||||
setPageDeleteRemoveFromPlaza(false);
|
||||
setSelectedAchievementPageIds((ids) => ids.filter((id) => id !== pageDeleteTarget.id));
|
||||
setAchievementsItems((items) => items.filter((page) => page.id !== pageDeleteTarget.id));
|
||||
setAchievementsTotal((total) => Math.max(0, total - 1));
|
||||
await refreshMindSpaceSnapshot({ quota: result.quota, freedBytes: result.freedBytes });
|
||||
if (achievementsOpen) {
|
||||
await loadAchievementsPage(achievementsPageIndex);
|
||||
}
|
||||
} catch (err) {
|
||||
if (isMindSpacePageNotFoundError(err)) {
|
||||
if (selectedPageId === pageDeleteTarget.id) {
|
||||
closePage();
|
||||
}
|
||||
setPageDeleteTarget(null);
|
||||
setPageDeletePreview(null);
|
||||
setPageDeleteRemoveFromPlaza(false);
|
||||
setSelectedAchievementPageIds((ids) => ids.filter((id) => id !== pageDeleteTarget.id));
|
||||
setAchievementsItems((items) => items.filter((page) => page.id !== pageDeleteTarget.id));
|
||||
setAchievementsTotal((total) => Math.max(0, total - 1));
|
||||
await refreshMindSpaceSnapshot();
|
||||
if (achievementsOpen) {
|
||||
await loadAchievementsPage(achievementsPageIndex);
|
||||
}
|
||||
return;
|
||||
}
|
||||
setError(err instanceof Error ? err.message : '删除页面失败');
|
||||
} finally {
|
||||
setDeletingPageId(null);
|
||||
@@ -959,12 +995,58 @@ export function MindSpaceView({
|
||||
setSelectedPageId(null);
|
||||
setNewPageOpen(false);
|
||||
setAgentJobsPanelOpen(false);
|
||||
setAchievementsOpen(false);
|
||||
setAllPagesOpen(true);
|
||||
setSelectedAllPageIds([]);
|
||||
routeSync?.pushHome();
|
||||
void loadAllPagesPage(0);
|
||||
};
|
||||
|
||||
const loadAchievementsPage = async (pageIndex: number) => {
|
||||
if (previewMode) {
|
||||
setAchievementsItems(PREVIEW_PAGES);
|
||||
setAchievementsTotal(PREVIEW_PAGES.length);
|
||||
setAchievementsPageIndex(0);
|
||||
setSelectedAchievementPageIds([]);
|
||||
return;
|
||||
}
|
||||
setAchievementsLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const { items, page } = await listMindSpaceAchievementPages({
|
||||
limit: ACHIEVEMENTS_PAGE_SIZE,
|
||||
offset: pageIndex * ACHIEVEMENTS_PAGE_SIZE,
|
||||
includeStats: false,
|
||||
});
|
||||
setAchievementsItems(items);
|
||||
setAchievementsPageIndex(pageIndex);
|
||||
setAchievementsTotal(page.total ?? items.length);
|
||||
setSelectedAchievementPageIds([]);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : '成果列表加载失败');
|
||||
} finally {
|
||||
setAchievementsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const openAchievementsPanel = () => {
|
||||
setSelectedCategory(null);
|
||||
setSelectedPageId(null);
|
||||
setNewPageOpen(false);
|
||||
setAgentJobsPanelOpen(false);
|
||||
setAllPagesOpen(false);
|
||||
setAchievementsOpen(true);
|
||||
setSelectedAchievementPageIds([]);
|
||||
routeSync?.pushAchievements();
|
||||
void loadAchievementsPage(0);
|
||||
};
|
||||
|
||||
const closeAchievementsPanel = () => {
|
||||
setAchievementsOpen(false);
|
||||
setSelectedAchievementPageIds([]);
|
||||
routeSync?.pushHome();
|
||||
};
|
||||
|
||||
const refreshAgentJobsSummary = async () => {
|
||||
if (previewMode) return;
|
||||
const { page } = await listMindSpaceAgentJobs({ limit: 1, offset: 0 });
|
||||
@@ -999,6 +1081,7 @@ export function MindSpaceView({
|
||||
setSelectedPageId(null);
|
||||
setNewPageOpen(false);
|
||||
setAllPagesOpen(false);
|
||||
setAchievementsOpen(false);
|
||||
setAgentJobsPanelOpen(true);
|
||||
routeSync?.pushHome();
|
||||
void loadAgentJobsPage(0);
|
||||
@@ -1066,6 +1149,9 @@ export function MindSpaceView({
|
||||
if (allPagesOpen) {
|
||||
await loadAllPagesPage(allPagesPageIndex);
|
||||
}
|
||||
if (achievementsOpen) {
|
||||
await loadAchievementsPage(achievementsPageIndex);
|
||||
}
|
||||
} catch {
|
||||
// ignore background list refresh errors
|
||||
}
|
||||
@@ -1114,7 +1200,7 @@ export function MindSpaceView({
|
||||
useEffect(() => {
|
||||
if (previewMode) return;
|
||||
const refreshSchedule = () => {
|
||||
if (!selectedCategory && !selectedPageId && !newPageOpen && !agentJobsPanelOpen && !allPagesOpen) {
|
||||
if (!selectedCategory && !selectedPageId && !newPageOpen && !agentJobsPanelOpen && !allPagesOpen && !achievementsOpen) {
|
||||
void refreshSpaceQuietly();
|
||||
}
|
||||
};
|
||||
@@ -1130,6 +1216,7 @@ export function MindSpaceView({
|
||||
newPageOpen,
|
||||
agentJobsPanelOpen,
|
||||
allPagesOpen,
|
||||
achievementsOpen,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -1137,10 +1224,21 @@ export function MindSpaceView({
|
||||
}, [initialPageId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!space || !initialCategoryCode || initialCategoryCode === 'draft') return;
|
||||
if (!space || !initialCategoryCode || initialCategoryCode === 'draft' || initialAchievementsOpen) return;
|
||||
const category = space.categories.find((item) => item.code === initialCategoryCode);
|
||||
if (category) void openCategory(category);
|
||||
}, [space, initialCategoryCode]);
|
||||
}, [space, initialCategoryCode, initialAchievementsOpen]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!initialAchievementsOpen || previewMode) return;
|
||||
setSelectedCategory(null);
|
||||
setSelectedPageId(null);
|
||||
setNewPageOpen(false);
|
||||
setAgentJobsPanelOpen(false);
|
||||
setAllPagesOpen(false);
|
||||
setAchievementsOpen(true);
|
||||
void loadAchievementsPage(0);
|
||||
}, [initialAchievementsOpen, previewMode]);
|
||||
|
||||
useEffect(() => {
|
||||
if (previewMode || !agentJob || !['queued', 'running'].includes(agentJob.status)) return;
|
||||
@@ -1167,6 +1265,7 @@ export function MindSpaceView({
|
||||
const openCategory = async (category: MindSpaceCategory) => {
|
||||
setAgentJobsPanelOpen(false);
|
||||
setAllPagesOpen(false);
|
||||
setAchievementsOpen(false);
|
||||
setSelectedCategory(category);
|
||||
setSelectedPageId(null);
|
||||
setNewPageOpen(false);
|
||||
@@ -1586,13 +1685,13 @@ export function MindSpaceView({
|
||||
}, [bulkPageDeletePreviews]);
|
||||
|
||||
const closeBulkPageDeleteDialog = () => {
|
||||
if (bulkDeletingAllPages || bulkDeletingDraftPages) return;
|
||||
if (bulkDeletingAllPages || bulkDeletingDraftPages || bulkDeletingAchievements) return;
|
||||
setBulkPageDeleteOpen(false);
|
||||
setBulkPageDeletePreviews(null);
|
||||
setBulkPageDeleteRemoveFromPlaza(false);
|
||||
};
|
||||
|
||||
const startBulkPageDelete = async (pageIds: string[], source: 'all' | 'draft') => {
|
||||
const startBulkPageDelete = async (pageIds: string[], source: 'all' | 'draft' | 'achievements') => {
|
||||
if (pageIds.length === 0) return;
|
||||
if (previewMode) {
|
||||
setError('预览模式下无法删除页面');
|
||||
@@ -1632,7 +1731,11 @@ export function MindSpaceView({
|
||||
if (!bulkPageDeletePreviews || bulkPageDeletePreviews.length === 0) return;
|
||||
const deletingIds = bulkPageDeletePreviews.map((preview) => preview.page.id);
|
||||
const setBulkDeleting =
|
||||
bulkPageDeleteSource === 'all' ? setBulkDeletingAllPages : setBulkDeletingDraftPages;
|
||||
bulkPageDeleteSource === 'all'
|
||||
? setBulkDeletingAllPages
|
||||
: bulkPageDeleteSource === 'draft'
|
||||
? setBulkDeletingDraftPages
|
||||
: setBulkDeletingAchievements;
|
||||
setBulkDeleting(true);
|
||||
setError(null);
|
||||
const failedIds: string[] = [];
|
||||
@@ -1645,6 +1748,10 @@ export function MindSpaceView({
|
||||
});
|
||||
if (selectedPageId === preview.page.id) closePage();
|
||||
} catch (err) {
|
||||
if (isMindSpacePageNotFoundError(err)) {
|
||||
if (selectedPageId === preview.page.id) closePage();
|
||||
continue;
|
||||
}
|
||||
failedIds.push(preview.page.id);
|
||||
failedNames.push(preview.page.title);
|
||||
console.error('[MindSpace] delete page failed:', preview.page.id, err);
|
||||
@@ -1653,8 +1760,10 @@ export function MindSpaceView({
|
||||
const deletedIds = deletingIds.filter((id) => !failedIds.includes(id));
|
||||
if (bulkPageDeleteSource === 'all') {
|
||||
setSelectedAllPageIds((ids) => ids.filter((id) => failedIds.includes(id)));
|
||||
} else {
|
||||
} else if (bulkPageDeleteSource === 'draft') {
|
||||
setSelectedDraftPageIds((ids) => ids.filter((id) => failedIds.includes(id)));
|
||||
} else {
|
||||
setSelectedAchievementPageIds((ids) => ids.filter((id) => failedIds.includes(id)));
|
||||
}
|
||||
setBulkPageDeleteOpen(false);
|
||||
setBulkPageDeletePreviews(null);
|
||||
@@ -1668,6 +1777,12 @@ export function MindSpaceView({
|
||||
: allPagesPageIndex;
|
||||
await loadAllPagesPage(nextPageIndex);
|
||||
}
|
||||
if (bulkPageDeleteSource === 'achievements' && deletedIds.length > 0) {
|
||||
setAchievementsItems((items) => items.filter((page) => !deletedIds.includes(page.id)));
|
||||
setAchievementsTotal((total) => Math.max(0, total - deletedIds.length));
|
||||
setSelectedAchievementPageIds((ids) => ids.filter((id) => !deletedIds.includes(id)));
|
||||
await loadAchievementsPage(achievementsPageIndex);
|
||||
}
|
||||
if (failedNames.length > 0) {
|
||||
setError(`有 ${failedNames.length} 个页面删除失败:${failedNames.slice(0, 3).join('、')}`);
|
||||
}
|
||||
@@ -1698,6 +1813,45 @@ export function MindSpaceView({
|
||||
void startBulkPageDelete([...selectedAllPageIds], 'all');
|
||||
};
|
||||
|
||||
const selectedAchievementPageSet = useMemo(
|
||||
() => new Set(selectedAchievementPageIds),
|
||||
[selectedAchievementPageIds],
|
||||
);
|
||||
|
||||
const toggleAchievementPageSelected = (pageId: string, checked: boolean) => {
|
||||
setSelectedAchievementPageIds((ids) =>
|
||||
checked ? (ids.includes(pageId) ? ids : [...ids, pageId]) : ids.filter((id) => id !== pageId),
|
||||
);
|
||||
};
|
||||
|
||||
const toggleAchievementDateGroupSelected = (pageIds: string[], checked: boolean) => {
|
||||
setSelectedAchievementPageIds((ids) => {
|
||||
if (!checked) {
|
||||
const remove = new Set(pageIds);
|
||||
return ids.filter((id) => !remove.has(id));
|
||||
}
|
||||
return [...new Set([...ids, ...pageIds])];
|
||||
});
|
||||
};
|
||||
|
||||
const toggleAllAchievementPagesSelected = () => {
|
||||
const allSelected =
|
||||
achievementsItems.length > 0 &&
|
||||
achievementsItems.every((page) => selectedAchievementPageSet.has(page.id));
|
||||
if (allSelected) {
|
||||
const visibleIds = new Set(achievementsItems.map((page) => page.id));
|
||||
setSelectedAchievementPageIds((ids) => ids.filter((id) => !visibleIds.has(id)));
|
||||
return;
|
||||
}
|
||||
setSelectedAchievementPageIds((ids) => [
|
||||
...new Set([...ids, ...achievementsItems.map((page) => page.id)]),
|
||||
]);
|
||||
};
|
||||
|
||||
const removeSelectedAchievementPages = () => {
|
||||
void startBulkPageDelete([...selectedAchievementPageIds], 'achievements');
|
||||
};
|
||||
|
||||
const allPagesPageCount = Math.max(1, Math.ceil(allPagesTotal / ALL_PAGES_PAGE_SIZE));
|
||||
|
||||
const previewAsset = useMemo(
|
||||
@@ -1926,7 +2080,13 @@ export function MindSpaceView({
|
||||
);
|
||||
|
||||
const showHomeModules =
|
||||
space && !selectedCategory && !selectedPageId && !newPageOpen && !agentJobsPanelOpen && !allPagesOpen;
|
||||
space &&
|
||||
!selectedCategory &&
|
||||
!selectedPageId &&
|
||||
!newPageOpen &&
|
||||
!agentJobsPanelOpen &&
|
||||
!allPagesOpen &&
|
||||
!achievementsOpen;
|
||||
const rawUpcomingReminders = previewMode ? [] : space?.schedule?.upcomingReminders ?? [];
|
||||
const scheduleReminders = previewMode
|
||||
? PREVIEW_SCHEDULE_REMINDERS.map((item) => ({ ...item }))
|
||||
@@ -2066,7 +2226,7 @@ export function MindSpaceView({
|
||||
</header>
|
||||
|
||||
<main className="mindspace-content">
|
||||
{!allPagesOpen && (
|
||||
{!allPagesOpen && !achievementsOpen && (
|
||||
<section className="mindspace-hero">
|
||||
<div className="mindspace-hero-left">
|
||||
<p className="mindspace-eyebrow">MINDSPACE</p>
|
||||
@@ -2088,6 +2248,7 @@ export function MindSpaceView({
|
||||
setSelectedCategory(null);
|
||||
setSelectedPageId(null);
|
||||
setAllPagesOpen(false);
|
||||
setAchievementsOpen(false);
|
||||
setNewPageOpen(true);
|
||||
}}
|
||||
>
|
||||
@@ -2362,7 +2523,7 @@ export function MindSpaceView({
|
||||
<section className="mindspace-page-reader">
|
||||
<header className="mindspace-page-reader-bar">
|
||||
<button type="button" className="mindspace-inline-back" onClick={closePage}>
|
||||
{allPagesOpen ? '返回全部页面' : '返回空间首页'}
|
||||
{allPagesOpen ? '返回全部页面' : achievementsOpen ? '返回成果展示' : '返回空间首页'}
|
||||
</button>
|
||||
<span>站内浏览</span>
|
||||
</header>
|
||||
@@ -2444,6 +2605,29 @@ export function MindSpaceView({
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
) : achievementsOpen ? (
|
||||
<MindSpaceAchievementsPanel
|
||||
items={achievementsItems}
|
||||
total={achievementsTotal}
|
||||
loading={achievementsLoading}
|
||||
pageIndex={achievementsPageIndex}
|
||||
pageSize={ACHIEVEMENTS_PAGE_SIZE}
|
||||
selectedIds={selectedAchievementPageIds}
|
||||
deleting={bulkDeletingAchievements}
|
||||
deletingPageId={deletingPageId}
|
||||
onBack={closeAchievementsPanel}
|
||||
onOpenPage={(page) => void openPageViewInNewTab(page)}
|
||||
onShowPage={(pageId) => showPage(pageId)}
|
||||
onTogglePage={toggleAchievementPageSelected}
|
||||
onToggleDateGroup={toggleAchievementDateGroupSelected}
|
||||
onToggleAll={toggleAllAchievementPagesSelected}
|
||||
onClearSelection={() => setSelectedAchievementPageIds([])}
|
||||
onDeleteSelected={() => void removeSelectedAchievementPages()}
|
||||
onDeletePage={(page) => void openPageDeleteDialog(page)}
|
||||
onPrevPage={() => void loadAchievementsPage(achievementsPageIndex - 1)}
|
||||
onNextPage={() => void loadAchievementsPage(achievementsPageIndex + 1)}
|
||||
onFirstPage={() => void loadAchievementsPage(0)}
|
||||
/>
|
||||
) : allPagesOpen ? (
|
||||
<section className="mindspace-independent-page mindspace-all-pages">
|
||||
<div className="mindspace-section-heading">
|
||||
@@ -3023,6 +3207,17 @@ export function MindSpaceView({
|
||||
))}
|
||||
</div>
|
||||
<div className="mindspace-grid-secondary">
|
||||
<article className="mindspace-card mindspace-card-compact mindspace-card-achievements">
|
||||
<div className="mindspace-card-top">
|
||||
<span className="mindspace-card-code">SHOWCASE</span>
|
||||
<span>{recentPagesTotal} 项</span>
|
||||
</div>
|
||||
<h3>我的成果展示</h3>
|
||||
<p>按日期查看页面标题、创建/修改时间与访问数据。</p>
|
||||
<button type="button" onClick={openAchievementsPanel}>
|
||||
查看成果
|
||||
</button>
|
||||
</article>
|
||||
{space.categories
|
||||
.filter((category) => category.code === 'draft')
|
||||
.map((category) => (
|
||||
@@ -3048,7 +3243,7 @@ export function MindSpaceView({
|
||||
</section>
|
||||
)}
|
||||
|
||||
{!selectedCategory && !selectedPageId && !newPageOpen && !agentJobsPanelOpen && !allPagesOpen && (
|
||||
{!selectedCategory && !selectedPageId && !newPageOpen && !agentJobsPanelOpen && !allPagesOpen && !achievementsOpen && (
|
||||
<section className="mindspace-section mindspace-recent-work">
|
||||
<div className="mindspace-section-heading">
|
||||
<div>
|
||||
@@ -3433,7 +3628,7 @@ export function MindSpaceView({
|
||||
eyebrow="DELETE PAGES"
|
||||
className="mindspace-delete-dialog"
|
||||
disableClose={
|
||||
bulkPageDeleteLoading || bulkDeletingAllPages || bulkDeletingDraftPages
|
||||
bulkPageDeleteLoading || bulkDeletingAllPages || bulkDeletingDraftPages || bulkDeletingAchievements
|
||||
}
|
||||
>
|
||||
{bulkPageDeleteLoading && <div className="mindspace-state">正在分析连带内容…</div>}
|
||||
@@ -3460,7 +3655,7 @@ export function MindSpaceView({
|
||||
<button
|
||||
type="button"
|
||||
onClick={closeBulkPageDeleteDialog}
|
||||
disabled={bulkDeletingAllPages || bulkDeletingDraftPages}
|
||||
disabled={bulkDeletingAllPages || bulkDeletingDraftPages || bulkDeletingAchievements}
|
||||
>
|
||||
取消
|
||||
</button>
|
||||
@@ -3468,9 +3663,11 @@ export function MindSpaceView({
|
||||
type="button"
|
||||
className="mindspace-primary"
|
||||
onClick={() => void confirmBulkPageDelete()}
|
||||
disabled={bulkDeletingAllPages || bulkDeletingDraftPages}
|
||||
disabled={bulkDeletingAllPages || bulkDeletingDraftPages || bulkDeletingAchievements}
|
||||
>
|
||||
{bulkDeletingAllPages || bulkDeletingDraftPages ? '删除中…' : '确认删除'}
|
||||
{bulkDeletingAllPages || bulkDeletingDraftPages || bulkDeletingAchievements
|
||||
? '删除中…'
|
||||
: '确认删除'}
|
||||
</button>
|
||||
</div>
|
||||
</>
|
||||
|
||||
@@ -111,6 +111,8 @@ export const PREVIEW_PAGES: MindSpacePage[] = [
|
||||
currentVersionId: 'page-1-v2',
|
||||
versionNo: 2,
|
||||
contentFormat: 'markdown',
|
||||
viewCount: 86,
|
||||
clickCount: 5,
|
||||
createdAt: Date.now() - 172_800_000,
|
||||
updatedAt: Date.now() - 43_200_000,
|
||||
},
|
||||
@@ -130,6 +132,8 @@ export const PREVIEW_PAGES: MindSpacePage[] = [
|
||||
currentVersionId: 'page-2-v1',
|
||||
versionNo: 1,
|
||||
contentFormat: 'html',
|
||||
viewCount: 12,
|
||||
clickCount: 2,
|
||||
createdAt: Date.now() - 259_200_000,
|
||||
updatedAt: Date.now() - 86_400_000,
|
||||
},
|
||||
|
||||
+173
-81
@@ -58,6 +58,9 @@ import {
|
||||
buildAutoChatSkillPrefix,
|
||||
} from '../../chat-skills.mjs';
|
||||
import {
|
||||
buildQueuedChatSubmitNotice,
|
||||
canFlushQueuedChatSubmit,
|
||||
isChatSubmitBusy,
|
||||
reconcileSessionEventRequestContext,
|
||||
resolvePostAgentRunChatState,
|
||||
shouldIgnoreZeroActivityFinish,
|
||||
@@ -89,6 +92,24 @@ import {
|
||||
touchSession,
|
||||
} from '../utils/sessions';
|
||||
|
||||
type ChatSubmitOptions = {
|
||||
mindspaceContext?: MindSpaceChatContext;
|
||||
messageId?: string;
|
||||
forceDeepReasoning?: boolean;
|
||||
pgRequired?: boolean;
|
||||
imageGenerationMode?: ImageGenerationMode;
|
||||
selectedChatSkill?: string;
|
||||
fileAttachments?: ChatFileAttachment[];
|
||||
goalRunId?: string;
|
||||
};
|
||||
|
||||
type PendingChatSubmitEntry = {
|
||||
userMessage: Message;
|
||||
options?: ChatSubmitOptions;
|
||||
normalizedImageUrls: string[];
|
||||
normalizedFileAttachments: ChatFileAttachment[];
|
||||
};
|
||||
|
||||
const INSUFFICIENT_BALANCE_NOTICE = '余额不足,请充值后继续使用';
|
||||
const REPLY_RECOVERY_SYNC_DELAYS_MS = [1500, 5000, 12000];
|
||||
const FINISH_SYNC_RETRY_DELAYS_MS = [500, 1500, 3000];
|
||||
@@ -400,11 +421,18 @@ export function useTKMindChat(
|
||||
const onUserUpdateRef = useRef(onUserUpdate);
|
||||
const chatImageCategoryIdRef = useRef<string | null>(null);
|
||||
const chatFileCategoryIdRef = useRef<string | null>(null);
|
||||
const pendingSubmitQueueRef = useRef<PendingChatSubmitEntry[]>([]);
|
||||
const flushingPendingSubmitRef = useRef(false);
|
||||
const pendingToolRef = useRef<ToolConfirmation | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
chatStateRef.current = chatState;
|
||||
}, [chatState]);
|
||||
|
||||
useEffect(() => {
|
||||
pendingToolRef.current = pendingTool;
|
||||
}, [pendingTool]);
|
||||
|
||||
const clearActiveRequestMissingTimer = useCallback(() => {
|
||||
if (!activeRequestMissingTimerRef.current) return;
|
||||
window.clearTimeout(activeRequestMissingTimerRef.current);
|
||||
@@ -1175,6 +1203,8 @@ export function useTKMindChat(
|
||||
unsubscribeRef.current = null;
|
||||
subscribedSessionIdRef.current = null;
|
||||
clearActiveRequestMissingTimer();
|
||||
pendingSubmitQueueRef.current = [];
|
||||
flushingPendingSubmitRef.current = false;
|
||||
setError(null);
|
||||
setPendingTool(null);
|
||||
agentRunPendingRef.current = false;
|
||||
@@ -1478,84 +1508,23 @@ export function useTKMindChat(
|
||||
[session, chatState, connectSession, resetSessionView, sessions],
|
||||
);
|
||||
|
||||
const submit = useCallback(
|
||||
const executeAgentSubmit = useCallback(
|
||||
async (
|
||||
text: string,
|
||||
options?: {
|
||||
mindspaceContext?: MindSpaceChatContext;
|
||||
messageId?: string;
|
||||
forceDeepReasoning?: boolean;
|
||||
pgRequired?: boolean;
|
||||
imageGenerationMode?: ImageGenerationMode;
|
||||
selectedChatSkill?: string;
|
||||
fileAttachments?: ChatFileAttachment[];
|
||||
goalRunId?: string;
|
||||
},
|
||||
imageUrls?: string[],
|
||||
previewImageUrls?: string[],
|
||||
userMessage: Message,
|
||||
options: ChatSubmitOptions | undefined,
|
||||
normalizedImageUrls: string[],
|
||||
normalizedFileAttachments: ChatFileAttachment[],
|
||||
) => {
|
||||
const normalizedImageUrls = (imageUrls ?? []).filter((value) => typeof value === 'string' && value.trim());
|
||||
const normalizedPreviewImageUrls = (previewImageUrls ?? []).filter(
|
||||
(value) => typeof value === 'string' && value.trim(),
|
||||
);
|
||||
const normalizedFileAttachments = (options?.fileAttachments ?? []).filter(
|
||||
(item) => item?.downloadUrl?.trim() && item?.filename?.trim(),
|
||||
);
|
||||
if (!text.trim() && normalizedImageUrls.length === 0 && normalizedFileAttachments.length === 0) return;
|
||||
// Use the ref here (not the React state) so that rapid back-to-back calls in the
|
||||
// same render cycle are blocked even before the state update has been re-rendered.
|
||||
if (
|
||||
chatStateRef.current === 'streaming' ||
|
||||
chatStateRef.current === 'loading' ||
|
||||
chatStateRef.current === 'connecting' ||
|
||||
chatStateRef.current === 'waiting'
|
||||
) return;
|
||||
|
||||
const trimmed = text.trim();
|
||||
const mindspacePrefix = options?.mindspaceContext
|
||||
? buildContextPrefix(options.mindspaceContext)
|
||||
: '';
|
||||
const userPrefix = buildUserAddressPrefix(userRef.current);
|
||||
const skillPrefix = buildAutoChatSkillPrefix(trimmed, grantedSkills ?? []);
|
||||
const pgContractPrefix = options?.pgRequired
|
||||
? '[交付约束:用户已明确要求使用专属 PostgreSQL 数据空间。若生成页面,必须按 page-data-collect 完成建表、dataset、policy 和 workspace page 绑定;禁止 localStorage、SQLite、静态 JSON 或内存持久化。所有验证通过前不得回复已发布或给出页面链接。]\n'
|
||||
: '';
|
||||
const agentPrefix = `${userPrefix}${mindspacePrefix}${skillPrefix}${pgContractPrefix}`;
|
||||
const priorMessageCount = messagesRef.current.length;
|
||||
const userMessage = buildUserMessage(trimmed, {
|
||||
id: options?.messageId,
|
||||
agentText: `${agentPrefix}${trimmed}`,
|
||||
displayText: trimmed,
|
||||
imageUrls: normalizedImageUrls,
|
||||
previewImageUrls: normalizedPreviewImageUrls,
|
||||
fileAttachments: normalizedFileAttachments,
|
||||
});
|
||||
userMessage.metadata = {
|
||||
...userMessage.metadata,
|
||||
memindRun: {
|
||||
...(userMessage.metadata?.memindRun && typeof userMessage.metadata.memindRun === 'object'
|
||||
? userMessage.metadata.memindRun
|
||||
: {}),
|
||||
sessionMessageCount: priorMessageCount,
|
||||
...(options?.pgRequired ? { pgRequired: true } : {}),
|
||||
imageGenerationMode: options?.imageGenerationMode ?? 'auto',
|
||||
...(options?.selectedChatSkill ? { selectedChatSkill: options.selectedChatSkill } : {}),
|
||||
},
|
||||
};
|
||||
const trimmed = getDisplayText(userMessage).trim();
|
||||
const requestId = crypto.randomUUID();
|
||||
const submitToken = connectTokenRef.current;
|
||||
activeRequestId.current = requestId;
|
||||
messagesRef.current = [...messagesRef.current, userMessage];
|
||||
messageHistoryLoadedCountRef.current = messagesRef.current.length;
|
||||
setMessages(messagesRef.current);
|
||||
setChatState('waiting');
|
||||
// Immediately reflect in the ref so any synchronous re-entry is blocked before
|
||||
// the next React render cycle runs the useEffect that normally syncs this ref.
|
||||
chatStateRef.current = 'waiting';
|
||||
setError(null);
|
||||
setPendingTool(null);
|
||||
|
||||
let activeSessionId = session?.id ?? null;
|
||||
let activeSessionId = sessionRef.current?.id ?? null;
|
||||
|
||||
if (activeSessionId) {
|
||||
setSessions((prev) => touchSession(prev, activeSessionId!, 1));
|
||||
@@ -1634,14 +1603,15 @@ export function useTKMindChat(
|
||||
});
|
||||
if (submitToken !== connectTokenRef.current) return;
|
||||
agentRunPendingRef.current = false;
|
||||
activeSessionId = finishedRun.sessionId;
|
||||
activeSessionId = finishedRun.sessionId ?? activeSessionId;
|
||||
if (!activeSessionId) {
|
||||
throw new Error('后台任务已提交,但未返回会话');
|
||||
}
|
||||
if (normalizedImageUrls.length > 0 || normalizedFileAttachments.length > 0) {
|
||||
void claimMindSpaceConversationUploads(activeSessionId, userMessage.id).catch(() => {});
|
||||
}
|
||||
if (!session?.id || session.id !== activeSessionId) {
|
||||
const currentSessionId = sessionRef.current?.id ?? null;
|
||||
if (!currentSessionId || currentSessionId !== activeSessionId) {
|
||||
const nextSession: Session = {
|
||||
id: activeSessionId,
|
||||
name: 'New Chat',
|
||||
@@ -1700,10 +1670,6 @@ export function useTKMindChat(
|
||||
const nextChatState = resolvePostAgentRunChatState({
|
||||
chatState: chatStateRef.current,
|
||||
finishedViaPortalDirectChat,
|
||||
// The agent-run result is authoritative even when the immediate
|
||||
// session snapshot has not yet carried portal-direct metadata.
|
||||
// Without this, a completed Page Data task can re-enter streaming
|
||||
// and leave the Stop button attached to no active request.
|
||||
agentRunSucceeded: finishedRun.status === 'succeeded',
|
||||
});
|
||||
if (nextChatState === 'idle') {
|
||||
@@ -1735,9 +1701,6 @@ export function useTKMindChat(
|
||||
errorCode(err),
|
||||
)
|
||||
) {
|
||||
// Goose may report its session concurrency guard as a failed run
|
||||
// message instead of an HTTP 409. Reattach to the session stream
|
||||
// and reconcile the snapshot; do not strand the composer in error.
|
||||
subscribeToSession(activeSessionId);
|
||||
setChatState('streaming');
|
||||
setError(null);
|
||||
@@ -1745,7 +1708,9 @@ export function useTKMindChat(
|
||||
return;
|
||||
}
|
||||
agentRunPendingRef.current = false;
|
||||
if (session && activeSessionId) setSessions((prev) => touchSession(prev, activeSessionId!, -1));
|
||||
if (sessionRef.current && activeSessionId) {
|
||||
setSessions((prev) => touchSession(prev, activeSessionId!, -1));
|
||||
}
|
||||
if (err instanceof ApiError && err.status === 402) {
|
||||
notifyInsufficientBalance();
|
||||
} else {
|
||||
@@ -1758,18 +1723,143 @@ export function useTKMindChat(
|
||||
},
|
||||
[
|
||||
notifyInsufficientBalance,
|
||||
session,
|
||||
grantedSkills,
|
||||
clearActiveRequestMissingTimer,
|
||||
subscribeToSession,
|
||||
scheduleReplyRecoverySync,
|
||||
ensureProvider,
|
||||
loadProjectMemory,
|
||||
refreshSessions,
|
||||
syncSessionMessages,
|
||||
],
|
||||
);
|
||||
|
||||
const flushPendingSubmitQueue = useCallback(async () => {
|
||||
if (flushingPendingSubmitRef.current) return;
|
||||
if (
|
||||
!canFlushQueuedChatSubmit({
|
||||
chatState: chatStateRef.current,
|
||||
agentRunPending: agentRunPendingRef.current,
|
||||
pendingTool: Boolean(pendingToolRef.current),
|
||||
queueLength: pendingSubmitQueueRef.current.length,
|
||||
})
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const next = pendingSubmitQueueRef.current.shift();
|
||||
if (!next) return;
|
||||
|
||||
flushingPendingSubmitRef.current = true;
|
||||
try {
|
||||
await executeAgentSubmit(
|
||||
next.userMessage,
|
||||
next.options,
|
||||
next.normalizedImageUrls,
|
||||
next.normalizedFileAttachments,
|
||||
);
|
||||
} finally {
|
||||
flushingPendingSubmitRef.current = false;
|
||||
if (
|
||||
canFlushQueuedChatSubmit({
|
||||
chatState: chatStateRef.current,
|
||||
agentRunPending: agentRunPendingRef.current,
|
||||
pendingTool: Boolean(pendingToolRef.current),
|
||||
queueLength: pendingSubmitQueueRef.current.length,
|
||||
})
|
||||
) {
|
||||
void flushPendingSubmitQueue();
|
||||
}
|
||||
}
|
||||
}, [executeAgentSubmit]);
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
!canFlushQueuedChatSubmit({
|
||||
chatState,
|
||||
agentRunPending: agentRunPendingRef.current,
|
||||
pendingTool: Boolean(pendingTool),
|
||||
queueLength: pendingSubmitQueueRef.current.length,
|
||||
})
|
||||
) {
|
||||
return;
|
||||
}
|
||||
void flushPendingSubmitQueue();
|
||||
}, [chatState, pendingTool, flushPendingSubmitQueue]);
|
||||
|
||||
const submit = useCallback(
|
||||
async (
|
||||
text: string,
|
||||
options?: ChatSubmitOptions,
|
||||
imageUrls?: string[],
|
||||
previewImageUrls?: string[],
|
||||
) => {
|
||||
const normalizedImageUrls = (imageUrls ?? []).filter((value) => typeof value === 'string' && value.trim());
|
||||
const normalizedPreviewImageUrls = (previewImageUrls ?? []).filter(
|
||||
(value) => typeof value === 'string' && value.trim(),
|
||||
);
|
||||
const normalizedFileAttachments = (options?.fileAttachments ?? []).filter(
|
||||
(item) => item?.downloadUrl?.trim() && item?.filename?.trim(),
|
||||
);
|
||||
if (!text.trim() && normalizedImageUrls.length === 0 && normalizedFileAttachments.length === 0) return;
|
||||
|
||||
const trimmed = text.trim();
|
||||
const mindspacePrefix = options?.mindspaceContext
|
||||
? buildContextPrefix(options.mindspaceContext)
|
||||
: '';
|
||||
const userPrefix = buildUserAddressPrefix(userRef.current);
|
||||
const skillPrefix = buildAutoChatSkillPrefix(trimmed, grantedSkills ?? []);
|
||||
const pgContractPrefix = options?.pgRequired
|
||||
? '[交付约束:用户已明确要求使用专属 PostgreSQL 数据空间。若生成页面,必须按 page-data-collect 完成建表、dataset、policy 和 workspace page 绑定;禁止 localStorage、SQLite、静态 JSON 或内存持久化。所有验证通过前不得回复已发布或给出页面链接。]\n'
|
||||
: '';
|
||||
const agentPrefix = `${userPrefix}${mindspacePrefix}${skillPrefix}${pgContractPrefix}`;
|
||||
const priorMessageCount = messagesRef.current.length;
|
||||
const userMessage = buildUserMessage(trimmed, {
|
||||
id: options?.messageId,
|
||||
agentText: `${agentPrefix}${trimmed}`,
|
||||
displayText: trimmed,
|
||||
imageUrls: normalizedImageUrls,
|
||||
previewImageUrls: normalizedPreviewImageUrls,
|
||||
fileAttachments: normalizedFileAttachments,
|
||||
});
|
||||
userMessage.metadata = {
|
||||
...userMessage.metadata,
|
||||
memindRun: {
|
||||
...(userMessage.metadata?.memindRun && typeof userMessage.metadata.memindRun === 'object'
|
||||
? userMessage.metadata.memindRun
|
||||
: {}),
|
||||
sessionMessageCount: priorMessageCount,
|
||||
...(options?.pgRequired ? { pgRequired: true } : {}),
|
||||
imageGenerationMode: options?.imageGenerationMode ?? 'auto',
|
||||
...(options?.selectedChatSkill ? { selectedChatSkill: options.selectedChatSkill } : {}),
|
||||
},
|
||||
};
|
||||
|
||||
if (isChatSubmitBusy(chatStateRef.current)) {
|
||||
pendingSubmitQueueRef.current.push({
|
||||
userMessage,
|
||||
options,
|
||||
normalizedImageUrls,
|
||||
normalizedFileAttachments,
|
||||
});
|
||||
messagesRef.current = [...messagesRef.current, userMessage];
|
||||
messageHistoryLoadedCountRef.current = messagesRef.current.length;
|
||||
setMessages(messagesRef.current);
|
||||
setNotice(buildQueuedChatSubmitNotice(pendingSubmitQueueRef.current.length));
|
||||
return;
|
||||
}
|
||||
|
||||
messagesRef.current = [...messagesRef.current, userMessage];
|
||||
messageHistoryLoadedCountRef.current = messagesRef.current.length;
|
||||
setMessages(messagesRef.current);
|
||||
await executeAgentSubmit(
|
||||
userMessage,
|
||||
options,
|
||||
normalizedImageUrls,
|
||||
normalizedFileAttachments,
|
||||
);
|
||||
},
|
||||
[executeAgentSubmit, grantedSkills],
|
||||
);
|
||||
|
||||
const stop = useCallback(async () => {
|
||||
if (!session || !activeRequestId.current) return;
|
||||
try {
|
||||
@@ -1894,6 +1984,8 @@ export function useTKMindChat(
|
||||
clearStoredSessionId(userRef.current?.id);
|
||||
agentRunPendingRef.current = false;
|
||||
activeRequestId.current = null;
|
||||
pendingSubmitQueueRef.current = [];
|
||||
flushingPendingSubmitRef.current = false;
|
||||
messagesRef.current = [];
|
||||
messageHistoryLoadedCountRef.current = 0;
|
||||
messageHistoryTotalRef.current = 0;
|
||||
|
||||
+206
@@ -7964,6 +7964,212 @@ body,
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.mindspace-achievements-intro {
|
||||
margin: 0 0 18px;
|
||||
color: rgba(24, 33, 29, 0.72);
|
||||
font-size: 14px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.mindspace-achievements-bulkbar {
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
|
||||
.mindspace-achievements-bulkbar .mindspace-achievements-back-page {
|
||||
margin-left: auto;
|
||||
padding: 5px 11px;
|
||||
border: 1px solid rgba(47, 111, 87, 0.18);
|
||||
border-radius: 999px;
|
||||
color: #2f6f57;
|
||||
background: rgba(235, 248, 240, 0.72);
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.mindspace-achievements-bulkbar .mindspace-achievements-back-page:disabled {
|
||||
opacity: 0.45;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.mindspace-achievements-pagination {
|
||||
gap: 10px;
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.mindspace-achievements-pagination button {
|
||||
padding: 5px 11px;
|
||||
border: 1px solid rgba(24, 33, 29, 0.1);
|
||||
border-radius: 999px;
|
||||
background: rgba(255, 252, 244, 0.92);
|
||||
color: #2f6f57;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.mindspace-achievements-pagination span {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.mindspace-achievements-groups {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 22px;
|
||||
}
|
||||
|
||||
.mindspace-achievements-group h3 {
|
||||
margin: 0;
|
||||
font-size: 16px;
|
||||
font-weight: 700;
|
||||
color: #18211d;
|
||||
}
|
||||
|
||||
.mindspace-achievements-group-heading {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.mindspace-achievements-group-select {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 13px;
|
||||
color: rgba(24, 33, 29, 0.72);
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.mindspace-achievements-group-select input {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
accent-color: #2f6f57;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.mindspace-achievements-col-select {
|
||||
width: 52px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.mindspace-achievements-col-select input {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
accent-color: #2f6f57;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.mindspace-achievements-delete-link {
|
||||
padding: 0;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: #9b3d2f;
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
text-decoration: underline;
|
||||
text-underline-offset: 2px;
|
||||
}
|
||||
|
||||
.mindspace-achievements-delete-link:disabled {
|
||||
opacity: 0.55;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.mindspace-achievements-load-more {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
padding: 18px 0 8px;
|
||||
color: rgba(24, 33, 29, 0.62);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.mindspace-achievements-load-more button {
|
||||
padding: 8px 14px;
|
||||
border: 1px solid rgba(47, 111, 87, 0.24);
|
||||
border-radius: 999px;
|
||||
background: rgba(235, 248, 240, 0.8);
|
||||
color: #1f4f3d;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.mindspace-achievements-table-wrap {
|
||||
overflow-x: auto;
|
||||
border: 1px solid rgba(24, 33, 29, 0.08);
|
||||
border-radius: 16px;
|
||||
background: rgba(255, 252, 244, 0.92);
|
||||
}
|
||||
|
||||
.mindspace-achievements-table {
|
||||
width: 100%;
|
||||
min-width: 760px;
|
||||
border-collapse: collapse;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.mindspace-achievements-table th,
|
||||
.mindspace-achievements-table td {
|
||||
padding: 12px 14px;
|
||||
border-bottom: 1px solid rgba(24, 33, 29, 0.08);
|
||||
text-align: left;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.mindspace-achievements-table th {
|
||||
color: rgba(24, 33, 29, 0.62);
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.04em;
|
||||
text-transform: uppercase;
|
||||
background: rgba(245, 240, 229, 0.72);
|
||||
}
|
||||
|
||||
.mindspace-achievements-table tbody tr:last-child td {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.mindspace-achievements-title {
|
||||
min-width: 220px;
|
||||
}
|
||||
|
||||
.mindspace-achievements-title-link {
|
||||
display: inline;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: #2f6f57;
|
||||
font: inherit;
|
||||
font-weight: 700;
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
text-decoration: underline;
|
||||
text-underline-offset: 2px;
|
||||
}
|
||||
|
||||
.mindspace-achievements-title-link:hover {
|
||||
color: #1f4f3d;
|
||||
}
|
||||
|
||||
.mindspace-achievements-detail-link {
|
||||
display: inline-block;
|
||||
margin-left: 10px;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: rgba(24, 33, 29, 0.56);
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
text-decoration: underline;
|
||||
text-underline-offset: 2px;
|
||||
}
|
||||
|
||||
.mindspace-card-achievements {
|
||||
border-color: rgba(47, 111, 87, 0.18);
|
||||
background: linear-gradient(180deg, rgba(235, 248, 240, 0.92), rgba(255, 252, 244, 0.96));
|
||||
}
|
||||
|
||||
.mindspace-all-pages .mindspace-feed-card-wrap {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
@@ -20,6 +20,7 @@ export function MindSpaceRoute({
|
||||
const location = useLocation();
|
||||
const [searchParams] = useSearchParams();
|
||||
const pageMatch = matchPath('/space/page/:pageId', location.pathname);
|
||||
const achievementsMatch = matchPath('/space/achievements', location.pathname);
|
||||
const pageId = pageMatch?.params.pageId ?? null;
|
||||
const categoryCode = parseCategory(searchParams.get('category'));
|
||||
|
||||
@@ -28,11 +29,13 @@ export function MindSpaceRoute({
|
||||
user={user}
|
||||
initialPageId={pageId}
|
||||
initialCategoryCode={categoryCode}
|
||||
initialAchievementsOpen={Boolean(achievementsMatch)}
|
||||
onBack={() => navigate('/')}
|
||||
onLogout={onLogout}
|
||||
onOpenFeedback={() => navigate('/feedback')}
|
||||
routeSync={{
|
||||
pushHome: () => navigate('/space'),
|
||||
pushAchievements: () => navigate('/space/achievements'),
|
||||
pushCategory: (code) => navigate(`/space?category=${code}`),
|
||||
pushPage: (id) => navigate(`/space/page/${id}`),
|
||||
}}
|
||||
|
||||
@@ -870,6 +870,12 @@ export type MindSpacePage = {
|
||||
status: 'draft' | 'reviewing' | 'risk_found' | 'ready' | 'published' | 'protected' | 'expired' | 'offline';
|
||||
visibility: 'private' | 'internal' | 'public';
|
||||
publicationAccessMode?: 'public' | 'password' | 'private_link' | 'time_limited' | 'login_required' | 'owner_only' | null;
|
||||
publicationId?: string | null;
|
||||
publicationStatus?: string | null;
|
||||
viewCount?: number;
|
||||
clickCount?: number | null;
|
||||
statsSource?: 'none' | 'publication' | 'umami';
|
||||
publishedAt?: number | null;
|
||||
publicationUrl?: string | null;
|
||||
workspaceRelativePath?: string | null;
|
||||
workspacePublicUrl?: string | null;
|
||||
|
||||
Reference in New Issue
Block a user