| 1 | // Command starterextension is the smallest installable Reasonix code |
| 2 | // extension. It rewrites inputs beginning with "starter: " so developers can |
| 3 | // verify the complete manifest -> sidecar -> intercept path before adding more |
| 4 | // capabilities. |
| 5 | package main |
| 6 | |
| 7 | import ( |
| 8 | "context" |
| 9 | "encoding/json" |
| 10 | "os" |
| 11 | "strings" |
| 12 | |
| 13 | extension "github.com/esengine/DeepSeek-Reasonix/sdk/go" |
| 14 | ) |
| 15 | |
| 16 | const inputPrefix = "starter: " |
| 17 | |
| 18 | type starter struct{} |
| 19 | |
| 20 | func (starter) Initialize(context.Context, extension.InitializeParams) (*extension.InitializeResult, error) { |
| 21 | return &extension.InitializeResult{ |
| 22 | Subscriptions: []string{"input.receive"}, |
| 23 | }, nil |
| 24 | } |
| 25 | |
| 26 | func interceptInput(_ context.Context, _ string, payload json.RawMessage) (*extension.InterceptResult, error) { |
| 27 | var input struct { |
| 28 | Text string `json:"text"` |
| 29 | } |
| 30 | if err := json.Unmarshal(payload, &input); err != nil || !strings.HasPrefix(input.Text, inputPrefix) { |
| 31 | return extension.Continue(), nil |
| 32 | } |
| 33 | return extension.Replace(map[string]string{ |
| 34 | "text": strings.TrimPrefix(input.Text, inputPrefix) + " [rewritten by starter-extension]", |
| 35 | }) |
| 36 | } |
| 37 | |
| 38 | func main() { |
| 39 | err := extension.Serve(context.Background(), starter{}, extension.Options{ |
| 40 | Name: "starter-extension", |
| 41 | Version: "0.1.0", |
| 42 | Interceptors: map[string]extension.InterceptorFunc{ |
| 43 | "input.receive": interceptInput, |
| 44 | }, |
| 45 | }) |
| 46 | if err != nil { |
| 47 | os.Exit(1) |
| 48 | } |
| 49 | } |
| 50 |