@louisultra/dsh-verymath 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -1,15 +1,57 @@
1
+ import { registerHttp } from "./http.js";
1
2
  export * as core from "./core/index.js";
2
3
  export * as tool from "./tool/index.js";
3
4
  export const name = 'verymath-client';
4
- /** The root entry needs no services of its own; it only anchors the client bundle. */
5
+ /** `connection` is optional on purpose: see the apply comment. */
5
6
  export const inject = [];
6
7
  /**
7
- * Mount point for the bare-name loader entry. Deliberately empty: the service and
8
- * the tools are mounted from `./core` and `./tool`, and the browser half is
9
- * served by the host from `dsh.client`. Keeping the function (rather than a
10
- * module without `apply`) means the host mounts an ordinary plugin instead of
11
- * warning about a module it cannot apply.
8
+ * Look up an optional host service. The cast is explained where it happens.
12
9
  */
13
- export const apply = (_ctx) => {
14
- // Intentionally empty — see the doc comment above.
10
+ function optionalService(ctx, service) {
11
+ // SAFETY: `Context.get` is typed by the cordis service map of the host build,
12
+ // which this package does not import (the workspace registry lives in an
13
+ // optional host package). The cast only narrows an `unknown` that every caller
14
+ // re-checks field by field, so nothing is treated as more than the fields read.
15
+ return ctx.get(service);
16
+ }
17
+ /**
18
+ * The workspace the panel browses.
19
+ *
20
+ * Preferred source is the host's `workspaceRegistry` (each record carries the
21
+ * canonical directory); when that service is absent — a different host build, or
22
+ * a headless run — fall back to the process cwd. The resolved root is returned to
23
+ * the panel so the user can see which directory it reads instead of wondering why
24
+ * a glossary is "missing".
25
+ */
26
+ function resolveWorkspace(ctx) {
27
+ const registry = optionalService(ctx, 'workspaceRegistry');
28
+ const entities = registry?.entities;
29
+ if (entities instanceof Map) {
30
+ for (const entity of entities.values()) {
31
+ const path = entity?.path;
32
+ if (typeof path === 'string' && path.length > 0)
33
+ return path;
34
+ }
35
+ }
36
+ return process.cwd();
37
+ }
38
+ /**
39
+ * Mount point for the bare-name loader entry.
40
+ *
41
+ * It registers the panel's HTTP routes and nothing else: the service and the
42
+ * tools are mounted from `./core` and `./tool`, and the browser half is served by
43
+ * the host from `dsh.client`.
44
+ *
45
+ * `connection` is looked up with `ctx.inject`, not `ctx.get`: at apply time the
46
+ * service may not exist yet, and a `ctx.get` that quietly returns undefined
47
+ * leaves every route unregistered — the panel then shows 404 for all of them.
48
+ */
49
+ export const apply = (ctx) => {
50
+ ctx.inject(['connection'], (inner) => {
51
+ const connection = optionalService(inner, 'connection');
52
+ registerHttp({
53
+ workspace: () => resolveWorkspace(inner),
54
+ log: (message) => inner.logger?.warn?.(message),
55
+ }, connection);
56
+ });
15
57
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@louisultra/dsh-verymath",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "VeryMath capabilities for DSH: 16 bundled math skills and 14 tools covering paper reading, bilingual glossary, writing, Beamer, optimization, computation, Lean formalization, research workflows, Sage doc lookup and MATLAB. Community plugin for issue ECNU/EduWork#152.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -73,8 +73,11 @@
73
73
  "@deepseek-ai/dsh-tool-executor-native": "0.2.2-rc.1",
74
74
  "@deepseek-ai/dsh-tools": "0.2.2-rc.1",
75
75
  "@deepseek-ai/schemastery": "3.19.0",
76
+ "@testing-library/dom": "10.4.2",
77
+ "@testing-library/react": "16.3.3",
76
78
  "@types/js-yaml": "4.0.9",
77
79
  "@types/node": "24.19.2",
80
+ "jsdom": "31.0.0",
78
81
  "typescript": "6.0.3",
79
82
  "vitest": "4.1.8"
80
83
  },