@olane/os 0.7.24 → 0.7.26

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.
@@ -17,6 +17,11 @@ export declare class OlaneOS extends oObject {
17
17
  addLeader(leader: oLeaderNode): void;
18
18
  addNode(node: OlaneOSNode): Promise<void>;
19
19
  private loadConfig;
20
+ /**
21
+ * Load config from o://os-config storage backend
22
+ * This is called after the leader is started and tools are initialized
23
+ */
24
+ private loadConfigFromStorage;
20
25
  getOSInstanceName(): Promise<string | undefined>;
21
26
  startNodes(type: NodeType): Promise<void>;
22
27
  runSavedPlans(): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"o-os.d.ts","sourceRoot":"","sources":["../../../src/o-olane-os/o-os.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG5D,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAIzC,OAAO,EAAG,SAAS,EAAE,MAAM,eAAe,CAAC;AAK3C,KAAK,WAAW,GAAG,SAAS,GAAG,WAAW,CAAC;AAC3C,qBAAa,OAAQ,SAAQ,OAAO;IAClC,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,KAAK,CAAqB;IAC3B,UAAU,EAAE,WAAW,GAAG,IAAI,CAAQ;IACtC,MAAM,EAAG,mBAAmB,CAAC;IACpC,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,eAAe,CAAa;gBAExB,MAAM,EAAE,aAAa;IAKjC,SAAS,IAAI,SAAS,GAAG,WAAW;IAMpC,SAAS,CAAC,MAAM,EAAE,WAAW;IAOvB,OAAO,CAAC,IAA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QAAQ;IAsDzB,aAAa;IAwEb,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG;IASnC,KAAK,IAAI,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,UAAU,EAAE,CAAA;KAAE,CAAC;IAuC9D,IAAI;IAwBJ,OAAO;CAKd"}
@@ -46,7 +46,8 @@ export class OlaneOS extends oObject {
46
46
  parent.addChildNode(node);
47
47
  }
48
48
  async loadConfig() {
49
- // TODO make this a promise based function
49
+ // Load config from filesystem first to get initial structure
50
+ // Then we'll migrate to using o://os-config for persistence
50
51
  if (this.config.configFilePath) {
51
52
  try {
52
53
  await touch(this.config.configFilePath);
@@ -83,6 +84,61 @@ export class OlaneOS extends oObject {
83
84
  this.logger.warn('No config file path provided, using default config');
84
85
  }
85
86
  }
87
+ /**
88
+ * Load config from o://os-config storage backend
89
+ * This is called after the leader is started and tools are initialized
90
+ */
91
+ async loadConfigFromStorage() {
92
+ if (!this.rootLeader) {
93
+ this.logger.warn('No root leader available, skipping storage config load');
94
+ return;
95
+ }
96
+ try {
97
+ const osInstanceName = await this.getOSInstanceName();
98
+ if (!osInstanceName) {
99
+ this.logger.warn('No OS instance name available, skipping storage config load');
100
+ return;
101
+ }
102
+ this.logger.debug(`Loading config from o://os-config for: ${osInstanceName}`);
103
+ // Try to load existing config from storage
104
+ const loadResult = await this.rootLeader.use(new oAddress('o://os-config'), {
105
+ method: 'load_config',
106
+ params: { osName: osInstanceName },
107
+ });
108
+ if (loadResult.result?.success) {
109
+ const loadedConfig = loadResult.result.data;
110
+ this.logger.debug('Loaded config from storage:', loadedConfig);
111
+ // Merge storage config with current config, prioritizing storage for lanes
112
+ if (loadedConfig.oNetworkConfig) {
113
+ this.config = {
114
+ ...this.config,
115
+ lanes: loadedConfig.oNetworkConfig.lanes || this.config.lanes || [],
116
+ };
117
+ }
118
+ this.logger.info(`Loaded config from storage: ${this.config.lanes?.length || 0} saved lanes`);
119
+ }
120
+ else {
121
+ this.logger.debug('No config found in storage, creating default:', loadResult.result?.error);
122
+ // Create default config in storage
123
+ await this.rootLeader.use(new oAddress('o://os-config'), {
124
+ method: 'save_config',
125
+ params: {
126
+ osName: osInstanceName,
127
+ config: {
128
+ oNetworkConfig: {
129
+ lanes: this.config.lanes || [],
130
+ },
131
+ },
132
+ },
133
+ });
134
+ this.logger.info('Created default config in storage');
135
+ }
136
+ }
137
+ catch (error) {
138
+ this.logger.error('Failed to load config from storage (non-fatal):', error);
139
+ // Don't throw - allow OS to continue with filesystem config
140
+ }
141
+ }
86
142
  async getOSInstanceName() {
87
143
  if (this.config.configFilePath) {
88
144
  const osConfig = await ConfigManager.getOSConfigFromPath(this.config.configFilePath);
@@ -138,28 +194,57 @@ export class OlaneOS extends oObject {
138
194
  }
139
195
  }
140
196
  async runSavedPlans() {
141
- const laneCIDs = Array.from(new Set(this.config?.lanes || []));
142
- if (laneCIDs.length === 0) {
143
- this.logger.debug('No saved lanes to replay');
197
+ if (!this.rootLeader) {
198
+ this.logger.warn('No root leader available, skipping lane replay');
144
199
  return;
145
200
  }
146
- this.logger.info(`Replaying ${laneCIDs.length} saved lane(s) to restore network state...`);
147
- for (const cid of laneCIDs) {
148
- this.logger.debug('Replaying lane with CID: ' + cid);
149
- try {
150
- // Use the entry node's lane tool to replay the lane
151
- const result = await this.use(this.entryNode().address, {
152
- method: 'replay',
153
- params: { cid },
154
- });
155
- this.logger.info('Lane replay completed successfully: ' + cid, result);
201
+ try {
202
+ const osInstanceName = await this.getOSInstanceName();
203
+ if (!osInstanceName) {
204
+ this.logger.warn('No OS instance name available, skipping lane replay');
205
+ return;
156
206
  }
157
- catch (error) {
158
- this.logger.error('Failed to replay lane: ' + cid, error);
159
- // Continue with other lanes even if one fails
207
+ this.logger.debug(`Loading saved lanes for OS: ${osInstanceName}`);
208
+ // Get lanes from o://os-config storage (same as cloud pattern)
209
+ const lanesResult = await this.rootLeader.use(new oAddress('o://os-config'), {
210
+ method: 'get_lanes',
211
+ params: { osName: osInstanceName },
212
+ });
213
+ const lanes = lanesResult.result?.data?.lanes || [];
214
+ if (!Array.isArray(lanes) || lanes.length === 0) {
215
+ this.logger.debug('No saved lanes found to replay');
216
+ return;
217
+ }
218
+ this.logger.info(`Found ${lanes.length} saved lane(s) to replay: ${lanes.join(', ')}`);
219
+ const replayedLanes = [];
220
+ // Replay each lane
221
+ for (const cid of lanes) {
222
+ try {
223
+ this.logger.debug(`Replaying lane: ${cid}`);
224
+ // Use the entry node's lane tool to replay the lane
225
+ const replayResult = await this.use(this.entryNode().address, {
226
+ method: 'replay',
227
+ params: { cid },
228
+ });
229
+ if (replayResult.result?.success !== false) {
230
+ replayedLanes.push(cid);
231
+ this.logger.info(`Successfully replayed lane: ${cid}`);
232
+ }
233
+ else {
234
+ this.logger.warn(`Failed to replay lane ${cid}:`, replayResult.result?.error);
235
+ }
236
+ }
237
+ catch (error) {
238
+ this.logger.error(`Error replaying lane ${cid}:`, error);
239
+ // Continue with other lanes even if one fails
240
+ }
160
241
  }
242
+ this.logger.info(`Replayed ${replayedLanes.length} of ${lanes.length} lane(s)`);
243
+ }
244
+ catch (error) {
245
+ this.logger.error('Error loading and replaying saved lanes:', error);
246
+ // Don't throw - allow OS to continue even if replay fails
161
247
  }
162
- this.logger.info('All saved lanes replayed');
163
248
  }
164
249
  async use(oAddress, params) {
165
250
  const entryNode = this.entryNode();
@@ -180,6 +265,11 @@ export class OlaneOS extends oObject {
180
265
  this.logger.debug('Leaders started...');
181
266
  await this.startNodes(NodeType.NODE);
182
267
  this.logger.debug('Nodes started...');
268
+ // Load config from o://os-config storage backend (after tools are initialized)
269
+ // This merges any saved lanes from persistent storage
270
+ await this.loadConfigFromStorage();
271
+ this.logger.debug('Config loaded from storage...');
272
+ // Replay saved lanes from storage
183
273
  await this.runSavedPlans();
184
274
  this.logger.debug('Saved plans run...');
185
275
  this.logger.debug('OS instance started...');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@olane/os",
3
- "version": "0.7.24",
3
+ "version": "0.7.26",
4
4
  "type": "module",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
@@ -58,23 +58,23 @@
58
58
  "typescript": "5.4.5"
59
59
  },
60
60
  "dependencies": {
61
- "@olane/o-client-limited": "0.7.24",
62
- "@olane/o-config": "0.7.24",
63
- "@olane/o-core": "0.7.24",
64
- "@olane/o-intelligence": "0.7.24",
65
- "@olane/o-lane": "0.7.24",
66
- "@olane/o-leader": "0.7.24",
67
- "@olane/o-login": "0.7.24",
68
- "@olane/o-protocol": "0.7.24",
69
- "@olane/o-storage": "0.7.24",
70
- "@olane/o-tool": "0.7.24",
71
- "@olane/o-tool-registry": "0.7.24",
72
- "@olane/o-tools-common": "0.7.24",
61
+ "@olane/o-client-limited": "0.7.26",
62
+ "@olane/o-config": "0.7.26",
63
+ "@olane/o-core": "0.7.26",
64
+ "@olane/o-intelligence": "0.7.26",
65
+ "@olane/o-lane": "0.7.26",
66
+ "@olane/o-leader": "0.7.26",
67
+ "@olane/o-login": "0.7.26",
68
+ "@olane/o-protocol": "0.7.26",
69
+ "@olane/o-storage": "0.7.26",
70
+ "@olane/o-tool": "0.7.26",
71
+ "@olane/o-tool-registry": "0.7.26",
72
+ "@olane/o-tools-common": "0.7.26",
73
73
  "chalk": "^5.4.1",
74
74
  "debug": "^4.4.1",
75
75
  "dotenv": "^16.5.0",
76
76
  "fs-extra": "^11.3.0",
77
77
  "touch": "^3.1.1"
78
78
  },
79
- "gitHead": "6f3520b1a7e24d39c0b0d9e6f7b7b3c26145738c"
79
+ "gitHead": "ded249359b4d2d0eb2e1bf438ce59287ba9dfd58"
80
80
  }