Secrets Management
Loopstack provides built-in tools for requesting and retrieving secrets (API keys, tokens, etc.) from users at runtime.
Overview
Secrets are requested from the user via RequestSecretsTool and stored securely. They can later be retrieved with GetSecretKeysTool to verify availability.
Available Tools
| Tool | Source | Description |
|---|---|---|
RequestSecretsTool | @loopstack/core | Request secrets from the user via a UI prompt |
GetSecretKeysTool | @loopstack/core | List stored secret keys and their availability |
SecretRequestDocument | @loopstack/core | Document displaying the secret input form |
Example Workflow
import { BaseWorkflow, Final, Initial, InjectTool, ToolResult, Transition, Workflow } from '@loopstack/common';
import { GetSecretKeysTool, MarkdownDocument, RequestSecretsTool, SecretRequestDocument } from '@loopstack/core';
@Workflow({ uiConfig: __dirname + '/secrets-example.ui.yaml' })
export class SecretsExampleWorkflow extends BaseWorkflow {
@InjectTool() private requestSecrets: RequestSecretsTool;
@InjectTool() private getSecretKeys: GetSecretKeysTool;
secretKeys?: Array<{ key: string; hasValue: boolean }>;
@Initial({ to: 'requesting_secrets' })
async requestSecretsFromUser() {
// Request specific secrets from the user
await this.requestSecrets.call({
variables: [{ key: 'EXAMPLE_API_KEY' }, { key: 'EXAMPLE_SECRET' }],
});
// Display the secret request form
await this.repository.save(SecretRequestDocument, {
variables: [{ key: 'EXAMPLE_API_KEY' }, { key: 'EXAMPLE_SECRET' }],
});
}
@Transition({ from: 'requesting_secrets', to: 'verifying', wait: true })
async secretsSubmitted() {
// Verify which secrets are now available
const result: ToolResult<Array<{ key: string; hasValue: boolean }>> = await this.getSecretKeys.call({});
this.secretKeys = result.data;
}
@Final({ from: 'verifying' })
async showResult() {
await this.repository.save(MarkdownDocument, {
markdown: this.render(__dirname + '/templates/secretsVerified.md', {
secretKeys: this.secretKeys,
}),
});
}
}How It Works
- Request —
RequestSecretsTooltells the framework which secrets are needed - Display —
SecretRequestDocumentshows a secure input form in the UI - Wait — The workflow pauses (
wait: true) until the user submits the secrets - Verify —
GetSecretKeysToolchecks which secrets are now stored - Use — Secrets are available as environment variables in subsequent tool calls
Template Example
# Secrets Verification
{{#each secretKeys}}
- **{{this.key}}**: {{#if this.hasValue}}Stored{{else}}Missing{{/if}}
{{/each}}Registry References
- secrets-example-workflow — Request secrets from user, verify storage, and display results with both direct workflow and agent-based approaches
Last updated on