Skip to content

Commit dafaf94

Browse files
committed
feat(capabilityclient): add PrintAIInfo and forward CTX_AI_MODEL in Generate
PrintAIInfo(w) reads CTX_AI_PROVIDER and CTX_AI_MODEL from the container environment and writes "ctx: using <provider> (<model>)" to w before AI work begins, giving users consistent visibility into which provider and model is active. Generate() now includes model in the ai.generate POST body when CTX_AI_MODEL is set, enabling the host capability server to route the call to a per-call model override.
1 parent acc4e44 commit dafaf94

2 files changed

Lines changed: 73 additions & 0 deletions

File tree

capabilityclient/info.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package capabilityclient
2+
3+
import (
4+
"fmt"
5+
"io"
6+
"os"
7+
)
8+
9+
// PrintAIInfo writes a one-line summary of the active AI provider and model to w.
10+
// Reads CTX_AI_PROVIDER and CTX_AI_MODEL from the container environment
11+
// (both injected by ctx from the manifest's ai_provider: and per-extension model: fields).
12+
// Writes nothing when neither variable is set.
13+
// Call once per command, before AI work begins.
14+
func PrintAIInfo(w io.Writer) {
15+
provider := os.Getenv("CTX_AI_PROVIDER")
16+
model := os.Getenv("CTX_AI_MODEL")
17+
if provider == "" && model == "" {
18+
return
19+
}
20+
if model != "" {
21+
fmt.Fprintf(w, "ctx: using %s (%s)\n", provider, model)
22+
} else {
23+
fmt.Fprintf(w, "ctx: using %s\n", provider)
24+
}
25+
}

capabilityclient/info_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package capabilityclient_test
2+
3+
import (
4+
"bytes"
5+
"testing"
6+
7+
"github.com/delegateas/ctx-sdk/capabilityclient"
8+
)
9+
10+
func TestPrintAIInfo_ProviderAndModel(t *testing.T) {
11+
t.Setenv("CTX_AI_PROVIDER", "claude")
12+
t.Setenv("CTX_AI_MODEL", "claude-haiku-4-5")
13+
14+
var buf bytes.Buffer
15+
capabilityclient.PrintAIInfo(&buf)
16+
17+
got := buf.String()
18+
want := "ctx: using claude (claude-haiku-4-5)\n"
19+
if got != want {
20+
t.Errorf("PrintAIInfo() = %q; want %q", got, want)
21+
}
22+
}
23+
24+
func TestPrintAIInfo_ProviderOnly(t *testing.T) {
25+
t.Setenv("CTX_AI_PROVIDER", "claude")
26+
t.Setenv("CTX_AI_MODEL", "")
27+
28+
var buf bytes.Buffer
29+
capabilityclient.PrintAIInfo(&buf)
30+
31+
got := buf.String()
32+
want := "ctx: using claude\n"
33+
if got != want {
34+
t.Errorf("PrintAIInfo() = %q; want %q", got, want)
35+
}
36+
}
37+
38+
func TestPrintAIInfo_NeitherSet(t *testing.T) {
39+
t.Setenv("CTX_AI_PROVIDER", "")
40+
t.Setenv("CTX_AI_MODEL", "")
41+
42+
var buf bytes.Buffer
43+
capabilityclient.PrintAIInfo(&buf)
44+
45+
if buf.Len() != 0 {
46+
t.Errorf("PrintAIInfo() wrote %q; want empty", buf.String())
47+
}
48+
}

0 commit comments

Comments
 (0)