front-cpu 0.1.3 → 0.1.4

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.
@@ -1,157 +1,157 @@
1
- export type CPUConsoleLocale = 'en' | 'zh-CN'
2
-
3
- export type CPUConsoleI18nKey =
4
- | 'instruction.created'
5
- | 'instruction.success'
6
- | 'instruction.cancelled'
7
- | 'instruction.failed'
8
- | 'optimistic.applied'
9
- | 'optimistic.rolledBack'
10
- | 'scheduler.conflictWait'
11
- | 'network.request'
12
- | 'network.response'
13
- | 'label.instructionInfo'
14
- | 'label.payload'
15
- | 'label.payloadDebugOnly'
16
- | 'label.callSourceDetails'
17
- | 'label.backendResult'
18
- | 'label.wbExecution'
19
- | 'label.rollbackReason'
20
- | 'label.pipelineStages'
21
- | 'label.details'
22
- | 'label.suggestions'
23
- | 'label.stats'
24
- | 'label.reason'
25
- | 'label.cancelStage'
26
- | 'label.totalDuration'
27
- | 'label.optimisticUpdate'
28
- | 'label.snapshotSaved'
29
- | 'stats.total'
30
- | 'stats.success'
31
- | 'stats.failed'
32
- | 'stats.avgLatency'
33
- | 'wb.commitOk'
34
- | 'wb.commitFail'
35
- | 'wb.commitArgs'
36
- | 'wb.commitError'
37
- | 'wb.commitUnknown'
38
- | 'wb.noCommit'
39
- | 'wb.rollbackExecuted'
40
- | 'wb.rollbackSnapshot'
41
- | 'wb.rollbackError'
42
- | 'wb.interruptRegistered'
43
- | 'common.unknownReason'
44
- | 'suggest.dbLocked'
45
- | 'suggest.network'
46
- | 'suggest.timeout'
47
- | 'suggest.slowInstruction'
48
-
49
- export type CPUConsoleTranslate = (key: CPUConsoleI18nKey, params?: Record<string, any>) => string
50
-
51
- type Dict = Record<CPUConsoleI18nKey, string>
52
-
53
- const EN: Dict = {
54
- 'instruction.created': 'Instruction Created',
55
- 'instruction.success': 'Instruction Success',
56
- 'instruction.cancelled': 'Instruction Cancelled',
57
- 'instruction.failed': 'Instruction Failed',
58
- 'optimistic.applied': 'Optimistic Update',
59
- 'optimistic.rolledBack': 'Optimistic Rollback',
60
- 'scheduler.conflictWait': 'Resource conflict, waiting {waitTime}ms',
61
- 'network.request': 'HTTP Request',
62
- 'network.response': 'HTTP Response',
63
- 'label.instructionInfo': 'Instruction Info:',
64
- 'label.payload': 'Payload:',
65
- 'label.payloadDebugOnly': 'Payload: (use level=DEBUG to see payload)',
66
- 'label.callSourceDetails': 'Call Source Details:',
67
- 'label.backendResult': 'Backend Result:',
68
- 'label.wbExecution': 'WB Execution:',
69
- 'label.rollbackReason': 'Rollback Reason:',
70
- 'label.pipelineStages': 'Pipeline Stages:',
71
- 'label.details': 'Details:',
72
- 'label.suggestions': 'Suggestions:',
73
- 'label.stats': 'Pipeline Stats',
74
- 'label.reason': 'Reason:',
75
- 'label.cancelStage': 'Cancelled At:',
76
- 'label.totalDuration': 'Total:',
77
- 'label.optimisticUpdate': 'Optimistic Update',
78
- 'label.snapshotSaved': 'snapshot saved (for rollback)',
79
- 'stats.total': 'Total:',
80
- 'stats.success': 'Success:',
81
- 'stats.failed': 'Failed:',
82
- 'stats.avgLatency': 'Avg latency:',
83
- 'wb.commitOk': '✅ commit() succeeded',
84
- 'wb.commitFail': '❌ commit() failed',
85
- 'wb.commitArgs': '📝 commit args:',
86
- 'wb.commitError': '🚨 commit error:',
87
- 'wb.commitUnknown': '⚠️ commit() status unknown',
88
- 'wb.noCommit': '⏭️ no commit()',
89
- 'wb.rollbackExecuted': '🔄 optimistic rollback executed',
90
- 'wb.rollbackSnapshot': '📋 rollback snapshot:',
91
- 'wb.rollbackError': '🚨 rollback error:',
92
- 'wb.interruptRegistered': '🎯 registered to interrupt handler (SSE dedup)',
93
- 'common.unknownReason': 'Unknown',
94
- 'suggest.dbLocked': 'Backend database is locked; check write lock/transaction handling.',
95
- 'suggest.network': 'Network error; check whether backend service is running.',
96
- 'suggest.timeout': 'Request timeout; consider increasing timeout or optimizing backend.',
97
- 'suggest.slowInstruction': 'Execution took {duration}ms (> 1000ms); investigate performance.',
98
- }
99
-
100
- const ZH_CN: Dict = {
101
- 'instruction.created': '指令创建',
102
- 'instruction.success': '指令成功',
103
- 'instruction.cancelled': '指令取消',
104
- 'instruction.failed': '指令失败',
105
- 'optimistic.applied': '乐观更新',
106
- 'optimistic.rolledBack': '乐观回滚',
107
- 'scheduler.conflictWait': '资源冲突,等待 {waitTime}ms',
108
- 'network.request': '网络请求',
109
- 'network.response': '网络响应',
110
- 'label.instructionInfo': '指令信息:',
111
- 'label.payload': '指令参数 (Payload):',
112
- 'label.payloadDebugOnly': '指令参数: (use level=DEBUG to see payload)',
113
- 'label.callSourceDetails': '调用源详情:',
114
- 'label.backendResult': '后端返回 (Result):',
115
- 'label.wbExecution': 'WB阶段执行记录:',
116
- 'label.rollbackReason': '回滚原因:',
117
- 'label.pipelineStages': '流水线阶段:',
118
- 'label.details': '详细信息:',
119
- 'label.suggestions': '建议:',
120
- 'label.stats': '流水线统计',
121
- 'label.reason': '原因:',
122
- 'label.cancelStage': '取消阶段:',
123
- 'label.totalDuration': '总耗时:',
124
- 'label.optimisticUpdate': '乐观更新',
125
- 'label.snapshotSaved': '已保存快照(用于回滚)',
126
- 'stats.total': '总指令数:',
127
- 'stats.success': '成功:',
128
- 'stats.failed': '失败:',
129
- 'stats.avgLatency': '平均延迟:',
130
- 'wb.commitOk': '✅ commit() 函数执行成功',
131
- 'wb.commitFail': '❌ commit() 函数执行失败',
132
- 'wb.commitArgs': '📝 commit 调用参数:',
133
- 'wb.commitError': '🚨 commit 错误:',
134
- 'wb.commitUnknown': '⚠️ commit() 状态未知',
135
- 'wb.noCommit': '⏭️ 无 commit() 函数',
136
- 'wb.rollbackExecuted': '🔄 执行了乐观更新回滚',
137
- 'wb.rollbackSnapshot': '📋 回滚快照:',
138
- 'wb.rollbackError': '🚨 回滚错误:',
139
- 'wb.interruptRegistered': '🎯 已注册到中断处理器 (SSE去重)',
140
- 'common.unknownReason': '未知原因',
141
- 'suggest.dbLocked': '后端数据库锁定,检查写入许可/事务锁是否正确获取',
142
- 'suggest.network': '网络错误,检查后端服务是否运行',
143
- 'suggest.timeout': '请求超时,考虑增加超时时间或优化后端性能',
144
- 'suggest.slowInstruction': '执行耗时 {duration}ms,超过 1 秒,检查是否存在性能问题',
145
- }
146
-
147
- function format(template: string, params: Record<string, any> | undefined): string {
148
- if (!params) return template
149
- return template.replace(/\{(\w+)\}/g, (_, key: string) => String(params[key] ?? `{${key}}`))
150
- }
151
-
152
- export function createCPUConsoleTranslator(locale: CPUConsoleLocale): CPUConsoleTranslate {
153
- const dict = locale === 'zh-CN' ? ZH_CN : EN
154
- return (key, params) => format(dict[key], params)
155
- }
156
-
157
-
1
+ export type CPUConsoleLocale = 'en' | 'zh-CN'
2
+
3
+ export type CPUConsoleI18nKey =
4
+ | 'instruction.created'
5
+ | 'instruction.success'
6
+ | 'instruction.cancelled'
7
+ | 'instruction.failed'
8
+ | 'optimistic.applied'
9
+ | 'optimistic.rolledBack'
10
+ | 'scheduler.conflictWait'
11
+ | 'network.request'
12
+ | 'network.response'
13
+ | 'label.instructionInfo'
14
+ | 'label.payload'
15
+ | 'label.payloadDebugOnly'
16
+ | 'label.callSourceDetails'
17
+ | 'label.backendResult'
18
+ | 'label.wbExecution'
19
+ | 'label.rollbackReason'
20
+ | 'label.pipelineStages'
21
+ | 'label.details'
22
+ | 'label.suggestions'
23
+ | 'label.stats'
24
+ | 'label.reason'
25
+ | 'label.cancelStage'
26
+ | 'label.totalDuration'
27
+ | 'label.optimisticUpdate'
28
+ | 'label.snapshotSaved'
29
+ | 'stats.total'
30
+ | 'stats.success'
31
+ | 'stats.failed'
32
+ | 'stats.avgLatency'
33
+ | 'wb.commitOk'
34
+ | 'wb.commitFail'
35
+ | 'wb.commitArgs'
36
+ | 'wb.commitError'
37
+ | 'wb.commitUnknown'
38
+ | 'wb.noCommit'
39
+ | 'wb.rollbackExecuted'
40
+ | 'wb.rollbackSnapshot'
41
+ | 'wb.rollbackError'
42
+ | 'wb.interruptRegistered'
43
+ | 'common.unknownReason'
44
+ | 'suggest.dbLocked'
45
+ | 'suggest.network'
46
+ | 'suggest.timeout'
47
+ | 'suggest.slowInstruction'
48
+
49
+ export type CPUConsoleTranslate = (key: CPUConsoleI18nKey, params?: Record<string, any>) => string
50
+
51
+ type Dict = Record<CPUConsoleI18nKey, string>
52
+
53
+ const EN: Dict = {
54
+ 'instruction.created': 'Instruction Created',
55
+ 'instruction.success': 'Instruction Success',
56
+ 'instruction.cancelled': 'Instruction Cancelled',
57
+ 'instruction.failed': 'Instruction Failed',
58
+ 'optimistic.applied': 'Optimistic Update',
59
+ 'optimistic.rolledBack': 'Optimistic Rollback',
60
+ 'scheduler.conflictWait': 'Resource conflict, waiting {waitTime}ms',
61
+ 'network.request': 'HTTP Request',
62
+ 'network.response': 'HTTP Response',
63
+ 'label.instructionInfo': 'Instruction Info:',
64
+ 'label.payload': 'Payload:',
65
+ 'label.payloadDebugOnly': 'Payload: (use level=DEBUG to see payload)',
66
+ 'label.callSourceDetails': 'Call Source Details:',
67
+ 'label.backendResult': 'Backend Result:',
68
+ 'label.wbExecution': 'WB Execution:',
69
+ 'label.rollbackReason': 'Rollback Reason:',
70
+ 'label.pipelineStages': 'Pipeline Stages:',
71
+ 'label.details': 'Details:',
72
+ 'label.suggestions': 'Suggestions:',
73
+ 'label.stats': 'Pipeline Stats',
74
+ 'label.reason': 'Reason:',
75
+ 'label.cancelStage': 'Cancelled At:',
76
+ 'label.totalDuration': 'Total:',
77
+ 'label.optimisticUpdate': 'Optimistic Update',
78
+ 'label.snapshotSaved': 'snapshot saved (for rollback)',
79
+ 'stats.total': 'Total:',
80
+ 'stats.success': 'Success:',
81
+ 'stats.failed': 'Failed:',
82
+ 'stats.avgLatency': 'Avg latency:',
83
+ 'wb.commitOk': '✅ commit() succeeded',
84
+ 'wb.commitFail': '❌ commit() failed',
85
+ 'wb.commitArgs': '📝 commit args:',
86
+ 'wb.commitError': '🚨 commit error:',
87
+ 'wb.commitUnknown': '⚠️ commit() status unknown',
88
+ 'wb.noCommit': '⏭️ no commit()',
89
+ 'wb.rollbackExecuted': '🔄 optimistic rollback executed',
90
+ 'wb.rollbackSnapshot': '📋 rollback snapshot:',
91
+ 'wb.rollbackError': '🚨 rollback error:',
92
+ 'wb.interruptRegistered': '🎯 registered to interrupt handler (SSE dedup)',
93
+ 'common.unknownReason': 'Unknown',
94
+ 'suggest.dbLocked': 'Backend database is locked; check write lock/transaction handling.',
95
+ 'suggest.network': 'Network error; check whether backend service is running.',
96
+ 'suggest.timeout': 'Request timeout; consider increasing timeout or optimizing backend.',
97
+ 'suggest.slowInstruction': 'Execution took {duration}ms (> 1000ms); investigate performance.',
98
+ }
99
+
100
+ const ZH_CN: Dict = {
101
+ 'instruction.created': '指令创建',
102
+ 'instruction.success': '指令成功',
103
+ 'instruction.cancelled': '指令取消',
104
+ 'instruction.failed': '指令失败',
105
+ 'optimistic.applied': '乐观更新',
106
+ 'optimistic.rolledBack': '乐观回滚',
107
+ 'scheduler.conflictWait': '资源冲突,等待 {waitTime}ms',
108
+ 'network.request': '网络请求',
109
+ 'network.response': '网络响应',
110
+ 'label.instructionInfo': '指令信息:',
111
+ 'label.payload': '指令参数 (Payload):',
112
+ 'label.payloadDebugOnly': '指令参数: (use level=DEBUG to see payload)',
113
+ 'label.callSourceDetails': '调用源详情:',
114
+ 'label.backendResult': '后端返回 (Result):',
115
+ 'label.wbExecution': 'WB阶段执行记录:',
116
+ 'label.rollbackReason': '回滚原因:',
117
+ 'label.pipelineStages': '流水线阶段:',
118
+ 'label.details': '详细信息:',
119
+ 'label.suggestions': '建议:',
120
+ 'label.stats': '流水线统计',
121
+ 'label.reason': '原因:',
122
+ 'label.cancelStage': '取消阶段:',
123
+ 'label.totalDuration': '总耗时:',
124
+ 'label.optimisticUpdate': '乐观更新',
125
+ 'label.snapshotSaved': '已保存快照(用于回滚)',
126
+ 'stats.total': '总指令数:',
127
+ 'stats.success': '成功:',
128
+ 'stats.failed': '失败:',
129
+ 'stats.avgLatency': '平均延迟:',
130
+ 'wb.commitOk': '✅ commit() 函数执行成功',
131
+ 'wb.commitFail': '❌ commit() 函数执行失败',
132
+ 'wb.commitArgs': '📝 commit 调用参数:',
133
+ 'wb.commitError': '🚨 commit 错误:',
134
+ 'wb.commitUnknown': '⚠️ commit() 状态未知',
135
+ 'wb.noCommit': '⏭️ 无 commit() 函数',
136
+ 'wb.rollbackExecuted': '🔄 执行了乐观更新回滚',
137
+ 'wb.rollbackSnapshot': '📋 回滚快照:',
138
+ 'wb.rollbackError': '🚨 回滚错误:',
139
+ 'wb.interruptRegistered': '🎯 已注册到中断处理器 (SSE去重)',
140
+ 'common.unknownReason': '未知原因',
141
+ 'suggest.dbLocked': '后端数据库锁定,检查写入许可/事务锁是否正确获取',
142
+ 'suggest.network': '网络错误,检查后端服务是否运行',
143
+ 'suggest.timeout': '请求超时,考虑增加超时时间或优化后端性能',
144
+ 'suggest.slowInstruction': '执行耗时 {duration}ms,超过 1 秒,检查是否存在性能问题',
145
+ }
146
+
147
+ function format(template: string, params: Record<string, any> | undefined): string {
148
+ if (!params) return template
149
+ return template.replace(/\{(\w+)\}/g, (_, key: string) => String(params[key] ?? `{${key}}`))
150
+ }
151
+
152
+ export function createCPUConsoleTranslator(locale: CPUConsoleLocale): CPUConsoleTranslate {
153
+ const dict = locale === 'zh-CN' ? ZH_CN : EN
154
+ return (key, params) => format(dict[key], params)
155
+ }
156
+
157
+
@@ -94,3 +94,6 @@ export function setLoggingProvider(provider: Partial<LoggingProvider>): void {
94
94
  }
95
95
 
96
96
 
97
+
98
+
99
+