parseUrl
Generic URL parser. Extracts standard URL parts (domain, path, query) plus Prisme.ai-specific fields (workspaceId, file id/filename).
Returns an object with the following fields:
How id / filename splitting works
The last path segment is parsed based on the number of dots:
- 2+ dots (
{id}.{name}.{ext}):idis everything before the first dot,filenameis the rest. - 1 dot (
{name}.{ext}): the whole segment is thefilename, noid. - 0 dots: the whole segment is the
filename, noid.
Examples
Extract a file ID from a native upload URL:splitText
Split text into chunks using a recursive character splitting strategy. The splitter tries separators in order, splits on the first one found, merges small pieces back up tochunkSize, maintains chunkOverlap between consecutive chunks, and recurses with finer separators for pieces still too large.
Returns an array of
{ content, size } objects:
Split with custom separators (e.g. Markdown headings)
Iterate over chunks
search
grep-like line search over a text content. Returns the matching lines with their 1-based line numbers, so an automation can act on positions without re-parsing the text.
Returns
{ matches: [{ line, text, context? }], count } where count is the number of matching lines (context lines excluded).
substitute
sed-like regex substitution. Use this instead of thereplace() expression helper when you need a regular expression (the expression helper is literal-only). Returns the new content and the number of replacements made, so you can detect no-ops.
Returns
{ content, count }.
diff
Produces a unified diff between two texts, the complement ofapplyPatch. Feed the result to applyPatch to reapply the change: applyPatch(a, diff(a, b).patch) yields b.
Returns
{ patch, changed, additions, deletions }.
applyPatch
Applies a unified diff to a text content. Designed for LLM-generated patches: hunks are located by matching their context lines, not by trusting the@@ line numbers (models are unreliable at line arithmetic), so a patch still applies even when its line numbers are off.
Returns
{ content, hunksTotal, hunksApplied, hunksFailed }. A hunk that fails never corrupts the content, its reason is actionable so a model can regenerate just that hunk.