mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-29 23:56:43 +01:00
External object references across issue surfaces (#8512)
## Thinking Path > - Paperclip is the open source control plane people use to coordinate AI agents, issues, approvals, comments, and work products. > - The involved subsystem is issue context: markdown links, issue properties, related work, lists, filters, inbox/sidebar status, and plugin-provided external context. > - The gap is that URLs to external systems currently remain mostly plain links, so humans and agents must manually open them to understand status, identity, and liveness. > - This matters because external work objects such as GitHub issues and pull requests are part of the operational state of a Paperclip company. > - The implementation keeps core provider-neutral: shared contracts, storage, sync, routes, and UI surfaces live in core while providers can contribute detection and status resolution. > - This pull request adds the external object reference foundation, GitHub provider support, issue-surface rendering, filters, sidebar/list/inbox signals, and test/story coverage. > - The benefit is that linked external work becomes inspectable Paperclip context without hardcoding every provider directly into the UI. ## Linked Issues or Issue Description No public GitHub issue exists for this work. Feature request: - Problem: URLs in Paperclip issues, comments, documents, and related surfaces do not expose provider status or object identity inline. - Proposed behavior: detect supported external object URLs, persist normalized references, refresh provider status, and render concise status-aware links across issue surfaces. - Users affected: board users, agents, and maintainers who triage issues containing external work links. - Acceptance: external object references are company-scoped, provider-extensible, visible in key issue surfaces, filterable where relevant, and covered by focused shared/server/UI tests. Related PR search: - No open duplicate PRs found for `external object references`. - Closed related prior attempt: #4556. ## What Changed - Added shared external-object contracts, validators, status/liveness helpers, and plugin protocol declarations. - Added database schema and additive migrations for external objects, source mentions, and display metadata. - Added server services/routes for detecting, syncing, summarizing, refreshing, and resolving external objects across issues, documents, comments, projects, and plugins. - Added a GitHub external-object provider plus plugin SDK authoring docs. - Wired UI presentation across markdown links, comments, issue chat, documents, properties, related work, issue rows, filters, inbox/sidebar badges, and Storybook stories. - Rebasing cleanup: moved the branch onto current `master`, repaired stale worktree provision config, hardened environment-sensitive tests/mocks, and removed committed screenshot artifacts from the PR branch to keep the reviewable file set below tool limits. ## Verification - `pnpm exec vitest run packages/shared/src/external-objects.test.ts server/src/__tests__/external-object-routes.test.ts server/src/__tests__/external-objects-service.test.ts ui/src/components/ExternalObjectPill.test.tsx ui/src/lib/external-objects.test.ts` passed after rebasing: 5 files, 56 tests. - Historical branch verification before this PR creation included `pnpm test:run`, `pnpm -r typecheck`, and `pnpm build`; this PR body does not claim those were rerun after the final rebase. ## Risks - Medium: this adds a new cross-surface sync path on issue/document/comment writes. The implementation uses safe sync wrappers so external-object failures warn instead of blocking core mutations. - Medium: the migrations introduce new tables and indexes. They are additive and company-scoped. - Medium: provider-specific URL parsing can miss or misclassify edge cases. Shared canonicalization tests and provider tests cover current GitHub shapes. - Low: UI badge/filter behavior could add visual noise for object-heavy issues; component tests and Storybook stories cover the intended surfaces. > Roadmap checked: `ROADMAP.md` references the plugin system as the current extension path and does not list a duplicate core feature. Related long-range docs discuss external references, work products, preview URLs, and plugin extension points; this PR implements the scoped external-object reference foundation. ## Model Used OpenAI Codex, GPT-5 coding-agent runtime, with shell and GitHub CLI tool use. Reasoning mode: medium. Exact deployed runtime model ID and context window were not exposed in the environment. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
cd38c150b0
commit
2dbaf4a7fa
97 files changed
+8217
-84
No files matched your search
@@ -358,6 +358,53 @@ export const DOCUMENT_ANNOTATION_ANCHOR_CONFIDENCES = [
|
||||
export type DocumentAnnotationAnchorConfidence =
|
||||
(typeof DOCUMENT_ANNOTATION_ANCHOR_CONFIDENCES)[number];
|
||||
|
||||
export const EXTERNAL_OBJECT_STATUS_CATEGORIES = [
|
||||
"unknown",
|
||||
"open",
|
||||
"waiting",
|
||||
"running",
|
||||
"succeeded",
|
||||
"failed",
|
||||
"blocked",
|
||||
"closed",
|
||||
"archived",
|
||||
"auth_required",
|
||||
"unreachable",
|
||||
] as const;
|
||||
export type ExternalObjectStatusCategory = (typeof EXTERNAL_OBJECT_STATUS_CATEGORIES)[number];
|
||||
|
||||
export const EXTERNAL_OBJECT_STATUS_TONES = [
|
||||
"neutral",
|
||||
"info",
|
||||
"success",
|
||||
"warning",
|
||||
"danger",
|
||||
"muted",
|
||||
] as const;
|
||||
export type ExternalObjectStatusTone = (typeof EXTERNAL_OBJECT_STATUS_TONES)[number];
|
||||
|
||||
export const EXTERNAL_OBJECT_LIVENESS_STATES = [
|
||||
"unknown",
|
||||
"fresh",
|
||||
"stale",
|
||||
"auth_required",
|
||||
"unreachable",
|
||||
] as const;
|
||||
export type ExternalObjectLivenessState = (typeof EXTERNAL_OBJECT_LIVENESS_STATES)[number];
|
||||
|
||||
export const EXTERNAL_OBJECT_MENTION_SOURCE_KINDS = [
|
||||
"title",
|
||||
"description",
|
||||
"comment",
|
||||
"document",
|
||||
"property",
|
||||
"plugin",
|
||||
] as const;
|
||||
export type ExternalObjectMentionSourceKind = (typeof EXTERNAL_OBJECT_MENTION_SOURCE_KINDS)[number];
|
||||
|
||||
export const EXTERNAL_OBJECT_MENTION_CONFIDENCES = ["exact", "likely", "possible"] as const;
|
||||
export type ExternalObjectMentionConfidence = (typeof EXTERNAL_OBJECT_MENTION_CONFIDENCES)[number];
|
||||
|
||||
export const ISSUE_EXECUTION_POLICY_MODES = ["normal", "auto"] as const;
|
||||
export type IssueExecutionPolicyMode = (typeof ISSUE_EXECUTION_POLICY_MODES)[number];
|
||||
|
||||
@@ -677,6 +724,7 @@ export const LIVE_EVENT_TYPES = [
|
||||
"heartbeat.run.log",
|
||||
"agent.status",
|
||||
"activity.logged",
|
||||
"external_object.updated",
|
||||
"plugin.ui.updated",
|
||||
"plugin.worker.crashed",
|
||||
"plugin.worker.restarted",
|
||||
@@ -851,6 +899,10 @@ export const PLUGIN_CAPABILITIES = [
|
||||
"telemetry.track",
|
||||
"database.namespace.migrate",
|
||||
"database.namespace.write",
|
||||
"external.objects.detect",
|
||||
"external.objects.read",
|
||||
"external.objects.write",
|
||||
"external.objects.refresh",
|
||||
// Plugin State
|
||||
"plugin.state.read",
|
||||
"plugin.state.write",
|
||||
|
||||
@@ -0,0 +1,217 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { parseIssueReferenceHref } from "./issue-references.js";
|
||||
import type {
|
||||
ExternalObjectCanonicalIdentity,
|
||||
ExternalObjectCanonicalUrl,
|
||||
ExternalObjectMentionSource,
|
||||
ExternalObjectUrlCanonicalizationOptions,
|
||||
ExternalObjectUrlMatch,
|
||||
} from "./external-objects.js";
|
||||
|
||||
const EXTERNAL_URL_TOKEN_RE = /https?:\/\/[^\s<>()]+/gi;
|
||||
|
||||
function preserveNewlinesAsWhitespace(value: string) {
|
||||
return value.replace(/[^\n]/g, " ");
|
||||
}
|
||||
|
||||
function stripMarkdownCode(markdown: string): string {
|
||||
if (!markdown) return "";
|
||||
|
||||
let output = "";
|
||||
let index = 0;
|
||||
|
||||
while (index < markdown.length) {
|
||||
const remaining = markdown.slice(index);
|
||||
const fenceMatch = /^(?:```+|~~~+)/.exec(remaining);
|
||||
const atLineStart = index === 0 || markdown[index - 1] === "\n";
|
||||
|
||||
if (atLineStart && fenceMatch) {
|
||||
const fence = fenceMatch[0]!;
|
||||
const blockStart = index;
|
||||
index += fence.length;
|
||||
while (index < markdown.length && markdown[index] !== "\n") index += 1;
|
||||
if (index < markdown.length) index += 1;
|
||||
|
||||
while (index < markdown.length) {
|
||||
const lineStart = index === 0 || markdown[index - 1] === "\n";
|
||||
if (lineStart && markdown.startsWith(fence, index)) {
|
||||
index += fence.length;
|
||||
while (index < markdown.length && markdown[index] !== "\n") index += 1;
|
||||
if (index < markdown.length) index += 1;
|
||||
break;
|
||||
}
|
||||
index += 1;
|
||||
}
|
||||
|
||||
output += preserveNewlinesAsWhitespace(markdown.slice(blockStart, index));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (markdown[index] === "`") {
|
||||
let tickCount = 1;
|
||||
while (index + tickCount < markdown.length && markdown[index + tickCount] === "`") {
|
||||
tickCount += 1;
|
||||
}
|
||||
const fence = "`".repeat(tickCount);
|
||||
const inlineStart = index;
|
||||
index += tickCount;
|
||||
const closeIndex = markdown.indexOf(fence, index);
|
||||
if (closeIndex === -1) {
|
||||
output += markdown.slice(inlineStart, inlineStart + tickCount);
|
||||
index = inlineStart + tickCount;
|
||||
continue;
|
||||
}
|
||||
index = closeIndex + tickCount;
|
||||
output += preserveNewlinesAsWhitespace(markdown.slice(inlineStart, index));
|
||||
continue;
|
||||
}
|
||||
|
||||
output += markdown[index]!;
|
||||
index += 1;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
function trimTrailingPunctuation(token: string): string {
|
||||
let trimmed = token;
|
||||
while (trimmed.length > 0) {
|
||||
const last = trimmed[trimmed.length - 1]!;
|
||||
if (!".,!?;:".includes(last) && last !== ")" && last !== "]") break;
|
||||
|
||||
if (
|
||||
(last === ")" && (trimmed.match(/\(/g)?.length ?? 0) >= (trimmed.match(/\)/g)?.length ?? 0))
|
||||
|| (last === "]" && (trimmed.match(/\[/g)?.length ?? 0) >= (trimmed.match(/\]/g)?.length ?? 0))
|
||||
) {
|
||||
break;
|
||||
}
|
||||
trimmed = trimmed.slice(0, -1);
|
||||
}
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
function sha256Hex(value: string): string {
|
||||
return createHash("sha256").update(value).digest("hex");
|
||||
}
|
||||
|
||||
function stableStringify(value: unknown): string {
|
||||
if (Array.isArray(value)) {
|
||||
return `[${value.map((entry) => stableStringify(entry)).join(",")}]`;
|
||||
}
|
||||
if (value && typeof value === "object") {
|
||||
const record = value as Record<string, unknown>;
|
||||
return `{${Object.keys(record)
|
||||
.sort()
|
||||
.map((key) => `${JSON.stringify(key)}:${stableStringify(record[key])}`)
|
||||
.join(",")}}`;
|
||||
}
|
||||
return JSON.stringify(value);
|
||||
}
|
||||
|
||||
function normalizePathname(pathname: string): string {
|
||||
return pathname || "/";
|
||||
}
|
||||
|
||||
export function findExternalObjectUrlMatches(markdown: string): ExternalObjectUrlMatch[] {
|
||||
if (!markdown) return [];
|
||||
|
||||
const scrubbed = stripMarkdownCode(markdown);
|
||||
const matches: ExternalObjectUrlMatch[] = [];
|
||||
let match: RegExpExecArray | null;
|
||||
const re = new RegExp(EXTERNAL_URL_TOKEN_RE);
|
||||
|
||||
while ((match = re.exec(scrubbed)) !== null) {
|
||||
const matchedText = trimTrailingPunctuation(match[0]);
|
||||
if (!matchedText || parseIssueReferenceHref(matchedText)) continue;
|
||||
|
||||
matches.push({
|
||||
index: match.index,
|
||||
length: matchedText.length,
|
||||
matchedText,
|
||||
});
|
||||
}
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
export function canonicalizeExternalObjectUrl(
|
||||
value: string,
|
||||
options: ExternalObjectUrlCanonicalizationOptions = {},
|
||||
): ExternalObjectCanonicalUrl | null {
|
||||
let url: URL;
|
||||
try {
|
||||
url = new URL(value.trim());
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (url.protocol !== "http:" && url.protocol !== "https:") return null;
|
||||
if (url.username || url.password) return null;
|
||||
|
||||
const scheme = url.protocol === "https:" ? "https" : "http";
|
||||
const path = normalizePathname(url.pathname);
|
||||
const sanitizedCanonicalUrl = `${scheme}://${url.host.toLowerCase()}${path}`;
|
||||
const identityQueryParams = new Set(options.identityQueryParams ?? []);
|
||||
const queryParamHashes: Record<string, string> = {};
|
||||
|
||||
for (const key of [...identityQueryParams].sort()) {
|
||||
const values = url.searchParams.getAll(key);
|
||||
if (values.length === 0) continue;
|
||||
queryParamHashes[key] = sha256Hex(values.join("\u0000"));
|
||||
}
|
||||
|
||||
const canonicalIdentity: ExternalObjectCanonicalIdentity = {
|
||||
scheme,
|
||||
host: url.host.toLowerCase(),
|
||||
path,
|
||||
...(Object.keys(queryParamHashes).length > 0 ? { queryParamHashes } : {}),
|
||||
};
|
||||
|
||||
return {
|
||||
sanitizedCanonicalUrl,
|
||||
sanitizedDisplayUrl: sanitizedCanonicalUrl,
|
||||
canonicalIdentity,
|
||||
canonicalIdentityHash: sha256Hex(stableStringify(canonicalIdentity)),
|
||||
redactedMatchedText: sanitizedCanonicalUrl,
|
||||
};
|
||||
}
|
||||
|
||||
export function extractExternalObjectCanonicalUrls(
|
||||
markdown: string,
|
||||
options: ExternalObjectUrlCanonicalizationOptions = {},
|
||||
): ExternalObjectCanonicalUrl[] {
|
||||
const seen = new Set<string>();
|
||||
const ordered: ExternalObjectCanonicalUrl[] = [];
|
||||
|
||||
for (const match of findExternalObjectUrlMatches(markdown)) {
|
||||
const canonical = canonicalizeExternalObjectUrl(match.matchedText, options);
|
||||
if (!canonical || seen.has(canonical.canonicalIdentityHash)) continue;
|
||||
seen.add(canonical.canonicalIdentityHash);
|
||||
ordered.push(canonical);
|
||||
}
|
||||
|
||||
return ordered;
|
||||
}
|
||||
|
||||
export function buildExternalObjectScopedIdentityKey(args: {
|
||||
companyId: string;
|
||||
providerKey: string;
|
||||
objectType: string;
|
||||
canonicalIdentityHash: string;
|
||||
}): string {
|
||||
return [args.companyId, args.providerKey, args.objectType, args.canonicalIdentityHash].join(":");
|
||||
}
|
||||
|
||||
export function buildExternalObjectMentionSourceKey(source: Required<Pick<
|
||||
ExternalObjectMentionSource,
|
||||
"companyId" | "sourceIssueId" | "sourceKind"
|
||||
>> & ExternalObjectMentionSource): string {
|
||||
return [
|
||||
source.companyId,
|
||||
source.sourceIssueId,
|
||||
source.sourceKind,
|
||||
source.sourceRecordId ?? "",
|
||||
source.documentKey ?? "",
|
||||
source.propertyKey ?? "",
|
||||
].join(":");
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { formatExternalObjectMentionSourceLabel } from "./external-objects.js";
|
||||
import {
|
||||
buildExternalObjectMentionSourceKey,
|
||||
buildExternalObjectScopedIdentityKey,
|
||||
canonicalizeExternalObjectUrl,
|
||||
extractExternalObjectCanonicalUrls,
|
||||
findExternalObjectUrlMatches,
|
||||
} from "./external-objects-server.js";
|
||||
import { externalObjectProviderKeySchema, externalObjectTypeSchema } from "./validators/external-object.js";
|
||||
|
||||
describe("external object references", () => {
|
||||
it("extracts external urls without changing internal issue reference behavior", () => {
|
||||
expect(
|
||||
findExternalObjectUrlMatches(
|
||||
"See PAP-1, /issues/PAP-2, https://paperclip.ing/PAP/issues/PAP-3, and https://github.com/acme/app/pull/4.",
|
||||
),
|
||||
).toEqual([{ index: 70, length: 34, matchedText: "https://github.com/acme/app/pull/4" }]);
|
||||
});
|
||||
|
||||
it("ignores urls inside inline and fenced code", () => {
|
||||
const markdown = [
|
||||
"Use https://github.com/acme/app/pull/1 here.",
|
||||
"`https://github.com/acme/app/pull/2` should not count.",
|
||||
"```",
|
||||
"https://github.com/acme/app/pull/3",
|
||||
"```",
|
||||
].join("\n");
|
||||
|
||||
expect(findExternalObjectUrlMatches(markdown).map((match) => match.matchedText)).toEqual([
|
||||
"https://github.com/acme/app/pull/1",
|
||||
]);
|
||||
});
|
||||
|
||||
it("canonicalizes urls by stripping query and fragment by default", () => {
|
||||
expect(canonicalizeExternalObjectUrl("HTTPS://GitHub.com/acme/app/pull/1?token=secret#discussion")).toMatchObject({
|
||||
sanitizedCanonicalUrl: "https://github.com/acme/app/pull/1",
|
||||
sanitizedDisplayUrl: "https://github.com/acme/app/pull/1",
|
||||
redactedMatchedText: "https://github.com/acme/app/pull/1",
|
||||
canonicalIdentity: {
|
||||
scheme: "https",
|
||||
host: "github.com",
|
||||
path: "/acme/app/pull/1",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects urls with userinfo", () => {
|
||||
expect(canonicalizeExternalObjectUrl("https://token:secret@github.com/acme/app/pull/1")).toBeNull();
|
||||
});
|
||||
|
||||
it("hashes provider-required query identity values without storing plaintext", () => {
|
||||
const first = canonicalizeExternalObjectUrl("https://deploy.test/run?id=secret-run&token=drop", {
|
||||
identityQueryParams: ["id"],
|
||||
});
|
||||
const second = canonicalizeExternalObjectUrl("https://deploy.test/run?id=secret-run&token=other", {
|
||||
identityQueryParams: ["id"],
|
||||
});
|
||||
|
||||
expect(first?.sanitizedCanonicalUrl).toBe("https://deploy.test/run");
|
||||
expect(first?.canonicalIdentity.queryParamHashes?.id).toHaveLength(64);
|
||||
expect(first?.canonicalIdentity.queryParamHashes?.id).not.toContain("secret-run");
|
||||
expect(second?.canonicalIdentityHash).toBe(first?.canonicalIdentityHash);
|
||||
});
|
||||
|
||||
it("dedupes extracted canonical urls by canonical identity", () => {
|
||||
expect(
|
||||
extractExternalObjectCanonicalUrls(
|
||||
"https://github.com/acme/app/pull/1?token=a and https://github.com/acme/app/pull/1#discussion",
|
||||
).map((entry) => entry.sanitizedCanonicalUrl),
|
||||
).toEqual(["https://github.com/acme/app/pull/1"]);
|
||||
});
|
||||
|
||||
it("includes company id in scoped object identity keys", () => {
|
||||
const base = {
|
||||
providerKey: "github",
|
||||
objectType: "pull_request",
|
||||
canonicalIdentityHash: "hash",
|
||||
};
|
||||
|
||||
expect(buildExternalObjectScopedIdentityKey({ companyId: "company-a", ...base })).not.toBe(
|
||||
buildExternalObjectScopedIdentityKey({ companyId: "company-b", ...base }),
|
||||
);
|
||||
});
|
||||
|
||||
it("builds source keys for replacing mentions from the same source", () => {
|
||||
const oldMentionSource = buildExternalObjectMentionSourceKey({
|
||||
companyId: "company-a",
|
||||
sourceIssueId: "issue-1",
|
||||
sourceKind: "comment",
|
||||
sourceRecordId: "comment-1",
|
||||
});
|
||||
const newMentionSource = buildExternalObjectMentionSourceKey({
|
||||
companyId: "company-a",
|
||||
sourceIssueId: "issue-1",
|
||||
sourceKind: "comment",
|
||||
sourceRecordId: "comment-1",
|
||||
});
|
||||
const anotherCompanySource = buildExternalObjectMentionSourceKey({
|
||||
companyId: "company-b",
|
||||
sourceIssueId: "issue-1",
|
||||
sourceKind: "comment",
|
||||
sourceRecordId: "comment-1",
|
||||
});
|
||||
|
||||
expect(newMentionSource).toBe(oldMentionSource);
|
||||
expect(anotherCompanySource).not.toBe(oldMentionSource);
|
||||
});
|
||||
|
||||
it("formats stable source labels", () => {
|
||||
expect(formatExternalObjectMentionSourceLabel({ sourceKind: "title" })).toBe("Title");
|
||||
expect(formatExternalObjectMentionSourceLabel({ sourceKind: "document", documentKey: "plan" })).toBe(
|
||||
"Document: plan",
|
||||
);
|
||||
expect(formatExternalObjectMentionSourceLabel({ sourceKind: "property", propertyKey: "pr" })).toBe(
|
||||
"Property: pr",
|
||||
);
|
||||
});
|
||||
|
||||
it("validates provider keys and object types", () => {
|
||||
expect(externalObjectProviderKeySchema.parse("github.enterprise")).toBe("github.enterprise");
|
||||
expect(externalObjectTypeSchema.parse("pull_request")).toBe("pull_request");
|
||||
expect(externalObjectProviderKeySchema.safeParse("GitHub").success).toBe(false);
|
||||
expect(externalObjectTypeSchema.safeParse("pull-request").success).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,52 @@
|
||||
import type { ExternalObjectMentionSourceKind } from "./constants.js";
|
||||
|
||||
export interface ExternalObjectUrlMatch {
|
||||
index: number;
|
||||
length: number;
|
||||
matchedText: string;
|
||||
}
|
||||
|
||||
export interface ExternalObjectCanonicalIdentity {
|
||||
scheme: "http" | "https";
|
||||
host: string;
|
||||
path: string;
|
||||
queryParamHashes?: Record<string, string>;
|
||||
}
|
||||
|
||||
export interface ExternalObjectUrlCanonicalizationOptions {
|
||||
identityQueryParams?: readonly string[];
|
||||
}
|
||||
|
||||
export interface ExternalObjectCanonicalUrl {
|
||||
sanitizedCanonicalUrl: string;
|
||||
sanitizedDisplayUrl: string;
|
||||
canonicalIdentity: ExternalObjectCanonicalIdentity;
|
||||
canonicalIdentityHash: string;
|
||||
redactedMatchedText: string;
|
||||
}
|
||||
|
||||
export interface ExternalObjectMentionSource {
|
||||
companyId?: string;
|
||||
sourceIssueId?: string;
|
||||
sourceKind: ExternalObjectMentionSourceKind;
|
||||
sourceRecordId?: string | null;
|
||||
documentKey?: string | null;
|
||||
propertyKey?: string | null;
|
||||
}
|
||||
|
||||
export function formatExternalObjectMentionSourceLabel(source: ExternalObjectMentionSource): string {
|
||||
switch (source.sourceKind) {
|
||||
case "title":
|
||||
return "Title";
|
||||
case "description":
|
||||
return "Description";
|
||||
case "comment":
|
||||
return "Comment";
|
||||
case "document":
|
||||
return source.documentKey ? `Document: ${source.documentKey}` : "Document";
|
||||
case "property":
|
||||
return source.propertyKey ? `Property: ${source.propertyKey}` : "Property";
|
||||
case "plugin":
|
||||
return "Plugin";
|
||||
}
|
||||
}
|
||||
@@ -92,6 +92,11 @@ export {
|
||||
DOCUMENT_ANNOTATION_THREAD_STATUSES,
|
||||
DOCUMENT_ANNOTATION_ANCHOR_STATES,
|
||||
DOCUMENT_ANNOTATION_ANCHOR_CONFIDENCES,
|
||||
EXTERNAL_OBJECT_STATUS_CATEGORIES,
|
||||
EXTERNAL_OBJECT_STATUS_TONES,
|
||||
EXTERNAL_OBJECT_LIVENESS_STATES,
|
||||
EXTERNAL_OBJECT_MENTION_SOURCE_KINDS,
|
||||
EXTERNAL_OBJECT_MENTION_CONFIDENCES,
|
||||
ISSUE_EXECUTION_POLICY_MODES,
|
||||
ISSUE_EXECUTION_STAGE_TYPES,
|
||||
ISSUE_MONITOR_SCHEDULED_BY,
|
||||
@@ -217,6 +222,11 @@ export {
|
||||
type DocumentAnnotationThreadStatus,
|
||||
type DocumentAnnotationAnchorState,
|
||||
type DocumentAnnotationAnchorConfidence,
|
||||
type ExternalObjectStatusCategory,
|
||||
type ExternalObjectStatusTone,
|
||||
type ExternalObjectLivenessState,
|
||||
type ExternalObjectMentionSourceKind,
|
||||
type ExternalObjectMentionConfidence,
|
||||
type IssueExecutionPolicyMode,
|
||||
type IssueExecutionStageType,
|
||||
type IssueMonitorScheduledBy,
|
||||
@@ -522,6 +532,11 @@ export type {
|
||||
DocumentTextRange,
|
||||
UpdateDocumentAnnotationThreadRequest,
|
||||
AttachmentArtifactWorkProductMetadata,
|
||||
ExternalObject,
|
||||
ExternalObjectMention,
|
||||
ExternalObjectMentionGroup,
|
||||
ExternalObjectSummary,
|
||||
ExternalObjectSummaryItem,
|
||||
Issue,
|
||||
IssueAssigneeAdapterOverrides,
|
||||
IssueBlockerAttention,
|
||||
@@ -786,6 +801,8 @@ export type {
|
||||
PluginDatabaseDeclaration,
|
||||
PluginApiRouteCompanyResolution,
|
||||
PluginApiRouteDeclaration,
|
||||
PluginObjectReferenceRefreshPolicy,
|
||||
PluginObjectReferenceProviderDeclaration,
|
||||
PaperclipPluginManifestV1,
|
||||
PluginRecord,
|
||||
PluginDatabaseNamespaceRecord,
|
||||
@@ -829,6 +846,15 @@ export {
|
||||
type VerifyDocumentAnchorSelectorResult,
|
||||
} from "./document-anchors.js";
|
||||
|
||||
export {
|
||||
formatExternalObjectMentionSourceLabel,
|
||||
type ExternalObjectCanonicalIdentity,
|
||||
type ExternalObjectCanonicalUrl,
|
||||
type ExternalObjectMentionSource,
|
||||
type ExternalObjectUrlCanonicalizationOptions,
|
||||
type ExternalObjectUrlMatch,
|
||||
} from "./external-objects.js";
|
||||
|
||||
export {
|
||||
sidebarOrderPreferenceSchema,
|
||||
upsertSidebarOrderPreferenceSchema,
|
||||
@@ -924,11 +950,24 @@ export {
|
||||
feedbackTargetTypeSchema,
|
||||
feedbackTraceStatusSchema,
|
||||
feedbackVoteValueSchema,
|
||||
externalObjectStatusCategorySchema,
|
||||
externalObjectStatusToneSchema,
|
||||
externalObjectLivenessStateSchema,
|
||||
externalObjectMentionSourceKindSchema,
|
||||
externalObjectMentionConfidenceSchema,
|
||||
externalObjectProviderKeySchema,
|
||||
externalObjectTypeSchema,
|
||||
externalObjectCanonicalIdentitySchema,
|
||||
externalObjectMentionSourceSchema,
|
||||
upsertIssueFeedbackVoteSchema,
|
||||
type CreateCompany,
|
||||
type UpdateCompany,
|
||||
type UpdateCompanyBranding,
|
||||
type UpsertIssueFeedbackVote,
|
||||
type ExternalObjectCanonicalIdentityInput,
|
||||
type ExternalObjectMentionSourceInput,
|
||||
type ExternalObjectProviderKeyInput,
|
||||
type ExternalObjectTypeInput,
|
||||
environmentDriverSchema,
|
||||
environmentStatusSchema,
|
||||
environmentLeaseStatusSchema,
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
import type {
|
||||
ExternalObjectLivenessState,
|
||||
ExternalObjectMentionConfidence,
|
||||
ExternalObjectMentionSourceKind,
|
||||
ExternalObjectStatusCategory,
|
||||
ExternalObjectStatusTone,
|
||||
} from "../constants.js";
|
||||
|
||||
export interface ExternalObject {
|
||||
id: string;
|
||||
companyId: string;
|
||||
providerKey: string;
|
||||
pluginId: string | null;
|
||||
objectType: string;
|
||||
externalId: string;
|
||||
sanitizedCanonicalUrl: string | null;
|
||||
canonicalIdentityHash: string | null;
|
||||
displayKey?: string | null;
|
||||
iconKey?: string | null;
|
||||
displayTitle: string | null;
|
||||
statusKey: string | null;
|
||||
statusLabel: string | null;
|
||||
statusIconKey?: string | null;
|
||||
statusCategory: ExternalObjectStatusCategory;
|
||||
statusTone: ExternalObjectStatusTone;
|
||||
liveness: ExternalObjectLivenessState;
|
||||
isTerminal: boolean;
|
||||
data: Record<string, unknown>;
|
||||
remoteVersion: string | null;
|
||||
etag: string | null;
|
||||
lastResolvedAt: string | null;
|
||||
lastChangedAt: string | null;
|
||||
lastErrorAt: string | null;
|
||||
nextRefreshAt: string | null;
|
||||
lastErrorCode: string | null;
|
||||
lastErrorMessage: string | null;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface ExternalObjectMention {
|
||||
id: string;
|
||||
companyId: string;
|
||||
sourceIssueId: string;
|
||||
sourceKind: ExternalObjectMentionSourceKind;
|
||||
sourceRecordId: string | null;
|
||||
documentKey: string | null;
|
||||
propertyKey: string | null;
|
||||
matchedTextRedacted: string | null;
|
||||
sanitizedDisplayUrl: string | null;
|
||||
canonicalIdentityHash: string | null;
|
||||
canonicalIdentity: Record<string, unknown> | null;
|
||||
objectId: string | null;
|
||||
providerKey: string | null;
|
||||
detectorKey: string | null;
|
||||
objectType: string | null;
|
||||
confidence: ExternalObjectMentionConfidence;
|
||||
createdByPluginId: string | null;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface ExternalObjectMentionGroup {
|
||||
object: ExternalObject | null;
|
||||
mentions: ExternalObjectMention[];
|
||||
mentionCount: number;
|
||||
sourceLabels: string[];
|
||||
}
|
||||
|
||||
export interface ExternalObjectSummaryItem {
|
||||
id: string;
|
||||
providerKey: string;
|
||||
objectType: string;
|
||||
displayKey?: string | null;
|
||||
iconKey?: string | null;
|
||||
displayTitle: string | null;
|
||||
statusIconKey?: string | null;
|
||||
statusCategory: ExternalObjectStatusCategory;
|
||||
statusTone: ExternalObjectStatusTone;
|
||||
liveness: ExternalObjectLivenessState;
|
||||
isTerminal: boolean;
|
||||
}
|
||||
|
||||
export interface ExternalObjectSummary {
|
||||
total: number;
|
||||
byStatusCategory: Record<string, number>;
|
||||
byLiveness: Record<string, number>;
|
||||
highestSeverity: ExternalObjectStatusTone;
|
||||
staleCount: number;
|
||||
authRequiredCount: number;
|
||||
unreachableCount: number;
|
||||
objects: ExternalObjectSummaryItem[];
|
||||
}
|
||||
@@ -265,6 +265,14 @@ export type {
|
||||
CompanyArtifactSource,
|
||||
CompanyArtifactsResponse,
|
||||
} from "./artifact.js";
|
||||
|
||||
export type {
|
||||
ExternalObject,
|
||||
ExternalObjectMention,
|
||||
ExternalObjectMentionGroup,
|
||||
ExternalObjectSummary,
|
||||
ExternalObjectSummaryItem,
|
||||
} from "./external-object.js";
|
||||
export type {
|
||||
Issue,
|
||||
IssueWorkMode,
|
||||
@@ -551,6 +559,8 @@ export type {
|
||||
PluginDatabaseDeclaration,
|
||||
PluginApiRouteCompanyResolution,
|
||||
PluginApiRouteDeclaration,
|
||||
PluginObjectReferenceRefreshPolicy,
|
||||
PluginObjectReferenceProviderDeclaration,
|
||||
PaperclipPluginManifestV1,
|
||||
PluginRecord,
|
||||
PluginDatabaseNamespaceRecord,
|
||||
|
||||
@@ -53,6 +53,7 @@ export interface InstanceExperimentalSettings {
|
||||
enableIssuePlanDecompositions: boolean;
|
||||
enableExperimentalFileViewer: boolean;
|
||||
enableCloudSync: boolean;
|
||||
enableExternalObjects: boolean;
|
||||
autoRestartDevServerWhenIdle: boolean;
|
||||
enableIssueGraphLivenessAutoRecovery: boolean;
|
||||
issueGraphLivenessAutoRecoveryLookbackHours: number;
|
||||
|
||||
@@ -504,6 +504,31 @@ export interface PluginApiRouteDeclaration {
|
||||
companyResolution?: PluginApiRouteCompanyResolution;
|
||||
}
|
||||
|
||||
export interface PluginObjectReferenceRefreshPolicy {
|
||||
/** Default freshness window for resolved objects from this provider. */
|
||||
defaultTtlSeconds?: number;
|
||||
/** UI-visible staleness window. Core still stores liveness separately from remote status. */
|
||||
staleAfterSeconds?: number;
|
||||
}
|
||||
|
||||
export interface PluginObjectReferenceProviderDeclaration {
|
||||
/** Stable provider key such as "github", "linear", or "mocktracker". */
|
||||
providerKey: string;
|
||||
/** Human-readable provider name shown in operator-facing surfaces. */
|
||||
displayName: string;
|
||||
/** Provider object types this plugin can detect and resolve. */
|
||||
objectTypes: string[];
|
||||
/**
|
||||
* Human-readable URL patterns this provider recognizes.
|
||||
* These are metadata for operators and docs; workers still perform detection.
|
||||
*/
|
||||
urlPatterns?: string[];
|
||||
/** Optional default refresh behavior for this provider. */
|
||||
refreshPolicy?: PluginObjectReferenceRefreshPolicy;
|
||||
/** Optional webhook endpoint keys declared under `webhooks` that can refresh these objects. */
|
||||
webhookEndpointKeys?: string[];
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Plugin Manifest V1
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -570,6 +595,8 @@ export interface PaperclipPluginManifestV1 {
|
||||
skills?: PluginManagedSkillDeclaration[];
|
||||
/** Trusted local folders this plugin can configure and access by stable key. */
|
||||
localFolders?: PluginLocalFolderDeclaration[];
|
||||
/** External object reference providers this plugin contributes. */
|
||||
objectReferences?: PluginObjectReferenceProviderDeclaration[];
|
||||
/**
|
||||
* Legacy top-level launcher declarations.
|
||||
* Prefer `ui.launchers` for new manifests.
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { z } from "zod";
|
||||
import {
|
||||
EXTERNAL_OBJECT_LIVENESS_STATES,
|
||||
EXTERNAL_OBJECT_MENTION_CONFIDENCES,
|
||||
EXTERNAL_OBJECT_MENTION_SOURCE_KINDS,
|
||||
EXTERNAL_OBJECT_STATUS_CATEGORIES,
|
||||
EXTERNAL_OBJECT_STATUS_TONES,
|
||||
} from "../constants.js";
|
||||
|
||||
export const externalObjectStatusCategorySchema = z.enum(EXTERNAL_OBJECT_STATUS_CATEGORIES);
|
||||
export const externalObjectStatusToneSchema = z.enum(EXTERNAL_OBJECT_STATUS_TONES);
|
||||
export const externalObjectLivenessStateSchema = z.enum(EXTERNAL_OBJECT_LIVENESS_STATES);
|
||||
export const externalObjectMentionSourceKindSchema = z.enum(EXTERNAL_OBJECT_MENTION_SOURCE_KINDS);
|
||||
export const externalObjectMentionConfidenceSchema = z.enum(EXTERNAL_OBJECT_MENTION_CONFIDENCES);
|
||||
export const externalObjectProviderKeySchema = z.string().trim().min(1).max(80).regex(/^[a-z][a-z0-9_.-]*$/);
|
||||
export const externalObjectTypeSchema = z.string().trim().min(1).max(80).regex(/^[a-z][a-z0-9_]*$/);
|
||||
|
||||
export const externalObjectCanonicalIdentitySchema = z
|
||||
.object({
|
||||
scheme: z.enum(["http", "https"]),
|
||||
host: z.string().trim().min(1),
|
||||
path: z.string().trim().min(1),
|
||||
queryParamHashes: z.record(z.string().regex(/^[a-f0-9]{64}$/)).optional(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
export const externalObjectMentionSourceSchema = z
|
||||
.object({
|
||||
sourceKind: externalObjectMentionSourceKindSchema,
|
||||
documentKey: z.string().trim().min(1).optional().nullable(),
|
||||
propertyKey: z.string().trim().min(1).optional().nullable(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
export type ExternalObjectCanonicalIdentityInput = z.infer<typeof externalObjectCanonicalIdentitySchema>;
|
||||
export type ExternalObjectMentionSourceInput = z.infer<typeof externalObjectMentionSourceSchema>;
|
||||
export type ExternalObjectProviderKeyInput = z.infer<typeof externalObjectProviderKeySchema>;
|
||||
export type ExternalObjectTypeInput = z.infer<typeof externalObjectTypeSchema>;
|
||||
@@ -59,6 +59,22 @@ export {
|
||||
updateResourceMembershipSchema,
|
||||
type UpdateResourceMembership,
|
||||
} from "./resource-memberships.js";
|
||||
|
||||
export {
|
||||
externalObjectStatusCategorySchema,
|
||||
externalObjectStatusToneSchema,
|
||||
externalObjectLivenessStateSchema,
|
||||
externalObjectMentionSourceKindSchema,
|
||||
externalObjectMentionConfidenceSchema,
|
||||
externalObjectProviderKeySchema,
|
||||
externalObjectTypeSchema,
|
||||
externalObjectCanonicalIdentitySchema,
|
||||
externalObjectMentionSourceSchema,
|
||||
type ExternalObjectCanonicalIdentityInput,
|
||||
type ExternalObjectMentionSourceInput,
|
||||
type ExternalObjectProviderKeyInput,
|
||||
type ExternalObjectTypeInput,
|
||||
} from "./external-object.js";
|
||||
export {
|
||||
companySkillSourceTypeSchema,
|
||||
companySkillTrustLevelSchema,
|
||||
|
||||
@@ -47,6 +47,7 @@ export const instanceExperimentalSettingsSchema = z.object({
|
||||
enableIssuePlanDecompositions: z.boolean().default(false),
|
||||
enableExperimentalFileViewer: z.boolean().default(false),
|
||||
enableCloudSync: z.boolean().default(false),
|
||||
enableExternalObjects: z.boolean().default(false),
|
||||
autoRestartDevServerWhenIdle: z.boolean().default(false),
|
||||
enableIssueGraphLivenessAutoRecovery: z.boolean().default(false),
|
||||
issueGraphLivenessAutoRecoveryLookbackHours: z
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
ISSUE_SURFACE_VISIBILITIES,
|
||||
} from "../constants.js";
|
||||
import { routineVariableSchema } from "./routine.js";
|
||||
import { externalObjectProviderKeySchema, externalObjectTypeSchema } from "./external-object.js";
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// JSON Schema placeholder – a permissive validator for JSON Schema objects
|
||||
@@ -568,6 +569,55 @@ export const pluginApiRouteDeclarationSchema = z.object({
|
||||
|
||||
export type PluginApiRouteDeclarationInput = z.infer<typeof pluginApiRouteDeclarationSchema>;
|
||||
|
||||
export const pluginObjectReferenceRefreshPolicySchema = z.object({
|
||||
defaultTtlSeconds: z.number().int().positive().max(86_400).optional(),
|
||||
staleAfterSeconds: z.number().int().positive().max(604_800).optional(),
|
||||
}).superRefine((value, ctx) => {
|
||||
if (
|
||||
value.defaultTtlSeconds != null &&
|
||||
value.staleAfterSeconds != null &&
|
||||
value.staleAfterSeconds < value.defaultTtlSeconds
|
||||
) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "staleAfterSeconds must be greater than or equal to defaultTtlSeconds",
|
||||
path: ["staleAfterSeconds"],
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export const pluginObjectReferenceProviderDeclarationSchema = z.object({
|
||||
providerKey: externalObjectProviderKeySchema,
|
||||
displayName: z.string().min(1).max(100),
|
||||
objectTypes: z.array(externalObjectTypeSchema).min(1),
|
||||
urlPatterns: z.array(z.string().trim().min(1).max(500)).optional(),
|
||||
refreshPolicy: pluginObjectReferenceRefreshPolicySchema.optional(),
|
||||
webhookEndpointKeys: z.array(z.string().min(1)).optional(),
|
||||
}).superRefine((value, ctx) => {
|
||||
const duplicateObjectTypes = value.objectTypes.filter((type, i) => value.objectTypes.indexOf(type) !== i);
|
||||
if (duplicateObjectTypes.length > 0) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: `Duplicate objectTypes: ${[...new Set(duplicateObjectTypes)].join(", ")}`,
|
||||
path: ["objectTypes"],
|
||||
});
|
||||
}
|
||||
|
||||
const webhookKeys = value.webhookEndpointKeys ?? [];
|
||||
const duplicateWebhookKeys = webhookKeys.filter((key, i) => webhookKeys.indexOf(key) !== i);
|
||||
if (duplicateWebhookKeys.length > 0) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: `Duplicate webhookEndpointKeys: ${[...new Set(duplicateWebhookKeys)].join(", ")}`,
|
||||
path: ["webhookEndpointKeys"],
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export type PluginObjectReferenceProviderDeclarationInput = z.infer<
|
||||
typeof pluginObjectReferenceProviderDeclarationSchema
|
||||
>;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Plugin Manifest V1 schema
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -647,6 +697,7 @@ export const pluginManifestV1Schema = z.object({
|
||||
routines: z.array(pluginManagedRoutineDeclarationSchema).optional(),
|
||||
skills: z.array(pluginManagedSkillDeclarationSchema).optional(),
|
||||
localFolders: z.array(pluginLocalFolderDeclarationSchema).optional(),
|
||||
objectReferences: z.array(pluginObjectReferenceProviderDeclarationSchema).optional(),
|
||||
launchers: z.array(pluginLauncherDeclarationSchema).optional(),
|
||||
ui: z.object({
|
||||
slots: z.array(pluginUiSlotDeclarationSchema).min(1).optional(),
|
||||
@@ -787,6 +838,31 @@ export const pluginManifestV1Schema = z.object({
|
||||
}
|
||||
}
|
||||
|
||||
if (manifest.objectReferences && manifest.objectReferences.length > 0) {
|
||||
for (const capability of ["external.objects.detect", "external.objects.read"] as const) {
|
||||
if (!manifest.capabilities.includes(capability)) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: `Capability '${capability}' is required when objectReferences are declared`,
|
||||
path: ["capabilities"],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const declaredWebhookKeys = new Set((manifest.webhooks ?? []).map((webhook) => webhook.endpointKey));
|
||||
for (const [providerIndex, provider] of manifest.objectReferences.entries()) {
|
||||
for (const endpointKey of provider.webhookEndpointKeys ?? []) {
|
||||
if (!declaredWebhookKeys.has(endpointKey)) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: `objectReferences webhookEndpointKey "${endpointKey}" must match a declared webhook endpoint`,
|
||||
path: ["objectReferences", providerIndex, "webhookEndpointKeys"],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (manifest.database) {
|
||||
const requiredCapabilities = [
|
||||
"database.namespace.migrate",
|
||||
@@ -950,6 +1026,18 @@ export const pluginManifestV1Schema = z.object({
|
||||
}
|
||||
}
|
||||
|
||||
if (manifest.objectReferences) {
|
||||
const providerKeys = manifest.objectReferences.map((provider) => provider.providerKey);
|
||||
const duplicateProviders = providerKeys.filter((key, i) => providerKeys.indexOf(key) !== i);
|
||||
if (duplicateProviders.length > 0) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: `Duplicate object reference provider keys: ${[...new Set(duplicateProviders)].join(", ")}`,
|
||||
path: ["objectReferences"],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// UI slot ids must be unique within the plugin (namespaced at runtime)
|
||||
if (manifest.ui) {
|
||||
if (manifest.ui.slots) {
|
||||
|
||||
Reference in new issue
Block a user