model-language 1.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1dc26fa88cd94d1c61b5b429a74f9b0d1a332df64d697123a5d14e19679e5137
4
+ data.tar.gz: 74a447f30b8c1bab233f0310bb78b818ae5f8aef01a0e3fdfa544ef61305a355
5
+ SHA512:
6
+ metadata.gz: 72a40897bf888f1b047704b641b2bc66da99b82be7d1593885576928a028a9efb3f20d0c5bc26f770f662b8394b405d678ba3c167bd149133d03970bc36fdabb
7
+ data.tar.gz: d50a8b7e0f68758cacd07856029618532bc95a33263cfd950e6666089b7a106a7bf387ccf63f67255483048b9588d051838f14580e277384dcd6934464d93f1c
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # model-language (Ruby)
2
+
3
+ Ruby bindings for [model-language](https://github.com/wexiohub/model-language) —
4
+ a typed, safe template language for AI-agent prompts. Runs the exact same engine
5
+ as the JavaScript/TypeScript package via an **embedded** WebAssembly module:
6
+ byte-for-byte identical output, guaranteed by a shared conformance suite.
7
+
8
+ ```ruby
9
+ require "model_language"
10
+
11
+ engine = ModelLanguage::Engine.new
12
+ out = engine.render(
13
+ "Hi {{ user.name | default: 'there' }}!",
14
+ data: { "user" => { "name" => "Vasyl" } }
15
+ )
16
+ puts out["text"] # => "Hi Vasyl!"
17
+ ```
18
+
19
+ - `render(template, data:, schema:, options:)` → `{"text", "warnings", "resolvedBranches", "directives", "tokenEstimate"}`
20
+ - `validate(template, schema:, options:)` → `{"diagnostics", "maxTokenEstimate"}`
21
+ - `parse(template)` → `{"ast", "diagnostics"}`
22
+
23
+ Never raises for template problems — they degrade to empty output plus a warning.
24
+ Pass `options: { "now" => epoch_ms }` for datetime filters.
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Ruby host for the model-language WebAssembly module. Runs the exact same engine
4
+ # as the TypeScript package: one JSON request in on the module's stdin, one JSON
5
+ # response out on its stdout. Same input, same output.
6
+
7
+ require "wasmtime"
8
+ require "json"
9
+ require "tempfile"
10
+
11
+ module ModelLanguage
12
+ class Engine
13
+ def initialize(wasm_path = nil)
14
+ wasm_path ||= ENV["MODEL_LANGUAGE_WASM"] || bundled_wasm ||
15
+ File.expand_path("../../../wasm/dist/model_language.wasm", __dir__)
16
+ @engine = Wasmtime::Engine.new
17
+ @module = Wasmtime::Module.from_file(@engine, wasm_path)
18
+ @linker = Wasmtime::Linker.new(@engine)
19
+ Wasmtime::WASI::P1.add_to_linker_sync(@linker)
20
+ end
21
+
22
+ def render(template, data: {}, schema: [], options: {})
23
+ invoke("op" => "render", "template" => template, "data" => data,
24
+ "schema" => schema, "options" => options)
25
+ end
26
+
27
+ def validate(template, schema: [], options: {})
28
+ invoke("op" => "validate", "template" => template, "schema" => schema, "options" => options)
29
+ end
30
+
31
+ def parse(template)
32
+ invoke("op" => "parse", "template" => template)
33
+ end
34
+
35
+ private
36
+
37
+ def invoke(request)
38
+ Tempfile.create("model-language") do |out|
39
+ config = Wasmtime::WasiConfig.new
40
+ .set_stdin_string(JSON.dump(request))
41
+ .set_stdout_file(out.path)
42
+ store = Wasmtime::Store.new(@engine, wasi_p1_config: config)
43
+ instance = @linker.instantiate(store, @module)
44
+
45
+ error = nil
46
+ begin
47
+ instance.invoke("_start")
48
+ rescue StandardError => e
49
+ error = e # a clean WASI exit surfaces as an error; the response is written
50
+ end
51
+
52
+ content = File.read(out.path)
53
+ raise error if content.empty? && error
54
+
55
+ JSON.parse(content)
56
+ end
57
+ end
58
+
59
+ def bundled_wasm
60
+ path = File.expand_path("model_language.wasm", __dir__)
61
+ File.exist?(path) ? path : nil
62
+ end
63
+ end
64
+ end
Binary file
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: model-language
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Wexio
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-07-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: wasmtime
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '30.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '30.0'
27
+ description: Runs the exact same engine as the JavaScript/TypeScript package via an
28
+ embedded WebAssembly module — byte-for-byte identical output, guaranteed by a shared
29
+ conformance suite.
30
+ email:
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - README.md
36
+ - lib/model_language.rb
37
+ - lib/model_language.wasm
38
+ homepage: https://github.com/wexiohub/model-language
39
+ licenses:
40
+ - MIT
41
+ metadata:
42
+ source_code_uri: https://github.com/wexiohub/model-language
43
+ rubygems_mfa_required: 'true'
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '3.0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubygems_version: 3.5.22
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: A typed, safe template language for AI-agent prompts (WebAssembly-backed).
63
+ test_files: []