@vanillaskyai/video 0.10.8 → 0.10.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,14 @@ VanillaSky follows semantic versioning. This changelog begins with the 0.1 beta.
4
4
 
5
5
  ## Unreleased
6
6
 
7
+ ## 0.10.9
8
+
9
+ - Use essential subject hints and explicit exclusions when selecting starter Pexels footage, and isolate cached selections by those hints. Metadata-free results remain unverified provider-ranked fallbacks.
10
+
11
+ - Forward bounded optional subject/activity hints to Pexels resolvers from the existing planning stream, without adding fields to emitted scenes or AI-video requests.
12
+
13
+ - Clarify beginner instructions and condition-dependent advice, and retain essential subjects and activities in Pexels search planning.
14
+
7
15
  ## 0.10.8
8
16
 
9
17
  - Reassert a requested pause if native video playback starts late, preserving footage during delayed narration and keeping viewer pauses in place.
package/dist/server.js CHANGED
@@ -895,6 +895,21 @@ var object = (value) => value && typeof value === "object" && !Array.isArray(val
895
895
  function text(value, maximum) {
896
896
  return typeof value === "string" && value.trim().length <= maximum ? value.trim() : "";
897
897
  }
898
+ function readStockSelection(value) {
899
+ const item = object(value);
900
+ const phrase = (candidate) => {
901
+ if (typeof candidate !== "string") return;
902
+ const normalized = candidate.trim().replace(/\s+/gu, " ");
903
+ if (!normalized || normalized.length > 48 || !/^[\p{L}\p{N} '’-]+$/u.test(normalized)) return;
904
+ const words = normalized.match(/[\p{L}\p{N}]+/gu) ?? [];
905
+ return words.length >= 1 && words.length <= 4 ? normalized : void 0;
906
+ };
907
+ const subject = phrase(item?.subject);
908
+ if (!subject) return;
909
+ const activity = phrase(item?.activity), equipment = phrase(item?.equipment);
910
+ const exclude = Array.isArray(item?.exclude) && item.exclude.length <= 3 ? item.exclude.map(phrase).filter((value2) => value2 !== void 0) : [];
911
+ return { subject, ...activity ? { activity } : {}, ...equipment ? { equipment } : {}, ...exclude.length ? { exclude } : {} };
912
+ }
898
913
  function chapterSubject(subject) {
899
914
  const normalized = subject.replace(/\s+/gu, " ");
900
915
  if (normalized.length <= 65) return normalized;
@@ -912,6 +927,7 @@ function readShot(value, clipDurationSec, answerSubject = "") {
912
927
  return {
913
928
  narration,
914
929
  title,
930
+ stockSelection: readStockSelection(item?.stockSelection),
915
931
  subject,
916
932
  action: text(item?.action, 600),
917
933
  durationSec: typeof item?.durationSec === "number" && Number.isFinite(item.durationSec) ? Math.min(clipDurationSec, Math.max(2, item.durationSec)) : clipDurationSec,
@@ -964,7 +980,7 @@ function createChatShotPlanner(options) {
964
980
  return { type: "scene.add", ...closer ? { placement: "closer" } : {}, scene: {
965
981
  id: `${context.request.requestId}-shot-${++index}`,
966
982
  templateId: "cinemaMedia",
967
- variables: { fallbackText: shot.title, mediaType: "video", mediaKeyword: shot.subject, shotDirection: [
983
+ variables: { ...options.mode === "pexels" && shot.stockSelection ? { stockSelection: shot.stockSelection } : {}, fallbackText: shot.title, mediaType: "video", mediaKeyword: shot.subject, shotDirection: [
968
984
  brief?.visualDirection,
969
985
  shot.action,
970
986
  shot.continuity === "continue" ? "Continue the established subject, setting and action consistently." : "A deliberate new shot; choose framing that reveals this beat.",
@@ -1132,8 +1148,10 @@ function createVideoChatResponseInstructions(generatedVideoAvailable, openingAlr
1132
1148
  `First write one brief: {"type":"answer","intent":"explanation|story|comedy|imagination|practical","opening":"a short inviting spoken introduction of 6\u20139 words","subject":"literal visual subject","development":"the essential development of this answer","visualDirection":"consistent subjects, appearance and visual approach","ending":{"title":"short meaningful chapter title, at most 65 characters","narration":"the authored payoff","subject":"literal subject","action":"visible action or change","durationSec":${clipDurationSec},"continuity":"cut|continue"}}.`,
1133
1149
  `Then stream each developing shot on its own line: {"type":"shot","title":"short meaningful chapter title, at most 65 characters","narration":"the exact spoken beat","subject":"2\u20138 literal filmable words, at most 80 characters","action":"concrete subject, action or visible change and useful framing","durationSec":${clipDurationSec},"continuity":"cut|continue"}.`,
1134
1150
  `The selected footage mode is ${mode === "pexels" ? "Pexels stock search: use literal filmable subjects; never imply stock proves a mechanism or depicts fictional events exactly" : `AI video, with at most ${generatedVideoAvailable ? maxGeneratedVideos : 0} generation attempts`}. Missing footage becomes the authored chapter title, with complete narration. Preserve the full answer rather than shortening it to fit credits. The host selects providers; do not make source choices.`,
1151
+ ...mode === "pexels" ? ["Stock queries must retain the essential subject, activity and distinguishing equipment in the shot's subject field, within its word limit. That field alone is the search query; action and visualDirection do not refine it. Prefer common observable actions with usable framing. Do not replace the required actor or activity with scenery, a different sport or a loosely related setting. Preserve fictional or comic narration, but do not depend on stock showing an exact invented expression or sequence; choose an illustrative action that supports the beat."] : [],
1152
+ ...mode === "pexels" ? ['Include stockSelection on every shot and the saved ending when the essential subject is known: "stockSelection":{"subject":"essential actor or object category","activity":"optional literal activity","equipment":"optional distinguishing equipment","exclude":["optional contradictory subject or activity"]}. Each phrase must be 1\u20134 words and at most 48 characters; exclude has at most 3 phrases. The essential subject is separate from the setting: do not use scenery, mood, camera framing or incidental appearance as the actor. Keep the search query broad enough to find footage; the optional hint helps select results without substituting a different actor or task. Use exclusions only for actual contradictions, not every detail absent from the story. Omit unknown fields or the whole hint rather than inventing an anchor. This is selection guidance, not verification that footage depicts the exact narration.'] : [],
1135
1153
  "For a very short answer whose ending alone fulfills the request, development may be empty and no developing shots are needed. Otherwise, develop the essential content before the ending.",
1136
- "The brief's ending is saved and played after your developing shots. Do not repeat it as a shot. Stop writing after the last developing shot. No technical events, identifiers, template choices, media providers, URLs or extra fields.",
1154
+ "The brief's ending is saved and played after your developing shots. Do not repeat it as a shot. Stop writing after the last developing shot. No technical events, identifiers, template choices, media providers, URLs or unlisted fields.",
1137
1155
  "Every shot uses moving footage with separate narration and subtitles. Generated footage is silent: do not ask its subjects to speak or render words. No headline cards or on-screen explanatory text.",
1138
1156
  `Each clip has at most ${clipDurationSec} seconds. Write spoken beats that fit naturally, usually ${Math.floor(clipDurationSec * 1.6)}\u2013${Math.floor(clipDurationSec * 2)} words per shot. Split longer ideas across purposeful shots, preserving facts and qualifiers. Never truncate a claim to meet a word target. Use only the shots needed within the total duration, including the ending; do not pad to a fixed count.`,
1139
1157
  "Identify the full answer and its ending before developing shots. Each action must support what is said: camera movement alone is not progression. Vary scale, viewpoint and meaningful details while keeping subjects consistent.",
@@ -1141,7 +1159,7 @@ function createVideoChatResponseInstructions(generatedVideoAvailable, openingAlr
1141
1159
  "Stories: portray characters making choices and experiencing consequences; use consistent character descriptions and an earned resolution, not a promised next scene.",
1142
1160
  "Comedy: establish the premise, time the visual or spoken reveal, allow a reaction beat, and stop on the payoff without explaining the joke.",
1143
1161
  "Imagination: make the impossible action concrete, establish the world's internal rules and keep its imagery consistent. Do not replace imagination with an explanation of it.",
1144
- "Practical answers: show usable actions in their necessary order, with framing that makes the method and result visible. Preserve essential steps and relevant safety conditions.",
1162
+ "Practical answers: show usable actions in their necessary order, with framing that makes the method and result visible. Preserve essential steps and relevant safety conditions. Match the requested experience level. For beginners, explain an unavoidable technical term in ordinary words or replace it with an observable action. Make the essential setup and a useful success cue explicit. Qualify advice that depends on equipment, task or conditions instead of presenting one setup as universal. Never add unsupported precision merely to sound instructional.",
1145
1163
  openingAlreadyProvided ? "The supplied opening has already been spoken. Preserve it and begin the body with new content." : "The brief opening is spoken during preparation. The first body shot must develop it rather than repeat its words or claim.",
1146
1164
  "Use continuity=continue when the same subject/action should remain coherent; choose cut for a purposeful new view. Describe recurring subjects consistently. Never assume a different angle or generated depiction proves a factual claim."
1147
1165
  ].join("\n");
@@ -1630,6 +1648,7 @@ function createVideoChatHandler(options) {
1630
1648
  invalidPartBehavior: videoOptions.invalidPartBehavior,
1631
1649
  requireCloser: options.requireCloser ?? true,
1632
1650
  generate: createChatShotPlanner({
1651
+ mode,
1633
1652
  streamText: (context) => {
1634
1653
  lifecycle = getGenerationLifecycleSink(context);
1635
1654
  return videoOptions.streamText(context);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vanillaskyai/video",
3
- "version": "0.10.8",
3
+ "version": "0.10.9",
4
4
  "description": "Open-source voice-and-video chat SDK for AI applications.",
5
5
  "keywords": [
6
6
  "video-chat",
@@ -66,3 +66,26 @@ work and playback, and failed media becomes the authored chapter.
66
66
  The provider names its own model. Override the tested defaults with
67
67
  `ANTHROPIC_PLANNER_MODEL`, `ANTHROPIC_NARRATION_MODEL`, or `FAL_VIDEO_MODEL`
68
68
  when needed.
69
+
70
+ ### Stock selection hints
71
+
72
+ In Pexels mode, the same planning stream can supply an optional
73
+ `scene.variables.stockSelection` to the application's media resolver:
74
+
75
+ ```ts
76
+ { subject: "cyclist", activity: "riding", equipment: "bicycle", exclude: ["motorcycle"] }
77
+ ```
78
+
79
+ `subject` names the essential actor or object separately from the search query's
80
+ setting. `activity`, `equipment` and `exclude` are optional. Each phrase has
81
+ one to four words and at most 48 characters; `exclude` has at most three phrases.
82
+ The SDK validates these fields, drops unknown keys and invalid optional values,
83
+ and omits the whole hint when the essential subject is missing or invalid.
84
+ It never guesses that subject from the first query word.
85
+
86
+ Adapters can use this hint to prefer matching subjects and reject explicitly
87
+ contradictory metadata while keeping the query broad enough for catalog search.
88
+ Missing metadata remains uncertain, not proof of a match. The hint does not
89
+ verify the depicted action or factual correctness. It is omitted from AI-video
90
+ requests and removed before scenes are emitted or persisted; it adds no model
91
+ request or public scene field.
@@ -9,7 +9,7 @@
9
9
  "preview": "vite preview"
10
10
  },
11
11
  "dependencies": {
12
- "@vanillaskyai/video": "0.10.8",
12
+ "@vanillaskyai/video": "0.10.9",
13
13
  "react": "^19.2.8",
14
14
  "react-dom": "^19.2.8",
15
15
  "@ai-sdk/anthropic": "^3.0.0",
@@ -37,7 +37,7 @@ export const handleVideoChat = createVideoChatHandler({
37
37
  return text;
38
38
  },
39
39
  searchMedia: process.env.PEXELS_API_KEY
40
- ? (query, { orientation, signal }) => findStockFootage(query, orientation, signal)
40
+ ? (query, { orientation, signal, scene }) => findStockFootage(query, orientation, signal, scene?.variables.stockSelection)
41
41
  : undefined,
42
42
  ...providers,
43
43
  welcome: {
@@ -9,11 +9,27 @@ interface PexelsVideo {
9
9
  url?: string;
10
10
  image?: string;
11
11
  title?: unknown;
12
+ description?: unknown;
12
13
  tags?: unknown;
13
14
  video_files?: { link?: string; width?: number; height?: number; file_type?: string }[];
14
15
  }
15
16
  const cache = new Map<string, { expires: number; media: StockVideo | null }>();
16
17
  const words = (value: string): string[] => value.toLowerCase().match(/[\p{L}\p{N}]+/gu) ?? [];
18
+ const ignored = new Set(['a','an','the','in','on','at','of','with','and','to']);
19
+ const terms = (value: string) => words(value).filter(word => !ignored.has(word));
20
+ function selectionHint(value: unknown) {
21
+ const phrase = (input: unknown) => {
22
+ if (typeof input !== 'string') return undefined;
23
+ const normalized = input.trim().toLowerCase().replace(/\s+/gu,' ').replaceAll('’', "'");
24
+ return normalized.length <= 48 && /^[\p{L}\p{N} '-]+$/u.test(normalized) && words(normalized).length <= 4 && terms(normalized).length ? normalized : undefined;
25
+ };
26
+ const raw = value && typeof value === 'object' ? value as Record<string, unknown> : {};
27
+ const subject = phrase(raw.subject);
28
+ if (!subject) return undefined;
29
+ const activity = phrase(raw.activity), equipment = phrase(raw.equipment);
30
+ const exclude = Array.isArray(raw.exclude) && raw.exclude.length <= 3 ? raw.exclude.map(phrase).filter((item): item is string => Boolean(item)) : [];
31
+ return {subject, ...(activity ? {activity} : {}), ...(equipment ? {equipment} : {}), ...(exclude.length ? {exclude} : {})};
32
+ }
17
33
  function pexelsUrl(value: unknown): value is string {
18
34
  if (typeof value !== "string") return false;
19
35
  try {
@@ -27,11 +43,12 @@ function pexelsUrl(value: unknown): value is string {
27
43
  * Applications using this adapter must display a prominent link to Pexels.
28
44
  * https://www.pexels.com/api/documentation/#guidelines
29
45
  */
30
- export async function findStockFootage(query: string, orientation: VideoOrientation, signal: AbortSignal) {
46
+ export async function findStockFootage(query: string, orientation: VideoOrientation, signal: AbortSignal, rawSelection?: unknown) {
31
47
  signal.throwIfAborted();
32
48
  const normalized = query.trim().toLowerCase().replace(/\s+/g, " ");
33
49
  const tokens = words(normalized);
34
- const key = `${orientation}:${normalized}`;
50
+ const selection = selectionHint(rawSelection);
51
+ const key = JSON.stringify({version: 2, orientation, query: normalized, selection});
35
52
  const apiKey = process.env.PEXELS_API_KEY;
36
53
  if (!apiKey || !tokens.length || normalized.length > 80 || tokens.length > 8) return null;
37
54
  const existing = cache.get(key);
@@ -49,8 +66,14 @@ export async function findStockFootage(query: string, orientation: VideoOrientat
49
66
  const slug = new URL(video.url).pathname.replace(/^\/video\//, "");
50
67
  const title = typeof video.title === "string" ? video.title : "";
51
68
  const tags = Array.isArray(video.tags) ? video.tags.filter((tag): tag is string => typeof tag === "string").join(" ") : "";
52
- const subject = words(`${slug} ${title} ${tags}`).filter(token => !/^\d+$/.test(token));
53
- const matches = tokens.filter(token => subject.includes(token)).length;
69
+ const subject = words(`${slug} ${title} ${typeof video.description === "string" ? video.description : ""} ${tags}`).filter(token => !/^\d+$/.test(token));
70
+ let matches = tokens.filter(token => subject.includes(token)).length;
71
+ if (selection && subject.length) {
72
+ const covers = (phrase: string) => terms(phrase).every(word => subject.includes(word));
73
+ if (!covers(selection.subject) || selection.exclude?.some(covers)) continue;
74
+ matches = 2 + Number(Boolean(selection.activity && covers(selection.activity)))
75
+ + Number(Boolean(selection.equipment && covers(selection.equipment)));
76
+ }
54
77
  // The documented Video resource can have only a numeric page URL and no
55
78
  // editorial metadata. Preserve provider search order for unknown relevance;
56
79
  // positive overlap ranks above it, while explicitly unrelated copy is skipped.