Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rewrite plugin to v2 #122

Merged
merged 163 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
163 commits
Select commit Hold shift + click to select a range
433fa46
Add basic engine outline
KnorpelSenf Oct 8, 2023
9c2e957
Add first working version of replay engine
KnorpelSenf Oct 15, 2023
5b79b23
test: add more tests
KnorpelSenf Oct 16, 2023
f1bfbe4
Update test deps
KnorpelSenf Oct 16, 2023
6fd0ff6
Update oson to 1.0.2
KnorpelSenf Oct 16, 2023
17a0de3
Do not resolve all interrupts
KnorpelSenf Oct 16, 2023
49ce885
Remove pointless async op
KnorpelSenf Oct 16, 2023
82d8240
Drop support for concurrent cursors because YAGNI
KnorpelSenf Oct 17, 2023
0581bf3
Support undo
KnorpelSenf Oct 17, 2023
f97d647
Add test for boom ops
KnorpelSenf Oct 17, 2023
72ce94e
Support canceling
KnorpelSenf Oct 17, 2023
3823b83
Fix completed replay during done reordering
KnorpelSenf Oct 17, 2023
736f60e
Add test for floating cancel ops
KnorpelSenf Oct 17, 2023
d329072
Clean up
KnorpelSenf Oct 17, 2023
3946433
Wait for floating actions
KnorpelSenf Oct 23, 2023
af0dcbe
Fix comments
KnorpelSenf Oct 23, 2023
e456d7a
Merge branch 'main' into engine
KnorpelSenf Feb 11, 2024
d62e466
chore: throw out v1 code
KnorpelSenf Mar 7, 2024
f5251df
Merge branch 'main' into engine
KnorpelSenf Jun 2, 2024
5e10472
style: small refactorings and added comments
KnorpelSenf Jun 2, 2024
67fd924
test: rename test for payload
KnorpelSenf Jun 2, 2024
5f34bf7
test: add test for nested floating promises
KnorpelSenf Jun 2, 2024
9831ce9
fix: do not return early for nested floating promises
KnorpelSenf Jun 2, 2024
873217a
test: simplify test by using a loop
KnorpelSenf Jun 2, 2024
3b69c96
test: add tests for interrupt/cancel messages
KnorpelSenf Jun 2, 2024
3dfe613
feat: support interrupt/cancel messages
KnorpelSenf Jun 2, 2024
a4abc66
feat: draft plugin on top of replay engine
KnorpelSenf Jun 2, 2024
0ca27c5
docs: update readme
KnorpelSenf Jun 2, 2024
f65b4d2
fix: list deps explicitly
KnorpelSenf Jun 3, 2024
2223d3f
feat: let replay engine generate initial state for external use
KnorpelSenf Jun 3, 2024
6b5df47
feat: have distinct methods for entering and resuming conversations
KnorpelSenf Jun 3, 2024
003c582
feat: add checkpoint support to states
KnorpelSenf Jun 3, 2024
8c6d395
feat: add core plugin functionality
KnorpelSenf Jun 3, 2024
6bddaea
feat: draft grammY integration
KnorpelSenf Jun 4, 2024
1920c18
add todo comments
KnorpelSenf Jun 12, 2024
62bdd7d
fix: read type
KnorpelSenf Jun 12, 2024
0065bed
doc: add another todo note
KnorpelSenf Jun 12, 2024
ba00b94
test: cover conversations
KnorpelSenf Jun 26, 2024
4f9f5f4
fix: correctly detect empty convo name
KnorpelSenf Jun 26, 2024
64e0974
test: cover convo name test
KnorpelSenf Jun 26, 2024
3cb9093
feat: enter conversations from middleware
KnorpelSenf Jun 27, 2024
d1bfdf3
feat: improve error message for recovered errors
KnorpelSenf Jun 29, 2024
c7a3b10
test: add notes for pending tests
KnorpelSenf Jun 29, 2024
5a80e1c
test: improve state validation tests
KnorpelSenf Jul 8, 2024
20964fc
fix: off-by-one error in state payload validation
KnorpelSenf Jul 8, 2024
2e28ed6
test: add more test cases for ctx.conversation
KnorpelSenf Jul 8, 2024
2e06a9f
fix: return 0 from ctx.conversation.active for unknown conversations
KnorpelSenf Jul 8, 2024
5520962
test: add more state tests
KnorpelSenf Jul 8, 2024
e9c2c47
fix: loosen checkpoint validation constraints
KnorpelSenf Jul 8, 2024
3b8ddff
test: add another todo for testing
KnorpelSenf Jul 8, 2024
e8dd088
feat: return extra information when entering conversations
KnorpelSenf Jul 8, 2024
db96be0
fix: remove useless exhaustiveness check
KnorpelSenf Jul 8, 2024
9db77ef
feat: detect missing await for enter calls
KnorpelSenf Jul 8, 2024
0b061dc
test: cover resuming, inspecting active, and incorrectly entering con…
KnorpelSenf Jul 8, 2024
f58a4f9
chore: update deno editor config
KnorpelSenf Jul 9, 2024
27bf046
perf: skip useless deletions
KnorpelSenf Jul 9, 2024
7146156
test: cover more concurrent entering scenarios
KnorpelSenf Jul 9, 2024
e1fc25a
refactor: move conversation class to own file
KnorpelSenf Jul 9, 2024
34020a0
test: add another todo
KnorpelSenf Jul 9, 2024
06d3bf8
feat: implement exiting, onEnter, and onExit
KnorpelSenf Jul 9, 2024
8a5c1bb
test: cover exitAll and add more todos
KnorpelSenf Jul 9, 2024
9aeb533
feat: prevent recursive plugin installs
KnorpelSenf Jul 9, 2024
fbe1e85
test: cover args, onEnter, onExit, and all exit calls
KnorpelSenf Jul 9, 2024
83581a5
test: cover exiting, resuming, and refactor tests
KnorpelSenf Jul 9, 2024
043660d
docs: add comment with to-do about parallel
KnorpelSenf Jul 11, 2024
3e8cded
feat: require parallel for conversations of all identifiers
KnorpelSenf Jul 11, 2024
c1dee4d
test: cover new behaviour of parallel flag
KnorpelSenf Jul 11, 2024
a36e874
test: remove completed todo
KnorpelSenf Jul 11, 2024
2f99659
feat: drop conversation.run for now
KnorpelSenf Jul 11, 2024
a22b739
refactor: remove unused vars
KnorpelSenf Jul 11, 2024
920d17d
perf: skip spinning event loop without exit handler
KnorpelSenf Jul 11, 2024
9e738c6
refactor: collect context constructor args
KnorpelSenf Jul 11, 2024
9628c25
fix: exit handler is never being called
KnorpelSenf Jul 11, 2024
14b8f0f
fix: add workaround for bad compilation error since TS 5.5
KnorpelSenf Jul 12, 2024
58154e5
feat: export interface ContextBaseData
KnorpelSenf Jul 12, 2024
50fe365
perf: use faster loop over interrupts
KnorpelSenf Jul 12, 2024
40bdff5
test: cover enterConversation and resumeConversation
KnorpelSenf Jul 12, 2024
c578aef
feat: export types of conversation states
KnorpelSenf Jul 12, 2024
c00522a
test: cover conversation.{wait,skip,halt}
KnorpelSenf Jul 12, 2024
a97a159
test: cover conversation.external
KnorpelSenf Jul 12, 2024
a069bd4
test: cover cascading interrupts in engine
KnorpelSenf Jul 12, 2024
6e626d8
chore: use JSR testing modules
KnorpelSenf Jul 12, 2024
edfff79
test: cover concurrent conversation.{wait,skip,halt}
KnorpelSenf Jul 12, 2024
2b30cbd
test: improve test name consistency
KnorpelSenf Jul 12, 2024
b49e64e
test: disallow interrupts after cancel
KnorpelSenf Jul 12, 2024
1b9f80d
fix: do not return unrecorded interrupts
KnorpelSenf Jul 12, 2024
1e0f010
test: fix chaotic test
KnorpelSenf Jul 12, 2024
e6851f4
refactor: drop lost comments
KnorpelSenf Jul 17, 2024
cd97870
fix: floating behaviour after returning or cancelling
KnorpelSenf Sep 3, 2024
b2681f4
test: add assertion for actions after floating interrupts
KnorpelSenf Sep 3, 2024
84be1df
feat: prevent concurrent or nested calls to external
KnorpelSenf Sep 3, 2024
1d38cc6
test: cover wait calls in combination with external
KnorpelSenf Sep 3, 2024
12a2d8e
test: fix typos in test names
KnorpelSenf Sep 4, 2024
930beef
feat: group storage config options
KnorpelSenf Sep 4, 2024
16d348f
feat: support existing storage adapters
KnorpelSenf Sep 4, 2024
4377c85
test: cover support for existing storage adapters
KnorpelSenf Sep 4, 2024
e1de704
feat: improve storage adapter integration
KnorpelSenf Sep 4, 2024
7539e2e
test: cover loops and recursion with side-effects
KnorpelSenf Sep 5, 2024
34ee291
feat: access outside context objects via external
KnorpelSenf Sep 6, 2024
e703adb
feat: support plugins
KnorpelSenf Sep 6, 2024
5bf778a
fix: support menu plugin
KnorpelSenf Sep 6, 2024
4ca1bcf
docs: add TODO comments for remaining tasks
KnorpelSenf Sep 6, 2024
572afee
fix: improve transformer error handling
KnorpelSenf Sep 7, 2024
d9583d6
fix: make `external` types usable without type cast
KnorpelSenf Sep 7, 2024
143b68f
feat: do not require storage
KnorpelSenf Sep 13, 2024
89e0f09
feat: conversation.{now,random,log,error}
KnorpelSenf Sep 13, 2024
d57a4c1
test: cover conversation.{now,random,log,error}
KnorpelSenf Sep 13, 2024
d111282
feat: wait timeouts, drop, kill, halt handler
KnorpelSenf Sep 24, 2024
98a7111
test: cover wait timeouts
KnorpelSenf Sep 24, 2024
aeb2853
feat: wait* methods
KnorpelSenf Sep 24, 2024
bfadab3
feat: forms
KnorpelSenf Sep 24, 2024
0bcde25
fix: add missing exports for node build
KnorpelSenf Sep 24, 2024
83cf79a
fix: suppress compile error for old versions of Node
KnorpelSenf Sep 24, 2024
bd2892e
feat: sealing conversations
KnorpelSenf Sep 24, 2024
52ab016
refactor: make engine usable without state
KnorpelSenf Sep 26, 2024
104f8bd
refactor: require interrupt keys, support more cancel reasons
KnorpelSenf Sep 26, 2024
482a6ca
fix: do not lose wait options when plugins intercept updates
KnorpelSenf Sep 26, 2024
46ec51d
refactor: remove dep from plugin on state
KnorpelSenf Sep 26, 2024
d16ce81
refactor(engine): stricter replays by splitting up interrupted result…
KnorpelSenf Sep 26, 2024
d3c3a2d
feat: checkpoints
KnorpelSenf Sep 30, 2024
5f45220
test: cover checkpoints
KnorpelSenf Sep 30, 2024
269587e
feat: wait call conjunctions
KnorpelSenf Oct 1, 2024
4d34bb4
fix: support absent otherwise opts in wait.and
KnorpelSenf Oct 1, 2024
21b1b94
test: cover some filtered wait calls and conjunctions
KnorpelSenf Oct 1, 2024
d1a2cc3
feat: integrate menus with conversation
KnorpelSenf Oct 3, 2024
538475d
feat: add rough draft of a conversational menu
KnorpelSenf Oct 3, 2024
5a13b43
fix: add missing type imports
KnorpelSenf Oct 3, 2024
6a543d0
feat: built-in data versioning
KnorpelSenf Oct 15, 2024
7f9688c
refactor: improve variable names
KnorpelSenf Oct 15, 2024
3f21e3c
feat: rework storage adapters once more
KnorpelSenf Oct 21, 2024
6bdd692
refactor: extract version management
KnorpelSenf Oct 21, 2024
2d4f9d7
feat: export everything
KnorpelSenf Oct 21, 2024
e8ed0d6
fix: compile again
KnorpelSenf Oct 21, 2024
d96258e
refactor: be more explicit about onHalt type
KnorpelSenf Oct 21, 2024
f11b02b
style: reformat GH actions with Deno 2
KnorpelSenf Oct 21, 2024
c027e92
refactor: extract you-touch-you-die
KnorpelSenf Oct 22, 2024
77ae119
feat: add conversation.menu
KnorpelSenf Oct 22, 2024
c6a0833
fix: incorrect lookup of internal menus
KnorpelSenf Oct 22, 2024
c7f2d93
fix: set default of autoAnswer to `true`
KnorpelSenf Oct 22, 2024
1c93ed1
chore: fix permission in deno task check
KnorpelSenf Oct 22, 2024
983f13b
chore: fix permission in deno task test
KnorpelSenf Oct 22, 2024
774b28b
fix: node types
KnorpelSenf Oct 23, 2024
8e51287
feat: allow specifying menu parent
KnorpelSenf Oct 23, 2024
e913bef
fix: correctly set menu parent
KnorpelSenf Oct 27, 2024
bd6a8c7
fix: keep conversation-global index of dirty menus
KnorpelSenf Oct 27, 2024
79e919e
fix: missing async/await in menu integration
KnorpelSenf Oct 28, 2024
afc9cb7
feat: export all menu symbols
KnorpelSenf Oct 28, 2024
dbc8949
feat: simplfiy parallel conversations
KnorpelSenf Oct 28, 2024
b3500a4
fix: persist data even upon error
KnorpelSenf Oct 28, 2024
3d32a06
chore: rework deno tasks
KnorpelSenf Oct 29, 2024
9025ce9
docs: update README
KnorpelSenf Oct 29, 2024
b09d363
refactor: drop workaround after TS fix
KnorpelSenf Oct 29, 2024
62407b7
chore: update Deno in CI to Deno 2
KnorpelSenf Oct 29, 2024
27f411b
chore: update Deno for coverage job, too
KnorpelSenf Oct 29, 2024
9282ad9
test: adjust tests to latest breaking changes
KnorpelSenf Oct 29, 2024
7f559d0
feat: do not require storage key function for key adapters
KnorpelSenf Oct 29, 2024
f107d68
test: cover storages
KnorpelSenf Oct 29, 2024
bd440c3
test: fix bad import path
KnorpelSenf Oct 29, 2024
d795dda
chore: add -I to task coverage
KnorpelSenf Oct 29, 2024
8dbc97a
style: add missing trailing newline to deno.jsonc
KnorpelSenf Oct 29, 2024
ae3b842
chore: fix CI permissions
KnorpelSenf Oct 29, 2024
e7cf54f
Revert "chore: add -I to task coverage"
KnorpelSenf Oct 29, 2024
d81689a
test: fix flaky timeout tests
KnorpelSenf Oct 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 72 additions & 72 deletions .github/workflows/deno.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,77 +9,77 @@
name: grammY conversations

on:
push:
branches: [main]
pull_request:
branches: [main]
push:
branches: [main]
pull_request:
branches: [main]

jobs:
backport:
runs-on: ubuntu-latest
steps:
- name: Setup repo
uses: actions/checkout@v3

- name: Install dependencies
run: npm install --ignore-scripts

- name: Run backporting
run: npm run backport

format-and-lint:
runs-on: ubuntu-latest
steps:
- name: Setup repo
uses: actions/checkout@v3

- uses: denoland/setup-deno@main
with:
deno-version: v1.x

- name: Check Format
run: deno fmt --check

- name: Lint
run: deno lint

test:
runs-on: ${{ matrix.os }} # runs a test on Ubuntu, Windows and macOS

strategy:
matrix:
os: [macOS-latest, windows-latest, ubuntu-latest]

steps:
- name: Setup repo
uses: actions/checkout@v3

- uses: denoland/setup-deno@main
with:
deno-version: v1.x

- name: Cache Dependencies
run: deno cache src/mod.ts

- name: Run Tests
run: deno task test

coverage:
runs-on: ubuntu-latest
steps:
- name: Setup repo
uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: denoland/setup-deno@main
with:
deno-version: v1.x

- name: Create coverage files
run: deno task coverage

- name: Collect coverage
uses: codecov/codecov-action@v1.0.10 # upload the report on Codecov
with:
file: ./coverage.lcov
backport:
runs-on: ubuntu-latest
steps:
- name: Setup repo
uses: actions/checkout@v4

- name: Install dependencies
run: npm install --ignore-scripts

- name: Run backporting
run: npm run backport

format-and-lint:
runs-on: ubuntu-latest
steps:
- name: Setup repo
uses: actions/checkout@v4

- uses: denoland/setup-deno@v2
with:
deno-version: v2.x

- name: Check Format
run: deno fmt --check

- name: Lint
run: deno lint

test:
runs-on: ${{ matrix.os }} # runs a test on Ubuntu, Windows and macOS

strategy:
matrix:
os: [macOS-latest, windows-latest, ubuntu-latest]

steps:
- name: Setup repo
uses: actions/checkout@v4

- uses: denoland/setup-deno@v2
with:
deno-version: v2.x

- name: Cache Dependencies
run: deno task check

- name: Run Tests
run: deno task test

coverage:
runs-on: ubuntu-latest
steps:
- name: Setup repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: denoland/setup-deno@v2
with:
deno-version: v2.x

- name: Create coverage files
run: deno task coverage

- name: Collect coverage
uses: codecov/codecov-action@v1.0.10 # upload the report on Codecov
with:
file: ./coverage.lcov
9 changes: 0 additions & 9 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,5 @@
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": "explicit"
},
"deno.enable": true,
"deno.lint": true,
"deno.config": "./deno.jsonc",
"deno.suggest.imports.hosts": {
"https://deno.land": true,
"https://x.nest.land": true,
"https://crux.land": true,
"https://lib.deno.dev": false
}
}
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,48 @@
# <h1 align="center">grammY Conversations</h1>
# <h1 align="center">grammY conversations</h1>

---

The grammY conversations plugin lets you create powerful conversational interfaces with ease.

Here is a quickstart for you, but the real docs are on this page: <https://grammy.dev/plugins/conversations>
This is version 2 of the plugin.
Version 2 is a complete rewrite from scratch.
It is not released yet, but most of the coding is done, so it will likely be released in the coming days or weeks, right after the documentation was written.

That being said, now is the perfect time to try out the rewrite!

Here is a quickstart for you for v2, but if you want to use v1 instead, you should rather look at the actual docs page: <https://grammy.dev/plugins/conversations>

## Quickstart

Run `npm i grammy @grammyjs/conversations` and paste the following code:
Run `npm i github:grammyjs/conversations` to install the code right from this repository and paste the following code:

```ts
import { Bot, type Context, session } from "grammy";
import { Bot, type Context } from "grammy";
import {
type Conversation,
type ConversationFlavor,
conversations,
createConversation,
} from "@grammyjs/conversations";

type MyContext = Context & ConversationFlavor;
type MyConversation = Conversation<MyContext>;
type MyContext = ConversationFlavor<Context>;
type MyConversationContext = HydrateFlavor<Context>;

type MyConversation = Conversation<MyConversationContext>;

const bot = new Bot<MyContext>("");

/** Defines the conversation */
async function greeting(conversation: MyConversation, ctx: MyContext) {
async function greeting(
conversation: MyConversation,
ctx: MyConversationContext,
) {
await ctx.reply("Hi there! What is your name?");
const { message } = await conversation.wait();
await ctx.reply(`Welcome to the chat, ${message.text}!`);
}

bot.use(session({ initial: () => ({}) }));
bot.use(conversations());

bot.use(createConversation(greeting));

bot.command("enter", async (ctx) => {
Expand Down
29 changes: 11 additions & 18 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
{
"lock": false,
"tasks": {
"check": "deno cache --check=all src/mod.ts",
"backport": "deno run --no-prompt --allow-read=. --allow-write=. https://deno.land/x/deno2node@v1.8.1/src/cli.ts tsconfig.json",
"test": "deno test test",
"dev": "deno fmt && deno lint && deno task test && deno task check",
"check": "deno cache --allow-import --check=all src/mod.ts",
"build": "deno run --no-prompt --allow-read=. --allow-write=. https://deno.land/x/deno2node@v1.8.1/src/cli.ts tsconfig.json",
"test": "deno test --allow-import test",
"ok": "deno fmt && deno lint && deno task test && deno task check",
"clean": "git clean -fX out test/cov_profile test/coverage coverage.lcov",
"coverage": "deno task clean && deno task test --coverage=./test/cov_profile && deno coverage --lcov --output=./coverage.lcov ./test/cov_profile",
"report": "genhtml ./coverage.lcov --output-directory ./test/coverage/ && echo 'Point your browser to test/coverage/index.html to see the test coverage report.'"
},
"exclude": [
"./node_modules/",
"./out/",
"./package-lock.json",
"./test/cov_profile"
],
"fmt": {
"indentWidth": 4,
"proseWrap": "preserve",
"exclude": [
"./node_modules/",
"./out/",
"./package-lock.json",
"./test/cov_profile"
]
},
"lint": {
"exclude": [
"./node_modules/",
"./out/",
"./package-lock.json"
]
"proseWrap": "preserve"
}
}
Loading
Loading