Skip to content

Commit

Permalink
feat(assistant): Code refactor and first draft of agenda assistant
Browse files Browse the repository at this point in the history
  • Loading branch information
thomashermine committed Nov 14, 2023
1 parent bcf04da commit 07c7988
Show file tree
Hide file tree
Showing 28 changed files with 2,664 additions and 540 deletions.
80 changes: 27 additions & 53 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,33 @@
module.exports = {
root: true,
ignorePatterns: [],
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx', 'd.ts'],
},
},
"env": {
"browser": true,
"es2021": true
},
env: {
node: true,
},
extends: [
'airbnb-base',
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 12,
sourceType: 'module',
},
plugins: [
'@typescript-eslint',
'extra-rules',
"overrides": [
{
"env": {
"node": true
},
"files": [
".eslintrc.{js,cjs}"
],
"parserOptions": {
"sourceType": "script"
}
}
],
rules: {
// Following are rules we added to the airbnb-base ruleset.
'extra-rules/no-commented-out-code': 'warn',

// Following are rules we explicitly don't want to follow.
'no-console': 'off', // Logging is a good practice.
'import/extensions': ['error', 'always', { // Never allow .js .ts in imports. Make transition from .js to .ts easier.
js: 'never',
ts: 'never',
}],
'no-restricted-imports': ['error', {
name: 'pg',
importNames: ['Pool'],
message: 'Use Pool from src/utils/db instead.',
}],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
overrides: [
{
files: ['./src/**/*.test.js'],
globals: {
jest: true,
it: true,
fit: true,
describe: true,
afterAll: true,
beforeAll: true,
afterEach: true,
expect: true,
fail: true,
},
},
"plugins": [
"@typescript-eslint"
],
};

"rules": {
}
}
1 change: 0 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ jobs:
name: 🚀 Build & Push
runs-on: ubuntu-latest
steps:

# Setup
# ============================================================================================
- name: ⚙️ Setup — QEMU
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.env
node_modules
/token.json
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# assistant

A NodeJS app bridging the gap between openai/chatgpt and various tools : Home-Assistant, calendar, emails
6 changes: 3 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
preset: "ts-jest",
testEnvironment: "node",
};
20 changes: 15 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"license": "MIT",
"scripts": {
"dev": "nodemon --exec node --loader @esbuild-kit/esm-loader -r @esbuild-kit/cjs-loader src/index.ts",
"dev": "nodemon --ignore '*.json' --exec node --loader @esbuild-kit/esm-loader -r @esbuild-kit/cjs-loader src/index.ts",
"d": "yarn dev",
"start": "node --loader @esbuild-kit/esm-loader -r @esbuild-kit/cjs-loader src/index.ts",
"lint": "eslint src --max-warnings=0",
Expand All @@ -14,19 +14,29 @@
"devDependencies": {
"@esbuild-kit/esm-loader": "^2.6.5",
"@types/jest": "^29.5.6",
"@typescript-eslint/eslint-plugin": "^6.8.0",
"@typescript-eslint/parser": "^6.8.0",
"eslint": "^8.51.0",
"@typescript-eslint/eslint-plugin": "^6.11.0",
"@typescript-eslint/parser": "^6.11.0",
"eslint": "^8.2.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-plugin-extra-rules": "^0.0.0-development",
"eslint-plugin-import": "^2.25.2",
"jest": "^29.7.0",
"nodemon": "^3.0.1",
"prettier": "3.1.0",
"ts-jest": "^29.1.1",
"typescript": "^5.2.2"
},
"dependencies": {
"@esbuild-kit/cjs-loader": "^2.4.4",
"@google-cloud/local-auth": "2.1.0",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"googleapis": "105",
"homeassistant": "^0.2.0",
"openai": "^4.12.4",
"open": "^9.1.0",
"openai": "^4.17.4",
"passport": "^0.6.0",
"prompt": "^1.3.0",
"winston": "^3.11.0"
}
}
62 changes: 0 additions & 62 deletions src/_helpers/ha.ts

This file was deleted.

51 changes: 38 additions & 13 deletions src/_helpers/logs.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,44 @@

// TODO: Switch to winston, use ENV_VAR to set log level we want to see

let PROGRESS_INDEX = 0;

/**
* Log a message to the console with proper formatting
* @param {string} category - The category of the log
* @param {string} severity - The severity level of the log
* @param {...string} messages - The messages to be logged
*/
export async function log(category, severity, ...messages) {
export async function log(
category: string,
severity: string,
...messages: string[]
) {
if (severity === "debug") {
return null;
}
const emojiForCategory = {
openai: "🧠",
ha: "🏠",
google: "🔍",
app: "🤖",
prompt: "🗣️",
response: "📢",
server: "🌐",
};
const emoji = emojiForCategory[category] || "";
return console.log(emoji, `[${category.toUpperCase()}]`, ...messages);
}

//if(severity === 'debug') { return null; }
const emojiForCategory = {
'openai': '🧠',
'ha': '🏠',
'app': '🤖',
'prompt': '🗣️',
'response': '📢',
}
const emoji = emojiForCategory[category] || '';
return console.log(emoji, `[${category.toUpperCase()}]`, ...messages);
}
/**
* Logs progress bar message
* @param {string} action - The action being performed
* @param {string} [message] - Overwrite the default message entirely
*/
export function logLoading(action = "Loading", message?: string) {
const defaultMessage = `${action}${".".repeat((PROGRESS_INDEX % 3) + 1)}`;
PROGRESS_INDEX = (PROGRESS_INDEX + 1) % 3;
const messageToDisplay = message || defaultMessage;
process.stdout.clearLine(0);
process.stdout.cursorTo(0);
process.stdout.write(messageToDisplay);
}
43 changes: 0 additions & 43 deletions src/_helpers/openai.ts

This file was deleted.

6 changes: 3 additions & 3 deletions src/_helpers/sleep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
* Sleep for a given number of milliseconds.
* @param ms - The number of milliseconds to sleep for.
*/
export async function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
export async function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
Loading

0 comments on commit 07c7988

Please sign in to comment.