@metta-ts/das-gateway 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 MesTTo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # @metta-ts/das-gateway
2
+
3
+ A transport-agnostic gateway that bridges [MeTTa TS](https://github.com/MesTTo/Meta-TypeScript-Talk) to a SingularityNET Distributed AtomSpace (DAS). It encodes a pattern query, sends it over an injected transport (Connect/HTTP, usable from the browser), and decodes the bindings back into MeTTa atoms.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @metta-ts/das-gateway
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```ts
14
+ import { queryDas, type GatewayTransport } from "@metta-ts/das-gateway";
15
+ import { parse, standardTokenizer } from "@metta-ts/core";
16
+
17
+ // You provide the transport (e.g. a Connect client). The gateway is browser-reachable over HTTP.
18
+ const transport: GatewayTransport = {
19
+ /* query(request) => Promise<QueryResponse> */
20
+ };
21
+
22
+ const pattern = parse("(Parent $x Bob)", standardTokenizer())!;
23
+ const bindings = await queryDas(transport, "&self", pattern);
24
+ ```
25
+
26
+ Querying a DAS involves network I/O, so the gateway's query API is async. Pair it with the async evaluation path in `@metta-ts/core` to call it from MeTTa source.
27
+
28
+ ## License
29
+
30
+ [MIT](https://github.com/MesTTo/Meta-TypeScript-Talk/blob/main/LICENSE).
@@ -0,0 +1,23 @@
1
+ import { Bindings, Atom } from '@metta-ts/core';
2
+
3
+ /** Gateway query payloads use MeTTa source strings on the wire. */
4
+ interface QueryRequest {
5
+ readonly space: string;
6
+ readonly pattern: string;
7
+ }
8
+ interface QueryResponse {
9
+ /** Each solution as a flat list of `[varName, atomSource]` pairs. */
10
+ readonly bindings: ReadonlyArray<ReadonlyArray<readonly [string, string]>>;
11
+ }
12
+ /** Shared MeTTa source wire-codec helpers for gateway clients and servers. */
13
+ declare const encodePattern: (a: Atom) => string;
14
+ declare const decodeBindings: (resp: QueryResponse) => Bindings[];
15
+ /** Async browser-to-gateway transport, for example a Connect-web client. */
16
+ interface GatewayTransport {
17
+ query(req: QueryRequest): Promise<QueryResponse>;
18
+ }
19
+ /** Browser-side async DAS access. Limitation: kernel `match` is synchronous while gateway transport
20
+ * is async, so call this directly instead of `(match &das ...)`. */
21
+ declare function queryDas(transport: GatewayTransport, space: string, pattern: Atom): Promise<Bindings[]>;
22
+
23
+ export { type GatewayTransport, type QueryRequest, type QueryResponse, decodeBindings, encodePattern, queryDas };
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ // src/index.ts
2
+ import { format, parse, standardTokenizer } from "@metta-ts/core";
3
+ var encodePattern = (a) => format(a);
4
+ var decodeBindings = (resp) => {
5
+ const tk = standardTokenizer();
6
+ return resp.bindings.map(
7
+ (sol) => sol.map(([x, src]) => ({ tag: "val", x, a: parse(src, tk), y: void 0 }))
8
+ );
9
+ };
10
+ async function queryDas(transport, space, pattern) {
11
+ return decodeBindings(await transport.query({ space, pattern: encodePattern(pattern) }));
12
+ }
13
+ export {
14
+ decodeBindings,
15
+ encodePattern,
16
+ queryDas
17
+ };
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@metta-ts/das-gateway",
3
+ "version": "1.0.0",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "dependencies": {
18
+ "@metta-ts/core": "1.0.0"
19
+ },
20
+ "author": "MesTTo",
21
+ "engines": {
22
+ "node": ">=20"
23
+ },
24
+ "sideEffects": false,
25
+ "module": "./dist/index.js",
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "description": "HTTP/Connect gateway bridging MeTTa TS to a Distributed AtomSpace, reachable from the browser.",
30
+ "keywords": [
31
+ "metta",
32
+ "hyperon",
33
+ "das",
34
+ "gateway",
35
+ "singularitynet"
36
+ ],
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/MesTTo/Meta-TypeScript-Talk.git",
40
+ "directory": "packages/das-gateway"
41
+ },
42
+ "homepage": "https://github.com/MesTTo/Meta-TypeScript-Talk#readme",
43
+ "bugs": {
44
+ "url": "https://github.com/MesTTo/Meta-TypeScript-Talk/issues"
45
+ },
46
+ "scripts": {
47
+ "build": "tsup src/index.ts --format esm --dts --clean"
48
+ }
49
+ }