
Research
Malicious fezbox npm Package Steals Browser Passwords from Cookies via Innovative QR Code Steganographic Technique
A malicious package uses a QR code as steganography in an innovative technique.
@redhat-cloud-services/ai-client-common
Advanced tools
Common interfaces and utilities for AI client packages in the Red Hat Cloud Services ecosystem.
Common interfaces and utilities for AI client packages in the Red Hat Cloud Services ecosystem.
IAIClient
interface for all AI servicesnpm install @redhat-cloud-services/ai-client-common
All AI clients in this workspace implement the IAIClient
interface:
import { IAIClient } from '@redhat-cloud-services/ai-client-common';
interface IAIClient<AP extends Record<string, unknown> = Record<string, unknown>> {
init(): Promise<{
initialConversationId: string;
conversations: IConversation[];
}>;
sendMessage<TChunk = unknown, T extends Record<string, unknown> = Record<string, unknown>>(
conversationId: string,
message: string,
options?: ISendMessageOptions<T>
): Promise<TChunk | IMessageResponse<AP> | void>;
getDefaultStreamingHandler?<TChunk = unknown>(): IStreamingHandler<TChunk> | undefined;
getConversationHistory(conversationId: string, options?: IRequestOptions): Promise<IConversationHistoryResponse<AP>>;
healthCheck(options?: IRequestOptions): Promise<unknown>;
getServiceStatus?(options?: IRequestOptions): Promise<unknown>;
createNewConversation(): Promise<IConversation>;
}
Important: Do NOT set 'Content-Type'
headers in your fetchFunction - AI clients manage these internally based on endpoint requirements.
import { IFetchFunction } from '@redhat-cloud-services/ai-client-common';
const customFetch: IFetchFunction = async (input, init) => {
// Add authentication headers
const token = await getAuthToken();
return fetch(input, {
...init,
headers: {
...init?.headers,
'Authorization': `Bearer ${token}`,
// DO NOT set 'Content-Type' - AI clients handle this internally
},
});
};
import { IBaseClientConfig } from '@redhat-cloud-services/ai-client-common';
const config: IBaseClientConfig = {
baseUrl: 'https://your-ai-service.com',
fetchFunction: customFetch,
defaultStreamingHandler: new CustomStreamingHandler()
};
The streaming interface has been updated to standardize chunk handling across all AI clients. The afterChunk
callback now receives an IStreamChunk
object with standardized structure.
import { IStreamChunk } from '@redhat-cloud-services/ai-client-common';
interface IStreamChunk<T extends Record<string, unknown> = Record<string, unknown>> {
answer: string;
additionalAttributes: T;
}
import { IStreamingHandler, AfterChunkCallback, IStreamChunk } from '@redhat-cloud-services/ai-client-common';
class CustomStreamingHandler<TChunk = unknown> implements IStreamingHandler<TChunk> {
onChunk(chunk: TChunk, afterChunk?: AfterChunkCallback): void {
console.log('Received chunk:', chunk);
// Process the chunk and call afterChunk with standardized format
if (afterChunk) {
afterChunk({
answer: extractAnswer(chunk), // Extract answer from chunk
additionalAttributes: extractAttributes(chunk) // Extract additional data
});
}
}
onStart?(conversationId?: string, messageId?: string): void {
console.log('Stream started', { conversationId, messageId });
}
onComplete?(finalChunk: TChunk): void {
console.log('Stream completed:', finalChunk);
}
onError?(error: Error): void {
console.error('Stream error:', error);
}
onAbort?(): void {
console.log('Stream aborted');
}
}
import { ISendMessageOptions, IStreamChunk } from '@redhat-cloud-services/ai-client-common';
const streamingOptions: ISendMessageOptions = {
stream: true,
headers: { 'Custom-Header': 'value' },
signal: abortController.signal,
afterChunk: (chunk: IStreamChunk) => {
// Process each standardized chunk as it arrives
console.log('Answer:', chunk.answer);
console.log('Additional data:', chunk.additionalAttributes);
updateUI(chunk.answer);
}
};
import {
AIClientError,
AIClientValidationError
} from '@redhat-cloud-services/ai-client-common';
try {
const response = await client.sendMessage(conversationId, message);
} catch (error) {
if (error instanceof AIClientValidationError) {
console.error('Validation errors:', error.validationErrors);
error.validationErrors.forEach(validationError => {
console.log(`Field: ${validationError.loc.join('.')}`);
console.log(`Message: ${validationError.msg}`);
console.log(`Type: ${validationError.type}`);
});
} else if (error instanceof AIClientError) {
console.error(`API Error ${error.status}: ${error.message}`);
console.error('Response data:', error.data);
} else {
console.error('Unexpected error:', error);
}
}
import {
IRequestOptions,
IMessageResponse,
IConversationHistoryResponse,
IConversation
} from '@redhat-cloud-services/ai-client-common';
// Standard request options
const options: IRequestOptions = {
headers: { 'Custom-Header': 'value' },
signal: new AbortController().signal
};
// Message response structure
interface IMessageResponse<AP = Record<string, unknown>> {
messageId: string;
answer: string;
conversationId: string;
createdAt?: string;
additionalAttributes?: AP;
}
// Conversation structure
interface IConversation {
id: string;
title: string;
locked: boolean; // Prevents new messages when true
}
This package provides the foundation for:
Run nx build ai-client-common
to build the library.
Run nx test ai-client-common
to execute the unit tests via Jest.
This package follows the workspace standards:
any
typesFAQs
Common interfaces and utilities for AI client packages in the Red Hat Cloud Services ecosystem.
The npm package @redhat-cloud-services/ai-client-common receives a total of 172 weekly downloads. As such, @redhat-cloud-services/ai-client-common popularity was classified as not popular.
We found that @redhat-cloud-services/ai-client-common demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.
Application Security
/Research
/Security News
Socket detected multiple compromised CrowdStrike npm packages, continuing the "Shai-Hulud" supply chain attack that has now impacted nearly 500 packages.