-
Notifications
You must be signed in to change notification settings - Fork 21
Code Generation Tool #718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bobur-khay
wants to merge
36
commits into
eclipse-thingweb:master
Choose a base branch
from
bobur-khay:feature/code-gen
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Code Generation Tool #718
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
ad0b00b
init
bobur-khay 13b49a3
mvp for generate prompt
bobur-khay cae8f98
mvp for algorithmic approach
bobur-khay 23a7fb9
overall mvp
bobur-khay 328b575
new generators
bobur-khay b5f4032
dynamic client
bobur-khay d9a043b
refactoring
bobur-khay b173ead
initial generators
bobur-khay 97f71a2
cleanup
bobur-khay 46efae9
mvp
bobur-khay b485feb
tests
bobur-khay 7eb08e4
copy button
bobur-khay fcb11a7
vitest version change
bobur-khay 0a1efdd
visual test fix
bobur-khay 45edd86
change the dependency to file location
bobur-khay 8535c55
fix test
bobur-khay 717f98d
Readme file
bobur-khay 0b9ec1a
license update
bobur-khay 6fcf10a
test
bobur-khay c28346e
revert test
bobur-khay a491070
updated package-lock
bobur-khay 5d476e5
add typescript to dependencies
bobur-khay f769971
update lock file
bobur-khay 2aa1cfc
package lock update
bobur-khay 2b1134d
fix hidden input bars for build
bobur-khay 4387afa
post-rebase
bobur-khay fe114b4
fix netlify tests
bobur-khay 44e4a37
rebase
bobur-khay 848b774
fix rebase lost change
bobur-khay c2fb82b
tsx dependency
bobur-khay 07956a7
interactive path input
bobur-khay b832734
readme update
bobur-khay 6fae049
fix modbus
bobur-khay f8f79fe
refactoring
bobur-khay 3996fe6
update package-lock
bobur-khay 8435829
update package-lock
bobur-khay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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). |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.