Skip to content

Commit

Permalink
ran prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
robgruen committed Nov 13, 2024
1 parent d143314 commit 7f6b196
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 41 deletions.
32 changes: 26 additions & 6 deletions ts/packages/agents/androidMobile/src/androidMobileActionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ import {
ActionResult,
} from "@typeagent/agent-sdk";
import { createActionResult } from "@typeagent/agent-sdk/helpers/action";
import { AndroidMobileAction, AutomatePhoneUIAction, CallPhoneNumberAction, SearchNearbyAction, SendSMSAction, SetAlarmAction } from "./androidMobileSchema.js";
import {
AndroidMobileAction,
AutomatePhoneUIAction,
CallPhoneNumberAction,
SearchNearbyAction,
SendSMSAction,
SetAlarmAction,
} from "./androidMobileSchema.js";

export function instantiate(): AppAgent {
return {
Expand Down Expand Up @@ -56,14 +63,21 @@ async function handlePhotoAction(
switch (action.actionName) {
case "sendSMS": {
let smsAction = action as SendSMSAction;
result = createActionResult(`Sending SMS to ${smsAction.parameters.phoneNumber} message '${smsAction.parameters.message}'`);
result = createActionResult(
`Sending SMS to ${smsAction.parameters.phoneNumber} message '${smsAction.parameters.message}'`,
);
context.actionIO.takeAction("send-sms", smsAction.parameters);
break;
}
case "callPhoneNumber": {
let callAction = action as CallPhoneNumberAction;
result = createActionResult(`Calling ${callAction.parameters.phoneNumber}`);
context.actionIO.takeAction("call-phonenumber", callAction.parameters);
result = createActionResult(
`Calling ${callAction.parameters.phoneNumber}`,
);
context.actionIO.takeAction(
"call-phonenumber",
callAction.parameters,
);
break;
}
case "setAlarm": {
Expand All @@ -75,13 +89,19 @@ async function handlePhotoAction(
case "searchNearby": {
let nearbySearchAction = action as SearchNearbyAction;
result = createActionResult("Local search");
context.actionIO.takeAction("search-nearby", nearbySearchAction.parameters);
context.actionIO.takeAction(
"search-nearby",
nearbySearchAction.parameters,
);
break;
}
case "automateUI": {
let automateAction = action as AutomatePhoneUIAction;
result = createActionResult("Automating phone UI");
context.actionIO.takeAction("automate-phone-ui", automateAction.parameters);
context.actionIO.takeAction(
"automate-phone-ui",
automateAction.parameters,
);
break;
}
default:
Expand Down
23 changes: 14 additions & 9 deletions ts/packages/agents/androidMobile/src/androidMobileSchema.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

export type AndroidMobileAction = SendSMSAction | CallPhoneNumberAction | SetAlarmAction | SearchNearbyAction | AutomatePhoneUIAction;
export type AndroidMobileAction =
| SendSMSAction
| CallPhoneNumberAction
| SetAlarmAction
| SearchNearbyAction
| AutomatePhoneUIAction;

// sends a SMS to the supplied phone number
export type SendSMSAction = {
actionName: "sendSMS",
actionName: "sendSMS";
parameters: {
// the original request of the user
originalRequest: string;
// the phone number to message
phoneNumber: string;
// the sms message
message: string;
}
}
};
};

// calls a user's phone number but only if we know the phone number
export type CallPhoneNumberAction = {
actionName: "callPhoneNumber",
actionName: "callPhoneNumber";
parameters: {
// the original request of the user
originalRequest: string;
// the phone number to dial
phoneNumber: string;
}
}
};
};

// sets an alarm on the local mobile device
export type SetAlarmAction = {
Expand All @@ -47,7 +52,7 @@ export type SearchNearbyAction = {
// the search term to use when searching nearby locations
searchTerm: string;
};
}
};

// Automation agent on the phone that can perform UI tasks on behalf of the user
export type AutomatePhoneUIAction = {
Expand All @@ -56,4 +61,4 @@ export type AutomatePhoneUIAction = {
// the original request of the user
originalRequest: string;
};
}
};
22 changes: 11 additions & 11 deletions ts/packages/api/src/webServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import { getMimeType } from "common-utils";
import { existsSync, readFileSync, realpathSync } from "node:fs";
import { createServer, Server } from "node:http";
import { createServer as createSecureServer, Server as SecureServer } from "node:https"
import {
createServer as createSecureServer,
Server as SecureServer,
} from "node:https";
import path from "node:path";

export type TypeAgentAPIServerConfig = {
Expand All @@ -18,7 +21,6 @@ export class TypeAgentAPIWebServer {
private secureServer: SecureServer<any, any>;

constructor(config: TypeAgentAPIServerConfig) {

// web server
this.server = createServer((request: any, response: any) => {
this.serve(config, request, response);
Expand All @@ -27,14 +29,15 @@ export class TypeAgentAPIWebServer {
// secure webserver
this.secureServer = createSecureServer(
{
key: readFileSync('.cert/localhost+2-key.pem'), // path to localhost+2-key.pem
cert: readFileSync('.cert/localhost+2.pem'), // path to localhost+2.pem
key: readFileSync(".cert/localhost+2-key.pem"), // path to localhost+2-key.pem
cert: readFileSync(".cert/localhost+2.pem"), // path to localhost+2.pem
requestCert: false,
rejectUnauthorized: false,
},
(request: any, response: any) => {
this.serve(config, request, response);
});
},
);
}

serve(config: TypeAgentAPIServerConfig, request: any, response: any) {
Expand All @@ -59,9 +62,7 @@ export class TypeAgentAPIWebServer {
// serve requested file
if (existsSync(requestedFile)) {
response.writeHead(200, {
"Content-Type": getMimeType(
path.extname(requestedFile),
),
"Content-Type": getMimeType(path.extname(requestedFile)),
"Access-Control-Allow-Origin": "*",
//"Permissions-Policy": "camera=(self)", // allow access to getUserMedia() for the camera
});
Expand All @@ -74,17 +75,16 @@ export class TypeAgentAPIWebServer {
response.end("File Not Found!\n");

console.log(`Unable to serve '${request.url}', 404. ${error}`);
}
}
}

start() {

this.server.listen(3000, () => {
console.log("Listening on all local IPs at port 3000");
});

this.secureServer.listen(3443, () => {
console.log("Listening securely on all local IPs at port 3443")
console.log("Listening securely on all local IPs at port 3443");
});
}

Expand Down
1 change: 0 additions & 1 deletion ts/packages/shell/src/renderer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,5 @@
<body>
<script type="module" src="./src/main.ts"></script>
<div id="wrapper" class="wrapper"></div>
</div>
</body>
</html>
5 changes: 4 additions & 1 deletion ts/packages/shell/src/renderer/src/chatInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,10 @@ export class ChatInput {
this.attachButton.className = "chat-input-button";

getSpeechToken().then((result) => {
if (result == undefined && !Android?.isSpeechRecognitionSupported()) {
if (
result == undefined &&
!Android?.isSpeechRecognitionSupported()
) {
const button = document.querySelector<HTMLButtonElement>(
`#${buttonId}`,
)!;
Expand Down
4 changes: 3 additions & 1 deletion ts/packages/shell/src/renderer/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ document.addEventListener("DOMContentLoaded", async function () {
}

if (Android) {
Bridge.interfaces.Android.domReady((userMessage: string) => { chatView.addUserMessage(userMessage); });
Bridge.interfaces.Android.domReady((userMessage: string) => {
chatView.addUserMessage(userMessage);
});
}
});
16 changes: 12 additions & 4 deletions ts/packages/shell/src/renderer/src/speech.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,20 @@ export function recognizeOnce(
let result: speechSDK.SpeechRecognitionResult | undefined;

if (text === undefined || text === null) {
result = new speechSDK.SpeechRecognitionResult(undefined, speechSDK.ResultReason.NoMatch, text);
} else {
result = new speechSDK.SpeechRecognitionResult(undefined, speechSDK.ResultReason.RecognizedSpeech, text);
result = new speechSDK.SpeechRecognitionResult(
undefined,
speechSDK.ResultReason.NoMatch,
text,
);
} else {
result = new speechSDK.SpeechRecognitionResult(
undefined,
speechSDK.ResultReason.RecognizedSpeech,
text,
);
}

onRecognizedResult(result, inputId, buttonId, messageHandler )
onRecognizedResult(result, inputId, buttonId, messageHandler);
});
} else {
const audioConfig = getAudioConfig();
Expand Down
2 changes: 1 addition & 1 deletion ts/packages/telemetry/src/profiler/profileLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { ProfileEntry, UnreadProfileEntries } from "./profileReader.js";
import registerDebug from "debug";
import { Profiler } from "./profiler.js"
import { Profiler } from "./profiler.js";

const debug = registerDebug("typeagent:profiler");

Expand Down
6 changes: 2 additions & 4 deletions ts/packages/telemetry/src/stopWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,10 @@ export class StopWatch {
}

public log(label: string, inSeconds: boolean = true): void {
import("chalk").then(chalk => {

import("chalk").then((chalk) => {
let elapsed = `[${this.elapsedString(inSeconds)}]`;
let text = `${chalk.default.gray(label)} ${chalk.default.green(elapsed)}`;
console.log(text);

})
});
}
}
3 changes: 0 additions & 3 deletions ts/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7f6b196

Please sign in to comment.