定制 vinkius-labs/synapse-toon 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

Tests License Latest Version Total Downloads PHP 8.2+ 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 我们能提供哪些服务?
定制开发 / 二次开发

基于 vinkius-labs/synapse-toon 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 29
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2025-11-12