@learnpack/learnpack 2.1.30 → 2.1.32

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -21,7 +21,7 @@ $ npm install -g @learnpack/learnpack
21
21
  $ learnpack COMMAND
22
22
  running command...
23
23
  $ learnpack (-v|--version|version)
24
- @learnpack/learnpack/2.1.30 darwin-arm64 node-v16.20.0
24
+ @learnpack/learnpack/2.1.32 darwin-arm64 node-v16.20.0
25
25
  $ learnpack --help [COMMAND]
26
26
  USAGE
27
27
  $ learnpack COMMAND
@@ -74,7 +74,7 @@ DESCRIPTION
74
74
  12. If there is a file within the exercises folder but not inside of any particular exercise's folder. (Warning)
75
75
  ```
76
76
 
77
- _See code: [src/commands/audit.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.30/src/commands/audit.ts)_
77
+ _See code: [src/commands/audit.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.32/src/commands/audit.ts)_
78
78
 
79
79
  ## `learnpack clean`
80
80
 
@@ -89,7 +89,7 @@ DESCRIPTION
89
89
  Extra documentation goes here
90
90
  ```
91
91
 
92
- _See code: [src/commands/clean.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.30/src/commands/clean.ts)_
92
+ _See code: [src/commands/clean.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.32/src/commands/clean.ts)_
93
93
 
94
94
  ## `learnpack download [PACKAGE]`
95
95
 
@@ -107,7 +107,7 @@ DESCRIPTION
107
107
  Extra documentation goes here
108
108
  ```
109
109
 
110
- _See code: [src/commands/download.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.30/src/commands/download.ts)_
110
+ _See code: [src/commands/download.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.32/src/commands/download.ts)_
111
111
 
112
112
  ## `learnpack help [COMMAND]`
113
113
 
@@ -138,7 +138,7 @@ OPTIONS
138
138
  -h, --grading show CLI help
139
139
  ```
140
140
 
141
- _See code: [src/commands/init.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.30/src/commands/init.ts)_
141
+ _See code: [src/commands/init.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.32/src/commands/init.ts)_
142
142
 
143
143
  ## `learnpack login [PACKAGE]`
144
144
 
@@ -156,7 +156,7 @@ DESCRIPTION
156
156
  Extra documentation goes here
157
157
  ```
158
158
 
159
- _See code: [src/commands/login.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.30/src/commands/login.ts)_
159
+ _See code: [src/commands/login.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.32/src/commands/login.ts)_
160
160
 
161
161
  ## `learnpack logout [PACKAGE]`
162
162
 
@@ -174,7 +174,7 @@ DESCRIPTION
174
174
  Extra documentation goes here
175
175
  ```
176
176
 
177
- _See code: [src/commands/logout.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.30/src/commands/logout.ts)_
177
+ _See code: [src/commands/logout.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.32/src/commands/logout.ts)_
178
178
 
179
179
  ## `learnpack plugins`
180
180
 
@@ -309,7 +309,7 @@ DESCRIPTION
309
309
  Extra documentation goes here
310
310
  ```
311
311
 
312
- _See code: [src/commands/publish.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.30/src/commands/publish.ts)_
312
+ _See code: [src/commands/publish.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.32/src/commands/publish.ts)_
313
313
 
314
314
  ## `learnpack start`
315
315
 
@@ -330,7 +330,7 @@ OPTIONS
330
330
  -w, --watch Watch for file changes
331
331
  ```
332
332
 
333
- _See code: [src/commands/start.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.30/src/commands/start.ts)_
333
+ _See code: [src/commands/start.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.32/src/commands/start.ts)_
334
334
 
335
335
  ## `learnpack test [EXERCISESLUG]`
336
336
 
@@ -344,5 +344,7 @@ ARGUMENTS
344
344
  EXERCISESLUG The name of the exercise to test
345
345
  ```
346
346
 
347
- _See code: [src/commands/test.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.30/src/commands/test.ts)_
347
+ _See code: [src/commands/test.ts](https://github.com/learnpack/learnpack-cli/blob/v2.1.32/src/commands/test.ts)_
348
348
  <!-- commandsstop -->
349
+
350
+ > > > > > > > 0cb3e56d84c197f9d008836bb573eade212b7e57
@@ -5,6 +5,7 @@ const command_1 = require("@oclif/command");
5
5
  const SessionCommand_1 = require("../utils/SessionCommand");
6
6
  const console_1 = require("../utils/console");
7
7
  const socket_1 = require("../managers/socket");
8
+ const telemetry_1 = require("../managers/telemetry");
8
9
  const fileQueue_1 = require("../utils/fileQueue");
9
10
  const file_1 = require("../managers/file");
10
11
  const misc_1 = require("../utils/misc");
@@ -92,8 +93,9 @@ class StartCommand extends SessionCommand_1.default {
92
93
  exercise,
93
94
  });
94
95
  });
95
- socket_1.default.on("generate", async (data) => {
96
- console.log("Receving generate event, this shouldn't be happening", data);
96
+ socket_1.default.on("telemetry", (data) => {
97
+ console_1.default.info("Registering telemetry event: ", data);
98
+ telemetry_1.default.registerEvent(data);
97
99
  });
98
100
  socket_1.default.on("test", async (data) => {
99
101
  var _a, _b;
@@ -135,7 +137,10 @@ class StartCommand extends SessionCommand_1.default {
135
137
  setTimeout(() => dispatcher.enqueue(dispatcher.events.RUNNING), 1000);
136
138
  // start watching for file changes
137
139
  if (StartCommand.flags.watch)
138
- this.configManager.watchIndex(_exercises => socket_1.default.reload(null, _exercises));
140
+ this.configManager.watchIndex(_filename => {
141
+ // Instead of reloading with socket.reload(), I just notify the frontend for the file change
142
+ socket_1.default.emit("file_change", "ready", _filename);
143
+ });
139
144
  }
140
145
  }
141
146
  }
@@ -135,9 +135,9 @@ exports.default = async ({ grading, mode, disableGrading, version, }) => {
135
135
  configObj.config.editor.version = version;
136
136
  else if (configObj.config && configObj.config.editor.version === null) {
137
137
  console_1.default.debug("Config version not found, downloading default.");
138
- const resp = await fetch("https://raw.githubusercontent.com/learnpack/coding-ide/learnpack/package.json");
138
+ const resp = await fetch("https://raw.githubusercontent.com/learnpack/ide/master/package.json");
139
139
  const packageJSON = await resp.json();
140
- configObj.config.editor.version = packageJSON.version || "1.0.73";
140
+ configObj.config.editor.version = packageJSON.version || "3.0.20";
141
141
  }
142
142
  if (configObj.config) {
143
143
  configObj.config.dirPath = "./" + confPath.base;
@@ -284,11 +284,10 @@ exports.default = async ({ grading, mode, disableGrading, version, }) => {
284
284
  throw errors_1.ValidationError("No exercises directory to watch: " + configObj.config.exercisesPath);
285
285
  this.buildIndex();
286
286
  watcher_1.default(((_a = configObj === null || configObj === void 0 ? void 0 : configObj.config) === null || _a === void 0 ? void 0 : _a.exercisesPath) || "", onChange)
287
- .then(( /* eventname, filename */) => {
287
+ .then(() => {
288
288
  console_1.default.debug("Changes detected on your exercises");
289
289
  this.buildIndex();
290
- if (onChange)
291
- onChange();
290
+ // if (onChange) onChange(filename);
292
291
  })
293
292
  .catch(error => {
294
293
  throw error;
@@ -30,9 +30,14 @@ exports.decompress = (sourcePath, destinationPath) => new Promise((resolve, reje
30
30
  exports.downloadEditor = async (version, destination) => {
31
31
  // https://raw.githubusercontent.com/learnpack/coding-ide/master/dist/app.tar.gz
32
32
  // if(versions[version] === undefined) throw new Error(`Invalid editor version ${version}`)
33
- if (!version)
34
- throw errors_1.InternalError("Missing editor version on learn.json");
35
- const versionNumber = parseInt(version === null || version === void 0 ? void 0 : version.split(".")[0]);
33
+ if (!version) {
34
+ const res = await fetch("https://raw.githubusercontent.com/learnpack/ide/master/package.json");
35
+ const json = await res.json();
36
+ version = json.version;
37
+ if (!version)
38
+ throw errors_1.InternalError(`Coding Editor version was not found on learnpack repository, check the config.editor.version property on learn.json`);
39
+ }
40
+ const versionNumber = parseInt(version.split(".")[0]);
36
41
  let url = `https://github.com/learnpack/coding-ide/blob/${version}/dist`;
37
42
  if (versionNumber > 2)
38
43
  url = `https://github.com/learnpack/ide/blob/master/bin/learnpack-${version}.tar.gz`;
@@ -46,25 +46,32 @@ async function default_1(app, configObject, configManager) {
46
46
  const payload = await session_1.default.loginWeb(email, password);
47
47
  res.json(payload);
48
48
  }));
49
- app.post("/set-openai-token", jsonBodyParser, withHandler(async (req, res) => {
49
+ app.post("/set-rigobot-token", jsonBodyParser, withHandler(async (req, res) => {
50
50
  const token = req.body.token;
51
- const tokenSaved = await session_1.default.setOpenAIToken(token);
52
- if (tokenSaved) {
53
- res.json({ status: "ok" });
54
- }
55
- else {
56
- res.status(400);
51
+ // Ensure token is provided in the request body
52
+ if (!token) {
53
+ return res.status(400).json({ error: "Token is required" });
54
+ }
55
+ try {
56
+ const tokenSaved = await session_1.default.setRigoToken(token);
57
+ // Check if the token was saved successfully
58
+ if (tokenSaved) {
59
+ res.json({ status: "ok" });
60
+ }
61
+ else {
62
+ res.status(500).json({ error: "Failed to save the token" });
63
+ }
64
+ }
65
+ catch (_a) {
66
+ // Handle any unexpected errors during the process
67
+ res.status(500).json({ error: "Internal server error" });
57
68
  }
58
69
  }));
59
70
  app.get("/check/rigo/status", withHandler(async (_, res) => {
60
71
  const payload = await session_1.default.getPayload();
61
- const openaiToken = await session_1.default.getOpenAIToken();
62
72
  if (payload && payload.rigobot && payload.rigobot.key) {
63
73
  res.json({ rigoToken: payload.rigobot.key });
64
74
  }
65
- else if (openaiToken) {
66
- res.json({ openaiToken });
67
- }
68
75
  else {
69
76
  res
70
77
  .status(400)
@@ -25,21 +25,11 @@ const Session = {
25
25
  }
26
26
  return true;
27
27
  },
28
- getOpenAIToken: async function () {
28
+ setRigoToken: async function (token) {
29
29
  await this.initialize();
30
- let token = null;
31
- try {
32
- token = await storage.getItem("openai-token");
33
- }
34
- catch (_a) {
35
- console_1.default.debug("Error retriving openai token");
36
- }
37
- return token;
38
- },
39
- setOpenAIToken: async function (token) {
40
- await this.initialize();
41
- await storage.setItem("openai-token", token);
42
- console_1.default.debug("OpenAI token successfuly set");
30
+ const payload = await storage.getItem("bc-payload");
31
+ await storage.setItem("bc-payload", Object.assign(Object.assign({}, payload), { rigobot: { key: token } }));
32
+ console_1.default.debug("Rigobot token successfuly set");
43
33
  return true;
44
34
  },
45
35
  setPayload: async function (value) {
@@ -0,0 +1,26 @@
1
+ declare type TEventType = "form_submit" | "build" | "test" | "visualize_step" | "code_start";
2
+ declare type TFile = {
3
+ name: string;
4
+ content: string;
5
+ };
6
+ declare type TStep = {
7
+ name: string;
8
+ position: number;
9
+ files: TFile[];
10
+ };
11
+ declare type TTelemetryEvent = {
12
+ type: TEventType;
13
+ data: any;
14
+ timestamp: number;
15
+ step: TStep;
16
+ };
17
+ interface ITelemetryManager {
18
+ current: Array<TTelemetryEvent> | null;
19
+ start: () => void;
20
+ submit: () => void;
21
+ registerEvent: (event: Omit<TTelemetryEvent, "timestamp">) => void;
22
+ save: () => void;
23
+ onSaveCallback?: (current: Array<TTelemetryEvent>) => void;
24
+ }
25
+ declare const TelemetryManager: ITelemetryManager;
26
+ export default TelemetryManager;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const TelemetryManager = {
4
+ current: null,
5
+ start: function () {
6
+ if (!this.current) {
7
+ this.current = [];
8
+ }
9
+ },
10
+ submit: function () {
11
+ console.log("submit");
12
+ },
13
+ registerEvent: function (event) {
14
+ var _a;
15
+ this.start();
16
+ const timestamp = Date.now();
17
+ const _event = Object.assign(Object.assign({}, event), { timestamp });
18
+ (_a = this.current) === null || _a === void 0 ? void 0 : _a.push(_event);
19
+ },
20
+ save: function () {
21
+ if (this.onSaveCallback && this.current) {
22
+ this.onSaveCallback(this.current);
23
+ }
24
+ },
25
+ };
26
+ exports.default = TelemetryManager;
@@ -1,2 +1,2 @@
1
- export declare type TAction = "test" | "log" | "reload" | "ready" | "clean" | "ask" | "generation";
1
+ export declare type TAction = "test" | "log" | "reload" | "ready" | "clean" | "ask" | "file_change";
2
2
  export declare type ICallback = (...agrs: any[]) => any;
@@ -12,8 +12,7 @@ export interface ISession {
12
12
  config: IConfig | null;
13
13
  currentCohort: null;
14
14
  initialize: () => Promise<boolean>;
15
- getOpenAIToken: () => Promise<string | null>;
16
- setOpenAIToken: (token: string) => Promise<boolean>;
15
+ setRigoToken: (token: string) => Promise<boolean>;
17
16
  setPayload: (value: IPayload) => Promise<boolean>;
18
17
  getPayload: () => Promise<any>;
19
18
  isActive: () => boolean;
@@ -8,7 +8,5 @@ declare const _default: {
8
8
  lang?: string | undefined;
9
9
  slug?: string | undefined;
10
10
  }) => Promise<any>;
11
- getRigoFeedback: (readme: string, currentCode: string) => Promise<any>;
12
- getOpenAIToken: () => Promise<any>;
13
11
  };
14
12
  export default _default;
package/lib/utils/api.js CHANGED
@@ -66,8 +66,14 @@ const login = async (identification, password) => {
66
66
  method: "post",
67
67
  });
68
68
  cli_ux_1.default.action.stop("ready");
69
- const payload = await loginRigo(data.token);
70
- return Object.assign(Object.assign({}, data), { rigobot: payload });
69
+ let rigoPayload = null;
70
+ try {
71
+ rigoPayload = await loginRigo(data.token);
72
+ }
73
+ catch (_a) {
74
+ return Object.assign(Object.assign({}, data), { rigobot: null });
75
+ }
76
+ return Object.assign(Object.assign({}, data), { rigobot: rigoPayload });
71
77
  }
72
78
  catch (error) {
73
79
  cli_ux_1.default.action.stop("error");
@@ -76,31 +82,17 @@ const login = async (identification, password) => {
76
82
  }
77
83
  };
78
84
  const loginRigo = async (token) => {
79
- const rigoUrl = `${RIGOBOT_HOST}/v1/auth/me/token?breathecode_token=${token}`;
80
- const rigoResp = await _fetch(rigoUrl);
81
- const rigobotJson = await rigoResp.json();
82
- return rigobotJson;
83
- };
84
- const getOpenAIToken = async () => {
85
- const token = await storage.getItem("openai-token");
86
- return token;
87
- };
88
- const getRigoFeedback = async (readme, currentCode) => {
89
- const payload = {
90
- current_code: Buffer.from(currentCode).toString("base64"),
91
- tutorial: Buffer.from(readme).toString("base64"),
92
- };
93
- const session = await storage.getItem("bc-payload");
94
- const response = await _fetch(`${RIGOBOT_HOST}/v1/conversation/feedback/`, {
95
- method: "POST",
96
- headers: {
97
- "Content-Type": "application/json",
98
- Authorization: `Token ${session.rigobot.key}`,
99
- },
100
- body: JSON.stringify(payload),
101
- });
102
- const responseData = await response.json();
103
- return responseData.feedback;
85
+ try {
86
+ const rigoUrl = `${RIGOBOT_HOST}/v1/auth/me/token?breathecode_token=${token}`;
87
+ const rigoResp = await _fetch(rigoUrl);
88
+ const rigobotJson = await rigoResp.json();
89
+ return rigobotJson;
90
+ }
91
+ catch (error) {
92
+ // Handle the error as needed, for example log it or return a custom error message
93
+ console_1.default.error("Error logging in to Rigo, did you already accepted Rigobot?:", error);
94
+ throw new Error("Failed to log in to Rigo");
95
+ }
104
96
  };
105
97
  const publish = async (config) => {
106
98
  const keys = [
@@ -211,6 +203,4 @@ exports.default = {
211
203
  getPackage,
212
204
  getLangs,
213
205
  getAllPackages,
214
- getRigoFeedback,
215
- getOpenAIToken,
216
206
  };
@@ -1,2 +1,2 @@
1
- declare const _default: (path: string, reloadSocket: () => void) => Promise<unknown>;
1
+ declare const _default: (path: string, reloadSocket: (filename: string) => void) => Promise<unknown>;
2
2
  export default _default;
@@ -7,12 +7,14 @@ exports.default = (path, reloadSocket) => new Promise((resolve /* , reject */) =
7
7
  console_1.default.debug("PATH:", path);
8
8
  const watcher = chokidar.watch(path, {
9
9
  // TODO: This watcher is not ready yet
10
- ignored: /^(?=.*(\.\w+)$)(?!.*\.md$).*$/gm,
10
+ // ignored: /^(?=.*(\.\w+)$)(?!.*\.md$).*$/gm,
11
+ ignored: /\.pyc$/,
11
12
  ignoreInitial: true,
12
13
  });
13
14
  const onChange = (eventname, _filename) => {
14
- resolve(eventname /* , filename */);
15
- reloadSocket();
15
+ // Console.info(`Event ${eventname} detected. in file: ${_filename}`)
16
+ resolve(_filename);
17
+ reloadSocket(_filename);
16
18
  };
17
19
  watcher.on("all", debounce(onChange, 500, true));
18
20
  // watcher.on('all', onChange)
@@ -1 +1 @@
1
- {"version":"2.1.30","commands":{"audit":{"id":"audit","description":"learnpack audit is the command in charge of creating an auditory of the repository\n...\nlearnpack audit checks for the following information in a repository:\n 1. The configuration object has slug, repository and description. (Error)\n 2. The command learnpack clean has been run. (Error)\n 3. If a markdown or test file doesn't have any content. (Error)\n 4. The links are accessing to valid servers. (Error)\n 5. The relative images are working (If they have the shortest path to the image or if the images exists in the assets). (Error)\n 6. The external images are working (If they are pointing to a valid server). (Error)\n 7. The exercises directory names are valid. (Error)\n 8. If an exercise doesn't have a README file. (Error)\n 9. The exercises array (Of the config file) has content. (Error)\n 10. The exercses have the same translations. (Warning)\n 11. The .gitignore file exists. (Warning)\n 12. If there is a file within the exercises folder but not inside of any particular exercise's folder. (Warning)\n","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[]},"clean":{"id":"clean","description":"Clean the configuration object\n ...\n Extra documentation goes here\n ","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[]},"download":{"id":"download","description":"Describe the command here\n...\nExtra documentation goes here\n","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"package","description":"The unique string that identifies this package on learnpack","required":false,"hidden":false}]},"init":{"id":"init","description":"Create a new learning package: Book, Tutorial or Exercise","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"grading":{"name":"grading","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"login":{"id":"login","description":"Describe the command here\n ...\n Extra documentation goes here\n ","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"package","description":"The unique string that identifies this package on learnpack","required":false,"hidden":false}]},"logout":{"id":"logout","description":"Describe the command here\n ...\n Extra documentation goes here\n ","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"package","description":"The unique string that identifies this package on learnpack","required":false,"hidden":false}]},"publish":{"id":"publish","description":"Describe the command here\n ...\n Extra documentation goes here\n ","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"package","description":"The unique string that identifies this package on learnpack","required":false,"hidden":false}]},"start":{"id":"start","description":"Runs a small server with all the exercise instructions","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"port":{"name":"port","type":"option","char":"p","description":"server port"},"host":{"name":"host","type":"option","char":"h","description":"server host"},"disableGrading":{"name":"disableGrading","type":"boolean","char":"D","description":"disble grading functionality","allowNo":false},"watch":{"name":"watch","type":"boolean","char":"w","description":"Watch for file changes","allowNo":false},"editor":{"name":"editor","type":"option","char":"e","description":"[standalone, gitpod]","options":["standalone","gitpod"]},"version":{"name":"version","type":"option","char":"v","description":"E.g: 1.0.1"},"grading":{"name":"grading","type":"option","char":"g","description":"[isolated, incremental]","options":["isolated","incremental"]},"debug":{"name":"debug","type":"boolean","char":"d","description":"debugger mode for more verbage","allowNo":false}},"args":[]},"test":{"id":"test","description":"Test exercises","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"exerciseSlug","description":"The name of the exercise to test","required":false,"hidden":false}]}}}
1
+ {"version":"2.1.32","commands":{"audit":{"id":"audit","description":"learnpack audit is the command in charge of creating an auditory of the repository\n...\nlearnpack audit checks for the following information in a repository:\n 1. The configuration object has slug, repository and description. (Error)\n 2. The command learnpack clean has been run. (Error)\n 3. If a markdown or test file doesn't have any content. (Error)\n 4. The links are accessing to valid servers. (Error)\n 5. The relative images are working (If they have the shortest path to the image or if the images exists in the assets). (Error)\n 6. The external images are working (If they are pointing to a valid server). (Error)\n 7. The exercises directory names are valid. (Error)\n 8. If an exercise doesn't have a README file. (Error)\n 9. The exercises array (Of the config file) has content. (Error)\n 10. The exercses have the same translations. (Warning)\n 11. The .gitignore file exists. (Warning)\n 12. If there is a file within the exercises folder but not inside of any particular exercise's folder. (Warning)\n","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[]},"clean":{"id":"clean","description":"Clean the configuration object\n ...\n Extra documentation goes here\n ","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[]},"download":{"id":"download","description":"Describe the command here\n...\nExtra documentation goes here\n","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"package","description":"The unique string that identifies this package on learnpack","required":false,"hidden":false}]},"init":{"id":"init","description":"Create a new learning package: Book, Tutorial or Exercise","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"grading":{"name":"grading","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"login":{"id":"login","description":"Describe the command here\n ...\n Extra documentation goes here\n ","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"package","description":"The unique string that identifies this package on learnpack","required":false,"hidden":false}]},"logout":{"id":"logout","description":"Describe the command here\n ...\n Extra documentation goes here\n ","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"package","description":"The unique string that identifies this package on learnpack","required":false,"hidden":false}]},"publish":{"id":"publish","description":"Describe the command here\n ...\n Extra documentation goes here\n ","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"package","description":"The unique string that identifies this package on learnpack","required":false,"hidden":false}]},"start":{"id":"start","description":"Runs a small server with all the exercise instructions","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"port":{"name":"port","type":"option","char":"p","description":"server port"},"host":{"name":"host","type":"option","char":"h","description":"server host"},"disableGrading":{"name":"disableGrading","type":"boolean","char":"D","description":"disble grading functionality","allowNo":false},"watch":{"name":"watch","type":"boolean","char":"w","description":"Watch for file changes","allowNo":false},"editor":{"name":"editor","type":"option","char":"e","description":"[standalone, gitpod]","options":["standalone","gitpod"]},"version":{"name":"version","type":"option","char":"v","description":"E.g: 1.0.1"},"grading":{"name":"grading","type":"option","char":"g","description":"[isolated, incremental]","options":["isolated","incremental"]},"debug":{"name":"debug","type":"boolean","char":"d","description":"debugger mode for more verbage","allowNo":false}},"args":[]},"test":{"id":"test","description":"Test exercises","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"exerciseSlug","description":"The name of the exercise to test","required":false,"hidden":false}]}}}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@learnpack/learnpack",
3
3
  "description": "Create, sell or download and take learning amazing learning packages",
4
- "version": "2.1.30",
4
+ "version": "2.1.32",
5
5
  "author": "Alejandro Sanchez @alesanchezr",
6
6
  "bin": {
7
7
  "learnpack": "bin/run"
@@ -11,7 +11,6 @@ class DownloadCommand extends Command {
11
11
  ...
12
12
  Extra documentation goes here
13
13
  `
14
-
15
14
  static flags: any = {
16
15
  // name: flags.string({char: 'n', description: 'name to print'}),
17
16
  }
@@ -4,6 +4,8 @@ import { flags } from "@oclif/command"
4
4
  import SessionCommand from "../utils/SessionCommand"
5
5
  import Console from "../utils/console"
6
6
  import socket from "../managers/socket"
7
+ import TelemetryManager from "../managers/telemetry"
8
+
7
9
  import queue from "../utils/fileQueue"
8
10
  import {
9
11
  decompress,
@@ -185,11 +187,9 @@ export default class StartCommand extends SessionCommand {
185
187
  })
186
188
  })
187
189
 
188
- socket.on("generate", async (data: IExerciseData) => {
189
- console.log(
190
- "Receving generate event, this shouldn't be happening",
191
- data
192
- )
190
+ socket.on("telemetry", (data: any) => {
191
+ Console.info("Registering telemetry event: ", data)
192
+ TelemetryManager.registerEvent(data)
193
193
  })
194
194
 
195
195
  socket.on("test", async (data: IExerciseData) => {
@@ -248,11 +248,11 @@ export default class StartCommand extends SessionCommand {
248
248
  setTimeout(() => dispatcher.enqueue(dispatcher.events.RUNNING), 1000)
249
249
 
250
250
  // start watching for file changes
251
-
252
251
  if (StartCommand.flags.watch)
253
- this.configManager.watchIndex(_exercises =>
254
- socket.reload(null, _exercises)
255
- )
252
+ this.configManager.watchIndex(_filename => {
253
+ // Instead of reloading with socket.reload(), I just notify the frontend for the file change
254
+ socket.emit("file_change", "ready", _filename)
255
+ })
256
256
  }
257
257
  }
258
258
  }
@@ -194,10 +194,10 @@ configObj.config.editor.version = version
194
194
  else if (configObj.config && configObj.config.editor.version === null) {
195
195
  Console.debug("Config version not found, downloading default.")
196
196
  const resp = await fetch(
197
- "https://raw.githubusercontent.com/learnpack/coding-ide/learnpack/package.json"
197
+ "https://raw.githubusercontent.com/learnpack/ide/master/package.json"
198
198
  )
199
199
  const packageJSON = await resp.json()
200
- configObj.config.editor.version = packageJSON.version || "1.0.73"
200
+ configObj.config.editor.version = packageJSON.version || "3.0.20"
201
201
  }
202
202
 
203
203
  if (configObj.config) {
@@ -386,24 +386,25 @@ fs.mkdirSync(confPath.base)
386
386
  [exercise(configObj?.config?.exercisesPath || "", 0, configObj)]
387
387
  this.save()
388
388
  },
389
- watchIndex: function (onChange: () => void) {
389
+ watchIndex: function (onChange: (filename: string) => void) {
390
390
  if (configObj.config && !configObj.config.exercisesPath)
391
391
  throw ValidationError(
392
392
  "No exercises directory to watch: " + configObj.config.exercisesPath
393
393
  )
394
394
 
395
395
  this.buildIndex()
396
+
396
397
  watch(configObj?.config?.exercisesPath || "", onChange)
397
- .then((/* eventname, filename */) => {
398
+ .then(() => {
398
399
  Console.debug("Changes detected on your exercises")
399
400
  this.buildIndex()
400
- if (onChange)
401
- onChange()
401
+ // if (onChange) onChange(filename);
402
402
  })
403
403
  .catch(error => {
404
404
  throw error
405
405
  })
406
406
  },
407
+
407
408
  save: () => {
408
409
  // Console.debug("Saving configuration with: ", configObj)
409
410
 
@@ -37,9 +37,20 @@ export const downloadEditor = async (
37
37
  // https://raw.githubusercontent.com/learnpack/coding-ide/master/dist/app.tar.gz
38
38
  // if(versions[version] === undefined) throw new Error(`Invalid editor version ${version}`)
39
39
 
40
- if (!version)
41
- throw InternalError("Missing editor version on learn.json")
42
- const versionNumber = parseInt(version?.split(".")[0])
40
+ if (!version) {
41
+ const res = await fetch(
42
+ "https://raw.githubusercontent.com/learnpack/ide/master/package.json"
43
+ )
44
+ const json = await res.json()
45
+ version = json.version
46
+
47
+ if (!version)
48
+ throw InternalError(
49
+ `Coding Editor version was not found on learnpack repository, check the config.editor.version property on learn.json`
50
+ )
51
+ }
52
+
53
+ const versionNumber = parseInt(version.split(".")[0])
43
54
 
44
55
  let url = `https://github.com/learnpack/coding-ide/blob/${version}/dist`
45
56
 
@@ -69,30 +69,36 @@ export default async function (
69
69
  })
70
70
  )
71
71
  app.post(
72
- "/set-openai-token",
72
+ "/set-rigobot-token",
73
73
  jsonBodyParser,
74
74
  withHandler(async (req: express.Request, res: express.Response) => {
75
75
  const token = req.body.token
76
+ // Ensure token is provided in the request body
77
+ if (!token) {
78
+ return res.status(400).json({ error: "Token is required" })
79
+ }
76
80
 
77
- const tokenSaved = await SessionManager.setOpenAIToken(token)
78
- if (tokenSaved) {
79
- res.json({ status: "ok" })
80
- } else {
81
- res.status(400)
81
+ try {
82
+ const tokenSaved = await SessionManager.setRigoToken(token)
83
+ // Check if the token was saved successfully
84
+ if (tokenSaved) {
85
+ res.json({ status: "ok" })
86
+ } else {
87
+ res.status(500).json({ error: "Failed to save the token" })
88
+ }
89
+ } catch {
90
+ // Handle any unexpected errors during the process
91
+ res.status(500).json({ error: "Internal server error" })
82
92
  }
83
93
  })
84
94
  )
85
-
86
95
  app.get(
87
96
  "/check/rigo/status",
88
97
  withHandler(async (_: express.Request, res: express.Response) => {
89
98
  const payload = await SessionManager.getPayload()
90
- const openaiToken = await SessionManager.getOpenAIToken()
91
99
 
92
100
  if (payload && payload.rigobot && payload.rigobot.key) {
93
101
  res.json({ rigoToken: payload.rigobot.key })
94
- } else if (openaiToken) {
95
- res.json({ openaiToken })
96
102
  } else {
97
103
  res
98
104
  .status(400)
@@ -32,21 +32,15 @@ const Session: ISession = {
32
32
 
33
33
  return true
34
34
  },
35
- getOpenAIToken: async function () {
36
- await this.initialize()
37
- let token = null
38
- try {
39
- token = await storage.getItem("openai-token")
40
- } catch {
41
- Console.debug("Error retriving openai token")
42
- }
43
35
 
44
- return token
45
- },
46
- setOpenAIToken: async function (token: string) {
36
+ setRigoToken: async function (token: string) {
47
37
  await this.initialize()
48
- await storage.setItem("openai-token", token)
49
- Console.debug("OpenAI token successfuly set")
38
+ const payload = await storage.getItem("bc-payload")
39
+ await storage.setItem("bc-payload", {
40
+ ...payload,
41
+ rigobot: { key: token },
42
+ })
43
+ Console.debug("Rigobot token successfuly set")
50
44
  return true
51
45
  },
52
46
  setPayload: async function (value: IPayload) {
@@ -0,0 +1,58 @@
1
+ type TEventType =
2
+ | "form_submit"
3
+ | "build"
4
+ | "test"
5
+ | "visualize_step"
6
+ | "code_start";
7
+
8
+ type TFile = {
9
+ name: string;
10
+ content: string;
11
+ };
12
+
13
+ type TStep = {
14
+ name: string;
15
+ position: number;
16
+ files: TFile[];
17
+ };
18
+
19
+ type TTelemetryEvent = {
20
+ type: TEventType;
21
+ data: any;
22
+ timestamp: number;
23
+ step: TStep;
24
+ };
25
+
26
+ interface ITelemetryManager {
27
+ current: Array<TTelemetryEvent> | null;
28
+ start: () => void;
29
+ submit: () => void;
30
+ registerEvent: (event: Omit<TTelemetryEvent, "timestamp">) => void;
31
+ save: () => void;
32
+ onSaveCallback?: (current: Array<TTelemetryEvent>) => void;
33
+ }
34
+
35
+ const TelemetryManager: ITelemetryManager = {
36
+ current: null,
37
+ start: function () {
38
+ if (!this.current) {
39
+ this.current = []
40
+ }
41
+ },
42
+ submit: function () {
43
+ console.log("submit")
44
+ },
45
+ registerEvent: function (event) {
46
+ this.start()
47
+ const timestamp = Date.now()
48
+ const _event = { ...event, timestamp }
49
+ this.current?.push(_event)
50
+ },
51
+ save: function () {
52
+ if (this.onSaveCallback && this.current) {
53
+ this.onSaveCallback(this.current)
54
+ }
55
+ },
56
+ }
57
+
58
+ export default TelemetryManager
@@ -5,6 +5,6 @@ export type TAction =
5
5
  | "ready"
6
6
  | "clean"
7
7
  | "ask"
8
- | "generation";
8
+ | "file_change";
9
9
 
10
10
  export type ICallback = (...agrs: any[]) => any;
@@ -15,8 +15,7 @@ export interface ISession {
15
15
  config: IConfig | null;
16
16
  currentCohort: null;
17
17
  initialize: () => Promise<boolean>;
18
- getOpenAIToken: () => Promise<string | null>;
19
- setOpenAIToken: (token: string) => Promise<boolean>;
18
+ setRigoToken: (token: string) => Promise<boolean>;
20
19
  setPayload: (value: IPayload) => Promise<boolean>;
21
20
  getPayload: () => Promise<any>;
22
21
  isActive: () => boolean;
package/src/utils/api.ts CHANGED
@@ -78,9 +78,14 @@ const login = async (identification: string, password: string) => {
78
78
  method: "post",
79
79
  })
80
80
  cli.action.stop("ready")
81
- const payload = await loginRigo(data.token)
82
-
83
- return { ...data, rigobot: payload }
81
+ let rigoPayload = null
82
+ try {
83
+ rigoPayload = await loginRigo(data.token)
84
+ } catch {
85
+ return { ...data, rigobot: null }
86
+ }
87
+
88
+ return { ...data, rigobot: rigoPayload }
84
89
  } catch (error) {
85
90
  cli.action.stop("error")
86
91
  Console.error((error as TypeError).message)
@@ -89,36 +94,19 @@ const login = async (identification: string, password: string) => {
89
94
  }
90
95
 
91
96
  const loginRigo = async (token: string) => {
92
- const rigoUrl = `${RIGOBOT_HOST}/v1/auth/me/token?breathecode_token=${token}`
93
- const rigoResp = await _fetch(rigoUrl)
94
- const rigobotJson = await rigoResp.json()
95
- return rigobotJson
96
- }
97
-
98
- const getOpenAIToken = async () => {
99
- const token = await storage.getItem("openai-token")
100
- return token
101
- }
102
-
103
- const getRigoFeedback = async (readme: string, currentCode: string) => {
104
- const payload = {
105
- current_code: Buffer.from(currentCode).toString("base64"), // Encode currentCode as base64
106
- tutorial: Buffer.from(readme).toString("base64"), // Encode readme as base64
97
+ try {
98
+ const rigoUrl = `${RIGOBOT_HOST}/v1/auth/me/token?breathecode_token=${token}`
99
+ const rigoResp = await _fetch(rigoUrl)
100
+ const rigobotJson = await rigoResp.json()
101
+ return rigobotJson
102
+ } catch (error) {
103
+ // Handle the error as needed, for example log it or return a custom error message
104
+ Console.error(
105
+ "Error logging in to Rigo, did you already accepted Rigobot?:",
106
+ error
107
+ )
108
+ throw new Error("Failed to log in to Rigo")
107
109
  }
108
-
109
- const session = await storage.getItem("bc-payload")
110
-
111
- const response = await _fetch(`${RIGOBOT_HOST}/v1/conversation/feedback/`, {
112
- method: "POST",
113
- headers: {
114
- "Content-Type": "application/json",
115
- Authorization: `Token ${session.rigobot.key}`,
116
- },
117
- body: JSON.stringify(payload),
118
- })
119
-
120
- const responseData = await response.json()
121
- return responseData.feedback
122
110
  }
123
111
 
124
112
  const publish = async (config: any) => {
@@ -240,6 +228,4 @@ export default {
240
228
  getPackage,
241
229
  getLangs,
242
230
  getAllPackages,
243
- getRigoFeedback,
244
- getOpenAIToken,
245
231
  }
@@ -3,17 +3,19 @@ import Console from "./console"
3
3
  import * as debounce from "debounce"
4
4
  import { IConfigManager } from "../models/config-manager"
5
5
 
6
- export default (path: string, reloadSocket: () => void) =>
6
+ export default (path: string, reloadSocket: (filename: string) => void) =>
7
7
  new Promise((resolve /* , reject */) => {
8
8
  Console.debug("PATH:", path)
9
9
  const watcher = chokidar.watch(path, {
10
10
  // TODO: This watcher is not ready yet
11
- ignored: /^(?=.*(\.\w+)$)(?!.*\.md$).*$/gm,
11
+ // ignored: /^(?=.*(\.\w+)$)(?!.*\.md$).*$/gm,
12
+ ignored: /\.pyc$/,
12
13
  ignoreInitial: true,
13
14
  })
14
15
  const onChange = (eventname: string, _filename: string) => {
15
- resolve(eventname /* , filename */)
16
- reloadSocket()
16
+ // Console.info(`Event ${eventname} detected. in file: ${_filename}`)
17
+ resolve(_filename)
18
+ reloadSocket(_filename)
17
19
  }
18
20
 
19
21
  watcher.on("all", debounce(onChange, 500, true))