UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

61 lines • 2.88 kB
// ========= 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 { FlagView } from "../../../spec/flag_view.js"; import { getSelf } from "../../../../core/notion/pages.js"; import { IOResult } from "../../../../io/types.js"; import { asObject, stringOf } from "../../../../utils/records.js"; import { notionTransport, prettyJson } from "./util.js"; const ENC = new TextEncoder(); // Nine columns, pinned against the upstream binary: identity, then the // workspace the token belongs to, then the bot's owner. A bot owned by the // workspace repeats the workspace in the owner columns because that is // literally who owns it; a bot owned by a user names that user, and their // email is the fourth column, the same slot a person's own email occupies. export function whoamiRow(me) { const bot = asObject(me.bot); const owner = asObject(bot.owner); const user = asObject(owner.user); const workspaceId = stringOf(bot, 'workspace_id'); const workspaceName = stringOf(bot, 'workspace_name'); const hasBot = Object.keys(bot).length > 0; const byUser = owner.type === 'user'; const email = byUser ? stringOf(asObject(user.person), 'email') : stringOf(asObject(me.person), 'email'); const ownerId = byUser ? stringOf(user, 'id') : workspaceId; const ownerName = byUser ? stringOf(user, 'name') : workspaceName; // The last column is the owner's own kind, so a user owner reports what // that user is (`person`), not the `user` discriminator on the envelope. const ownerType = byUser ? stringOf(user, 'type') : stringOf(owner, 'type'); const columns = [ stringOf(me, 'id'), stringOf(me, 'name'), stringOf(me, 'type'), email, workspaceId, workspaceName, hasBot ? ownerId : '', hasBot ? ownerName : '', ownerType, ]; return ENC.encode(`${columns.join('\t')}\n`); } export async function whoami(accessor, _paths, _texts, ctx) { const fl = new FlagView(ctx.flags); const me = await getSelf(notionTransport(accessor, ctx.flags)); if (fl.asBool('json')) return [prettyJson(me), new IOResult()]; return [whoamiRow(me), new IOResult()]; } //# sourceMappingURL=whoami.js.map