Skip to content

feat: Add supply-chain-risk-oracle kit#277

Open
KURO-1125 wants to merge 5 commits into
Lamatic:mainfrom
KURO-1125:feat/supply-chain-risk-oracle
Open

feat: Add supply-chain-risk-oracle kit#277
KURO-1125 wants to merge 5 commits into
Lamatic:mainfrom
KURO-1125:feat/supply-chain-risk-oracle

Conversation

@KURO-1125

@KURO-1125 KURO-1125 commented Jul 20, 2026

Copy link
Copy Markdown

Supply Chain Risk Oracle

Adds a full-stack Kit that autonomously scans global disruption signals for a user-supplied list of suppliers, scores each node 0–100, and drafts professional mitigation emails for high-risk suppliers.

Problem

Procurement and logistics teams learn about supply chain disruptions after they have already caused delays. There is no existing kit in AgentKit that addresses proactive supplier risk monitoring.

What this kit does

  1. User pastes a supplier list (CSV or JSON) into the Next.js UI
  2. Flow 1 — Supply Chain Scan: parses suppliers → builds search queries → fetches live news (NewsAPI) and weather (OpenWeatherMap) → LLM analyzes disruption signals → scores each supplier 0–100 → returns a structured risk matrix
  3. Flow 2 — Email Draft: takes a high-risk supplier profile and generates a professional supplier inquiry email staged for human review before sending

Live Demo

https://supply-chain-risk-oracle.vercel.app

Load the sample data and click Run risk scan to see it in action.

Flows

Flow Description
supply-chain-scan Parses suppliers, fetches live API data, returns scored risk matrix
supply-chain-email-draft Drafts a professional outreach email for a high-risk supplier

Tech stack

  • Platform: Lamatic.ai (visual flows + edge GraphQL API)
  • Frontend: Next.js 15, Tailwind CSS, plain CSS (no shadcn dependency)
  • LLM: Configurable in Studio (tested with llama-3.1-8b on Groq free tier)
  • Live data: NewsAPI (free tier) + OpenWeatherMap (free tier)

PR Checklist

1. Select Contribution Type

  • Kit (kits/<category>/<kit-name>/)
  • Bundle (bundles/<bundle-name>/)
  • Template (templates/<template-name>/)

2. General Requirements

  • PR is for one project only (no unrelated changes)
  • No secrets, API keys, or real credentials are committed
  • Folder name uses kebab-case and matches the flow ID
  • All changes are documented in README.md (purpose, setup, usage)

3. File Structure (Check what applies)

  • config.json present with valid metadata (name, description, tags, steps, author, env keys)
  • All flows in flows/<flow-name>/ (where applicable) include:
    • config.json (Lamatic flow export)
    • inputs.json
    • meta.json
    • README.md
  • .env.example with placeholder values only (kits only)
  • No hand‑edited flow config.json node graphs (changes via Lamatic Studio export)

4. Validation

  • npm install && npm run dev works locally (kits: UI runs; bundles/templates: flows are valid)
  • PR title is clear (e.g., [kit] Add <name> for <use case>)
  • GitHub Actions workflows pass (all checks are green)
  • All CodeRabbit or other PR review comments are addressed and resolved
  • No unrelated files or projects are modified
  • Added kits/supply-chain-risk-oracle Kit scaffolding and documentation:
    • .env.example, README.md, agent.md, constitutions/default.md, lamatic.config.ts
    • .gitignore
  • Added Lamatic agent/flow building blocks:
    • Flows:
      • flows/supply-chain-scan.ts: node graph triggerNodedynamicNode (LLM parse) → dynamicNode (code: build API queries) → dynamicNode (apiNode: NewsAPI + OpenWeatherMap) → dynamicNode (code: format API data) → dynamicNode (LLM search) → dynamicNode (LLM score/synthesize) → dynamicNode (code: build output) → graphqlResponseNode response (defaultEdge + final responseEdge). Produces risk_matrix, high_risk_suppliers, scan_timestamp, summary.
      • flows/supply-chain-email-draft.ts: node graph triggerNodedynamicNode (LLM draft) → graphqlResponseNode response. Produces email_subject, email_body, urgency_level for high-risk suppliers.
    • Prompts: prompts/scan-system.md, supply-chain-scan_parse_user.md, supply-chain-scan_search_user.md, supply-chain-scan_score_user.md, email-system.md, supply-chain-email-draft_draft_user.md
    • Model config stubs: model-configs/supply-chain-scan_* and model-configs/supply-chain-email-draft_draft.ts (empty memories/messages/attachments arrays)
    • Scripts:
      • scripts/supply-chain-scan_build-query.ts
      • scripts/supply-chain-scan_format-api-data.ts
      • scripts/supply-chain-scan_build-output.ts (JSON parsing incl. markdown code-fence stripping + fallback error output)
  • Added Next.js 15 full-stack UI/config under kits/supply-chain-risk-oracle/apps:
    • App config/templates: apps/.env.example, apps/.gitignore, package.json, next.config.mjs, tsconfig.json, next-env.d.ts, postcss.config.mjs
    • Frontend: app/layout.tsx, app/page.tsx, app/globals.css (risk dashboard, expandable supplier rows, email-draft modal)
    • Server/client logic:
      • apps/lib/config.ts (env/flow IDs + Lamatic credentials)
      • apps/lib/lamatic-client.ts (validates required config)
      • apps/lib/types.ts (typed risk/scan/email contracts + ActionResult)
      • apps/actions/orchestrate.ts (server actions runSupplyChainScan + draftSupplierEmail, including normalization/clamping and flexible JSON parsing for email generation)

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: 05ef3ddd-0997-415f-9a6a-cae39b65cfb6

📥 Commits

Reviewing files that changed from the base of the PR and between 69020f2 and 4e67dbb.

📒 Files selected for processing (2)
  • kits/supply-chain-risk-oracle/apps/.gitignore
  • kits/supply-chain-risk-oracle/apps/app/page.tsx

Walkthrough

Changes

The pull request adds a complete Supply Chain Risk Oracle kit with Lamatic scan and email workflows, prompts and processing scripts, server actions, configuration, and a Next.js dashboard for supplier risk analysis and outreach drafting.

Changes

Supply Chain Risk Oracle

Layer / File(s) Summary
Agent contract and kit configuration
kits/supply-chain-risk-oracle/agent.md, constitutions/default.md, lamatic.config.ts, .env.example, .gitignore
Defines agent behavior, scoring constraints, workflow entries, environment variables, and ignored local artifacts.
Supply-chain scan pipeline
flows/supply-chain-scan.ts, prompts/scan-*, model-configs/supply-chain-scan_*, scripts/supply-chain-scan_*
Adds supplier parsing, query construction, news and weather retrieval, API formatting, disruption analysis, scoring, and structured risk output.
Supplier email drafting flow
flows/supply-chain-email-draft.ts, prompts/email-*, model-configs/supply-chain-email-draft_draft.ts
Adds email-drafting flow configuration, prompt contracts, model configuration, and JSON response mapping.
Application contracts and Lamatic actions
apps/lib/*, apps/actions/orchestrate.ts
Adds typed results, Lamatic client validation, workflow execution, response normalization, and error handling.
Risk dashboard and email modal
apps/app/page.tsx, apps/app/globals.css, apps/app/layout.tsx
Adds scan controls, sorted risk findings, supplier details, risk summaries, email drafting, clipboard copying, responsive styles, and metadata.
App setup and usage documentation
apps/package.json, apps/*.config.mjs, apps/tsconfig.json, apps/next-env.d.ts, apps/.env.example, README.md
Adds Next.js and Tailwind setup, TypeScript configuration, environment documentation, ignore rules, and local/deployment instructions.

Suggested reviewers: amanintech, d-pamneja

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the new supply-chain-risk-oracle kit and matches the main change.
Description check ✅ Passed The description is well structured, covers purpose, flows, tech stack, demo, and the checklist, with only a few incomplete checklist items.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@github-actions

github-actions Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

:robot_face: AgentKit Structural Validation

New Contributions Detected

  • Kit: kits/supply-chain-risk-oracle

Check Results

Check Status
No edits to existing kits ✅ Pass
Required root files present ✅ Pass
Flow .ts files present ✅ Pass
lamatic.config.ts valid ✅ Pass
No changes outside kits/ ✅ Pass
Flow asset references valid ✅ Pass

🎉 All checks passed! This contribution follows the AgentKit structure.

@github-actions

Copy link
Copy Markdown
Contributor

Failure recorded at 2026-07-20T13:13:39Z UTC. If this PR is not fixed within 4 weeks it will be automatically closed.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 8

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@kits/supply-chain-risk-oracle/apps/actions/orchestrate.ts`:
- Around line 40-48: Harden runSupplyChainScan output by normalizing every
risk_matrix entry with defaults for missing SupplierRisk fields, including
risk_factors as an empty array and risk_score plus other promised fields as
appropriate. Also update both kits/supply-chain-risk-oracle/apps/app/page.tsx
sites at lines 102 and 188-189 to use optional risk_factors mapping with an
empty-array fallback in EmailModal and SupplierAccordion.
- Around line 76-77: Update the cleaning logic immediately before JSON.parse in
the draft parsing flow to trim raw before removing the opening and closing code
fences, then retain the final trim. Ensure fenced JSON with leading blank lines
or trailing newlines is normalized so JSON.parse receives only the payload.
- Around line 28-33: Remove news_api_key and weather_api_key from the
executeFlow input object in the orchestration flow. Configure the flow to obtain
these credentials through its supported secret or environment-variable
mechanism, while preserving the suppliers and scan_focus inputs and the existing
NEWS_API_KEY and WEATHER_API_KEY configuration names.
- Around line 3-4: Validate each risk_matrix entry in the action before
returning flow output, ensuring every supplier has risk_factors and all required
SupplierRisk fields expected by apps/app/page.tsx; reject or handle malformed
entries instead of returning them. Apply the root fix in
kits/supply-chain-risk-oracle/apps/actions/orchestrate.ts (lines 3-4);
kits/supply-chain-risk-oracle/apps/lib/config.ts (lines 7-16) requires no direct
change.

In `@kits/supply-chain-risk-oracle/apps/app/page.tsx`:
- Around line 161-176: Make the supplier accordion control in the
supplier-row-head element keyboard accessible by adding an appropriate
button-like role, tabIndex, and keyboard handler that toggles open for Enter and
Space while preserving the existing click behavior. Ensure assistive
technologies can identify its expanded state so keyboard and screen-reader users
can reach the row’s inquiry content.
- Around line 71-149: Update the EmailModal root dialog to support keyboard
dismissal and accessible dialog semantics: add role="dialog", aria-modal="true",
and an onKeyDown handler that calls onClose when Escape is pressed. Ensure
keyboard focus is contained within the modal while it is open, using the
component’s existing modal structure and controls.

In `@kits/supply-chain-risk-oracle/apps/package.json`:
- Line 24: Update the tailwindcss dependency in the package manifest from the
current 3.x range to a Tailwind CSS v4 or newer release, preserving the existing
dependency configuration.

In `@kits/supply-chain-risk-oracle/prompts/scan-system.md`:
- Around line 1-3: Remove the cosmetic heading and following blank line from
kits/supply-chain-risk-oracle/prompts/scan-system.md at lines 1-3, leaving the
prompt content as the file’s first text. In
kits/supply-chain-risk-oracle/prompts/email-system.md at lines 1-36, remove the
“Email Drafting System Prompt” heading and all two-space indentation throughout
the file.
🪄 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: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0c667b5f-7773-4425-8351-41c4653d3a24

📥 Commits

Reviewing files that changed from the base of the PR and between 69b0fc6 and 6482090.

⛔ Files ignored due to path filters (1)
  • kits/supply-chain-risk-oracle/apps/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (33)
  • kits/supply-chain-risk-oracle/.env.example
  • kits/supply-chain-risk-oracle/.gitignore
  • kits/supply-chain-risk-oracle/README.md
  • kits/supply-chain-risk-oracle/agent.md
  • kits/supply-chain-risk-oracle/apps/.env.example
  • kits/supply-chain-risk-oracle/apps/.gitignore
  • kits/supply-chain-risk-oracle/apps/actions/orchestrate.ts
  • kits/supply-chain-risk-oracle/apps/app/globals.css
  • kits/supply-chain-risk-oracle/apps/app/layout.tsx
  • kits/supply-chain-risk-oracle/apps/app/page.tsx
  • kits/supply-chain-risk-oracle/apps/lib/config.ts
  • kits/supply-chain-risk-oracle/apps/lib/lamatic-client.ts
  • kits/supply-chain-risk-oracle/apps/lib/types.ts
  • kits/supply-chain-risk-oracle/apps/next-env.d.ts
  • kits/supply-chain-risk-oracle/apps/next.config.mjs
  • kits/supply-chain-risk-oracle/apps/package.json
  • kits/supply-chain-risk-oracle/apps/postcss.config.mjs
  • kits/supply-chain-risk-oracle/apps/tailwind.config.ts
  • kits/supply-chain-risk-oracle/apps/tsconfig.json
  • kits/supply-chain-risk-oracle/constitutions/default.md
  • kits/supply-chain-risk-oracle/flows/supply-chain-email-draft.ts
  • kits/supply-chain-risk-oracle/flows/supply-chain-scan.ts
  • kits/supply-chain-risk-oracle/lamatic.config.ts
  • kits/supply-chain-risk-oracle/model-configs/supply-chain-email-draft_draft.ts
  • kits/supply-chain-risk-oracle/model-configs/supply-chain-scan_parse.ts
  • kits/supply-chain-risk-oracle/model-configs/supply-chain-scan_score.ts
  • kits/supply-chain-risk-oracle/model-configs/supply-chain-scan_search.ts
  • kits/supply-chain-risk-oracle/prompts/email-system.md
  • kits/supply-chain-risk-oracle/prompts/scan-system.md
  • kits/supply-chain-risk-oracle/prompts/supply-chain-email-draft_draft_user.md
  • kits/supply-chain-risk-oracle/prompts/supply-chain-scan_parse_user.md
  • kits/supply-chain-risk-oracle/prompts/supply-chain-scan_score_user.md
  • kits/supply-chain-risk-oracle/prompts/supply-chain-scan_search_user.md

Comment thread kits/supply-chain-risk-oracle/apps/actions/orchestrate.ts
Comment thread kits/supply-chain-risk-oracle/apps/actions/orchestrate.ts
Comment thread kits/supply-chain-risk-oracle/apps/actions/orchestrate.ts
Comment thread kits/supply-chain-risk-oracle/apps/actions/orchestrate.ts Outdated
Comment thread kits/supply-chain-risk-oracle/apps/app/page.tsx
Comment thread kits/supply-chain-risk-oracle/apps/app/page.tsx Outdated
Comment thread kits/supply-chain-risk-oracle/apps/package.json Outdated
Comment thread kits/supply-chain-risk-oracle/prompts/scan-system.md Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@kits/supply-chain-risk-oracle/scripts/supply-chain-scan_build-output.ts`:
- Around line 3-25: Replace the top-level return in the parsed-response handler
with standard if/else control flow: track parse failure, treat null or otherwise
absent parsed values as errors, and assign the existing fallback output without
returning. Only access parsed.risk_matrix and parsed.summary in the successful
branch, preserving the existing output structure and safely filtering supplier
entries.

In `@kits/supply-chain-risk-oracle/scripts/supply-chain-scan_build-query.ts`:
- Around line 3-14: Harden the supplier extraction and query construction around
the suppliers and locationTerms logic: wrap JSON parsing and payload extraction
in try/catch, normalize non-array results to an empty array, and safely ignore
suppliers without a usable location. Filter empty location terms and append the
location clause only when terms exist, so newsQuery never ends with an empty
pair of parentheses.
🪄 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: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: 8f63076b-8133-483a-86ac-ba9fc82b3909

📥 Commits

Reviewing files that changed from the base of the PR and between 6482090 and 122879f.

📒 Files selected for processing (3)
  • kits/supply-chain-risk-oracle/scripts/supply-chain-scan_build-output.ts
  • kits/supply-chain-risk-oracle/scripts/supply-chain-scan_build-query.ts
  • kits/supply-chain-risk-oracle/scripts/supply-chain-scan_format-api-data.ts

Comment thread kits/supply-chain-risk-oracle/scripts/supply-chain-scan_build-output.ts Outdated
Comment thread kits/supply-chain-risk-oracle/scripts/supply-chain-scan_build-query.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@kits/supply-chain-risk-oracle/apps/.gitignore`:
- Line 5: Update the .gitignore rules around the existing .vercel entry to
ignore all .env.* environment-file variants while explicitly allowing the
intended environment template file. Preserve the existing ignore behavior and
ensure production and development environment files cannot be committed.

In `@kits/supply-chain-risk-oracle/apps/app/page.tsx`:
- Around line 169-176: Update the supplier-row keyboard handler on the accordion
element to call e.preventDefault() when the Space key is pressed before toggling
open state, while preserving Enter behavior and the existing setOpen logic.
🪄 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: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: e7ef7b3a-b7ed-497b-9a1e-0db9904d2bfe

📥 Commits

Reviewing files that changed from the base of the PR and between 122879f and 69020f2.

⛔ Files ignored due to path filters (1)
  • kits/supply-chain-risk-oracle/apps/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (15)
  • kits/supply-chain-risk-oracle/.env.example
  • kits/supply-chain-risk-oracle/README.md
  • kits/supply-chain-risk-oracle/apps/.env.example
  • kits/supply-chain-risk-oracle/apps/.gitignore
  • kits/supply-chain-risk-oracle/apps/actions/orchestrate.ts
  • kits/supply-chain-risk-oracle/apps/app/globals.css
  • kits/supply-chain-risk-oracle/apps/app/page.tsx
  • kits/supply-chain-risk-oracle/apps/package.json
  • kits/supply-chain-risk-oracle/apps/postcss.config.mjs
  • kits/supply-chain-risk-oracle/lamatic.config.ts
  • kits/supply-chain-risk-oracle/prompts/email-system.md
  • kits/supply-chain-risk-oracle/prompts/scan-system.md
  • kits/supply-chain-risk-oracle/scripts/supply-chain-scan_build-output.ts
  • kits/supply-chain-risk-oracle/scripts/supply-chain-scan_build-query.ts
  • kits/supply-chain-risk-oracle/scripts/supply-chain-scan_format-api-data.ts
💤 Files with no reviewable changes (1)
  • kits/supply-chain-risk-oracle/.env.example

Comment thread kits/supply-chain-risk-oracle/apps/.gitignore
Comment thread kits/supply-chain-risk-oracle/apps/app/page.tsx
@coderabbitai
coderabbitai Bot requested a review from d-pamneja July 20, 2026 14:56
@github-actions

Copy link
Copy Markdown
Contributor

Hi @KURO-1125! 👋

Before this PR can be reviewed by maintainers, please resolve all comments and requested changes from the CodeRabbit automated review.

Steps to follow:

  1. Read through all CodeRabbit comments carefully
  2. Address each issue raised (or reply explaining why you disagree)
  3. Push your fixes as new commits
  4. Once all issues are resolved, comment here so we can re-review

This helps keep the review process efficient for everyone. Thank you! 🙏

@KURO-1125

Copy link
Copy Markdown
Author

Hi @KURO-1125! 👋

Before this PR can be reviewed by maintainers, please resolve all comments and requested changes from the CodeRabbit automated review.

Steps to follow:

  1. Read through all CodeRabbit comments carefully
  2. Address each issue raised (or reply explaining why you disagree)
  3. Push your fixes as new commits
  4. Once all issues are resolved, comment here so we can re-review

This helps keep the review process efficient for everyone. Thank you! 🙏

All the coderabbit reviews has been resolved and coderabbit has approved the changes as well.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant