Merge public-gh/master into paperclip-subissues
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
import { useState, useEffect, useRef, useMemo, useCallback } from "react";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { AGENT_ADAPTER_TYPES } from "@paperclipai/shared";
|
||||
import {
|
||||
hasSessionCompactionThresholds,
|
||||
resolveSessionCompactionPolicy,
|
||||
type ResolvedSessionCompactionPolicy,
|
||||
} from "@paperclipai/adapter-utils";
|
||||
import type {
|
||||
Agent,
|
||||
AdapterEnvironmentTestResult,
|
||||
@@ -383,6 +388,31 @@ export function AgentConfigForm(props: AgentConfigFormProps) {
|
||||
const codexSearchEnabled = adapterType === "codex_local"
|
||||
? (isCreate ? Boolean(val!.search) : eff("adapterConfig", "search", Boolean(config.search)))
|
||||
: false;
|
||||
const effectiveRuntimeConfig = useMemo(() => {
|
||||
if (isCreate) {
|
||||
return {
|
||||
heartbeat: {
|
||||
enabled: val!.heartbeatEnabled,
|
||||
intervalSec: val!.intervalSec,
|
||||
},
|
||||
};
|
||||
}
|
||||
const mergedHeartbeat = {
|
||||
...(runtimeConfig.heartbeat && typeof runtimeConfig.heartbeat === "object"
|
||||
? runtimeConfig.heartbeat as Record<string, unknown>
|
||||
: {}),
|
||||
...overlay.heartbeat,
|
||||
};
|
||||
return {
|
||||
...runtimeConfig,
|
||||
heartbeat: mergedHeartbeat,
|
||||
};
|
||||
}, [isCreate, overlay.heartbeat, runtimeConfig, val]);
|
||||
const sessionCompaction = useMemo(
|
||||
() => resolveSessionCompactionPolicy(adapterType, effectiveRuntimeConfig),
|
||||
[adapterType, effectiveRuntimeConfig],
|
||||
);
|
||||
const showSessionCompactionCard = Boolean(sessionCompaction.adapterSessionManagement);
|
||||
|
||||
return (
|
||||
<div className={cn("relative", cards && "space-y-6")}>
|
||||
@@ -813,6 +843,12 @@ export function AgentConfigForm(props: AgentConfigFormProps) {
|
||||
numberHint={help.intervalSec}
|
||||
showNumber={val!.heartbeatEnabled}
|
||||
/>
|
||||
{showSessionCompactionCard && (
|
||||
<SessionCompactionPolicyCard
|
||||
adapterType={adapterType}
|
||||
resolution={sessionCompaction}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
@@ -835,6 +871,12 @@ export function AgentConfigForm(props: AgentConfigFormProps) {
|
||||
numberHint={help.intervalSec}
|
||||
showNumber={eff("heartbeat", "enabled", heartbeat.enabled !== false)}
|
||||
/>
|
||||
{showSessionCompactionCard && (
|
||||
<SessionCompactionPolicyCard
|
||||
adapterType={adapterType}
|
||||
resolution={sessionCompaction}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<CollapsibleSection
|
||||
title="Advanced Run Policy"
|
||||
@@ -922,6 +964,69 @@ function AdapterEnvironmentResult({ result }: { result: AdapterEnvironmentTestRe
|
||||
);
|
||||
}
|
||||
|
||||
function formatSessionThreshold(value: number, suffix: string) {
|
||||
if (value <= 0) return "Off";
|
||||
return `${value.toLocaleString("en-US")} ${suffix}`;
|
||||
}
|
||||
|
||||
function SessionCompactionPolicyCard({
|
||||
adapterType,
|
||||
resolution,
|
||||
}: {
|
||||
adapterType: string;
|
||||
resolution: ResolvedSessionCompactionPolicy;
|
||||
}) {
|
||||
const { adapterSessionManagement, policy, source } = resolution;
|
||||
if (!adapterSessionManagement) return null;
|
||||
|
||||
const adapterLabel = adapterLabels[adapterType] ?? adapterType;
|
||||
const sourceLabel = source === "agent_override" ? "Agent override" : "Adapter default";
|
||||
const rotationDisabled = !policy.enabled || !hasSessionCompactionThresholds(policy);
|
||||
const nativeSummary =
|
||||
adapterSessionManagement.nativeContextManagement === "confirmed"
|
||||
? `${adapterLabel} is treated as natively managing long context, so Paperclip fresh-session rotation defaults to off.`
|
||||
: adapterSessionManagement.nativeContextManagement === "likely"
|
||||
? `${adapterLabel} likely manages long context itself, but Paperclip still keeps conservative rotation defaults for now.`
|
||||
: `${adapterLabel} does not have verified native compaction behavior, so Paperclip keeps conservative rotation defaults.`;
|
||||
|
||||
return (
|
||||
<div className="rounded-md border border-sky-500/25 bg-sky-500/10 px-3 py-3 space-y-2">
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<div className="text-xs font-medium text-sky-50">Session compaction</div>
|
||||
<span className="rounded-full border border-sky-400/30 px-2 py-0.5 text-[11px] text-sky-100">
|
||||
{sourceLabel}
|
||||
</span>
|
||||
</div>
|
||||
<p className="text-xs text-sky-100/90">
|
||||
{nativeSummary}
|
||||
</p>
|
||||
<p className="text-xs text-sky-100/80">
|
||||
{rotationDisabled
|
||||
? "No Paperclip-managed fresh-session thresholds are active for this adapter."
|
||||
: "Paperclip will start a fresh session when one of these thresholds is reached."}
|
||||
</p>
|
||||
<div className="grid grid-cols-3 gap-2 text-[11px] text-sky-100/85 tabular-nums">
|
||||
<div>
|
||||
<div className="text-sky-100/60">Runs</div>
|
||||
<div>{formatSessionThreshold(policy.maxSessionRuns, "runs")}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-sky-100/60">Raw input</div>
|
||||
<div>{formatSessionThreshold(policy.maxRawInputTokens, "tokens")}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-sky-100/60">Age</div>
|
||||
<div>{formatSessionThreshold(policy.maxSessionAgeHours, "hours")}</div>
|
||||
</div>
|
||||
</div>
|
||||
<p className="text-[11px] text-sky-100/75">
|
||||
A large cumulative raw token total does not mean the full session is resent on every heartbeat.
|
||||
{source === "agent_override" && " This agent has an explicit runtimeConfig session compaction override."}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/* ---- Internal sub-components ---- */
|
||||
|
||||
const ENABLED_ADAPTER_TYPES = new Set(["claude_local", "codex_local", "gemini_local", "opencode_local", "cursor"]);
|
||||
|
||||
@@ -61,6 +61,10 @@ export interface MarkdownEditorRef {
|
||||
focus: () => void;
|
||||
}
|
||||
|
||||
function escapeRegExp(value: string): string {
|
||||
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||
}
|
||||
|
||||
/* ---- Mention detection helpers ---- */
|
||||
|
||||
interface MentionState {
|
||||
@@ -251,6 +255,24 @@ export const MarkdownEditor = forwardRef<MarkdownEditorRef, MarkdownEditorProps>
|
||||
try {
|
||||
const src = await handler(file);
|
||||
setUploadError(null);
|
||||
// After MDXEditor inserts the image, ensure two newlines follow it
|
||||
// so the cursor isn't stuck right next to the image.
|
||||
setTimeout(() => {
|
||||
const current = latestValueRef.current;
|
||||
const escapedSrc = escapeRegExp(src);
|
||||
const updated = current.replace(
|
||||
new RegExp(`(!\\[[^\\]]*\\]\\(${escapedSrc}\\))(?!\\n\\n)`, "g"),
|
||||
"$1\n\n",
|
||||
);
|
||||
if (updated !== current) {
|
||||
latestValueRef.current = updated;
|
||||
ref.current?.setMarkdown(updated);
|
||||
onChange(updated);
|
||||
requestAnimationFrame(() => {
|
||||
ref.current?.focus(undefined, { defaultSelection: "rootEnd" });
|
||||
});
|
||||
}
|
||||
}, 100);
|
||||
return src;
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : "Image upload failed";
|
||||
|
||||
@@ -150,6 +150,71 @@ function ProjectStatusPicker({ status, onChange }: { status: string; onChange: (
|
||||
);
|
||||
}
|
||||
|
||||
function ArchiveDangerZone({
|
||||
project,
|
||||
onArchive,
|
||||
archivePending,
|
||||
}: {
|
||||
project: Project;
|
||||
onArchive: (archived: boolean) => void;
|
||||
archivePending?: boolean;
|
||||
}) {
|
||||
const [confirming, setConfirming] = useState(false);
|
||||
const isArchive = !project.archivedAt;
|
||||
const action = isArchive ? "Archive" : "Unarchive";
|
||||
|
||||
return (
|
||||
<div className="space-y-3 rounded-md border border-destructive/40 bg-destructive/5 px-4 py-4">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{isArchive
|
||||
? "Archive this project to hide it from the sidebar and project selectors."
|
||||
: "Unarchive this project to restore it in the sidebar and project selectors."}
|
||||
</p>
|
||||
{archivePending ? (
|
||||
<Button size="sm" variant="destructive" disabled>
|
||||
<Loader2 className="h-3 w-3 animate-spin mr-1" />
|
||||
{isArchive ? "Archiving..." : "Unarchiving..."}
|
||||
</Button>
|
||||
) : confirming ? (
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-sm text-destructive font-medium">
|
||||
{action} “{project.name}”?
|
||||
</span>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="destructive"
|
||||
onClick={() => {
|
||||
setConfirming(false);
|
||||
onArchive(isArchive);
|
||||
}}
|
||||
>
|
||||
Confirm
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={() => setConfirming(false)}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="destructive"
|
||||
onClick={() => setConfirming(true)}
|
||||
>
|
||||
{isArchive ? (
|
||||
<><Archive className="h-3 w-3 mr-1" />{action} project</>
|
||||
) : (
|
||||
<><ArchiveRestore className="h-3 w-3 mr-1" />{action} project</>
|
||||
)}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function ProjectProperties({ project, onUpdate, onFieldUpdate, getFieldSaveState, onArchive, archivePending }: ProjectPropertiesProps) {
|
||||
const { selectedCompanyId } = useCompany();
|
||||
const queryClient = useQueryClient();
|
||||
@@ -1046,34 +1111,11 @@ export function ProjectProperties({ project, onUpdate, onFieldUpdate, getFieldSa
|
||||
<div className="text-xs font-medium text-destructive uppercase tracking-wide">
|
||||
Danger Zone
|
||||
</div>
|
||||
<div className="space-y-3 rounded-md border border-destructive/40 bg-destructive/5 px-4 py-4">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{project.archivedAt
|
||||
? "Unarchive this project to restore it in the sidebar and project selectors."
|
||||
: "Archive this project to hide it from the sidebar and project selectors."}
|
||||
</p>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="destructive"
|
||||
disabled={archivePending}
|
||||
onClick={() => {
|
||||
const action = project.archivedAt ? "Unarchive" : "Archive";
|
||||
const confirmed = window.confirm(
|
||||
`${action} project "${project.name}"?`,
|
||||
);
|
||||
if (!confirmed) return;
|
||||
onArchive(!project.archivedAt);
|
||||
}}
|
||||
>
|
||||
{archivePending ? (
|
||||
<><Loader2 className="h-3 w-3 animate-spin mr-1" />{project.archivedAt ? "Unarchiving..." : "Archiving..."}</>
|
||||
) : project.archivedAt ? (
|
||||
<><ArchiveRestore className="h-3 w-3 mr-1" />Unarchive project</>
|
||||
) : (
|
||||
<><Archive className="h-3 w-3 mr-1" />Archive project</>
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
<ArchiveDangerZone
|
||||
project={project}
|
||||
onArchive={onArchive}
|
||||
archivePending={archivePending}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user