@glassly/miniapp-cli 0.1.0-beta.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.
- package/README.md +248 -0
- package/package.json +49 -0
- package/schema/miniapp.schema.json +269 -0
- package/src/api.ts +10 -0
- package/src/build-helpers.test.ts +104 -0
- package/src/build-helpers.ts +357 -0
- package/src/build.ts +67 -0
- package/src/dev-server.test.ts +138 -0
- package/src/dev-server.ts +454 -0
- package/src/dev.ts +348 -0
- package/src/hardware.ts +163 -0
- package/src/lan.test.ts +84 -0
- package/src/lan.ts +161 -0
- package/src/manifest-format.ts +121 -0
- package/src/manifest-mutate.test.ts +191 -0
- package/src/manifest-mutate.ts +213 -0
- package/src/manifest-wizard.ts +218 -0
- package/src/manifest.test.ts +376 -0
- package/src/manifest.ts +412 -0
- package/src/pack.ts +131 -0
- package/src/permission-hints.ts +40 -0
- package/src/permission.ts +142 -0
- package/src/qr.test.ts +81 -0
- package/src/qr.ts +119 -0
- package/src/regenerate-schema.ts +6 -0
- package/src/release.ts +265 -0
- package/src/schema.test.ts +64 -0
- package/src/schema.ts +258 -0
package/src/schema.ts
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
// JSON Schema generator for miniapp.json.
|
|
2
|
+
//
|
|
3
|
+
// The schema is built from the same constants the validator uses (ALLOWED_PERMISSIONS,
|
|
4
|
+
// ALLOWED_HARDWARE_TYPES, ALLOWED_HARDWARE_LEVELS) so the two never drift.
|
|
5
|
+
//
|
|
6
|
+
// Surface:
|
|
7
|
+
// - generateSchema(): returns the JSON Schema object
|
|
8
|
+
// - glassly schema print : prints the schema to stdout
|
|
9
|
+
//
|
|
10
|
+
// Authors point their IDE at the schema via $schema in miniapp.json:
|
|
11
|
+
// "$schema": "./node_modules/@glassly/miniapp-cli/schema/miniapp.schema.json"
|
|
12
|
+
//
|
|
13
|
+
// The scaffolder injects this $schema line so new projects get autocomplete on
|
|
14
|
+
// day one without anyone having to know it exists.
|
|
15
|
+
|
|
16
|
+
import {writeFileSync, mkdirSync} from 'fs';
|
|
17
|
+
import {dirname, resolve} from 'path';
|
|
18
|
+
import {fileURLToPath} from 'url';
|
|
19
|
+
import {
|
|
20
|
+
ALLOWED_PERMISSIONS,
|
|
21
|
+
ALLOWED_HARDWARE_TYPES,
|
|
22
|
+
ALLOWED_HARDWARE_LEVELS,
|
|
23
|
+
ALLOWED_ACTION_PARAM_TYPES,
|
|
24
|
+
KNOWN_TAGS,
|
|
25
|
+
TAGLINE_MAX_LENGTH,
|
|
26
|
+
TAGS_MAX_COUNT,
|
|
27
|
+
TAG_MAX_LENGTH,
|
|
28
|
+
} from './manifest.js';
|
|
29
|
+
|
|
30
|
+
const SCHEMA_ID = 'https://schemas.glassly.com/miniapp/v1.json';
|
|
31
|
+
|
|
32
|
+
export function generateSchema(): Record<string, unknown> {
|
|
33
|
+
return {
|
|
34
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
35
|
+
$id: SCHEMA_ID,
|
|
36
|
+
title: 'Glassly miniapp manifest',
|
|
37
|
+
description: 'Manifest schema for a Glassly miniapp (miniapp.json)',
|
|
38
|
+
type: 'object',
|
|
39
|
+
required: ['packageName', 'version', 'name', 'hardwareRequirements'],
|
|
40
|
+
additionalProperties: true,
|
|
41
|
+
properties: {
|
|
42
|
+
$schema: {type: 'string'},
|
|
43
|
+
packageName: {
|
|
44
|
+
type: 'string',
|
|
45
|
+
pattern: '^[a-zA-Z][a-zA-Z0-9_]*(\\.[a-zA-Z][a-zA-Z0-9_]*)+$',
|
|
46
|
+
description: 'Reverse-DNS app identifier (e.g. com.example.app)',
|
|
47
|
+
},
|
|
48
|
+
version: {
|
|
49
|
+
type: 'string',
|
|
50
|
+
description: 'Semver version string (e.g. 1.0.0)',
|
|
51
|
+
},
|
|
52
|
+
name: {
|
|
53
|
+
type: 'string',
|
|
54
|
+
description: 'Human-readable app name',
|
|
55
|
+
},
|
|
56
|
+
description: {
|
|
57
|
+
type: 'string',
|
|
58
|
+
description: 'Short description shown in the store / dev tools',
|
|
59
|
+
},
|
|
60
|
+
tagline: {
|
|
61
|
+
type: 'string',
|
|
62
|
+
maxLength: TAGLINE_MAX_LENGTH,
|
|
63
|
+
description: 'One line shown under the name in the Glassly Miniapp Store',
|
|
64
|
+
},
|
|
65
|
+
tags: {
|
|
66
|
+
type: 'array',
|
|
67
|
+
maxItems: TAGS_MAX_COUNT,
|
|
68
|
+
uniqueItems: true,
|
|
69
|
+
description: `Store tags used as filter chips. Known tags: ${KNOWN_TAGS.join(', ')}. Other lowercase slugs are accepted.`,
|
|
70
|
+
items: {
|
|
71
|
+
type: 'string',
|
|
72
|
+
pattern: '^[a-z0-9]+(?:-[a-z0-9]+)*$',
|
|
73
|
+
maxLength: TAG_MAX_LENGTH,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
icon: {
|
|
77
|
+
type: 'string',
|
|
78
|
+
description: 'Path or URL to the app icon (e.g. icon.png)',
|
|
79
|
+
},
|
|
80
|
+
port: {
|
|
81
|
+
type: 'integer',
|
|
82
|
+
minimum: 1,
|
|
83
|
+
maximum: 65535,
|
|
84
|
+
description: 'Port the dev server listens on (default 3000)',
|
|
85
|
+
},
|
|
86
|
+
sdkVersion: {
|
|
87
|
+
type: 'string',
|
|
88
|
+
description: 'Semver of the @glassly/miniapp SDK this bundle targets. Host refuses to spawn a miniapp whose sdkVersion is incompatible with the runtime it ships.',
|
|
89
|
+
},
|
|
90
|
+
minHostVersion: {
|
|
91
|
+
type: 'string',
|
|
92
|
+
description: 'Semver of the lowest Glassly Manager host version that can run this bundle. The host re-validates this on every install and after host upgrades; bundles that no longer meet the bar are disabled (not deleted) with a clear UI.',
|
|
93
|
+
},
|
|
94
|
+
entry: {
|
|
95
|
+
type: 'object',
|
|
96
|
+
description: 'Two-layer bundle entry points. Background is the always-running JSContext entry; UI is the on-demand WebView entry.',
|
|
97
|
+
additionalProperties: false,
|
|
98
|
+
required: ['background'],
|
|
99
|
+
properties: {
|
|
100
|
+
background: {
|
|
101
|
+
type: 'string',
|
|
102
|
+
description: 'Path to the background bundle, relative to the bundle root (e.g. background/index.js). Required for V2+ two-layer bundles.',
|
|
103
|
+
},
|
|
104
|
+
ui: {
|
|
105
|
+
type: 'string',
|
|
106
|
+
description: "Path to the UI bundle entry HTML, relative to the bundle root (e.g. ui/index.html). Optional -- pure-background miniapps don't need a WebView.",
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
type: {
|
|
111
|
+
type: 'string',
|
|
112
|
+
enum: ['standard', 'background', 'dashboard'],
|
|
113
|
+
description:
|
|
114
|
+
"Miniapp type. 'standard' includes a UI WebView; 'background' is JSContext-only; 'dashboard' is a standard app that can hold the dashboard role (one dashboard runs at a time, and the host hands the running one the overlay slot). Defaults to 'standard'.",
|
|
115
|
+
},
|
|
116
|
+
alwaysOn: {
|
|
117
|
+
type: 'boolean',
|
|
118
|
+
description:
|
|
119
|
+
'Always On miniapp: the host starts it at launch and its background task keeps running after its app switcher card is swiped away. The wearer can still stop it or turn Always On off from the home grid.',
|
|
120
|
+
},
|
|
121
|
+
permissions: {
|
|
122
|
+
type: 'array',
|
|
123
|
+
description: 'Phone permissions the miniapp needs to declare',
|
|
124
|
+
items: {
|
|
125
|
+
type: 'object',
|
|
126
|
+
required: ['type'],
|
|
127
|
+
additionalProperties: false,
|
|
128
|
+
properties: {
|
|
129
|
+
type: {
|
|
130
|
+
type: 'string',
|
|
131
|
+
enum: [...ALLOWED_PERMISSIONS],
|
|
132
|
+
description: 'Permission type',
|
|
133
|
+
},
|
|
134
|
+
required: {
|
|
135
|
+
type: 'boolean',
|
|
136
|
+
description:
|
|
137
|
+
'If false, the permission is optional: asked at launch after the required ones, and the miniapp opens without it. Defaults to true.',
|
|
138
|
+
},
|
|
139
|
+
description: {
|
|
140
|
+
type: 'string',
|
|
141
|
+
description: "User-facing reason this permission is needed (shown in OS prompts)",
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
hardwareRequirements: {
|
|
147
|
+
type: 'array',
|
|
148
|
+
description: 'Glasses hardware capabilities the miniapp needs',
|
|
149
|
+
items: {
|
|
150
|
+
type: 'object',
|
|
151
|
+
required: ['type', 'level'],
|
|
152
|
+
additionalProperties: false,
|
|
153
|
+
properties: {
|
|
154
|
+
type: {
|
|
155
|
+
type: 'string',
|
|
156
|
+
enum: [...ALLOWED_HARDWARE_TYPES],
|
|
157
|
+
description: 'Hardware capability type',
|
|
158
|
+
},
|
|
159
|
+
level: {
|
|
160
|
+
type: 'string',
|
|
161
|
+
enum: [...ALLOWED_HARDWARE_LEVELS],
|
|
162
|
+
description: 'REQUIRED hides the app on glasses without it; OPTIONAL still lets it run',
|
|
163
|
+
},
|
|
164
|
+
description: {
|
|
165
|
+
type: 'string',
|
|
166
|
+
description: 'How the miniapp uses this hardware',
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
actions: {
|
|
172
|
+
type: 'array',
|
|
173
|
+
description: 'Actions other miniapps can discover and invoke via session.actions. Maps 1:1 onto MCP tools.',
|
|
174
|
+
items: {
|
|
175
|
+
type: 'object',
|
|
176
|
+
required: ['id', 'description'],
|
|
177
|
+
additionalProperties: false,
|
|
178
|
+
properties: {
|
|
179
|
+
id: {
|
|
180
|
+
type: 'string',
|
|
181
|
+
pattern: '^[a-z][a-z0-9_]*$',
|
|
182
|
+
maxLength: 64,
|
|
183
|
+
description: 'Unique-within-app action id (lowercase, starts with a letter).',
|
|
184
|
+
},
|
|
185
|
+
description: {
|
|
186
|
+
type: 'string',
|
|
187
|
+
description: 'AI-facing contract -- say when to use the action.',
|
|
188
|
+
},
|
|
189
|
+
visibility: {
|
|
190
|
+
type: 'string',
|
|
191
|
+
enum: ['public', 'system'],
|
|
192
|
+
description:
|
|
193
|
+
'Who may invoke this action: "public" (default -- any installed miniapp) or "system" (system miniapps such as the AI assistant only).',
|
|
194
|
+
},
|
|
195
|
+
parameters: {
|
|
196
|
+
type: 'object',
|
|
197
|
+
description: 'JSON-Schema input descriptor (the MCP inputSchema subset).',
|
|
198
|
+
properties: {
|
|
199
|
+
type: {const: 'object'},
|
|
200
|
+
properties: {
|
|
201
|
+
type: 'object',
|
|
202
|
+
additionalProperties: {
|
|
203
|
+
type: 'object',
|
|
204
|
+
properties: {
|
|
205
|
+
type: {type: 'string', enum: [...ALLOWED_ACTION_PARAM_TYPES]},
|
|
206
|
+
description: {type: 'string'},
|
|
207
|
+
enum: {type: 'array'},
|
|
208
|
+
items: {
|
|
209
|
+
type: 'object',
|
|
210
|
+
properties: {
|
|
211
|
+
type: {type: 'string', enum: ['string', 'number', 'boolean']},
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
required: {type: 'array', items: {type: 'string'}},
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
outputSchema: {
|
|
221
|
+
type: 'object',
|
|
222
|
+
description: 'JSON-Schema descriptor for the structured action result (MCP outputSchema).',
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** Returns the schema as a pretty-printed JSON string. */
|
|
232
|
+
export function generateSchemaString(): string {
|
|
233
|
+
return JSON.stringify(generateSchema(), null, 2) + '\n';
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** Write the schema to disk. Used at build time to produce `schema/miniapp.schema.json`. */
|
|
237
|
+
export function writeSchemaFile(absPath: string): void {
|
|
238
|
+
mkdirSync(dirname(absPath), {recursive: true});
|
|
239
|
+
writeFileSync(absPath, generateSchemaString(), 'utf8');
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** CLI entry: `glassly schema print` writes JSON to stdout. */
|
|
243
|
+
export function schemaPrint(): void {
|
|
244
|
+
process.stdout.write(generateSchemaString());
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* CLI entry: regenerate the on-disk schema file. Run from the CLI package's
|
|
249
|
+
* own scripts (e.g. as a build step) so the published file stays in sync.
|
|
250
|
+
*/
|
|
251
|
+
export function regenerateSchemaFile(): void {
|
|
252
|
+
// Resolve relative to this file: sdk/miniapp-cli/src/schema.ts -> ../schema/miniapp.schema.json
|
|
253
|
+
const here = fileURLToPath(import.meta.url);
|
|
254
|
+
const target = resolve(here, '..', '..', 'schema', 'miniapp.schema.json');
|
|
255
|
+
writeSchemaFile(target);
|
|
256
|
+
process.stdout.write(`Wrote ${target}\n`);
|
|
257
|
+
}
|
|
258
|
+
|