agentexec's wire contract, harness adapters and log forwarding no longer import the AI SDK; the in-process model loop, runtime, tool set and sampling helpers that do now live in agentexec/modelloop, used by the Gateway and archie-agent only.
63 lines
1.7 KiB
Go
63 lines
1.7 KiB
Go
package agentexec
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/samcharles93/archie-core/internal/domain/agentrun"
|
|
)
|
|
|
|
// copilotHarnessOutput reads GitHub Copilot CLI's `--output-format json`.
|
|
// The stream carries no token counts, so a Copilot run reports no usage and
|
|
// its budget is wall clock.
|
|
type copilotHarnessOutput struct {
|
|
sessionID string
|
|
pending map[string]string
|
|
}
|
|
|
|
func newCopilotHarnessOutput() *copilotHarnessOutput {
|
|
return &copilotHarnessOutput{pending: make(map[string]string)}
|
|
}
|
|
|
|
func (o *copilotHarnessOutput) Line(line []byte, report agentrun.ToolCallReporter) {
|
|
var event struct {
|
|
Type string `json:"type"`
|
|
SessionID string `json:"sessionId"`
|
|
Data struct {
|
|
ToolCallID string `json:"toolCallId"`
|
|
ToolName string `json:"toolName"`
|
|
MCPToolName string `json:"mcpToolName"`
|
|
Success bool `json:"success"`
|
|
Result struct {
|
|
Content string `json:"content"`
|
|
} `json:"result"`
|
|
} `json:"data"`
|
|
}
|
|
if json.Unmarshal(line, &event) != nil {
|
|
return
|
|
}
|
|
switch event.Type {
|
|
case "result":
|
|
o.sessionID = event.SessionID
|
|
case "tool.execution_start":
|
|
name := event.Data.MCPToolName
|
|
if name == "" {
|
|
name = event.Data.ToolName
|
|
}
|
|
if event.Data.ToolCallID != "" && name != "" {
|
|
o.pending[event.Data.ToolCallID] = name
|
|
}
|
|
case "tool.execution_complete":
|
|
tool, ok := o.pending[event.Data.ToolCallID]
|
|
if !ok {
|
|
return
|
|
}
|
|
delete(o.pending, event.Data.ToolCallID)
|
|
if report != nil {
|
|
report(agentrun.ToolCallReport{Tool: tool, Detail: ClipToolCallDetail(event.Data.Result.Content), Failed: !event.Data.Success})
|
|
}
|
|
}
|
|
}
|
|
|
|
func (o *copilotHarnessOutput) SessionID() string { return o.sessionID }
|
|
func (o *copilotHarnessOutput) Usage() agentrun.Usage { return agentrun.Usage{} }
|