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(core): typing fixes #13

Merged
merged 9 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
"ignore": [],
"snapshot": {
"useCalculatedVersion": true,
"prereleaseTemplate": "{tag}-{datetime}-{commit}"
}
}
5 changes: 5 additions & 0 deletions .changeset/khaki-bikes-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@inngest/workflow-kit": patch
---

feat(core): typing fixes
41 changes: 41 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: "canary"
on:
pull_request:
branches:
- main
paths:
- ".changeset/**/*.md"

env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
# Used to fetch all history so that changesets doesn't attempt to
# publish duplicate tags.
fetch-depth: 0
# Replaces `concurrency` - never cancels any jobs
- uses: softprops/turnstyle@v1
with:
poll-interval-seconds: 30
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install pnpm
uses: pnpm/action-setup@v4
- run: pnpm install
- uses: "the-guild-org/[email protected]"
with:
tag: "alpha"
prepareScript: "pnpm run build"
env:
GITHUB_TOKEN: ${{ secrets.CHANGESET_GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_ENV: test # disable npm access checks; they don't work in CI
4 changes: 2 additions & 2 deletions examples/nextjs-blog-cms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ npm i
# or
yarn
# or
pnpm
pnpm --ignore-workspace i
```

3. Finally, copy your local `.env.example` as `.env.local` and fill your `OPENAI_API_KEY`.
Expand Down Expand Up @@ -114,7 +114,7 @@ To run this demo locally, you'll need the following:

Use the below button to deploy this template to Vercel:

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Finngest%2Fworkflow-kit%2Ftree%2Fmain%2Fexamples%2Fnextjs-blog-cms%2F&project-name=nextjs-blog-cms-ai-workflow-with-inngest&repository-name=workflow-kit&demo-title=nextjs-blog-cms-ai-workflow-with-inngest&demo-description=Next.js%20blog%20back-office%20featuring%20some%20AI%20workflows%20helping%20with%20grammar%20fixes%2C%20generating%20Table%20of%20Contents%20or%20Tweets&demo-image=https%3A%2F%2Fraw.githubusercontent.com%2Finngest%2Fworkflow-kit%2Frefs%2Fheads%2Fmain%2Fworkflow-kit.jpg)
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?install-command=pnpm%20--ignore-workspace%20i&repository-url=https%3A%2F%2Fgithub.com%2Finngest%2Fworkflow-kit%2Ftree%2Fmain%2Fexamples%2Fnextjs-blog-cms%2F&project-name=nextjs-blog-cms-ai-workflow-with-inngest&repository-name=workflow-kit&demo-title=nextjs-blog-cms-ai-workflow-with-inngest&demo-description=Next.js%20blog%20back-office%20featuring%20some%20AI%20workflows%20helping%20with%20grammar%20fixes%2C%20generating%20Table%20of%20Contents%20or%20Tweets&demo-image=https%3A%2F%2Fraw.githubusercontent.com%2Finngest%2Fworkflow-kit%2Frefs%2Fheads%2Fmain%2Fworkflow-kit.jpg)

**Once deployed, make sure to configure your `OPENAI_API_KEY` environment variable.**

Expand Down
2 changes: 1 addition & 1 deletion examples/nextjs-blog-cms/app/blog-post/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default async function BlogPost({ params }: { params: { id: string } }) {
MDXBlogPostAIContent = (
await evaluate(
blogPost.markdown_ai_revision ||
blogPost.ai_publishing_recommendations,
blogPost.ai_publishing_recommendations!,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
runtime as any
)
Expand Down
1 change: 0 additions & 1 deletion examples/nextjs-blog-cms/lib/inngest/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { actionsWithHandlers } from "./workflowActionHandlers";

const workflowEngine = new Engine({
actions: actionsWithHandlers,
// @ts-expect-error FIX
loader: loadWorkflow,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { type EngineAction, type WorkflowAction } from "@inngest/workflow-kit";
import OpenAI from "openai";

Expand All @@ -7,6 +6,7 @@ import { type BlogPost } from "../supabase/types";
import { loadBlogPost } from "../loaders/blog-post";
import { createClient } from "../supabase/server";
import { actions } from "./workflowActions";
import { inngest } from "./client";

// helper to ensure that each step of the workflow use
// the original content or current AI revision
Expand All @@ -28,7 +28,7 @@ function addAiPublishingSuggestion(
: blogPost.ai_publishing_recommendations + `<br/ >` + additionalSuggestion; // otherwise add one
}

export const actionsWithHandlers: EngineAction[] = [
export const actionsWithHandlers: EngineAction<typeof inngest>[] = [
{
// Add a Table of Contents
...actions[0],
Expand Down
5 changes: 2 additions & 3 deletions examples/nextjs-blog-cms/lib/inngest/workflowActions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// import { type PublicEngineAction } from "@inngest/workflow-kit";
import { type PublicEngineAction } from "@inngest/workflow-kit";

// Actions
// - Review actions
Expand All @@ -9,8 +9,7 @@
// - Post-publish actions
// - Get Tweet verbatim
// - Get LinkedIn verbatim
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const actions: any[] = [
export const actions: PublicEngineAction[] = [
{
kind: "add_ToC",
name: "Add a Table of Contents",
Expand Down
11 changes: 9 additions & 2 deletions examples/nextjs-blog-cms/lib/loaders/blog-post.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createClient } from "../supabase/server";
import { BlogPost } from "../supabase/types";

export async function loadBlogPost(id: string) {
export async function loadBlogPost(id: string): Promise<BlogPost> {
const supabase = createClient();
const { data: blogPosts } = await supabase
.from("blog_posts")
Expand All @@ -10,5 +11,11 @@ export async function loadBlogPost(id: string) {
.eq("id", id)
.limit(1);

return blogPosts && blogPosts[0];
const blogPost = blogPosts && blogPosts[0];

if (!blogPost) {
throw new Error(`Blog post #${id} not found`);
}

return blogPost;
}
2 changes: 1 addition & 1 deletion examples/nextjs-blog-cms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"@inngest/workflow-kit": "0.1.2",
"@inngest/workflow-kit": "0.1.3-alpha-20240927112743-cfb6053c0cb7347670c83bb0edcd2edaedd11d9c",
"@mdx-js/mdx": "^3.0.1",
"@radix-ui/react-checkbox": "^1.1.1",
"@radix-ui/react-icons": "^1.3.0",
Expand Down
23 changes: 5 additions & 18 deletions examples/nextjs-blog-cms/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/workflow/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
"@xyflow/react": "^12.1.1",
"graphology": "^0.25.4",
"graphology-dag": "^0.4.1",
"inngest": "^3.19.14",
"json-logic-js": "^2.0.5",
"jsonpath": "^1.1.1",
"reactflow": "^11.11.3"
Expand All @@ -88,6 +87,7 @@
"@types/jsonpath": "^0.2.4",
"@types/node": "^22.5.5",
"@types/react": "^18.3.5",
"inngest": "^3.19.14",
"jest": "^29.7.0",
"preset": "link:@storybook/react-vite/preset",
"prop-types": "^15.8.1",
Expand Down
32 changes: 18 additions & 14 deletions packages/workflow/src/builtin.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { builtinActions } from "./builtin";
import { resolveInputs } from "./interpolation";
import { ActionHandler, ActionHandlerArgs, Workflow, WorkflowAction } from "./types";
import {
ActionHandler,
ActionHandlerArgs,
Workflow,
WorkflowAction,
} from "./types";

describe("builtin:if", () => {
// This tests the handler logic of the builtin:if action.
Expand All @@ -14,8 +19,8 @@ describe("builtin:if", () => {
id: "1",
kind: "builtin:if",
inputs: {
condition: { "==": [1, 1] }
}
condition: { "==": [1, 1] },
},
};

let result = await action.handler(handlerInput(workflowAction));
Expand All @@ -27,7 +32,7 @@ describe("builtin:if", () => {
});

it("evaluates complex conditions with refs", async () => {
const state = new Map(Object.entries({"action_a": 1.123}));
const state = new Map(Object.entries({ action_a: 1.123 }));
const event = { data: { name: "jimothy" } };

const workflowAction: WorkflowAction = {
Expand All @@ -36,21 +41,21 @@ describe("builtin:if", () => {
inputs: resolveInputs(
{
condition: {
"and": [
and: [
{ "==": ["!ref($.state.action_a)", 1.123] },
{ "==": ["!ref($.event.data.name)", "jimothy"] },
]
],
},
},
{ state: Object.fromEntries(state), event }
)
),
};

let result = await action.handler({
workflowAction,
event,
state,
step: {},
step: {} as any,
workflow: {
actions: [workflowAction],
edges: [],
Expand All @@ -66,16 +71,15 @@ describe("builtin:if", () => {
event: {
data: {
age: 82.1,
likes: ["a"]
}
likes: ["a"],
},
},
step: {},
workflow: {
actions: [workflowAction],
edges: [],
},
state: new Map(),
}
}

});
};
};
});
1 change: 1 addition & 0 deletions packages/workflow/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export {
type RunArgs,
type EngineOptions,
type EngineAction,
type PublicEngineAction,
type WorkflowAction,
type Loader,
type Workflow,
Expand Down
Loading
Loading