-
Notifications
You must be signed in to change notification settings - Fork 541
feat: hand off video turns to local watch-skill #63
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
Closed
carbongotfound
wants to merge
3
commits into
milind-soni:main
from
carbongotfound:feat/watch-skill-handoff
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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,16 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { videoReferences } from "./watch-skill.ts"; | ||
| describe("watch-skill handoff", () => { | ||
| it("recognizes supported video URLs but ignores normal links", () => expect(videoReferences("see https://youtu.be/demo https://example.com/a https://cdn.x/demo.webm")).toEqual(["https://youtu.be/demo", "https://cdn.x/demo.webm"])); | ||
| it("does not treat prose as a video reference", () => expect(videoReferences("please explain this recording")).toEqual([])); | ||
|
|
||
| it("accepts provider video paths but rejects ordinary supported-host pages", () => { | ||
| expect(videoReferences("https://youtube.com/channel/example https://vimeo.com/12345 https://twitch.tv/videos/77 https://loom.com/share/abc")) | ||
| .toEqual(["https://vimeo.com/12345", "https://twitch.tv/videos/77", "https://loom.com/share/abc"]); | ||
| }); | ||
|
|
||
| it("keeps direct video queries while removing surrounding prose punctuation", () => { | ||
| expect(videoReferences("Watch (https://cdn.example/demo.webm?download=1), then reply.")) | ||
| .toEqual(["https://cdn.example/demo.webm?download=1"]); | ||
| }); | ||
| }); |
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,40 @@ | ||
| import { execFile } from "node:child_process"; | ||
|
|
||
| const VIDEO_URL = /https?:\/\/[^\s<>()]+/gi; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| const VIDEO_FILE = /\.(mp4|mov|mkv|webm|avi|m4v)(?:[?#].*)?$/i; | ||
| let availability: Promise<boolean> | undefined; | ||
|
|
||
| function isHostedVideo(url: URL) { | ||
| const host = url.hostname.toLowerCase(); | ||
| const path = url.pathname.replace(/\/+$/, ""); | ||
| if (host === "youtu.be") return path.length > 1; | ||
| if (host.endsWith("youtube.com")) return (path === "/watch" && Boolean(url.searchParams.get("v"))) || /^\/(shorts|live|embed)\/[^/]+$/i.test(path); | ||
| if (host.endsWith("vimeo.com")) return /^\/(video\/)?\d+$/i.test(path); | ||
| if (host === "clips.twitch.tv") return path.length > 1; | ||
| if (host.endsWith("twitch.tv")) return /^\/videos\/\d+$/i.test(path) || /^\/[^/]+\/clip\/[^/]+$/i.test(path); | ||
| if (host.endsWith("loom.com")) return /^\/(share|embed)\/[^/]+$/i.test(path); | ||
| return false; | ||
| } | ||
|
|
||
| /** Conservative detection: ordinary links do not start a video workflow. */ | ||
| export function videoReferences(text: string): string[] { | ||
| return (text.match(VIDEO_URL) ?? []).flatMap((raw) => { | ||
| const candidate = raw.replace(/[.,;:'"\]\)]+$/, ""); | ||
| try { | ||
| const url = new URL(candidate); | ||
| return isHostedVideo(url) || VIDEO_FILE.test(url.pathname) ? [candidate] : []; | ||
| } catch { return []; } | ||
| }); | ||
| } | ||
|
|
||
| /** No install/fetch side effect. Users opt in by installing watch-skill locally. */ | ||
| export function hasWatchSkill(command = "watch-skill"): Promise<boolean> { | ||
| if (command === "watch-skill" && availability) return availability; | ||
| const probe = new Promise<boolean>((resolve) => { | ||
| execFile(command, ["--version"], { windowsHide: true, timeout: 2_000 }, (error) => resolve(!error)); | ||
| }); | ||
| if (command === "watch-skill") availability = probe; | ||
| return probe; | ||
| } | ||
|
|
||
| export function watchSkillIntegration(command = "watch-skill") { return { command, args: ["serve"], env: {} as Record<string, string> }; } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.