clawflowbang 1.0.0 → 1.0.2

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.
@@ -6,13 +6,13 @@ const fs = require('fs-extra');
6
6
  const path = require('path');
7
7
  const os = require('os');
8
8
 
9
- class ConfigManager {
10
- constructor(configPath = null, options = {}) {
11
- this.configPath = configPath || this.getDefaultConfigPath();
12
- this.overrides = options;
13
- this.config = null;
14
- this.ensureDirectories();
15
- }
9
+ class ConfigManager {
10
+ constructor(configPath = null, options = {}) {
11
+ this.configPath = configPath || this.getDefaultConfigPath();
12
+ this.overrides = options;
13
+ this.config = null;
14
+ this.ensureDirectories();
15
+ }
16
16
 
17
17
  /**
18
18
  * ได้รับ default config path ตาม OS
@@ -32,55 +32,55 @@ class ConfigManager {
32
32
  /**
33
33
  * สร้างโฟลเดอร์ที่จำเป็น
34
34
  */
35
- ensureDirectories() {
36
- const configFile = path.join(this.configPath, 'config.json');
37
- const defaultConfig = this.getDefaultConfig();
38
- const existingConfig = fs.existsSync(configFile) ? fs.readJsonSync(configFile) : {};
39
- const mergedConfig = this.applyOpenClawOverrides({
40
- ...defaultConfig,
41
- ...existingConfig,
42
- openclaw: {
43
- ...defaultConfig.openclaw,
44
- ...(existingConfig.openclaw || {}),
45
- },
46
- });
47
-
48
- const dirs = [
49
- this.configPath,
50
- path.dirname(mergedConfig.openclaw.skillsPath),
51
- mergedConfig.openclaw.skillsPath,
52
- path.dirname(mergedConfig.openclaw.cronJobsFile),
53
- path.join(this.configPath, 'logs'),
54
- path.join(this.configPath, 'packages'),
55
- ];
56
-
57
- dirs.forEach((dir) => {
58
- fs.ensureDirSync(dir);
59
- });
60
-
61
- if (!fs.existsSync(configFile) || JSON.stringify(existingConfig) !== JSON.stringify(mergedConfig)) {
62
- fs.writeJsonSync(configFile, mergedConfig, { spaces: 2 });
63
- }
64
- }
35
+ ensureDirectories() {
36
+ const configFile = path.join(this.configPath, 'config.json');
37
+ const defaultConfig = this.getDefaultConfig();
38
+ const existingConfig = fs.existsSync(configFile) ? fs.readJsonSync(configFile) : {};
39
+ const mergedConfig = this.applyOpenClawOverrides({
40
+ ...defaultConfig,
41
+ ...existingConfig,
42
+ openclaw: {
43
+ ...defaultConfig.openclaw,
44
+ ...(existingConfig.openclaw || {}),
45
+ },
46
+ });
47
+
48
+ const dirs = [
49
+ this.configPath,
50
+ path.dirname(mergedConfig.openclaw.skillsPath),
51
+ mergedConfig.openclaw.skillsPath,
52
+ path.dirname(mergedConfig.openclaw.cronJobsFile),
53
+ path.join(this.configPath, 'logs'),
54
+ path.join(this.configPath, 'packages'),
55
+ ];
56
+
57
+ dirs.forEach((dir) => {
58
+ fs.ensureDirSync(dir);
59
+ });
60
+
61
+ if (!fs.existsSync(configFile) || JSON.stringify(existingConfig) !== JSON.stringify(mergedConfig)) {
62
+ fs.writeJsonSync(configFile, mergedConfig, { spaces: 2 });
63
+ }
64
+ }
65
65
 
66
66
  /**
67
67
  * Config เริ่มต้น
68
68
  */
69
- getDefaultConfig() {
70
- const openclawHome = path.join(os.homedir(), '.openclaw');
71
- const workspacePath = path.join(openclawHome, 'workspace');
72
-
73
- return {
74
- version: '1.0.0',
75
- openclaw: {
76
- baseUrl: 'http://localhost:3000',
77
- apiKey: null,
78
- cliBin: 'openclaw',
79
- clawhubBin: 'clawhub',
80
- workspacePath,
81
- skillsPath: path.join(workspacePath, 'skills'),
82
- cronJobsFile: path.join(openclawHome, 'cron', 'jobs.json'),
83
- },
69
+ getDefaultConfig() {
70
+ const openclawHome = path.join(os.homedir(), '.openclaw');
71
+ const workspacePath = path.join(openclawHome, 'workspace');
72
+
73
+ return {
74
+ version: '1.0.0',
75
+ openclaw: {
76
+ baseUrl: 'http://localhost:18789',
77
+ apiKey: null,
78
+ cliBin: 'openclaw',
79
+ clawhubBin: 'clawhub',
80
+ workspacePath,
81
+ skillsPath: path.join(workspacePath, 'skills'),
82
+ cronJobsFile: path.join(openclawHome, 'cron', 'jobs.json'),
83
+ },
84
84
  registry: {
85
85
  url: 'https://registry.clawflowhub.dev',
86
86
  cacheExpiry: 3600, // วินาที
@@ -93,34 +93,34 @@ class ConfigManager {
93
93
  installed: {},
94
94
  crons: [],
95
95
  lastUpdate: null,
96
- };
97
- }
98
-
99
- applyOpenClawOverrides(config) {
100
- return {
101
- ...config,
102
- openclaw: {
103
- ...(config.openclaw || {}),
104
- ...(this.overrides.skillsPath ? { skillsPath: this.overrides.skillsPath } : {}),
105
- ...(this.overrides.cronJobsFile ? { cronJobsFile: this.overrides.cronJobsFile } : {}),
106
- ...(this.overrides.openclawBin ? { cliBin: this.overrides.openclawBin } : {}),
107
- ...(this.overrides.clawhubBin ? { clawhubBin: this.overrides.clawhubBin } : {}),
108
- },
109
- };
110
- }
96
+ };
97
+ }
98
+
99
+ applyOpenClawOverrides(config) {
100
+ return {
101
+ ...config,
102
+ openclaw: {
103
+ ...(config.openclaw || {}),
104
+ ...(this.overrides.skillsPath ? { skillsPath: this.overrides.skillsPath } : {}),
105
+ ...(this.overrides.cronJobsFile ? { cronJobsFile: this.overrides.cronJobsFile } : {}),
106
+ ...(this.overrides.openclawBin ? { cliBin: this.overrides.openclawBin } : {}),
107
+ ...(this.overrides.clawhubBin ? { clawhubBin: this.overrides.clawhubBin } : {}),
108
+ },
109
+ };
110
+ }
111
111
 
112
112
  /**
113
113
  * โหลด config
114
114
  */
115
- loadConfig() {
116
- const configFile = path.join(this.configPath, 'config.json');
117
- if (fs.existsSync(configFile)) {
118
- this.config = fs.readJsonSync(configFile);
119
- } else {
120
- this.config = this.applyOpenClawOverrides(this.getDefaultConfig());
121
- }
122
- return this.config;
123
- }
115
+ loadConfig() {
116
+ const configFile = path.join(this.configPath, 'config.json');
117
+ if (fs.existsSync(configFile)) {
118
+ this.config = fs.readJsonSync(configFile);
119
+ } else {
120
+ this.config = this.applyOpenClawOverrides(this.getDefaultConfig());
121
+ }
122
+ return this.config;
123
+ }
124
124
 
125
125
  /**
126
126
  * บันทึก config
@@ -172,25 +172,25 @@ class ConfigManager {
172
172
  /**
173
173
  * ดึง path ของ skills
174
174
  */
175
- getSkillsPath() {
176
- const config = this.getConfig();
177
- return config.openclaw?.skillsPath || path.join(this.configPath, 'skills');
178
- }
175
+ getSkillsPath() {
176
+ const config = this.getConfig();
177
+ return config.openclaw?.skillsPath || path.join(this.configPath, 'skills');
178
+ }
179
179
 
180
180
  /**
181
181
  * ดึง path ของ crons
182
182
  */
183
- getCronsPath() {
184
- return path.dirname(this.getCronJobsFilePath());
185
- }
186
-
187
- /**
188
- * ดึง path ของ cron jobs file
189
- */
190
- getCronJobsFilePath() {
191
- const config = this.getConfig();
192
- return config.openclaw?.cronJobsFile || path.join(this.configPath, 'crons', 'jobs.json');
193
- }
183
+ getCronsPath() {
184
+ return path.dirname(this.getCronJobsFilePath());
185
+ }
186
+
187
+ /**
188
+ * ดึง path ของ cron jobs file
189
+ */
190
+ getCronJobsFilePath() {
191
+ const config = this.getConfig();
192
+ return config.openclaw?.cronJobsFile || path.join(this.configPath, 'crons', 'jobs.json');
193
+ }
194
194
 
195
195
  /**
196
196
  * ดึง path ของ logs
@@ -235,16 +235,16 @@ class ConfigManager {
235
235
  /**
236
236
  * เพิ่ม cronjob
237
237
  */
238
- addCron(cronInfo) {
239
- const config = this.getConfig();
240
- if (!config.crons) {
241
- config.crons = [];
242
- }
243
- config.crons.push({
244
- id: cronInfo.id || Date.now().toString(),
245
- ...cronInfo,
246
- createdAt: new Date().toISOString(),
247
- });
238
+ addCron(cronInfo) {
239
+ const config = this.getConfig();
240
+ if (!config.crons) {
241
+ config.crons = [];
242
+ }
243
+ config.crons.push({
244
+ id: cronInfo.id || Date.now().toString(),
245
+ ...cronInfo,
246
+ createdAt: new Date().toISOString(),
247
+ });
248
248
  this.saveConfig();
249
249
  return config.crons[config.crons.length - 1];
250
250
  }
@@ -252,37 +252,37 @@ class ConfigManager {
252
252
  /**
253
253
  * ลบ cronjob
254
254
  */
255
- removeCron(cronId) {
256
- const config = this.getConfig();
257
- if (config.crons) {
258
- config.crons = config.crons.filter(cron => cron.id !== cronId);
259
- this.saveConfig();
260
- }
261
- }
262
-
263
- /**
264
- * แก้ไข cronjob
265
- */
266
- updateCron(cronId, patch = {}) {
267
- const config = this.getConfig();
268
- if (!config.crons) {
269
- return null;
270
- }
271
-
272
- const idx = config.crons.findIndex((c) => c.id === cronId);
273
- if (idx === -1) {
274
- return null;
275
- }
276
-
277
- config.crons[idx] = {
278
- ...config.crons[idx],
279
- ...patch,
280
- updatedAt: new Date().toISOString(),
281
- };
282
- this.saveConfig();
283
-
284
- return config.crons[idx];
285
- }
255
+ removeCron(cronId) {
256
+ const config = this.getConfig();
257
+ if (config.crons) {
258
+ config.crons = config.crons.filter(cron => cron.id !== cronId);
259
+ this.saveConfig();
260
+ }
261
+ }
262
+
263
+ /**
264
+ * แก้ไข cronjob
265
+ */
266
+ updateCron(cronId, patch = {}) {
267
+ const config = this.getConfig();
268
+ if (!config.crons) {
269
+ return null;
270
+ }
271
+
272
+ const idx = config.crons.findIndex((c) => c.id === cronId);
273
+ if (idx === -1) {
274
+ return null;
275
+ }
276
+
277
+ config.crons[idx] = {
278
+ ...config.crons[idx],
279
+ ...patch,
280
+ updatedAt: new Date().toISOString(),
281
+ };
282
+ this.saveConfig();
283
+
284
+ return config.crons[idx];
285
+ }
286
286
 
287
287
  /**
288
288
  * ดึงรายการ cronjobs