~kris/9p

llm9p

ref: ed43a61bf88f3238d4844391e1f7926d8490ae50 llm9p/internal/llmfs/root.go -rw-r--r-- 1.3 KiB
ed43a61b — pdfinn feat(llm9p): Add per-fid session isolation and prefill support 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Package llmfs implements the LLM filesystem exposed via 9P.
package llmfs

import (
	"github.com/NERVsystems/llm9p/internal/llm"
	"github.com/NERVsystems/llm9p/internal/protocol"
)

// NewRoot creates the root directory of the LLM filesystem.
// It takes a SessionManager which provides per-fid session isolation
// and access to the underlying backend for global settings.
func NewRoot(sm *llm.SessionManager) protocol.Dir {
	backend := sm.Backend()
	root := protocol.NewStaticDir("llm")

	// Session-aware files (per-fid isolation)
	root.AddChild(NewAskFile(sm))
	root.AddChild(NewNewFile(sm))
	root.AddChild(NewContextFile(sm))

	// Global settings files (shared across all fids)
	root.AddChild(NewModelFile(backend))
	root.AddChild(NewTemperatureFile(backend))
	root.AddChild(NewSystemFile(backend))
	root.AddChild(NewThinkingFile(backend))
	root.AddChild(NewPrefillFile(backend))

	// Token tracking (uses backend's global counters)
	root.AddChild(NewTokensFile(backend))
	root.AddChild(NewUsageFile(backend))
	root.AddChild(NewMetricsFile(backend))
	root.AddChild(NewCompactFile(backend))

	// Static files
	root.AddChild(NewExampleFile())

	// Add stream directory (uses backend directly)
	streamDir := protocol.NewStaticDir("stream")
	streamDir.AddChild(NewStreamAskFile(backend))
	streamDir.AddChild(NewChunkFile(backend))
	root.AddChild(streamDir)

	return root
}