-
Notifications
You must be signed in to change notification settings - Fork 278
Description
Describe the bug
ODSP (maybe others?) makes it hard to use environment variables for dyanmic values.
Scenario:
I want to provide a specific document in an SPO list as knowledge via the doc's ID. In a JSON-based DA, I'd use:
"capabilities": [
{
"name": "OneDriveAndSharePoint",
"items_by_sharepoint_ids": [
{
"unique_id": "${{SPO_POLICY_DOC_ID}}"
}
]
}
]In TypeSpec, specifically with the @microsoft/typespec-m365-copilot package, it appears impossible, whereas I can do this in other places.
Reproduced
Define envvar in ./env/.env.local:
SPO_PTO_POLICY_DOC_ID=00000000-0000-0000-0000-000000000000On TypeSpec compile, it adds all envars, including this one, to ./src/env.tsp... cool ✅
namespace Environment {
// SPO_PTO_POLICY_DOC_ID
alias SPO_PTO_POLICY_DOC_ID = "00000000-0000-0000-0000-000000000000";
...
}Note
The existing script to gen the env.tsp uses const, but it doesn't matter in this case... same issue with const & alias, while I've already bugged #15017 & submitted a fix #15026 for this
But when it's referenced in the agent's TSP, like:
op pto_policy_doc is AgentCapabilities.OneDriveAndSharePoint<ItemsBySharePointIds = [
{ itemId: Environment.SPO_PTO_POLICY_DOC_ID }
]>;It isn't resolved... You just get:
"capabilities": [
{
"name": "OneDriveAndSharePoint",
"items_by_sharepoint_ids": [
{}
]
}
]But other places where you use TypeSpec aliases from envvars work just fine, like this:
alias AUTHORIZATION_ENDPOINT = "https://login.microsoftonline.com/${Environment.TEAMS_APP_TENANT_ID}/oauth2/v2.0/authorize";
alias TOKEN_ENDPOINT = "https://login.microsoftonline.com/${Environment.TEAMS_APP_TENANT_ID}/oauth2/v2.0/token";
model MyAuth is OAuth2Auth<[{
type: OAuth2FlowType.authorizationCode;
authorizationUrl: AUTHORIZATION_ENDPOINT;
tokenUrl: TOKEN_ENDPOINT;
refreshUrl: TOKEN_ENDPOINT;
scopes: [ .. ];
}]>;Because the source isn't public, sharing the gen'd JS in the package's distribution.
I believe the issue is rooted in the extractAndEscapeValue method ./dist/src/utils.js#133, which is called from the ODSP capability: .dist/src/entities/capabilities/onedrive-and-sharepoint.js#19-27
// utils.js
export function extractAndEscapeValue(node) {
if (!node) {
return undefined;
}
// Simply return the node value without escaping
// JSON.stringify will handle all escaping when the object is serialized
return node.value;
}@Microsoft/typespec-m365-copilot:
- Version v1.0.0