fix: correct raw app flow inputs (#8667)

* fix: correct raw app flow inputs

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* refactor: remove raw app legacy migration

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
centdix
2026-04-02 03:57:56 +02:00
committed by GitHub
parent c86846ac19
commit 28c073056c
5 changed files with 156 additions and 34 deletions

View File

@@ -8,10 +8,10 @@
import WorkspaceFlowList from './WorkspaceFlowList.svelte'
import { createEventDispatcher, untrack } from 'svelte'
import type { Schema } from '$lib/common'
import { schemaToInputsSpec } from '$lib/components/apps/utils'
import { defaultIfEmptyString, emptySchema } from '$lib/utils'
import { emptySchema } from '$lib/utils'
import { loadSchema } from '$lib/infer'
import { workspaceStore } from '$lib/stores'
import { buildPathRunnableSelection } from './runnableSelectorUtils'
type TabType = 'hubscripts' | 'workspacescripts' | 'workspaceflows' | 'inlinescripts'
@@ -62,51 +62,44 @@
}
async function pickScript(path: string) {
const schema = await loadSchemaFromTriggerable(path, 'script')
const fields = schemaToInputsSpec(schema.schema, defaultUserInput)
const runnable = {
type: 'path',
const selection = buildPathRunnableSelection(
path,
runType: 'script',
schema: schema.schema,
name: defaultIfEmptyString(schema.summary, path)
} as const
'script',
await loadSchemaFromTriggerable(path, 'script'),
defaultUserInput,
rawApps
)
dispatch('pick', {
runnable,
fields
runnable: selection.runnable,
fields: selection.fields
})
}
async function pickFlow(path: string) {
const schema = await loadSchemaFromTriggerable(path, 'flow')
const fields = schemaToInputsSpec(schema.schema, defaultUserInput)
const runnable = {
type: 'path',
const selection = buildPathRunnableSelection(
path,
runType: 'flow',
schema,
name: defaultIfEmptyString(schema.summary, path)
} as const
'flow',
await loadSchemaFromTriggerable(path, 'flow'),
defaultUserInput,
rawApps
)
dispatch('pick', {
runnable,
fields
runnable: selection.runnable,
fields: selection.fields
})
}
async function pickHubScript(path: string) {
const schema = await loadSchemaFromTriggerable(path, 'hubscript')
const fields = schemaToInputsSpec(schema.schema, defaultUserInput)
const runnable = {
type: 'path',
const selection = buildPathRunnableSelection(
path,
runType: 'hubscript',
schema: schema.schema,
name: defaultIfEmptyString(schema.summary, path)
} as const
'hubscript',
await loadSchemaFromTriggerable(path, 'hubscript'),
defaultUserInput,
rawApps
)
dispatch('pick', {
runnable,
fields
runnable: selection.runnable,
fields: selection.fields
})
}

View File

@@ -0,0 +1,53 @@
import { describe, expect, it } from 'vitest'
import type { LoadedRunnableSchema } from './runnableSelectorUtils'
import { buildPathRunnableSelection } from './runnableSelectorUtils'
const loadedSchema: LoadedRunnableSchema = {
summary: 'My flow',
schema: {
$schema: 'https://json-schema.org/draft/2020-12/schema',
type: 'object',
required: ['string_input'],
properties: {
string_input: {
type: 'string',
default: ''
}
}
}
}
describe('buildPathRunnableSelection', () => {
it('keeps the actual schema object and defaults raw-app fields to user mode', () => {
const selection = buildPathRunnableSelection(
'u/dev/my_flow',
'flow',
loadedSchema,
false,
true
)
expect(selection.runnable).toMatchObject({
type: 'path',
path: 'u/dev/my_flow',
runType: 'flow',
schema: loadedSchema.schema,
name: 'My flow'
})
expect(selection.fields.string_input.type).toBe('user')
expect(selection.fields.string_input.value).toBe('')
})
it('preserves static defaults for non-raw-app pickers', () => {
const selection = buildPathRunnableSelection(
'u/dev/my_flow',
'flow',
loadedSchema,
false,
false
)
expect(selection.fields.string_input.type).toBe('static')
})
})

View File

@@ -0,0 +1,31 @@
import type { Schema } from '$lib/common'
import type { Runnable, StaticAppInput } from '$lib/components/apps/inputType'
import { schemaToInputsSpec } from '$lib/components/apps/utils'
import { defaultIfEmptyString } from '$lib/utils'
export type LoadedRunnableSchema = {
schema: Schema
summary: string | undefined
}
export function buildPathRunnableSelection(
path: string,
runType: 'script' | 'flow' | 'hubscript',
loadedSchema: LoadedRunnableSchema,
defaultUserInput: boolean,
rawApps: boolean
): {
runnable: Runnable
fields: Record<string, StaticAppInput>
} {
return {
runnable: {
type: 'path',
path,
runType,
schema: loadedSchema.schema,
name: defaultIfEmptyString(loadedSchema.summary, path)
},
fields: schemaToInputsSpec(loadedSchema.schema, defaultUserInput || rawApps)
}
}

View File

@@ -0,0 +1,45 @@
import { describe, expect, it } from 'vitest'
import { genWmillTs, type Runnable } from './utils'
const flowSchema = {
$schema: 'https://json-schema.org/draft/2020-12/schema',
type: 'object',
required: ['string_input'],
properties: {
string_input: {
type: 'string',
default: ''
},
count: {
type: 'integer'
}
}
} as const
describe('genWmillTs', () => {
it('generates the correct flow args type for path runnables', () => {
const runnables: Record<string, Runnable> = {
myflow: {
type: 'path',
runType: 'flow',
path: 'u/dev/my_flow',
name: 'My flow',
schema: flowSchema,
fields: {
count: {
type: 'static',
value: 1,
fieldType: 'number'
}
}
}
}
const dts = genWmillTs(runnables)
expect(dts).toContain(
'myflow: (args: { string_input: string }) => Promise<any>;'
)
})
})

View File

@@ -108,7 +108,7 @@ function hiddenRunnableToTsType(runnable: Runnable) {
}
} else if (isRunnableByPath(runnable)) {
if (runnable?.schema) {
return schemaToTsType(removeStaticFields(runnable.schema, runnable?.fields ?? {}))
return schemaToTsType(removeStaticFields(runnable.schema as Schema, runnable?.fields ?? {}))
} else {
return '{}'
}