@eliceio/cdk-cli 1.2.1 → 1.3.0-contenttypes.1

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 (169) hide show
  1. package/README.md +63 -53
  2. package/es/cli.js +11 -2
  3. package/es/commands/build/index.js +12 -0
  4. package/es/commands/create/index.js +2 -0
  5. package/es/commands/create/scaffold.d.ts +2 -2
  6. package/es/commands/create/scaffold.js +3 -3
  7. package/es/commands/dev/index.d.ts +10 -1
  8. package/es/commands/dev/index.js +47 -7
  9. package/es/commands/doctor/index.js +6 -2
  10. package/es/core/config.d.ts +42 -9
  11. package/es/core/config.js +217 -12
  12. package/es/core/project-check.d.ts +3 -2
  13. package/es/core/project-check.js +14 -3
  14. package/es/core/regex.d.ts +11 -0
  15. package/es/core/regex.js +41 -0
  16. package/es/core/sandbox.d.ts +26 -0
  17. package/es/core/sandbox.js +240 -30
  18. package/es/dev/assets.d.ts +80 -0
  19. package/es/dev/assets.js +240 -0
  20. package/es/dev/check.d.ts +30 -0
  21. package/es/dev/check.js +224 -34
  22. package/es/dev/grading.d.ts +49 -14
  23. package/es/dev/grading.js +109 -29
  24. package/es/dev/host-page.js +27 -3
  25. package/es/dev/inject.d.ts +2 -1
  26. package/es/dev/inject.js +10 -2
  27. package/es/dev/mock-api.d.ts +26 -3
  28. package/es/dev/mock-api.js +219 -40
  29. package/es/dev/server.d.ts +12 -1
  30. package/es/dev/server.js +115 -9
  31. package/es/engines/vite/index.js +1 -1
  32. package/es/engines/vite/plugin.d.ts +2 -0
  33. package/es/engines/vite/plugin.js +33 -5
  34. package/es/rules/answers.d.ts +13 -0
  35. package/es/rules/answers.js +94 -0
  36. package/es/rules/check.js +70 -1
  37. package/es/rules/index.d.ts +1 -0
  38. package/es/rules/index.js +1 -0
  39. package/es/rules/size.d.ts +31 -0
  40. package/es/rules/size.js +58 -0
  41. package/es/rules/types.d.ts +12 -0
  42. package/es/rules.json.js +2 -2
  43. package/package.json +2 -2
  44. package/rules.json +34 -5
  45. package/skills/_shared/always.md +3 -3
  46. package/skills/_shared/references/00-what-the-person-decides.md +1 -1
  47. package/skills/_shared/references/02-design-the-material.md +10 -7
  48. package/skills/_shared/references/03-create-the-project.md +10 -8
  49. package/skills/_shared/references/04-rules.md +1 -1
  50. package/skills/_shared/references/05-screen-code.md +52 -23
  51. package/skills/_shared/references/06-using-the-quiz-template.md +7 -6
  52. package/skills/_shared/references/08-fix-check-errors.md +23 -22
  53. package/skills/_shared/references/09-check.md +8 -6
  54. package/skills/_shared/references/12-upload-with-the-material-mcp.md +13 -13
  55. package/skills/_shared/references/13-edit-screen-design.md +122 -0
  56. package/skills/_shared/references/14-layouts.md +96 -0
  57. package/skills/elice-content-check/SKILL.md +2 -2
  58. package/skills/elice-content-create/SKILL.md +1 -1
  59. package/skills/elice-content-migrate/SKILL.md +1 -1
  60. package/skills/elice-content-publish/SKILL.md +1 -1
  61. package/templates/_shared/lib/cdk-mock.d.ts +47 -3
  62. package/templates/_shared/lib/cdk-mock.js +293 -15
  63. package/templates/_shared/lib/elice-content-editor.js +89 -58
  64. package/templates/_shared/lib/elice-content.css +1313 -126
  65. package/templates/_shared/lib/elice-content.d.ts +222 -23
  66. package/templates/_shared/lib/elice-content.js +1176 -88
  67. package/templates/_shared/lib/icons/empty-content.d.ts +2 -0
  68. package/templates/_shared/lib/icons/empty-content.js +11 -0
  69. package/templates/_shared/lib/icons/file-video.d.ts +2 -0
  70. package/templates/_shared/lib/icons/file-video.js +11 -0
  71. package/templates/_shared/lib/icons/file.d.ts +2 -0
  72. package/templates/_shared/lib/icons/file.js +11 -0
  73. package/templates/blank/README.md +6 -4
  74. package/templates/blank/edit.html +8 -2
  75. package/templates/blank/index.html +6 -1
  76. package/templates/blank/instructor.html +6 -1
  77. package/templates/blank/screens/instructor.js +8 -2
  78. package/templates/blank/screens/learn.js +1 -1
  79. package/templates/blank/template.json +1 -1
  80. package/templates/document/README.md +92 -0
  81. package/templates/document/commentary.txt +2 -0
  82. package/templates/document/core/dom.d.ts +13 -0
  83. package/templates/document/core/dom.js +83 -0
  84. package/templates/document/core/file-type.d.ts +21 -0
  85. package/templates/document/core/file-type.js +85 -0
  86. package/templates/document/core/group-3d.d.ts +20 -0
  87. package/templates/document/core/group-3d.js +256 -0
  88. package/templates/document/core/inline-edit.d.ts +15 -0
  89. package/templates/document/core/inline-edit.js +377 -0
  90. package/templates/document/core/load.d.ts +13 -0
  91. package/templates/document/core/load.js +40 -0
  92. package/templates/document/core/pdf-options.d.ts +9 -0
  93. package/templates/document/core/pdf-options.js +36 -0
  94. package/templates/document/core/pdf-worker.d.ts +24 -0
  95. package/templates/document/core/pdf-worker.js +122 -0
  96. package/templates/document/core/pdf.d.ts +12 -0
  97. package/templates/document/core/pdf.js +190 -0
  98. package/templates/document/core/pptx-edit.d.ts +14 -0
  99. package/templates/document/core/pptx-edit.js +137 -0
  100. package/templates/document/core/pptx-fonts.d.ts +5 -0
  101. package/templates/document/core/pptx-fonts.js +115 -0
  102. package/templates/document/core/pptx-media.d.ts +18 -0
  103. package/templates/document/core/pptx-media.js +83 -0
  104. package/templates/document/core/pptx-view.d.ts +5 -0
  105. package/templates/document/core/pptx-view.js +185 -0
  106. package/templates/document/core/settings.d.ts +25 -0
  107. package/templates/document/core/settings.js +86 -0
  108. package/templates/document/core/slide-edges.d.ts +3 -0
  109. package/templates/document/core/slide-edges.js +82 -0
  110. package/templates/document/core/viewer.d.ts +28 -0
  111. package/templates/document/core/viewer.js +159 -0
  112. package/templates/document/edit.html +17 -0
  113. package/templates/document/gitignore +4 -0
  114. package/templates/document/index.html +18 -0
  115. package/templates/document/metadata.json +9 -0
  116. package/templates/document/package.json +17 -0
  117. package/templates/document/public/fonts/OFL-Caladea.txt +93 -0
  118. package/templates/document/public/fonts/OFL-Carlito.txt +93 -0
  119. package/templates/document/public/fonts/caladea-latin-400-normal.woff2 +0 -0
  120. package/templates/document/public/fonts/caladea-latin-700-normal.woff2 +0 -0
  121. package/templates/document/public/fonts/carlito-latin-400-normal.woff2 +0 -0
  122. package/templates/document/public/fonts/carlito-latin-700-normal.woff2 +0 -0
  123. package/templates/document/screens/edit.js +574 -0
  124. package/templates/document/screens/learn.js +61 -0
  125. package/templates/document/styles.css +644 -0
  126. package/templates/document/template.json +6 -0
  127. package/templates/document/ui/templates/edit.js +82 -0
  128. package/templates/document/ui/templates/page.js +11 -0
  129. package/templates/document/ui/templates/viewer.js +41 -0
  130. package/templates/document/ui/texts.d.ts +3 -0
  131. package/templates/document/ui/texts.js +62 -0
  132. package/templates/document/ui/theme.css +69 -0
  133. package/templates/quiz/README.md +32 -14
  134. package/templates/quiz/core/behaviors.d.ts +17 -7
  135. package/templates/quiz/core/behaviors.js +40 -53
  136. package/templates/quiz/core/editor.d.ts +27 -2
  137. package/templates/quiz/core/editor.js +412 -11
  138. package/templates/quiz/core/markdown.d.ts +19 -0
  139. package/templates/quiz/core/markdown.js +225 -11
  140. package/templates/quiz/core/model.d.ts +40 -3
  141. package/templates/quiz/core/model.js +112 -5
  142. package/templates/quiz/core/rich-text.d.ts +18 -0
  143. package/templates/quiz/core/rich-text.js +469 -0
  144. package/templates/quiz/edit.html +12 -3
  145. package/templates/quiz/index.html +12 -3
  146. package/templates/quiz/public/img/mascot-half.webp +0 -0
  147. package/templates/quiz/screens/edit.js +331 -49
  148. package/templates/quiz/screens/learn.js +147 -15
  149. package/templates/quiz/styles.css +1244 -622
  150. package/templates/quiz/template.json +9 -2
  151. package/templates/quiz/ui/templates/edit.d.ts +19 -5
  152. package/templates/quiz/ui/templates/edit.js +371 -77
  153. package/templates/quiz/ui/templates/group.js +19 -8
  154. package/templates/quiz/ui/templates/order.js +25 -24
  155. package/templates/quiz/ui/templates/page.js +33 -8
  156. package/templates/quiz/ui/templates/question.js +6 -4
  157. package/templates/quiz/ui/texts.js +91 -26
  158. package/templates/quiz/ui/theme.css +8 -9
  159. package/templates/steps/README.md +77 -0
  160. package/templates/steps/commentary.txt +7 -0
  161. package/templates/steps/edit.html +21 -0
  162. package/templates/steps/gitignore +4 -0
  163. package/templates/steps/index.html +69 -0
  164. package/templates/steps/metadata.json +9 -0
  165. package/templates/steps/package.json +13 -0
  166. package/templates/steps/screens/edit.js +32 -0
  167. package/templates/steps/screens/learn.js +108 -0
  168. package/templates/steps/styles.css +54 -0
  169. package/templates/steps/template.json +6 -0
@@ -1,21 +1,56 @@
1
1
  import type { LocalGrading } from '../core/config.js';
2
- /** 제출 응답 `{ is_correct, score }` (서버 설계 v25). 채점하지 않으면 둘 다 null */
2
+ /**
3
+ * `ecdk dev` 흉내 채점. 서버 elice-material(`sprint/custom-material-2`)과 같은 규칙이다:
4
+ * `app/core/grading.py`(get_effective_completion · get_completion_score · build_*_outcome),
5
+ * `app/api/routes/material_submissions.py`(`_grade` · 422 조건), `app/core/submission_service.py`(결과 점수 · 완료 시각).
6
+ * SDK의 편집기 미리보기 채점(`packages/eliceio-cdk/src/apis/material-apis/preview-grading.ts`, MR !112)도 같은 규칙이고,
7
+ * CLI는 SDK를 import하지 않으므로 여기에 따로 둔다.
8
+ */
9
+ /** 자료의 완료 정책 (LXP 페이지 설정 `completion_policy`) */
10
+ export type CompletionPolicy = 'on_access' | 'on_submit' | 'on_graded';
11
+ export declare const COMPLETION_POLICIES: readonly CompletionPolicy[];
12
+ export declare const isCompletionPolicy: (v: unknown) => v is CompletionPolicy;
13
+ /**
14
+ * dev에서 고르지 않았을 때의 완료 정책: publish 스킬이 제안하는 값과 같다.
15
+ * 채점 설정(`settings.grading`)을 저장했으면 `on_graded`, 아니면 `on_submit`.
16
+ * (제출이 없는 자료에 제안하는 `on_access`는 dev가 코드만으로 알 수 없어 SDK 기능 메뉴에서 고른다)
17
+ */
18
+ export declare function recommendedCompletionPolicy(local: LocalGrading | undefined): CompletionPolicy;
19
+ /** 제출 응답 `{ is_correct, score, answer_correctness }`. 채점하지 않으면 is_correct · score가 null */
3
20
  export interface GradeResult {
4
21
  isCorrect: boolean | null;
5
22
  score: number | null;
23
+ /** partial_pattern 문항별 맞음 (answer_key 순서, 없는 답은 false). 그 밖은 서버처럼 [] */
24
+ answerCorrectness: boolean[];
6
25
  }
7
- /** dev가 rubric(AI) 채점을 흉내 낼 때 돌려주는 점수. 서버는 요청 안에서 채점한다 */
8
- export declare const RUBRIC_DEV_SCORE = 80;
9
- /** 정답 비교에 쓰는 답 문자열: 문자열은 앞뒤 공백을 자르고, 그 밖은 JSON으로 */
10
- export declare const answerText: (answer: unknown) => string;
11
- /** pattern: 정답 정규식(문자열 하나)이 답 문자열 전체와 맞는지. 정규식이 틀리거나 없으면 오답 */
12
- export declare function matchesPattern(answerKey: unknown, answer: unknown): boolean;
26
+ /** pattern: 정답 정규식(문자열 하나)이 답 문자열(앞뒤 공백을 자름) 전체와 맞는지. 정규식이 틀리거나 없으면 오답 */
27
+ export declare function matchesPattern(answerKey: unknown, answer: string): boolean;
28
+ /**
29
+ * 채점 전에 서버가 거절하는 답 (422 VALIDATION_ERROR, 저장하지 않음). 채점은 on_graded일 때만 하므로 그때만 본다.
30
+ * pattern은 문자열(`not_a_string`), partial_pattern은 문자열 배열(`not_a_string_array`)이어야 한다.
31
+ * 문제가 없으면 null, 있으면 `{ reason, message }`
32
+ */
33
+ export declare function answerError(local: LocalGrading | undefined, answer: unknown, policy: CompletionPolicy): {
34
+ reason: 'not_a_string' | 'not_a_string_array';
35
+ message: string;
36
+ } | null;
37
+ /**
38
+ * partial_pattern: `answer[i]`를 `answer_key[i]`에 맞춰 보고, 맞은 문항의 `scores[i]`를 더해 100에서 자른다.
39
+ * 없는 문항은 0점(answerCorrectness false), 남는 답은 무시. 100점일 때만 정답. 답 모양은 answerError가 먼저 본다
40
+ */
41
+ export declare function gradePartial(answerKey: string[], scores: number[], answer: unknown): GradeResult;
42
+ /**
43
+ * 제출 하나를 서버처럼 채점한다 (`_grade`). 답 모양은 answerError가 먼저 본다.
44
+ * - `on_access`: 채점하지 않음 `{ null, null }` (열면 완료)
45
+ * - `on_submit`: 채점하지 않고 만점 `{ null, 100 }`
46
+ * - `on_graded` + pattern: 0 / 100. partial_pattern: 맞은 문항 점수의 합(최대 100), 100점만 정답
47
+ * - `on_graded` + rubric: dev는 채점하지 않음 `{ null, null }`. 서버는 AI 모델이 매긴 점수(100점만 정답, 1점 이상 완료)를
48
+ * 주는데 dev는 부를 수 없고, 지어낸 점수는 진짜처럼 읽힌다 (SDK 미리보기 채점과 같음)
49
+ * - `on_graded` + 채점 설정 없음: `{ false, 0 }` (서버도 0점이라 완료되지 않음)
50
+ */
51
+ export declare function grade(local: LocalGrading | undefined, answer: unknown, policy: CompletionPolicy): GradeResult;
13
52
  /**
14
- * elice-material 채점 흉내 (채점 방식 → 점수). 채점은 모두 요청 안에서 끝난다.
15
- * 템플릿 mock(`lib/cdk-mock.js`의 gradeLocally)과 같은 판정이다. 완료 정책은 LXP 설정이라 보지 않는다 (ADR 0012):
16
- * 채점 설정이 있으면 채점하고, 없으면 제출만 받는다.
17
- * - pattern: 답 문자열 전체를 정규식 하나로 비교 0 / 100
18
- * - rubric: 흉내 점수 RUBRIC_DEV_SCORE, 통과로 본다 (통과 기준 pass_threshold는 정해지지 않음)
19
- * - 채점 설정(편집 화면이 저장하는 settings.grading)이 없으면 제출만 받고 `{ null, null }`
53
+ * 제출 뒤 결과의 완료 기준 점수 (서버 get_completion_score). on_access는 null(제출과 상관없이 완료).
54
+ * rubric은 1점, 그 밖은 100점
20
55
  */
21
- export declare function grade(local: LocalGrading | undefined, answer: unknown): GradeResult;
56
+ export declare function completionScore(local: LocalGrading | undefined, policy: CompletionPolicy): number | null;
package/es/dev/grading.js CHANGED
@@ -1,41 +1,121 @@
1
- /** dev가 rubric(AI) 채점을 흉내 낼 때 돌려주는 점수. 서버는 요청 안에서 채점한다 */
2
- const RUBRIC_DEV_SCORE = 80;
3
- /** 정답 비교에 쓰는 답 문자열: 문자열은 앞뒤 공백을 자르고, 그 밖은 JSON으로 */
4
- const answerText = answer => typeof answer === 'string' ? answer.trim() : JSON.stringify(answer ?? null);
5
- /** pattern: 정답 정규식(문자열 하나)이 답 문자열 전체와 맞는지. 정규식이 틀리거나 없으면 오답 */
1
+ import { fullMatch } from '../core/regex.js';
2
+
3
+ const COMPLETION_POLICIES = ['on_access', 'on_submit', 'on_graded'];
4
+ const isCompletionPolicy = v => typeof v === 'string' && COMPLETION_POLICIES.includes(v);
5
+ /**
6
+ * dev에서 고르지 않았을 때의 완료 정책: publish 스킬이 제안하는 값과 같다.
7
+ * 채점 설정(`settings.grading`)을 저장했으면 `on_graded`, 아니면 `on_submit`.
8
+ * (제출이 없는 자료에 제안하는 `on_access`는 dev가 코드만으로 알 수 없어 SDK 기능 메뉴에서 고른다)
9
+ */
10
+ function recommendedCompletionPolicy(local) {
11
+ return local?.grading ? 'on_graded' : 'on_submit';
12
+ }
13
+ const SCORE_MAX = 100;
14
+ /** rubric은 1점 이상이면 완료, 그 밖은 100점 (서버 get_completion_score) */
15
+ const RUBRIC_COMPLETION_SCORE = 1;
16
+ /** pattern: 정답 정규식(문자열 하나)이 답 문자열(앞뒤 공백을 자름) 전체와 맞는지. 정규식이 틀리거나 없으면 오답 */
6
17
  function matchesPattern(answerKey, answer) {
7
18
  if (typeof answerKey !== 'string') return false;
8
- try {
9
- return new RegExp(`^(?:${answerKey})$`).test(answerText(answer));
10
- } catch {
11
- return false;
12
- }
19
+ return fullMatch(answerKey, answer);
13
20
  }
14
21
  /**
15
- * elice-material 채점 흉내 (채점 방식 → 점수). 채점은 모두 요청 안에서 끝난다.
16
- * 템플릿 mock(`lib/cdk-mock.js`의 gradeLocally)과 같은 판정이다. 완료 정책은 LXP 설정이라 보지 않는다 (ADR 0012):
17
- * 채점 설정이 있으면 채점하고, 없으면 제출만 받는다.
18
- * - pattern: 답 문자열 전체를 정규식 하나로 비교 0 / 100
19
- * - rubric: 흉내 점수 RUBRIC_DEV_SCORE, 통과로 본다 (통과 기준 pass_threshold는 정해지지 않음)
20
- * - 채점 설정(편집 화면이 저장하는 settings.grading)이 없으면 제출만 받고 `{ null, null }`
22
+ * 채점 전에 서버가 거절하는 답 (422 VALIDATION_ERROR, 저장하지 않음). 채점은 on_graded일 때만 하므로 그때만 본다.
23
+ * pattern은 문자열(`not_a_string`), partial_pattern은 문자열 배열(`not_a_string_array`)이어야 한다.
24
+ * 문제가 없으면 null, 있으면 `{ reason, message }`
21
25
  */
22
- function grade(local, answer) {
23
- const grading = local?.grading;
24
- if (grading?.type === 'pattern') {
25
- const ok = matchesPattern(grading.answer_key, answer);
26
- return {
27
- isCorrect: ok,
28
- score: ok ? 100 : 0
26
+ function answerError(local, answer, policy) {
27
+ if (policy !== 'on_graded') return null;
28
+ const type = local?.grading?.type;
29
+ if (type === 'pattern' && typeof answer !== 'string') return {
30
+ reason: 'not_a_string',
31
+ message: 'pattern: answer must be a string'
32
+ };
33
+ if (type === 'partial_pattern') {
34
+ if (!Array.isArray(answer)) return {
35
+ reason: 'not_a_string_array',
36
+ message: 'partial_pattern: answer must be an array of strings'
37
+ };
38
+ const bad = answer.findIndex(item => typeof item !== 'string');
39
+ if (bad >= 0) return {
40
+ reason: 'not_a_string_array',
41
+ message: `partial_pattern: answer[${bad}] must be a string`
29
42
  };
30
43
  }
31
- if (grading?.type === 'rubric') return {
32
- isCorrect: true,
33
- score: RUBRIC_DEV_SCORE
34
- };
44
+ return null;
45
+ }
46
+ /**
47
+ * partial_pattern: `answer[i]`를 `answer_key[i]`에 맞춰 보고, 맞은 문항의 `scores[i]`를 더해 100에서 자른다.
48
+ * 없는 문항은 0점(answerCorrectness false), 남는 답은 무시. 100점일 때만 정답. 답 모양은 answerError가 먼저 본다
49
+ */
50
+ function gradePartial(answerKey, scores, answer) {
51
+ const items = Array.isArray(answer) ? answer : [];
52
+ const answerCorrectness = answerKey.map((key, i) => {
53
+ const item = items[i];
54
+ return typeof item === 'string' && fullMatch(key, item);
55
+ });
56
+ const total = answerCorrectness.reduce((sum, ok, i) => sum + (ok ? scores[i] ?? 0 : 0), 0);
57
+ const score = Math.min(SCORE_MAX, total);
35
58
  return {
59
+ isCorrect: score === SCORE_MAX,
60
+ score,
61
+ answerCorrectness
62
+ };
63
+ }
64
+ /**
65
+ * 제출 하나를 서버처럼 채점한다 (`_grade`). 답 모양은 answerError가 먼저 본다.
66
+ * - `on_access`: 채점하지 않음 `{ null, null }` (열면 완료)
67
+ * - `on_submit`: 채점하지 않고 만점 `{ null, 100 }`
68
+ * - `on_graded` + pattern: 0 / 100. partial_pattern: 맞은 문항 점수의 합(최대 100), 100점만 정답
69
+ * - `on_graded` + rubric: dev는 채점하지 않음 `{ null, null }`. 서버는 AI 모델이 매긴 점수(100점만 정답, 1점 이상 완료)를
70
+ * 주는데 dev는 부를 수 없고, 지어낸 점수는 진짜처럼 읽힌다 (SDK 미리보기 채점과 같음)
71
+ * - `on_graded` + 채점 설정 없음: `{ false, 0 }` (서버도 0점이라 완료되지 않음)
72
+ */
73
+ function grade(local, answer, policy) {
74
+ if (policy === 'on_access') return {
75
+ isCorrect: null,
76
+ score: null,
77
+ answerCorrectness: []
78
+ };
79
+ if (policy === 'on_submit') return {
36
80
  isCorrect: null,
37
- score: null
81
+ score: SCORE_MAX,
82
+ answerCorrectness: []
38
83
  };
84
+ const grading = local?.grading;
85
+ switch (grading?.type) {
86
+ case 'pattern':
87
+ {
88
+ const ok = typeof answer === 'string' && matchesPattern(grading.answer_key, answer);
89
+ return {
90
+ isCorrect: ok,
91
+ score: ok ? SCORE_MAX : 0,
92
+ answerCorrectness: []
93
+ };
94
+ }
95
+ case 'partial_pattern':
96
+ return gradePartial(grading.answer_key, grading.scores, answer);
97
+ case 'rubric':
98
+ return {
99
+ isCorrect: null,
100
+ score: null,
101
+ answerCorrectness: []
102
+ };
103
+ default:
104
+ return {
105
+ isCorrect: false,
106
+ score: 0,
107
+ answerCorrectness: []
108
+ };
109
+ }
110
+ }
111
+ /**
112
+ * 제출 뒤 결과의 완료 기준 점수 (서버 get_completion_score). on_access는 null(제출과 상관없이 완료).
113
+ * rubric은 1점, 그 밖은 100점
114
+ */
115
+ function completionScore(local, policy) {
116
+ if (policy === 'on_access') return null;
117
+ if (policy === 'on_graded' && local?.grading?.type === 'rubric') return RUBRIC_COMPLETION_SCORE;
118
+ return SCORE_MAX;
39
119
  }
40
120
 
41
- export { RUBRIC_DEV_SCORE, answerText, grade, matchesPattern };
121
+ export { COMPLETION_POLICIES, answerError, completionScore, grade, gradePartial, isCompletionPolicy, matchesPattern, recommendedCompletionPolicy };
@@ -57,6 +57,15 @@ function hostPage(opts) {
57
57
  <details id="sdk-tools">
58
58
  <summary title="@eliceio/cdk가 LXP에서 받는 값을 바꿔 봅니다">SDK 기능</summary>
59
59
  <div class="tools">
60
+ <div class="tool" role="group" aria-label="완료 정책" title="LXP 자료 편집 화면의 '설정'에서 교육자가 고르는 완료 정책 (sdk.material.completionPolicy). 흉내 서버가 서버처럼 이 정책으로 채점 · 완료합니다: 열면 완료(채점 안 함) · 제출하면 100점 · 채점(pattern · partial_pattern, rubric은 dev에서 채점 안 함). 권장값은 채점 설정이 있으면 on_graded, 없으면 on_submit">
61
+ <b>완료 정책</b> <code>material.completionPolicy</code>
62
+ <select id="completion-policy" aria-label="완료 정책">
63
+ <option value="">권장값</option>
64
+ <option value="on_access">on_access · 열면 완료</option>
65
+ <option value="on_submit">on_submit · 제출하면 완료</option>
66
+ <option value="on_graded">on_graded · 채점해 통과하면 완료</option>
67
+ </select>
68
+ </div>
60
69
  <div class="tool" role="group" aria-label="차시 이동" title="sdk.navigation.getHasPrevious() · getHasNext()가 받는 값. 끄면 첫 차시 · 마지막 차시처럼 동작합니다. previous() · next()는 dev에서 이동하지 않고 아래에 기록만 남깁니다">
61
70
  <b>차시 이동</b> <code>sdk.navigation</code>
62
71
  <label><input type="checkbox" id="has-prev" checked>이전 차시 있음</label>
@@ -66,7 +75,7 @@ function hostPage(opts) {
66
75
  <b>저장 전 편집 화면</b> <code>#edit=1</code>
67
76
  <button type="button" id="open-edit-draft">열기</button>
68
77
  </div>
69
- <div class="tool" role="group" aria-label="저장 전 미리보기" title="LXP 편집 페이지의 미리보기처럼 토큰 없이 학생 화면을 엽니다. settings가 비어 '아직 내용이 없습니다' 안내가 뜨고(기본 내용 없음), 제출은 기록되지 않습니다(늘 100점)">
78
+ <div class="tool" role="group" aria-label="저장 전 미리보기" title="LXP 편집 페이지의 미리보기처럼 토큰 없이 학생 화면을 엽니다. settings가 비어 '학습 자료를 준비하고 있어요' 안내가 뜨고(기본 내용 없음), 제출은 기록되지 않습니다(늘 100점)">
70
79
  <b>저장 전 미리보기</b> <code>#preview=1</code>
71
80
  <button type="button" id="open-preview">열기</button>
72
81
  </div>
@@ -247,17 +256,32 @@ function hostPage(opts) {
247
256
  toolsEl.open = false;
248
257
  toolsEl.querySelector('summary').focus();
249
258
  });
259
+ // 완료 정책: 흉내 서버에 알리고 지금 보기를 다시 연다 (SDK는 init 때 읽음). 권장값 줄에는 지금 권장값을 적는다
260
+ const policyEl = document.getElementById('completion-policy');
261
+ function renderPolicy() {
262
+ const p = state.completionPolicy;
263
+ if (!p) return;
264
+ policyEl.value = p.chosen ?? '';
265
+ policyEl.options[0].textContent = '권장값 (' + p.recommended + ')';
266
+ }
267
+ policyEl.onchange = async () => {
268
+ const policy = policyEl.value || null;
269
+ state = await (await fetch('/__ecdk/completion-policy', { method: 'POST', body: JSON.stringify({ policy }) })).json();
270
+ renderPolicy();
271
+ note('완료 정책: ' + (policy ?? '권장값 (' + state.completionPolicy.recommended + ')'));
272
+ open(current);
273
+ };
250
274
  previewEl.onclick = () => { toolsEl.open = false; open(PREVIEW[0]); };
251
275
  editDraftEl.onclick = () => { toolsEl.open = false; open(EDIT_DRAFT[0]); };
252
276
  document.getElementById('reset').onclick = async () => { await fetch('/__ecdk/reset', { method: 'POST' }); open(current); };
253
277
 
254
278
  state = await (await fetch('/__ecdk/state')).json();
255
- renderScenarios(); renderCheck(state.check); open(current);
279
+ renderScenarios(); renderCheck(state.check); renderPolicy(); open(current);
256
280
 
257
281
  const events = new EventSource('/__ecdk/events');
258
282
  events.addEventListener('reload', async (e) => {
259
283
  state = JSON.parse(e.data);
260
- renderScenarios(); renderCheck(state.check); open(current);
284
+ renderScenarios(); renderCheck(state.check); renderPolicy(); open(current);
261
285
  });
262
286
  </script>
263
287
  </body>
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * dev에서만 콘텐츠 HTML의 <head> 맨 앞에 넣는 스크립트 (zip에는 들어가지 않음).
3
- * - 키트가 흉내 서버를 쓰도록 API 주소를, 콘텐츠 주소를 직접 열어 mock으로 돌 때 쓸 로컬 채점 설정 주소를 알려 줌 (window.__ECDK_DEV__)
3
+ * - 키트가 흉내 서버를 쓰도록 API 주소를, 콘텐츠 주소를 직접 열어 mock으로 돌 때 쓸 로컬 채점 설정 주소 · 자료 파일
4
+ * 올리기(토큰 없는 dev 전용 upload-url) · 보기(asset_base_url) 주소를 알려 줌 (window.__ECDK_DEV__)
4
5
  * - 콘솔 오류 · 처리 안 된 예외 · 불러오지 못한 파일을 터미널로 보냄
5
6
  * - 콘텐츠 CSP(rules/csp.ts)가 막은 요청(securitypolicyviolation)을 dev 화면(부모 창, 호스트 출처로만)과 터미널에 알림.
6
7
  * 키트가 아니라 여기서 듣는 이유: 이 스크립트는 ecdk dev 응답에만 들어가 운영 LXP에서는 돌지 않고, 다른 스크립트보다
package/es/dev/inject.js CHANGED
@@ -1,6 +1,9 @@
1
+ import { ASSET_SIGNED_PATH, MOCK_UPLOAD_URL_PATH } from './assets.js';
2
+
1
3
  /**
2
4
  * dev에서만 콘텐츠 HTML의 <head> 맨 앞에 넣는 스크립트 (zip에는 들어가지 않음).
3
- * - 키트가 흉내 서버를 쓰도록 API 주소를, 콘텐츠 주소를 직접 열어 mock으로 돌 때 쓸 로컬 채점 설정 주소를 알려 줌 (window.__ECDK_DEV__)
5
+ * - 키트가 흉내 서버를 쓰도록 API 주소를, 콘텐츠 주소를 직접 열어 mock으로 돌 때 쓸 로컬 채점 설정 주소 · 자료 파일
6
+ * 올리기(토큰 없는 dev 전용 upload-url) · 보기(asset_base_url) 주소를 알려 줌 (window.__ECDK_DEV__)
4
7
  * - 콘솔 오류 · 처리 안 된 예외 · 불러오지 못한 파일을 터미널로 보냄
5
8
  * - 콘텐츠 CSP(rules/csp.ts)가 막은 요청(securitypolicyviolation)을 dev 화면(부모 창, 호스트 출처로만)과 터미널에 알림.
6
9
  * 키트가 아니라 여기서 듣는 이유: 이 스크립트는 ecdk dev 응답에만 들어가 운영 LXP에서는 돌지 않고, 다른 스크립트보다
@@ -11,11 +14,16 @@
11
14
  const DEV_MESSAGE_SOURCE = 'ecdk-dev';
12
15
  function devScript(hostOrigin) {
13
16
  const api = `${hostOrigin}/api`;
17
+ // 콘텐츠 주소를 직접 열어 mock으로 돌 때 문서 파일을 흉내 서버에 올리고 여는 주소 (실제 SDK + 흉내 API와 같은 모양)
18
+ const assets = {
19
+ uploadUrl: `${hostOrigin}${MOCK_UPLOAD_URL_PATH}`,
20
+ baseUrl: `${api}${ASSET_SIGNED_PATH}`
21
+ };
14
22
  const log = `${hostOrigin}/__ecdk/log`;
15
23
  const grading = `${hostOrigin}/__ecdk/grading`;
16
24
  return `<script>
17
25
  (() => {
18
- window.__ECDK_DEV__ = { api: ${JSON.stringify(api)}, grading: ${JSON.stringify(grading)} };
26
+ window.__ECDK_DEV__ = { api: ${JSON.stringify(api)}, grading: ${JSON.stringify(grading)}, assets: ${JSON.stringify(assets)} };
19
27
  const send = (level, message) => {
20
28
  try { fetch(${JSON.stringify(log)}, { method: 'POST', body: JSON.stringify({ level, message: String(message), page: location.pathname.split('/').pop() }) }); } catch (e) {}
21
29
  };
@@ -1,4 +1,5 @@
1
1
  import { type LocalGrading } from '../core/config.js';
2
+ import { type CompletionPolicy } from './grading.js';
2
3
  import type { IncomingMessage, ServerResponse } from 'node:http';
3
4
  /**
4
5
  * elice-material API 흉내 (서버 설계 v25, @eliceio/cdk 1.x가 부르는 것만).
@@ -23,8 +24,9 @@ export type MaterialViewer = 'student' | 'instructor' | 'tutor';
23
24
  * - edit: `#token=…` (scope edit). LXP 편집 페이지처럼 편집 화면을 edit 토큰으로 열고,
24
25
  * 콘텐츠의 `saveSettings`가 이 토큰으로 `PATCH /materials/{id}/draft`를 부른다 (토큰 없는 `#edit=1` draft는 저장할 수 없음).
25
26
  * dev에는 draft 발행 단계가 없어 draft에 저장한 settings가 바로 지금 버전 settings가 된다
26
- * 완료 정책은 LXP 설정이라 (ADR 0012) 흉내 내지 않는다: 채점 설정이 있으면 채점하고, 없으면 제출만 받는다.
27
- * 편집 화면의 `saveSettings`가 보낸 settings(내용 + `grading` { type: pattern | rubric })는 통째로 `.ecdk/settings.json`에 쓰고,
27
+ * 완료 정책은 LXP 페이지 설정이고 콘텐츠는 읽기만 한다. dev는 호스트 화면 'SDK 기능 › 완료 정책'에서 고르고(고르지 않으면
28
+ * 권장값: 채점 설정이 있으면 on_graded, 없으면 on_submit), 채점 · 결과는 서버처럼 그 정책을 따른다 (`grading.ts`).
29
+ * 편집 화면의 `saveSettings`가 보낸 settings(내용 + `grading` { type: pattern | partial_pattern | rubric })는 통째로 `.ecdk/settings.json`에 쓰고,
28
30
  * edit 범위 응답에는 `grading`까지, 학생 · 튜터 · 교육자(learn scope) 응답에는 서버처럼 `grading`을 빼고 준다
29
31
  */
30
32
  export type DevScenario = 'student' | 'instructor' | 'tutor' | 'edit';
@@ -44,6 +46,8 @@ interface Submission {
44
46
  answer: unknown;
45
47
  is_correct: boolean | null;
46
48
  score: number | null;
49
+ /** partial_pattern 문항별 맞음, 그 밖은 [] */
50
+ answer_correctness: boolean[];
47
51
  }
48
52
  interface Result {
49
53
  score: number | null;
@@ -60,8 +64,14 @@ export interface MockState {
60
64
  results: Map<number, Result>;
61
65
  /** 계정별 최근 1분 제출 시각 (rate limit) */
62
66
  recent: Map<number, number[]>;
67
+ /** kvstore 문서: 계정별 (나 · 이 자료) */
68
+ kv: Map<number, Record<string, unknown>>;
69
+ /** 호스트 화면에서 고른 완료 정책. null이면 권장값(recommendedCompletionPolicy). 처음 상태로 되돌려도 그대로 */
70
+ completionPolicy: CompletionPolicy | null;
63
71
  }
64
72
  export declare const createState: () => MockState;
73
+ /** 지금 쓰는 완료 정책: 고른 값, 없으면 권장값 */
74
+ export declare const effectiveCompletionPolicy: (state: MockState, local: LocalGrading | undefined) => CompletionPolicy;
65
75
  export interface MockApiOptions {
66
76
  state: MockState;
67
77
  /** 채점에 쓰는 값 (저장한 settings.grading) */
@@ -69,8 +79,21 @@ export interface MockApiOptions {
69
79
  /** 편집 화면이 저장한 settings 전체(내용 + grading)를 `.ecdk/settings.json`에 쓴다 */
70
80
  saveSettings?: (settings: Record<string, unknown>) => Promise<void>;
71
81
  getEntries: () => Record<string, string>;
82
+ /** 자료 응답 `current_version` · `draft`의 `asset_base_url` (dev: 흉내 API `/s/dev/`, 운영처럼 서명 경로까지) */
83
+ assetBaseUrl?: () => string;
84
+ /** `POST /storage/upload-url` (dev/assets.ts `createUploadUrl`) */
85
+ createUploadUrl?: (body: unknown, materialId: string) => {
86
+ ok: true;
87
+ data: unknown;
88
+ } | {
89
+ ok: false;
90
+ status: number;
91
+ code: string;
92
+ message: string;
93
+ details?: unknown[];
94
+ };
72
95
  onEvent?: (message: string) => void;
73
96
  }
74
97
  /** `/api` 아래 요청을 처리한다 */
75
- export declare function handleMockApi(req: IncomingMessage, res: ServerResponse, path: string, opts: MockApiOptions): Promise<void>;
98
+ export declare function handleMockApi(req: IncomingMessage, res: ServerResponse, path: string, opts: MockApiOptions): Promise<void | ServerResponse<IncomingMessage>>;
76
99
  export {};