Skip to content

The micro-VM for AI agents — light enough to embed on your laptop, elastic enough to power an agentic cloud.

1.7 KB
Raw Blame
/** The App handoff prompt with its organization API URL and project selection. */
import { existsSync, readFileSync } from 'node:fs'
import { dirname, join } from 'node:path'
import type { Config } from './config'

type PromptContext = { config: Pick<Config, 'promptTemplatePath' | 'agentMdPath' | 'managementUrl'> }

const FALLBACK_TEMPLATE = `Read the Applet agent guide at {{AGENT_URL}} before building and deploying this app on BoxLite.

export BOXLITE_API_URL={{API_URL}}
App: {{APP}}
Environment: {{ENV}}

Use the BoxLite CLI. If needed, ask the user to sign in with an account that has Apps permissions using boxlite auth login --url {{SERVER_URL}}. To sign in with an organization key, use boxlite auth login --url {{SERVER_URL}} --method api-key and enter the key at the prompt.
In the project directory, run boxlite app init --app {{APP}} --env {{ENV}} with the organization API URL above.

What I want: {{REQUEST}}
`

function promptTemplate(ctx: PromptContext): string {
  const path = ctx.config.promptTemplatePath ?? join(dirname(ctx.config.agentMdPath), 'prompt-template.md')
  return existsSync(path) ? readFileSync(path, 'utf8') : FALLBACK_TEMPLATE
}

export function handoffPrompt(ctx: PromptContext, app: string, env = 'main'): string {
  return (
    promptTemplate(ctx)
      .replaceAll('{{API_URL}}', ctx.config.managementUrl)
      .replaceAll('{{SERVER_URL}}', new URL('..', ctx.config.managementUrl).href.replace(/\/$/, ''))
      .replaceAll('{{AGENT_URL}}', 'https://boxlite.ai/agent.applet.md')
      .replaceAll('{{APP}}', app)
      .replaceAll('{{ENV}}', env)
      .replace(/^.*\{\{REQUEST\}\}.*$/m, 'What I want: (tell your agent here)')
      .trimEnd() + '\n'
  )
}