tjs-lang 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTEXT.md +594 -0
- package/LICENSE +190 -0
- package/README.md +220 -0
- package/bin/benchmarks.ts +351 -0
- package/bin/dev.ts +205 -0
- package/bin/docs.js +170 -0
- package/bin/install-cursor.sh +71 -0
- package/bin/install-vscode.sh +71 -0
- package/bin/select-local-models.d.ts +1 -0
- package/bin/select-local-models.js +28 -0
- package/bin/select-local-models.ts +31 -0
- package/demo/autocomplete.test.ts +232 -0
- package/demo/docs.json +186 -0
- package/demo/examples.test.ts +598 -0
- package/demo/index.html +91 -0
- package/demo/src/autocomplete.ts +482 -0
- package/demo/src/capabilities.ts +859 -0
- package/demo/src/demo-nav.ts +2097 -0
- package/demo/src/examples.test.ts +161 -0
- package/demo/src/examples.ts +476 -0
- package/demo/src/imports.test.ts +196 -0
- package/demo/src/imports.ts +421 -0
- package/demo/src/index.ts +639 -0
- package/demo/src/module-store.ts +635 -0
- package/demo/src/module-sw.ts +132 -0
- package/demo/src/playground.ts +949 -0
- package/demo/src/service-host.ts +389 -0
- package/demo/src/settings.ts +440 -0
- package/demo/src/style.ts +280 -0
- package/demo/src/tjs-playground.ts +1605 -0
- package/demo/src/ts-examples.ts +478 -0
- package/demo/src/ts-playground.ts +1092 -0
- package/demo/static/favicon.svg +30 -0
- package/demo/static/photo-1.jpg +0 -0
- package/demo/static/photo-2.jpg +0 -0
- package/demo/static/texts/ai-history.txt +9 -0
- package/demo/static/texts/coffee-origins.txt +9 -0
- package/demo/static/texts/renewable-energy.txt +9 -0
- package/dist/index.js +256 -0
- package/dist/index.js.map +37 -0
- package/dist/tjs-batteries.js +4 -0
- package/dist/tjs-batteries.js.map +15 -0
- package/dist/tjs-full.js +256 -0
- package/dist/tjs-full.js.map +37 -0
- package/dist/tjs-transpiler.js +220 -0
- package/dist/tjs-transpiler.js.map +21 -0
- package/dist/tjs-vm.js +4 -0
- package/dist/tjs-vm.js.map +14 -0
- package/docs/CNAME +1 -0
- package/docs/favicon.svg +30 -0
- package/docs/index.html +91 -0
- package/docs/index.js +10468 -0
- package/docs/index.js.map +92 -0
- package/docs/photo-1.jpg +0 -0
- package/docs/photo-1.webp +0 -0
- package/docs/photo-2.jpg +0 -0
- package/docs/photo-2.webp +0 -0
- package/docs/texts/ai-history.txt +9 -0
- package/docs/texts/coffee-origins.txt +9 -0
- package/docs/texts/renewable-energy.txt +9 -0
- package/docs/tjs-lang.svg +31 -0
- package/docs/tosijs-agent.svg +31 -0
- package/editors/README.md +325 -0
- package/editors/ace/ajs-mode.js +328 -0
- package/editors/ace/ajs-mode.ts +269 -0
- package/editors/ajs-syntax.ts +212 -0
- package/editors/build-grammars.ts +510 -0
- package/editors/codemirror/ajs-language.js +287 -0
- package/editors/codemirror/ajs-language.ts +1447 -0
- package/editors/codemirror/autocomplete.test.ts +531 -0
- package/editors/codemirror/component.ts +404 -0
- package/editors/monaco/ajs-monarch.js +243 -0
- package/editors/monaco/ajs-monarch.ts +225 -0
- package/editors/tjs-syntax.ts +115 -0
- package/editors/vscode/language-configuration.json +37 -0
- package/editors/vscode/package.json +65 -0
- package/editors/vscode/syntaxes/ajs-injection.tmLanguage.json +107 -0
- package/editors/vscode/syntaxes/ajs.tmLanguage.json +252 -0
- package/editors/vscode/syntaxes/tjs.tmLanguage.json +333 -0
- package/package.json +83 -0
- package/src/cli/commands/check.ts +41 -0
- package/src/cli/commands/convert.ts +133 -0
- package/src/cli/commands/emit.ts +260 -0
- package/src/cli/commands/run.ts +68 -0
- package/src/cli/commands/test.ts +194 -0
- package/src/cli/commands/types.ts +20 -0
- package/src/cli/create-app.ts +236 -0
- package/src/cli/playground.ts +250 -0
- package/src/cli/tjs.ts +166 -0
- package/src/cli/tjsx.ts +160 -0
- package/tjs-lang.svg +31 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2025-2026 Tonio Loewald
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
<!--{"section": "home", "order": 0, "navTitle": "Home"}-->
|
|
2
|
+
|
|
3
|
+
# TJS Platform
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
[playground](https://tjs-platform.web.app) | [github](https://github.com/tonioloewald/tjs-lang#readme) | [npm](https://www.npmjs.com/package/tjs-lang) | [discord](https://discord.gg/ramJ9rgky5)
|
|
8
|
+
|
|
9
|
+
## The Problem
|
|
10
|
+
|
|
11
|
+
**TypeScript is fragile.** It pretends to be a superset of JavaScript, but it isn't. It pretends to be typesafe, but it isn't. Its Turing-complete type system is harder to reason about than the code it supposedly documents—and then it all disappears at runtime.
|
|
12
|
+
|
|
13
|
+
> TypeScript is also difficult to transpile. Your browser can run full virtual machines in JavaScript, but most TypeScript playgrounds either fake it by stripping type declarations or use a server backend to do the real work.
|
|
14
|
+
|
|
15
|
+
**JavaScript is dangerous.** `eval()` and `Function()` are so powerful they're forbidden almost everywhere—blocked by CSP in most production environments. The industry's answer? The **Container Fallacy**: wrap every function in a 200MB Linux container just to run it safely. We ship buildings to deliver letters.
|
|
16
|
+
|
|
17
|
+
**Security is a mess.** Every layer validates. Gateway validates. Auth validates. Business logic validates. Database validates. We spend 90% of our time building pipelines to move data to code, re-checking it at every hop.
|
|
18
|
+
|
|
19
|
+
## What If?
|
|
20
|
+
|
|
21
|
+
What if your language were:
|
|
22
|
+
|
|
23
|
+
- **Honest** — types that actually exist at runtime, not fiction that evaporates
|
|
24
|
+
- **Safe** — a gas-metered VM where infinite loops are impossible, no container required
|
|
25
|
+
- **Mobile** — logic that travels to data, not oceans of data dragged to logic
|
|
26
|
+
- **Unified** — one source of truth, not TypeScript interfaces _plus_ Zod schemas _plus_ JSDoc
|
|
27
|
+
|
|
28
|
+
That's what TJS Platform provides: **TJS** for writing your infrastructure, and **AJS** for shipping logic that runs anywhere.
|
|
29
|
+
|
|
30
|
+
## TJS — Types That Survive
|
|
31
|
+
|
|
32
|
+
Write typed JavaScript where the type _is_ an example. No split-brain validation.
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
// TJS: The type is an example AND a test
|
|
36
|
+
function greet(name: 'World') -> 'Hello, World!' {
|
|
37
|
+
return `Hello, ${name}!`
|
|
38
|
+
}
|
|
39
|
+
// At transpile time: greet('World') is called and checked against 'Hello, World!'
|
|
40
|
+
|
|
41
|
+
// Runtime: The type becomes a contract
|
|
42
|
+
console.log(greet.__tjs.params) // { name: { type: 'string', example: 'World', required: true } }
|
|
43
|
+
|
|
44
|
+
// Safety: Errors are values, not crashes
|
|
45
|
+
const result = greet(123) // { $error: true, message: 'type mismatch' }
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**Why it matters:**
|
|
49
|
+
|
|
50
|
+
- **One source of truth** — no more TS interfaces + Zod schemas + JSDoc comments
|
|
51
|
+
- **Types as examples** — `name: 'Alice'` means "required string, like 'Alice'"
|
|
52
|
+
- **Runtime metadata** — `__tjs` enables reflection, autocomplete, documentation from live objects
|
|
53
|
+
- **Monadic errors** — type failures return values, never throw
|
|
54
|
+
- **Zero build step** — transpiles in the browser, no webpack/Vite/Babel
|
|
55
|
+
- **The compiler _is_ the client** — TJS transpiles itself _and_ TypeScript entirely client-side
|
|
56
|
+
|
|
57
|
+
## AJS — Code That Travels
|
|
58
|
+
|
|
59
|
+
Write logic that compiles to JSON and runs in a gas-limited sandbox. Send agents to data instead of shipping data to code.
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
const agent = ajs`
|
|
63
|
+
function research(topic: 'AI') {
|
|
64
|
+
let data = httpFetch({ url: '/search?q=' + topic })
|
|
65
|
+
let summary = llmPredict({ prompt: 'Summarize: ' + data })
|
|
66
|
+
return { topic, summary }
|
|
67
|
+
}
|
|
68
|
+
`
|
|
69
|
+
|
|
70
|
+
// Run it safely—no Docker required
|
|
71
|
+
const result = await vm.run(
|
|
72
|
+
agent,
|
|
73
|
+
{ topic: 'Agents' },
|
|
74
|
+
{
|
|
75
|
+
fuel: 500, // Strict CPU budget
|
|
76
|
+
capabilities: { fetch: http }, // Allow ONLY http, block everything else
|
|
77
|
+
}
|
|
78
|
+
)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
**Why it matters:**
|
|
82
|
+
|
|
83
|
+
- **Safe eval** — run untrusted code without containers
|
|
84
|
+
- **Code is JSON** — store in databases, diff, version, transmit
|
|
85
|
+
- **Fuel metering** — every operation costs gas, infinite loops impossible
|
|
86
|
+
- **Capability-based** — zero I/O by default, grant only what's needed
|
|
87
|
+
- **LLM-native** — simple enough for small models to generate correctly
|
|
88
|
+
|
|
89
|
+
## The Architecture Shift
|
|
90
|
+
|
|
91
|
+
**Old way (data-to-code):**
|
|
92
|
+
Client requests data → Server fetches 100 rows → Server filters to 5 → Client receives 5.
|
|
93
|
+
_High latency. High bandwidth. Validate at every layer._
|
|
94
|
+
|
|
95
|
+
**TJS way (code-to-data):**
|
|
96
|
+
Client sends agent → Edge runs agent at data → Edge returns 5 rows.
|
|
97
|
+
_Low latency. Zero waste. Validate once._
|
|
98
|
+
|
|
99
|
+
The agent carries its own validation. The server grants capabilities. Caching happens automatically because the query _is_ the code.
|
|
100
|
+
|
|
101
|
+
## Safe Eval
|
|
102
|
+
|
|
103
|
+
The holy grail: `eval()` that's actually safe.
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
import { Eval } from 'tjs-lang/eval'
|
|
107
|
+
|
|
108
|
+
// Whitelist-wrapped fetch - untrusted code only reaches your domains
|
|
109
|
+
const safeFetch = (url: string) => {
|
|
110
|
+
const allowed = ['api.example.com', 'cdn.example.com']
|
|
111
|
+
const host = new URL(url).host
|
|
112
|
+
if (!allowed.includes(host)) {
|
|
113
|
+
return { error: 'Domain not allowed' }
|
|
114
|
+
}
|
|
115
|
+
return fetch(url)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const { result, fuelUsed } = await Eval({
|
|
119
|
+
code: `
|
|
120
|
+
let data = fetch('https://api.example.com/products')
|
|
121
|
+
return data.filter(x => x.price < budget)
|
|
122
|
+
`,
|
|
123
|
+
context: { budget: 100 },
|
|
124
|
+
fuel: 1000,
|
|
125
|
+
capabilities: { fetch: safeFetch }, // Only whitelisted domains
|
|
126
|
+
})
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
The untrusted code thinks it has `fetch`, but it only has _your_ `fetch`. No CSP violations. No infinite loops. No access to anything you didn't explicitly grant.
|
|
130
|
+
|
|
131
|
+
## Quick Start
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
npm install tjs-lang
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Run an Agent
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
import { ajs, AgentVM } from 'tjs-lang'
|
|
141
|
+
|
|
142
|
+
const agent = ajs`
|
|
143
|
+
function double(value: 21) {
|
|
144
|
+
return { result: value * 2 }
|
|
145
|
+
}
|
|
146
|
+
`
|
|
147
|
+
|
|
148
|
+
const vm = new AgentVM()
|
|
149
|
+
const { result } = await vm.run(agent, { value: 21 })
|
|
150
|
+
console.log(result) // { result: 42 }
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Write Typed Code
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import { tjs } from 'tjs-lang'
|
|
157
|
+
|
|
158
|
+
const { code, metadata } = tjs`
|
|
159
|
+
function add(a: 0, b: 0) -> 0 {
|
|
160
|
+
return a + b
|
|
161
|
+
}
|
|
162
|
+
`
|
|
163
|
+
// code: JavaScript with __tjs metadata attached
|
|
164
|
+
// metadata: { add: { params: { a: { type: 'number', example: 0 }, b: { type: 'number', example: 0 } }, returns: { type: 'number' } } }
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Try the Playground
|
|
168
|
+
|
|
169
|
+
Since TJS compiles itself, the playground is the full engine running entirely in your browser.
|
|
170
|
+
|
|
171
|
+
**[tjs-platform.web.app](https://tjs-platform.web.app)**
|
|
172
|
+
|
|
173
|
+
## At a Glance
|
|
174
|
+
|
|
175
|
+
| | TJS | AJS |
|
|
176
|
+
| --------------- | -------------------------------- | ----------------- |
|
|
177
|
+
| **Purpose** | Write your platform | Write your agents |
|
|
178
|
+
| **Trust level** | Your code | Anyone's code |
|
|
179
|
+
| **Compiles to** | JavaScript + metadata | JSON AST |
|
|
180
|
+
| **Runs in** | Browser, Node, Bun | Sandboxed VM |
|
|
181
|
+
| **Types** | Examples → runtime validation | Schemas for I/O |
|
|
182
|
+
| **Errors** | Monadic (values, not exceptions) | Monadic |
|
|
183
|
+
| **Build step** | None | None |
|
|
184
|
+
|
|
185
|
+
## Bundle Size
|
|
186
|
+
|
|
187
|
+
The cost of "safe eval"—compare to a 200MB Docker image:
|
|
188
|
+
|
|
189
|
+
| Bundle | Size | Gzipped |
|
|
190
|
+
| ------------------------- | ------ | --------- |
|
|
191
|
+
| VM only | 42 KB | **14 KB** |
|
|
192
|
+
| + Batteries (LLM, vector) | 56 KB | 19 KB |
|
|
193
|
+
| + Transpiler | 89 KB | 27 KB |
|
|
194
|
+
| Full (with TS support) | 180 KB | 56 KB |
|
|
195
|
+
|
|
196
|
+
**Dependencies:** `acorn` (JS parser), `tosijs-schema` (validation). Both have zero transitive dependencies.
|
|
197
|
+
|
|
198
|
+
## Documentation
|
|
199
|
+
|
|
200
|
+
- **[TJS Language Guide](DOCS-TJS.md)** — Types, syntax, runtime
|
|
201
|
+
- **[AJS Runtime Guide](DOCS-AJS.md)** — VM, atoms, capabilities
|
|
202
|
+
- **[Architecture Deep Dive](CONTEXT.md)** — How it all fits together
|
|
203
|
+
- **[Playground](https://tjs-platform.web.app)** — Try it now
|
|
204
|
+
|
|
205
|
+
## Installation
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
# npm
|
|
209
|
+
npm install tjs-lang
|
|
210
|
+
|
|
211
|
+
# bun
|
|
212
|
+
bun add tjs-lang
|
|
213
|
+
|
|
214
|
+
# pnpm
|
|
215
|
+
pnpm add tjs-lang
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## License
|
|
219
|
+
|
|
220
|
+
Apache 2.0
|