Skip to content

Commit 0642902

Browse files
authored
Merge pull request #48 from FluffyAIcode/AgentMemory/v030-pr-b5-typescript-sdk-8e7f
PR-B5 (ADR 0008 Phase B): TypeScript SDK — @kakeya/runtime
2 parents db38dcc + a2c4c22 commit 0642902

16 files changed

Lines changed: 6098 additions & 11 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,55 @@ jobs:
258258
# bytes, this job catches it as a drift before merge.
259259
pip install 'grpcio>=1.65,<2.0' 'grpcio-tools>=1.65,<2.0'
260260
261-
- name: Regenerate stubs
261+
- name: Set up Node.js (for ts-proto plugin)
262+
uses: actions/setup-node@v4
263+
with:
264+
node-version: "20"
265+
cache: npm
266+
cache-dependency-path: sdks/typescript/package-lock.json
267+
268+
- name: Install ts-proto in sdks/typescript
269+
run: |
270+
cd sdks/typescript
271+
npm install --no-audit --no-fund
272+
273+
- name: Regenerate stubs (Python + TypeScript)
262274
run: bash scripts/regenerate_proto_stubs.sh
263275

264276
- name: Fail if regenerated stubs differ from committed stubs
265277
run: |
266-
if ! git diff --exit-code -- inference_engine/server/proto_gen/; then
278+
if ! git diff --exit-code -- inference_engine/server/proto_gen/ sdks/typescript/src/proto_gen/; then
267279
echo "::error::Committed stubs are out of date with proto/."
268280
echo "Run scripts/regenerate_proto_stubs.sh locally and commit."
269281
exit 1
270282
fi
283+
284+
typescript-sdk-tests:
285+
name: TypeScript SDK tests
286+
runs-on: ubuntu-latest
287+
# ADR 0008 PR-B5: vitest under Node 20+. The TypeScript SDK is
288+
# Linux-runnable end-to-end (no MLX dependency); the in-Node
289+
# gRPC server fixture lets us test the SDK against a real
290+
# @grpc/grpc-js channel without needing the Python runtime.
291+
steps:
292+
- name: Check out
293+
uses: actions/checkout@v4
294+
295+
- name: Set up Node.js
296+
uses: actions/setup-node@v4
297+
with:
298+
node-version: "20"
299+
cache: npm
300+
cache-dependency-path: sdks/typescript/package-lock.json
301+
302+
- name: Install dependencies
303+
working-directory: sdks/typescript
304+
run: npm install --no-audit --no-fund
305+
306+
- name: Type-check
307+
working-directory: sdks/typescript
308+
run: npm run typecheck
309+
310+
- name: Run vitest with 100% coverage
311+
working-directory: sdks/typescript
312+
run: npm test

scripts/regenerate_proto_stubs.sh

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
11
#!/usr/bin/env bash
2-
# Regenerate Python gRPC stubs from proto/kakeya/v1/*.proto.
2+
# Regenerate gRPC stubs from proto/kakeya/v1/*.proto for every SDK.
33
#
4-
# Generated files land in inference_engine/server/proto_gen/ and are
5-
# committed to the repo. Re-run this script whenever a .proto file
6-
# changes; CI's `proto-stub-drift` check verifies that the committed
7-
# stubs are up-to-date by re-running the script and `git diff
8-
# --exit-code`.
4+
# Targets:
5+
# * Python -> inference_engine/server/proto_gen/ (PR-A1)
6+
# * TypeScript -> sdks/typescript/src/proto_gen/ (PR-B5)
7+
#
8+
# Generated files are committed to the repo. Re-run this script
9+
# whenever a .proto file changes; CI's `proto-stub-drift` check
10+
# verifies that the committed stubs are byte-identical to what
11+
# this script produces.
912
#
1013
# This is the canonical regeneration command. Do NOT invoke
11-
# `python -m grpc_tools.protoc` ad-hoc — keep all flags here so they
12-
# are reproducible across contributor machines and CI.
14+
# `protoc` ad-hoc — keep all flags here so they are reproducible
15+
# across contributor machines and CI.
16+
#
17+
# Prerequisites:
18+
# * Python: grpcio-tools (provides grpc_tools.protoc)
19+
# * TypeScript: ts-proto (installed in sdks/typescript/node_modules)
1320

1421
set -euo pipefail
1522

1623
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
1724
PROTO_ROOT="$ROOT/proto"
1825
OUT_ROOT="$ROOT/inference_engine/server/proto_gen"
26+
TS_OUT_ROOT="$ROOT/sdks/typescript/src/proto_gen"
27+
TS_PROTO_PLUGIN="$ROOT/sdks/typescript/node_modules/.bin/protoc-gen-ts_proto"
1928

2029
# Clean only generated files (preserve hand-written package __init__.py).
2130
find "$OUT_ROOT" -type f \( -name '*_pb2.py' -o -name '*_pb2_grpc.py' -o -name '*_pb2.pyi' \) -delete 2>/dev/null || true
@@ -57,4 +66,36 @@ if [ -f "$GRPC_FILE" ]; then
5766
rm -f "$GRPC_FILE.bak"
5867
fi
5968

60-
echo "Regenerated stubs into $OUT_ROOT"
69+
echo "Regenerated Python stubs into $OUT_ROOT"
70+
71+
# -----------------------------------------------------------------------------
72+
# TypeScript stubs (PR-B5)
73+
# -----------------------------------------------------------------------------
74+
75+
if [ -x "$TS_PROTO_PLUGIN" ]; then
76+
# Clean only generated TS files (preserve hand-written package
77+
# entry points — none today, but defensive).
78+
find "$TS_OUT_ROOT" -type f -name '*.ts' -delete 2>/dev/null || true
79+
mkdir -p "$TS_OUT_ROOT"
80+
81+
# ts-proto generation flags worth pinning here:
82+
# esModuleInterop=true tsconfig has it; matching keeps imports clean.
83+
# forceLong=string uint64 / int64 -> string (JS number can't hold them).
84+
# useExactTypes=false ts-proto's stricter typing for oneof; we keep
85+
# the more ergonomic discriminated-union shape.
86+
# outputServices=grpc-js generate @grpc/grpc-js style client + server.
87+
# useOptionals=messages proto3 optional + message fields use TS optional.
88+
# stringEnums=false enums emit as integer constants (matches wire).
89+
# removeEnumPrefix=true strip the GenerateDone_ prefix from enum members.
90+
python3 -m grpc_tools.protoc \
91+
--plugin="protoc-gen-ts_proto=$TS_PROTO_PLUGIN" \
92+
--proto_path="$PROTO_ROOT" \
93+
--ts_proto_out="$TS_OUT_ROOT" \
94+
--ts_proto_opt=esModuleInterop=true,forceLong=string,outputServices=grpc-js,useOptionals=messages,stringEnums=false,removeEnumPrefix=true \
95+
$(find "$PROTO_ROOT" -name '*.proto')
96+
97+
echo "Regenerated TypeScript stubs into $TS_OUT_ROOT"
98+
else
99+
echo "WARN: ts-proto plugin not found at $TS_PROTO_PLUGIN; skipping TypeScript stub regen." >&2
100+
echo " Run 'npm install' in sdks/typescript/ first." >&2
101+
fi

sdks/typescript/.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# TypeScript build output
2+
dist/
3+
*.tsbuildinfo
4+
5+
# vitest / coverage
6+
coverage/
7+
8+
# npm
9+
node_modules/
10+
11+
# IDE
12+
.vscode/
13+
.idea/

0 commit comments

Comments
 (0)