@microsoft/agents-a365-runtime 0.1.0-preview.103

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +33 -0
  3. package/dist/cjs/agentic-authorization-service.d.ts +28 -0
  4. package/dist/cjs/agentic-authorization-service.d.ts.map +1 -0
  5. package/dist/cjs/agentic-authorization-service.js +18 -0
  6. package/dist/cjs/agentic-authorization-service.js.map +1 -0
  7. package/dist/cjs/configuration/DefaultConfigurationProvider.d.ts +39 -0
  8. package/dist/cjs/configuration/DefaultConfigurationProvider.d.ts.map +1 -0
  9. package/dist/cjs/configuration/DefaultConfigurationProvider.js +47 -0
  10. package/dist/cjs/configuration/DefaultConfigurationProvider.js.map +1 -0
  11. package/dist/cjs/configuration/IConfigurationProvider.d.ts +8 -0
  12. package/dist/cjs/configuration/IConfigurationProvider.d.ts.map +1 -0
  13. package/dist/cjs/configuration/IConfigurationProvider.js +5 -0
  14. package/dist/cjs/configuration/IConfigurationProvider.js.map +1 -0
  15. package/dist/cjs/configuration/RuntimeConfiguration.d.ts +35 -0
  16. package/dist/cjs/configuration/RuntimeConfiguration.d.ts.map +1 -0
  17. package/dist/cjs/configuration/RuntimeConfiguration.js +71 -0
  18. package/dist/cjs/configuration/RuntimeConfiguration.js.map +1 -0
  19. package/dist/cjs/configuration/RuntimeConfigurationOptions.d.ts +35 -0
  20. package/dist/cjs/configuration/RuntimeConfigurationOptions.d.ts.map +1 -0
  21. package/dist/cjs/configuration/RuntimeConfigurationOptions.js +5 -0
  22. package/dist/cjs/configuration/RuntimeConfigurationOptions.js.map +1 -0
  23. package/dist/cjs/configuration/index.d.ts +5 -0
  24. package/dist/cjs/configuration/index.d.ts.map +1 -0
  25. package/dist/cjs/configuration/index.js +23 -0
  26. package/dist/cjs/configuration/index.js.map +1 -0
  27. package/dist/cjs/environment-utils.d.ts +98 -0
  28. package/dist/cjs/environment-utils.d.ts.map +1 -0
  29. package/dist/cjs/environment-utils.js +121 -0
  30. package/dist/cjs/environment-utils.js.map +1 -0
  31. package/dist/cjs/index.d.ts +8 -0
  32. package/dist/cjs/index.d.ts.map +1 -0
  33. package/dist/cjs/index.js +26 -0
  34. package/dist/cjs/index.js.map +1 -0
  35. package/dist/cjs/operation-error.d.ts +24 -0
  36. package/dist/cjs/operation-error.d.ts.map +1 -0
  37. package/dist/cjs/operation-error.js +35 -0
  38. package/dist/cjs/operation-error.js.map +1 -0
  39. package/dist/cjs/operation-result.d.ts +41 -0
  40. package/dist/cjs/operation-result.d.ts.map +1 -0
  41. package/dist/cjs/operation-result.js +56 -0
  42. package/dist/cjs/operation-result.js.map +1 -0
  43. package/dist/cjs/power-platform-api-discovery.d.ts +30 -0
  44. package/dist/cjs/power-platform-api-discovery.d.ts.map +1 -0
  45. package/dist/cjs/power-platform-api-discovery.js +86 -0
  46. package/dist/cjs/power-platform-api-discovery.js.map +1 -0
  47. package/dist/cjs/utility.d.ts +73 -0
  48. package/dist/cjs/utility.d.ts.map +1 -0
  49. package/dist/cjs/utility.js +187 -0
  50. package/dist/cjs/utility.js.map +1 -0
  51. package/dist/cjs/version.d.ts +2 -0
  52. package/dist/cjs/version.d.ts.map +1 -0
  53. package/dist/cjs/version.js +5 -0
  54. package/dist/cjs/version.js.map +1 -0
  55. package/dist/esm/agentic-authorization-service.d.ts +28 -0
  56. package/dist/esm/agentic-authorization-service.d.ts.map +1 -0
  57. package/dist/esm/agentic-authorization-service.js +14 -0
  58. package/dist/esm/agentic-authorization-service.js.map +1 -0
  59. package/dist/esm/configuration/DefaultConfigurationProvider.d.ts +39 -0
  60. package/dist/esm/configuration/DefaultConfigurationProvider.d.ts.map +1 -0
  61. package/dist/esm/configuration/DefaultConfigurationProvider.js +43 -0
  62. package/dist/esm/configuration/DefaultConfigurationProvider.js.map +1 -0
  63. package/dist/esm/configuration/IConfigurationProvider.d.ts +8 -0
  64. package/dist/esm/configuration/IConfigurationProvider.d.ts.map +1 -0
  65. package/dist/esm/configuration/IConfigurationProvider.js +4 -0
  66. package/dist/esm/configuration/IConfigurationProvider.js.map +1 -0
  67. package/dist/esm/configuration/RuntimeConfiguration.d.ts +35 -0
  68. package/dist/esm/configuration/RuntimeConfiguration.d.ts.map +1 -0
  69. package/dist/esm/configuration/RuntimeConfiguration.js +67 -0
  70. package/dist/esm/configuration/RuntimeConfiguration.js.map +1 -0
  71. package/dist/esm/configuration/RuntimeConfigurationOptions.d.ts +35 -0
  72. package/dist/esm/configuration/RuntimeConfigurationOptions.d.ts.map +1 -0
  73. package/dist/esm/configuration/RuntimeConfigurationOptions.js +4 -0
  74. package/dist/esm/configuration/RuntimeConfigurationOptions.js.map +1 -0
  75. package/dist/esm/configuration/index.d.ts +5 -0
  76. package/dist/esm/configuration/index.d.ts.map +1 -0
  77. package/dist/esm/configuration/index.js +7 -0
  78. package/dist/esm/configuration/index.js.map +1 -0
  79. package/dist/esm/environment-utils.d.ts +98 -0
  80. package/dist/esm/environment-utils.d.ts.map +1 -0
  81. package/dist/esm/environment-utils.js +114 -0
  82. package/dist/esm/environment-utils.js.map +1 -0
  83. package/dist/esm/index.d.ts +8 -0
  84. package/dist/esm/index.d.ts.map +1 -0
  85. package/dist/esm/index.js +10 -0
  86. package/dist/esm/index.js.map +1 -0
  87. package/dist/esm/operation-error.d.ts +24 -0
  88. package/dist/esm/operation-error.d.ts.map +1 -0
  89. package/dist/esm/operation-error.js +31 -0
  90. package/dist/esm/operation-error.js.map +1 -0
  91. package/dist/esm/operation-result.d.ts +41 -0
  92. package/dist/esm/operation-result.d.ts.map +1 -0
  93. package/dist/esm/operation-result.js +52 -0
  94. package/dist/esm/operation-result.js.map +1 -0
  95. package/dist/esm/power-platform-api-discovery.d.ts +30 -0
  96. package/dist/esm/power-platform-api-discovery.d.ts.map +1 -0
  97. package/dist/esm/power-platform-api-discovery.js +82 -0
  98. package/dist/esm/power-platform-api-discovery.js.map +1 -0
  99. package/dist/esm/utility.d.ts +73 -0
  100. package/dist/esm/utility.d.ts.map +1 -0
  101. package/dist/esm/utility.js +147 -0
  102. package/dist/esm/utility.js.map +1 -0
  103. package/dist/esm/version.d.ts +2 -0
  104. package/dist/esm/version.d.ts.map +1 -0
  105. package/dist/esm/version.js +2 -0
  106. package/dist/esm/version.js.map +1 -0
  107. package/package.json +63 -0
@@ -0,0 +1,147 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import * as jwt from 'jsonwebtoken';
4
+ import os from 'os';
5
+ import fs from 'fs';
6
+ import path from 'path';
7
+ import { LIB_VERSION } from './version';
8
+ /**
9
+ * Utility class providing helper methods for agent runtime operations.
10
+ */
11
+ export class Utility {
12
+ /**
13
+ * Reads the application name from package.json at module load time.
14
+ * This ensures file I/O happens during initialization, not during requests.
15
+ *
16
+ * Note: Uses process.cwd() which assumes the application is started from its root directory.
17
+ * This is a fallback mechanism - npm_package_name (checked first in getApplicationName) is
18
+ * the preferred source as it's reliably set by npm/pnpm when running package scripts.
19
+ */
20
+ static initPackageName() {
21
+ try {
22
+ const packageJsonPath = path.resolve(process.cwd(), 'package.json');
23
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
24
+ return packageJson.name || null;
25
+ }
26
+ catch {
27
+ // TODO: Add debug-level logging once a logger implementation is available
28
+ // to help troubleshoot package.json read failures in production environments
29
+ return null;
30
+ }
31
+ }
32
+ /**
33
+ * **WARNING: NO SIGNATURE VERIFICATION** - This method uses jwt.decode() which does NOT
34
+ * verify the token signature. The token claims can be spoofed by malicious actors.
35
+ * This method is ONLY suitable for logging, analytics, and diagnostics purposes.
36
+ * Do NOT use the returned value for authorization, access control, or security decisions.
37
+ *
38
+ * Decodes the current token and retrieves the App ID (appid or azp claim).
39
+ *
40
+ * Note: Returns a default GUID ('00000000-0000-0000-0000-000000000000') for empty tokens
41
+ * for backward compatibility with callers that expect a valid-looking GUID.
42
+ * For agent identification where empty string is preferred, use {@link getAgentIdFromToken}.
43
+ *
44
+ * @param token Token to Decode
45
+ * @returns AppId, or default GUID for empty token, or empty string if decode fails
46
+ */
47
+ static GetAppIdFromToken(token) {
48
+ if (!token || token.trim() === '') {
49
+ return '00000000-0000-0000-0000-000000000000';
50
+ }
51
+ try {
52
+ const decoded = jwt.decode(token);
53
+ if (!decoded) {
54
+ return '';
55
+ }
56
+ // Look for appid claim first, then azp claim as fallback
57
+ const appIdClaim = decoded['appid'] || decoded['azp'];
58
+ return appIdClaim || '';
59
+ }
60
+ catch (_error) {
61
+ // Silent error handling - return empty string on decode failure
62
+ return '';
63
+ }
64
+ }
65
+ /**
66
+ * **WARNING: NO SIGNATURE VERIFICATION** - This method uses jwt.decode() which does NOT
67
+ * verify the token signature. The token claims can be spoofed by malicious actors.
68
+ * This method is ONLY suitable for logging, analytics, and diagnostics purposes.
69
+ * Do NOT use the returned value for authorization, access control, or security decisions.
70
+ *
71
+ * Decodes the token and retrieves the best available agent identifier.
72
+ * Checks claims in priority order: xms_par_app_azp (agent blueprint ID) > appid > azp.
73
+ *
74
+ * Note: Returns empty string for empty/missing tokens (unlike {@link GetAppIdFromToken} which
75
+ * returns a default GUID). This allows callers to omit headers when no identifier is available.
76
+ *
77
+ * @param token JWT token to decode
78
+ * @returns Agent ID (GUID) or empty string if not found or token is empty
79
+ */
80
+ static getAgentIdFromToken(token) {
81
+ if (!token || token.trim() === '') {
82
+ return '';
83
+ }
84
+ try {
85
+ const decoded = jwt.decode(token);
86
+ if (!decoded) {
87
+ return '';
88
+ }
89
+ // Priority: xms_par_app_azp (agent blueprint ID) > appid > azp
90
+ return decoded['xms_par_app_azp'] || decoded['appid'] || decoded['azp'] || '';
91
+ }
92
+ catch (_error) {
93
+ // Silent error handling - return empty string on decode failure
94
+ return '';
95
+ }
96
+ }
97
+ /**
98
+ * Resolves the agent identity from the turn context or auth token.
99
+ * @param context Turn Context of the turn.
100
+ * @param authToken Auth token if available.
101
+ * @returns Agent identity (App ID)
102
+ */
103
+ static ResolveAgentIdentity(context, authToken) {
104
+ // App ID is required to pass to MCP server URL.
105
+ const agenticAppId = context.activity.isAgenticRequest()
106
+ ? context.activity.getAgenticInstanceId() || ''
107
+ : this.GetAppIdFromToken(authToken);
108
+ return agenticAppId;
109
+ }
110
+ /**
111
+ * Generates a User-Agent header string containing SDK version, OS type, Node.js version, and orchestrator.
112
+ * @param orchestrator Optional orchestrator identifier to include in the User-Agent string.
113
+ * @returns Formatted User-Agent header string.
114
+ */
115
+ static GetUserAgentHeader(orchestrator) {
116
+ const osType = os.type();
117
+ const orchestratorPart = orchestrator ? `; ${orchestrator}` : '';
118
+ return `Agent365SDK/${LIB_VERSION} (${osType}; Node.js ${process.version}${orchestratorPart})`;
119
+ }
120
+ /**
121
+ * Gets the application name from npm_package_name environment variable or package.json.
122
+ * The package.json result is cached at module load time to avoid sync I/O during requests.
123
+ * @returns Application name or undefined if not available.
124
+ */
125
+ static getApplicationName() {
126
+ // First try npm_package_name (set automatically by npm/pnpm when running scripts)
127
+ // eslint-disable-next-line no-restricted-properties -- npm_package_name is set by npm at runtime, not a configurable setting
128
+ if (process.env.npm_package_name) {
129
+ // eslint-disable-next-line no-restricted-properties -- npm_package_name is set by npm at runtime, not a configurable setting
130
+ return process.env.npm_package_name;
131
+ }
132
+ // Fall back to cached package.json name (read at module load time)
133
+ return this.cachedPackageName || undefined;
134
+ }
135
+ /**
136
+ * Resets the cached application name. Used for testing purposes.
137
+ * @internal
138
+ */
139
+ static resetApplicationNameCache() {
140
+ this.cachedPackageName = Utility.initPackageName();
141
+ }
142
+ }
143
+ // Cache for application name read from package.json
144
+ // null = checked but not found, string = found
145
+ // Eagerly initialized at module load time to avoid sync I/O during requests
146
+ Utility.cachedPackageName = Utility.initPackageName();
147
+ //# sourceMappingURL=utility.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utility.js","sourceRoot":"","sources":["../../src/utility.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,KAAK,GAAG,M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;QAC7H,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;YACjC,6HAA6H;YAC7H,OAAO,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;QACtC,CAAC;QAED,mEAAmE;QACnE,OAAO,IAAI,CAAC,iBAAiB,IAAI,SAAS,CAAC;IAC7C,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,yBAAyB;QACrC,IAAI,CAAC,iBAAiB,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IACrD,CAAC;;AA9ID,oDAAoD;AACpD,+CAA+C;AAC/C,4EAA4E;AAC7D,yBAAiB,GAAkB,OAAO,CAAC,eAAe,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const LIB_VERSION = "0.1.0-preview.103";
2
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,sBAAsB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export const LIB_VERSION = "0.1.0-preview.103";
2
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,mBAAmB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@microsoft/agents-a365-runtime",
3
+ "version": "0.1.0-preview.103",
4
+ "description": "Agent 365 Runtime SDK for AI agents built with TypeScript/Node.js",
5
+ "main": "dist/cjs/index.js",
6
+ "module": "dist/esm/index.js",
7
+ "types": "dist/esm/index.d.ts",
8
+ "keywords": [
9
+ "ai",
10
+ "agents",
11
+ "azure",
12
+ "typescript"
13
+ ],
14
+ "author": "Microsoft Corporation",
15
+ "license": "MIT",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/microsoft/Agent365-nodejs.git",
19
+ "directory": "packages/agents-a365-runtime"
20
+ },
21
+ "dependencies": {
22
+ "@azure/identity": "^4.12.1",
23
+ "@microsoft/agents-hosting": "^1.1.0-alpha.85",
24
+ "jsonwebtoken": "^9.0.3"
25
+ },
26
+ "devDependencies": {
27
+ "@eslint/js": "^9.39.1",
28
+ "@types/jest": "^30.0.0",
29
+ "@types/jsonwebtoken": "^9.0.10",
30
+ "@types/node": "^20.17.0",
31
+ "@typescript-eslint/eslint-plugin": "^8.47.0",
32
+ "@typescript-eslint/parser": "^8.47.0",
33
+ "eslint": "^9.39.1",
34
+ "jest": "^30.2.0",
35
+ "rimraf": "^6.0.0",
36
+ "ts-jest": "^29.4.5",
37
+ "typescript": "^5.9.3",
38
+ "typescript-eslint": "^8.47.0"
39
+ },
40
+ "engines": {
41
+ "node": ">=18.0.0"
42
+ },
43
+ "files": [
44
+ "dist/**/*",
45
+ "README.md",
46
+ "CHANGELOG.md",
47
+ "LICENSE.md"
48
+ ],
49
+ "scripts": {
50
+ "prebuild": "node -p \"'export const LIB_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" > src/version.ts",
51
+ "build:cjs": "npx tsc --project tsconfig.cjs.json",
52
+ "build:esm": "npx tsc --project tsconfig.esm.json",
53
+ "build": "npm run build:cjs && npm run build:esm",
54
+ "build:watch": "npx tsc --watch",
55
+ "clean": "npx rimraf dist",
56
+ "test": "jest --passWithNoTests",
57
+ "test:watch": "jest --watch",
58
+ "lint": "eslint src",
59
+ "lint:fix": "eslint src --fix",
60
+ "ci": "npm ci",
61
+ "pack": "node ../../copyFiles.js . && pnpm pack --pack-destination=../"
62
+ }
63
+ }