pinokiod 7.3.1 → 7.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/kernel/api/github/index.js +444 -0
- package/kernel/api/index.js +199 -11
- package/kernel/api/process/index.js +124 -44
- package/kernel/api/shell_run_template.js +273 -0
- package/kernel/api/uri/index.js +51 -0
- package/kernel/bin/git.js +9 -10
- package/kernel/bin/huggingface.js +1 -1
- package/kernel/bin/zip.js +9 -1
- package/kernel/connect/providers/github/README.md +5 -4
- package/kernel/environment.js +195 -92
- package/kernel/git.js +98 -19
- package/kernel/gitconfig_template +7 -0
- package/kernel/gpu/amd.js +72 -0
- package/kernel/gpu/apple.js +8 -0
- package/kernel/gpu/common.js +12 -0
- package/kernel/gpu/intel.js +47 -0
- package/kernel/gpu/nvidia.js +8 -0
- package/kernel/index.js +11 -1
- package/kernel/managed_skills.js +871 -0
- package/kernel/plugin.js +6 -58
- package/kernel/plugin_sources.js +316 -0
- package/kernel/resource_usage/gpu.js +349 -0
- package/kernel/resource_usage/index.js +322 -0
- package/kernel/resource_usage/macos_footprint.js +197 -0
- package/kernel/resource_usage/preferences.js +92 -0
- package/kernel/resource_usage/process_tree.js +303 -0
- package/kernel/scripts/git/create +4 -4
- package/kernel/scripts/git/fork +7 -8
- package/kernel/shell.js +23 -2
- package/kernel/shells.js +41 -0
- package/kernel/sysinfo.js +62 -9
- package/kernel/util.js +60 -0
- package/package.json +1 -1
- package/server/index.js +984 -156
- package/server/lib/app_log_report.js +543 -0
- package/server/lib/content_validation.js +55 -33
- package/server/lib/launcher_instruction_bootstrap.js +4 -96
- package/server/lib/terminal_session_helpers.js +0 -3
- package/server/public/common.js +77 -31
- package/server/public/create-launcher.js +4 -32
- package/server/public/logs.js +1428 -0
- package/server/public/nav.js +7 -0
- package/server/public/plugin-detail.js +93 -10
- package/server/public/privacy_filter_worker.js +391 -0
- package/server/public/style.css +1104 -154
- package/server/public/task-launcher.js +8 -29
- package/server/public/universal-launcher.css +8 -6
- package/server/public/universal-launcher.js +3 -27
- package/server/routes/apps.js +195 -1
- package/server/views/app.ejs +3041 -717
- package/server/views/autolaunch.ejs +917 -0
- package/server/views/bootstrap.ejs +7 -1
- package/server/views/d.ejs +408 -65
- package/server/views/editor.ejs +85 -19
- package/server/views/index.ejs +661 -111
- package/server/views/init/index.ejs +1 -1
- package/server/views/install.ejs +1 -1
- package/server/views/logs.ejs +164 -86
- package/server/views/net.ejs +7 -1
- package/server/views/partials/d_terminal_column.ejs +2 -2
- package/server/views/partials/d_terminal_options.ejs +0 -8
- package/server/views/partials/fs_status.ejs +47 -0
- package/server/views/partials/home_action_modal.ejs +86 -0
- package/server/views/partials/home_run_menu.ejs +87 -0
- package/server/views/partials/main_sidebar.ejs +2 -0
- package/server/views/partials/menu.ejs +1 -1
- package/server/views/plugin_detail.ejs +19 -4
- package/server/views/plugins.ejs +201 -3
- package/server/views/pre.ejs +1 -1
- package/server/views/pro.ejs +1 -1
- package/server/views/shell.ejs +40 -18
- package/server/views/skills.ejs +506 -0
- package/server/views/terminal.ejs +45 -19
- package/spec/INSTRUCTION_SYNC.md +20 -10
- package/system/plugin/antigravity-cli/antigravity.png +0 -0
- package/system/plugin/antigravity-cli/common.js +155 -0
- package/system/plugin/antigravity-cli/install.js +272 -0
- package/system/plugin/antigravity-cli/pinokio.js +13 -0
- package/system/plugin/antigravity-cli-auto/antigravity.png +0 -0
- package/system/plugin/antigravity-cli-auto/pinokio.js +13 -0
- package/system/plugin/claude/claude.png +0 -0
- package/system/plugin/claude/pinokio.js +47 -0
- package/system/plugin/claude-auto/claude.png +0 -0
- package/system/plugin/claude-auto/pinokio.js +58 -0
- package/system/plugin/claude-desktop/icon.jpeg +0 -0
- package/system/plugin/claude-desktop/pinokio.js +23 -0
- package/system/plugin/codex/openai.webp +0 -0
- package/system/plugin/codex/pinokio.js +42 -0
- package/system/plugin/codex-auto/openai.webp +0 -0
- package/system/plugin/codex-auto/pinokio.js +49 -0
- package/system/plugin/codex-desktop/icon.png +0 -0
- package/system/plugin/codex-desktop/pinokio.js +23 -0
- package/system/plugin/crush/crush.png +0 -0
- package/system/plugin/crush/pinokio.js +15 -0
- package/system/plugin/cursor/cursor.jpeg +0 -0
- package/system/plugin/cursor/pinokio.js +23 -0
- package/system/plugin/qwen/pinokio.js +34 -0
- package/system/plugin/qwen/qwen.png +0 -0
- package/system/plugin/vscode/pinokio.js +20 -0
- package/system/plugin/vscode/vscode.png +0 -0
- package/system/plugin/windsurf/pinokio.js +23 -0
- package/system/plugin/windsurf/windsurf.png +0 -0
- package/test/antigravity-cli-plugin.test.js +185 -0
- package/test/app-api.test.js +239 -0
- package/test/app-log-report.test.js +67 -0
- package/test/environment-cache-preflight.test.js +98 -0
- package/test/git-bin.test.js +59 -0
- package/test/git-defaults.test.js +97 -0
- package/test/github-api.test.js +158 -0
- package/test/github-connection.test.js +117 -0
- package/test/huggingface-bin.test.js +25 -0
- package/test/managed-skills.test.js +351 -0
- package/test/plugin-action-functions.test.js +337 -0
- package/test/plugin-dev-iframe.test.js +17 -0
- package/test/plugin-sources.test.js +203 -0
- package/test/privacy-filter-worker-heuristics.test.js +69 -0
- package/test/process-wait.test.js +169 -0
- package/test/script-api.test.js +97 -0
- package/test/shell-api.test.js +134 -0
- package/test/shell-run-template.test.js +209 -0
- package/test/storage-api.test.js +137 -0
- package/test/uri-api.test.js +100 -0
package/kernel/plugin.js
CHANGED
|
@@ -1,39 +1,14 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const PluginSources = require("./plugin_sources")
|
|
3
|
+
|
|
4
4
|
class Plugin {
|
|
5
5
|
constructor(kernel) {
|
|
6
6
|
this.kernel = kernel
|
|
7
7
|
}
|
|
8
8
|
async setConfig() {
|
|
9
|
-
let plugin_dir = path.resolve(this.kernel.homedir, "plugin")
|
|
10
9
|
this.cache = {}
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
let plugins = []
|
|
15
|
-
for(let plugin_path of plugin_paths) {
|
|
16
|
-
let config = await this.kernel.require(path.resolve(plugin_dir, plugin_path))
|
|
17
|
-
if (config && config.run && Array.isArray(config.run)) {
|
|
18
|
-
let invalid
|
|
19
|
-
for(let key in config) {
|
|
20
|
-
if (typeof config[key] === "function") {
|
|
21
|
-
invalid = true
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
if (invalid) {
|
|
25
|
-
continue
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
let chunks = plugin_path.split(path.sep)
|
|
29
|
-
let cwd = chunks.slice(0, -1).join("/")
|
|
30
|
-
config.image = "/asset/plugin/" + cwd + "/" + config.icon
|
|
31
|
-
plugins.push({
|
|
32
|
-
href: "/run/plugin/" + chunks.join("/"),
|
|
33
|
-
...config
|
|
34
|
-
})
|
|
35
|
-
}
|
|
36
|
-
}
|
|
11
|
+
const plugins = await PluginSources.loadPluginMenu(this.kernel)
|
|
37
12
|
|
|
38
13
|
this.config = {
|
|
39
14
|
menu: plugins.map((plugin) => {
|
|
@@ -48,37 +23,10 @@ class Plugin {
|
|
|
48
23
|
if (!exists) {
|
|
49
24
|
await fs.promises.mkdir(this.kernel.path("plugin"), { recursive: true }).catch((e) => {})
|
|
50
25
|
}
|
|
51
|
-
|
|
52
|
-
console.log({ code_exists })
|
|
53
|
-
if (!code_exists) {
|
|
54
|
-
if (this.kernel.bin.installed && this.kernel.bin.installed.conda && this.kernel.bin.installed.conda.has("git")) {
|
|
55
|
-
await this.kernel.exec({
|
|
56
|
-
//message: "git clone https://github.com/peanutcocktail/plugin",
|
|
57
|
-
//message: "git clone https://github.com/pinokiocomputer/plugin",
|
|
58
|
-
message: "git clone https://github.com/pinokiocomputer/code",
|
|
59
|
-
path: this.kernel.path("plugin")
|
|
60
|
-
}, (e) => {
|
|
61
|
-
process.stdout.write(e.raw)
|
|
62
|
-
})
|
|
63
|
-
await this.setConfig()
|
|
64
|
-
return
|
|
65
|
-
}
|
|
66
|
-
} else {
|
|
67
|
-
await this.setConfig()
|
|
68
|
-
}
|
|
26
|
+
await this.setConfig()
|
|
69
27
|
}
|
|
70
28
|
async update() {
|
|
71
|
-
|
|
72
|
-
let exists = await this.kernel.exists("plugin")
|
|
73
|
-
if (!exists) {
|
|
74
|
-
await this.kernel.exec({
|
|
75
|
-
message: "git pull",
|
|
76
|
-
path: this.kernel.path("plugin")
|
|
77
|
-
}, (e) => {
|
|
78
|
-
process.stdout.write(e.raw)
|
|
79
|
-
})
|
|
80
|
-
}
|
|
81
|
-
}
|
|
29
|
+
await this.setConfig()
|
|
82
30
|
}
|
|
83
31
|
}
|
|
84
32
|
module.exports = Plugin
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
const fs = require("fs")
|
|
2
|
+
const path = require("path")
|
|
3
|
+
const { glob } = require("glob")
|
|
4
|
+
|
|
5
|
+
const LOCAL_RUN_PREFIX = "/run"
|
|
6
|
+
const LOCAL_ASSET_PREFIX = "/asset"
|
|
7
|
+
const SYSTEM_RUN_PREFIX = "/pinokio/run"
|
|
8
|
+
const SYSTEM_ASSET_PREFIX = "/pinokio/asset"
|
|
9
|
+
const LOCAL_PLUGIN_RUN_PREFIX = `${LOCAL_RUN_PREFIX}/plugin`
|
|
10
|
+
const LOCAL_PLUGIN_ASSET_PREFIX = `${LOCAL_ASSET_PREFIX}/plugin`
|
|
11
|
+
const SYSTEM_PLUGIN_RUN_PREFIX = `${SYSTEM_RUN_PREFIX}/plugin`
|
|
12
|
+
const SYSTEM_PLUGIN_ASSET_PREFIX = `${SYSTEM_ASSET_PREFIX}/plugin`
|
|
13
|
+
const ACTION_KEYS = new Set(["run", "install", "uninstall", "update"])
|
|
14
|
+
const STATUS_KEYS = new Set(["installed"])
|
|
15
|
+
const FUNCTION_KEYS = new Set([...ACTION_KEYS, ...STATUS_KEYS])
|
|
16
|
+
const BUILTIN_TOOL_ALIASES = {
|
|
17
|
+
claude: "pinokio/run/plugin/claude",
|
|
18
|
+
codex: "pinokio/run/plugin/codex",
|
|
19
|
+
antigravity: "pinokio/run/plugin/antigravity-cli",
|
|
20
|
+
"antigravity-cli": "pinokio/run/plugin/antigravity-cli",
|
|
21
|
+
"code/claude": "pinokio/run/plugin/claude",
|
|
22
|
+
"code/codex": "pinokio/run/plugin/codex",
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const toPathname = (value) => {
|
|
26
|
+
const raw = typeof value === "string" ? value.trim() : ""
|
|
27
|
+
if (!raw) return ""
|
|
28
|
+
try {
|
|
29
|
+
if (/^https?:\/\//i.test(raw)) return new URL(raw).pathname
|
|
30
|
+
if (raw.startsWith("/")) return new URL(`http://localhost${raw}`).pathname
|
|
31
|
+
} catch (_) {
|
|
32
|
+
}
|
|
33
|
+
return raw.split("?")[0].split("#")[0]
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const normalizeSlashes = (value) => String(value || "").replace(/\\/g, "/").replace(/\/{2,}/g, "/")
|
|
37
|
+
|
|
38
|
+
const systemRoot = (kernel) => {
|
|
39
|
+
if (kernel && typeof kernel.systemPath === "function") {
|
|
40
|
+
return kernel.systemPath()
|
|
41
|
+
}
|
|
42
|
+
return path.resolve(__dirname, "..", "system")
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const systemPluginRoot = (kernel) => {
|
|
46
|
+
if (kernel && typeof kernel.systemPath === "function") {
|
|
47
|
+
return kernel.systemPath("plugin")
|
|
48
|
+
}
|
|
49
|
+
return path.resolve(__dirname, "..", "system", "plugin")
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const isSystemRunPath = (value) => toPathname(value).startsWith(`${SYSTEM_RUN_PREFIX}/`)
|
|
53
|
+
const isLocalRunPath = (value) => toPathname(value).startsWith(`${LOCAL_RUN_PREFIX}/`)
|
|
54
|
+
const isRunPath = (value) => isLocalRunPath(value) || isSystemRunPath(value)
|
|
55
|
+
const isSystemPluginPath = (value) => normalizeSlashes(value).startsWith(`${SYSTEM_PLUGIN_RUN_PREFIX}/`)
|
|
56
|
+
const isLegacyPluginCodePath = (value) => {
|
|
57
|
+
const normalized = normalizeSlashes(value).replace(/^\/+/, "")
|
|
58
|
+
return normalized.startsWith("plugin/code/") || normalized.startsWith("code/")
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const normalizePluginPath = (value) => {
|
|
62
|
+
let normalized = toPathname(value)
|
|
63
|
+
if (!normalized) return ""
|
|
64
|
+
normalized = normalizeSlashes(normalized)
|
|
65
|
+
if (!normalized.startsWith(`${SYSTEM_RUN_PREFIX}/`)) {
|
|
66
|
+
normalized = normalized.replace(/^\/run(?=\/)/, "")
|
|
67
|
+
}
|
|
68
|
+
if (!normalized.startsWith("/")) {
|
|
69
|
+
normalized = `/${normalized}`
|
|
70
|
+
}
|
|
71
|
+
normalized = normalized.replace(/\/+$/, "")
|
|
72
|
+
if (!normalized.endsWith("/pinokio.js")) {
|
|
73
|
+
normalized = `${normalized}/pinokio.js`
|
|
74
|
+
}
|
|
75
|
+
return normalized
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const pluginSelectionMatches = (src, selectedValue) => {
|
|
79
|
+
const selectedPlugin = normalizeSlashes(typeof selectedValue === "string" ? selectedValue.trim() : "")
|
|
80
|
+
if (!selectedPlugin || !src) return false
|
|
81
|
+
const selectedRunPath = selectedPlugin.startsWith(`${SYSTEM_RUN_PREFIX}/`)
|
|
82
|
+
? selectedPlugin
|
|
83
|
+
: `${LOCAL_RUN_PREFIX}${selectedPlugin}`
|
|
84
|
+
return src === selectedPlugin || src.startsWith(selectedRunPath)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const resolveRunPath = (kernel, value) => {
|
|
88
|
+
const pathname = toPathname(value)
|
|
89
|
+
if (isSystemRunPath(pathname)) {
|
|
90
|
+
const parts = pathname.split("/").filter(Boolean).slice(2)
|
|
91
|
+
return kernel.systemPath(...parts)
|
|
92
|
+
}
|
|
93
|
+
if (isLocalRunPath(pathname)) {
|
|
94
|
+
const parts = pathname.split("/").filter(Boolean).slice(1)
|
|
95
|
+
return kernel.path(...parts)
|
|
96
|
+
}
|
|
97
|
+
return ""
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const systemRelativeFromPluginPath = (normalizedPath) => {
|
|
101
|
+
return normalizeSlashes(normalizedPath).replace(/^\/pinokio\/run\/+/, "")
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const pluginPathToAbsolute = (kernel, normalizedPath) => {
|
|
105
|
+
if (isSystemPluginPath(normalizedPath)) {
|
|
106
|
+
return kernel.systemPath(systemRelativeFromPluginPath(normalizedPath))
|
|
107
|
+
}
|
|
108
|
+
return kernel.path(normalizeSlashes(normalizedPath).replace(/^\/+/, ""))
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const pluginRunHrefForPath = (normalizedPath) => {
|
|
112
|
+
if (typeof normalizedPath !== "string" || !normalizedPath) return ""
|
|
113
|
+
if (isSystemPluginPath(normalizedPath)) return normalizedPath
|
|
114
|
+
return `${LOCAL_RUN_PREFIX}${normalizedPath}`
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const normalizeActionPathComponents = (components) => {
|
|
118
|
+
const normalized = Array.isArray(components)
|
|
119
|
+
? components.filter((part) => typeof part === "string" && part.length > 0)
|
|
120
|
+
: []
|
|
121
|
+
if (normalized[0] === "pinokio" && normalized[1] === "run") {
|
|
122
|
+
return {
|
|
123
|
+
system: true,
|
|
124
|
+
pathComponents: normalized.slice(2),
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (normalized[0] === "run") {
|
|
128
|
+
return {
|
|
129
|
+
system: false,
|
|
130
|
+
pathComponents: normalized.slice(1),
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
system: false,
|
|
135
|
+
pathComponents: normalized,
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const pluginAssetHrefForIcon = (normalizedPath, icon) => {
|
|
140
|
+
const trimmedIcon = typeof icon === "string" ? icon.trim() : ""
|
|
141
|
+
if (!trimmedIcon) return ""
|
|
142
|
+
if (isSystemPluginPath(normalizedPath)) {
|
|
143
|
+
const relativeDir = path.posix.dirname(systemRelativeFromPluginPath(normalizedPath))
|
|
144
|
+
return `${SYSTEM_ASSET_PREFIX}/${relativeDir}/${trimmedIcon}`
|
|
145
|
+
}
|
|
146
|
+
if (normalizeSlashes(normalizedPath).startsWith("/plugin/")) {
|
|
147
|
+
const relativeDir = path.posix.dirname(normalizeSlashes(normalizedPath).slice(1))
|
|
148
|
+
return `${LOCAL_ASSET_PREFIX}/${relativeDir}/${trimmedIcon}`
|
|
149
|
+
}
|
|
150
|
+
return ""
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const isAction = (value) => Array.isArray(value) || typeof value === "function"
|
|
154
|
+
const isInstalledCheck = (value) => typeof value === "function"
|
|
155
|
+
const hasAllowedFunction = (config, key) => FUNCTION_KEYS.has(key) && typeof config[key] === "function"
|
|
156
|
+
const isPlainObject = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value)
|
|
157
|
+
const declaredPluginPath = (config) => typeof config.path === "string" ? config.path.trim() : ""
|
|
158
|
+
const hasInvalidTopLevelFunction = (config) => {
|
|
159
|
+
return Object.keys(config).some((key) => typeof config[key] === "function" && !hasAllowedFunction(config, key))
|
|
160
|
+
}
|
|
161
|
+
const hasInvalidAction = (config) => {
|
|
162
|
+
return Array.from(ACTION_KEYS).some((key) => key in config && !isAction(config[key]))
|
|
163
|
+
}
|
|
164
|
+
const hasInvalidInstalledCheck = (config) => {
|
|
165
|
+
return "installed" in config && !isInstalledCheck(config.installed)
|
|
166
|
+
}
|
|
167
|
+
const isValidPluginConfig = (config, options = {}) => {
|
|
168
|
+
if (!isPlainObject(config) || !isAction(config.run)) {
|
|
169
|
+
return false
|
|
170
|
+
}
|
|
171
|
+
if (hasInvalidTopLevelFunction(config) || hasInvalidAction(config) || hasInvalidInstalledCheck(config)) {
|
|
172
|
+
return false
|
|
173
|
+
}
|
|
174
|
+
if (options.standalone && declaredPluginPath(config) !== "plugin") {
|
|
175
|
+
return false
|
|
176
|
+
}
|
|
177
|
+
return true
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const normalizeLauncherTool = (toolValue) => {
|
|
181
|
+
let normalizedTool = typeof toolValue === "string" ? toolValue.trim() : ""
|
|
182
|
+
normalizedTool = normalizedTool.replace(/^https?:\/\/[^/]+/i, "")
|
|
183
|
+
normalizedTool = normalizedTool.replace(/^\/+|\/+$/g, "")
|
|
184
|
+
if (!normalizedTool || normalizedTool.includes("..") || !/^[A-Za-z0-9._/-]+$/.test(normalizedTool)) {
|
|
185
|
+
const error = new Error("Invalid plugin.")
|
|
186
|
+
error.status = 400
|
|
187
|
+
throw error
|
|
188
|
+
}
|
|
189
|
+
normalizedTool = BUILTIN_TOOL_ALIASES[normalizedTool] || normalizedTool
|
|
190
|
+
if (!normalizedTool.startsWith("pinokio/run/")) {
|
|
191
|
+
normalizedTool = normalizedTool.replace(/^run\//, "")
|
|
192
|
+
}
|
|
193
|
+
if (isLegacyPluginCodePath(normalizedTool)) {
|
|
194
|
+
const error = new Error("The managed plugin/code path is no longer used.")
|
|
195
|
+
error.status = 400
|
|
196
|
+
throw error
|
|
197
|
+
}
|
|
198
|
+
return normalizedTool
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const resolveLauncherPluginHref = (toolValue) => {
|
|
202
|
+
const normalizedTool = normalizeLauncherTool(toolValue)
|
|
203
|
+
if (normalizedTool.startsWith("pinokio/run/")) {
|
|
204
|
+
const scriptPath = normalizedTool.endsWith(".js")
|
|
205
|
+
? normalizedTool
|
|
206
|
+
: `${normalizedTool}/pinokio.js`
|
|
207
|
+
return `/${scriptPath}`
|
|
208
|
+
}
|
|
209
|
+
if (normalizedTool.startsWith("plugin/") || normalizedTool.startsWith("api/")) {
|
|
210
|
+
const scriptPath = normalizedTool.endsWith(".js")
|
|
211
|
+
? normalizedTool
|
|
212
|
+
: `${normalizedTool}/pinokio.js`
|
|
213
|
+
return `${LOCAL_RUN_PREFIX}/${scriptPath}`
|
|
214
|
+
}
|
|
215
|
+
return `${LOCAL_PLUGIN_RUN_PREFIX}/${normalizedTool}/pinokio.js`
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const resolveLauncherPluginSelection = (toolValue) => {
|
|
219
|
+
const href = resolveLauncherPluginHref(toolValue)
|
|
220
|
+
if (href.startsWith(`${LOCAL_RUN_PREFIX}/`)) {
|
|
221
|
+
return href.slice(LOCAL_RUN_PREFIX.length)
|
|
222
|
+
}
|
|
223
|
+
return href
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const normalizeLauncherSuccessPlugin = (successUrl, toolValue) => {
|
|
227
|
+
if (typeof successUrl !== "string" || typeof toolValue !== "string" || !toolValue.trim()) {
|
|
228
|
+
return successUrl
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
try {
|
|
232
|
+
const parsed = new URL(successUrl, "http://localhost")
|
|
233
|
+
if (!parsed.searchParams.has("plugin")) {
|
|
234
|
+
return successUrl
|
|
235
|
+
}
|
|
236
|
+
parsed.searchParams.set("plugin", resolveLauncherPluginSelection(toolValue))
|
|
237
|
+
return `${parsed.pathname}${parsed.search}${parsed.hash}`
|
|
238
|
+
} catch (_) {
|
|
239
|
+
return successUrl
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const loadPluginsFromRoot = async ({ kernel, root, runPrefix, assetPrefix, source, ignore = [], standalone = false }) => {
|
|
244
|
+
const exists = await fs.promises.stat(root).then((stat) => stat.isDirectory()).catch(() => false)
|
|
245
|
+
if (!exists) return []
|
|
246
|
+
|
|
247
|
+
const pluginPaths = await glob("**/pinokio.js", { cwd: root, ignore })
|
|
248
|
+
const plugins = []
|
|
249
|
+
for (const pluginPath of pluginPaths) {
|
|
250
|
+
const normalizedPluginPath = normalizeSlashes(pluginPath)
|
|
251
|
+
const config = await kernel.require(path.resolve(root, pluginPath))
|
|
252
|
+
if (!isValidPluginConfig(config, { standalone })) continue
|
|
253
|
+
|
|
254
|
+
const cwd = normalizedPluginPath.split("/").slice(0, -1).join("/")
|
|
255
|
+
const href = `${runPrefix}/${normalizedPluginPath}`
|
|
256
|
+
const image = config.icon ? `${assetPrefix}/${cwd}/${config.icon}` : config.image
|
|
257
|
+
plugins.push({
|
|
258
|
+
...config,
|
|
259
|
+
href,
|
|
260
|
+
src: href,
|
|
261
|
+
image,
|
|
262
|
+
source,
|
|
263
|
+
system: source === "system",
|
|
264
|
+
})
|
|
265
|
+
}
|
|
266
|
+
return plugins
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const loadPluginMenu = async (kernel) => {
|
|
270
|
+
const systemPlugins = await loadPluginsFromRoot({
|
|
271
|
+
kernel,
|
|
272
|
+
root: systemPluginRoot(kernel),
|
|
273
|
+
runPrefix: SYSTEM_PLUGIN_RUN_PREFIX,
|
|
274
|
+
assetPrefix: SYSTEM_PLUGIN_ASSET_PREFIX,
|
|
275
|
+
source: "system",
|
|
276
|
+
})
|
|
277
|
+
const localPlugins = await loadPluginsFromRoot({
|
|
278
|
+
kernel,
|
|
279
|
+
root: path.resolve(kernel.homedir, "plugin"),
|
|
280
|
+
runPrefix: LOCAL_PLUGIN_RUN_PREFIX,
|
|
281
|
+
assetPrefix: LOCAL_PLUGIN_ASSET_PREFIX,
|
|
282
|
+
source: "local",
|
|
283
|
+
ignore: ["code/**"],
|
|
284
|
+
standalone: true,
|
|
285
|
+
})
|
|
286
|
+
return systemPlugins.concat(localPlugins)
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
module.exports = {
|
|
290
|
+
SYSTEM_RUN_PREFIX,
|
|
291
|
+
SYSTEM_ASSET_PREFIX,
|
|
292
|
+
SYSTEM_PLUGIN_RUN_PREFIX,
|
|
293
|
+
systemRoot,
|
|
294
|
+
systemPluginRoot,
|
|
295
|
+
isSystemRunPath,
|
|
296
|
+
isRunPath,
|
|
297
|
+
isSystemPluginPath,
|
|
298
|
+
isLegacyPluginCodePath,
|
|
299
|
+
normalizePluginPath,
|
|
300
|
+
pluginSelectionMatches,
|
|
301
|
+
resolveRunPath,
|
|
302
|
+
pluginPathToAbsolute,
|
|
303
|
+
pluginRunHrefForPath,
|
|
304
|
+
normalizeActionPathComponents,
|
|
305
|
+
pluginAssetHrefForIcon,
|
|
306
|
+
resolveLauncherPluginHref,
|
|
307
|
+
resolveLauncherPluginSelection,
|
|
308
|
+
normalizeLauncherSuccessPlugin,
|
|
309
|
+
loadPluginMenu,
|
|
310
|
+
ACTION_KEYS,
|
|
311
|
+
STATUS_KEYS,
|
|
312
|
+
FUNCTION_KEYS,
|
|
313
|
+
isAction,
|
|
314
|
+
isInstalledCheck,
|
|
315
|
+
isValidPluginConfig,
|
|
316
|
+
}
|