From 7dd7c93033636acde18959d46f31a5089cc059d4 Mon Sep 17 00:00:00 2001 From: Travis Fischer Date: Sat, 10 Jun 2023 17:50:52 -0700 Subject: [PATCH] chore: adjust eslint rules --- legacy/.eslintrc | 7 ++++++- legacy/src/llms/llm.ts | 2 ++ legacy/src/logging.ts | 1 + legacy/src/services/novu.ts | 1 + legacy/src/services/twilio-conversation.ts | 13 ++++++++++++- legacy/test/_utils.ts | 1 + legacy/test/twilio-conversation.test.ts | 4 ++++ 7 files changed, 27 insertions(+), 2 deletions(-) diff --git a/legacy/.eslintrc b/legacy/.eslintrc index b20915ec..70f7e354 100644 --- a/legacy/.eslintrc +++ b/legacy/.eslintrc @@ -22,7 +22,12 @@ "no-useless-catch": "warn", "@typescript-eslint/no-extra-semi": "off", "@typescript-eslint/no-non-null-assertion": "off", - "@typescript-eslint/no-explicit-any": "off" + "@typescript-eslint/no-explicit-any": "off", + "padding-line-between-statements": [ + "error", + { "blankLine": "always", "prev": ["block", "block-like"], "next": "*" }, + { "blankLine": "always", "prev": "*", "next": ["block", "block-like"] } + ] }, "overrides": [ { diff --git a/legacy/src/llms/llm.ts b/legacy/src/llms/llm.ts index fea0b0a8..2882ac6e 100644 --- a/legacy/src/llms/llm.ts +++ b/legacy/src/llms/llm.ts @@ -109,6 +109,7 @@ export abstract class BaseLLM< } const tokenizer = await this._tokenizerP + if (tokenizer) { return tokenizer.encode(text).length } @@ -255,6 +256,7 @@ export abstract class BaseChatModel< } const booleanOutput = booleanOutputs[output] + if (booleanOutput !== undefined) { output = booleanOutput } else { diff --git a/legacy/src/logging.ts b/legacy/src/logging.ts index 3d4bfbbe..b84d15b2 100644 --- a/legacy/src/logging.ts +++ b/legacy/src/logging.ts @@ -26,6 +26,7 @@ type SeverityType = (typeof Severity)[keyof typeof Severity] * Define minimum LOG_LEVEL, defaulting to Severity.INFO if not provided or if an invalid value is provided. Any events below that level won't be logged to the console. */ let LOG_LEVEL: SeverityType = Severity.INFO + if ( process.env.DEBUG_LOG_LEVEL && Severity[process.env.DEBUG_LOG_LEVEL.toUpperCase()] !== undefined diff --git a/legacy/src/services/novu.ts b/legacy/src/services/novu.ts index 45534bf1..6e3f4fc1 100644 --- a/legacy/src/services/novu.ts +++ b/legacy/src/services/novu.ts @@ -32,6 +32,7 @@ export class NovuClient { if (!apiKey) { throw new Error(`Error NovuClient missing required "apiKey"`) } + this.apiKey = apiKey this.baseUrl = baseUrl } diff --git a/legacy/src/services/twilio-conversation.ts b/legacy/src/services/twilio-conversation.ts index 158b00a5..2b4dda1a 100644 --- a/legacy/src/services/twilio-conversation.ts +++ b/legacy/src/services/twilio-conversation.ts @@ -148,11 +148,13 @@ export class TwilioConversationClient { `Error TwilioConversationClient missing required "accountSid" and/or "authToken"` ) } + if (!phoneNumber) { throw new Error( `Error TwilioConversationClient missing required "phoneNumber"` ) } + this.phoneNumber = phoneNumber this.api = ky.create({ prefixUrl: baseUrl, @@ -239,7 +241,7 @@ export class TwilioConversationClient { * * ### Notes * - * - The implementation will poll for replies to the message until the timeout is reached. This is not ideal, but it is the only way to retrieve replies without spinning up a local server to receive webhook events. + * - The implementation will poll for replies to the message until the timeout is reached. This is not ideal, but it is the only way to retrieve replies without spinning up a local server to receive webhook events. */ public async sendAndWaitForReply({ text, @@ -262,36 +264,45 @@ export class TwilioConversationClient { const { sid: conversationSid } = await this.createConversation(name) await this.addParticipant({ conversationSid, recipientPhoneNumber }) await this.sendMessage({ conversationSid, text }) + const start = Date.now() let nUserMessages = 0 + do { if (aborted) { await this.deleteConversation(conversationSid) const reason = stopSignal?.reason || 'Aborted waiting for reply' + if (reason instanceof Error) { throw reason } else { throw new Error(reason) } } + const response = await this.fetchMessages(conversationSid) + if (response.messages.length > 1) { const candidates = response.messages.filter( (message) => message.author !== BOT_NAME ) const candidate = candidates[candidates.length - 1] + if (validate(candidate)) { await this.deleteConversation(conversationSid) return candidate } + if (nUserMessages !== candidates.length) { await this.sendMessage({ text: `Invalid response: ${candidate.body}. Please try again with a valid response format.`, conversationSid }) } + nUserMessages = candidates.length } + await sleep(intervalMs) } while (Date.now() - start < timeoutMs) diff --git a/legacy/test/_utils.ts b/legacy/test/_utils.ts index 890d7293..f8589980 100644 --- a/legacy/test/_utils.ts +++ b/legacy/test/_utils.ts @@ -27,6 +27,7 @@ const keyv = new Keyv({ store: keyvRedis, namespace: 'agentic-test' }) // TODO: this is a lil hacky const keyvHas = (keyv.has as any).bind(keyv) + keyv.has = async (key, ...rest) => { if (refreshTestCache) { return undefined diff --git a/legacy/test/twilio-conversation.test.ts b/legacy/test/twilio-conversation.test.ts index 5b0da74a..f815b927 100644 --- a/legacy/test/twilio-conversation.test.ts +++ b/legacy/test/twilio-conversation.test.ts @@ -8,6 +8,7 @@ test('TwilioConversationClient.createConversation', async (t) => { if (!process.env.TWILIO_ACCOUNT_SID || !process.env.TWILIO_AUTH_TOKEN) { return t.pass() } + const client = new TwilioConversationClient() const friendlyName = 'create-conversation-test' @@ -25,6 +26,7 @@ test('TwilioConversationClient.addParticipant', async (t) => { ) { return t.pass() } + const client = new TwilioConversationClient() const { sid: conversationSid } = await client.createConversation( @@ -43,6 +45,7 @@ test('TwilioConversationClient.sendMessage', async (t) => { if (!process.env.TWILIO_ACCOUNT_SID || !process.env.TWILIO_AUTH_TOKEN) { return t.pass() } + const client = new TwilioConversationClient() const text = 'Hello, world!' @@ -59,6 +62,7 @@ test('TwilioConversationClient.fetchMessages', async (t) => { if (!process.env.TWILIO_ACCOUNT_SID || !process.env.TWILIO_AUTH_TOKEN) { return t.pass() } + const client = new TwilioConversationClient() const { sid: conversationSid } = await client.createConversation(