Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
76443e6
chore: add provider hash manifest for 1.4.2-alpha (#410)
github-actions[bot] Mar 14, 2026
8fb87d3
docs(ci): add comprehensive milestone management system with automate…
marc-romu Mar 24, 2026
f548443
Potential fix for code scanning alert no. 20: Code injection
marc-romu Mar 24, 2026
69fff92
docs(ci): add comprehensive versioning action documentation and stand…
marc-romu Mar 24, 2026
b9ba58e
Update .github/actions/versioning/move-milestone-items/action.yml
marc-romu Mar 24, 2026
21bec53
fix(ci): correct step references and improve milestone pagination in …
marc-romu Mar 24, 2026
4f945b0
ci: enhance milestone management and release automation workflows (#411)
marc-romu Mar 24, 2026
0ad00fb
docs: add milestone management guide and update release workflow docu…
marc-romu Mar 24, 2026
0d62507
Merge branch 'dev' of https://github.com/architects-toolkit/SmartHopp…
marc-romu Mar 24, 2026
2d4ed7f
ci: new automatic milestone management, automatic update to yak, and …
marc-romu Mar 24, 2026
f263f72
ci: enhance promotion eligibility checks with comprehensive validatio…
marc-romu Mar 24, 2026
b398f3e
ci: remove milestone check from promotion eligibility to allow promot…
marc-romu Mar 24, 2026
b6838c8
ci: fix version grouping to use minor version and standardize PowerSh…
marc-romu Mar 24, 2026
ae28638
ci: skip promotion for versions with closed target milestones and fix…
marc-romu Mar 24, 2026
eb59bb5
ci: standardize PowerShell output commands and improve PR URL parsing…
marc-romu Mar 24, 2026
98fda0e
ci: prevent older versions from being promoted when target milestone …
marc-romu Mar 24, 2026
9550ead
ci: new stabilization-aware milestone workflow
marc-romu Mar 25, 2026
4c61ce1
ci: add workflows write permission to stabilization init workflow
marc-romu Mar 25, 2026
f37899d
ci: remove unnecessary workflows write permission from stabilization …
marc-romu Mar 25, 2026
75e4a6d
ci: replace git commands with GitHub API calls for branch creation in…
marc-romu Mar 25, 2026
d93232d
ci: use PAT_TOKEN for branch creation in stabilization init workflow …
marc-romu Mar 25, 2026
84e2c20
chore: prepare release 1.4.2-beta with version update and code style …
github-actions[bot] Apr 15, 2026
4bad881
chore: add provider hash manifest for version 1.4.2-beta (dual platform)
github-actions[bot] Apr 15, 2026
b02687f
ci: remove automatic branch deletion from hash manifest PR merge in r…
marc-romu Apr 15, 2026
f7cc8da
ci: simplify GitHub Pages deployment trigger to run on all main branc…
marc-romu Apr 15, 2026
fb76c62
ci: add validation to prevent editing stable releases in release work…
marc-romu Apr 15, 2026
faca31d
ci: checkout specific version tag in build jobs for release workflow
marc-romu Apr 15, 2026
95b0e45
chore: add provider hash manifest for version 1.4.2-beta (dual platform)
github-actions[bot] Apr 15, 2026
71fd802
ci: add optional version input parameter to milestone assignment action
marc-romu Apr 15, 2026
d1e38e5
Merge branch 'main' of https://github.com/architects-toolkit/SmartHopper
marc-romu Apr 15, 2026
306289b
ci: extract manifest text update logic into reusable action and integ…
marc-romu Apr 15, 2026
4fda03e
ci: add reusable cherry-pick action and patch propagation workflow fo…
marc-romu Apr 25, 2026
061a4f7
ci: apply PR labels best-effort after creation to prevent unknown lab…
marc-romu Apr 25, 2026
201f4b0
ci: apply PR labels best-effort after creation to prevent unknown lab…
marc-romu Apr 25, 2026
83c39a5
Merge branch 'main' of https://github.com/architects-toolkit/SmartHopper
marc-romu Apr 25, 2026
bd7e3c8
build: replace GhJSON project references with NuGet package references
marc-romu Apr 25, 2026
e93fcd7
[patch] ci: add reusable cherry-pick action and patch propagation wor…
github-actions[bot] Apr 25, 2026
77b6a5e
ci: add patch/ prefix to auto-delete branch patterns in PR cleanup wo…
marc-romu Apr 25, 2026
7513d2c
[patch] ci: add patch/ prefix to auto-delete branch patterns in PR cl…
github-actions[bot] Apr 25, 2026
e0944c4
[patch] feat(model-registry): refresh AI model catalog across all pro…
github-actions[bot] Apr 25, 2026
d5b674f
docs(changelog): correct OpenAI gpt-5.5 rank and Anthropic claude-opu…
marc-romu Apr 25, 2026
5243dbb
refactor(ai-settings): add System.Threading.Tasks using directive
marc-romu Apr 25, 2026
f732c18
Update CHANGELOG.md
marc-romu Apr 25, 2026
a472b08
Delete src/SmartHopper.Components/AI/AISettingsComponent.cs
marc-romu Apr 25, 2026
dd33949
feat(model-registry): refresh AI model catalog across all providers w…
marc-romu Apr 25, 2026
e95ec0a
ci: automate release notes generation with Mistral AI
devin-ai-integration[bot] May 1, 2026
0091ae3
ci: add concurrency controls, promotion freeze, auto-discover branche…
devin-ai-integration[bot] May 1, 2026
84658a4
ci: revert hash PR target branch to always use main
devin-ai-integration[bot] May 1, 2026
7a9d5bd
docs(rules): clarify Windsurf guidance
devin-ai-integration[bot] May 3, 2026
d9759e0
Specify zeroed GUID for new components
marc-romu May 3, 2026
a897928
docs(rules): clarify component GUID placeholder
devin-ai-integration[bot] May 3, 2026
2b9a86f
Revise unit test guidelines for Rhino/Grasshopper
marc-romu May 3, 2026
9e82b63
docs(rules): align testing guidance
devin-ai-integration[bot] May 3, 2026
08f4f03
docs(rules): align tool envelope guidance
devin-ai-integration[bot] May 3, 2026
2456728
ci: remove redundant JSON output from PR creation in contributors wor…
marc-romu May 3, 2026
988c56f
docs: update contributors section for main
actions-user May 3, 2026
6f8a652
ci: fix patch propagate conflicts handling, manifest output ref, and …
marc-romu May 3, 2026
cf034b8
ci: allow hash files in PRs when content matches main exactly
marc-romu May 3, 2026
3c4b24d
Merge branch 'main' of https://github.com/architects-toolkit/SmartHopper
marc-romu May 3, 2026
9cb4d56
ci: automate license header updates on PRs
marc-romu May 3, 2026
1bb89d6
ci: add community model verification workflow and tooling
marc-romu May 3, 2026
b14c8cd
ci: add concurrency controls to prevent workflow race conditions
marc-romu May 3, 2026
52e4284
ci: harden auto-commit workflows against concurrent push race conditions
marc-romu May 3, 2026
fd716fc
ci: add workflow to auto-sync main into dev branches
marc-romu May 3, 2026
7a3332e
Merge remote-tracking branch 'public/main' into dev-1.4.2
marc-romu May 3, 2026
5f76f03
ci: restrict main-sync-to-dev to infra-only diffs for stabilization b…
marc-romu May 3, 2026
1c95372
Merge remote-tracking branch 'public/main' into dev-1.4.2
marc-romu May 3, 2026
c17ba8e
ci: refactor main-sync-to-dev to cherry-pick allow-listed files onto …
marc-romu May 3, 2026
a4e1e31
ci: add automated provider model discovery via OpenRouter API
marc-romu May 3, 2026
8418e06
refactor: remove JsonInput capability and add wildcard support for Di…
marc-romu May 3, 2026
7138dc6
refactor: skip fine-tuned models and group provider models by release…
marc-romu May 3, 2026
7c59756
refactor: reorganize MistralAI models by release quarter and mark 10 …
marc-romu May 3, 2026
93c4cde
refactor: add DeepSeek v4 models and deprecate v3/reasoner models
marc-romu May 3, 2026
45767e2
refactor: add suffix-based alias grouping for OpenAI/Anthropic and no…
marc-romu May 3, 2026
ee9d426
refactor: reorganize Anthropic models by release quarter, add Claude …
marc-romu May 3, 2026
406a865
refactor: reorganize OpenAI models by release quarter, add GPT-5/o3/o…
marc-romu May 3, 2026
1115076
refactor: fix dated model aliasing to preserve distinct releases and …
marc-romu May 3, 2026
96f0b62
refactor: reorder Anthropic/MistralAI models by release quarter and a…
marc-romu May 3, 2026
eff5608
refactor: resolve OpenRouter entries by newest release when multiple …
marc-romu May 3, 2026
85d5ebe
refactor: increase non-deprecated model rank ceiling from 1000 to 10000
marc-romu May 3, 2026
2531e01
refactor: add 4000+ OpenRouter models organized by release quarter (F…
marc-romu May 3, 2026
518deb5
refactor: exclude OpenRouter from provider API queries since it uses …
marc-romu May 3, 2026
7e5eee9
refactor: add section headers and improve formatting in code review w…
marc-romu May 3, 2026
3178a45
refactor: add optional provider-api-key input for dual-source model v…
marc-romu May 3, 2026
200ed76
chore(ci): update license headers
github-actions[bot] May 3, 2026
b4dd14e
refactor: add default capability flags to claude-sonnet-4-5-20250929 …
marc-romu May 3, 2026
1941580
Potential fix for pull request finding
marc-romu May 3, 2026
c5e1ac2
Potential fix for pull request finding
marc-romu May 3, 2026
b0b0f09
refactor: add VideoInput, VideoOutput, and EmbedOutput capability fla…
marc-romu May 3, 2026
2ec97a8
refactor: normalize model ranking scale from 900-1000 to 9900-10000 r…
marc-romu May 3, 2026
5b5b931
refactor: prioritize output_modalities for detecting embedding capabi…
marc-romu May 3, 2026
5bbb073
refactor: update default capability assignments for Anthropic models …
marc-romu May 3, 2026
79a9ab0
chore(ci): update license headers
github-actions[bot] May 3, 2026
0894e47
refactor: remove trailing whitespace from comment in Update-ProviderM…
marc-romu May 3, 2026
3f972d3
refactor: replace AICapability.Embedding with AICapability.EmbedOutpu…
marc-romu May 3, 2026
91eefc4
fix(ci): normalize whitespace in provider filter check for model upda…
marc-romu May 3, 2026
f1ab0a0
refactor(ci): standardize automation label from 'automation' to 'auto…
marc-romu May 3, 2026
e8b5dc4
refactor(ci): improve model alias handling and file encoding in Updat…
marc-romu May 3, 2026
8b44e47
refactor: add -latest aliases to all OpenAI and Anthropic models, con…
marc-romu May 3, 2026
1cc86d2
chore: anonymize SmartHopperPublicKey
actions-user May 3, 2026
32701de
chore: sync allow-listed files from main → dev-1.4.2
github-actions[bot] May 3, 2026
e19e928
Merge remote-tracking branch 'public/main' into dev-1.4.2
marc-romu May 3, 2026
248afd0
refactor: reorder AICapability bit positions, normalize capability or…
marc-romu May 3, 2026
4e4fbc8
chore: sync allow-listed files from main → dev-1.4.2
github-actions[bot] May 4, 2026
b68f57a
chore: sync allow-listed files from main → dev-1.4.2
github-actions[bot] May 12, 2026
20fd9d8
chore: sync main → dev-1.4.2 (infra + provider models) (#471)
github-actions[bot] May 17, 2026
1166ed8
chore: prepare release 1.4.2-rc with version update and code style fi…
github-actions[bot] May 17, 2026
bab2f76
Merge branch 'main-1.4.2' into dev-1.4.2
marc-romu May 17, 2026
aa2c195
refactor: add provider model validation with composite capability che…
marc-romu May 17, 2026
8146727
chore: sync main → dev-1.4.2 (infra + provider models) (#484)
github-actions[bot] May 17, 2026
5120fca
chore: sync main → dev-1.4.2 (infra + provider models) (#486)
github-actions[bot] May 17, 2026
c4d30e9
refactor: add Default capability flags to MistralAI models for Image2…
marc-romu May 17, 2026
8dc2533
fix: backport robust JSON recovery pipeline for scriptgenerate/ghput …
devin-ai-integration[bot] May 17, 2026
251d455
chore: sync main → dev-1.4.2 (infra + provider models) (#492)
github-actions[bot] May 17, 2026
e617778
chore: sync main → dev-1.4.2 (infra + provider models) (#504)
github-actions[bot] May 17, 2026
c6d6cd9
chore: sync main → dev-1.4.2 (infra + provider models) (#506)
github-actions[bot] May 18, 2026
f4eb5cd
feat: add component name alias resolution for AI-generated GhJSON (#507)
devin-ai-integration[bot] May 18, 2026
e7f9108
fix: resolve component aliases via live server GUID lookup for script…
devin-ai-integration[bot] May 18, 2026
a4aaf8a
fix: parameterize manifest-path in release workflow and add NOTE_TEXT…
marc-romu May 18, 2026
d7be78e
chore: prepare release 1.4.3 with version update and code style fixes…
github-actions[bot] May 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
625 changes: 625 additions & 0 deletions .github/ISSUE_TEMPLATE/model-verification.yml

Large diffs are not rendered by default.

111 changes: 111 additions & 0 deletions .github/WORKFLOWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Workflow Conventions

> Canonical reference for all GitHub Actions conventions in SmartHopper.
> Every contributor and every new workflow **must** follow these rules.

## Branch Protection Model

| Pattern | Protection |
|---------|-----------|
| `main`, `main-*` | PR + codeowner approval required |
| `dev`, `dev-*` | PR + codeowner approval required |
| `hotfix/*` | PR + codeowner approval required |
| `release/**` | PR + codeowner approval required |

**No workflow may push directly to a protected branch.** All automated
changes must go through a PR created by `peter-evans/create-pull-request@v6`
(preferred) or `gh pr create`.

## Action Version Pinning

| Action | Pin style |
|--------|-----------|
| First-party (`actions/*`) | **Tag** — e.g. `actions/checkout@v4` |
| Third-party (community) | **Tag** — e.g. `peter-evans/create-pull-request@v6` |
| Local composite actions | **Path** — e.g. `./.github/actions/…` |

Do **not** use SHA pinning (`@abc123…`). Tag pinning is easier to audit
and auto-update with Dependabot.

## PR Creation Convention

Use `peter-evans/create-pull-request@v6` for chore workflows that modify
files in the working tree. Use `gh pr create` only when constructing PRs
from existing branches (e.g. release pipeline).

Every automated PR must:
1. Carry the `automated` label.
2. Call `./.github/actions/milestone/assign-pr` to assign the current milestone.
3. Call `./.github/actions/dispatch-required-pr-checks` to trigger status checks.

## Concurrency & `cancel-in-progress`

| Workflow type | `cancel-in-progress` | Rationale |
|---------------|---------------------|-----------|
| PR validation / CI checks | `true` | Superseded by newer pushes |
| Chore (version-date, badge, manifest, …) | `false` | Must complete to avoid stale state |
| Release pipeline (`release-1` … `release-6`) | `false` | Irreversible side-effects |
| Issue/label management | `false` | Quick, idempotent |

## Timeout Policy

Every job **must** declare `timeout-minutes`. Defaults:

| Job type | Timeout |
|----------|---------|
| Lightweight (label, comment, branch delete) | 5 min |
| Standard (checkout + script) | 10 min |
| Build / test (.NET CI) | 30 min |
| Heavy (model fetch, AI generation) | 45 min |

## PowerShell Conventions

When a workflow step uses `shell: pwsh`, call scripts with the `&`
(call operator), **not** by spawning a nested `pwsh` process:

```yaml
# Good
shell: pwsh
run: |
& .\tools\My-Script.ps1 -Param value

# Bad — spawns a child pwsh inside the pwsh shell
shell: pwsh
run: |
pwsh -ExecutionPolicy Bypass -File .\tools\My-Script.ps1 -Param value
```

## Validation Tiers

### Provider Model Validation (`Update-ProviderModels.ps1`)

| Tier | Severity | Blocks merge? | Examples |
|------|----------|---------------|----------|
| Error | `::error::` | Yes | Invalid capability expression, realtime model in list, pending capability |
| Warning | `::warning::` | No | Missing default for a composite capability category |

### PR Validation (`pr-validation.yml`)

| Check | Blocks merge? | Notes |
|-------|---------------|-------|
| Version format | Yes | Must be valid semver |
| Code style | Yes | Trailing whitespace, namespace, using order |
| Changelog | **Warning only** | Skipped for `chore/ci/style/build/revert/docs` PRs |
| PR title | Yes | Must follow conventional commits |

## Node.js Runtime

Set `FORCE_JAVASCRIPT_ACTIONS_TO_NODE24=true` as a repository-level
environment variable (or in individual workflows) to opt into Node.js 24
before the June 2026 deadline.

## Cross-Reference Comments

When two workflows overlap in trigger or purpose, each must carry a
header comment referencing the other. Example:

```yaml
# Related workflows:
# - chore-version-date.yml (updates version date on dev pushes)
# - chore-version-badge.yml (updates README badge on version change)
```
142 changes: 142 additions & 0 deletions .github/actions/ai/fetch-models/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# Reusable action that delegates to tools/Update-ProviderModels.ps1.
# OpenRouter is used as the single source of truth; the script queries
# OpenRouter's /models endpoint, filters by provider prefix, and updates
# the *ProviderModels.cs file with full capabilities mapped from metadata.
#
# Usage:
# - uses: ./.github/actions/ai/fetch-models
# with:
# provider: OpenAI
# api-key: ${{ secrets.OPENROUTER_API_KEY }}
# update-file: true

name: 'Fetch AI Provider Models'
description: 'Fetch model metadata from OpenRouter and update *ProviderModels.cs via the centralized Update-ProviderModels.ps1 tool'

inputs:
provider:
description: 'Provider identifier (e.g. OpenAI, MistralAI, Anthropic, OpenRouter, DeepSeek)'
required: true
api-key:
description: 'OpenRouter API key (used as the single source of truth for all providers)'
required: true
provider-api-key:
description: 'Optional native API key for the target provider. When supplied, the provider''s own /models endpoint is queried as a secondary authoritative source (alias merging, deprecation flags). OpenRouter remains the metadata source of truth.'
required: false
default: ''
update-file:
description: 'When true, the script rewrites the source file: auto-inserts new models with capabilities mapped from OpenRouter metadata, updates existing model capabilities/ContextLimit, and marks disappeared or expiring models as Deprecated = true'
required: false
default: 'false'
fail-on-validation-errors:
description: 'When true, fail if updated provider models are missing required defaults, contain pending capabilities, or contain realtime models'
required: false
default: 'false'

outputs:
models:
description: 'JSON array of model ID strings returned by the API'
value: ${{ steps.run.outputs.models }}
count:
description: 'Number of distinct models returned'
value: ${{ steps.run.outputs.count }}
success:
description: 'Whether the operation succeeded'
value: ${{ steps.run.outputs.success }}
error:
description: 'Error message if the call failed'
value: ${{ steps.run.outputs.error }}
report:
description: 'Full JSON report emitted by Update-ProviderModels.ps1'
value: ${{ steps.run.outputs.report }}
changed:
description: 'Whether the source file was modified'
value: ${{ steps.run.outputs.changed }}

runs:
using: 'composite'
steps:
- name: Run Update-ProviderModels.ps1
id: run
shell: pwsh
env:
API_KEY: ${{ inputs.api-key }}
PROVIDER_API_KEY: ${{ inputs.provider-api-key }}
run: |
$ErrorActionPreference = 'Stop'

$params = @{
Provider = '${{ inputs.provider }}'
ApiKey = $env:API_KEY
}
if (-not [string]::IsNullOrWhiteSpace($env:PROVIDER_API_KEY)) {
$params['ProviderApiKey'] = $env:PROVIDER_API_KEY
}
if ('${{ inputs.update-file }}' -eq 'true') {
$params['UpdateFile'] = $true
}
if ('${{ inputs.fail-on-validation-errors }}' -eq 'true') {
$params['FailOnValidationErrors'] = $true
}

try {
$reportJson = & .\tools\Update-ProviderModels.ps1 @params
$scriptExit = $LASTEXITCODE

# The script emits its JSON report on stdout regardless of validation
# outcome. Try to parse it even on non-zero exit so we can surface the
# validation details (the script also writes ::error:: annotations,
# but exposing the structured report lets the caller decide what to do).
$report = $null
if ($reportJson) {
try { $report = $reportJson | ConvertFrom-Json } catch { $report = $null }
}

if ($scriptExit -ne 0) {
Write-Host "::error::Update-ProviderModels.ps1 exited with code $scriptExit"
"success=false" >> $env:GITHUB_OUTPUT
"error=Update-ProviderModels.ps1 exited with code $scriptExit" >> $env:GITHUB_OUTPUT
"changed=false" >> $env:GITHUB_OUTPUT
"count=0" >> $env:GITHUB_OUTPUT
"models=[]" >> $env:GITHUB_OUTPUT
if ($report) {
"report<<EOF_REPORT" >> $env:GITHUB_OUTPUT
"$reportJson" >> $env:GITHUB_OUTPUT
"EOF_REPORT" >> $env:GITHUB_OUTPUT
} else {
"report={}" >> $env:GITHUB_OUTPUT
}
exit $scriptExit
}

$modelsJson = ($report.apiModels | ConvertTo-Json -Compress)
if ($modelsJson -eq 'null') { $modelsJson = '[]' }

"success=true" >> $env:GITHUB_OUTPUT
"error=" >> $env:GITHUB_OUTPUT
"changed=$($report.fileUpdated)" >> $env:GITHUB_OUTPUT
"count=$($report.apiModels.Count)" >> $env:GITHUB_OUTPUT

"models<<EOF_MODELS" >> $env:GITHUB_OUTPUT
"$modelsJson" >> $env:GITHUB_OUTPUT
"EOF_MODELS" >> $env:GITHUB_OUTPUT

"report<<EOF_REPORT" >> $env:GITHUB_OUTPUT
"$reportJson" >> $env:GITHUB_OUTPUT
"EOF_REPORT" >> $env:GITHUB_OUTPUT
}
catch {
# Print the failure visibly. The previous implementation wrote the
# message to $env:GITHUB_OUTPUT only, which hid the actual cause from
# the run log and made these jobs near-impossible to diagnose.
Write-Host "::error::Update-ProviderModels.ps1 failed: $($_.Exception.Message)"
if ($_.ScriptStackTrace) { Write-Host $_.ScriptStackTrace }

"success=false" >> $env:GITHUB_OUTPUT
"error=$($_.Exception.Message)" >> $env:GITHUB_OUTPUT
"changed=false" >> $env:GITHUB_OUTPUT
"count=0" >> $env:GITHUB_OUTPUT
"models=[]" >> $env:GITHUB_OUTPUT
"report={}" >> $env:GITHUB_OUTPUT
exit 1
}
129 changes: 129 additions & 0 deletions .github/actions/ai/mistral-chat/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Generic, reusable Mistral AI Chat Completions API wrapper.
# This action is a raw API client with no domain-specific logic.
# It can be used by any workflow that needs AI text generation capabilities.

name: 'Mistral AI Chat'
description: 'Generic wrapper around the Mistral AI Chat Completions API'

inputs:
api-key:
description: 'Mistral AI API key'
required: true
model:
description: 'Mistral model name'
required: false
default: 'mistral-medium-latest'
system-prompt:
description: 'System message content'
required: false
default: ''
user-prompt:
description: 'User message content'
required: true
temperature:
description: 'Sampling temperature'
required: false
default: '0.7'
max-tokens:
description: 'Maximum tokens in response'
required: false
default: '4096'

outputs:
response:
description: 'Raw text content from the API response'
value: ${{ steps.call_api.outputs.response }}
usage-prompt-tokens:
description: 'Prompt tokens used'
value: ${{ steps.call_api.outputs.usage-prompt-tokens }}
usage-completion-tokens:
description: 'Completion tokens used'
value: ${{ steps.call_api.outputs.usage-completion-tokens }}
success:
description: 'Whether the API call succeeded'
value: ${{ steps.call_api.outputs.success }}
error:
description: 'Error message if the call failed'
value: ${{ steps.call_api.outputs.error }}

runs:
using: 'composite'
steps:
- name: Call Mistral AI API
id: call_api
shell: bash
env:
API_KEY: ${{ inputs.api-key }}
MODEL: ${{ inputs.model }}
SYSTEM_PROMPT: ${{ inputs.system-prompt }}
USER_PROMPT: ${{ inputs.user-prompt }}
TEMPERATURE: ${{ inputs.temperature }}
MAX_TOKENS: ${{ inputs.max-tokens }}
run: |
# Build JSON payload using jq to safely handle special characters
PAYLOAD=$(jq -n \
--arg model "$MODEL" \
--arg system "$SYSTEM_PROMPT" \
--arg user "$USER_PROMPT" \
--argjson temperature "$TEMPERATURE" \
--argjson max_tokens "$MAX_TOKENS" \
'{
model: $model,
messages: (
if ($system | length) > 0
then [{role: "system", content: $system}, {role: "user", content: $user}]
else [{role: "user", content: $user}]
end
),
temperature: $temperature,
max_tokens: $max_tokens
}')

# Call the API
HTTP_RESPONSE=$(curl -s -w "\n%{http_code}" -X POST "https://api.mistral.ai/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $API_KEY" \
-d "$PAYLOAD")

# Split body and status code
HTTP_BODY=$(echo "$HTTP_RESPONSE" | sed '$d')
HTTP_STATUS=$(echo "$HTTP_RESPONSE" | tail -n 1)

if [ "$HTTP_STATUS" -eq 200 ]; then
# Extract response content
CONTENT=$(echo "$HTTP_BODY" | jq -r '.choices[0].message.content // empty')
PROMPT_TOKENS=$(echo "$HTTP_BODY" | jq -r '.usage.prompt_tokens // 0')
COMPLETION_TOKENS=$(echo "$HTTP_BODY" | jq -r '.usage.completion_tokens // 0')

if [ -z "$CONTENT" ]; then
echo "::warning::Mistral API call succeeded but returned empty content"
echo "success=false" >> "$GITHUB_OUTPUT"
echo "error=API returned empty content" >> "$GITHUB_OUTPUT"
echo "response=" >> "$GITHUB_OUTPUT"
echo "usage-prompt-tokens=0" >> "$GITHUB_OUTPUT"
echo "usage-completion-tokens=0" >> "$GITHUB_OUTPUT"
else
echo "success=true" >> "$GITHUB_OUTPUT"
echo "error=" >> "$GITHUB_OUTPUT"
{
echo "response<<EOF_MISTRAL_RESPONSE"
echo "$CONTENT"
echo "EOF_MISTRAL_RESPONSE"
} >> "$GITHUB_OUTPUT"
echo "usage-prompt-tokens=$PROMPT_TOKENS" >> "$GITHUB_OUTPUT"
echo "usage-completion-tokens=$COMPLETION_TOKENS" >> "$GITHUB_OUTPUT"
fi
else
# Error handling
ERROR_MSG=$(echo "$HTTP_BODY" | head -c 500)
echo "::warning::Mistral API call failed: HTTP $HTTP_STATUS - $ERROR_MSG"
echo "success=false" >> "$GITHUB_OUTPUT"
{
echo "error<<EOF_MISTRAL_ERROR"
echo "HTTP $HTTP_STATUS: $ERROR_MSG"
echo "EOF_MISTRAL_ERROR"
} >> "$GITHUB_OUTPUT"
echo "response=" >> "$GITHUB_OUTPUT"
echo "usage-prompt-tokens=0" >> "$GITHUB_OUTPUT"
echo "usage-completion-tokens=0" >> "$GITHUB_OUTPUT"
fi
Loading
Loading