chore: import upstream snapshot with attribution
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 13:20:55 +08:00
commit d25d482dc2
13754 changed files with 4996608 additions and 0 deletions
@@ -0,0 +1,73 @@
/**
* The grammar of a markdown-embedded workspace image reference, shared by the frontend renderer
* (which rewrites one `src` at a time) and the server (which scans a whole document for the
* referenced-by-doc gate and the export bundler). Both go through {@link extractEmbeddedFileRef} so
* the set the client links and the set the server authorizes can never drift apart.
*
* Pure and isomorphic — no DOM, Node, or DB imports — so it is safe to import from both client and
* server code.
*/
/** A reference parsed from an embed `src`: a workspace storage key, a workspace file id, or neither. */
export type EmbeddedFileRef = { key: string } | { fileId: string } | null
/** Hard cap on embedded images resolved from one document — bounds export bundles and the cascade. */
export const MAX_EMBEDDED_IMAGES = 50
/**
* Candidate embed URL substrings in document text: a serve URL, a view URL, or the in-app workspace
* path. The captured run stops at whitespace/quote/paren/angle/query so authoritative parsing is left
* to {@link extractEmbeddedFileRef}.
*/
const EMBED_URL_RE =
/(?:\/api\/files\/(?:serve|view)\/|\/workspace\/[A-Za-z0-9-]+\/files\/)[^\s)"'<>?]*/g
/**
* Parse a single embed `src` into the workspace file it references, normalizing the spellings the
* editor and file agent produce: `/api/files/serve/<key>` (incl. `s3/`/`blob/` prefixes), `/api/files/view/<id>`,
* and the in-app path `/workspace/<wsId>/files/<id>`. Returns null for absolute, `data:`, or non-workspace
* URLs (e.g. public `profile-pictures/` assets), which render as-is.
*/
export function extractEmbeddedFileRef(src: string): EmbeddedFileRef {
try {
const parsed = new URL(src, 'http://placeholder')
if (parsed.origin !== 'http://placeholder') return null
const segs = parsed.pathname.split('/')
if (segs[1] === 'api' && segs[2] === 'files' && segs[3] === 'serve') {
let keySegs = segs.slice(4)
if (keySegs[0] === 's3' || keySegs[0] === 'blob') keySegs = keySegs.slice(1)
const raw = keySegs.join('/')
if (!raw) return null
const key = decodeURIComponent(raw)
return key.startsWith('workspace/') ? { key } : null
}
if (segs[1] === 'api' && segs[2] === 'files' && segs[3] === 'view' && segs[4]) {
return { fileId: segs[4] }
}
if (segs[1] === 'workspace' && segs[3] === 'files' && segs[4]) {
return { fileId: segs[4] }
}
return null
} catch {
return null
}
}
/**
* The de-duplicated keys and ids embedded in `content`, bounded to {@link MAX_EMBEDDED_IMAGES} unique
* references **combined** (keys + ids). Every candidate URL is interpreted by {@link extractEmbeddedFileRef},
* so this is exactly the set the frontend rewrites — the server's referenced-by-doc gate and the export
* bundler share one grammar.
*/
export function extractEmbeddedFileRefs(content: string): { keys: string[]; ids: string[] } {
const keys = new Set<string>()
const ids = new Set<string>()
for (const match of content.matchAll(EMBED_URL_RE)) {
const ref = extractEmbeddedFileRef(match[0])
if (!ref) continue
if ('key' in ref) keys.add(ref.key)
else ids.add(ref.fileId)
if (keys.size + ids.size >= MAX_EMBEDDED_IMAGES) break
}
return { keys: [...keys], ids: [...ids] }
}