@narumitw/pi-plan-mode 0.50.1 → 0.51.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.
- package/README.md +239 -130
- package/dist/chunks/{chunk-6SDTCIHD.ts → chunk-H3RGWRY7.ts} +68 -35
- package/dist/chunks/{chunk-6SDTCIHD.ts.map → chunk-H3RGWRY7.ts.map} +2 -2
- package/dist/chunks/{interactive-ui-JBSBPK6S.ts → interactive-ui-GFNX5OF4.ts} +2 -2
- package/dist/index.ts +2 -2
- package/package.json +4 -4
- package/src/question-tool.ts +90 -35
- /package/dist/chunks/{interactive-ui-JBSBPK6S.ts.map → interactive-ui-GFNX5OF4.ts.map} +0 -0
|
@@ -1177,6 +1177,7 @@ function isNodeError2(error) {
|
|
|
1177
1177
|
|
|
1178
1178
|
// src/question-tool.ts
|
|
1179
1179
|
var PLAN_MODE_QUESTION_TOOL_NAME = "plan_mode_question";
|
|
1180
|
+
var MAX_PLAN_MODE_RESPONSE_LENGTH = 4e3;
|
|
1180
1181
|
var PLAN_MODE_QUESTION_PARAMS = {
|
|
1181
1182
|
type: "object",
|
|
1182
1183
|
additionalProperties: false,
|
|
@@ -1309,43 +1310,75 @@ async function answerPlanModeQuestions(questions, ctx, lifecycle) {
|
|
|
1309
1310
|
return planModeQuestionAnswered(questions, answers);
|
|
1310
1311
|
}
|
|
1311
1312
|
async function askPlanModeQuestions(questions, ctx, shouldContinue = () => true) {
|
|
1312
|
-
const
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1313
|
+
const { runQuestionnaire, sanitizeTerminalText } = await import("@narumitw/pi-tui-kit");
|
|
1314
|
+
if (!shouldContinue()) return void 0;
|
|
1315
|
+
const runnerQuestions = questions.map((question, index) => ({
|
|
1316
|
+
id: String(index),
|
|
1317
|
+
header: displayText(question.header, `Question ${index + 1}`, sanitizeTerminalText),
|
|
1318
|
+
prompt: displayText(question.question, `Question ${index + 1}`, sanitizeTerminalText),
|
|
1319
|
+
options: question.options.map((option, optionIndex) => ({
|
|
1320
|
+
...option,
|
|
1321
|
+
label: displayText(option.label, `Option ${optionIndex + 1}`, sanitizeTerminalText)
|
|
1322
|
+
}))
|
|
1323
|
+
}));
|
|
1324
|
+
const result = await runQuestionnaire(ctx, {
|
|
1325
|
+
questions: runnerQuestions,
|
|
1326
|
+
allowNotes: true,
|
|
1327
|
+
maxTextLength: MAX_PLAN_MODE_RESPONSE_LENGTH,
|
|
1328
|
+
signal: ctx.signal,
|
|
1329
|
+
isCurrent: shouldContinue
|
|
1330
|
+
});
|
|
1331
|
+
if (!shouldContinue()) return void 0;
|
|
1332
|
+
return mapQuestionnaireResult(questions, result);
|
|
1333
|
+
}
|
|
1334
|
+
function mapQuestionnaireResult(questions, result) {
|
|
1335
|
+
if (result.kind !== "submitted") return void 0;
|
|
1336
|
+
if (result.answers.length !== questions.length) {
|
|
1337
|
+
throw new Error("Questionnaire returned an incomplete answer set");
|
|
1338
|
+
}
|
|
1339
|
+
const answers = /* @__PURE__ */ new Map();
|
|
1340
|
+
for (const answer of result.answers) {
|
|
1341
|
+
const index = Number(answer.questionId);
|
|
1342
|
+
if (!Number.isSafeInteger(index) || String(index) !== answer.questionId || !questions[index]) {
|
|
1343
|
+
throw new Error("Questionnaire returned an answer for an unknown question");
|
|
1332
1344
|
}
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
});
|
|
1345
|
+
if (answers.has(index)) throw new Error("Questionnaire returned duplicate answers");
|
|
1346
|
+
if (answer.wasCustom) {
|
|
1347
|
+
if (answer.optionIndex !== void 0) {
|
|
1348
|
+
throw new Error("Questionnaire returned a custom answer with an option index");
|
|
1349
|
+
}
|
|
1350
|
+
if (!answer.answer.trim()) return void 0;
|
|
1351
|
+
} else if (answer.optionIndex === void 0 || !questions[index]?.options[answer.optionIndex - 1]) {
|
|
1352
|
+
throw new Error("Questionnaire returned an invalid selected option");
|
|
1353
|
+
}
|
|
1354
|
+
answers.set(index, answer);
|
|
1344
1355
|
}
|
|
1345
|
-
return
|
|
1356
|
+
return questions.map((question, index) => {
|
|
1357
|
+
const answer = answers.get(index);
|
|
1358
|
+
if (!answer) throw new Error("Questionnaire returned an incomplete answer set");
|
|
1359
|
+
const answerText = answer.wasCustom ? answer.answer : question.options[(answer.optionIndex ?? 0) - 1]?.label ?? answer.answer;
|
|
1360
|
+
return answerFor(question, answerText, {
|
|
1361
|
+
wasCustom: answer.wasCustom,
|
|
1362
|
+
optionIndex: answer.optionIndex,
|
|
1363
|
+
note: answer.note
|
|
1364
|
+
});
|
|
1365
|
+
});
|
|
1346
1366
|
}
|
|
1347
|
-
function
|
|
1348
|
-
|
|
1367
|
+
function displayText(value, fallback, sanitize) {
|
|
1368
|
+
const sanitized = sanitize(value);
|
|
1369
|
+
return sanitized.trim() ? sanitized : fallback;
|
|
1370
|
+
}
|
|
1371
|
+
function answerFor(question, answer, options) {
|
|
1372
|
+
const result = {
|
|
1373
|
+
id: question.id,
|
|
1374
|
+
header: question.header,
|
|
1375
|
+
question: question.question,
|
|
1376
|
+
answer,
|
|
1377
|
+
wasCustom: options.wasCustom
|
|
1378
|
+
};
|
|
1379
|
+
if (options.optionIndex !== void 0) result.optionIndex = options.optionIndex;
|
|
1380
|
+
if (options.note !== void 0) result.note = options.note;
|
|
1381
|
+
return result;
|
|
1349
1382
|
}
|
|
1350
1383
|
function planModeQuestionAnswered(questions, answers) {
|
|
1351
1384
|
return {
|
|
@@ -1487,4 +1520,4 @@ export {
|
|
|
1487
1520
|
withRequiredPlanModeTools,
|
|
1488
1521
|
withoutRequiredPlanModeTools
|
|
1489
1522
|
};
|
|
1490
|
-
//# sourceMappingURL=chunk-
|
|
1523
|
+
//# sourceMappingURL=chunk-H3RGWRY7.ts.map
|