MCPcopy Create free account
hub / github.com/arctic-cli/interface / process

Function process

packages/arctic/src/session/processor.ts:52–479  ·  view source on GitHub ↗
(streamInput: StreamInput)

Source from the content-addressed store, hash-verified

50 return toolcalls[toolCallID]
51 },
52 async process(streamInput: StreamInput) {
53 log.info("process")
54 let reasoningMap: Record<string, MessageV2.ReasoningPart> = {}
55 while (true) {
56 try {
57 let currentText: MessageV2.TextPart | undefined
58 const stream = streamText(streamInput)
59
60 // batching for text deltas to reduce ui update frequency
61 let textDeltaBatch = ""
62 let textDeltaTimer: Timer | undefined
63 const flushTextDelta = async () => {
64 if (textDeltaBatch && currentText) {
65 await Session.updatePart({
66 part: currentText,
67 delta: textDeltaBatch,
68 })
69 textDeltaBatch = ""
70 }
71 }
72
73 // batching for reasoning deltas
74 const reasoningDeltaBatch: Record<string, string> = {}
75 let reasoningDeltaTimer: Timer | undefined
76 const flushReasoningDelta = async () => {
77 for (const [id, delta] of Object.entries(reasoningDeltaBatch)) {
78 const part = reasoningMap[id]
79 if (part && delta) {
80 await Session.updatePart({ part, delta })
81 }
82 }
83 Object.keys(reasoningDeltaBatch).forEach((key) => {
84 reasoningDeltaBatch[key] = ""
85 })
86 }
87
88 for await (const value of stream.fullStream) {
89 input.abort.throwIfAborted()
90 switch (value.type) {
91 case "start":
92 SessionStatus.set(input.sessionID, { type: "busy" })
93 break
94
95 case "reasoning-start":
96 if (value.id in reasoningMap) {
97 continue
98 }
99 reasoningMap[value.id] = {
100 id: Identifier.ascending("part"),
101 messageID: input.assistantMessage.id,
102 sessionID: input.assistantMessage.sessionID,
103 type: "reasoning",
104 text: "",
105 time: {
106 start: Date.now(),
107 },
108 metadata: value.providerMetadata,
109 }

Callers

nothing calls this directly

Calls 6

flushTextDeltaFunction · 0.85
isInstanceMethod · 0.80
setMethod · 0.45
getMethod · 0.45
summarizeMethod · 0.45
publishMethod · 0.45

Tested by

no test coverage detected