{#if scriptPath}
(historyBrowserDrawerOpen = false)}>
{/if}
{#if pick_existing == 'hub'}
{:else}
{/if}
{#if codeObj}
{:else}
{/if}
{
if (!editor) return
if (lang == 'deno') {
editor.insertAtCursor(`Deno.env.get('${name}')`)
} else if (lang === 'bun') {
editor.insertAtCursor(`Bun.env["${name}"]`)
} else if (lang == 'python3') {
if (!editor.getCode().includes('import os')) {
editor.insertAtBeginning('import os\n')
}
editor.insertAtCursor(`os.environ.get("${name}")`)
} else if (lang == 'go') {
if (!editor.getCode().includes('"os"')) {
editor.insertAtLine('import "os"\n', 2)
}
editor.insertAtCursor(`os.Getenv("${name}")`)
} else if (lang == 'bash') {
editor.insertAtCursor(`$${name}`)
}
sendUserToast(`${name} inserted at cursor`)
}}
tooltip="Contextual Variables are variables whose values are contextual to the Script
execution. They are are automatically set by Windmill."
documentationLink="https://www.windmill.dev/docs/core_concepts/variables_and_secrets#contextual-variables"
itemName="Contextual Variable"
extraField="name"
loadItems={loadContextualVariables}
/>
{
if (!editor) return
if (lang == 'deno') {
if (!editor.getCode().includes('import * as wmill from')) {
editor.insertAtBeginning(`import * as wmill from "npm:windmill-client@1"\n`)
}
editor.insertAtCursor(`(await wmill.getVariable('${path}'))`)
} else if (lang === 'bun') {
const code = editor.getCode()
if (!code.includes(`import * as wmill from`)) {
editor.insertAtBeginning(`import * as wmill from "windmill-client"\n`)
}
editor.insertAtCursor(`(await wmill.getVariable('${path}'))`)
} else if (lang == 'python3') {
if (!editor.getCode().includes('import wmill')) {
editor.insertAtBeginning('import wmill\n')
}
editor.insertAtCursor(`wmill.get_variable("${path}")`)
} else if (lang == 'go') {
if (!editor.getCode().includes('wmill "github.com/windmill-labs/windmill-go-client"')) {
editor.insertAtLine('import wmill "github.com/windmill-labs/windmill-go-client"\n\n', 3)
}
editor.insertAtCursor(`v, _ := wmill.GetVariable("${path}")`)
} else if (lang == 'bash') {
editor.insertAtCursor(`curl -s -H "Authorization: Bearer $WM_TOKEN" \\
"$BASE_INTERNAL_URL/api/w/$WM_WORKSPACE/variables/get_value/${path}" | jq -r .`)
}
sendUserToast(`${name} inserted at cursor`)
}}
tooltip="Variables are dynamic values that have a key associated to them and can be retrieved during the execution of a Script or Flow."
documentationLink="https://www.windmill.dev/docs/core_concepts/variables_and_secrets"
itemName="Variable"
extraField="path"
loadItems={loadVariables}
buttons={{ 'Edit/View': (x) => variableEditor.editVariable(x) }}
>
{
if (!editor) return
if (lang == 'deno') {
if (!editor.getCode().includes('import * as wmill from')) {
editor.insertAtBeginning(`import * as wmill from "npm:windmill-client@1"\n`)
}
editor.insertAtCursor(`(await wmill.getResource('${path}'))`)
} else if (lang === 'bun') {
const code = editor.getCode()
if (!code.includes(`import * as wmill from`)) {
editor.insertAtBeginning(`import * as wmill from "windmill-client"\n`)
}
editor.insertAtCursor(`(await wmill.getResource('${path}'))`)
} else if (lang == 'python3') {
if (!editor.getCode().includes('import wmill')) {
editor.insertAtBeginning('import wmill\n')
}
editor.insertAtCursor(`wmill.get_resource("${path}")`)
} else if (lang == 'go') {
if (!editor.getCode().includes('wmill "github.com/windmill-labs/windmill-go-client"')) {
editor.insertAtLine('import wmill "github.com/windmill-labs/windmill-go-client"\n\n', 3)
}
editor.insertAtCursor(`r, _ := wmill.GetResource("${path}")`)
} else if (lang == 'bash') {
editor.insertAtCursor(`curl -s -H "Authorization: Bearer $WM_TOKEN" \\
"$BASE_INTERNAL_URL/api/w/$WM_WORKSPACE/resources/get_value_interpolated/${path}" | jq`)
}
sendUserToast(`${path} inserted at cursor`)
}}
tooltip="Resources represent connections to third party systems. Resources are a good way to define a connection to a frequently used third party system such as a database."
documentationLink="https://www.windmill.dev/docs/core_concepts/resources_and_types"
itemName="Resource"
buttons={{ 'Edit/View': (x) => resourceEditor.initEdit(x) }}
extraField="description"
extraField2="resource_type"
loadItems={async () =>
await ResourceService.listResource({ workspace: $workspaceStore ?? 'NO_W' })}
>
{#if showResourceTypePicker}
{
if (!editor) return
const resourceType = await ResourceService.getResourceType({
workspace: $workspaceStore ?? 'NO_W',
path: name
})
if (lang == 'python3') {
const pySchema = pythonCompile(resourceType.schema)
editor.insertAtCursor(`class ${name}(TypedDict):\n${pySchema}\n`)
const code = editor.getCode()
if (!code.includes('from typing import TypedDict')) {
editor.insertAtBeginning('from typing import TypedDict\n')
}
} else {
const tsSchema = compile(resourceType.schema)
editor.insertAtCursor(`type ${toCamel(capitalize(name))} = ${tsSchema}\n`)
}
sendUserToast(`${name} inserted at cursor`)
}}
tooltip="Resources Types are the schemas associated with a Resource. They define the structure of the data that is returned from a Resource."
documentationLink="https://www.windmill.dev/docs/core_concepts/resources_and_types"
itemName="Resource Type"
extraField="name"
loadItems={async () =>
await ResourceService.listResourceType({ workspace: $workspaceStore ?? 'NO_W' })}
/>
{/if}