@iola_adm/iola-cli 0.1.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/LICENSE +22 -0
- package/README.md +46 -0
- package/bin/iola.js +9 -0
- package/package.json +40 -0
- package/src/cli.js +167 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Yoshkar-Ola Administration
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# iola-cli
|
|
2
|
+
|
|
3
|
+
CLI для работы с открытыми данными городского округа "Город Йошкар-Ола".
|
|
4
|
+
|
|
5
|
+
Проект использует публичные endpoints:
|
|
6
|
+
|
|
7
|
+
- `https://apiiola.yasg.ru/api/v1`
|
|
8
|
+
- `https://apiiola.yasg.ru/mcp`
|
|
9
|
+
|
|
10
|
+
## Установка
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npx -y @iola_adm/iola-cli help
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
После публикации npm-пакета можно будет установить глобально:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install -g @iola_adm/iola-cli
|
|
20
|
+
iola help
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Команды
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
iola layers
|
|
27
|
+
iola schools --limit 10
|
|
28
|
+
iola kindergartens --search "29"
|
|
29
|
+
iola search "лицей"
|
|
30
|
+
iola mcp-info
|
|
31
|
+
iola setup codex
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Назначение
|
|
35
|
+
|
|
36
|
+
Первый релиз CLI дает прямой терминальный доступ к открытым данным и командам
|
|
37
|
+
подключения MCP/skill. Дальше планируется добавить режим AI-запросов через
|
|
38
|
+
ключ пользователя для OpenAI/OpenRouter и интерактивный агентный режим.
|
|
39
|
+
|
|
40
|
+
## Переменные окружения
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
IOLA_API_BASE_URL=https://apiiola.yasg.ru/api/v1
|
|
44
|
+
IOLA_MCP_BASE_URL=https://apiiola.yasg.ru
|
|
45
|
+
```
|
|
46
|
+
|
package/bin/iola.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@iola_adm/iola-cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CLI и AI-агент для работы с открытыми данными городского округа Йошкар-Ола.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://github.com/adm-iola/iola-cli#readme",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/adm-iola/iola-cli.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/adm-iola/iola-cli/issues"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"bin": {
|
|
16
|
+
"iola": "bin/iola.js"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"bin",
|
|
20
|
+
"src",
|
|
21
|
+
"README.md",
|
|
22
|
+
"LICENSE"
|
|
23
|
+
],
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"start": "node bin/iola.js",
|
|
29
|
+
"test": "node --check bin/iola.js && node --check src/cli.js"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"yoshkar-ola",
|
|
33
|
+
"open-data",
|
|
34
|
+
"mcp",
|
|
35
|
+
"cli"
|
|
36
|
+
],
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=18"
|
|
39
|
+
}
|
|
40
|
+
}
|
package/src/cli.js
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
const API_BASE_URL = process.env.IOLA_API_BASE_URL || "https://apiiola.yasg.ru/api/v1";
|
|
2
|
+
const MCP_BASE_URL = process.env.IOLA_MCP_BASE_URL || "https://apiiola.yasg.ru";
|
|
3
|
+
|
|
4
|
+
const COMMANDS = new Map([
|
|
5
|
+
["help", showHelp],
|
|
6
|
+
["version", showVersion],
|
|
7
|
+
["layers", listLayers],
|
|
8
|
+
["schools", listSchools],
|
|
9
|
+
["kindergartens", listKindergartens],
|
|
10
|
+
["search", searchAll],
|
|
11
|
+
["mcp-info", showMcpInfo],
|
|
12
|
+
["setup", setupClient],
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
export async function main(argv) {
|
|
16
|
+
const [command = "help", ...args] = argv;
|
|
17
|
+
const handler = COMMANDS.get(command);
|
|
18
|
+
|
|
19
|
+
if (!handler) {
|
|
20
|
+
throw new Error(`Unknown command: ${command}\nRun "iola help" to see available commands.`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
await handler(args);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function showHelp() {
|
|
27
|
+
console.log(`iola - CLI для открытых данных городского округа "Город Йошкар-Ола"
|
|
28
|
+
|
|
29
|
+
Usage:
|
|
30
|
+
iola layers
|
|
31
|
+
iola schools [--limit 10] [--search TEXT]
|
|
32
|
+
iola kindergartens [--limit 10] [--search TEXT]
|
|
33
|
+
iola search TEXT [--limit 5]
|
|
34
|
+
iola mcp-info
|
|
35
|
+
iola setup codex
|
|
36
|
+
iola version
|
|
37
|
+
|
|
38
|
+
Environment:
|
|
39
|
+
IOLA_API_BASE_URL default: ${API_BASE_URL}
|
|
40
|
+
IOLA_MCP_BASE_URL default: ${MCP_BASE_URL}
|
|
41
|
+
`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function showVersion() {
|
|
45
|
+
const packageJson = await import("../package.json", { with: { type: "json" } });
|
|
46
|
+
console.log(packageJson.default.version);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function listLayers() {
|
|
50
|
+
const info = await fetchJson(`${MCP_BASE_URL}/mcp-version`);
|
|
51
|
+
printJson(info.data_layers);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function showMcpInfo() {
|
|
55
|
+
const info = await fetchJson(`${MCP_BASE_URL}/mcp-version`);
|
|
56
|
+
printJson(info);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function listSchools(args) {
|
|
60
|
+
await listDataset("schools", args);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function listKindergartens(args) {
|
|
64
|
+
await listDataset("kindergartens", args);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function listDataset(dataset, args) {
|
|
68
|
+
const options = parseOptions(args);
|
|
69
|
+
const params = new URLSearchParams();
|
|
70
|
+
params.set("limit", options.limit || "20");
|
|
71
|
+
params.set("offset", options.offset || "0");
|
|
72
|
+
|
|
73
|
+
const data = await fetchJson(`${API_BASE_URL}/${dataset}?${params}`);
|
|
74
|
+
const items = normalizeItems(data);
|
|
75
|
+
const filtered = options.search ? filterItems(items, options.search) : items;
|
|
76
|
+
printJson(filtered.slice(0, Number(options.limit || 20)));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function searchAll(args) {
|
|
80
|
+
const options = parseOptions(args);
|
|
81
|
+
const query = options._.join(" ").trim();
|
|
82
|
+
|
|
83
|
+
if (!query) {
|
|
84
|
+
throw new Error('Search text is required. Example: iola search "лицей"');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const [schools, kindergartens] = await Promise.all([
|
|
88
|
+
fetchJson(`${API_BASE_URL}/schools?limit=100&offset=0`),
|
|
89
|
+
fetchJson(`${API_BASE_URL}/kindergartens?limit=100&offset=0`),
|
|
90
|
+
]);
|
|
91
|
+
|
|
92
|
+
const limit = Number(options.limit || 5);
|
|
93
|
+
const result = {
|
|
94
|
+
schools: filterItems(normalizeItems(schools), query).slice(0, limit),
|
|
95
|
+
kindergartens: filterItems(normalizeItems(kindergartens), query).slice(0, limit),
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
printJson(result);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function setupClient(args) {
|
|
102
|
+
const [client] = args;
|
|
103
|
+
|
|
104
|
+
if (client !== "codex") {
|
|
105
|
+
throw new Error('Only "iola setup codex" is available in this first release.');
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
console.log("Run:");
|
|
109
|
+
console.log(" codex mcp add yoshkarOlaPublicData --url https://apiiola.yasg.ru/mcp");
|
|
110
|
+
console.log(" npx -y @iola_adm/yoshkar-ola-public-mcp install-skill codex");
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function parseOptions(args) {
|
|
114
|
+
const result = { _: [] };
|
|
115
|
+
|
|
116
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
117
|
+
const arg = args[index];
|
|
118
|
+
if (arg === "--limit" || arg === "--offset" || arg === "--search") {
|
|
119
|
+
result[arg.slice(2)] = args[index + 1];
|
|
120
|
+
index += 1;
|
|
121
|
+
} else {
|
|
122
|
+
result._.push(arg);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function filterItems(items, query) {
|
|
130
|
+
const normalized = query.toLocaleLowerCase("ru-RU");
|
|
131
|
+
return items.filter((item) => JSON.stringify(item).toLocaleLowerCase("ru-RU").includes(normalized));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function normalizeItems(payload) {
|
|
135
|
+
if (Array.isArray(payload)) {
|
|
136
|
+
return payload;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (Array.isArray(payload.data)) {
|
|
140
|
+
return payload.data;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (Array.isArray(payload.items)) {
|
|
144
|
+
return payload.items;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return [];
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async function fetchJson(url) {
|
|
151
|
+
const response = await fetch(url, {
|
|
152
|
+
headers: {
|
|
153
|
+
accept: "application/json",
|
|
154
|
+
"user-agent": "@iola_adm/iola-cli",
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
if (!response.ok) {
|
|
159
|
+
throw new Error(`Request failed: ${response.status} ${response.statusText} (${url})`);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return response.json();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function printJson(value) {
|
|
166
|
+
console.log(JSON.stringify(value, null, 2));
|
|
167
|
+
}
|