- {#if mod.value.type === FlowModuleValue.type.SCRIPT && !shouldPick}
+ {#if mod.value.type === 'script' && !shouldPick}
{/if}
- {#if mod.value.type === FlowModuleValue.type.RAWSCRIPT && !shouldPick}
+ {#if mod.value.type === 'rawscript' && !shouldPick}
- Script {mod?.value.path}
+ Script {'path' in mod?.value ? mod?.value.path : ''}
{#if modalViewerLanguage === 'python3'}
diff --git a/frontend/src/lib/components/flows/flowStore.ts b/frontend/src/lib/components/flows/flowStore.ts
index ce525fcebb..da4841bc01 100644
--- a/frontend/src/lib/components/flows/flowStore.ts
+++ b/frontend/src/lib/components/flows/flowStore.ts
@@ -1,5 +1,5 @@
import type { Schema } from '$lib/common'
-import { FlowModuleValue, InputTransform, ScriptService, type Flow, type FlowModule } from '$lib/gen'
+import { InputTransform, RawScript, ScriptService, type Flow, type FlowModule } from '$lib/gen'
import { initialCode } from '$lib/script_helpers'
import { userStore, workspaceStore } from '$lib/stores'
import { derived, get, writable } from 'svelte/store'
@@ -12,9 +12,9 @@ export const flowStore = writable(undefined)
export const schemasStore = writable([])
export function initFlow(flow: Flow) {
- const newMode = flow.value.modules[1]?.value.type === FlowModuleValue.type.FORLOOPFLOW ? 'pull' : 'push'
+ const newMode = flow.value.modules[1]?.value.type === 'forloopflow' ? 'pull' : 'push'
mode.set(newMode)
- flow = flattenForloopFlows(flow, newMode)
+ flow = flattenForloopFlows(flow)
flow.value.modules.forEach((mod) => {
Object.values(mod.input_transform).forEach((inp) => {
if (inp.type == InputTransform.type.JAVASCRIPT) {
@@ -46,10 +46,11 @@ export function codeToStaticTemplate(code?: string): string | undefined {
}
return undefined
}
-export function flattenForloopFlows(flow: Flow, mode: FlowMode): Flow {
+export function flattenForloopFlows(flow: Flow): Flow {
let newFlow: Flow = JSON.parse(JSON.stringify(flow))
- if (mode == 'pull') {
- const oldModules = newFlow.value.modules[1].value.value?.modules ?? []
+ const mod = flow.value.modules[1]?.value
+ if (mod.type === 'forloopflow') {
+ const oldModules = mod.value?.modules ?? []
newFlow.value.modules = newFlow.value.modules.slice(0, 1)
newFlow.value.modules.push(...oldModules)
}
@@ -61,7 +62,7 @@ export const isCopyFirstStepSchemaDisabled = derived(flowStore, (flow: Flow | un
const modules = flow.value.modules
const [firstModule] = modules
return (
- modules.length === 0 || (firstModule.value.path === '' && firstModule.value.type === 'script')
+ modules.length === 0 || (firstModule.value.type === 'script' && firstModule.value.path === '')
)
} else {
return true
@@ -70,7 +71,7 @@ export const isCopyFirstStepSchemaDisabled = derived(flowStore, (flow: Flow | un
export function addModule(i?: number) {
const newModule: FlowModule = {
- value: { type: FlowModuleValue.type.SCRIPT, path: '' },
+ value: { type: 'script', path: '' },
input_transform: {}
}
@@ -89,7 +90,7 @@ export function addModule(i?: number) {
export async function pickScript(path: string, step: number) {
flowStore.update((flow: Flow) => {
if (flow.value.modules[step]) {
- flow.value.modules[step].value.path = path
+ flow.value.modules[step].value = { type: 'script', path }
}
return flow
@@ -98,11 +99,11 @@ export async function pickScript(path: string, step: number) {
await loadSchema(step)
}
-export async function createInlineScriptModule(language: FlowModuleValue.language, step: number, mode: FlowMode) {
+export async function createInlineScriptModule(language: RawScript.language, step: number, mode: FlowMode) {
const code = initialCode(language, (mode === 'pull' && step == 0))
flowStore.update((flow: Flow) => {
flow.value.modules[step].value = {
- type: FlowModuleValue.type.RAWSCRIPT,
+ type: 'rawscript',
content: code,
language,
}
@@ -132,6 +133,9 @@ export async function fork(step: number) {
const flow = get(flowStore)
const flowModuleValue = flow.value.modules[step].value
+ if (flowModuleValue.type !== 'script') {
+ throw new Error('Can only fork a script module')
+ }
if (flowModuleValue.path) {
const moduleValue = await createInlineScriptModuleFromPath(flowModuleValue.path)
flowStore.update((flow: Flow) => {
@@ -146,8 +150,13 @@ export async function createScriptFromInlineScript(step: number) {
const schemas = get(schemasStore)
const user = get(userStore)
+
const flowModuleValue = flow.value.modules[step].value
+ if (flowModuleValue.type != 'rawscript') {
+ throw new Error("Can't create script from non-inline script")
+ }
+
const originalScriptPath = flowModuleValue.path
const wasForked = Boolean(originalScriptPath)
@@ -170,17 +179,17 @@ export async function createScriptFromInlineScript(step: number) {
path: availablePath,
summary: '',
description,
- content: flowModuleValue.content!,
+ content: flowModuleValue.content,
parent_hash: undefined,
schema: schemas[step],
is_template: false,
- language: flowModuleValue.language!
+ language: flowModuleValue.language
}
})
flowStore.update((flow: Flow) => {
flow.value.modules[step].value = {
- type: FlowModuleValue.type.SCRIPT,
+ type: 'script',
path: availablePath
}
@@ -236,5 +245,5 @@ export async function findNextAvailablePath(path: string): Promise {
export function shouldPickOrCreateScript(flow: Flow, step: number): boolean {
const module = flow.value.modules[step]
- return module.value.path === '' && module.value.language === undefined
+ return module.value.type === 'script' && module.value.path === ''
}
diff --git a/frontend/src/lib/components/flows/utils.ts b/frontend/src/lib/components/flows/utils.ts
index c4a3f8c927..3915c73fa8 100644
--- a/frontend/src/lib/components/flows/utils.ts
+++ b/frontend/src/lib/components/flows/utils.ts
@@ -1,5 +1,5 @@
import type { Schema } from '$lib/common'
-import { FlowModuleValue, InputTransform, type Flow, type FlowModule } from '$lib/gen'
+import { type FlowModuleValue, InputTransform, type Flow, type FlowModule, RawScript } from '$lib/gen'
import { inferArgs } from '$lib/infer'
import { loadSchema } from '$lib/scripts'
import { emptySchema, getScriptByPath, schemaToObject } from '$lib/utils'
@@ -32,7 +32,7 @@ export function flowToMode(flow: Flow | any, mode: FlowMode): Flow {
newFlow.value.modules.push({
input_transform: oldModules[0].input_transform,
value: {
- type: FlowModuleValue.type.FORLOOPFLOW,
+ type: 'forloopflow',
iterator: { type: InputTransform.type.JAVASCRIPT, expr: 'result.res1' },
value: {
modules: oldModules
@@ -60,14 +60,14 @@ export function getTypeAsString(arg: any): string {
export async function getFirstStepSchema(flow: Flow): Promise {
const [firstModule] = flow.value.modules
- if (firstModule.value.type === FlowModuleValue.type.RAWSCRIPT) {
+ if (firstModule.value.type === 'rawscript') {
const { language, content } = firstModule.value
if (language && content) {
const schema = emptySchema()
await inferArgs(language, content, schema)
return schema
}
- } else if (firstModule.value.path) {
+ } else if (firstModule.value.type == 'script') {
return await loadSchema(firstModule.value.path)
}
return emptySchema()
@@ -77,8 +77,8 @@ export async function createInlineScriptModuleFromPath(path: string): Promise
schema: Schema
}> {
- const isRaw = module?.value.type === FlowModuleValue.type.RAWSCRIPT
+ const mod = module.value
- if (isRaw || Boolean(module.value.path)) {
+ if (mod.type == 'rawscript' || mod.type === 'script') {
let schema: Schema
- if (isRaw) {
+ if (mod.type === 'rawscript') {
schema = emptySchema()
- await inferArgs(module.value.language!, module.value.content!, schema)
+ await inferArgs(mod.language!, mod.content!, schema)
} else {
- schema = await loadSchema(module.value.path!)
+ schema = await loadSchema(mod.path!)
}
const keys = Object.keys(schema?.properties ?? {})
diff --git a/frontend/src/lib/infer.ts b/frontend/src/lib/infer.ts
index de0fca2a03..e91d09dbf7 100644
--- a/frontend/src/lib/infer.ts
+++ b/frontend/src/lib/infer.ts
@@ -1,6 +1,5 @@
import type { Schema, SchemaProperty } from './common.js'
import { ScriptService, type MainArgSignature } from '$lib/gen'
-import { sendUserToast } from './utils.js'
export async function inferArgs(
language: 'python3' | 'deno',
diff --git a/frontend/src/lib/utils.ts b/frontend/src/lib/utils.ts
index 76690dbb0f..e6b7fbd525 100644
--- a/frontend/src/lib/utils.ts
+++ b/frontend/src/lib/utils.ts
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { goto } from '$app/navigation'
-import { FlowService, Script, ScriptService, type Flow, type User } from '$lib/gen'
+import { FlowService, ScriptService, type Flow, type User } from '$lib/gen'
import { toast } from '@zerodevx/svelte-toast'
import { get } from 'svelte/store'
import type { Schema } from './common'
@@ -48,9 +48,9 @@ export function displayDate(dateString: string | undefined): string {
}
}
-export function msToSec(ms: integer | undefined): string {
- if (ms === undefined) return '?';
- return (ms / 1000).toLocaleString(undefined, {maximumFractionDigits: 3});
+export function msToSec(ms: number | undefined): string {
+ if (ms === undefined) return '?'
+ return (ms / 1000).toLocaleString(undefined, { maximumFractionDigits: 3 })
}
export function getToday() {
@@ -302,7 +302,7 @@ export function step(n: number): any;
/**
* flow input as an object
*/
-export const flow_input: ${previousResultType};
+export const flow_input: ${flowInput};
/**
* previous result as an object
diff --git a/frontend/src/routes/__layout-root@none.svelte b/frontend/src/routes/__layout-root@none.svelte
index 4bba8882fd..f8045d3fac 100644
--- a/frontend/src/routes/__layout-root@none.svelte
+++ b/frontend/src/routes/__layout-root@none.svelte
@@ -8,6 +8,7 @@
import { sendUserToast } from '$lib/utils'
import { SvelteToast } from '@zerodevx/svelte-toast'
import { onMount } from 'svelte'
+ import github from 'svelte-highlight/styles/github'
// Default toast options
const toastOptions = {
@@ -93,6 +94,10 @@
})
+
+ {@html github}
+
+
diff --git a/frontend/src/routes/__layout@root.svelte b/frontend/src/routes/__layout@root.svelte
index 6a30c570c5..24dad814c9 100644
--- a/frontend/src/routes/__layout@root.svelte
+++ b/frontend/src/routes/__layout@root.svelte
@@ -21,10 +21,9 @@
import { onMount } from 'svelte'
import Icon from 'svelte-awesome'
import '../app.css'
- import { page } from '$app/stores'
import { OpenAPI } from '$lib/gen'
import { superadmin, userStore, usersWorkspaceStore, workspaceStore } from '$lib/stores'
- import { clickOutside, sendUserToast, sleep } from '$lib/utils'
+ import { clickOutside } from '$lib/utils'
import { logout } from '$lib/logout'
import { goto } from '$app/navigation'
diff --git a/frontend/src/routes/audit_logs.svelte b/frontend/src/routes/audit_logs.svelte
index 734b47d262..744a44094f 100644
--- a/frontend/src/routes/audit_logs.svelte
+++ b/frontend/src/routes/audit_logs.svelte
@@ -10,7 +10,7 @@
import { AuditService, AuditLog, UserService } from '$lib/gen'
import type { ActionKind } from '$lib/common'
import { page } from '$app/stores'
- import { displayDate, sendUserToast } from '$lib/utils'
+ import { displayDate } from '$lib/utils'
import { goto } from '$app/navigation'
import PageHeader from '$lib/components/PageHeader.svelte'
import { userStore, workspaceStore } from '$lib/stores'
diff --git a/frontend/src/routes/flows.svelte b/frontend/src/routes/flows.svelte
index 5d800cc38c..57afa8f732 100644
--- a/frontend/src/routes/flows.svelte
+++ b/frontend/src/routes/flows.svelte
@@ -215,7 +215,7 @@
|