-
Notifications
You must be signed in to change notification settings - Fork 129
Extract web UI API client and trace viewer into shared package #125
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
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
ca8d80d
Add `workflow web` command as an alias to `workflow inspect runs --web`
VaguelySerious 2e502b1
Hide trace viewer search bar if there are less than 10 spans
VaguelySerious 08c8a3a
Delete dead code
VaguelySerious cac18b9
Extract package
VaguelySerious 9d65f5e
Add UI picture in docs getting started guide
VaguelySerious 80f923e
Fix up
VaguelySerious 02f1d72
Add UI picture in docs getting started guide
VaguelySerious 8301bc7
Merge branch 'peter/more-web-commands' into peter/move
VaguelySerious 59b04d1
Changeset
VaguelySerious 58e24e2
Merge branch 'peter/more-web-commands' into peter/move
VaguelySerious 5266745
Fix build
VaguelySerious e8449ed
Merge branch 'main' into peter/move
VaguelySerious dc23d55
Don't ship test command
VaguelySerious eb03e44
Changeset
VaguelySerious a67d3ac
Merge branch 'main' into peter/move
VaguelySerious 9b3fa9a
Merge branch 'main' into peter/move
VaguelySerious e024f4f
Undo image change
VaguelySerious 8c9876a
Smol fix
VaguelySerious 5885bb3
Readme
VaguelySerious 507d391
Merge branch 'main' into peter/move
VaguelySerious c293841
Fix build
VaguelySerious 5f9fe2f
Fix build?
VaguelySerious bfd9a40
Update readme
VaguelySerious c3cf6e7
License
VaguelySerious 71948e3
Fix hydration to recreating runs
VaguelySerious 28a5603
So pedantic
VaguelySerious File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@workflow/web-shared": patch | ||
| "@workflow/web": patch | ||
| --- | ||
|
|
||
| Extract reusable web UI code into shared package |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
|
||
| # dependencies | ||
| /node_modules | ||
| /.pnp | ||
| .pnp.* | ||
| .yarn/* | ||
| !.yarn/patches | ||
| !.yarn/plugins | ||
| !.yarn/releases | ||
| !.yarn/versions | ||
|
|
||
| # testing | ||
| /coverage | ||
|
|
||
| # next.js | ||
| /.next/ | ||
| /out/ | ||
|
|
||
| # production | ||
| /build | ||
|
|
||
| # misc | ||
| .DS_Store | ||
| *.pem | ||
|
|
||
| # debug | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
| .pnpm-debug.log* | ||
|
|
||
| # env files (can opt-in for committing if needed) | ||
| .env* | ||
|
|
||
| # vercel | ||
| .vercel | ||
|
|
||
| # typescript | ||
| *.tsbuildinfo | ||
| next-env.d.ts | ||
| .env*.local |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../LICENSE.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # @workflow/web-shared | ||
|
|
||
| Workflow Observability tools for NextJS. See [Workflow DevKit](https://useworkflow.dev/docs/observability) for more information. | ||
|
|
||
| ## Usage | ||
|
|
||
| This package contains client and server code to interact with the Workflow API. | ||
| You can use it like so to display your own runs list: | ||
|
|
||
| ```tsx | ||
| import { useWorkflowRuns } from '@workflow/web-shared'; | ||
|
|
||
| export default function MyRunsList() { | ||
| const { | ||
| data, | ||
| error, | ||
| nextPage, | ||
| previousPage, | ||
| hasNextPage, | ||
| hasPreviousPage, | ||
| reload, | ||
| pageInfo, | ||
| } = useWorkflowRuns(env, { | ||
| sortOrder, | ||
| workflowName: workflowNameFilter === 'all' ? undefined : workflowNameFilter, | ||
| status: status === 'all' ? undefined : status, | ||
| }); | ||
|
|
||
| // Shows an interactive trace viewer for the given run | ||
| return <div>{runs.map((run) => ( | ||
| <div key={run.runId}> | ||
| {run.workflowName} | ||
| {run.status} | ||
| {run.startedAt} | ||
| {run.completedAt} | ||
| </div> | ||
| ))}</div>; | ||
| } | ||
| ``` | ||
|
|
||
| It also comes with a pre-styled interactive trace viewer that you can use to display the trace for a given run: | ||
|
|
||
| ```tsx | ||
| import { RunTraceView } from '@workflow/web-shared'; | ||
|
|
||
| export default function MyRunDetailView({ env, runId }: { env: EnvMap, runId: string }) { | ||
| // ... your other code | ||
|
|
||
| // Shows an interactive trace viewer for the given run | ||
| return <RunTraceView env={env} runId={runId} />; | ||
| } | ||
| ``` | ||
|
|
||
| ## Environment Variables | ||
|
|
||
| For API calls to work, you'll need to pass the same environment variables that are used by the Workflow CLI. | ||
| See `npx workflow inspect --help` for more information. | ||
|
|
||
| If you're deploying this as part of your Vercel NextJS app, setting `WORKFLOW_TARGET_WORLD` to `vercel` is enough | ||
| to infer your other project details from the Vercel environment variables. | ||
|
|
||
| ## Styling | ||
|
|
||
| In order for tailwind classes to be picked up correctly, you might need to configure your NextJS app | ||
| to use the correct CSS processor. E.g. if you're using PostCSS with TailwindCSS, you can do the following: | ||
|
|
||
| ```tsx | ||
| // postcss.config.mjs in your NextJS app | ||
| const config = { | ||
| plugins: ['@tailwindcss/postcss'], | ||
| }; | ||
|
|
||
| export default config; | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you also symlink the LICENSE from the repo root please like we do in all the other packages? |
||
| "name": "@workflow/web-shared", | ||
| "description": "Shared components for Workflow Observability UI", | ||
| "version": "4.0.1-beta.4", | ||
| "private": false, | ||
| "files": [ | ||
| "dist" | ||
| ], | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "license": "MIT", | ||
| "exports": { | ||
| ".": { | ||
| "types": "./dist/index.d.ts", | ||
| "default": "./dist/index.js" | ||
| }, | ||
| "./server": { | ||
| "types": "./dist/api/workflow-server-actions.d.ts", | ||
| "default": "./dist/api/workflow-server-actions.js" | ||
| } | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/vercel/workflow.git", | ||
| "directory": "packages/web-shared" | ||
| }, | ||
| "scripts": { | ||
| "build": "tsc && cp -r src/trace-viewer/*.css dist/trace-viewer/", | ||
| "dev": "tsc --watch", | ||
| "clean": "tsc --build --clean && rm -r dist ||:", | ||
| "typecheck": "tsc --noEmit", | ||
| "lint": "biome check", | ||
| "format": "biome format --write" | ||
| }, | ||
| "dependencies": { | ||
| "@tailwindcss/postcss": "^4", | ||
| "@workflow/core": "workspace:*", | ||
| "@workflow/world": "workspace:*", | ||
| "class-variance-authority": "^0.7.1", | ||
| "clsx": "^2.1.1", | ||
| "date-fns": "^4.1.0", | ||
| "lucide-react": "^0.469.0", | ||
| "react": "19.1.0", | ||
| "react-dom": "19.1.0", | ||
| "sonner": "^2.0.7", | ||
| "swr": "^2.3.6", | ||
| "tailwind-merge": "^2.5.5", | ||
| "tailwindcss": "^4" | ||
| }, | ||
| "devDependencies": { | ||
| "@biomejs/biome": "catalog:", | ||
| "@types/node": "catalog:", | ||
| "@types/react": "^19", | ||
| "@types/react-dom": "^19", | ||
| "typescript": "catalog:", | ||
| "@workflow/tsconfig": "workspace:*" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| const config = { | ||
| plugins: ['@tailwindcss/postcss'], | ||
| }; | ||
|
|
||
| export default config; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import { cva, type VariantProps } from 'class-variance-authority'; | ||
| import * as React from 'react'; | ||
|
|
||
| import { cn } from '../../lib/utils'; | ||
|
|
||
| const alertVariants = cva( | ||
| 'relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground', | ||
| { | ||
| variants: { | ||
| variant: { | ||
| default: 'bg-background text-foreground', | ||
| destructive: | ||
| 'border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive', | ||
| }, | ||
| }, | ||
| defaultVariants: { | ||
| variant: 'default', | ||
| }, | ||
| } | ||
| ); | ||
|
|
||
| const Alert = React.forwardRef< | ||
| HTMLDivElement, | ||
| React.HTMLAttributes<HTMLDivElement> & VariantProps<typeof alertVariants> | ||
| >(({ className, variant, ...props }, ref) => ( | ||
| <div | ||
| ref={ref} | ||
| role="alert" | ||
| className={cn(alertVariants({ variant }), className)} | ||
| {...props} | ||
| /> | ||
| )); | ||
| Alert.displayName = 'Alert'; | ||
|
|
||
| const AlertTitle = React.forwardRef< | ||
| HTMLParagraphElement, | ||
| React.HTMLAttributes<HTMLHeadingElement> | ||
| >(({ className, ...props }, ref) => ( | ||
| <h5 | ||
| ref={ref} | ||
| className={cn('mb-1 font-medium leading-none tracking-tight', className)} | ||
| {...props} | ||
| /> | ||
| )); | ||
| AlertTitle.displayName = 'AlertTitle'; | ||
|
|
||
| const AlertDescription = React.forwardRef< | ||
| HTMLParagraphElement, | ||
| React.HTMLAttributes<HTMLParagraphElement> | ||
| >(({ className, ...props }, ref) => ( | ||
| <div | ||
| ref={ref} | ||
| className={cn('text-sm [&_p]:leading-relaxed', className)} | ||
| {...props} | ||
| /> | ||
| )); | ||
| AlertDescription.displayName = 'AlertDescription'; | ||
|
|
||
| export { Alert, AlertTitle, AlertDescription }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { type ClassValue, clsx } from 'clsx'; | ||
| import { twMerge } from 'tailwind-merge'; | ||
|
|
||
| export function cn(...inputs: ClassValue[]) { | ||
| return twMerge(clsx(inputs)); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a formatted pagination display string | ||
| * @param currentPage - The current page number | ||
| * @param totalPages - The total number of pages visited so far | ||
| * @param hasMore - Whether there are more pages available | ||
| * @returns Formatted string like "Page 1 of 3+" or "Page 2 of 2" | ||
| */ | ||
| export function getPaginationDisplay( | ||
| currentPage: number, | ||
| totalPages: number, | ||
| hasMore: boolean | ||
| ): string { | ||
| if (hasMore) { | ||
| return `Page ${currentPage} of ${totalPages}+`; | ||
| } | ||
| return `Page ${currentPage} of ${totalPages}`; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this just a formatting change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes - must have originally not been formatted with biome