Files
windmill/frontend/src/lib/common.ts
T
hugocasaandClaude Opus 5 c297ed0052 feat: managed memory with an inherited or custom memory id per step (#11118)
* feat: split ai agent memory into agent policy, run memory id and step history

* fix: scope string memory ids to workspace and flow, keep nested tool history inputs

* chore: update sqlx cache for the flow context query

* docs: describe memory id scoping as collision-free rather than isolated

* chore: regenerate openflow json after merging main

* fix: offer no memory id for legacy manual memory, document linked history inputs

* fix: seed provided messages from legacy manual memory and hide its note once set

* fix: bypass memory when a provided messages expression evaluates to null

* fix: require a user message when provided messages are empty

* chore: keep the empty messages comment within the line width

* docs: name the history inputs wherever linked steps list their flow-local inputs

* docs: keep the memory storage path on one line

* feat: managed memory with an inherited or custom memory id per step

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

* fix: list a custom memory id in the test run form and name where an inherited one comes from

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

* fix: keep memory id out of the add-field menu and drop the memory id telemetry

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

* fix: keep legacy auto memory without an id working after an untouched redeploy

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

* fix: rename step messages to previous_messages and address review

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

* style: rewrap comments and docs lines lengthened by the previous_messages rename

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

* refactor: read agent memory as either a legacy shape or the current one

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

* fix: name the memory setting in ignored-input notes and keep conversions honest

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

* fix: keep a legacy memory count unset on open and read a cleared count as off

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* fix: address review on cleared test history and zero-count memory

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* fix: drop flow-local keys from a linked agent resource before interpolating it

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* fix: keep a linked resource's own inputs as fallbacks and note ignored history on image runs

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* fix: restore the linked agent draft tests and log ignored history on every image run

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* fix: resolve the one-of variant from the value when the selected one leaves the list

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* fix: treat zero-count managed memory as off when enabling chat mode and shorten comments

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* fix: stop requiring user_message in the openflow agent contract when previous messages are the prompt

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-17 11:55:43 +02:00

191 lines
4.7 KiB
TypeScript

import type { Script, ScriptLang } from './gen'
export type OwnerKind = 'group' | 'user' | 'folder'
export type ActionKind = 'Create' | 'Update' | 'Delete' | 'Execute'
export type SupportedLanguage = Script['language']
export interface PropertyDisplayInfo {
property: SchemaProperty
name: string
isRequired: boolean
path: string[]
index: number
propertiesNumber: number
}
export type EnumType = string[] | { value: string; label: string }[] | undefined
export interface SchemaProperty {
type: string | undefined
description?: string
pattern?: string
default?: any
enum?: EnumType
/** Display names by stored value, for an enum's options or a one-of's variants. */
enumLabels?: Record<string, string>
contentEncoding?: 'base64' | 'binary'
format?: string
items?: {
type?: 'string' | 'number' | 'bytes' | 'object' | 'resource'
contentEncoding?: 'base64'
enum?: string[]
resourceType?: string
properties?: { [name: string]: SchemaProperty }
required?: string[]
}
min?: number
max?: number
/** Height a string field's text area opens at, in rows. */
minRows?: number
currency?: string
currencyLocale?: string
multiselect?: boolean
customErrorMessage?: string
properties?: { [name: string]: SchemaProperty }
required?: string[]
showExpr?: string
hideWhenChatEnabled?: boolean
/** Why the oneOf variant is chat mode's to pick. Set = selector disabled, reason shown. */
lockOneOfWhenChatEnabled?: string
password?: boolean
order?: string[]
nullable?: boolean
dateFormat?: string
title?: string
placeholder?: string
oneOf?: SchemaProperty[]
originalType?: string
disabled?: boolean
'x-no-s3-storage-workspace-warning'?: string
'x-auto-generate'?: boolean
}
export interface ModalSchemaProperty {
selectedType?: string
description: string
name: string
required: boolean
min?: number
max?: number
currency?: string
currencyLocale?: string
multiselect?: boolean
format?: string
pattern?: string
enum_?: EnumType
default?: any
items?: { type?: 'string' | 'number'; enum?: string[] }
contentEncoding?: 'base64' | 'binary'
schema?: Schema
customErrorMessage?: string
showExpr?: string
password?: boolean
nullable?: boolean
dateFormat?: string
title?: string
placeholder?: string
oneOf?: SchemaProperty[]
}
export function modalToSchema(schema: ModalSchemaProperty): SchemaProperty {
return {
type: schema.selectedType,
description: schema.description,
pattern: schema.pattern,
default: schema.default,
enum: schema.enum_,
items: schema.items,
contentEncoding: schema.contentEncoding,
format: schema.format,
customErrorMessage: schema.customErrorMessage,
properties: schema.schema?.properties,
required: schema.schema?.required,
min: schema.min,
max: schema.max,
currency: schema.currency,
currencyLocale: schema.currencyLocale,
multiselect: schema.multiselect,
showExpr: schema.showExpr,
password: schema.password,
nullable: schema.nullable,
dateFormat: schema.dateFormat,
title: schema.title,
placeholder: schema.placeholder,
oneOf: schema.oneOf
}
}
export type Schema = {
$schema: string | undefined
type: string
'x-windmill-dyn-select-code'?: string
'x-windmill-dyn-select-lang'?: ScriptLang
properties: { [name: string]: SchemaProperty }
order?: string[]
required: string[]
}
export function mergeSchema(
schema: Schema | Record<string, any>,
enum_payload: Record<string, any> = {}
) {
if (!schema.properties || !enum_payload) {
return schema
}
let new_schema: Schema = JSON.parse(JSON.stringify(schema))
for (let [key, value] of Object.entries(new_schema.properties ?? {})) {
if (enum_payload[key]) {
value.enum = enum_payload[key]
value['disableCreate'] = true
}
}
return new_schema
}
export type Meta = { ownerKind: OwnerKind; owner: string; name: string }
type Enumerate<N extends number, Acc extends number[] = []> = Acc['length'] extends N
? Acc[number]
: Enumerate<N, [...Acc, Acc['length']]>
/** An inclusive range of integer numbers */
export type IntRange<F extends number, T extends number> =
| F
| Exclude<Enumerate<T>, Enumerate<F>>
| T
export function pathToMeta(path: string, hideUser: boolean): Meta {
const splitted = path.split('/')
let ownerKind: OwnerKind
if (splitted[0] == 'g') {
ownerKind = 'group'
} else if (splitted[0] == 'f') {
ownerKind = 'folder'
} else if (splitted[0] == 'u') {
ownerKind = 'user'
} else {
console.error('Not recognized owner:' + splitted[0])
return {
ownerKind: hideUser ? 'folder' : 'user',
owner: '',
name: ''
}
}
return {
ownerKind,
owner: splitted[1],
name: splitted.slice(2).join('/')
}
}
export function prettyLanguage(lang: string) {
switch (lang) {
case 'nativets':
return 'Native TypeScript'
default:
return lang.charAt(0).toUpperCase() + lang.slice(1)
}
}