feat: reuse integrations in custom widgets
This commit is contained in:
1 parent
c32a5317ca
commit
52c82f72db
49 files changed
+793
-269
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import { getCustomWidgetSourceAuthType } from "../src/core/request-schema";
|
||||
import { mkdir, writeFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
@@ -279,7 +280,7 @@ export function getDeterministicEvaluationIssues(
|
||||
message: `Use the verified source URL ${expectations.sourceBaseUrl}.`,
|
||||
});
|
||||
}
|
||||
const authType = typeof source?.auth === "string" ? source.auth : source?.auth.type;
|
||||
const authType = getCustomWidgetSourceAuthType(source);
|
||||
if (authType !== expectations.sourceAuth) {
|
||||
issues.push({
|
||||
path: ["sources", "default", "auth"],
|
||||
@@ -467,7 +468,7 @@ const getJudgeRuntimeContext = (widget: HomarrCustomWidgetV2) => {
|
||||
const sections = [getCustomWidgetSkillReference("runtime").content];
|
||||
const hasMutation = Object.values(widget.requests).some((request) => request.kind === "action");
|
||||
const hasProtectedSource = Object.values(widget.sources).some((source) => {
|
||||
const authType = typeof source.auth === "string" ? source.auth : source.auth.type;
|
||||
const authType = getCustomWidgetSourceAuthType(source);
|
||||
return authType !== "none";
|
||||
});
|
||||
if (hasMutation || hasProtectedSource) sections.push(getCustomWidgetSkillReference("security").content);
|
||||
|
||||
@@ -72,6 +72,8 @@ ${leanShape}
|
||||
|
||||
Sources are keyed by name and must include "default". Auth is "none", "bearer", "basic", {"type":"apiKeyHeader","name":"X-Api-Key"}, or {"type":"apiKeyQuery","name":"api_key"}. Use the stable public API URL for public services and a clear suggested URL for self-hosted services; Homarr asks the installer for their own server URL. Never put credentials in the manifest.
|
||||
|
||||
Existing Sonarr and Radarr integrations use {"type":"integration","integrationKind":"sonarr"} as a source, without baseUrl, networkScope, or auth. The installer selects their local integration. An MCP author can use integration_all to obtain a matching integrationId for preview/create. Integration URLs and credentials resolve server-side; exports remove integrationId. Integration methods other than GET must be manual actions.
|
||||
|
||||
Requests are keyed by ID. Defaults are source "default", kind "query", method "GET", query trigger "load", inherited auth, and permission "view" for queries or "modify" for actions. Actions are always manual. DELETE is valid only for actions, requires full permission, and receives confirmation automatically. Use {option:name} or {"$option":"name"} for saved options. Use {param:name} or {"$param":"name"} only for invocation-time params supplied by SubFetch, ActionButton, or ToggleSwitch. Load queries cannot use params. Values and primitive types are inferred from references; do not declare parameters or option bindings. Paths and query values must be primitive; JSON bodies may bind structured options.
|
||||
|
||||
Options are keyed by name. Every option has label, control, and default. Controls: text, textarea, number, switch, select, multiSelect, slider, date, time, color, icon, url, duration, timeZone, json. Select choices use \`"choices": [{"label":"...","value":"..."}]\`. Dynamic choices must use \`"choicesFrom": {"request":"requestId","itemsPath":"optional.path","valuePath":"id","labelPath":"name"}\`, never an object under \`choices\`. Options are configured outside the widget and read through \`options.name\`; a bound control writes only to \`inputs.name\` and never changes an option.
|
||||
|
||||
@@ -13,7 +13,7 @@ export const CUSTOM_WIDGET_SKILL_SOURCE_URL =
|
||||
"https://github.com/homarr-labs/homarr/tree/HEAD/.agents/skills/homarr-custom-widget";
|
||||
export const CUSTOM_WIDGET_SKILL_INSTALL_COMMAND =
|
||||
"npx skills add https://github.com/homarr-labs/homarr --skill homarr-custom-widget";
|
||||
export const CUSTOM_WIDGET_SKILL_VERSION = "2.9.0";
|
||||
export const CUSTOM_WIDGET_SKILL_VERSION = "2.10.0";
|
||||
export const CUSTOM_WIDGET_SKILL_REFERENCE_NAMES = ["schema", "runtime", "security"] as const;
|
||||
export type CustomWidgetSkillReferenceName = (typeof CUSTOM_WIDGET_SKILL_REFERENCE_NAMES)[number];
|
||||
|
||||
@@ -58,7 +58,7 @@ interface HomarrCustomWidgetV2 {
|
||||
}
|
||||
\`\`\`
|
||||
|
||||
The object key \`default\` is the required source ID; \`default\` is not a property on a source. Source properties are \`name?\`, \`baseUrl\`, \`networkScope\`, and \`auth?\`:
|
||||
\`sources.default\` is required. HTTP source properties: \`name?\`, \`baseUrl\`, \`networkScope\`, and \`auth?\`:
|
||||
|
||||
\`\`\`json
|
||||
{
|
||||
@@ -85,14 +85,17 @@ The object key \`default\` is the required source ID; \`default\` is not a prope
|
||||
}
|
||||
\`\`\`
|
||||
|
||||
Auth is \`none\`, \`bearer\`, \`basic\`, \`{ "type": "apiKeyHeader", "name": "X-Api-Key" }\`, or \`{ "type": "apiKeyQuery", "name": "api_key" }\`. A request defaults to source \`default\`, kind \`query\`, method \`GET\`, trigger \`load\`, inherited auth, and view permission. Set \`trigger: "manual"\` for a parameterized query. An action defaults to manual and modify permission. DELETE uses full permission and confirmation. Do not use \`load: false\`.
|
||||
Integration sources use \`{"type":"integration","integrationKind":"sonarr"}\` (Sonarr or Radarr). Bind a local \`integrationId\` from \`integration_all\`; exports omit it. Omit URL/auth fields. Paths append to the integration URL; non-GET requests must be actions.
|
||||
|
||||
Use stable real URLs for public APIs and clear suggested URLs for self-hosted services. Homarr collects the installer's server URL, network scope, and credentials as source setup; credentials remain outside the manifest.
|
||||
Auth: \`none\`, \`bearer\`, \`basic\`, \`{ "type": "apiKeyHeader", "name": "X-Api-Key" }\`, or \`{ "type": "apiKeyQuery", "name": "api_key" }\`. Requests default to source \`default\`, kind \`query\`, method \`GET\`, trigger \`load\`, inherited auth, and view permission. Parameterized queries need \`trigger: "manual"\`. Actions default to manual/modify; DELETE requires full permission and confirmation. Do not use \`load: false\`.
|
||||
|
||||
Paths use \`{option:name}\` and \`{param:name}\`; query/body references use \`{ "$option": "name" }\` and \`{ "$param": "name" }\`. Constants stay primitive (\`take: 10\`); \`$param\` is only for manual helpers, never load queries. Names and types are inferred.
|
||||
HTTP sources declare public URLs or self-hosted suggestions; installers configure their URL, network scope, and credentials separately.
|
||||
|
||||
Every option has \`label\`, \`control\`, and \`default\`. Optional fields are \`description\`, \`choices\`, \`choicesFrom\`, \`min\`, \`max\`, \`step\`, \`advanced\`, and \`group\`.
|
||||
Paths bind \`{option:name}\` and \`{param:name}\`; query/body references bind \`{ "$option": "name" }\` and \`{ "$param": "name" }\`. Use primitive constants (\`take: 10\`). \`$param\` is only for manual requests.
|
||||
|
||||
Options require \`label\`, \`control\`, and \`default\`. Optional fields: \`description\`, \`choices\`, \`choicesFrom\`, \`min\`, \`max\`, \`step\`, \`advanced\`, \`group\`.
|
||||
`,
|
||||
|
||||
"references/runtime.md": `# Runtime
|
||||
|
||||
Templates read \`data.requestId\`, \`status.requestId\`, \`options.name\`, and temporary \`inputs.name\`. Status is \`{ loading, ok, status, statusText, error }\`. Render load queries directly from \`data\` and \`status\` with \`RefreshButton\`; never wrap them in \`SubFetch\`.
|
||||
|
||||
@@ -104,6 +104,17 @@ type Definition = z.infer<typeof customWidgetDefinitionSchema>;
|
||||
|
||||
function validateRequests(definition: Definition, ctx: z.RefinementCtx) {
|
||||
for (const [requestId, request] of Object.entries(definition.requests)) {
|
||||
if (
|
||||
definition.sources[request.source]?.type === "integration" &&
|
||||
request.method !== "GET" &&
|
||||
request.kind !== "action"
|
||||
) {
|
||||
ctx.addIssue({
|
||||
code: "custom",
|
||||
path: ["requests", requestId, "kind"],
|
||||
message: "Integration requests with a method other than GET must be manual actions",
|
||||
});
|
||||
}
|
||||
if (!definition.sources[request.source]) {
|
||||
ctx.addIssue({
|
||||
code: "custom",
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { getCustomWidgetSourceAuthType } from "./request-schema";
|
||||
import type { HomarrCustomWidgetV2 } from "./custom-jsx-schema";
|
||||
import { customWidgetImportSchema } from "./custom-jsx-schema";
|
||||
|
||||
@@ -104,7 +105,7 @@ export function parseCustomWidgetClipboardDetailed(text: string): CustomWidgetPa
|
||||
if (removedIssues.length > 0) return { success: false, issues: removedIssues };
|
||||
const parsed = customWidgetImportSchema.safeParse(widget);
|
||||
if (!parsed.success) return { success: false, issues: zodIssues(parsed.error) };
|
||||
return { success: true, widget: parsed.data, warnings: [] };
|
||||
return { success: true, widget: exportCustomWidgetDefinition(parsed.data), warnings: [] };
|
||||
}
|
||||
|
||||
export function parseCustomWidgetAiResponse(text: string): CustomWidgetParseResult {
|
||||
@@ -157,17 +158,35 @@ export function getImportReview(value: unknown): ImportReview | null {
|
||||
const widget = parsed.data;
|
||||
return {
|
||||
name: widget.name,
|
||||
origins: Object.values(widget.sources).map((source) => new URL(source.baseUrl).origin),
|
||||
origins: Object.values(widget.sources).map((source) =>
|
||||
source.type === "integration" ? source.integrationKind : new URL(source.baseUrl).origin,
|
||||
),
|
||||
authTypes: [
|
||||
...new Set(
|
||||
Object.values(widget.sources).map((source) =>
|
||||
typeof source.auth === "string" ? source.auth : source.auth.type,
|
||||
source.type === "integration" ? "integration" : getCustomWidgetSourceAuthType(source),
|
||||
),
|
||||
),
|
||||
],
|
||||
networkScopes: [...new Set(Object.values(widget.sources).map((source) => source.networkScope))],
|
||||
networkScopes: [
|
||||
...new Set(Object.values(widget.sources).flatMap((source) => (source.networkScope ? [source.networkScope] : []))),
|
||||
],
|
||||
methods: [...new Set(Object.values(widget.requests).map((request) => request.method))],
|
||||
permissions: [...new Set(Object.values(widget.requests).map((request) => request.permission))],
|
||||
hasActions: Object.values(widget.requests).some((request) => request.kind === "action"),
|
||||
};
|
||||
}
|
||||
|
||||
/** Deployment bindings never travel with an exported or published widget. */
|
||||
export function exportCustomWidgetDefinition(widget: HomarrCustomWidgetV2): HomarrCustomWidgetV2 {
|
||||
return {
|
||||
...widget,
|
||||
sources: Object.fromEntries(
|
||||
Object.entries(widget.sources).map(([id, source]) => {
|
||||
if (source.type !== "integration") return [id, source];
|
||||
const { integrationId: _localBinding, ...portable } = source;
|
||||
return [id, portable];
|
||||
}),
|
||||
),
|
||||
};
|
||||
}
|
||||
@@ -41,7 +41,10 @@ const sourceUrlIssueMessages: Record<CustomWidgetSourceUrlIssue, string> = {
|
||||
queryOrFragment: "API source URLs cannot contain a query string or fragment",
|
||||
};
|
||||
|
||||
export const customWidgetSourceSchema = z.strictObject({
|
||||
export const customWidgetHttpSourceSchema = z.strictObject({
|
||||
type: z.literal("http").optional(),
|
||||
integrationKind: z.never().optional(),
|
||||
integrationId: z.never().optional(),
|
||||
name: z.string().trim().min(1).max(128).optional(),
|
||||
baseUrl: z
|
||||
.string()
|
||||
@@ -54,7 +57,26 @@ export const customWidgetSourceSchema = z.strictObject({
|
||||
networkScope: z.enum(customJsxNetworkScopes),
|
||||
auth: authSchema.default("none"),
|
||||
});
|
||||
export const customWidgetIntegrationKinds = ["sonarr", "radarr"] as const;
|
||||
export const customWidgetIntegrationSourceSchema = z.strictObject({
|
||||
type: z.literal("integration"),
|
||||
name: z.string().trim().min(1).max(128).optional(),
|
||||
integrationKind: z.enum(customWidgetIntegrationKinds),
|
||||
integrationId: z.string().min(1).max(100).optional(),
|
||||
baseUrl: z.never().optional(),
|
||||
networkScope: z.never().optional(),
|
||||
auth: z.never().optional(),
|
||||
});
|
||||
export const customWidgetSourceSchema = z.union([customWidgetHttpSourceSchema, customWidgetIntegrationSourceSchema]);
|
||||
export type CustomWidgetSource = z.infer<typeof customWidgetSourceSchema>;
|
||||
export type CustomWidgetHttpSource = z.infer<typeof customWidgetHttpSourceSchema>;
|
||||
export type CustomWidgetIntegrationSource = z.infer<typeof customWidgetIntegrationSourceSchema>;
|
||||
|
||||
export function getCustomWidgetSourceAuthType(source: { auth?: CustomWidgetHttpSource["auth"] } | undefined) {
|
||||
if (!source?.auth) return "none" as const;
|
||||
if (typeof source.auth === "string") return source.auth;
|
||||
return source.auth.type;
|
||||
}
|
||||
|
||||
export const customWidgetSourcesSchema = z
|
||||
.record(customWidgetIdentifierSchema, customWidgetSourceSchema)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { getCustomWidgetSourceAuthType } from "./request-schema";
|
||||
import type { CustomWidgetSource } from "./request-schema";
|
||||
import type { CustomWidgetSecretKind } from "./schema-types";
|
||||
|
||||
@@ -21,7 +22,7 @@ export function getCustomWidgetSecretRequirements(
|
||||
sources: Record<string, CustomWidgetSource>,
|
||||
): CustomWidgetSecretRequirement[] {
|
||||
return Object.entries(sources).flatMap(([sourceId, source]) => {
|
||||
const authType = typeof source.auth === "string" ? source.auth : source.auth.type;
|
||||
const authType = getCustomWidgetSourceAuthType(source);
|
||||
return getCustomWidgetRequiredSecretKinds(authType).map((kind) => ({
|
||||
sourceId,
|
||||
sourceName: source.name ?? sourceId,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { CustomWidgetSource } from "./request-schema";
|
||||
import { getCustomWidgetSourceAuthType } from "./request-schema";
|
||||
import type { CustomJsxNetworkScope, CustomWidgetSource } from "./request-schema";
|
||||
import { getCustomWidgetSourceUrlIssue } from "./request-schema";
|
||||
import type { CustomWidgetSecretKind } from "./schema-types";
|
||||
import { getCustomWidgetSecretRequirements } from "./secret-requirements";
|
||||
@@ -15,7 +16,9 @@ export interface CustomWidgetSourceSetup {
|
||||
sourceName: string;
|
||||
suggestedBaseUrl: string;
|
||||
baseUrl: string;
|
||||
networkScope: CustomWidgetSource["networkScope"];
|
||||
networkScope: CustomJsxNetworkScope;
|
||||
integrationKind?: string;
|
||||
integrationId?: string;
|
||||
authType: "none" | "bearer" | "basic" | "apiKeyHeader" | "apiKeyQuery";
|
||||
credentialFields: Array<{
|
||||
kind: CustomWidgetSecretKind;
|
||||
@@ -40,10 +43,18 @@ export function isCustomWidgetSourceUrlPlaceholder(baseUrl: string) {
|
||||
}
|
||||
|
||||
export function customWidgetSourceRequiresUrlConfirmation(source: CustomWidgetSource) {
|
||||
if (source.type === "integration") return !source.integrationId;
|
||||
return source.networkScope !== "public" || isCustomWidgetSourceUrlPlaceholder(source.baseUrl);
|
||||
}
|
||||
|
||||
export function hasSameCustomWidgetSourceAuthentication(left: CustomWidgetSource, right: CustomWidgetSource) {
|
||||
if (left.type === "integration" || right.type === "integration") {
|
||||
return (
|
||||
left.type === right.type &&
|
||||
left.integrationKind === right.integrationKind &&
|
||||
left.integrationId === right.integrationId
|
||||
);
|
||||
}
|
||||
if (typeof left.auth === "string" || typeof right.auth === "string") return left.auth === right.auth;
|
||||
return left.auth.type === right.auth.type && left.auth.name === right.auth.name;
|
||||
}
|
||||
@@ -54,13 +65,15 @@ export function getCustomWidgetSourceSetups(
|
||||
): CustomWidgetSourceSetup[] {
|
||||
const requirements = getCustomWidgetSecretRequirements(sources);
|
||||
return Object.entries(sources).map(([sourceId, source]) => {
|
||||
const authType = typeof source.auth === "string" ? source.auth : source.auth.type;
|
||||
const authType = getCustomWidgetSourceAuthType(source);
|
||||
return {
|
||||
sourceId,
|
||||
sourceName: source.name ?? sourceId,
|
||||
suggestedBaseUrl: source.baseUrl,
|
||||
baseUrl: source.baseUrl,
|
||||
networkScope: source.networkScope,
|
||||
suggestedBaseUrl: source.baseUrl ?? "",
|
||||
baseUrl: source.baseUrl ?? "",
|
||||
networkScope: source.networkScope ?? "private",
|
||||
integrationKind: source.integrationKind,
|
||||
integrationId: source.integrationId,
|
||||
authType,
|
||||
credentialFields: requirements
|
||||
.filter((requirement) => requirement.sourceId === sourceId)
|
||||
@@ -81,12 +94,23 @@ export function getCustomWidgetSourceSetups(
|
||||
|
||||
export function applyCustomWidgetSourceSetup(
|
||||
sources: Record<string, CustomWidgetSource>,
|
||||
setup: Record<string, Pick<CustomWidgetSource, "baseUrl" | "networkScope">>,
|
||||
setup: Record<string, { baseUrl?: string; networkScope?: CustomJsxNetworkScope; integrationId?: string }>,
|
||||
) {
|
||||
return Object.fromEntries(
|
||||
Object.entries(sources).map(([sourceId, source]) => {
|
||||
const configured = setup[sourceId];
|
||||
return [sourceId, configured ? { ...source, ...configured } : source];
|
||||
if (!configured) return [sourceId, source];
|
||||
if (source.type === "integration") {
|
||||
return [sourceId, { ...source, integrationId: configured.integrationId }];
|
||||
}
|
||||
return [
|
||||
sourceId,
|
||||
{
|
||||
...source,
|
||||
baseUrl: configured.baseUrl ?? source.baseUrl,
|
||||
networkScope: configured.networkScope ?? source.networkScope,
|
||||
},
|
||||
];
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { lookup } from "node:dns/promises";
|
||||
import type { ConnectionOptions } from "node:tls";
|
||||
import { BlockList, isIP } from "node:net";
|
||||
import type { LookupFunction } from "node:net";
|
||||
import { Agent } from "undici";
|
||||
@@ -191,7 +192,11 @@ export function assertSafeStaticHeaders(headers: Record<string, string> | undefi
|
||||
}
|
||||
}
|
||||
|
||||
export function createPinnedAgent(addresses: ResolvedAddress[], timeoutMs: number) {
|
||||
export function createPinnedAgent(
|
||||
addresses: ResolvedAddress[],
|
||||
timeoutMs: number,
|
||||
tls?: Pick<ConnectionOptions, "ca" | "checkServerIdentity">,
|
||||
) {
|
||||
const customLookup: LookupFunction = (_hostname, options, callback) => {
|
||||
const family = options.family === 4 || options.family === 6 ? options.family : undefined;
|
||||
const candidates = family ? addresses.filter((entry) => entry.family === family) : addresses;
|
||||
@@ -204,10 +209,42 @@ export function createPinnedAgent(addresses: ResolvedAddress[], timeoutMs: numbe
|
||||
else callback(null, selected.address, selected.family);
|
||||
};
|
||||
return new Agent({
|
||||
connect: { lookup: customLookup },
|
||||
connect: { ...tls, lookup: customLookup },
|
||||
connectTimeout: timeoutMs,
|
||||
headersTimeout: timeoutMs,
|
||||
bodyTimeout: timeoutMs,
|
||||
maxResponseSize: MAX_RESPONSE_BODY_BYTES,
|
||||
});
|
||||
}
|
||||
|
||||
export function assertCustomWidgetPathScope(url: URL, pathPrefix: string) {
|
||||
const prefix = decodePath(pathPrefix).replace(/\/+$/u, "");
|
||||
const path = decodePath(url.pathname);
|
||||
if (
|
||||
path.includes("\\") ||
|
||||
path.split("/").some((segment) => segment === "." || segment === "..") ||
|
||||
(prefix && path !== prefix && !path.startsWith(`${prefix}/`))
|
||||
) {
|
||||
throw new CustomWidgetDomainError({
|
||||
code: "FORBIDDEN",
|
||||
message: "Request must remain within the selected integration URL",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function decodePath(value: string) {
|
||||
let path = value;
|
||||
for (let pass = 0; pass < 4; pass += 1) {
|
||||
let decoded: string;
|
||||
try {
|
||||
decoded = decodeURIComponent(path);
|
||||
} catch {
|
||||
return path;
|
||||
}
|
||||
if (decoded === path) return path;
|
||||
path = decoded;
|
||||
}
|
||||
if (/%[0-9a-f]{2}/iu.test(path))
|
||||
throw new CustomWidgetDomainError({ code: "FORBIDDEN", message: "Request path is excessively encoded" });
|
||||
return path;
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { hasSameCustomWidgetSourceAuthentication } from "../core";
|
||||
import { customWidgetDefinitionSchema } from "../core";
|
||||
import type { CustomJsxRequest, CustomWidgetOptions, CustomWidgetSource } from "../core";
|
||||
import { CustomWidgetDomainError } from "./errors";
|
||||
@@ -36,3 +37,9 @@ export function validatePreviewTemplateRevision(current: PreviewTemplateContext,
|
||||
}
|
||||
return parsed.data.template;
|
||||
}
|
||||
|
||||
export function canConfigurePreviewSource(current: CustomWidgetSource, source: CustomWidgetSource) {
|
||||
if (current.type === "integration" && source.type === "integration")
|
||||
return current.integrationKind === source.integrationKind;
|
||||
return hasSameCustomWidgetSourceAuthentication(current, source);
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { canConfigurePreviewSource } from "./preview-session-template";
|
||||
import { z } from "zod/v4";
|
||||
|
||||
import {
|
||||
@@ -5,7 +6,6 @@ import {
|
||||
customWidgetRequestsSchema,
|
||||
customWidgetSecretKinds,
|
||||
customWidgetSourcesSchema,
|
||||
hasSameCustomWidgetSourceAuthentication,
|
||||
} from "../core";
|
||||
import type { CustomJsxRequest, CustomWidgetOptions, CustomWidgetSource } from "../core";
|
||||
import { CustomWidgetDomainError } from "./errors";
|
||||
@@ -242,7 +242,7 @@ export class CustomWidgetPreviewSessionService {
|
||||
if (!currentSource) {
|
||||
throw new CustomWidgetDomainError({ code: "NOT_FOUND", message: "Preview source was not found" });
|
||||
}
|
||||
if (!hasSameCustomWidgetSourceAuthentication(currentSource, source)) {
|
||||
if (!canConfigurePreviewSource(currentSource, source)) {
|
||||
throw new CustomWidgetDomainError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "Preview source authentication changed; create a new configuration request",
|
||||
@@ -253,7 +253,7 @@ export class CustomWidgetPreviewSessionService {
|
||||
...session,
|
||||
sources: {
|
||||
...session.sources,
|
||||
[sourceId]: { ...currentSource, baseUrl: source.baseUrl, networkScope: source.networkScope },
|
||||
[sourceId]: source,
|
||||
},
|
||||
secrets: [
|
||||
...session.secrets.filter((secret) => !replacements.has(`${secret.sourceId}:${secret.kind}`)),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Buffer } from "node:buffer";
|
||||
import { STATUS_CODES } from "node:http";
|
||||
import type { ConnectionOptions } from "node:tls";
|
||||
import { Headers, Response } from "undici";
|
||||
|
||||
import type { CustomJsxNetworkScope, CustomWidgetMethod } from "../core";
|
||||
@@ -7,6 +8,7 @@ import { applyAuth } from "./auth";
|
||||
import { CustomWidgetDomainError } from "./errors";
|
||||
import {
|
||||
assertSafeStaticHeaders,
|
||||
assertCustomWidgetPathScope,
|
||||
createPinnedAgent,
|
||||
resolveAndValidateHost,
|
||||
resolveSameOriginTarget,
|
||||
@@ -44,6 +46,8 @@ export interface CustomWidgetAuthConfig {
|
||||
}
|
||||
|
||||
export interface CustomWidgetHttpRequest {
|
||||
tls?: Pick<ConnectionOptions, "ca" | "checkServerIdentity">;
|
||||
pathPrefix?: string;
|
||||
baseUrl: string;
|
||||
targetUrl?: string | URL;
|
||||
method: CustomWidgetMethod;
|
||||
@@ -110,9 +114,11 @@ async function performRequestWithinDeadline(
|
||||
let currentBody = input.body;
|
||||
const maxRedirects = input.kind === "query" ? MAX_QUERY_REDIRECTS : 0;
|
||||
for (let redirects = 0; ; redirects += 1) {
|
||||
if (input.pathPrefix !== undefined) assertCustomWidgetPathScope(currentUrl, input.pathPrefix);
|
||||
const dispatcher = createPinnedAgent(
|
||||
await resolveAndValidateHost(currentUrl.hostname, input.networkScope, { signal: deadlineSignal }),
|
||||
REQUEST_TIMEOUT_MS,
|
||||
input.tls,
|
||||
);
|
||||
const headers = buildHeaders(input, currentUrl, currentBody);
|
||||
const controller = new AbortController();
|
||||
|
||||
@@ -22,7 +22,7 @@ const skillSourceDirectory = path.resolve(import.meta.dirname, "../../../../.age
|
||||
describe("authoring resources", () => {
|
||||
it("returns the complete portable skill and keeps every bundled source file in sync", () => {
|
||||
const skill = getCustomWidgetSkill();
|
||||
expect(skill).toMatchObject({ name: "homarr-custom-widget", version: "2.9.0" });
|
||||
expect(skill).toMatchObject({ name: "homarr-custom-widget", version: "2.10.0" });
|
||||
expect(skill.skillsShUrl).toContain("skills.sh/homarr-labs/homarr");
|
||||
expect(skill.sourceUrl).toContain("/tree/HEAD/.agents/skills/homarr-custom-widget");
|
||||
expect(skill.installCommand).toContain("--skill homarr-custom-widget");
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import type { ReactNode } from "react";
|
||||
import { Alert, Badge, Checkbox, Group, PasswordInput, Select, Stack, Text, TextInput } from "@mantine/core";
|
||||
import { IconCheck, IconKey, IconServer, IconX } from "@tabler/icons-react";
|
||||
|
||||
import type {
|
||||
CustomWidgetSecretKind,
|
||||
CustomWidgetSource,
|
||||
CustomJsxNetworkScope,
|
||||
CustomWidgetSourceSetup,
|
||||
CustomWidgetSourceUrlIssue,
|
||||
} from "../core";
|
||||
@@ -11,7 +12,8 @@ import { getCustomWidgetSourceSetupIssue } from "../core";
|
||||
|
||||
export interface CustomWidgetSourceSetupValue {
|
||||
baseUrl: string;
|
||||
networkScope: CustomWidgetSource["networkScope"];
|
||||
networkScope: CustomJsxNetworkScope;
|
||||
integrationId?: string;
|
||||
urlConfirmed: boolean;
|
||||
secrets: Partial<Record<CustomWidgetSecretKind, string>>;
|
||||
}
|
||||
@@ -38,6 +40,7 @@ export interface CustomWidgetSourceSetupPanelProps {
|
||||
values: Record<string, CustomWidgetSourceSetupValue>;
|
||||
messages: CustomWidgetSourceSetupMessages;
|
||||
onChange(sourceId: string, value: CustomWidgetSourceSetupValue): void;
|
||||
renderIntegrationSource?(setup: CustomWidgetSourceSetup, value: CustomWidgetSourceSetupValue): ReactNode;
|
||||
}
|
||||
|
||||
export function createCustomWidgetSourceSetupValues(
|
||||
@@ -48,6 +51,7 @@ export function createCustomWidgetSourceSetupValues(
|
||||
setup.sourceId,
|
||||
{
|
||||
baseUrl: setup.baseUrl,
|
||||
integrationId: setup.integrationId,
|
||||
networkScope: setup.networkScope,
|
||||
urlConfirmed: !setup.requiresUrlConfirmation,
|
||||
secrets: {} as Partial<Record<CustomWidgetSecretKind, string>>,
|
||||
@@ -62,6 +66,7 @@ export function isCustomWidgetSourceSetupReady(
|
||||
) {
|
||||
return setups.every((setup) => {
|
||||
const value = values[setup.sourceId];
|
||||
if (setup.integrationKind) return Boolean(value?.integrationId);
|
||||
return Boolean(value && !getCustomWidgetSourceSetupIssue(value) && value.urlConfirmed);
|
||||
});
|
||||
}
|
||||
@@ -71,6 +76,7 @@ export function CustomWidgetSourceSetupPanel({
|
||||
values,
|
||||
messages,
|
||||
onChange,
|
||||
renderIntegrationSource,
|
||||
}: CustomWidgetSourceSetupPanelProps) {
|
||||
if (setups.length === 0) return null;
|
||||
return (
|
||||
@@ -84,6 +90,14 @@ export function CustomWidgetSourceSetupPanel({
|
||||
{setups.map((setup) => {
|
||||
const value = values[setup.sourceId] ?? createCustomWidgetSourceSetupValues([setup])[setup.sourceId];
|
||||
if (!value) return null;
|
||||
if (setup.integrationKind) {
|
||||
return (
|
||||
<Stack key={setup.sourceId} gap="sm">
|
||||
<Text fw={600}>{setup.sourceName}</Text>
|
||||
{renderIntegrationSource?.(setup, value)}
|
||||
</Stack>
|
||||
);
|
||||
}
|
||||
const issue = getCustomWidgetSourceSetupIssue(value);
|
||||
const missingCredentials = setup.credentialFields.filter(
|
||||
(field) => !field.configured && !value.secrets[field.kind]?.trim(),
|
||||
@@ -143,7 +157,7 @@ export function CustomWidgetSourceSetupPanel({
|
||||
networkScope &&
|
||||
onChange(setup.sourceId, {
|
||||
...value,
|
||||
networkScope: networkScope as CustomWidgetSource["networkScope"],
|
||||
networkScope: networkScope as CustomJsxNetworkScope,
|
||||
})
|
||||
}
|
||||
/>
|
||||
|
||||
Reference in new issue
Block a user