Skip to content

Commit 73895eb

Browse files
committed
feat: list available Copilot models on startup
- After successful CopilotClient.StartAsync, call ListModelsAsync and emit 'ocp: models: ...' line (before HTTP server listens) - Add small pure ToStartupModelsLine formatter in OpenAIMapper (reuses ToModelsListResponse shape for consistency) - Unit tests for the startup formatter with real ModelInfo instances - Primary entrypoint (ocp.exe / dotnet run) now produces the model list on startup
1 parent ce6f0f8 commit 73895eb

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

src/Tests/OpenAIMapperTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,24 @@ public void Roundtrip_ChatRequest_SerializesAsExpected()
6464
Assert.Contains("\"role\":\"user\"", json);
6565
Assert.Contains("test prompt", json);
6666
}
67+
68+
[Fact]
69+
public void ToStartupModelsLine_ProducesOcpPrefixedIdsLine_UsingMapperShape()
70+
{
71+
// ModelInfo has public ctor (verified via reflection); properties are writable
72+
var models = new List<ModelInfo>
73+
{
74+
new ModelInfo { Id = "gpt-5" },
75+
new ModelInfo { Id = "claude-sonnet-4.5" }
76+
};
77+
var line = OpenAIMapper.ToStartupModelsLine(models);
78+
Assert.Equal("ocp: models: gpt-5, claude-sonnet-4.5", line);
79+
}
80+
81+
[Fact]
82+
public void ToStartupModelsLine_HandlesEmptyList()
83+
{
84+
var line = OpenAIMapper.ToStartupModelsLine(new List<ModelInfo>());
85+
Assert.Equal("ocp: models: ", line);
86+
}
6787
}

src/ocp/OpenAIMapper.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ public static ModelsListResponse ToModelsListResponse(IList<ModelInfo> models)
3131
var data = models.Select(m => new ModelObject(m.Id, "model", now, "copilot")).ToList();
3232
return new ModelsListResponse("list", data);
3333
}
34+
35+
/// <summary>
36+
/// Pure formatter for startup console output. Returns a single "ocp: models: ..." line.
37+
/// Reuses ToModelsListResponse shape internally for consistency.
38+
/// </summary>
39+
public static string ToStartupModelsLine(IList<ModelInfo> models)
40+
{
41+
var resp = ToModelsListResponse(models);
42+
var ids = resp.Data.Select(d => d.Id);
43+
return "ocp: models: " + string.Join(", ", ids);
44+
}
3445
}
3546

3647
// OpenAI compatible request/response shapes (minimal, for /v1 compat)

src/ocp/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@
8383
{
8484
await client.StartAsync();
8585
Console.WriteLine("ocp: Copilot client started.");
86+
var models = await client.ListModelsAsync();
87+
Console.WriteLine(OpenAIMapper.ToStartupModelsLine(models));
8688
}
8789
catch (Exception ex)
8890
{

0 commit comments

Comments
 (0)