28 lines
1.1 KiB
TypeScript
28 lines
1.1 KiB
TypeScript
/**
|
||
* Host 所有的易失 Artifact 内容缓存。
|
||
*
|
||
* 它只保存已经通过 ArtifactState 接纳的宿主字节;内容不写入 Conversation Store,
|
||
* Agent 只能引用不透明 local_ref,不能直接填充或读取缓存。
|
||
*
|
||
* Host-owned volatile bytes for Artifact metadata already accepted by
|
||
* ArtifactState. This cache has no network, persistence, DOM or protocol
|
||
* dependency: an Agent can name an opaque ref but cannot populate or read it.
|
||
*/
|
||
export class ArtifactContentCache {
|
||
private readonly blobs = new Map<string, Blob>();
|
||
|
||
public put(localRef: string, content: Blob): boolean {
|
||
if (!opaqueRef(localRef) || content.size > 512 * 1024 * 1024) return false;
|
||
this.blobs.set(localRef, content);
|
||
return true;
|
||
}
|
||
|
||
public get(localRef: string): Blob | undefined { return this.blobs.get(localRef); }
|
||
public has(localRef: string | undefined): boolean { return Boolean(localRef && this.blobs.has(localRef)); }
|
||
public clear(): void { this.blobs.clear(); }
|
||
}
|
||
|
||
function opaqueRef(value: string): boolean {
|
||
return /^[A-Za-z0-9_.:-]{1,128}$/.test(value) && !/[\\/]/.test(value);
|
||
}
|