export function executeStoreAction(store, action, args) {
    const collection = args.collection;
    const id = args.id;
    switch (action) {
        case "has":
            return store.has(collection, id ?? "");
        case "put": {
            // Strict type checks: a caller that passed a wrong-shape value/meta is
            // making a mistake (e.g. value:{url:...} instead of meta:{url:...}).
            // Silently coercing to undefined would persist an empty payload and
            // return "ok", and the LLM would believe its metadata was saved.
            if (args.value !== undefined && args.value !== null && typeof args.value !== "string") {
                return (`store.put rejected: value must be a string (got ${typeof args.value}). ` +
                    `For structured data put it in meta (a JSON object), not value.`);
            }
            if (args.meta !== undefined &&
                args.meta !== null &&
                (typeof args.meta !== "object" || Array.isArray(args.meta))) {
                return (`store.put rejected: meta must be a JSON object (got ${Array.isArray(args.meta) ? "array" : typeof args.meta}).`);
            }
            const value = typeof args.value === "string" ? args.value : undefined;
            const meta = args.meta && typeof args.meta === "object" && !Array.isArray(args.meta)
                ? args.meta
                : undefined;
            return store.put(collection, id ?? "", value, meta);
        }
        case "get":
            return store.get(collection, id ?? "");
        case "list": {
            const limit = typeof args.limit === "number" ? args.limit : undefined;
            const sinceMs = typeof args.sinceMs === "number" ? args.sinceMs : undefined;
            return store.list(collection, { limit, sinceMs });
        }
        case "count":
            return store.count(collection);
        case "delete":
            return store.delete(collection, id ?? "");
        default:
            return `Unknown store action: ${action}. Supported: has, put, get, list, count, delete.`;
    }
}
//# sourceMappingURL=store-executor.js.map