@mo7yw4ng/openape 1.0.6 → 2.0.3

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.
Files changed (152) hide show
  1. package/bin/openape +29 -0
  2. package/bin/openape.js +29 -0
  3. package/package.json +22 -28
  4. package/LICENSE +0 -21
  5. package/README.md +0 -138
  6. package/esm/_dnt.polyfills.d.ts +0 -101
  7. package/esm/_dnt.polyfills.d.ts.map +0 -1
  8. package/esm/_dnt.polyfills.js +0 -127
  9. package/esm/_dnt.shims.d.ts +0 -6
  10. package/esm/_dnt.shims.d.ts.map +0 -1
  11. package/esm/_dnt.shims.js +0 -61
  12. package/esm/deno.d.ts +0 -25
  13. package/esm/deno.d.ts.map +0 -1
  14. package/esm/deno.js +0 -23
  15. package/esm/package.json +0 -3
  16. package/esm/src/commands/announcements.d.ts +0 -3
  17. package/esm/src/commands/announcements.d.ts.map +0 -1
  18. package/esm/src/commands/announcements.js +0 -71
  19. package/esm/src/commands/assignments.d.ts +0 -3
  20. package/esm/src/commands/assignments.d.ts.map +0 -1
  21. package/esm/src/commands/assignments.js +0 -229
  22. package/esm/src/commands/auth.d.ts +0 -3
  23. package/esm/src/commands/auth.d.ts.map +0 -1
  24. package/esm/src/commands/auth.js +0 -290
  25. package/esm/src/commands/calendar.d.ts +0 -3
  26. package/esm/src/commands/calendar.d.ts.map +0 -1
  27. package/esm/src/commands/calendar.js +0 -127
  28. package/esm/src/commands/courses.d.ts +0 -3
  29. package/esm/src/commands/courses.d.ts.map +0 -1
  30. package/esm/src/commands/courses.js +0 -312
  31. package/esm/src/commands/forums.d.ts +0 -3
  32. package/esm/src/commands/forums.d.ts.map +0 -1
  33. package/esm/src/commands/forums.js +0 -190
  34. package/esm/src/commands/grades.d.ts +0 -3
  35. package/esm/src/commands/grades.d.ts.map +0 -1
  36. package/esm/src/commands/grades.js +0 -84
  37. package/esm/src/commands/materials.d.ts +0 -3
  38. package/esm/src/commands/materials.d.ts.map +0 -1
  39. package/esm/src/commands/materials.js +0 -402
  40. package/esm/src/commands/quizzes.d.ts +0 -3
  41. package/esm/src/commands/quizzes.d.ts.map +0 -1
  42. package/esm/src/commands/quizzes.js +0 -236
  43. package/esm/src/commands/skills.d.ts +0 -3
  44. package/esm/src/commands/skills.d.ts.map +0 -1
  45. package/esm/src/commands/skills.js +0 -106
  46. package/esm/src/commands/upload.d.ts +0 -3
  47. package/esm/src/commands/upload.d.ts.map +0 -1
  48. package/esm/src/commands/upload.js +0 -55
  49. package/esm/src/commands/videos.d.ts +0 -3
  50. package/esm/src/commands/videos.d.ts.map +0 -1
  51. package/esm/src/commands/videos.js +0 -266
  52. package/esm/src/index.d.ts +0 -28
  53. package/esm/src/index.d.ts.map +0 -1
  54. package/esm/src/index.js +0 -164
  55. package/esm/src/lib/auth.d.ts +0 -66
  56. package/esm/src/lib/auth.d.ts.map +0 -1
  57. package/esm/src/lib/auth.js +0 -286
  58. package/esm/src/lib/config.d.ts +0 -6
  59. package/esm/src/lib/config.d.ts.map +0 -1
  60. package/esm/src/lib/config.js +0 -36
  61. package/esm/src/lib/logger.d.ts +0 -3
  62. package/esm/src/lib/logger.d.ts.map +0 -1
  63. package/esm/src/lib/logger.js +0 -26
  64. package/esm/src/lib/moodle.d.ts +0 -447
  65. package/esm/src/lib/moodle.d.ts.map +0 -1
  66. package/esm/src/lib/moodle.js +0 -1353
  67. package/esm/src/lib/session.d.ts +0 -8
  68. package/esm/src/lib/session.d.ts.map +0 -1
  69. package/esm/src/lib/session.js +0 -42
  70. package/esm/src/lib/token.d.ts +0 -38
  71. package/esm/src/lib/token.d.ts.map +0 -1
  72. package/esm/src/lib/token.js +0 -178
  73. package/esm/src/lib/types.d.ts +0 -189
  74. package/esm/src/lib/types.d.ts.map +0 -1
  75. package/esm/src/lib/types.js +0 -2
  76. package/esm/src/lib/utils.d.ts +0 -52
  77. package/esm/src/lib/utils.d.ts.map +0 -1
  78. package/esm/src/lib/utils.js +0 -122
  79. package/script/_dnt.polyfills.d.ts +0 -101
  80. package/script/_dnt.polyfills.d.ts.map +0 -1
  81. package/script/_dnt.polyfills.js +0 -130
  82. package/script/_dnt.shims.d.ts +0 -6
  83. package/script/_dnt.shims.d.ts.map +0 -1
  84. package/script/_dnt.shims.js +0 -65
  85. package/script/deno.d.ts +0 -25
  86. package/script/deno.d.ts.map +0 -1
  87. package/script/deno.js +0 -25
  88. package/script/package.json +0 -3
  89. package/script/src/commands/announcements.d.ts +0 -3
  90. package/script/src/commands/announcements.d.ts.map +0 -1
  91. package/script/src/commands/announcements.js +0 -74
  92. package/script/src/commands/assignments.d.ts +0 -3
  93. package/script/src/commands/assignments.d.ts.map +0 -1
  94. package/script/src/commands/assignments.js +0 -268
  95. package/script/src/commands/auth.d.ts +0 -3
  96. package/script/src/commands/auth.d.ts.map +0 -1
  97. package/script/src/commands/auth.js +0 -296
  98. package/script/src/commands/calendar.d.ts +0 -3
  99. package/script/src/commands/calendar.d.ts.map +0 -1
  100. package/script/src/commands/calendar.js +0 -133
  101. package/script/src/commands/courses.d.ts +0 -3
  102. package/script/src/commands/courses.d.ts.map +0 -1
  103. package/script/src/commands/courses.js +0 -315
  104. package/script/src/commands/forums.d.ts +0 -3
  105. package/script/src/commands/forums.d.ts.map +0 -1
  106. package/script/src/commands/forums.js +0 -193
  107. package/script/src/commands/grades.d.ts +0 -3
  108. package/script/src/commands/grades.d.ts.map +0 -1
  109. package/script/src/commands/grades.js +0 -87
  110. package/script/src/commands/materials.d.ts +0 -3
  111. package/script/src/commands/materials.d.ts.map +0 -1
  112. package/script/src/commands/materials.js +0 -408
  113. package/script/src/commands/quizzes.d.ts +0 -3
  114. package/script/src/commands/quizzes.d.ts.map +0 -1
  115. package/script/src/commands/quizzes.js +0 -239
  116. package/script/src/commands/skills.d.ts +0 -3
  117. package/script/src/commands/skills.d.ts.map +0 -1
  118. package/script/src/commands/skills.js +0 -112
  119. package/script/src/commands/upload.d.ts +0 -3
  120. package/script/src/commands/upload.d.ts.map +0 -1
  121. package/script/src/commands/upload.js +0 -61
  122. package/script/src/commands/videos.d.ts +0 -3
  123. package/script/src/commands/videos.d.ts.map +0 -1
  124. package/script/src/commands/videos.js +0 -272
  125. package/script/src/index.d.ts +0 -28
  126. package/script/src/index.d.ts.map +0 -1
  127. package/script/src/index.js +0 -171
  128. package/script/src/lib/auth.d.ts +0 -66
  129. package/script/src/lib/auth.d.ts.map +0 -1
  130. package/script/src/lib/auth.js +0 -296
  131. package/script/src/lib/config.d.ts +0 -6
  132. package/script/src/lib/config.d.ts.map +0 -1
  133. package/script/src/lib/config.js +0 -42
  134. package/script/src/lib/logger.d.ts +0 -3
  135. package/script/src/lib/logger.d.ts.map +0 -1
  136. package/script/src/lib/logger.js +0 -29
  137. package/script/src/lib/moodle.d.ts +0 -447
  138. package/script/src/lib/moodle.d.ts.map +0 -1
  139. package/script/src/lib/moodle.js +0 -1425
  140. package/script/src/lib/session.d.ts +0 -8
  141. package/script/src/lib/session.d.ts.map +0 -1
  142. package/script/src/lib/session.js +0 -45
  143. package/script/src/lib/token.d.ts +0 -38
  144. package/script/src/lib/token.d.ts.map +0 -1
  145. package/script/src/lib/token.js +0 -189
  146. package/script/src/lib/types.d.ts +0 -189
  147. package/script/src/lib/types.d.ts.map +0 -1
  148. package/script/src/lib/types.js +0 -3
  149. package/script/src/lib/utils.d.ts +0 -52
  150. package/script/src/lib/utils.d.ts.map +0 -1
  151. package/script/src/lib/utils.js +0 -167
  152. package/skills/openape/SKILL.md +0 -115
@@ -1,239 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.registerQuizzesCommand = registerQuizzesCommand;
4
- const utils_js_1 = require("../lib/utils.js");
5
- const moodle_js_1 = require("../lib/moodle.js");
6
- const auth_js_1 = require("../lib/auth.js");
7
- const index_js_1 = require("../index.js");
8
- function stripHtmlKeepLines(html) {
9
- return html
10
- .replace(/<br\s*\/?>/gi, "\n")
11
- .replace(/<\/p>/gi, "\n")
12
- .replace(/<[^>]+>/g, "")
13
- .replace(/&nbsp;/g, " ")
14
- .replace(/&amp;/g, "&")
15
- .replace(/&lt;/g, "<")
16
- .replace(/&gt;/g, ">")
17
- .replace(/\n{3,}/g, "\n\n")
18
- .trim();
19
- }
20
- function parseQuestionHtml(html) {
21
- const qtextMatch = html.match(/<div class="qtext">([\s\S]*?)<\/div>\s*<\/div>/);
22
- const text = stripHtmlKeepLines(qtextMatch?.[1] ?? "");
23
- const options = [];
24
- const optionRegex = /data-region="answer-label">([\s\S]*?)<\/div>\s*<\/div>/g;
25
- let match;
26
- while ((match = optionRegex.exec(html)) !== null) {
27
- options.push(stripHtmlKeepLines(match[1]));
28
- }
29
- return { text, options };
30
- }
31
- function parseSavedAnswer(html) {
32
- const radioChecked = html.match(/<input type="radio"[^>]*value="(\d+)"[^>]*checked="checked"/);
33
- if (radioChecked && radioChecked[1] !== "-1")
34
- return radioChecked[1];
35
- const checkboxChecked = [...html.matchAll(/<input type="checkbox"[^>]*name="[^"]*choice(\d+)"[^>]*checked="checked"/g)];
36
- if (checkboxChecked.length > 0)
37
- return checkboxChecked.map(m => m[1]);
38
- // Match <input> with both name="*_answer" and type="text" in any attribute order
39
- const textMatch = html.match(/<input[^>]*(?:name="[^"]*:_answer"|type="text")[^>]*(?:name="[^"]*:_answer"|type="text")[^>]*value="([^"]*)"/);
40
- if (textMatch && textMatch[1] !== "")
41
- return textMatch[1];
42
- return null;
43
- }
44
- function parseQuizQuestions(questions) {
45
- return Object.values(questions).map((q) => {
46
- const parsed = parseQuestionHtml(q.html ?? "");
47
- const savedAnswer = parseSavedAnswer(q.html ?? "");
48
- return {
49
- slot: q.slot,
50
- type: q.type,
51
- status: q.status,
52
- stateclass: q.stateclass,
53
- savedAnswer,
54
- question: parsed.text,
55
- options: parsed.options,
56
- };
57
- });
58
- }
59
- function registerQuizzesCommand(program) {
60
- const quizzesCmd = program.command("quizzes");
61
- quizzesCmd.description("Quiz operations");
62
- quizzesCmd
63
- .command("list")
64
- .description("List incomplete quizzes in a course")
65
- .argument("<course-id>", "Course ID")
66
- .option("--all", "Include completed quizzes")
67
- .option("--output <format>", "Output format: json|csv|table|silent")
68
- .action(async (courseId, options, command) => {
69
- const output = (0, utils_js_1.getOutputFormat)(command);
70
- const apiContext = await (0, auth_js_1.createApiContext)(options, command);
71
- if (!apiContext) {
72
- process.exitCode = 1;
73
- return;
74
- }
75
- const quizzes = await (0, moodle_js_1.getQuizzesByCoursesApi)(apiContext.session, [parseInt(courseId, 10)]);
76
- // Default: only show incomplete quizzes
77
- const filtered = options.all ? quizzes : quizzes.filter(q => !q.isComplete);
78
- const formattedQuizzes = filtered.map(({ courseId, ...q }) => ({
79
- ...q,
80
- timeClose: q.timeClose ? (0, utils_js_1.formatTimestamp)(q.timeClose) : null,
81
- }));
82
- (0, index_js_1.formatAndOutput)(formattedQuizzes, output, apiContext.log);
83
- });
84
- quizzesCmd
85
- .command("list-all")
86
- .description("List all incomplete quizzes across all courses")
87
- .option("--level <type>", "Course level: in_progress (default) | all", "in_progress")
88
- .option("--all", "Include completed quizzes")
89
- .option("--output <format>", "Output format: json|csv|table|silent")
90
- .action(async (options, command) => {
91
- const output = (0, utils_js_1.getOutputFormat)(command);
92
- const apiContext = await (0, auth_js_1.createApiContext)(options, command);
93
- if (!apiContext) {
94
- process.exitCode = 1;
95
- return;
96
- }
97
- const classification = options.level === "all" ? undefined : "inprogress";
98
- const courses = await (0, moodle_js_1.getEnrolledCoursesApi)(apiContext.session, {
99
- classification,
100
- });
101
- // Get quizzes via WS API (no browser needed!)
102
- const courseIds = courses.map(c => c.id);
103
- const apiQuizzes = await (0, moodle_js_1.getQuizzesByCoursesApi)(apiContext.session, courseIds);
104
- // Build a map of courseId -> course for quick lookup
105
- const courseMap = new Map(courses.map(c => [c.id, c]));
106
- const allQuizzes = [];
107
- for (const q of apiQuizzes) {
108
- const course = courseMap.get(q.courseId);
109
- if (course && (options.all || !q.isComplete)) {
110
- allQuizzes.push({
111
- courseName: course.fullname,
112
- courseId: q.courseId,
113
- name: q.name,
114
- url: q.url,
115
- quizid: q.quizid,
116
- isComplete: q.isComplete,
117
- attemptsUsed: q.attemptsUsed,
118
- maxAttempts: q.maxAttempts,
119
- timeClose: q.timeClose ? (0, utils_js_1.formatTimestamp)(q.timeClose) : null,
120
- });
121
- }
122
- }
123
- apiContext.log.info(`\n總計發現 ${allQuizzes.length} 個測驗。`);
124
- (0, index_js_1.formatAndOutput)(allQuizzes, output, apiContext.log);
125
- });
126
- quizzesCmd
127
- .command("start")
128
- .description("Start a new quiz attempt")
129
- .argument("<quiz-id>", "Quiz ID")
130
- .option("--output <format>", "Output format: json|csv|table|silent")
131
- .action(async (quizCmid, options, command) => {
132
- const output = (0, utils_js_1.getOutputFormat)(command);
133
- const apiContext = await (0, auth_js_1.createApiContext)(options, command);
134
- if (!apiContext) {
135
- process.exitCode = 1;
136
- return;
137
- }
138
- try {
139
- const result = await (0, moodle_js_1.startQuizAttemptApi)(apiContext.session, quizCmid);
140
- apiContext.log.success(`Quiz attempt ${result.attempt.attemptid} started.`);
141
- const attemptId = result.attempt.attemptid;
142
- const data = await (0, moodle_js_1.getAllQuizAttemptDataApi)(apiContext.session, attemptId);
143
- const questions = parseQuizQuestions(data.questions);
144
- const outputData = [{
145
- attemptId,
146
- quizId: result.attempt.quizid,
147
- state: result.attempt.state,
148
- timeStart: (0, utils_js_1.formatTimestamp)(result.attempt.timestart),
149
- timeFinish: result.attempt.timefinish
150
- ? (0, utils_js_1.formatTimestamp)(result.attempt.timefinish)
151
- : null,
152
- isPreview: result.attempt.preview,
153
- totalQuestions: questions.length,
154
- questions,
155
- }];
156
- (0, index_js_1.formatAndOutput)(outputData, output, apiContext.log);
157
- }
158
- catch (error) {
159
- apiContext.log.error(`Failed to start quiz attempt: ${error instanceof Error ? error.message : String(error)}`);
160
- process.exitCode = 1;
161
- }
162
- });
163
- quizzesCmd
164
- .command("info")
165
- .description("Get quiz attempt data and questions")
166
- .argument("<attempt-id>", "Quiz attempt ID")
167
- .option("--page <number>", "Page number (-1 for all pages)", "-1")
168
- .option("--output <format>", "Output format: json|csv|table|silent")
169
- .action(async (attemptId, options, command) => {
170
- const output = (0, utils_js_1.getOutputFormat)(command);
171
- const apiContext = await (0, auth_js_1.createApiContext)(options, command);
172
- if (!apiContext) {
173
- process.exitCode = 1;
174
- return;
175
- }
176
- try {
177
- const pageNumber = parseInt(options.page);
178
- const data = pageNumber === -1
179
- ? await (0, moodle_js_1.getAllQuizAttemptDataApi)(apiContext.session, parseInt(attemptId))
180
- : await (0, moodle_js_1.getQuizAttemptDataApi)(apiContext.session, parseInt(attemptId), pageNumber);
181
- const questions = parseQuizQuestions(data.questions);
182
- const outputData = [{
183
- attemptId: data.attempt.attemptid,
184
- quizId: data.attempt.quizid,
185
- state: data.attempt.state,
186
- totalQuestions: questions.length,
187
- questions,
188
- }];
189
- apiContext.log.success(`Retrieved attempt ${data.attempt.attemptid}`);
190
- (0, index_js_1.formatAndOutput)(outputData, output, apiContext.log);
191
- }
192
- catch (error) {
193
- apiContext.log.error(`Failed to get attempt data: ${error instanceof Error ? error.message : String(error)}`);
194
- process.exitCode = 1;
195
- }
196
- });
197
- quizzesCmd
198
- .command("save")
199
- .description("Save answers for a quiz attempt")
200
- .argument("<attempt-id>", "Quiz attempt ID")
201
- .argument("<answers>", "Answers JSON: [{slot:1,answer:\"0\"}] multichoice=number, multichoices=\"0,2\", shortanswer=\"text\"")
202
- .option("--submit", "Submit the attempt after saving")
203
- .option("--output <format>", "Output format: json|csv|table|silent")
204
- .action(async (attemptId, answersJson, options, command) => {
205
- const output = (0, utils_js_1.getOutputFormat)(command);
206
- const apiContext = await (0, auth_js_1.createApiContext)(options, command);
207
- if (!apiContext) {
208
- process.exitCode = 1;
209
- return;
210
- }
211
- let answers;
212
- try {
213
- answers = JSON.parse(answersJson);
214
- }
215
- catch {
216
- apiContext.log.error("Invalid answers JSON. Expected format: [{\"slot\":1,\"answer\":\"0\"},...]");
217
- process.exitCode = 1;
218
- return;
219
- }
220
- try {
221
- // Get attempt data to find uniqueid and sequencecheck values
222
- const attemptData = await (0, moodle_js_1.getAllQuizAttemptDataApi)(apiContext.session, parseInt(attemptId));
223
- const uniqueId = attemptData.attempt.uniqueid ?? attemptData.attempt.attemptid;
224
- const sequenceChecks = new Map();
225
- for (const q of Object.values(attemptData.questions)) {
226
- if (q.sequencecheck !== undefined) {
227
- sequenceChecks.set(q.slot, q.sequencecheck);
228
- }
229
- }
230
- const result = await (0, moodle_js_1.processQuizAttemptApi)(apiContext.session, parseInt(attemptId), uniqueId, answers, sequenceChecks, !!options.submit);
231
- apiContext.log.success(`Attempt ${attemptId} state: ${result.state}`);
232
- (0, index_js_1.formatAndOutput)([result], output, apiContext.log);
233
- }
234
- catch (error) {
235
- apiContext.log.error(`Failed to submit attempt: ${error instanceof Error ? error.message : String(error)}`);
236
- process.exitCode = 1;
237
- }
238
- });
239
- }
@@ -1,3 +0,0 @@
1
- import { Command } from "commander";
2
- export declare function registerSkillsCommand(program: Command): void;
3
- //# sourceMappingURL=skills.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"skills.d.ts","sourceRoot":"","sources":["../../../src/src/commands/skills.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA2CpC,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAuE5D"}
@@ -1,112 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.registerSkillsCommand = registerSkillsCommand;
7
- const node_fs_1 = __importDefault(require("node:fs"));
8
- const node_path_1 = __importDefault(require("node:path"));
9
- const node_os_1 = __importDefault(require("node:os"));
10
- const node_url_1 = require("node:url");
11
- const SKILL_NAME = "openape";
12
- const GITHUB_RAW_URL = `https://raw.githubusercontent.com/mo7yw4ng/openape/refs/heads/main/skills/${SKILL_NAME}/SKILL.md`;
13
- /**
14
- * Known agent platforms and their skills directories
15
- */
16
- const PLATFORMS = {
17
- claude: { name: "Claude Code", path: node_path_1.default.join(node_os_1.default.homedir(), ".claude", "skills") },
18
- codex: { name: "Codex CLI", path: node_path_1.default.join(node_os_1.default.homedir(), ".codex", "skills") },
19
- opencode: { name: "OpenCode", path: node_path_1.default.join(node_os_1.default.homedir(), ".opencode", "skills") },
20
- };
21
- /**
22
- * Try to read SKILL.md from local project first (dev mode / bundled build),
23
- * fallback to fetching from GitHub (when installed globally via npm).
24
- */
25
- async function readSkillContent() {
26
- // Try local path first (relative to this file's location)
27
- try {
28
- const base = node_path_1.default.dirname((0, node_url_1.fileURLToPath)(globalThis[Symbol.for("import-meta-ponyfill-commonjs")](require, module).url));
29
- // When running from source: src/commands/ → ../../skills/openape/SKILL.md
30
- // When bundled by dnt into build/: esm/commands/ or script/ → ../../skills/openape/SKILL.md
31
- const localPath = node_path_1.default.resolve(base, "..", "..", "skills", SKILL_NAME, "SKILL.md");
32
- return await node_fs_1.default.promises.readFile(localPath, "utf-8");
33
- }
34
- catch {
35
- // import.meta.url may be unavailable in some environments, or file doesn't exist
36
- }
37
- // Fallback: fetch from GitHub
38
- const res = await fetch(GITHUB_RAW_URL, { headers: { "User-Agent": "openape-cli" } });
39
- if (!res.ok) {
40
- throw new Error(`Failed to fetch skill from GitHub: ${res.status} ${res.statusText}`);
41
- }
42
- return res.text();
43
- }
44
- function registerSkillsCommand(program) {
45
- const skills = program
46
- .command("skills")
47
- .description("Manage OpenApe skills for AI agents");
48
- skills
49
- .command("install [platform]")
50
- .description("Install the OpenApe skill to an agent platform (claude, codex, opencode)")
51
- .option("--all", "Detect installed agents and install to all")
52
- .action(async (platform, opts) => {
53
- try {
54
- let targets = [];
55
- if (opts?.all) {
56
- for (const [key, info] of Object.entries(PLATFORMS)) {
57
- const parentDir = node_path_1.default.dirname(info.path);
58
- if (node_fs_1.default.existsSync(parentDir)) {
59
- targets.push({ key, ...info });
60
- }
61
- }
62
- if (targets.length === 0) {
63
- console.log("No supported agents detected. Supported platforms: " + Object.keys(PLATFORMS).join(", "));
64
- return;
65
- }
66
- }
67
- else if (platform) {
68
- const info = PLATFORMS[platform.toLowerCase()];
69
- if (!info) {
70
- console.error(`Unknown platform: ${platform}`);
71
- console.error(`Supported platforms: ${Object.keys(PLATFORMS).join(", ")}`);
72
- process.exitCode = 1;
73
- return;
74
- }
75
- targets = [{ key: platform.toLowerCase(), ...info }];
76
- }
77
- else {
78
- console.error("Specify a platform or use --all.");
79
- console.error(`Example: openape skills install claude`);
80
- process.exitCode = 1;
81
- return;
82
- }
83
- console.log(`Fetching ${SKILL_NAME} skill...`);
84
- const content = await readSkillContent();
85
- for (const target of targets) {
86
- console.log(`Installing to ${target.name} (${target.path})...`);
87
- const destDir = node_path_1.default.join(target.path, SKILL_NAME);
88
- await node_fs_1.default.promises.mkdir(destDir, { recursive: true });
89
- await node_fs_1.default.promises.writeFile(node_path_1.default.join(destDir, "SKILL.md"), content, "utf-8");
90
- console.log(` \x1b[32m✔\x1b[0m ${SKILL_NAME} installed!`);
91
- }
92
- console.log("\nDone!");
93
- }
94
- catch (err) {
95
- console.error(`\x1b[31mFailed to install skill: ${err.message}\x1b[0m`);
96
- process.exitCode = 1;
97
- }
98
- });
99
- skills
100
- .command("show")
101
- .description("Print the raw SKILL.md content")
102
- .action(async () => {
103
- try {
104
- const content = await readSkillContent();
105
- process.stdout.write(content);
106
- }
107
- catch (err) {
108
- console.error(`\x1b[31mFailed: ${err.message}\x1b[0m`);
109
- process.exitCode = 1;
110
- }
111
- });
112
- }
@@ -1,3 +0,0 @@
1
- import { Command } from "commander";
2
- export declare function registerUploadCommand(program: Command): void;
3
- //# sourceMappingURL=upload.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../../src/src/commands/upload.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQpC,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAwD5D"}
@@ -1,61 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.registerUploadCommand = registerUploadCommand;
7
- const utils_js_1 = require("../lib/utils.js");
8
- const moodle_js_1 = require("../lib/moodle.js");
9
- const auth_js_1 = require("../lib/auth.js");
10
- const index_js_1 = require("../index.js");
11
- const node_path_1 = __importDefault(require("node:path"));
12
- const promises_1 = __importDefault(require("node:fs/promises"));
13
- function registerUploadCommand(program) {
14
- const uploadCmd = program.command("upload");
15
- uploadCmd.description("Upload files to Moodle draft area");
16
- uploadCmd
17
- .command("file")
18
- .description("Upload a file to Moodle draft area")
19
- .argument("<file-path>", "Path to the file to upload")
20
- .option("--filename <name>", "Custom filename (default: original filename)")
21
- .option("--output <format>", "Output format: json|csv|table|silent")
22
- .action(async (filePath, options, command) => {
23
- const output = (0, utils_js_1.getOutputFormat)(command);
24
- const apiContext = await (0, auth_js_1.createApiContext)(options, command);
25
- if (!apiContext) {
26
- process.exitCode = 1;
27
- return;
28
- }
29
- const resolvedPath = node_path_1.default.resolve(filePath);
30
- let stats;
31
- try {
32
- stats = await promises_1.default.stat(resolvedPath);
33
- }
34
- catch {
35
- apiContext.log.error(`檔案不存在: ${filePath}`);
36
- process.exitCode = 1;
37
- return;
38
- }
39
- const fileSizeKB = (0, utils_js_1.formatFileSize)(stats.size);
40
- apiContext.log.info(`上傳檔案: ${node_path_1.default.basename(resolvedPath)} (${fileSizeKB} KB)`);
41
- // Upload file
42
- const result = await (0, moodle_js_1.uploadFileApi)(apiContext.session, resolvedPath, {
43
- filename: options.filename,
44
- });
45
- if (!result.success) {
46
- apiContext.log.error(`上傳失敗: ${result.error}`);
47
- process.exitCode = 1;
48
- return;
49
- }
50
- apiContext.log.info(`✓ 上傳成功!Draft ID: ${result.draftId}`);
51
- const uploadResult = {
52
- success: true,
53
- draft_id: result.draftId,
54
- filename: node_path_1.default.basename(resolvedPath),
55
- filesize: stats.size,
56
- filesize_kb: (0, utils_js_1.formatFileSize)(stats.size),
57
- message: "Use this draft ID for assignment submission or forum posts",
58
- };
59
- (0, index_js_1.formatAndOutput)(uploadResult, output, apiContext.log);
60
- });
61
- }
@@ -1,3 +0,0 @@
1
- import { Command } from "commander";
2
- export declare function registerVideosCommand(program: Command): void;
3
- //# sourceMappingURL=videos.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"videos.d.ts","sourceRoot":"","sources":["../../../src/src/commands/videos.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQpC,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAgT5D"}