@tvbs-ai/news-rd 0.3.2 → 0.4.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.
- package/README.md +6 -4
- package/dist/cli.js +115 -91
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -69,13 +69,15 @@ news-rd prompt compile 2026-03-10 0600
|
|
|
69
69
|
### Shell Completion
|
|
70
70
|
|
|
71
71
|
```bash
|
|
72
|
-
# Bash
|
|
73
|
-
news-rd completion bash >> ~/.bashrc
|
|
72
|
+
# Bash — add to ~/.bashrc
|
|
73
|
+
echo 'source <(news-rd completion bash)' >> ~/.bashrc
|
|
74
74
|
|
|
75
|
-
# Zsh
|
|
76
|
-
news-rd completion zsh >> ~/.zshrc
|
|
75
|
+
# Zsh — add to ~/.zshrc
|
|
76
|
+
echo 'source <(news-rd completion zsh)' >> ~/.zshrc
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
+
Completion auto-updates when the CLI is updated.
|
|
80
|
+
|
|
79
81
|
## Update
|
|
80
82
|
|
|
81
83
|
The CLI automatically checks for new versions and shows a hint after command output. To update:
|
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/cli.ts
|
|
4
|
-
var CLI_VERSION = "0.
|
|
4
|
+
var CLI_VERSION = "0.4.0";
|
|
5
5
|
var rawArgs = process.argv.slice(2);
|
|
6
6
|
function parseArgs() {
|
|
7
7
|
const options = {
|
|
@@ -25,6 +25,9 @@ function parseArgs() {
|
|
|
25
25
|
case "--json":
|
|
26
26
|
options.json = true;
|
|
27
27
|
break;
|
|
28
|
+
case "--channel":
|
|
29
|
+
options.channel = rawArgs[++i];
|
|
30
|
+
break;
|
|
28
31
|
case "--category":
|
|
29
32
|
options.category = rawArgs[++i];
|
|
30
33
|
break;
|
|
@@ -113,6 +116,7 @@ Groups:
|
|
|
113
116
|
Global Options:
|
|
114
117
|
--base-url URL API base URL (default: https://news-rundown.tvbs.ai)
|
|
115
118
|
--token TOKEN JWT token (or RD_TOKEN env)
|
|
119
|
+
--channel CODE Channel code (default: tvbsn)
|
|
116
120
|
--json Raw JSON output
|
|
117
121
|
--version, -v Show version
|
|
118
122
|
--help, -h Show help
|
|
@@ -127,8 +131,12 @@ config \u2014 \u6642\u6BB5\u8207\u74B0\u5883\u8A2D\u5B9A
|
|
|
127
131
|
Commands:
|
|
128
132
|
timeslots List all available timeslots
|
|
129
133
|
|
|
134
|
+
Options:
|
|
135
|
+
--channel CODE Channel code (default: tvbsn)
|
|
136
|
+
|
|
130
137
|
Examples:
|
|
131
138
|
news-rd config timeslots
|
|
139
|
+
news-rd config timeslots --channel news-ctv
|
|
132
140
|
`,
|
|
133
141
|
rundown: `
|
|
134
142
|
rundown \u2014 Rundown \u67E5\u8A62\u8207\u7248\u672C\u6BD4\u5C0D
|
|
@@ -137,8 +145,12 @@ Commands:
|
|
|
137
145
|
get <date> <timeslot> Get rundown content
|
|
138
146
|
history <date> <timeslot> Get version history (initial + edits)
|
|
139
147
|
|
|
148
|
+
Options:
|
|
149
|
+
--channel CODE Channel code (default: tvbsn)
|
|
150
|
+
|
|
140
151
|
Examples:
|
|
141
152
|
news-rd rundown get 2026-03-10 0600
|
|
153
|
+
news-rd rundown get 2026-03-10 0600 --channel news-ctv
|
|
142
154
|
news-rd rundown history 2026-03-10 0600
|
|
143
155
|
`,
|
|
144
156
|
news: `
|
|
@@ -172,14 +184,17 @@ Commands:
|
|
|
172
184
|
Options:
|
|
173
185
|
--version N Specific prompt version (show, compile)
|
|
174
186
|
--variables VARS Comma-separated variable names (resolve)
|
|
187
|
+
--channel CODE Channel code (resolve, compile; default: tvbsn)
|
|
175
188
|
|
|
176
189
|
Examples:
|
|
177
190
|
news-rd prompt list
|
|
178
191
|
news-rd prompt show rundown-generation-0600
|
|
179
|
-
news-rd prompt show rundown-generation-0600 --version 5
|
|
192
|
+
news-rd prompt show tvbsn:rundown-generation-0600 --version 5
|
|
180
193
|
news-rd prompt variables
|
|
181
194
|
news-rd prompt resolve 2026-03-10 0600 --variables GOOGLE_TRENDS_FOUR_HR
|
|
195
|
+
news-rd prompt resolve 2026-03-10 0600 --channel news-ctv
|
|
182
196
|
news-rd prompt compile 2026-03-10 0600
|
|
197
|
+
news-rd prompt compile 2026-03-10 0600 --channel news-ctv
|
|
183
198
|
`,
|
|
184
199
|
token: `
|
|
185
200
|
token \u2014 JWT Token \u7BA1\u7406
|
|
@@ -201,9 +216,11 @@ Commands:
|
|
|
201
216
|
bash Output bash completion script
|
|
202
217
|
zsh Output zsh completion script
|
|
203
218
|
|
|
204
|
-
Setup:
|
|
205
|
-
news-rd completion bash >> ~/.bashrc
|
|
206
|
-
news-rd completion zsh >> ~/.zshrc
|
|
219
|
+
Setup (add one line to your shell rc file):
|
|
220
|
+
echo 'source <(news-rd completion bash)' >> ~/.bashrc
|
|
221
|
+
echo 'source <(news-rd completion zsh)' >> ~/.zshrc
|
|
222
|
+
|
|
223
|
+
Then restart your shell or run: source ~/.zshrc
|
|
207
224
|
`
|
|
208
225
|
};
|
|
209
226
|
function showGroupHelp(group) {
|
|
@@ -315,11 +332,13 @@ function printTable(rows, columns) {
|
|
|
315
332
|
async function handleConfig(command, _positional, options) {
|
|
316
333
|
switch (command) {
|
|
317
334
|
case "timeslots": {
|
|
318
|
-
const data = await apiCall(
|
|
335
|
+
const data = await apiCall(`/timeslots${qs({ channel: options.channel })}`, options);
|
|
319
336
|
if (options.json) {
|
|
320
337
|
printJson(data);
|
|
321
338
|
return;
|
|
322
339
|
}
|
|
340
|
+
if (data.channel) console.log(`Channel: ${data.channel}
|
|
341
|
+
`);
|
|
323
342
|
printTable(data.timeslots, ["slot_code", "description"]);
|
|
324
343
|
return;
|
|
325
344
|
}
|
|
@@ -332,7 +351,7 @@ async function handleRundown(command, positional, options) {
|
|
|
332
351
|
switch (command) {
|
|
333
352
|
case "get": {
|
|
334
353
|
const [date, timeslot] = requireDateTimeslot(positional, "rundown", "get");
|
|
335
|
-
const data = await apiCall(`/rundown${qs({ date, timeslot })}`, options);
|
|
354
|
+
const data = await apiCall(`/rundown${qs({ date, timeslot, channel: options.channel })}`, options);
|
|
336
355
|
if (options.json) {
|
|
337
356
|
printJson(data);
|
|
338
357
|
return;
|
|
@@ -365,7 +384,7 @@ async function handleRundown(command, positional, options) {
|
|
|
365
384
|
}
|
|
366
385
|
case "history": {
|
|
367
386
|
const [date, timeslot] = requireDateTimeslot(positional, "rundown", "history");
|
|
368
|
-
const data = await apiCall(`/rundown/changes${qs({ date, timeslot })}`, options);
|
|
387
|
+
const data = await apiCall(`/rundown/changes${qs({ date, timeslot, channel: options.channel })}`, options);
|
|
369
388
|
if (options.json) {
|
|
370
389
|
printJson(data);
|
|
371
390
|
return;
|
|
@@ -501,6 +520,7 @@ ${data.template}
|
|
|
501
520
|
const data = await apiCall(`/prompt/rundown/variables/resolve${qs({
|
|
502
521
|
date,
|
|
503
522
|
timeslot,
|
|
523
|
+
channel: options.channel,
|
|
504
524
|
variables: options.variables
|
|
505
525
|
})}`, options);
|
|
506
526
|
if (options.json) {
|
|
@@ -518,7 +538,7 @@ ${v.name} (${v.value_type}, ${v.value_length} chars${v.item_count !== void 0 ? `
|
|
|
518
538
|
}
|
|
519
539
|
case "compile": {
|
|
520
540
|
const [date, timeslot] = requireDateTimeslot(positional, "prompt", "compile");
|
|
521
|
-
const data = await apiCall(`/prompt/rundown/compiled${qs({ date, timeslot, version: options.version })}`, options);
|
|
541
|
+
const data = await apiCall(`/prompt/rundown/compiled${qs({ date, timeslot, version: options.version, channel: options.channel })}`, options);
|
|
522
542
|
if (options.json) {
|
|
523
543
|
printJson(data);
|
|
524
544
|
return;
|
|
@@ -570,111 +590,115 @@ function handleCompletion(command) {
|
|
|
570
590
|
process.exit(0);
|
|
571
591
|
}
|
|
572
592
|
}
|
|
593
|
+
var COMPLETION_DATA = {
|
|
594
|
+
groups: "config rundown news prompt token completion",
|
|
595
|
+
commands: {
|
|
596
|
+
config: "timeslots",
|
|
597
|
+
rundown: "get history",
|
|
598
|
+
news: "candidates trends keywords",
|
|
599
|
+
prompt: "list show variables resolve compile",
|
|
600
|
+
token: "generate",
|
|
601
|
+
completion: "bash zsh"
|
|
602
|
+
},
|
|
603
|
+
timeslots: "0600 0700 0800 1400 1500 1600",
|
|
604
|
+
optionsWithValue: "--base-url --token --channel --category --content-type --limit --version --variables",
|
|
605
|
+
globalFlags: "--help --version --json"
|
|
606
|
+
};
|
|
573
607
|
function generateBashCompletion() {
|
|
608
|
+
const d = COMPLETION_DATA;
|
|
574
609
|
return `# bash completion for news-rd
|
|
610
|
+
# Setup: source <(news-rd completion bash)
|
|
611
|
+
# Persist: echo 'source <(news-rd completion bash)' >> ~/.bashrc
|
|
612
|
+
|
|
575
613
|
_news_rd_completions() {
|
|
576
|
-
local cur prev
|
|
614
|
+
local cur prev
|
|
577
615
|
cur="\${COMP_WORDS[COMP_CWORD]}"
|
|
578
616
|
prev="\${COMP_WORDS[COMP_CWORD-1]}"
|
|
579
|
-
groups="config rundown news prompt token completion"
|
|
580
617
|
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
COMPREPLY=($(compgen -W "get history" -- "$cur"))
|
|
587
|
-
;;
|
|
588
|
-
news)
|
|
589
|
-
COMPREPLY=($(compgen -W "candidates trends keywords" -- "$cur"))
|
|
590
|
-
;;
|
|
591
|
-
prompt)
|
|
592
|
-
COMPREPLY=($(compgen -W "list show variables resolve compile" -- "$cur"))
|
|
593
|
-
;;
|
|
594
|
-
token)
|
|
595
|
-
COMPREPLY=($(compgen -W "generate" -- "$cur"))
|
|
596
|
-
;;
|
|
597
|
-
completion)
|
|
598
|
-
COMPREPLY=($(compgen -W "bash zsh" -- "$cur"))
|
|
599
|
-
;;
|
|
600
|
-
*)
|
|
601
|
-
if [[ \${COMP_CWORD} -eq 1 ]]; then
|
|
602
|
-
COMPREPLY=($(compgen -W "$groups --help --version --json" -- "$cur"))
|
|
603
|
-
fi
|
|
618
|
+
# If previous word expects a value, don't complete
|
|
619
|
+
case "$prev" in
|
|
620
|
+
${d.optionsWithValue.split(" ").join("|")})
|
|
621
|
+
COMPREPLY=()
|
|
622
|
+
return
|
|
604
623
|
;;
|
|
605
624
|
esac
|
|
606
625
|
|
|
626
|
+
# Timeslot completion (position 4+: after group command date)
|
|
607
627
|
case "$prev" in
|
|
608
|
-
--base-url|--token|--category|--content-type|--limit|--version|--variables)
|
|
609
|
-
COMPREPLY=()
|
|
610
|
-
;;
|
|
611
628
|
get|history|candidates|trends|keywords|resolve|compile)
|
|
612
|
-
# Suggest timeslots after date
|
|
613
629
|
if [[ \${COMP_CWORD} -ge 4 ]]; then
|
|
614
|
-
COMPREPLY=($(compgen -W "
|
|
630
|
+
COMPREPLY=($(compgen -W "${d.timeslots}" -- "$cur"))
|
|
631
|
+
return
|
|
615
632
|
fi
|
|
616
633
|
;;
|
|
617
634
|
esac
|
|
635
|
+
|
|
636
|
+
# Command completion based on group (position 2)
|
|
637
|
+
if [[ \${COMP_CWORD} -eq 2 ]]; then
|
|
638
|
+
case "\${COMP_WORDS[1]}" in
|
|
639
|
+
${Object.entries(d.commands).map(
|
|
640
|
+
([g, cmds]) => ` ${g}) COMPREPLY=($(compgen -W "${cmds}" -- "$cur")) ;;`
|
|
641
|
+
).join("\n")}
|
|
642
|
+
esac
|
|
643
|
+
return
|
|
644
|
+
fi
|
|
645
|
+
|
|
646
|
+
# Group completion (position 1)
|
|
647
|
+
if [[ \${COMP_CWORD} -eq 1 ]]; then
|
|
648
|
+
COMPREPLY=($(compgen -W "${d.groups} ${d.globalFlags}" -- "$cur"))
|
|
649
|
+
return
|
|
650
|
+
fi
|
|
618
651
|
}
|
|
619
652
|
complete -F _news_rd_completions news-rd`;
|
|
620
653
|
}
|
|
621
654
|
function generateZshCompletion() {
|
|
655
|
+
const d = COMPLETION_DATA;
|
|
622
656
|
return `# zsh completion for news-rd
|
|
623
|
-
#
|
|
657
|
+
# Setup: source <(news-rd completion zsh)
|
|
658
|
+
# Persist: echo 'source <(news-rd completion zsh)' >> ~/.zshrc
|
|
624
659
|
|
|
625
660
|
_news_rd() {
|
|
626
|
-
local
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
'--json[Raw JSON output]' \\
|
|
643
|
-
'--version[Show version]' \\
|
|
644
|
-
'--help[Show help]' \\
|
|
645
|
-
'1:group:->group' \\
|
|
646
|
-
'*::arg:->args'
|
|
647
|
-
|
|
648
|
-
case $state in
|
|
649
|
-
group)
|
|
650
|
-
_describe 'group' groups
|
|
651
|
-
;;
|
|
652
|
-
args)
|
|
653
|
-
case \${words[1]} in
|
|
654
|
-
config)
|
|
655
|
-
_values 'command' 'timeslots[List timeslots]'
|
|
656
|
-
;;
|
|
657
|
-
rundown)
|
|
658
|
-
_values 'command' 'get[Get rundown]' 'history[Version history]'
|
|
659
|
-
;;
|
|
660
|
-
news)
|
|
661
|
-
_values 'command' 'candidates[Scored candidates]' 'trends[Google Trends]' 'keywords[NewsRadar keywords]'
|
|
662
|
-
;;
|
|
663
|
-
prompt)
|
|
664
|
-
_values 'command' 'list[List prompts]' 'show[Get template]' 'variables[List variables]' 'resolve[Resolve variables]' 'compile[Compiled prompt]'
|
|
665
|
-
;;
|
|
666
|
-
token)
|
|
667
|
-
_values 'command' 'generate[Generate JWT token]'
|
|
668
|
-
;;
|
|
669
|
-
completion)
|
|
670
|
-
_values 'command' 'bash[Bash completion]' 'zsh[Zsh completion]'
|
|
671
|
-
;;
|
|
672
|
-
esac
|
|
673
|
-
;;
|
|
674
|
-
esac
|
|
675
|
-
}
|
|
661
|
+
local cur="\${words[CURRENT]}"
|
|
662
|
+
local group="\${words[2]}"
|
|
663
|
+
|
|
664
|
+
# Group completion (position 2)
|
|
665
|
+
if (( CURRENT == 2 )); then
|
|
666
|
+
local -a groups=(
|
|
667
|
+
'config:\u6642\u6BB5\u8207\u74B0\u5883\u8A2D\u5B9A'
|
|
668
|
+
'rundown:Rundown \u67E5\u8A62\u8207\u7248\u672C\u6BD4\u5C0D'
|
|
669
|
+
'news:\u5019\u9078\u65B0\u805E\u8207\u8DA8\u52E2\u95DC\u9375\u5B57'
|
|
670
|
+
'prompt:Prompt \u6A21\u677F\u3001\u8B8A\u6578\u8207\u7DE8\u8B6F'
|
|
671
|
+
'token:JWT Token \u7BA1\u7406'
|
|
672
|
+
'completion:Shell auto-completion'
|
|
673
|
+
)
|
|
674
|
+
_describe 'group' groups
|
|
675
|
+
return
|
|
676
|
+
fi
|
|
676
677
|
|
|
677
|
-
|
|
678
|
+
# Command completion (position 3)
|
|
679
|
+
if (( CURRENT == 3 )); then
|
|
680
|
+
case "$group" in
|
|
681
|
+
${Object.entries(d.commands).map(([g, cmds]) => {
|
|
682
|
+
const items = cmds.split(" ").map((c) => `'${c}'`).join(" ");
|
|
683
|
+
return ` ${g}) compadd ${items} ;;`;
|
|
684
|
+
}).join("\n")}
|
|
685
|
+
esac
|
|
686
|
+
return
|
|
687
|
+
fi
|
|
688
|
+
|
|
689
|
+
# Timeslot completion (position 5: after date)
|
|
690
|
+
if (( CURRENT == 5 )); then
|
|
691
|
+
compadd ${d.timeslots}
|
|
692
|
+
return
|
|
693
|
+
fi
|
|
694
|
+
|
|
695
|
+
# Flag completion
|
|
696
|
+
if [[ "$cur" == -* ]]; then
|
|
697
|
+
compadd -- ${d.globalFlags} ${d.optionsWithValue}
|
|
698
|
+
return
|
|
699
|
+
fi
|
|
700
|
+
}
|
|
701
|
+
if (( $+functions[compdef] )); then compdef _news_rd news-rd; fi`;
|
|
678
702
|
}
|
|
679
703
|
async function checkForUpdates() {
|
|
680
704
|
try {
|