MCPcopy Create free account
hub / github.com/Noumena-Network/code / ensureToolState

Function ensureToolState

src/services/api/openAICompatInferenceClient.ts:1244–1268  ·  view source on GitHub ↗
(
    toolKey: string,
    toolCall: OpenAIStreamToolCallDelta,
  )

Source from the content-addressed store, hash-verified

1242 }
1243
1244 const ensureToolState = (
1245 toolKey: string,
1246 toolCall: OpenAIStreamToolCallDelta,
1247 ): OpenAIStreamToolState => {
1248 const existing = openTools.get(toolKey)
1249 if (existing) {
1250 if (!existing.name && toolCall.function?.name) {
1251 existing.name = toolCall.function.name
1252 }
1253 if (toolCall.id && existing.id.startsWith('generated-')) {
1254 existing.id = toolCall.id
1255 }
1256 return existing
1257 }
1258
1259 const state: OpenAIStreamToolState = {
1260 contentIndex: nextIndex++,
1261 id: toolCall.id ?? `generated-${randomUUID()}`,
1262 name: toolCall.function?.name ?? undefined,
1263 arguments: '',
1264 started: false,
1265 }
1266 openTools.set(toolKey, state)
1267 return state
1268 }
1269
1270 const emitToolStartIfReady = (
1271 state: OpenAIStreamToolState,

Calls 3

randomUUIDFunction · 0.90
setMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected