feat(resource): add stable resource registry with LLM-context alias compaction
Introduce resource://<handle> as the stable application identity for stored objects, decoupling API responses, persisted rich text, and LLM prompts from physical storage paths. Adds a resource catalog service (register/resolve/bind, revocable expiring access grants), a request-local alias registry that compacts resource references while in the LLM context and restores them (including across streaming chunks), plus router, IM, chat-pipeline, and multimodal integration. Includes schema migrations (resources, resource_bindings, resource_access_grants) for sqlite, and hardens URL/output security handling.
This commit is contained in:
@@ -2,7 +2,7 @@ export const domPurifyForbidTags = ['script', 'style', 'object', 'embed', 'form'
|
||||
export const domPurifyForbidAttr = ['onerror', 'onload', 'onclick', 'onmouseover', 'onfocus', 'onblur'] as const;
|
||||
|
||||
export const domPurifyAllowedUriRegexp =
|
||||
/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp|blob):|(?:storage|local|minio|cos|tos|s3|oss|ks3|obs):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i;
|
||||
/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp|blob):|(?:resource|storage|local|minio|cos|tos|s3|oss|ks3|obs):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i;
|
||||
|
||||
/** Shared DOMPurify security options (FORBID_*, URI scheme, DOM flags). */
|
||||
export const domPurifySecurityOptions = {
|
||||
|
||||
@@ -24,3 +24,15 @@ test('protectProviderImageSrcInHTML uses a placeholder src for storage-backend i
|
||||
/data-protected-src="storage:\/\/c0d93536-702c-4977-aa5e-fe670073c3cb\/local:\/\/10000\/exports\/a\.png"/,
|
||||
)
|
||||
})
|
||||
|
||||
test('protectProviderImageSrcInHTML uses a placeholder src for resource references', () => {
|
||||
const html = '<p><img alt="preview" src="resource://AbCdEfGhIjKlMnOpQrStUv"></p>'
|
||||
const sanitized = protectProviderImageSrcInHTML(html)
|
||||
const renderedSrc = sanitized.match(/<img[^>]*\ssrc="([^"]+)"/)?.[1]
|
||||
|
||||
assert.match(renderedSrc || '', /^data:image\/gif;base64,/)
|
||||
assert.match(
|
||||
sanitized,
|
||||
/data-protected-src="resource:\/\/AbCdEfGhIjKlMnOpQrStUv"/,
|
||||
)
|
||||
})
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
} from './markdownDomPurify.ts';
|
||||
|
||||
const PROVIDER_IMAGE_PLACEHOLDER = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==';
|
||||
const PROVIDER_SCHEME_PATTERN = 'local|minio|cos|tos|s3|oss|ks3|obs';
|
||||
const PROVIDER_SCHEME_PATTERN = 'resource|local|minio|cos|tos|s3|oss|ks3|obs';
|
||||
const PROVIDER_FILE_SCHEME_RE = new RegExp(`^(${PROVIDER_SCHEME_PATTERN}):\\/\\/\\S+$`, 'i');
|
||||
const STORAGE_BACKEND_FILE_SCHEME_RE = new RegExp(
|
||||
`^storage:\\/\\/[0-9A-Za-z_-]+\\/(${PROVIDER_SCHEME_PATTERN}):\\/\\/\\S+$`,
|
||||
@@ -499,7 +499,7 @@ export async function hydrateProtectedFileImages(
|
||||
}
|
||||
|
||||
const images = root.querySelectorAll<HTMLImageElement>(
|
||||
'img[data-protected-src], img[src^="storage://"], img[src^="local://"], img[src^="minio://"], img[src^="cos://"], img[src^="tos://"], img[src^="s3://"], img[src^="oss://"], img[src^="ks3://"], img[src^="obs://"]',
|
||||
'img[data-protected-src], img[src^="resource://"], img[src^="storage://"], img[src^="local://"], img[src^="minio://"], img[src^="cos://"], img[src^="tos://"], img[src^="s3://"], img[src^="oss://"], img[src^="ks3://"], img[src^="obs://"]',
|
||||
);
|
||||
if (!images.length) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user