From 7b2b366cd4cea744ef1b542f2254a8aa4222fc7c Mon Sep 17 00:00:00 2001 From: Rick Hennigan Date: Tue, 21 Jan 2025 14:06:12 -0500 Subject: [PATCH] Bugfix: Attempt a `PacletDataRebuild[]` if `FrontEndResource["ChatbookStrings", name]` fails --- Source/Chatbook/Common.wl | 26 ++++++++++++++++++- .../PromptGenerators/RelatedDocumentation.wl | 19 ++++++++------ 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/Source/Chatbook/Common.wl b/Source/Chatbook/Common.wl index ac849efb..3a4deb25 100644 --- a/Source/Chatbook/Common.wl +++ b/Source/Chatbook/Common.wl @@ -1340,9 +1340,33 @@ tr // endDefinition; (*trRaw*) trRaw // beginDefinition; trRaw[ name_? StringQ ] /; $CloudEvaluation := cloudTextResource @ name; -trRaw[ name_? StringQ ] := FrontEndResource[ "ChatbookStrings", name ]; +trRaw[ name_? StringQ ] := chatbookString @ name; trRaw // endDefinition; +(* ::**************************************************************************************************************:: *) +(* ::Subsubsection::Closed:: *) +(*chatbookString*) +chatbookString // beginDefinition; + +chatbookString[ name_String ] := Enclose[ + Catch @ Module[ { string }, + string = ConfirmMatch[ usingFrontEnd @ FrontEndResource[ "ChatbookStrings", name ], _String|$Failed, "String" ]; + If[ StringQ @ string, Throw @ string ]; + pacletDataRebuild[ ]; + ConfirmBy[ usingFrontEnd @ FrontEndResource[ "ChatbookStrings", name ], StringQ, "Retry" ] + ], + throwInternalFailure +]; + +chatbookString // endDefinition; + +(* ::**************************************************************************************************************:: *) +(* ::Subsubsubsection::Closed:: *) +(*pacletDataRebuild*) +pacletDataRebuild // beginDefinition; +pacletDataRebuild[ ] := pacletDataRebuild[ ] = PacletDataRebuild[ ]; +pacletDataRebuild // endDefinition; + (* ::**************************************************************************************************************:: *) (* ::Subsection::Closed:: *) (*trStringTemplate*) diff --git a/Source/Chatbook/PromptGenerators/RelatedDocumentation.wl b/Source/Chatbook/PromptGenerators/RelatedDocumentation.wl index 9fd31a2b..3575f0cf 100644 --- a/Source/Chatbook/PromptGenerators/RelatedDocumentation.wl +++ b/Source/Chatbook/PromptGenerators/RelatedDocumentation.wl @@ -919,14 +919,17 @@ fetchDocumentationSnippets[ uris: { __String } ] := Enclose[ Module[ { count, text, $results, tasks }, count = Length @ uris; - text = ConfirmBy[ - If[ count === 1, - trStringTemplate[ "ProgressTextDownloadingSnippet" ][ count ], - trStringTemplate[ "ProgressTextDownloadingSnippets" ][ count ] - ], - StringQ, - "Text" - ]; + text = If[ $EvaluationEnvironment === "Session", + ConfirmBy[ + If[ count === 1, + trStringTemplate[ "ProgressTextDownloadingSnippet" ][ count ], + trStringTemplate[ "ProgressTextDownloadingSnippets" ][ count ] + ], + StringQ, + "Text" + ], + "" + ]; withApproximateProgress[ $results = AssociationMap[ <| "URI" -> #1 |> &, uris ];