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

Function summarizeMessage

packages/arctic/src/session/summary.ts:63–174  ·  view source on GitHub ↗
(input: { messageID: string; messages: MessageV2.WithParts[] })

Source from the content-addressed store, hash-verified

61 }
62
63 async function summarizeMessage(input: { messageID: string; messages: MessageV2.WithParts[] }) {
64 const cfg = await Config.get()
65 const messages = input.messages.filter(
66 (m) => m.info.id === input.messageID || (m.info.role === "assistant" && m.info.parentID === input.messageID),
67 )
68 const msgWithParts = messages.find((m) => m.info.id === input.messageID)!
69 const userMsg = msgWithParts.info as MessageV2.User
70 const diffs = await computeDiff({ messages })
71 userMsg.summary = {
72 ...userMsg.summary,
73 diffs,
74 }
75 await Session.updateMessage(userMsg)
76
77 const assistantMsg = messages.find((m) => m.info.role === "assistant")!.info as MessageV2.Assistant
78 const small =
79 (await Provider.getSmallModel(assistantMsg.providerID)) ??
80 (await Provider.getModel(assistantMsg.providerID, assistantMsg.modelID))
81 const provider = await Provider.getProvider(small.providerID)
82 const language = await Provider.getLanguage(small)
83
84 const options = pipe(
85 {},
86 mergeDeep(ProviderTransform.options(small, assistantMsg.sessionID, provider?.options)),
87 mergeDeep(ProviderTransform.smallOptions(small)),
88 mergeDeep(small.options),
89 )
90
91 const textPart = msgWithParts.parts.find((p) => p.type === "text" && !p.synthetic) as MessageV2.TextPart
92 if (textPart && !userMsg.summary?.title && !provider?.options?.disableMessageTitle) {
93 const result = await generateText({
94 maxOutputTokens: small.capabilities.reasoning ? 1500 : 20,
95 providerOptions: ProviderTransform.providerOptions(small, options),
96 messages: [
97 ...SystemPrompt.title(small.providerID).map(
98 (x): ModelMessage => ({
99 role: "system",
100 content: x,
101 }),
102 ),
103 {
104 role: "user" as const,
105 content: `
106 The following is the text to summarize:
107 <text>
108 ${textPart?.text ?? ""}
109 </text>
110 `,
111 },
112 ],
113 headers: small.headers,
114 model: language,
115 experimental_telemetry: {
116 isEnabled: cfg.experimental?.openTelemetry,
117 metadata: {
118 userId: cfg.username ?? "unknown",
119 sessionId: assistantMsg.sessionID,
120 },

Callers 1

summary.tsFile · 0.85

Calls 3

computeDiffFunction · 0.85
getMethod · 0.45
summarizeMethod · 0.45

Tested by

no test coverage detected