Skip to content

Commit

Permalink
Refactor email responder tool: remove default dbName, enhance date ha…
Browse files Browse the repository at this point in the history
…ndling, and improve table check logic
  • Loading branch information
Eduardo Soto authored and Eduardo Soto committed Jan 9, 2025
1 parent 69e9bd4 commit fbfb3fe
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions tools/email-responder/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ function escapeSqlString(str: string): string {
}

export async function run(config: CONFIG, inputs: INPUTS): Promise<OUTPUT> {
const dbName = 'default';
const tableName = 'answered_emails';

const createTableQuery = `
Expand All @@ -75,16 +74,19 @@ export async function run(config: CONFIG, inputs: INPUTS): Promise<OUTPUT> {
query: `SELECT name FROM sqlite_master WHERE type='table' AND name=?;`,
params: [tableName]
});
const tableCreated = tableCheck?.result?.length > 0;
let { emails, login_status } = await emailFetcher({ from_date: inputs.from_date, to_date: inputs.to_date });

const tableCreated = (tableCheck?.result?.length ?? 0) > 0;
let { emails, login_status } = await emailFetcher({
from_date: inputs.from_date || '',
to_date: inputs.to_date || '',
});

const answeredEmailsQuery = await shinkaiSqliteQueryExecutor({
query: `SELECT * FROM ${tableName}`,
});
if (!answeredEmailsQuery?.result) {
throw new Error('Failed to query answered emails');
}
const answeredEmails: ANSWERED_EMAIL_REGISTER[] = answeredEmailsQuery.result ?? [];
const answeredEmails: ANSWERED_EMAIL_REGISTER[] = (answeredEmailsQuery.result as ANSWERED_EMAIL_REGISTER[]) ?? [];
const mailIds: string[] = [];
const minDate = inputs.from_date ? new Date(inputs.from_date) : new Date('1970-01-01T00:00:00.000Z');
emails = emails
Expand Down

0 comments on commit fbfb3fe

Please sign in to comment.