@icaruk/zai-peak-hours 0.0.2 → 0.0.3
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 +4 -6
- package/dist/index.d.ts +2 -7
- package/dist/index.js +93 -82
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
# @icaruk/zai-peak-hours
|
|
2
2
|
|
|
3
|
-
OpenCode
|
|
3
|
+
OpenCode plugin that displays z.ai peak hours information with automatic timezone detection via toast notifications.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
-
Add to your `~/.config/opencode/
|
|
7
|
+
Add to your `~/.config/opencode/opencode.json`:
|
|
8
8
|
|
|
9
9
|
```json
|
|
10
10
|
{
|
|
11
|
-
"$schema": "https://opencode.ai/tui.json",
|
|
12
11
|
"plugin": ["@icaruk/zai-peak-hours"]
|
|
13
12
|
}
|
|
14
13
|
```
|
|
@@ -58,13 +57,12 @@ npm run build
|
|
|
58
57
|
npm run dev
|
|
59
58
|
```
|
|
60
59
|
|
|
61
|
-
Add local config in `
|
|
60
|
+
Add local config in `opencode.json`
|
|
62
61
|
|
|
63
62
|
```json
|
|
64
63
|
{
|
|
65
|
-
"$schema": "https://opencode.ai/tui.json",
|
|
66
64
|
"plugin": [
|
|
67
|
-
"D:/Dev/zai-peak-hours/dist/index.js"
|
|
65
|
+
"file:///D:/Dev/zai-peak-hours/dist/index.js"
|
|
68
66
|
]
|
|
69
67
|
}
|
|
70
68
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
declare function tui(api: TuiPluginApi, options: PluginOptions | undefined, meta: TuiPluginMeta): Promise<void>;
|
|
4
|
-
declare const plugin: {
|
|
5
|
-
id: string;
|
|
6
|
-
tui: typeof tui;
|
|
7
|
-
};
|
|
1
|
+
import type { Plugin } from '@opencode-ai/plugin';
|
|
2
|
+
export declare const plugin: Plugin;
|
|
8
3
|
export default plugin;
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { tool } from '@opencode-ai/plugin';
|
|
1
2
|
import { getPeakHoursStatus, formatPeakHoursMessage } from './peak-hours';
|
|
2
3
|
import { DEFAULT_CONFIG } from './config';
|
|
3
4
|
import * as fs from 'fs';
|
|
4
5
|
import * as path from 'path';
|
|
5
6
|
let timerId = null;
|
|
6
|
-
let pluginLoaded = false;
|
|
7
7
|
let configCache = null;
|
|
8
8
|
function getConfigPath() {
|
|
9
9
|
const configDir = process.env.XDG_CONFIG_HOME
|
|
@@ -33,105 +33,116 @@ function loadConfig() {
|
|
|
33
33
|
configCache = DEFAULT_CONFIG;
|
|
34
34
|
return configCache;
|
|
35
35
|
}
|
|
36
|
-
function showPeakHoursToast(
|
|
36
|
+
async function showPeakHoursToast(client) {
|
|
37
37
|
const config = loadConfig();
|
|
38
38
|
if (!config.enabled) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
await client.tui.showToast({
|
|
40
|
+
body: {
|
|
41
|
+
message: 'Peak Hours plugin is disabled in config',
|
|
42
|
+
variant: 'info',
|
|
43
|
+
duration: 3000
|
|
44
|
+
}
|
|
42
45
|
});
|
|
43
46
|
return;
|
|
44
47
|
}
|
|
45
48
|
const status = getPeakHoursStatus();
|
|
46
49
|
const message = formatPeakHoursMessage(status);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
await client.tui.showToast({
|
|
51
|
+
body: {
|
|
52
|
+
message,
|
|
53
|
+
variant: status.inPeakHours ? 'warning' : 'info',
|
|
54
|
+
duration: 5000
|
|
55
|
+
}
|
|
50
56
|
});
|
|
51
57
|
}
|
|
52
|
-
function showDiagnostics(
|
|
58
|
+
async function showDiagnostics(client) {
|
|
53
59
|
const config = loadConfig();
|
|
54
60
|
const status = getPeakHoursStatus();
|
|
55
61
|
const currentTime = new Date().toISOString();
|
|
56
|
-
const diagnostics =
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
+
}
|
|
69
75
|
});
|
|
70
76
|
}
|
|
71
|
-
async
|
|
72
|
-
pluginLoaded = true;
|
|
77
|
+
export const plugin = async ({ client }) => {
|
|
73
78
|
const config = loadConfig();
|
|
74
|
-
const updateInterval = config.updateIntervalMinutes * 60 * 1000;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
+
}
|
|
79
86
|
});
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
{
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
description: 'Display current peak hours status
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
87
|
+
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
|
+
'tool.execute.after': async (input) => {
|
|
100
|
+
if (!config.enabled) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (input.tool === 'peak_hours') {
|
|
104
|
+
await showPeakHoursToast(client);
|
|
105
|
+
}
|
|
106
|
+
else if (input.tool === 'peak_hours_status') {
|
|
107
|
+
await showDiagnostics(client);
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
'session.created': async () => {
|
|
111
|
+
if (!config.enabled) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
await showPeakHoursToast(client);
|
|
115
|
+
timerId = setInterval(async () => {
|
|
116
|
+
await showPeakHoursToast(client);
|
|
117
|
+
}, updateInterval);
|
|
118
|
+
},
|
|
119
|
+
tool: {
|
|
120
|
+
'peak_hours': tool({
|
|
121
|
+
description: 'Display current z.ai peak hours status and time until next transition',
|
|
122
|
+
args: {},
|
|
123
|
+
async execute(_args, context) {
|
|
124
|
+
const status = getPeakHoursStatus();
|
|
125
|
+
const message = formatPeakHoursMessage(status);
|
|
126
|
+
return `Peak Hours Status:\n${message}\n\nIn peak hours: ${status.inPeakHours}\nTime until ${status.transitionType}: ${status.timeUntilTransition}`;
|
|
92
127
|
}
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
128
|
+
}),
|
|
129
|
+
'peak_hours_status': tool({
|
|
130
|
+
description: 'Display peak hours plugin diagnostics and configuration status',
|
|
131
|
+
args: {},
|
|
132
|
+
async execute(_args, context) {
|
|
133
|
+
const config = loadConfig();
|
|
134
|
+
const status = getPeakHoursStatus();
|
|
135
|
+
const currentTime = new Date().toISOString();
|
|
136
|
+
return `=== Peak Hours Plugin Diagnostics ===
|
|
137
|
+
Plugin enabled: ${config.enabled}
|
|
138
|
+
Update interval: ${config.updateIntervalMinutes} minutes
|
|
139
|
+
Current time: ${currentTime}
|
|
140
|
+
In peak hours: ${status.inPeakHours}
|
|
141
|
+
Time until ${status.transitionType}: ${status.timeUntilTransition}
|
|
142
|
+
====================================`;
|
|
104
143
|
}
|
|
105
|
-
}
|
|
106
|
-
];
|
|
107
|
-
api.command.register(() => commands);
|
|
108
|
-
}
|
|
109
|
-
catch (error) {
|
|
110
|
-
api.ui.toast({
|
|
111
|
-
message: `Error registering peak_hours commands: ${error}`,
|
|
112
|
-
duration: 5000
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
if (!config.enabled) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
const unsubscribe = api.event.on('session.created', () => {
|
|
119
|
-
showPeakHoursToast(api);
|
|
120
|
-
timerId = setInterval(() => {
|
|
121
|
-
showPeakHoursToast(api);
|
|
122
|
-
}, updateInterval);
|
|
123
|
-
});
|
|
124
|
-
api.lifecycle.onDispose(() => {
|
|
125
|
-
unsubscribe();
|
|
126
|
-
if (timerId) {
|
|
127
|
-
clearInterval(timerId);
|
|
128
|
-
timerId = null;
|
|
144
|
+
})
|
|
129
145
|
}
|
|
130
|
-
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
const plugin = {
|
|
134
|
-
id: "icaruk.peak-hours",
|
|
135
|
-
tui
|
|
146
|
+
};
|
|
136
147
|
};
|
|
137
148
|
export default plugin;
|