seance-cli 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +40 -2
- package/dist/commands/init.d.ts +29 -0
- package/dist/commands/init.js +310 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/mcp.d.ts +19 -0
- package/dist/commands/mcp.js +38 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/commands/quiz.d.ts +23 -0
- package/dist/commands/quiz.js +187 -0
- package/dist/commands/quiz.js.map +1 -0
- package/dist/commands/review.d.ts +4 -0
- package/dist/commands/review.js +115 -0
- package/dist/commands/review.js.map +1 -0
- package/dist/commands/sync.d.ts +17 -0
- package/dist/commands/sync.js +367 -0
- package/dist/commands/sync.js.map +1 -0
- package/dist/git.d.ts +33 -0
- package/dist/git.js +103 -0
- package/dist/git.js.map +1 -0
- package/dist/hosted-api.d.ts +24 -0
- package/dist/hosted-api.js +85 -0
- package/dist/hosted-api.js.map +1 -0
- package/dist/hosted-consent.d.ts +8 -0
- package/dist/hosted-consent.js +37 -0
- package/dist/hosted-consent.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +108 -0
- package/dist/index.js.map +1 -0
- package/dist/init-fs.d.ts +51 -0
- package/dist/init-fs.js +220 -0
- package/dist/init-fs.js.map +1 -0
- package/dist/init-questions.d.ts +21 -0
- package/dist/init-questions.js +161 -0
- package/dist/init-questions.js.map +1 -0
- package/dist/mcp-handlers.d.ts +22 -0
- package/dist/mcp-handlers.js +185 -0
- package/dist/mcp-handlers.js.map +1 -0
- package/dist/mcp-server.d.ts +4 -0
- package/dist/mcp-server.js +39 -0
- package/dist/mcp-server.js.map +1 -0
- package/dist/prompter.d.ts +29 -0
- package/dist/prompter.js +42 -0
- package/dist/prompter.js.map +1 -0
- package/dist/quiz-backend.d.ts +40 -0
- package/dist/quiz-backend.js +116 -0
- package/dist/quiz-backend.js.map +1 -0
- package/dist/quiz-input.d.ts +12 -0
- package/dist/quiz-input.js +52 -0
- package/dist/quiz-input.js.map +1 -0
- package/dist/quiz-io.d.ts +30 -0
- package/dist/quiz-io.js +83 -0
- package/dist/quiz-io.js.map +1 -0
- package/dist/quiz-ui.d.ts +18 -0
- package/dist/quiz-ui.js +51 -0
- package/dist/quiz-ui.js.map +1 -0
- package/node_modules/@seance/ai/LICENSE +21 -0
- package/node_modules/@seance/ai/dist/chain.d.ts +31 -0
- package/node_modules/@seance/ai/dist/chain.js +114 -0
- package/node_modules/@seance/ai/dist/chain.js.map +1 -0
- package/node_modules/@seance/ai/dist/grade.d.ts +14 -0
- package/node_modules/@seance/ai/dist/grade.js +44 -0
- package/node_modules/@seance/ai/dist/grade.js.map +1 -0
- package/node_modules/@seance/ai/dist/hosted-config.d.ts +9 -0
- package/node_modules/@seance/ai/dist/hosted-config.js +27 -0
- package/node_modules/@seance/ai/dist/hosted-config.js.map +1 -0
- package/node_modules/@seance/ai/dist/index.d.ts +9 -0
- package/node_modules/@seance/ai/dist/index.js +9 -0
- package/node_modules/@seance/ai/dist/index.js.map +1 -0
- package/node_modules/@seance/ai/dist/providers.d.ts +54 -0
- package/node_modules/@seance/ai/dist/providers.js +149 -0
- package/node_modules/@seance/ai/dist/providers.js.map +1 -0
- package/node_modules/@seance/ai/dist/quiz.d.ts +26 -0
- package/node_modules/@seance/ai/dist/quiz.js +41 -0
- package/node_modules/@seance/ai/dist/quiz.js.map +1 -0
- package/node_modules/@seance/ai/package.json +25 -0
- package/node_modules/@seance/core/LICENSE +21 -0
- package/node_modules/@seance/core/dist/ai-check.d.ts +58 -0
- package/node_modules/@seance/core/dist/ai-check.js +460 -0
- package/node_modules/@seance/core/dist/ai-check.js.map +1 -0
- package/node_modules/@seance/core/dist/ai-prompts.d.ts +29 -0
- package/node_modules/@seance/core/dist/ai-prompts.js +221 -0
- package/node_modules/@seance/core/dist/ai-prompts.js.map +1 -0
- package/node_modules/@seance/core/dist/ai-schemas.d.ts +155 -0
- package/node_modules/@seance/core/dist/ai-schemas.js +92 -0
- package/node_modules/@seance/core/dist/ai-schemas.js.map +1 -0
- package/node_modules/@seance/core/dist/api-client.d.ts +26 -0
- package/node_modules/@seance/core/dist/api-client.js +71 -0
- package/node_modules/@seance/core/dist/api-client.js.map +1 -0
- package/node_modules/@seance/core/dist/api-errors.d.ts +37 -0
- package/node_modules/@seance/core/dist/api-errors.js +66 -0
- package/node_modules/@seance/core/dist/api-errors.js.map +1 -0
- package/node_modules/@seance/core/dist/api-schemas.d.ts +284 -0
- package/node_modules/@seance/core/dist/api-schemas.js +67 -0
- package/node_modules/@seance/core/dist/api-schemas.js.map +1 -0
- package/node_modules/@seance/core/dist/decision-log.d.ts +73 -0
- package/node_modules/@seance/core/dist/decision-log.js +239 -0
- package/node_modules/@seance/core/dist/decision-log.js.map +1 -0
- package/node_modules/@seance/core/dist/dependency-guard.d.ts +20 -0
- package/node_modules/@seance/core/dist/dependency-guard.js +732 -0
- package/node_modules/@seance/core/dist/dependency-guard.js.map +1 -0
- package/node_modules/@seance/core/dist/gate.d.ts +11 -0
- package/node_modules/@seance/core/dist/gate.js +26 -0
- package/node_modules/@seance/core/dist/gate.js.map +1 -0
- package/node_modules/@seance/core/dist/git-parse.d.ts +11 -0
- package/node_modules/@seance/core/dist/git-parse.js +23 -0
- package/node_modules/@seance/core/dist/git-parse.js.map +1 -0
- package/node_modules/@seance/core/dist/index.d.ts +65 -0
- package/node_modules/@seance/core/dist/index.js +47 -0
- package/node_modules/@seance/core/dist/index.js.map +1 -0
- package/node_modules/@seance/core/dist/init-checklist.d.ts +153 -0
- package/node_modules/@seance/core/dist/init-checklist.js +200 -0
- package/node_modules/@seance/core/dist/init-checklist.js.map +1 -0
- package/node_modules/@seance/core/dist/init-detect.d.ts +9 -0
- package/node_modules/@seance/core/dist/init-detect.js +84 -0
- package/node_modules/@seance/core/dist/init-detect.js.map +1 -0
- package/node_modules/@seance/core/dist/init-templates.d.ts +36 -0
- package/node_modules/@seance/core/dist/init-templates.js +257 -0
- package/node_modules/@seance/core/dist/init-templates.js.map +1 -0
- package/node_modules/@seance/core/dist/map-basics.d.ts +13 -0
- package/node_modules/@seance/core/dist/map-basics.js +19 -0
- package/node_modules/@seance/core/dist/map-basics.js.map +1 -0
- package/node_modules/@seance/core/dist/map-summary.d.ts +5 -0
- package/node_modules/@seance/core/dist/map-summary.js +50 -0
- package/node_modules/@seance/core/dist/map-summary.js.map +1 -0
- package/node_modules/@seance/core/dist/markers.d.ts +51 -0
- package/node_modules/@seance/core/dist/markers.js +84 -0
- package/node_modules/@seance/core/dist/markers.js.map +1 -0
- package/node_modules/@seance/core/dist/mcp-quiz.d.ts +94 -0
- package/node_modules/@seance/core/dist/mcp-quiz.js +130 -0
- package/node_modules/@seance/core/dist/mcp-quiz.js.map +1 -0
- package/node_modules/@seance/core/dist/mcp-tools.d.ts +82 -0
- package/node_modules/@seance/core/dist/mcp-tools.js +136 -0
- package/node_modules/@seance/core/dist/mcp-tools.js.map +1 -0
- package/node_modules/@seance/core/dist/mcp-views.d.ts +21 -0
- package/node_modules/@seance/core/dist/mcp-views.js +83 -0
- package/node_modules/@seance/core/dist/mcp-views.js.map +1 -0
- package/node_modules/@seance/core/dist/quiz-assembly.d.ts +21 -0
- package/node_modules/@seance/core/dist/quiz-assembly.js +43 -0
- package/node_modules/@seance/core/dist/quiz-assembly.js.map +1 -0
- package/node_modules/@seance/core/dist/quiz-cards.d.ts +183 -0
- package/node_modules/@seance/core/dist/quiz-cards.js +215 -0
- package/node_modules/@seance/core/dist/quiz-cards.js.map +1 -0
- package/node_modules/@seance/core/dist/quiz-session.d.ts +67 -0
- package/node_modules/@seance/core/dist/quiz-session.js +141 -0
- package/node_modules/@seance/core/dist/quiz-session.js.map +1 -0
- package/node_modules/@seance/core/dist/quiz-subjects.d.ts +13 -0
- package/node_modules/@seance/core/dist/quiz-subjects.js +63 -0
- package/node_modules/@seance/core/dist/quiz-subjects.js.map +1 -0
- package/node_modules/@seance/core/dist/rate-limit.d.ts +33 -0
- package/node_modules/@seance/core/dist/rate-limit.js +114 -0
- package/node_modules/@seance/core/dist/rate-limit.js.map +1 -0
- package/node_modules/@seance/core/dist/scoring.d.ts +48 -0
- package/node_modules/@seance/core/dist/scoring.js +95 -0
- package/node_modules/@seance/core/dist/scoring.js.map +1 -0
- package/node_modules/@seance/core/dist/seance-config.d.ts +177 -0
- package/node_modules/@seance/core/dist/seance-config.js +43 -0
- package/node_modules/@seance/core/dist/seance-config.js.map +1 -0
- package/node_modules/@seance/core/dist/seance-state.d.ts +125 -0
- package/node_modules/@seance/core/dist/seance-state.js +61 -0
- package/node_modules/@seance/core/dist/seance-state.js.map +1 -0
- package/node_modules/@seance/core/dist/sm2.d.ts +18 -0
- package/node_modules/@seance/core/dist/sm2.js +87 -0
- package/node_modules/@seance/core/dist/sm2.js.map +1 -0
- package/node_modules/@seance/core/dist/stored-schemas.d.ts +29 -0
- package/node_modules/@seance/core/dist/stored-schemas.js +29 -0
- package/node_modules/@seance/core/dist/stored-schemas.js.map +1 -0
- package/node_modules/@seance/core/dist/structural-questions.d.ts +31 -0
- package/node_modules/@seance/core/dist/structural-questions.js +575 -0
- package/node_modules/@seance/core/dist/structural-questions.js.map +1 -0
- package/node_modules/@seance/core/dist/structure-map-schema.d.ts +84 -0
- package/node_modules/@seance/core/dist/structure-map-schema.js +73 -0
- package/node_modules/@seance/core/dist/structure-map-schema.js.map +1 -0
- package/node_modules/@seance/core/dist/structure-map.d.ts +78 -0
- package/node_modules/@seance/core/dist/structure-map.js +750 -0
- package/node_modules/@seance/core/dist/structure-map.js.map +1 -0
- package/node_modules/@seance/core/dist/sync-changes.d.ts +38 -0
- package/node_modules/@seance/core/dist/sync-changes.js +89 -0
- package/node_modules/@seance/core/dist/sync-changes.js.map +1 -0
- package/node_modules/@seance/core/dist/sync-render.d.ts +28 -0
- package/node_modules/@seance/core/dist/sync-render.js +113 -0
- package/node_modules/@seance/core/dist/sync-render.js.map +1 -0
- package/node_modules/@seance/core/dist/terminal-text.d.ts +8 -0
- package/node_modules/@seance/core/dist/terminal-text.js +33 -0
- package/node_modules/@seance/core/dist/terminal-text.js.map +1 -0
- package/node_modules/@seance/core/dist/write-plan.d.ts +51 -0
- package/node_modules/@seance/core/dist/write-plan.js +173 -0
- package/node_modules/@seance/core/dist/write-plan.js.map +1 -0
- package/node_modules/@seance/core/package.json +26 -0
- package/package.json +42 -6
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// Where `seance quiz` and `seance review` get their questions and grades from: structural questions and keyword grading
|
|
2
|
+
// (no network), the user's own AI providers through @seance/ai, or the Seance hosted API (Task 8), all behind the same interface.
|
|
3
|
+
import { generateQuiz, gradeExplanation } from "@seance/ai";
|
|
4
|
+
import { AI_LIMITS, BLANK_ANSWER_FEEDBACK, DECISIONS_PATH, QuizItemSchema, decisionPromptText, fillQuiz, fitQuizFiles, generateStructuralQuestions, isBlankAnswer, keywordGrade, parseGradeResponse, parseQuizResponse, } from "@seance/core";
|
|
5
|
+
const QUESTION_COUNT = 5;
|
|
6
|
+
/** Provider names without repeats, in chain order. */
|
|
7
|
+
function providerLabel(config) {
|
|
8
|
+
const names = [...new Set(config.providers.map((provider) => provider.name))];
|
|
9
|
+
return names.length === 0 ? "none" : names.join(", ");
|
|
10
|
+
}
|
|
11
|
+
function explainRubric(item) {
|
|
12
|
+
if (item.kind !== "explain" || item.rubric === undefined)
|
|
13
|
+
throw new RangeError("grade needs an explain question with a rubric");
|
|
14
|
+
return item.rubric;
|
|
15
|
+
}
|
|
16
|
+
/** Grades by keywords only (no network). A blank answer is a sure 0. */
|
|
17
|
+
function gradeByKeywords(item, answer) {
|
|
18
|
+
const rubric = explainRubric(item);
|
|
19
|
+
if (answer.length > AI_LIMITS.maxAnswerChars)
|
|
20
|
+
throw new RangeError("the answer is too long");
|
|
21
|
+
if (isBlankAnswer(answer))
|
|
22
|
+
return { score: 0, feedback: BLANK_ANSWER_FEEDBACK, rough: false };
|
|
23
|
+
const { score, covered } = keywordGrade(rubric, answer);
|
|
24
|
+
const missing = rubric.keyPoints.filter((_point, index) => !covered.includes(index));
|
|
25
|
+
const head = `Matched ${covered.length} of ${rubric.keyPoints.length} key points by keywords.`;
|
|
26
|
+
const tail = missing.length > 0 ? ` Not found: ${missing.join("; ")}.` : "";
|
|
27
|
+
return { score, feedback: `${head}${tail}`.slice(0, AI_LIMITS.maxFeedbackChars), rough: true };
|
|
28
|
+
}
|
|
29
|
+
function structuralBackend(source) {
|
|
30
|
+
return {
|
|
31
|
+
source,
|
|
32
|
+
sendsCode: false,
|
|
33
|
+
label: "none",
|
|
34
|
+
destination: "this computer",
|
|
35
|
+
makeQuiz: async (input) => {
|
|
36
|
+
const questions = [];
|
|
37
|
+
for (const question of generateStructuralQuestions(input.map, { count: QUESTION_COUNT, seed: input.seed, attempt: input.attempt })) {
|
|
38
|
+
const item = QuizItemSchema.safeParse({ ...question, origin: "structural" });
|
|
39
|
+
if (item.success)
|
|
40
|
+
questions.push(item.data);
|
|
41
|
+
}
|
|
42
|
+
return { questions, servedBy: "structural" };
|
|
43
|
+
},
|
|
44
|
+
grade: async (item, answer) => gradeByKeywords(item, answer),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/** The hosted backend: asks the Seance API, and uses the structural questions or keyword grading when the API fails (requirements 9.7, 9.8). */
|
|
48
|
+
function hostedBackend(hosted, warn) {
|
|
49
|
+
const local = structuralBackend("structural");
|
|
50
|
+
return {
|
|
51
|
+
source: "hosted",
|
|
52
|
+
sendsCode: true,
|
|
53
|
+
label: hosted.host,
|
|
54
|
+
destination: `the Seance API (${hosted.host})`,
|
|
55
|
+
makeQuiz: async (input) => {
|
|
56
|
+
const fallback = await local.makeQuiz(input);
|
|
57
|
+
// The decision text is sent and counted in the body size only when there is a decision; its question may then point at DECISIONS.md.
|
|
58
|
+
const decision = input.decision === undefined ? undefined : decisionPromptText(input.decision);
|
|
59
|
+
const fit = fitQuizFiles(input.files, { seed: input.seed, attempt: input.attempt, ...(decision === undefined ? {} : { decision }) });
|
|
60
|
+
if (fit.files.length === 0)
|
|
61
|
+
return fallback;
|
|
62
|
+
const reply = await hosted.post("/api/quiz", { files: fit.files, seed: input.seed, attempt: input.attempt, ...(decision === undefined ? {} : { decision }) });
|
|
63
|
+
const sentPaths = fit.files.map((file) => file.path);
|
|
64
|
+
const parsed = reply.ok ? parseQuizResponse(reply.json, decision === undefined ? sentPaths : [...sentPaths, DECISIONS_PATH]) : null;
|
|
65
|
+
if (parsed === null) {
|
|
66
|
+
warn(`Seance API unavailable (${reply.ok ? "invalid reply" : reply.reason}); questions from the code structure`);
|
|
67
|
+
return fallback;
|
|
68
|
+
}
|
|
69
|
+
// 1-4 valid questions are topped up with local structural ones, as for the local AI chain; more than 5 are cut to 5 (changed after review).
|
|
70
|
+
const questions = parsed.questions.length >= QUESTION_COUNT ? parsed.questions.slice(0, QUESTION_COUNT) : fillQuiz(parsed.questions, generateStructuralQuestions(input.map, { count: QUESTION_COUNT * 2, seed: input.seed, attempt: input.attempt }));
|
|
71
|
+
return { questions, servedBy: parsed.servedBy, ...(parsed.model === undefined ? {} : { model: parsed.model }) };
|
|
72
|
+
},
|
|
73
|
+
grade: async (item, answer) => {
|
|
74
|
+
const text = answer.slice(0, AI_LIMITS.maxAnswerChars);
|
|
75
|
+
explainRubric(item);
|
|
76
|
+
if (isBlankAnswer(text))
|
|
77
|
+
return gradeByKeywords(item, text); // a blank answer is a sure 0: nothing is sent
|
|
78
|
+
const reply = await hosted.post("/api/grade", { item, answer: text });
|
|
79
|
+
const parsed = reply.ok ? parseGradeResponse(reply.json) : null;
|
|
80
|
+
if (parsed === null) {
|
|
81
|
+
warn(`Seance API unavailable (${reply.ok ? "invalid reply" : reply.reason}); graded by keywords`);
|
|
82
|
+
return gradeByKeywords(item, text);
|
|
83
|
+
}
|
|
84
|
+
return { score: parsed.score, feedback: parsed.feedback, rough: parsed.rough };
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Makes the backend for a source. `local-ai` calls `generateQuiz` and `gradeExplanation`, which fall back on their own.
|
|
90
|
+
* `hosted` needs `deps.hosted`; `deps.warn` receives the "API unavailable" lines.
|
|
91
|
+
*/
|
|
92
|
+
export function createBackend(source, deps) {
|
|
93
|
+
if (source === "hosted") {
|
|
94
|
+
if (deps.hosted === undefined)
|
|
95
|
+
throw new RangeError("the hosted source needs a HostedApi");
|
|
96
|
+
return hostedBackend(deps.hosted, deps.warn ?? (() => undefined));
|
|
97
|
+
}
|
|
98
|
+
if (source !== "local-ai")
|
|
99
|
+
return structuralBackend(source);
|
|
100
|
+
const chain = deps.clientFactory === undefined ? { config: deps.config } : { config: deps.config, clientFactory: deps.clientFactory };
|
|
101
|
+
return {
|
|
102
|
+
source,
|
|
103
|
+
sendsCode: true,
|
|
104
|
+
label: providerLabel(deps.config),
|
|
105
|
+
destination: `your AI providers (${providerLabel(deps.config)})`,
|
|
106
|
+
makeQuiz: async (input) => {
|
|
107
|
+
const quiz = await generateQuiz({ map: input.map, files: input.files, seed: input.seed, attempt: input.attempt, ...(input.decision === undefined ? {} : { decision: input.decision }) }, chain);
|
|
108
|
+
return { questions: quiz.questions, servedBy: quiz.servedBy, ...(quiz.model === undefined ? {} : { model: quiz.model }) };
|
|
109
|
+
},
|
|
110
|
+
grade: async (item, answer) => {
|
|
111
|
+
const grade = await gradeExplanation(item, answer, chain);
|
|
112
|
+
return { score: grade.score, feedback: grade.feedback, rough: grade.rough };
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=quiz-backend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quiz-backend.js","sourceRoot":"","sources":["../src/quiz-backend.ts"],"names":[],"mappings":"AAAA,wHAAwH;AACxH,kIAAkI;AAClI,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAwC,MAAM,YAAY,CAAC;AAClG,OAAO,EACL,SAAS,EACT,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,EAAE,MAAM,EAAE,EAAE;YAC5B,MAAM,KAAK,GAAG,MAAM,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;YAC1D,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;QAC9E,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { QuizItem, SourceFile, StructureMap } from "@seance/core";
|
|
2
|
+
import type { GitRunner } from "./git.js";
|
|
3
|
+
/** The paths to quiz on: the pending quiz's files, else the JS/TS files git knows. `undefined` when git cannot answer. */
|
|
4
|
+
export declare function choosePaths(git: GitRunner, pendingFiles: readonly string[] | undefined): Promise<string[] | undefined>;
|
|
5
|
+
/** Reads the files (100 KB each and in total) and builds the structure map; a throw gives an empty map. */
|
|
6
|
+
export declare function readMap(root: string, paths: readonly string[]): Promise<{
|
|
7
|
+
map: StructureMap;
|
|
8
|
+
files: SourceFile[];
|
|
9
|
+
bytes: number;
|
|
10
|
+
}>;
|
|
11
|
+
/** Keeps the questions that pass the schema, with unique ids, at most 10. */
|
|
12
|
+
export declare function usable(questions: readonly QuizItem[]): QuizItem[];
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// What `seance quiz` and the MCP `start_quiz` tool quiz on: which files, the structure map read from them, and which questions are usable.
|
|
2
|
+
// Moved unchanged from commands/quiz.ts in Task 11, except that `choosePaths` returns undefined instead of stopping the command.
|
|
3
|
+
import { MAP_LIMITS, QuizItemSchema, buildStructureMap, parseNulPaths, pickQuizFiles } from "@seance/core";
|
|
4
|
+
import { readExisting } from "./init-fs.js";
|
|
5
|
+
import { isSafeRelativePath } from "./quiz-ui.js";
|
|
6
|
+
const MAX_FILE_BYTES = 102_400;
|
|
7
|
+
const MAX_SESSION_QUESTIONS = 10;
|
|
8
|
+
/** The paths to quiz on: the pending quiz's files, else the JS/TS files git knows. `undefined` when git cannot answer. */
|
|
9
|
+
export async function choosePaths(git, pendingFiles) {
|
|
10
|
+
if (pendingFiles !== undefined)
|
|
11
|
+
return pickQuizFiles(pendingFiles.filter(isSafeRelativePath));
|
|
12
|
+
const listed = await git(["ls-files", "-z", "--cached", "--others", "--exclude-standard"]);
|
|
13
|
+
if (!listed.ok)
|
|
14
|
+
return undefined;
|
|
15
|
+
return pickQuizFiles(parseNulPaths(listed.stdout).filter(isSafeRelativePath));
|
|
16
|
+
}
|
|
17
|
+
/** Reads the files (100 KB each and in total) and builds the structure map; a throw gives an empty map. */
|
|
18
|
+
export async function readMap(root, paths) {
|
|
19
|
+
const files = [];
|
|
20
|
+
let bytes = 0;
|
|
21
|
+
for (const path of paths) {
|
|
22
|
+
const read = await readExisting(root, path, MAX_FILE_BYTES);
|
|
23
|
+
if (read?.type !== "file")
|
|
24
|
+
continue; // missing, too large, not UTF-8 or unsafe: skipped
|
|
25
|
+
const size = Buffer.byteLength(read.content);
|
|
26
|
+
if (bytes + size > MAP_LIMITS.maxTotalBytes)
|
|
27
|
+
break;
|
|
28
|
+
bytes += size;
|
|
29
|
+
files.push({ path, content: read.content });
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
return { map: buildStructureMap(files), files, bytes };
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return { map: { schemaVersion: 1, files: [] }, files: [], bytes: 0 };
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** Keeps the questions that pass the schema, with unique ids, at most 10. */
|
|
39
|
+
export function usable(questions) {
|
|
40
|
+
const seen = new Set();
|
|
41
|
+
const kept = [];
|
|
42
|
+
for (const item of questions) {
|
|
43
|
+
if (seen.has(item.id) || !QuizItemSchema.safeParse(item).success)
|
|
44
|
+
continue;
|
|
45
|
+
seen.add(item.id);
|
|
46
|
+
kept.push(item);
|
|
47
|
+
if (kept.length === MAX_SESSION_QUESTIONS)
|
|
48
|
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@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { DecisionEntry, GateMode, SeanceState } from "@seance/core";
|
|
2
|
+
import { type WriteOps } from "./init-fs.js";
|
|
3
|
+
export type StateRead = {
|
|
4
|
+
ok: true;
|
|
5
|
+
state: SeanceState;
|
|
6
|
+
text: string | undefined;
|
|
7
|
+
} | {
|
|
8
|
+
ok: false;
|
|
9
|
+
};
|
|
10
|
+
/** The state file: a missing file is an empty state; anything unreadable, too large, not JSON or not matching the schema is `ok: false`. */
|
|
11
|
+
export declare function readState(root: string): Promise<StateRead>;
|
|
12
|
+
/**
|
|
13
|
+
* The latest DECISIONS.md entry, only when it has Chose and Why. Missing, not a regular UTF-8 file, over 256 KB or without a
|
|
14
|
+
* usable entry gives undefined. Never throws (Task 13, req 11.1 and 11.2).
|
|
15
|
+
*/
|
|
16
|
+
export declare function readDecision(root: string): Promise<DecisionEntry | undefined>;
|
|
17
|
+
/** The gate from the config file. Missing: soft 0.7 silently. Invalid: soft 0.7 and a warning line. */
|
|
18
|
+
export declare function readGate(root: string): Promise<{
|
|
19
|
+
mode: GateMode;
|
|
20
|
+
passMark: number;
|
|
21
|
+
warning?: string;
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* Applies `apply` to the state that was read and writes the result. When the file changed since it was read, reads it again,
|
|
25
|
+
* applies the same change once more and writes again; a second change, or an invalid file, gives `conflict`.
|
|
26
|
+
* A write error throws (the caller prints the code); no temporary file is left behind.
|
|
27
|
+
*/
|
|
28
|
+
export declare function saveWithRetry(root: string, read: StateRead & {
|
|
29
|
+
ok: true;
|
|
30
|
+
}, apply: (state: SeanceState) => SeanceState, ops?: Partial<WriteOps>): Promise<"written" | "conflict">;
|
package/dist/quiz-io.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// File access of `seance quiz` and `seance review`: read `.seance/state.json` and the gate settings from `.seance/config.json`,
|
|
2
|
+
// and save the new state with one merge retry when the file changed meanwhile. Reads and writes go through init-fs.ts.
|
|
3
|
+
import { DECISIONS_PATH, DECISION_LIMITS, DEFAULT_PASS_MARK, STATE_LIMITS, STATE_PATH, SeanceConfigSchema, SeanceStateSchema, emptyState, firstIssuePath, hasChoice, latestDecision, parseDecisionLog, serializeState, } from "@seance/core";
|
|
4
|
+
import { REAL_WRITE_OPS, readExisting, writeAtomic } from "./init-fs.js";
|
|
5
|
+
const CONFIG_PATH = ".seance/config.json";
|
|
6
|
+
const MAX_CONFIG_BYTES = 65_536;
|
|
7
|
+
/** The state file: a missing file is an empty state; anything unreadable, too large, not JSON or not matching the schema is `ok: false`. */
|
|
8
|
+
export async function readState(root) {
|
|
9
|
+
const found = await readExisting(root, STATE_PATH, STATE_LIMITS.maxBytes);
|
|
10
|
+
if (found === undefined)
|
|
11
|
+
return { ok: true, state: emptyState(), text: undefined };
|
|
12
|
+
if (found.type !== "file")
|
|
13
|
+
return { ok: false };
|
|
14
|
+
try {
|
|
15
|
+
const parsed = SeanceStateSchema.safeParse(JSON.parse(found.content));
|
|
16
|
+
return parsed.success ? { ok: true, state: parsed.data, text: found.content } : { ok: false };
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return { ok: false };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The latest DECISIONS.md entry, only when it has Chose and Why. Missing, not a regular UTF-8 file, over 256 KB or without a
|
|
24
|
+
* usable entry gives undefined. Never throws (Task 13, req 11.1 and 11.2).
|
|
25
|
+
*/
|
|
26
|
+
export async function readDecision(root) {
|
|
27
|
+
try {
|
|
28
|
+
const found = await readExisting(root, DECISIONS_PATH, DECISION_LIMITS.maxFileBytes);
|
|
29
|
+
if (found?.type !== "file")
|
|
30
|
+
return undefined;
|
|
31
|
+
const entry = latestDecision(parseDecisionLog(found.content));
|
|
32
|
+
return entry !== undefined && hasChoice(entry) ? entry : undefined;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** The gate from the config file. Missing: soft 0.7 silently. Invalid: soft 0.7 and a warning line. */
|
|
39
|
+
export async function readGate(root) {
|
|
40
|
+
const fallback = { mode: "soft", passMark: DEFAULT_PASS_MARK };
|
|
41
|
+
const found = await readExisting(root, CONFIG_PATH, MAX_CONFIG_BYTES);
|
|
42
|
+
if (found === undefined)
|
|
43
|
+
return fallback;
|
|
44
|
+
const invalid = (where) => ({ ...fallback, warning: `${CONFIG_PATH} is invalid (${where}); using gate soft` });
|
|
45
|
+
if (found.type !== "file")
|
|
46
|
+
return invalid("not a regular UTF-8 file");
|
|
47
|
+
let json;
|
|
48
|
+
try {
|
|
49
|
+
json = JSON.parse(found.content);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return invalid("not JSON");
|
|
53
|
+
}
|
|
54
|
+
const parsed = SeanceConfigSchema.safeParse(json);
|
|
55
|
+
if (!parsed.success)
|
|
56
|
+
return invalid(firstIssuePath(parsed.error));
|
|
57
|
+
return { mode: parsed.data.gate.mode, passMark: parsed.data.gate.passMark };
|
|
58
|
+
}
|
|
59
|
+
/** Checks a new state against the schema and writes it. `written`, or `changed` when the file is not what was read. */
|
|
60
|
+
async function writeChecked(root, text, next, ops) {
|
|
61
|
+
if (!SeanceStateSchema.safeParse(next).success)
|
|
62
|
+
throw Object.assign(new Error("new state is not valid"), { code: "INVALID_STATE" });
|
|
63
|
+
const serialized = serializeState(next);
|
|
64
|
+
// The next read refuses a file over the limit, so do not write one (changed after review).
|
|
65
|
+
if (Buffer.byteLength(serialized) > STATE_LIMITS.maxBytes)
|
|
66
|
+
throw Object.assign(new Error("new state is too large"), { code: "STATE_TOO_LARGE" });
|
|
67
|
+
return writeAtomic(root, STATE_PATH, serialized, text, ops);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Applies `apply` to the state that was read and writes the result. When the file changed since it was read, reads it again,
|
|
71
|
+
* applies the same change once more and writes again; a second change, or an invalid file, gives `conflict`.
|
|
72
|
+
* A write error throws (the caller prints the code); no temporary file is left behind.
|
|
73
|
+
*/
|
|
74
|
+
export async function saveWithRetry(root, read, apply, ops = {}) {
|
|
75
|
+
const writeOps = { ...REAL_WRITE_OPS, ...ops };
|
|
76
|
+
if ((await writeChecked(root, read.text, apply(read.state), writeOps)) === "written")
|
|
77
|
+
return "written";
|
|
78
|
+
const again = await readState(root);
|
|
79
|
+
if (!again.ok)
|
|
80
|
+
return "conflict";
|
|
81
|
+
return (await writeChecked(root, again.text, apply(again.state), writeOps)) === "written" ? "written" : "conflict";
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=quiz-io.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quiz-io.js","sourceRoot":"","sources":["../src/quiz-io.ts"],"names":[],"mappings":"AAAA,gIAAgI;AAChI,uHAAuH;AACvH,OAAO,EACL,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,UAAU,EACV,kBAAkB,EAClB,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,SAAS,EACT,cAAc,EACd,gBAAgB,EAChB,cAAc,GACf,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,WAAW,EAAiB,MAAM,cAAc,CAAC;AAExF,MAAM,WAAW,GAAG,qBAAqB,CAAC;AAC1C,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAIhC,4IAA4I;AAC5I,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,IAAY;IAC1C,MAAM,KAAK,GAAG,MAAM,YAAY,CAAC,IAAI,EAAE,UAAU,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC;IAC1E,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;IACnF,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM;QAAE,OAAO,EAAE,EAAE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,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,wBAAwB,CAAC,EAAE,EAAE,IAAI,EAAE,iBAAiB,EAAE,CAAC,CAAC;IACjJ,OAAO,WAAW,CAAC,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;AAC9D,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,IAAY,EACZ,IAA8B,EAC9B,KAA0C,EAC1C,GAAG,GAAsB,EAAE;IAE3B,MAAM,QAAQ,GAAa,EAAE,GAAG,cAAc,EAAE,GAAG,GAAG,EAAE,CAAC;IACzD,IAAI,CAAC,MAAM,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,CAAC,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACvG,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,CAAC;IACpC,IAAI,CAAC,KAAK,CAAC,EAAE;QAAE,OAAO,UAAU,CAAC;IACjC,OAAO,CAAC,MAAM,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC;AACrH,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AnswerOutcome, QuizItem } from "@seance/core";
|
|
2
|
+
import type { Prompter } from "./prompter.js";
|
|
3
|
+
import type { QuizBackend } from "./quiz-backend.js";
|
|
4
|
+
export declare function isDirectory(path: string): Promise<boolean>;
|
|
5
|
+
/** The local calendar date as YYYY-MM-DD: `dueAt` is a date the user reads (open question 15). */
|
|
6
|
+
export declare function localDate(now: Date): string;
|
|
7
|
+
export declare function plural(count: number, one: string, many: string): string;
|
|
8
|
+
export { isSafeRelativePath } from "@seance/core";
|
|
9
|
+
export interface AskContext {
|
|
10
|
+
prompter: Prompter;
|
|
11
|
+
out: (line: string) => void;
|
|
12
|
+
backend: QuizBackend;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Asks one question and returns the outcome. A choice question is a `select` (values "0".."3"); an explain question is a `text`
|
|
16
|
+
* graded by `backend.grade`. `beforeGrade` runs just before a grade call, so the caller can print its network notice once.
|
|
17
|
+
*/
|
|
18
|
+
export declare function askQuestion(ctx: AskContext, item: QuizItem, label: string, beforeGrade?: () => void): Promise<AnswerOutcome>;
|
package/dist/quiz-ui.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Small helpers shared by `seance quiz` and `seance review`: the local date, a check for paths read from the state file,
|
|
2
|
+
// and asking one question (print, prompt, check or grade) through the Prompter. Every text from outside goes through toPlainText.
|
|
3
|
+
import { stat } from "node:fs/promises";
|
|
4
|
+
import { AI_LIMITS, BLANK_ANSWER_FEEDBACK, isBlankAnswer, toPlainText } from "@seance/core";
|
|
5
|
+
export async function isDirectory(path) {
|
|
6
|
+
try {
|
|
7
|
+
return (await stat(path)).isDirectory();
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/** The local calendar date as YYYY-MM-DD: `dueAt` is a date the user reads (open question 15). */
|
|
14
|
+
export function localDate(now) {
|
|
15
|
+
const pad = (value) => String(value).padStart(2, "0");
|
|
16
|
+
return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`;
|
|
17
|
+
}
|
|
18
|
+
export function plural(count, one, many) {
|
|
19
|
+
return count === 1 ? one : many;
|
|
20
|
+
}
|
|
21
|
+
// Moved to @seance/core in Task 11 (the MCP views use it too); re-exported so the CLI imports stay the same.
|
|
22
|
+
// Paths come from `.seance/state.json` or git, so they are checked before a file is read and sent to a provider.
|
|
23
|
+
export { isSafeRelativePath } from "@seance/core";
|
|
24
|
+
/**
|
|
25
|
+
* Asks one question and returns the outcome. A choice question is a `select` (values "0".."3"); an explain question is a `text`
|
|
26
|
+
* graded by `backend.grade`. `beforeGrade` runs just before a grade call, so the caller can print its network notice once.
|
|
27
|
+
*/
|
|
28
|
+
export async function askQuestion(ctx, item, label, beforeGrade) {
|
|
29
|
+
const header = toPlainText(`${label} [${item.concept}] ${item.source?.path ?? ""}`);
|
|
30
|
+
const prompt = toPlainText(item.prompt);
|
|
31
|
+
if (item.kind === "explain") {
|
|
32
|
+
const typed = await ctx.prompter.text({ id: `answer:${item.id}`, message: `${header}\n${prompt}`, maxLength: AI_LIMITS.maxAnswerChars });
|
|
33
|
+
// A blank answer scores 0 here (changed Dec 2 after manual test): no backend call and no "sending your answers" notice.
|
|
34
|
+
const blank = isBlankAnswer(typed);
|
|
35
|
+
if (!blank)
|
|
36
|
+
beforeGrade?.();
|
|
37
|
+
const grade = blank ? { score: 0, feedback: BLANK_ANSWER_FEEDBACK, rough: false } : await ctx.backend.grade(item, typed.slice(0, AI_LIMITS.maxAnswerChars));
|
|
38
|
+
ctx.out(`Explanation score: ${Math.round(grade.score * 100)}%${grade.rough ? " (rough keyword match)" : ""}`);
|
|
39
|
+
const feedback = toPlainText(grade.feedback);
|
|
40
|
+
if (feedback !== "")
|
|
41
|
+
ctx.out(feedback);
|
|
42
|
+
return { questionId: item.id, kind: "graded", score: grade.score, rough: grade.rough };
|
|
43
|
+
}
|
|
44
|
+
const choices = item.choices.map((choice, index) => ({ value: String(index), name: toPlainText(choice) || "(empty)" }));
|
|
45
|
+
const picked = await ctx.prompter.select({ id: `answer:${item.id}`, message: `${header}\n${prompt}`, choices });
|
|
46
|
+
const choiceIndex = Number(picked);
|
|
47
|
+
const correct = choiceIndex === item.answerIndex;
|
|
48
|
+
ctx.out(correct ? "Correct." : `Not quite. The answer is: ${choices[item.answerIndex]?.name ?? ""}`);
|
|
49
|
+
return { questionId: item.id, kind: "choice", choiceIndex, correct };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O,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;IACzF,CAAC;IACD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,IAAI,SAAS,EAAE,CAAC,CAAC,CAAC;IACxH,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,UAAU,IAAI,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,GAAG,MAAM,KAAK,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;IAChH,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IACnC,MAAM,OAAO,GAAG,WAAW,KAAK,IAAI,CAAC,WAAW,CAAC;IACjD,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,6BAA6B,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC;IACrG,OAAO,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC;AACvE,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vedant Hande
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Checked } from "@seance/core";
|
|
2
|
+
import type { ChainConfig, ChatRequest, ClientFactory, ProviderName } from "./providers.js";
|
|
3
|
+
export type Outcome = "ok" | "timeout" | "network" | "http" | "empty" | "not-json" | "oversize" | "invalid" | "semantic" | "no-time";
|
|
4
|
+
/** What happened with one (provider, model) pair. Only these facts are kept (req 2.8); model names are not secret. */
|
|
5
|
+
export interface Attempt {
|
|
6
|
+
provider: ProviderName;
|
|
7
|
+
model: string;
|
|
8
|
+
outcome: Outcome;
|
|
9
|
+
ms: number;
|
|
10
|
+
status?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface ChainDeps {
|
|
13
|
+
config: ChainConfig;
|
|
14
|
+
clientFactory?: ClientFactory;
|
|
15
|
+
now?: () => number;
|
|
16
|
+
}
|
|
17
|
+
export type ChainResult<T> = {
|
|
18
|
+
ok: true;
|
|
19
|
+
value: T;
|
|
20
|
+
servedBy: ProviderName;
|
|
21
|
+
model: string;
|
|
22
|
+
attempts: Attempt[];
|
|
23
|
+
} | {
|
|
24
|
+
ok: false;
|
|
25
|
+
attempts: Attempt[];
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Tries the configured (provider, model) pairs in order and returns the first reply that passes `check`.
|
|
29
|
+
* Each pair is tried at most once; there are no retries (the next pair is the retry).
|
|
30
|
+
*/
|
|
31
|
+
export declare function runChain<T>(req: ChatRequest, check: (json: unknown) => Checked<T>, deps: ChainDeps): Promise<ChainResult<T>>;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// The provider chain: try every model of Gemini, then of NVIDIA, then of OpenRouter, with a time budget for each call
|
|
2
|
+
// and for the whole chain. The first (provider, model) pair whose reply passes the checks wins. It never throws and never records keys, prompts or replies.
|
|
3
|
+
import { AI_LIMITS, extractJson } from "@seance/core";
|
|
4
|
+
import { createOpenAiClientFactory, DEFAULT_CHAIN_TIMEOUT_MS, DEFAULT_PROVIDER_TIMEOUT_MS, ProviderCallError } from "./providers.js";
|
|
5
|
+
/** If less time than this is left in the chain, the remaining providers are skipped (req 2.3). */
|
|
6
|
+
const MIN_BUDGET_MS = 500;
|
|
7
|
+
const encoder = new TextEncoder();
|
|
8
|
+
/** Is the content bigger than the limit? Checks the string length first, because that is cheap. */
|
|
9
|
+
function isOversize(content) {
|
|
10
|
+
const max = AI_LIMITS.maxContentBytes;
|
|
11
|
+
if (content.length > max)
|
|
12
|
+
return true;
|
|
13
|
+
// One UTF-16 unit is at most 3 bytes in UTF-8, so only longer strings can be over the limit.
|
|
14
|
+
return content.length * 3 > max && encoder.encode(content).length > max;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Calls the client and waits at most `budgetMs`. Two things stop a slow call: the AbortSignal (a client that
|
|
18
|
+
* listens to it stops) and the race (a client that ignores it still loses at the same moment).
|
|
19
|
+
*/
|
|
20
|
+
async function callWithBudget(client, req, budgetMs) {
|
|
21
|
+
const controller = new AbortController();
|
|
22
|
+
let timer;
|
|
23
|
+
const timedOut = new Promise((_resolve, reject) => {
|
|
24
|
+
timer = setTimeout(() => {
|
|
25
|
+
controller.abort();
|
|
26
|
+
reject(new ProviderCallError("timeout"));
|
|
27
|
+
}, budgetMs);
|
|
28
|
+
});
|
|
29
|
+
try {
|
|
30
|
+
return await Promise.race([client().complete(req, controller.signal), timedOut]);
|
|
31
|
+
}
|
|
32
|
+
finally {
|
|
33
|
+
clearTimeout(timer);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** A timeout that is a positive, finite number, or the default. `readChainConfig` always gives one; a hand-made config might not. */
|
|
37
|
+
function positiveOr(value, fallback) {
|
|
38
|
+
return Number.isFinite(value) && value > 0 ? value : fallback;
|
|
39
|
+
}
|
|
40
|
+
/** The error a client threw, as an outcome. Only the kind and the HTTP status are used, never the message. */
|
|
41
|
+
function outcomeOfError(error) {
|
|
42
|
+
if (error instanceof ProviderCallError) {
|
|
43
|
+
return error.kind === "http" && error.status !== undefined
|
|
44
|
+
? { outcome: "http", status: error.status }
|
|
45
|
+
: { outcome: error.kind };
|
|
46
|
+
}
|
|
47
|
+
return { outcome: "network" };
|
|
48
|
+
}
|
|
49
|
+
/** Checks the content: not empty, not too big, valid JSON, then the caller's own check. */
|
|
50
|
+
function checkContent(content, check) {
|
|
51
|
+
if (typeof content !== "string" || content.trim() === "")
|
|
52
|
+
return { outcome: "empty" };
|
|
53
|
+
if (isOversize(content))
|
|
54
|
+
return { outcome: "oversize" }; // before JSON.parse and zod (req 2.5)
|
|
55
|
+
const json = extractJson(content);
|
|
56
|
+
if (!json.ok)
|
|
57
|
+
return { outcome: json.reason };
|
|
58
|
+
try {
|
|
59
|
+
const checked = check(json.value);
|
|
60
|
+
return checked.ok ? { outcome: "ok", value: checked.value } : { outcome: checked.reason };
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return { outcome: "invalid" }; // a check must not throw; if it does, the reply is unusable
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async function tryProvider(provider, req, check, budgetMs, factory) {
|
|
67
|
+
try {
|
|
68
|
+
const content = await callWithBudget(() => factory(provider, budgetMs), req, budgetMs);
|
|
69
|
+
return checkContent(content, check);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
return outcomeOfError(error);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Tries the configured (provider, model) pairs in order and returns the first reply that passes `check`.
|
|
77
|
+
* Each pair is tried at most once; there are no retries (the next pair is the retry).
|
|
78
|
+
*/
|
|
79
|
+
export async function runChain(req, check, deps) {
|
|
80
|
+
const now = deps.now ?? Date.now;
|
|
81
|
+
const factory = deps.clientFactory ?? createOpenAiClientFactory();
|
|
82
|
+
const { providers } = deps.config;
|
|
83
|
+
const providerTimeoutMs = positiveOr(deps.config.providerTimeoutMs, DEFAULT_PROVIDER_TIMEOUT_MS);
|
|
84
|
+
const chainTimeoutMs = positiveOr(deps.config.chainTimeoutMs, DEFAULT_CHAIN_TIMEOUT_MS);
|
|
85
|
+
const attempts = [];
|
|
86
|
+
const chainStart = now();
|
|
87
|
+
// Chain loop: one pass over the (provider, model) pairs, in order, stopping at the first success.
|
|
88
|
+
for (const [index, provider] of providers.entries()) {
|
|
89
|
+
// Time maths: a pair gets its own limit, or what is left of the chain, whichever is smaller.
|
|
90
|
+
// Example: chain 36 000 ms, limit 15 000 ms: the 1st gets 15 000, the 2nd 15 000, the 3rd min(15 000, 6 000) = 6 000.
|
|
91
|
+
// With the defaults (30 000 / 15 000) two hanging targets use the whole chain and the 3rd gets no-time.
|
|
92
|
+
// A 429 fails in a few ms, so the next model of the same provider still gets almost the whole budget.
|
|
93
|
+
const remainingMs = chainTimeoutMs - (now() - chainStart);
|
|
94
|
+
if (remainingMs < MIN_BUDGET_MS) {
|
|
95
|
+
// Not enough time left for a useful call: mark this pair and all later ones, call none of them.
|
|
96
|
+
for (const skipped of providers.slice(index)) {
|
|
97
|
+
attempts.push({ provider: skipped.name, model: skipped.model, outcome: "no-time", ms: 0 });
|
|
98
|
+
}
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
const budgetMs = Math.min(providerTimeoutMs, remainingMs);
|
|
102
|
+
const started = now();
|
|
103
|
+
const result = await tryProvider(provider, req, check, budgetMs, factory);
|
|
104
|
+
const ms = Math.max(0, Math.round(now() - started));
|
|
105
|
+
const attempt = { provider: provider.name, model: provider.model, outcome: result.outcome, ms };
|
|
106
|
+
if (result.outcome !== "ok" && result.status !== undefined)
|
|
107
|
+
attempt.status = result.status;
|
|
108
|
+
attempts.push(attempt);
|
|
109
|
+
if (result.outcome === "ok")
|
|
110
|
+
return { ok: true, value: result.value, servedBy: provider.name, model: provider.model, attempts };
|
|
111
|
+
}
|
|
112
|
+
return { ok: false, attempts };
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=chain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain.js","sourceRoot":"","sources":["../src/chain.ts"],"names":[],"mappings":"AAAA,sHAAsH;AACtH,4JAA4J;AAC5J,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEtD,OAAO,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,2BAA2B,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAwBrI,kGAAkG;AAClG,MAAM,aAAa,GAAG,GAAG,CAAC;AAE1B,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAKlC,mGAAmG;AACnG,SAAS,UAAU,CAAC,OAAe;IACjC,MAAM,GAAG,GAAG,SAAS,CAAC,eAAe,CAAC;IACtC,IAAI,OAAO,CAAC,MAAM,GAAG,GAAG;QAAE,OAAO,IAAI,CAAC;IACtC,6FAA6F;IAC7F,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,GAAG,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO,CAA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AAQ,GAAG,IAAI,CAAC,GAAG,CAAC,iBAAiB,EAAE,WAAW,CAAC,CAAC;QAE1D,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC;QACtB,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;QAC1E,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC;QACpD,MAAM,OAAO,GAAY,EAAE,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,EAAE,EAAE,CAAC;QACzG,IAAI,MAAM,CAAC,OAAO,KAAK,IAAI,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS;YAAE,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC3F,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAEvB,IAAI,MAAM,CAAC,OAAO,KAAK,IAAI;YAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClI,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { QuizItem } from "@seance/core";
|
|
2
|
+
import type { Attempt, ChainDeps } from "./chain.js";
|
|
3
|
+
import type { ProviderName } from "./providers.js";
|
|
4
|
+
export interface Grade {
|
|
5
|
+
score: number;
|
|
6
|
+
feedback: string;
|
|
7
|
+
servedBy: ProviderName | "keyword";
|
|
8
|
+
/** The model that answered; left out when `servedBy` is `keyword`. */
|
|
9
|
+
model?: string;
|
|
10
|
+
/** True when the score comes from keyword matching, which is only a rough guess. */
|
|
11
|
+
rough: boolean;
|
|
12
|
+
attempts: Attempt[];
|
|
13
|
+
}
|
|
14
|
+
export declare function gradeExplanation(question: QuizItem, answerText: string, deps: ChainDeps): Promise<Grade>;
|