Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions bot/scripts/install_local_openclaw_plugin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/bash
set -e

# 安装本地 OpenClaw OpenViking 插件
# 用法: ./install_local_openclaw_plugin.sh [--rebuild]
#
# 选项:
# --rebuild 只重新编译,不重新复制文件

REBUILD=false
if [[ "$1" == "--rebuild" ]]; then
REBUILD=true
fi

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"

# 源目录:openviking 根目录下的 examples/openclaw-plugin
OPENCLAW_PLUGIN_SOURCE="$(dirname "$SCRIPT_DIR")/../examples/openclaw-plugin"
OPENCLAW_PLUGIN_DIR="$HOME/.openclaw/extensions/openviking"

echo "=== 安装本地 OpenClaw OpenViking 插件 ==="
echo "源目录: $OPENCLAW_PLUGIN_SOURCE"
echo "目标目录: $OPENCLAW_PLUGIN_DIR"

# 检查源目录是否存在
if [[ ! -d "$OPENCLAW_PLUGIN_SOURCE" ]]; then
echo "错误: 源目录不存在: $OPENCLAW_PLUGIN_SOURCE"
exit 1
fi

# 删除旧的插件目录
if [[ "$REBUILD" == "false" ]]; then
echo "删除旧插件目录..."
rm -rf "$OPENCLAW_PLUGIN_DIR"

# 复制源文件到插件目录
echo "复制源文件..."
cp -r "$OPENCLAW_PLUGIN_SOURCE" "$OPENCLAW_PLUGIN_DIR"

# 复制 tsconfig.json
echo "复制 tsconfig.json..."
cp "$OPENCLAW_PLUGIN_SOURCE/tsconfig.json" "$OPENCLAW_PLUGIN_DIR/"

# 安装依赖
echo "安装依赖..."
cd "$OPENCLAW_PLUGIN_DIR"
npm install --include=dev
fi

# 编译 TypeScript
echo "编译 TypeScript..."
cd "$OPENCLAW_PLUGIN_DIR"
npx -p typescript tsc -p tsconfig.json

# 重启 OpenClaw
echo "重启 OpenClaw..."
if command -v openclaw &> /dev/null; then
openclaw gateway restart
sleep 2
echo ""
echo "=== 等待插件加载,按 Ctrl+C 退出日志 ==="
openclaw logs --follow | grep -E "openviking|context-engine|error.*plugin" | head -10
else
echo "警告: openclaw 命令未找到,请手动重启 OpenClaw"
fi
25 changes: 11 additions & 14 deletions crates/ragfs/src/plugins/localfs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl FileSystem for LocalFileSystem {
}
}

async fn write(&self, path: &str, data: &[u8], offset: u64, _flags: WriteFlag) -> Result<u64> {
async fn write(&self, path: &str, data: &[u8], offset: u64, flags: WriteFlag) -> Result<u64> {
let local_path = self.resolve_path(path);

// Check if it's a directory
Expand All @@ -195,19 +195,16 @@ impl FileSystem for LocalFileSystem {
}
}

// Open or create file
let mut file = if local_path.exists() {
fs::OpenOptions::new()
.write(true)
.open(&local_path)
.map_err(|e| Error::plugin(format!("failed to open file: {}", e)))?
} else {
fs::OpenOptions::new()
.write(true)
.create(true)
.open(&local_path)
.map_err(|e| Error::plugin(format!("failed to create file: {}", e)))?
};
// Determine if we should truncate based on flags
let should_truncate = matches!(flags, WriteFlag::Create | WriteFlag::Truncate);

// Open or create file with truncate support
let mut file = fs::OpenOptions::new()
.write(true)
.create(true)
.truncate(should_truncate)
.open(&local_path)
.map_err(|e| Error::plugin(format!("failed to open file: {}", e)))?;

// Write data
use std::io::{Seek, SeekFrom, Write};
Expand Down
22 changes: 17 additions & 5 deletions examples/openclaw-plugin/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export type CommitSessionResult = {
/** Present when wait=true and extraction completed. Keyed by category. */
memories_extracted?: Record<string, number>;
error?: string;
trace_id?: string;
};

export type TaskResult = {
Expand Down Expand Up @@ -629,25 +630,36 @@ export class OpenVikingClient {
async addSessionMessage(
sessionId: string,
role: string,
content: string,
parts: Array<{
type: "text" | "tool" | "context";
text?: string;
tool_name?: string;
tool_output?: string;
tool_status?: string;
tool_input?: Record<string, unknown>;
tool_id?: string;
uri?: string;
abstract?: string;
context_type?: "memory" | "resource" | "skill";
}>,
agentId?: string,
createdAt?: string,
): Promise<void> {
const body: {
role: string;
content: string;
parts: typeof parts;
created_at?: string;
} = { role, content };
} = { role, parts };
if (createdAt) {
body.created_at = createdAt;
}
await this.emitRoutingDebug(
"session message POST",
"session message POST (with parts)",
{
path: `/api/v1/sessions/${encodeURIComponent(sessionId)}/messages`,
sessionId,
role,
contentChars: content.length,
partCount: parts.length,
created_at: createdAt ?? null,
},
agentId,
Expand Down
Loading
Loading