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

Function create

packages/arctic/src/session/processor.ts:33–482  ·  view source on GitHub ↗
(input: {
    assistantMessage: MessageV2.Assistant
    sessionID: string
    model: Provider.Model
    abort: AbortSignal
    toolNameResolver?: (name: string) => string
  })

Source from the content-addressed store, hash-verified

31 }
32
33 export function create(input: {
34 assistantMessage: MessageV2.Assistant
35 sessionID: string
36 model: Provider.Model
37 abort: AbortSignal
38 toolNameResolver?: (name: string) => string
39 }) {
40 const toolcalls: Record<string, MessageV2.ToolPart> = {}
41 let snapshot: string | undefined
42 let blocked = false
43 let attempt = 0
44
45 const result = {
46 get message() {
47 return input.assistantMessage
48 },
49 partFromToolCall(toolCallID: string) {
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) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected