@simonesiega/codex-limits 0.1.1 → 0.1.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/dist/cli.js CHANGED
@@ -41481,7 +41481,7 @@ var init_app = __esm(async () => {
41481
41481
  // package.json
41482
41482
  var package_default = {
41483
41483
  name: "@simonesiega/codex-limits",
41484
- version: "0.1.1",
41484
+ version: "0.1.3",
41485
41485
  description: "Check Codex usage limits, reset times, and reset-credit coupons from a fast, read-only terminal dashboard.",
41486
41486
  type: "module",
41487
41487
  bin: {
package/dist/index.js CHANGED
@@ -1021,33 +1021,49 @@ var DESCRIPTION = "Check Codex limits, resets, and credits.";
1021
1021
  var module = {
1022
1022
  id: "codex-limits",
1023
1023
  tui: async (api) => {
1024
- api.command?.register(() => [
1025
- {
1026
- title: TITLE,
1027
- value: "codex-limits.show",
1028
- description: DESCRIPTION,
1029
- category: "Codex",
1030
- slash: { name: "codex-limits" },
1031
- onSelect: async (dialog) => {
1032
- dialog?.clear();
1033
- api.ui.dialog.clear();
1034
- await nextFrame();
1035
- const target = api.ui.dialog;
1036
- target.setSize("large");
1037
- target.replace(() => alert(api, "Loading Codex limits..."));
1038
- try {
1039
- const result = await getCodexLimits();
1040
- target.replace(() => alert(api, formatOpencodeLimits(result)));
1041
- } catch (error) {
1042
- const message = error instanceof Error ? error.message : "Could not load Codex limits.";
1043
- api.ui.toast({ variant: "error", title: TITLE, message });
1044
- target.replace(() => alert(api, message));
1045
- }
1024
+ const command = createCommand(api);
1025
+ const disposes = [api.command?.register(() => [command]), registerCommandLayer(api, command)].filter(isDispose);
1026
+ if (disposes.length > 0) {
1027
+ api.lifecycle.onDispose(() => {
1028
+ for (const dispose of disposes) {
1029
+ dispose();
1046
1030
  }
1047
- }
1048
- ]);
1031
+ });
1032
+ }
1049
1033
  }
1050
1034
  };
1035
+ function createCommand(api) {
1036
+ return {
1037
+ title: TITLE,
1038
+ value: "codex-limits.show",
1039
+ description: DESCRIPTION,
1040
+ category: "Codex",
1041
+ slash: { name: "codex-limits" },
1042
+ onSelect: async (dialog) => {
1043
+ dialog?.clear();
1044
+ api.ui.dialog.clear();
1045
+ await nextFrame();
1046
+ const target = api.ui.dialog;
1047
+ target.setSize("large");
1048
+ target.replace(() => alert(api, "Loading Codex limits..."));
1049
+ try {
1050
+ const result = await getCodexLimits();
1051
+ target.replace(() => alert(api, formatOpencodeLimits(result)));
1052
+ } catch (error) {
1053
+ const message = error instanceof Error ? error.message : "Could not load Codex limits.";
1054
+ api.ui.toast({ variant: "error", title: TITLE, message });
1055
+ target.replace(() => alert(api, message));
1056
+ }
1057
+ }
1058
+ };
1059
+ }
1060
+ function registerCommandLayer(api, command) {
1061
+ const keymap = api.keymap;
1062
+ return keymap?.registerLayer?.({ commands: [command], bindings: [] });
1063
+ }
1064
+ function isDispose(value) {
1065
+ return typeof value === "function";
1066
+ }
1051
1067
  function alert(api, message) {
1052
1068
  return api.ui.DialogAlert({ title: TITLE, message });
1053
1069
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simonesiega/codex-limits",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Check Codex usage limits, reset times, and reset-credit coupons from a fast, read-only terminal dashboard.",
5
5
  "type": "module",
6
6
  "bin": {