{"id":36321666,"url":"https://github.com/iamgerwin/nova-ai-context-aware-input","last_synced_at":"2026-01-14T00:34:53.595Z","repository":{"id":331843489,"uuid":"1088987842","full_name":"iamgerwin/nova-ai-context-aware-input","owner":"iamgerwin","description":"AI-assisted Nova field that seamlessly improves text with context","archived":false,"fork":false,"pushed_at":"2025-11-03T19:22:29.000Z","size":581,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-11T15:19:03.120Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iamgerwin.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"John Gerwin De las Alas"}},"created_at":"2025-11-03T18:21:25.000Z","updated_at":"2025-11-03T19:22:31.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/iamgerwin/nova-ai-context-aware-input","commit_stats":null,"previous_names":["iamgerwin/nova-ai-context-aware-input"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/iamgerwin/nova-ai-context-aware-input","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamgerwin%2Fnova-ai-context-aware-input","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamgerwin%2Fnova-ai-context-aware-input/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamgerwin%2Fnova-ai-context-aware-input/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamgerwin%2Fnova-ai-context-aware-input/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iamgerwin","download_url":"https://codeload.github.com/iamgerwin/nova-ai-context-aware-input/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamgerwin%2Fnova-ai-context-aware-input/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28406515,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-11T11:48:18.530Z","updated_at":"2026-01-14T00:34:53.586Z","avatar_url":"https://github.com/iamgerwin.png","language":"PHP","readme":"# Nova AI Context-Aware Input\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/iamgerwin/nova-ai-context-aware-input.svg?style=flat-square)](https://packagist.org/packages/iamgerwin/nova-ai-context-aware-input)\n[![Total Downloads](https://img.shields.io/packagist/dt/iamgerwin/nova-ai-context-aware-input.svg?style=flat-square)](https://packagist.org/packages/iamgerwin/nova-ai-context-aware-input)\n[![License](https://img.shields.io/packagist/l/iamgerwin/nova-ai-context-aware-input.svg?style=flat-square)](https://packagist.org/packages/iamgerwin/nova-ai-context-aware-input)\n\nA Laravel Nova field that brings the power of AI to your admin panel, enhancing text input with intelligent, context-aware suggestions. Seamlessly integrates with Nova's workflow while providing real-time text improvements powered by leading AI providers.\n\nThink of it as having a professional editor looking over your shoulder, understanding the context of your entire form, and offering thoughtful improvements—without disrupting your natural writing flow.\n\n## Features\n\n### Core Capabilities\n- **Multiple AI Providers**: OpenAI, Anthropic Claude, DeepSeek, and Azure OpenAI support\n- **Context-Aware Intelligence**: Leverages form data, user information, and resource context for relevant suggestions\n- **Real-Time Suggestions**: Choose from blur, idle, or manual trigger modes\n- **Visual Diff Mode**: See exactly what changed with highlighted additions and deletions\n- **Suggestion History**: Navigate through previous AI suggestions with undo/redo support\n- **Flexible Styling**: Six built-in writing styles (professional, formal, friendly, succinct, marketing, technical)\n\n### Performance \u0026 Security\n- **Intelligent Caching**: Reduces API costs by caching similar improvements\n- **Rate Limiting**: Configurable per-user or global rate limits\n- **PII Detection**: Built-in detection to prevent sensitive data from being sent to AI providers\n- **Input Validation**: Maximum length enforcement and content filtering\n- **Fallback Support**: Automatic failover to backup providers\n\n### Developer Experience\n- **Zero Configuration**: Works out of the box with sensible defaults\n- **Highly Customizable**: Fine-tune every aspect through configuration or field methods\n- **Event System**: Hook into `TextImproved` and `SuggestionDiscarded` events\n- **Comprehensive Logging**: Track usage, errors, and performance metrics\n- **Type-Safe**: Full PHP 8.2+ type declarations\n\n## Requirements\n\n- PHP 8.2+ or 8.3+\n- Laravel 10.x, 11.x, or 12.x\n- Laravel Nova 4.x or 5.x\n- At least one AI provider API key (OpenAI, Anthropic, DeepSeek, or Azure OpenAI)\n\n## Installation\n\nInstall the package via Composer:\n\n```bash\ncomposer require iamgerwin/nova-ai-context-aware-input\n```\n\nPublish the configuration file:\n\n```bash\nphp artisan vendor:publish --tag=\"nova-ai-context-aware-input-config\"\n```\n\nBuild the Nova assets:\n\n```bash\ncd vendor/iamgerwin/nova-ai-context-aware-input\nnpm install \u0026\u0026 npm run build\n```\n\nOr if you prefer using the root directory:\n\n```bash\nphp artisan nova:publish\n```\n\n## Quick Start\n\n### 1. Configure Your AI Provider\n\nAdd your API key to your `.env` file:\n\n```env\n# Choose your preferred provider\nTEXT_IMPROVE_PROVIDER=openai:gpt-4o-mini\nOPENAI_API_KEY=sk-...\n\n# Or use Anthropic\nTEXT_IMPROVE_PROVIDER=anthropic:claude-3-5-sonnet-20241022\nANTHROPIC_API_KEY=sk-ant-...\n\n# Or DeepSeek\nTEXT_IMPROVE_PROVIDER=deepseek:deepseek-chat\nDEEPSEEK_API_KEY=sk-...\n\n# Or Azure OpenAI\nTEXT_IMPROVE_PROVIDER=azure_openai:gpt-4\nAZURE_OPENAI_API_KEY=...\nAZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com/\nAZURE_OPENAI_DEPLOYMENT_NAME=gpt-4\n```\n\n### 2. Use the Field in Your Nova Resource\n\nReplace the standard `Textarea` field with `TextImprove`:\n\n```php\nuse Iamgerwin\\NovaAiContextAwareInput\\Fields\\TextImprove;\n\npublic function fields(Request $request)\n{\n    return [\n        TextImprove::make('Description')\n            -\u003estyle('professional')\n            -\u003etrigger('blur'),\n    ];\n}\n```\n\nThat's it! Your field now has AI-powered text improvement capabilities.\n\n## Configuration\n\nThe package comes with extensive configuration options. Here are the key settings:\n\n### Default Provider\n\n```php\n// config/nova-ai-context-aware-input.php\n'provider' =\u003e env('TEXT_IMPROVE_PROVIDER', 'openai:gpt-4o-mini'),\n```\n\n### Field Defaults\n\n```php\n'min_length' =\u003e 12,           // Minimum characters before AI triggers\n'history_size' =\u003e 3,          // Number of suggestions to keep\n'trigger' =\u003e 'blur',          // blur|idle|manual\n'style' =\u003e 'professional',    // Default writing style\n'debounce_ms' =\u003e 600,        // Milliseconds to wait before processing\n```\n\n### Rate Limiting\n\n```php\n'rate_limit' =\u003e env('TEXT_IMPROVE_RATE_LIMIT', 'user:10,1'),\n```\n\nFormat: `scope:max_attempts,decay_minutes`\n- `user:10,1` - 10 attempts per user per minute\n- `global:100,60` - 100 attempts globally per hour\n\n### Caching\n\n```php\n'cache' =\u003e [\n    'enabled' =\u003e true,\n    'ttl' =\u003e 3600,              // Cache for 1 hour\n    'driver' =\u003e env('CACHE_DRIVER', 'file'),\n],\n```\n\n### Security\n\n```php\n'security' =\u003e [\n    'max_input_length' =\u003e 5000,\n    'enable_pii_detection' =\u003e true,\n    'pii_patterns' =\u003e [\n        // Email detection\n        '/\\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Z|a-z]{2,}\\b/',\n        // Phone numbers\n        '/\\b\\d{3}[-.]?\\d{3}[-.]?\\d{4}\\b/',\n        // Credit card numbers\n        '/\\b\\d{4}[\\s-]?\\d{4}[\\s-]?\\d{4}[\\s-]?\\d{4}\\b/',\n    ],\n],\n```\n\n## Usage Examples\n\n### Basic Usage\n\n```php\nuse Iamgerwin\\NovaAiContextAwareInput\\Fields\\TextImprove;\n\nTextImprove::make('Content')\n    -\u003estyle('professional')\n    -\u003etrigger('blur')\n    -\u003eminLength(20);\n```\n\n### Advanced Configuration\n\n```php\nTextImprove::make('Product Description')\n    -\u003eprovider('anthropic:claude-3-5-sonnet-20241022')\n    -\u003efallback('openai:gpt-4o-mini')\n    -\u003estyle('marketing')\n    -\u003etrigger('idle')\n    -\u003econtext(['title', 'category', 'price'])\n    -\u003eminLength(30)\n    -\u003emaxTokens(500)\n    -\u003ehistory(5)\n    -\u003erateLimit('user:20,1')\n    -\u003ediff(true);\n```\n\n### Custom Styling\n\n```php\nTextImprove::make('Blog Post')\n    -\u003estyle('technical')  // Built-in styles\n    -\u003etrigger('manual');  // Only improve when user clicks button\n```\n\nAvailable styles:\n- `professional` - Professional and clear business writing\n- `formal` - Formal and academic tone\n- `friendly` - Warm and approachable tone\n- `succinct` - Brief and to the point\n- `marketing` - Persuasive marketing copy\n- `technical` - Technical and precise language\n\n### Context-Aware Improvements\n\nLeverage contextual information for smarter suggestions:\n\n```php\nTextImprove::make('Email Body')\n    -\u003econtext(['subject', 'recipient_name', 'sender_role'])\n    -\u003estyle('professional');\n```\n\n## Available Providers\n\n### OpenAI\n\n```php\n'provider' =\u003e 'openai:gpt-4o-mini',\n// or\n'provider' =\u003e 'openai:gpt-4',\n'provider' =\u003e 'openai:gpt-4-turbo',\n```\n\nEnvironment variables:\n```env\nOPENAI_API_KEY=sk-...\n```\n\n### Anthropic Claude\n\n```php\n'provider' =\u003e 'anthropic:claude-3-5-sonnet-20241022',\n// or\n'provider' =\u003e 'anthropic:claude-3-opus-20240229',\n'provider' =\u003e 'anthropic:claude-3-haiku-20240307',\n```\n\nEnvironment variables:\n```env\nANTHROPIC_API_KEY=sk-ant-...\n```\n\n### DeepSeek\n\n```php\n'provider' =\u003e 'deepseek:deepseek-chat',\n```\n\nEnvironment variables:\n```env\nDEEPSEEK_API_KEY=sk-...\n```\n\n### Azure OpenAI\n\n```php\n'provider' =\u003e 'azure_openai:gpt-4',\n```\n\nEnvironment variables:\n```env\nAZURE_OPENAI_API_KEY=...\nAZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com/\nAZURE_OPENAI_DEPLOYMENT_NAME=gpt-4\n```\n\n## Context Providers\n\nContext providers enrich AI suggestions by providing relevant information about the form, user, and resource being edited.\n\n### Sibling Fields Provider\n\nIncludes data from other fields in the form:\n\n```php\nTextImprove::make('Description')\n    -\u003econtext(['title', 'category', 'tags']);\n```\n\nThis helps the AI understand the broader context. For example, when improving a product description, it knows the product's title and category.\n\n### User Persona Provider\n\nIncludes information about the authenticated user:\n\n```php\n// Automatically includes:\n// - User role\n// - Locale/language preference\n// - Timezone\n```\n\nHelps tailor suggestions to the user's context and language.\n\n### Resource Snapshot Provider\n\nProvides context about the resource being edited:\n\n```php\n// Automatically includes:\n// - Resource type (e.g., \"Article\", \"Product\")\n// - Resource ID\n// - Common fields (title, name, description, category, type, status)\n```\n\n### Policy Hints Provider\n\nEnforces content policies and guidelines:\n\n```php\n// config/nova-ai-context-aware-input.php\n'policy_hints' =\u003e [\n    'Avoid using profanity or offensive language.',\n    'Maintain professional tone and clarity.',\n    'Preserve factual accuracy of the original text.',\n],\n```\n\nYou can also add custom hints per field:\n\n```php\nuse Iamgerwin\\NovaAiContextAwareInput\\Context\\PolicyHintsProvider;\n\nTextImprove::make('Comment')\n    -\u003econtext([\n        (new PolicyHintsProvider())-\u003eaddHints([\n            'Be respectful and constructive.',\n            'Avoid personal attacks.',\n        ])\n    ]);\n```\n\n### Disabling Context Providers\n\n```php\n// config/nova-ai-context-aware-input.php\n'context_providers' =\u003e [\n    'sibling_fields' =\u003e true,\n    'user_persona' =\u003e false,      // Disable user context\n    'resource_snapshot' =\u003e true,\n    'policy_hints' =\u003e true,\n],\n```\n\n## Security Features\n\n### PII Detection\n\nThe package automatically detects and warns about potential PII (Personally Identifiable Information) before sending data to AI providers:\n\n- Email addresses\n- Phone numbers\n- Credit card numbers\n- Custom patterns (configurable)\n\nWhen PII is detected, the request is blocked and an error is returned.\n\n### Input Validation\n\n- Maximum input length enforcement (default: 5000 characters)\n- Content sanitization\n- API key validation\n\n### Rate Limiting\n\nPrevent abuse with configurable rate limits:\n\n```php\nTextImprove::make('Content')\n    -\u003erateLimit('user:10,1');  // 10 requests per user per minute\n```\n\n### Caching\n\nReduce costs and improve performance by caching improvements:\n\n```php\n// Cache key is based on: hash(input + context + style)\n// Same input with same context = cache hit\n```\n\n## Events\n\nThe package dispatches events you can listen to:\n\n### TextImproved Event\n\nFired when text is successfully improved:\n\n```php\nuse Iamgerwin\\NovaAiContextAwareInput\\Events\\TextImproved;\n\nclass LogTextImprovement\n{\n    public function handle(TextImproved $event): void\n    {\n        // $event-\u003eoriginalText\n        // $event-\u003eimprovedText\n        // $event-\u003eprovider\n        // $event-\u003estyle\n        // $event-\u003euser\n    }\n}\n```\n\n### SuggestionDiscarded Event\n\nFired when a user discards an AI suggestion:\n\n```php\nuse Iamgerwin\\NovaAiContextAwareInput\\Events\\SuggestionDiscarded;\n\nclass LogDiscardedSuggestion\n{\n    public function handle(SuggestionDiscarded $event): void\n    {\n        // $event-\u003eoriginalText\n        // $event-\u003esuggestedText\n        // $event-\u003euser\n    }\n}\n```\n\n## Customizing Prompts\n\nYou can customize the system and user prompts sent to AI providers:\n\n```php\n// config/nova-ai-context-aware-input.php\n'templates' =\u003e [\n    'system' =\u003e \u003c\u003c\u003c'TXT'\nYou are an expert editor improving business text for clarity and professionalism.\nYour task is to enhance the given text while:\n- Preserving all factual information\n- Respecting domain-specific terminology\n- Maintaining the original intent and meaning\n- Following the specified style guidelines\nReturn ONLY the improved text without explanations, quotes, or additional commentary.\nTXT,\n    'user' =\u003e \u003c\u003c\u003c'TXT'\nPlease improve the following text:\n\n{{ user_input }}\n\nContext: {{ context }}\nDesired Style: {{ style }}\nLanguage: {{ language }}\nTXT,\n],\n```\n\nAvailable placeholders:\n- `{{ user_input }}` - The text to improve\n- `{{ context }}` - Contextual information from providers\n- `{{ style }}` - The selected writing style\n- `{{ language }}` - User's language/locale\n\n## Testing\n\nRun the test suite:\n\n```bash\ncomposer test\n```\n\nRun tests with coverage:\n\n```bash\ncomposer test-coverage\n```\n\nRun static analysis:\n\n```bash\ncomposer analyse\n```\n\nFormat code (PSR-12):\n\n```bash\ncomposer format\n```\n\n## Performance Tips\n\n1. **Enable caching** to reduce API calls for similar content\n2. **Use rate limiting** to control costs\n3. **Choose appropriate models**: Smaller models (gpt-4o-mini, claude-3-haiku) for simple improvements, larger models for complex content\n4. **Set reasonable `minLength`** to avoid processing very short inputs\n5. **Use `trigger='manual'`** for fields where AI assistance is optional\n\n## Contributing\n\nWe welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.\n\n### Development Setup\n\n1. Clone the repository\n2. Install dependencies: `composer install \u0026\u0026 npm install`\n3. Copy `.env.example` to `.env` and add your API keys\n4. Run tests: `composer test`\n\n## Changelog\n\nPlease see [CHANGELOG.md](CHANGELOG.md) for recent changes.\n\n## Security\n\nIf you discover any security-related issues, please email iamgerwin@live.com instead of using the issue tracker.\n\n## License\n\nThe MIT License (MIT). Please see [LICENSE.md](LICENSE.md) for more information.\n\n## Credits\n\n- [Gerwin](https://github.com/iamgerwin) - Creator and maintainer\n- Built with [Laravel Nova](https://nova.laravel.com)\n- Powered by leading AI providers: [OpenAI](https://openai.com), [Anthropic](https://anthropic.com), [DeepSeek](https://deepseek.com)\n\n## Acknowledgments\n\nSpecial thanks to the Laravel and Nova communities for their excellent frameworks and tools that made this package possible.\n\n---\n\n**Made with care for the Laravel community.**\n","funding_links":["https://github.com/sponsors/John Gerwin De las Alas"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiamgerwin%2Fnova-ai-context-aware-input","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiamgerwin%2Fnova-ai-context-aware-input","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiamgerwin%2Fnova-ai-context-aware-input/lists"}