Skip to content

Commit 88de307

Browse files
Brian Leonardbnchrch
Brian Leonard
andcommitted
chore: add data and caching to AI assist (#13750)
Co-authored-by: Ben Church <[email protected]>
1 parent 9d5a39e commit 88de307

File tree

12 files changed

+237
-140
lines changed

12 files changed

+237
-140
lines changed

airbyte-connector-builder-server/src/main/kotlin/io/airbyte/connector_builder/requester/assist/AssistProxy.kt

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class AssistProxy(private val proxyConfig: AssistConfiguration) {
2222
requestMethod = "POST"
2323
setRequestProperty("Content-Type", "application/json")
2424
doOutput = true
25+
connectTimeout = 1 * 60 * 1000 // 1 minute
26+
readTimeout = 10 * 60 * 1000 // 10 minutes
2527
}
2628

2729
connection.outputStream.use { outputStream ->

airbyte-webapp/jest.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const jestConfig: Config = {
1818
"\\.(css|png|scss)$": "test-utils/mock-data/mockEmpty.js",
1919
"\\.svg$": "test-utils/mock-data/mockSvgString.js",
2020
"\\.svg\\?react$": "test-utils/mock-data/mockSvg.js",
21+
"\\?worker$": "test-utils/mock-data/mockWorker.js",
2122
},
2223
setupFilesAfterEnv: ["./src/test-utils/setup-tests.ts"],
2324
globalSetup: "./src/test-utils/global-setup.js",

airbyte-webapp/src/components/connectorBuilder/Builder/AddStreamButton.tsx

+14-31
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ import { Icon } from "components/ui/Icon";
1414
import { Modal, ModalBody, ModalFooter } from "components/ui/Modal";
1515

1616
import {
17-
BuilderAssistCreateStreamParams,
1817
BuilderAssistFindStreamsResponse,
19-
BuilderAssistGlobalParams,
18+
BuilderAssistInputStreamParams,
2019
BuilderAssistManifestResponse,
2120
useBuilderAssistCreateStream,
2221
useBuilderAssistFindStreams,
@@ -29,7 +28,7 @@ import { convertToAssistFormValuesSync } from "./Assist/assist";
2928
import { AssistWaiting } from "./Assist/AssistWaiting";
3029
import { BuilderField } from "./BuilderField";
3130
import { BuilderFieldWithInputs } from "./BuilderFieldWithInputs";
32-
import { AssistData, BuilderStream, DEFAULT_BUILDER_STREAM_VALUES, DEFAULT_SCHEMA, useBuilderWatch } from "../types";
31+
import { BuilderStream, DEFAULT_BUILDER_STREAM_VALUES, DEFAULT_SCHEMA, useBuilderWatch } from "../types";
3332

3433
interface AddStreamResponse {
3534
streamName: string;
@@ -172,26 +171,12 @@ const AddStreamModal = ({
172171
streams: BuilderStream[];
173172
initialUrlPath?: string;
174173
}) => {
175-
const baseUrl = useBuilderWatch("formValues.global.urlBase");
176-
const appName = useBuilderWatch("name") || "Connector";
177-
const assistData: AssistData = useBuilderWatch("formValues.assist");
178174
const { assistEnabled } = useConnectorBuilderFormState();
179-
180175
const shouldAssist = assistEnabled && !isDuplicate;
181176

182177
// TODO refactor to useMutation, as this is a bit of a hack
183178
const [assistFormValues, setAssistFormValues] = useState<AddStreamFormValues | null>(null);
184179

185-
const assistParams = useMemo(
186-
() => ({
187-
docs_url: assistData?.docsUrl,
188-
openapi_spec_url: assistData?.openApiSpecUrl,
189-
app_name: appName,
190-
url_base: baseUrl,
191-
}),
192-
[assistData?.docsUrl, assistData?.openApiSpecUrl, appName, baseUrl]
193-
);
194-
195180
const submitResponse = useCallback(
196181
(values: AddStreamFormValues) => {
197182
const otherStreamValues = values.copyOtherStream
@@ -235,10 +220,9 @@ const AddStreamModal = ({
235220
return null;
236221
}
237222
return {
238-
...assistParams,
239223
stream_name: assistFormValues.streamName,
240224
};
241-
}, [assistParams, assistFormValues]);
225+
}, [assistFormValues]);
242226

243227
return (
244228
<Modal
@@ -255,7 +239,6 @@ const AddStreamModal = ({
255239
isDuplicate={isDuplicate}
256240
streams={streams}
257241
initialUrlPath={initialUrlPath}
258-
assistParams={assistParams}
259242
shouldAssist={shouldAssist}
260243
/>
261244
)}
@@ -276,19 +259,21 @@ const AddStreamForm = ({
276259
isDuplicate,
277260
streams,
278261
initialUrlPath,
279-
assistParams,
280262
shouldAssist,
281263
}: {
282264
onSubmit: (values: AddStreamFormValues) => void;
283265
onCancel: () => void;
284266
isDuplicate: boolean;
285267
streams: BuilderStream[];
286268
initialUrlPath?: string;
287-
assistParams: BuilderAssistGlobalParams;
288269
shouldAssist: boolean;
289270
}) => {
290271
const { formatMessage } = useIntl();
291272

273+
const { data, isFetching } = useBuilderAssistFindStreams({
274+
enabled: shouldAssist,
275+
});
276+
292277
const showCopyFromStream = !isDuplicate && streams.length > 0;
293278
const showUrlPath = !shouldAssist;
294279

@@ -306,6 +291,7 @@ const AddStreamForm = ({
306291
validator.urlPath = yup.string().required("form.empty.error");
307292
}
308293

294+
// put the main form default values here so the API can use the context in the new form
309295
const methods = useForm({
310296
defaultValues: {
311297
streamName: "",
@@ -324,7 +310,7 @@ const AddStreamForm = ({
324310
<form onSubmit={methods.handleSubmit(onSubmit)}>
325311
<ModalBody className={styles.body}>
326312
{shouldAssist ? (
327-
<AssistedStreamNameField path="streamName" streams={streams} assistParams={assistParams} />
313+
<AssistedStreamNameField path="streamName" streams={streams} data={data} isFetching={isFetching} />
328314
) : (
329315
<BuilderField
330316
path="streamName"
@@ -393,19 +379,16 @@ const AssistLoadingMessage = () => {
393379
const AssistedStreamNameField = ({
394380
path,
395381
streams,
396-
assistParams,
382+
data,
383+
isFetching,
397384
}: {
398385
path: string;
399386
streams: BuilderStream[];
400-
assistParams: BuilderAssistGlobalParams;
387+
data: BuilderAssistFindStreamsResponse | undefined;
388+
isFetching: boolean;
401389
}) => {
402390
const { formatMessage } = useIntl();
403391

404-
const { data, isFetching } = useBuilderAssistFindStreams({
405-
...assistParams,
406-
enabled: true,
407-
});
408-
409392
const streamOptions = useMemo(() => {
410393
if (data) {
411394
return getStreamOptions(streams, data);
@@ -443,7 +426,7 @@ const AssistProcessing = ({
443426
onComplete,
444427
onSkip,
445428
}: {
446-
input: BuilderAssistCreateStreamParams;
429+
input: BuilderAssistInputStreamParams;
447430
onComplete: (values: AddStreamResponse) => void;
448431
onSkip: () => void;
449432
}) => {

airbyte-webapp/src/components/connectorBuilder/Builder/Assist/AssistButton.tsx

+17-28
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { Tooltip } from "components/ui/Tooltip";
1313

1414
import {
1515
BuilderAssistFindStreamsResponse,
16+
BuilderAssistInputAllParams,
1617
BuilderAssistManifestResponse,
1718
useBuilderAssistFindAuth,
1819
useBuilderAssistFindUrlBase,
@@ -144,66 +145,54 @@ export interface AssistButtonProps {
144145
}
145146

146147
interface AssistButtonConfig {
147-
useHook: (params: object) => UseQueryResult<BuilderAssistManifestResponse, HttpError<KnownExceptionInfo>>;
148+
useHook: (
149+
input: BuilderAssistInputAllParams
150+
) => UseQueryResult<BuilderAssistManifestResponse, HttpError<KnownExceptionInfo>>;
151+
useHookParams: Array<keyof BuilderAssistInputAllParams>;
148152
formPathToSet: string | ((streamNum: number) => string);
149153
propertiesToPluck?: string[];
150154
}
151155

152-
const assistButtonConfigs = {
156+
const assistButtonConfigs: { [key in AssistKey]: AssistButtonConfig } = {
153157
urlbase: {
154158
useHook: useBuilderAssistFindUrlBase,
159+
useHookParams: [],
155160
formPathToSet: "global.urlBase",
156161
},
157162
auth: {
158163
useHook: useBuilderAssistFindAuth,
164+
useHookParams: [],
159165
formPathToSet: "global.authenticator",
160166
},
161167
metadata: {
162168
useHook: useBuilderAssistStreamMetadata,
169+
useHookParams: ["stream_name"],
163170
formPathToSet: (streamNum: number) => `streams.${streamNum}`,
164171
propertiesToPluck: ["urlPath", "httpMethod", "primaryKey"],
165172
},
166173
record_selector: {
167174
useHook: useBuilderAssistStreamResponse,
175+
useHookParams: ["stream_name"],
168176
formPathToSet: (streamNum: number) => `streams.${streamNum}.recordSelector`,
169177
},
170178
paginator: {
171179
useHook: useBuilderAssistFindStreamPaginator,
180+
useHookParams: ["stream_name"],
172181
formPathToSet: (streamNum: number) => `streams.${streamNum}.paginator`,
173182
},
174-
} as const;
183+
};
175184

176185
export const AssistButton: React.FC<AssistButtonProps> = ({ assistKey, streamNum }) => {
177-
const assistData: AssistData = useBuilderWatch("formValues.assist");
178-
const app_name = useWatch({ name: "name" }) || "Connector";
179-
const url_base = useWatch({ name: "formValues.global.urlBase" });
180186
const stream_name = useWatch({ name: `formValues.streams.${streamNum}.name` });
181187

182-
const { assistEnabled } = useConnectorBuilderFormState();
183-
if (!assistData || !assistEnabled) {
184-
return null;
185-
}
186-
187-
// TODO: this is a hack to get the docs_url and openapi_spec_url from the assistData
188-
// Before we bring this to our customers we should hoist this error higher.
189-
const docs_url = assistData?.docsUrl?.trim();
190-
const openapi_spec_url = assistData?.openApiSpecUrl?.trim();
188+
const config = assistButtonConfigs[assistKey];
189+
const hookParams = useMemo(() => pick({ stream_name }, config.useHookParams), [stream_name, config.useHookParams]);
191190

192-
const config = assistButtonConfigs[assistKey] as AssistButtonConfig | undefined;
193-
if (!config) {
194-
console.error(`Unknown assist key: ${assistKey}`);
191+
const { assistEnabled } = useConnectorBuilderFormState();
192+
if (!assistEnabled) {
195193
return null;
196194
}
197195

198-
const hookParams = {
199-
docs_url,
200-
openapi_spec_url,
201-
app_name,
202-
url_base,
203-
stream_name,
204-
streamNum,
205-
};
206-
207196
return <InternalAssistButton assistKey={assistKey} hookParams={hookParams} streamNum={streamNum} {...config} />;
208197
};
209198

@@ -278,8 +267,8 @@ export const AssistAddStreamButton: React.FC<AssistAddStreamProps> = ({
278267

279268
interface InternalAssistButtonProps extends AssistButtonConfig {
280269
streamNum?: number;
281-
hookParams: object;
282270
assistKey: AssistKey;
271+
hookParams: BuilderAssistInputAllParams;
283272
}
284273

285274
const InternalAssistButton: React.FC<InternalAssistButtonProps> = ({

0 commit comments

Comments
 (0)