(str)
| 696 | return Array.isArray(val) ? val : [val] |
| 697 | } |
| 698 | function parseTaskFromText(str) { |
| 699 | const taskReqBody = {} |
| 700 | |
| 701 | const lines = str.split("\n") |
| 702 | if (lines.length === 0) { |
| 703 | return |
| 704 | } |
| 705 | |
| 706 | // Prompt |
| 707 | let knownKeyOnFirstLine = false |
| 708 | for (let key in TASK_TEXT_MAPPING) { |
| 709 | for (const name of getTaskTextLabels(key)) { |
| 710 | if (lines[0].startsWith(name + ":")) { |
| 711 | knownKeyOnFirstLine = true |
| 712 | break |
| 713 | } |
| 714 | } |
| 715 | if (knownKeyOnFirstLine) break |
| 716 | } |
| 717 | if (!knownKeyOnFirstLine) { |
| 718 | taskReqBody.prompt = lines[0] |
| 719 | console.log("Prompt:", taskReqBody.prompt) |
| 720 | } |
| 721 | |
| 722 | for (const key in TASK_TEXT_MAPPING) { |
| 723 | if (key in taskReqBody) { |
| 724 | continue |
| 725 | } |
| 726 | |
| 727 | let val = undefined |
| 728 | |
| 729 | for (const name of getTaskTextLabels(key)) { |
| 730 | const reName = new RegExp(`${escapeRegExp(name)}\\ *:\\ *(.*)(?:\\r\\n|\\r|\\n)*`, "igm") |
| 731 | const match = reName.exec(str) |
| 732 | if (match) { |
| 733 | str = str.slice(0, match.index) + str.slice(match.index + match[0].length) |
| 734 | val = match[1] |
| 735 | break |
| 736 | } |
| 737 | } |
| 738 | if (val !== undefined) { |
| 739 | taskReqBody[key] = TASK_MAPPING[key].parse(val.trim()) |
| 740 | console.log(TASK_MAPPING[key].name + ":", taskReqBody[key]) |
| 741 | if (!str) { |
| 742 | break |
| 743 | } |
| 744 | } |
| 745 | } |
| 746 | if (Object.keys(taskReqBody).length <= 0) { |
| 747 | return undefined |
| 748 | } |
| 749 | const task = { reqBody: taskReqBody } |
| 750 | if ("seed" in taskReqBody) { |
| 751 | task.seed = taskReqBody.seed |
| 752 | } |
| 753 | return task |
| 754 | } |
| 755 |
no test coverage detected