aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2025-02-26 20:48:51 -0500
committerbobzel <zzzman@gmail.com>2025-02-26 20:48:51 -0500
commita9a1a6a507616a77f70d6525dab5027f5b7a60e6 (patch)
tree97a37fdcdfed7bb2f0635b88b543ad525b58de14 /src/client/views/nodes
parentfa8122df7467af3d4410b7daf1cd75227a53fd96 (diff)
added typing to PostToServer calls. made smartDraw popup create images locally.
Diffstat (limited to 'src/client/views/nodes')
-rw-r--r--src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx3
-rw-r--r--src/client/views/nodes/ImageBox.tsx20
-rw-r--r--src/client/views/nodes/RecordingBox/RecordingView.tsx3
-rw-r--r--src/client/views/nodes/chatbot/tools/CreateCSVTool.ts4
-rw-r--r--src/client/views/nodes/chatbot/tools/ImageCreationTool.ts4
-rw-r--r--src/client/views/nodes/chatbot/tools/RAGTool.ts2
-rw-r--r--src/client/views/nodes/chatbot/tools/SearchTool.ts8
7 files changed, 24 insertions, 20 deletions
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx
index 7fc906e59..4d9173211 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx
@@ -29,6 +29,7 @@ import './DocCreatorMenu.scss';
import { DefaultStyleProvider, returnEmptyDocViewList } from '../../StyleProvider';
import { Transform } from '../../../util/Transform';
import { IconProp } from '@fortawesome/fontawesome-svg-core';
+import { Upload } from '../../../../server/SharedMediaTypes';
export enum LayoutType {
Stacked = 'stacked',
@@ -536,7 +537,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
const res = await gptImageCall(prompt);
if (res) {
- const result = await Networking.PostToServer('/uploadRemoteImage', { sources: res });
+ const result = (await Networking.PostToServer('/uploadRemoteImage', { sources: res })) as Upload.FileInformation[];
const source = ClientUtils.prepend(result[0].accessPaths.agnostic.client);
return source;
}
diff --git a/src/client/views/nodes/ImageBox.tsx b/src/client/views/nodes/ImageBox.tsx
index b6b0e4a8a..9395863d8 100644
--- a/src/client/views/nodes/ImageBox.tsx
+++ b/src/client/views/nodes/ImageBox.tsx
@@ -36,7 +36,7 @@ import { OverlayView } from '../OverlayView';
import { AnchorMenu } from '../pdf/AnchorMenu';
import { PinDocView, PinProps } from '../PinFuncs';
import { DrawingFillHandler } from '../smartdraw/DrawingFillHandler';
-import { FireflyImageData } from '../smartdraw/FireflyConstants';
+import { FireflyImageData, isFireflyImageData } from '../smartdraw/FireflyConstants';
import { SmartDrawHandler } from '../smartdraw/SmartDrawHandler';
import { StickerPalette } from '../smartdraw/StickerPalette';
import { StyleProp } from '../StyleProp';
@@ -354,7 +354,8 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
const ext = extname(file);
return file.replace(ext, (this._error ? '_o' : this._curSuffix) + ext);
})(ImageCast(this.Document[Doc.LayoutFieldKey(this.Document)])?.url.href),
- }).then((info: Upload.ImageInformation) => {
+ }).then(res => {
+ const info = res as Upload.ImageInformation;
const img = Docs.Create.ImageDocument(info.accessPaths.agnostic.client, { title: 'expand:' + this.Document.title });
DocUtils.assignImageInfo(info, img);
this._props.addDocTab(img, OpenWhere.addRight);
@@ -627,14 +628,15 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
} else
SmartDrawHandler.Instance.regenerate([this.Document], undefined, undefined, this._regenInput || StrCast(this.Document.title), true).then(
action(newImgs => {
- if (newImgs[0] && !(newImgs[0] instanceof Doc)) {
- const url = newImgs[0].pathname;
+ const firstImg = newImgs[0];
+ if (isFireflyImageData(firstImg)) {
+ const url = firstImg.pathname;
const imgField = new ImageField(url);
this._prevImgs.length === 0 &&
this._prevImgs.push({ prompt: StrCast(this.dataDoc.ai_firefly_prompt), seed: this.dataDoc.ai_firefly_seed as number, href: this.paths.lastElement(), pathname: field.url.pathname });
- this._prevImgs.unshift({ prompt: newImgs[0].prompt, seed: newImgs[0].seed, pathname: url });
+ this._prevImgs.unshift({ prompt: firstImg.prompt, seed: firstImg.seed, pathname: url });
this.dataDoc.ai_firefly_history = JSON.stringify(this._prevImgs);
- this.dataDoc.ai_firefly_prompt = newImgs[0].prompt;
+ this.dataDoc.ai_firefly_prompt = firstImg.prompt;
this.dataDoc[this.fieldKey] = imgField;
this._regenerateLoading = false;
this._regenInput = '';
@@ -688,7 +690,8 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
const ext = extname(file);
return file.replace(ext, (this._error ? '_o' : this._curSuffix) + ext);
})(ImageCast(this.Document[Doc.LayoutFieldKey(this.Document)])?.url.href),
- }).then((info: Upload.ImageInformation) => {
+ }).then(res => {
+ const info = res as Upload.ImageInformation;
const img = Docs.Create.ImageDocument(info.accessPaths.agnostic.client, { title: 'expand:' + this.Document.title });
DocUtils.assignImageInfo(info, img);
const genratedDocs = this.Document.generatedDocs
@@ -741,7 +744,8 @@ export class ImageBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
focus = (anchor: Doc, options: FocusViewOptions) => (anchor.type === DocumentType.CONFIG ? undefined : this._ffref.current?.focus(anchor, options));
renderedPixelDimensions = async () => {
- const { nativeWidth: width, nativeHeight: height } = await Networking.PostToServer('/inspectImage', { source: this.paths[0] });
+ const res = await Networking.PostToServer('/inspectImage', { source: this.paths[0] });
+ const { nativeWidth: width, nativeHeight: height } = res as { nativeWidth: number; nativeHeight: number };
return { width, height };
};
savedAnnotations = () => this._savedAnnotations;
diff --git a/src/client/views/nodes/RecordingBox/RecordingView.tsx b/src/client/views/nodes/RecordingBox/RecordingView.tsx
index 37ffca2d6..e7a6193d4 100644
--- a/src/client/views/nodes/RecordingBox/RecordingView.tsx
+++ b/src/client/views/nodes/RecordingBox/RecordingView.tsx
@@ -1,4 +1,3 @@
-/* eslint-disable react/button-has-type */
import * as React from 'react';
import { useEffect, useRef, useState } from 'react';
import { IconContext } from 'react-icons';
@@ -72,7 +71,7 @@ export function RecordingView(props: IRecordingViewProps) {
const serverPaths: string[] = (await Networking.UploadFilesToServer(videoFiles.map(file => ({ file })))).map(res => (res.result instanceof Error ? '' : res.result.accessPaths.agnostic.server));
// concat the segments together using post call
- const result: Upload.AccessPathInfo | Error = await Networking.PostToServer('/concatVideos', serverPaths);
+ const result = (await Networking.PostToServer('/concatVideos', serverPaths)) as Upload.AccessPathInfo | Error;
!(result instanceof Error) ? props.setResult(result, concatPres || undefined) : console.error('video conversion failed');
})();
}
diff --git a/src/client/views/nodes/chatbot/tools/CreateCSVTool.ts b/src/client/views/nodes/chatbot/tools/CreateCSVTool.ts
index e8ef3fbfe..290c48d6c 100644
--- a/src/client/views/nodes/chatbot/tools/CreateCSVTool.ts
+++ b/src/client/views/nodes/chatbot/tools/CreateCSVTool.ts
@@ -38,10 +38,10 @@ export class CreateCSVTool extends BaseTool<CreateCSVToolParamsType> {
async execute(args: ParametersType<CreateCSVToolParamsType>): Promise<Observation[]> {
try {
console.log('Creating CSV file:', args.filename, ' with data:', args.csvData);
- const { fileUrl, id } = await Networking.PostToServer('/createCSV', {
+ const { fileUrl, id } = (await Networking.PostToServer('/createCSV', {
filename: args.filename,
data: args.csvData,
- });
+ })) as { fileUrl: string; id: string };
this._handleCSVResult(fileUrl, args.filename, id, args.csvData);
diff --git a/src/client/views/nodes/chatbot/tools/ImageCreationTool.ts b/src/client/views/nodes/chatbot/tools/ImageCreationTool.ts
index dc6140871..e92d87dfd 100644
--- a/src/client/views/nodes/chatbot/tools/ImageCreationTool.ts
+++ b/src/client/views/nodes/chatbot/tools/ImageCreationTool.ts
@@ -37,9 +37,9 @@ export class ImageCreationTool extends BaseTool<ImageCreationToolParamsType> {
console.log(`Generating image for prompt: ${image_prompt}`);
// Create an array of promises, each one handling a search for a query
try {
- const { result, url } = await Networking.PostToServer('/generateImage', {
+ const { result, url } = (await Networking.PostToServer('/generateImage', {
image_prompt,
- });
+ })) as { result: Upload.FileInformation & Upload.InspectionResults; url: string };
console.log('Image generation result:', result);
this._createImage(result, { text: RTFCast(image_prompt) });
return url
diff --git a/src/client/views/nodes/chatbot/tools/RAGTool.ts b/src/client/views/nodes/chatbot/tools/RAGTool.ts
index 2db61c768..ef374ed22 100644
--- a/src/client/views/nodes/chatbot/tools/RAGTool.ts
+++ b/src/client/views/nodes/chatbot/tools/RAGTool.ts
@@ -75,7 +75,7 @@ export class RAGTool extends BaseTool<RAGToolParamsType> {
async getFormattedChunks(relevantChunks: RAGChunk[]): Promise<Observation[]> {
try {
- const { formattedChunks } = await Networking.PostToServer('/formatChunks', { relevantChunks });
+ const { formattedChunks } = await Networking.PostToServer('/formatChunks', { relevantChunks }) as { formattedChunks: Observation[]}
if (!formattedChunks) {
throw new Error('Failed to format chunks');
diff --git a/src/client/views/nodes/chatbot/tools/SearchTool.ts b/src/client/views/nodes/chatbot/tools/SearchTool.ts
index 5fc6ab768..6a11407a5 100644
--- a/src/client/views/nodes/chatbot/tools/SearchTool.ts
+++ b/src/client/views/nodes/chatbot/tools/SearchTool.ts
@@ -41,15 +41,15 @@ export class SearchTool extends BaseTool<SearchToolParamsType> {
// Create an array of promises, each one handling a search for a query
const searchPromises = queries.map(async query => {
try {
- const { results } = await Networking.PostToServer('/getWebSearchResults', {
+ const { results } = (await Networking.PostToServer('/getWebSearchResults', {
query,
max_results: this._max_results,
- });
+ })) as { results: { url: string; snippet: string }[] };
const data = results.map((result: { url: string; snippet: string }) => {
const id = uuidv4();
this._addLinkedUrlDoc(result.url, id);
return {
- type: 'text',
+ type: 'text' as const,
text: `<chunk chunk_id="${id}" chunk_type="url"><url>${result.url}</url><overview>${result.snippet}</overview></chunk>`,
};
});
@@ -58,7 +58,7 @@ export class SearchTool extends BaseTool<SearchToolParamsType> {
console.log(error);
return [
{
- type: 'text',
+ type: 'text' as const,
text: `An error occurred while performing the web search for query: ${query}`,
},
];