Skip to content
Closed
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
6 changes: 4 additions & 2 deletions src/tools/GpfDescribeTypeTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import BaseTool from "./BaseTool.js";
import { z } from "zod";
import type { Collection } from "@ignfab/gpf-schema-store";
import type { Collection, CollectionProperty } from "@ignfab/gpf-schema-store";

import { wfsSchemaStore } from "../wfs/catalog.js";
import { READ_ONLY_OPEN_WORLD_TOOL_ANNOTATIONS } from "../helpers/toolAnnotations.js";
Expand Down Expand Up @@ -71,7 +71,9 @@ class GpfDescribeTypeTool extends BaseTool<GpfDescribeTypeInput> {

try {
const featureType: Collection = await wfsSchemaStore.getFeatureType(input.typename);
return featureType;
// Hide the geometric property from the LLM-facing output to prevent it
// from querying it in the `select` of GpfGetFeatures or GpfGetFeatureById.
return { ...featureType, properties: featureType.properties.filter((p: CollectionProperty) => !p.defaultCrs) };
} catch (e: unknown) {
const message = e instanceof Error ? e.message : String(e);
throw new Error(`${message}. Utiliser gpf_search_types pour trouver un type valide.`);
Expand Down
39 changes: 38 additions & 1 deletion test/tools/wfs/describeType.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { describe, it, expect } from "vitest";
import { describe, it, expect, vi } from "vitest";

import type { Collection } from "@ignfab/gpf-schema-store";

import GpfDescribeTypeTool from "../../../src/tools/GpfDescribeTypeTool";
import { wfsSchemaStore } from "../../../src/wfs/catalog.js";

vi.mock("../../../src/wfs/catalog.js", () => ({
wfsSchemaStore: {
getFeatureType: vi.fn(),
},
}));

describe("Test GpfDescribeTypeTool",() => {
const mockCollection: Collection = {
Expand Down Expand Up @@ -126,4 +133,34 @@ describe("Test GpfDescribeTypeTool",() => {
type: "urn:geocontext:problem:execution-error",
});
});

it("should filter out geometry properties (those with defaultCrs) from the output", async () => {
const collectionWithGeometry: Collection = {
id: "BDTOPO_V3:batiment",
namespace: "BDTOPO_V3",
name: "batiment",
title: "Batiment",
description: "Description de test",
properties: [
{ name: "hauteur", type: "float" },
{ name: "geometrie", type: "polygon", defaultCrs: "EPSG:2154" },
],
};

vi.mocked(wfsSchemaStore.getFeatureType).mockResolvedValueOnce(collectionWithGeometry);

const tool = new GpfDescribeTypeTool();
const response = await tool.toolCall({
params: {
name: "gpf_describe_type",
arguments: { typename: "BDTOPO_V3:batiment" },
},
});

expect(response.isError).toBeUndefined();
const properties = (response.structuredContent as { properties: { name: string }[] }).properties;
expect(properties).toHaveLength(1);
expect(properties[0]).toMatchObject({ name: "hauteur" });
expect(properties.find(p => p.name === "geometrie")).toBeUndefined();
});
});
Loading