Skip to content

Commit

Permalink
ran prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
robgruen committed Oct 31, 2024
1 parent 74b6a41 commit 70b9068
Show file tree
Hide file tree
Showing 23 changed files with 294 additions and 213 deletions.
2 changes: 1 addition & 1 deletion ts/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ module.exports = {
moduleNameMapper: {
"^../src/(.*)$": "<rootDir>/dist/$1",
},
testTimeout: 30000
testTimeout: 30000,
};
7 changes: 6 additions & 1 deletion ts/packages/agentSdk/src/display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ export type DisplayMessageKind =

export type DisplayAppendMode = "inline" | "block" | "temporary";

export type ClientAction = "show-camera" | "open-app" | "show-notification" | "start-intent" | "set-alarm";
export type ClientAction =
| "show-camera"
| "open-app"
| "show-notification"
| "start-intent"
| "set-alarm";

export interface ActionIO {
readonly type: DisplayType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type SetAlarmAction = {
// the original request of the user
originalRequest: string;
// the time for the alarm in the format YYYY-mm-ddThh:mm:ss (i.e. 2024-02-15T08:30:15 )
time: string
time: string;
};
};

Expand Down
1 change: 0 additions & 1 deletion ts/packages/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ assert(envPath, ".env file not found!");

const typeAgentServer: TypeAgentServer = new TypeAgentServer(envPath);
typeAgentServer.start();

17 changes: 12 additions & 5 deletions ts/packages/api/src/typeAgentServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ import {
import { WebAPIClientIO } from "./webClientIO.js";
import { TypeAgentAPIWebSocketServer } from "./webSocketServer.js";


export class TypeAgentServer {
private dispatcher: Dispatcher | undefined;
private webClientIO: WebAPIClientIO | undefined;
private webSocketServer: TypeAgentAPIWebSocketServer | undefined;
private webServer: TypeAgentAPIWebServer | undefined;

constructor(private envPath: string, private wsPort: number = 3030) {
constructor(
private envPath: string,
private wsPort: number = 3030,
) {
// typeAgent config
dotenv.config({ path: this.envPath });
}
Expand All @@ -36,9 +38,14 @@ export class TypeAgentServer {
});

// websocket server
const hostEndpoint = process.env["WEBSOCKET_HOST"] ?? `ws://localhost:${this.wsPort}`;
const hostEndpoint =
process.env["WEBSOCKET_HOST"] ?? `ws://localhost:${this.wsPort}`;
const url = new URL(hostEndpoint);
this.webSocketServer = new TypeAgentAPIWebSocketServer(url, this.dispatcher, this.webClientIO!);
this.webSocketServer = new TypeAgentAPIWebSocketServer(
url,
this.dispatcher,
this.webClientIO!,
);

// web server config
const config: TypeAgentAPIServerConfig = JSON.parse(
Expand All @@ -54,4 +61,4 @@ export class TypeAgentServer {
this.webServer?.stop();
this.webSocketServer?.stop();
}
}
}
13 changes: 7 additions & 6 deletions ts/packages/api/test/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { TypeAgentServer } from "../src/typeAgentServer.js";
import findConfig from "find-config";

describe("api web/ws server", () => {

it("verify web server respnses", async () => {

const envPath = findConfig(".env");
if (envPath !== null) {
assert(envPath, ".env file not found!");
const typeAgentServer: TypeAgentServer = new TypeAgentServer(envPath!);
const typeAgentServer: TypeAgentServer = new TypeAgentServer(
envPath!,
);
await typeAgentServer.start();

let response = await fetch("http://localhost:3000/");
Expand All @@ -26,8 +26,9 @@ describe("api web/ws server", () => {

typeAgentServer.stop();
} else {
console.warn("Skipping test 'verify web server respnses', no .env file!");
console.warn(
"Skipping test 'verify web server respnses', no .env file!",
);
}
})
});
});

2 changes: 1 addition & 1 deletion ts/packages/dispatcher/src/agent/agentProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ function getActionContextShim(
rpc.send("takeAction", {
actionContextId,
action,
data
data,
});
},
};
Expand Down
8 changes: 6 additions & 2 deletions ts/packages/dispatcher/src/agent/agentProcessShim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
CommandDescriptors,
ParsedCommandParams,
ParameterDefinitions,
ClientAction
ClientAction,
} from "@typeagent/agent-sdk";
import {
AgentCallFunctions,
Expand Down Expand Up @@ -244,7 +244,11 @@ export async function createAgentProcessShim(
.get(param.actionContextId)
.actionIO.appendDisplay(param.content, param.mode);
},
takeAction: (param: { actionContextId: number; action: ClientAction, data?: unknown }) => {
takeAction: (param: {
actionContextId: number;
action: ClientAction;
data?: unknown;
}) => {
actionContextMap
.get(param.actionContextId)
.actionIO.takeAction(param.action, param.data);
Expand Down
6 changes: 5 additions & 1 deletion ts/packages/dispatcher/src/agent/agentProcessTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ export type AgentContextCallFunctions = {
content: DisplayContent;
mode: DisplayAppendMode;
}) => void;
takeAction: (param: { actionContextId: number; action: ClientAction, data?: unknown }) => void;
takeAction: (param: {
actionContextId: number;
action: ClientAction;
data?: unknown;
}) => void;
};

export type AgentContextInvokeFunctions = {
Expand Down
2 changes: 1 addition & 1 deletion ts/packages/shell/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"typechat": "^0.1.1",
"ws": "^8.17.1"
},
"devDependencies": {
"devDependencies": {
"@electron-toolkit/tsconfig": "^1.0.1",
"@types/debug": "^4.1.10",
"@types/dompurify": "^3.0.5",
Expand Down
2 changes: 1 addition & 1 deletion ts/packages/shell/src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { AppAgentEvent, DisplayAppendMode } from "@typeagent/agent-sdk";
import { shellAgentProvider } from "./agent.js";
import { BrowserAgentIpc } from "./browserIpc.js";
import { WebSocketMessage } from "common-utils";
import { AzureSpeech } from "./azureSpeech.js"
import { AzureSpeech } from "./azureSpeech.js";
import { auth } from "aiclient";

console.log(auth.AzureTokenScopes.CogServices);
Expand Down
12 changes: 10 additions & 2 deletions ts/packages/shell/src/preload/electronTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ export interface ClientSettingsProvider {

export type DisplayType = "html" | "iframe" | "text";

export type ClientActions = "show-camera" | "open-app" | "show-notification" | "start-intent";
export type ClientActions =
| "show-camera"
| "open-app"
| "show-notification"
| "start-intent";

// end duplicate type section

Expand Down Expand Up @@ -187,7 +191,11 @@ export interface ClientAPI {
) => void,
): void;
onTakeAction(
callback: (e: Electron.IpcRendererEvent, action: string, data: unknown) => void,
callback: (
e: Electron.IpcRendererEvent,
action: string,
data: unknown,
) => void,
);
}

Expand Down
71 changes: 46 additions & 25 deletions ts/packages/shell/src/renderer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
<link href="./assets/cameraStyles.less" type="text/css" rel="stylesheet" />
<link href="./assets/carousel.less" type="text/css" rel="stylesheet" />
<link href="./assets/loading.less" type="text/css" rel="stylesheet" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"
crossorigin="anonymous"
/>
</head>
<body>
<script type="module" src="./src/main.ts"></script>
Expand All @@ -26,43 +29,61 @@
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<a class="navbar-brand" href="/">Microsoft identity platform</a>
<div class="btn-group ml-auto dropleft">
<button type="button" id="SignIn" class="btn btn-secondary" onclick="signIn()">
<button
type="button"
id="SignIn"
class="btn btn-secondary"
onclick="signIn()"
>
Sign In
</button>
</div>
</nav>
<br>
<h5 class="card-header text-center">Vanilla JavaScript SPA calling MS Graph API with MSAL.js</h5>
<br>
<div class="row" style="margin:auto">
<div id="card-div" class="col-md-3" style="display:none">
<br />
<h5 class="card-header text-center">
Vanilla JavaScript SPA calling MS Graph API with MSAL.js
</h5>
<br />
<div class="row" style="margin: auto">
<div id="card-div" class="col-md-3" style="display: none">
<div class="card text-center">
<div class="card-body">
<h5 class="card-title" id="WelcomeMessage">Please sign-in to see your profile and read your mails</h5>
<h5 class="card-title" id="WelcomeMessage">
Please sign-in to see your profile and read your mails
</h5>
<div id="profile-div"></div>
<br>
<br>
<button class="btn btn-primary" id="seeProfile" onclick="seeProfile()">See Profile</button>
<br>
<br>
<button class="btn btn-primary" id="readMail" onclick="readMail()">Read Mails</button>
<br />
<br />
<button
class="btn btn-primary"
id="seeProfile"
onclick="seeProfile()"
>
See Profile
</button>
<br />
<br />
<button
class="btn btn-primary"
id="readMail"
onclick="readMail()"
>
Read Mails
</button>
</div>
</div>
</div>
<br>
<br>
<br />
<br />
<div class="col-md-4">
<div class="list-group" id="list-tab" role="tablist">
</div>
<div class="list-group" id="list-tab" role="tablist"></div>
</div>
<div class="col-md-5">
<div class="tab-content" id="nav-tabContent">
</div>
<div class="tab-content" id="nav-tabContent"></div>
</div>
</div>
<br>
<br>

<br />
<br />
</div>
</body>
</html>
59 changes: 30 additions & 29 deletions ts/packages/shell/src/renderer/src/auth/authConfig.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,57 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import * as msal from "@azure/msal-browser"
import * as msal from "@azure/msal-browser";

/**
* Configuration object to be passed to MSAL instance on creation.
* Configuration object to be passed to MSAL instance on creation.
* For a full list of MSAL.js configuration parameters, visit:
* https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/configuration.md
* https://github.com/AzureAD/microsoft-authentication-library-for-js/blob/dev/lib/msal-browser/docs/configuration.md
*/
export const msalConfig = {
auth: {
// 'Application (client) ID' of app registration in Azure portal - this value is a GUID
clientId: "de5757b7-986f-4f02-aea1-395670da6da0",
//clientId: "04b07795-8ddb-461a-bbee-02f9e1bf7b46",
// Full directory URL, in the form of https://login.microsoftonline.com/<tenant-id>
authority: "https://login.microsoftonline.com/72f988bf-86f1-41af-91ab-2d7cd011db47",
authority:
"https://login.microsoftonline.com/72f988bf-86f1-41af-91ab-2d7cd011db47",
// Full redirect URL, in form of http://localhost:3000
redirectUri: "http://localhost:3000/",
},
cache: {
cacheLocation: "sessionStorage", // This configures where your cache will be stored
storeAuthStateInCookie: false, // Set this to "true" if you are having issues on IE11 or Edge
},
system: {
loggerOptions: {
loggerCallback: (level, message, containsPii) => {
if (containsPii) {
return;
}
switch (level) {
case msal.LogLevel.Error:
console.error(message);
return;
case msal.LogLevel.Info:
console.info(message);
return;
case msal.LogLevel.Verbose:
console.debug(message);
return;
case msal.LogLevel.Warning:
console.warn(message);
return;
}
}
}
}
system: {
loggerOptions: {
loggerCallback: (level, message, containsPii) => {
if (containsPii) {
return;
}
switch (level) {
case msal.LogLevel.Error:
console.error(message);
return;
case msal.LogLevel.Info:
console.info(message);
return;
case msal.LogLevel.Verbose:
console.debug(message);
return;
case msal.LogLevel.Warning:
console.warn(message);
return;
}
},
},
},
};

/**
* Scopes you add here will be prompted for user consent during sign-in.
* By default, MSAL.js will add OIDC scopes (openid, profile, email) to any login request.
* For more information about OIDC scopes, visit:
* For more information about OIDC scopes, visit:
* https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-permissions-and-consent#openid-connect-scopes
*/
export const loginRequest = {
Expand All @@ -63,5 +64,5 @@ export const loginRequest = {
*/
export const tokenRequest = {
scopes: ["https://cognitiveservices.azure.com/.default"],
forceRefresh: false // Set this to "true" to skip a cached token and go to the server to get a new token
forceRefresh: false, // Set this to "true" to skip a cached token and go to the server to get a new token
};
Loading

0 comments on commit 70b9068

Please sign in to comment.