Skip to content

Conversation

@noencke
Copy link
Contributor

@noencke noencke commented Sep 26, 2025

This covers more cases - e.g. recursive inlined types, cleans up usage, and improves docs.

@github-actions github-actions bot added area: framework Framework is a tag for issues involving the developer framework. Eg Aqueduct base: main PRs targeted against main branch labels Sep 26, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves the schema naming utility functions in the tree-agent package to handle more complex cases including recursive inlined types, while also cleaning up the codebase and improving documentation.

Key changes:

  • Refactored schema naming utilities with new functions getFriendlyName, unqualifySchema, and isNamedSchema to replace the previous getFriendlySchema and getFriendlySchemaName functions
  • Added support for generating human-readable names for recursive and nested inline array/map/record types
  • Introduced findNamedSchemas utility to iterate through named schemas transitively

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
packages/framework/tree-agent/src/utils.ts Core implementation of improved schema naming utilities with better handling of inline types and recursive structures
packages/framework/tree-agent/src/test/systemPrompt.spec.ts Updated to use new unqualifySchema and isNamedSchema functions instead of deprecated getFriendlySchemaName
packages/framework/tree-agent/src/test/schemaUtils.spec.ts New comprehensive test suite for the updated schema utility functions
packages/framework/tree-agent/src/agent.ts Updated to use new utility functions and replaced manual schema traversal with findNamedSchemas

}
const schema = Tree.schema(value);
return getFriendlySchemaName(schema.identifier) ?? schema.identifier;
fail("Unexpected node schema");
Copy link

Copilot AI Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When writing asserts (from @fluidframework/core-utils), please use a string literal for the error message, not a hex assert code. Consider using assert(false, "Unexpected node schema") instead of fail().

Copilot generated this review using guidance from repository custom instructions.
}

const matches = schemaName.match(/[^.]+$/);
return schemaIdentifier.match(/\.*(?:Array|Map|Record)<\["(.*)"]>/) === null;
Copy link

Copilot AI Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex pattern /\.*(?:Array|Map|Record)<\["(.*)"]>/ contains an escaped dot that should be literal. The pattern should be /.*(?:Array|Map|Record)<\["(.*)"]>/ to match any characters before the container type patterns.

Suggested change
return schemaIdentifier.match(/\.*(?:Array|Map|Record)<\["(.*)"]>/) === null;
return schemaIdentifier.match(/.*(?:Array|Map|Record)<\["(.*)"]>/) === null;

Copilot uses AI. Check for mistakes.
for (const s of findNamedSchemas(Root)) {
identifiers.push((s as { identifier: string }).identifier);
}
assert.equal(identifiers.length, new Set(identifiers).size + 1); // There is one duplicate schema that is used twice (NamedStringMap)
Copy link

Copilot AI Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion is fragile and relies on magic numbers. Consider using a more explicit test that verifies the specific duplicate schema instead of assuming there's exactly one duplicate.

Suggested change
assert.equal(identifiers.length, new Set(identifiers).size + 1); // There is one duplicate schema that is used twice (NamedStringMap)
// Check that the only duplicate identifier is "NamedStringMap"
const duplicateIdentifiers = Object.entries(
identifiers.reduce((acc, id) => {
acc[id] = (acc[id] ?? 0) + 1;
return acc;
}, {} as Record<string, number>)
)
.filter(([_, count]) => count > 1)
.map(([id]) => id);
assert.deepEqual(duplicateIdentifiers, [NamedStringMap.identifier], "Expected only NamedStringMap to be duplicated");

Copilot uses AI. Check for mistakes.
@noencke noencke enabled auto-merge (squash) September 29, 2025 17:29
@noencke noencke merged commit 523aa5e into microsoft:main Sep 30, 2025
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: framework Framework is a tag for issues involving the developer framework. Eg Aqueduct base: main PRs targeted against main branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants