semnet-snap-protocol
Version:
TypeScript reference implementation of the SNAP Protocol v1.1 - Agent Internet Edition
187 lines • 4.92 kB
TypeScript
import type { SNAPMessage, Part, AgentID, Payment, FilePart, ImagePart } from './types.js';
/**
* Message builder for creating SNAP messages
*/
export declare class MessageBuilder {
private message;
constructor(from: AgentID);
/**
* Set the recipient agent
*/
to(recipient: AgentID): this;
/**
* Set conversation context
*/
context(contextId: string): this;
/**
* Add payment information
*/
payment(payment: Payment): this;
/**
* Add metadata
*/
metadata(metadata: Record<string, any>): this;
/**
* Add a text part
*/
text(content: string, options?: {
format?: 'plain' | 'markdown' | 'html';
language?: string;
encoding?: 'utf-8' | 'base64';
}): this;
/**
* Add a data part
*/
data(content: Record<string, any>, options?: {
schema?: Record<string, any>;
format?: 'json' | 'xml' | 'yaml';
}): this;
/**
* Add a file part
*/
file(content: {
uri?: string;
bytes?: string;
name: string;
mimeType: string;
size?: number;
hash?: string;
}, options?: {
description?: string;
}): this;
/**
* Add an image part
*/
image(content: {
uri?: string;
bytes?: string;
mimeType: 'image/jpeg' | 'image/png' | 'image/gif' | 'image/webp';
width?: number;
height?: number;
alt?: string;
}, options?: {
caption?: string;
}): this;
/**
* Add an audio part
*/
audio(content: {
uri?: string;
bytes?: string;
mimeType: 'audio/mpeg' | 'audio/wav' | 'audio/ogg' | 'audio/webm';
duration?: number;
sampleRate?: number;
}, options?: {
title?: string;
artist?: string;
}): this;
/**
* Add a video part
*/
video(content: {
uri?: string;
bytes?: string;
mimeType: 'video/mp4' | 'video/webm' | 'video/quicktime';
duration?: number;
width?: number;
height?: number;
frameRate?: number;
}, options?: {
title?: string;
description?: string;
}): this;
/**
* Add a custom part
*/
part(part: Part): this;
/**
* Set custom message ID
*/
id(messageId: string): this;
/**
* Set custom timestamp
*/
timestamp(timestamp: string): this;
/**
* Build and validate the message
*/
build(): SNAPMessage;
/**
* Build message for signing (without signature field)
*/
buildForSigning(): Omit<SNAPMessage, 'signature'>;
}
/**
* Message utilities
*/
export declare class MessageUtils {
/**
* Create a simple text message
*/
static text(from: AgentID, content: string, to?: AgentID): SNAPMessage;
/**
* Create a data message
*/
static data(from: AgentID, content: Record<string, any>, to?: AgentID): SNAPMessage;
/**
* Create an error response message
*/
static error(from: AgentID, errorMessage: string, to?: AgentID): SNAPMessage;
/**
* Extract text content from message parts
*/
static extractText(message: SNAPMessage): string[];
/**
* Extract data content from message parts
*/
static extractData(message: SNAPMessage): Record<string, any>[];
/**
* Get all file parts from message
*/
static extractFiles(message: SNAPMessage): FilePart[];
/**
* Get all image parts from message
*/
static extractImages(message: SNAPMessage): ImagePart[];
/**
* Check if message has payment
*/
static hasPayment(message: SNAPMessage): boolean;
/**
* Get payment amount from message
*/
static getPaymentAmount(message: SNAPMessage): number | null;
/**
* Check if message is in a conversation context
*/
static hasContext(message: SNAPMessage): boolean;
/**
* Get message size estimate in bytes
*/
static estimateSize(message: SNAPMessage): number;
/**
* Validate message structure
*/
static validate(message: any): SNAPMessage;
/**
* Create canonical representation for signing
*/
static canonicalize(message: Omit<SNAPMessage, 'signature'>): string;
/**
* Check if message is expired (based on timestamp)
*/
static isExpired(message: SNAPMessage, maxAgeMinutes?: number): boolean;
/**
* Create a reply message
*/
static reply(originalMessage: SNAPMessage, from: AgentID): MessageBuilder;
/**
* Create a payment request message
*/
static paymentRequest(from: AgentID, to: AgentID, amount: number, description: string): SNAPMessage;
}
/**
* Convenience function to create a message builder
*/
export declare function createMessage(from: AgentID): MessageBuilder;
//# sourceMappingURL=message.d.ts.map