Skip to content

Commit

Permalink
update dependencies (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart authored Feb 7, 2025
1 parent bb6610f commit bc5eefc
Show file tree
Hide file tree
Showing 8 changed files with 778 additions and 761 deletions.
40 changes: 19 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,28 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@effect/ai": "^0.5.0",
"@effect/ai-openai": "^0.8.0",
"@effect/experimental": "^0.36.0",
"@effect/ai": "^0.8.4",
"@effect/ai-openai": "^0.11.4",
"@effect/experimental": "^0.39.4",
"@effect/language-service": "^0.2.0",
"@effect/opentelemetry": "^0.42.0",
"@effect/platform": "^0.72.0",
"@effect/platform-node": "^0.68.0",
"@octokit/types": "^13.6.2",
"@opentelemetry/exporter-metrics-otlp-http": "^0.57.0",
"@opentelemetry/exporter-trace-otlp-http": "^0.57.0",
"@opentelemetry/sdk-metrics": "^1.30.0",
"@opentelemetry/sdk-trace-base": "^1.30.0",
"@opentelemetry/sdk-trace-node": "^1.30.0",
"@types/node": "^22.10.2",
"dfx": "^0.109.0",
"effect": "^3.12.0",
"@effect/opentelemetry": "^0.43.0",
"@effect/platform": "^0.75.4",
"@effect/platform-node": "^0.71.4",
"@octokit/types": "^13.8.0",
"@opentelemetry/exporter-metrics-otlp-http": "^0.57.1",
"@opentelemetry/exporter-trace-otlp-http": "^0.57.1",
"@opentelemetry/sdk-metrics": "^1.30.1",
"@opentelemetry/sdk-trace-base": "^1.30.1",
"@opentelemetry/sdk-trace-node": "^1.30.1",
"@types/node": "^22.13.1",
"dfx": "^0.111.3",
"effect": "^3.12.10",
"fuzzysort": "^3.1.0",
"html-entities": "^2.5.2",
"octokit": "^4.0.2",
"octokit": "^4.1.1",
"prettier": "^3.4.2",
"tsup": "^8.3.5",
"tsup": "^8.3.6",
"tsx": "^4.19.2",
"typescript": "5.7.2"
},
"dependencies": {
"fuzzysort": "^3.1.0"
"typescript": "5.7.3"
}
}
1,293 changes: 663 additions & 630 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/DocsLookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ const make = Effect.gen(function* () {
},
Effect.fn("DocsLookup.command")(
function* (ix) {
const key = yield* ix.optionValue("query")
const reveal = yield* ix.optionValue("public")
const key = ix.optionValue("query")
const reveal = ix.optionValue("public")
const docs = yield* allDocs
const entry = yield* Effect.fromNullable(docs.map[key])
yield* Effect.annotateCurrentSpan({
Expand All @@ -127,7 +127,7 @@ const make = Effect.gen(function* () {
type: Discord.InteractionCallbackType.CHANNEL_MESSAGE_WITH_SOURCE,
data: {
flags: Discord.MessageFlag.EPHEMERAL,
content: `Sorry, that query could not found.`,
content: `Sorry, that query could not be found.`,
},
}),
),
Expand Down
2 changes: 1 addition & 1 deletion src/Issueifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ https://discord.com/channels/${channel.guild_id}/${channel.id}
Effect.fn("Issueifier.command")(
function* (ix) {
const context = yield* Ix.Interaction
const repoIndex = yield* ix.optionValue("repository")
const repoIndex = ix.optionValue("repository")
const repo = githubRepos[repoIndex]
yield* Effect.annotateCurrentSpan({ repo: repo.label })
const channel = yield* channels.get(
Expand Down
38 changes: 17 additions & 21 deletions src/Playground.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { InteractionsRegistry } from "dfx/gateway"
import { Discord, Ix, IxHelpers } from "dfx"
import { Discord, Ix } from "dfx"
import { Effect, Encoding, Layer, Option } from "effect"
import { DiscordLive } from "./Discord.js"

Expand All @@ -17,33 +17,29 @@ export const PlaygroundLive = Effect.gen(function* () {
type: Discord.ApplicationCommandType.MESSAGE,
name: "Open in playground",
},
Effect.gen(function* () {
const interaction = yield* Ix.Interaction
const command = yield* Ix.ApplicationCommand
const resolved = yield* IxHelpers.resolved(interaction)
const message = resolved.messages?.[command.target_id!]
const content = yield* Effect.fromNullable(message?.content)
const code = yield* extractCode(content)
const url = yield* linkFromCode(code)
Effect.fn("Playground.command")(
function* (ix) {
const code = yield* extractCode(ix.target.content)
const url = yield* linkFromCode(code)

const response = `Here is your [playground link](${url}).`
if (response.length > 1950) {
const response = `Here is your [playground link](${url}).`
if (response.length > 1950) {
return Ix.response({
type: Discord.InteractionCallbackType.CHANNEL_MESSAGE_WITH_SOURCE,
data: {
flags: Discord.MessageFlag.EPHEMERAL,
content: `The code snippet is too long to be displayed in a single message.`,
},
})
}
return Ix.response({
type: Discord.InteractionCallbackType.CHANNEL_MESSAGE_WITH_SOURCE,
data: {
flags: Discord.MessageFlag.EPHEMERAL,
content: `The code snippet is too long to be displayed in a single message.`,
content: `Here is your [playground link](${url}).`,
},
})
}
return Ix.response({
type: Discord.InteractionCallbackType.CHANNEL_MESSAGE_WITH_SOURCE,
data: {
flags: Discord.MessageFlag.EPHEMERAL,
content: `Here is your [playground link](${url}).`,
},
})
}).pipe(
},
Effect.catchTag("NoSuchElementException", () =>
Effect.succeed(
Ix.response({
Expand Down
2 changes: 1 addition & 1 deletion src/Reminders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DiscordGateway } from "dfx/gateway"
import { Discord } from "dfx/index"
import { Cron, Data, Effect, FiberMap, Layer, Schedule, pipe } from "effect"

class MissingTopic extends Data.TaggedError("MissingTopic")<{}> {}
class MissingTopic extends Data.TaggedError("MissingTopic") {}

class InvalidTopic extends Data.TaggedError("InvalidTopic")<{
readonly reason: string
Expand Down
37 changes: 18 additions & 19 deletions src/ReproRequester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,26 @@ const make = Effect.gen(function* () {
),
)

const respond = (channel: Discord.Channel, context: Discord.Interaction) =>
Effect.gen(function* () {
const input = yield* ai.generateAiInput(channel)
const content = yield* tokenizer.truncate(input, 30_000).pipe(
Effect.flatMap(completions.create),
Effect.map(response => response.text),
AiInput.provideSystem(systemInstruction),
Effect.annotateLogs({
thread: channel.id,
}),
)
yield* discord.editOriginalInteractionResponse(
application.id,
context.token,
{ content },
)
}).pipe(
Effect.withSpan("ReproRequester.respond", {
attributes: { channel: channel.id },
const respond = Effect.fn("ReproRequester.respond")(function* (
channel: Discord.Channel,
context: Discord.Interaction,
) {
yield* Effect.annotateCurrentSpan({ channel: channel.id })
const input = yield* ai.generateAiInput(channel)
const content = yield* tokenizer.truncate(input, 30_000).pipe(
Effect.flatMap(completions.create),
Effect.map(response => response.text),
AiInput.provideSystem(systemInstruction),
Effect.annotateLogs({
thread: channel.id,
}),
)
yield* discord.editOriginalInteractionResponse(
application.id,
context.token,
{ content },
)
})

const ix = Ix.builder
.add(command)
Expand Down
121 changes: 56 additions & 65 deletions src/Summarizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Messages } from "bot/Messages"
import { Discord, DiscordREST, Ix } from "dfx"
import { InteractionsRegistry } from "dfx/gateway"
import { Cause, Chunk, Data, Effect, Option, Stream, pipe } from "effect"
import { constTrue } from "effect/Function"

export class NotInThreadError extends Data.TaggedError(
"NotInThreadError",
Expand All @@ -21,20 +22,19 @@ export class Summarizer extends Effect.Service<Summarizer>()("app/Summarizer", {
const scope = yield* Effect.scope
const application = yield* DiscordApplication

const summarizeThread = (channel: Discord.Channel, small = true) =>
pipe(
Effect.all({
parentChannel: channels.get(channel.guild_id!, channel.parent_id!),
messages: Effect.map(
Stream.runCollect(messages.cleanForChannel(channel)),
Chunk.reverse,
),
}),
Effect.flatMap(({ parentChannel, messages }) =>
summarize(parentChannel, channel, messages, small),
),
Effect.withSpan("Summarizer.summarizeThread"),
const summarizeThread = Effect.fn("Summarizer.summarizeThread")(function* (
channel: Discord.Channel,
small: boolean = true,
) {
const parentChannel = yield* channels.get(
channel.guild_id!,
channel.parent_id!,
)
const threadMessages = yield* Stream.runCollect(
messages.cleanForChannel(channel),
).pipe(Effect.map(Chunk.reverse))
return yield* summarize(parentChannel, channel, threadMessages, small)
})

const summarizeWithMessages = (
channel: Discord.Channel,
Expand Down Expand Up @@ -85,14 +85,19 @@ ${messageContent.join("\n\n")}`,
Effect.withSpan("Summarizer.summarize"),
)

const summarizeMessage = (
thread: Discord.Channel,
index: number,
message: Discord.Message,
replyTo: Option.Option<readonly [Discord.Message, number]>,
small: boolean,
) =>
Effect.gen(function* () {
const summarizeMessage = Effect.fn("Summarizer.summarizeMessage")(
function* (
thread: Discord.Channel,
index: number,
message: Discord.Message,
replyTo: Option.Option<readonly [Discord.Message, number]>,
small: boolean,
) {
yield* Effect.annotateCurrentSpan({
channelId: thread.id,
messageId: message.id,
})

const user = message.author
const member = yield* members.get(thread.guild_id!, message.author.id)
const username = member.nick ?? user.username
Expand All @@ -119,14 +124,8 @@ ${messageContent.join("\n\n")}`,

return `${header}<br />
${message.content}${imagesContent}`
}).pipe(
Effect.withSpan("Summarizer.summarizeMessage", {
attributes: {
channelId: thread.id,
messageId: message.id,
},
}),
)
},
)

const followUpResponse = (
context: Discord.Interaction,
Expand Down Expand Up @@ -180,42 +179,34 @@ ${message.content}${imagesContent}`
},
],
},
ix =>
pipe(
Effect.all({
context: Ix.Interaction,
small: Effect.map(
ix.optionValueOptional("small"),
Option.getOrElse(() => true),
),
}),
Effect.bind("channel", ({ context }) =>
channels.get(context.guild_id!, context.channel_id!),
),
Effect.tap(({ channel, small }) =>
Effect.annotateCurrentSpan({
channelId: channel.id,
small,
}),
),
Effect.filterOrFail(
({ channel }) => channel.type === Discord.ChannelType.PUBLIC_THREAD,
() => new NotInThreadError(),
),
Effect.tap(({ context, channel, small }) =>
Effect.forkIn(followUpResponse(context, channel, small), scope),
),
Effect.as(
Ix.response({
type: Discord.InteractionCallbackType.CHANNEL_MESSAGE_WITH_SOURCE,
data: {
content: "Creating summary...",
flags: Discord.MessageFlag.EPHEMERAL,
},
}),
),
Effect.withSpan("Summarizer.command"),
),
Effect.fn("Summarizer.command")(function* (ix) {
const context = yield* Ix.Interaction
const small = ix.optionValueOrElse("small", constTrue)
console.log("small", small)
const channel = yield* channels.get(
context.guild_id!,
context.channel_id!,
)

yield* Effect.annotateCurrentSpan({
channelId: channel.id,
small,
})

if (channel.type !== Discord.ChannelType.PUBLIC_THREAD) {
return yield* new NotInThreadError()
}

yield* Effect.forkIn(followUpResponse(context, channel, small), scope)

return Ix.response({
type: Discord.InteractionCallbackType.CHANNEL_MESSAGE_WITH_SOURCE,
data: {
content: "Creating summary...",
flags: Discord.MessageFlag.EPHEMERAL,
},
})
}),
)

const ix = Ix.builder
Expand Down

0 comments on commit bc5eefc

Please sign in to comment.