Merge upstream v0.4.0 into Gitea fork
This commit is contained in:
+11
-10
@@ -1,7 +1,7 @@
|
||||
"use strict";
|
||||
const { randomUUID } = require("node:crypto");
|
||||
const path = require("node:path");
|
||||
const { createRequire, registerHooks } = require("node:module");
|
||||
const { registerHooks } = require("node:module");
|
||||
const { pathToFileURL } = require("node:url");
|
||||
const { PROVIDERS, fileStore, validateCredential, safeHttps, failure } = require("./subscription-store.cjs");
|
||||
|
||||
@@ -21,17 +21,18 @@ const MESSAGES = {
|
||||
function publicError(error) { return MESSAGES[error?.code] ?? MESSAGES.unavailable; }
|
||||
/** Resolve the SAME SDK installation as the standalone server, through public exports. */
|
||||
async function loadSubscriptionSDK(baseDirectory) {
|
||||
const resolve = createRequire(path.join(baseDirectory, "package.json"));
|
||||
const load = (id) => {
|
||||
// Pi exports are import-only. Resolve the public export with ESM
|
||||
// conditions, then remove this synchronous, exact-specifier hook
|
||||
// BEFORE evaluation; no private package path or global hook remains.
|
||||
const parentURL = pathToFileURL(path.join(baseDirectory, "package.json")).href;
|
||||
const load = async (id) => {
|
||||
// The manifest URL plus fragment is an exact resolution token, never
|
||||
// evaluated. Normal ESM resolution selects the public import export
|
||||
// from the server's installation, including under test-loader hooks.
|
||||
const token = `${parentURL}#${encodeURIComponent(id)}`;
|
||||
const hook = registerHooks({ resolve(specifier, context, next) {
|
||||
return next(specifier, specifier === id ? { ...context, conditions: [...context.conditions, "import"] } : context);
|
||||
if (specifier !== token) return next(specifier, context);
|
||||
hook.deregister();
|
||||
return next(id, { ...context, parentURL });
|
||||
} });
|
||||
let file;
|
||||
try { file = resolve.resolve(id); } finally { hook.deregister(); }
|
||||
return import(pathToFileURL(file).href);
|
||||
try { return await import(token); } finally { hook.deregister(); }
|
||||
};
|
||||
const [sdk, copilot, xai] = await Promise.all([load("@earendil-works/pi-ai"), load("@earendil-works/pi-ai/providers/github-copilot"), load("@earendil-works/pi-ai/providers/xai")]);
|
||||
return { ...sdk, ...copilot, ...xai };
|
||||
|
||||
Reference in New Issue
Block a user