From 6a4e1ce111acb9b1e447b25d13743ff28274ee92 Mon Sep 17 00:00:00 2001 From: Tim Date: Sat, 2 Dec 2023 21:22:35 +1300 Subject: [PATCH] use unique symbols for config tags --- package.json | 4 ++-- pnpm-lock.yaml | 36 ++++++++++++++++++------------------ src/AutoThreads.ts | 12 +++++++++--- src/Github.ts | 10 ++++++---- src/NoEmbed.ts | 11 +++++++---- src/OpenAI.ts | 10 ++++++---- src/Summarizer.ts | 6 +----- src/main.ts | 6 +++--- src/utils/Layer.ts | 2 +- 9 files changed, 53 insertions(+), 44 deletions(-) diff --git a/package.json b/package.json index 445592c..5c27af0 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "license": "ISC", "devDependencies": { "@octokit/types": "^12.3.0", - "@types/node": "^20.10.1", + "@types/node": "^20.10.2", "tsc-watch": "^6.0.4", "typescript": "^5.3.2" }, @@ -25,7 +25,7 @@ "@effect/platform-node": "^0.33.4", "@effect/schema": "^0.51.1", "cron-parser": "^4.9.0", - "dfx": "^0.77.2", + "dfx": "^0.77.3", "dotenv": "^16.3.1", "effect": "2.0.0-next.58", "gpt-tokenizer": "^2.1.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ac11976..f768319 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -15,8 +15,8 @@ dependencies: specifier: ^4.9.0 version: 4.9.0 dfx: - specifier: ^0.77.2 - version: 0.77.2(@effect/platform@0.32.2)(effect@2.0.0-next.58) + specifier: ^0.77.3 + version: 0.77.3(@effect/platform@0.32.2)(effect@2.0.0-next.58) dotenv: specifier: ^16.3.1 version: 16.3.1 @@ -44,8 +44,8 @@ devDependencies: specifier: ^12.3.0 version: 12.3.0 '@types/node': - specifier: ^20.10.1 - version: 20.10.1 + specifier: ^20.10.2 + version: 20.10.2 tsc-watch: specifier: ^6.0.4 version: 6.0.4(typescript@5.3.2) @@ -336,7 +336,7 @@ packages: requiresBuild: true dependencies: '@types/connect': 3.4.38 - '@types/node': 20.10.1 + '@types/node': 20.10.2 dev: false optional: true @@ -348,7 +348,7 @@ packages: resolution: {integrity: sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug==} requiresBuild: true dependencies: - '@types/node': 20.10.1 + '@types/node': 20.10.2 dev: false optional: true @@ -356,7 +356,7 @@ packages: resolution: {integrity: sha512-OaJ7XLaelTgrvlZD8/aa0vvvxZdUmlCn6MtWeB7TkiKW70BQLc9XEPpDLPdbo52ZhXUCrznlWdCHWxJWtdyajA==} requiresBuild: true dependencies: - '@types/node': 20.10.1 + '@types/node': 20.10.2 '@types/qs': 6.9.10 '@types/range-parser': 1.2.7 '@types/send': 0.17.4 @@ -383,7 +383,7 @@ packages: /@types/jsonwebtoken@9.0.5: resolution: {integrity: sha512-VRLSGzik+Unrup6BsouBeHsf4d1hOEgYWTm/7Nmw1sXoN1+tRly/Gy/po3yeahnP4jfnQWWAhQAqcNfH7ngOkA==} dependencies: - '@types/node': 20.10.1 + '@types/node': 20.10.2 dev: false /@types/mime@1.3.5: @@ -401,18 +401,18 @@ packages: /@types/node-fetch@2.6.9: resolution: {integrity: sha512-bQVlnMLFJ2d35DkPNjEPmd9ueO/rh5EiaZt2bhqiSarPjZIuIV6bPQVqcrEyvNo+AfTrRGVazle1tl597w3gfA==} dependencies: - '@types/node': 20.10.1 + '@types/node': 20.10.2 form-data: 4.0.0 dev: false - /@types/node@18.19.0: - resolution: {integrity: sha512-667KNhaD7U29mT5wf+TZUnrzPrlL2GNQ5N0BMjO2oNULhBxX0/FKCkm6JMu0Jh7Z+1LwUlR21ekd7KhIboNFNw==} + /@types/node@18.19.1: + resolution: {integrity: sha512-mZJ9V11gG5Vp0Ox2oERpeFDl+JvCwK24PGy76vVY/UgBtjwJWc5rYBThFxmbnYOm9UPZNm6wEl/sxHt2SU7x9A==} dependencies: undici-types: 5.26.5 dev: false - /@types/node@20.10.1: - resolution: {integrity: sha512-T2qwhjWwGH81vUEx4EXmBKsTJRXFXNZTL4v0gi01+zyBmCwzE6TyHszqX01m+QHTEq+EZNo13NeJIdEqf+Myrg==} + /@types/node@20.10.2: + resolution: {integrity: sha512-37MXfxkb0vuIlRKHNxwCkb60PNBpR94u4efQuN4JgIAm66zfCDXGSAFCef9XUWFovX2R1ok6Z7MHhtdVXXkkIw==} dependencies: undici-types: 5.26.5 @@ -433,7 +433,7 @@ packages: requiresBuild: true dependencies: '@types/mime': 1.3.5 - '@types/node': 20.10.1 + '@types/node': 20.10.2 dev: false optional: true @@ -443,7 +443,7 @@ packages: dependencies: '@types/http-errors': 2.0.4 '@types/mime': 3.0.4 - '@types/node': 20.10.1 + '@types/node': 20.10.2 dev: false optional: true @@ -546,8 +546,8 @@ packages: resolution: {integrity: sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==} dev: false - /dfx@0.77.2(@effect/platform@0.32.2)(effect@2.0.0-next.58): - resolution: {integrity: sha512-QffbFiVAEUxtauup1Ivk3w9+7UYqdFZAg1rK/5h16mWNmB5ch4lRWqOID8NE2YvovkvFbqB+/8OtLc5OegzsUQ==} + /dfx@0.77.3(@effect/platform@0.32.2)(effect@2.0.0-next.58): + resolution: {integrity: sha512-lOSq2gFHsguJ4LOg1toEigQLUh/5xBIcrzVx605VRYkhQEu661D7Um3KSg4ncwHjRV03MTLr6EtXE74FcsJUTg==} peerDependencies: '@effect/platform': ^0.32.1 effect: 2.0.0-next.58 @@ -884,7 +884,7 @@ packages: resolution: {integrity: sha512-Dd3q8EvINfganZFtg6V36HjrMaihqRgIcKiHua4Nq9aw/PxOP48dhbsk8x5klrxajt5Lpnc1KTOG5i1S6BKAJA==} hasBin: true dependencies: - '@types/node': 18.19.0 + '@types/node': 18.19.1 '@types/node-fetch': 2.6.9 abort-controller: 3.0.0 agentkeepalive: 4.5.0 diff --git a/src/AutoThreads.ts b/src/AutoThreads.ts index 7ba8ae2..4757a59 100644 --- a/src/AutoThreads.ts +++ b/src/AutoThreads.ts @@ -231,10 +231,16 @@ const make = ({ topicKeyword }: AutoThreadsOptions) => yield* _(handleMessages, Effect.forkScoped) }) -export const AutoThreadsOptions = Context.Tag() -export const layerOptions = LayerUtils.config(AutoThreadsOptions) +export interface AutoThreadsConfig { + readonly _: unique symbol +} +export const AutoThreadsConfig = Context.Tag< + AutoThreadsConfig, + AutoThreadsOptions +>() +export const layerConfig = LayerUtils.config(AutoThreadsConfig) export const layer = Layer.scopedDiscard( - Effect.flatMap(AutoThreadsOptions, make), + Effect.flatMap(AutoThreadsConfig, make), ).pipe( Layer.provide(ChannelsCacheLive), Layer.provide(OpenAI.layer), diff --git a/src/Github.ts b/src/Github.ts index 4d25311..aa2a17b 100644 --- a/src/Github.ts +++ b/src/Github.ts @@ -2,7 +2,6 @@ import type { OctokitResponse } from "@octokit/types" import { LayerUtils } from "bot/_common" import { Chunk, - Config, ConfigSecret, Context, Effect, @@ -14,7 +13,7 @@ import { } from "effect" import { Octokit } from "octokit" -export interface GithubConfig { +export interface GithubConfigValue { readonly token: ConfigSecret.ConfigSecret } @@ -22,7 +21,7 @@ export class GithubError extends Data.TaggedError("GithubError")<{ readonly reason: unknown }> {} -const make = ({ token }: GithubConfig) => { +const make = ({ token }: GithubConfigValue) => { const octokit = new Octokit({ auth: ConfigSecret.value(token) }) const rest = octokit.rest @@ -66,7 +65,10 @@ const make = ({ token }: GithubConfig) => { return { octokit, token, request, wrap, stream } } -export const GithubConfig = Context.Tag() +export interface GithubConfig { + readonly _: unique symbol +} +export const GithubConfig = Context.Tag() export const layerConfig = LayerUtils.config(GithubConfig) export interface Github extends ReturnType {} diff --git a/src/NoEmbed.ts b/src/NoEmbed.ts index b5fa139..5bc9248 100644 --- a/src/NoEmbed.ts +++ b/src/NoEmbed.ts @@ -3,7 +3,7 @@ import { ChannelsCache, ChannelsCacheLive } from "bot/ChannelsCache" import { LayerUtils } from "bot/_common" import { Discord, DiscordREST } from "dfx" import { DiscordGateway, DiscordLive } from "dfx/gateway" -import { Config, Effect, Data, Layer, pipe, Context } from "effect" +import { Context, Effect, Layer, pipe } from "effect" export interface NoEmbedOptions { readonly topicKeyword: string @@ -94,9 +94,12 @@ const make = ({ topicKeyword, urlWhitelist }: NoEmbedOptions) => ) }) -export const NoEmbedOptions = Context.Tag() -export const layerOptions = LayerUtils.config(NoEmbedOptions) +export interface NoEmbedConfig { + readonly _: unique symbol +} +export const NoEmbedConfig = Context.Tag() +export const layerConfig = LayerUtils.config(NoEmbedConfig) export const layer = Layer.effectDiscard( - Effect.flatMap(NoEmbedOptions, make), + Effect.flatMap(NoEmbedConfig, make), ).pipe(Layer.provide(ChannelsCacheLive), Layer.provide(DiscordLive)) diff --git a/src/OpenAI.ts b/src/OpenAI.ts index 9733e35..5dc0f0b 100644 --- a/src/OpenAI.ts +++ b/src/OpenAI.ts @@ -1,7 +1,6 @@ import { LayerUtils } from "bot/_common" import * as Str from "bot/utils/String" import { - Config, ConfigSecret, Context, Data, @@ -171,12 +170,15 @@ The title of this chat is "${title}".`, } as const } -export const OpenAIOptions = Context.Tag() -export const layerOptions = LayerUtils.config(OpenAIOptions) +export interface OpenAIConfig { + readonly _: unique symbol +} +export const OpenAIConfig = Context.Tag() +export const layerConfig = LayerUtils.config(OpenAIConfig) export interface OpenAI extends ReturnType {} export const OpenAI = Context.Tag() -export const layer = Layer.effect(OpenAI, Effect.map(OpenAIOptions, make)) +export const layer = Layer.effect(OpenAI, Effect.map(OpenAIConfig, make)) const cleanTitle = (_: string) => pipe(Str.firstParagraph(_), Str.removeQuotes, Str.removePeriod) diff --git a/src/Summarizer.ts b/src/Summarizer.ts index d10e3aa..0230aa6 100644 --- a/src/Summarizer.ts +++ b/src/Summarizer.ts @@ -3,11 +3,7 @@ import { MemberCache, MemberCacheLive } from "bot/MemberCache" import { Messages, MessagesLive } from "bot/Messages" import { Http } from "bot/_common" import { Discord, DiscordREST, Ix } from "dfx" -import { - DiscordIxLive, - InteractionsRegistry, - InteractionsRegistryLive, -} from "dfx/gateway" +import { DiscordIxLive, InteractionsRegistry } from "dfx/gateway" import { Cause, Chunk, diff --git a/src/main.ts b/src/main.ts index 7a532dc..694cd89 100644 --- a/src/main.ts +++ b/src/main.ts @@ -22,19 +22,19 @@ const DiscordConfigLive = DiscordConfig.layerConfig({ }, }) -const OpenAIOptions = OpenAI.layerOptions({ +const OpenAIOptions = OpenAI.layerConfig({ apiKey: Config.secret("OPENAI_API_KEY"), organization: Config.option(Config.secret("OPENAI_ORGANIZATION")), }) -const AutoThreadsOptions = AutoThreads.layerOptions({ +const AutoThreadsOptions = AutoThreads.layerConfig({ topicKeyword: Config.withDefault( Config.string("AUTOTHREADS_KEYWORD"), "[threads]", ), }) -const NoEmbedOptions = NoEmbed.layerOptions({ +const NoEmbedOptions = NoEmbed.layerConfig({ topicKeyword: Config.withDefault( Config.string("NOEMBED_KEYWORD"), "[noembed]", diff --git a/src/utils/Layer.ts b/src/utils/Layer.ts index 614914b..e27e2f3 100644 --- a/src/utils/Layer.ts +++ b/src/utils/Layer.ts @@ -1,6 +1,6 @@ import { Config, Context, Effect, Layer } from "effect" export const config = - (tag: Context.Tag) => + (tag: Context.Tag) => (config: Config.Config.Wrap) => Layer.effect(tag, Effect.config(Config.unwrap(config)))