MCPcopy Index your code
hub / github.com/simstudioai/sim / takeIndexableWithinCap

Function takeIndexableWithinCap

apps/sim/connectors/utils.ts:207–230  ·  view source on GitHub ↗
(
  items: T[],
  isSkipped: (item: T) => boolean,
  max: number,
  alreadyIndexed: number
)

Source from the content-addressed store, hash-verified

205 * that count toward the cap), and whether the cap is now reached
206 */
207export function takeIndexableWithinCap<T>(
208 items: T[],
209 isSkipped: (item: T) => boolean,
210 max: number,
211 alreadyIndexed: number
212): { documents: T[]; indexableCount: number; capReached: boolean } {
213 if (max <= 0) {
214 let indexableCount = 0
215 for (const item of items) {
216 if (!isSkipped(item)) indexableCount += 1
217 }
218 return { documents: items, indexableCount, capReached: false }
219 }
220
221 const remaining = max - alreadyIndexed
222 const documents: T[] = []
223 let indexableCount = 0
224 for (const item of items) {
225 if (indexableCount >= remaining) break
226 documents.push(item)
227 if (!isSkipped(item)) indexableCount += 1
228 }
229 return { documents, indexableCount, capReached: alreadyIndexed + indexableCount >= max }
230}
231
232/**
233 * Raised by a connector when a file exceeds its size cap mid-download — i.e. the

Callers 7

utils.test.tsFile · 0.90
sharepoint.tsFile · 0.90
dropbox.tsFile · 0.90
s3.tsFile · 0.90
github.tsFile · 0.90
onedrive.tsFile · 0.90
zoom.tsFile · 0.90

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected