~kris/9p

llm9p

ref: 68199d2ad65152fa84d9c9be5008dc7659afdda0 llm9p/internal/llmfs/new.go -rw-r--r-- 769 bytes
68199d2a — pdfinn feat: Initial implementation of llm9p - LLM as 9P filesystem 8 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
package llmfs

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

// NewFile is a write-only file that resets the conversation when written to
type NewFile struct {
	*protocol.BaseFile
	client *llm.Client
}

// NewNewFile creates the new file
func NewNewFile(client *llm.Client) *NewFile {
	return &NewFile{
		BaseFile: protocol.NewBaseFile("new", 0222),
		client:   client,
	}
}

func (f *NewFile) Read(p []byte, offset int64) (int, error) {
	return 0, protocol.ErrPermission
}

func (f *NewFile) Write(p []byte, offset int64) (int, error) {
	// Any write resets the conversation
	f.client.Reset()
	return len(p), nil
}

func (f *NewFile) Stat() protocol.Stat {
	s := f.BaseFile.Stat()
	s.Length = 0
	return s
}