@leeoohoo/ui-apps-devkit 0.1.0 → 0.1.2

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 +75 -60
  2. package/bin/chatos-uiapp.js +4 -4
  3. package/package.json +26 -20
  4. package/src/cli.js +53 -53
  5. package/src/commands/dev.js +14 -14
  6. package/src/commands/init.js +131 -129
  7. package/src/commands/install.js +47 -46
  8. package/src/commands/pack.js +72 -72
  9. package/src/commands/validate.js +138 -80
  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 -168
  17. package/src/sandbox/server.js +1957 -692
  18. package/templates/basic/README.md +78 -54
  19. package/templates/basic/chatos.config.json +5 -5
  20. package/templates/basic/docs/CHATOS_UI_APPS_AI_CONTRIBUTIONS.md +214 -181
  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 -123
  23. package/templates/basic/docs/CHATOS_UI_APPS_OVERVIEW.md +112 -107
  24. package/templates/basic/docs/CHATOS_UI_APPS_PLUGIN_MANIFEST.md +242 -227
  25. package/templates/basic/docs/CHATOS_UI_APPS_STYLE_GUIDE.md +95 -0
  26. package/templates/basic/docs/CHATOS_UI_APPS_TROUBLESHOOTING.md +45 -0
  27. package/templates/basic/docs/CHATOS_UI_PROMPTS_PROTOCOL.md +392 -392
  28. package/templates/basic/plugin/apps/app/compact.mjs +41 -0
  29. package/templates/basic/plugin/apps/app/index.mjs +287 -263
  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 +55 -24
  36. package/templates/notepad/chatos.config.json +4 -4
  37. package/templates/notepad/docs/CHATOS_UI_APPS_AI_CONTRIBUTIONS.md +214 -181
  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 -123
  40. package/templates/notepad/docs/CHATOS_UI_APPS_OVERVIEW.md +112 -107
  41. package/templates/notepad/docs/CHATOS_UI_APPS_PLUGIN_MANIFEST.md +242 -227
  42. package/templates/notepad/docs/CHATOS_UI_APPS_STYLE_GUIDE.md +95 -0
  43. package/templates/notepad/docs/CHATOS_UI_APPS_TROUBLESHOOTING.md +45 -0
  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 -0
  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 +206 -199
  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 +59 -41
  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
+ }
@@ -2,61 +2,79 @@ import fs from 'fs';
2
2
  import os from 'os';
3
3
  import path from 'path';
4
4
 
5
+ const STATE_ROOT_DIRNAME = '.deepseek_cli';
6
+ const COMPAT_STATE_ROOT_DIRNAME = '.chatos';
7
+
5
8
  function normalizeString(value) {
6
9
  return typeof value === 'string' ? value.trim() : '';
7
10
  }
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
-
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
+
28
31
  function tryEnsureWritableDir(dirPath) {
29
32
  const target = normalizeString(dirPath);
30
33
  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;
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;
41
44
  }
42
45
  }
43
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
+
44
53
  export function resolveUiAppDataDir({ pluginId, env } = {}) {
45
54
  const id = normalizeString(pluginId);
46
55
  if (!id) throw new Error('pluginId is required');
47
56
  const resolvedEnv = env && typeof env === 'object' ? env : process.env;
48
- const hostApp = resolveHostApp(resolvedEnv);
49
- const home = resolveHomeDir(resolvedEnv);
57
+ const hostApp = resolveHostApp(resolvedEnv);
58
+ const home = resolveHomeDir(resolvedEnv);
50
59
  const sessionRoot = resolveSessionRoot(resolvedEnv);
51
60
 
52
61
  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;
62
+ if (home) {
63
+ pushDataDir(candidates, home, STATE_ROOT_DIRNAME, hostApp, id);
64
+ pushDataDir(candidates, home, COMPAT_STATE_ROOT_DIRNAME, hostApp, id);
59
65
  }
60
- return candidates[0];
61
- }
62
-
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
+