-
Notifications
You must be signed in to change notification settings - Fork 2
feat: agents apis #375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: agents apis #375
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /** | ||
| * This file is the custom implementation of the Agents client (src/api/resources/agents/client/Client.ts) | ||
| * | ||
| * It extends the auto-generated Agents class and adds custom helper methods. | ||
| * | ||
| * All the patches marked with `// Patch: ...` comments. | ||
| */ | ||
|
|
||
| import { AgentsClient } from "../../api/resources/agents/client/Client.js"; | ||
| import * as core from "../../core/index.js"; | ||
|
|
||
| export class CustomAgents extends AgentsClient { | ||
| /** | ||
| * Patch: added helper method to get agent card URL | ||
|
markitosha marked this conversation as resolved.
Outdated
|
||
| * | ||
| * Returns the URL for the agent card JSON file. | ||
| * | ||
| * @param {string} agentId - The ID of the agentW | ||
| * @returns {Promise<URL>} The URL for the agent card | ||
| * | ||
| * @example | ||
| * const url = await client.agents.getAgentCardUrl("agent-123"); | ||
|
tve-corti marked this conversation as resolved.
Outdated
|
||
| */ | ||
| public getCardUrl = async (agentId: string): Promise<URL> => | ||
| new URL(`/agents/${agentId}/agent-card.json`, (await core.Supplier.get(this._options.environment)).agents); | ||
|
tve-corti marked this conversation as resolved.
Outdated
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| import { CortiClient } from "../../src/custom/CortiClient"; | ||
|
|
||
| describe("cortiClient.agents.getCardUrl", () => { | ||
| describe("with client credentials", () => { | ||
| it("should return correct URL for agent card", async () => { | ||
| const agentId = "test-agent-123"; | ||
| const mockTenantName = "test-tenant"; | ||
|
|
||
| const cortiClient = new CortiClient({ | ||
| environment: "eu", | ||
| tenantName: mockTenantName, | ||
| auth: { | ||
| clientId: "test-client-id", | ||
| clientSecret: "test-client-secret", | ||
| }, | ||
| }); | ||
|
|
||
| const url = await cortiClient.agents.getCardUrl(agentId); | ||
|
|
||
| expect(url).toBeInstanceOf(URL); | ||
| expect(url.toString()).toBe(`https://api.eu.corti.app/agents/${agentId}/agent-card.json`); | ||
| }); | ||
|
|
||
| it("should handle different agent IDs correctly", async () => { | ||
| const agentIds = ["agent-1", "550e8400-e29b-41d4-a716-446655440000", "my-custom-agent"]; | ||
|
|
||
| const cortiClient = new CortiClient({ | ||
| environment: "us", | ||
| tenantName: "prod-tenant", | ||
| auth: { | ||
| clientId: "test-client-id", | ||
| clientSecret: "test-client-secret", | ||
| }, | ||
| }); | ||
|
|
||
| for (const agentId of agentIds) { | ||
| const url = await cortiClient.agents.getCardUrl(agentId); | ||
|
|
||
| expect(url).toBeInstanceOf(URL); | ||
| expect(url.toString()).toBe(`https://api.us.corti.app/agents/${agentId}/agent-card.json`); | ||
| } | ||
| }); | ||
|
|
||
| it("should work with dev environment", async () => { | ||
| const agentId = "test-agent"; | ||
|
|
||
| const cortiClient = new CortiClient({ | ||
| environment: "dev-eu", | ||
| tenantName: "dev-tenant", | ||
| auth: { | ||
| clientId: "test-client-id", | ||
| clientSecret: "test-client-secret", | ||
| }, | ||
| }); | ||
|
|
||
| const url = await cortiClient.agents.getCardUrl(agentId); | ||
|
|
||
| expect(url).toBeInstanceOf(URL); | ||
| expect(url.toString()).toBe(`https://api.dev-eu.corti.app/agents/${agentId}/agent-card.json`); | ||
| }); | ||
| }); | ||
|
|
||
| describe("with bearer token", () => { | ||
| it("should return correct URL for agent card", async () => { | ||
| const agentId = "bearer-agent-456"; | ||
|
|
||
| // Helper function to create a mock JWT | ||
| const createMockJWT = (environment: string, tenant: string, expiresInSeconds: number = 3600): string => { | ||
| const header = { alg: "RS256", typ: "JWT" }; | ||
| const payload = { | ||
| iss: `https://keycloak.${environment}.corti.app/realms/${tenant}`, | ||
| exp: Math.floor(Date.now() / 1000) + expiresInSeconds, | ||
| iat: Math.floor(Date.now() / 1000), | ||
| }; | ||
|
|
||
| const base64UrlEncode = (str: string) => { | ||
| return Buffer.from(str) | ||
| .toString("base64") | ||
| .replace(/\+/g, "-") | ||
| .replace(/\//g, "_") | ||
| .replace(/=/g, ""); | ||
| }; | ||
|
|
||
| const encodedHeader = base64UrlEncode(JSON.stringify(header)); | ||
| const encodedPayload = base64UrlEncode(JSON.stringify(payload)); | ||
| const signature = "mock-signature"; | ||
|
|
||
| return `${encodedHeader}.${encodedPayload}.${signature}`; | ||
| }; | ||
|
|
||
| const mockAccessToken = createMockJWT("eu", "test-tenant"); | ||
|
|
||
| const cortiClient = new CortiClient({ | ||
| auth: { | ||
| accessToken: mockAccessToken, | ||
| refreshToken: "mock-refresh-token", | ||
| }, | ||
| }); | ||
|
|
||
| const url = await cortiClient.agents.getCardUrl(agentId); | ||
|
|
||
| expect(url).toBeInstanceOf(URL); | ||
| expect(url.toString()).toContain(`/agents/${agentId}/agent-card.json`); | ||
| }); | ||
| }); | ||
|
|
||
| describe("URL encoding", () => { | ||
| it("should handle special characters in agent ID", async () => { | ||
| const agentId = "agent with spaces"; | ||
| const cortiClient = new CortiClient({ | ||
| environment: "eu", | ||
| tenantName: "test-tenant", | ||
| auth: { | ||
| clientId: "test-client-id", | ||
| clientSecret: "test-client-secret", | ||
| }, | ||
| }); | ||
|
|
||
| const url = await cortiClient.agents.getCardUrl(agentId); | ||
|
|
||
| expect(url).toBeInstanceOf(URL); | ||
| // The URL constructor should handle encoding | ||
| expect(url.pathname).toContain("agent-card.json"); | ||
| }); | ||
|
tve-corti marked this conversation as resolved.
Outdated
|
||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.