@leeoohoo/ui-apps-devkit 0.1.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.
Files changed (55) hide show
  1. package/README.md +70 -0
  2. package/bin/chatos-uiapp.js +5 -0
  3. package/package.json +22 -0
  4. package/src/cli.js +53 -0
  5. package/src/commands/dev.js +14 -0
  6. package/src/commands/init.js +141 -0
  7. package/src/commands/install.js +55 -0
  8. package/src/commands/pack.js +72 -0
  9. package/src/commands/validate.js +103 -0
  10. package/src/lib/args.js +49 -0
  11. package/src/lib/config.js +29 -0
  12. package/src/lib/fs.js +78 -0
  13. package/src/lib/path-boundary.js +16 -0
  14. package/src/lib/plugin.js +45 -0
  15. package/src/lib/template.js +168 -0
  16. package/src/sandbox/server.js +861 -0
  17. package/templates/basic/README.md +58 -0
  18. package/templates/basic/chatos.config.json +5 -0
  19. package/templates/basic/docs/CHATOS_UI_APPS_AI_CONTRIBUTIONS.md +181 -0
  20. package/templates/basic/docs/CHATOS_UI_APPS_BACKEND_PROTOCOL.md +74 -0
  21. package/templates/basic/docs/CHATOS_UI_APPS_HOST_API.md +123 -0
  22. package/templates/basic/docs/CHATOS_UI_APPS_OVERVIEW.md +110 -0
  23. package/templates/basic/docs/CHATOS_UI_APPS_PLUGIN_MANIFEST.md +227 -0
  24. package/templates/basic/docs/CHATOS_UI_PROMPTS_PROTOCOL.md +392 -0
  25. package/templates/basic/plugin/apps/app/index.mjs +263 -0
  26. package/templates/basic/plugin/apps/app/mcp-prompt.en.md +7 -0
  27. package/templates/basic/plugin/apps/app/mcp-prompt.zh.md +7 -0
  28. package/templates/basic/plugin/apps/app/mcp-server.mjs +15 -0
  29. package/templates/basic/plugin/backend/index.mjs +37 -0
  30. package/templates/basic/template.json +7 -0
  31. package/templates/notepad/README.md +36 -0
  32. package/templates/notepad/chatos.config.json +4 -0
  33. package/templates/notepad/docs/CHATOS_UI_APPS_AI_CONTRIBUTIONS.md +181 -0
  34. package/templates/notepad/docs/CHATOS_UI_APPS_BACKEND_PROTOCOL.md +74 -0
  35. package/templates/notepad/docs/CHATOS_UI_APPS_HOST_API.md +123 -0
  36. package/templates/notepad/docs/CHATOS_UI_APPS_OVERVIEW.md +110 -0
  37. package/templates/notepad/docs/CHATOS_UI_APPS_PLUGIN_MANIFEST.md +227 -0
  38. package/templates/notepad/docs/CHATOS_UI_PROMPTS_PROTOCOL.md +392 -0
  39. package/templates/notepad/plugin/apps/app/api.mjs +30 -0
  40. package/templates/notepad/plugin/apps/app/dom.mjs +14 -0
  41. package/templates/notepad/plugin/apps/app/ds-tree.mjs +35 -0
  42. package/templates/notepad/plugin/apps/app/index.mjs +1056 -0
  43. package/templates/notepad/plugin/apps/app/layers.mjs +338 -0
  44. package/templates/notepad/plugin/apps/app/markdown.mjs +120 -0
  45. package/templates/notepad/plugin/apps/app/mcp-prompt.en.md +22 -0
  46. package/templates/notepad/plugin/apps/app/mcp-prompt.zh.md +22 -0
  47. package/templates/notepad/plugin/apps/app/mcp-server.mjs +200 -0
  48. package/templates/notepad/plugin/apps/app/styles.mjs +355 -0
  49. package/templates/notepad/plugin/apps/app/tags.mjs +21 -0
  50. package/templates/notepad/plugin/apps/app/ui.mjs +280 -0
  51. package/templates/notepad/plugin/backend/index.mjs +99 -0
  52. package/templates/notepad/plugin/plugin.json +23 -0
  53. package/templates/notepad/plugin/shared/notepad-paths.mjs +62 -0
  54. package/templates/notepad/plugin/shared/notepad-store.mjs +765 -0
  55. package/templates/notepad/template.json +8 -0
@@ -0,0 +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
+ }
@@ -0,0 +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
+ }
@@ -0,0 +1,62 @@
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
+