@agy-daddy/plugin-template 0.0.0-stage → 1.0.0
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/LICENSE +21 -0
- package/README.md +6 -2
- package/agy-plugin.json +43 -0
- package/locales/en.json +1 -0
- package/locales/zh-CN.json +1 -0
- package/package.json +28 -4
- package/settings.schema.json +27 -0
- package/src/node.js +73 -0
- package/src/renderer.js +124 -0
- package/src/styles.js +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Agy-Daddy Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @agy-daddy/plugin-template
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Agy-Daddy 第三方社区插件标准模板(默认隔离世界 `isolated` + `T2` 权限最小化 + 紫色主题门禁 + `@agy-daddy/sdk` 契约测试)。
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm test
|
|
7
|
+
```
|
package/agy-plugin.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"id": "example.hello",
|
|
4
|
+
"publisher": "example",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"displayName": {
|
|
8
|
+
"zh-CN": "Hello 示例插件",
|
|
9
|
+
"en": "Hello Sample Plugin"
|
|
10
|
+
},
|
|
11
|
+
"description": {
|
|
12
|
+
"zh-CN": "Agy-Daddy 微内核 v2 官方示例插件(isolated 世界、全托管配置、声明式命令与样式自注入)",
|
|
13
|
+
"en": "Official Agy-Daddy microkernel v2 starter plugin (isolated world, host-managed settings, commands, and scoped style injection)"
|
|
14
|
+
},
|
|
15
|
+
"engines": {
|
|
16
|
+
"agyDaddy": "^1.0.0",
|
|
17
|
+
"antigravity": ">=2.32.0"
|
|
18
|
+
},
|
|
19
|
+
"main": "./src/node.js",
|
|
20
|
+
"renderer": "./src/renderer.js",
|
|
21
|
+
"world": "isolated",
|
|
22
|
+
"activationEvents": ["onStartup"],
|
|
23
|
+
"requires": {
|
|
24
|
+
"anchors": ["topbar.rightCluster"]
|
|
25
|
+
},
|
|
26
|
+
"provides": {
|
|
27
|
+
"services": {
|
|
28
|
+
"hello": { "version": "1.0.0", "realm": "node" }
|
|
29
|
+
},
|
|
30
|
+
"states": ["state:hello.greeting@1"],
|
|
31
|
+
"surfaces": []
|
|
32
|
+
},
|
|
33
|
+
"permissions": ["dom:write"],
|
|
34
|
+
"contributes": {
|
|
35
|
+
"topbar.units": [{ "id": "hello-badge", "order": 90 }],
|
|
36
|
+
"topbar.popovers": [{ "id": "hello-popover", "anchorId": "hello-badge" }],
|
|
37
|
+
"commands": [
|
|
38
|
+
{ "id": "hello.greet", "title": { "zh-CN": "发送示例问候", "en": "Run Sample Greeting" } }
|
|
39
|
+
],
|
|
40
|
+
"settings": { "schema": "./settings.schema.json" },
|
|
41
|
+
"locales": "./locales"
|
|
42
|
+
}
|
|
43
|
+
}
|
package/locales/en.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "badge.label": "Hello" }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "badge.label": "示例" }
|
package/package.json
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agy-daddy/plugin-template",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Official Agy-Daddy starter template for third-party isolated-world plugins",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/agy-daddy/agy-daddy.git",
|
|
9
|
+
"directory": "agy-daddy-plugin-template"
|
|
10
|
+
},
|
|
11
|
+
"main": "./src/node.js",
|
|
12
|
+
"agyPlugin": "./agy-plugin.json",
|
|
13
|
+
"files": [
|
|
14
|
+
"agy-plugin.json",
|
|
15
|
+
"settings.schema.json",
|
|
16
|
+
"src/",
|
|
17
|
+
"locales/",
|
|
18
|
+
"README.md",
|
|
19
|
+
"LICENSE"
|
|
20
|
+
],
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"test": "AGY_DADDY_TEST_MODE=1 node --test test/*.test.js"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=22.4.0"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"title": { "zh-CN": "示例插件设置", "en": "Sample Plugin Settings" },
|
|
3
|
+
"fields": [
|
|
4
|
+
{
|
|
5
|
+
"key": "greeting",
|
|
6
|
+
"type": "string",
|
|
7
|
+
"default": "Hello Agy-Daddy",
|
|
8
|
+
"placeholder": "Hello Agy-Daddy",
|
|
9
|
+
"label": { "zh-CN": "欢迎语", "en": "Greeting text" },
|
|
10
|
+
"description": { "zh-CN": "点击示例胶囊或执行问候命令时展示的提示文本", "en": "Message displayed when clicking the badge or running the greet command" }
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"key": "showBadge",
|
|
14
|
+
"type": "boolean",
|
|
15
|
+
"default": true,
|
|
16
|
+
"label": { "zh-CN": "显示顶栏示例胶囊", "en": "Show topbar sample badge" },
|
|
17
|
+
"description": { "zh-CN": "在顶栏右侧集群挂载示例状态胶囊入口", "en": "Mount the sample capsule inside the topbar right cluster" }
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"actions": [
|
|
21
|
+
{
|
|
22
|
+
"id": "greet-now",
|
|
23
|
+
"command": "hello.greet",
|
|
24
|
+
"label": { "zh-CN": "立即发送问候", "en": "Send Greeting Now" }
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
package/src/node.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const DEFAULT_SETTINGS = Object.freeze({
|
|
4
|
+
greeting: 'Hello Agy-Daddy',
|
|
5
|
+
showBadge: true
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
let disposers = [];
|
|
9
|
+
|
|
10
|
+
async function activate(host) {
|
|
11
|
+
let count = 0;
|
|
12
|
+
|
|
13
|
+
function readSettings() {
|
|
14
|
+
return {
|
|
15
|
+
...DEFAULT_SETTINGS,
|
|
16
|
+
...(host.settings?.get?.() || {})
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let settings = readSettings();
|
|
21
|
+
|
|
22
|
+
const serviceMethods = {
|
|
23
|
+
greet(name = 'Agy-Daddy') {
|
|
24
|
+
settings = readSettings();
|
|
25
|
+
count++;
|
|
26
|
+
const out = {
|
|
27
|
+
ok: true,
|
|
28
|
+
message: `Hello, ${name}!`,
|
|
29
|
+
greeting: settings.greeting,
|
|
30
|
+
count
|
|
31
|
+
};
|
|
32
|
+
host.state.set('state:hello.greeting@1', { ready: true, ...out });
|
|
33
|
+
return out;
|
|
34
|
+
},
|
|
35
|
+
getSettings() {
|
|
36
|
+
settings = readSettings();
|
|
37
|
+
return { ...settings };
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const stopSettings = host.settings?.onChange?.((nextValues) => {
|
|
42
|
+
settings = { ...DEFAULT_SETTINGS, ...(nextValues || {}) };
|
|
43
|
+
host.state.set('state:hello.greeting@1', {
|
|
44
|
+
ready: true,
|
|
45
|
+
greeting: settings.greeting,
|
|
46
|
+
showBadge: settings.showBadge,
|
|
47
|
+
count
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const stopSvc = await host.services.provide('hello', serviceMethods, { realm: 'node', version: '1.0.0' });
|
|
52
|
+
const stopCmd = await host.commands.register('hello.greet', (name = 'Agy-Daddy') => {
|
|
53
|
+
return serviceMethods.greet(name);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
host.state.set('state:hello.greeting@1', {
|
|
57
|
+
ready: true,
|
|
58
|
+
greeting: settings.greeting,
|
|
59
|
+
showBadge: settings.showBadge,
|
|
60
|
+
count
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
disposers.push(stopSettings, stopSvc, stopCmd);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function deactivate() {
|
|
67
|
+
for (const fn of disposers) {
|
|
68
|
+
try { if (typeof fn === 'function') fn(); } catch {}
|
|
69
|
+
}
|
|
70
|
+
disposers = [];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
module.exports = { activate, deactivate };
|
package/src/renderer.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { HELLO_TEMPLATE_STYLES } = require('./styles');
|
|
4
|
+
|
|
5
|
+
const DEFAULT_SETTINGS = Object.freeze({
|
|
6
|
+
greeting: 'Hello Agy-Daddy',
|
|
7
|
+
showBadge: true
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
let disposers = [];
|
|
11
|
+
|
|
12
|
+
async function mount(ctx) {
|
|
13
|
+
let settings = {
|
|
14
|
+
...DEFAULT_SETTINGS,
|
|
15
|
+
...(ctx.settings?.get?.() || {})
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const stopStyles = ctx.styles?.inject?.(HELLO_TEMPLATE_STYLES, {
|
|
19
|
+
scope: 'shadow',
|
|
20
|
+
id: 'hello-template-styles'
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
let stopUnit = null;
|
|
24
|
+
let popoverHandle = null;
|
|
25
|
+
let greetingNode = null;
|
|
26
|
+
let statusNode = null;
|
|
27
|
+
|
|
28
|
+
function renderPopoverContent(bodyNode) {
|
|
29
|
+
const doc = bodyNode?.ownerDocument || globalThis.document;
|
|
30
|
+
if (!bodyNode || !doc?.createElement) return;
|
|
31
|
+
bodyNode.innerHTML = '';
|
|
32
|
+
|
|
33
|
+
const card = doc.createElement('div');
|
|
34
|
+
card.className = 'agy-hello-card';
|
|
35
|
+
|
|
36
|
+
greetingNode = doc.createElement('div');
|
|
37
|
+
greetingNode.className = 'agy-hello-greeting';
|
|
38
|
+
greetingNode.textContent = settings.greeting;
|
|
39
|
+
card.appendChild(greetingNode);
|
|
40
|
+
|
|
41
|
+
statusNode = doc.createElement('div');
|
|
42
|
+
statusNode.className = 'agy-hello-meta';
|
|
43
|
+
statusNode.textContent = 'Isolated World · Host-Managed Settings';
|
|
44
|
+
card.appendChild(statusNode);
|
|
45
|
+
|
|
46
|
+
const actions = doc.createElement('div');
|
|
47
|
+
actions.className = 'agy-hello-actions';
|
|
48
|
+
const greetBtn = doc.createElement('button');
|
|
49
|
+
greetBtn.type = 'button';
|
|
50
|
+
greetBtn.className = 'ag-btn ag-btn-primary';
|
|
51
|
+
greetBtn.textContent = '发送问候';
|
|
52
|
+
greetBtn.addEventListener('click', () => {
|
|
53
|
+
void ctx.commands?.execute?.('hello.greet', ['Agy-Daddy']).then((res) => {
|
|
54
|
+
if (statusNode && res?.result?.message) {
|
|
55
|
+
statusNode.textContent = `${res.result.message} (#${res.result.count})`;
|
|
56
|
+
}
|
|
57
|
+
}).catch(() => {});
|
|
58
|
+
});
|
|
59
|
+
actions.appendChild(greetBtn);
|
|
60
|
+
card.appendChild(actions);
|
|
61
|
+
|
|
62
|
+
bodyNode.appendChild(card);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
popoverHandle = ctx.topbar.registerPopover({
|
|
66
|
+
id: 'hello-popover',
|
|
67
|
+
anchorId: 'hello-badge',
|
|
68
|
+
title: 'Hello 示例插件',
|
|
69
|
+
render(bodyNode) {
|
|
70
|
+
renderPopoverContent(bodyNode);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
function syncUnit() {
|
|
75
|
+
if (!settings.showBadge) {
|
|
76
|
+
if (typeof stopUnit === 'function') {
|
|
77
|
+
try { stopUnit(); } catch {}
|
|
78
|
+
stopUnit = null;
|
|
79
|
+
}
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (!stopUnit) {
|
|
83
|
+
stopUnit = ctx.topbar.registerUnit({
|
|
84
|
+
id: 'hello-badge',
|
|
85
|
+
order: 90,
|
|
86
|
+
label: 'Hello',
|
|
87
|
+
tone: 'accent',
|
|
88
|
+
onClick() {
|
|
89
|
+
void popoverHandle?.toggle?.();
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
} else {
|
|
93
|
+
void ctx.topbar.updateUnit('hello-badge', {
|
|
94
|
+
label: 'Hello',
|
|
95
|
+
tone: 'accent'
|
|
96
|
+
}).catch?.(() => {});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
syncUnit();
|
|
101
|
+
|
|
102
|
+
const stopSettings = ctx.settings?.onChange?.((nextValues) => {
|
|
103
|
+
settings = { ...DEFAULT_SETTINGS, ...(nextValues || {}) };
|
|
104
|
+
if (greetingNode) greetingNode.textContent = settings.greeting;
|
|
105
|
+
syncUnit();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
disposers.push(
|
|
109
|
+
stopSettings,
|
|
110
|
+
stopStyles,
|
|
111
|
+
() => { if (typeof stopUnit === 'function') stopUnit(); stopUnit = null; },
|
|
112
|
+
() => { popoverHandle?.dispose?.(); popoverHandle = null; },
|
|
113
|
+
() => { greetingNode = null; statusNode = null; }
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function dispose() {
|
|
118
|
+
for (const fn of disposers) {
|
|
119
|
+
try { if (typeof fn === 'function') fn(); } catch {}
|
|
120
|
+
}
|
|
121
|
+
disposers = [];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
module.exports = { mount, dispose };
|
package/src/styles.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const HELLO_TEMPLATE_STYLES = `
|
|
4
|
+
/* Example Hello Plugin Styles (auto-follows host --ag-* theme tokens) */
|
|
5
|
+
|
|
6
|
+
.agy-hello-card {
|
|
7
|
+
display: flex;
|
|
8
|
+
flex-direction: column;
|
|
9
|
+
gap: 8px;
|
|
10
|
+
padding: 12px 14px;
|
|
11
|
+
border-radius: 12px;
|
|
12
|
+
background: var(--ag-bg-card, rgba(255, 255, 255, 0.03));
|
|
13
|
+
border: 1px solid var(--ag-border-card, rgba(255, 255, 255, 0.09));
|
|
14
|
+
color: var(--ag-text-primary, #ececef);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.agy-hello-greeting {
|
|
18
|
+
font-size: 13.5px;
|
|
19
|
+
font-weight: 600;
|
|
20
|
+
color: var(--ag-custom-token-accent, var(--ag-text-primary, #18181b));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.agy-hello-meta {
|
|
24
|
+
font-size: 11px;
|
|
25
|
+
color: var(--ag-text-muted, #a1a1aa);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.agy-hello-actions {
|
|
29
|
+
display: flex;
|
|
30
|
+
align-items: center;
|
|
31
|
+
gap: 6px;
|
|
32
|
+
}
|
|
33
|
+
`.trim();
|
|
34
|
+
|
|
35
|
+
module.exports = {
|
|
36
|
+
HELLO_TEMPLATE_STYLES
|
|
37
|
+
};
|