@walkhi/code-relax 0.1.0-beta.65 → 0.1.0-beta.68
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/dist/bin/codex-remote.mjs +4 -2
- package/dist/bin/manage-relay-admin.mjs +20 -20
- package/dist/bin/migrate-relay-db.mjs +109 -109
- package/dist/bin/publish-harmony-release.mjs +46 -46
- package/dist/bin/self-relay-admin.mjs +8 -8
- package/dist/bin/self-relay-demo.mjs +33 -33
- package/dist/bin/self-relay-server.mjs +66 -66
- package/dist/bin/set-relay-admin-password.mjs +11 -11
- package/dist/build-platform.json +1 -1
- package/dist/get-lan-networks.ps1 +40 -40
- package/dist/shared/app-server-events.cjs +511 -511
- package/dist/shared/p2p-data-channel.cjs +72 -72
- package/dist/shared/p2p-diagnostics.cjs +28 -28
- package/dist/shared/p2p-ice-policy.cjs +22 -22
- package/dist/shared/plan-pricing.cjs +32 -32
- package/dist/shared/question-attention.cjs +69 -69
- package/dist/shared/release-version.cjs +31 -31
- package/dist/src/archived-threads.mjs +22 -22
- package/dist/src/background-process.mjs +18 -18
- package/dist/src/code-browser.mjs +100 -100
- package/dist/src/desktop-launcher.mjs +62 -62
- package/dist/src/dots-task-files.mjs +52 -52
- package/dist/src/execution-health.mjs +26 -26
- package/dist/src/message-images.mjs +9 -9
- package/dist/src/plan-pricing.mjs +47 -47
- package/dist/src/platform/codex-runtime.mjs +3 -3
- package/dist/src/platform/credential-store.mjs +19 -19
- package/dist/src/platform/desktop-host.mjs +3 -3
- package/dist/src/platform/desktop-permission-mode.mjs +17 -17
- package/dist/src/platform/desktop-project-registration.mjs +3 -3
- package/dist/src/platform/file-opener.mjs +9 -9
- package/dist/src/platform/linux/README.md +3 -3
- package/dist/src/platform/linux/codex-runtime.mjs +56 -56
- package/dist/src/platform/linux/desktop-installation.mjs +36 -36
- package/dist/src/platform/linux/desktop-project-registration.mjs +11 -11
- package/dist/src/platform/linux/network-info.mjs +11 -11
- package/dist/src/platform/linux/project-locations.mjs +17 -17
- package/dist/src/platform/linux/resident-startup.mjs +52 -52
- package/dist/src/platform/linux/retained-runtime.mjs +76 -76
- package/dist/src/platform/linux/service-host.mjs +18 -18
- package/dist/src/platform/macos/README.md +3 -3
- package/dist/src/platform/macos/codex-runtime.mjs +0 -4
- package/dist/src/platform/macos/desktop-project-registration.mjs +11 -11
- package/dist/src/platform/macos/network-info.mjs +8 -8
- package/dist/src/platform/macos/project-locations.mjs +8 -8
- package/dist/src/platform/macos/resident-startup.mjs +84 -84
- package/dist/src/platform/macos/retained-runtime.mjs +127 -127
- package/dist/src/platform/macos/service-host.mjs +18 -18
- package/dist/src/platform/macos/system.mjs +29 -29
- package/dist/src/platform/network-info.mjs +3 -3
- package/dist/src/platform/path-identity.mjs +5 -5
- package/dist/src/platform/posix/network-candidates.mjs +23 -23
- package/dist/src/platform/posix/runtime-paths.mjs +25 -25
- package/dist/src/platform/power-inhibitor.mjs +22 -22
- package/dist/src/platform/project-locations.mjs +3 -3
- package/dist/src/platform/runtime-paths.mjs +8 -8
- package/dist/src/platform/select.mjs +5 -5
- package/dist/src/platform/service-host.mjs +3 -3
- package/dist/src/platform/user-environment.mjs +3 -3
- package/dist/src/platform/windows/IsolatedProcess.cs +79 -79
- package/dist/src/platform/windows/background-process.mjs +30 -30
- package/dist/src/platform/windows/desktop-helper.mjs +179 -179
- package/dist/src/platform/windows/desktop-runtime.ps1 +10 -10
- package/dist/src/platform/windows/desktop-shortcuts.ps1 +7 -7
- package/dist/src/platform/windows/keep-awake.ps1 +20 -20
- package/dist/src/platform/windows/network-info.mjs +34 -34
- package/dist/src/platform/windows/resident-start.js +20 -20
- package/dist/src/platform/windows/resident-start.ps1 +7 -7
- package/dist/src/platform/windows/resident-startup.ps1 +83 -83
- package/dist/src/platform/windows/resolve-state-root.ps1 +14 -14
- package/dist/src/platform/windows/runtime-paths.mjs +20 -20
- package/dist/src/platform/windows/rustdesk-video-probe.mjs +167 -167
- package/dist/src/platform/windows/start-hidden-console.ps1 +58 -58
- package/dist/src/platform/windows/stop-desktop.ps1 +22 -22
- package/dist/src/platform/windows/user-environment.ps1 +41 -41
- package/dist/src/project-create.mjs +121 -121
- package/dist/src/project-management.mjs +1 -1
- package/dist/src/project-remove.mjs +55 -55
- package/dist/src/project-update.mjs +59 -59
- package/dist/src/relay-config-import.mjs +45 -45
- package/dist/src/self-relay/account-connections.mjs +52 -52
- package/dist/src/self-relay/admin-auth.mjs +59 -59
- package/dist/src/self-relay/admin-cloud.mjs +101 -101
- package/dist/src/self-relay/admin-login-page.mjs +7 -7
- package/dist/src/self-relay/admin-server.mjs +105 -105
- package/dist/src/self-relay/admin-state.mjs +127 -127
- package/dist/src/self-relay/admin-workstations-page.mjs +95 -95
- package/dist/src/self-relay/admin-workstations.mjs +143 -143
- package/dist/src/self-relay/android-releases.mjs +61 -61
- package/dist/src/self-relay/client.mjs +61 -61
- package/dist/src/self-relay/connection-reporting.mjs +38 -38
- package/dist/src/self-relay/debug-allowlist.mjs +33 -33
- package/dist/src/self-relay/demo.mjs +6 -6
- package/dist/src/self-relay/device-info.mjs +27 -27
- package/dist/src/self-relay/device-store.mjs +92 -92
- package/dist/src/self-relay/lan-authorizations.mjs +71 -71
- package/dist/src/self-relay/lifecycle.mjs +278 -278
- package/dist/src/self-relay/long-pairing.mjs +40 -40
- package/dist/src/self-relay/mysql-state.mjs +118 -118
- package/dist/src/self-relay/phone-connections.mjs +55 -55
- package/dist/src/self-relay/server.mjs +1066 -1066
- package/dist/src/self-relay/usage-daily.mjs +55 -55
- package/dist/src/self-relay/windows-route-helper.mjs +75 -75
- package/dist/src/self-relay/wire.mjs +36 -36
- package/dist/src/server.mjs +1947 -1947
- package/dist/src/service-control.mjs +82 -82
- package/dist/src/service-health.mjs +33 -33
- package/dist/src/service-power.mjs +58 -58
- package/dist/src/service-restart.mjs +81 -81
- package/dist/src/service-update-worker.mjs +42 -42
- package/dist/src/service-update.mjs +80 -80
- package/dist/src/shared-recovery.mjs +152 -152
- package/dist/src/skill-install.mjs +51 -51
- package/dist/src/thread-title-generation.mjs +150 -150
- package/dist/src/turn-model-history.mjs +47 -47
- package/dist/tools/rtc-route-helper.ps1 +99 -99
- package/dist/tools/start-rtc-route-helper.ps1 +15 -15
- package/dist/web/vendor/markdown-it.LICENSE.txt +22 -22
- package/dist/web/vendor/markdown-it.umd.min.js +13 -13
- package/package.json +4 -4
- package/tools/postinstall.mjs +1 -1
|
@@ -1,150 +1,150 @@
|
|
|
1
|
-
import { randomUUID } from 'node:crypto';
|
|
2
|
-
|
|
3
|
-
const TITLE_MODEL = 'gpt-5.6-luna';
|
|
4
|
-
const TITLE_TIMEOUT_MS = 30_000;
|
|
5
|
-
const TITLE_SCHEMA = Object.freeze({
|
|
6
|
-
type: 'object',
|
|
7
|
-
properties: {
|
|
8
|
-
title: { type: 'string', minLength: 1, maxLength: 36 },
|
|
9
|
-
description: { type: 'string', minLength: 1, maxLength: 100 },
|
|
10
|
-
},
|
|
11
|
-
required: ['title', 'description'],
|
|
12
|
-
additionalProperties: false,
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
function titlePrompt(prompt) {
|
|
16
|
-
return [
|
|
17
|
-
'You are a helpful assistant. You will be presented with a user prompt, and your job is to provide a short title for a task that will be created from that prompt.',
|
|
18
|
-
'The title will be shown in the UI to represent the prompt.',
|
|
19
|
-
'Generate a concise UI title of at most 36 characters and fill the structured title field with plain text.',
|
|
20
|
-
'Fill the structured description field with a compact, search-oriented summary of at most 100 characters.',
|
|
21
|
-
'Write both values in the user\'s locale. Do not include quotes, markdown, formatting characters, or trailing punctuation.',
|
|
22
|
-
'Capture the question or core change requested instead of copying the whole prompt.',
|
|
23
|
-
'Do not respond to the user or attempt to solve the problem; only fill the structured fields.',
|
|
24
|
-
'',
|
|
25
|
-
'User prompt:',
|
|
26
|
-
prompt,
|
|
27
|
-
].join('\n');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function normalizeTitle(value) {
|
|
31
|
-
let title = String(value || '').replace(/\r\n/g, '\n').split('\n').find(line => line.trim())?.trim() || '';
|
|
32
|
-
title = title.replace(/^title[:\s]+/i, '');
|
|
33
|
-
title = title.replace(/^[`"'“”‘’]+|[`"'“”‘’]+$/g, '');
|
|
34
|
-
title = title.replace(/\s+/g, ' ').replace(/[.?!。?!]+$/, '').trim();
|
|
35
|
-
if (!title) return null;
|
|
36
|
-
if (title.length <= 36) return title;
|
|
37
|
-
let end = 36;
|
|
38
|
-
if (title[end] !== ' ' && title[end - 1] !== ' ') {
|
|
39
|
-
const nextSpace = title.indexOf(' ', end);
|
|
40
|
-
end = nextSpace < 0 ? title.length : nextSpace;
|
|
41
|
-
}
|
|
42
|
-
const head = title.slice(0, end).trimEnd();
|
|
43
|
-
return title.slice(end).trim() ? `${head}…` : head;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function parseStructuredTitle(text) {
|
|
47
|
-
if (!text?.trim()) return null;
|
|
48
|
-
try {
|
|
49
|
-
const value = JSON.parse(text.trim());
|
|
50
|
-
return normalizeTitle(value?.title);
|
|
51
|
-
} catch {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export async function generateThreadTitle({ request, subscribe, prompt, cwd = null,
|
|
57
|
-
timeoutMs = TITLE_TIMEOUT_MS, uuid = randomUUID }) {
|
|
58
|
-
const source = String(prompt || '').trim();
|
|
59
|
-
if (!source) return null;
|
|
60
|
-
const { thread } = await request('thread/start', {
|
|
61
|
-
model: TITLE_MODEL,
|
|
62
|
-
modelProvider: null,
|
|
63
|
-
allowProviderModelFallback: true,
|
|
64
|
-
cwd,
|
|
65
|
-
approvalPolicy: 'never',
|
|
66
|
-
permissions: ':read-only',
|
|
67
|
-
runtimeWorkspaceRoots: [],
|
|
68
|
-
config: {
|
|
69
|
-
'features.enable_fanout': false,
|
|
70
|
-
'features.hooks': false,
|
|
71
|
-
'features.multi_agent': false,
|
|
72
|
-
'features.multi_agent_v2': false,
|
|
73
|
-
'features.plugins': false,
|
|
74
|
-
'features.shell_snapshot': false,
|
|
75
|
-
'features.tool_suggest': false,
|
|
76
|
-
'features.apps': false,
|
|
77
|
-
'mcp_servers.codex_app': { enabled: false, command: '' },
|
|
78
|
-
apps: { _default: { enabled: false, destructive_enabled: false, open_world_enabled: false } },
|
|
79
|
-
model_reasoning_effort: 'low',
|
|
80
|
-
web_search: 'disabled',
|
|
81
|
-
},
|
|
82
|
-
personality: null,
|
|
83
|
-
ephemeral: true,
|
|
84
|
-
threadSource: 'thread_title',
|
|
85
|
-
experimentalRawEvents: false,
|
|
86
|
-
dynamicTools: null,
|
|
87
|
-
serviceTier: null,
|
|
88
|
-
});
|
|
89
|
-
const threadId = thread.id;
|
|
90
|
-
let message = '';
|
|
91
|
-
let turnId = null;
|
|
92
|
-
let stop = () => {};
|
|
93
|
-
try {
|
|
94
|
-
const completed = new Promise((resolve, reject) => {
|
|
95
|
-
const timer = setTimeout(() => reject(new Error('生成对话标题超时。')), timeoutMs);
|
|
96
|
-
timer.unref?.();
|
|
97
|
-
const unsubscribe = subscribe(({ method, params }) => {
|
|
98
|
-
if (params.threadId !== threadId) return;
|
|
99
|
-
if (method === 'turn/started') turnId = params.turn?.id || turnId;
|
|
100
|
-
if (turnId && params.turnId && params.turnId !== turnId) return;
|
|
101
|
-
if (method === 'item/agentMessage/delta') message += params.delta || '';
|
|
102
|
-
if (method === 'item/completed' && params.item?.type === 'agentMessage') message = params.item.text || message;
|
|
103
|
-
if (method === 'error') {
|
|
104
|
-
clearTimeout(timer);
|
|
105
|
-
reject(new Error(params.error?.message || '生成对话标题失败。'));
|
|
106
|
-
}
|
|
107
|
-
if (method === 'turn/completed') {
|
|
108
|
-
clearTimeout(timer);
|
|
109
|
-
if (params.turn?.status !== 'completed') {
|
|
110
|
-
reject(new Error(params.turn?.error?.message || `生成对话标题失败:${params.turn?.status || 'unknown'}`));
|
|
111
|
-
} else resolve(parseStructuredTitle(message));
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
stop = () => { clearTimeout(timer); unsubscribe(); };
|
|
115
|
-
});
|
|
116
|
-
const started = await request('turn/start', {
|
|
117
|
-
threadId,
|
|
118
|
-
turnTrigger: 'thread_title',
|
|
119
|
-
clientUserMessageId: uuid(),
|
|
120
|
-
input: [{ type: 'text', text: titlePrompt(source), text_elements: [] }],
|
|
121
|
-
cwd: null,
|
|
122
|
-
approvalPolicy: null,
|
|
123
|
-
permissions: ':read-only',
|
|
124
|
-
runtimeWorkspaceRoots: [],
|
|
125
|
-
model: null,
|
|
126
|
-
effort: null,
|
|
127
|
-
serviceTier: null,
|
|
128
|
-
personality: null,
|
|
129
|
-
outputSchema: TITLE_SCHEMA,
|
|
130
|
-
collaborationMode: null,
|
|
131
|
-
});
|
|
132
|
-
turnId ||= started.turn?.id || null;
|
|
133
|
-
return await completed;
|
|
134
|
-
} finally {
|
|
135
|
-
stop();
|
|
136
|
-
await request('thread/unsubscribe', { threadId }).catch(() => {});
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export async function generateAndSetThreadTitle({ request, subscribe, threadId, prompt, cwd = null,
|
|
141
|
-
timeoutMs, uuid }) {
|
|
142
|
-
const title = await generateThreadTitle({ request, subscribe, prompt, cwd, timeoutMs, uuid });
|
|
143
|
-
if (!title) return null;
|
|
144
|
-
const current = await request('thread/read', { threadId, includeTurns: false });
|
|
145
|
-
if (current.thread?.name?.trim()) return null;
|
|
146
|
-
await request('thread/name/set', { threadId, name: title });
|
|
147
|
-
return title;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export const threadTitleInternals = { normalizeTitle, parseStructuredTitle, TITLE_SCHEMA, TITLE_MODEL };
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
const TITLE_MODEL = 'gpt-5.6-luna';
|
|
4
|
+
const TITLE_TIMEOUT_MS = 30_000;
|
|
5
|
+
const TITLE_SCHEMA = Object.freeze({
|
|
6
|
+
type: 'object',
|
|
7
|
+
properties: {
|
|
8
|
+
title: { type: 'string', minLength: 1, maxLength: 36 },
|
|
9
|
+
description: { type: 'string', minLength: 1, maxLength: 100 },
|
|
10
|
+
},
|
|
11
|
+
required: ['title', 'description'],
|
|
12
|
+
additionalProperties: false,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
function titlePrompt(prompt) {
|
|
16
|
+
return [
|
|
17
|
+
'You are a helpful assistant. You will be presented with a user prompt, and your job is to provide a short title for a task that will be created from that prompt.',
|
|
18
|
+
'The title will be shown in the UI to represent the prompt.',
|
|
19
|
+
'Generate a concise UI title of at most 36 characters and fill the structured title field with plain text.',
|
|
20
|
+
'Fill the structured description field with a compact, search-oriented summary of at most 100 characters.',
|
|
21
|
+
'Write both values in the user\'s locale. Do not include quotes, markdown, formatting characters, or trailing punctuation.',
|
|
22
|
+
'Capture the question or core change requested instead of copying the whole prompt.',
|
|
23
|
+
'Do not respond to the user or attempt to solve the problem; only fill the structured fields.',
|
|
24
|
+
'',
|
|
25
|
+
'User prompt:',
|
|
26
|
+
prompt,
|
|
27
|
+
].join('\n');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function normalizeTitle(value) {
|
|
31
|
+
let title = String(value || '').replace(/\r\n/g, '\n').split('\n').find(line => line.trim())?.trim() || '';
|
|
32
|
+
title = title.replace(/^title[:\s]+/i, '');
|
|
33
|
+
title = title.replace(/^[`"'“”‘’]+|[`"'“”‘’]+$/g, '');
|
|
34
|
+
title = title.replace(/\s+/g, ' ').replace(/[.?!。?!]+$/, '').trim();
|
|
35
|
+
if (!title) return null;
|
|
36
|
+
if (title.length <= 36) return title;
|
|
37
|
+
let end = 36;
|
|
38
|
+
if (title[end] !== ' ' && title[end - 1] !== ' ') {
|
|
39
|
+
const nextSpace = title.indexOf(' ', end);
|
|
40
|
+
end = nextSpace < 0 ? title.length : nextSpace;
|
|
41
|
+
}
|
|
42
|
+
const head = title.slice(0, end).trimEnd();
|
|
43
|
+
return title.slice(end).trim() ? `${head}…` : head;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function parseStructuredTitle(text) {
|
|
47
|
+
if (!text?.trim()) return null;
|
|
48
|
+
try {
|
|
49
|
+
const value = JSON.parse(text.trim());
|
|
50
|
+
return normalizeTitle(value?.title);
|
|
51
|
+
} catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function generateThreadTitle({ request, subscribe, prompt, cwd = null,
|
|
57
|
+
timeoutMs = TITLE_TIMEOUT_MS, uuid = randomUUID }) {
|
|
58
|
+
const source = String(prompt || '').trim();
|
|
59
|
+
if (!source) return null;
|
|
60
|
+
const { thread } = await request('thread/start', {
|
|
61
|
+
model: TITLE_MODEL,
|
|
62
|
+
modelProvider: null,
|
|
63
|
+
allowProviderModelFallback: true,
|
|
64
|
+
cwd,
|
|
65
|
+
approvalPolicy: 'never',
|
|
66
|
+
permissions: ':read-only',
|
|
67
|
+
runtimeWorkspaceRoots: [],
|
|
68
|
+
config: {
|
|
69
|
+
'features.enable_fanout': false,
|
|
70
|
+
'features.hooks': false,
|
|
71
|
+
'features.multi_agent': false,
|
|
72
|
+
'features.multi_agent_v2': false,
|
|
73
|
+
'features.plugins': false,
|
|
74
|
+
'features.shell_snapshot': false,
|
|
75
|
+
'features.tool_suggest': false,
|
|
76
|
+
'features.apps': false,
|
|
77
|
+
'mcp_servers.codex_app': { enabled: false, command: '' },
|
|
78
|
+
apps: { _default: { enabled: false, destructive_enabled: false, open_world_enabled: false } },
|
|
79
|
+
model_reasoning_effort: 'low',
|
|
80
|
+
web_search: 'disabled',
|
|
81
|
+
},
|
|
82
|
+
personality: null,
|
|
83
|
+
ephemeral: true,
|
|
84
|
+
threadSource: 'thread_title',
|
|
85
|
+
experimentalRawEvents: false,
|
|
86
|
+
dynamicTools: null,
|
|
87
|
+
serviceTier: null,
|
|
88
|
+
});
|
|
89
|
+
const threadId = thread.id;
|
|
90
|
+
let message = '';
|
|
91
|
+
let turnId = null;
|
|
92
|
+
let stop = () => {};
|
|
93
|
+
try {
|
|
94
|
+
const completed = new Promise((resolve, reject) => {
|
|
95
|
+
const timer = setTimeout(() => reject(new Error('生成对话标题超时。')), timeoutMs);
|
|
96
|
+
timer.unref?.();
|
|
97
|
+
const unsubscribe = subscribe(({ method, params }) => {
|
|
98
|
+
if (params.threadId !== threadId) return;
|
|
99
|
+
if (method === 'turn/started') turnId = params.turn?.id || turnId;
|
|
100
|
+
if (turnId && params.turnId && params.turnId !== turnId) return;
|
|
101
|
+
if (method === 'item/agentMessage/delta') message += params.delta || '';
|
|
102
|
+
if (method === 'item/completed' && params.item?.type === 'agentMessage') message = params.item.text || message;
|
|
103
|
+
if (method === 'error') {
|
|
104
|
+
clearTimeout(timer);
|
|
105
|
+
reject(new Error(params.error?.message || '生成对话标题失败。'));
|
|
106
|
+
}
|
|
107
|
+
if (method === 'turn/completed') {
|
|
108
|
+
clearTimeout(timer);
|
|
109
|
+
if (params.turn?.status !== 'completed') {
|
|
110
|
+
reject(new Error(params.turn?.error?.message || `生成对话标题失败:${params.turn?.status || 'unknown'}`));
|
|
111
|
+
} else resolve(parseStructuredTitle(message));
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
stop = () => { clearTimeout(timer); unsubscribe(); };
|
|
115
|
+
});
|
|
116
|
+
const started = await request('turn/start', {
|
|
117
|
+
threadId,
|
|
118
|
+
turnTrigger: 'thread_title',
|
|
119
|
+
clientUserMessageId: uuid(),
|
|
120
|
+
input: [{ type: 'text', text: titlePrompt(source), text_elements: [] }],
|
|
121
|
+
cwd: null,
|
|
122
|
+
approvalPolicy: null,
|
|
123
|
+
permissions: ':read-only',
|
|
124
|
+
runtimeWorkspaceRoots: [],
|
|
125
|
+
model: null,
|
|
126
|
+
effort: null,
|
|
127
|
+
serviceTier: null,
|
|
128
|
+
personality: null,
|
|
129
|
+
outputSchema: TITLE_SCHEMA,
|
|
130
|
+
collaborationMode: null,
|
|
131
|
+
});
|
|
132
|
+
turnId ||= started.turn?.id || null;
|
|
133
|
+
return await completed;
|
|
134
|
+
} finally {
|
|
135
|
+
stop();
|
|
136
|
+
await request('thread/unsubscribe', { threadId }).catch(() => {});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export async function generateAndSetThreadTitle({ request, subscribe, threadId, prompt, cwd = null,
|
|
141
|
+
timeoutMs, uuid }) {
|
|
142
|
+
const title = await generateThreadTitle({ request, subscribe, prompt, cwd, timeoutMs, uuid });
|
|
143
|
+
if (!title) return null;
|
|
144
|
+
const current = await request('thread/read', { threadId, includeTurns: false });
|
|
145
|
+
if (current.thread?.name?.trim()) return null;
|
|
146
|
+
await request('thread/name/set', { threadId, name: title });
|
|
147
|
+
return title;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export const threadTitleInternals = { normalizeTitle, parseStructuredTitle, TITLE_SCHEMA, TITLE_MODEL };
|
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
|
|
3
|
-
// Read authoritative turn contexts locally; never send rollout text to a terminal.
|
|
4
|
-
export class TurnModelHistory {
|
|
5
|
-
constructor() { this.files = new Map(); }
|
|
6
|
-
|
|
7
|
-
async read(file, turnIds) {
|
|
8
|
-
if (!file || !turnIds.length) return [];
|
|
9
|
-
let state = this.files.get(file);
|
|
10
|
-
if (!state) {
|
|
11
|
-
state = { offset: 0, lastModel: '', turns: new Map(), changes: new Map(), tail: Promise.resolve() };
|
|
12
|
-
this.files.set(file, state);
|
|
13
|
-
if (this.files.size > 16) this.files.delete(this.files.keys().next().value);
|
|
14
|
-
}
|
|
15
|
-
const task = state.tail.then(async () => {
|
|
16
|
-
const stat = await fs.promises.stat(file);
|
|
17
|
-
if (stat.size < state.offset) {
|
|
18
|
-
state.offset = 0; state.lastModel = ''; state.turns.clear(); state.changes.clear();
|
|
19
|
-
}
|
|
20
|
-
if (stat.size > state.offset) {
|
|
21
|
-
let pending = Buffer.alloc(0);
|
|
22
|
-
const stream = fs.createReadStream(file, { start: state.offset, end: stat.size - 1 });
|
|
23
|
-
for await (const chunk of stream) {
|
|
24
|
-
const data = pending.length ? Buffer.concat([pending, chunk]) : chunk;
|
|
25
|
-
let start = 0, end;
|
|
26
|
-
while ((end = data.indexOf(10, start)) !== -1) {
|
|
27
|
-
const line = data.subarray(start, end);
|
|
28
|
-
if (line.subarray(0, 160).includes(Buffer.from('"turn_context"'))) {
|
|
29
|
-
const event = JSON.parse(line.toString('utf8'));
|
|
30
|
-
const { turn_id: turnId, model } = event.payload || {};
|
|
31
|
-
if (event.type === 'turn_context' && typeof turnId === 'string' && typeof model === 'string' && model && !state.turns.has(turnId)) {
|
|
32
|
-
if (state.lastModel && state.lastModel !== model) state.changes.set(turnId, { turnId, fromModel: state.lastModel, toModel: model });
|
|
33
|
-
state.turns.set(turnId, model); state.lastModel = model;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
state.offset += end - start + 1;
|
|
37
|
-
start = end + 1;
|
|
38
|
-
}
|
|
39
|
-
pending = data.subarray(start);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return turnIds.flatMap(id => state.changes.has(id) ? [state.changes.get(id)] : []);
|
|
43
|
-
});
|
|
44
|
-
state.tail = task.catch(() => {});
|
|
45
|
-
return task;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
|
|
3
|
+
// Read authoritative turn contexts locally; never send rollout text to a terminal.
|
|
4
|
+
export class TurnModelHistory {
|
|
5
|
+
constructor() { this.files = new Map(); }
|
|
6
|
+
|
|
7
|
+
async read(file, turnIds) {
|
|
8
|
+
if (!file || !turnIds.length) return [];
|
|
9
|
+
let state = this.files.get(file);
|
|
10
|
+
if (!state) {
|
|
11
|
+
state = { offset: 0, lastModel: '', turns: new Map(), changes: new Map(), tail: Promise.resolve() };
|
|
12
|
+
this.files.set(file, state);
|
|
13
|
+
if (this.files.size > 16) this.files.delete(this.files.keys().next().value);
|
|
14
|
+
}
|
|
15
|
+
const task = state.tail.then(async () => {
|
|
16
|
+
const stat = await fs.promises.stat(file);
|
|
17
|
+
if (stat.size < state.offset) {
|
|
18
|
+
state.offset = 0; state.lastModel = ''; state.turns.clear(); state.changes.clear();
|
|
19
|
+
}
|
|
20
|
+
if (stat.size > state.offset) {
|
|
21
|
+
let pending = Buffer.alloc(0);
|
|
22
|
+
const stream = fs.createReadStream(file, { start: state.offset, end: stat.size - 1 });
|
|
23
|
+
for await (const chunk of stream) {
|
|
24
|
+
const data = pending.length ? Buffer.concat([pending, chunk]) : chunk;
|
|
25
|
+
let start = 0, end;
|
|
26
|
+
while ((end = data.indexOf(10, start)) !== -1) {
|
|
27
|
+
const line = data.subarray(start, end);
|
|
28
|
+
if (line.subarray(0, 160).includes(Buffer.from('"turn_context"'))) {
|
|
29
|
+
const event = JSON.parse(line.toString('utf8'));
|
|
30
|
+
const { turn_id: turnId, model } = event.payload || {};
|
|
31
|
+
if (event.type === 'turn_context' && typeof turnId === 'string' && typeof model === 'string' && model && !state.turns.has(turnId)) {
|
|
32
|
+
if (state.lastModel && state.lastModel !== model) state.changes.set(turnId, { turnId, fromModel: state.lastModel, toModel: model });
|
|
33
|
+
state.turns.set(turnId, model); state.lastModel = model;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
state.offset += end - start + 1;
|
|
37
|
+
start = end + 1;
|
|
38
|
+
}
|
|
39
|
+
pending = data.subarray(start);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return turnIds.flatMap(id => state.changes.has(id) ? [state.changes.get(id)] : []);
|
|
43
|
+
});
|
|
44
|
+
state.tail = task.catch(() => {});
|
|
45
|
+
return task;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
param(
|
|
2
|
-
[Parameter(Mandatory = $true)][string]$Token,
|
|
3
|
-
[int]$IdleSeconds = 1800
|
|
4
|
-
)
|
|
5
|
-
|
|
6
|
-
$ErrorActionPreference = 'Stop'
|
|
7
|
-
$pipeName = 'CodeRelaxRtcRouteHelper'
|
|
8
|
-
$leases = @{}
|
|
9
|
-
$pipeSecurity = [System.IO.Pipes.PipeSecurity]::new()
|
|
10
|
-
$currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().User
|
|
11
|
-
$pipeSecurity.AddAccessRule([System.IO.Pipes.PipeAccessRule]::new($currentUser, [System.IO.Pipes.PipeAccessRights]::ReadWrite,
|
|
12
|
-
[System.Security.AccessControl.AccessControlType]::Allow))
|
|
13
|
-
$pipeSecurity.AddAccessRule([System.IO.Pipes.PipeAccessRule]::new([System.Security.Principal.SecurityIdentifier]::new('S-1-5-18'),
|
|
14
|
-
[System.IO.Pipes.PipeAccessRights]::FullControl, [System.Security.AccessControl.AccessControlType]::Allow))
|
|
15
|
-
$pipeSecurity.AddAccessRule([System.IO.Pipes.PipeAccessRule]::new([System.Security.Principal.SecurityIdentifier]::new('S-1-5-32-544'),
|
|
16
|
-
[System.IO.Pipes.PipeAccessRights]::FullControl, [System.Security.AccessControl.AccessControlType]::Allow))
|
|
17
|
-
|
|
18
|
-
function Test-PublicIpv4([string]$Address) {
|
|
19
|
-
$parts = $Address.Split('.')
|
|
20
|
-
if ($parts.Count -ne 4) { return $false }
|
|
21
|
-
try { $bytes = $parts | ForEach-Object { [byte]$_ } } catch { return $false }
|
|
22
|
-
$a = $bytes[0]; $b = $bytes[1]
|
|
23
|
-
return $a -ne 0 -and $a -ne 10 -and $a -ne 127 -and $a -lt 224 -and -not ($a -eq 169 -and $b -eq 254) -and
|
|
24
|
-
-not ($a -eq 172 -and $b -ge 16 -and $b -le 31) -and -not ($a -eq 192 -and $b -eq 168) -and
|
|
25
|
-
-not ($a -eq 100 -and $b -ge 64 -and $b -le 127) -and -not ($a -eq 198 -and ($b -eq 18 -or $b -eq 19))
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function Get-PhysicalDefaultRoute {
|
|
29
|
-
$routes = Get-NetRoute -DestinationPrefix '0.0.0.0/0' -AddressFamily IPv4 | Where-Object {
|
|
30
|
-
$adapter = Get-NetAdapter -InterfaceIndex $_.InterfaceIndex -ErrorAction SilentlyContinue
|
|
31
|
-
$_.NextHop -and $_.NextHop -ne '0.0.0.0' -and $adapter.Status -eq 'Up' -and $adapter.HardwareInterface -eq $true -and $adapter.Virtual -ne $true
|
|
32
|
-
} | Sort-Object @{ Expression = { $_.RouteMetric + $_.InterfaceMetric } }
|
|
33
|
-
foreach ($route in $routes) {
|
|
34
|
-
$adapter = Get-NetAdapter -InterfaceIndex $route.InterfaceIndex -ErrorAction SilentlyContinue
|
|
35
|
-
if ($adapter.Name -notmatch 'Mihomo|Meta|Tunnel|VPN|TAP|Wintun') { return $route }
|
|
36
|
-
}
|
|
37
|
-
throw '找不到活动物理 IPv4 默认路由'
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function Clear-ExpiredRoutes {
|
|
41
|
-
$now = Get-Date
|
|
42
|
-
foreach ($address in @($leases.Keys)) {
|
|
43
|
-
if ($leases[$address].expires -gt $now) { continue }
|
|
44
|
-
$lease = $leases[$address]
|
|
45
|
-
if ($lease.created) {
|
|
46
|
-
Get-NetRoute -DestinationPrefix "$address/32" -InterfaceIndex $lease.ifIndex -NextHop $lease.nextHop -ErrorAction SilentlyContinue |
|
|
47
|
-
Remove-NetRoute -Confirm:$false -ErrorAction SilentlyContinue
|
|
48
|
-
}
|
|
49
|
-
$leases.Remove($address)
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function Clear-AllRoutes {
|
|
54
|
-
foreach ($address in @($leases.Keys)) {
|
|
55
|
-
$lease = $leases[$address]
|
|
56
|
-
if ($lease.created) {
|
|
57
|
-
Get-NetRoute -DestinationPrefix "$address/32" -InterfaceIndex $lease.ifIndex -NextHop $lease.nextHop -ErrorAction SilentlyContinue |
|
|
58
|
-
Remove-NetRoute -Confirm:$false -ErrorAction SilentlyContinue
|
|
59
|
-
}
|
|
60
|
-
$leases.Remove($address)
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
try {
|
|
65
|
-
$deadline = (Get-Date).AddSeconds($IdleSeconds)
|
|
66
|
-
while ((Get-Date) -lt $deadline) {
|
|
67
|
-
Clear-ExpiredRoutes
|
|
68
|
-
$server = [System.IO.Pipes.NamedPipeServerStream]::new($pipeName, [System.IO.Pipes.PipeDirection]::InOut, 1,
|
|
69
|
-
[System.IO.Pipes.PipeTransmissionMode]::Byte, [System.IO.Pipes.PipeOptions]::Asynchronous, 0, 0, $pipeSecurity)
|
|
70
|
-
$writer = $null
|
|
71
|
-
try {
|
|
72
|
-
$wait = $server.WaitForConnectionAsync()
|
|
73
|
-
if (-not $wait.Wait(1000)) { continue }
|
|
74
|
-
$reader = [System.IO.StreamReader]::new($server)
|
|
75
|
-
$writer = [System.IO.StreamWriter]::new($server); $writer.AutoFlush = $true
|
|
76
|
-
$request = $reader.ReadLine() | ConvertFrom-Json
|
|
77
|
-
if ($request.token -cne $Token -or $request.action -ne 'add') { throw '请求未授权' }
|
|
78
|
-
$ttl = [Math]::Min([Math]::Max([int]$request.ttlSeconds, 15), 180)
|
|
79
|
-
$route = Get-PhysicalDefaultRoute
|
|
80
|
-
$rawAddresses = @($request.addresses)
|
|
81
|
-
$addresses = @($rawAddresses | Where-Object { Test-PublicIpv4 $_ } | Select-Object -Unique)
|
|
82
|
-
if ($addresses.Count -ne $rawAddresses.Count -or $addresses.Count -gt 8) { throw '路由目标无效' }
|
|
83
|
-
foreach ($address in $addresses) {
|
|
84
|
-
$created = $leases[$address].created -eq $true
|
|
85
|
-
if (-not $leases.ContainsKey($address) -and -not (Get-NetRoute -DestinationPrefix "$address/32" -InterfaceIndex $route.InterfaceIndex -NextHop $route.NextHop -ErrorAction SilentlyContinue)) {
|
|
86
|
-
New-NetRoute -DestinationPrefix "$address/32" -InterfaceIndex $route.InterfaceIndex -NextHop $route.NextHop -RouteMetric 5 -PolicyStore ActiveStore | Out-Null
|
|
87
|
-
$created = $true
|
|
88
|
-
}
|
|
89
|
-
$leases[$address] = @{ expires = (Get-Date).AddSeconds($ttl); ifIndex = $route.InterfaceIndex; nextHop = $route.NextHop; created = $created }
|
|
90
|
-
}
|
|
91
|
-
$writer.WriteLine((@{ ok = $true; count = $addresses.Count } | ConvertTo-Json -Compress))
|
|
92
|
-
}
|
|
93
|
-
catch {
|
|
94
|
-
if ($writer) { $writer.WriteLine((@{ ok = $false; error = $_.Exception.Message } | ConvertTo-Json -Compress)) }
|
|
95
|
-
}
|
|
96
|
-
finally { $server.Dispose() }
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
finally { Clear-AllRoutes }
|
|
1
|
+
param(
|
|
2
|
+
[Parameter(Mandatory = $true)][string]$Token,
|
|
3
|
+
[int]$IdleSeconds = 1800
|
|
4
|
+
)
|
|
5
|
+
|
|
6
|
+
$ErrorActionPreference = 'Stop'
|
|
7
|
+
$pipeName = 'CodeRelaxRtcRouteHelper'
|
|
8
|
+
$leases = @{}
|
|
9
|
+
$pipeSecurity = [System.IO.Pipes.PipeSecurity]::new()
|
|
10
|
+
$currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().User
|
|
11
|
+
$pipeSecurity.AddAccessRule([System.IO.Pipes.PipeAccessRule]::new($currentUser, [System.IO.Pipes.PipeAccessRights]::ReadWrite,
|
|
12
|
+
[System.Security.AccessControl.AccessControlType]::Allow))
|
|
13
|
+
$pipeSecurity.AddAccessRule([System.IO.Pipes.PipeAccessRule]::new([System.Security.Principal.SecurityIdentifier]::new('S-1-5-18'),
|
|
14
|
+
[System.IO.Pipes.PipeAccessRights]::FullControl, [System.Security.AccessControl.AccessControlType]::Allow))
|
|
15
|
+
$pipeSecurity.AddAccessRule([System.IO.Pipes.PipeAccessRule]::new([System.Security.Principal.SecurityIdentifier]::new('S-1-5-32-544'),
|
|
16
|
+
[System.IO.Pipes.PipeAccessRights]::FullControl, [System.Security.AccessControl.AccessControlType]::Allow))
|
|
17
|
+
|
|
18
|
+
function Test-PublicIpv4([string]$Address) {
|
|
19
|
+
$parts = $Address.Split('.')
|
|
20
|
+
if ($parts.Count -ne 4) { return $false }
|
|
21
|
+
try { $bytes = $parts | ForEach-Object { [byte]$_ } } catch { return $false }
|
|
22
|
+
$a = $bytes[0]; $b = $bytes[1]
|
|
23
|
+
return $a -ne 0 -and $a -ne 10 -and $a -ne 127 -and $a -lt 224 -and -not ($a -eq 169 -and $b -eq 254) -and
|
|
24
|
+
-not ($a -eq 172 -and $b -ge 16 -and $b -le 31) -and -not ($a -eq 192 -and $b -eq 168) -and
|
|
25
|
+
-not ($a -eq 100 -and $b -ge 64 -and $b -le 127) -and -not ($a -eq 198 -and ($b -eq 18 -or $b -eq 19))
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function Get-PhysicalDefaultRoute {
|
|
29
|
+
$routes = Get-NetRoute -DestinationPrefix '0.0.0.0/0' -AddressFamily IPv4 | Where-Object {
|
|
30
|
+
$adapter = Get-NetAdapter -InterfaceIndex $_.InterfaceIndex -ErrorAction SilentlyContinue
|
|
31
|
+
$_.NextHop -and $_.NextHop -ne '0.0.0.0' -and $adapter.Status -eq 'Up' -and $adapter.HardwareInterface -eq $true -and $adapter.Virtual -ne $true
|
|
32
|
+
} | Sort-Object @{ Expression = { $_.RouteMetric + $_.InterfaceMetric } }
|
|
33
|
+
foreach ($route in $routes) {
|
|
34
|
+
$adapter = Get-NetAdapter -InterfaceIndex $route.InterfaceIndex -ErrorAction SilentlyContinue
|
|
35
|
+
if ($adapter.Name -notmatch 'Mihomo|Meta|Tunnel|VPN|TAP|Wintun') { return $route }
|
|
36
|
+
}
|
|
37
|
+
throw '找不到活动物理 IPv4 默认路由'
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function Clear-ExpiredRoutes {
|
|
41
|
+
$now = Get-Date
|
|
42
|
+
foreach ($address in @($leases.Keys)) {
|
|
43
|
+
if ($leases[$address].expires -gt $now) { continue }
|
|
44
|
+
$lease = $leases[$address]
|
|
45
|
+
if ($lease.created) {
|
|
46
|
+
Get-NetRoute -DestinationPrefix "$address/32" -InterfaceIndex $lease.ifIndex -NextHop $lease.nextHop -ErrorAction SilentlyContinue |
|
|
47
|
+
Remove-NetRoute -Confirm:$false -ErrorAction SilentlyContinue
|
|
48
|
+
}
|
|
49
|
+
$leases.Remove($address)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function Clear-AllRoutes {
|
|
54
|
+
foreach ($address in @($leases.Keys)) {
|
|
55
|
+
$lease = $leases[$address]
|
|
56
|
+
if ($lease.created) {
|
|
57
|
+
Get-NetRoute -DestinationPrefix "$address/32" -InterfaceIndex $lease.ifIndex -NextHop $lease.nextHop -ErrorAction SilentlyContinue |
|
|
58
|
+
Remove-NetRoute -Confirm:$false -ErrorAction SilentlyContinue
|
|
59
|
+
}
|
|
60
|
+
$leases.Remove($address)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
$deadline = (Get-Date).AddSeconds($IdleSeconds)
|
|
66
|
+
while ((Get-Date) -lt $deadline) {
|
|
67
|
+
Clear-ExpiredRoutes
|
|
68
|
+
$server = [System.IO.Pipes.NamedPipeServerStream]::new($pipeName, [System.IO.Pipes.PipeDirection]::InOut, 1,
|
|
69
|
+
[System.IO.Pipes.PipeTransmissionMode]::Byte, [System.IO.Pipes.PipeOptions]::Asynchronous, 0, 0, $pipeSecurity)
|
|
70
|
+
$writer = $null
|
|
71
|
+
try {
|
|
72
|
+
$wait = $server.WaitForConnectionAsync()
|
|
73
|
+
if (-not $wait.Wait(1000)) { continue }
|
|
74
|
+
$reader = [System.IO.StreamReader]::new($server)
|
|
75
|
+
$writer = [System.IO.StreamWriter]::new($server); $writer.AutoFlush = $true
|
|
76
|
+
$request = $reader.ReadLine() | ConvertFrom-Json
|
|
77
|
+
if ($request.token -cne $Token -or $request.action -ne 'add') { throw '请求未授权' }
|
|
78
|
+
$ttl = [Math]::Min([Math]::Max([int]$request.ttlSeconds, 15), 180)
|
|
79
|
+
$route = Get-PhysicalDefaultRoute
|
|
80
|
+
$rawAddresses = @($request.addresses)
|
|
81
|
+
$addresses = @($rawAddresses | Where-Object { Test-PublicIpv4 $_ } | Select-Object -Unique)
|
|
82
|
+
if ($addresses.Count -ne $rawAddresses.Count -or $addresses.Count -gt 8) { throw '路由目标无效' }
|
|
83
|
+
foreach ($address in $addresses) {
|
|
84
|
+
$created = $leases[$address].created -eq $true
|
|
85
|
+
if (-not $leases.ContainsKey($address) -and -not (Get-NetRoute -DestinationPrefix "$address/32" -InterfaceIndex $route.InterfaceIndex -NextHop $route.NextHop -ErrorAction SilentlyContinue)) {
|
|
86
|
+
New-NetRoute -DestinationPrefix "$address/32" -InterfaceIndex $route.InterfaceIndex -NextHop $route.NextHop -RouteMetric 5 -PolicyStore ActiveStore | Out-Null
|
|
87
|
+
$created = $true
|
|
88
|
+
}
|
|
89
|
+
$leases[$address] = @{ expires = (Get-Date).AddSeconds($ttl); ifIndex = $route.InterfaceIndex; nextHop = $route.NextHop; created = $created }
|
|
90
|
+
}
|
|
91
|
+
$writer.WriteLine((@{ ok = $true; count = $addresses.Count } | ConvertTo-Json -Compress))
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
if ($writer) { $writer.WriteLine((@{ ok = $false; error = $_.Exception.Message } | ConvertTo-Json -Compress)) }
|
|
95
|
+
}
|
|
96
|
+
finally { $server.Dispose() }
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
finally { Clear-AllRoutes }
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
$ErrorActionPreference = 'Stop'
|
|
2
|
-
$roots = @(
|
|
3
|
-
(Join-Path $env:LOCALAPPDATA 'CodexRemote'),
|
|
4
|
-
(Join-Path $env:LOCALAPPDATA 'Packages\OpenAI.Codex_2p2nqsd0c76g0\LocalCache\Local\CodexRemote')
|
|
5
|
-
)
|
|
6
|
-
$config = $null
|
|
7
|
-
foreach ($root in $roots) {
|
|
8
|
-
$path = Join-Path $root 'self-relay-config.json'
|
|
9
|
-
if (-not (Test-Path -LiteralPath $path)) { continue }
|
|
10
|
-
$value = Get-Content -LiteralPath $path -Raw -Encoding UTF8 | ConvertFrom-Json
|
|
11
|
-
if ($value.p2pWindowsRouteHelper -eq $true -and $value.p2pWindowsRouteHelperToken) { $config = $value; break }
|
|
12
|
-
}
|
|
13
|
-
if (-not $config) { throw '未找到已启用的 RTC 路由辅助配置' }
|
|
14
|
-
$helper = Join-Path $PSScriptRoot 'rtc-route-helper.ps1'
|
|
15
|
-
& $helper -Token $config.p2pWindowsRouteHelperToken -IdleSeconds 1800
|
|
1
|
+
$ErrorActionPreference = 'Stop'
|
|
2
|
+
$roots = @(
|
|
3
|
+
(Join-Path $env:LOCALAPPDATA 'CodexRemote'),
|
|
4
|
+
(Join-Path $env:LOCALAPPDATA 'Packages\OpenAI.Codex_2p2nqsd0c76g0\LocalCache\Local\CodexRemote')
|
|
5
|
+
)
|
|
6
|
+
$config = $null
|
|
7
|
+
foreach ($root in $roots) {
|
|
8
|
+
$path = Join-Path $root 'self-relay-config.json'
|
|
9
|
+
if (-not (Test-Path -LiteralPath $path)) { continue }
|
|
10
|
+
$value = Get-Content -LiteralPath $path -Raw -Encoding UTF8 | ConvertFrom-Json
|
|
11
|
+
if ($value.p2pWindowsRouteHelper -eq $true -and $value.p2pWindowsRouteHelperToken) { $config = $value; break }
|
|
12
|
+
}
|
|
13
|
+
if (-not $config) { throw '未找到已启用的 RTC 路由辅助配置' }
|
|
14
|
+
$helper = Join-Path $PSScriptRoot 'rtc-route-helper.ps1'
|
|
15
|
+
& $helper -Token $config.p2pWindowsRouteHelperToken -IdleSeconds 1800
|