@gemigo/app-sdk 0.2.5

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.
@@ -0,0 +1,167 @@
1
+ /**
2
+ * Browser Extension API types
3
+ *
4
+ * These APIs are only available when `gemigo.platform === 'extension'`.
5
+ *
6
+ * Note: This file defines the v1 "stable surface" used by the current Host/SW
7
+ * implementation. Future APIs are kept as optional to avoid blocking v1.
8
+ */
9
+ export interface PageInfo {
10
+ url: string;
11
+ title: string;
12
+ favIconUrl?: string;
13
+ }
14
+ export interface SelectionRect {
15
+ x: number;
16
+ y: number;
17
+ width: number;
18
+ height: number;
19
+ }
20
+ export interface SelectionResult {
21
+ text: string;
22
+ rect: SelectionRect | null;
23
+ }
24
+ export interface ElementInfo {
25
+ tagName: string;
26
+ text: string;
27
+ attributes: Record<string, string>;
28
+ }
29
+ export interface ArticleContent {
30
+ title: string;
31
+ content: string;
32
+ excerpt?: string;
33
+ url?: string;
34
+ }
35
+ export interface LinkInfo {
36
+ href: string;
37
+ text: string;
38
+ title?: string;
39
+ }
40
+ export interface ImageInfo {
41
+ src: string;
42
+ alt?: string;
43
+ width?: number;
44
+ height?: number;
45
+ }
46
+ export interface HighlightOptions {
47
+ color?: string;
48
+ duration?: number;
49
+ }
50
+ export interface WidgetPosition {
51
+ x: number;
52
+ y: number;
53
+ }
54
+ export interface WidgetConfig {
55
+ html: string;
56
+ position: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | WidgetPosition;
57
+ }
58
+ export interface WidgetHandle {
59
+ remove(): void;
60
+ update(html: string): void;
61
+ }
62
+ export interface CaptureFullOptions {
63
+ maxHeight?: number;
64
+ }
65
+ export interface ContextMenuEvent {
66
+ menuId: string;
67
+ selectionText?: string;
68
+ pageUrl?: string;
69
+ }
70
+ export interface ContextMenuEventResult {
71
+ success: boolean;
72
+ event?: ContextMenuEvent;
73
+ }
74
+ export interface CaptureResult {
75
+ success: boolean;
76
+ dataUrl?: string;
77
+ error?: string;
78
+ }
79
+ export interface HighlightResult {
80
+ success: boolean;
81
+ count?: number;
82
+ highlightId?: string;
83
+ error?: string;
84
+ }
85
+ export interface WidgetResult {
86
+ success: boolean;
87
+ widgetId?: string;
88
+ error?: string;
89
+ }
90
+ export interface CSSResult {
91
+ success: boolean;
92
+ styleId?: string;
93
+ error?: string;
94
+ }
95
+ export interface ExtractArticleResult {
96
+ success: boolean;
97
+ title?: string;
98
+ content?: string;
99
+ excerpt?: string;
100
+ url?: string;
101
+ error?: string;
102
+ }
103
+ export interface ExtractLinksResult {
104
+ success: boolean;
105
+ links?: LinkInfo[];
106
+ error?: string;
107
+ }
108
+ export interface ExtractImagesResult {
109
+ success: boolean;
110
+ images?: ImageInfo[];
111
+ error?: string;
112
+ }
113
+ export interface QueryElementResult {
114
+ success: boolean;
115
+ elements?: ElementInfo[];
116
+ count?: number;
117
+ error?: string;
118
+ }
119
+ /**
120
+ * Extension RPC Methods - shared between SDK and Host
121
+ *
122
+ * These methods are the actual RPC calls to the extension host.
123
+ * HostMethods extends this interface.
124
+ */
125
+ export interface ExtensionRPCMethods {
126
+ getPageInfo(): Promise<PageInfo | null>;
127
+ getPageHTML(): Promise<string>;
128
+ getPageText(): Promise<string>;
129
+ getSelection(): Promise<SelectionResult>;
130
+ extractArticle(): Promise<ExtractArticleResult>;
131
+ extractLinks(): Promise<ExtractLinksResult>;
132
+ extractImages(): Promise<ExtractImagesResult>;
133
+ queryElement(selector: string, limit?: number): Promise<QueryElementResult>;
134
+ highlight(selector: string, color?: string): Promise<HighlightResult>;
135
+ removeHighlight(highlightId: string): Promise<{
136
+ success: boolean;
137
+ error?: string;
138
+ }>;
139
+ insertWidget(html: string, position?: string | WidgetPosition): Promise<WidgetResult>;
140
+ updateWidget(widgetId: string, html: string): Promise<{
141
+ success: boolean;
142
+ error?: string;
143
+ }>;
144
+ removeWidget(widgetId: string): Promise<{
145
+ success: boolean;
146
+ error?: string;
147
+ }>;
148
+ injectCSS(css: string): Promise<CSSResult>;
149
+ removeCSS(styleId: string): Promise<{
150
+ success: boolean;
151
+ error?: string;
152
+ }>;
153
+ captureVisible(): Promise<CaptureResult>;
154
+ getContextMenuEvent(): Promise<ContextMenuEventResult>;
155
+ }
156
+ /**
157
+ * Full Extension API - includes RPC methods + local event handlers
158
+ */
159
+ export interface ExtensionAPI extends ExtensionRPCMethods {
160
+ onContextMenu(callback: (event: ContextMenuEvent) => void): () => void;
161
+ onSelectionChange(handler: (text: string, rect: SelectionRect | null, url?: string) => void): () => void;
162
+ onSelectionAction?: (actionId: string, callback: () => void) => () => void;
163
+ onNavigate?: (callback: (url: string) => void) => () => void;
164
+ onScroll?: (callback: (scrollY: number) => void) => () => void;
165
+ captureFull?: (options?: CaptureFullOptions) => Promise<CaptureResult>;
166
+ registerShortcut?: (combo: string, callback: () => void) => () => void;
167
+ }
@@ -0,0 +1,79 @@
1
+ import { FileEntry, FileStat } from './common';
2
+ /** Mkdir options */
3
+ export interface MkdirOptions {
4
+ /** Create parent directories if they don't exist */
5
+ recursive?: boolean;
6
+ }
7
+ /** File API for file system operations */
8
+ export interface FileAPI {
9
+ /**
10
+ * Read text file (UTF-8)
11
+ * @param path - File path
12
+ * @returns File content as text
13
+ */
14
+ readText(path: string): Promise<string>;
15
+ /**
16
+ * Read binary file
17
+ * @param path - File path
18
+ * @returns File content as ArrayBuffer
19
+ */
20
+ readBinary(path: string): Promise<ArrayBuffer>;
21
+ /**
22
+ * Write to file
23
+ * @param path - File path
24
+ * @param data - Content to write
25
+ */
26
+ write(path: string, data: string | ArrayBuffer): Promise<void>;
27
+ /**
28
+ * Append to file
29
+ * @param path - File path
30
+ * @param data - Content to append
31
+ */
32
+ append(path: string, data: string | ArrayBuffer): Promise<void>;
33
+ /**
34
+ * Check if path exists
35
+ * @param path - File path
36
+ * @returns True if exists
37
+ */
38
+ exists(path: string): Promise<boolean>;
39
+ /**
40
+ * Get file/directory stats
41
+ * @param path - File path
42
+ * @returns File stat information
43
+ */
44
+ stat(path: string): Promise<FileStat>;
45
+ /**
46
+ * Copy file
47
+ * @param src - Source path
48
+ * @param dest - Destination path
49
+ */
50
+ copy(src: string, dest: string): Promise<void>;
51
+ /**
52
+ * Move/rename file
53
+ * @param src - Source path
54
+ * @param dest - Destination path
55
+ */
56
+ move(src: string, dest: string): Promise<void>;
57
+ /**
58
+ * Remove file or directory
59
+ * @param path - Path to remove
60
+ */
61
+ remove(path: string): Promise<void>;
62
+ /**
63
+ * List directory contents
64
+ * @param path - Directory path
65
+ * @returns Array of file entries
66
+ */
67
+ list(path: string): Promise<FileEntry[]>;
68
+ /**
69
+ * Create directory
70
+ * @param path - Directory path
71
+ * @param options - Creation options
72
+ */
73
+ mkdir(path: string, options?: MkdirOptions): Promise<void>;
74
+ /**
75
+ * Persist permission for a user-selected path
76
+ * @param path - Path to persist permission for
77
+ */
78
+ persistPermission(path: string): Promise<void>;
79
+ }
@@ -0,0 +1,91 @@
1
+ import { Platform, Capabilities, SDKError, FileEntry } from './common';
2
+ import { StorageAPI } from './storage';
3
+ import { NotifyOptions, NotifyResult } from './notify';
4
+ import { AIAPI } from './ai';
5
+ import { ClipboardAPI } from './clipboard';
6
+ import { DialogAPI } from './dialog';
7
+ import { FileAPI } from './file';
8
+ import { NetworkAPI } from './network';
9
+ import { SchedulerAPI, FileWatchAPI, FileWatchEvent, ShellAPI, GlobalShortcutAPI, AutostartAPI } from './desktop';
10
+ import { ExtensionAPI } from './extension';
11
+ /**
12
+ * GemiGo SDK Types
13
+ *
14
+ * Complete TypeScript type definitions for the GemiGo SDK API.
15
+ */
16
+ export type { Platform, Capabilities, FileEntry, FileStat, RPCResult, RPCResultWithData, SDKErrorCode, } from './common';
17
+ export { SDKError } from './common';
18
+ export type { StorageAPI } from './storage';
19
+ export type { NotifyAction, NotifyOptions, NotifyResult, NotifyFn, NotificationActionHandler, } from './notify';
20
+ export type { ChatMessage, ChatResponse, TranslateOptions, TranslateResult, AIAPI } from './ai';
21
+ export type { ClipboardContent, ClipboardChangeCallback, ClipboardAPI } from './clipboard';
22
+ export type { FileFilter, OpenFileOptions, SaveFileOptions, MessageOptions, DialogAPI, FileDropCallback, FileDropHandler, } from './dialog';
23
+ export type { MkdirOptions, FileAPI } from './file';
24
+ export type { HttpMethod, ResponseType, RequestOptions, RequestResponse, NetworkAPI, } from './network';
25
+ export type { SchedulerConfig, SchedulerResult, SchedulerAPI, FileWatchEventType, FileWatchConfig, FileWatchEvent, FileWatchAPI, FileWatchHandler, ShellAPI, GlobalShortcutAPI, AutostartAPI, } from './desktop';
26
+ export type { PageInfo, SelectionRect, SelectionResult, ElementInfo, ArticleContent, LinkInfo, ImageInfo, HighlightOptions, WidgetPosition, WidgetConfig, WidgetHandle, CaptureFullOptions, ContextMenuEvent, ContextMenuEventResult, CaptureResult, HighlightResult, WidgetResult, CSSResult, ExtractArticleResult, ExtractLinksResult, ExtractImagesResult, QueryElementResult, ExtensionRPCMethods, ExtensionAPI, } from './extension';
27
+ export type { AppType, PlatformType, PermissionType, FileScope, ContextMenuContext, ContextMenuItem, SelectionAction, SidePanelConfig, UIConfig, BackgroundCapability, BackgroundConfig, FileConfig, ExtensionConfig, AppManifest, } from './manifest';
28
+ /**
29
+ * Complete GemiGo SDK interface
30
+ *
31
+ * Available APIs depend on the current platform:
32
+ * - `web`: Common APIs only
33
+ * - `desktop`: Common + Desktop APIs
34
+ * - `extension`: Common + Extension APIs
35
+ */
36
+ export interface GemigoSDK {
37
+ /** Current platform: 'web' | 'desktop' | 'extension' */
38
+ readonly platform: Platform;
39
+ /** Available capabilities for current environment */
40
+ readonly capabilities: Capabilities;
41
+ /** SDK Error class for error handling and instanceof checks */
42
+ readonly SDKError: typeof SDKError;
43
+ /** Persistent key-value storage */
44
+ storage: StorageAPI;
45
+ /**
46
+ * Send system notification
47
+ * @param options - Notification options
48
+ */
49
+ notify(options: NotifyOptions): Promise<NotifyResult>;
50
+ /**
51
+ * Listen for notification action button clicks
52
+ * @param actionId - Action ID from notification
53
+ * @param callback - Handler function
54
+ * @returns Unsubscribe function
55
+ */
56
+ onNotificationAction(actionId: string, callback: () => void): () => void;
57
+ /** AI/LLM integration */
58
+ ai: AIAPI;
59
+ /** Clipboard access */
60
+ clipboard: ClipboardAPI;
61
+ /** File/folder dialogs */
62
+ dialog: DialogAPI;
63
+ /**
64
+ * Listen for files dropped onto the app
65
+ * @param callback - Drop handler
66
+ * @returns Unsubscribe function
67
+ */
68
+ onFileDrop(callback: (files: FileEntry[]) => void): () => void;
69
+ /** File system operations */
70
+ file: FileAPI;
71
+ /** Cross-origin HTTP requests */
72
+ network: NetworkAPI;
73
+ /** Background scheduled tasks */
74
+ scheduler?: SchedulerAPI;
75
+ /** File system change monitoring */
76
+ fileWatch?: FileWatchAPI;
77
+ /**
78
+ * Listen for file watch events
79
+ * @param callbackId - Callback ID from registration
80
+ * @param handler - Event handler
81
+ */
82
+ onFileWatch?(callbackId: string, handler: (event: FileWatchEvent) => void): void;
83
+ /** System shell integration */
84
+ shell?: ShellAPI;
85
+ /** Global keyboard shortcuts */
86
+ globalShortcut?: GlobalShortcutAPI;
87
+ /** Auto-start on system boot */
88
+ autostart?: AutostartAPI;
89
+ /** Browser extension page interaction */
90
+ extension?: ExtensionAPI;
91
+ }
@@ -0,0 +1,87 @@
1
+ /**
2
+ * App Manifest types
3
+ */
4
+ /** Application type */
5
+ export type AppType = 'ui' | 'hybrid' | 'service';
6
+ /** Platform type */
7
+ export type PlatformType = 'web' | 'desktop' | 'extension';
8
+ /** Permission types */
9
+ export type PermissionType = 'storage' | 'notify' | 'scheduler' | 'fileWatch' | 'fileWrite' | 'ai' | 'clipboard' | 'shell' | 'network' | 'extension.modify' | 'extension.capture' | 'extension.shortcuts';
10
+ /** File scope paths */
11
+ export type FileScope = '$DOWNLOAD' | '$DOCUMENT' | '$PICTURE' | '$DESKTOP' | '$APP_DATA' | '$TEMP';
12
+ /** Context menu context types */
13
+ export type ContextMenuContext = 'selection' | 'page' | 'image';
14
+ /** Context menu item configuration */
15
+ export interface ContextMenuItem {
16
+ id: string;
17
+ title: string;
18
+ contexts: ContextMenuContext[];
19
+ }
20
+ /** Selection action configuration */
21
+ export interface SelectionAction {
22
+ id: string;
23
+ label: string;
24
+ icon?: string;
25
+ }
26
+ /** Side panel configuration */
27
+ export interface SidePanelConfig {
28
+ enabled: boolean;
29
+ icon?: string;
30
+ title?: string;
31
+ }
32
+ /** UI entry points */
33
+ export interface UIConfig {
34
+ /** Main UI HTML file */
35
+ main: string;
36
+ /** Settings UI HTML file (for hybrid/service apps) */
37
+ settings?: string;
38
+ }
39
+ /** Background capabilities */
40
+ export type BackgroundCapability = 'scheduler' | 'fileWatch';
41
+ /** Background configuration */
42
+ export interface BackgroundConfig {
43
+ enabled: boolean;
44
+ capabilities?: BackgroundCapability[];
45
+ }
46
+ /** File permission configuration */
47
+ export interface FileConfig {
48
+ scope?: FileScope[];
49
+ }
50
+ /** Extension-specific configuration */
51
+ export interface ExtensionConfig {
52
+ sidePanel?: SidePanelConfig;
53
+ contextMenu?: ContextMenuItem[];
54
+ selectionAction?: SelectionAction;
55
+ }
56
+ /**
57
+ * Application manifest definition
58
+ * The manifest.json file that configures app metadata and permissions
59
+ */
60
+ export interface AppManifest {
61
+ /** App name (required) */
62
+ name: string;
63
+ /** Version string (required) */
64
+ version: string;
65
+ /** App description (required) */
66
+ description: string;
67
+ /** App icon relative path (required) */
68
+ icon: string;
69
+ /** Author name */
70
+ author?: string;
71
+ /** App type (default: 'ui') */
72
+ type?: AppType;
73
+ /** Supported platforms */
74
+ platforms?: PlatformType[];
75
+ /** Required permissions */
76
+ permissions?: PermissionType[];
77
+ /** UI entry configuration */
78
+ ui?: UIConfig;
79
+ /** Installation script */
80
+ onInstall?: string;
81
+ /** File permission scopes */
82
+ file?: FileConfig;
83
+ /** Background task configuration */
84
+ background?: BackgroundConfig;
85
+ /** Browser extension configuration */
86
+ extension?: ExtensionConfig;
87
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Network API types
3
+ */
4
+ /** HTTP request method */
5
+ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE';
6
+ /** Response type */
7
+ export type ResponseType = 'json' | 'text' | 'arraybuffer';
8
+ /** Request options */
9
+ export interface RequestOptions {
10
+ /** HTTP method */
11
+ method?: HttpMethod;
12
+ /** Request headers */
13
+ headers?: Record<string, string>;
14
+ /** Request body */
15
+ body?: string | object;
16
+ /** Response type */
17
+ responseType?: ResponseType;
18
+ }
19
+ /** Request response */
20
+ export interface RequestResponse<T = unknown> {
21
+ /** HTTP status code */
22
+ status: number;
23
+ /** Response data */
24
+ data: T;
25
+ /** Response headers */
26
+ headers: Record<string, string>;
27
+ }
28
+ /** Network API for cross-origin HTTP requests */
29
+ export interface NetworkAPI {
30
+ /**
31
+ * Make an HTTP request (bypasses CORS restrictions)
32
+ * @param url - Request URL
33
+ * @param options - Request options
34
+ * @returns Response with status, data, and headers
35
+ */
36
+ request<T = unknown>(url: string, options?: RequestOptions): Promise<RequestResponse<T>>;
37
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Notify API types
3
+ */
4
+ /** Notification action button */
5
+ export interface NotifyAction {
6
+ id: string;
7
+ label: string;
8
+ }
9
+ /** Notification options */
10
+ export interface NotifyOptions {
11
+ /** Notification title (required) */
12
+ title: string;
13
+ /** Notification message text */
14
+ message?: string;
15
+ /** Icon URL */
16
+ icon?: string;
17
+ /** Action buttons (desktop only) */
18
+ actions?: NotifyAction[];
19
+ }
20
+ /** Notification result */
21
+ export interface NotifyResult {
22
+ success: boolean;
23
+ reason?: string;
24
+ }
25
+ /** Notify function signature */
26
+ export type NotifyFn = (options: NotifyOptions) => Promise<NotifyResult>;
27
+ /** Notification action handler */
28
+ export type NotificationActionHandler = (actionId: string, callback: () => void) => () => void;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Storage API types
3
+ */
4
+ /** Storage API for persistent key-value storage */
5
+ export interface StorageAPI {
6
+ /**
7
+ * Get a stored value
8
+ * @param key - Storage key
9
+ * @returns The stored value or null if not found
10
+ */
11
+ get<T = unknown>(key: string): Promise<T | null>;
12
+ /**
13
+ * Store a value
14
+ * @param key - Storage key
15
+ * @param value - Value to store (will be JSON serialized)
16
+ */
17
+ set(key: string, value: unknown): Promise<void>;
18
+ /**
19
+ * Delete a stored value
20
+ * @param key - Storage key
21
+ */
22
+ delete(key: string): Promise<void>;
23
+ /**
24
+ * Clear all data for the current app
25
+ */
26
+ clear(): Promise<void>;
27
+ }
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@gemigo/app-sdk",
3
+ "private": false,
4
+ "version": "0.2.5",
5
+ "type": "module",
6
+ "description": "GemiGo App SDK (auto-adapts for web/desktop/extension)",
7
+ "main": "dist/gemigo-app-sdk.umd.js",
8
+ "module": "dist/gemigo-app-sdk.es.js",
9
+ "types": "dist/index.d.ts",
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "dependencies": {
14
+ "penpal": "^6.2.2"
15
+ },
16
+ "devDependencies": {
17
+ "typescript": "^5.7.2",
18
+ "vite": "^6.2.5",
19
+ "vite-plugin-dts": "^4.5.4"
20
+ },
21
+ "scripts": {
22
+ "build": "vite build",
23
+ "dev": "vite build --watch",
24
+ "format": "prettier --write .",
25
+ "lint": "eslint ."
26
+ }
27
+ }