dsh-fulltext 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/LICENSE +21 -0
- package/README.md +77 -2
- package/README_CN.md +78 -0
- package/RELEASING.md +17 -0
- package/assets/icon.svg +1 -0
- package/assets/report.css +588 -0
- package/assets/report.html +354 -0
- package/cordis.patch.yml +3 -0
- package/lib/client-types/client/Workspace.d.ts +14 -0
- package/lib/client-types/client/controller.d.ts +57 -0
- package/lib/client-types/client/credentials-port.d.ts +94 -0
- package/lib/client-types/client/handoff.d.ts +7 -0
- package/lib/client-types/client/index.d.ts +3 -0
- package/lib/client-types/client/styles.d.ts +1 -0
- package/lib/client-types/shared/types.d.ts +59 -0
- package/lib/client.js +938 -0
- package/lib/client.js.map +1 -0
- package/lib/index.d.ts +14 -0
- package/lib/index.js +53 -0
- package/lib/report.d.ts +6 -0
- package/lib/report.js +69 -0
- package/lib/routes.d.ts +18 -0
- package/lib/routes.js +62 -0
- package/lib/search.d.ts +16 -0
- package/lib/search.js +147 -0
- package/lib/shared/types.d.ts +59 -0
- package/lib/shared/types.js +23 -0
- package/lib/store.d.ts +13 -0
- package/lib/store.js +59 -0
- package/lib/tools.d.ts +4 -0
- package/lib/tools.js +122 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +114 -4
package/lib/client.js
ADDED
|
@@ -0,0 +1,938 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: "dsh-fulltext",
|
|
3
|
+
factory: (require) => {
|
|
4
|
+
var module = { exports: {} };
|
|
5
|
+
var exports = module.exports;
|
|
6
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
7
|
+
let react = require("react");
|
|
8
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
9
|
+
//#region src/shared/types.ts
|
|
10
|
+
const ROUTE = "/api/fulltext";
|
|
11
|
+
const PANEL = "fulltext";
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/client/controller.ts
|
|
14
|
+
const request = async (path, signal, body) => {
|
|
15
|
+
const response = await fetch(new URL(path.replace(/^\//, ""), document.baseURI), {
|
|
16
|
+
method: body === void 0 ? "GET" : "POST",
|
|
17
|
+
credentials: "same-origin",
|
|
18
|
+
cache: "no-store",
|
|
19
|
+
signal,
|
|
20
|
+
...body === void 0 ? {} : {
|
|
21
|
+
headers: { "Content-Type": "application/json" },
|
|
22
|
+
body: JSON.stringify(body)
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
if (!response.headers.get("content-type")?.includes("application/json")) throw new Error(`全文搜索暂不可用(HTTP ${response.status})。`);
|
|
26
|
+
return response.json();
|
|
27
|
+
};
|
|
28
|
+
/** Persistent in-memory UI state; saved reports themselves live on the host. */
|
|
29
|
+
var Controller = class {
|
|
30
|
+
credentials;
|
|
31
|
+
fetcher;
|
|
32
|
+
state = {
|
|
33
|
+
reports: [],
|
|
34
|
+
draft: {
|
|
35
|
+
query: "",
|
|
36
|
+
limit: 10,
|
|
37
|
+
enrich: true
|
|
38
|
+
},
|
|
39
|
+
loading: true,
|
|
40
|
+
busy: false,
|
|
41
|
+
keyBusy: false
|
|
42
|
+
};
|
|
43
|
+
listeners = /* @__PURE__ */ new Set();
|
|
44
|
+
active;
|
|
45
|
+
refreshRequest;
|
|
46
|
+
first = true;
|
|
47
|
+
disposed = false;
|
|
48
|
+
revision = 0;
|
|
49
|
+
constructor(credentials, fetcher = request) {
|
|
50
|
+
this.credentials = credentials;
|
|
51
|
+
this.fetcher = fetcher;
|
|
52
|
+
}
|
|
53
|
+
getSnapshot = () => this.state;
|
|
54
|
+
subscribe = (listener) => {
|
|
55
|
+
this.listeners.add(listener);
|
|
56
|
+
return () => this.listeners.delete(listener);
|
|
57
|
+
};
|
|
58
|
+
set(patch) {
|
|
59
|
+
if (this.disposed) return;
|
|
60
|
+
this.state = {
|
|
61
|
+
...this.state,
|
|
62
|
+
...patch
|
|
63
|
+
};
|
|
64
|
+
this.listeners.forEach((l) => l());
|
|
65
|
+
}
|
|
66
|
+
edit(patch) {
|
|
67
|
+
this.first = false;
|
|
68
|
+
this.set({
|
|
69
|
+
draft: {
|
|
70
|
+
...this.state.draft,
|
|
71
|
+
...patch
|
|
72
|
+
},
|
|
73
|
+
error: void 0,
|
|
74
|
+
message: void 0
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
select(id) {
|
|
78
|
+
const selected = this.state.reports.find((r) => r.id === id);
|
|
79
|
+
if (selected) this.set({
|
|
80
|
+
selected,
|
|
81
|
+
error: void 0,
|
|
82
|
+
message: void 0
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
newSearch() {
|
|
86
|
+
this.set({
|
|
87
|
+
selected: void 0,
|
|
88
|
+
error: void 0,
|
|
89
|
+
message: void 0
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
async attach() {
|
|
93
|
+
this.refreshRequest?.abort();
|
|
94
|
+
const control = new AbortController(), revision = this.revision;
|
|
95
|
+
this.refreshRequest = control;
|
|
96
|
+
this.set({ loading: true });
|
|
97
|
+
try {
|
|
98
|
+
const reply = await this.fetcher(ROUTE, control.signal);
|
|
99
|
+
if (control.signal.aborted || this.disposed) return;
|
|
100
|
+
if (!reply.ok) throw new Error(reply.error);
|
|
101
|
+
const catalog = reply.value;
|
|
102
|
+
const reports = revision === this.revision ? catalog.reports : this.state.reports;
|
|
103
|
+
const selected = this.state.selected ? reports.find((r) => r.id === this.state.selected.id) ?? this.state.selected : void 0;
|
|
104
|
+
this.set({
|
|
105
|
+
catalog,
|
|
106
|
+
reports,
|
|
107
|
+
selected,
|
|
108
|
+
...this.first ? { draft: {
|
|
109
|
+
...this.state.draft,
|
|
110
|
+
limit: catalog.defaultLimit
|
|
111
|
+
} } : {},
|
|
112
|
+
error: void 0
|
|
113
|
+
});
|
|
114
|
+
this.first = false;
|
|
115
|
+
} catch (error) {
|
|
116
|
+
if (!control.signal.aborted) this.set({ error: error instanceof Error ? error.message : "读取报告失败。" });
|
|
117
|
+
} finally {
|
|
118
|
+
if (this.refreshRequest === control) {
|
|
119
|
+
this.refreshRequest = void 0;
|
|
120
|
+
this.set({ loading: false });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async search() {
|
|
125
|
+
if (this.state.busy || this.state.loading || !this.state.draft.query.trim()) return;
|
|
126
|
+
const control = new AbortController();
|
|
127
|
+
this.active = control;
|
|
128
|
+
this.set({
|
|
129
|
+
busy: true,
|
|
130
|
+
error: void 0,
|
|
131
|
+
message: void 0
|
|
132
|
+
});
|
|
133
|
+
try {
|
|
134
|
+
const reply = await this.fetcher(ROUTE + "/search", control.signal, this.state.draft);
|
|
135
|
+
if (control.signal.aborted || this.disposed || this.active !== control) return;
|
|
136
|
+
if (!reply.ok) throw new Error(reply.error);
|
|
137
|
+
this.revision++;
|
|
138
|
+
this.set({
|
|
139
|
+
reports: [reply.value, ...this.state.reports.filter((r) => r.id !== reply.value.id)].slice(0, 100),
|
|
140
|
+
selected: reply.value
|
|
141
|
+
});
|
|
142
|
+
} catch (error) {
|
|
143
|
+
if (!control.signal.aborted) this.set({ error: error instanceof Error ? error.message : "检索失败。" });
|
|
144
|
+
} finally {
|
|
145
|
+
if (this.active === control) {
|
|
146
|
+
this.active = void 0;
|
|
147
|
+
this.set({ busy: false });
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
cancel() {
|
|
152
|
+
this.active?.abort();
|
|
153
|
+
this.active = void 0;
|
|
154
|
+
this.set({
|
|
155
|
+
busy: false,
|
|
156
|
+
message: "已停止等待;已发出的接口请求仍可能计费。"
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
notify(message) {
|
|
160
|
+
this.set({ message });
|
|
161
|
+
}
|
|
162
|
+
async saveKey(text) {
|
|
163
|
+
if (!text.trim() || this.state.keyBusy || !this.state.catalog) return false;
|
|
164
|
+
this.set({
|
|
165
|
+
keyBusy: true,
|
|
166
|
+
error: void 0,
|
|
167
|
+
message: void 0
|
|
168
|
+
});
|
|
169
|
+
try {
|
|
170
|
+
const port = this.credentials(), ref = this.state.catalog.keyRef;
|
|
171
|
+
if ((await port.describe(ref))?.writable === false) throw new Error("独立 Key 由环境变量或只读来源管理,请在启动环境中修改。");
|
|
172
|
+
await port.set(ref, text.trim());
|
|
173
|
+
await this.attach();
|
|
174
|
+
this.set({ message: "独立 API Key 已保存。" });
|
|
175
|
+
return true;
|
|
176
|
+
} catch (error) {
|
|
177
|
+
this.set({ error: error instanceof Error ? error.message : "保存失败。" });
|
|
178
|
+
return false;
|
|
179
|
+
} finally {
|
|
180
|
+
this.set({ keyBusy: false });
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
async removeKey() {
|
|
184
|
+
if (!this.state.catalog || this.state.keyBusy) return;
|
|
185
|
+
this.set({
|
|
186
|
+
keyBusy: true,
|
|
187
|
+
error: void 0
|
|
188
|
+
});
|
|
189
|
+
try {
|
|
190
|
+
const port = this.credentials(), ref = this.state.catalog.keyRef;
|
|
191
|
+
if ((await port.describe(ref))?.writable === false) throw new Error("独立 Key 由环境变量或只读来源管理,请在启动环境中移除。");
|
|
192
|
+
await port.unset(ref);
|
|
193
|
+
await this.attach();
|
|
194
|
+
this.set({ message: "已移除独立 Key;如已配置 Ai4Scholar,将自动使用其 Key。" });
|
|
195
|
+
} catch (error) {
|
|
196
|
+
this.set({ error: error instanceof Error ? error.message : "移除失败。" });
|
|
197
|
+
} finally {
|
|
198
|
+
this.set({ keyBusy: false });
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
dispose() {
|
|
202
|
+
this.disposed = true;
|
|
203
|
+
this.active?.abort();
|
|
204
|
+
this.refreshRequest?.abort();
|
|
205
|
+
this.listeners.clear();
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
//#endregion
|
|
209
|
+
//#region src/client/credentials-port.ts
|
|
210
|
+
/** Narrow an unknown to something with a readable property, without `any`. */
|
|
211
|
+
const at = (host, key) => typeof host === "object" && host !== null ? host[key] : void 0;
|
|
212
|
+
/** Whether every named member of a candidate face is callable. */
|
|
213
|
+
const callable = (face, methods) => methods.every((m) => typeof at(face, m) === "function");
|
|
214
|
+
/** The credential methods both contracts expose, under either calling convention. */
|
|
215
|
+
const METHODS = [
|
|
216
|
+
"describe",
|
|
217
|
+
"set",
|
|
218
|
+
"unset"
|
|
219
|
+
];
|
|
220
|
+
/**
|
|
221
|
+
* Error message for the case no host should produce: neither face present.
|
|
222
|
+
* Names both the surface and its version, because the answer differs per build
|
|
223
|
+
* of the same app and the version is what a bug report needs.
|
|
224
|
+
*/
|
|
225
|
+
var NoCredentialsFace = class extends Error {
|
|
226
|
+
constructor() {
|
|
227
|
+
super("this dsh build exposes no credentials API (neither connection.api.credentials nor the remote.credentials service) — the plugin cannot store the key here");
|
|
228
|
+
this.name = "NoCredentialsFace";
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
/**
|
|
232
|
+
* Read `{ok, value}` off either envelope depth.
|
|
233
|
+
*
|
|
234
|
+
* Stable nests the result one level down (`response.result`) and alpha does not,
|
|
235
|
+
* so the depth is probed rather than assumed: a future build that changes only
|
|
236
|
+
* the nesting keeps working.
|
|
237
|
+
* @param response - whatever the call returned.
|
|
238
|
+
* @returns the unwrapped outcome.
|
|
239
|
+
*/
|
|
240
|
+
function unwrap(response) {
|
|
241
|
+
const envelope = at(response, "result") ?? response;
|
|
242
|
+
const ok = at(envelope, "ok");
|
|
243
|
+
return {
|
|
244
|
+
ok: ok === void 0 ? true : ok === true,
|
|
245
|
+
value: at(envelope, "value"),
|
|
246
|
+
error: at(envelope, "error")
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Throw when a call reported failure, preserving the Host's own message.
|
|
251
|
+
* @param response - whatever the call returned.
|
|
252
|
+
* @param what - the operation, for the fallback message.
|
|
253
|
+
* @returns the unwrapped value on success.
|
|
254
|
+
*/
|
|
255
|
+
function orThrow(response, what) {
|
|
256
|
+
const { ok, value, error } = unwrap(response);
|
|
257
|
+
if (ok) return value;
|
|
258
|
+
if (error instanceof Error) throw error;
|
|
259
|
+
const message = at(error, "message");
|
|
260
|
+
throw new Error(typeof message === "string" ? message : `credentials ${what} failed`);
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* The stable face: object arguments, `result` envelope, views under a
|
|
264
|
+
* `credentials` key.
|
|
265
|
+
* @param credentials - `connection.api.credentials`.
|
|
266
|
+
* @returns a port speaking the ≤0.1.1-rc.2 contract.
|
|
267
|
+
*/
|
|
268
|
+
function legacyPort(credentials) {
|
|
269
|
+
return {
|
|
270
|
+
async describe(ref) {
|
|
271
|
+
const value = orThrow(await credentials.describe({ refs: [ref] }), "describe");
|
|
272
|
+
return at(at(value, "credentials"), ref);
|
|
273
|
+
},
|
|
274
|
+
async set(ref, value) {
|
|
275
|
+
orThrow(await credentials.set({
|
|
276
|
+
ref,
|
|
277
|
+
value
|
|
278
|
+
}), "set");
|
|
279
|
+
},
|
|
280
|
+
async unset(ref) {
|
|
281
|
+
orThrow(await credentials.unset({ ref }), "unset");
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* The alpha face: positional arguments, bare envelope, views keyed by reference.
|
|
287
|
+
* @param credentials - `ctx.remote.credentials`.
|
|
288
|
+
* @returns a port speaking the ≥0.1.2-alpha contract.
|
|
289
|
+
*/
|
|
290
|
+
function modernPort(credentials) {
|
|
291
|
+
return {
|
|
292
|
+
async describe(ref) {
|
|
293
|
+
const value = orThrow(await credentials.describe([ref]), "describe");
|
|
294
|
+
return at(value, ref);
|
|
295
|
+
},
|
|
296
|
+
async set(ref, value) {
|
|
297
|
+
orThrow(await credentials.set(ref, value), "set");
|
|
298
|
+
},
|
|
299
|
+
async unset(ref) {
|
|
300
|
+
orThrow(await credentials.unset(ref), "unset");
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Pick the face this host actually has.
|
|
306
|
+
*
|
|
307
|
+
* The alpha face is preferred: a host carrying both is mid-migration, and the
|
|
308
|
+
* newer face is the one it will keep.
|
|
309
|
+
* @param faces - the two candidate faces, as resolved from the client context.
|
|
310
|
+
* @returns a port for whichever contract is present.
|
|
311
|
+
* @throws NoCredentialsFace when neither is.
|
|
312
|
+
*/
|
|
313
|
+
function resolveCredentialsPort(faces) {
|
|
314
|
+
const modern = faces.remoteCredentials;
|
|
315
|
+
if (callable(modern, METHODS)) return modernPort(modern);
|
|
316
|
+
const legacy = at(at(faces.connection, "api"), "credentials");
|
|
317
|
+
if (callable(legacy, METHODS)) return legacyPort(legacy);
|
|
318
|
+
throw new NoCredentialsFace();
|
|
319
|
+
}
|
|
320
|
+
//#endregion
|
|
321
|
+
//#region src/client/handoff.ts
|
|
322
|
+
const reportPrompt = (report) => `/fulltext 读取已有报告 ${report.id},总结主要发现并用 [1] 等编号对应片段,为英文标题添加中文翻译。更新该报告并交付 HTML 和 CSV,不要重新检索。`;
|
|
323
|
+
/** Use the native draft initializer when no Session has been selected yet. */
|
|
324
|
+
async function handoffReport(ctx, report) {
|
|
325
|
+
const sessions = ctx.get("sessions");
|
|
326
|
+
const conversation = ctx.get("conversation");
|
|
327
|
+
const layout = ctx.get("layout");
|
|
328
|
+
if (!sessions || !conversation || !layout) return "unavailable";
|
|
329
|
+
const currentInput = () => {
|
|
330
|
+
const row = Object.values(sessions.list.getSnapshot().byId).find((s) => (s.retainedBy.mainView ?? 0) > 0);
|
|
331
|
+
const binding = row && sessions.binding(row.id);
|
|
332
|
+
return binding ? conversation.input.for(binding.ctx) : void 0;
|
|
333
|
+
};
|
|
334
|
+
const text = reportPrompt(report);
|
|
335
|
+
let input = currentInput();
|
|
336
|
+
if (!input) {
|
|
337
|
+
const navigation = ctx.get("uiWorkspace");
|
|
338
|
+
if (!navigation?.startSession) return "unavailable";
|
|
339
|
+
navigation.startSession(void 0, {
|
|
340
|
+
prompt: text,
|
|
341
|
+
whenDraftExists: "keep",
|
|
342
|
+
clearPreviousDraft: false
|
|
343
|
+
});
|
|
344
|
+
input = await new Promise((resolve) => {
|
|
345
|
+
let done = false, unsubscribe = () => {};
|
|
346
|
+
const finish = (value) => {
|
|
347
|
+
if (done) return;
|
|
348
|
+
done = true;
|
|
349
|
+
clearTimeout(timer);
|
|
350
|
+
unsubscribe();
|
|
351
|
+
resolve(value);
|
|
352
|
+
};
|
|
353
|
+
const check = () => {
|
|
354
|
+
const value = currentInput();
|
|
355
|
+
if (value) finish(value);
|
|
356
|
+
};
|
|
357
|
+
const timer = setTimeout(() => finish(void 0), 8e3);
|
|
358
|
+
unsubscribe = sessions.list.subscribe(check);
|
|
359
|
+
check();
|
|
360
|
+
});
|
|
361
|
+
if (!input) return "unavailable";
|
|
362
|
+
if (input.state.getSnapshot().draft === text) {
|
|
363
|
+
layout.selectPanel(null);
|
|
364
|
+
queueMicrotask(() => input?.focus?.());
|
|
365
|
+
return "filled";
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
const state = input.state.getSnapshot();
|
|
369
|
+
if (state.draft.trim() || [
|
|
370
|
+
"submitting",
|
|
371
|
+
"adjudicating",
|
|
372
|
+
"submitted"
|
|
373
|
+
].includes(state.phase)) return "busy";
|
|
374
|
+
input.setDraft(text);
|
|
375
|
+
if (input.state.getSnapshot().draft !== text) return "busy";
|
|
376
|
+
layout.selectPanel(null);
|
|
377
|
+
queueMicrotask(() => input?.focus?.());
|
|
378
|
+
return "filled";
|
|
379
|
+
}
|
|
380
|
+
//#endregion
|
|
381
|
+
//#region src/client/Workspace.tsx
|
|
382
|
+
function Icon({ size = 20 }) {
|
|
383
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
|
|
384
|
+
width: size,
|
|
385
|
+
height: size,
|
|
386
|
+
viewBox: "0 0 24 24",
|
|
387
|
+
fill: "none",
|
|
388
|
+
stroke: "currentColor",
|
|
389
|
+
strokeWidth: "1.6",
|
|
390
|
+
strokeLinecap: "round",
|
|
391
|
+
strokeLinejoin: "round",
|
|
392
|
+
"aria-hidden": "true",
|
|
393
|
+
children: [
|
|
394
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M14 2H5v20h14V7l-5-5Zm0 0v5h5M8 6h3M8 10h3M8 18h3" }),
|
|
395
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("circle", {
|
|
396
|
+
cx: "15",
|
|
397
|
+
cy: "14",
|
|
398
|
+
r: "3"
|
|
399
|
+
}),
|
|
400
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "m17.2 16.2 3 3" })
|
|
401
|
+
]
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
function reportUrl(report, format, download = false) {
|
|
405
|
+
const url = new URL((ROUTE + "/report").slice(1), document.baseURI);
|
|
406
|
+
url.searchParams.set("id", report.id);
|
|
407
|
+
url.searchParams.set("format", format);
|
|
408
|
+
url.searchParams.set("v", report.updatedAt);
|
|
409
|
+
if (download) url.searchParams.set("download", "1");
|
|
410
|
+
return url.href;
|
|
411
|
+
}
|
|
412
|
+
function keyStatus(state) {
|
|
413
|
+
const c = state.catalog;
|
|
414
|
+
if (!c) return state.loading ? "正在读取配置…" : "配置暂不可用";
|
|
415
|
+
return c.keySource === "own" ? "已配置独立 API Key" : c.keySource === "shared" ? "正在使用已有 Ai4Scholar API Key" : "尚未配置 API Key";
|
|
416
|
+
}
|
|
417
|
+
function Settings({ controller }) {
|
|
418
|
+
const state = (0, react.useSyncExternalStore)(controller.subscribe, controller.getSnapshot), [key, setKey] = (0, react.useState)(""), keyId = (0, react.useId)();
|
|
419
|
+
const c = state.catalog;
|
|
420
|
+
(0, react.useEffect)(() => {
|
|
421
|
+
controller.attach();
|
|
422
|
+
}, [controller]);
|
|
423
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
424
|
+
className: "ft-settings",
|
|
425
|
+
children: [
|
|
426
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", { children: "全文搜索设置" }),
|
|
427
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: "可以独立使用,也可以直接沿用 Ai4Scholar 的 API Key。" }),
|
|
428
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
429
|
+
className: "ft-key-status",
|
|
430
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
431
|
+
className: "ft-status-dot",
|
|
432
|
+
"data-ready": c?.configured ?? false
|
|
433
|
+
}), keyStatus(state)]
|
|
434
|
+
}),
|
|
435
|
+
state.error ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
436
|
+
className: "ft-alert",
|
|
437
|
+
role: "alert",
|
|
438
|
+
children: state.error
|
|
439
|
+
}) : null,
|
|
440
|
+
state.message ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
441
|
+
className: "ft-alert",
|
|
442
|
+
role: "status",
|
|
443
|
+
children: state.message
|
|
444
|
+
}) : null,
|
|
445
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
|
|
446
|
+
htmlFor: keyId,
|
|
447
|
+
children: "独立 API Key"
|
|
448
|
+
}),
|
|
449
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
450
|
+
className: "ft-key-row",
|
|
451
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
452
|
+
id: keyId,
|
|
453
|
+
type: "password",
|
|
454
|
+
autoComplete: "off",
|
|
455
|
+
spellCheck: false,
|
|
456
|
+
placeholder: "输入新 Key",
|
|
457
|
+
value: key,
|
|
458
|
+
onChange: (e) => setKey(e.target.value)
|
|
459
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
460
|
+
className: "ft-button ft-button-primary",
|
|
461
|
+
disabled: !key.trim() || state.keyBusy || !c,
|
|
462
|
+
onClick: () => {
|
|
463
|
+
controller.saveKey(key).then((ok) => {
|
|
464
|
+
if (ok) setKey("");
|
|
465
|
+
});
|
|
466
|
+
},
|
|
467
|
+
children: state.keyBusy ? "保存中…" : "保存"
|
|
468
|
+
})]
|
|
469
|
+
}),
|
|
470
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", { children: ["保存独立 Key 后,仅全文搜索使用它;移除后会恢复使用已有 Ai4Scholar Key。", /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
|
|
471
|
+
href: "https://ai4scholar.net/?src=dsh_fulltext",
|
|
472
|
+
target: "_blank",
|
|
473
|
+
rel: "noopener noreferrer",
|
|
474
|
+
children: "获取 API Key ↗"
|
|
475
|
+
})] }),
|
|
476
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
477
|
+
className: "ft-settings-actions",
|
|
478
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
479
|
+
className: "ft-button",
|
|
480
|
+
disabled: c?.keySource !== "own" || state.keyBusy,
|
|
481
|
+
onClick: () => {
|
|
482
|
+
controller.removeKey();
|
|
483
|
+
},
|
|
484
|
+
children: "移除独立 Key"
|
|
485
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
486
|
+
className: "ft-button",
|
|
487
|
+
disabled: state.loading,
|
|
488
|
+
onClick: () => {
|
|
489
|
+
controller.attach();
|
|
490
|
+
},
|
|
491
|
+
children: "刷新状态"
|
|
492
|
+
})]
|
|
493
|
+
}),
|
|
494
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: "搜索结果会保存为本机 HTML、CSV 和原始数据。重新打开报告、报告内筛选和导出不会再次检索;搜索和可选的论文信息补全按接口返回值计费。" }),
|
|
495
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", { children: [
|
|
496
|
+
"版本 ",
|
|
497
|
+
c?.version ?? "—",
|
|
498
|
+
" · 原文来自 Semantic Scholar 已索引内容。"
|
|
499
|
+
] })
|
|
500
|
+
]
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
function Workspace({ controller, handoff }) {
|
|
504
|
+
const state = (0, react.useSyncExternalStore)(controller.subscribe, controller.getSnapshot), [settings, setSettings] = (0, react.useState)(false);
|
|
505
|
+
const [library, setLibrary] = (0, react.useState)(false), [prompt, setPrompt] = (0, react.useState)(""), query = (0, react.useRef)(null), filters = (0, react.useRef)(null);
|
|
506
|
+
const selected = state.selected, c = state.catalog;
|
|
507
|
+
(0, react.useEffect)(() => {
|
|
508
|
+
controller.attach();
|
|
509
|
+
}, [controller]);
|
|
510
|
+
const disabled = state.busy || state.loading || !c?.configured;
|
|
511
|
+
const start = () => {
|
|
512
|
+
controller.newSearch();
|
|
513
|
+
setSettings(false);
|
|
514
|
+
setLibrary(false);
|
|
515
|
+
query.current?.focus();
|
|
516
|
+
};
|
|
517
|
+
const organize = async () => {
|
|
518
|
+
if (!selected) return;
|
|
519
|
+
const result = await handoff(selected);
|
|
520
|
+
if (result === "busy") controller.notify("当前对话已有草稿或正在提交,请先处理,再使用「AI 整理」。");
|
|
521
|
+
if (result === "unavailable") setPrompt(reportPrompt(selected));
|
|
522
|
+
};
|
|
523
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("main", {
|
|
524
|
+
className: "ft",
|
|
525
|
+
children: [
|
|
526
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("header", {
|
|
527
|
+
className: "ft-head",
|
|
528
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
529
|
+
className: "ft-title",
|
|
530
|
+
children: [
|
|
531
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Icon, {}),
|
|
532
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: "全文搜索" }),
|
|
533
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
534
|
+
className: "ft-brand",
|
|
535
|
+
children: "Fulltext · Ai4Scholar"
|
|
536
|
+
})
|
|
537
|
+
]
|
|
538
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
539
|
+
style: {
|
|
540
|
+
display: "flex",
|
|
541
|
+
gap: 7
|
|
542
|
+
},
|
|
543
|
+
children: [
|
|
544
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
545
|
+
className: "ft-button ft-library-toggle",
|
|
546
|
+
"aria-pressed": library,
|
|
547
|
+
onClick: () => {
|
|
548
|
+
setLibrary(!library);
|
|
549
|
+
setSettings(false);
|
|
550
|
+
},
|
|
551
|
+
children: "报告"
|
|
552
|
+
}),
|
|
553
|
+
selected || settings ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
554
|
+
className: "ft-button",
|
|
555
|
+
onClick: start,
|
|
556
|
+
children: "新检索"
|
|
557
|
+
}) : null,
|
|
558
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
559
|
+
className: "ft-button",
|
|
560
|
+
onClick: () => {
|
|
561
|
+
setSettings(!settings);
|
|
562
|
+
setLibrary(false);
|
|
563
|
+
if (settings) controller.attach();
|
|
564
|
+
},
|
|
565
|
+
children: settings ? "返回" : "设置"
|
|
566
|
+
})
|
|
567
|
+
]
|
|
568
|
+
})]
|
|
569
|
+
}),
|
|
570
|
+
!settings ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("form", {
|
|
571
|
+
className: "ft-search",
|
|
572
|
+
onSubmit: (event) => {
|
|
573
|
+
event.preventDefault();
|
|
574
|
+
if (!disabled) {
|
|
575
|
+
setLibrary(false);
|
|
576
|
+
setPrompt("");
|
|
577
|
+
if (filters.current) filters.current.open = false;
|
|
578
|
+
controller.search();
|
|
579
|
+
}
|
|
580
|
+
},
|
|
581
|
+
children: [
|
|
582
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
583
|
+
className: "ft-search-row",
|
|
584
|
+
children: [
|
|
585
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
586
|
+
className: "ft-query",
|
|
587
|
+
ref: query,
|
|
588
|
+
"aria-label": "全文检索词",
|
|
589
|
+
placeholder: "查找方法、实验参数或具体论述,建议使用英文关键词",
|
|
590
|
+
value: state.draft.query,
|
|
591
|
+
onChange: (e) => controller.edit({ query: e.target.value }),
|
|
592
|
+
maxLength: 2e3,
|
|
593
|
+
required: true,
|
|
594
|
+
disabled: state.busy
|
|
595
|
+
}),
|
|
596
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
|
|
597
|
+
className: "ft-count",
|
|
598
|
+
children: ["片段数 ", /* @__PURE__ */ (0, react_jsx_runtime.jsx)("select", {
|
|
599
|
+
"aria-label": "片段数",
|
|
600
|
+
value: state.draft.limit,
|
|
601
|
+
disabled: state.busy,
|
|
602
|
+
onChange: (e) => controller.edit({ limit: Number(e.target.value) }),
|
|
603
|
+
children: [.../* @__PURE__ */ new Set([
|
|
604
|
+
5,
|
|
605
|
+
10,
|
|
606
|
+
20,
|
|
607
|
+
50,
|
|
608
|
+
100,
|
|
609
|
+
state.draft.limit
|
|
610
|
+
])].sort((a, b) => a - b).map((n) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", { children: n }, n))
|
|
611
|
+
})]
|
|
612
|
+
}),
|
|
613
|
+
state.busy ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
614
|
+
type: "button",
|
|
615
|
+
className: "ft-button",
|
|
616
|
+
onClick: (event) => {
|
|
617
|
+
event.preventDefault();
|
|
618
|
+
controller.cancel();
|
|
619
|
+
},
|
|
620
|
+
children: "取消"
|
|
621
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
622
|
+
className: "ft-button ft-button-primary",
|
|
623
|
+
type: "submit",
|
|
624
|
+
disabled: disabled || !state.draft.query.trim(),
|
|
625
|
+
children: "搜索原文"
|
|
626
|
+
})
|
|
627
|
+
]
|
|
628
|
+
}),
|
|
629
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("details", {
|
|
630
|
+
className: "ft-options",
|
|
631
|
+
ref: filters,
|
|
632
|
+
children: [
|
|
633
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("summary", { children: ["检索条件", state.draft.year || state.draft.venue || state.draft.fieldsOfStudy || state.draft.minCitationCount !== void 0 ? " · 已设置" : ""] }),
|
|
634
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
635
|
+
className: "ft-filters",
|
|
636
|
+
children: [
|
|
637
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
|
|
638
|
+
className: "ft-filter",
|
|
639
|
+
children: ["年份 / 范围", /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
640
|
+
placeholder: "2020-2026",
|
|
641
|
+
"aria-label": "检索年份",
|
|
642
|
+
value: state.draft.year ?? "",
|
|
643
|
+
disabled: state.busy,
|
|
644
|
+
onChange: (e) => controller.edit({ year: e.target.value })
|
|
645
|
+
})]
|
|
646
|
+
}),
|
|
647
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
|
|
648
|
+
className: "ft-filter",
|
|
649
|
+
children: ["学科", /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
650
|
+
placeholder: "Computer Science",
|
|
651
|
+
"aria-label": "学科",
|
|
652
|
+
value: state.draft.fieldsOfStudy ?? "",
|
|
653
|
+
disabled: state.busy,
|
|
654
|
+
onChange: (e) => controller.edit({ fieldsOfStudy: e.target.value })
|
|
655
|
+
})]
|
|
656
|
+
}),
|
|
657
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
|
|
658
|
+
className: "ft-filter",
|
|
659
|
+
children: ["期刊 / 会议", /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
660
|
+
placeholder: "Nature,Science",
|
|
661
|
+
"aria-label": "检索期刊",
|
|
662
|
+
value: state.draft.venue ?? "",
|
|
663
|
+
disabled: state.busy,
|
|
664
|
+
onChange: (e) => controller.edit({ venue: e.target.value })
|
|
665
|
+
})]
|
|
666
|
+
}),
|
|
667
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
|
|
668
|
+
className: "ft-filter",
|
|
669
|
+
children: ["最低引用数", /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
670
|
+
type: "number",
|
|
671
|
+
min: 0,
|
|
672
|
+
step: 1,
|
|
673
|
+
placeholder: "不限",
|
|
674
|
+
"aria-label": "最低引用数",
|
|
675
|
+
value: state.draft.minCitationCount ?? "",
|
|
676
|
+
disabled: state.busy,
|
|
677
|
+
onChange: (e) => controller.edit({ minCitationCount: e.target.value ? Number(e.target.value) : void 0 })
|
|
678
|
+
})]
|
|
679
|
+
})
|
|
680
|
+
]
|
|
681
|
+
}),
|
|
682
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
683
|
+
className: "ft-enrich",
|
|
684
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
685
|
+
type: "checkbox",
|
|
686
|
+
checked: state.draft.enrich,
|
|
687
|
+
disabled: state.busy,
|
|
688
|
+
onChange: (e) => controller.edit({ enrich: e.target.checked })
|
|
689
|
+
}), "补全年份、期刊和 PDF 链接"] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "启用后会增加一次论文信息请求,按返回值计费。" })]
|
|
690
|
+
})
|
|
691
|
+
]
|
|
692
|
+
}),
|
|
693
|
+
c && !c.configured ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
694
|
+
className: "ft-key-warning",
|
|
695
|
+
children: ["先配置 API Key,即可开始检索。", /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
696
|
+
type: "button",
|
|
697
|
+
className: "ft-button",
|
|
698
|
+
onClick: () => setSettings(true),
|
|
699
|
+
children: "打开设置"
|
|
700
|
+
})]
|
|
701
|
+
}) : null,
|
|
702
|
+
state.busy ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
703
|
+
className: "ft-loading",
|
|
704
|
+
role: "status",
|
|
705
|
+
children: "正在检索并生成报告…"
|
|
706
|
+
}) : null
|
|
707
|
+
]
|
|
708
|
+
}) : null,
|
|
709
|
+
!settings && state.error ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
710
|
+
className: "ft-alert",
|
|
711
|
+
role: "alert",
|
|
712
|
+
children: state.error
|
|
713
|
+
}) : null,
|
|
714
|
+
!settings && state.message ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
715
|
+
className: "ft-alert",
|
|
716
|
+
role: "status",
|
|
717
|
+
children: state.message
|
|
718
|
+
}) : null,
|
|
719
|
+
settings ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Settings, { controller }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
720
|
+
className: "ft-body",
|
|
721
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("aside", {
|
|
722
|
+
className: `ft-library${library ? " ft-library-open" : ""}`,
|
|
723
|
+
"aria-label": "已保存报告",
|
|
724
|
+
children: [
|
|
725
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
726
|
+
className: "ft-library-head",
|
|
727
|
+
children: ["已保存报告 ", /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
728
|
+
type: "button",
|
|
729
|
+
className: "ft-button",
|
|
730
|
+
disabled: state.loading,
|
|
731
|
+
onClick: () => {
|
|
732
|
+
controller.attach();
|
|
733
|
+
},
|
|
734
|
+
children: "刷新"
|
|
735
|
+
})]
|
|
736
|
+
}),
|
|
737
|
+
state.reports.map((r) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
738
|
+
className: "ft-report-item",
|
|
739
|
+
"aria-current": r.id === selected?.id,
|
|
740
|
+
onClick: () => {
|
|
741
|
+
controller.select(r.id);
|
|
742
|
+
setLibrary(false);
|
|
743
|
+
setPrompt("");
|
|
744
|
+
},
|
|
745
|
+
children: [
|
|
746
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("b", { children: r.query }),
|
|
747
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [
|
|
748
|
+
r.count,
|
|
749
|
+
" 个片段 · ",
|
|
750
|
+
r.papers,
|
|
751
|
+
" 篇论文"
|
|
752
|
+
] }),
|
|
753
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [new Date(r.createdAt).toLocaleDateString("zh-CN"), r.charged === void 0 ? "" : ` · ${r.charged} 积分`] })
|
|
754
|
+
]
|
|
755
|
+
}, r.id)),
|
|
756
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
757
|
+
className: "ft-library-note",
|
|
758
|
+
children: state.reports.length ? "报告保存在本机,刷新后仍可查看。" : state.loading ? "正在读取…" : "搜索后,报告会保存在这里。"
|
|
759
|
+
})
|
|
760
|
+
]
|
|
761
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("section", {
|
|
762
|
+
className: "ft-view",
|
|
763
|
+
"aria-label": "报告预览",
|
|
764
|
+
children: selected ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
765
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
766
|
+
className: "ft-report-bar",
|
|
767
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
768
|
+
className: "ft-report-bar-title",
|
|
769
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("b", {
|
|
770
|
+
title: selected.query,
|
|
771
|
+
children: selected.query
|
|
772
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("small", { children: [
|
|
773
|
+
selected.count,
|
|
774
|
+
" 个片段 · ",
|
|
775
|
+
selected.papers,
|
|
776
|
+
" 篇论文",
|
|
777
|
+
selected.charged === void 0 ? "" : ` · ${selected.charged} 积分`
|
|
778
|
+
] })]
|
|
779
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
780
|
+
className: "ft-report-actions",
|
|
781
|
+
children: [
|
|
782
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
783
|
+
className: "ft-button",
|
|
784
|
+
onClick: organize,
|
|
785
|
+
children: "AI 整理"
|
|
786
|
+
}),
|
|
787
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
|
|
788
|
+
className: "ft-button",
|
|
789
|
+
href: reportUrl(selected, "html"),
|
|
790
|
+
target: "_blank",
|
|
791
|
+
rel: "noopener noreferrer",
|
|
792
|
+
children: "新窗口打开 ↗"
|
|
793
|
+
}),
|
|
794
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
|
|
795
|
+
className: "ft-button",
|
|
796
|
+
href: reportUrl(selected, "html", true),
|
|
797
|
+
download: true,
|
|
798
|
+
children: "下载 HTML"
|
|
799
|
+
}),
|
|
800
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
|
|
801
|
+
className: "ft-button",
|
|
802
|
+
href: reportUrl(selected, "csv", true),
|
|
803
|
+
download: true,
|
|
804
|
+
children: "CSV"
|
|
805
|
+
})
|
|
806
|
+
]
|
|
807
|
+
})]
|
|
808
|
+
}),
|
|
809
|
+
prompt ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
810
|
+
className: "ft-alert",
|
|
811
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: "复制到对话输入框后发送,可在已有原文基础上整理报告。" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("textarea", {
|
|
812
|
+
className: "ft-task-prompt",
|
|
813
|
+
"aria-label": "报告整理指令",
|
|
814
|
+
readOnly: true,
|
|
815
|
+
value: prompt,
|
|
816
|
+
onFocus: (e) => e.target.select()
|
|
817
|
+
})]
|
|
818
|
+
}) : null,
|
|
819
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("iframe", {
|
|
820
|
+
className: "ft-frame",
|
|
821
|
+
title: "全文搜索 HTML 报告",
|
|
822
|
+
sandbox: "allow-scripts allow-popups allow-popups-to-escape-sandbox",
|
|
823
|
+
allow: "clipboard-write",
|
|
824
|
+
src: reportUrl(selected, "html")
|
|
825
|
+
}, selected.id + selected.updatedAt)
|
|
826
|
+
] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
827
|
+
className: "ft-empty",
|
|
828
|
+
children: [
|
|
829
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Icon, { size: 40 }),
|
|
830
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h1", { children: "从论文原文里,找到证据" }),
|
|
831
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: "搜索已索引的标题、摘要和正文片段。直接阅读交互报告,也可以把同一份 HTML 和 CSV 保存下来。" }),
|
|
832
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
833
|
+
className: "ft-examples",
|
|
834
|
+
children: [
|
|
835
|
+
"solid-state battery interfacial resistance",
|
|
836
|
+
"attention mechanism implementation",
|
|
837
|
+
"CRISPR off-target detection methods"
|
|
838
|
+
].map((q) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
839
|
+
type: "button",
|
|
840
|
+
onClick: () => {
|
|
841
|
+
controller.edit({ query: q });
|
|
842
|
+
query.current?.focus();
|
|
843
|
+
},
|
|
844
|
+
children: q
|
|
845
|
+
}, q))
|
|
846
|
+
})
|
|
847
|
+
]
|
|
848
|
+
})
|
|
849
|
+
})]
|
|
850
|
+
})
|
|
851
|
+
]
|
|
852
|
+
});
|
|
853
|
+
}
|
|
854
|
+
//#endregion
|
|
855
|
+
//#region src/client/styles.ts
|
|
856
|
+
function installStyles() {
|
|
857
|
+
const tag = document.createElement("style");
|
|
858
|
+
tag.dataset.plugin = "dsh-fulltext";
|
|
859
|
+
tag.textContent = `
|
|
860
|
+
.ft{--ft-text:var(--dsw-alias-label-primary,#24252a);--ft-muted:var(--dsw-alias-label-secondary,#767880);--ft-line:var(--dsw-alias-border-l3,#e1e2e6);--ft-bg:var(--dsw-alias-bg-base,#fff);--ft-fill:var(--dsw-alias-bg-l1,#f6f7f9);color:var(--ft-text);height:100%;min-height:0;min-width:0;display:flex;flex-direction:column;overflow:hidden;font:13px/1.6 system-ui,sans-serif;container:fulltext / inline-size}
|
|
861
|
+
.ft *{box-sizing:border-box}.ft button,.ft input,.ft select{font:inherit}.ft button,.ft a{touch-action:manipulation}.ft button{cursor:pointer}.ft button:disabled{cursor:default;opacity:.5}.ft button:focus-visible,.ft a:focus-visible,.ft input:focus-visible,.ft select:focus-visible,.ft summary:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#597dfa);outline-offset:2px}
|
|
862
|
+
.ft-head{min-height:64px;flex:none;display:flex;gap:12px;align-items:center;justify-content:space-between;padding:14px 24px;padding-left:max(24px,var(--dsh-frame-leading-clearance,0px));border-bottom:1px solid var(--ft-line)}.ft-title{display:flex;gap:9px;align-items:center;white-space:nowrap}.ft-title strong{font-size:15px;font-weight:550}.ft-brand{color:var(--ft-muted);font-size:11px;margin-left:6px}.ft-button{display:inline-flex;gap:6px;align-items:center;justify-content:center;color:var(--ft-text);background:transparent;border:1px solid var(--ft-line);border-radius:8px;padding:6px 10px;text-decoration:none;white-space:nowrap;font-size:12px;line-height:20px}.ft-button:hover{background:var(--dsw-alias-interactive-bg-hover,#8881)}.ft-button-primary{background:var(--ft-text);color:var(--ft-bg);border-color:transparent}.ft-button-primary:hover{background:var(--ft-text);opacity:.85}
|
|
863
|
+
.ft-search{padding:16px 24px;border-bottom:1px solid var(--ft-line);flex:none}.ft-search-row{display:flex;gap:10px;align-items:center;max-width:1120px;margin:auto}.ft-query{flex:1;min-width:0;background:var(--ft-bg);color:var(--ft-text);border:1px solid var(--ft-line);border-radius:10px;padding:11px 14px;font-size:14px!important;line-height:22px}.ft-query::placeholder{color:var(--ft-muted)}.ft-count{display:flex;align-items:center;gap:6px;white-space:nowrap;color:var(--ft-muted);font-size:12px}.ft-count select,.ft-filter input,.ft-filter select{color:var(--ft-text);background:var(--ft-bg);border:1px solid var(--ft-line);border-radius:7px;padding:6px 8px;min-width:0}.ft-count select{width:66px}.ft-search-row .ft-button{min-height:44px;padding:8px 16px}.ft-options{max-width:1120px;margin:10px auto 0;color:var(--ft-muted);font-size:12px}.ft-options summary{cursor:pointer;width:fit-content}.ft-options[open] summary{margin-bottom:12px}.ft-filters{display:grid;grid-template-columns:repeat(4,minmax(90px,1fr));gap:12px}.ft-filter{display:flex;flex-direction:column;gap:5px}.ft-enrich{display:flex;flex-wrap:wrap;gap:6px 14px;margin-top:12px;align-items:center}.ft-enrich label{display:flex;align-items:center;gap:7px;color:var(--ft-text)}.ft-enrich input{accent-color:#657ee7}.ft-key-warning{max-width:1120px;margin:8px auto 0;display:flex;gap:8px;align-items:center;color:var(--ft-muted)}
|
|
864
|
+
.ft-alert{padding:10px 24px;color:var(--ft-text);background:var(--ft-fill);flex:none;overflow-wrap:anywhere}.ft-alert[role=alert]{color:var(--dsw-alias-state-danger-primary,#cc5364)}.ft-body{display:flex;flex:1;min-height:0;min-width:0}.ft-library{width:220px;flex:none;padding:18px 10px;border-right:1px solid var(--ft-line);overflow:auto}.ft-library-head{display:flex;align-items:center;justify-content:space-between;padding:0 8px 12px;color:var(--ft-muted);font-size:11px;letter-spacing:.04em}.ft-library .ft-button{padding:2px 7px;font-size:11px}.ft-report-item{display:flex;flex-direction:column;text-align:left;gap:5px;width:100%;padding:12px 10px;border:0;background:transparent;color:var(--ft-text);border-radius:8px;margin-bottom:4px}.ft-report-item:hover,.ft-report-item[aria-current=true]{background:var(--dsw-alias-interactive-bg-hover,#8881)}.ft-report-item b{font-size:12px;font-weight:500;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;overflow-wrap:anywhere}.ft-report-item span{font-size:10px;color:var(--ft-muted)}.ft-library-note{color:var(--ft-muted);font-size:11px;padding:8px;line-height:1.8}.ft-view{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column}.ft-report-bar{padding:10px 16px;display:flex;flex-wrap:wrap;justify-content:space-between;align-items:center;gap:8px;flex:none;border-bottom:1px solid var(--ft-line)}.ft-report-bar-title{min-width:0;flex:1}.ft-report-bar-title b{display:block;font-size:12px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:42ch}.ft-report-bar-title small{color:var(--ft-muted);font-size:11px}.ft-report-actions{display:flex;flex-wrap:wrap;gap:6px}.ft-report-actions .ft-button{font-size:11px;padding:4px 8px}.ft-frame{width:100%;flex:1;min-height:0;border:0;background:var(--ft-bg)}.ft-empty{display:flex;flex:1;flex-direction:column;align-items:center;justify-content:center;text-align:center;padding:32px 24px 70px;overflow:auto}.ft-empty svg{color:var(--ft-muted);margin-bottom:18px}.ft-empty h1{font-size:27px;line-height:1.4;letter-spacing:-.04em;font-weight:550;margin:0 0 12px}.ft-empty p{color:var(--ft-muted);max-width:440px;margin:0 0 22px;font-size:13px;line-height:1.8}.ft-examples{display:flex;gap:8px;flex-wrap:wrap;justify-content:center;max-width:540px}.ft-examples button{border:1px solid var(--ft-line);border-radius:20px;background:transparent;color:var(--ft-muted);padding:7px 12px;font-size:11px}.ft-examples button:hover{color:var(--ft-text);background:var(--ft-fill)}.ft-loading{font-size:12px;color:var(--ft-muted);margin-left:8px}
|
|
865
|
+
.ft-settings{padding:32px 24px;max-width:680px;width:100%;margin:0 auto;overflow:auto}.ft-settings h2{font-size:18px;font-weight:550;margin:0 0 12px}.ft-settings p{color:var(--ft-muted);font-size:13px;line-height:1.8}.ft-settings label{display:block;font-size:12px;color:var(--ft-muted);margin:20px 0 7px}.ft-key-row{display:flex;gap:8px}.ft-key-row input{flex:1;min-width:0;background:var(--ft-bg);color:var(--ft-text);border:1px solid var(--ft-line);border-radius:8px;padding:9px 12px}.ft-settings-actions{display:flex;flex-wrap:wrap;gap:10px;margin:18px 0}.ft-settings a{color:var(--dsw-alias-state-business-primary,#687ee1)}.ft-key-status{padding:14px 16px;background:var(--ft-fill);border:1px solid var(--ft-line);border-radius:10px;font-size:12px}.ft-status-dot{display:inline-block;width:6px;height:6px;border-radius:50%;background:#8590a2;margin-right:7px}.ft-status-dot[data-ready=true]{background:#3da888}.ft-library-toggle{display:none}.ft-task-prompt{width:100%;height:100px;background:var(--ft-bg);color:var(--ft-text);border:1px solid var(--ft-line);border-radius:8px;padding:10px;font:12px/1.6 system-ui,sans-serif}
|
|
866
|
+
@container fulltext (max-width:820px){.ft-library{width:190px}.ft-report-bar-title{flex-basis:100%;max-width:100%}.ft-report-bar-title b{max-width:100%}.ft-brand{display:none}.ft-report-actions{width:100%}.ft-filters{grid-template-columns:repeat(2,minmax(90px,1fr))}}
|
|
867
|
+
@container fulltext (max-width:620px){.ft-head{padding:12px 16px;min-height:56px;padding-left:max(16px,var(--dsh-frame-leading-clearance,0px))}.ft-search{padding:12px 16px}.ft-search-row{gap:7px;flex-wrap:wrap}.ft-query{width:100%;flex-basis:100%;font-size:13px!important}.ft-search-row .ft-button{min-height:36px;padding:4px 14px}.ft-count{margin-right:auto}.ft-options{margin-top:9px}.ft-library{display:none}.ft-library.ft-library-open{display:block;width:100%;border-right:0}.ft-body:has(.ft-library-open) .ft-view{display:none}.ft-library-toggle{display:inline-flex}.ft-report-bar{padding:10px 12px}.ft-report-actions{gap:5px}.ft-report-actions .ft-button{padding:3px 6px}.ft-empty{padding:24px 20px 36px}.ft-empty h1{font-size:23px}.ft-empty p{font-size:12px}.ft-title strong{font-size:14px}.ft-title svg{width:18px;height:18px}.ft-alert{padding:10px 16px}.ft-settings{padding:24px 16px}}
|
|
868
|
+
`;
|
|
869
|
+
document.head.appendChild(tag);
|
|
870
|
+
return () => tag.remove();
|
|
871
|
+
}
|
|
872
|
+
//#endregion
|
|
873
|
+
//#region src/client/index.tsx
|
|
874
|
+
const inject = ["slots"];
|
|
875
|
+
function apply(ctx) {
|
|
876
|
+
const controller = new Controller(() => resolveCredentialsPort({
|
|
877
|
+
connection: ctx.get("connection"),
|
|
878
|
+
remoteCredentials: ctx.get("remote.credentials")
|
|
879
|
+
}));
|
|
880
|
+
ctx.effect(() => installStyles(), "fulltext: styles");
|
|
881
|
+
ctx.effect(() => () => controller.dispose(), "fulltext: state");
|
|
882
|
+
const slots = ctx.slots;
|
|
883
|
+
const Root = () => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Workspace, {
|
|
884
|
+
controller,
|
|
885
|
+
handoff: (report) => handoffReport(ctx, report)
|
|
886
|
+
});
|
|
887
|
+
slots.inject("main", () => slots.register({
|
|
888
|
+
name: "main",
|
|
889
|
+
key: PANEL
|
|
890
|
+
}, Root));
|
|
891
|
+
slots.inject("sidebar.panellist", () => slots.register({
|
|
892
|
+
name: "sidebar.panellist",
|
|
893
|
+
id: PANEL,
|
|
894
|
+
order: 66,
|
|
895
|
+
label: () => "全文搜索"
|
|
896
|
+
}, () => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Icon, {})));
|
|
897
|
+
const Config = ({ view = "page" }) => {
|
|
898
|
+
const state = (0, react.useSyncExternalStore)(controller.subscribe, controller.getSnapshot);
|
|
899
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
900
|
+
className: "ft",
|
|
901
|
+
style: {
|
|
902
|
+
height: "auto",
|
|
903
|
+
overflow: "visible"
|
|
904
|
+
},
|
|
905
|
+
children: view === "summary" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
|
|
906
|
+
style: {
|
|
907
|
+
margin: 0,
|
|
908
|
+
color: "var(--ft-muted)",
|
|
909
|
+
fontSize: 12
|
|
910
|
+
},
|
|
911
|
+
children: [keyStatus(state), " · 打开详情配置独立 Key"]
|
|
912
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Settings, { controller })
|
|
913
|
+
});
|
|
914
|
+
};
|
|
915
|
+
slots.inject("plugins.bundle.config", () => slots.register({
|
|
916
|
+
name: "plugins.bundle.config",
|
|
917
|
+
key: "dsh-fulltext"
|
|
918
|
+
}, Config));
|
|
919
|
+
slots.inject("plugins.row.config", () => slots.register({
|
|
920
|
+
name: "plugins.row.config",
|
|
921
|
+
key: "dsh-fulltext#fulltext"
|
|
922
|
+
}, Config));
|
|
923
|
+
slots.inject("settings.section", () => slots.register({
|
|
924
|
+
name: "settings.section",
|
|
925
|
+
id: PANEL,
|
|
926
|
+
order: 191,
|
|
927
|
+
label: () => "全文搜索"
|
|
928
|
+
}, Config));
|
|
929
|
+
controller.attach();
|
|
930
|
+
}
|
|
931
|
+
//#endregion
|
|
932
|
+
exports.apply = apply;
|
|
933
|
+
exports.inject = inject;
|
|
934
|
+
return module.exports;
|
|
935
|
+
}
|
|
936
|
+
});
|
|
937
|
+
|
|
938
|
+
//# sourceMappingURL=client.js.map
|