@stamn/stamn-plugin 0.1.0-alpha.20 → 0.1.0-alpha.21
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/index.js +112 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4764,7 +4764,7 @@ var StamnClient = class {
|
|
|
4764
4764
|
return Math.random() * capped;
|
|
4765
4765
|
}
|
|
4766
4766
|
sleep(ms) {
|
|
4767
|
-
return new Promise((
|
|
4767
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
4768
4768
|
}
|
|
4769
4769
|
async parseErrorResponse(res) {
|
|
4770
4770
|
const body = await res.text();
|
|
@@ -5507,6 +5507,57 @@ function readLogs(opts) {
|
|
|
5507
5507
|
};
|
|
5508
5508
|
}
|
|
5509
5509
|
|
|
5510
|
+
// src/workspace-files.ts
|
|
5511
|
+
import { readdirSync, readFileSync as readFileSync3, writeFileSync as writeFileSync4, statSync as statSync2, mkdirSync as mkdirSync3 } from "fs";
|
|
5512
|
+
import { join as join6, resolve, relative, dirname as dirname2 } from "path";
|
|
5513
|
+
import { homedir as homedir3 } from "os";
|
|
5514
|
+
var WORKSPACE_DIR = join6(homedir3(), ".openclaw", "workspace");
|
|
5515
|
+
function assertWithinWorkspace(relativePath) {
|
|
5516
|
+
const full = resolve(WORKSPACE_DIR, relativePath);
|
|
5517
|
+
if (!full.startsWith(WORKSPACE_DIR + "/") && full !== WORKSPACE_DIR) {
|
|
5518
|
+
throw new Error("Path outside workspace");
|
|
5519
|
+
}
|
|
5520
|
+
return full;
|
|
5521
|
+
}
|
|
5522
|
+
function walkDir(dir, base) {
|
|
5523
|
+
const results = [];
|
|
5524
|
+
let entries;
|
|
5525
|
+
try {
|
|
5526
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
5527
|
+
} catch {
|
|
5528
|
+
return results;
|
|
5529
|
+
}
|
|
5530
|
+
for (const entry of entries) {
|
|
5531
|
+
const fullPath = join6(dir, entry.name);
|
|
5532
|
+
if (entry.isDirectory()) {
|
|
5533
|
+
results.push(...walkDir(fullPath, base));
|
|
5534
|
+
} else if (entry.isFile() && entry.name.endsWith(".md")) {
|
|
5535
|
+
const stat = statSync2(fullPath);
|
|
5536
|
+
results.push({
|
|
5537
|
+
path: relative(base, fullPath),
|
|
5538
|
+
size: stat.size,
|
|
5539
|
+
modifiedAt: stat.mtime.toISOString()
|
|
5540
|
+
});
|
|
5541
|
+
}
|
|
5542
|
+
}
|
|
5543
|
+
return results;
|
|
5544
|
+
}
|
|
5545
|
+
function listWorkspaceFiles() {
|
|
5546
|
+
return walkDir(WORKSPACE_DIR, WORKSPACE_DIR);
|
|
5547
|
+
}
|
|
5548
|
+
function readWorkspaceFile(relativePath) {
|
|
5549
|
+
const full = assertWithinWorkspace(relativePath);
|
|
5550
|
+
const content = readFileSync3(full, "utf-8");
|
|
5551
|
+
const stat = statSync2(full);
|
|
5552
|
+
return { path: relativePath, content, size: stat.size };
|
|
5553
|
+
}
|
|
5554
|
+
function writeWorkspaceFile(relativePath, content) {
|
|
5555
|
+
const full = assertWithinWorkspace(relativePath);
|
|
5556
|
+
mkdirSync3(dirname2(full), { recursive: true });
|
|
5557
|
+
writeFileSync4(full, content, "utf-8");
|
|
5558
|
+
return { path: relativePath, written: true };
|
|
5559
|
+
}
|
|
5560
|
+
|
|
5510
5561
|
// src/ws-service.ts
|
|
5511
5562
|
var MAX_EVENT_BUFFER_SIZE = 200;
|
|
5512
5563
|
var BASE_RECONNECT_DELAY_MS = 1e3;
|
|
@@ -5678,6 +5729,18 @@ var StamnWsService = class {
|
|
|
5678
5729
|
this.handleRequestLogs(payload.params);
|
|
5679
5730
|
return;
|
|
5680
5731
|
}
|
|
5732
|
+
if (payload.command === "list_files") {
|
|
5733
|
+
this.handleListFiles(payload.params);
|
|
5734
|
+
return;
|
|
5735
|
+
}
|
|
5736
|
+
if (payload.command === "read_file") {
|
|
5737
|
+
this.handleReadFile(payload.params);
|
|
5738
|
+
return;
|
|
5739
|
+
}
|
|
5740
|
+
if (payload.command === "write_file") {
|
|
5741
|
+
this.handleWriteFile(payload.params);
|
|
5742
|
+
return;
|
|
5743
|
+
}
|
|
5681
5744
|
this.logger.info(`Command received: ${payload.command} (${payload.commandId})`);
|
|
5682
5745
|
if (payload.command === "update_plugin") {
|
|
5683
5746
|
this.handleUpdatePlugin();
|
|
@@ -5722,6 +5785,54 @@ var StamnWsService = class {
|
|
|
5722
5785
|
});
|
|
5723
5786
|
}
|
|
5724
5787
|
}
|
|
5788
|
+
handleListFiles(params) {
|
|
5789
|
+
try {
|
|
5790
|
+
const files = listWorkspaceFiles();
|
|
5791
|
+
this.sendMessage("participant:file_response", {
|
|
5792
|
+
requestId: params.requestId,
|
|
5793
|
+
files
|
|
5794
|
+
});
|
|
5795
|
+
} catch (err) {
|
|
5796
|
+
this.sendMessage("participant:file_response", {
|
|
5797
|
+
requestId: params.requestId,
|
|
5798
|
+
files: [],
|
|
5799
|
+
error: err.message
|
|
5800
|
+
});
|
|
5801
|
+
}
|
|
5802
|
+
}
|
|
5803
|
+
handleReadFile(params) {
|
|
5804
|
+
try {
|
|
5805
|
+
const result = readWorkspaceFile(params.path);
|
|
5806
|
+
this.sendMessage("participant:file_response", {
|
|
5807
|
+
requestId: params.requestId,
|
|
5808
|
+
...result
|
|
5809
|
+
});
|
|
5810
|
+
} catch (err) {
|
|
5811
|
+
this.sendMessage("participant:file_response", {
|
|
5812
|
+
requestId: params.requestId,
|
|
5813
|
+
path: params.path,
|
|
5814
|
+
content: "",
|
|
5815
|
+
size: 0,
|
|
5816
|
+
error: err.message
|
|
5817
|
+
});
|
|
5818
|
+
}
|
|
5819
|
+
}
|
|
5820
|
+
handleWriteFile(params) {
|
|
5821
|
+
try {
|
|
5822
|
+
const result = writeWorkspaceFile(params.path, params.content);
|
|
5823
|
+
this.sendMessage("participant:file_response", {
|
|
5824
|
+
requestId: params.requestId,
|
|
5825
|
+
...result
|
|
5826
|
+
});
|
|
5827
|
+
} catch (err) {
|
|
5828
|
+
this.sendMessage("participant:file_response", {
|
|
5829
|
+
requestId: params.requestId,
|
|
5830
|
+
path: params.path,
|
|
5831
|
+
written: false,
|
|
5832
|
+
error: err.message
|
|
5833
|
+
});
|
|
5834
|
+
}
|
|
5835
|
+
}
|
|
5725
5836
|
onAuthError(payload) {
|
|
5726
5837
|
this.authFailed = true;
|
|
5727
5838
|
this.logger.error(`Authentication failed: ${payload.reason}`);
|