aliyun-sls-mcp 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/README.md ADDED
@@ -0,0 +1,342 @@
1
+ # aliyun-sls-mcp
2
+
3
+ 阿里云日志服务(SLS)的 MCP Server,让 AI 助手(Cursor、Claude Desktop 等)能够直接查询 SLS 日志,辅助开发过程中的问题排查与分析。
4
+
5
+ **只读模式,不执行任何写入或删除操作。**
6
+
7
+ [English](./README.en.md) | [GitHub](https://github.com/SuxyEE/aliyun-sls-mcp) | [npm](https://www.npmjs.com/package/aliyun-sls-mcp)
8
+
9
+ ## 功能特性
10
+
11
+ - **列出项目** — 按地域动态发现所有 SLS Project,无需手动配置项目列表
12
+ - **列出日志库** — 浏览 Project 下的所有 Logstore
13
+ - **查询日志** — 支持时间范围 + SLS 查询语法过滤,适合错误排查
14
+ - **SQL 分析** — 对日志做聚合、统计、分组分析
15
+ - **日志分布图** — ASCII 柱状图展示某时间段内的日志量分布,快速定位异常时间窗口
16
+ - **上下文日志** — 获取某条日志前后的日志,还原完整执行链路
17
+
18
+ ---
19
+
20
+ ## 快速开始(npx 方式)
21
+
22
+ > 推荐方式,无需克隆代码,配置完成后即可使用。
23
+
24
+ ### 第一步:获取阿里云 AccessKey
25
+
26
+ 前往 [RAM 访问控制台](https://ram.console.aliyun.com/manage/ak) 创建 AccessKey,并为对应 RAM 用户授予以下权限:
27
+
28
+ ```
29
+ AliyunLogReadOnlyAccess
30
+ ```
31
+
32
+ ### 第二步:配置 MCP
33
+
34
+ **Cursor**:编辑 `~/.cursor/mcp.json`(Windows: `%USERPROFILE%\.cursor\mcp.json`)
35
+
36
+ **Claude Desktop**:编辑 `~/Library/Application Support/Claude/claude_desktop_config.json`(Windows: `%APPDATA%\Claude\claude_desktop_config.json`)
37
+
38
+ ```json
39
+ {
40
+ "mcpServers": {
41
+ "aliyun-sls": {
42
+ "command": "npx",
43
+ "args": ["-y", "aliyun-sls-mcp"],
44
+ "env": {
45
+ "ALIBABA_CLOUD_ACCESS_KEY_ID": "your_access_key_id",
46
+ "ALIBABA_CLOUD_ACCESS_KEY_SECRET": "your_access_key_secret",
47
+ "SLS_REGION": "cn-hangzhou"
48
+ }
49
+ }
50
+ }
51
+ }
52
+ ```
53
+
54
+ ### 第三步:重启 AI 客户端
55
+
56
+ 重启 Cursor 或 Claude Desktop,即可在对话中直接查询 SLS 日志。
57
+
58
+ ---
59
+
60
+ ## 本地开发 / 源码运行
61
+
62
+ 适合希望二次开发或尚未发布到 npm 时使用。
63
+
64
+ ### 克隆并构建
65
+
66
+ ```bash
67
+ git clone https://github.com/your-name/aliyun-sls-mcp.git
68
+ cd aliyun-sls-mcp
69
+ npm install
70
+ npm run build
71
+ ```
72
+
73
+ ### 配置 MCP(本地路径方式)
74
+
75
+ ```json
76
+ {
77
+ "mcpServers": {
78
+ "aliyun-sls": {
79
+ "command": "node",
80
+ "args": ["/path/to/aliyun-sls-mcp/dist/index.js"],
81
+ "env": {
82
+ "ALIBABA_CLOUD_ACCESS_KEY_ID": "your_access_key_id",
83
+ "ALIBABA_CLOUD_ACCESS_KEY_SECRET": "your_access_key_secret",
84
+ "SLS_REGION": "cn-hangzhou"
85
+ }
86
+ }
87
+ }
88
+ }
89
+ ```
90
+
91
+ Windows 路径示例:
92
+
93
+ ```json
94
+ "args": ["e:\\tools\\aliyun-sls-mcp\\dist\\index.js"]
95
+ ```
96
+
97
+ ### 本地验证
98
+
99
+ ```bash
100
+ node dist/index.js
101
+ # 输出: Aliyun SLS MCP Server running on stdio
102
+ ```
103
+
104
+ ---
105
+
106
+ ## 环境变量
107
+
108
+ | 变量名 | 是否必填 | 说明 |
109
+ |--------|----------|------|
110
+ | `ALIBABA_CLOUD_ACCESS_KEY_ID` | ✅ 必填 | 阿里云 AccessKey ID |
111
+ | `ALIBABA_CLOUD_ACCESS_KEY_SECRET` | ✅ 必填 | 阿里云 AccessKey Secret |
112
+ | `SLS_REGION` | 可选 | 默认地域,如 `cn-hangzhou`。所有工具调用时可通过 `region` 参数单独覆盖 |
113
+ | `SLS_NETWORK` | 可选 | 网络类型:`public`(默认,公网)或 `vpc`(VPC 私网) |
114
+
115
+ > **多地域支持**:只需配置一个默认地域,所有工具均支持通过 `region` 参数动态切换到任意地域的项目,无需为每个地域单独部署。
116
+
117
+ ---
118
+
119
+ ## 可用工具
120
+
121
+ ### `list_projects` — 列出项目
122
+
123
+ 列出指定地域下的所有 SLS Project。
124
+
125
+ | 参数 | 类型 | 必填 | 说明 |
126
+ |------|------|------|------|
127
+ | `region` | string | 否 | 地域 ID,默认使用 `SLS_REGION` |
128
+
129
+ ---
130
+
131
+ ### `list_logstores` — 列出日志库
132
+
133
+ 列出某个 Project 下的所有 Logstore。
134
+
135
+ | 参数 | 类型 | 必填 | 说明 |
136
+ |------|------|------|------|
137
+ | `project` | string | ✅ | SLS Project 名称 |
138
+ | `region` | string | 否 | 地域 ID |
139
+
140
+ ---
141
+
142
+ ### `query_logs` — 查询日志
143
+
144
+ 按时间范围和过滤条件查询日志,适合错误排查、接口追踪等场景。
145
+
146
+ | 参数 | 类型 | 必填 | 默认值 | 说明 |
147
+ |------|------|------|--------|------|
148
+ | `project` | string | ✅ | — | SLS Project 名称 |
149
+ | `logstore` | string | ✅ | — | Logstore 名称 |
150
+ | `query` | string | 否 | `*` | SLS 查询语句 |
151
+ | `time_range` | string | 否 | `15m` | 相对时间范围 |
152
+ | `from` | number | 否 | — | 开始时间(Unix 秒),优先于 `time_range` |
153
+ | `to` | number | 否 | — | 结束时间(Unix 秒) |
154
+ | `max_logs` | number | 否 | `50` | 最多返回条数(1-500) |
155
+ | `region` | string | 否 | — | 地域 ID |
156
+
157
+ **时间范围格式:** `1m` `5m` `15m` `30m` `1h` `2h` `6h` `12h` `1d` `3d` `7d`
158
+
159
+ **SLS 查询语法示例:**
160
+
161
+ ```
162
+ * # 所有日志
163
+ level: ERROR # 错误级别日志
164
+ content: timeout # 包含 timeout 的日志
165
+ level: ERROR AND status: 500 # 组合条件
166
+ NOT level: INFO # 排除 INFO 日志
167
+ requestId: abc-123 # 按请求 ID 追踪
168
+ ```
169
+
170
+ ---
171
+
172
+ ### `query_logs_sql` — SQL 分析
173
+
174
+ 对日志执行 SQL 查询,支持聚合、统计、分组,适合趋势分析和问题统计。
175
+
176
+ | 参数 | 类型 | 必填 | 默认值 | 说明 |
177
+ |------|------|------|--------|------|
178
+ | `project` | string | ✅ | — | SLS Project 名称 |
179
+ | `query` | string | ✅ | — | SQL 语句,FROM 子句指定 Logstore 名称 |
180
+ | `time_range` | string | 否 | `1h` | 时间范围 |
181
+ | `from` | number | 否 | — | 开始时间(Unix 秒) |
182
+ | `to` | number | 否 | — | 结束时间(Unix 秒) |
183
+ | `region` | string | 否 | — | 地域 ID |
184
+
185
+ **SQL 示例:**
186
+
187
+ ```sql
188
+ -- 按函数名统计调用量
189
+ SELECT functionName, count(*) as total
190
+ FROM default-logs
191
+ WHERE __time__ > 1700000000
192
+ GROUP BY functionName
193
+ ORDER BY total DESC
194
+
195
+ -- 统计各状态码数量
196
+ SELECT statusCode, count(*) as cnt
197
+ FROM default-logs
198
+ WHERE __time__ > 1700000000 AND statusCode != ''
199
+ GROUP BY statusCode
200
+ ORDER BY cnt DESC
201
+ ```
202
+
203
+ ---
204
+
205
+ ### `get_log_histogram` — 日志分布图
206
+
207
+ 获取某段时间内日志量的分钟级分布,以 ASCII 柱状图展示,用于快速定位流量异常或错误高峰时间点。
208
+
209
+ | 参数 | 类型 | 必填 | 默认值 | 说明 |
210
+ |------|------|------|--------|------|
211
+ | `project` | string | ✅ | — | SLS Project 名称 |
212
+ | `logstore` | string | ✅ | — | Logstore 名称 |
213
+ | `query` | string | 否 | `*` | 过滤条件 |
214
+ | `time_range` | string | 否 | `1h` | 时间范围 |
215
+ | `from` | number | 否 | — | 开始时间(Unix 秒) |
216
+ | `to` | number | 否 | — | 结束时间(Unix 秒) |
217
+ | `region` | string | 否 | — | 地域 ID |
218
+
219
+ **输出示例:**
220
+
221
+ ```
222
+ 2026/3/19 11:03:00 ███████████████████░░░░░░░░░░░ 1996
223
+ 2026/3/19 11:04:00 ███████████████████████░░░░░░░ 2379 ← 流量高峰
224
+ 2026/3/19 11:05:00 ████████████████░░░░░░░░░░░░░░ 1670
225
+ ```
226
+
227
+ ---
228
+
229
+ ### `get_context_logs` — 上下文日志
230
+
231
+ 获取某条日志前后的若干条日志,还原事件发生前后的完整执行链路。
232
+
233
+ > 需要日志包含 `__tag__:__pack_meta__` 字段。阿里云 FC 函数计算的日志通常没有该字段,可改用 `query_logs` 按 `__tag__:__pack_id__` 过滤同一批次的日志。
234
+
235
+ | 参数 | 类型 | 必填 | 默认值 | 说明 |
236
+ |------|------|------|--------|------|
237
+ | `project` | string | ✅ | — | SLS Project 名称 |
238
+ | `logstore` | string | ✅ | — | Logstore 名称 |
239
+ | `pack_id` | string | ✅ | — | 目标日志的 `__tag__:__pack_id__` 字段值 |
240
+ | `pack_meta` | string | ✅ | — | 目标日志的 `__tag__:__pack_meta__` 字段值 |
241
+ | `back_lines` | number | 否 | `10` | 向前获取的条数(最大 100) |
242
+ | `forward_lines` | number | 否 | `10` | 向后获取的条数(最大 100) |
243
+ | `region` | string | 否 | — | 地域 ID |
244
+
245
+ ---
246
+
247
+ ## 对话使用示例
248
+
249
+ ```
250
+ 列出深圳地域所有 SLS 项目
251
+
252
+ 查询 my-project 项目 app-logs 日志库最近 15 分钟的错误日志
253
+
254
+ 查看 my-project 最近 1 小时的日志量分布,找出流量高峰时间点
255
+
256
+ 统计 my-project 最近 1 小时各函数的调用量
257
+
258
+ 查询 cn-shanghai 地域 payment-project 项目 order-logs 中包含 timeout 的日志
259
+
260
+ 帮我排查 2026-03-19 11:00 到 11:30 之间 xyjapi 函数出现的 SLOW SQL 问题
261
+ ```
262
+
263
+ ---
264
+
265
+ ## 支持的地域
266
+
267
+ ### 亚太
268
+
269
+ | 地域名称 | 地域 ID |
270
+ |----------|---------|
271
+ | 华北1(青岛) | `cn-qingdao` |
272
+ | 华北2(北京) | `cn-beijing` |
273
+ | 华北3(张家口) | `cn-zhangjiakou` |
274
+ | 华北5(呼和浩特) | `cn-huhehaote` |
275
+ | 华北6(乌兰察布) | `cn-wulanchabu` |
276
+ | 华东1(杭州) | `cn-hangzhou` |
277
+ | 华东2(上海) | `cn-shanghai` |
278
+ | 华东5(南京-本地地域) | `cn-nanjing` |
279
+ | 华东6(福州-本地地域) | `cn-fuzhou` |
280
+ | 华南1(深圳) | `cn-shenzhen` |
281
+ | 华南2(河源) | `cn-heyuan` |
282
+ | 华南3(广州) | `cn-guangzhou` |
283
+ | 西南1(成都) | `cn-chengdu` |
284
+ | 中国香港 | `cn-hongkong` |
285
+ | 日本(东京) | `ap-northeast-1` |
286
+ | 韩国(首尔) | `ap-northeast-2` |
287
+ | 新加坡 | `ap-southeast-1` |
288
+ | 马来西亚(吉隆坡) | `ap-southeast-3` |
289
+ | 印度尼西亚(雅加达) | `ap-southeast-5` |
290
+ | 菲律宾(马尼拉) | `ap-southeast-6` |
291
+ | 泰国(曼谷) | `ap-southeast-7` |
292
+
293
+ ### 欧洲与美洲
294
+
295
+ | 地域名称 | 地域 ID |
296
+ |----------|---------|
297
+ | 美国(硅谷) | `us-west-1` |
298
+ | 美国(弗吉尼亚) | `us-east-1` |
299
+ | 美国(亚特兰大) | `us-southeast-1` |
300
+ | 德国(法兰克福) | `eu-central-1` |
301
+ | 英国(伦敦) | `eu-west-1` |
302
+
303
+ ### 中东
304
+
305
+ | 地域名称 | 地域 ID |
306
+ |----------|---------|
307
+ | 沙特(利雅得) | `me-central-1` |
308
+ | 阿联酋(迪拜) | `me-east-1` |
309
+
310
+ ### 行业云
311
+
312
+ | 地域名称 | 地域 ID |
313
+ |----------|---------|
314
+ | 华北2 金融云 | `cn-beijing-finance-1` |
315
+ | 华东1 金融云 | `cn-hangzhou-finance` |
316
+ | 华东2 金融云 | `cn-shanghai-finance-1` |
317
+ | 华南1 金融云 | `cn-shenzhen-finance-1` |
318
+ | 河源专属云(汽车合规) | `cn-heyuan-acdr-1` |
319
+
320
+ > 完整接入点列表参见[阿里云 SLS 服务接入点文档](https://help.aliyun.com/zh/sls/developer-reference/service-entrance)。
321
+
322
+ ---
323
+
324
+ ## 技术栈
325
+
326
+ - **语言**:TypeScript
327
+ - **运行时**:Node.js >= 18
328
+ - **MCP SDK**:`@modelcontextprotocol/sdk` ^1.27.1
329
+ - **SLS SDK**:`@alicloud/sls20201230` ^5.9.0
330
+
331
+ ## 本地开发
332
+
333
+ ```bash
334
+ npm install # 安装依赖
335
+ npm run dev # 监听变化自动编译
336
+ npm run build # 构建
337
+ npm start # 运行
338
+ ```
339
+
340
+ ## License
341
+
342
+ MIT
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js ADDED
@@ -0,0 +1,116 @@
1
+ #!/usr/bin/env node
2
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
3
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
4
+ import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
5
+ import { zodToJsonSchema } from 'zod-to-json-schema';
6
+ import { listProjectsSchema, handleListProjects } from './tools/list-projects.js';
7
+ import { listLogStoresSchema, handleListLogStores } from './tools/list-logstores.js';
8
+ import { queryLogsSchema, handleQueryLogs } from './tools/query-logs.js';
9
+ import { queryLogsSQLSchema, handleQueryLogsSQL } from './tools/query-logs-sql.js';
10
+ import { getLogHistogramSchema, handleGetLogHistogram } from './tools/get-log-histogram.js';
11
+ import { getContextLogsSchema, handleGetContextLogs } from './tools/get-context-logs.js';
12
+ const TOOLS = [
13
+ {
14
+ name: 'list_projects',
15
+ description: 'List all SLS projects in the specified Alibaba Cloud region. Use this to discover available projects before querying logs.',
16
+ inputSchema: zodToJsonSchema(listProjectsSchema),
17
+ },
18
+ {
19
+ name: 'list_logstores',
20
+ description: 'List all logstores within an SLS project. Use this to discover available logstores before querying logs.',
21
+ inputSchema: zodToJsonSchema(listLogStoresSchema),
22
+ },
23
+ {
24
+ name: 'query_logs',
25
+ description: 'Query log data from an SLS logstore with a time range and optional filter query. Returns formatted log entries. Use for debugging, error investigation, and log analysis. Supports SLS query syntax like "level: ERROR", "content: timeout", "status: 500 AND method: POST".',
26
+ inputSchema: zodToJsonSchema(queryLogsSchema),
27
+ },
28
+ {
29
+ name: 'query_logs_sql',
30
+ description: 'Execute a SQL query against an SLS project for log analysis and aggregation. Best for counting, grouping, statistical analysis. Example: "SELECT status, count(*) as cnt FROM <logstore> WHERE __time__ > 1700000000 GROUP BY status".',
31
+ inputSchema: zodToJsonSchema(queryLogsSQLSchema),
32
+ },
33
+ {
34
+ name: 'get_log_histogram',
35
+ description: 'Get the time-series distribution of log counts matching a query. Returns a visual histogram showing log volume over time. Useful for identifying when errors spiked or when unusual activity occurred.',
36
+ inputSchema: zodToJsonSchema(getLogHistogramSchema),
37
+ },
38
+ {
39
+ name: 'get_context_logs',
40
+ description: 'Retrieve log lines before and after a specific log entry using its pack_id and pack_meta. First query logs with query_logs to find a log entry, then use its __tag__:__pack_id__ and __tag__:__pack_meta__ fields to get surrounding context. Useful for understanding full execution flow around an error.',
41
+ inputSchema: zodToJsonSchema(getContextLogsSchema),
42
+ },
43
+ ];
44
+ const server = new Server({
45
+ name: 'aliyun-sls-mcp',
46
+ version: '0.1.0',
47
+ }, {
48
+ capabilities: {
49
+ tools: {},
50
+ },
51
+ });
52
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
53
+ return { tools: TOOLS };
54
+ });
55
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
56
+ const { name, arguments: args } = request.params;
57
+ try {
58
+ let text;
59
+ switch (name) {
60
+ case 'list_projects': {
61
+ const input = listProjectsSchema.parse(args);
62
+ text = await handleListProjects(input);
63
+ break;
64
+ }
65
+ case 'list_logstores': {
66
+ const input = listLogStoresSchema.parse(args);
67
+ text = await handleListLogStores(input);
68
+ break;
69
+ }
70
+ case 'query_logs': {
71
+ const input = queryLogsSchema.parse(args);
72
+ text = await handleQueryLogs(input);
73
+ break;
74
+ }
75
+ case 'query_logs_sql': {
76
+ const input = queryLogsSQLSchema.parse(args);
77
+ text = await handleQueryLogsSQL(input);
78
+ break;
79
+ }
80
+ case 'get_log_histogram': {
81
+ const input = getLogHistogramSchema.parse(args);
82
+ text = await handleGetLogHistogram(input);
83
+ break;
84
+ }
85
+ case 'get_context_logs': {
86
+ const input = getContextLogsSchema.parse(args);
87
+ text = await handleGetContextLogs(input);
88
+ break;
89
+ }
90
+ default:
91
+ throw new Error(`Unknown tool: ${name}`);
92
+ }
93
+ return {
94
+ content: [{ type: 'text', text }],
95
+ };
96
+ }
97
+ catch (error) {
98
+ const message = error instanceof Error ? error.message : String(error);
99
+ return {
100
+ content: [{ type: 'text', text: `Error: ${message}` }],
101
+ isError: true,
102
+ };
103
+ }
104
+ });
105
+ async function main() {
106
+ const transport = new StdioServerTransport();
107
+ await server.connect(transport);
108
+ process.stderr.write('Aliyun SLS MCP Server running on stdio\n');
109
+ }
110
+ process.on('SIGINT', () => process.exit(0));
111
+ process.on('SIGTERM', () => process.exit(0));
112
+ main().catch((err) => {
113
+ process.stderr.write(`Fatal error: ${err}\n`);
114
+ process.exit(1);
115
+ });
116
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GAEvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,EAAE,k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AC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC;IAC9C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,74 @@
1
+ export interface SlsConfig {
2
+ accessKeyId: string;
3
+ accessKeySecret: string;
4
+ region: string;
5
+ network?: 'public' | 'vpc';
6
+ }
7
+ export interface LogEntry {
8
+ [key: string]: string;
9
+ }
10
+ export interface QueryLogsResult {
11
+ logs: LogEntry[];
12
+ count: number;
13
+ processedRows?: number;
14
+ hasMore: boolean;
15
+ progress?: string;
16
+ }
17
+ export interface LogHistogram {
18
+ from: number;
19
+ to: number;
20
+ count: number;
21
+ progress: string;
22
+ }
23
+ export interface ContextLogsResult {
24
+ logs: LogEntry[];
25
+ backCount: number;
26
+ forwardCount: number;
27
+ }
28
+ export declare function listProjects(region?: string): Promise<{
29
+ projectName: string;
30
+ description: string;
31
+ region: string;
32
+ }[]>;
33
+ export declare function listLogStores(project: string, region?: string): Promise<{
34
+ logstoreName: string;
35
+ }[]>;
36
+ export declare function queryLogs(params: {
37
+ project: string;
38
+ logstore: string;
39
+ query: string;
40
+ from: number;
41
+ to: number;
42
+ maxLogs?: number;
43
+ region?: string;
44
+ }): Promise<QueryLogsResult>;
45
+ export declare function queryLogsBySQL(params: {
46
+ project: string;
47
+ query: string;
48
+ from: number;
49
+ to: number;
50
+ region?: string;
51
+ }): Promise<QueryLogsResult>;
52
+ export declare function getLogHistogram(params: {
53
+ project: string;
54
+ logstore: string;
55
+ query: string;
56
+ from: number;
57
+ to: number;
58
+ region?: string;
59
+ }): Promise<LogHistogram[]>;
60
+ export declare function getContextLogs(params: {
61
+ project: string;
62
+ logstore: string;
63
+ packId: string;
64
+ packMeta: string;
65
+ backLines?: number;
66
+ forwardLines?: number;
67
+ region?: string;
68
+ }): Promise<ContextLogsResult>;
69
+ export declare function parseTimeRange(timeStr: string): {
70
+ from: number;
71
+ to: number;
72
+ };
73
+ export declare function formatTimestamp(unixSeconds: number): string;
74
+ //# sourceMappingURL=sls-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sls-client.d.ts","sourceRoot":"","sources":["../src/sls-client.ts"],"names":[],"mappings":"AAWA,MAAM,WAAW,SAAS;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAC;CAC5B;AAED,MAAM,WAAW,QAAQ;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;CACtB;AAsCD,wBAAsB,YAAY,CAChC,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAAE,CAAC,CA4BzE;AAED,wBAAsB,aAAa,CACjC,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC;IAAE,YAAY,EAAE,MAAM,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