| layout | default |
|---|---|
| title | Chapter 7: Troubleshooting, Safety, and Cost Controls |
| nav_order | 7 |
| parent | Refly Tutorial |
Welcome to Chapter 7: Troubleshooting, Safety, and Cost Controls. In this part of Refly Tutorial: Build Deterministic Agent Skills and Ship Them Across APIs and Claude Code, you will build an intuitive mental model first, then move into concrete implementation details and practical production tradeoffs.
This chapter provides pragmatic recovery and guardrail practices for production usage.
- triage common failure modes across API, webhook, and runtime
- enforce safe key handling and permission boundaries
- reduce wasted runs through validation-first execution
- keep costs and failure blast radius under control
| Symptom | Likely Cause | First Fix |
|---|---|---|
| unauthorized API calls | invalid or missing API key | rotate/reconfigure auth header |
| webhook not triggering | webhook disabled or invalid URL | re-enable webhook and verify endpoint |
| run fails mid-execution | invalid variables or dependent service issues | validate input schema and service health |
| high token/runtime cost | oversized workflow scope | split into smaller composable skills |
- keep API keys out of logs and committed files
- test changes in constrained environments before broad rollout
- prefer deterministic, validated workflows over opaque one-shot prompts
- retain run history and telemetry for postmortem analysis
You now have a practical troubleshooting and safety playbook for Refly operations.
Next: Chapter 8: Contribution Workflow and Governance
The getDefaultEndpoint function in packages/cli/tsup.config.ts handles a key part of this chapter's functionality:
// Determine the default API endpoint based on build environment
function getDefaultEndpoint(): string {
if (customEndpoint) return customEndpoint;
return ENV_CONFIG[buildEnv]?.apiEndpoint ?? ENV_CONFIG.production.apiEndpoint;
}
// Determine the default Web URL based on build environment
function getDefaultWebUrl(): string {
if (customWebUrl) return customWebUrl;
if (customEndpoint) return customEndpoint; // Assume same domain if only endpoint specified
return ENV_CONFIG[buildEnv]?.webUrl ?? ENV_CONFIG.production.webUrl;
}
// Determine the npm tag based on build environment
function getNpmTag(): string {
return ENV_CONFIG[buildEnv]?.npmTag ?? 'latest';
}
const defaultEndpoint = getDefaultEndpoint();
const defaultWebUrl = getDefaultWebUrl();
const npmTag = getNpmTag();
console.log(`[tsup] Building CLI for environment: ${buildEnv}`);
console.log(`[tsup] CLI version: ${cliVersion}`);
console.log(`[tsup] NPM tag: ${npmTag}`);
console.log(`[tsup] Default API endpoint: ${defaultEndpoint}`);
console.log(`[tsup] Default Web URL: ${defaultWebUrl}`);
export default defineConfig({
entry: {
'bin/refly': 'src/bin/refly.ts',This function is important because it defines how Refly Tutorial: Build Deterministic Agent Skills and Ship Them Across APIs and Claude Code implements the patterns covered in this chapter.
The getDefaultWebUrl function in packages/cli/tsup.config.ts handles a key part of this chapter's functionality:
// Determine the default Web URL based on build environment
function getDefaultWebUrl(): string {
if (customWebUrl) return customWebUrl;
if (customEndpoint) return customEndpoint; // Assume same domain if only endpoint specified
return ENV_CONFIG[buildEnv]?.webUrl ?? ENV_CONFIG.production.webUrl;
}
// Determine the npm tag based on build environment
function getNpmTag(): string {
return ENV_CONFIG[buildEnv]?.npmTag ?? 'latest';
}
const defaultEndpoint = getDefaultEndpoint();
const defaultWebUrl = getDefaultWebUrl();
const npmTag = getNpmTag();
console.log(`[tsup] Building CLI for environment: ${buildEnv}`);
console.log(`[tsup] CLI version: ${cliVersion}`);
console.log(`[tsup] NPM tag: ${npmTag}`);
console.log(`[tsup] Default API endpoint: ${defaultEndpoint}`);
console.log(`[tsup] Default Web URL: ${defaultWebUrl}`);
export default defineConfig({
entry: {
'bin/refly': 'src/bin/refly.ts',
index: 'src/index.ts',
},
format: ['cjs'],
target: 'node18',
clean: true,
dts: true,This function is important because it defines how Refly Tutorial: Build Deterministic Agent Skills and Ship Them Across APIs and Claude Code implements the patterns covered in this chapter.
flowchart TD
A[getDefaultEndpoint]
B[getDefaultWebUrl]
A --> B