Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/front-end/components/D3Tree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ export default {
default: 40, // Default size of the image node
},
},
watch: {
data: {
handler() {
this.drawTree();
},
deep: true, // Watch nested properties for changes
},
},
mounted() {
this.drawTree();
},
Expand Down
2 changes: 1 addition & 1 deletion packages/front-end/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default defineNuxtConfig({
public: {
baseUrl: process.env.BACKEND_URL ? process.env.BACKEND_URL : globalBaseUrl,
// Supply Graph AI configuration
supplyGraphAiUrl: process.env.SUPPLY_GRAPH_AI_URL || 'http://localhost:8081'
supplyGraphAiUrl: process.env.SUPPLY_GRAPH_AI_URL || 'http://localhost:8001'
// apiBase: '/api'
}
},
Expand Down
149 changes: 47 additions & 102 deletions packages/front-end/pages/products/[id]/supplyTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const apiBaseUrl = ref(
const supplyGraphApiUrl = ref(
import.meta.env.VITE_SUPPLY_GRAPH_AI_URL || "http://localhost:8001"
);
const supplyGraphApiEndpoint = ref("/v1/match"); // Path to the versioned supply tree creation endpoint
const supplyGraphApiEndpoint = ref("/v1/api/match"); // Path to the versioned supply tree creation endpoint


const sendToSupplyGraphAI = async (o: any) => {
if (!o) {
Expand Down Expand Up @@ -54,37 +55,11 @@ const sendToSupplyGraphAI = async (o: any) => {
try {
const originalData = okhItem.originalData || okhItem;

console.log("Preparing to send OKH item to Supply Graph AI:", okhItem);

// WARNING! TODO: This is hard coding a recipe. We instatn want this to be the OKH!
const payload = {
okh_reference:
okhItem.id?.toString() ||
originalData.fname ||
originalData.id ||
"unknown",
required_quantity: 1,
deadline: null,
metadata: {
name: okhItem.name || originalData.name || originalData.title,
shortDescription:
okhItem.shortDescription ||
originalData.description ||
originalData.summary,
keywords:
okhItem.keywords || originalData.keywords || originalData.tags || [],
maker:
okhItem.maker ||
originalData.maker ||
originalData.author ||
originalData.creator,
whereToFind:
okhItem.whereToFind ||
originalData.whereToFind ||
originalData.source,
source: "project-data-platform-ts",
image: okhItem.image || originalData.image || originalData.imageUrl,
originalId: originalData.id || originalData.fname,
dataSource: originalData.dataSource || "project-data-platform",
...originalData,
},
recipe_id: "8f14e3c4-09f2-4a5e-8bd9-4b5bb5d0a9cd",
};

console.log("Enhanced payload for Supply Graph AI (port 8001):", payload);
Expand Down Expand Up @@ -134,87 +109,57 @@ const sendToSupplyGraphAI = async (o: any) => {

// Parse the response from supply graph AI
const supplyTreeResponse = await response.json();
console.log("Supply Graph AI Response:", supplyTreeResponse);

// Enhanced response processing to handle various response formats
supplyTreeData.value = {
rootItem: selectedOkh.value,
relatedComponents:
supplyTreeResponse.components ||
supplyTreeResponse.related_items ||
supplyTreeResponse.dependencies ||
[],
supplyChainDepth:
supplyTreeResponse.depth || supplyTreeResponse.chain_depth || 1,
analysisTimestamp:
supplyTreeResponse.creation_time ||
supplyTreeResponse.timestamp ||
new Date().toISOString(),
analysisMethod: "supply-graph-ai-port-8001",
apiResponse: supplyTreeResponse, // Keep full response for debugging
requestPayload: payload, // Keep request for debugging
};

console.log("Final Supply Tree Data:", supplyTreeData.value);

console.log("Supply Graph AI Response2:", supplyTreeResponse);

// Clear previous solutions
const formattedSolutions: any[] = [];

supplyTreeResponse.data.solutions.forEach((solution: any) => {

const children = solution.tree.capabilities_used.map((capability: string) => ({
name: capability,
image: "/OKP_icon.png",
}));


const formattedSolution = {
name: solution.facility_name,
image: "/okw_maker.png",
class: "test",
children: children,
};

formattedSolutions.push(formattedSolution);
});

console.log("formattedSolutions:", formattedSolutions);

// Update treeData.value to trigger re-render in D3Tree component
treeData.value = {
name: selectedOkh.value?.name || "Supply Tree",
children: [
{
image: "/okh.png",
children: formattedSolutions,
},
],
};
} catch (err) {
console.error("Error generating supply tree:", err);
error.value = `Failed to generate supply tree: ${err.message}`;
error.value = `Failed to generate supply tree: ${err instanceof Error ? err.message : String(err)}`;
} finally {
loading.value = false;
}
};

const treeData = reactive({
name: "Oatmeal raisin cookie",

const treeData = ref<any>({
name: "Chocolate Chip Cookies",
children: [
{
// name: "OKW",
image: "/okw.png",
children: [
{
name: "cinnamon",
class: "test",
children: [
{
image: "/okw.png",
children: [
{
name: "testA",
children: [
{
image: "/okw.png",
children: [
{
name: "test1",
},
],
},
{ image: "/okw.png" },
{ image: "/okw.png" },
{ image: "/okw.png" },
],
},
],
},
{ image: "/okw.png", children: [{ name: "testB" }] },
{ image: "/okw.png" },
{ image: "/okw.png" },
],
},
{ name: "vanilla extract", children: [{ image: "/okw.png" }] },
{ name: "white sugar", children: [{ image: "/okw.png" }] },
{ name: "raisin", children: [{ image: "/okw.png" }] },
{ name: "egg", children: [{ image: "/okw.png" }] },
{ name: "shipping supply", children: [{ image: "/okw.png" }] },
{ name: "butter", children: [{ image: "/okw.png" }] },
{ name: "oats", children: [{ image: "/okw.png" }] },
{
name: "all purpose flour",
children: [{ image: "/okw.png" }],
},
{ name: "brown sugar", children: [{ image: "/okw.png" }] },
],
image: "/okh.png",
children: [],
},
],
});
Expand Down
38 changes: 21 additions & 17 deletions packages/front-end/pages/supply-graph-api.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,27 @@ const sendToSupplyGraphAI = async (okhItem) => {
console.log('Processing OKH item for Supply Graph AI:', okhItem);
const originalData = okhItem.originalData || okhItem;

const payload = {
okh_reference: okhItem.id?.toString() || originalData.fname || originalData.id || 'unknown',
required_quantity: 1,
deadline: null,
metadata: {
name: okhItem.name || originalData.name || originalData.title,
shortDescription: okhItem.shortDescription || originalData.description || originalData.summary,
keywords: okhItem.keywords || originalData.keywords || originalData.tags || [],
maker: okhItem.maker || originalData.maker || originalData.author || originalData.creator,
whereToFind: okhItem.whereToFind || originalData.whereToFind || originalData.source,
source: "project-data-platform-ts",
image: okhItem.image || originalData.image || originalData.imageUrl,
originalId: originalData.id || originalData.fname,
dataSource: originalData.dataSource || 'project-data-platform',
...originalData
}
};
// const payload = {
// okh_reference: okhItem.id?.toString() || originalData.fname || originalData.id || 'unknown',
// required_quantity: 1,
// deadline: null,
// metadata: {
// name: okhItem.name || originalData.name || originalData.title,
// shortDescription: okhItem.shortDescription || originalData.description || originalData.summary,
// keywords: okhItem.keywords || originalData.keywords || originalData.tags || [],
// maker: okhItem.maker || originalData.maker || originalData.author || originalData.creator,
// whereToFind: okhItem.whereToFind || originalData.whereToFind || originalData.source,
// source: "project-data-platform-ts",
// image: okhItem.image || originalData.image || originalData.imageUrl,
// originalId: originalData.id || originalData.fname,
// dataSource: originalData.dataSource || 'project-data-platform',
// ...originalData
// }
// };

const payload = {
"recipe_id": "8f14e3c4-09f2-4a5e-8bd9-4b5bb5d0a9cd"
}

console.log('Enhanced payload for Supply Graph AI (port 8001):', payload);
console.log(`Sending request to: ${supplyGraphApiUrl.value}${supplyGraphApiEndpoint.value}`);
Expand Down
Binary file added packages/front-end/public/OKP_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/front-end/public/okh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/front-end/public/okw_maker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions packages/mock-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Mock API (project-data-platform-ts)

Lightweight Express mock API used for local development and for testing integration with the frontend and supply-graph services.

- Port: 8081 (default)
- Purpose: return deterministic mock supply-tree responses and basic health checks.

## Quick start

1. Install dependencies

```powershell
npm install
```

2. Start dev server

```powershell
npm run dev
```

3. Server will be listening on:

```
http://localhost:8081
```

(If you want to run without nodemon, use `node index.js`.)

## Available endpoints

- GET /
- Basic welcome text.

- POST /v1/match
- Accepts a JSON body and returns a mock supply-tree response.
- Useful for testing supply-graph AI integration.

- GET /health
- Returns a simple health JSON: `{ "status": "OK", "message": "Server is healthy!" }`.

## Example cURL

POST to the match endpoint:

```bash
curl -X POST http://localhost:8081/v1/match \
-H "Content-Type: application/json" \
-d '{"product": {"id":"Q15026","desc":"chair"}}'
```

Response will be the mock supply-tree JSON defined in `mock-data.js`.

## Files

- `index.js` — Express server and endpoints.
- `mock-data.js` — Contains the mock response object(s) including `supplyTreeMockResponse`.
- `package.json` — Scripts and dependencies.

## Notes

- This mock API is intentionally simple and synchronous to make frontend integration straightforward.
- Replace or extend the mock response in `mock-data.js` to suit tests or demos.
- The repo uses `type: "module"`, so Node should be v14+ (prefer v18+).

## License

Project license follows the parent repository. See top-level LICENSE for details.
32 changes: 32 additions & 0 deletions packages/mock-api/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import express from "express";
import morgan from "morgan";
import { supplyTreeMockResponse } from "./mock-data.js";

const app = express();

const PORT = 8001;

// Middleware to parse JSON
app.use(express.json());

//middleware for logging
app.use(morgan('tiny'));

// Basic route
app.get("/", (req, res) => {
res.send("Hello from your first Node.js backend!");
});

app.post("/v1/match", (req, res) => {
console.log("Received data:", req.body);
res.status(200).json({ status: "OK", data: supplyTreeMockResponse });
});

app.get("/health", (req, res) => {
res.status(200).json({ status: "OK", message: "Server is healthy!" });
});

// Start the server
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});
Loading