@stacksjs/ai 0.70.23 → 0.70.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  This package contains a set of tools to help you build AI-powered applications.
4
4
 
5
5
  1. Request model access from AWS: <https://us-east-1.console.aws.amazon.com/bedrock/home?region=us-east-1#/modelaccess>
6
+
6
7
  2.
7
8
 
8
9
  ## ☘️ Features
@@ -0,0 +1,29 @@
1
+ import type { AIDriver, StreamingResult } from '../../types';
2
+ /**
3
+ * Create a local Claude CLI agent
4
+ */
5
+ export declare function createClaudeLocalAgent(config?: ClaudeAgentConfig): AIDriver;
6
+ /**
7
+ * Create a remote Claude CLI agent (EC2)
8
+ */
9
+ export declare function createClaudeEC2Agent(config: ClaudeAgentConfig): AIDriver;
10
+ /**
11
+ * Process command with streaming output using Claude CLI
12
+ *
13
+ * Returns a ReadableStream that emits chunks of the response in real-time.
14
+ * Uses --output-format stream-json for detailed streaming with tool usage.
15
+ */
16
+ export declare function processCommandStreaming(command: string, cwd: string): Promise<StreamingResult>;
17
+ export declare function resetPromptCount(): void;
18
+ export declare const claudeAgent: {
19
+ createLocal: typeof createClaudeLocalAgent
20
+ createEC2: typeof createClaudeEC2Agent
21
+ processStreaming: typeof processCommandStreaming
22
+ resetPromptCount: typeof resetPromptCount
23
+ };
24
+ export declare interface ClaudeAgentConfig {
25
+ cwd?: string
26
+ ec2Host?: string
27
+ ec2User?: string
28
+ ec2Key?: string
29
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * AI Agents
3
+ *
4
+ * Export all available AI agents.
5
+ */
6
+ export * from './claude';
@@ -0,0 +1,67 @@
1
+ import type { AIDriver, AIMessage, BuddyApiKeys, BuddyConfig, BuddyState, GitHubCredentials, RepoState, StreamingResult } from './types';
2
+ /**
3
+ * Build system prompt for AI with repository context
4
+ */
5
+ export declare function buildSystemPrompt(context: string): string;
6
+ /**
7
+ * Get driver instance by name
8
+ */
9
+ export declare function getDriver(driverName: string): AIDriver;
10
+ /**
11
+ * Get list of available AI drivers
12
+ */
13
+ export declare function getAvailableDrivers(): string[];
14
+ /**
15
+ * Get repository structure for context
16
+ */
17
+ export declare function getRepoContext(repoPath: string): Promise<string>;
18
+ /**
19
+ * Clone or open a repository
20
+ */
21
+ export declare function openRepository(input: string): Promise<RepoState>;
22
+ /**
23
+ * Apply file changes from AI response
24
+ */
25
+ export declare function applyChanges(aiResponse: string): Promise<string[]>;
26
+ /**
27
+ * Configure git user for commits
28
+ */
29
+ export declare function configureGitUser(): Promise<void>;
30
+ /**
31
+ * Stage and commit changes
32
+ */
33
+ export declare function commitChanges(): Promise<string>;
34
+ /**
35
+ * Push changes to remote
36
+ */
37
+ export declare function pushChanges(): Promise<void>;
38
+ /**
39
+ * Process command with selected AI driver
40
+ */
41
+ export declare function processCommand(command: string, driverName?: string): Promise<string>;
42
+ /**
43
+ * Process command with streaming output using Claude CLI
44
+ */
45
+ export declare function buddyProcessStreaming(command: string, driverName?: string, history?: Array<{role: string; content: string}>): Promise<StreamingResult>;
46
+ /**
47
+ * Stream a simple Q&A response using the Anthropic API directly.
48
+ * This provides true token-by-token streaming like ChatGPT/Claude web.
49
+ * Use this for questions/explanations that don't require agentic tool use.
50
+ */
51
+ export declare function buddyStreamSimple(command: string, history?: Array<{ role: string; content: string }>): Promise<StreamingResult>;
52
+ // =============================================================================
53
+ // Configuration
54
+ // =============================================================================
55
+ export declare const CONFIG: BuddyConfig;
56
+ // API Keys state (can be set at runtime via settings endpoint)
57
+ export declare const apiKeys: BuddyApiKeys;
58
+ export declare const buddyState: BuddyStateManager;
59
+ // Buddy State Manager
60
+ export declare interface BuddyStateManager {
61
+ getState: () => BuddyState
62
+ setRepo: (repo: RepoState | null) => void
63
+ setCurrentDriver: (driver: string) => void
64
+ setGitHub: (github: GitHubCredentials | null) => void
65
+ addToHistory: (message: AIMessage) => void
66
+ clearHistory: () => void
67
+ }
@@ -0,0 +1,34 @@
1
+ import type { AIDriver, AIDriverConfig, AIMessage, AIResult, ChatCompletionOptions } from '../../types';
2
+ /**
3
+ * Configure Anthropic globally
4
+ */
5
+ export declare function configure(config: AnthropicDriverConfig): void;
6
+ export declare function createAnthropicDriver(config: AnthropicDriverConfig): AIDriver;
7
+ /**
8
+ * Chat completion with full options
9
+ */
10
+ export declare function chat(messages: AIMessage[], options?: ChatCompletionOptions & { system?: string }): Promise<AIResult>;
11
+ /**
12
+ * Stream chat completion
13
+ */
14
+ export declare function streamChat(messages: AIMessage[], options?: ChatCompletionOptions & { system?: string }): AsyncGenerator<string>;
15
+ /**
16
+ * Simple prompt helper
17
+ */
18
+ export declare function prompt(text: string, options?: ChatCompletionOptions & { system?: string }): Promise<string>;
19
+ /**
20
+ * Count tokens (approximate)
21
+ * Note: This is a rough estimate. For accurate counts, use the tokenizer.
22
+ */
23
+ export declare function estimateTokens(text: string): number;
24
+ export declare const anthropicDriver: { create: typeof createAnthropicDriver };
25
+ export declare const anthropic: {
26
+ createDriver: unknown
27
+ };
28
+ export declare interface AnthropicDriverConfig extends AIDriverConfig {
29
+ apiKey: string
30
+ model?: string
31
+ maxTokens?: number
32
+ anthropicVersion?: string
33
+ }
34
+ export default anthropic;
@@ -0,0 +1,36 @@
1
+ import type { AIDriver, AIDriverConfig, StreamingResult } from '../../types';
2
+ /**
3
+ * Create a Claude Agent SDK driver instance
4
+ */
5
+ export declare function createClaudeAgentSDKDriver(config?: ClaudeAgentSDKConfig): AIDriver;
6
+ /**
7
+ * Process a command with streaming and return a StreamingResult
8
+ */
9
+ export declare function processStreaming(command: string, cwd?: string, config?: Omit<ClaudeAgentSDKConfig, 'cwd'>): Promise<StreamingResult>;
10
+ /**
11
+ * Resume a previous SDK session
12
+ */
13
+ export declare function resumeSession(sessionId: string, prompt: string): Promise<string>;
14
+ /**
15
+ * Get the last session ID for potential resume
16
+ */
17
+ export declare function getLastSessionId(): string | undefined;
18
+ /**
19
+ * Clear the stored session ID
20
+ */
21
+ export declare function clearSession(): void;
22
+ // Export the driver creator and utilities
23
+ export declare const claudeAgentSDK: {
24
+ createDriver: unknown
25
+ };
26
+ export declare interface ClaudeAgentSDKConfig extends AIDriverConfig {
27
+ maxTurns?: number
28
+ cwd?: string
29
+ allowedTools?: string[]
30
+ disallowedTools?: string[]
31
+ permissionMode?: 'default' | 'acceptEdits' | 'bypassPermissions' | 'plan'
32
+ customSystemPrompt?: string
33
+ appendSystemPrompt?: string
34
+ resumeSessionId?: string
35
+ }
36
+ export default claudeAgentSDK;
@@ -0,0 +1,13 @@
1
+ export type { AnthropicDriverConfig } from './anthropic';
2
+ export type { OpenAIDriverConfig } from './openai';
3
+ export type { OllamaDriverConfig } from './ollama';
4
+ export type { ClaudeAgentSDKConfig } from './claude-agent-sdk';
5
+ /**
6
+ * AI Drivers
7
+ *
8
+ * Export all available AI drivers.
9
+ */
10
+ export { createAnthropicDriver, anthropicDriver, anthropic, estimateTokens } from './anthropic';
11
+ export { createOpenAIDriver, openaiDriver, openai } from './openai';
12
+ export { createOllamaDriver, ollamaDriver, ollama } from './ollama';
13
+ export { createClaudeAgentSDKDriver, claudeAgentSDK, getLastSessionId, clearSession } from './claude-agent-sdk';
@@ -0,0 +1,83 @@
1
+ import type { AIDriver, AIDriverConfig, AIMessage, AIResult, ChatCompletionOptions } from '../../types';
2
+ /**
3
+ * Configure Ollama globally
4
+ */
5
+ export declare function configure(config: OllamaDriverConfig): void;
6
+ export declare function createOllamaDriver(config?: OllamaDriverConfig): AIDriver;
7
+ /**
8
+ * Chat completion with full options
9
+ */
10
+ export declare function chat(messages: AIMessage[], options?: ChatCompletionOptions): Promise<AIResult>;
11
+ /**
12
+ * Stream chat completion
13
+ */
14
+ export declare function streamChat(messages: AIMessage[], options?: ChatCompletionOptions): AsyncGenerator<string>;
15
+ /**
16
+ * Generate text completion (non-chat)
17
+ */
18
+ export declare function generate(prompt: string, options?: {
19
+ model?: string
20
+ system?: string
21
+ template?: string
22
+ context?: number[]
23
+ raw?: boolean
24
+ format?: 'json'
25
+ images?: string[]
26
+ }): Promise<AIResult>;
27
+ /**
28
+ * Create embeddings
29
+ */
30
+ export declare function embed(input: string | string[], model?: string): Promise<number[] | number[][]>;
31
+ /**
32
+ * List available models
33
+ */
34
+ export declare function listModels(): Promise<Array<{
35
+ name: string
36
+ modified_at: string
37
+ size: number
38
+ digest: string
39
+ details: {
40
+ format: string
41
+ family: string
42
+ families: string[]
43
+ parameter_size: string
44
+ quantization_level: string
45
+ }
46
+ }>>;
47
+ /**
48
+ * Pull a model from the library
49
+ */
50
+ export declare function pullModel(name: string, onProgress?: (status: string, completed?: number, total?: number) => void): Promise<void>;
51
+ /**
52
+ * Delete a model
53
+ */
54
+ export declare function deleteModel(name: string): Promise<void>;
55
+ /**
56
+ * Show model information
57
+ */
58
+ export declare function showModel(_name: string): Promise<{
59
+ modelfile: string
60
+ parameters: string
61
+ template: string
62
+ details: {
63
+ format: string
64
+ family: string
65
+ families: string[]
66
+ parameter_size: string
67
+ quantization_level: string
68
+ }
69
+ }>;
70
+ /**
71
+ * Check if Ollama is running
72
+ */
73
+ export declare function isRunning(): Promise<boolean>;
74
+ export declare const ollamaDriver: { create: typeof createOllamaDriver };
75
+ export declare const ollama: {
76
+ createDriver: unknown
77
+ };
78
+ export declare interface OllamaDriverConfig extends AIDriverConfig {
79
+ host?: string
80
+ model?: string
81
+ embeddingModel?: string
82
+ }
83
+ export default ollama;
@@ -0,0 +1,59 @@
1
+ import type { AIDriver, AIDriverConfig, AIMessage, AIResult, ChatCompletionOptions } from '../../types';
2
+ /**
3
+ * Configure OpenAI globally
4
+ */
5
+ export declare function configure(config: OpenAIDriverConfig): void;
6
+ export declare function createOpenAIDriver(config: OpenAIDriverConfig): AIDriver;
7
+ /**
8
+ * Chat completion with full options
9
+ */
10
+ export declare function chat(messages: AIMessage[], options?: ChatCompletionOptions): Promise<AIResult>;
11
+ /**
12
+ * Stream chat completion
13
+ */
14
+ export declare function streamChat(messages: AIMessage[], options?: ChatCompletionOptions): AsyncGenerator<string>;
15
+ /**
16
+ * Create embeddings
17
+ */
18
+ export declare function embed(input: string | string[], model?: unknown): Promise<number[] | number[][]>;
19
+ /**
20
+ * Generate images using DALL-E
21
+ */
22
+ export declare function generateImage(prompt: string, options?: {
23
+ model?: 'dall-e-2' | 'dall-e-3'
24
+ size?: '256x256' | '512x512' | '1024x1024' | '1792x1024' | '1024x1792'
25
+ quality?: 'standard' | 'hd'
26
+ n?: number
27
+ responseFormat?: 'url' | 'b64_json'
28
+ }): Promise<{ url?: string, b64_json?: string }[]>;
29
+ /**
30
+ * Transcribe audio using Whisper
31
+ */
32
+ export declare function transcribe(audioFile: Blob | File, options?: {
33
+ model?: 'whisper-1'
34
+ language?: string
35
+ prompt?: string
36
+ responseFormat?: 'json' | 'text' | 'srt' | 'verbose_json' | 'vtt'
37
+ temperature?: number
38
+ }): Promise<{ text: string }>;
39
+ /**
40
+ * Text-to-speech using OpenAI TTS
41
+ */
42
+ export declare function textToSpeech(input: string, options?: {
43
+ model?: 'tts-1' | 'tts-1-hd'
44
+ voice?: 'alloy' | 'echo' | 'fable' | 'onyx' | 'nova' | 'shimmer'
45
+ responseFormat?: 'mp3' | 'opus' | 'aac' | 'flac' | 'wav' | 'pcm'
46
+ speed?: number
47
+ }): Promise<ArrayBuffer>;
48
+ export declare const openaiDriver: { create: typeof createOpenAIDriver };
49
+ export declare const openai: {
50
+ createDriver: unknown
51
+ };
52
+ export declare interface OpenAIDriverConfig extends AIDriverConfig {
53
+ apiKey: string
54
+ model?: string
55
+ maxTokens?: number
56
+ embeddingModel?: string
57
+ baseUrl?: string
58
+ }
59
+ export default openai;
@@ -0,0 +1,83 @@
1
+ import type { AIResult } from './types';
2
+ /**
3
+ * Generate images from a text prompt.
4
+ * Currently supports OpenAI DALL-E models.
5
+ */
6
+ export declare function generateImage(prompt: string, options?: ImageGenerationOptions): Promise<ImageGenerationResult>;
7
+ /**
8
+ * Edit an existing image with a text prompt (OpenAI DALL-E 2).
9
+ */
10
+ export declare function editImage(image: Blob | File, prompt: string, options?: ImageEditOptions): Promise<ImageGenerationResult>;
11
+ /**
12
+ * Create variations of an existing image (OpenAI DALL-E 2).
13
+ */
14
+ export declare function createImageVariation(image: Blob | File, options?: {
15
+ model?: 'dall-e-2'
16
+ n?: number
17
+ size?: '256x256' | '512x512' | '1024x1024'
18
+ responseFormat?: 'url' | 'b64_json'
19
+ }): Promise<ImageGenerationResult>;
20
+ /**
21
+ * Analyze an image using AI vision capabilities.
22
+ * Supports Anthropic Claude, OpenAI GPT-4V, and Ollama multimodal models.
23
+ */
24
+ export declare function analyzeImage(imageInput: ImageInput, prompt: string, options?: VisionOptions): Promise<VisionResult>;
25
+ /**
26
+ * Analyze multiple images together with a prompt.
27
+ * Useful for comparison, batch analysis, etc.
28
+ */
29
+ export declare function analyzeImages(images: ImageInput[], prompt: string, options?: VisionOptions): Promise<VisionResult>;
30
+ // ============================================================================
31
+ // Exports
32
+ // ============================================================================
33
+ export declare const image: {
34
+ generate: unknown;
35
+ edit: unknown;
36
+ variation: unknown;
37
+ analyze: unknown;
38
+ analyzeMultiple: unknown
39
+ };
40
+ // ============================================================================
41
+ // Types
42
+ // ============================================================================
43
+ export declare interface ImageGenerationOptions {
44
+ provider?: 'openai' | 'ollama'
45
+ model?: string
46
+ size?: '256x256' | '512x512' | '1024x1024' | '1792x1024' | '1024x1792'
47
+ quality?: 'standard' | 'hd'
48
+ n?: number
49
+ responseFormat?: 'url' | 'b64_json'
50
+ style?: 'vivid' | 'natural'
51
+ }
52
+ export declare interface ImageGenerationResult {
53
+ images: Array<{
54
+ url?: string
55
+ b64_json?: string
56
+ revisedPrompt?: string
57
+ }>
58
+ provider: string
59
+ model: string
60
+ }
61
+ export declare interface VisionOptions {
62
+ provider?: 'anthropic' | 'openai' | 'ollama'
63
+ model?: string
64
+ maxTokens?: number
65
+ temperature?: number
66
+ detail?: 'auto' | 'low' | 'high'
67
+ }
68
+ export declare interface VisionResult extends AIResult {
69
+ provider: string
70
+ }
71
+ // ============================================================================
72
+ // Image Editing
73
+ // ============================================================================
74
+ export declare interface ImageEditOptions {
75
+ mask?: Blob | File
76
+ model?: 'dall-e-2'
77
+ n?: number
78
+ size?: '256x256' | '512x512' | '1024x1024'
79
+ responseFormat?: 'url' | 'b64_json'
80
+ }
81
+ export type ImageInput = | { type: 'url'; url: string }
82
+ | { type: 'base64'; data: string; mediaType: string }
83
+ | { type: 'file'; path: string }
@@ -0,0 +1,22 @@
1
+ // Types
2
+ export * from './types';
3
+ // Drivers
4
+ export * from './drivers';
5
+ // Agents
6
+ export * from './agents';
7
+ // Buddy - Voice AI Code Assistant
8
+ export * from './buddy';
9
+ // Text utilities
10
+ export * from './text';
11
+ // Image generation & vision
12
+ export * from './image';
13
+ // Semantic search, embeddings & RAG
14
+ export * from './search';
15
+ // Personalization, sentiment & classification
16
+ export * from './personalization';
17
+ // Model Context Protocol (MCP) client
18
+ export * from './mcp';
19
+ // AWS Bedrock utilities
20
+ export * from './utils/client-bedrock';
21
+ export * from './utils/client-bedrock-runtime';
22
+ export * from './utils/model-access';