@walkhi/code-relax 0.1.0-beta.30 → 0.1.0-beta.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/README.md +95 -89
  2. package/dist/bin/cleanup-accounts.mjs +63 -63
  3. package/dist/bin/codex-remote.mjs +374 -367
  4. package/dist/bin/manage-relay-admin.mjs +20 -20
  5. package/dist/bin/migrate-relay-db.mjs +109 -109
  6. package/dist/bin/publish-android-release.mjs +63 -58
  7. package/dist/bin/publish-harmony-release.mjs +46 -0
  8. package/dist/bin/release-upload-server.mjs +174 -0
  9. package/dist/bin/self-relay-admin.mjs +8 -8
  10. package/dist/bin/self-relay-demo.mjs +33 -33
  11. package/dist/bin/self-relay-server.mjs +66 -66
  12. package/dist/build-platform.json +1 -1
  13. package/dist/get-lan-networks.ps1 +40 -40
  14. package/dist/get-shared-service-url.ps1 +6 -6
  15. package/dist/shared/app-server-events.cjs +422 -412
  16. package/dist/shared/code-browser.cjs +159 -159
  17. package/dist/shared/file-changes.cjs +31 -31
  18. package/dist/shared/file-citations.cjs +117 -117
  19. package/dist/shared/file-mentions.cjs +92 -92
  20. package/dist/shared/message-delivery.cjs +54 -54
  21. package/dist/shared/p2p-data-channel.cjs +72 -72
  22. package/dist/shared/p2p-diagnostics.cjs +28 -28
  23. package/dist/shared/p2p-file-channel.cjs +78 -74
  24. package/dist/shared/plan-pricing.cjs +32 -32
  25. package/dist/shared/question-attention.cjs +69 -0
  26. package/dist/shared/server-requests.cjs +219 -219
  27. package/dist/shared/timeline-sync.cjs +173 -173
  28. package/dist/skills/code-relax/SKILL.md +22 -22
  29. package/dist/src/archived-threads.mjs +22 -0
  30. package/dist/src/background-process.mjs +18 -18
  31. package/dist/src/bounded-process-log.mjs +63 -63
  32. package/dist/src/celsius-client.mjs +107 -107
  33. package/dist/src/code-browser.mjs +100 -100
  34. package/dist/src/desktop-launcher.mjs +46 -46
  35. package/dist/src/dots-approval-timeline.mjs +99 -99
  36. package/dist/src/dots-avatar.mjs +42 -42
  37. package/dist/src/dots-chat-projection.mjs +50 -50
  38. package/dist/src/dots-chat-server.mjs +461 -461
  39. package/dist/src/dots-message-images.mjs +319 -319
  40. package/dist/src/dots-profile.mjs +77 -77
  41. package/dist/src/dots-room-activity.mjs +94 -94
  42. package/dist/src/dots-room-client.mjs +135 -135
  43. package/dist/src/dots-room-projection.mjs +94 -94
  44. package/dist/src/dots-schedules.mjs +66 -66
  45. package/dist/src/dots-summary-tasks.mjs +32 -32
  46. package/dist/src/dots-task-catalog.mjs +430 -430
  47. package/dist/src/dots-task-files.mjs +52 -52
  48. package/dist/src/execution-health.mjs +26 -26
  49. package/dist/src/file-transfer-range.mjs +22 -22
  50. package/dist/src/file-upload-session.mjs +130 -130
  51. package/dist/src/hosted-history-app-server.mjs +103 -103
  52. package/dist/src/hosted-history-cache.mjs +113 -113
  53. package/dist/src/lan-socket-server.mjs +265 -263
  54. package/dist/src/managed-app-server.mjs +244 -244
  55. package/dist/src/message-images.mjs +9 -9
  56. package/dist/src/message-upload-files.mjs +74 -74
  57. package/dist/src/onboarding.mjs +12 -12
  58. package/dist/src/plan-pricing.mjs +47 -47
  59. package/dist/src/platform/README.md +12 -12
  60. package/dist/src/platform/codex-protocol.mjs +46 -46
  61. package/dist/src/platform/codex-runtime.mjs +3 -3
  62. package/dist/src/platform/credential-store.mjs +3 -3
  63. package/dist/src/platform/desktop-host.mjs +3 -3
  64. package/dist/src/platform/desktop-project-registration.mjs +3 -3
  65. package/dist/src/platform/desktop-project-store.mjs +208 -149
  66. package/dist/src/platform/file-opener.mjs +9 -0
  67. package/dist/src/platform/linux/README.md +3 -3
  68. package/dist/src/platform/linux/codex-runtime.mjs +56 -0
  69. package/dist/src/platform/linux/credential-store.mjs +28 -0
  70. package/dist/src/platform/linux/desktop-host.mjs +83 -0
  71. package/dist/src/platform/linux/desktop-installation.mjs +36 -0
  72. package/dist/src/platform/linux/desktop-project-registration.mjs +11 -0
  73. package/dist/src/platform/linux/network-info.mjs +11 -0
  74. package/dist/src/platform/linux/process.mjs +42 -0
  75. package/dist/src/platform/linux/project-locations.mjs +17 -0
  76. package/dist/src/platform/linux/resident-startup.mjs +52 -0
  77. package/dist/src/platform/linux/retained-runtime.mjs +76 -0
  78. package/dist/src/platform/linux/service-host.mjs +18 -0
  79. package/dist/src/platform/linux/system.mjs +49 -0
  80. package/dist/src/platform/linux/user-environment.mjs +7 -0
  81. package/dist/src/platform/macos/README.md +3 -3
  82. package/dist/src/platform/macos/codex-runtime.mjs +125 -125
  83. package/dist/src/platform/macos/credential-store.mjs +10 -10
  84. package/dist/src/platform/macos/desktop-host.mjs +82 -82
  85. package/dist/src/platform/macos/desktop-project-registration.mjs +11 -10
  86. package/dist/src/platform/macos/network-info.mjs +8 -28
  87. package/dist/src/platform/macos/project-locations.mjs +8 -8
  88. package/dist/src/platform/macos/resident-startup.mjs +84 -84
  89. package/dist/src/platform/macos/retained-runtime.mjs +127 -127
  90. package/dist/src/platform/macos/service-host.mjs +18 -18
  91. package/dist/src/platform/macos/system.mjs +29 -29
  92. package/dist/src/platform/macos/user-environment.mjs +7 -7
  93. package/dist/src/platform/native-package.mjs +58 -46
  94. package/dist/src/platform/network-info.mjs +3 -3
  95. package/dist/src/platform/path-identity.mjs +5 -5
  96. package/dist/src/platform/posix/network-candidates.mjs +23 -0
  97. package/dist/src/platform/posix/runtime-paths.mjs +25 -25
  98. package/dist/src/platform/project-locations.mjs +3 -3
  99. package/dist/src/platform/runtime-paths.mjs +8 -8
  100. package/dist/src/platform/select.mjs +5 -5
  101. package/dist/src/platform/service-host.mjs +3 -3
  102. package/dist/src/platform/user-environment.mjs +3 -3
  103. package/dist/src/platform/windows/IsolatedProcess.cs +79 -79
  104. package/dist/src/platform/windows/activate-desktop.ps1 +48 -48
  105. package/dist/src/platform/windows/background-process.mjs +30 -30
  106. package/dist/src/platform/windows/codex-runtime.mjs +215 -215
  107. package/dist/src/platform/windows/credential-store.mjs +27 -27
  108. package/dist/src/platform/windows/credential-store.ps1 +49 -49
  109. package/dist/src/platform/windows/desktop-helper.mjs +179 -179
  110. package/dist/src/platform/windows/desktop-host.mjs +58 -58
  111. package/dist/src/platform/windows/desktop-info.ps1 +14 -14
  112. package/dist/src/platform/windows/desktop-project-registration.mjs +4 -4
  113. package/dist/src/platform/windows/desktop-runtime.ps1 +10 -10
  114. package/dist/src/platform/windows/desktop-shortcuts.ps1 +21 -21
  115. package/dist/src/platform/windows/dots-profile.mjs +49 -49
  116. package/dist/src/platform/windows/launch-worker.mjs +41 -41
  117. package/dist/src/platform/windows/network-info.mjs +34 -34
  118. package/dist/src/platform/windows/project-locations.mjs +16 -16
  119. package/dist/src/platform/windows/resident-start.js +20 -20
  120. package/dist/src/platform/windows/resident-start.ps1 +7 -7
  121. package/dist/src/platform/windows/resident-startup.ps1 +83 -83
  122. package/dist/src/platform/windows/resolve-state-root.ps1 +14 -14
  123. package/dist/src/platform/windows/runtime-paths.mjs +20 -20
  124. package/dist/src/platform/windows/rustdesk-video-probe.mjs +167 -167
  125. package/dist/src/platform/windows/service-host.mjs +31 -31
  126. package/dist/src/platform/windows/start-hidden-console.ps1 +49 -49
  127. package/dist/src/platform/windows/stop-desktop.ps1 +22 -22
  128. package/dist/src/platform/windows/user-environment.mjs +50 -50
  129. package/dist/src/platform/windows/user-environment.ps1 +41 -41
  130. package/dist/src/project-archive.mjs +30 -0
  131. package/dist/src/project-create.mjs +121 -119
  132. package/dist/src/project-management.mjs +59 -69
  133. package/dist/src/project-remove.mjs +55 -0
  134. package/dist/src/project-update.mjs +56 -0
  135. package/dist/src/runtime-discovery.mjs +47 -47
  136. package/dist/src/self-relay/account-cleanup.mjs +30 -30
  137. package/dist/src/self-relay/account-connections.mjs +52 -52
  138. package/dist/src/self-relay/admin-cloud.mjs +101 -101
  139. package/dist/src/self-relay/admin-page.mjs +80 -80
  140. package/dist/src/self-relay/admin-server.mjs +74 -74
  141. package/dist/src/self-relay/admin-state.mjs +127 -127
  142. package/dist/src/self-relay/admin-style.mjs +14 -14
  143. package/dist/src/self-relay/android-releases.mjs +61 -61
  144. package/dist/src/self-relay/client.mjs +61 -61
  145. package/dist/src/self-relay/connector.mjs +439 -438
  146. package/dist/src/self-relay/debug-allowlist.mjs +33 -33
  147. package/dist/src/self-relay/demo.mjs +37 -37
  148. package/dist/src/self-relay/device-info.mjs +27 -0
  149. package/dist/src/self-relay/device-store.mjs +92 -84
  150. package/dist/src/self-relay/diagnostics.mjs +54 -54
  151. package/dist/src/self-relay/email-accounts.mjs +183 -183
  152. package/dist/src/self-relay/file-wire.mjs +13 -13
  153. package/dist/src/self-relay/lan-authorizations.mjs +71 -42
  154. package/dist/src/self-relay/lifecycle.mjs +264 -250
  155. package/dist/src/self-relay/long-pairing.mjs +40 -40
  156. package/dist/src/self-relay/mysql-state.mjs +118 -105
  157. package/dist/src/self-relay/p2p-probe.mjs +159 -159
  158. package/dist/src/self-relay/privacy-page.mjs +26 -26
  159. package/dist/src/self-relay/public-releases.mjs +52 -0
  160. package/dist/src/self-relay/rtc-file-bridge.mjs +41 -41
  161. package/dist/src/self-relay/server.mjs +1006 -932
  162. package/dist/src/self-relay/usage-daily.mjs +55 -55
  163. package/dist/src/self-relay/usage-meter.mjs +141 -141
  164. package/dist/src/self-relay/windows-route-helper.mjs +75 -75
  165. package/dist/src/self-relay/wire.mjs +36 -36
  166. package/dist/src/server.mjs +1861 -1778
  167. package/dist/src/service-control.mjs +82 -82
  168. package/dist/src/service-doctor.mjs +110 -110
  169. package/dist/src/service-health.mjs +33 -33
  170. package/dist/src/service-install.mjs +91 -91
  171. package/dist/src/service-lifecycle.mjs +138 -138
  172. package/dist/src/service-restart.mjs +81 -81
  173. package/dist/src/shared-app-server.mjs +615 -611
  174. package/dist/src/shared-catalog.mjs +132 -132
  175. package/dist/src/shared-recovery.mjs +146 -146
  176. package/dist/src/shared-thread-stream.mjs +164 -164
  177. package/dist/src/skill-install.mjs +51 -51
  178. package/dist/src/thread-title-generation.mjs +150 -150
  179. package/dist/src/turn-model-history.mjs +47 -47
  180. package/dist/src/usage-reset.mjs +17 -17
  181. package/dist/src/workstation-downloads.mjs +120 -120
  182. package/dist/tools/rtc-route-helper.ps1 +99 -99
  183. package/dist/tools/start-rtc-route-helper.ps1 +15 -15
  184. package/dist/web/vendor/markdown-it.LICENSE.txt +22 -22
  185. package/dist/web/vendor/markdown-it.umd.min.js +13 -13
  186. package/package.json +7 -6
  187. package/tools/postinstall.mjs +127 -127
@@ -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,17 +1,17 @@
1
- export async function consumeUsageReset(client, body) {
2
- if (typeof body?.idempotencyKey !== 'string' || !body.idempotencyKey.trim() || body.idempotencyKey.length > 200
3
- || typeof body.creditId !== 'string' || !body.creditId.trim() || body.creditId.length > 200) {
4
- throw Object.assign(new Error('请选择重置卡并确认使用。'), { statusCode: 400, code: 'usage_reset_not_submitted' });
5
- }
6
- let usage;
7
- try { usage = await client.usage(); }
8
- catch (error) { throw Object.assign(new Error('用量尚未确认,请恢复连接后重新选择重置卡。', { cause: error }),
9
- { statusCode: 503, code: 'usage_reset_not_submitted' }); }
10
- if ((usage.accountId || null) !== (body.accountId || null)) {
11
- throw Object.assign(new Error('Codex 账号已变化,请重新打开用量详情。'), { statusCode: 409, code: 'usage_reset_not_submitted' });
12
- }
13
- // The core owns eligibility and the idempotent redemption outcome.
14
- return client.request('account/rateLimitResetCredit/consume', {
15
- idempotencyKey: body.idempotencyKey, creditId: body.creditId,
16
- });
17
- }
1
+ export async function consumeUsageReset(client, body) {
2
+ if (typeof body?.idempotencyKey !== 'string' || !body.idempotencyKey.trim() || body.idempotencyKey.length > 200
3
+ || typeof body.creditId !== 'string' || !body.creditId.trim() || body.creditId.length > 200) {
4
+ throw Object.assign(new Error('请选择重置卡并确认使用。'), { statusCode: 400, code: 'usage_reset_not_submitted' });
5
+ }
6
+ let usage;
7
+ try { usage = await client.usage(); }
8
+ catch (error) { throw Object.assign(new Error('用量尚未确认,请恢复连接后重新选择重置卡。', { cause: error }),
9
+ { statusCode: 503, code: 'usage_reset_not_submitted' }); }
10
+ if ((usage.accountId || null) !== (body.accountId || null)) {
11
+ throw Object.assign(new Error('Codex 账号已变化,请重新打开用量详情。'), { statusCode: 409, code: 'usage_reset_not_submitted' });
12
+ }
13
+ // The core owns eligibility and the idempotent redemption outcome.
14
+ return client.request('account/rateLimitResetCredit/consume', {
15
+ idempotencyKey: body.idempotencyKey, creditId: body.creditId,
16
+ });
17
+ }