@terreno/ui 57.9.0 → 57.10.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 +2 -0
- package/dist/Button.d.ts.map +1 -1
- package/dist/Button.js +19 -4
- package/dist/Button.js.map +1 -1
- package/dist/Common.d.ts +68 -1
- package/dist/Common.d.ts.map +1 -1
- package/dist/Common.js.map +1 -1
- package/dist/DateTimeField.d.ts.map +1 -1
- package/dist/DateTimeField.js +90 -17
- package/dist/DateTimeField.js.map +1 -1
- package/dist/FilePickerButton.d.ts +15 -1
- package/dist/FilePickerButton.d.ts.map +1 -1
- package/dist/FilePickerButton.js +26 -9
- package/dist/FilePickerButton.js.map +1 -1
- package/dist/GPTChat.d.ts +57 -1
- package/dist/GPTChat.d.ts.map +1 -1
- package/dist/GPTChat.js +199 -7
- package/dist/GPTChat.js.map +1 -1
- package/dist/HtmlFrame.d.ts +11 -0
- package/dist/HtmlFrame.d.ts.map +1 -0
- package/dist/HtmlFrame.js +29 -0
- package/dist/HtmlFrame.js.map +1 -0
- package/dist/Text.d.ts +1 -1
- package/dist/Text.d.ts.map +1 -1
- package/dist/Text.js +2 -2
- package/dist/Text.js.map +1 -1
- package/dist/asks/AskCard.d.ts +34 -0
- package/dist/asks/AskCard.d.ts.map +1 -0
- package/dist/asks/AskCard.js +91 -0
- package/dist/asks/AskCard.js.map +1 -0
- package/dist/asks/AskChoice.d.ts +11 -0
- package/dist/asks/AskChoice.d.ts.map +1 -0
- package/dist/asks/AskChoice.js +146 -0
- package/dist/asks/AskChoice.js.map +1 -0
- package/dist/asks/AskConfirm.d.ts +15 -0
- package/dist/asks/AskConfirm.d.ts.map +1 -0
- package/dist/asks/AskConfirm.js +17 -0
- package/dist/asks/AskConfirm.js.map +1 -0
- package/dist/asks/AskFiles.d.ts +18 -0
- package/dist/asks/AskFiles.d.ts.map +1 -0
- package/dist/asks/AskFiles.js +149 -0
- package/dist/asks/AskFiles.js.map +1 -0
- package/dist/asks/AskForm.d.ts +27 -0
- package/dist/asks/AskForm.d.ts.map +1 -0
- package/dist/asks/AskForm.js +146 -0
- package/dist/asks/AskForm.js.map +1 -0
- package/dist/asks/AskMarkdown.d.ts +25 -0
- package/dist/asks/AskMarkdown.d.ts.map +1 -0
- package/dist/asks/AskMarkdown.js +73 -0
- package/dist/asks/AskMarkdown.js.map +1 -0
- package/dist/asks/SimpleAskCard.d.ts +23 -0
- package/dist/asks/SimpleAskCard.d.ts.map +1 -0
- package/dist/asks/SimpleAskCard.js +32 -0
- package/dist/asks/SimpleAskCard.js.map +1 -0
- package/dist/asks/askControls.d.ts +33 -0
- package/dist/asks/askControls.d.ts.map +1 -0
- package/dist/asks/askControls.js +30 -0
- package/dist/asks/askControls.js.map +1 -0
- package/dist/asks/askFileRefs.d.ts +26 -0
- package/dist/asks/askFileRefs.d.ts.map +1 -0
- package/dist/asks/askFileRefs.js +75 -0
- package/dist/asks/askFileRefs.js.map +1 -0
- package/dist/asks/askFormDraft.d.ts +60 -0
- package/dist/asks/askFormDraft.d.ts.map +1 -0
- package/dist/asks/askFormDraft.js +224 -0
- package/dist/asks/askFormDraft.js.map +1 -0
- package/dist/asks/askSummary.d.ts +10 -0
- package/dist/asks/askSummary.d.ts.map +1 -0
- package/dist/asks/askSummary.js +138 -0
- package/dist/asks/askSummary.js.map +1 -0
- package/dist/asks/askTypes.d.ts +21 -0
- package/dist/asks/askTypes.d.ts.map +1 -0
- package/dist/asks/askTypes.js +2 -0
- package/dist/asks/askTypes.js.map +1 -0
- package/dist/asks/simpleCardButtonVariants.d.ts +5 -0
- package/dist/asks/simpleCardButtonVariants.d.ts.map +1 -0
- package/dist/asks/simpleCardButtonVariants.js +8 -0
- package/dist/asks/simpleCardButtonVariants.js.map +1 -0
- package/dist/blocks/BlocksError.d.ts +8 -0
- package/dist/blocks/BlocksError.d.ts.map +1 -0
- package/dist/blocks/BlocksError.js +14 -0
- package/dist/blocks/BlocksError.js.map +1 -0
- package/dist/blocks/BlocksView.d.ts +10 -0
- package/dist/blocks/BlocksView.d.ts.map +1 -0
- package/dist/blocks/BlocksView.js +90 -0
- package/dist/blocks/BlocksView.js.map +1 -0
- package/dist/blocks/blockRenderers.d.ts +25 -0
- package/dist/blocks/blockRenderers.d.ts.map +1 -0
- package/dist/blocks/blockRenderers.js +136 -0
- package/dist/blocks/blockRenderers.js.map +1 -0
- package/dist/blocks/datasetToPoints.d.ts +22 -0
- package/dist/blocks/datasetToPoints.d.ts.map +1 -0
- package/dist/blocks/datasetToPoints.js +28 -0
- package/dist/blocks/datasetToPoints.js.map +1 -0
- package/dist/blocks/useBlockSelections.d.ts +6 -0
- package/dist/blocks/useBlockSelections.d.ts.map +1 -0
- package/dist/blocks/useBlockSelections.js +10 -0
- package/dist/blocks/useBlockSelections.js.map +1 -0
- package/dist/blocks/useResolvedDatasets.d.ts +18 -0
- package/dist/blocks/useResolvedDatasets.d.ts.map +1 -0
- package/dist/blocks/useResolvedDatasets.js +59 -0
- package/dist/blocks/useResolvedDatasets.js.map +1 -0
- package/dist/blocks/useResolvedImages.d.ts +15 -0
- package/dist/blocks/useResolvedImages.d.ts.map +1 -0
- package/dist/blocks/useResolvedImages.js +66 -0
- package/dist/blocks/useResolvedImages.js.map +1 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/lazyBoundaries/heavyOptionalExports.d.ts +6 -0
- package/dist/lazyBoundaries/heavyOptionalExports.d.ts.map +1 -1
- package/dist/lazyBoundaries/heavyOptionalExports.js +4 -0
- package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -1
- package/package.json +2 -1
- package/src/Button.test.tsx +72 -0
- package/src/Button.tsx +34 -4
- package/src/Common.ts +67 -0
- package/src/DateTimeField.test.tsx +185 -2
- package/src/DateTimeField.tsx +106 -16
- package/src/DonutChart.test.tsx +5 -10
- package/src/FilePickerButton.test.tsx +56 -3
- package/src/FilePickerButton.tsx +83 -17
- package/src/GPTChat.test.tsx +758 -2
- package/src/GPTChat.tsx +517 -7
- package/src/HtmlFrame.tsx +60 -0
- package/src/LineChart.test.tsx +5 -10
- package/src/Text.test.tsx +22 -0
- package/src/Text.tsx +10 -1
- package/src/asks/AskCard.test.tsx +1428 -0
- package/src/asks/AskCard.tsx +240 -0
- package/src/asks/AskChoice.tsx +368 -0
- package/src/asks/AskConfirm.tsx +42 -0
- package/src/asks/AskFiles.test.tsx +347 -0
- package/src/asks/AskFiles.tsx +246 -0
- package/src/asks/AskForm.tsx +334 -0
- package/src/asks/AskMarkdown.tsx +176 -0
- package/src/asks/SimpleAskCard.test.tsx +253 -0
- package/src/asks/SimpleAskCard.tsx +82 -0
- package/src/asks/askControls.tsx +98 -0
- package/src/asks/askFileRefs.test.ts +155 -0
- package/src/asks/askFileRefs.ts +98 -0
- package/src/asks/askFormDraft.test.ts +347 -0
- package/src/asks/askFormDraft.ts +309 -0
- package/src/asks/askSummary.test.ts +255 -0
- package/src/asks/askSummary.ts +160 -0
- package/src/asks/askTypes.ts +25 -0
- package/src/asks/asksUseTerrenoComponents.test.ts +55 -0
- package/src/asks/simpleCardButtonVariants.ts +14 -0
- package/src/blocks/BlocksError.tsx +28 -0
- package/src/blocks/BlocksView.test.tsx +607 -0
- package/src/blocks/BlocksView.tsx +125 -0
- package/src/blocks/blockRenderers.tsx +288 -0
- package/src/blocks/datasetToPoints.test.ts +31 -0
- package/src/blocks/datasetToPoints.ts +48 -0
- package/src/blocks/useBlockSelections.ts +13 -0
- package/src/blocks/useResolvedDatasets.ts +78 -0
- package/src/blocks/useResolvedImages.ts +81 -0
- package/src/index.tsx +7 -0
- package/src/isolated/HtmlFrame.isolated.tsx +54 -0
- package/src/lazyBoundaries/heavyOptionalExports.test.tsx +2 -0
- package/src/lazyBoundaries/heavyOptionalExports.tsx +14 -0
package/src/GPTChat.test.tsx
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import {afterAll, afterEach, describe, it, mock} from "bun:test";
|
|
2
|
-
import {
|
|
2
|
+
import type {ChoiceAskInput} from "@terreno/blocks";
|
|
3
|
+
import {act, fireEvent, render, waitFor, within} from "@testing-library/react-native";
|
|
3
4
|
import {assert} from "chai";
|
|
4
5
|
import {setImageAsync, setStringAsync} from "expo-clipboard";
|
|
5
6
|
import React from "react";
|
|
6
|
-
import {Platform, Pressable, ScrollView} from "react-native";
|
|
7
|
+
import {AccessibilityInfo, ActivityIndicator, Platform, Pressable, ScrollView} from "react-native";
|
|
7
8
|
|
|
9
|
+
import type {AskSubmission, ChatAsk} from "./asks/askTypes";
|
|
8
10
|
import type {SelectedFile} from "./FilePickerButton";
|
|
9
11
|
import type {GPTChatHistory, GPTChatMessage, GPTChatProps, MessageContentPart} from "./GPTChat";
|
|
10
12
|
import {GPTChat} from "./GPTChat";
|
|
@@ -49,6 +51,49 @@ const press = async (element: Parameters<typeof fireEvent.press>[0]): Promise<vo
|
|
|
49
51
|
});
|
|
50
52
|
};
|
|
51
53
|
|
|
54
|
+
// Block buttons await a haptic call before onClick.
|
|
55
|
+
const pressControl = async (element: Parameters<typeof fireEvent.press>[0]): Promise<void> => {
|
|
56
|
+
await act(async () => {
|
|
57
|
+
fireEvent.press(element);
|
|
58
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const BLOCKS_REPLY = `v: 1
|
|
63
|
+
blocks:
|
|
64
|
+
- type: heading
|
|
65
|
+
text: Quarter heading
|
|
66
|
+
- type: actions
|
|
67
|
+
id: row
|
|
68
|
+
elements:
|
|
69
|
+
- type: button
|
|
70
|
+
id: reply_btn
|
|
71
|
+
text: Ask again
|
|
72
|
+
action:
|
|
73
|
+
kind: reply
|
|
74
|
+
text: Show the weekly numbers
|
|
75
|
+
- type: button
|
|
76
|
+
id: open_btn
|
|
77
|
+
text: Open
|
|
78
|
+
action:
|
|
79
|
+
kind: open
|
|
80
|
+
route: /reports
|
|
81
|
+
- type: button
|
|
82
|
+
id: run_btn
|
|
83
|
+
text: Export
|
|
84
|
+
action:
|
|
85
|
+
kind: callback
|
|
86
|
+
name: export_csv
|
|
87
|
+
`;
|
|
88
|
+
|
|
89
|
+
const BLOCKS_STREAMING = `v: 1
|
|
90
|
+
blocks:
|
|
91
|
+
- type: heading
|
|
92
|
+
text: Done heading
|
|
93
|
+
- type: heading
|
|
94
|
+
text: "Still typ
|
|
95
|
+
`;
|
|
96
|
+
|
|
52
97
|
const histories: GPTChatHistory[] = [
|
|
53
98
|
{id: "h1", prompts: [], title: "First chat"},
|
|
54
99
|
{id: "h2", prompts: []},
|
|
@@ -928,3 +973,714 @@ describe("GPTChat web keyboard submit", () => {
|
|
|
928
973
|
assert.include(removed, "keydown");
|
|
929
974
|
});
|
|
930
975
|
});
|
|
976
|
+
|
|
977
|
+
describe("GPTChat asks", () => {
|
|
978
|
+
const PLAN_INPUT: ChoiceAskInput = {
|
|
979
|
+
default: ["team"],
|
|
980
|
+
options: [
|
|
981
|
+
{description: "$0, one seat", id: "starter", label: "Starter"},
|
|
982
|
+
{description: "$20 per seat", id: "team", label: "Team"},
|
|
983
|
+
{id: "enterprise", label: "Enterprise"},
|
|
984
|
+
],
|
|
985
|
+
prompt: "Which plan should I set up?",
|
|
986
|
+
select: "one",
|
|
987
|
+
title: "Choose a plan",
|
|
988
|
+
};
|
|
989
|
+
|
|
990
|
+
const planAsk = (state: Partial<ChatAsk> = {}): ChatAsk => ({
|
|
991
|
+
input: PLAN_INPUT,
|
|
992
|
+
kind: "choice",
|
|
993
|
+
status: "pending",
|
|
994
|
+
toolCallId: "call_plan",
|
|
995
|
+
...state,
|
|
996
|
+
});
|
|
997
|
+
|
|
998
|
+
const askMessage = (ask: ChatAsk): GPTChatMessage => ({
|
|
999
|
+
ask,
|
|
1000
|
+
content: "Tool call: ask_choice",
|
|
1001
|
+
role: "tool-call",
|
|
1002
|
+
toolCall: {args: {...ask.input}, toolCallId: ask.toolCallId, toolName: "ask_choice"},
|
|
1003
|
+
});
|
|
1004
|
+
|
|
1005
|
+
const askResultMessage = (result: unknown): GPTChatMessage => ({
|
|
1006
|
+
content: "Tool result: ask_choice",
|
|
1007
|
+
role: "tool-result",
|
|
1008
|
+
toolResult: {result, toolCallId: "call_plan", toolName: "ask_choice"},
|
|
1009
|
+
});
|
|
1010
|
+
|
|
1011
|
+
const userMessage: GPTChatMessage = {content: "Set up my workspace", role: "user"};
|
|
1012
|
+
|
|
1013
|
+
const originalOS = Platform.OS;
|
|
1014
|
+
const setAccessibilityFocus = AccessibilityInfo.setAccessibilityFocus as ReturnType<typeof mock>;
|
|
1015
|
+
|
|
1016
|
+
afterEach(() => {
|
|
1017
|
+
Platform.OS = originalOS;
|
|
1018
|
+
});
|
|
1019
|
+
|
|
1020
|
+
it("renders a pending ask as a card in place of its tool call and sends the answer", async () => {
|
|
1021
|
+
const onAskSubmit = mock(async (_submission: AskSubmission) => {});
|
|
1022
|
+
const {getByTestId, queryByText} = renderChat({
|
|
1023
|
+
currentMessages: [userMessage, askMessage(planAsk())],
|
|
1024
|
+
onAskSubmit,
|
|
1025
|
+
});
|
|
1026
|
+
|
|
1027
|
+
assert.isOk(getByTestId("gpt-ask-call_plan"));
|
|
1028
|
+
assert.isNull(queryByText("Tool: ask_choice"));
|
|
1029
|
+
await act(async () => {
|
|
1030
|
+
fireEvent.press(getByTestId("gpt-ask-call_plan-button-option:team"));
|
|
1031
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
1032
|
+
});
|
|
1033
|
+
|
|
1034
|
+
assert.deepEqual(onAskSubmit.mock.calls[0]?.[0], {
|
|
1035
|
+
response: {action: "accept", content: {selected: ["team"]}},
|
|
1036
|
+
toolCallId: "call_plan",
|
|
1037
|
+
});
|
|
1038
|
+
});
|
|
1039
|
+
|
|
1040
|
+
it("keeps a pending ask restored from history interactive", async () => {
|
|
1041
|
+
const onAskSubmit = mock(async (_submission: AskSubmission) => {});
|
|
1042
|
+
const restored: GPTChatHistory = {
|
|
1043
|
+
id: "h3",
|
|
1044
|
+
prompts: [userMessage, askMessage(planAsk({simple: undefined}))],
|
|
1045
|
+
title: "Plan setup",
|
|
1046
|
+
};
|
|
1047
|
+
const {getByTestId} = renderChat({
|
|
1048
|
+
currentHistoryId: "h3",
|
|
1049
|
+
currentMessages: restored.prompts,
|
|
1050
|
+
histories: [...histories, restored],
|
|
1051
|
+
onAskSubmit,
|
|
1052
|
+
});
|
|
1053
|
+
|
|
1054
|
+
await act(async () => {
|
|
1055
|
+
fireEvent.press(getByTestId("gpt-ask-call_plan-button-skip"));
|
|
1056
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
1057
|
+
});
|
|
1058
|
+
|
|
1059
|
+
assert.deepEqual(onAskSubmit.mock.calls[0]?.[0], {
|
|
1060
|
+
response: {action: "decline"},
|
|
1061
|
+
toolCallId: "call_plan",
|
|
1062
|
+
});
|
|
1063
|
+
});
|
|
1064
|
+
|
|
1065
|
+
it("sends the checked options and the Other text of a restored select many ask", async () => {
|
|
1066
|
+
const onAskSubmit = mock(async (_submission: AskSubmission) => {});
|
|
1067
|
+
const toppingsAsk = planAsk({
|
|
1068
|
+
input: {
|
|
1069
|
+
allowOther: true,
|
|
1070
|
+
default: ["cheese"],
|
|
1071
|
+
maxSelected: 3,
|
|
1072
|
+
options: [
|
|
1073
|
+
{id: "cheese", label: "Extra cheese"},
|
|
1074
|
+
{id: "mushrooms", label: "Mushrooms"},
|
|
1075
|
+
{id: "olives", label: "Olives"},
|
|
1076
|
+
],
|
|
1077
|
+
otherLabel: "Another topping",
|
|
1078
|
+
prompt: "Which toppings should I add?",
|
|
1079
|
+
select: "many",
|
|
1080
|
+
},
|
|
1081
|
+
simple: undefined,
|
|
1082
|
+
toolCallId: "call_toppings",
|
|
1083
|
+
});
|
|
1084
|
+
const restored: GPTChatHistory = {
|
|
1085
|
+
id: "h4",
|
|
1086
|
+
prompts: [userMessage, askMessage(toppingsAsk)],
|
|
1087
|
+
title: "Building a pizza",
|
|
1088
|
+
};
|
|
1089
|
+
const {getByLabelText, getByTestId} = renderChat({
|
|
1090
|
+
currentHistoryId: "h4",
|
|
1091
|
+
currentMessages: restored.prompts,
|
|
1092
|
+
histories: [...histories, restored],
|
|
1093
|
+
onAskSubmit,
|
|
1094
|
+
});
|
|
1095
|
+
|
|
1096
|
+
await press(getByLabelText("Olives"));
|
|
1097
|
+
await act(async () => {
|
|
1098
|
+
fireEvent.changeText(getByTestId("gpt-ask-call_toppings-other"), "Basil");
|
|
1099
|
+
});
|
|
1100
|
+
await press(getByTestId("gpt-ask-call_toppings-submit"));
|
|
1101
|
+
|
|
1102
|
+
assert.deepEqual(onAskSubmit.mock.calls[0]?.[0], {
|
|
1103
|
+
response: {action: "accept", content: {other: "Basil", selected: ["cheese", "olives"]}},
|
|
1104
|
+
toolCallId: "call_toppings",
|
|
1105
|
+
});
|
|
1106
|
+
});
|
|
1107
|
+
|
|
1108
|
+
describe("files asks", () => {
|
|
1109
|
+
const notesAsk = (state: Partial<ChatAsk> = {}): ChatAsk =>
|
|
1110
|
+
({
|
|
1111
|
+
input: {accept: ["text"], maxFiles: 1, prompt: "Upload your notes."},
|
|
1112
|
+
kind: "files",
|
|
1113
|
+
status: "pending",
|
|
1114
|
+
toolCallId: "call_notes",
|
|
1115
|
+
...state,
|
|
1116
|
+
}) as ChatAsk;
|
|
1117
|
+
|
|
1118
|
+
const filesMessage = (ask: ChatAsk): GPTChatMessage => ({
|
|
1119
|
+
ask,
|
|
1120
|
+
content: "Tool call: ask_files",
|
|
1121
|
+
role: "tool-call",
|
|
1122
|
+
toolCall: {args: {...ask.input}, toolCallId: ask.toolCallId, toolName: "ask_files"},
|
|
1123
|
+
});
|
|
1124
|
+
|
|
1125
|
+
it("sends the refs resolveAskFiles returns for the picked files", async () => {
|
|
1126
|
+
const onAskSubmit = mock(async (_submission: AskSubmission) => {});
|
|
1127
|
+
const resolveAskFiles = mock(async (files: SelectedFile[]) =>
|
|
1128
|
+
files.map((file) => ({
|
|
1129
|
+
fileId: "upload-1",
|
|
1130
|
+
filename: file.name,
|
|
1131
|
+
mimeType: file.mimeType,
|
|
1132
|
+
size: 12,
|
|
1133
|
+
}))
|
|
1134
|
+
);
|
|
1135
|
+
const {getByTestId, getByText} = renderChat({
|
|
1136
|
+
currentMessages: [userMessage, filesMessage(notesAsk())],
|
|
1137
|
+
onAskSubmit,
|
|
1138
|
+
resolveAskFiles,
|
|
1139
|
+
});
|
|
1140
|
+
|
|
1141
|
+
await press(getByTestId("gpt-ask-call_notes-picker"));
|
|
1142
|
+
await waitFor(() => assert.isOk(getByText("notes.txt")));
|
|
1143
|
+
await press(getByTestId("gpt-ask-call_notes-submit"));
|
|
1144
|
+
|
|
1145
|
+
assert.deepEqual(resolveAskFiles.mock.calls[0]?.[0], [pickedDocument]);
|
|
1146
|
+
assert.deepEqual(onAskSubmit.mock.calls[0]?.[0], {
|
|
1147
|
+
response: {
|
|
1148
|
+
action: "accept",
|
|
1149
|
+
content: {
|
|
1150
|
+
files: [{fileId: "upload-1", filename: "notes.txt", mimeType: "text/plain", size: 12}],
|
|
1151
|
+
},
|
|
1152
|
+
},
|
|
1153
|
+
toolCallId: "call_notes",
|
|
1154
|
+
});
|
|
1155
|
+
});
|
|
1156
|
+
|
|
1157
|
+
it("summarizes an answered files ask from the stored metadata", () => {
|
|
1158
|
+
const {getByText} = renderChat({
|
|
1159
|
+
currentMessages: [
|
|
1160
|
+
userMessage,
|
|
1161
|
+
filesMessage(notesAsk({status: "answered"})),
|
|
1162
|
+
{
|
|
1163
|
+
content: "Tool result: ask_files",
|
|
1164
|
+
role: "tool-result",
|
|
1165
|
+
toolResult: {
|
|
1166
|
+
result: {
|
|
1167
|
+
action: "accept",
|
|
1168
|
+
content: {files: [{filename: "notes.txt", mimeType: "text/plain", size: 12}]},
|
|
1169
|
+
},
|
|
1170
|
+
toolCallId: "call_notes",
|
|
1171
|
+
toolName: "ask_files",
|
|
1172
|
+
},
|
|
1173
|
+
},
|
|
1174
|
+
],
|
|
1175
|
+
});
|
|
1176
|
+
|
|
1177
|
+
assert.isOk(getByText("You sent 1 file: notes.txt"));
|
|
1178
|
+
});
|
|
1179
|
+
});
|
|
1180
|
+
|
|
1181
|
+
describe("confirm asks", () => {
|
|
1182
|
+
const archiveAsk = (state: Partial<ChatAsk> = {}): ChatAsk =>
|
|
1183
|
+
({
|
|
1184
|
+
input: {
|
|
1185
|
+
confirmLabel: "Archive 12 chats",
|
|
1186
|
+
denyLabel: "Keep them",
|
|
1187
|
+
destructive: true,
|
|
1188
|
+
prompt: "Archive the 12 chats older than 90 days?",
|
|
1189
|
+
},
|
|
1190
|
+
kind: "confirm",
|
|
1191
|
+
status: "pending",
|
|
1192
|
+
toolCallId: "call_archive",
|
|
1193
|
+
...state,
|
|
1194
|
+
}) as ChatAsk;
|
|
1195
|
+
|
|
1196
|
+
const confirmMessage = (ask: ChatAsk): GPTChatMessage => ({
|
|
1197
|
+
ask,
|
|
1198
|
+
content: "Tool call: ask_confirm",
|
|
1199
|
+
role: "tool-call",
|
|
1200
|
+
toolCall: {args: {...ask.input}, toolCallId: ask.toolCallId, toolName: "ask_confirm"},
|
|
1201
|
+
});
|
|
1202
|
+
|
|
1203
|
+
it("sends {confirmed: false} from the deny button of a restored confirm ask", async () => {
|
|
1204
|
+
const onAskSubmit = mock(async (_submission: AskSubmission) => {});
|
|
1205
|
+
const restored: GPTChatHistory = {
|
|
1206
|
+
id: "h5",
|
|
1207
|
+
prompts: [userMessage, confirmMessage(archiveAsk())],
|
|
1208
|
+
title: "Cleaning up",
|
|
1209
|
+
};
|
|
1210
|
+
const {getByTestId} = renderChat({
|
|
1211
|
+
currentHistoryId: "h5",
|
|
1212
|
+
currentMessages: restored.prompts,
|
|
1213
|
+
histories: [...histories, restored],
|
|
1214
|
+
onAskSubmit,
|
|
1215
|
+
});
|
|
1216
|
+
|
|
1217
|
+
assert.isOk(
|
|
1218
|
+
within(getByTestId("gpt-ask-call_archive-button-approve")).getByText("Archive 12 chats")
|
|
1219
|
+
);
|
|
1220
|
+
await press(getByTestId("gpt-ask-call_archive-button-deny"));
|
|
1221
|
+
|
|
1222
|
+
assert.deepEqual(onAskSubmit.mock.calls[0]?.[0], {
|
|
1223
|
+
response: {action: "accept", content: {confirmed: false}},
|
|
1224
|
+
toolCallId: "call_archive",
|
|
1225
|
+
});
|
|
1226
|
+
});
|
|
1227
|
+
|
|
1228
|
+
it("summarizes an answered confirm ask from its hidden result message", () => {
|
|
1229
|
+
const {getByText, queryByTestId, queryByText} = renderChat({
|
|
1230
|
+
currentMessages: [
|
|
1231
|
+
userMessage,
|
|
1232
|
+
confirmMessage(archiveAsk({status: "answered"})),
|
|
1233
|
+
{
|
|
1234
|
+
content: "Tool result: ask_confirm",
|
|
1235
|
+
role: "tool-result",
|
|
1236
|
+
toolResult: {
|
|
1237
|
+
result: {action: "accept", content: {confirmed: true}},
|
|
1238
|
+
toolCallId: "call_archive",
|
|
1239
|
+
toolName: "ask_confirm",
|
|
1240
|
+
},
|
|
1241
|
+
},
|
|
1242
|
+
{content: "Archived 12 chats.", role: "assistant"},
|
|
1243
|
+
],
|
|
1244
|
+
});
|
|
1245
|
+
|
|
1246
|
+
assert.isOk(getByText("You confirmed: Archive 12 chats"));
|
|
1247
|
+
assert.isNull(queryByText("Result: ask_confirm"));
|
|
1248
|
+
assert.isNull(queryByTestId("gpt-ask-call_archive-button-approve"));
|
|
1249
|
+
});
|
|
1250
|
+
});
|
|
1251
|
+
|
|
1252
|
+
it("summarizes an answered ask from its hidden result message", () => {
|
|
1253
|
+
const {getByText, queryByTestId, queryByText} = renderChat({
|
|
1254
|
+
currentMessages: [
|
|
1255
|
+
userMessage,
|
|
1256
|
+
askMessage(planAsk({status: "answered"})),
|
|
1257
|
+
askResultMessage({action: "accept", content: {selected: ["starter"]}}),
|
|
1258
|
+
{content: "Starter it is.", role: "assistant"},
|
|
1259
|
+
],
|
|
1260
|
+
});
|
|
1261
|
+
|
|
1262
|
+
assert.isOk(getByText("You chose: Starter"));
|
|
1263
|
+
assert.isNull(queryByText("Result: ask_choice"));
|
|
1264
|
+
assert.isNull(queryByTestId("gpt-ask-call_plan-button-option:team"));
|
|
1265
|
+
assert.isOk(getByText("Starter it is."));
|
|
1266
|
+
});
|
|
1267
|
+
|
|
1268
|
+
it("still shows tool results that do not belong to an ask", () => {
|
|
1269
|
+
const {getByText} = renderChat({
|
|
1270
|
+
currentMessages: [
|
|
1271
|
+
askMessage(planAsk({status: "answered"})),
|
|
1272
|
+
askResultMessage({action: "decline"}),
|
|
1273
|
+
{
|
|
1274
|
+
content: "Tool result: lookup",
|
|
1275
|
+
role: "tool-result",
|
|
1276
|
+
toolResult: {result: {ok: true}, toolCallId: "call_lookup", toolName: "lookup"},
|
|
1277
|
+
},
|
|
1278
|
+
],
|
|
1279
|
+
});
|
|
1280
|
+
|
|
1281
|
+
assert.isOk(getByText("You skipped this question."));
|
|
1282
|
+
assert.isOk(getByText("Result: lookup"));
|
|
1283
|
+
});
|
|
1284
|
+
|
|
1285
|
+
it("shows the errors for the matching ask inline", () => {
|
|
1286
|
+
const {getByText} = renderChat({
|
|
1287
|
+
askErrors: {
|
|
1288
|
+
call_other: [
|
|
1289
|
+
{code: "SELECTION_COUNT", fix: "", message: "Not this ask's error.", path: "content"},
|
|
1290
|
+
],
|
|
1291
|
+
call_plan: [
|
|
1292
|
+
{
|
|
1293
|
+
code: "OPTION_NOT_OFFERED",
|
|
1294
|
+
fix: "Use the id of one of the ask's options.",
|
|
1295
|
+
message: '"gold" is not one of the offered options.',
|
|
1296
|
+
path: "content.selected[0]",
|
|
1297
|
+
},
|
|
1298
|
+
],
|
|
1299
|
+
},
|
|
1300
|
+
currentMessages: [askMessage(planAsk())],
|
|
1301
|
+
onAskSubmit: async () => {},
|
|
1302
|
+
});
|
|
1303
|
+
|
|
1304
|
+
assert.isOk(getByText('"gold" is not one of the offered options.'));
|
|
1305
|
+
});
|
|
1306
|
+
|
|
1307
|
+
describe("when the host switches to another conversation", () => {
|
|
1308
|
+
const regionAsk = (toolCallId: string): ChatAsk => ({
|
|
1309
|
+
input: {
|
|
1310
|
+
options: [
|
|
1311
|
+
{description: "Oregon", id: "west", label: "West"},
|
|
1312
|
+
{id: "central", label: "Central"},
|
|
1313
|
+
{id: "east", label: "East"},
|
|
1314
|
+
{id: "europe", label: "Europe"},
|
|
1315
|
+
{id: "asia", label: "Asia"},
|
|
1316
|
+
],
|
|
1317
|
+
prompt: "Where should the data live?",
|
|
1318
|
+
select: "one",
|
|
1319
|
+
},
|
|
1320
|
+
kind: "choice",
|
|
1321
|
+
status: "pending",
|
|
1322
|
+
toolCallId,
|
|
1323
|
+
});
|
|
1324
|
+
|
|
1325
|
+
const chatWith = ({
|
|
1326
|
+
historyId,
|
|
1327
|
+
onAskSubmit,
|
|
1328
|
+
toolCallId,
|
|
1329
|
+
}: {
|
|
1330
|
+
historyId: string;
|
|
1331
|
+
onAskSubmit: GPTChatProps["onAskSubmit"];
|
|
1332
|
+
toolCallId: string;
|
|
1333
|
+
}): React.ReactElement => (
|
|
1334
|
+
<GPTChat
|
|
1335
|
+
currentHistoryId={historyId}
|
|
1336
|
+
currentMessages={[userMessage, askMessage(regionAsk(toolCallId))]}
|
|
1337
|
+
histories={histories}
|
|
1338
|
+
onAskSubmit={onAskSubmit}
|
|
1339
|
+
onCreateHistory={() => {}}
|
|
1340
|
+
onDeleteHistory={() => {}}
|
|
1341
|
+
onSelectHistory={() => {}}
|
|
1342
|
+
onSubmit={() => {}}
|
|
1343
|
+
/>
|
|
1344
|
+
);
|
|
1345
|
+
|
|
1346
|
+
const isDisabled = (element: {props: {accessibilityState?: {disabled?: boolean}}}): boolean =>
|
|
1347
|
+
element.props.accessibilityState?.disabled === true;
|
|
1348
|
+
|
|
1349
|
+
it("does not carry the option chosen in one chat into the other chat's ask", async () => {
|
|
1350
|
+
const onAskSubmit = mock(async (_submission: AskSubmission) => {});
|
|
1351
|
+
const {getByLabelText, getByTestId, rerender} = renderWithTheme(
|
|
1352
|
+
chatWith({historyId: "h1", onAskSubmit, toolCallId: "call_first"})
|
|
1353
|
+
);
|
|
1354
|
+
await press(getByLabelText("West — Oregon"));
|
|
1355
|
+
assert.isFalse(isDisabled(getByTestId("gpt-ask-call_first-submit")));
|
|
1356
|
+
|
|
1357
|
+
rerender(chatWith({historyId: "h2", onAskSubmit, toolCallId: "call_second"}));
|
|
1358
|
+
|
|
1359
|
+
assert.isTrue(isDisabled(getByTestId("gpt-ask-call_second-submit")));
|
|
1360
|
+
});
|
|
1361
|
+
|
|
1362
|
+
it("does not show one chat's answer still loading on the other chat's ask", async () => {
|
|
1363
|
+
const onAskSubmit = mock((_submission: AskSubmission) => new Promise<void>(() => {}));
|
|
1364
|
+
const {getByLabelText, getByTestId, rerender} = renderWithTheme(
|
|
1365
|
+
chatWith({historyId: "h1", onAskSubmit, toolCallId: "call_first"})
|
|
1366
|
+
);
|
|
1367
|
+
await press(getByLabelText("West — Oregon"));
|
|
1368
|
+
await act(async () => {
|
|
1369
|
+
fireEvent.press(getByTestId("gpt-ask-call_first-submit"));
|
|
1370
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
1371
|
+
});
|
|
1372
|
+
assert.lengthOf(onAskSubmit.mock.calls, 1);
|
|
1373
|
+
|
|
1374
|
+
rerender(chatWith({historyId: "h2", onAskSubmit, toolCallId: "call_second"}));
|
|
1375
|
+
|
|
1376
|
+
const spinners = getByTestId("gpt-ask-call_second-submit").findAll(
|
|
1377
|
+
(node) => node.type === "ActivityIndicator"
|
|
1378
|
+
);
|
|
1379
|
+
assert.lengthOf(spinners, 0);
|
|
1380
|
+
assert.isFalse(isDisabled(getByTestId("gpt-ask-call_second-button-skip")));
|
|
1381
|
+
});
|
|
1382
|
+
});
|
|
1383
|
+
|
|
1384
|
+
it("moves screen reader focus to a pending ask's question, an accessible header, when it appears", () => {
|
|
1385
|
+
setAccessibilityFocus.mockClear();
|
|
1386
|
+
const scrollable = {scrollTo: (): void => {}, scrollToEnd: (): void => {}};
|
|
1387
|
+
const {rerender} = render(
|
|
1388
|
+
<GPTChat
|
|
1389
|
+
currentMessages={[userMessage]}
|
|
1390
|
+
histories={histories}
|
|
1391
|
+
onCreateHistory={() => {}}
|
|
1392
|
+
onDeleteHistory={() => {}}
|
|
1393
|
+
onSelectHistory={() => {}}
|
|
1394
|
+
onSubmit={() => {}}
|
|
1395
|
+
/>,
|
|
1396
|
+
{
|
|
1397
|
+
createNodeMock: (element) =>
|
|
1398
|
+
element.props.accessibilityRole === "header" &&
|
|
1399
|
+
element.props.children === PLAN_INPUT.prompt
|
|
1400
|
+
? 42
|
|
1401
|
+
: scrollable,
|
|
1402
|
+
wrapper: ThemeProvider,
|
|
1403
|
+
}
|
|
1404
|
+
);
|
|
1405
|
+
assert.lengthOf(setAccessibilityFocus.mock.calls, 0);
|
|
1406
|
+
|
|
1407
|
+
rerender(
|
|
1408
|
+
<GPTChat
|
|
1409
|
+
currentMessages={[userMessage, askMessage(planAsk())]}
|
|
1410
|
+
histories={histories}
|
|
1411
|
+
onCreateHistory={() => {}}
|
|
1412
|
+
onDeleteHistory={() => {}}
|
|
1413
|
+
onSelectHistory={() => {}}
|
|
1414
|
+
onSubmit={() => {}}
|
|
1415
|
+
/>
|
|
1416
|
+
);
|
|
1417
|
+
|
|
1418
|
+
assert.deepEqual(setAccessibilityFocus.mock.calls, [[42]]);
|
|
1419
|
+
});
|
|
1420
|
+
|
|
1421
|
+
it("focuses a pending ask's group on web without scrolling the page", () => {
|
|
1422
|
+
Platform.OS = "web";
|
|
1423
|
+
const focus = mock((_options: {preventScroll: boolean}) => {});
|
|
1424
|
+
const node = {
|
|
1425
|
+
addEventListener: (): void => {},
|
|
1426
|
+
focus,
|
|
1427
|
+
removeEventListener: (): void => {},
|
|
1428
|
+
scrollTo: (): void => {},
|
|
1429
|
+
scrollToEnd: (): void => {},
|
|
1430
|
+
};
|
|
1431
|
+
const {getByLabelText} = render(
|
|
1432
|
+
<GPTChat
|
|
1433
|
+
currentMessages={[userMessage, askMessage(planAsk())]}
|
|
1434
|
+
histories={histories}
|
|
1435
|
+
onCreateHistory={() => {}}
|
|
1436
|
+
onDeleteHistory={() => {}}
|
|
1437
|
+
onSelectHistory={() => {}}
|
|
1438
|
+
onSubmit={() => {}}
|
|
1439
|
+
/>,
|
|
1440
|
+
{createNodeMock: () => node, wrapper: ThemeProvider}
|
|
1441
|
+
);
|
|
1442
|
+
|
|
1443
|
+
assert.isOk(getByLabelText("Choose a plan"));
|
|
1444
|
+
assert.deepEqual(focus.mock.calls, [[{preventScroll: true}]]);
|
|
1445
|
+
});
|
|
1446
|
+
|
|
1447
|
+
it("leaves assistant markdown in place when uiBlocks is off", async () => {
|
|
1448
|
+
const {queryByTestId, toJSON} = renderChat({
|
|
1449
|
+
currentMessages: [{content: BLOCKS_REPLY, id: "m1", role: "assistant"}],
|
|
1450
|
+
});
|
|
1451
|
+
assert.isNull(queryByTestId("gpt-blocks-m1"));
|
|
1452
|
+
await waitFor(() => {
|
|
1453
|
+
assert.include(JSON.stringify(toJSON()), "Quarter heading");
|
|
1454
|
+
});
|
|
1455
|
+
});
|
|
1456
|
+
|
|
1457
|
+
it("sends a reply and reports open from a block document", async () => {
|
|
1458
|
+
const onSubmit = mock(() => {});
|
|
1459
|
+
const onBlockAction = mock(() => {});
|
|
1460
|
+
const {getByText} = renderChat({
|
|
1461
|
+
currentMessages: [{content: BLOCKS_REPLY, id: "m1", role: "assistant"}],
|
|
1462
|
+
onBlockAction,
|
|
1463
|
+
onSubmit,
|
|
1464
|
+
uiBlocks: true,
|
|
1465
|
+
});
|
|
1466
|
+
assert.isOk(getByText("Quarter heading"));
|
|
1467
|
+
await pressControl(getByText("Ask again"));
|
|
1468
|
+
await pressControl(getByText("Open"));
|
|
1469
|
+
assert.deepEqual(onSubmit.mock.calls[0], ["Show the weekly numbers"]);
|
|
1470
|
+
assert.deepEqual(onBlockAction.mock.calls[0], [
|
|
1471
|
+
{
|
|
1472
|
+
action: {kind: "open", route: "/reports"},
|
|
1473
|
+
blockId: "row",
|
|
1474
|
+
elementId: "open_btn",
|
|
1475
|
+
messageId: "m1",
|
|
1476
|
+
},
|
|
1477
|
+
]);
|
|
1478
|
+
});
|
|
1479
|
+
|
|
1480
|
+
it("shows a callback as loading, then replaces that block", async () => {
|
|
1481
|
+
let finish: (result: {
|
|
1482
|
+
blocks: {blocks: {status: "info"; text: string; type: "badge"}[]; v: 1};
|
|
1483
|
+
replace: "block";
|
|
1484
|
+
}) => void = () => {};
|
|
1485
|
+
const onBlockCallback = mock(
|
|
1486
|
+
() =>
|
|
1487
|
+
new Promise<{
|
|
1488
|
+
blocks: {blocks: {status: "info"; text: string; type: "badge"}[]; v: 1};
|
|
1489
|
+
replace: "block";
|
|
1490
|
+
}>((resolve) => {
|
|
1491
|
+
finish = resolve;
|
|
1492
|
+
})
|
|
1493
|
+
);
|
|
1494
|
+
const {getByTestId, getByText, queryByText} = renderChat({
|
|
1495
|
+
currentMessages: [{content: BLOCKS_REPLY, id: "m1", role: "assistant"}],
|
|
1496
|
+
hostActions: ["export_csv"],
|
|
1497
|
+
onBlockCallback,
|
|
1498
|
+
uiBlocks: true,
|
|
1499
|
+
});
|
|
1500
|
+
await pressControl(getByText("Export"));
|
|
1501
|
+
await waitFor(() => {
|
|
1502
|
+
assert.equal(getByTestId("blocks-1-run_btn").props.accessibilityState.disabled, true);
|
|
1503
|
+
});
|
|
1504
|
+
assert.deepEqual(onBlockCallback.mock.calls[0], [
|
|
1505
|
+
{
|
|
1506
|
+
action: {kind: "callback", name: "export_csv"},
|
|
1507
|
+
blockId: "row",
|
|
1508
|
+
elementId: "run_btn",
|
|
1509
|
+
messageId: "m1",
|
|
1510
|
+
},
|
|
1511
|
+
]);
|
|
1512
|
+
await act(async () => {
|
|
1513
|
+
finish({
|
|
1514
|
+
blocks: {blocks: [{status: "info", text: "Exporting", type: "badge"}], v: 1},
|
|
1515
|
+
replace: "block",
|
|
1516
|
+
});
|
|
1517
|
+
});
|
|
1518
|
+
await waitFor(() => {
|
|
1519
|
+
assert.isOk(getByText("Exporting"));
|
|
1520
|
+
});
|
|
1521
|
+
assert.isNull(queryByText("Export"));
|
|
1522
|
+
});
|
|
1523
|
+
|
|
1524
|
+
it("appends an assistant message when a callback returns text", async () => {
|
|
1525
|
+
const onBlockCallback = mock(async () => ({text: "Export started"}));
|
|
1526
|
+
const {getByText} = renderChat({
|
|
1527
|
+
currentMessages: [{content: BLOCKS_REPLY, id: "m1", role: "assistant"}],
|
|
1528
|
+
hostActions: ["export_csv"],
|
|
1529
|
+
onBlockCallback,
|
|
1530
|
+
uiBlocks: true,
|
|
1531
|
+
});
|
|
1532
|
+
await pressControl(getByText("Export"));
|
|
1533
|
+
await waitFor(() => {
|
|
1534
|
+
assert.isOk(getByText("Export started"));
|
|
1535
|
+
});
|
|
1536
|
+
});
|
|
1537
|
+
|
|
1538
|
+
it("shows callback text when the source message has no id", async () => {
|
|
1539
|
+
const onBlockCallback = mock(async () => ({text: "Export started"}));
|
|
1540
|
+
const {getByText} = renderChat({
|
|
1541
|
+
currentMessages: [{content: BLOCKS_REPLY, role: "assistant"}],
|
|
1542
|
+
hostActions: ["export_csv"],
|
|
1543
|
+
onBlockCallback,
|
|
1544
|
+
uiBlocks: true,
|
|
1545
|
+
});
|
|
1546
|
+
await pressControl(getByText("Export"));
|
|
1547
|
+
await waitFor(() => {
|
|
1548
|
+
assert.isOk(getByText("Export started"));
|
|
1549
|
+
});
|
|
1550
|
+
});
|
|
1551
|
+
|
|
1552
|
+
it("keeps callback text after the message that started it", async () => {
|
|
1553
|
+
const onBlockCallback = mock(async () => ({text: "Export started"}));
|
|
1554
|
+
const {getByText, toJSON} = renderChat({
|
|
1555
|
+
currentMessages: [
|
|
1556
|
+
{content: BLOCKS_REPLY, id: "m1", role: "assistant"},
|
|
1557
|
+
{content: "Next question", id: "m2", role: "user"},
|
|
1558
|
+
],
|
|
1559
|
+
hostActions: ["export_csv"],
|
|
1560
|
+
onBlockCallback,
|
|
1561
|
+
uiBlocks: true,
|
|
1562
|
+
});
|
|
1563
|
+
await pressControl(getByText("Export"));
|
|
1564
|
+
await waitFor(() => {
|
|
1565
|
+
const tree = JSON.stringify(toJSON());
|
|
1566
|
+
const statusAt = tree.indexOf("Export started");
|
|
1567
|
+
const nextAt = tree.indexOf("Next question");
|
|
1568
|
+
assert.isAtLeast(statusAt, 0);
|
|
1569
|
+
assert.isBelow(statusAt, nextAt);
|
|
1570
|
+
});
|
|
1571
|
+
});
|
|
1572
|
+
|
|
1573
|
+
it("drops a callback result after the history changes", async () => {
|
|
1574
|
+
let finish: (result: {text: string}) => void = () => {};
|
|
1575
|
+
const onBlockCallback = mock(
|
|
1576
|
+
() =>
|
|
1577
|
+
new Promise<{text: string}>((resolve) => {
|
|
1578
|
+
finish = resolve;
|
|
1579
|
+
})
|
|
1580
|
+
);
|
|
1581
|
+
const props = {
|
|
1582
|
+
currentMessages: [{content: BLOCKS_REPLY, id: "m1", role: "assistant"}],
|
|
1583
|
+
histories,
|
|
1584
|
+
hostActions: ["export_csv"],
|
|
1585
|
+
onBlockCallback,
|
|
1586
|
+
onCreateHistory: () => {},
|
|
1587
|
+
onDeleteHistory: () => {},
|
|
1588
|
+
onSelectHistory: () => {},
|
|
1589
|
+
onSubmit: () => {},
|
|
1590
|
+
uiBlocks: true,
|
|
1591
|
+
};
|
|
1592
|
+
const {getByText, queryByText, rerender} = renderWithTheme(
|
|
1593
|
+
<GPTChat {...props} currentHistoryId="h1" />
|
|
1594
|
+
);
|
|
1595
|
+
await pressControl(getByText("Export"));
|
|
1596
|
+
rerender(<GPTChat {...props} currentHistoryId="h2" />);
|
|
1597
|
+
await act(async () => {
|
|
1598
|
+
finish({text: "Export started"});
|
|
1599
|
+
});
|
|
1600
|
+
assert.isNull(queryByText("Export started"));
|
|
1601
|
+
});
|
|
1602
|
+
|
|
1603
|
+
it("does not flash a nested layout error when an ask follows the live reply", async () => {
|
|
1604
|
+
const nested = `v: 1
|
|
1605
|
+
blocks:
|
|
1606
|
+
- type: heading
|
|
1607
|
+
text: Plans
|
|
1608
|
+
- type: text
|
|
1609
|
+
markdown: Compare the options.
|
|
1610
|
+
- type: columns
|
|
1611
|
+
children:
|
|
1612
|
+
- type: card
|
|
1613
|
+
title: Team
|
|
1614
|
+
children:
|
|
1615
|
+
- type: text
|
|
1616
|
+
markdown: Twenty dollars
|
|
1617
|
+
- type: text
|
|
1618
|
+
markdown: Starter is free.
|
|
1619
|
+
- type: text
|
|
1620
|
+
markdown: Still writing
|
|
1621
|
+
`;
|
|
1622
|
+
const depthError =
|
|
1623
|
+
"blocks[2].children[0]: A columns or card block is nested inside another columns or card block.";
|
|
1624
|
+
const ask: GPTChatMessage = {
|
|
1625
|
+
ask: {
|
|
1626
|
+
input: {options: [{id: "team", label: "Team"}], prompt: "Which plan?", select: "one"},
|
|
1627
|
+
kind: "choice",
|
|
1628
|
+
status: "pending",
|
|
1629
|
+
toolCallId: "call_plan",
|
|
1630
|
+
},
|
|
1631
|
+
content: "Tool call: ask_choice",
|
|
1632
|
+
role: "tool-call",
|
|
1633
|
+
toolCall: {
|
|
1634
|
+
args: {prompt: "Which plan?"},
|
|
1635
|
+
toolCallId: "call_plan",
|
|
1636
|
+
toolName: "ask_choice",
|
|
1637
|
+
},
|
|
1638
|
+
};
|
|
1639
|
+
const streaming = renderChat({
|
|
1640
|
+
currentMessages: [{content: nested, id: "m1", role: "assistant"}, ask],
|
|
1641
|
+
isStreaming: true,
|
|
1642
|
+
uiBlocks: true,
|
|
1643
|
+
});
|
|
1644
|
+
assert.isNull(streaming.queryByText(depthError));
|
|
1645
|
+
assert.isOk(streaming.getByTestId("gpt-blocks-pending"));
|
|
1646
|
+
|
|
1647
|
+
const finished = renderChat({
|
|
1648
|
+
currentMessages: [{content: nested, id: "m1", role: "assistant"}, ask],
|
|
1649
|
+
uiBlocks: true,
|
|
1650
|
+
});
|
|
1651
|
+
assert.isOk(finished.getByText(depthError));
|
|
1652
|
+
});
|
|
1653
|
+
|
|
1654
|
+
it("renders finished blocks and a spinner while a document is streaming", async () => {
|
|
1655
|
+
const {getByTestId, getByText, queryByTestId, queryByText, UNSAFE_getAllByType} = renderChat({
|
|
1656
|
+
currentMessages: [{content: BLOCKS_STREAMING, id: "m1", role: "assistant"}],
|
|
1657
|
+
isStreaming: true,
|
|
1658
|
+
uiBlocks: true,
|
|
1659
|
+
});
|
|
1660
|
+
assert.isOk(getByText("Done heading"));
|
|
1661
|
+
assert.isNull(queryByText("Still typ"));
|
|
1662
|
+
assert.isOk(getByTestId("gpt-blocks-pending"));
|
|
1663
|
+
assert.isNull(queryByTestId("gpt-streaming-indicator"));
|
|
1664
|
+
await waitFor(() => {
|
|
1665
|
+
assert.isAtLeast(UNSAFE_getAllByType(ActivityIndicator).length, 1);
|
|
1666
|
+
});
|
|
1667
|
+
});
|
|
1668
|
+
|
|
1669
|
+
it("keeps a finished reply intact while the next turn is still sending", () => {
|
|
1670
|
+
const finished = `v: 1
|
|
1671
|
+
blocks:
|
|
1672
|
+
- type: html
|
|
1673
|
+
html: "<p>Invoice</p>"
|
|
1674
|
+
`;
|
|
1675
|
+
const {getByText, queryByText} = renderChat({
|
|
1676
|
+
currentMessages: [
|
|
1677
|
+
{content: finished, id: "m1", role: "assistant"},
|
|
1678
|
+
{content: "Send another", id: "m2", role: "user"},
|
|
1679
|
+
],
|
|
1680
|
+
isStreaming: true,
|
|
1681
|
+
uiBlocks: true,
|
|
1682
|
+
});
|
|
1683
|
+
assert.isOk(getByText("HTML preview is turned off."));
|
|
1684
|
+
assert.isNull(queryByText("The preview appears when this reply finishes."));
|
|
1685
|
+
});
|
|
1686
|
+
});
|