Reorganize: Move all skills to skills/ folder
- Created skills/ directory - Moved 272 skills to skills/ subfolder - Kept agents/ at root level - Kept installation scripts and docs at root level Repository structure: - skills/ - All 272 skills from skills.sh - agents/ - Agent definitions - *.sh, *.ps1 - Installation scripts - README.md, etc. - Documentation Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
9
skills/plugins/cache/zai-coding-plugins/glm-plan-bug/0.0.1/.claude-plugin/plugin.json
vendored
Normal file
9
skills/plugins/cache/zai-coding-plugins/glm-plan-bug/0.0.1/.claude-plugin/plugin.json
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "glm-plan-bug",
|
||||
"description": "Submit case feedback and bug reports for GLM Coding Plan service",
|
||||
"version": "0.0.1",
|
||||
"author": {
|
||||
"name": "gongchao",
|
||||
"email": "chao.gong@z.ai"
|
||||
}
|
||||
}
|
||||
29
skills/plugins/cache/zai-coding-plugins/glm-plan-bug/0.0.1/README.md
vendored
Normal file
29
skills/plugins/cache/zai-coding-plugins/glm-plan-bug/0.0.1/README.md
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
# GLM Plan Bug Plugin
|
||||
|
||||
Submit case feedback and bug reports for GLM Coding Plan.
|
||||
|
||||
Attention:
|
||||
|
||||
- This plugin is designed to work specifically with the GLM Coding Plan in Claude Code.
|
||||
- This plugin requires Node.js to be installed in your environment.
|
||||
|
||||
## How to use
|
||||
|
||||
In Claude Code, run:
|
||||
```
|
||||
/glm-plan-bug:case-feedback i have a issue with my plan
|
||||
```
|
||||
|
||||
## Command overview
|
||||
|
||||
### /case-feedback
|
||||
|
||||
Submit case feedback to report issues or suggestions for the current conversation.
|
||||
|
||||
**Execution flow:**
|
||||
1. Command `/case-feedback` triggers `@case-feedback-agent`
|
||||
2. The agent invokes `@case-feedback-skill`
|
||||
3. The skill gathers feedback information and executes the submission script
|
||||
4. The skill returns either the successful response or the failure reason
|
||||
|
||||
**Important constraint:** Run the submission exactly once and return immediately whether it succeeds or fails.
|
||||
37
skills/plugins/cache/zai-coding-plugins/glm-plan-bug/0.0.1/agents/case-feedback-agent.md
vendored
Normal file
37
skills/plugins/cache/zai-coding-plugins/glm-plan-bug/0.0.1/agents/case-feedback-agent.md
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
---
|
||||
name: case-feedback-agent
|
||||
description: Submit case feedback to report issues or suggestions. Triggered by the /glm-plan-bug:case-feedback command.
|
||||
tools: Bash, Read, Skill, Glob, Grep
|
||||
---
|
||||
|
||||
# Case Feedback Agent
|
||||
|
||||
You are responsible for submitting user feedback about the current case/conversation.
|
||||
|
||||
## Critical constraint
|
||||
|
||||
**Run the submission exactly once.** Regardless of success or failure, execute a single submission and immediately return the result. No retries, no loops.
|
||||
|
||||
## Execution
|
||||
|
||||
### Invoke the skill
|
||||
|
||||
Call @glm-plan-bug:case-feedback-skill to feedback.
|
||||
|
||||
The skill will run submit-feedback.mjs automatically, then return the result.
|
||||
|
||||
### Report the outcome
|
||||
|
||||
Based on the skill output, respond to the user:
|
||||
|
||||
Attention: If the Platform in the skill output is ZHIPU, then output Chinese 中文. If it is ZAI, then output English.
|
||||
|
||||
- **Success**: Confirm that feedback has been submitted successfully
|
||||
- **Failure**: Show the error details
|
||||
|
||||
## Prohibited actions
|
||||
|
||||
- Do not run multiple submissions
|
||||
- Do not retry automatically after failure
|
||||
- Do not ask the user whether to retry
|
||||
- Do not modify user files
|
||||
16
skills/plugins/cache/zai-coding-plugins/glm-plan-bug/0.0.1/commands/case-feedback.md
vendored
Normal file
16
skills/plugins/cache/zai-coding-plugins/glm-plan-bug/0.0.1/commands/case-feedback.md
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
---
|
||||
allowed-tools: all
|
||||
description: Submit case feedback to report issues or suggestions for the current conversation
|
||||
---
|
||||
|
||||
# Case Feedback
|
||||
|
||||
Invoke @glm-plan-bug:case-feedback-agent to submit feedback for the current case/conversation.
|
||||
|
||||
## Critical constraint
|
||||
|
||||
**Run the submission exactly once** — regardless of success or failure, execute a single submission and return the result immediately.
|
||||
|
||||
## Usage
|
||||
|
||||
The user may provide feedback content directly, or you can help summarize the issue. The context will be automatically extracted from the current conversation.
|
||||
63
skills/plugins/cache/zai-coding-plugins/glm-plan-bug/0.0.1/skills/case-feedback-skill/SKILL.md
vendored
Normal file
63
skills/plugins/cache/zai-coding-plugins/glm-plan-bug/0.0.1/skills/case-feedback-skill/SKILL.md
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
---
|
||||
name: case-feedback-skill
|
||||
description: Run the case feedback script to submit feedback for the current conversation. Only use when invoked by case-feedback-agent.
|
||||
allowed-tools: Bash, Read
|
||||
---
|
||||
|
||||
# Case Feedback Skill
|
||||
|
||||
Execute the feedback submission script and return the result.
|
||||
|
||||
## Critical constraint
|
||||
|
||||
**Run the script exactly once** — regardless of success or failure, execute it once and return the outcome.
|
||||
|
||||
## Execution
|
||||
|
||||
### Gather information
|
||||
|
||||
**feedback**:
|
||||
|
||||
- If the user explicitly provided feedback text, use that directly
|
||||
- If the user describes a problem or issue, summarize it concisely as the feedback
|
||||
- Ask the user for clarification only if no feedback intent can be inferred
|
||||
|
||||
**context**:
|
||||
|
||||
The context contains a summary of the conversation, and **must append** the original, complete conversation history data.
|
||||
|
||||
Summarize the current conversation context, including:
|
||||
- What task the user was trying to accomplish
|
||||
- What operations were performed
|
||||
- Any errors or unexpected behaviors encountered
|
||||
- Relevant code snippets or file paths (keep it concise)
|
||||
|
||||
**code_type**:
|
||||
|
||||
Identify the programming language or code type involved (e.g., JavaScript, Python, Java). If not relevant, leave it blank.
|
||||
|
||||
**request_id**:
|
||||
|
||||
Extract the unique request ID or the session ID associated with this conversation or case. If not available, leave it blank.
|
||||
|
||||
**happened_time**:
|
||||
|
||||
Extract the timestamp when the issue occurred. If not mentioned, leave it blank.
|
||||
|
||||
|
||||
### Run the submission
|
||||
|
||||
Use Node.js to execute the bundled script, pay attention to the path changes in the Windows:
|
||||
|
||||
```bash
|
||||
node scripts/submit-feedback.mjs --feedback "user feedback content" --context "conversation context summary" --code_type "the current code type, eg: javascript, typescript, python, java, etc. Not required." --happened_time "the time when the issue happened, eg: 2025-12-10 11:15:00. Not required." --request_id "the unique request id if available. Not required."
|
||||
```
|
||||
|
||||
> If your working directory is elsewhere, `cd` into the plugin root first or use an absolute path:
|
||||
> `node /absolute/path/to/glm-plan-bug/skills/case-feedback-skill/scripts/submit-feedback.mjs --feedback "..." --context "..."`
|
||||
|
||||
### Return the result
|
||||
|
||||
After execution, return the result to the caller:
|
||||
- **Success**: display the submission confirmation
|
||||
- **Failure**: show the error details and likely cause
|
||||
@@ -0,0 +1,176 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Case feedback submission script.
|
||||
* Determines whether to call the Z.ai or ZHIPU endpoint based on ANTHROPIC_BASE_URL
|
||||
* and authenticates with ANTHROPIC_AUTH_TOKEN.
|
||||
*/
|
||||
|
||||
import https from 'https';
|
||||
|
||||
// Parse command line arguments
|
||||
const args = process.argv.slice(2);
|
||||
let feedback = '';
|
||||
let context = '';
|
||||
let codeType = '';
|
||||
let happenedTime = '';
|
||||
let requestId = '';
|
||||
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
if (args[i] === '--feedback' && args[i + 1]) {
|
||||
feedback = args[i + 1];
|
||||
i++;
|
||||
} else if (args[i] === '--context' && args[i + 1]) {
|
||||
context = args[i + 1];
|
||||
i++;
|
||||
} else if (args[i] === '--code_type' && args[i + 1]) {
|
||||
codeType = args[i + 1];
|
||||
i++;
|
||||
} else if (args[i] === '--happened_time' && args[i + 1]) {
|
||||
happenedTime = args[i + 1];
|
||||
i++;
|
||||
} else if (args[i] === '--request_id' && args[i + 1]) {
|
||||
requestId = args[i + 1];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!feedback) {
|
||||
console.error('Error: --feedback argument is required');
|
||||
console.error('');
|
||||
console.error('Usage:');
|
||||
console.error(' node submit-feedback.mjs --feedback "your feedback" --context "context info"');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (!context) {
|
||||
console.error('Error: --context argument is required');
|
||||
console.error('');
|
||||
console.error('Usage:');
|
||||
console.error(' node submit-feedback.mjs --feedback "your feedback" --context "context info"');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Read environment variables
|
||||
const baseUrl = process.env.ANTHROPIC_BASE_URL || '';
|
||||
const authToken = process.env.ANTHROPIC_AUTH_TOKEN || '';
|
||||
|
||||
if (!authToken) {
|
||||
console.error('Error: ANTHROPIC_AUTH_TOKEN is not set');
|
||||
console.error('');
|
||||
console.error('Set the environment variable and retry:');
|
||||
console.error(' export ANTHROPIC_AUTH_TOKEN="your-token-here"');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Validate ANTHROPIC_BASE_URL
|
||||
if (!baseUrl) {
|
||||
console.error('Error: ANTHROPIC_BASE_URL is not set');
|
||||
console.error('');
|
||||
console.error('Set the environment variable and retry:');
|
||||
console.error(' export ANTHROPIC_BASE_URL="https://api.z.ai/api/anthropic"');
|
||||
console.error(' or');
|
||||
console.error(' export ANTHROPIC_BASE_URL="https://open.bigmodel.cn/api/anthropic"');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Determine which platform to use
|
||||
let platform;
|
||||
let feedbackUrl;
|
||||
|
||||
// Extract the base domain from ANTHROPIC_BASE_URL
|
||||
const parsedBaseUrl = new URL(baseUrl);
|
||||
const baseDomain = `${parsedBaseUrl.protocol}//${parsedBaseUrl.host}`;
|
||||
|
||||
if (baseUrl.includes('api.z.ai')) {
|
||||
platform = 'ZAI';
|
||||
feedbackUrl = `${baseDomain}/api/monitor/feedback/case`;
|
||||
} else if (baseUrl.includes('open.bigmodel.cn') || baseUrl.includes('dev.bigmodel.cn')) {
|
||||
platform = 'ZHIPU';
|
||||
feedbackUrl = `${baseDomain}/api/monitor/feedback/case`;
|
||||
} else {
|
||||
console.error('Error: Unrecognized ANTHROPIC_BASE_URL:', baseUrl);
|
||||
console.error('');
|
||||
console.error('Supported values:');
|
||||
console.error(' - https://api.z.ai/api/anthropic');
|
||||
console.error(' - https://open.bigmodel.cn/api/anthropic');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(`Platform: ${platform}`);
|
||||
console.log('');
|
||||
|
||||
const submitFeedback = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const parsedUrl = new URL(feedbackUrl);
|
||||
const postData = JSON.stringify({
|
||||
feedback: feedback,
|
||||
context: context,
|
||||
codeType: codeType,
|
||||
happenedTime: happenedTime,
|
||||
requestId: requestId
|
||||
});
|
||||
|
||||
const options = {
|
||||
hostname: parsedUrl.hostname,
|
||||
port: 443,
|
||||
path: parsedUrl.pathname,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': authToken,
|
||||
'Content-Type': 'application/json',
|
||||
'Accept-Language': 'en-US,en',
|
||||
'Content-Length': Buffer.byteLength(postData)
|
||||
}
|
||||
};
|
||||
|
||||
const req = https.request(options, (res) => {
|
||||
let data = '';
|
||||
|
||||
res.on('data', (chunk) => {
|
||||
data += chunk;
|
||||
});
|
||||
|
||||
res.on('end', () => {
|
||||
if (res.statusCode !== 200) {
|
||||
return reject(new Error(`HTTP ${res.statusCode}\n${data}`));
|
||||
}
|
||||
|
||||
console.log('Feedback submitted successfully!');
|
||||
console.log('');
|
||||
|
||||
try {
|
||||
const json = JSON.parse(data);
|
||||
console.log('Response:');
|
||||
console.log(JSON.stringify(json, null, 2));
|
||||
} catch (e) {
|
||||
console.log('Response body:');
|
||||
console.log(data);
|
||||
}
|
||||
|
||||
console.log('');
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
req.on('error', (error) => {
|
||||
reject(error);
|
||||
});
|
||||
|
||||
req.write(postData);
|
||||
req.end();
|
||||
});
|
||||
};
|
||||
|
||||
const run = async () => {
|
||||
console.log('Submitting feedback...');
|
||||
console.log('Feedback:', feedback);
|
||||
console.log('Context:', context.substring(0, 200) + (context.length > 200 ? '...' : ''));
|
||||
console.log('');
|
||||
await submitFeedback();
|
||||
};
|
||||
|
||||
run().catch((error) => {
|
||||
console.error('Request failed:', error.message);
|
||||
process.exit(1);
|
||||
});
|
||||
9
skills/plugins/cache/zai-coding-plugins/glm-plan-usage/0.0.1/.claude-plugin/plugin.json
vendored
Normal file
9
skills/plugins/cache/zai-coding-plugins/glm-plan-usage/0.0.1/.claude-plugin/plugin.json
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "glm-plan-usage",
|
||||
"description": "Query quota and usage statistics for GLM Coding Plan service",
|
||||
"version": "0.0.1",
|
||||
"author": {
|
||||
"name": "gongchao",
|
||||
"email": "chao.gong@z.ai"
|
||||
}
|
||||
}
|
||||
29
skills/plugins/cache/zai-coding-plugins/glm-plan-usage/0.0.1/README.md
vendored
Normal file
29
skills/plugins/cache/zai-coding-plugins/glm-plan-usage/0.0.1/README.md
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
# GLM Plan Usage Plugin
|
||||
|
||||
Query quota and usage statistics for GLM Coding Plan.
|
||||
|
||||
Attention:
|
||||
|
||||
- This plugin is designed to work specifically with the GLM Coding Plan in Claude Code.
|
||||
- This plugin requires Node.js to be installed in your environment.
|
||||
|
||||
## How to use
|
||||
|
||||
In Claude Code, run:
|
||||
```
|
||||
/glm-plan-usage:usage-query
|
||||
```
|
||||
|
||||
## Command overview
|
||||
|
||||
### /usage-query
|
||||
|
||||
Retrieve the usage information for the current account.
|
||||
|
||||
**Execution flow:**
|
||||
1. Command `/usage-query` triggers `@usage-query-agent`
|
||||
2. The agent invokes `@usage-query-skill`
|
||||
3. The skill checks the Node.js environment and executes the query script with the appropriate method
|
||||
4. The skill returns either the successful response or the failure reason
|
||||
|
||||
**Important constraint:** Run the query exactly once and return immediately whether it succeeds or fails.
|
||||
34
skills/plugins/cache/zai-coding-plugins/glm-plan-usage/0.0.1/agents/usage-query-agent.md
vendored
Normal file
34
skills/plugins/cache/zai-coding-plugins/glm-plan-usage/0.0.1/agents/usage-query-agent.md
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
---
|
||||
name: usage-query-agent
|
||||
description: Query GLM Coding Plan usage statistics for the current account. Triggered by the /glm-plan-usage:usage-query command.
|
||||
tools: Bash, Read, Skill, Glob, Grep
|
||||
---
|
||||
|
||||
# Usage Query Agent
|
||||
|
||||
You are responsible for querying the user's current usage information.
|
||||
|
||||
## Critical constraint
|
||||
|
||||
**Run the query exactly once.** Regardless of success or failure, execute a single query and immediately return the result. No retries, no loops.
|
||||
|
||||
## Execution
|
||||
|
||||
### Invoke the skill
|
||||
|
||||
Call @glm-plan-usage:usage-query-skill to perform the usage query.
|
||||
|
||||
The skill will run query-usage.mjs automatically, then return the result.
|
||||
|
||||
### Report the outcome
|
||||
|
||||
Based on the skill output, respond to the user:
|
||||
|
||||
Attention: If the Platform in the skill output is ZHIPU, then output Chinese 中文. If it is ZAI, then output English.
|
||||
|
||||
## Prohibited actions
|
||||
|
||||
- Do not run multiple queries
|
||||
- Do not retry automatically after failure
|
||||
- Do not ask the user whether to retry
|
||||
- Do not modify files
|
||||
12
skills/plugins/cache/zai-coding-plugins/glm-plan-usage/0.0.1/commands/usage-query.md
vendored
Normal file
12
skills/plugins/cache/zai-coding-plugins/glm-plan-usage/0.0.1/commands/usage-query.md
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
---
|
||||
allowed-tools: all
|
||||
description: Query the usage information for the current account
|
||||
---
|
||||
|
||||
# Usage Query
|
||||
|
||||
Invoke @glm-plan-usage:usage-query-agent to retrieve the usage information for the current account.
|
||||
|
||||
## Critical constraint
|
||||
|
||||
**Run the query exactly once** — regardless of success or failure, execute a single query and return the result immediately.
|
||||
33
skills/plugins/cache/zai-coding-plugins/glm-plan-usage/0.0.1/skills/usage-query-skill/SKILL.md
vendored
Normal file
33
skills/plugins/cache/zai-coding-plugins/glm-plan-usage/0.0.1/skills/usage-query-skill/SKILL.md
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
---
|
||||
name: usage-query-skill
|
||||
description: Run the usage query script to retrieve account usage information for GLM Coding Plan. Only use when invoked by usage-query-agent.
|
||||
allowed-tools: Bash, Read
|
||||
---
|
||||
|
||||
# Usage Query Skill
|
||||
|
||||
Execute the usage query script and return the result.
|
||||
|
||||
## Critical constraint
|
||||
|
||||
**Run the script exactly once** — regardless of success or failure, execute it once and return the outcome.
|
||||
|
||||
## Execution
|
||||
|
||||
|
||||
### Run the query
|
||||
|
||||
Use Node.js to execute the bundled script, pay attention to the path changes in the Windows:
|
||||
|
||||
```bash
|
||||
node scripts/query-usage.mjs
|
||||
```
|
||||
|
||||
> If your working directory is elsewhere, `cd` into the plugin root first or use an absolute path:
|
||||
> `node /absolute/path/to/glm-plan-usage/skills/usage-query-skill/scripts/query-usage.mjs`
|
||||
|
||||
### Return the result
|
||||
|
||||
After execution, return the result to the caller:
|
||||
- **Success**: display the usage payload (JSON)
|
||||
- **Failure**: show the error details and likely cause
|
||||
@@ -0,0 +1,175 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Usage query script.
|
||||
* Determines whether to call the Z.ai or ZHIPU endpoint based on ANTHROPIC_BASE_URL
|
||||
* and authenticates with ANTHROPIC_AUTH_TOKEN.
|
||||
*/
|
||||
|
||||
import https from 'https';
|
||||
|
||||
// Read environment variables
|
||||
const baseUrl = process.env.ANTHROPIC_BASE_URL || '';
|
||||
const authToken = process.env.ANTHROPIC_AUTH_TOKEN || '';
|
||||
|
||||
if (!authToken) {
|
||||
console.error('Error: ANTHROPIC_AUTH_TOKEN is not set');
|
||||
console.error('');
|
||||
console.error('Set the environment variable and retry:');
|
||||
console.error(' export ANTHROPIC_AUTH_TOKEN="your-token-here"');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Validate ANTHROPIC_BASE_URL
|
||||
if (!baseUrl) {
|
||||
console.error('Error: ANTHROPIC_BASE_URL is not set');
|
||||
console.error('');
|
||||
console.error('Set the environment variable and retry:');
|
||||
console.error(' export ANTHROPIC_BASE_URL="https://api.z.ai/api/anthropic"');
|
||||
console.error(' or');
|
||||
console.error(' export ANTHROPIC_BASE_URL="https://open.bigmodel.cn/api/anthropic"');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Determine which platform to use
|
||||
let platform;
|
||||
let modelUsageUrl;
|
||||
let toolUsageUrl;
|
||||
let quotaLimitUrl;
|
||||
|
||||
// Extract the base domain from ANTHROPIC_BASE_URL
|
||||
const parsedBaseUrl = new URL(baseUrl);
|
||||
const baseDomain = `${parsedBaseUrl.protocol}//${parsedBaseUrl.host}`;
|
||||
|
||||
if (baseUrl.includes('api.z.ai')) {
|
||||
platform = 'ZAI';
|
||||
modelUsageUrl = `${baseDomain}/api/monitor/usage/model-usage`;
|
||||
toolUsageUrl = `${baseDomain}/api/monitor/usage/tool-usage`;
|
||||
quotaLimitUrl = `${baseDomain}/api/monitor/usage/quota/limit`;
|
||||
} else if (baseUrl.includes('open.bigmodel.cn') || baseUrl.includes('dev.bigmodel.cn')) {
|
||||
platform = 'ZHIPU';
|
||||
modelUsageUrl = `${baseDomain}/api/monitor/usage/model-usage`;
|
||||
toolUsageUrl = `${baseDomain}/api/monitor/usage/tool-usage`;
|
||||
quotaLimitUrl = `${baseDomain}/api/monitor/usage/quota/limit`;
|
||||
} else {
|
||||
console.error('Error: Unrecognized ANTHROPIC_BASE_URL:', baseUrl);
|
||||
console.error('');
|
||||
console.error('Supported values:');
|
||||
console.error(' - https://api.z.ai/api/anthropic');
|
||||
console.error(' - https://open.bigmodel.cn/api/anthropic');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(`Platform: ${platform}`);
|
||||
console.log('');
|
||||
// Time window: from yesterday at the current hour (HH:00:00) to today at the current hour end (HH:59:59).
|
||||
const now = new Date();
|
||||
const startDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1, now.getHours(), 0, 0, 0);
|
||||
const endDate = new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours(), 59, 59, 999);
|
||||
|
||||
// Format dates as yyyy-MM-dd HH:mm:ss
|
||||
const formatDateTime = (date) => {
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
const hours = String(date.getHours()).padStart(2, '0');
|
||||
const minutes = String(date.getMinutes()).padStart(2, '0');
|
||||
const seconds = String(date.getSeconds()).padStart(2, '0');
|
||||
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
||||
};
|
||||
|
||||
const startTime = formatDateTime(startDate);
|
||||
const endtime = formatDateTime(endDate);
|
||||
|
||||
// Properly encode query parameters
|
||||
const queryParams = `?startTime=${encodeURIComponent(startTime)}&endTime=${encodeURIComponent(endtime)}`;
|
||||
|
||||
const processQuotaLimit = (data) => {
|
||||
if (!data || !data.limits) return data;
|
||||
|
||||
data.limits = data.limits.map(item => {
|
||||
if (item.type === 'TOKENS_LIMIT') {
|
||||
return {
|
||||
type: 'Token usage(5 Hour)',
|
||||
percentage: item.percentage
|
||||
};
|
||||
}
|
||||
if (item.type === 'TIME_LIMIT') {
|
||||
return {
|
||||
type: 'MCP usage(1 Month)',
|
||||
percentage: item.percentage,
|
||||
currentUsage: item.currentValue,
|
||||
totol: item.usage,
|
||||
usageDetails: item.usageDetails
|
||||
};
|
||||
}
|
||||
return item;
|
||||
});
|
||||
return data;
|
||||
};
|
||||
|
||||
const queryUsage = (apiUrl, label, appendQueryParams = true, postProcessor = null) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const parsedUrl = new URL(apiUrl);
|
||||
const options = {
|
||||
hostname: parsedUrl.hostname,
|
||||
port: 443,
|
||||
path: parsedUrl.pathname + (appendQueryParams ? queryParams : ''),
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Authorization': authToken,
|
||||
'Accept-Language': 'en-US,en',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
};
|
||||
|
||||
const req = https.request(options, (res) => {
|
||||
let data = '';
|
||||
|
||||
res.on('data', (chunk) => {
|
||||
data += chunk;
|
||||
});
|
||||
|
||||
res.on('end', () => {
|
||||
if (res.statusCode !== 200) {
|
||||
return reject(new Error(`[${label}] HTTP ${res.statusCode}\n${data}`));
|
||||
}
|
||||
|
||||
console.log(`${label} data:`);
|
||||
console.log('');
|
||||
|
||||
try {
|
||||
const json = JSON.parse(data);
|
||||
let outputData = json.data || json;
|
||||
if (postProcessor && json.data) {
|
||||
outputData = postProcessor(json.data);
|
||||
}
|
||||
console.log(JSON.stringify(outputData));
|
||||
} catch (e) {
|
||||
console.log('Response body:');
|
||||
console.log(data);
|
||||
}
|
||||
|
||||
console.log('');
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
req.on('error', (error) => {
|
||||
reject(error);
|
||||
});
|
||||
|
||||
req.end();
|
||||
});
|
||||
};
|
||||
|
||||
const run = async () => {
|
||||
await queryUsage(modelUsageUrl, 'Model usage');
|
||||
await queryUsage(toolUsageUrl, 'Tool usage');
|
||||
await queryUsage(quotaLimitUrl, 'Quota limit', false, processQuotaLimit);
|
||||
};
|
||||
|
||||
run().catch((error) => {
|
||||
console.error('Request failed:', error.message);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user