@gratux/sdk 1.0.0 → 1.0.1
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/README.md +43 -9
- package/dist/api-types.d.ts +5 -0
- package/dist/manifest.d.ts +7 -0
- package/dist/runtime.js +35 -2
- package/package.json +5 -1
- package/templates/basic/README.md +1 -1
- package/templates/webview/README.md +1 -1
package/README.md
CHANGED
|
@@ -5,14 +5,14 @@ status bar items, WebView views, editor edits, terminals, language features, fil
|
|
|
5
5
|
network, storage, Android APIs and AI — all backed by the Android runtime, with no
|
|
6
6
|
simulated behaviour.
|
|
7
7
|
|
|
8
|
-
> The SDK is
|
|
9
|
-
>
|
|
8
|
+
> The SDK is published on npm as [`@gratux/sdk`](https://www.npmjs.com/package/@gratux/sdk).
|
|
9
|
+
> Add it as a development dependency for types and tooling. Extension bundles must keep
|
|
10
|
+
> `@gratux/sdk` **external**; the app injects the API at runtime via
|
|
10
11
|
> `require("@gratux/sdk")`.
|
|
11
12
|
|
|
12
13
|
## Quick start
|
|
13
14
|
|
|
14
15
|
```bash
|
|
15
|
-
cd sdk
|
|
16
16
|
npm install
|
|
17
17
|
npm run build # compile the SDK (dist/)
|
|
18
18
|
npm test # node:test suite
|
|
@@ -53,12 +53,19 @@ Bundle and validate:
|
|
|
53
53
|
```bash
|
|
54
54
|
npx esbuild src/extension.ts --bundle --format=cjs --platform=neutral \
|
|
55
55
|
--target=es2020 --external:@gratux/sdk --outfile=dist/extension.js
|
|
56
|
-
node
|
|
56
|
+
node /path/to/gratux-sdk/scripts/validate-extension.mjs .
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Install the SDK in an extension project for TypeScript declarations and editor
|
|
60
|
+
autocomplete:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
npm install --save-dev @gratux/sdk esbuild
|
|
57
64
|
```
|
|
58
65
|
|
|
59
66
|
Pack a `.gxpkg` (zip with `gratux.json` and `dist/extension.js` at the root) and
|
|
60
67
|
install it from **Extensions → Install from file**, or drop it into
|
|
61
|
-
`app/src/main/assets/extensions/` and add a registry entry.
|
|
68
|
+
`gratux/app/src/main/assets/extensions/` and add a registry entry.
|
|
62
69
|
|
|
63
70
|
Templates: [`templates/basic`](templates/basic), [`templates/webview`](templates/webview).
|
|
64
71
|
Working samples: [`samples/`](samples) — Word Count, TODO Tree, JSON Tools, Quick Runner,
|
|
@@ -88,9 +95,9 @@ The authoritative validation lives in the Android app
|
|
|
88
95
|
| Module | What works |
|
|
89
96
|
| --- | --- |
|
|
90
97
|
| `commands` | register/unregister, execute contributed and built-in commands, list, onDidExecuteCommand |
|
|
91
|
-
| `window` | status bar items, messages, quick picks, input boxes, custom dialogs, progress, output/log channels, WebView views
|
|
98
|
+
| `window` | status bar items, messages, quick picks, input boxes, custom dialogs, progress, output/log channels, WebView views with package assets and `showView` |
|
|
92
99
|
| `workspace` | root/folders, `findFiles`, `relativePath`, `openFile`, `saveAll`, watchers (creation/change/deletion events), configuration |
|
|
93
|
-
| `fs` |
|
|
100
|
+
| `fs` | text and binary reads, write/exists/stat/list/create/delete/rename/copy — sandboxed to the workspace |
|
|
94
101
|
| `editor` | active document snapshot, selection, insert/replace/applyEdits, setSelection, reveal, save, find, replaceAll, line decorations, document/selection/save events |
|
|
95
102
|
| `languages` | register languages and completion/hover/definition/reference/formatting/code-action/symbol providers, diagnostics |
|
|
96
103
|
| `lsp` | register/start/stop language servers installed in the prefix, status |
|
|
@@ -98,7 +105,7 @@ The authoritative validation lives in the Android app
|
|
|
98
105
|
| `network` | `fetch` (native HTTP), `cancelAll`, `createWebSocket` |
|
|
99
106
|
| `storage` | per-extension key/value, secrets encrypted with an Android Keystore key |
|
|
100
107
|
| `config` | global/workspace settings, update, change events |
|
|
101
|
-
| `android` | notifications, clipboard, share, open URL, device info, document picker, lifecycle events |
|
|
108
|
+
| `android` | notifications, clipboard, share, open URL, device info, document picker, text/binary document reads, lifecycle events |
|
|
102
109
|
| `ai` | providers, models, one-shot requests, real streaming with cancellation |
|
|
103
110
|
| `env` | app/SDK version, arch, prefix, home, workspace |
|
|
104
111
|
| `permissions` | check/granted/declared |
|
|
@@ -127,7 +134,12 @@ The authoritative validation lives in the Android app
|
|
|
127
134
|
host their own LSP transport or semantic-token provider.
|
|
128
135
|
- WebSocket support is real but the host shares one JS sandbox: extensions are
|
|
129
136
|
isolated by token + permission checks, not by V8 isolates.
|
|
130
|
-
- WebView views render
|
|
137
|
+
- WebView views render in an expandable panel. Package-local JS/CSS/images load through
|
|
138
|
+
`webview.asWebviewUri`; remote page/resource loads require the `network.request`
|
|
139
|
+
permission. HTML video supports native fullscreen playback. Browser and PDF-reader
|
|
140
|
+
extensions can be built as WebView apps (PDF.js can be bundled as an extension asset).
|
|
141
|
+
`fs.readFileBytes` and `android.readDocumentBytes` return `Uint8Array` data for binary
|
|
142
|
+
formats; one native binary read is limited to 16 MB to bound memory use.
|
|
131
143
|
- No VS Code / VSIX / Open VSX compatibility; the manifest and API are Gratux-native.
|
|
132
144
|
|
|
133
145
|
## Security model
|
|
@@ -147,6 +159,28 @@ The authoritative validation lives in the Android app
|
|
|
147
159
|
See [`../docs/EXTENSION_PLATFORM.md`](../docs/EXTENSION_PLATFORM.md) for the full
|
|
148
160
|
architecture, lifecycle and roadmap.
|
|
149
161
|
|
|
162
|
+
## Publishing to npm
|
|
163
|
+
|
|
164
|
+
The `publish.yml` GitHub Actions workflow tests and builds the SDK on pushes to
|
|
165
|
+
`main` that change SDK source, build scripts, templates, or package metadata. It
|
|
166
|
+
publishes a version only when that version is not already on npm; bump
|
|
167
|
+
`package.json` and `package-lock.json` for each release. The workflow uses npm
|
|
168
|
+
Trusted Publishing with GitHub Actions OIDC and does not need an npm token.
|
|
169
|
+
|
|
170
|
+
Configure the package's **Trusted Publisher** settings on npmjs.com:
|
|
171
|
+
|
|
172
|
+
| Field | Value |
|
|
173
|
+
| --- | --- |
|
|
174
|
+
| Publisher | GitHub Actions |
|
|
175
|
+
| Organization or user | `PanditSiddharth` |
|
|
176
|
+
| Repository | `gratux-sdk` |
|
|
177
|
+
| Workflow filename | `publish.yml` |
|
|
178
|
+
| Environment name | Leave blank |
|
|
179
|
+
| Allowed action | Enable direct `npm publish` |
|
|
180
|
+
|
|
181
|
+
The workflow also supports manual runs from the GitHub Actions tab. Re-running
|
|
182
|
+
without a version bump safely skips a version that has already been published.
|
|
183
|
+
|
|
150
184
|
## Scripts
|
|
151
185
|
|
|
152
186
|
| Script | Purpose |
|
package/dist/api-types.d.ts
CHANGED
|
@@ -83,6 +83,7 @@ export interface Webview {
|
|
|
83
83
|
readonly options: WebviewOptions;
|
|
84
84
|
postMessage(message: unknown): Promise<boolean>;
|
|
85
85
|
readonly onDidReceiveMessage: Event<unknown>;
|
|
86
|
+
/** Resolves a package-relative path or extension-local file path to a WebView URL. */
|
|
86
87
|
asWebviewUri(path: string): Uri;
|
|
87
88
|
}
|
|
88
89
|
export interface WebviewView {
|
|
@@ -200,6 +201,7 @@ export interface FileStat {
|
|
|
200
201
|
}
|
|
201
202
|
export interface FileSystemApi {
|
|
202
203
|
readFile(path: string): Promise<string>;
|
|
204
|
+
readFileBytes(path: string): Promise<Uint8Array>;
|
|
203
205
|
readFileSync(path: string): string;
|
|
204
206
|
writeFile(path: string, content: string): Promise<void>;
|
|
205
207
|
writeFileSync(path: string, content: string): void;
|
|
@@ -563,6 +565,7 @@ export interface AndroidApi {
|
|
|
563
565
|
multiple?: boolean;
|
|
564
566
|
}): Promise<PickedDocument[]>;
|
|
565
567
|
readDocument(uri: string): Promise<string>;
|
|
568
|
+
readDocumentBytes(uri: string): Promise<Uint8Array>;
|
|
566
569
|
writeDocument(uri: string, content: string): Promise<boolean>;
|
|
567
570
|
readonly onDidChangeLifecycle: Event<{
|
|
568
571
|
state: "foreground" | "background";
|
|
@@ -616,6 +619,8 @@ export interface PermissionsApi {
|
|
|
616
619
|
check(permission: string): boolean;
|
|
617
620
|
getGranted(): string[];
|
|
618
621
|
getDeclared(): string[];
|
|
622
|
+
/** Requests a declared permission from the user; approved choices are remembered. */
|
|
623
|
+
request(permission: string): Promise<boolean>;
|
|
619
624
|
readonly onDidChange: Event<{
|
|
620
625
|
permission: string;
|
|
621
626
|
granted: boolean;
|
package/dist/manifest.d.ts
CHANGED
|
@@ -63,6 +63,12 @@ export interface ViewContribution {
|
|
|
63
63
|
location?: "sidebar" | "panel";
|
|
64
64
|
icon?: string;
|
|
65
65
|
}
|
|
66
|
+
export interface FileOpenerContribution {
|
|
67
|
+
title: string;
|
|
68
|
+
extensions: string[];
|
|
69
|
+
command: string;
|
|
70
|
+
priority?: number;
|
|
71
|
+
}
|
|
66
72
|
export interface LanguageContribution {
|
|
67
73
|
id: string;
|
|
68
74
|
extensions?: string[];
|
|
@@ -100,6 +106,7 @@ export interface Contributions {
|
|
|
100
106
|
keybindings?: KeybindingContribution[];
|
|
101
107
|
menus?: MenuContribution[];
|
|
102
108
|
views?: ViewContribution[];
|
|
109
|
+
fileOpeners?: FileOpenerContribution[];
|
|
103
110
|
languages?: LanguageContribution[];
|
|
104
111
|
languageServers?: LanguageServerContribution[];
|
|
105
112
|
configuration?: ConfigurationSchema;
|
package/dist/runtime.js
CHANGED
|
@@ -29,6 +29,13 @@ function selectorToJson(selector) {
|
|
|
29
29
|
return undefined;
|
|
30
30
|
return selector;
|
|
31
31
|
}
|
|
32
|
+
function decodeBase64(value) {
|
|
33
|
+
const binary = atob(value);
|
|
34
|
+
const bytes = new Uint8Array(binary.length);
|
|
35
|
+
for (let index = 0; index < binary.length; index++)
|
|
36
|
+
bytes[index] = binary.charCodeAt(index);
|
|
37
|
+
return bytes;
|
|
38
|
+
}
|
|
32
39
|
function createExtensionApi(binding) {
|
|
33
40
|
const transport = binding.transport;
|
|
34
41
|
const state = binding.state;
|
|
@@ -374,7 +381,23 @@ function createExtensionApi(binding) {
|
|
|
374
381
|
options: { enableScripts: true },
|
|
375
382
|
postMessage: (message) => post("window.webviewPostMessage", { viewId, message }).then((result) => Boolean(result?.delivered)),
|
|
376
383
|
onDidReceiveMessage: emitters.message.event,
|
|
377
|
-
asWebviewUri: (path) =>
|
|
384
|
+
asWebviewUri: (path) => {
|
|
385
|
+
const extensionPath = String(binding.manifest.__extensionPath ?? "").replace(/[\\/]+$/, "");
|
|
386
|
+
let relativePath = path;
|
|
387
|
+
if (path.startsWith("file:"))
|
|
388
|
+
relativePath = types_1.Uri.parse(path).fsPath;
|
|
389
|
+
if (extensionPath && (relativePath === extensionPath || relativePath.startsWith(`${extensionPath}/`))) {
|
|
390
|
+
relativePath = relativePath.slice(extensionPath.length);
|
|
391
|
+
}
|
|
392
|
+
else if (relativePath.startsWith("/")) {
|
|
393
|
+
throw new Error("Webview resources must be inside the extension package");
|
|
394
|
+
}
|
|
395
|
+
const segments = relativePath.split(/[\\/]+/).filter((segment) => segment && segment !== ".");
|
|
396
|
+
if (segments.some((segment) => segment === "..")) {
|
|
397
|
+
throw new Error("Webview resource path cannot escape the extension package");
|
|
398
|
+
}
|
|
399
|
+
return types_1.Uri.parse(`https://gratux.extension/${encodeURIComponent(binding.extensionId)}/${segments.map(encodeURIComponent).join("/")}`);
|
|
400
|
+
},
|
|
378
401
|
};
|
|
379
402
|
const view = {
|
|
380
403
|
viewId,
|
|
@@ -534,6 +557,7 @@ function createExtensionApi(binding) {
|
|
|
534
557
|
// ------------------------------------------------------------------- fs
|
|
535
558
|
const fs = {
|
|
536
559
|
readFile: (path) => post("fs.readFile", { path }),
|
|
560
|
+
readFileBytes: async (path) => decodeBase64(await post("fs.readFileBytes", { path })),
|
|
537
561
|
readFileSync: (path) => sync("fs.readFileSync", { path }) ?? "",
|
|
538
562
|
writeFile: async (path, content) => {
|
|
539
563
|
await post("fs.writeFile", { path, content });
|
|
@@ -916,6 +940,7 @@ function createExtensionApi(binding) {
|
|
|
916
940
|
getDeviceInfo: () => sync("android.deviceInfo"),
|
|
917
941
|
pickDocument: (options) => post("android.pickDocument", options ?? {}),
|
|
918
942
|
readDocument: (uri) => post("android.readDocument", { uri }),
|
|
943
|
+
readDocumentBytes: async (uri) => decodeBase64(await post("android.readDocumentBytes", { uri })),
|
|
919
944
|
writeDocument: async (uri, content) => (await post("android.writeDocument", { uri, content })).ok,
|
|
920
945
|
onDidChangeLifecycle: nativeEvent("android.lifecycle"),
|
|
921
946
|
};
|
|
@@ -1009,6 +1034,10 @@ function createExtensionApi(binding) {
|
|
|
1009
1034
|
};
|
|
1010
1035
|
// ----------------------------------------------------------- permissions
|
|
1011
1036
|
let granted;
|
|
1037
|
+
const onDidChangePermissions = nativeEvent("permissions.didChange");
|
|
1038
|
+
onDidChangePermissions(() => {
|
|
1039
|
+
granted = undefined;
|
|
1040
|
+
});
|
|
1012
1041
|
const permissions = {
|
|
1013
1042
|
check(permission) {
|
|
1014
1043
|
try {
|
|
@@ -1038,7 +1067,11 @@ function createExtensionApi(binding) {
|
|
|
1038
1067
|
return [];
|
|
1039
1068
|
}
|
|
1040
1069
|
},
|
|
1041
|
-
|
|
1070
|
+
async request(permission) {
|
|
1071
|
+
const result = await post("permissions.request", { permission });
|
|
1072
|
+
return Boolean(result?.granted);
|
|
1073
|
+
},
|
|
1074
|
+
onDidChange: onDidChangePermissions,
|
|
1042
1075
|
};
|
|
1043
1076
|
const api = {
|
|
1044
1077
|
version: exports.SDK_VERSION,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gratux/sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "TypeScript-first SDK for building Gratux Native extensions",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -49,5 +49,9 @@
|
|
|
49
49
|
},
|
|
50
50
|
"engines": {
|
|
51
51
|
"node": ">=18"
|
|
52
|
+
},
|
|
53
|
+
"repository": {
|
|
54
|
+
"type": "git",
|
|
55
|
+
"url": "git+https://github.com/PanditSiddharth/gratux-sdk.git"
|
|
52
56
|
}
|
|
53
57
|
}
|