UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

98 lines • 4.42 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 { enoent } from "../../errors/fs.js"; import { stringOf as pickString } from "../../utils/records.js"; import { makeRead } from "../hierarchy/read.js"; import { jsonBytes, jsonlBytesByCreatedAt } from "../render/json.js"; import { getIssue, listIssueComments, listTeamCycles, listTeamDocuments, listTeamIssues, listTeamMembers, listTeamProjects, listTeams, } from "./client.js"; import { normalizeComment, normalizeCycle, normalizeDocument, normalizeIssue, normalizeProject, normalizeTeam, normalizeUser, projectIssueRows, } from "./normalize.js"; import { filteredTeams } from "./readdir.js"; import { detectScope } from "./scope.js"; async function readTeamJson(accessor, match, path) { const teamId = match.slots.team_id ?? ''; for (const team of await filteredTeams(accessor)) { if (team.id === teamId) return jsonBytes(normalizeTeam(team)); } throw enoent(path.virtual); } async function readMember(accessor, match, path) { const memberId = match.slots.member_id ?? ''; const users = await listTeamMembers(accessor.transport, match.slots.team_id ?? ''); for (const user of users) { if (user.id === memberId) return jsonBytes(normalizeUser(user)); } throw enoent(path.virtual); } async function readIssueJson(accessor, match) { const issue = await getIssue(accessor.transport, match.slots.issue_id ?? ''); return jsonBytes(normalizeIssue(issue)); } async function readComments(accessor, match) { const issueId = match.slots.issue_id ?? ''; const issue = await getIssue(accessor.transport, issueId); const normIssue = normalizeIssue(issue); const comments = await listIssueComments(accessor.transport, issueId); const rows = comments.map((c) => normalizeComment(c, issueId, normIssue.issue_key)); return jsonlBytesByCreatedAt(rows); } async function readProject(accessor, match, path) { const teamId = match.slots.team_id ?? ''; const projectId = match.slots.project_id ?? ''; const teams = await listTeams(accessor.transport); const team = teams.find((t) => t.id === teamId) ?? {}; const projects = await listTeamProjects(accessor.transport, teamId); const teamIssues = await listTeamIssues(accessor.transport, teamId, undefined, [projectId]); for (const project of projects) { if (project.id !== projectId) continue; const projectIssues = projectIssueRows(teamIssues, projectId); return jsonBytes(normalizeProject(project, { teamId, teamKey: pickString(team, 'key') || null, teamName: pickString(team, 'name') || null, issues: projectIssues, })); } throw enoent(path.virtual); } async function readCycle(accessor, match, path) { const teamId = match.slots.team_id ?? ''; const cycles = await listTeamCycles(accessor.transport, teamId); for (const cycle of cycles) { if (cycle.id === match.slots.cycle_id) return jsonBytes(normalizeCycle(cycle, teamId)); } throw enoent(path.virtual); } async function readDocument(accessor, match, path) { const documents = await listTeamDocuments(accessor.transport, match.slots.team_id ?? ''); for (const document of documents) { if (document.id === match.slots.document_id) { return jsonBytes(normalizeDocument(document)); } } throw enoent(path.virtual); } export const read = makeRead(detectScope, { team_json: readTeamJson, member: readMember, issue_json: readIssueJson, comments_jsonl: readComments, project: readProject, cycle: readCycle, document: readDocument, }, { parented: true }); //# sourceMappingURL=read.js.map