Skip to content

Commit 93b7c21

Browse files
ai-edge-botcopybara-github
authored andcommitted
Internal change
LiteRT-LM-PiperOrigin-RevId: 908963075
1 parent 1bd571a commit 93b7c21

11 files changed

Lines changed: 345 additions & 0 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "@litertjs/lm-tester",
3+
"version": "1.0.0",
4+
"publishConfig": {
5+
"access": "public"
6+
},
7+
"type": "module",
8+
"main": "serve.js",
9+
"bin": {
10+
"model-tester": "serve.js"
11+
},
12+
"scripts": {
13+
"copy-wasm": "mkdirp dist && cp -r `node -e \"console.log(path.join(require.resolve('@litertjs/lm/package.json'), '../wasm'))\"` dist/",
14+
"copy-static-files": "cp -r static dist && npm run copy-wasm",
15+
"dev": "rimraf dist && npm run copy-static-files && node scripts/devserver.js",
16+
"build": "rimraf dist && npm run copy-static-files && esbuild --bundle --target=es2020 --outfile=dist/bundle.js --sourcemap src/index.ts"
17+
},
18+
"author": "",
19+
"repository": {
20+
"type": "git",
21+
"url": "https://github.com/google-ai-edge/LiteRT-LM.git",
22+
"directory": "js/apps/model_tester"
23+
},
24+
"license": "Apache-2.0",
25+
"description": "",
26+
"dependencies": {
27+
"@lit/task": "^1.0.2",
28+
"@litertjs/lm": "^1.0.0",
29+
"@material/web": "^2.3.0",
30+
"argparse": "^2.0.1",
31+
"esbuild": "^0.23.0",
32+
"express": "^5.1.0",
33+
"lit": "^3.2.1",
34+
"mkdirp": "^3.0.1",
35+
"open": "^10.2.0",
36+
"rimraf": "^6.0.1"
37+
},
38+
"devDependencies": {
39+
"@types/argparse": "^2.0.17",
40+
"@types/express": "^5.0.3"
41+
}
42+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import * as esbuild from 'esbuild';
18+
import http from 'node:http';
19+
20+
// Start esbuild's server on port 3000
21+
let ctx = await esbuild.context({
22+
bundle: true,
23+
target: 'es2020',
24+
outfile: 'dist/bundle.js',
25+
sourcemap: true,
26+
entryPoints: ['src/index.ts'],
27+
});
28+
29+
// The return value tells us where esbuild's local server is. It might
30+
// not be 3000 if that port was busy.
31+
let { host, port } = await ctx.serve({ servedir: 'dist', port: 3000});
32+
33+
// Then start a proxy server on port 8000
34+
http.createServer((req, res) => {
35+
const options = {
36+
hostname: host,
37+
port: port,
38+
path: req.url,
39+
method: req.method,
40+
headers: req.headers,
41+
};
42+
43+
// Forward each incoming request to esbuild
44+
const proxyReq = http.request(options, proxyRes => {
45+
// If esbuild returns "not found", send a custom 404 page
46+
if (proxyRes.statusCode === 404) {
47+
res.writeHead(404, { 'Content-Type': 'text/html' });
48+
res.end('<h1>Not found</h1>');
49+
return;
50+
}
51+
52+
// Otherwise, forward the response from esbuild to the client.
53+
// Include cross origin headers for Wasm threaded support.
54+
const headers = {
55+
...proxyRes.headers,
56+
'Cross-Origin-Opener-Policy': 'same-origin',
57+
'Cross-Origin-Embedder-Policy': 'require-corp',
58+
};
59+
res.writeHead(proxyRes.statusCode, headers);
60+
proxyRes.pipe(res, { end: true });
61+
});
62+
63+
// Forward the body of the request to esbuild
64+
req.pipe(proxyReq, { end: true });
65+
}).listen(8000);
66+
67+
console.log('Server listening on http://localhost:8000');
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"compilerOptions": {
3+
"noFallthroughCasesInSwitch": true,
4+
"noImplicitOverride": true,
5+
"noPropertyAccessFromIndexSignature": true,
6+
"strict": true,
7+
"moduleResolution": "bundler",
8+
"module": "ESNext",
9+
"esModuleInterop": true,
10+
"forceConsistentCasingInFileNames": true,
11+
"isolatedModules": true,
12+
"target": "ESNext",
13+
"skipLibCheck": true,
14+
"sourceMap": true,
15+
"experimentalDecorators": true,
16+
"useDefineForClassFields": false,
17+
"emitDecoratorMetadata": true
18+
},
19+
"include": ["src/**/*.ts"],
20+
"exclude": ["**/node_modules"]
21+
}

opensource_only/js/package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "litert-lm-monorepo",
3+
"version": "1.0.0",
4+
"private": true,
5+
"license": "Apache-2.0",
6+
"workspaces": [
7+
"packages/*",
8+
"apps/*"
9+
],
10+
"scripts": {
11+
"build": "turbo build",
12+
"test": "turbo test",
13+
"typecheck": "turbo typecheck",
14+
"dev": "turbo watch dev",
15+
"lint": "turbo lint",
16+
"check-format": "prettier --check .",
17+
"format": "prettier --write .",
18+
"clean": "turbo clean && turbo daemon clean",
19+
"pack": "turbo pack",
20+
"docs": "npm run build && typedoc"
21+
},
22+
"packageManager": "[email protected]",
23+
"engines": {
24+
"node": ">=20"
25+
},
26+
"devDependencies": {
27+
"prettier": "^3.3.3",
28+
"turbo": "^2.0.10",
29+
"typedoc": "^0.28.7"
30+
}
31+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "@litertjs/lm",
3+
"version": "1.0.0",
4+
"description": "LiteRT-LM package",
5+
"publishConfig": {
6+
"access": "public"
7+
},
8+
"main": "./dist/index.js",
9+
"types": "./dist/index.d.ts",
10+
"type": "module",
11+
"files": [
12+
"dist/**",
13+
"wasm/**"
14+
],
15+
"author": "",
16+
"repository": {
17+
"type": "git",
18+
"url": "https://github.com/google-ai-edge/LiteRT-LM.git",
19+
"directory": "js/packages/core"
20+
},
21+
"license": "Apache-2.0",
22+
"scripts": {
23+
"build": "tsc",
24+
"lint": "eslint .",
25+
"typecheck": "tsc --noEmit",
26+
"bundle-tests": "esbuild --bundle src/litertlm_web_test.ts --sourcemap --outfile=spec_dist/litertlm_web_test.js",
27+
"test": "npm run bundle-tests && jasmine-browser-runner",
28+
"clean": "rimraf .turbo node_modules dist spec_dist",
29+
"pack": "npm pack"
30+
},
31+
"devDependencies": {
32+
"@types/jasmine": "^5.1.8",
33+
"@webgpu/types": "^0.1.54",
34+
"esbuild": "^0.23.0",
35+
"eslint": "^9.8.0",
36+
"jasmine": "^5.8.0",
37+
"jasmine-browser-runner": "^3.0.0",
38+
"jasmine-core": "^5.8.0",
39+
"rimraf": "^6.0.1",
40+
"selenium-webdriver": "^4.34.0",
41+
"typescript": "^5.5.4"
42+
},
43+
"dependencies": {
44+
"@litertjs/wasm-utils": "^2.0.0"
45+
}
46+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Copyright 2026 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* Type for a path to a resource.
19+
*/
20+
export type UrlPath = string;
21+
22+
/**
23+
* Returns the string representation of the given url path.
24+
*/
25+
export function pathToString(path: UrlPath): string {
26+
return path;
27+
}
28+
29+
/**
30+
* Appends a path segment to the given url path.
31+
*/
32+
export function appendPathSegment(path: UrlPath, segment: string): string {
33+
if (!path) return segment;
34+
if (!segment) return path;
35+
36+
const pathWithSlash = path.endsWith('/') ? path : path + '/';
37+
const segmentWithoutSlash =
38+
segment.startsWith('/') ? segment.substring(1) : segment;
39+
return pathWithSlash + segmentWithoutSlash;
40+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"compilerOptions": {
3+
"noFallthroughCasesInSwitch": true,
4+
"noImplicitOverride": true,
5+
"noPropertyAccessFromIndexSignature": true,
6+
"strict": true,
7+
"moduleResolution": "bundler",
8+
"module": "ESNext",
9+
"esModuleInterop": true,
10+
"forceConsistentCasingInFileNames": true,
11+
"isolatedModules": true,
12+
"target": "ESNext",
13+
"skipLibCheck": true,
14+
"sourceMap": true,
15+
"declaration": true,
16+
"declarationMap": true,
17+
"types": ["@webgpu/types"],
18+
"outDir": "dist"
19+
},
20+
"include": ["src/**/*.ts"],
21+
"exclude": ["src/**/*_test.ts", "**/node_modules"]
22+
}

opensource_only/js/turbo.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"$schema": "https://turbo.build/schema.json",
3+
"tasks": {
4+
"build": {
5+
"inputs": ["$TURBO_DEFAULT$", ".env*"],
6+
"outputs": ["dist/**"],
7+
"dependsOn": ["^build"]
8+
},
9+
"dev": {
10+
"persistent": true,
11+
"dependsOn": ["build"]
12+
},
13+
"test": {
14+
"dependsOn": ["build"]
15+
},
16+
"typecheck": {
17+
"dependsOn": ["^build"]
18+
},
19+
"lint": {
20+
"dependsOn": ["^lint"]
21+
},
22+
"clean": {
23+
"cache": false
24+
},
25+
"pack": {
26+
"dependsOn": ["build"]
27+
}
28+
}
29+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "@litertjs/tsconfig/tsconfig.json",
3+
"include": ["src/**/*.ts"],
4+
"compilerOptions": {
5+
"experimentalDecorators": true,
6+
"useDefineForClassFields": false,
7+
"emitDecoratorMetadata": true
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "@litertjs/tsconfig/tsconfig.json",
3+
"include": ["src/**/*.ts"],
4+
"exclude": ["src/**/*_test.ts"],
5+
"compilerOptions": {
6+
"types": ["@webgpu/types"],
7+
"outDir": "dist"
8+
}
9+
}

0 commit comments

Comments
 (0)