odant-work 1.0.76 → 1.0.77

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.
@@ -0,0 +1,225 @@
1
+ /**
2
+ * Встроенный MCP-сервер для Yandex Market Partner API (https://api.partner.market.yandex.ru).
3
+ * Ключи берутся из `YANDEX_MARKET_API_KEY` и (опционально) `YANDEX_MARKET_CAMPAIGN_ID` (в WORK — через #secret).
4
+ */
5
+ import { startMcpStdioServer } from './mcp-stdio.js';
6
+
7
+ const YM_BASE = 'https://api.partner.market.yandex.ru';
8
+
9
+ function getYmCreds() {
10
+ const apiKey = String(process.env.YANDEX_MARKET_API_KEY || '').trim();
11
+ const campaignId = String(process.env.YANDEX_MARKET_CAMPAIGN_ID || '').trim();
12
+ if (!apiKey) {
13
+ return {
14
+ notConfigured: true,
15
+ hint: 'Укажите Api-Key партнёра Яндекс Маркета в секрете сервиса /SERVICES/Marketplaces/YandexMarket: #secret/yandex_market_api_key (и при желании #secret/yandex_market_campaign_id).',
16
+ };
17
+ }
18
+ return { apiKey, campaignId };
19
+ }
20
+
21
+ async function ymRequest(relPath, { method = 'GET', query = null, body = undefined } = {}) {
22
+ const creds = getYmCreds();
23
+ if (creds.notConfigured)
24
+ return creds;
25
+ const cleanPath = '/' + String(relPath || '').replace(/^\/+/, '');
26
+ if (cleanPath.includes('..') || /^https?:/i.test(String(relPath || '')))
27
+ return { error: 'Недопустимый путь эндпоинта Yandex Market API' };
28
+ const urlObj = new URL(YM_BASE + cleanPath);
29
+ if (query && typeof query === 'object') {
30
+ for (const [k, v] of Object.entries(query)) {
31
+ if (v != null && v !== '')
32
+ urlObj.searchParams.set(k, String(v));
33
+ }
34
+ }
35
+ const res = await fetch(urlObj.toString(), {
36
+ method,
37
+ headers: {
38
+ 'Api-Key': creds.apiKey,
39
+ Accept: 'application/json',
40
+ ...(body !== undefined ? { 'Content-Type': 'application/json' } : {}),
41
+ },
42
+ body: body !== undefined ? JSON.stringify(body) : undefined,
43
+ signal: AbortSignal.timeout(25000),
44
+ });
45
+ const text = await res.text();
46
+ let parsed = null;
47
+ try { parsed = JSON.parse(text); } catch { /* raw */ }
48
+ if (!res.ok)
49
+ return { error: `Yandex Market API HTTP ${res.status}`, details: parsed || text.slice(0, 1000) };
50
+ return parsed ?? { raw: text.slice(0, 4000) };
51
+ }
52
+
53
+ function resolveCampaignId(argId) {
54
+ return String(argId || process.env.YANDEX_MARKET_CAMPAIGN_ID || '').trim();
55
+ }
56
+
57
+ const tools = [
58
+ {
59
+ name: 'campaigns_list',
60
+ description: 'Список магазинов (кампаний) и их businessId в кабинете Яндекс Маркета (/campaigns).',
61
+ inputSchema: {
62
+ type: 'object',
63
+ properties: {
64
+ page: { type: 'number' },
65
+ pageSize: { type: 'number' },
66
+ },
67
+ },
68
+ handler: (a) => ymRequest('/campaigns', { query: { page: a.page, pageSize: a.pageSize } }),
69
+ },
70
+ {
71
+ name: 'offers_list',
72
+ description: 'Список товаров и карточек кабинета Яндекс Маркета (/businesses/{businessId}/offer-mappings).',
73
+ inputSchema: {
74
+ type: 'object',
75
+ properties: {
76
+ businessId: { type: 'number', description: 'ID кабинета (businessId — можно узнать через campaigns_list)' },
77
+ offerIds: { type: 'array', items: { type: 'string' } },
78
+ page_token: { type: 'string' },
79
+ limit: { type: 'number' },
80
+ },
81
+ required: ['businessId'],
82
+ },
83
+ handler: (a) => ymRequest(`/businesses/${encodeURIComponent(a.businessId)}/offer-mappings`, {
84
+ method: 'POST',
85
+ query: {
86
+ ...(a.page_token ? { page_token: a.page_token } : {}),
87
+ limit: Math.min(200, Math.max(1, Number(a.limit) || 50)),
88
+ },
89
+ body: Array.isArray(a.offerIds) && a.offerIds.length ? { offerIds: a.offerIds } : {},
90
+ }),
91
+ },
92
+ {
93
+ name: 'stocks_list',
94
+ description: 'Остатки товаров магазина на Яндекс Маркете (/campaigns/{campaignId}/offers/stocks).',
95
+ inputSchema: {
96
+ type: 'object',
97
+ properties: {
98
+ campaignId: { type: 'string', description: 'ID кампании (магазина)' },
99
+ offerIds: { type: 'array', items: { type: 'string' } },
100
+ limit: { type: 'number' },
101
+ page_token: { type: 'string' },
102
+ },
103
+ },
104
+ handler: (a) => {
105
+ const cid = resolveCampaignId(a.campaignId);
106
+ if (!cid) return { error: 'Укажите campaignId (или задайте #secret/yandex_market_campaign_id)' };
107
+ return ymRequest(`/campaigns/${encodeURIComponent(cid)}/offers/stocks`, {
108
+ method: 'POST',
109
+ query: {
110
+ ...(a.page_token ? { page_token: a.page_token } : {}),
111
+ limit: Math.min(500, Math.max(1, Number(a.limit) || 50)),
112
+ },
113
+ body: Array.isArray(a.offerIds) && a.offerIds.length ? { offerIds: a.offerIds } : {},
114
+ });
115
+ },
116
+ },
117
+ {
118
+ name: 'orders_list',
119
+ description: 'Список заказов магазина на Яндекс Маркете (/campaigns/{campaignId}/orders).',
120
+ inputSchema: {
121
+ type: 'object',
122
+ properties: {
123
+ campaignId: { type: 'string', description: 'ID кампании (магазина)' },
124
+ status: { type: 'string', description: 'PROCESSING, DELIVERY, PICKUP, DELIVERED, CANCELLED' },
125
+ fromDate: { type: 'string', description: 'DD-MM-YYYY или YYYY-MM-DD' },
126
+ toDate: { type: 'string' },
127
+ page: { type: 'number' },
128
+ pageSize: { type: 'number' },
129
+ },
130
+ },
131
+ handler: (a) => {
132
+ const cid = resolveCampaignId(a.campaignId);
133
+ if (!cid) return { error: 'Укажите campaignId (или задайте #secret/yandex_market_campaign_id)' };
134
+ return ymRequest(`/campaigns/${encodeURIComponent(cid)}/orders`, {
135
+ query: {
136
+ ...(a.status ? { status: a.status } : {}),
137
+ ...(a.fromDate ? { fromDate: a.fromDate } : {}),
138
+ ...(a.toDate ? { toDate: a.toDate } : {}),
139
+ page: a.page || 1,
140
+ pageSize: Math.min(50, Math.max(1, Number(a.pageSize) || 20)),
141
+ },
142
+ });
143
+ },
144
+ },
145
+ {
146
+ name: 'stats_orders',
147
+ description: 'Отчёт по заказам и продажам Яндекс Маркета (/campaigns/{campaignId}/stats/orders).',
148
+ inputSchema: {
149
+ type: 'object',
150
+ properties: {
151
+ campaignId: { type: 'string' },
152
+ dateFrom: { type: 'string', description: 'YYYY-MM-DD' },
153
+ dateTo: { type: 'string', description: 'YYYY-MM-DD' },
154
+ limit: { type: 'number' },
155
+ },
156
+ required: ['dateFrom', 'dateTo'],
157
+ },
158
+ handler: (a) => {
159
+ const cid = resolveCampaignId(a.campaignId);
160
+ if (!cid) return { error: 'Укажите campaignId (или задайте #secret/yandex_market_campaign_id)' };
161
+ return ymRequest(`/campaigns/${encodeURIComponent(cid)}/stats/orders`, {
162
+ method: 'POST',
163
+ query: { limit: Math.min(200, Math.max(1, Number(a.limit) || 50)) },
164
+ body: { dateFrom: a.dateFrom, dateTo: a.dateTo },
165
+ });
166
+ },
167
+ },
168
+ {
169
+ name: 'prices_update',
170
+ description: '[ЗАПИСЬ] Обновить цены товаров в кабинете Яндекс Маркета (/businesses/{businessId}/offer-prices/updates).',
171
+ inputSchema: {
172
+ type: 'object',
173
+ properties: {
174
+ businessId: { type: 'number', description: 'ID кабинета' },
175
+ offers: { type: 'array', items: { type: 'object' }, description: 'Массив { offerId, price: { value, currencyId: "RUR", discountBase? } }' },
176
+ },
177
+ required: ['businessId', 'offers'],
178
+ },
179
+ handler: (a) => ymRequest(`/businesses/${encodeURIComponent(a.businessId)}/offer-prices/updates`, {
180
+ method: 'POST',
181
+ body: { offers: a.offers },
182
+ }),
183
+ },
184
+ {
185
+ name: 'stocks_update',
186
+ description: '[ЗАПИСЬ] Обновить остатки товаров магазина на Яндекс Маркете (/campaigns/{campaignId}/offers/stocks).',
187
+ inputSchema: {
188
+ type: 'object',
189
+ properties: {
190
+ campaignId: { type: 'string' },
191
+ skus: { type: 'array', items: { type: 'object' }, description: 'Массив { sku, items: [{ count, updatedAt? }] }' },
192
+ },
193
+ required: ['skus'],
194
+ },
195
+ handler: (a) => {
196
+ const cid = resolveCampaignId(a.campaignId);
197
+ if (!cid) return { error: 'Укажите campaignId (или задайте #secret/yandex_market_campaign_id)' };
198
+ return ymRequest(`/campaigns/${encodeURIComponent(cid)}/offers/stocks`, {
199
+ method: 'PUT',
200
+ body: { skus: a.skus },
201
+ });
202
+ },
203
+ },
204
+ {
205
+ name: 'api_call',
206
+ description: 'Универсальный запрос к Yandex Market Partner API (https://api.partner.market.yandex.ru).',
207
+ inputSchema: {
208
+ type: 'object',
209
+ properties: {
210
+ endpoint: { type: 'string', description: 'Путь эндпоинта, например /campaigns' },
211
+ method: { type: 'string', description: 'GET, POST, PUT или DELETE' },
212
+ query: { type: 'object' },
213
+ body: { type: 'object' },
214
+ },
215
+ required: ['endpoint'],
216
+ },
217
+ handler: (a) => ymRequest(a.endpoint, {
218
+ method: String(a.method || 'GET').toUpperCase(),
219
+ query: a.query,
220
+ body: a.body,
221
+ }),
222
+ },
223
+ ];
224
+
225
+ startMcpStdioServer({ name: 'yandex-market-mcp', version: '1.0.0', tools });
@@ -46,7 +46,7 @@ export const MEMBERS = Object.freeze({
46
46
  mail_draft_save: L.WRITE, mail_send: L.WRITE, mail_state: L.WRITE, mail_refresh: L.WRITE,
47
47
  calendar_list: L.READ, calendar_save: L.WRITE,
48
48
  agent_rules_list: L.READ, agent_rule_save: L.ADMIN, agent_schedule_save: L.ADMIN, agent_proactivity_save: L.ADMIN,
49
- agent_system_get: L.READ, agent_system_save: L.ADMIN, agent_available_classes: L.READ, agent_structures_list: L.READ, agent_tasks_list: L.READ,
49
+ agent_system_get: L.READ, agent_system_save: L.ADMIN, agent_available_classes: L.READ, agent_structures_list: L.READ, agent_network_nodes: L.READ, agent_tasks_list: L.READ,
50
50
  security_update: L.ADMIN,
51
51
  roles: L.READ, members: L.READ, is_data_type: L.READ, reset: L.READ,
52
52
  work_zone: L.READ, places: L.READ,
@@ -248,6 +248,12 @@ export const classFeedMethods = {
248
248
  return listNodeStructures(this, params);
249
249
  },
250
250
 
251
+ /** Список серверов сети (/NODES) для назначения в роли доступа (только BOSS). */
252
+ async agent_network_nodes(params = {}) {
253
+ const { listNodeNetworkNodes } = await import('../../modules/agent/node-rules.js');
254
+ return listNodeNetworkNodes(this, params);
255
+ },
256
+
251
257
  /** Список последних выполненных задач (.task) узла для повторения по расписанию (только BOSS). */
252
258
  async agent_tasks_list(params = {}) {
253
259
  const { listNodeTasks } = await import('../../modules/agent/node-rules.js');
@@ -2118,7 +2118,7 @@ export class $folder extends $item{
2118
2118
  }
2119
2119
 
2120
2120
  sortItems(files, reverse = false, isType = this.isType) {
2121
- const rootOrder = { ORGANIZATIONS: 0, PROJECTS: 1, USERS: 2, MODULES: 3, MODELS: 4, NODES: 5, nodes: 5, SERVICES: 6 };
2121
+ const rootOrder = { ORGANIZATIONS: 0, PROJECTS: 1, USERS: 2, NODES: 3, nodes: 3, MODULES: 4, MODELS: 5, SERVICES: 6 };
2122
2122
  const typeGroup = (t) => {
2123
2123
  if (t === '$catalog' || t === '$virtual' || t === '$struct' || t === '$operation' || t === '$register' || t === '$account')
2124
2124
  return 0;