Skip to content

Conversation

@wrenj
Copy link
Collaborator

@wrenj wrenj commented Jan 21, 2026

add basic formatting functions

@github-project-automation github-project-automation bot moved this to Todo in A2UI Jan 21, 2026
@wrenj wrenj requested a review from gspencergoog January 21, 2026 01:17
@wrenj wrenj enabled auto-merge (squash) January 21, 2026 01:17
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors string_format to formatString for consistency and introduces several new basic formatting functions: formatNumber, formatCurrency, formatDate, and pluralize. The changes are mostly well-implemented, but there is a critical issue with a broken JSON schema reference in the new formatDate function. I've also included some feedback on API consistency and the implementation of the pluralize function for your consideration.

Comment on lines 768 to 771
"value": {
"$ref": "common_types.json#/$defs/DynamicDate",
"description": "The date to format."
},
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The schema reference common_types.json#/$defs/DynamicDate is broken, as DynamicDate is not defined in common_types.json. This will cause validation failures. Based on other components like DateTimeInput, dates are typically handled as strings (ISO 8601) or numbers (timestamps). You should change this to a valid type, such as DynamicValue to support both strings and numbers.

Suggested change
"value": {
"$ref": "common_types.json#/$defs/DynamicDate",
"description": "The date to format."
},
"value": {
"$ref": "common_types.json#/$defs/DynamicValue",
"description": "The date to format, typically as an ISO 8601 string or a numeric timestamp."
},

Comment on lines 722 to 739
"parameters": {
"type": "object",
"required": [ "value" ],
"properties": {
"value": {
"$ref": "common_types.json#/$defs/DynamicNumber",
"description": "The number to format."
},
"decimals": {
"$ref": "common_types.json#/$defs/DynamicNumber",
"description": "Optional. The number of decimal places to show. Defaults to 0 or 2 depending on locale."
},
"useGrouping": {
"$ref": "common_types.json#/$defs/DynamicBoolean",
"description": "Optional. If true, uses locale-specific grouping separators (e.g. '1,000'). If false, returns raw digits (e.g. '1000'). Defaults to true."
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The new formatting functions (formatNumber, formatCurrency, etc.) use named parameters (an object with properties), while existing functions (required, regex, formatString) use positional parameters (an array of values). This introduces an inconsistency in the function catalog's API design. While named parameters are great for functions with optional arguments, this shift in pattern could be confusing for developers. It would be beneficial to document this as the new standard for functions or consider a plan to migrate older functions for better consistency.

Comment on lines 779 to 801
{
"name": "pluralize",
"description": "Returns the singular string if the count is 1, otherwise returns the plural string.",
"returnType": "string",
"parameters": {
"type": "object",
"required": [ "value", "singular", "plural" ],
"properties": {
"value": {
"$ref": "common_types.json#/$defs/DynamicNumber",
"description": "The numeric value to check."
},
"singular": {
"$ref": "common_types.json#/$defs/DynamicString",
"description": "The string to return if count is exactly 1."
},
"plural": {
"$ref": "common_types.json#/$defs/DynamicString",
"description": "The string to return if count is not 1."
}
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The pluralize function is described as returning the plural form if the count is not 1. This is a very basic approach to pluralization and doesn't align with the locale-aware nature of the other new formatting functions. It will not work correctly for many languages and even has edge cases in English (e.g., 0 items, -1 items).

For better internationalization support, I recommend adopting a more robust mechanism based on CLDR plural rules, which include categories like zero, one, two, few, many, and other. A more flexible function signature could accept a map of these categories to their corresponding strings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant