vinkius-labs/synapse-toon
Composer 安装命令:
composer require vinkius-labs/synapse-toon
包简介
Synapse TOON - high-performance API payload optimization and streaming toolkit for Laravel 11/12
README 文档
README
Synapse TOON
High-performance API payload optimization engine for Laravel
Synapse TOON transforms verbose JSON API responses into ultra-dense representations, reducing token consumption by 25–45% while preserving full semantic fidelity. Ship faster APIs and pay dramatically less for LLM inference.
Every runtime surface ships with an explicit SynapseToon prefix, making package ownership obvious in your codebase and eliminating class-name collisions.
Highlights
- Cost Savings First — Reduce LLM API bills by 25–45% through entropy-aware encoding, adaptive compression, and smart routing.
- Performance Native — HTTP/3 detection, Brotli/Gzip negotiation, and SSE streaming deliver sub-100 ms response times.
- Observable by Default — Log, Prometheus, and Datadog drivers expose savings metrics and ROI in real time.
- Production Ready — Queue-aware batch jobs, edge caching, and complexity-aware routing keep high-traffic APIs responsive.
- Framework Native — Middleware aliases, response macros, and Octane preloading for zero-friction Laravel integration.
- Zero Lock-in — Bring your own vector stores, LLM clients, and cache drivers via lightweight contracts.
Requirements
| Dependency | Version |
|---|---|
| PHP | 8.2+ |
| Laravel | 11.x | 12.x |
| ext-brotli | Optional (recommended) |
| ext-zlib | Optional |
Installation
composer require vinkius-labs/synapse-toon
Publish the configuration file:
php artisan vendor:publish --tag=synapse-toon-config
Register middleware in bootstrap/app.php:
->withMiddleware(function (Middleware $middleware) { $middleware->api(append: [ \VinkiusLabs\SynapseToon\Http\Middleware\SynapseToonCompressionMiddleware::class, \VinkiusLabs\SynapseToon\Http\Middleware\SynapseToonHttp3Middleware::class, ]); })
Quick Start
Encode a response
use VinkiusLabs\SynapseToon\Facades\SynapseToon; // Before: 1,247 tokens → After: 683 tokens (45% reduction) $encoded = SynapseToon::encoder()->encode([ 'products' => Product::with('category', 'reviews')->get(), 'meta' => ['page' => 1, 'per_page' => 50], ]); return response()->synapseToon($encoded);
Stream an LLM response
return response()->synapseToonStream($llmStream, function ($chunk) { return [ 'delta' => $chunk['choices'][0]['delta']['content'], 'usage' => $chunk['usage'] ?? null, ]; });
Route by complexity
$target = SynapseToon::router()->route($payload, [ 'complexity' => 0.4, 'tokens' => 512, ]);
Build RAG context
$context = SynapseToon::rag()->buildContext( 'How do I implement OAuth2 in Laravel?', ['user_id' => auth()->id()] );
Dispatch a batch job
use VinkiusLabs\SynapseToon\Jobs\SynapseToonProcessLLMBatchJob; SynapseToonProcessLLMBatchJob::dispatch($prompts, [ 'queue' => 'llm-batch', 'connection' => 'openai', 'batch_size' => 50, ]);
Architecture Overview
| Component | Purpose |
|---|---|
SynapseToonEncoder / SynapseToonDecoder |
Lossless TOON codec with dictionary support and entropy-aware heuristics |
SynapseToonCompressor |
Adaptive Brotli, Gzip, and Deflate selection based on Accept-Encoding |
SynapseToonSseStreamer |
Server-Sent Events with zero-copy chunking and buffer flush guardrails |
SynapseToonEdgeCache |
Encode-once edge cache helper tuned for Redis and Octane workloads |
SynapseToonMetrics |
Driver-agnostic metrics (Log, Prometheus, Datadog, or custom drivers) |
SynapseToonProcessLLMBatchJob |
Queue-friendly batch encoder for up to 100 prompts per dispatch |
SynapseToonLLMRouter |
Complexity-aware model router with pluggable LLM client implementations |
SynapseToonRagService |
Vector-store abstraction with snippet thresholds and metadata braiding |
SynapseToonGraphQLAdapter |
Lighthouse / Rebing GraphQL pipeline with TOON encoding built in |
SynapseToonPayloadAnalyzer |
Token analytics and savings calculator for middleware and dashboards |
Real-World Impact
| Scenario | Before | After | Savings |
|---|---|---|---|
| E-commerce feed (500 items) | 47,200 tokens | 26,100 tokens | 44.7% |
| Chat completion with context | 3,840 tokens | 2,310 tokens | 39.8% |
| GraphQL nested query | 2,156 tokens | 1,405 tokens | 34.8% |
| RAG context injection | 1,920 tokens | 1,152 tokens | 40.0% |
| Batch job (50 prompts) | 12,500 tokens | 7,000 tokens | 44.0% |
Average token reduction: 40.7%
Documentation
| Guide | Description |
|---|---|
| Getting Started | Installation, first response, and quick tips |
| Configuration | Full reference for every config option |
| Encoding & Compression | TOON algorithm deep-dive and compression strategies |
| Streaming & SSE | Server-Sent Events for real-time LLM responses |
| Metrics & Analytics | Prometheus, Datadog, and custom driver setup |
| RAG Integration | Vector-store abstraction and context building |
| Batch Processing | Queue-native batch encoding and fan-out |
| GraphQL Adapter | Lighthouse / Rebing integration |
| Edge Cache | Multi-tier caching strategies |
| HTTP/3 Optimization | HTTP/3 detection and header optimization |
| Cost Optimization | Maximize ROI with concrete strategies |
| Performance Tuning | Latency and throughput optimization |
| Technical Reference | Container bindings, macros, and full API |
Testing
Run the test suite locally via Docker:
docker compose build
docker compose run --rm app bash -c "composer install --no-interaction && vendor/bin/phpunit"
Or, if you have PHP 8.2+ installed locally:
composer install vendor/bin/phpunit
Compatibility
| Component | Support |
|---|---|
| Laravel | 11.x, 12.x |
| PHP | 8.2, 8.3 |
| Octane | Swoole, RoadRunner, FrankenPHP |
| HTTP/3 | Full detection and optimization |
| Brotli | Optional (ext-brotli) |
Contributing
Contributions are welcome! Please read our Contributing Guide before submitting a pull request.
Security
If you discover a security vulnerability, please review our Security Policy. Do not open a public issue.
Changelog
All notable changes are documented in the Changelog.
License
Copyright 2026 Vinkius Labs
Licensed under the Apache License, Version 2.0. See LICENSE for the full text.
vinkius-labs/synapse-toon 适用场景与选型建议
vinkius-labs/synapse-toon 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 11 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「compression」 「optimization」 「streaming」 「laravel」 「apis」 「llm」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 vinkius-labs/synapse-toon 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 vinkius-labs/synapse-toon 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 vinkius-labs/synapse-toon 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Asset Management for PHP
Image optimization / compression library. This library is able to optimize png, jpg and gif files in very easy and handy way. It uses optipng, pngquant, pngcrush, pngout, gifsicle, jpegoptim and jpegtran tools.
Image optimization widget for Yii2 Framework with auto WebP/AVIF image format generation from PNG/JPG files.
Optimize your email templates' styles via native Laravel templating mechanism.
A/B Testing of content elements
A laravel bundle for the OpenTok PHP SDK
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 29
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2025-11-12