Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ad0b00b
init
bobur-khay Apr 8, 2026
13b49a3
mvp for generate prompt
bobur-khay Apr 9, 2026
cae8f98
mvp for algorithmic approach
bobur-khay Apr 9, 2026
23a7fb9
overall mvp
bobur-khay Apr 9, 2026
328b575
new generators
bobur-khay Apr 9, 2026
b5f4032
dynamic client
bobur-khay Apr 9, 2026
d9a043b
refactoring
bobur-khay May 20, 2026
b173ead
initial generators
bobur-khay May 20, 2026
97f71a2
cleanup
bobur-khay May 20, 2026
46efae9
mvp
bobur-khay May 24, 2026
b485feb
tests
bobur-khay May 25, 2026
7eb08e4
copy button
bobur-khay May 25, 2026
fcb11a7
vitest version change
bobur-khay May 25, 2026
0a1efdd
visual test fix
bobur-khay May 25, 2026
45edd86
change the dependency to file location
bobur-khay May 25, 2026
8535c55
fix test
bobur-khay May 25, 2026
717f98d
Readme file
bobur-khay May 26, 2026
0b9ec1a
license update
bobur-khay May 26, 2026
6fcf10a
test
bobur-khay May 27, 2026
c28346e
revert test
bobur-khay May 27, 2026
a491070
updated package-lock
bobur-khay May 27, 2026
5d476e5
add typescript to dependencies
bobur-khay May 27, 2026
f769971
update lock file
bobur-khay May 27, 2026
2aa1cfc
package lock update
bobur-khay May 27, 2026
2b1134d
fix hidden input bars for build
bobur-khay May 27, 2026
4387afa
post-rebase
bobur-khay May 27, 2026
fe114b4
fix netlify tests
bobur-khay May 27, 2026
44e4a37
rebase
bobur-khay Jun 3, 2026
848b774
fix rebase lost change
bobur-khay Jun 3, 2026
c2fb82b
tsx dependency
bobur-khay Jun 3, 2026
07956a7
interactive path input
bobur-khay Jun 3, 2026
b832734
readme update
bobur-khay Jun 3, 2026
6fae049
fix modbus
bobur-khay Jun 17, 2026
f8f79fe
refactoring
bobur-khay Jun 17, 2026
3996fe6
update package-lock
bobur-khay Jun 18, 2026
8435829
update package-lock
bobur-khay Jun 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
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"jest": true
},
"parserOptions": {
"ecmaVersion": 2018,
"ecmaVersion": 2020,
"sourceType": "module"
},
"globals": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
"lint:fix": "npx eslint . --config .eslintrc.json --fix",
"format": "prettier --write . && npm run format --silent --workspaces --if-present",
"format:quick": "pretty-quick",
"test": "npm test -w packages/core -w packages/assertions -w packages/defaults -w packages/cli"
"test": "npm test -w packages/core -w packages/assertions -w packages/defaults -w packages/cli -w packages/code-gen"
}
}
78 changes: 78 additions & 0 deletions packages/code-gen/README.md
Comment thread
bobur-khay marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# @thingweb/code-gen

Generates code snippets for interacting with [Thing Descriptions (TD)](https://www.w3.org/TR/wot-thing-description11/). Supports multiple programming languages and libraries. For unsupported language/library combinations, it generates a prompt for an LLM to complete the task.

## Usage

### As a Library

```js
import { generateCode, isProtocolSupported } from "@thingweb/code-gen";

const result = generateCode({
td,
affordanceType: "properties",
affordanceKey: "temperature",
operation: "readproperty",
language: "javascript",
library: "fetch",
});

if ("code" in result) {
console.log(result.code);
} else {
console.log(result.prompt); // LLM prompt for unsupported combinations
}
```

### CLI

The package provides both interactive and non-interactive CLI modes.

**Interactive mode** — run without arguments to be guided through prompts:

```bash
npm run cli
```

**Non-interactive mode** — pass all options as flags. When running the CLI through the npm script, parameters are added after `--`:

```bash
npm run cli -- --td ./my-thing.td.jsonld --affordance-type properties --affordance-key temperature --operation readproperty --language javascript --library fetch --output ./output
```

#### CLI Options

| Flag | Description |
| ----------------------- | ---------------------------------------------------------- |
| `-t, --td` | Path to the TD JSON file (relative or absolute) |
| `-a, --affordance-type` | Affordance type: `properties`, `actions`, or `events` |
| `-k, --affordance-key` | Key name of the affordance |
| `-o, --operation` | Operation to perform (e.g. `readproperty`, `invokeaction`) |
| `-l, --language` | Programming language |
| `-b, --library` | Library to use |
| `-O, --output` | Output folder path (relative or absolute, default: `./`) |

## Supported Languages and Libraries

| Language | Libraries |
| ---------- | --------------------------------------------- |
| JavaScript | fetch, node-wot, webthing, modbus-serial |
| Python | requests, wotpy, PyModbus |
| Java | httpclient, wot-servient, digitalpetri/modbus |
| Rust | reqwest |
| Go | net-http |
| C# | httpclient, WoT.Net |
| PHP | curl |
| Ruby | net-http |
| Dart | dart-wot, http |

## Scripts

- `npm run build` — Compile TypeScript to `dist/`
- `npm run cli` — Run the CLI
- `npm test` — Run tests

## License

Licensed under the MIT license, see [License](../../LICENSE.md).
Loading
Loading