import { randomUUID } from "node:crypto";
//#region src/gateway/file-reference-registry.ts
const DEFAULT_TTL_MS = 1800 * 1e3;
var FileReferenceRegistry = class {
	refs = /* @__PURE__ */ new Map();
	register(input) {
		this.expire();
		const id = randomUUID();
		const ref = {
			id,
			absolutePath: input.absolutePath,
			sessionKey: input.sessionKey?.trim() || void 0,
			scope: input.scope,
			locationKind: input.locationKind,
			capabilities: [...new Set(input.capabilities)],
			expiresAt: Date.now() + (input.ttlMs ?? DEFAULT_TTL_MS)
		};
		this.refs.set(id, ref);
		return ref;
	}
	resolve(id) {
		this.expire();
		const ref = this.refs.get(id);
		if (!ref) return null;
		if (ref.expiresAt <= Date.now()) {
			this.refs.delete(id);
			return null;
		}
		return ref;
	}
	/**
	* Remove a specific reference (used after a one-shot action like
	* import-to-workspace completes so the source card can't be re-triggered).
	* Returns true if the reference existed and was removed.
	*/
	expireById(id) {
		return this.refs.delete(id);
	}
	expire(now = Date.now()) {
		for (const [id, ref] of this.refs) if (ref.expiresAt <= now) this.refs.delete(id);
	}
};
const fileReferenceRegistry = new FileReferenceRegistry();
//#endregion
export { FileReferenceRegistry, fileReferenceRegistry };

//# sourceMappingURL=file-reference-registry.js.map