From cae905f3e215ad5a6fe792aeb0b6458bdae1cdc9 Mon Sep 17 00:00:00 2001 From: Rick Hennigan Date: Sat, 20 May 2023 13:14:46 -0400 Subject: [PATCH] Avoid loading extra package file at startup --- PacletInfo.wl | 8 +-- Source/Chatbook/Main.wl | 35 ++++++------ .../ServerSentEventUtils.wl | 2 +- Source/Chatbook/UI.wl | 4 +- Tests/SSETests.wlt | 53 ++++++++----------- 5 files changed, 44 insertions(+), 58 deletions(-) rename Source/{ServerSentEventUtils => Chatbook}/ServerSentEventUtils.wl (98%) diff --git a/PacletInfo.wl b/PacletInfo.wl index 1f808ff7..553a5c45 100644 --- a/PacletInfo.wl +++ b/PacletInfo.wl @@ -15,13 +15,7 @@ PacletObject[<| "PrimaryContext" -> "Wolfram`Chatbook`", "Extensions" -> { {"Kernel", "Root" -> "Source/Startup/Begin", "Context" -> "Wolfram`Chatbook`BeginStartup`"}, - {"Kernel", - "Root" -> "Source/Chatbook", - "Context" -> "Wolfram`Chatbook`" - }, - {"Kernel", - "Root" -> "Source/ServerSentEventUtils", - "Context" -> "Wolfram`ServerSentEventUtils`"}, + {"Kernel", "Root" -> "Source/Chatbook", "Context" -> "Wolfram`Chatbook`"}, {"Kernel", "Root" -> "Source/Startup/End", "Context" -> "Wolfram`Chatbook`EndStartup`"}, {"Asset", "Root" -> "Assets", diff --git a/Source/Chatbook/Main.wl b/Source/Chatbook/Main.wl index 9e1d5aa9..3fe0a321 100644 --- a/Source/Chatbook/Main.wl +++ b/Source/Chatbook/Main.wl @@ -65,23 +65,24 @@ Chatbook is a symbol for miscellaneous chat notebook messages.\ (* ::Section::Closed:: *) (*Load Files*) Block[ { $ContextPath }, - Get[ "Wolfram`Chatbook`Common`" ]; - Get[ "Wolfram`Chatbook`Debug`" ]; - Get[ "Wolfram`Chatbook`ErrorUtils`" ]; - Get[ "Wolfram`Chatbook`Errors`" ]; - Get[ "Wolfram`Chatbook`CreateChatNotebook`" ]; - Get[ "Wolfram`Chatbook`Serialization`" ]; - Get[ "Wolfram`Chatbook`Streaming`" ]; - Get[ "Wolfram`Chatbook`Utils`" ]; - Get[ "Wolfram`Chatbook`FrontEnd`" ]; - Get[ "Wolfram`Chatbook`UI`" ]; - Get[ "Wolfram`Chatbook`Formatting`" ]; - Get[ "Wolfram`Chatbook`Prompting`" ]; - Get[ "Wolfram`Chatbook`Actions`" ]; - Get[ "Wolfram`Chatbook`Menus`" ]; - Get[ "Wolfram`Chatbook`Personas`" ]; - Get[ "Wolfram`Chatbook`PersonaInstaller`" ]; - Get[ "Wolfram`Chatbook`InlineReferences`" ]; + Get[ "Wolfram`Chatbook`Common`" ]; + Get[ "Wolfram`Chatbook`Debug`" ]; + Get[ "Wolfram`Chatbook`ErrorUtils`" ]; + Get[ "Wolfram`Chatbook`Errors`" ]; + Get[ "Wolfram`Chatbook`CreateChatNotebook`" ]; + Get[ "Wolfram`Chatbook`Serialization`" ]; + Get[ "Wolfram`Chatbook`Streaming`" ]; + Get[ "Wolfram`Chatbook`Utils`" ]; + Get[ "Wolfram`Chatbook`FrontEnd`" ]; + Get[ "Wolfram`Chatbook`UI`" ]; + Get[ "Wolfram`Chatbook`Formatting`" ]; + Get[ "Wolfram`Chatbook`Prompting`" ]; + Get[ "Wolfram`Chatbook`Actions`" ]; + Get[ "Wolfram`Chatbook`Menus`" ]; + Get[ "Wolfram`Chatbook`Personas`" ]; + Get[ "Wolfram`Chatbook`PersonaInstaller`" ]; + Get[ "Wolfram`Chatbook`InlineReferences`" ]; + Get[ "Wolfram`Chatbook`ServerSentEventUtils`" ]; ]; (* ::**************************************************************************************************************:: *) diff --git a/Source/ServerSentEventUtils/ServerSentEventUtils.wl b/Source/Chatbook/ServerSentEventUtils.wl similarity index 98% rename from Source/ServerSentEventUtils/ServerSentEventUtils.wl rename to Source/Chatbook/ServerSentEventUtils.wl index af47e452..1f0d15ed 100644 --- a/Source/ServerSentEventUtils/ServerSentEventUtils.wl +++ b/Source/Chatbook/ServerSentEventUtils.wl @@ -1,4 +1,4 @@ -BeginPackage["Wolfram`ServerSentEventUtils`"] +BeginPackage["Wolfram`Chatbook`ServerSentEventUtils`"] (* Avoiding context aliasing due to bug 434990: *) Needs[ "GeneralUtilities`" -> None ]; diff --git a/Source/Chatbook/UI.wl b/Source/Chatbook/UI.wl index b0647c9a..fea621d9 100644 --- a/Source/Chatbook/UI.wl +++ b/Source/Chatbook/UI.wl @@ -39,7 +39,7 @@ Needs["Wolfram`Chatbook`PersonaInstaller`"] Needs["Wolfram`Chatbook`FrontEnd`"] -Needs["Wolfram`ServerSentEventUtils`" -> None] +Needs["Wolfram`Chatbook`ServerSentEventUtils`" -> None] $ChatOutputTypePrompts = <| @@ -710,7 +710,7 @@ doAsyncChatRequest[ task = URLSubmit[ request, HandlerFunctions -> <| - "BodyChunkReceived" -> Wolfram`ServerSentEventUtils`ServerSentEventBodyChunkTransformer[ + "BodyChunkReceived" -> Wolfram`Chatbook`ServerSentEventUtils`ServerSentEventBodyChunkTransformer[ event |-> ( AppendTo[events, event]; Handle[ diff --git a/Tests/SSETests.wlt b/Tests/SSETests.wlt index 447177a7..680b6630 100644 --- a/Tests/SSETests.wlt +++ b/Tests/SSETests.wlt @@ -1,4 +1,4 @@ -Needs["Wolfram`ServerSentEventUtils`"] +Needs["Wolfram`Chatbook`ServerSentEventUtils`"] (*=================================================*) @@ -9,22 +9,22 @@ Module[{ generator = CreateChunkToServerSentEventGenerator[] }, VerificationTest[ - generator["data:"] - , - Missing["IncompleteData"] - ]; + generator["data:"], + Missing["IncompleteData"], + TestID -> "Untitled-7@@Tests/SSETests.wlt:11,2-15,2" +]; VerificationTest[ - generator[" foo\n"] - , - Missing["IncompleteData"] - ]; + generator[" foo\n"], + Missing["IncompleteData"], + TestID -> "Untitled-8@@Tests/SSETests.wlt:17,2-21,2" +]; VerificationTest[ - generator["\n"] - , - {<|"Data" -> "foo"|>} - ]; + generator["\n"], + {Association["Data" -> "foo"]}, + TestID -> "Untitled-9@@Tests/SSETests.wlt:23,2-27,2" +]; ] (*===========================================*) @@ -35,28 +35,19 @@ $events = {} $func = ServerSentEventBodyChunkTransformer[event |-> AppendTo[$events, event]] VerificationTest[ - { - $func[<| "BodyChunk" -> "data: " |>], - $events - } - , - {Null, {}} + {$func[Association["BodyChunk" -> "data: "]], $events}, + {Null, {}}, + TestID -> "Untitled-10@@Tests/SSETests.wlt:37,1-41,2" ] VerificationTest[ - { - $func[<| "BodyChunk" -> "foo\n" |>], - $events - } - , - {Null, {}} + {$func[Association["BodyChunk" -> "foo\n"]], $events}, + {Null, {}}, + TestID -> "Untitled-11@@Tests/SSETests.wlt:43,1-47,2" ] VerificationTest[ - { - $func[<| "BodyChunk" -> "\n\n" |>], - $events - } - , - {Null, {<| "Data" -> "foo" |>}} + {$func[Association["BodyChunk" -> "\n\n"]], $events}, + {Null, {Association["Data" -> "foo"]}}, + TestID -> "Untitled-12@@Tests/SSETests.wlt:49,1-53,2" ] \ No newline at end of file