UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

106 lines (105 loc) • 4.32 kB
import { r as isIncognitoSessionKey } from "./session-key-DW1jcHbM.mjs"; import "./session-key-CqAyZeVk.mjs"; import { o as resolveSessionStorePathForScope } from "./session-store-path-BIJyO4vM.mjs"; import { g as resolveUserProfileGitHubAttribution, m as prepareUserProfileGitHubAttribution } from "./user-profile-identity.read-DZIwS_8H.mjs"; import { c as isMainGitContributorScope, o as inheritSessionGitContributorProfileIds, t as MAX_SESSION_PARTICIPANTS } from "./session-entry-provenance-01l9mXT0.mjs"; import { n as readSessionEntriesFromStoreInWorker } from "./session-entry-read-runtime-1Fp1sybj.mjs"; import { a as resolveConfiguredGitHubHost } from "./github-host-CjR25cOO.mjs"; import { f as resolveConfiguredGitHubToolIdentity } from "./github-tool-identity-41SK6r8O.mjs"; //#region src/agents/git-coauthor-attribution.ts async function resolveGitCoauthorAttribution(e) { return (await resolveAttribution(e, false)).attribution; } async function prepareGitCoauthorAttribution(e) { return await resolveAttribution(e, true); } async function resolveAttribution(e, t) { const n = { attribution: void 0, isCurrent: () => true }; if (!e.sessionKey || isIncognitoSessionKey(e.sessionKey)) return n; const r = resolveSessionStorePathForScope({ agentId: e.agentId, env: e.env, sessionKey: e.sessionKey, storePath: e.storePath }, e.config); const i = await readSessionEntriesFromStoreInWorker({ agentId: e.agentId, env: e.env, sessionKeys: [e.sessionKey], storePath: r, includeParticipantRecords: true, snapshotFields: [] }); const a = i.entries.find(({ sessionKey: t }) => t === e.sessionKey)?.entry; if (!a || a.incognito || e.sessionId && a.sessionId !== e.sessionId) return n; const o = i.participantRecords?.[e.sessionKey] ?? []; const s = new Map(o.flatMap((e) => e.identity.type === "profile" ? [[e.identity.id, e]] : [])); const c = a.inheritedGitContributorProfileIds ?? []; const l = { ...e, sessionKey: e.sessionKey, requesterProfileId: e.requesterProfileId }; const u = isMainGitContributorScope(l) ? inheritSessionGitContributorProfileIds(a, l) ?? [] : [.../* @__PURE__ */ new Set([...s.keys(), ...c])]; if (u.length === 0) return n; const d = e.host ?? resolveConfiguredGitHubHost(e.config); const f = t ? await prepareUserProfileGitHubAttribution(u, { env: e.env, host: d }) : { identities: await resolveUserProfileGitHubAttribution(u, { env: e.env, host: d }), isCurrent: () => true }; const p = f.identities; const m = (resolveConfiguredGitHubToolIdentity({ ...e, scope: "agent" }) ?? resolveConfiguredGitHubToolIdentity({ ...e, scope: "system" }))?.gitAuthor?.email?.trim().toLowerCase(); const h = /* @__PURE__ */ new Map(); for (const t of u) { const n = s.get(t); const r = p.get(t); if (!r) continue; if (("host" in r ? r.host : "github.com") !== d || r.accountId === e.excludeAccountId) continue; const i = "host" in r ? r.verifiedEmail : `${r.accountId}+${r.login}@users.noreply.github.com`; if (!i) continue; if (e.excludeAccountId === void 0 && i.toLowerCase() === m) continue; const a = h.get(r.accountId); if (a) { if (n) { a.contributionCount += n.contributionCount; a.firstPromptedAt = a.firstPromptedAt === null || n.firstPromptedAt === null ? null : Math.min(a.firstPromptedAt, n.firstPromptedAt); } continue; } h.set(r.accountId, { accountId: r.accountId, email: i, contributionCount: n?.contributionCount ?? 0, firstPromptedAt: n?.firstPromptedAt ?? null, login: r.login, ...!n ? { inheritedOrder: c.indexOf(t) } : {} }); } const g = [...h.values()].toSorted((e, t) => t.contributionCount - e.contributionCount || (e.firstPromptedAt === null ? t.firstPromptedAt === null ? 0 : 1 : t.firstPromptedAt === null ? -1 : e.firstPromptedAt - t.firstPromptedAt) || (e.inheritedOrder ?? Number.MAX_SAFE_INTEGER) - (t.inheritedOrder ?? Number.MAX_SAFE_INTEGER) || e.accountId - t.accountId).slice(0, MAX_SESSION_PARTICIPANTS); const _ = g.map(({ login: e }) => e); const v = g.map(({ email: e, login: t }) => `Co-authored-by: ${t} <${e}>`); return { attribution: v.length ? { trailers: v, logins: _ } : void 0, isCurrent: f.isCurrent }; } //#endregion export { resolveGitCoauthorAttribution as n, prepareGitCoauthorAttribution as t };