Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2d39290
feat: support custom OpenAI-compatible API endpoints (Ollama, LM Stud…
Eistee82 Mar 17, 2026
352035f
fix: add error handling for unreachable API providers and model fetch…
Eistee82 Mar 17, 2026
cfa416b
feat: add Test API connection button, changelog and documentation
Eistee82 Mar 17, 2026
87ec6c8
refactor: remove Custom model name field, models are fetched dynamically
Eistee82 Mar 17, 2026
1fa5036
fix: remove invalid icon from test API connection button
Eistee82 Mar 17, 2026
273726d
build: recompile backend to include testApiConnection handler
Eistee82 Mar 17, 2026
fe3f9b8
refactor: move all API calls server-side via sendTo to avoid CORS issues
Eistee82 Mar 17, 2026
be54e0f
fix: build frontend, fix TypeScript error type and disabled prop
Eistee82 Mar 17, 2026
b0abf90
fix: restore admin/tab.html and admin/custom/ removed by build
Eistee82 Mar 17, 2026
4a6697c
fix: rebuild frontend correctly with manual copy and tab.html generation
Eistee82 Mar 17, 2026
96ec8f6
fix: add Content-Length header and increase timeout to 600s for chat …
Eistee82 Mar 17, 2026
1b9fb9c
fix: strip LLM thinking artifacts from code generator responses
Eistee82 Mar 17, 2026
bb08a98
docs: add recommended providers (Gemini free, DeepSeek) and note abou…
Eistee82 Mar 17, 2026
b71fb25
fix: strip 'models/' prefix from Google Gemini model IDs
Eistee82 Mar 17, 2026
38e98b9
chore: cleanup orphaned build assets and update changelog
Eistee82 Mar 17, 2026
dc81bce
fix: allow empty API key for local providers like Ollama
Eistee82 Mar 17, 2026
eb83f7d
style: fix prettier formatting for sendTo calls
Eistee82 Mar 18, 2026
607a2a5
Removed useless models
GermanBluefox Mar 19, 2026
ab2f522
Removed useless models
GermanBluefox Mar 19, 2026
db116a8
Updated packages
GermanBluefox Mar 19, 2026
c58e059
Fixed some minor possible errors
GermanBluefox Mar 19, 2026
f8aa540
Fix linter
GermanBluefox Mar 19, 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ iob_npm.dode

#ignore .commitinfo created by ioBroker release script
.commitinfo
/.claude/settings.local.json
93 changes: 93 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

ioBroker.javascript is a JavaScript/TypeScript/Blockly script engine adapter for the ioBroker home automation platform. It runs as a daemon adapter that executes user-written scripts in a sandboxed environment, with a web-based editor UI (Monaco + Blockly) and an admin configuration panel.

## Build Commands

```bash
# Full build (backend TypeScript + both frontends)
npm run build

# Backend only (TypeScript → build/)
npm run build-backend

# Editor UI only (src-editor → admin/)
npm run build-editor

# Admin config UI only (src-admin → admin/custom/)
npm run admin-build

# Install all dependencies (root + src-editor + src-admin)
npm run npm
```

## Testing

```bash
# All tests (declaration checks + integration)
npm test

# Individual test suites
npm run test:declarations # TypeScript declaration compilation checks
npm run test:integration # Mocha integration tests (test/testFunctions.js etc.)
npm run test:scheduler # Scheduler/cron tests only
npm run test:package # Package structure validation

# Run a single test file directly
npx mocha test/testScheduler.js --exit
```

Test framework is Mocha, configured via `.mocharc.json`. Tests are in `test/`.

## Linting

```bash
npm run lint # Lint backend (root) only
npm run lint-all # Lint root + src-editor + src-admin
```

ESLint uses `@iobroker/eslint-config` (flat config in `eslint.config.mjs`). Prettier config extends `@iobroker/eslint-config/prettier.config.mjs`. The root ESLint config only covers `src/` — frontend directories have their own configs.

## Architecture

### Three codebases in one repo

1. **Backend adapter** (`src/` → compiled to `build/`): Node.js TypeScript, compiled to CommonJS. Entry point is `src/main.ts`. Runs as an ioBroker adapter daemon.

2. **Script editor UI** (`src-editor/`): React + TypeScript app built with Vite. Contains the Monaco code editor, Blockly visual editor, script management sidebar, log viewer, and OpenAI integration. Built output is copied to `admin/` by `tasks.js`.

3. **Admin config UI** (`src-admin/`): React + TypeScript app built with Vite. Provides adapter configuration via `@iobroker/json-config`. Built output goes to `admin/custom/`.

Each frontend has its own `package.json`, `node_modules`, and ESLint config. The build orchestration in `tasks.js` handles cleanup, npm installs, compilation, and copying built assets to `admin/`.

### Key backend modules (`src/lib/`)

- **`sandbox.ts`** (~244KB) — The script execution sandbox. Provides all global functions available to user scripts (`getState`, `setState`, `on`, `schedule`, `createState`, `httpGet`, etc.). This is the core of the adapter.
- **`scheduler.ts`** — Cron and astro-based scheduling engine (sunrise/sunset events via suncalc2).
- **`protectFs.ts`** — Filesystem access control for sandboxed scripts.
- **`debugger.ts`** — Script debugging support.
- **`mirror.ts`** — Mirrors scripts to/from the filesystem.
- **`javascript.d.ts`** (~140KB) — Complete TypeScript type definitions for the script API, used for editor autocompletion.
- **`typescriptTools.ts`** — TypeScript compilation for user scripts (via `virtual-tsc`).

### Build orchestration (`tasks.js`)

Custom Node.js build script using `@iobroker/build-tools`. Supports granular steps via CLI flags (`--0-clean`, `--1-npm`, `--2-build`, `--3-copy`, `--4-patch`). The `npm run build` command runs backend compilation first, then `node tasks` for the full frontend build pipeline.

### Adapter configuration

`io-package.json` defines adapter metadata, native configuration defaults, instance objects (astro variables, debug states), and ioBroker dependency requirements (js-controller >=5.0.19, admin >=7.6.1).

## TypeScript Configuration

- Backend targets ES2022, compiled to CommonJS (`tsconfig.build.json`)
- `@types/node` major version should match the lowest supported Node.js version
- Frontend apps target Chrome 89+ (Vite build config)

## CI/CD

GitHub Actions (`.github/workflows/test-and-release.yml`) runs lint, build, and adapter tests across Node 18/20/22/24 on Ubuntu, Windows, and macOS. Releases are automated via `@alcalzone/release-script` with NPM publish and GitHub release creation.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ Executes Javascript, Typescript Scripts.
## Changelog
<!--
### **WORK IN PROGRESS**
* Added support for custom OpenAI-compatible API endpoints (e.g. Ollama, LM Studio, Google Gemini, DeepSeek, OpenRouter)
* Added configurable base URL in adapter settings
* Models are now fetched dynamically from the configured API endpoint
* Added "Test API connection" button in adapter settings
* Added error handling with user-friendly messages for unreachable providers
* Added retry functionality for failed model loading
* All API calls (models + chat) are proxied server-side to avoid CORS issues with local providers
* Strip LLM thinking artifacts from responses (for local models like Ollama)
-->
### 9.0.18 (2026-01-11)
* (@GermanBluefox) Corrected an error message with `lastSync`
Expand All @@ -40,7 +48,7 @@ Executes Javascript, Typescript Scripts.
### 9.0.10 (2025-07-27)
* (@klein0r) Added Blockly block to format a numeric value
* (@GermanBluefox) Fixing some blocks in blockly: cron, time
* (@GermanBluefox) Added new block: "unconditional return"
* (@GermanBluefox) Added a new block: "unconditional return"
* (@GermanBluefox) Type definitions for TypeScript were updated
* (@GermanBluefox) Corrected bug with deleting of sub-folders

Expand Down
Loading
Loading