@icaruk/zai-peak-hours 0.0.6 → 0.0.9
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/index.js +32 -66
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -33,88 +33,54 @@ function loadConfig() {
|
|
|
33
33
|
configCache = DEFAULT_CONFIG;
|
|
34
34
|
return configCache;
|
|
35
35
|
}
|
|
36
|
-
async function showPeakHoursToast(client) {
|
|
37
|
-
const config = loadConfig();
|
|
38
|
-
if (!config.enabled) {
|
|
39
|
-
await client.tui.showToast({
|
|
40
|
-
body: {
|
|
41
|
-
message: 'Peak Hours plugin is disabled in config',
|
|
42
|
-
variant: 'info',
|
|
43
|
-
duration: 3000
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
const status = getPeakHoursStatus();
|
|
49
|
-
const message = formatPeakHoursMessage(status);
|
|
50
|
-
await client.tui.showToast({
|
|
51
|
-
body: {
|
|
52
|
-
message,
|
|
53
|
-
variant: status.inPeakHours ? 'warning' : 'info',
|
|
54
|
-
duration: 5000
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
async function showDiagnostics(client) {
|
|
59
|
-
const config = loadConfig();
|
|
60
|
-
const status = getPeakHoursStatus();
|
|
61
|
-
const currentTime = new Date().toISOString();
|
|
62
|
-
const diagnostics = `=== Peak Hours Plugin Diagnostics ===
|
|
63
|
-
Plugin enabled: ${config.enabled}
|
|
64
|
-
Update interval: ${config.updateIntervalMinutes} minutes
|
|
65
|
-
Current time: ${currentTime}
|
|
66
|
-
In peak hours: ${status.inPeakHours}
|
|
67
|
-
Time until ${status.transitionType}: ${status.timeUntilTransition}
|
|
68
|
-
====================================`;
|
|
69
|
-
await client.tui.showToast({
|
|
70
|
-
body: {
|
|
71
|
-
message: diagnostics,
|
|
72
|
-
variant: 'info',
|
|
73
|
-
duration: 8000
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
36
|
export const PeakHours = async ({ client }) => {
|
|
78
37
|
const config = loadConfig();
|
|
79
|
-
const updateInterval = config.updateIntervalMinutes * 60 * 1000;
|
|
80
|
-
await client.tui.showToast({
|
|
81
|
-
body: {
|
|
82
|
-
message: 'Peak Hours Plugin loaded successfully',
|
|
83
|
-
variant: 'info',
|
|
84
|
-
duration: 3000
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
38
|
return {
|
|
88
|
-
config: async (input) => {
|
|
89
|
-
input.command ?? (input.command = {});
|
|
90
|
-
input.command['peak_hours'] = {
|
|
91
|
-
template: '/peak_hours',
|
|
92
|
-
description: 'Display current peak hours status'
|
|
93
|
-
};
|
|
94
|
-
input.command['peak_hours_status'] = {
|
|
95
|
-
template: '/peak_hours_status',
|
|
96
|
-
description: 'Display peak hours plugin diagnostics'
|
|
97
|
-
};
|
|
98
|
-
},
|
|
99
39
|
'tool.execute.after': async (input) => {
|
|
100
40
|
if (!config.enabled) {
|
|
101
41
|
return;
|
|
102
42
|
}
|
|
103
43
|
if (input.tool === 'peak_hours') {
|
|
104
|
-
|
|
44
|
+
const status = getPeakHoursStatus();
|
|
45
|
+
const message = formatPeakHoursMessage(status);
|
|
46
|
+
await client.tui.showToast({
|
|
47
|
+
body: {
|
|
48
|
+
message,
|
|
49
|
+
variant: status.inPeakHours ? 'warning' : 'info'
|
|
50
|
+
}
|
|
51
|
+
});
|
|
105
52
|
}
|
|
106
53
|
else if (input.tool === 'peak_hours_status') {
|
|
107
|
-
|
|
54
|
+
const config = loadConfig();
|
|
55
|
+
const status = getPeakHoursStatus();
|
|
56
|
+
const currentTime = new Date().toISOString();
|
|
57
|
+
const diagnostics = `=== Peak Hours Plugin Diagnostics ===
|
|
58
|
+
Plugin enabled: ${config.enabled}
|
|
59
|
+
Update interval: ${config.updateIntervalMinutes} minutes
|
|
60
|
+
Current time: ${currentTime}
|
|
61
|
+
In peak hours: ${status.inPeakHours}
|
|
62
|
+
Time until ${status.transitionType}: ${status.timeUntilTransition}
|
|
63
|
+
===================================`;
|
|
64
|
+
await client.tui.showToast({
|
|
65
|
+
body: {
|
|
66
|
+
message: diagnostics,
|
|
67
|
+
variant: 'info'
|
|
68
|
+
}
|
|
69
|
+
});
|
|
108
70
|
}
|
|
109
71
|
},
|
|
110
72
|
'session.created': async () => {
|
|
111
73
|
if (!config.enabled) {
|
|
112
74
|
return;
|
|
113
75
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
76
|
+
const status = getPeakHoursStatus();
|
|
77
|
+
const message = formatPeakHoursMessage(status);
|
|
78
|
+
await client.tui.showToast({
|
|
79
|
+
body: {
|
|
80
|
+
message,
|
|
81
|
+
variant: status.inPeakHours ? 'warning' : 'info'
|
|
82
|
+
}
|
|
83
|
+
});
|
|
118
84
|
},
|
|
119
85
|
tool: {
|
|
120
86
|
'peak_hours': tool({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@icaruk/zai-peak-hours",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "OpenCode plugin to display z.ai peak hours information with automatic timezone detection",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@opencode-ai/plugin": "^1.4.0",
|
|
30
|
+
"@opencode-ai/sdk": "^1.4.3",
|
|
30
31
|
"dayjs": "^1.11.10"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|