@leeoohoo/ui-apps-devkit 0.1.1 → 0.1.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.
Files changed (62) hide show
  1. package/README.md +84 -76
  2. package/bin/chatos-uiapp.js +3 -4
  3. package/package.json +28 -25
  4. package/src/cli.js +53 -53
  5. package/src/commands/dev.js +14 -14
  6. package/src/commands/init.js +143 -142
  7. package/src/commands/install.js +56 -55
  8. package/src/commands/pack.js +72 -72
  9. package/src/commands/validate.js +113 -113
  10. package/src/lib/args.js +49 -49
  11. package/src/lib/config.js +29 -29
  12. package/src/lib/fs.js +78 -78
  13. package/src/lib/path-boundary.js +16 -16
  14. package/src/lib/plugin.js +45 -45
  15. package/src/lib/state-constants.js +2 -0
  16. package/src/lib/template.js +172 -172
  17. package/src/sandbox/server.js +2302 -1200
  18. package/templates/basic/README.md +80 -77
  19. package/templates/basic/chatos.config.json +5 -5
  20. package/templates/basic/docs/CHATOS_UI_APPS_AI_CONTRIBUTIONS.md +178 -178
  21. package/templates/basic/docs/CHATOS_UI_APPS_BACKEND_PROTOCOL.md +75 -74
  22. package/templates/basic/docs/CHATOS_UI_APPS_HOST_API.md +136 -136
  23. package/templates/basic/docs/CHATOS_UI_APPS_OVERVIEW.md +115 -113
  24. package/templates/basic/docs/CHATOS_UI_APPS_PLUGIN_MANIFEST.md +225 -224
  25. package/templates/basic/docs/CHATOS_UI_APPS_STYLE_GUIDE.md +95 -95
  26. package/templates/basic/docs/CHATOS_UI_APPS_TROUBLESHOOTING.md +45 -45
  27. package/templates/basic/docs/CHATOS_UI_PROMPTS_PROTOCOL.md +392 -392
  28. package/templates/basic/plugin/apps/app/compact.mjs +41 -41
  29. package/templates/basic/plugin/apps/app/index.mjs +287 -287
  30. package/templates/basic/plugin/apps/app/mcp-prompt.en.md +7 -7
  31. package/templates/basic/plugin/apps/app/mcp-prompt.zh.md +7 -7
  32. package/templates/basic/plugin/apps/app/mcp-server.mjs +15 -15
  33. package/templates/basic/plugin/backend/index.mjs +37 -37
  34. package/templates/basic/template.json +7 -7
  35. package/templates/notepad/README.md +61 -58
  36. package/templates/notepad/chatos.config.json +4 -4
  37. package/templates/notepad/docs/CHATOS_UI_APPS_AI_CONTRIBUTIONS.md +178 -178
  38. package/templates/notepad/docs/CHATOS_UI_APPS_BACKEND_PROTOCOL.md +75 -74
  39. package/templates/notepad/docs/CHATOS_UI_APPS_HOST_API.md +136 -136
  40. package/templates/notepad/docs/CHATOS_UI_APPS_OVERVIEW.md +115 -113
  41. package/templates/notepad/docs/CHATOS_UI_APPS_PLUGIN_MANIFEST.md +225 -224
  42. package/templates/notepad/docs/CHATOS_UI_APPS_STYLE_GUIDE.md +95 -95
  43. package/templates/notepad/docs/CHATOS_UI_APPS_TROUBLESHOOTING.md +45 -45
  44. package/templates/notepad/docs/CHATOS_UI_PROMPTS_PROTOCOL.md +392 -392
  45. package/templates/notepad/plugin/apps/app/api.mjs +30 -30
  46. package/templates/notepad/plugin/apps/app/compact.mjs +41 -41
  47. package/templates/notepad/plugin/apps/app/dom.mjs +14 -14
  48. package/templates/notepad/plugin/apps/app/ds-tree.mjs +35 -35
  49. package/templates/notepad/plugin/apps/app/index.mjs +1056 -1056
  50. package/templates/notepad/plugin/apps/app/layers.mjs +338 -338
  51. package/templates/notepad/plugin/apps/app/markdown.mjs +120 -120
  52. package/templates/notepad/plugin/apps/app/mcp-prompt.en.md +22 -22
  53. package/templates/notepad/plugin/apps/app/mcp-prompt.zh.md +22 -22
  54. package/templates/notepad/plugin/apps/app/mcp-server.mjs +207 -200
  55. package/templates/notepad/plugin/apps/app/styles.mjs +355 -355
  56. package/templates/notepad/plugin/apps/app/tags.mjs +21 -21
  57. package/templates/notepad/plugin/apps/app/ui.mjs +280 -280
  58. package/templates/notepad/plugin/backend/index.mjs +99 -99
  59. package/templates/notepad/plugin/plugin.json +23 -23
  60. package/templates/notepad/plugin/shared/notepad-paths.mjs +80 -62
  61. package/templates/notepad/plugin/shared/notepad-store.mjs +765 -765
  62. package/templates/notepad/template.json +8 -8
@@ -1,99 +1,99 @@
1
- import { createNotepadStore } from '../shared/notepad-store.mjs';
2
- import { resolveUiAppDataDir } from '../shared/notepad-paths.mjs';
3
-
4
- function normalizeString(value) {
5
- return typeof value === 'string' ? value.trim() : '';
6
- }
7
-
8
- function resolveFallbackDataDir(ctx) {
9
- const pluginId = normalizeString(ctx?.pluginId) || '__PLUGIN_ID__';
10
- return resolveUiAppDataDir({ pluginId });
11
- }
12
-
13
- export async function createUiAppsBackend(ctx) {
14
- const dataDir = normalizeString(ctx?.dataDir) || resolveFallbackDataDir(ctx);
15
- const store = createNotepadStore({ dataDir });
16
-
17
- return {
18
- methods: {
19
- async ping(params, ctx2) {
20
- return { ok: true, params: params ?? null, pluginId: ctx2?.pluginId || '' };
21
- },
22
-
23
- async 'notes.init'() {
24
- return await store.init();
25
- },
26
-
27
- async 'notes.listFolders'() {
28
- return await store.listFolders();
29
- },
30
-
31
- async 'notes.createFolder'(params) {
32
- return await store.createFolder({ folder: params?.folder });
33
- },
34
-
35
- async 'notes.renameFolder'(params) {
36
- return await store.renameFolder({ from: params?.from, to: params?.to });
37
- },
38
-
39
- async 'notes.deleteFolder'(params) {
40
- return await store.deleteFolder({ folder: params?.folder, recursive: params?.recursive === true });
41
- },
42
-
43
- async 'notes.listNotes'(params) {
44
- return await store.listNotes({
45
- folder: params?.folder,
46
- recursive: params?.recursive,
47
- tags: params?.tags,
48
- match: params?.match,
49
- query: params?.query,
50
- limit: params?.limit,
51
- });
52
- },
53
-
54
- async 'notes.createNote'(params) {
55
- return await store.createNote({
56
- folder: params?.folder,
57
- title: params?.title,
58
- content: params?.content,
59
- tags: params?.tags,
60
- });
61
- },
62
-
63
- async 'notes.getNote'(params) {
64
- return await store.getNote({ id: params?.id });
65
- },
66
-
67
- async 'notes.updateNote'(params) {
68
- return await store.updateNote({
69
- id: params?.id,
70
- title: params?.title,
71
- content: params?.content,
72
- folder: params?.folder,
73
- tags: params?.tags,
74
- });
75
- },
76
-
77
- async 'notes.deleteNote'(params) {
78
- return await store.deleteNote({ id: params?.id });
79
- },
80
-
81
- async 'notes.listTags'() {
82
- return await store.listTags();
83
- },
84
-
85
- async 'notes.searchNotes'(params) {
86
- return await store.searchNotes({
87
- query: params?.query,
88
- folder: params?.folder,
89
- recursive: params?.recursive,
90
- tags: params?.tags,
91
- match: params?.match,
92
- includeContent: params?.includeContent !== false,
93
- limit: params?.limit,
94
- });
95
- },
96
- },
97
- async dispose() {},
98
- };
99
- }
1
+ import { createNotepadStore } from '../shared/notepad-store.mjs';
2
+ import { resolveUiAppDataDir } from '../shared/notepad-paths.mjs';
3
+
4
+ function normalizeString(value) {
5
+ return typeof value === 'string' ? value.trim() : '';
6
+ }
7
+
8
+ function resolveFallbackDataDir(ctx) {
9
+ const pluginId = normalizeString(ctx?.pluginId) || '__PLUGIN_ID__';
10
+ return resolveUiAppDataDir({ pluginId });
11
+ }
12
+
13
+ export async function createUiAppsBackend(ctx) {
14
+ const dataDir = normalizeString(ctx?.dataDir) || resolveFallbackDataDir(ctx);
15
+ const store = createNotepadStore({ dataDir });
16
+
17
+ return {
18
+ methods: {
19
+ async ping(params, ctx2) {
20
+ return { ok: true, params: params ?? null, pluginId: ctx2?.pluginId || '' };
21
+ },
22
+
23
+ async 'notes.init'() {
24
+ return await store.init();
25
+ },
26
+
27
+ async 'notes.listFolders'() {
28
+ return await store.listFolders();
29
+ },
30
+
31
+ async 'notes.createFolder'(params) {
32
+ return await store.createFolder({ folder: params?.folder });
33
+ },
34
+
35
+ async 'notes.renameFolder'(params) {
36
+ return await store.renameFolder({ from: params?.from, to: params?.to });
37
+ },
38
+
39
+ async 'notes.deleteFolder'(params) {
40
+ return await store.deleteFolder({ folder: params?.folder, recursive: params?.recursive === true });
41
+ },
42
+
43
+ async 'notes.listNotes'(params) {
44
+ return await store.listNotes({
45
+ folder: params?.folder,
46
+ recursive: params?.recursive,
47
+ tags: params?.tags,
48
+ match: params?.match,
49
+ query: params?.query,
50
+ limit: params?.limit,
51
+ });
52
+ },
53
+
54
+ async 'notes.createNote'(params) {
55
+ return await store.createNote({
56
+ folder: params?.folder,
57
+ title: params?.title,
58
+ content: params?.content,
59
+ tags: params?.tags,
60
+ });
61
+ },
62
+
63
+ async 'notes.getNote'(params) {
64
+ return await store.getNote({ id: params?.id });
65
+ },
66
+
67
+ async 'notes.updateNote'(params) {
68
+ return await store.updateNote({
69
+ id: params?.id,
70
+ title: params?.title,
71
+ content: params?.content,
72
+ folder: params?.folder,
73
+ tags: params?.tags,
74
+ });
75
+ },
76
+
77
+ async 'notes.deleteNote'(params) {
78
+ return await store.deleteNote({ id: params?.id });
79
+ },
80
+
81
+ async 'notes.listTags'() {
82
+ return await store.listTags();
83
+ },
84
+
85
+ async 'notes.searchNotes'(params) {
86
+ return await store.searchNotes({
87
+ query: params?.query,
88
+ folder: params?.folder,
89
+ recursive: params?.recursive,
90
+ tags: params?.tags,
91
+ match: params?.match,
92
+ includeContent: params?.includeContent !== false,
93
+ limit: params?.limit,
94
+ });
95
+ },
96
+ },
97
+ async dispose() {},
98
+ };
99
+ }
@@ -1,23 +1,23 @@
1
- {
2
- "manifestVersion": 1,
3
- "id": "__PLUGIN_ID__",
4
- "name": "__PLUGIN_NAME__",
5
- "version": "__VERSION__",
6
- "description": "A ChatOS UI Apps example: Markdown notepad with folders & tags.",
7
- "backend": { "entry": "backend/index.mjs" },
8
- "apps": [
9
- {
10
- "id": "__APP_ID__",
11
- "name": "__PLUGIN_NAME__",
12
- "description": "Markdown 编辑/预览,文件夹分类,标签管理与快速检索。",
13
- "entry": { "type": "module", "path": "apps/__APP_ID__/index.mjs" },
14
- "ai": {
15
- "mcpPrompt": {
16
- "title": "__PLUGIN_NAME__ · MCP Prompt",
17
- "zh": "apps/__APP_ID__/mcp-prompt.zh.md",
18
- "en": "apps/__APP_ID__/mcp-prompt.en.md"
19
- }
20
- }
21
- }
22
- ]
23
- }
1
+ {
2
+ "manifestVersion": 1,
3
+ "id": "__PLUGIN_ID__",
4
+ "name": "__PLUGIN_NAME__",
5
+ "version": "__VERSION__",
6
+ "description": "A ChatOS UI Apps example: Markdown notepad with folders & tags.",
7
+ "backend": { "entry": "backend/index.mjs" },
8
+ "apps": [
9
+ {
10
+ "id": "__APP_ID__",
11
+ "name": "__PLUGIN_NAME__",
12
+ "description": "Markdown 编辑/预览,文件夹分类,标签管理与快速检索。",
13
+ "entry": { "type": "module", "path": "apps/__APP_ID__/index.mjs" },
14
+ "ai": {
15
+ "mcpPrompt": {
16
+ "title": "__PLUGIN_NAME__ · MCP Prompt",
17
+ "zh": "apps/__APP_ID__/mcp-prompt.zh.md",
18
+ "en": "apps/__APP_ID__/mcp-prompt.en.md"
19
+ }
20
+ }
21
+ }
22
+ ]
23
+ }
@@ -1,62 +1,80 @@
1
- import fs from 'fs';
2
- import os from 'os';
3
- import path from 'path';
4
-
5
- function normalizeString(value) {
6
- return typeof value === 'string' ? value.trim() : '';
7
- }
8
-
9
- function resolveHostApp(env) {
10
- const hostApp = normalizeString(env?.MODEL_CLI_HOST_APP);
11
- return hostApp || 'chatos';
12
- }
13
-
14
- function resolveHomeDir(env) {
15
- const homeEnv = normalizeString(env?.HOME) || normalizeString(env?.USERPROFILE);
16
- if (homeEnv) return homeEnv;
17
- try {
18
- return os.homedir();
19
- } catch {
20
- return '';
21
- }
22
- }
23
-
24
- function resolveSessionRoot(env) {
25
- return normalizeString(env?.MODEL_CLI_SESSION_ROOT);
26
- }
27
-
28
- function tryEnsureWritableDir(dirPath) {
29
- const target = normalizeString(dirPath);
30
- if (!target) return false;
31
- try {
32
- fs.mkdirSync(target, { recursive: true });
33
- } catch {
34
- return false;
35
- }
36
- try {
37
- fs.accessSync(target, fs.constants.W_OK);
38
- return true;
39
- } catch {
40
- return false;
41
- }
42
- }
43
-
44
- export function resolveUiAppDataDir({ pluginId, env } = {}) {
45
- const id = normalizeString(pluginId);
46
- if (!id) throw new Error('pluginId is required');
47
- const resolvedEnv = env && typeof env === 'object' ? env : process.env;
48
- const hostApp = resolveHostApp(resolvedEnv);
49
- const home = resolveHomeDir(resolvedEnv);
50
- const sessionRoot = resolveSessionRoot(resolvedEnv);
51
-
52
- const candidates = [];
53
- if (home) candidates.push(path.join(home, '.deepseek_cli', hostApp, 'ui_apps', 'data', id));
54
- if (sessionRoot) candidates.push(path.join(path.resolve(sessionRoot), '.deepseek_cli', hostApp, 'ui_apps', 'data', id));
55
- candidates.push(path.join(path.resolve(process.cwd()), '.deepseek_cli', hostApp, 'ui_apps', 'data', id));
56
-
57
- for (const candidate of candidates) {
58
- if (tryEnsureWritableDir(candidate)) return candidate;
59
- }
60
- return candidates[0];
61
- }
62
-
1
+ import fs from 'fs';
2
+ import os from 'os';
3
+ import path from 'path';
4
+
5
+ const STATE_ROOT_DIRNAME = '.deepseek_cli';
6
+ const COMPAT_STATE_ROOT_DIRNAME = '.chatos';
7
+
8
+ function normalizeString(value) {
9
+ return typeof value === 'string' ? value.trim() : '';
10
+ }
11
+
12
+ function resolveHostApp(env) {
13
+ const hostApp = normalizeString(env?.MODEL_CLI_HOST_APP);
14
+ return hostApp || 'chatos';
15
+ }
16
+
17
+ function resolveHomeDir(env) {
18
+ const homeEnv = normalizeString(env?.HOME) || normalizeString(env?.USERPROFILE);
19
+ if (homeEnv) return homeEnv;
20
+ try {
21
+ return os.homedir();
22
+ } catch {
23
+ return '';
24
+ }
25
+ }
26
+
27
+ function resolveSessionRoot(env) {
28
+ return normalizeString(env?.MODEL_CLI_SESSION_ROOT);
29
+ }
30
+
31
+ function tryEnsureWritableDir(dirPath) {
32
+ const target = normalizeString(dirPath);
33
+ if (!target) return false;
34
+ try {
35
+ fs.mkdirSync(target, { recursive: true });
36
+ } catch {
37
+ return false;
38
+ }
39
+ try {
40
+ fs.accessSync(target, fs.constants.W_OK);
41
+ return true;
42
+ } catch {
43
+ return false;
44
+ }
45
+ }
46
+
47
+ function pushDataDir(list, baseDir, rootDirName, hostApp, pluginId) {
48
+ const base = normalizeString(baseDir);
49
+ if (!base) return;
50
+ list.push(path.join(base, rootDirName, hostApp, 'ui_apps', 'data', pluginId));
51
+ }
52
+
53
+ export function resolveUiAppDataDir({ pluginId, env } = {}) {
54
+ const id = normalizeString(pluginId);
55
+ if (!id) throw new Error('pluginId is required');
56
+ const resolvedEnv = env && typeof env === 'object' ? env : process.env;
57
+ const hostApp = resolveHostApp(resolvedEnv);
58
+ const home = resolveHomeDir(resolvedEnv);
59
+ const sessionRoot = resolveSessionRoot(resolvedEnv);
60
+
61
+ const candidates = [];
62
+ if (home) {
63
+ pushDataDir(candidates, home, STATE_ROOT_DIRNAME, hostApp, id);
64
+ pushDataDir(candidates, home, COMPAT_STATE_ROOT_DIRNAME, hostApp, id);
65
+ }
66
+ if (sessionRoot) {
67
+ const root = path.resolve(sessionRoot);
68
+ pushDataDir(candidates, root, STATE_ROOT_DIRNAME, hostApp, id);
69
+ pushDataDir(candidates, root, COMPAT_STATE_ROOT_DIRNAME, hostApp, id);
70
+ }
71
+ const cwd = path.resolve(process.cwd());
72
+ pushDataDir(candidates, cwd, STATE_ROOT_DIRNAME, hostApp, id);
73
+ pushDataDir(candidates, cwd, COMPAT_STATE_ROOT_DIRNAME, hostApp, id);
74
+
75
+ for (const candidate of candidates) {
76
+ if (tryEnsureWritableDir(candidate)) return candidate;
77
+ }
78
+ return candidates[0];
79
+ }
80
+