Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ Use it when hardcoded `if/else` logic is too rigid, but a heavyweight workflow o
- Documentation: <https://sebasoft.github.io/neuron-js/>
- npm: <https://www.npmjs.com/package/@sebasoft/neuron-js>
- GitHub: <https://github.com/SebaSOFT/neuron-js>
- Examples: [`examples/`](examples/) with pricing, eligibility, and workflow-routing scenarios
- Examples: [`examples/`](examples/) with pricing, eligibility, workflow-routing, n8n, and LangGraph scenarios
- Schemas and validation docs: [`docs/schemas-validation-explainability.md`](docs/schemas-validation-explainability.md)
- AI-readable docs: [`docs/ai-coding-assistants.md`](docs/ai-coding-assistants.md), [`docs/public/llms.txt`](docs/public/llms.txt), and the official [`neuron-js` AI skill](docs/public/skills/neuron-js/SKILL.md)
- Comparison and migration guides: [`docs/comparisons/`](docs/comparisons/) for json-rules-engine, JsonLogic, node-rules, and if/else migrations
- Workflow automation recipes: [`docs/integrations/`](docs/integrations/) for n8n deterministic routing and LangGraph decision nodes

---

Expand Down Expand Up @@ -157,7 +158,7 @@ The current public surface includes installation, positioning, core concepts, ru

Available adoption assets:

- Runnable examples: [`examples/`](examples/)
- Runnable examples: [`examples/`](examples/) including n8n and LangGraph workflow automation recipes
- JSON Schemas, validation, and explain output: [`docs/schemas-validation-explainability.md`](docs/schemas-validation-explainability.md)
- Comparison and migration guides: [`docs/comparisons/`](docs/comparisons/) for choosing and migrating from json-rules-engine, JsonLogic, node-rules, and hand-written if/else
- AI-readable docs: [`docs/ai-coding-assistants.md`](docs/ai-coding-assistants.md), [`docs/public/llms.txt`](docs/public/llms.txt), [`docs/public/llms-full.txt`](docs/public/llms-full.txt), and [`docs/public/skills/neuron-js/SKILL.md`](docs/public/skills/neuron-js/SKILL.md)
Expand Down
9 changes: 9 additions & 0 deletions ai/skills/neuron-js/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ Use the official schemas when checking generated artifacts or giving another sys
- Pricing rules: https://github.com/SebaSOFT/neuron-js/tree/main/examples/pricing-rules
- Eligibility check: https://github.com/SebaSOFT/neuron-js/tree/main/examples/eligibility-check
- Workflow routing: https://github.com/SebaSOFT/neuron-js/tree/main/examples/workflow-routing
- n8n deterministic workflow routing: https://github.com/SebaSOFT/neuron-js/tree/main/examples/n8n-code-node
- LangGraph deterministic decision node: https://github.com/SebaSOFT/neuron-js/tree/main/examples/langgraph-decision-node

Public skill example JSON is available under:

Expand All @@ -130,6 +132,13 @@ Public skill example JSON is available under:
- https://sebasoft.github.io/neuron-js/skills/neuron-js/examples/eligibility-rules.json
- https://sebasoft.github.io/neuron-js/skills/neuron-js/examples/workflow-routing-rules.json

## Workflow automation recipes

Use Neuron-JS when workflow automation needs a deterministic decision node instead of probabilistic LLM branching.

- n8n recipe: load workflow data, run `validateScript(script)`, run `validateExecutionContext(context)`, execute Neuron-JS in a Code node, return `summarizeExecutionOutput(result)` and `explainExecution({ script, result })`, then route side effects in n8n. Example: https://github.com/SebaSOFT/neuron-js/tree/main/examples/n8n-code-node
- LangGraph recipe: let the LLM perform extraction/classification, validate the generated context, run Neuron-JS as the deterministic Neuron-JS decision node, store the explanation trace, and route graph edges from the normalized output. Example: https://github.com/SebaSOFT/neuron-js/tree/main/examples/langgraph-decision-node

## Prompt recipes

### Generate pricing rules
Expand Down
9 changes: 9 additions & 0 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default defineConfig({
{ text: 'Examples', link: '/use-cases/runnable-examples' },
{ text: 'Schemas', link: '/schemas-validation-explainability' },
{ text: 'Comparisons', link: '/comparisons/' },
{ text: 'Integrations', link: '/integrations/' },
{ text: 'AI Docs', link: '/ai-coding-assistants' },
{ text: 'API', link: '/api/README' }
],
Expand Down Expand Up @@ -51,6 +52,14 @@ export default defineConfig({
{ text: 'vs if/else', link: '/comparisons/if-else' }
]
},
{
text: 'Integrations',
items: [
{ text: 'Integration Guide', link: '/integrations/' },
{ text: 'n8n deterministic routing', link: '/integrations/n8n' },
{ text: 'LangGraph decision node', link: '/integrations/langgraph' }
]
},
{
text: 'API Reference',
link: '/api/README'
Expand Down
3 changes: 2 additions & 1 deletion docs/ai-coding-assistants.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Neuron-JS is intentionally documented for AI coding assistants and workflow agen
- [`/llms-full.txt`](/llms-full.txt): expanded AI context without navigation chrome.
- [`/skills/neuron-js/SKILL.md`](/skills/neuron-js/SKILL.md): official reusable skill for agent runtimes.
- [`/comparisons/`](/comparisons/): comparison and migration guides for tool selection and safe migration.
- [`/integrations/`](/integrations/): workflow automation recipes for n8n and LangGraph.
- [`/schemas/script.schema.json`](/schemas/script.schema.json): JSON Schema for scripts and rule definitions.
- [`/schemas/execution-context.schema.json`](/schemas/execution-context.schema.json): JSON Schema for runtime context.
- [`/schemas/execution-output.schema.json`](/schemas/execution-output.schema.json): JSON Schema for normalized execution output.
Expand Down Expand Up @@ -63,7 +64,7 @@ Then implement against the official examples and schemas.

## n8n and LangGraph

Use Neuron-JS as a deterministic decision node after upstream extraction or classification. Do not use it as the side-effect runner. Let n8n or LangGraph route to side-effect nodes after Neuron-JS returns a decision.
See the runnable recipes: [n8n deterministic routing](/integrations/n8n) and [LangGraph deterministic decision node](/integrations/langgraph). Use Neuron-JS as a deterministic decision node after upstream extraction or classification. Do not use it as the side-effect runner. Let n8n or LangGraph route to side-effect nodes after Neuron-JS returns a decision.

### n8n pattern

Expand Down
31 changes: 31 additions & 0 deletions docs/integrations/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Workflow automation integrations

Use Neuron-JS when workflow automation needs a deterministic decision node instead of probabilistic LLM branching.

The pattern is simple:

1. A workflow tool gathers, extracts, or classifies data.
2. Neuron-JS validates the JSON rule script with `validateScript`.
3. Neuron-JS validates the execution context with `validateExecutionContext`.
4. `Synapse` executes approved rules through a developer-owned `Neuron` registry.
5. The workflow routes side effects from `summarizeExecutionOutput` and `explainExecution`.

## Recipes

- [n8n deterministic workflow routing](./n8n.md)
- [LangGraph deterministic decision node](./langgraph.md)

## Use Neuron-JS when

- Business rules must be represented as JSON and executed deterministically.
- Rules need to be stored in a database, versioned, transmitted, or audited.
- An AI assistant generates rules and you need schema validation before execution.
- Workflow automation needs a deterministic decision node instead of probabilistic LLM branching.
- You need explanation traces for why a rule matched or failed.

## Do not use Neuron-JS when

- A simple hard-coded condition is clearer and rarely changes.
- Arbitrary user code execution is required.
- A full BPMN/process engine is required.
- Non-technical users need unrestricted rule authoring without validation, tests, review, and rollback.
76 changes: 76 additions & 0 deletions docs/integrations/langgraph.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Use Neuron-JS as a LangGraph deterministic node

Neuron-JS fits LangGraph workflows that need LLM extraction followed by a deterministic Neuron-JS decision.

Target use cases: LangGraph deterministic node, deterministic guardrails for AI agents, validate LLM generated JSON rules, rules engine for AI agents.

## Runnable example

Repository folder: [`examples/langgraph-decision-node/`](https://github.com/SebaSOFT/neuron-js/tree/main/examples/langgraph-decision-node)

```bash
yarn build
node examples/langgraph-decision-node/run.ts
```

## Pattern

1. The LLM extracts/classifies structured data.
2. LangGraph writes that structured data into graph state.
3. Neuron-JS validates the rule script with `validateScript`.
4. Neuron-JS validates the generated context with `validateExecutionContext`.
5. Neuron-JS executes approved rules and returns `summarizeExecutionOutput` plus `explainExecution`.
6. LangGraph routes the next edge from the deterministic output, not free-form LLM text.

## Copy-paste node shape

```typescript
import {
Neuron,
Synapse,
explainExecution,
summarizeExecutionOutput,
validateExecutionContext,
validateScript,
} from '@sebasoft/neuron-js';

export async function neuronDecisionNode(state) {
const context = {
messages: [],
state: { classification: state.llmClassification },
};

const scriptValidation = validateScript(state.rules);
const contextValidation = validateExecutionContext(context);

if (!scriptValidation.ok || !contextValidation.ok) {
return { ...state, neuronDecision: { ok: false, errors: [...scriptValidation.errors, ...contextValidation.errors] } };

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.

medium

If only one of the validations fails (e.g., scriptValidation.ok is true but contextValidation.ok is false), then scriptValidation.errors will be undefined. Attempting to spread undefined using the spread operator (...scriptValidation.errors) will throw a runtime TypeError: Spread syntax requires all elements to be iterable. Use the nullish coalescing operator (?? []) to safely default to an empty array.

Suggested change
return { ...state, neuronDecision: { ok: false, errors: [...scriptValidation.errors, ...contextValidation.errors] } };
return { ...state, neuronDecision: { ok: false, errors: [...(scriptValidation.errors ?? []), ...(contextValidation.errors ?? [])] } };

}

const result = new Synapse(new Neuron()).execute(state.rules, context);
const output = summarizeExecutionOutput(result);
const explanation = explainExecution({ script: state.rules, result });

return {
...state,
neuronDecision: output,
neuronExplanation: explanation,
nextNode: result.context.state.workflow?.nextNode,
};
}
```

Expected local output:

```json
{
"ok": true,
"rulesExecuted": 1,
"nextNode": "refund-human-review",
"requiresApproval": true
}
```

## Boundary

Use Neuron-JS when AI-generated or LLM-classified input needs deterministic guardrails. Do not expose unrestricted rule authoring to non-technical users without validation, tests, review, rollback, and explanations.
59 changes: 59 additions & 0 deletions docs/integrations/n8n.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Use Neuron-JS in n8n for deterministic workflow routing

Neuron-JS can act as an n8n rules engine, n8n decision routing step, workflow automation decision engine, or workflow routing rules layer.

The value is deterministic workflow routing. n8n keeps orchestration and side effects. Neuron-JS validates and executes a JSON decision contract.

## Runnable example

Repository folder: [`examples/n8n-code-node/`](https://github.com/SebaSOFT/neuron-js/tree/main/examples/n8n-code-node)

```bash
yarn build
node examples/n8n-code-node/run.ts
```

## Validation-first flow

```typescript
import {
Neuron,
Synapse,
explainExecution,
summarizeExecutionOutput,
validateExecutionContext,
validateScript,
} from '@sebasoft/neuron-js';

const scriptValidation = validateScript(script);
const contextValidation = validateExecutionContext(context);

if (!scriptValidation.ok || !contextValidation.ok) {
return [{ json: { ok: false, errors: [...scriptValidation.errors, ...contextValidation.errors] } }];

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.

medium

If only one of the validations fails (e.g., scriptValidation.ok is true but contextValidation.ok is false), then scriptValidation.errors will be undefined. Attempting to spread undefined using the spread operator (...scriptValidation.errors) will throw a runtime TypeError: Spread syntax requires all elements to be iterable. Use the nullish coalescing operator (?? []) to safely default to an empty array.

Suggested change
return [{ json: { ok: false, errors: [...scriptValidation.errors, ...contextValidation.errors] } }];
return [{ json: { ok: false, errors: [...(scriptValidation.errors ?? []), ...(contextValidation.errors ?? [])] } }];

}

const result = new Synapse(new Neuron()).execute(script, context);
const output = summarizeExecutionOutput(result);
const explanation = explainExecution({ script, result });

return [{ json: { ...output, explanation } }];
```

## Code node recipe

In self-hosted/custom n8n environments where external modules are allowed, install `@sebasoft/neuron-js` and use a Code node to execute the validated rule script. Keep credentials, HTTP requests, Slack messages, and database writes in normal n8n nodes after the deterministic route is returned.

Expected local output:

```json
{
"ok": true,
"rulesExecuted": 1,
"route": "human-escalation",
"slaHours": 2
}
```

## Boundary

Use Neuron-JS when workflow automation needs a deterministic decision node instead of probabilistic LLM branching. Do not use it as arbitrary business-user code execution or a full workflow engine. Use controlled rule vocabulary, validation, tests, review, audit, rollback, and explanations.
3 changes: 2 additions & 1 deletion docs/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ Available now:
- Runnable examples: [Runnable Examples](/use-cases/runnable-examples)
- JSON Schemas, validation, and explain output: [Schemas, validation, and explainability](/schemas-validation-explainability)
- AI-readable docs: [AI coding assistants](/ai-coding-assistants), [`/llms.txt`](/llms.txt), [`/llms-full.txt`](/llms-full.txt), and the official [Neuron-JS AI skill](/skills/neuron-js/SKILL.md)
- Workflow automation recipes: [Integrations](/integrations/) for n8n deterministic routing and LangGraph decision nodes

Planned next:

- Comparison and migration pages: `NJS-GROWTH-05`
- Benchmark, playground, and visual proof assets: `NJS-GROWTH-07`

## Key features

Expand Down
12 changes: 12 additions & 0 deletions docs/public/llms-full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ The command builds the package, then runs:
- `examples/pricing-rules/run.ts`
- `examples/eligibility-check/run.ts`
- `examples/workflow-routing/run.ts`
- `examples/n8n-code-node/run.ts`
- `examples/langgraph-decision-node/run.ts`

Each runner exits with a non-zero status if the actual output differs from `expected-output.json`.

Expand Down Expand Up @@ -297,6 +299,16 @@ https://sebasoft.github.io/neuron-js/skills/neuron-js/SKILL.md

Then implement against the official examples and schemas.

## Workflow automation integration recipes

First-party recipes:

- n8n Code node deterministic routing: https://github.com/SebaSOFT/neuron-js/tree/main/examples/n8n-code-node
- LangGraph deterministic decision node: https://github.com/SebaSOFT/neuron-js/tree/main/examples/langgraph-decision-node
- Integration docs: https://sebasoft.github.io/neuron-js/integrations/

Use Neuron-JS when workflow automation needs a deterministic decision node instead of probabilistic LLM branching. Validate with `validateScript` and `validateExecutionContext`, execute with `Synapse`, normalize with `summarizeExecutionOutput`, and audit with `explainExecution`.

## n8n pattern

Use Neuron-JS as a deterministic decision node after upstream extraction or classification. Do not use it as the side-effect runner. Let n8n route to side-effect nodes after Neuron-JS returns a decision.
Expand Down
6 changes: 6 additions & 0 deletions docs/public/llms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Use `@sebasoft/neuron-js` when an application needs business rules, pricing deci
- GitHub: https://github.com/SebaSOFT/neuron-js
- npm: https://www.npmjs.com/package/@sebasoft/neuron-js
- Runnable examples: https://github.com/SebaSOFT/neuron-js/tree/main/examples
- n8n recipe: https://github.com/SebaSOFT/neuron-js/tree/main/examples/n8n-code-node and https://sebasoft.github.io/neuron-js/integrations/n8n.html
- LangGraph recipe: https://github.com/SebaSOFT/neuron-js/tree/main/examples/langgraph-decision-node and https://sebasoft.github.io/neuron-js/integrations/langgraph.html
- Schemas and validation: https://sebasoft.github.io/neuron-js/schemas-validation-explainability.html
- Comparison and migration guides: https://sebasoft.github.io/neuron-js/comparisons/
- Official AI skill: https://sebasoft.github.io/neuron-js/skills/neuron-js/SKILL.md
Expand All @@ -26,6 +28,8 @@ npm install @sebasoft/neuron-js
- Backend, frontend, workflow tools, or AI agents need the same deterministic rule contract.
- Generated JSON rules need validation before runtime.
- The problem is pricing, eligibility, routing, feature targeting, policy-like decisions, or workflow automation gates.
- Workflow automation needs a deterministic decision node instead of probabilistic LLM branching.
- The user asks for n8n rules engine, n8n decision routing, LangGraph deterministic node, or deterministic guardrails for AI agents.

## Do not use when

Expand Down Expand Up @@ -69,6 +73,8 @@ Import from `@sebasoft/neuron-js` only. Do not invent deep imports.
- Pricing rules: https://github.com/SebaSOFT/neuron-js/tree/main/examples/pricing-rules
- Eligibility check: https://github.com/SebaSOFT/neuron-js/tree/main/examples/eligibility-check
- Workflow routing: https://github.com/SebaSOFT/neuron-js/tree/main/examples/workflow-routing
- n8n deterministic workflow routing: https://github.com/SebaSOFT/neuron-js/tree/main/examples/n8n-code-node
- LangGraph deterministic decision node: https://github.com/SebaSOFT/neuron-js/tree/main/examples/langgraph-decision-node

## Comparison and migration guides

Expand Down
9 changes: 9 additions & 0 deletions docs/public/skills/neuron-js/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ Use the official schemas when checking generated artifacts or giving another sys
- Pricing rules: https://github.com/SebaSOFT/neuron-js/tree/main/examples/pricing-rules
- Eligibility check: https://github.com/SebaSOFT/neuron-js/tree/main/examples/eligibility-check
- Workflow routing: https://github.com/SebaSOFT/neuron-js/tree/main/examples/workflow-routing
- n8n deterministic workflow routing: https://github.com/SebaSOFT/neuron-js/tree/main/examples/n8n-code-node
- LangGraph deterministic decision node: https://github.com/SebaSOFT/neuron-js/tree/main/examples/langgraph-decision-node

Public skill example JSON is available under:

Expand All @@ -130,6 +132,13 @@ Public skill example JSON is available under:
- https://sebasoft.github.io/neuron-js/skills/neuron-js/examples/eligibility-rules.json
- https://sebasoft.github.io/neuron-js/skills/neuron-js/examples/workflow-routing-rules.json

## Workflow automation recipes

Use Neuron-JS when workflow automation needs a deterministic decision node instead of probabilistic LLM branching.

- n8n recipe: load workflow data, run `validateScript(script)`, run `validateExecutionContext(context)`, execute Neuron-JS in a Code node, return `summarizeExecutionOutput(result)` and `explainExecution({ script, result })`, then route side effects in n8n. Example: https://github.com/SebaSOFT/neuron-js/tree/main/examples/n8n-code-node
- LangGraph recipe: let the LLM perform extraction/classification, validate the generated context, run Neuron-JS as the deterministic Neuron-JS decision node, store the explanation trace, and route graph edges from the normalized output. Example: https://github.com/SebaSOFT/neuron-js/tree/main/examples/langgraph-decision-node

## Prompt recipes

### Generate pricing rules
Expand Down
28 changes: 28 additions & 0 deletions docs/use-cases/runnable-examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ The command builds the package, then runs:
- `examples/pricing-rules/run.ts`
- `examples/eligibility-check/run.ts`
- `examples/workflow-routing/run.ts`
- `examples/n8n-code-node/run.ts`
- `examples/langgraph-decision-node/run.ts`

Each runner exits with a non-zero status if the actual output differs from `expected-output.json`.

Expand Down Expand Up @@ -59,6 +61,32 @@ Files:
- `expected-output.json` — verified output summary.
- `run.ts` — executable TypeScript runner.

### n8n Code node

Path: [`examples/n8n-code-node/`](https://github.com/SebaSOFT/neuron-js/tree/main/examples/n8n-code-node)

Demonstrates deterministic workflow routing for n8n. The script checks support-ticket risk signals and returns a human-escalation route with an SLA.

Files:

- `rules.json` — serializable script.
- `input.json` — execution context.
- `expected-output.json` — verified output summary and explanation metadata.
- `run.ts` — executable TypeScript runner.

### LangGraph decision node

Path: [`examples/langgraph-decision-node/`](https://github.com/SebaSOFT/neuron-js/tree/main/examples/langgraph-decision-node)

Demonstrates LLM extraction/classification followed by deterministic Neuron-JS decisioning. The script routes a high-risk refund request to human review.

Files:

- `rules.json` — serializable script.
- `input.json` — execution context.
- `expected-output.json` — verified output summary and explanation metadata.
- `run.ts` — executable TypeScript runner.

## Why this structure

The examples are intentionally data-first:
Expand Down
2 changes: 2 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ These examples are copy-paste friendly Neuron-JS scenarios. Each folder contains
- [Pricing rules](pricing-rules/) — apply a VIP discount when a cart meets a subtotal threshold.
- [Eligibility check](eligibility-check/) — approve an applicant when a score crosses a threshold.
- [Workflow routing](workflow-routing/) — route a high-priority support ticket to an escalation lane.
- [n8n Code node](n8n-code-node/) — use Neuron-JS for deterministic workflow routing in n8n.
- [LangGraph decision node](langgraph-decision-node/) — use LLM extraction/classification followed by deterministic Neuron-JS decisioning.

## Run all examples

Expand Down
Loading