@ubiquity-os/plugin-sdk
Version:
SDK for plugin support.
140 lines (136 loc) • 5.54 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/types/manifest.ts
var manifest_exports = {};
__export(manifest_exports, {
commandSchema: () => commandSchema,
exampleCommandExecutionSchema: () => exampleCommandExecutionSchema,
manifestSchema: () => manifestSchema,
resolveRuntimeManifest: () => resolveRuntimeManifest,
runEvent: () => runEvent
});
module.exports = __toCommonJS(manifest_exports);
var import_typebox = require("@sinclair/typebox");
var import_webhooks = require("@octokit/webhooks");
// src/helpers/runtime-manifest.ts
var EMPTY_VALUE = String();
var GITHUB_HEADS_PREFIX = "refs/heads/";
var GITHUB_TAGS_PREFIX = "refs/tags/";
function readRuntimeEnvValue(env, key) {
const explicitValue = env?.[key];
if (typeof explicitValue === "string" && explicitValue.trim()) {
return explicitValue.trim();
}
const runtime = globalThis;
if (typeof runtime.Deno?.env?.get === "function") {
const denoValue = runtime.Deno.env.get(key);
if (typeof denoValue === "string" && denoValue.trim()) {
return denoValue.trim();
}
}
if (typeof process !== "undefined") {
const processValue = process.env[key];
if (typeof processValue === "string" && processValue.trim()) {
return processValue.trim();
}
}
return EMPTY_VALUE;
}
function parseRefNameFromGitHubRef(ref) {
if (!ref) {
return EMPTY_VALUE;
}
if (ref.startsWith(GITHUB_HEADS_PREFIX)) {
return ref.slice(GITHUB_HEADS_PREFIX.length);
}
if (ref.startsWith(GITHUB_TAGS_PREFIX)) {
return ref.slice(GITHUB_TAGS_PREFIX.length);
}
return EMPTY_VALUE;
}
function overrideShortName(shortName, refName) {
if (!shortName || !refName) {
return shortName;
}
const separatorIndex = shortName.lastIndexOf("@");
const repository = separatorIndex === -1 ? shortName : shortName.slice(0, separatorIndex);
if (!repository) {
return shortName;
}
return `${repository}@${refName}`;
}
function resolveRuntimeRefName(env) {
const explicitRefName = readRuntimeEnvValue(env, "REF_NAME");
if (explicitRefName) {
return explicitRefName;
}
const legacyManifestRefName = readRuntimeEnvValue(env, "PLUGIN_MANIFEST_REF_NAME");
if (legacyManifestRefName) {
return legacyManifestRefName;
}
const githubRefName = readRuntimeEnvValue(env, "GITHUB_REF_NAME");
if (githubRefName) {
return githubRefName;
}
return parseRefNameFromGitHubRef(readRuntimeEnvValue(env, "GITHUB_REF"));
}
function resolveRuntimeManifest(manifest, env) {
const refName = resolveRuntimeRefName(env);
if (!refName) {
return manifest;
}
return {
...manifest,
short_name: overrideShortName(manifest.short_name, refName)
};
}
// src/types/manifest.ts
var runEvent = import_typebox.Type.Union(import_webhooks.emitterEventNames.map((o) => import_typebox.Type.Literal(o)));
var exampleCommandExecutionSchema = import_typebox.Type.Object({
commandInvocation: import_typebox.Type.String({ minLength: 1 }),
githubContext: import_typebox.Type.Optional(import_typebox.Type.Record(import_typebox.Type.String(), import_typebox.Type.Any())),
expectedToolCallResult: import_typebox.Type.Object({
function: import_typebox.Type.String({ minLength: 1 }),
parameters: import_typebox.Type.Record(import_typebox.Type.String(), import_typebox.Type.Any())
})
});
var commandSchema = import_typebox.Type.Object({
description: import_typebox.Type.String({ minLength: 1 }),
"ubiquity:example": import_typebox.Type.String({ minLength: 1 }),
parameters: import_typebox.Type.Optional(import_typebox.Type.Record(import_typebox.Type.String(), import_typebox.Type.Any())),
examples: import_typebox.Type.Optional(import_typebox.Type.Array(exampleCommandExecutionSchema, { default: [] }))
});
var manifestSchema = import_typebox.Type.Object({
name: import_typebox.Type.String({ minLength: 1 }),
short_name: import_typebox.Type.String({ minLength: 1 }),
description: import_typebox.Type.Optional(import_typebox.Type.String({ default: "" })),
commands: import_typebox.Type.Optional(import_typebox.Type.Record(import_typebox.Type.String({ pattern: "^[A-Za-z-_]+$" }), commandSchema, { default: {} })),
"ubiquity:listeners": import_typebox.Type.Optional(import_typebox.Type.Array(runEvent, { default: [] })),
configuration: import_typebox.Type.Optional(import_typebox.Type.Record(import_typebox.Type.String(), import_typebox.Type.Any(), { default: {} })),
skipBotEvents: import_typebox.Type.Optional(import_typebox.Type.Boolean({ default: true })),
homepage_url: import_typebox.Type.Optional(import_typebox.Type.String())
});
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
commandSchema,
exampleCommandExecutionSchema,
manifestSchema,
resolveRuntimeManifest,
runEvent
});