codex-overleaf-link 2.3.4 → 2.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +318 -211
- package/extension/bootstrap/manifest.template.json +1 -1
- package/extension/src/background.js +5 -0
- package/extension/src/content/composerPanel.js +1 -1
- package/extension/src/content/contentRuntime.js +27 -28
- package/extension/src/content/generated/content.bundle.js +457 -125
- package/extension/src/content/generated/content.bundle.meta.json +5 -3
- package/extension/src/content/globalPreferencesController.js +125 -0
- package/extension/src/content/legacyGlobalRegistry.js +2 -0
- package/extension/src/content/panelRenderer.js +6 -1
- package/extension/src/content/projectSettingsCoordinator.js +1 -0
- package/extension/src/content/providerSettingsCoordinator.js +15 -0
- package/extension/src/content/providerSettingsDialog.js +24 -15
- package/extension/src/content/settingsPanel.js +5 -3
- package/extension/src/content/themeController.js +3 -0
- package/extension/src/shared/compatibility.js +1 -1
- package/extension/src/shared/globalPreferences.js +131 -0
- package/extension/src/shared/i18n.js +2 -2
- package/extension/styles/panel.css +17 -2
- package/package.json +1 -1
- package/scripts/install-managed.mjs +1 -1
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"entry": "extension/entries/content-entry.mjs",
|
|
4
4
|
"output": "extension/src/content/generated/content.bundle.js",
|
|
5
|
-
"sourceDigest": "
|
|
6
|
-
"outputDigest": "
|
|
7
|
-
"byteLength":
|
|
5
|
+
"sourceDigest": "7ed22d5c82b20220316824547e1dfc359e45dfcdf1f1bca2fb7280195a05361c",
|
|
6
|
+
"outputDigest": "50436e35fe942b3fd8540a6267fba79c41a53c216b1ffc42995e4ed026771de4",
|
|
7
|
+
"byteLength": 2337940,
|
|
8
8
|
"inputs": [
|
|
9
9
|
"extension/entries/content-entry.mjs",
|
|
10
10
|
"extension/src/content/activeTurnControl.js",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"extension/src/content/diagnosticsController.js",
|
|
18
18
|
"extension/src/content/diagnosticsPanel.js",
|
|
19
19
|
"extension/src/content/diffReviewPanel.js",
|
|
20
|
+
"extension/src/content/globalPreferencesController.js",
|
|
20
21
|
"extension/src/content/legacyGlobalRegistry.js",
|
|
21
22
|
"extension/src/content/localSkillsPanel.js",
|
|
22
23
|
"extension/src/content/markdownDomRenderer.js",
|
|
@@ -68,6 +69,7 @@
|
|
|
68
69
|
"extension/src/shared/compatibility.js",
|
|
69
70
|
"extension/src/shared/compileAdapter.js",
|
|
70
71
|
"extension/src/shared/failureReasons.js",
|
|
72
|
+
"extension/src/shared/globalPreferences.js",
|
|
71
73
|
"extension/src/shared/governanceRules.js",
|
|
72
74
|
"extension/src/shared/i18n.js",
|
|
73
75
|
"extension/src/shared/lineReferences.js",
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
(function (root, factory) {
|
|
2
|
+
if (typeof module === 'object' && module.exports) module.exports = factory(require('../shared/globalPreferences'));
|
|
3
|
+
else root.CodexOverleafModuleRegistry.define('GlobalPreferencesController', ['GlobalPreferences'], factory);
|
|
4
|
+
})(typeof globalThis !== 'undefined' ? globalThis : this, function (Preferences) {
|
|
5
|
+
'use strict';
|
|
6
|
+
|
|
7
|
+
const CONTROLS = Object.freeze({ theme: '[data-theme-select]', locale: '[data-language-select]',
|
|
8
|
+
preloadProjectContext: '[data-preload-project-context]', loadCodexLocalSkills: '[data-load-codex-local-skills]',
|
|
9
|
+
loadCodexOverleafSkills: '[data-load-codex-overleaf-skills]' });
|
|
10
|
+
|
|
11
|
+
function create(options) {
|
|
12
|
+
const chromeApi = options.chromeApi;
|
|
13
|
+
const fallback = Preferences.pick(options.getState?.() || {});
|
|
14
|
+
let snapshot = null;
|
|
15
|
+
let loading = null;
|
|
16
|
+
let subscribed = false;
|
|
17
|
+
let disposed = false;
|
|
18
|
+
let lastError = null;
|
|
19
|
+
let tail = Promise.resolve();
|
|
20
|
+
const pending = [];
|
|
21
|
+
|
|
22
|
+
function view() {
|
|
23
|
+
return pending.reduce((values, operation) => Preferences.applyPatch(values, operation.patch), snapshot?.values || fallback);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function render(force = false) {
|
|
27
|
+
if (disposed) return;
|
|
28
|
+
const previous = options.getState?.() || {};
|
|
29
|
+
const values = view();
|
|
30
|
+
const changed = Preferences.changedKeys(Preferences.pick(previous), values);
|
|
31
|
+
options.setState?.({ ...previous, ...values });
|
|
32
|
+
const panel = options.getPanel?.();
|
|
33
|
+
if (!panel) return;
|
|
34
|
+
for (const [field, selector] of Object.entries(CONTROLS)) {
|
|
35
|
+
const control = panel.querySelector(selector);
|
|
36
|
+
if (!control) continue;
|
|
37
|
+
if (typeof values[field] === 'boolean') control.checked = values[field];
|
|
38
|
+
else if (control.value !== values[field]) control.value = values[field];
|
|
39
|
+
}
|
|
40
|
+
if (force || changed.includes('theme')) options.applyTheme?.(values.theme);
|
|
41
|
+
if (changed.includes('locale')) options.applyLocale?.();
|
|
42
|
+
if (force || changed.includes('preloadProjectContext')) options.onPreloadChange?.(values.preloadProjectContext);
|
|
43
|
+
if (changed.some(key => key === 'codexOverleafSkillEnabled' || key.startsWith('loadCodex'))) options.onSkillsChange?.();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function accept(value) {
|
|
47
|
+
const next = Preferences.validateSnapshot(value);
|
|
48
|
+
lastError = null;
|
|
49
|
+
if (!snapshot || next.revision > snapshot.revision) {
|
|
50
|
+
snapshot = next;
|
|
51
|
+
render();
|
|
52
|
+
}
|
|
53
|
+
return snapshot;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function request(type, patch) {
|
|
57
|
+
const response = await chromeApi.runtime.sendMessage({ type, ...(patch ? { patch } : {}) });
|
|
58
|
+
if (!response?.ok) throw new Error(response?.error?.message || 'Global preferences are unavailable.');
|
|
59
|
+
return response.result;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function onStorageChange(changes, area) {
|
|
63
|
+
if (disposed || area !== 'local' || !changes[Preferences.STORAGE_KEY]?.newValue) return;
|
|
64
|
+
try { accept(changes[Preferences.STORAGE_KEY].newValue); } catch (error) { reportError(error); }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function reportError(error) {
|
|
68
|
+
lastError = error;
|
|
69
|
+
options.onError?.(error);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function initialize() {
|
|
73
|
+
if (!subscribed) {
|
|
74
|
+
chromeApi.storage.onChanged.addListener(onStorageChange);
|
|
75
|
+
subscribed = true;
|
|
76
|
+
}
|
|
77
|
+
if (snapshot) return snapshot;
|
|
78
|
+
if (!loading) {
|
|
79
|
+
loading = request(Preferences.READ_MESSAGE).then(accept).catch(error => {
|
|
80
|
+
reportError(error);
|
|
81
|
+
return null;
|
|
82
|
+
}).finally(() => { loading = null; });
|
|
83
|
+
}
|
|
84
|
+
return loading;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function update(input) {
|
|
88
|
+
const patch = Preferences.validatePatch(input);
|
|
89
|
+
if (!Preferences.changedKeys(view(), Preferences.applyPatch(view(), patch)).length) return pending.length ? tail : Promise.resolve(snapshot);
|
|
90
|
+
const operation = { patch };
|
|
91
|
+
pending.push(operation);
|
|
92
|
+
render();
|
|
93
|
+
const result = tail.catch(() => {}).then(() => request(Preferences.PATCH_MESSAGE, patch)).then(Preferences.validateSnapshot).then(value => {
|
|
94
|
+
accept(value);
|
|
95
|
+
pending.splice(pending.indexOf(operation), 1);
|
|
96
|
+
render();
|
|
97
|
+
return snapshot;
|
|
98
|
+
}, error => {
|
|
99
|
+
pending.splice(pending.indexOf(operation), 1);
|
|
100
|
+
render();
|
|
101
|
+
reportError(error);
|
|
102
|
+
throw error;
|
|
103
|
+
});
|
|
104
|
+
tail = result;
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function handleInput(event) {
|
|
109
|
+
const field = Object.keys(CONTROLS).find(key => event?.target?.matches?.(CONTROLS[key]));
|
|
110
|
+
if (!field) return null;
|
|
111
|
+
return update({ [field]: ['theme', 'locale'].includes(field) ? event.target.value : Boolean(event.target.checked) });
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return Object.freeze({ initialize, update, handleInput,
|
|
115
|
+
overlay: state => snapshot || pending.length ? { ...state, ...view() } : state,
|
|
116
|
+
refreshView: () => { if (snapshot) render(true); if (lastError) options.onError?.(lastError); },
|
|
117
|
+
destroy() {
|
|
118
|
+
disposed = true;
|
|
119
|
+
if (subscribed) chromeApi.storage.onChanged.removeListener(onStorageChange);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return Object.freeze({ create });
|
|
125
|
+
});
|
|
@@ -327,7 +327,8 @@
|
|
|
327
327
|
|
|
328
328
|
return new Promise(resolve => {
|
|
329
329
|
let settled = false;
|
|
330
|
-
const
|
|
330
|
+
const returnFocus = doc.activeElement;
|
|
331
|
+
const overlay = doc.createElement('dialog');
|
|
331
332
|
overlay.className = 'codex-plugin-confirm';
|
|
332
333
|
overlay.setAttribute('data-plugin-confirm', 'true');
|
|
333
334
|
overlay.setAttribute('role', 'dialog');
|
|
@@ -371,13 +372,16 @@
|
|
|
371
372
|
card.append(head, body, actions);
|
|
372
373
|
overlay.append(card);
|
|
373
374
|
panel.append(overlay);
|
|
375
|
+
overlay.showModal?.();
|
|
374
376
|
|
|
375
377
|
const cleanup = value => {
|
|
376
378
|
if (settled) return;
|
|
377
379
|
settled = true;
|
|
378
380
|
activeResolve = null;
|
|
379
381
|
doc.removeEventListener('keydown', onKeydown, true);
|
|
382
|
+
overlay.close?.();
|
|
380
383
|
overlay.remove();
|
|
384
|
+
returnFocus?.focus?.();
|
|
381
385
|
resolve(value);
|
|
382
386
|
};
|
|
383
387
|
activeResolve = cleanup;
|
|
@@ -398,6 +402,7 @@
|
|
|
398
402
|
overlay.addEventListener('click', event => {
|
|
399
403
|
if (event.target === overlay) cleanup(false);
|
|
400
404
|
});
|
|
405
|
+
overlay.addEventListener('cancel', event => { event.preventDefault(); cleanup(false); });
|
|
401
406
|
cancel.addEventListener('click', () => cleanup(false));
|
|
402
407
|
confirm.addEventListener('click', () => cleanup(true));
|
|
403
408
|
doc.addEventListener('keydown', onKeydown, true);
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
getSettingsPanelInstance: options.getSettingsPanelInstance || (() => null),
|
|
15
15
|
getSelectedModel: options.getSelectedModel || (() => ''),
|
|
16
16
|
getSelectedProviderId: options.getSelectedProviderId || (() => 'builtin'),
|
|
17
|
+
hasCurrentProject: options.hasCurrentProject || (() => true),
|
|
17
18
|
setSelectedProviderId: options.setSelectedProviderId || (() => {}),
|
|
18
19
|
confirmProviderSwitch: options.confirmProviderSwitch || (() => true),
|
|
19
20
|
clearSelectedModel: options.clearSelectedModel || (() => {}),
|
|
@@ -43,6 +44,7 @@
|
|
|
43
44
|
tx: instance.tx,
|
|
44
45
|
ProviderProfiles: Profiles,
|
|
45
46
|
callbacks: {
|
|
47
|
+
hasCurrentProject: instance.hasCurrentProject,
|
|
46
48
|
getCurrentProjectProviderId: () => instance.getSelectedProviderId() || 'builtin',
|
|
47
49
|
onTest: context => testProvider(instance, context),
|
|
48
50
|
onCancelTest: () => cancelProviderTest(instance),
|
|
@@ -208,6 +210,7 @@
|
|
|
208
210
|
}
|
|
209
211
|
|
|
210
212
|
async function prepareProviderActivation(instance, providerId) {
|
|
213
|
+
requireCurrentProject(instance);
|
|
211
214
|
const previousProviderId = instance.getSelectedProviderId() || 'builtin';
|
|
212
215
|
const provider = instance.Profiles.getProviderById(instance.catalog, providerId);
|
|
213
216
|
if (providerId !== previousProviderId) {
|
|
@@ -301,6 +304,7 @@
|
|
|
301
304
|
async function saveProvider(instance, context, action = {}) {
|
|
302
305
|
instance.dialog.setBusy('saving', instance.tx('Saving provider…', '正在保存模型服务…'));
|
|
303
306
|
try {
|
|
307
|
+
if (action.activate === true) requireCurrentProject(instance);
|
|
304
308
|
const result = await request(instance, 'codex.providers.upsert', {
|
|
305
309
|
profileId: context.profileId,
|
|
306
310
|
expectedRevision: context.expectedRevision,
|
|
@@ -495,6 +499,12 @@
|
|
|
495
499
|
}
|
|
496
500
|
|
|
497
501
|
function updateSettingsSummary(instance, override = {}) {
|
|
502
|
+
if (!instance.hasCurrentProject()) {
|
|
503
|
+
instance.getSettingsPanelInstance()?.setProviderSummary?.({ summary: instance.tx(
|
|
504
|
+
'Shared model API profiles · open a project to select a provider',
|
|
505
|
+
'共享模型 API 配置 · 进入项目后选择使用的服务'), tone: 'info' });
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
498
508
|
const selectedProviderId = instance.getSelectedProviderId() || 'builtin';
|
|
499
509
|
const catalogProvider = instance.Profiles.getProviderById(
|
|
500
510
|
instance.catalog,
|
|
@@ -594,6 +604,11 @@
|
|
|
594
604
|
});
|
|
595
605
|
}
|
|
596
606
|
|
|
607
|
+
function requireCurrentProject(instance) {
|
|
608
|
+
if (!instance.hasCurrentProject()) throw createClientError(
|
|
609
|
+
'provider_project_required', instance.tx('Open an Overleaf project before selecting its provider.', '请先进入 Overleaf 项目,再选择该项目使用的模型服务。'));
|
|
610
|
+
}
|
|
611
|
+
|
|
597
612
|
function emptyCatalogChange() {
|
|
598
613
|
return { activeProviderChanged: false, activeModelCatalogChanged: false, changedProviderIds: [] };
|
|
599
614
|
}
|
|
@@ -47,12 +47,13 @@
|
|
|
47
47
|
if (instance.root) {
|
|
48
48
|
return instance.root;
|
|
49
49
|
}
|
|
50
|
-
const root = instance.document.createElement('
|
|
50
|
+
const root = instance.document.createElement('dialog');
|
|
51
51
|
root.className = 'codex-provider-dialog-root';
|
|
52
|
+
root.setAttribute('aria-labelledby', 'codex-provider-dialog-title');
|
|
52
53
|
root.hidden = true;
|
|
53
54
|
root.innerHTML = `
|
|
54
55
|
<div class="codex-provider-dialog-backdrop" data-provider-backdrop></div>
|
|
55
|
-
<section class="codex-provider-dialog"
|
|
56
|
+
<section class="codex-provider-dialog">
|
|
56
57
|
<header class="codex-provider-dialog-head">
|
|
57
58
|
<div class="codex-provider-dialog-heading">
|
|
58
59
|
<div class="codex-provider-dialog-titleline">
|
|
@@ -79,6 +80,7 @@
|
|
|
79
80
|
root.addEventListener('input', event => handleInput(instance, event));
|
|
80
81
|
root.addEventListener('change', event => handleInput(instance, event));
|
|
81
82
|
root.addEventListener('keydown', event => handleKeydown(instance, event));
|
|
83
|
+
root.addEventListener('cancel', event => { event.preventDefault(); requestClose(instance); });
|
|
82
84
|
root.addEventListener('mousedown', event => event.stopPropagation());
|
|
83
85
|
root.addEventListener('click', event => event.stopPropagation());
|
|
84
86
|
return root;
|
|
@@ -89,9 +91,12 @@
|
|
|
89
91
|
instance.root.hidden = false;
|
|
90
92
|
syncTheme(instance);
|
|
91
93
|
setCatalog(instance, catalog || instance.catalog);
|
|
94
|
+
if (!instance.root.open) instance.root.showModal?.();
|
|
92
95
|
queueMicrotask(() => {
|
|
93
|
-
instance.root.
|
|
94
|
-
|
|
96
|
+
if (!instance.root || instance.root.hidden) return;
|
|
97
|
+
const target = instance.root.querySelector('[data-provider-row][aria-current="true"]')
|
|
98
|
+
|| instance.root.querySelector('input, button, select, textarea');
|
|
99
|
+
target?.focus?.();
|
|
95
100
|
});
|
|
96
101
|
}
|
|
97
102
|
|
|
@@ -106,6 +111,7 @@
|
|
|
106
111
|
instance.callbacks.onCancelTest?.();
|
|
107
112
|
instance.busy = '';
|
|
108
113
|
}
|
|
114
|
+
instance.root.close?.();
|
|
109
115
|
instance.root.hidden = true;
|
|
110
116
|
instance.busy = '';
|
|
111
117
|
instance.returnFocus?.focus?.();
|
|
@@ -159,6 +165,9 @@
|
|
|
159
165
|
"Configure experimental third-party integrations used by this project's future Codex runs. Compatibility varies by provider and gateway.",
|
|
160
166
|
'配置当前项目后续 Codex 任务使用的实验性第三方集成;兼容性取决于具体模型服务与网关。'
|
|
161
167
|
);
|
|
168
|
+
if (instance.callbacks.hasCurrentProject?.() === false) instance.root.querySelector('[data-provider-dialog-subtitle]').textContent = tx(
|
|
169
|
+
'Manage shared model API profiles. Open a project to choose which provider its future turns use.',
|
|
170
|
+
'管理共享模型 API 配置。进入项目后,再选择该项目后续任务使用的服务。');
|
|
162
171
|
renderProviderList(instance);
|
|
163
172
|
renderDetail(instance);
|
|
164
173
|
renderFooter(instance);
|
|
@@ -408,8 +417,8 @@
|
|
|
408
417
|
<label class="codex-provider-disclosure">
|
|
409
418
|
<input type="checkbox" data-provider-disclosure ${disclosureSatisfied ? 'checked' : ''}>
|
|
410
419
|
<span data-provider-disclosure-text>${escapeHtml(tx(
|
|
411
|
-
`
|
|
412
|
-
|
|
420
|
+
`Projects using this shared provider may send task context to ${draft.baseUrl || 'this endpoint'}. Each project chooses its own provider.`,
|
|
421
|
+
`使用此共享服务配置的项目可能把任务上下文发送到 ${draft.baseUrl || '此端点'}。各项目独立选择使用的服务。`
|
|
413
422
|
))}</span>
|
|
414
423
|
</label>
|
|
415
424
|
<div class="codex-provider-test-row">
|
|
@@ -456,7 +465,7 @@
|
|
|
456
465
|
'Uses the authentication, model catalog, and provider configuration managed by the local Codex CLI.',
|
|
457
466
|
'使用本地 Codex CLI 管理的身份验证、模型目录和服务配置。'
|
|
458
467
|
))}</p>
|
|
459
|
-
${active
|
|
468
|
+
${instance.callbacks.hasCurrentProject?.() === false ? '' : active
|
|
460
469
|
? `<span class="codex-provider-active-badge">${escapeHtml(tx('Current project', '当前项目'))}</span>`
|
|
461
470
|
: `<button type="button" class="codex-provider-primary-button" data-provider-action="activate-builtin">${escapeHtml(tx('Use for this project', '用于当前项目'))}</button>`}
|
|
462
471
|
</div>
|
|
@@ -464,6 +473,7 @@
|
|
|
464
473
|
}
|
|
465
474
|
|
|
466
475
|
function getCurrentProjectProviderId(instance) {
|
|
476
|
+
if (instance.callbacks.hasCurrentProject?.() === false) return '';
|
|
467
477
|
const providerId = instance.callbacks.getCurrentProjectProviderId?.();
|
|
468
478
|
return typeof providerId === 'string' && providerId.trim()
|
|
469
479
|
? providerId.trim()
|
|
@@ -487,6 +497,7 @@
|
|
|
487
497
|
dirty: instance.dirty,
|
|
488
498
|
destinationChanged,
|
|
489
499
|
canSave: canSaveCurrentDraft(instance),
|
|
500
|
+
hasProject: instance.callbacks.hasCurrentProject?.() !== false,
|
|
490
501
|
canActivate: canActivateCurrentProvider(instance)
|
|
491
502
|
});
|
|
492
503
|
const saveDisabled = actionState.saveEnabled ? '' : ' disabled aria-disabled="true"';
|
|
@@ -508,8 +519,8 @@
|
|
|
508
519
|
const dirty = options.dirty === true;
|
|
509
520
|
return {
|
|
510
521
|
showSave: isNew || dirty,
|
|
511
|
-
showSaveAndUse: (isNew || dirty) && (!active || options.destinationChanged === true),
|
|
512
|
-
showUse: !isNew && !active && !dirty,
|
|
522
|
+
showSaveAndUse: options.hasProject !== false && (isNew || dirty) && (!active || options.destinationChanged === true),
|
|
523
|
+
showUse: options.hasProject !== false && !isNew && !active && !dirty,
|
|
513
524
|
saveEnabled: options.canSave === true,
|
|
514
525
|
useEnabled: options.canActivate === true
|
|
515
526
|
};
|
|
@@ -662,7 +673,7 @@
|
|
|
662
673
|
return;
|
|
663
674
|
}
|
|
664
675
|
const focusable = Array.from(instance.root.querySelectorAll('button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled])'))
|
|
665
|
-
.filter(element => !element.closest('[hidden]'));
|
|
676
|
+
.filter(element => !element.closest('[hidden]') && (!element.getClientRects || element.getClientRects().length));
|
|
666
677
|
if (!focusable.length) {
|
|
667
678
|
return;
|
|
668
679
|
}
|
|
@@ -941,8 +952,8 @@
|
|
|
941
952
|
if (!text) return;
|
|
942
953
|
const baseUrl = getCurrentBaseUrl(instance) || instance.tx('this endpoint', '此端点');
|
|
943
954
|
text.textContent = instance.tx(
|
|
944
|
-
`
|
|
945
|
-
|
|
955
|
+
`Projects using this shared provider may send task context to ${baseUrl}. Each project chooses its own provider.`,
|
|
956
|
+
`使用此共享服务配置的项目可能把任务上下文发送到 ${baseUrl}。各项目独立选择使用的服务。`
|
|
946
957
|
);
|
|
947
958
|
}
|
|
948
959
|
|
|
@@ -984,10 +995,7 @@
|
|
|
984
995
|
if (!panel) {
|
|
985
996
|
return;
|
|
986
997
|
}
|
|
987
|
-
const style = instance.document.defaultView.getComputedStyle(panel);
|
|
988
998
|
instance.root.dataset.theme = panel.dataset.theme === 'light' ? 'light' : 'dark';
|
|
989
|
-
instance.root.style.setProperty('--provider-panel-bg', style.backgroundColor || '#151716');
|
|
990
|
-
instance.root.style.setProperty('--provider-panel-color', style.color || '#eceeea');
|
|
991
999
|
}
|
|
992
1000
|
|
|
993
1001
|
function escapeHtml(value) {
|
|
@@ -1011,6 +1019,7 @@
|
|
|
1011
1019
|
}
|
|
1012
1020
|
|
|
1013
1021
|
function destroy(instance) {
|
|
1022
|
+
instance.root?.close?.();
|
|
1014
1023
|
instance.root?.remove?.();
|
|
1015
1024
|
instance.root = null;
|
|
1016
1025
|
}
|
|
@@ -251,10 +251,12 @@
|
|
|
251
251
|
for (const selector of ['[data-governance-readonly-patterns]', '[data-governance-writable-patterns]', '[data-sensitive-check-enabled]', '[data-sensitive-confirm-allowed]', '[data-preload-project-context]', '[data-load-codex-local-skills]', '[data-load-codex-overleaf-skills]', '[data-theme-select]', '[data-language-select]']) {
|
|
252
252
|
const element = container.querySelector(selector);
|
|
253
253
|
element?.addEventListener?.('change', event => {
|
|
254
|
-
instance.callbacks.onInputChange?.(event)
|
|
255
|
-
|
|
254
|
+
Promise.resolve(instance.callbacks.onInputChange?.(event))
|
|
255
|
+
.then(() => flashSaved(instance, event)).catch(() => {});
|
|
256
|
+
});
|
|
257
|
+
element?.addEventListener?.('input', event => {
|
|
258
|
+
Promise.resolve(instance.callbacks.onInputChange?.(event)).catch(() => {});
|
|
256
259
|
});
|
|
257
|
-
element?.addEventListener?.('input', event => instance.callbacks.onInputChange?.(event));
|
|
258
260
|
}
|
|
259
261
|
// Guardrails: live, non-blocking analysis of the protection globs.
|
|
260
262
|
for (const selector of ['[data-governance-readonly-patterns]', '[data-governance-writable-patterns]']) {
|
|
@@ -51,6 +51,9 @@
|
|
|
51
51
|
const resolved = resolveTheme(preference, mediaQueryList);
|
|
52
52
|
if (panelRoot && typeof panelRoot.setAttribute === 'function') {
|
|
53
53
|
panelRoot.setAttribute('data-theme', resolved);
|
|
54
|
+
for (const target of panelRoot.ownerDocument?.querySelectorAll?.('.codex-provider-dialog-root, #codex-overleaf-launcher') || []) {
|
|
55
|
+
target.setAttribute('data-theme', resolved);
|
|
56
|
+
}
|
|
54
57
|
}
|
|
55
58
|
return resolved;
|
|
56
59
|
}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
const MIN_NATIVE_VERSION = '1.0.0';
|
|
13
13
|
const MIN_COMPATIBLE_NATIVE_VERSION = '1.0.0';
|
|
14
14
|
const MIN_COMPATIBLE_EXTENSION_VERSION = '1.0.0';
|
|
15
|
-
const BUILD_TARGET_VERSION = '2.3.
|
|
15
|
+
const BUILD_TARGET_VERSION = '2.3.5';
|
|
16
16
|
const DEFAULT_CHROME_EXTENSION_ID = 'illdpneeeopfffmiepaejglgmhpmdhdc';
|
|
17
17
|
const REQUIRED_CAPABILITIES = Object.freeze([
|
|
18
18
|
'bridgePing',
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
(function (root, factory) {
|
|
2
|
+
const api = factory();
|
|
3
|
+
if (typeof module === 'object' && module.exports) module.exports = api;
|
|
4
|
+
if (root) root.CodexOverleafGlobalPreferences = api;
|
|
5
|
+
})(typeof globalThis !== 'undefined' ? globalThis : this, function () {
|
|
6
|
+
'use strict';
|
|
7
|
+
|
|
8
|
+
const STORAGE_KEY = 'codexOverleafGlobalPrefsV1';
|
|
9
|
+
const LEGACY_KEY = 'codexOverleafPrefs';
|
|
10
|
+
const READ_MESSAGE = 'codex-overleaf/global-preferences/read';
|
|
11
|
+
const PATCH_MESSAGE = 'codex-overleaf/global-preferences/patch';
|
|
12
|
+
const DEFAULTS = Object.freeze({ theme: 'dark', locale: 'en', preloadProjectContext: true,
|
|
13
|
+
loadCodexLocalSkills: true, loadCodexOverleafSkills: true });
|
|
14
|
+
const FIELDS = Object.freeze([...Object.keys(DEFAULTS), 'codexOverleafSkillEnabled']);
|
|
15
|
+
|
|
16
|
+
function validSkillId(id) {
|
|
17
|
+
return /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,79}$/.test(id)
|
|
18
|
+
&& !['__proto__', 'prototype', 'constructor'].includes(id) && !id.includes('..');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function pick(value = {}) {
|
|
22
|
+
const skills = {};
|
|
23
|
+
for (const [id, enabled] of Object.entries(value.codexOverleafSkillEnabled || {}).slice(0, 200)) {
|
|
24
|
+
if (validSkillId(id) && typeof enabled === 'boolean') skills[id] = enabled;
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
theme: ['dark', 'light', 'auto'].includes(value.theme) ? value.theme : 'dark',
|
|
28
|
+
locale: value.locale === 'zh' ? 'zh' : 'en',
|
|
29
|
+
preloadProjectContext: value.preloadProjectContext !== false,
|
|
30
|
+
loadCodexLocalSkills: value.loadCodexLocalSkills !== false,
|
|
31
|
+
loadCodexOverleafSkills: value.loadCodexOverleafSkills !== false,
|
|
32
|
+
codexOverleafSkillEnabled: skills
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function validatePatch(value) {
|
|
37
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) throw new Error('Invalid global preference patch.');
|
|
38
|
+
const patch = {};
|
|
39
|
+
for (const [key, item] of Object.entries(value)) {
|
|
40
|
+
if (!FIELDS.includes(key)) throw new Error('Unknown global preference: ' + key);
|
|
41
|
+
if (key === 'theme' && !['dark', 'light', 'auto'].includes(item)
|
|
42
|
+
|| key === 'locale' && !['en', 'zh'].includes(item)
|
|
43
|
+
|| typeof DEFAULTS[key] === 'boolean' && typeof item !== 'boolean') {
|
|
44
|
+
throw new Error('Invalid global preference: ' + key);
|
|
45
|
+
}
|
|
46
|
+
if (key === 'codexOverleafSkillEnabled') {
|
|
47
|
+
if (!item || typeof item !== 'object' || Array.isArray(item) || Object.keys(item).length > 200) {
|
|
48
|
+
throw new Error('Invalid skill preference map.');
|
|
49
|
+
}
|
|
50
|
+
for (const [id, enabled] of Object.entries(item)) {
|
|
51
|
+
if (!validSkillId(id) || typeof enabled !== 'boolean') throw new Error('Invalid skill preference.');
|
|
52
|
+
}
|
|
53
|
+
patch[key] = { ...item };
|
|
54
|
+
} else patch[key] = item;
|
|
55
|
+
}
|
|
56
|
+
return patch;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function applyPatch(values, patch) {
|
|
60
|
+
return { ...pick(values), ...patch, codexOverleafSkillEnabled: {
|
|
61
|
+
...pick(values).codexOverleafSkillEnabled, ...(patch.codexOverleafSkillEnabled || {})
|
|
62
|
+
} };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function changedKeys(left, right) {
|
|
66
|
+
return FIELDS.filter(key => JSON.stringify(left[key]) !== JSON.stringify(right[key]));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function validateSnapshot(value) {
|
|
70
|
+
if (!value || value.schemaVersion !== 1 || !Number.isSafeInteger(value.revision) || value.revision < 1) {
|
|
71
|
+
throw new Error('Invalid global preference revision.');
|
|
72
|
+
}
|
|
73
|
+
validatePatch(value.values);
|
|
74
|
+
if (!FIELDS.every(key => Object.hasOwn(value.values, key))) throw new Error('Incomplete global preferences.');
|
|
75
|
+
return { schemaVersion: 1, revision: value.revision, values: pick(value.values) };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function createStore(storage) {
|
|
79
|
+
let tail = Promise.resolve();
|
|
80
|
+
function serial(work) {
|
|
81
|
+
const pending = tail.then(work);
|
|
82
|
+
tail = pending.catch(() => {});
|
|
83
|
+
return pending;
|
|
84
|
+
}
|
|
85
|
+
async function read() {
|
|
86
|
+
const stored = await storage.get([STORAGE_KEY, LEGACY_KEY]);
|
|
87
|
+
if (stored[STORAGE_KEY] !== undefined) return validateSnapshot(stored[STORAGE_KEY]);
|
|
88
|
+
const snapshot = { schemaVersion: 1, revision: 1, values: pick(stored[LEGACY_KEY] || {}) };
|
|
89
|
+
await storage.set({ [STORAGE_KEY]: snapshot });
|
|
90
|
+
return snapshot;
|
|
91
|
+
}
|
|
92
|
+
return Object.freeze({
|
|
93
|
+
read: () => serial(read),
|
|
94
|
+
patch: input => serial(async () => {
|
|
95
|
+
const patch = validatePatch(input);
|
|
96
|
+
const previous = await read();
|
|
97
|
+
const values = applyPatch(previous.values, patch);
|
|
98
|
+
if (Object.keys(values.codexOverleafSkillEnabled).length > 200) throw new Error('Too many skill preferences.');
|
|
99
|
+
if (!changedKeys(previous.values, values).length) return previous;
|
|
100
|
+
const snapshot = { schemaVersion: 1, revision: previous.revision + 1, values };
|
|
101
|
+
await storage.set({ [STORAGE_KEY]: snapshot });
|
|
102
|
+
return snapshot;
|
|
103
|
+
})
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function installBackground(chromeApi) {
|
|
108
|
+
const store = createStore(chromeApi.storage?.local);
|
|
109
|
+
chromeApi.runtime.onMessage.addListener((message, sender, respond) => {
|
|
110
|
+
if (![READ_MESSAGE, PATCH_MESSAGE].includes(message?.type)) return undefined;
|
|
111
|
+
let allowed = false;
|
|
112
|
+
try {
|
|
113
|
+
const url = new URL(sender?.tab?.url || '');
|
|
114
|
+
allowed = sender.id === chromeApi.runtime.id && url.protocol === 'https:'
|
|
115
|
+
&& ['overleaf.com', 'www.overleaf.com'].includes(url.hostname)
|
|
116
|
+
&& /^\/project(?:\/|$)/.test(url.pathname);
|
|
117
|
+
} catch (_error) { /* reject unrelated contexts */ }
|
|
118
|
+
if (!allowed) {
|
|
119
|
+
respond({ ok: false, error: { message: 'Global preferences require an Overleaf tab.' } });
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
const pending = message.type === READ_MESSAGE ? store.read() : store.patch(message.patch);
|
|
123
|
+
pending.then(result => respond({ ok: true, result }), error => respond({ ok: false, error: { message: error.message } }));
|
|
124
|
+
return true;
|
|
125
|
+
});
|
|
126
|
+
return store;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return Object.freeze({ STORAGE_KEY, LEGACY_KEY, READ_MESSAGE, PATCH_MESSAGE, FIELDS,
|
|
130
|
+
pick, validatePatch, validateSnapshot, applyPatch, changedKeys, createStore, installBackground });
|
|
131
|
+
});
|
|
@@ -380,7 +380,7 @@
|
|
|
380
380
|
contextReadFailed: 'Could not read files: {message}',
|
|
381
381
|
contextNoFiles: 'No usable text files were read from this Overleaf project.',
|
|
382
382
|
contextSelectedFiles: 'Added {count} @file items. Future tasks will focus on them first.',
|
|
383
|
-
contextDefaultWholeProject: 'Default is the whole project.
|
|
383
|
+
contextDefaultWholeProject: 'Default is the whole project. Choose files or add @compile-log. For a section, name it in your request.',
|
|
384
384
|
preloadProjectContextTitle: 'Preload project context',
|
|
385
385
|
preloadProjectContextDescription: 'Fetch the exact project file list in the background after an Overleaf project becomes idle.',
|
|
386
386
|
contextResourceTitle: '{path} (non-text resource, shown only as project structure for now)',
|
|
@@ -900,7 +900,7 @@
|
|
|
900
900
|
contextReadFailed: '读取文件失败:{message}',
|
|
901
901
|
contextNoFiles: '没有从当前 Overleaf 项目读取到可用文本文件。',
|
|
902
902
|
contextSelectedFiles: '已添加 {count} 个 @file;后续任务会优先围绕它们。',
|
|
903
|
-
contextDefaultWholeProject: '
|
|
903
|
+
contextDefaultWholeProject: '默认使用整个项目。可选择文件或添加 @compile-log;处理章节时请在请求中注明章节名称。',
|
|
904
904
|
preloadProjectContextTitle: '预加载项目上下文',
|
|
905
905
|
preloadProjectContextDescription: 'Overleaf 项目进入空闲状态后,在后台读取精确的项目文件列表。',
|
|
906
906
|
contextResourceTitle: '{path}(非文本资源,当前只作为项目结构显示)',
|
|
@@ -170,14 +170,14 @@
|
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
.codex-provider-dialog-root {
|
|
173
|
-
--provider-bg:
|
|
173
|
+
--provider-bg: #151716;
|
|
174
174
|
--provider-surface: #1c1f1d;
|
|
175
175
|
--provider-surface-raised: #222622;
|
|
176
176
|
--provider-line: rgba(255, 255, 255, 0.12);
|
|
177
177
|
--provider-muted: #a0a59f;
|
|
178
178
|
--provider-accent: #79d58a;
|
|
179
179
|
--provider-danger: #ef8176;
|
|
180
|
-
--provider-text:
|
|
180
|
+
--provider-text: #eef0ec;
|
|
181
181
|
--provider-field-label: #dfe3dd;
|
|
182
182
|
--provider-control-bg: rgba(255, 255, 255, 0.035);
|
|
183
183
|
--provider-hover: rgba(255, 255, 255, 0.07);
|
|
@@ -191,6 +191,14 @@
|
|
|
191
191
|
position: fixed;
|
|
192
192
|
inset: 0;
|
|
193
193
|
z-index: 2147483600;
|
|
194
|
+
margin: 0;
|
|
195
|
+
padding: 0;
|
|
196
|
+
border: 0;
|
|
197
|
+
width: 100vw;
|
|
198
|
+
max-width: none;
|
|
199
|
+
height: 100vh;
|
|
200
|
+
max-height: none;
|
|
201
|
+
background: transparent;
|
|
194
202
|
color: var(--provider-text);
|
|
195
203
|
font-family: "Aptos", "SF Pro Text", sans-serif;
|
|
196
204
|
}
|
|
@@ -217,6 +225,7 @@
|
|
|
217
225
|
}
|
|
218
226
|
|
|
219
227
|
.codex-provider-dialog-root[hidden] { display: none !important; }
|
|
228
|
+
.codex-provider-dialog-root::backdrop { background: transparent; }
|
|
220
229
|
|
|
221
230
|
.codex-provider-dialog-backdrop {
|
|
222
231
|
position: absolute;
|
|
@@ -1801,9 +1810,15 @@
|
|
|
1801
1810
|
box-sizing: border-box;
|
|
1802
1811
|
width: var(--codex-overleaf-panel-width);
|
|
1803
1812
|
height: 100vh;
|
|
1813
|
+
max-width: none;
|
|
1814
|
+
max-height: none;
|
|
1815
|
+
margin: 0;
|
|
1816
|
+
border: 0;
|
|
1817
|
+
color: inherit;
|
|
1804
1818
|
padding: 14px;
|
|
1805
1819
|
background: rgba(12, 12, 12, 0.68);
|
|
1806
1820
|
}
|
|
1821
|
+
#codex-overleaf-panel .codex-plugin-confirm::backdrop { background: transparent; }
|
|
1807
1822
|
|
|
1808
1823
|
#codex-overleaf-panel .codex-plugin-confirm-card {
|
|
1809
1824
|
width: 100%;
|