UNPKG

pipe-protocol

Version:

A protocol for large scale Interplanetary Intertool Agent Context

148 lines 3.89 kB
/** * @file Pipe Class Implementation * @version 1.0.0 * @status STABLE - DO NOT MODIFY WITHOUT TESTS * @lastModified 2024-02-04 * * Core class for managing tool wrapping and IPFS integration. * * IMPORTANT: * - All modifications must maintain test coverage * - Configuration must be immutable after initialization * - Hook system must maintain order of execution * - IPFS operations must handle errors gracefully * * Functionality: * - Tool wrapping with IPFS capabilities * - Hook system for extensibility * - Configuration management * - IPFS client integration * - Token counting and limiting * - Schema generation * - Scope management (public/private) * - Pin management */ import { Tool } from './types/tool'; import { IPFSClient, IPFSClientConfig } from './services/ipfs/ipfsClient'; import { PipeRecord, Scope, PipeBundle } from './types'; export type HookType = 'beforeStore' | 'afterStore'; export interface Hook { name: string; type: HookType; handler: (data: unknown) => unknown | Promise<unknown>; } export interface PipeConfig { ipfs?: Partial<IPFSClientConfig>; defaults?: { maxTokens?: number; storeResult?: boolean; generateSchema?: boolean; scope?: 'public' | 'private'; pin?: boolean; }; } export interface WrappedToolConfig { ipfsClient: IPFSClient; maxTokens?: number; storeResult?: boolean; generateSchema?: boolean; scope?: 'public' | 'private'; pin?: boolean; hooks?: { beforeStore?: (data: unknown) => Promise<unknown>; afterStore?: (data: unknown) => Promise<unknown>; }; } export declare class Pipe { private ipfsClient; private hooks; private config; constructor(config?: PipeConfig); /** * Add hooks to the pipe */ addHooks(hooks: Hook[]): void; /** * Remove a hook by name */ removeHook(name: string): void; /** * Execute hooks of a specific type */ private executeHooks; /** * Store data in IPFS */ store(data: unknown, options?: { pin?: boolean; scope?: 'public' | 'private'; }): Promise<string>; /** * Retrieve data from IPFS */ retrieve(cid: string): Promise<unknown>; /** * Wrap tools with IPFS capabilities */ wrap(tools: Tool[]): Tool[]; /** * Publish a record to IPFS */ publishRecord(record: PipeRecord): Promise<PipeRecord>; /** * Fetch a record from IPFS */ fetchRecord(cid: string, scope: Scope): Promise<PipeRecord | null>; /** * Pin a record in IPFS */ pin(cid: string, scope: Scope): Promise<void>; /** * Unpin a record from IPFS */ unpin(cid: string, scope: Scope): Promise<void>; /** * Get pinned CIDs for a scope */ getPinnedCids(scope: Scope): Promise<string[]>; /** * Get node status */ getStatus(): { localNode: boolean; publicNode: boolean; }; /** * Get node info for a scope */ getNodeInfo(scope: Scope): Promise<any>; /** * Get storage metrics for a scope */ getStorageMetrics(scope: Scope): Promise<{ totalSize: number; numObjects: number; }>; /** * Publish a bundle to IPFS */ publishBundle(bundle: PipeBundle): Promise<PipeBundle>; /** * Replicate a record from one scope to another */ replicate(cid: string, fromScope: Scope, toScope: Scope): Promise<void>; /** * Get configuration for a scope */ getConfiguration(scope: Scope): Promise<any>; /** * Stop the pipe and cleanup resources */ stop(): Promise<void>; } export { Pipe as PipeProtocol }; /** * Example summary hook that generates a summary of data before storage */ export declare const summaryHook: Hook; //# sourceMappingURL=pipe.d.ts.map