v1.3.0: Full Rig integration - Multi-agent AI framework

This commit is contained in:
admin
2026-02-26 11:56:08 +04:00
Unverified
parent 04e0fcd59e
commit 5455eaa125
11 changed files with 1958 additions and 0 deletions

239
src/rig/client.ts Normal file
View File

@@ -0,0 +1,239 @@
/**
* Rig Service Client for QwenClaw
*
* TypeScript client for communicating with the Rig AI agent service
*/
export interface RigConfig {
host: string;
port: number;
}
export interface AgentConfig {
name: string;
preamble: string;
model?: string;
provider?: string;
temperature?: number;
}
export interface Tool {
name: string;
description: string;
parameters: Record<string, unknown>;
category: string;
}
export interface Document {
id: string;
content: string;
metadata: Record<string, unknown>;
}
export class RigClient {
private baseUrl: string;
constructor(config: RigConfig) {
this.baseUrl = `http://${config.host}:${config.port}`;
}
// Health check
async health(): Promise<boolean> {
try {
const res = await fetch(`${this.baseUrl}/health`);
const data = await res.json();
return data.status === "ok";
} catch {
return false;
}
}
// ========== Agent Methods ==========
async createAgent(config: AgentConfig): Promise<string> {
const res = await fetch(`${this.baseUrl}/api/agents`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(config),
});
if (!res.ok) {
throw new Error(`Failed to create agent: ${res.statusText}`);
}
const data = await res.json();
return data.session_id;
}
async listAgents(): Promise<Array<{ id: string; name: string; model: string }>> {
const res = await fetch(`${this.baseUrl}/api/agents`);
if (!res.ok) {
throw new Error(`Failed to list agents: ${res.statusText}`);
}
const data = await res.json();
return data.agents;
}
async executePrompt(sessionId: string, prompt: string): Promise<string> {
const res = await fetch(`${this.baseUrl}/api/agents/${sessionId}/prompt`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ prompt }),
});
if (!res.ok) {
throw new Error(`Failed to execute prompt: ${res.statusText}`);
}
const data = await res.json();
return data.response;
}
async getAgent(sessionId: string): Promise<AgentConfig & { id: string }> {
const res = await fetch(`${this.baseUrl}/api/agents/${sessionId}`);
if (!res.ok) {
throw new Error(`Failed to get agent: ${res.statusText}`);
}
const data = await res.json();
return data.agent;
}
async deleteAgent(sessionId: string): Promise<void> {
const res = await fetch(`${this.baseUrl}/api/agents/${sessionId}`, {
method: "DELETE",
});
if (!res.ok) {
throw new Error(`Failed to delete agent: ${res.statusText}`);
}
}
// ========== Council Methods ==========
async createCouncil(
name: string,
agents: AgentConfig[]
): Promise<string> {
const res = await fetch(`${this.baseUrl}/api/councils`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ name, agents }),
});
if (!res.ok) {
throw new Error(`Failed to create council: ${res.statusText}`);
}
const data = await res.json();
return data.council_id;
}
async listCouncils(): Promise<Array<{ id: string; name: string; agents: Array<{ id: string; name: string }> }>> {
const res = await fetch(`${this.baseUrl}/api/councils`);
if (!res.ok) {
throw new Error(`Failed to list councils: ${res.statusText}`);
}
const data = await res.json();
return data.councils;
}
async executeCouncil(councilId: string, task: string): Promise<string> {
const res = await fetch(`${this.baseUrl}/api/councils/${councilId}/execute`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ task }),
});
if (!res.ok) {
throw new Error(`Failed to execute council: ${res.statusText}`);
}
const data = await res.json();
return data.response;
}
// ========== Tool Methods ==========
async listTools(): Promise<Tool[]> {
const res = await fetch(`${this.baseUrl}/api/tools`);
if (!res.ok) {
throw new Error(`Failed to list tools: ${res.statusText}`);
}
const data = await res.json();
return data.tools;
}
async searchTools(query: string, limit = 10): Promise<Tool[]> {
const res = await fetch(`${this.baseUrl}/api/tools/search`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ query, limit }),
});
if (!res.ok) {
throw new Error(`Failed to search tools: ${res.statusText}`);
}
const data = await res.json();
return data.tools;
}
// ========== Document Methods ==========
async addDocument(content: string, metadata?: Record<string, unknown>): Promise<string> {
const res = await fetch(`${this.baseUrl}/api/documents`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ content, metadata }),
});
if (!res.ok) {
throw new Error(`Failed to add document: ${res.statusText}`);
}
const data = await res.json();
return data.id;
}
async searchDocuments(query: string, limit = 10): Promise<Document[]> {
const res = await fetch(`${this.baseUrl}/api/documents/search`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ query, limit }),
});
if (!res.ok) {
throw new Error(`Failed to search documents: ${res.statusText}`);
}
const data = await res.json();
return data.documents;
}
async getDocument(id: string): Promise<Document> {
const res = await fetch(`${this.baseUrl}/api/documents/${id}`);
if (!res.ok) {
throw new Error(`Failed to get document: ${res.statusText}`);
}
const data = await res.json();
return data.document;
}
async deleteDocument(id: string): Promise<void> {
const res = await fetch(`${this.baseUrl}/api/documents/${id}`, {
method: "DELETE",
});
if (!res.ok) {
throw new Error(`Failed to delete document: ${res.statusText}`);
}
}
}
// Export default client instance
export default RigClient;

116
src/rig/index.ts Normal file
View File

@@ -0,0 +1,116 @@
/**
* Rig Integration Module for QwenClaw
*
* Provides seamless integration between QwenClaw and Rig AI agent service
*/
import { RigClient } from "./client";
let rigClient: RigClient | null = null;
/**
* Initialize Rig client
*/
export function initRigClient(host = "127.0.0.1", port = 8080): RigClient {
rigClient = new RigClient({ host, port });
return rigClient;
}
/**
* Get Rig client instance
*/
export function getRigClient(): RigClient | null {
return rigClient;
}
/**
* Check if Rig service is available
*/
export async function isRigAvailable(): Promise<boolean> {
if (!rigClient) return false;
return await rigClient.health();
}
/**
* Execute a prompt using Rig agent
*/
export async function executeWithRig(
sessionId: string,
prompt: string
): Promise<string> {
if (!rigClient) {
throw new Error("Rig client not initialized. Call initRigClient() first.");
}
return await rigClient.executePrompt(sessionId, prompt);
}
/**
* Create a multi-agent council for complex tasks
*/
export async function createCouncil(
name: string,
agentConfigs: Array<{ name: string; preamble: string; model?: string }>
): Promise<string> {
if (!rigClient) {
throw new Error("Rig client not initialized. Call initRigClient() first.");
}
return await rigClient.createCouncil(name, agentConfigs);
}
/**
* Execute task with agent council
*/
export async function executeWithCouncil(
councilId: string,
task: string
): Promise<string> {
if (!rigClient) {
throw new Error("Rig client not initialized. Call initRigClient() first.");
}
return await rigClient.executeCouncil(councilId, task);
}
/**
* Search for relevant documents using RAG
*/
export async function searchDocuments(
query: string,
limit = 5
): Promise<Array<{ id: string; content: string; metadata: Record<string, unknown> }>> {
if (!rigClient) {
throw new Error("Rig client not initialized. Call initRigClient() first.");
}
return await rigClient.searchDocuments(query, limit);
}
/**
* Add document to vector store for RAG
*/
export async function addDocumentToStore(
content: string,
metadata?: Record<string, unknown>
): Promise<string> {
if (!rigClient) {
throw new Error("Rig client not initialized. Call initRigClient() first.");
}
return await rigClient.addDocument(content, metadata);
}
/**
* Search for relevant tools
*/
export async function searchTools(
query: string,
limit = 10
): Promise<Array<{ name: string; description: string; category: string }>> {
if (!rigClient) {
throw new Error("Rig client not initialized. Call initRigClient() first.");
}
return await rigClient.searchTools(query, limit);
}