Skip to main content
Runtime modules are the built-in capabilities you call from automations on the foundation, and the text module is one of them. It provides pure-JS text processing utilities, with no external dependencies.

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}): id is everything before the first dot, filename is the rest.
  • 1 dot ({name}.{ext}): the whole segment is the filename, no id.
  • 0 dots: the whole segment is the filename, no id.

Examples

Extract a file ID from a native upload URL:
Extract workspace ID from any Prisme.ai 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 to chunkSize, 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

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 the replace() 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 of applyPatch. 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.