Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v1.3.7 #513

Merged
merged 6 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion FrontEnd/StyleSheets/Chatbook.nb
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ Notebook[
],
Cell[
StyleData["ChatStyleSheetInformation"],
TaggingRules -> <|"StyleSheetVersion" -> "1.3.6.3913177292"|>
TaggingRules -> <|"StyleSheetVersion" -> "1.3.7.3913365950"|>
],
Cell[
StyleData["Text"],
Expand Down
2 changes: 1 addition & 1 deletion PacletInfo.wl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PacletObject[ <|
"Name" -> "Wolfram/Chatbook",
"PublisherID" -> "Wolfram",
"Version" -> "1.3.6",
"Version" -> "1.3.7",
"WolframVersion" -> "13.3+",
"Description" -> "Wolfram Notebooks + LLMs",
"License" -> "MIT",
Expand Down
38 changes: 31 additions & 7 deletions Source/Chatbook/Actions.wl
Original file line number Diff line number Diff line change
Expand Up @@ -902,12 +902,7 @@ scrape // endDefinition;
(*AttachCodeButtons*)
AttachCodeButtons // beginDefinition;

AttachCodeButtons[ attached_, cell0_CellObject, string_, lang_ ] :=
With[ { cell = parentCell @ cell0 },
AttachCodeButtons[ attached, cell, string, lang ] /; chatCodeBlockQ @ cell
];

AttachCodeButtons[ Dynamic[ attached_ ], cell_CellObject, string_, lang_ ] := (
AttachCodeButtons[ Dynamic[ attached_ ], cell_CellObject? chatCodeBlockQ, string_, lang_ ] := (
attached = AttachCell[
cell,
floatingButtonGrid[ attached, cell, lang ],
Expand All @@ -918,15 +913,44 @@ AttachCodeButtons[ Dynamic[ attached_ ], cell_CellObject, string_, lang_ ] := (
]
);

AttachCodeButtons[ attached_, cell_CellObject, string_, lang_ ] := Enclose[
Catch @ Module[ { parent, evalCell, newParent },
parent = parentCell @ cell;

(* The parent cell is the chat code block as expected, so attach there *)
If[ chatCodeBlockQ @ parent, Throw @ AttachCodeButtons[ attached, parent, string, lang ] ];

(* Otherwise, we have an EvaluationCell[] failure, so try to recover by retrying EvaluationCell[] *)
evalCell = ConfirmMatch[ (FinishDynamic[ ]; EvaluationCell[ ]), _CellObject, "EvaluationCell" ];

(* The chat code block should be the parent of the current evaluation cell *)
newParent = ConfirmBy[ parentCell @ evalCell, chatCodeBlockQ, "ParentCell" ];

(* Finish attaching now that we have the correct cell *)
AttachCodeButtons[ attached, newParent, string, lang ]
],
throwInternalFailure
];

AttachCodeButtons // endDefinition;

(* ::**************************************************************************************************************:: *)
(* ::Subsection::Closed:: *)
(*chatCodeBlockQ*)
chatCodeBlockQ // beginDefinition;
chatCodeBlockQ[ cell_CellObject ] := chatCodeBlockQ[ cell, Developer`CellInformation @ cell ];

(* Many operations that return cell objects can return $Failed, but error handling should be done elsewhere: *)
chatCodeBlockQ[ $Failed ] := False;

(* Cache the result, since we might be calling this multiple times on the same cell in AttachCodeButtons: *)
chatCodeBlockQ[ cell_CellObject ] := chatCodeBlockQ[ cell ] = chatCodeBlockQ[ cell, Developer`CellInformation @ cell ];

(* The expected style of a chat code block cell: *)
chatCodeBlockQ[ cell_, KeyValuePattern[ "Style" -> "ChatCodeBlock" ] ] := True;

(* Anything else means it's not a chat block: *)
chatCodeBlockQ[ cell_, _ ] := False;

chatCodeBlockQ // endDefinition;

(* ::**************************************************************************************************************:: *)
Expand Down
5 changes: 4 additions & 1 deletion Source/Chatbook/Explode.wl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Begin[ "`Private`" ];
Needs[ "Wolfram`Chatbook`" ];
Needs[ "Wolfram`Chatbook`Common`" ];

$$newCellStyle = "Section"|"Subsection"|"Subsubsection"|"Subsubsubsection"|"Item"|"Input"|"ExternalLanguage";
$$newCellStyle = "Section"|"Subsection"|"Subsubsection"|"Subsubsubsection"|"Item"|"Input"|"ExternalLanguage"|"Program";

(* ::**************************************************************************************************************:: *)
(* ::Section::Closed:: *)
Expand Down Expand Up @@ -70,6 +70,9 @@ $preprocessingRules := $preprocessingRules = Dispatch @ {
(* Remove "ChatCodeBlock" styling: *)
Cell[ BoxData[ cell_Cell, ___ ], "ChatCodeBlock", ___ ] :> cell,

(* Language-agnostic code blocks: *)
Cell[ text_, "ChatPreformatted", ___ ] :> Cell[ text, "Program" ],

(* Remove "ChatCodeBlockTemplate" template boxes: *)
TemplateBox[ { cell_Cell }, "ChatCodeBlockTemplate" ] :> cell,

Expand Down
2 changes: 1 addition & 1 deletion Source/Chatbook/Formatting.wl
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ inlineInteractiveCodeCell[ display_, string_, lang_ ] :=
],
TaggingRules -> <| "CellToStringType" -> "InlineInteractiveCodeCell", "CodeLanguage" -> lang |>,
UnsavedVariables :> { $CellContext`attached, $CellContext`cell },
Initialization :> { $CellContext`cell = EvaluationCell[ ] }
Initialization :> { $CellContext`cell = (FinishDynamic[ ]; EvaluationCell[ ]) }
];

inlineInteractiveCodeCell // endDefinition;
Expand Down