create-tx5dr-plugin 1.7.12 → 2.0.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 (2) hide show
  1. package/dist/index.js +86 -46
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -191,29 +191,36 @@ dist/
191
191
  function generateLocaleZh(config) {
192
192
  return JSON.stringify({
193
193
  pluginDescription: `${config.name} plugin`,
194
+ enabled: '启用自动发射控制',
195
+ enabledDesc: '允许此插件通过宿主发射协调器影响当前操作员的自动通联',
194
196
  }, null, 2) + '\n';
195
197
  }
196
198
  function generateLocaleEn(config) {
197
199
  return JSON.stringify({
198
200
  pluginDescription: `${config.name} plugin`,
201
+ enabled: 'Enable automatic transmit control',
202
+ enabledDesc: 'Allow this plugin to influence operator automation through the host coordinator',
199
203
  }, null, 2) + '\n';
200
204
  }
201
205
  // ===== Server-side plugin definition templates =====
202
206
  function generateTsUtilityPlugin(config) {
203
- return `import type {
204
- PluginDefinition,
205
- PluginContext,
206
- ParsedFT8Message,
207
- SlotInfo,
207
+ return `import {
208
+ definePlugin,
209
+ type ParsedFT8Message,
210
+ type SlotInfo,
208
211
  } from '@tx5dr/plugin-api';
209
212
  import zhLocale from './locales/zh.json' with { type: 'json' };
210
213
  import enLocale from './locales/en.json' with { type: 'json' };
211
214
 
212
- export const plugin: PluginDefinition = {
215
+ export const plugin = definePlugin({
216
+ apiVersion: 2,
213
217
  name: '${config.name}',
214
218
  version: '0.1.0',
215
219
  type: 'utility',
216
220
  description: 'pluginDescription',
221
+ // Add only the capabilities this plugin actually uses. The host omits all
222
+ // undeclared privileged APIs from both the TypeScript type and runtime context.
223
+ permissions: [],
217
224
 
218
225
  settings: {
219
226
  // Define your plugin settings here
@@ -227,18 +234,18 @@ export const plugin: PluginDefinition = {
227
234
  },
228
235
 
229
236
  hooks: {
230
- onSlotStart(slotInfo: SlotInfo, messages: ParsedFT8Message[], ctx: PluginContext): void {
237
+ onSlotStart(slotInfo: SlotInfo, messages: ParsedFT8Message[], ctx): void {
231
238
  ctx.log.debug('Slot started', { slotId: slotInfo.id, messageCount: messages.length });
232
239
  },
233
240
 
234
- onDecode(messages: ParsedFT8Message[], ctx: PluginContext): void {
241
+ onDecode(messages: ParsedFT8Message[], ctx): void {
235
242
  // Process decoded messages
236
243
  for (const msg of messages) {
237
244
  ctx.log.debug('Decoded message', { raw: msg.rawMessage, snr: msg.snr });
238
245
  }
239
246
  },
240
247
  },
241
- };
248
+ });
242
249
 
243
250
  export const locales: Record<string, Record<string, string>> = {
244
251
  zh: zhLocale,
@@ -249,19 +256,20 @@ export default plugin;
249
256
  `;
250
257
  }
251
258
  function generateTsStrategyPlugin(config) {
252
- return `import type {
253
- PluginDefinition,
254
- PluginContext,
255
- StrategyRuntime,
256
- StrategyRuntimeSnapshot,
257
- StrategyRuntimeSlot,
258
- StrategyRuntimeSlotContentUpdate,
259
- StrategyRuntimeContext,
260
- ParsedFT8Message,
261
- StrategyDecision,
262
- StrategyDecisionMeta,
263
- FrameMessage,
264
- SlotInfo,
259
+ return `import {
260
+ definePlugin,
261
+ type StrategyPluginContext,
262
+ type StrategyRuntime,
263
+ type StrategyRuntimeSnapshot,
264
+ type StrategyRuntimeSlot,
265
+ type StrategyRuntimeSlotContentUpdate,
266
+ type StrategyRuntimeContext,
267
+ type StrategyRuntimeCheckpoint,
268
+ type ParsedFT8Message,
269
+ type StrategyDecisionResult,
270
+ type StrategyDecisionMetaV2,
271
+ type FrameMessage,
272
+ type SlotInfo,
265
273
  } from '@tx5dr/plugin-api';
266
274
  import zhLocale from './locales/zh.json' with { type: 'json' };
267
275
  import enLocale from './locales/en.json' with { type: 'json' };
@@ -271,11 +279,32 @@ class PluginRuntime implements StrategyRuntime {
271
279
  private slots: Partial<Record<StrategyRuntimeSlot, string>> = {};
272
280
  private context: StrategyRuntimeContext = {};
273
281
 
274
- constructor(private ctx: PluginContext) {}
282
+ constructor(private ctx: StrategyPluginContext) {}
283
+
284
+ checkpoint(): StrategyRuntimeCheckpoint {
285
+ return structuredClone({ state: this.state, slots: this.slots, context: this.context });
286
+ }
275
287
 
276
- decide(messages: ParsedFT8Message[], meta?: StrategyDecisionMeta): StrategyDecision {
288
+ restore(checkpoint: StrategyRuntimeCheckpoint): void {
289
+ const saved = checkpoint as {
290
+ state: StrategyRuntimeSlot;
291
+ slots: Partial<Record<StrategyRuntimeSlot, string>>;
292
+ context: StrategyRuntimeContext;
293
+ };
294
+ this.state = saved.state;
295
+ this.slots = { ...saved.slots };
296
+ this.context = { ...saved.context };
297
+ }
298
+
299
+ decide(messages: ParsedFT8Message[], meta: StrategyDecisionMetaV2): StrategyDecisionResult {
300
+ if (meta.signal.aborted) {
301
+ throw meta.signal.reason ?? new Error('Strategy decision aborted');
302
+ }
277
303
  // Implement your QSO strategy logic here
278
- return {};
304
+ return {
305
+ transmission: this.getTransmitText(),
306
+ snapshot: this.getSnapshot(),
307
+ };
279
308
  }
280
309
 
281
310
  getTransmitText(): string | null {
@@ -317,15 +346,16 @@ class PluginRuntime implements StrategyRuntime {
317
346
  }
318
347
  }
319
348
 
320
- export const plugin: PluginDefinition = {
349
+ export const plugin = definePlugin({
350
+ apiVersion: 2,
321
351
  name: '${config.name}',
322
352
  version: '0.1.0',
323
353
  type: 'strategy',
324
354
  description: 'pluginDescription',
355
+ // Selecting a strategy is the explicit grant for declarative RF decisions.
356
+ // Add operator:transmit-control only to utility plugins that submit commands.
325
357
 
326
- settings: {},
327
-
328
- createStrategyRuntime(ctx: PluginContext): StrategyRuntime {
358
+ createStrategyRuntime(ctx: StrategyPluginContext): StrategyRuntime {
329
359
  return new PluginRuntime(ctx);
330
360
  },
331
361
 
@@ -334,7 +364,7 @@ export const plugin: PluginDefinition = {
334
364
  ctx.log.debug('Slot started', { slotId: slotInfo.id });
335
365
  },
336
366
  },
337
- };
367
+ });
338
368
 
339
369
  export const locales: Record<string, Record<string, string>> = {
340
370
  zh: zhLocale,
@@ -345,20 +375,22 @@ export default plugin;
345
375
  `;
346
376
  }
347
377
  function generateTsUtilityPluginWithUI(config) {
348
- return `import type {
349
- PluginDefinition,
350
- PluginContext,
351
- ParsedFT8Message,
352
- SlotInfo,
378
+ return `import {
379
+ definePlugin,
380
+ type ParsedFT8Message,
381
+ type SlotInfo,
353
382
  } from '@tx5dr/plugin-api';
354
383
  import zhLocale from './locales/zh.json' with { type: 'json' };
355
384
  import enLocale from './locales/en.json' with { type: 'json' };
356
385
 
357
- export const plugin: PluginDefinition = {
386
+ export const plugin = definePlugin({
387
+ apiVersion: 2,
358
388
  name: '${config.name}',
359
389
  version: '0.1.0',
360
390
  type: 'utility',
361
391
  description: 'pluginDescription',
392
+ // Add only the capabilities this plugin actually uses.
393
+ permissions: [],
362
394
 
363
395
  settings: {
364
396
  // Define your plugin settings here
@@ -372,11 +404,12 @@ export const plugin: PluginDefinition = {
372
404
  entry: 'settings.html',
373
405
  title: 'settingsPage',
374
406
  accessScope: 'admin',
407
+ resourceBinding: 'none',
375
408
  },
376
409
  ],
377
410
  },
378
411
 
379
- onLoad(ctx: PluginContext): void {
412
+ onLoad(ctx): void {
380
413
  ctx.ui.registerPageHandler({
381
414
  async onMessage(pageId, action, data) {
382
415
  if (action === 'getSettings') {
@@ -396,17 +429,17 @@ export const plugin: PluginDefinition = {
396
429
  },
397
430
 
398
431
  hooks: {
399
- onSlotStart(slotInfo: SlotInfo, messages: ParsedFT8Message[], ctx: PluginContext): void {
432
+ onSlotStart(slotInfo: SlotInfo, messages: ParsedFT8Message[], ctx): void {
400
433
  ctx.log.debug('Slot started', { slotId: slotInfo.id, messageCount: messages.length });
401
434
  },
402
435
 
403
- onDecode(messages: ParsedFT8Message[], ctx: PluginContext): void {
436
+ onDecode(messages: ParsedFT8Message[], ctx): void {
404
437
  for (const msg of messages) {
405
438
  ctx.log.debug('Decoded message', { raw: msg.rawMessage, snr: msg.snr });
406
439
  }
407
440
  },
408
441
  },
409
- };
442
+ });
410
443
 
411
444
  export const locales: Record<string, Record<string, string>> = {
412
445
  zh: zhLocale,
@@ -417,12 +450,15 @@ export default plugin;
417
450
  `;
418
451
  }
419
452
  function generateJsUtilityPlugin(config) {
420
- return `/** @type {import('@tx5dr/plugin-api').PluginDefinition} */
421
- export const plugin = {
453
+ return `import { definePlugin } from '@tx5dr/plugin-api';
454
+
455
+ export const plugin = definePlugin({
456
+ apiVersion: 2,
422
457
  name: '${config.name}',
423
458
  version: '0.1.0',
424
459
  type: 'utility',
425
460
  description: 'pluginDescription',
461
+ permissions: [],
426
462
 
427
463
  settings: {
428
464
  // Define your plugin settings here
@@ -439,18 +475,21 @@ export const plugin = {
439
475
  }
440
476
  },
441
477
  },
442
- };
478
+ });
443
479
 
444
480
  export default plugin;
445
481
  `;
446
482
  }
447
483
  function generateJsUtilityPluginWithUI(config) {
448
- return `/** @type {import('@tx5dr/plugin-api').PluginDefinition} */
449
- export const plugin = {
484
+ return `import { definePlugin } from '@tx5dr/plugin-api';
485
+
486
+ export const plugin = definePlugin({
487
+ apiVersion: 2,
450
488
  name: '${config.name}',
451
489
  version: '0.1.0',
452
490
  type: 'utility',
453
491
  description: 'pluginDescription',
492
+ permissions: [],
454
493
 
455
494
  settings: {},
456
495
 
@@ -462,6 +501,7 @@ export const plugin = {
462
501
  entry: 'settings.html',
463
502
  title: 'settingsPage',
464
503
  accessScope: 'admin',
504
+ resourceBinding: 'none',
465
505
  },
466
506
  ],
467
507
  },
@@ -495,7 +535,7 @@ export const plugin = {
495
535
  }
496
536
  },
497
537
  },
498
- };
538
+ });
499
539
 
500
540
  export default plugin;
501
541
  `;
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "create-tx5dr-plugin",
3
- "version": "1.7.12",
3
+ "version": "2.0.0",
4
4
  "type": "module",
5
5
  "description": "Scaffold a new TX-5DR plugin project",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "https://github.com/boybook/tx-5dr.git",
9
+ "url": "https://github.com/boybook/tx-5dr",
10
10
  "directory": "packages/create-tx5dr-plugin"
11
11
  },
12
12
  "keywords": [