Skip to content
Merged
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
2 changes: 2 additions & 0 deletions packages/agents-a365-runtime/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This file is generated by a prebuild script.
src/version.ts
1 change: 1 addition & 0 deletions packages/agents-a365-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"module": "dist/esm/index.js",
"types": "dist/esm/index.d.ts",
"scripts": {
"prebuild": "node -p \"'export const LIB_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" > src/version.ts",
"build:cjs": "npx tsc --project tsconfig.cjs.json",
"build:esm": "npx tsc --project tsconfig.esm.json",
"build": "npm run build:cjs && npm run build:esm",
Expand Down
14 changes: 14 additions & 0 deletions packages/agents-a365-runtime/src/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

import { TurnContext } from '@microsoft/agents-hosting';
import * as jwt from 'jsonwebtoken';
import os from 'os';

import { LIB_VERSION } from './version';

/**
* Utility class providing helper methods for agent runtime operations.
Expand Down Expand Up @@ -47,4 +50,15 @@ export class Utility {

return agenticAppId;
}

Comment thread
JesuTerraz marked this conversation as resolved.
/**
* Generates a User-Agent header string containing SDK version, OS type, Node.js version, and orchestrator.
* @param orchestrator Optional orchestrator identifier to include in the User-Agent string.
* @returns Formatted User-Agent header string.
*/
public static GetUserAgentHeader(orchestrator: string = ''): string {
const osType = os.type();
const orchestratorPart = orchestrator ? `; ${orchestrator}` : '';
return `Agent365SDK/${LIB_VERSION} (${osType}; Node.js ${process.version}${orchestratorPart})`;
}
}
27 changes: 27 additions & 0 deletions tests/runtime/utility.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,31 @@ describe('Utility', () => {
expect(Utility.ResolveAgentIdentity(mockContext, '')).toEqual('00000000-0000-0000-0000-000000000000');
});
});

describe('GetUserAgentHeader', () => {
it('returns string containing version, OS, and orchestrator', () => {
// Arrange
const orchestrator = 'orch';

// Act
const header = Utility.GetUserAgentHeader(orchestrator);

// Assert
expect(header).toMatch(
/^Agent365SDK\/.+ \(.+; Node\.js v\d+(\.\d+)*; orch\)$/
);
});

it('works without orchestrator passed', () => {
// Arrange

// Act
const header = Utility.GetUserAgentHeader();

// Assert
expect(header).toMatch(
/^Agent365SDK\/.+ \(.+; Node\.js v\d+(\.\d+)*\)$/
);
});
});
});