Skip to content

fix: require model discovery before AI SDK usage#17

Open
tonychang04 wants to merge 1 commit intomainfrom
fix/ai-model-discovery
Open

fix: require model discovery before AI SDK usage#17
tonychang04 wants to merge 1 commit intomainfrom
fix/ai-model-discovery

Conversation

@tonychang04
Copy link
Copy Markdown
Contributor

@tonychang04 tonychang04 commented Mar 30, 2026

Summary

  • AI skills were defaulting to hardcoded model IDs (e.g., claude-3.5-haiku) instead of querying which models are actually configured for the project
  • Updated sdk-integration.md to replace all hardcoded model IDs with MODEL_ID placeholders and add a "Discover Available Models First" section with CLI (npx @insforge/cli metadata --json) and raw SQL (ai.configs table) approaches
  • Updated backend-configuration.md to document the ai.configs table schema and prioritize CLI/SQL discovery over the HTTP endpoint

Test plan

  • Verify AI skill no longer causes agents to default to haiku
  • Confirm npx @insforge/cli metadata --json returns AI configurations
  • Confirm npx @insforge/cli db query "SELECT model_id FROM ai.configs WHERE is_active = true" works

🤖 Generated with Claude Code

Note

Require model discovery before AI SDK usage in documentation

  • Updates backend-configuration.md to center on discovering configured AI models via CLI (npx @insforge/cli metadata --json) or direct SQL against ai.configs, replacing the previous focus on admin HTTP endpoints.
  • Updates sdk-integration.md to add a 'Discover Available Models First' section and replace all hardcoded model ID strings in examples with dynamic MODEL_ID values sourced from metadata or ai.configs queries.
  • Both documents now recommend verifying is_active, input_modality, and output_modality fields from ai.configs before making SDK calls.

Macroscope summarized 4cbd844.

Summary by CodeRabbit

  • Documentation
    • Updated AI configuration documentation with new model discovery workflows.
    • Introduced recommended practices for discovering and configuring available AI models in projects.
    • Enhanced SDK integration guidance with updated code examples and best-practice recommendations.
    • Added recommendations for properly managing model identifiers in applications.

… defaults

AI skills were defaulting to hardcoded model IDs (e.g., claude-3.5-haiku) instead
of querying which models are actually configured. Now skills instruct agents to
run `npx @insforge/cli metadata --json` or query `ai.configs` table first.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 30, 2026

Walkthrough

The pull request updates documentation for AI model discovery, shifting from HTTP endpoint-based configuration to CLI-driven metadata queries and direct database table access. It removes hardcoded model IDs from SDK examples, replaces them with variables, and introduces explicit guidance on the ai.configs table schema and modality-specific configuration requirements.

Changes

Cohort / File(s) Summary
AI Configuration & SDK Documentation
skills/insforge/ai/backend-configuration.md, skills/insforge/ai/sdk-integration.md
Removed HTTP admin-authenticated endpoint emphasis; added CLI (npx @insforge/cli metadata --json) and database query alternatives for model discovery. Updated all SDK examples to use variable references instead of hardcoded model IDs. Added ai.configs table schema documentation (model_id, provider, is_active, input_modality, output_modality, system_prompt) and modality-specific guidance. Revised best practices and workflow sections to reflect new discovery approach.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • Refactor: integrating cli #6 — Shares the same strategic shift from admin HTTP backend-configuration workflows to CLI-driven model discovery and database queries for AI configuration management.

Suggested reviewers

  • Fermionic-Lyu

Poem

🐰 With whiskers twitching, I hop with glee,
CLI commands flowing wild and free,
No hardcoded paths in sight today,
Configs dance in a dynamic way! ✨
Your models now discover their own way! 🌟

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: require model discovery before AI SDK usage' directly and clearly summarizes the main change: making model discovery mandatory before using the AI SDK, replacing hardcoded model IDs with dynamic discovery.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ai-model-discovery

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
skills/insforge/ai/sdk-integration.md (1)

32-131: ⚠️ Potential issue | 🟠 Major

Introduce an explicit Usage Examples section header.

Examples are present, but the required Usage Examples section heading is missing. Please wrap sections like “Chat Completions”, “Embeddings”, and “Image Generation” under ## Usage Examples to satisfy the documentation format contract.

As per coding guidelines: "Documentation files must maintain consistent format: Setup, Usage Examples, Best Practices, Common Mistakes sections".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@skills/insforge/ai/sdk-integration.md` around lines 32 - 131, Add a top-level
"## Usage Examples" header and move the existing "Chat Completions",
"Embeddings", and "Image Generation" sections so they are subsections under that
header (e.g., "## Usage Examples" followed by "### Chat Completions", "###
Embeddings", "### Image Generation"); ensure the document follows the required
section order (Setup, Usage Examples, Best Practices, Common Mistakes) and that
the headings in the diff (Chat Completions, Embeddings, Image Generation) are
converted to subordinate headings under the new Usage Examples section.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@skills/insforge/ai/backend-configuration.md`:
- Around line 1-62: The AI Backend Configuration document is missing the
required headings; add concise "Setup", "Usage Examples", and "Common Mistakes"
sections to the existing content so it follows the repo's enforced documentation
structure: create a Setup section explaining prerequisites and how to run the
example commands (e.g., npx `@insforge/cli` metadata --json and the SQL/HTTP
options), a Usage Examples section showing minimal examples of using a returned
model_id in SDK/CLI/HTTP calls, and a Common Mistakes section listing typical
pitfalls (e.g., using shortened model_id, attempting AI calls when no models are
active). Ensure the new headings appear alongside the existing "Discovering
Available Models", "Best Practices", and "When No Models Are Configured"
sections.

---

Outside diff comments:
In `@skills/insforge/ai/sdk-integration.md`:
- Around line 32-131: Add a top-level "## Usage Examples" header and move the
existing "Chat Completions", "Embeddings", and "Image Generation" sections so
they are subsections under that header (e.g., "## Usage Examples" followed by
"### Chat Completions", "### Embeddings", "### Image Generation"); ensure the
document follows the required section order (Setup, Usage Examples, Best
Practices, Common Mistakes) and that the headings in the diff (Chat Completions,
Embeddings, Image Generation) are converted to subordinate headings under the
new Usage Examples section.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7978184f-303b-41e8-bc3e-670337b681e4

📥 Commits

Reviewing files that changed from the base of the PR and between 0a3f087 and 4cbd844.

📒 Files selected for processing (2)
  • skills/insforge/ai/backend-configuration.md
  • skills/insforge/ai/sdk-integration.md

Comment on lines 1 to 62
# AI Backend Configuration

HTTP endpoints to check AI configurations. Requires admin authentication.
Check which AI models are configured for a project.

## Authentication
## Discovering Available Models

All admin endpoints require:
```
Authorization: Bearer {admin-token-or-api-key}
### Option 1 — CLI (recommended)

```bash
npx @insforge/cli metadata --json
```

## List AI Configurations
The `ai.configurations` section lists all models with `modelId` and `enabled` status.

Check which AI models are available for this project.
### Option 2 — Raw SQL

```
GET /api/ai/configurations
Authorization: Bearer {admin-token}
```
Query the `ai.configs` table directly:

Response example:
```json
{
"configurations": [
{
"id": "config-uuid",
"name": "Claude Haiku",
"modelId": "anthropic/claude-3.5-haiku",
"enabled": true
},
{
"id": "config-uuid-2",
"name": "GPT-4",
"modelId": "openai/gpt-4",
"enabled": true
}
]
}
```bash
npx @insforge/cli db query "SELECT model_id, provider, is_active, input_modality, output_modality FROM ai.configs WHERE is_active = true"
```

## Quick Reference

| Task | Endpoint |
|------|----------|
| List AI configs | `GET /api/ai/configurations` |
**Table: `ai.configs`**

---
| Column | Type | Description |
|--------|------|-------------|
| `model_id` | VARCHAR(255) | Unique model identifier (use this in SDK calls) |
| `provider` | VARCHAR(255) | AI provider (e.g., `openai`, `anthropic`, `google`) |
| `is_active` | BOOLEAN | Whether the model is enabled |
| `input_modality` | TEXT[] | Supported input types: `text`, `image`, `audio`, `video`, `file` |
| `output_modality` | TEXT[] | Supported output types: `text`, `image`, `audio`, `video`, `file` |
| `system_prompt` | TEXT | Optional default system prompt |

## Best Practices

1. **Always check available configurations first** before implementing AI features
- Call `GET /api/ai/configurations` to see which models are enabled
- Only use model IDs that appear in the configurations list
### Option 3 — HTTP endpoint (requires admin auth)

2. **Verify the exact model ID** from the configurations response
- Model IDs must match exactly (e.g., `anthropic/claude-3.5-haiku`, not `claude-haiku`)
```
GET /api/ai/configurations
Authorization: Bearer {admin-token}
```

## Common Mistakes
## Best Practices

| Mistake | Solution |
|---------|----------|
| Using a model ID that isn't configured | Check configurations first, use only enabled models |
| Guessing model IDs | Always verify against `GET /api/ai/configurations` |
| Assuming all models are available | Each project has its own configured models |
1. **Always check available models first** before implementing AI features
2. **Use exact `model_id`** from the query response — do not shorten or guess
3. Each project has its own configured models — do not assume availability

## When No Configurations Exist
## When No Models Are Configured

If `GET /api/ai/configurations` returns an empty list or the requested model is not configured:
If the query returns no results:

1. **Do not attempt to use AI features** - they will fail
2. **Instruct the user** to configure AI models on the InsForge Dashboard:
- Go to the InsForge Dashboard → AI Settings
- Add and enable the desired AI model configurations
- Save changes
3. **After configuration**, verify by calling `GET /api/ai/configurations` again
1. **Do not attempt to use AI features** — they will fail
2. **Instruct the user** to configure AI models on the InsForge Dashboard → AI Settings
3. **After configuration**, verify by querying again

## Recommended Workflow

```
1. Check configurations → GET /api/ai/configurations
1. Check available models → npx @insforge/cli metadata --json
OR query ai.configs table
2. If empty or missing model → Instruct user to configure on Dashboard
3. If model exists → Proceed with SDK integration
3. If model exists → Use exact model_id in SDK calls
```
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Add required documentation sections to match repo format.

This file currently omits the required Setup, Usage Examples, and Common Mistakes sections. Please add those headings (even if brief) so the module follows the enforced documentation structure.

As per coding guidelines: "Documentation files must maintain consistent format: Setup, Usage Examples, Best Practices, Common Mistakes sections".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@skills/insforge/ai/backend-configuration.md` around lines 1 - 62, The AI
Backend Configuration document is missing the required headings; add concise
"Setup", "Usage Examples", and "Common Mistakes" sections to the existing
content so it follows the repo's enforced documentation structure: create a
Setup section explaining prerequisites and how to run the example commands
(e.g., npx `@insforge/cli` metadata --json and the SQL/HTTP options), a Usage
Examples section showing minimal examples of using a returned model_id in
SDK/CLI/HTTP calls, and a Common Mistakes section listing typical pitfalls
(e.g., using shortened model_id, attempting AI calls when no models are active).
Ensure the new headings appear alongside the existing "Discovering Available
Models", "Best Practices", and "When No Models Are Configured" sections.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant