MCPcopy Create free account
hub / github.com/Work-Fisher/code-claw / sendMessages

Function sendMessages

compatible-shell/src/client.mjs:20–56  ·  view source on GitHub ↗
({
  baseUrl,
  apiKey,
  model,
  system,
  messages,
  tools,
  maxTokens,
  temperature = 0.1,
})

Source from the content-addressed store, hash-verified

18}
19
20export async function sendMessages({
21 baseUrl,
22 apiKey,
23 model,
24 system,
25 messages,
26 tools,
27 maxTokens,
28 temperature = 0.1,
29}) {
30 const response = await fetch(joinUrl(baseUrl, '/v1/messages'), {
31 method: 'POST',
32 headers: {
33 'content-type': 'application/json',
34 'x-api-key': apiKey,
35 'anthropic-version': '2023-06-01',
36 },
37 body: JSON.stringify({
38 model,
39 system,
40 messages,
41 tools,
42 max_tokens: maxTokens,
43 temperature,
44 stream: false,
45 }),
46 })
47
48 const text = await response.text()
49 if (!response.ok) {
50 throw new Error(
51 `Messages API ${response.status}: ${text.slice(0, 1200) || response.statusText}`,
52 )
53 }
54
55 return text ? JSON.parse(text) : {}
56}
57
58function joinUrl(base, maybePath) {
59 const normalizedBase = base.endsWith('/') ? base.slice(0, -1) : base

Callers 1

runUserTurnFunction · 0.90

Calls 3

textMethod · 0.80
joinUrlFunction · 0.70
parseMethod · 0.45

Tested by

no test coverage detected