Changeset 0.37.18 (#230)
Co-authored-by: gobha <jasafpro@gmail.com> Co-committed-by: gobha <jasafpro@gmail.com>
This commit is contained in:
@@ -42,9 +42,16 @@ const defaultMaxRounds = 10
|
||||
|
||||
// LoopResult holds the accumulated output from a completion with tool
|
||||
// execution. Callers are responsible for persistence.
|
||||
// FileRef tracks a file created by a tool for auto-linking to the assistant message.
|
||||
type FileRef struct {
|
||||
WorkspaceID string `json:"workspace_id"`
|
||||
Path string `json:"path"`
|
||||
}
|
||||
|
||||
type LoopResult struct {
|
||||
Content string
|
||||
ToolActivity []map[string]interface{}
|
||||
FileRefs []FileRef // v0.37.18: workspace files created by tools
|
||||
InputTokens int
|
||||
OutputTokens int
|
||||
CacheCreationTokens int
|
||||
@@ -210,6 +217,11 @@ func CoreToolLoop(ctx context.Context, lcfg LoopConfig, sink LoopSink) LoopResul
|
||||
// Emit workspace.file.changed for live editor updates (v0.21.5)
|
||||
emitWorkspaceEvent(lcfg, call, toolResult)
|
||||
|
||||
// Collect file refs for tool_output auto-save (v0.37.18)
|
||||
if ref := collectFileRef(lcfg, call, toolResult); ref != nil {
|
||||
result.FileRefs = append(result.FileRefs, *ref)
|
||||
}
|
||||
|
||||
// Collect for persistence
|
||||
result.ToolActivity = append(result.ToolActivity, map[string]interface{}{
|
||||
"id": tc.ID,
|
||||
@@ -574,6 +586,26 @@ func emitWorkspaceEvent(lcfg LoopConfig, call tools.ToolCall, result tools.ToolR
|
||||
}
|
||||
}
|
||||
|
||||
// collectFileRef returns a FileRef when workspace_write or workspace_patch succeeds.
|
||||
func collectFileRef(lcfg LoopConfig, call tools.ToolCall, result tools.ToolResult) *FileRef {
|
||||
if result.IsError || lcfg.ExecCtx.WorkspaceID == "" {
|
||||
return nil
|
||||
}
|
||||
if call.Name != "workspace_write" && call.Name != "workspace_patch" {
|
||||
return nil
|
||||
}
|
||||
var toolArgs struct {
|
||||
Path string `json:"path"`
|
||||
}
|
||||
if json.Unmarshal([]byte(call.Arguments), &toolArgs) == nil && toolArgs.Path != "" {
|
||||
return &FileRef{
|
||||
WorkspaceID: lcfg.ExecCtx.WorkspaceID,
|
||||
Path: toolArgs.Path,
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ── Sink Implementations ───────────────────────
|
||||
|
||||
// sseSink writes SSE events to a gin.Context writer for interactive streaming.
|
||||
|
||||
Reference in New Issue
Block a user