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

Function applyCaching

packages/arctic/src/provider/transform.ts:126–166  ·  view source on GitHub ↗
(msgs: ModelMessage[], providerID: string)

Source from the content-addressed store, hash-verified

124 }
125
126 function applyCaching(msgs: ModelMessage[], providerID: string): ModelMessage[] {
127 const system = msgs.filter((msg) => msg.role === "system").slice(0, 2)
128 const final = msgs.filter((msg) => msg.role !== "system").slice(-2)
129
130 const providerOptions = {
131 anthropic: {
132 cacheControl: { type: "ephemeral" },
133 },
134 openrouter: {
135 cache_control: { type: "ephemeral" },
136 },
137 bedrock: {
138 cachePoint: { type: "ephemeral" },
139 },
140 openaiCompatible: {
141 cache_control: { type: "ephemeral" },
142 },
143 }
144
145 for (const msg of unique([...system, ...final])) {
146 const shouldUseContentOptions = providerID !== "anthropic" && Array.isArray(msg.content) && msg.content.length > 0
147
148 if (shouldUseContentOptions) {
149 const lastContent = msg.content[msg.content.length - 1]
150 if (lastContent && typeof lastContent === "object") {
151 lastContent.providerOptions = {
152 ...lastContent.providerOptions,
153 ...providerOptions,
154 }
155 continue
156 }
157 }
158
159 msg.providerOptions = {
160 ...msg.providerOptions,
161 ...providerOptions,
162 }
163 }
164
165 return msgs
166 }
167
168 function unsupportedParts(msgs: ModelMessage[], model: Provider.Model): ModelMessage[] {
169 return msgs.map((msg) => {

Callers 1

messageFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected