Files
Ran Shem Tov c9793b5e6e chore(integrations/langgraph-js): sync to langgraph-python reference demo
Align langgraph-js with examples/integrations/langgraph-python via the
parity tooling. Remove legacy app/ layout, adopt src/ layout, rewrite
the TS agent to expose the tracked tool surface (manage_todos,
get_todos, query_data, generate_a2ui, search_flights) and todos state,
and write the canonical PROMPT.md. Keeps LangGraphAgent + stategraph
runtime (allowed divergence per the manifest); brings deps,
Dockerfile.app, entrypoint, showcase metadata, and shared UI into
lockstep. Parity verifier: 88 ok / 0 error.
2026-05-01 12:31:04 +02:00

69 lines
1.7 KiB
TypeScript

import { readFileSync } from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { z } from "zod";
import { tool } from "@langchain/core/tools";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
function parseCsv(raw: string): Record<string, string>[] {
const lines = raw.trim().split(/\r?\n/);
if (lines.length === 0) return [];
const headers = lines[0].split(",");
const rows: Record<string, string>[] = [];
for (let i = 1; i < lines.length; i++) {
const cells = splitCsvLine(lines[i]);
const row: Record<string, string> = {};
headers.forEach((h, idx) => {
row[h] = cells[idx] ?? "";
});
rows.push(row);
}
return rows;
}
function splitCsvLine(line: string): string[] {
const out: string[] = [];
let cur = "";
let inQuotes = false;
for (let i = 0; i < line.length; i++) {
const ch = line[i];
if (inQuotes) {
if (ch === '"' && line[i + 1] === '"') {
cur += '"';
i++;
} else if (ch === '"') {
inQuotes = false;
} else {
cur += ch;
}
} else if (ch === '"') {
inQuotes = true;
} else if (ch === ",") {
out.push(cur);
cur = "";
} else {
cur += ch;
}
}
out.push(cur);
return out;
}
const _cached_data = parseCsv(
readFileSync(path.join(__dirname, "db.csv"), "utf8"),
);
export const query_data = tool(
(_input: { query: string }) => {
return JSON.stringify(_cached_data);
},
{
name: "query_data",
description:
"Query the database, takes natural language. Always call before showing a chart or graph.",
schema: z.object({ query: z.string() }),
},
);