@2en/clawly-plugins 1.30.0-beta.10 → 1.30.0-beta.11
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/config-setup.ts +8 -6
- package/gateway/config-model.ts +1 -7
- package/gateway/config-timezone.ts +1 -7
- package/model-gateway-setup.ts +0 -46
- package/package.json +1 -1
package/config-setup.ts
CHANGED
|
@@ -611,12 +611,14 @@ export function setupConfig(api: PluginApi): void {
|
|
|
611
611
|
try {
|
|
612
612
|
writeOpenclawConfig(configPath, config)
|
|
613
613
|
api.logger.info('Config setup: patched openclaw.json.')
|
|
614
|
-
//
|
|
615
|
-
//
|
|
616
|
-
//
|
|
617
|
-
//
|
|
618
|
-
//
|
|
619
|
-
|
|
614
|
+
// Refresh the gateway's in-memory runtime config snapshot.
|
|
615
|
+
// The sync write above updates the file on disk, but the gateway
|
|
616
|
+
// caches config via runtimeConfigSnapshot (set during startup by
|
|
617
|
+
// the secrets system). Without this refresh, loadConfig() keeps
|
|
618
|
+
// returning the stale pre-patch config until the next restart.
|
|
619
|
+
void api.runtime.config.writeConfigFile(config).catch((err) => {
|
|
620
|
+
api.logger.warn(`Config setup: runtime snapshot refresh failed: ${(err as Error).message}`)
|
|
621
|
+
})
|
|
620
622
|
} catch (err) {
|
|
621
623
|
api.logger.error(`Config setup failed: ${(err as Error).message}`)
|
|
622
624
|
}
|
package/gateway/config-model.ts
CHANGED
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
|
|
16
16
|
import type {PluginApi} from '../types'
|
|
17
17
|
import type {OpenClawConfig} from '../types/openclaw'
|
|
18
|
-
import {backfillDiskConfig} from '../model-gateway-setup'
|
|
19
18
|
|
|
20
19
|
export function registerConfigModel(api: PluginApi) {
|
|
21
20
|
api.registerGatewayMethod('clawly.config.setModel', async ({params, respond}) => {
|
|
@@ -54,13 +53,8 @@ export function registerConfigModel(api: PluginApi) {
|
|
|
54
53
|
agents.defaults = defaults
|
|
55
54
|
config.agents = agents
|
|
56
55
|
|
|
57
|
-
// Backfill fields written by setupConfig (which writes directly to disk)
|
|
58
|
-
// so writeConfigFile's merge-patch doesn't revert them.
|
|
59
|
-
const stateDir = api.runtime.state.resolveStateDir()
|
|
60
|
-
const configToWrite = stateDir ? backfillDiskConfig(stateDir, config) : config
|
|
61
|
-
|
|
62
56
|
try {
|
|
63
|
-
await api.runtime.config.writeConfigFile(
|
|
57
|
+
await api.runtime.config.writeConfigFile(config)
|
|
64
58
|
api.logger.info(`config-model: set model.primary to ${model}`)
|
|
65
59
|
respond(true, {changed: true, model})
|
|
66
60
|
} catch (err) {
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
|
|
12
12
|
import type {PluginApi} from '../types'
|
|
13
13
|
import type {OpenClawConfig} from '../types/openclaw'
|
|
14
|
-
import {backfillDiskConfig} from '../model-gateway-setup'
|
|
15
14
|
|
|
16
15
|
export function registerConfigTimezone(api: PluginApi) {
|
|
17
16
|
api.registerGatewayMethod('clawly.config.setTimezone', async ({params, respond}) => {
|
|
@@ -47,13 +46,8 @@ export function registerConfigTimezone(api: PluginApi) {
|
|
|
47
46
|
agents.defaults = defaults
|
|
48
47
|
config.agents = agents
|
|
49
48
|
|
|
50
|
-
// Backfill fields written by setupConfig (which writes directly to disk)
|
|
51
|
-
// so writeConfigFile's merge-patch doesn't revert them.
|
|
52
|
-
const stateDir = api.runtime.state.resolveStateDir()
|
|
53
|
-
const configToWrite = stateDir ? backfillDiskConfig(stateDir, config) : config
|
|
54
|
-
|
|
55
49
|
try {
|
|
56
|
-
await api.runtime.config.writeConfigFile(
|
|
50
|
+
await api.runtime.config.writeConfigFile(config)
|
|
57
51
|
api.logger.info(`config-timezone: set userTimezone to ${timezone}`)
|
|
58
52
|
respond(true, {changed: true, timezone})
|
|
59
53
|
} catch (err) {
|
package/model-gateway-setup.ts
CHANGED
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import fs from 'node:fs'
|
|
13
|
-
import path from 'node:path'
|
|
14
13
|
|
|
15
14
|
import type {PluginApi} from './index'
|
|
16
15
|
import type {OpenClawConfig} from './types/openclaw'
|
|
@@ -68,48 +67,3 @@ export function patchModelGateway(config: OpenClawConfig, _api: PluginApi): bool
|
|
|
68
67
|
|
|
69
68
|
return dirty
|
|
70
69
|
}
|
|
71
|
-
|
|
72
|
-
// ---------------------------------------------------------------------------
|
|
73
|
-
// backfillDiskConfig — merge setupConfig's disk writes into a loadConfig() result
|
|
74
|
-
// ---------------------------------------------------------------------------
|
|
75
|
-
|
|
76
|
-
function isPlainObject(v: unknown): v is Record<string, unknown> {
|
|
77
|
-
return v !== null && typeof v === 'object' && !Array.isArray(v)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Deep-merge `source` into `target`, where source wins for any key it has.
|
|
82
|
-
* Arrays and primitives from source overwrite target.
|
|
83
|
-
* Plain objects recurse.
|
|
84
|
-
*/
|
|
85
|
-
function deepMerge(target: Record<string, unknown>, source: Record<string, unknown>): void {
|
|
86
|
-
for (const key of Object.keys(source)) {
|
|
87
|
-
if (key === '$include') continue // meta-directive, not a resolved config field
|
|
88
|
-
const sv = source[key]
|
|
89
|
-
const tv = target[key]
|
|
90
|
-
if (isPlainObject(sv) && isPlainObject(tv)) {
|
|
91
|
-
deepMerge(tv, sv)
|
|
92
|
-
} else {
|
|
93
|
-
target[key] = sv
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Read the raw disk config (openclaw.json) and deep-merge its fields into a
|
|
100
|
-
* runtime config snapshot (from `loadConfig()`). This ensures that fields
|
|
101
|
-
* written by `setupConfig` (which writes directly to disk) are present in the
|
|
102
|
-
* config object before it's passed to `writeConfigFile`.
|
|
103
|
-
*
|
|
104
|
-
* Without this, `writeConfigFile`'s inner merge-patch sees the stale runtime
|
|
105
|
-
* snapshot (missing setupConfig's changes) and reverts them on disk.
|
|
106
|
-
*/
|
|
107
|
-
export function backfillDiskConfig(stateDir: string, config: OpenClawConfig): OpenClawConfig {
|
|
108
|
-
const configPath = path.join(stateDir, 'openclaw.json')
|
|
109
|
-
const diskConfig = readOpenclawConfig(configPath)
|
|
110
|
-
// Start from disk (setupConfig's fields) then overlay config (RPC handler's
|
|
111
|
-
// changes) so the caller's modifications win over stale disk values.
|
|
112
|
-
const merged = {...diskConfig} as Record<string, unknown>
|
|
113
|
-
deepMerge(merged, config as Record<string, unknown>)
|
|
114
|
-
return merged as OpenClawConfig
|
|
115
|
-
}
|