Skip to content

Commit

Permalink
Merge pull request #76 from superglue-ai/feature/change-runscreen-var…
Browse files Browse the repository at this point in the history
…iables

change runscreen vars
  • Loading branch information
stefanfaistenauer authored Mar 7, 2025
2 parents 526fe17 + 2a193d3 commit 71c2a54
Show file tree
Hide file tree
Showing 8 changed files with 615 additions and 1,447 deletions.
1,246 changes: 119 additions & 1,127 deletions package-lock.json

Large diffs are not rendered by default.

96 changes: 52 additions & 44 deletions packages/core/graphql/resolvers/upsert.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { ApiConfig, Context, ExtractConfig, TransformConfig } from "@superglue/shared";
import { GraphQLResolveInfo } from "graphql";

function resolveField<T>(newValue: T | null | undefined, oldValue: T | undefined, defaultValue?: T): T | undefined {
if (newValue === null) return undefined;
if (newValue !== undefined) return newValue;
if (oldValue !== undefined) return oldValue;
return defaultValue;
}

export const upsertApiResolver = async (
_: any,
{ id, input }: { id: string; input: ApiConfig },
Expand All @@ -10,7 +17,6 @@ export const upsertApiResolver = async (
if(!id) {
throw new Error("id is required");
}
// override id with the id from the input
const oldConfig = await context.datastore.getApiConfig(id, context.orgId);

if(!input.urlHost && !oldConfig?.urlHost) {
Expand All @@ -19,38 +25,39 @@ export const upsertApiResolver = async (
if(!input.instruction && !oldConfig?.instruction) {
throw new Error("instruction is required");
}
// reset the response mapping if there are major updates

// Handle response mapping with existing logic
let newResponseMapping = input.responseMapping;
const hasNoUpdates = (!input?.urlHost || oldConfig?.urlHost === input?.urlHost) &&
(!input?.urlPath || oldConfig?.urlPath === input?.urlPath) &&
(!input?.dataPath || oldConfig?.dataPath === input?.dataPath) &&
(!input?.body || oldConfig?.body === input?.body) &&
(!input?.queryParams || oldConfig?.queryParams === input?.queryParams) &&
(!input?.headers || oldConfig?.headers === input?.headers) &&
(!input?.responseSchema || oldConfig?.responseSchema === input?.responseSchema) &&
(!input?.instruction || oldConfig?.instruction === input?.instruction);
const hasNoUpdates = (input.urlHost === undefined || oldConfig?.urlHost === input.urlHost) &&
(input.urlPath === undefined || oldConfig?.urlPath === input.urlPath) &&
(input.dataPath === undefined || oldConfig?.dataPath === input.dataPath) &&
(input.body === undefined || oldConfig?.body === input.body) &&
(input.queryParams === undefined || oldConfig?.queryParams === input.queryParams) &&
(input.headers === undefined || oldConfig?.headers === input.headers) &&
(input.responseSchema === undefined || oldConfig?.responseSchema === input.responseSchema) &&
(input.instruction === undefined || oldConfig?.instruction === input.instruction);
if (!newResponseMapping && hasNoUpdates) {
newResponseMapping = oldConfig?.responseMapping;
}

const config = {
urlHost: input.urlHost || oldConfig?.urlHost || '',
urlPath: input.urlPath || oldConfig?.urlPath || '',
instruction: input.instruction || oldConfig?.instruction || '',
createdAt: input.createdAt || oldConfig?.createdAt || new Date(),
urlHost: resolveField(input.urlHost, oldConfig?.urlHost, ''),
urlPath: resolveField(input.urlPath, oldConfig?.urlPath, ''),
instruction: resolveField(input.instruction, oldConfig?.instruction, ''),
createdAt: resolveField(input.createdAt, oldConfig?.createdAt, new Date()),
updatedAt: new Date(),
id: id,
method: input.method || oldConfig?.method,
queryParams: input.queryParams || oldConfig?.queryParams,
headers: input.headers || oldConfig?.headers,
body: input.body || oldConfig?.body,
documentationUrl: input.documentationUrl || oldConfig?.documentationUrl,
responseSchema: input.responseSchema || oldConfig?.responseSchema,
method: resolveField(input.method, oldConfig?.method),
queryParams: resolveField(input.queryParams, oldConfig?.queryParams),
headers: resolveField(input.headers, oldConfig?.headers),
body: resolveField(input.body, oldConfig?.body),
documentationUrl: resolveField(input.documentationUrl, oldConfig?.documentationUrl),
responseSchema: resolveField(input.responseSchema, oldConfig?.responseSchema),
responseMapping: newResponseMapping,
authentication: input.authentication || oldConfig?.authentication,
pagination: input.pagination || oldConfig?.pagination,
dataPath: input.dataPath || oldConfig?.dataPath,
version: input.version || oldConfig?.version
authentication: resolveField(input.authentication, oldConfig?.authentication),
pagination: resolveField(input.pagination, oldConfig?.pagination),
dataPath: resolveField(input.dataPath, oldConfig?.dataPath),
version: resolveField(input.version, oldConfig?.version)
};
await context.datastore.upsertApiConfig(id, config, context.orgId);
return config;
Expand All @@ -69,19 +76,20 @@ export const upsertTransformResolver = async (

// reset the response mapping if there are major updates
let newResponseMapping = input.responseMapping;
if (!newResponseMapping && !input.responseSchema && !input.instruction) {
if (newResponseMapping === undefined && !input.responseSchema && !input.instruction) {
newResponseMapping = oldConfig?.responseMapping;
}

const config = {
id: id,
updatedAt: new Date(),
createdAt: oldConfig?.createdAt || new Date(),
instruction: input.instruction || oldConfig?.instruction || '',
responseSchema: input.responseSchema || oldConfig?.responseSchema || {},
createdAt: resolveField(input.createdAt, oldConfig?.createdAt, new Date()),
instruction: resolveField(input.instruction, oldConfig?.instruction, ''),
responseSchema: resolveField(input.responseSchema, oldConfig?.responseSchema, {}),
responseMapping: newResponseMapping,
version: input.version || oldConfig?.version
version: resolveField(input.version, oldConfig?.version)
};

await context.datastore.upsertTransformConfig(id, config, context.orgId);
return config;
};
Expand All @@ -98,21 +106,21 @@ export const upsertExtractResolver = async (
const oldConfig = await context.datastore.getExtractConfig(id, context.orgId);
const config = {
id: id,
urlHost: input.urlHost || oldConfig?.urlHost || '',
urlPath: input.urlPath || oldConfig?.urlPath || '',
instruction: input.instruction || oldConfig?.instruction || '',
createdAt: oldConfig?.createdAt || new Date(),
urlHost: resolveField(input.urlHost, oldConfig?.urlHost, ''),
urlPath: resolveField(input.urlPath, oldConfig?.urlPath, ''),
instruction: resolveField(input.instruction, oldConfig?.instruction, ''),
createdAt: resolveField(input.createdAt, oldConfig?.createdAt, new Date()),
updatedAt: new Date(),
method: input.method || oldConfig?.method,
queryParams: input.queryParams || oldConfig?.queryParams,
headers: input.headers || oldConfig?.headers,
body: input.body || oldConfig?.body,
documentationUrl: input.documentationUrl || oldConfig?.documentationUrl,
decompressionMethod: input.decompressionMethod || oldConfig?.decompressionMethod,
authentication: input.authentication || oldConfig?.authentication,
fileType: input.fileType || oldConfig?.fileType,
dataPath: input.dataPath || oldConfig?.dataPath,
version: input.version || oldConfig?.version
method: resolveField(input.method, oldConfig?.method),
queryParams: resolveField(input.queryParams, oldConfig?.queryParams),
headers: resolveField(input.headers, oldConfig?.headers),
body: resolveField(input.body, oldConfig?.body),
documentationUrl: resolveField(input.documentationUrl, oldConfig?.documentationUrl),
decompressionMethod: resolveField(input.decompressionMethod, oldConfig?.decompressionMethod),
authentication: resolveField(input.authentication, oldConfig?.authentication),
fileType: resolveField(input.fileType, oldConfig?.fileType),
dataPath: resolveField(input.dataPath, oldConfig?.dataPath),
version: resolveField(input.version, oldConfig?.version)
};
await context.datastore.upsertExtractConfig(id, config, context.orgId);
return config;
Expand Down
9 changes: 6 additions & 3 deletions packages/core/utils/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export async function generateSchema(instruction: string, responseData: string)

while (retryCount <= MAX_RETRIES) {
try {
return await attemptSchemaGeneration(messages, retryCount);
const schema = await attemptSchemaGeneration(messages, retryCount);
console.log(`Schema generated`);
return schema;
} catch (error) {
retryCount++;
if (retryCount > MAX_RETRIES) {
Expand All @@ -41,7 +43,7 @@ async function attemptSchemaGeneration(
messages: ChatCompletionMessageParam[],
retry: number
): Promise<string> {
console.log(`Generating schema: ${retry ? `(retry ${retry})` : ""}`);
console.log(`Generating schema${retry ? `: (retry ${retry})` : ""}`);
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
baseURL: process.env.OPENAI_API_BASE_URL
Expand Down Expand Up @@ -72,6 +74,7 @@ async function attemptSchemaGeneration(
throw new Error("No schema generated");
}
const validator = new Validator();
const validation = validator.validate({}, generatedSchema);
validator.validate({}, generatedSchema);

return generatedSchema;
}
3 changes: 3 additions & 0 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"lint": "next lint"
},
"dependencies": {
"@types/prismjs": "^1.26.5",
"prismjs": "^1.29.0",
"react-simple-code-editor": "^0.14.1",
"@apollo/client": "^3.13.1",
"@radix-ui/react-accordion": "^1.2.3",
"@radix-ui/react-alert-dialog": "^1.1.6",
Expand Down
54 changes: 54 additions & 0 deletions packages/web/src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,47 @@ body {
--chart-4: 330 75% 55%;
--chart-5: 150 65% 45%;
}

/* Code editor syntax highlighting */
.token {
background: none !important;
}

.token.property {
color: hsl(var(--chart-0));
}

.token.string {
color: hsl(var(--chart-5));
}

.token.number {
color: hsl(var(--chart-5));
}

.token.boolean {
color: hsl(var(--chart-2));
}

.token.punctuation {
color: hsl(var(--muted-foreground));
}

.token.operator {
color: hsl(var(--muted-foreground));
}

.token.keyword {
color: hsl(var(--chart-1));
}

.token.null {
color: hsl(var(--chart-2));
}

.token.comment {
color: hsl(var(--muted-foreground));
}
}

@layer base {
Expand All @@ -74,4 +115,17 @@ body {
button:hover {
@apply bg-secondary transition-colors;
}

/* Custom scrollbar styles */
::-webkit-scrollbar {
@apply w-2 h-2;
}

::-webkit-scrollbar-track {
@apply bg-secondary/50 rounded-full;
}

::-webkit-scrollbar-thumb {
@apply bg-muted-foreground/50 rounded-full hover:bg-muted-foreground/70 transition-colors;
}
}
Loading

0 comments on commit 71c2a54

Please sign in to comment.