agentic-flow 2.0.2 → 2.0.4
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/.claude/agents/test-neural.md +14 -0
- package/.claude/settings.json +9 -133
- package/README.md +622 -1862
- package/dist/.tsbuildinfo +1 -1
- package/dist/billing/mcp/tools.js +0 -1
- package/dist/billing/mcp/tools.js.map +1 -1
- package/dist/cli/commands/hooks.d.ts.map +1 -1
- package/dist/cli/commands/hooks.js +4 -79
- package/dist/cli/commands/hooks.js.map +1 -1
- package/dist/cli-proxy.js +1 -89
- package/dist/cli-proxy.js.map +1 -1
- package/dist/core/agentdb-fast.js +3 -3
- package/dist/core/agentdb-fast.js.map +1 -1
- package/dist/core/agentdb-wrapper-enhanced.d.ts.map +1 -1
- package/dist/core/agentdb-wrapper-enhanced.js +4 -20
- package/dist/core/agentdb-wrapper-enhanced.js.map +1 -1
- package/dist/core/agentdb-wrapper.d.ts +2 -3
- package/dist/core/agentdb-wrapper.d.ts.map +1 -1
- package/dist/core/agentdb-wrapper.js +1 -15
- package/dist/core/agentdb-wrapper.js.map +1 -1
- package/dist/core/attention-native.d.ts +0 -4
- package/dist/core/attention-native.d.ts.map +1 -1
- package/dist/core/attention-native.js +2 -14
- package/dist/core/attention-native.js.map +1 -1
- package/dist/federation/SecurityManager.d.ts +2 -11
- package/dist/federation/SecurityManager.d.ts.map +1 -1
- package/dist/federation/SecurityManager.js +17 -50
- package/dist/federation/SecurityManager.js.map +1 -1
- package/dist/federation/integrations/supabase-adapter-debug.js +3 -3
- package/dist/federation/integrations/supabase-adapter-debug.js.map +1 -1
- package/dist/hooks/swarm-learning-optimizer.js +5 -5
- package/dist/hooks/swarm-learning-optimizer.js.map +1 -1
- package/dist/intelligence/IntelligenceStore.d.ts +26 -35
- package/dist/intelligence/IntelligenceStore.d.ts.map +1 -1
- package/dist/intelligence/IntelligenceStore.js +123 -308
- package/dist/intelligence/IntelligenceStore.js.map +1 -1
- package/dist/intelligence/RuVectorIntelligence.d.ts +1 -26
- package/dist/intelligence/RuVectorIntelligence.d.ts.map +1 -1
- package/dist/intelligence/RuVectorIntelligence.js +10 -49
- package/dist/intelligence/RuVectorIntelligence.js.map +1 -1
- package/dist/intelligence/agent-booster-enhanced.d.ts +0 -1
- package/dist/intelligence/agent-booster-enhanced.d.ts.map +1 -1
- package/dist/intelligence/agent-booster-enhanced.js +3 -24
- package/dist/intelligence/agent-booster-enhanced.js.map +1 -1
- package/dist/intelligence/index.d.ts +3 -29
- package/dist/intelligence/index.d.ts.map +1 -1
- package/dist/intelligence/index.js +3 -13
- package/dist/intelligence/index.js.map +1 -1
- package/dist/mcp/claudeFlowSdkServer.d.ts.map +1 -1
- package/dist/mcp/claudeFlowSdkServer.js +3 -9
- package/dist/mcp/claudeFlowSdkServer.js.map +1 -1
- package/dist/mcp/fastmcp/tools/hooks/intelligence-bridge.js +5 -5
- package/dist/mcp/fastmcp/tools/hooks/intelligence-bridge.js.map +1 -1
- package/dist/mcp/fastmcp/tools/swarm/init.d.ts.map +1 -1
- package/dist/mcp/fastmcp/tools/swarm/init.js +7 -36
- package/dist/mcp/fastmcp/tools/swarm/init.js.map +1 -1
- package/dist/mcp/fastmcp/tools/swarm/spawn.d.ts.map +1 -1
- package/dist/mcp/fastmcp/tools/swarm/spawn.js +8 -47
- package/dist/mcp/fastmcp/tools/swarm/spawn.js.map +1 -1
- package/dist/mcp/tools/agent-booster-tools.d.ts +1 -1
- package/dist/mcp/tools/agent-booster-tools.d.ts.map +1 -1
- package/dist/mcp/tools/agent-booster-tools.js +4 -10
- package/dist/mcp/tools/agent-booster-tools.js.map +1 -1
- package/dist/mcp/tools/sona-tools.d.ts.map +1 -1
- package/dist/mcp/tools/sona-tools.js +0 -6
- package/dist/mcp/tools/sona-tools.js.map +1 -1
- package/dist/optimizations/agent-booster-migration.d.ts.map +1 -1
- package/dist/optimizations/agent-booster-migration.js +2 -5
- package/dist/optimizations/agent-booster-migration.js.map +1 -1
- package/dist/proxy/anthropic-to-openrouter.js.map +1 -1
- package/dist/proxy/anthropic-to-requesty.js.map +1 -1
- package/dist/proxy/quic-proxy.d.ts +1 -0
- package/dist/proxy/quic-proxy.d.ts.map +1 -1
- package/dist/proxy/quic-proxy.js +2 -2
- package/dist/proxy/quic-proxy.js.map +1 -1
- package/dist/reasoningbank/AdvancedMemory.js +1 -1
- package/dist/reasoningbank/AdvancedMemory.js.map +1 -1
- package/dist/reasoningbank/HybridBackend.d.ts.map +1 -1
- package/dist/reasoningbank/HybridBackend.js +5 -2
- package/dist/reasoningbank/HybridBackend.js.map +1 -1
- package/dist/reasoningbank/backend-selector.d.ts +1 -11
- package/dist/reasoningbank/backend-selector.d.ts.map +1 -1
- package/dist/reasoningbank/backend-selector.js +5 -45
- package/dist/reasoningbank/backend-selector.js.map +1 -1
- package/dist/reasoningbank/core/consolidate.d.ts.map +1 -1
- package/dist/reasoningbank/core/consolidate.js +45 -113
- package/dist/reasoningbank/core/consolidate.js.map +1 -1
- package/dist/reasoningbank/index-new.d.ts +6 -1
- package/dist/reasoningbank/index-new.d.ts.map +1 -1
- package/dist/reasoningbank/index-new.js +6 -1
- package/dist/reasoningbank/index-new.js.map +1 -1
- package/dist/reasoningbank/index.d.ts +6 -2
- package/dist/reasoningbank/index.d.ts.map +1 -1
- package/dist/reasoningbank/index.js +6 -2
- package/dist/reasoningbank/index.js.map +1 -1
- package/dist/reasoningbank/utils/embeddings.d.ts +0 -1
- package/dist/reasoningbank/utils/embeddings.d.ts.map +1 -1
- package/dist/reasoningbank/utils/embeddings.js +26 -53
- package/dist/reasoningbank/utils/embeddings.js.map +1 -1
- package/dist/router/index.d.ts +17 -0
- package/dist/router/index.d.ts.map +1 -0
- package/dist/router/index.js +19 -0
- package/dist/router/index.js.map +1 -0
- package/dist/router/providers/onnx-local-optimized.d.ts +0 -2
- package/dist/router/providers/onnx-local-optimized.d.ts.map +1 -1
- package/dist/router/providers/onnx-local-optimized.js +0 -10
- package/dist/router/providers/onnx-local-optimized.js.map +1 -1
- package/dist/router/providers/onnx-local.d.ts +0 -1
- package/dist/router/providers/onnx-local.d.ts.map +1 -1
- package/dist/router/providers/onnx-local.js +5 -22
- package/dist/router/providers/onnx-local.js.map +1 -1
- package/dist/services/embedding-service.js.map +1 -1
- package/dist/services/sona-agent-training.d.ts +0 -1
- package/dist/services/sona-agent-training.d.ts.map +1 -1
- package/dist/services/sona-agent-training.js.map +1 -1
- package/dist/services/sona-agentdb-integration.d.ts.map +1 -1
- package/dist/services/sona-agentdb-integration.js +6 -9
- package/dist/services/sona-agentdb-integration.js.map +1 -1
- package/dist/services/sona-service.d.ts.map +1 -1
- package/dist/services/sona-service.js +5 -6
- package/dist/services/sona-service.js.map +1 -1
- package/dist/utils/cli.d.ts +1 -1
- package/dist/utils/cli.d.ts.map +1 -1
- package/dist/utils/cli.js +0 -21
- package/dist/utils/cli.js.map +1 -1
- package/package.json +7 -19
- package/scripts/postinstall.js +4 -45
- package/wasm/reasoningbank/reasoningbank_wasm_bg.js +2 -2
- package/wasm/reasoningbank/reasoningbank_wasm_bg.wasm +0 -0
- package/.claude/agents/.claude-flow/metrics/agent-metrics.json +0 -1
- package/.claude/agents/.claude-flow/metrics/performance.json +0 -87
- package/.claude/agents/.claude-flow/metrics/task-metrics.json +0 -10
- package/.claude/skills/.claude-flow/metrics/agent-metrics.json +0 -1
- package/.claude/skills/.claude-flow/metrics/performance.json +0 -87
- package/.claude/skills/.claude-flow/metrics/task-metrics.json +0 -10
- package/.claude/skills/agentic-flow-quickstart/skill.md +0 -69
- package/.claude/skills/hooks-automation/skill.md +0 -155
- package/.claude/skills/memory-patterns/skill.md +0 -110
- package/.claude/skills/skill-builder/.claude-flow/metrics/agent-metrics.json +0 -1
- package/.claude/skills/skill-builder/.claude-flow/metrics/performance.json +0 -87
- package/.claude/skills/skill-builder/.claude-flow/metrics/task-metrics.json +0 -10
- package/.claude/skills/sparc-methodology/skill.md +0 -137
- package/.claude/skills/swarm-coordination/skill.md +0 -94
- package/.claude/skills/worker-benchmarks/skill.md +0 -135
- package/.claude/skills/worker-integration/skill.md +0 -154
- package/.claude/statusline.mjs +0 -109
- package/.claude/statusline.sh +0 -71
- package/dist/agentdb/benchmarks/comprehensive-benchmark.js +0 -664
- package/dist/agentdb/benchmarks/frontier-benchmark.js +0 -419
- package/dist/agentdb/benchmarks/reflexion-benchmark.js +0 -370
- package/dist/agentdb/cli/agentdb-cli.js +0 -717
- package/dist/agentdb/controllers/CausalMemoryGraph.js +0 -322
- package/dist/agentdb/controllers/CausalRecall.js +0 -281
- package/dist/agentdb/controllers/EmbeddingService.d.ts +0 -37
- package/dist/agentdb/controllers/EmbeddingService.d.ts.map +0 -1
- package/dist/agentdb/controllers/EmbeddingService.js +0 -119
- package/dist/agentdb/controllers/EmbeddingService.js.map +0 -1
- package/dist/agentdb/controllers/ExplainableRecall.js +0 -387
- package/dist/agentdb/controllers/NightlyLearner.js +0 -382
- package/dist/agentdb/controllers/ReflexionMemory.js +0 -239
- package/dist/agentdb/controllers/SkillLibrary.js +0 -276
- package/dist/agentdb/controllers/frontier-index.js +0 -9
- package/dist/agentdb/controllers/index.js +0 -8
- package/dist/agentdb/optimizations/BatchOperations.js +0 -198
- package/dist/agentdb/optimizations/QueryOptimizer.js +0 -225
- package/dist/agentdb/optimizations/index.js +0 -7
- package/dist/agentdb/tests/frontier-features.test.js +0 -665
- package/dist/benchmarks/embeddings-benchmark.d.ts +0 -38
- package/dist/benchmarks/embeddings-benchmark.d.ts.map +0 -1
- package/dist/benchmarks/embeddings-benchmark.js +0 -282
- package/dist/benchmarks/embeddings-benchmark.js.map +0 -1
- package/dist/cli/commands/embeddings.d.ts +0 -12
- package/dist/cli/commands/embeddings.d.ts.map +0 -1
- package/dist/cli/commands/embeddings.js +0 -386
- package/dist/cli/commands/embeddings.js.map +0 -1
- package/dist/cli/commands/init.d.ts +0 -8
- package/dist/cli/commands/init.d.ts.map +0 -1
- package/dist/cli/commands/init.js +0 -514
- package/dist/cli/commands/init.js.map +0 -1
- package/dist/cli/commands/workers.d.ts +0 -9
- package/dist/cli/commands/workers.d.ts.map +0 -1
- package/dist/cli/commands/workers.js +0 -991
- package/dist/cli/commands/workers.js.map +0 -1
- package/dist/cli/skills-manager.js +0 -1297
- package/dist/cli/update-message.js +0 -175
- package/dist/embeddings/index.d.ts +0 -17
- package/dist/embeddings/index.d.ts.map +0 -1
- package/dist/embeddings/index.js +0 -17
- package/dist/embeddings/index.js.map +0 -1
- package/dist/embeddings/neural-substrate.d.ts +0 -206
- package/dist/embeddings/neural-substrate.d.ts.map +0 -1
- package/dist/embeddings/neural-substrate.js +0 -629
- package/dist/embeddings/neural-substrate.js.map +0 -1
- package/dist/embeddings/optimized-embedder.d.ts +0 -103
- package/dist/embeddings/optimized-embedder.d.ts.map +0 -1
- package/dist/embeddings/optimized-embedder.js +0 -730
- package/dist/embeddings/optimized-embedder.js.map +0 -1
- package/dist/examples/embedding-geometry.d.ts +0 -105
- package/dist/examples/embedding-geometry.d.ts.map +0 -1
- package/dist/examples/embedding-geometry.js +0 -528
- package/dist/examples/embedding-geometry.js.map +0 -1
- package/dist/memory/SharedMemoryPool.d.ts +0 -129
- package/dist/memory/SharedMemoryPool.d.ts.map +0 -1
- package/dist/memory/SharedMemoryPool.js +0 -243
- package/dist/memory/SharedMemoryPool.js.map +0 -1
- package/dist/memory/index.d.ts +0 -8
- package/dist/memory/index.d.ts.map +0 -1
- package/dist/memory/index.js +0 -7
- package/dist/memory/index.js.map +0 -1
- package/dist/proxy/http3-proxy-old.js +0 -331
- package/dist/proxy/proxy/anthropic-to-gemini.js +0 -439
- package/dist/proxy/utils/logger.js +0 -59
- package/dist/reasoningbank/agentdb-adapter.js +0 -125
- package/dist/reasoningbank/core/database.js +0 -250
- package/dist/reasoningbank/core/memory-engine.js +0 -335
- package/dist/swarm/ipfs-swarm.d.ts +0 -265
- package/dist/swarm/ipfs-swarm.d.ts.map +0 -1
- package/dist/swarm/ipfs-swarm.js +0 -508
- package/dist/swarm/ipfs-swarm.js.map +0 -1
- package/dist/swarm/p2p-free-swarm.d.ts +0 -344
- package/dist/swarm/p2p-free-swarm.d.ts.map +0 -1
- package/dist/swarm/p2p-free-swarm.js +0 -603
- package/dist/swarm/p2p-free-swarm.js.map +0 -1
- package/dist/swarm/real-p2p-swarm.d.ts +0 -183
- package/dist/swarm/real-p2p-swarm.d.ts.map +0 -1
- package/dist/swarm/real-p2p-swarm.js +0 -469
- package/dist/swarm/real-p2p-swarm.js.map +0 -1
- package/dist/utils/adaptive-pool-sizing.js +0 -414
- package/dist/utils/agentdbCommands.js +0 -175
- package/dist/utils/circular-rate-limiter.js +0 -391
- package/dist/utils/dynamic-compression.js +0 -298
- package/dist/utils/http2-multiplexing.js +0 -319
- package/dist/utils/index.d.ts +0 -6
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js +0 -6
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/lazy-auth.js +0 -311
- package/dist/utils/model-cache.d.ts +0 -61
- package/dist/utils/model-cache.d.ts.map +0 -1
- package/dist/utils/model-cache.js +0 -176
- package/dist/utils/model-cache.js.map +0 -1
- package/dist/utils/server-push.js +0 -251
- package/dist/utils/suppress-warnings.d.ts +0 -19
- package/dist/utils/suppress-warnings.d.ts.map +0 -1
- package/dist/utils/suppress-warnings.js +0 -59
- package/dist/utils/suppress-warnings.js.map +0 -1
- package/dist/utils/zero-copy-buffer.js +0 -286
- package/dist/workers/consolidated-phases.d.ts +0 -40
- package/dist/workers/consolidated-phases.d.ts.map +0 -1
- package/dist/workers/consolidated-phases.js +0 -497
- package/dist/workers/consolidated-phases.js.map +0 -1
- package/dist/workers/custom-worker-config.d.ts +0 -133
- package/dist/workers/custom-worker-config.d.ts.map +0 -1
- package/dist/workers/custom-worker-config.js +0 -215
- package/dist/workers/custom-worker-config.js.map +0 -1
- package/dist/workers/custom-worker-factory.d.ts +0 -89
- package/dist/workers/custom-worker-factory.d.ts.map +0 -1
- package/dist/workers/custom-worker-factory.js +0 -404
- package/dist/workers/custom-worker-factory.js.map +0 -1
- package/dist/workers/dispatch-service.d.ts +0 -123
- package/dist/workers/dispatch-service.d.ts.map +0 -1
- package/dist/workers/dispatch-service.js +0 -1024
- package/dist/workers/dispatch-service.js.map +0 -1
- package/dist/workers/hooks-integration.d.ts +0 -79
- package/dist/workers/hooks-integration.d.ts.map +0 -1
- package/dist/workers/hooks-integration.js +0 -286
- package/dist/workers/hooks-integration.js.map +0 -1
- package/dist/workers/index.d.ts +0 -42
- package/dist/workers/index.d.ts.map +0 -1
- package/dist/workers/index.js +0 -52
- package/dist/workers/index.js.map +0 -1
- package/dist/workers/mcp-tools.d.ts +0 -56
- package/dist/workers/mcp-tools.d.ts.map +0 -1
- package/dist/workers/mcp-tools.js +0 -359
- package/dist/workers/mcp-tools.js.map +0 -1
- package/dist/workers/phase-executors.d.ts +0 -22
- package/dist/workers/phase-executors.d.ts.map +0 -1
- package/dist/workers/phase-executors.js +0 -445
- package/dist/workers/phase-executors.js.map +0 -1
- package/dist/workers/resource-governor.d.ts +0 -75
- package/dist/workers/resource-governor.d.ts.map +0 -1
- package/dist/workers/resource-governor.js +0 -187
- package/dist/workers/resource-governor.js.map +0 -1
- package/dist/workers/ruvector-integration.d.ts +0 -163
- package/dist/workers/ruvector-integration.d.ts.map +0 -1
- package/dist/workers/ruvector-integration.js +0 -543
- package/dist/workers/ruvector-integration.js.map +0 -1
- package/dist/workers/ruvector-native-integration.d.ts +0 -91
- package/dist/workers/ruvector-native-integration.d.ts.map +0 -1
- package/dist/workers/ruvector-native-integration.js +0 -254
- package/dist/workers/ruvector-native-integration.js.map +0 -1
- package/dist/workers/trigger-detector.d.ts +0 -68
- package/dist/workers/trigger-detector.d.ts.map +0 -1
- package/dist/workers/trigger-detector.js +0 -281
- package/dist/workers/trigger-detector.js.map +0 -1
- package/dist/workers/types.d.ts +0 -145
- package/dist/workers/types.d.ts.map +0 -1
- package/dist/workers/types.js +0 -6
- package/dist/workers/types.js.map +0 -1
- package/dist/workers/worker-agent-integration.d.ts +0 -140
- package/dist/workers/worker-agent-integration.d.ts.map +0 -1
- package/dist/workers/worker-agent-integration.js +0 -471
- package/dist/workers/worker-agent-integration.js.map +0 -1
- package/dist/workers/worker-benchmarks.d.ts +0 -88
- package/dist/workers/worker-benchmarks.d.ts.map +0 -1
- package/dist/workers/worker-benchmarks.js +0 -452
- package/dist/workers/worker-benchmarks.js.map +0 -1
- package/dist/workers/worker-registry.d.ts +0 -85
- package/dist/workers/worker-registry.d.ts.map +0 -1
- package/dist/workers/worker-registry.js +0 -547
- package/dist/workers/worker-registry.js.map +0 -1
- package/docs/.claude-flow/metrics/agent-metrics.json +0 -1
- package/docs/.claude-flow/metrics/performance.json +0 -87
- package/docs/.claude-flow/metrics/task-metrics.json +0 -10
- package/docs/embeddings/EMBEDDING_GEOMETRY.md +0 -935
- /package/.claude/agents/analysis/{analyze-code-quality.md → code-review/analyze-code-quality.md} +0 -0
- /package/.claude/agents/architecture/{arch-system-design.md → system-design/arch-system-design.md} +0 -0
- /package/.claude/agents/data/{data-ml-model.md → ml/data-ml-model.md} +0 -0
- /package/.claude/agents/development/{dev-backend-api.md → backend/dev-backend-api.md} +0 -0
- /package/.claude/agents/devops/{ops-cicd-github.md → ci-cd/ops-cicd-github.md} +0 -0
- /package/.claude/agents/documentation/{docs-api-openapi.md → api-docs/docs-api-openapi.md} +0 -0
- /package/.claude/agents/specialized/{spec-mobile-react-native.md → mobile/spec-mobile-react-native.md} +0 -0
- /package/.claude/agents/testing/{tdd-london-swarm.md → unit/tdd-london-swarm.md} +0 -0
- /package/.claude/agents/testing/{production-validator.md → validation/production-validator.md} +0 -0
|
@@ -1,331 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HTTP/3 (QUIC) Proxy for LLM Streaming
|
|
3
|
-
*
|
|
4
|
-
* Features:
|
|
5
|
-
* - Zero RTT: Faster connection establishment (50-70% faster than HTTP/2)
|
|
6
|
-
* - No head-of-line blocking: Independent streams
|
|
7
|
-
* - Better mobile: Handles network switches gracefully
|
|
8
|
-
* - Built-in encryption: TLS 1.3 mandatory
|
|
9
|
-
* - Leverages existing QUIC transport implementation
|
|
10
|
-
*
|
|
11
|
-
* Performance: 50-70% faster than HTTP/2, 70-80% faster than HTTP/1.1
|
|
12
|
-
*/
|
|
13
|
-
import { QuicTransport } from '../transport/quic.js';
|
|
14
|
-
import { logger } from '../utils/logger.js';
|
|
15
|
-
export class HTTP3Proxy {
|
|
16
|
-
transport;
|
|
17
|
-
config;
|
|
18
|
-
isRunning = false;
|
|
19
|
-
constructor(config) {
|
|
20
|
-
this.config = config;
|
|
21
|
-
this.transport = new QuicTransport({
|
|
22
|
-
host: 'localhost',
|
|
23
|
-
port: config.port,
|
|
24
|
-
cert: config.cert,
|
|
25
|
-
key: config.key,
|
|
26
|
-
alpn: ['h3'], // HTTP/3 ALPN identifier
|
|
27
|
-
maxConcurrentStreams: config.maxConcurrentStreams || 100
|
|
28
|
-
});
|
|
29
|
-
logger.info('HTTP/3 proxy created', {
|
|
30
|
-
port: config.port,
|
|
31
|
-
maxStreams: config.maxConcurrentStreams
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
async start() {
|
|
35
|
-
try {
|
|
36
|
-
await this.transport.listen();
|
|
37
|
-
this.isRunning = true;
|
|
38
|
-
// Handle incoming QUIC streams
|
|
39
|
-
this.transport.on('stream', async (stream) => {
|
|
40
|
-
try {
|
|
41
|
-
const headers = await this.readHeaders(stream);
|
|
42
|
-
const path = headers[':path'];
|
|
43
|
-
const method = headers[':method'];
|
|
44
|
-
logger.debug('HTTP/3 stream request', { path, method });
|
|
45
|
-
if (path === '/v1/messages' && method === 'POST') {
|
|
46
|
-
await this.handleMessagesRequest(stream, headers);
|
|
47
|
-
}
|
|
48
|
-
else if (path === '/health') {
|
|
49
|
-
await this.handleHealthCheck(stream);
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
await this.sendErrorResponse(stream, 404, 'Not Found');
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
catch (error) {
|
|
56
|
-
logger.error('HTTP/3 stream error', { error: error.message });
|
|
57
|
-
await this.sendErrorResponse(stream, 500, error.message);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
this.transport.on('error', (error) => {
|
|
61
|
-
logger.error('HTTP/3 transport error', { error: error.message });
|
|
62
|
-
});
|
|
63
|
-
logger.info('HTTP/3 proxy started', {
|
|
64
|
-
port: this.config.port,
|
|
65
|
-
protocol: 'HTTP/3 (QUIC)',
|
|
66
|
-
url: `https://localhost:${this.config.port}`
|
|
67
|
-
});
|
|
68
|
-
console.log(`\n✅ HTTP/3 (QUIC) Proxy running at https://localhost:${this.config.port}`);
|
|
69
|
-
console.log(` Protocol: HTTP/3 over QUIC (50-70% faster than HTTP/2)`);
|
|
70
|
-
console.log(` Features: Zero RTT, No HOL blocking, Mobile-optimized\n`);
|
|
71
|
-
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
logger.error('Failed to start HTTP/3 proxy', { error: error.message });
|
|
74
|
-
throw error;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
async readHeaders(stream) {
|
|
78
|
-
// Read HTTP/3 headers from QUIC stream
|
|
79
|
-
// This is a simplified implementation - real HTTP/3 uses QPACK compression
|
|
80
|
-
const headerData = await stream.read();
|
|
81
|
-
if (!headerData) {
|
|
82
|
-
return {};
|
|
83
|
-
}
|
|
84
|
-
try {
|
|
85
|
-
// For simplicity, assume JSON-encoded headers
|
|
86
|
-
// Real HTTP/3 would use QPACK binary format
|
|
87
|
-
return JSON.parse(headerData.toString());
|
|
88
|
-
}
|
|
89
|
-
catch {
|
|
90
|
-
// Fallback: parse basic HTTP-style headers
|
|
91
|
-
const lines = headerData.toString().split('\r\n');
|
|
92
|
-
const headers = {};
|
|
93
|
-
for (const line of lines) {
|
|
94
|
-
const [key, ...valueParts] = line.split(': ');
|
|
95
|
-
if (key && valueParts.length > 0) {
|
|
96
|
-
headers[key.toLowerCase()] = valueParts.join(': ');
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return headers;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
async handleHealthCheck(stream) {
|
|
103
|
-
await stream.writeHeaders({
|
|
104
|
-
':status': '200',
|
|
105
|
-
'content-type': 'application/json'
|
|
106
|
-
});
|
|
107
|
-
await stream.write(JSON.stringify({
|
|
108
|
-
status: 'ok',
|
|
109
|
-
service: 'http3-proxy',
|
|
110
|
-
protocol: 'HTTP/3',
|
|
111
|
-
transport: 'QUIC'
|
|
112
|
-
}));
|
|
113
|
-
await stream.end();
|
|
114
|
-
}
|
|
115
|
-
async handleMessagesRequest(stream, headers) {
|
|
116
|
-
try {
|
|
117
|
-
// Read request body from QUIC stream
|
|
118
|
-
const bodyData = await stream.read();
|
|
119
|
-
const anthropicReq = JSON.parse(bodyData.toString());
|
|
120
|
-
logger.info('HTTP/3 messages request', {
|
|
121
|
-
model: anthropicReq.model,
|
|
122
|
-
stream: anthropicReq.stream,
|
|
123
|
-
messageCount: anthropicReq.messages?.length
|
|
124
|
-
});
|
|
125
|
-
// Convert Anthropic format to Gemini format
|
|
126
|
-
const geminiReq = this.convertAnthropicToGemini(anthropicReq);
|
|
127
|
-
// Determine endpoint
|
|
128
|
-
const endpoint = anthropicReq.stream ? 'streamGenerateContent' : 'generateContent';
|
|
129
|
-
const streamParam = anthropicReq.stream ? '&alt=sse' : '';
|
|
130
|
-
const geminiBaseUrl = this.config.geminiBaseUrl || 'https://generativelanguage.googleapis.com/v1beta';
|
|
131
|
-
const url = `${geminiBaseUrl}/models/gemini-2.0-flash-exp:${endpoint}?key=${this.config.geminiApiKey}${streamParam}`;
|
|
132
|
-
// Forward to Gemini
|
|
133
|
-
const response = await fetch(url, {
|
|
134
|
-
method: 'POST',
|
|
135
|
-
headers: { 'Content-Type': 'application/json' },
|
|
136
|
-
body: JSON.stringify(geminiReq)
|
|
137
|
-
});
|
|
138
|
-
if (!response.ok) {
|
|
139
|
-
const error = await response.text();
|
|
140
|
-
logger.error('Gemini API error', { status: response.status, error });
|
|
141
|
-
await this.sendErrorResponse(stream, response.status, error);
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
// Handle streaming vs non-streaming
|
|
145
|
-
if (anthropicReq.stream) {
|
|
146
|
-
// Stream response over QUIC
|
|
147
|
-
await stream.writeHeaders({
|
|
148
|
-
':status': '200',
|
|
149
|
-
'content-type': 'text/event-stream',
|
|
150
|
-
'cache-control': 'no-cache'
|
|
151
|
-
});
|
|
152
|
-
const reader = response.body?.getReader();
|
|
153
|
-
if (!reader) {
|
|
154
|
-
throw new Error('No response body');
|
|
155
|
-
}
|
|
156
|
-
const decoder = new TextDecoder();
|
|
157
|
-
let chunkCount = 0;
|
|
158
|
-
while (true) {
|
|
159
|
-
const { done, value } = await reader.read();
|
|
160
|
-
if (done)
|
|
161
|
-
break;
|
|
162
|
-
const chunk = decoder.decode(value);
|
|
163
|
-
chunkCount++;
|
|
164
|
-
const anthropicChunk = this.convertGeminiStreamToAnthropic(chunk);
|
|
165
|
-
await stream.write(anthropicChunk);
|
|
166
|
-
}
|
|
167
|
-
logger.info('HTTP/3 stream complete', { totalChunks: chunkCount });
|
|
168
|
-
await stream.end();
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
// Non-streaming response
|
|
172
|
-
const geminiRes = await response.json();
|
|
173
|
-
const anthropicRes = this.convertGeminiToAnthropic(geminiRes);
|
|
174
|
-
await stream.writeHeaders({
|
|
175
|
-
':status': '200',
|
|
176
|
-
'content-type': 'application/json'
|
|
177
|
-
});
|
|
178
|
-
await stream.write(JSON.stringify(anthropicRes));
|
|
179
|
-
await stream.end();
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
catch (error) {
|
|
183
|
-
logger.error('HTTP/3 request error', { error: error.message });
|
|
184
|
-
await this.sendErrorResponse(stream, 500, error.message);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
async sendErrorResponse(stream, status, message) {
|
|
188
|
-
try {
|
|
189
|
-
await stream.writeHeaders({
|
|
190
|
-
':status': status.toString(),
|
|
191
|
-
'content-type': 'application/json'
|
|
192
|
-
});
|
|
193
|
-
await stream.write(JSON.stringify({
|
|
194
|
-
error: {
|
|
195
|
-
type: 'proxy_error',
|
|
196
|
-
message
|
|
197
|
-
}
|
|
198
|
-
}));
|
|
199
|
-
await stream.end();
|
|
200
|
-
}
|
|
201
|
-
catch (error) {
|
|
202
|
-
logger.error('Failed to send error response', { error: error.message });
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
convertAnthropicToGemini(anthropicReq) {
|
|
206
|
-
const contents = [];
|
|
207
|
-
let systemPrefix = '';
|
|
208
|
-
if (anthropicReq.system) {
|
|
209
|
-
systemPrefix = `System: ${anthropicReq.system}\n\n`;
|
|
210
|
-
}
|
|
211
|
-
for (let i = 0; i < anthropicReq.messages.length; i++) {
|
|
212
|
-
const msg = anthropicReq.messages[i];
|
|
213
|
-
let text;
|
|
214
|
-
if (typeof msg.content === 'string') {
|
|
215
|
-
text = msg.content;
|
|
216
|
-
}
|
|
217
|
-
else if (Array.isArray(msg.content)) {
|
|
218
|
-
text = msg.content
|
|
219
|
-
.filter((block) => block.type === 'text')
|
|
220
|
-
.map((block) => block.text)
|
|
221
|
-
.join('\n');
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
224
|
-
text = '';
|
|
225
|
-
}
|
|
226
|
-
if (i === 0 && msg.role === 'user' && systemPrefix) {
|
|
227
|
-
text = systemPrefix + text;
|
|
228
|
-
}
|
|
229
|
-
contents.push({
|
|
230
|
-
role: msg.role === 'assistant' ? 'model' : 'user',
|
|
231
|
-
parts: [{ text }]
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
const geminiReq = { contents };
|
|
235
|
-
if (anthropicReq.temperature !== undefined || anthropicReq.max_tokens !== undefined) {
|
|
236
|
-
geminiReq.generationConfig = {};
|
|
237
|
-
if (anthropicReq.temperature !== undefined) {
|
|
238
|
-
geminiReq.generationConfig.temperature = anthropicReq.temperature;
|
|
239
|
-
}
|
|
240
|
-
if (anthropicReq.max_tokens !== undefined) {
|
|
241
|
-
geminiReq.generationConfig.maxOutputTokens = anthropicReq.max_tokens;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
return geminiReq;
|
|
245
|
-
}
|
|
246
|
-
convertGeminiStreamToAnthropic(chunk) {
|
|
247
|
-
const lines = chunk.split('\n').filter(line => line.trim());
|
|
248
|
-
const anthropicChunks = [];
|
|
249
|
-
for (const line of lines) {
|
|
250
|
-
try {
|
|
251
|
-
if (line.startsWith('data: ')) {
|
|
252
|
-
const jsonStr = line.substring(6);
|
|
253
|
-
const parsed = JSON.parse(jsonStr);
|
|
254
|
-
const candidate = parsed.candidates?.[0];
|
|
255
|
-
const text = candidate?.content?.parts?.[0]?.text;
|
|
256
|
-
if (text) {
|
|
257
|
-
anthropicChunks.push(`event: content_block_delta\ndata: ${JSON.stringify({
|
|
258
|
-
type: 'content_block_delta',
|
|
259
|
-
delta: { type: 'text_delta', text }
|
|
260
|
-
})}\n\n`);
|
|
261
|
-
}
|
|
262
|
-
if (candidate?.finishReason) {
|
|
263
|
-
anthropicChunks.push('event: message_stop\ndata: {}\n\n');
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
catch (e) {
|
|
268
|
-
logger.debug('Failed to parse stream chunk', { line });
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
return anthropicChunks.join('');
|
|
272
|
-
}
|
|
273
|
-
convertGeminiToAnthropic(geminiRes) {
|
|
274
|
-
const candidate = geminiRes.candidates?.[0];
|
|
275
|
-
if (!candidate) {
|
|
276
|
-
throw new Error('No candidates in Gemini response');
|
|
277
|
-
}
|
|
278
|
-
const content = candidate.content;
|
|
279
|
-
const parts = content?.parts || [];
|
|
280
|
-
let rawText = '';
|
|
281
|
-
for (const part of parts) {
|
|
282
|
-
if (part.text) {
|
|
283
|
-
rawText += part.text;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
return {
|
|
287
|
-
id: `msg_${Date.now()}`,
|
|
288
|
-
type: 'message',
|
|
289
|
-
role: 'assistant',
|
|
290
|
-
model: 'gemini-2.0-flash-exp',
|
|
291
|
-
content: [
|
|
292
|
-
{
|
|
293
|
-
type: 'text',
|
|
294
|
-
text: rawText
|
|
295
|
-
}
|
|
296
|
-
],
|
|
297
|
-
stop_reason: 'end_turn',
|
|
298
|
-
usage: {
|
|
299
|
-
input_tokens: geminiRes.usageMetadata?.promptTokenCount || 0,
|
|
300
|
-
output_tokens: geminiRes.usageMetadata?.candidatesTokenCount || 0
|
|
301
|
-
}
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
async stop() {
|
|
305
|
-
if (this.isRunning) {
|
|
306
|
-
await this.transport.close();
|
|
307
|
-
this.isRunning = false;
|
|
308
|
-
logger.info('HTTP/3 proxy stopped');
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
// CLI entry point
|
|
313
|
-
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
314
|
-
const port = parseInt(process.env.PORT || '4433');
|
|
315
|
-
const geminiApiKey = process.env.GOOGLE_GEMINI_API_KEY;
|
|
316
|
-
if (!geminiApiKey) {
|
|
317
|
-
console.error('❌ Error: GOOGLE_GEMINI_API_KEY environment variable required');
|
|
318
|
-
process.exit(1);
|
|
319
|
-
}
|
|
320
|
-
const proxy = new HTTP3Proxy({
|
|
321
|
-
port,
|
|
322
|
-
geminiApiKey,
|
|
323
|
-
cert: process.env.TLS_CERT || './certs/cert.pem',
|
|
324
|
-
key: process.env.TLS_KEY || './certs/key.pem',
|
|
325
|
-
geminiBaseUrl: process.env.GEMINI_BASE_URL
|
|
326
|
-
});
|
|
327
|
-
proxy.start().catch((error) => {
|
|
328
|
-
console.error('❌ Failed to start HTTP/3 proxy:', error);
|
|
329
|
-
process.exit(1);
|
|
330
|
-
});
|
|
331
|
-
}
|