MCPcopy Index your code
hub / github.com/coder/coder / appendStreamToolInput

Function appendStreamToolInput

coderd/x/chatd/chatdebug/model.go:810–869  ·  view source on GitHub ↗

appendStreamToolInput accumulates incremental tool-input deltas per tool call ID so that parallel or sequential tool invocations remain distinguishable in interrupted stream debug payloads.

(
	content []normalizedContentPart,
	part fantasy.StreamPart,
	streamDebugBytes *int,
)

Source from the content-addressed store, hash-verified

808// per tool call ID so that parallel or sequential tool invocations
809// remain distinguishable in interrupted stream debug payloads.
810func appendStreamToolInput(
811 content []normalizedContentPart,
812 part fantasy.StreamPart,
813 streamDebugBytes *int,
814) []normalizedContentPart {
815 if part.Delta == "" {
816 return content
817 }
818
819 remaining := maxStreamDebugTextBytes
820 if streamDebugBytes != nil {
821 remaining -= *streamDebugBytes
822 }
823 if remaining <= 0 {
824 return content
825 }
826 delta := part.Delta
827 if len(delta) > remaining {
828 cut := 0
829 for _, r := range delta {
830 size := utf8.RuneLen(r)
831 if size < 0 {
832 size = 1
833 }
834 if cut+size > remaining {
835 break
836 }
837 cut += size
838 }
839 delta = delta[:cut]
840 }
841 if delta == "" {
842 return content
843 }
844
845 // Find the existing tool_input part for this specific tool call ID.
846 // Scan backwards through all content; tool_input deltas for the
847 // same call may be separated by text, reasoning, or source parts
848 // when streams interleave multiple tool invocations.
849 for i := len(content) - 1; i >= 0; i-- {
850 if content[i].Type == "tool_input" && content[i].ToolCallID == part.ID {
851 content[i].Arguments += delta
852 if streamDebugBytes != nil {
853 *streamDebugBytes += len(delta)
854 }
855 return content
856 }
857 }
858
859 content = append(content, normalizedContentPart{
860 Type: "tool_input",
861 ToolCallID: part.ID,
862 ToolName: part.ToolCallName,
863 Arguments: delta,
864 })
865 if streamDebugBytes != nil {
866 *streamDebugBytes += len(delta)
867 }

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected