@edryslabs/edrys-dev 0.1.0 → 0.1.2

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/dist/chat.js CHANGED
@@ -97,9 +97,6 @@ export class Chat extends EventEmitter {
97
97
  // e.g. a form that was closed in the meantime
98
98
  res.sendStatus(409);
99
99
  });
100
- for (const [file, source] of Object.entries(PANEL_FILES)) {
101
- app.get('/edrys-dev/' + file, (req, res) => res.sendFile(source()));
102
- }
103
100
  }
104
101
  add(entry) {
105
102
  this.entries.push(entry);
@@ -130,5 +127,19 @@ const PANEL_FILES = {
130
127
  'marked.js': () => path.join(path.dirname(require.resolve('marked/package.json')), 'lib', 'marked.umd.js'),
131
128
  'purify.js': () => require.resolve('dompurify/purify.min.js'),
132
129
  };
133
- /** The script tag that brings the panel into the edrys-Lite page. */
134
- export const PANEL_SCRIPT = '<script src="/edrys-dev/panel.js" defer></script>';
130
+ /** Serves panel.js and the libraries its chat uses. */
131
+ export function panelFiles(app) {
132
+ for (const [file, source] of Object.entries(PANEL_FILES)) {
133
+ // dotfiles: sendFile checks the whole absolute path, and installs often
134
+ // live under one (~/.nvm, ~/.npm/_npx); the path is ours, not the request's
135
+ app.get('/edrys-dev/' + file, (req, res) => res.sendFile(source(), { dotfiles: 'allow' }));
136
+ }
137
+ }
138
+ /**
139
+ * The script tag that brings panel.js into the edrys-Lite page: it reloads
140
+ * student and station tabs when a local module changed, and with `chat` (an
141
+ * agent is connected) shows the chat in the class tab.
142
+ */
143
+ export function panelScript(chat) {
144
+ return `<script src="/edrys-dev/panel.js" defer${chat ? ' data-chat' : ''}></script>`;
145
+ }
package/dist/index.js CHANGED
@@ -60,6 +60,7 @@ const server = await startDevServer({
60
60
  host: values.host,
61
61
  local: values.local,
62
62
  modules,
63
+ agent: values.mcp,
63
64
  });
64
65
  server.bus.on('report', (report) => {
65
66
  switch (report.type) {
package/dist/server.js CHANGED
@@ -9,7 +9,7 @@ import { unpack } from 'msgpackr';
9
9
  import { watchFile, watchModules } from './watch.js';
10
10
  import { moduleApp } from './modules.js';
11
11
  import { sameOrigin } from './origin.js';
12
- import { Chat, PANEL_SCRIPT } from './chat.js';
12
+ import { Chat, panelFiles, panelScript } from './chat.js';
13
13
  // entries the log keeps, oldest first out
14
14
  const LOG_MAX = 300;
15
15
  // a body in the log is cut to this many characters of JSON
@@ -158,11 +158,14 @@ export async function startDevServer(options) {
158
158
  res.sendStatus(204);
159
159
  });
160
160
  const chat = new Chat(path.join(path.dirname(options.lab), '.edrys-dev', 'chat.json'));
161
- chat.routes(app);
162
- // edrys-Lite's page, with the chat panel (it shows only in the class tab)
161
+ // without an agent, nobody would answer
162
+ if (options.agent)
163
+ chat.routes(app);
164
+ panelFiles(app);
165
+ // edrys-Lite's page, with panel.js (the chat shows only in the class tab)
163
166
  app.get(['/', '/index.html'], async (req, res) => {
164
167
  const page = await fs.readFile(path.join(edrysDist(), 'index.html'), 'utf8');
165
- res.type('html').send(page + PANEL_SCRIPT);
168
+ res.type('html').send(page + panelScript(!!options.agent));
166
169
  });
167
170
  app.use(express.static(edrysDist()));
168
171
  const server = http.createServer(app);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edryslabs/edrys-dev",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Develop edrys-Lite labs locally: serves edrys-Lite, syncs on its own port and republishes the class whenever the lab file changes",
5
5
  "type": "module",
6
6
  "bin": {
package/views/panel.js CHANGED
@@ -10,6 +10,8 @@
10
10
  }
11
11
  return
12
12
  }
13
+ // the chat only with an agent to answer it (edrys-dev --mcp)
14
+ if (!document.currentScript || !document.currentScript.hasAttribute('data-chat')) return
13
15
 
14
16
  const OPEN_KEY = 'edrys-dev:chat-open'
15
17