@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
59 lines • 2.69 kB
JavaScript
// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
import { heldPages } from "../hierarchy/readdir.js";
import { cursorPages } from "./paginate.js";
import { compactJsonBytes } from "../render/json.js";
function isRealUser(m) {
return m.deleted !== true && m.is_bot !== true && m.id !== 'USLACKBOT';
}
export async function* listUsersStream(accessor, options = {}) {
const limit = options.limit ?? 200;
for await (const page of cursorPages(accessor.transport, 'users.list', { limit: String(limit) }, 'members')) {
yield page.filter(isRealUser);
}
}
export async function listUsers(accessor, options = {}) {
return heldPages(listUsersStream(accessor, options), options.stopAt);
}
// The single renderer behind both read and the readdir-time size.
// readdir sizes a user from the users.list member; read renders the
// users.info response. Sizing is exact only while those two payloads encode
// identically, which was verified live on 2026-08-01: every real user in a
// live workspace matched byte for byte, key order included.
//
// The integ battery cannot catch a regression here. The fake server builds
// users.list and users.info from one row through one helper, so they agree
// by construction; only a live call tests the assumption.
export function userJsonBytes(user) {
return compactJsonBytes(user);
}
export async function getUserProfile(accessor, userId) {
const data = await accessor.transport.call('users.info', { user: userId });
return data.user ?? {};
}
export async function searchUsers(accessor, query, options = {}) {
const all = await listUsers(accessor, options);
const q = query.toLowerCase();
return all.filter((u) => {
if ((u.name ?? '').toLowerCase().includes(q))
return true;
if ((u.real_name ?? '').toLowerCase().includes(q))
return true;
const email = u.profile?.email ?? '';
if (email.toLowerCase().includes(q))
return true;
return false;
});
}
//# sourceMappingURL=users.js.map