@opencraw/studio 0.0.39 → 0.0.41

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/dist/index.esm.js CHANGED
@@ -3,7 +3,7 @@ import { createServer } from 'node:http';
3
3
  import { promisify, stripVTControlCharacters } from 'node:util';
4
4
  import { fileURLToPath, pathToFileURL } from 'node:url';
5
5
  import { z } from 'zod';
6
- import { BODY_KINDS, formatOfResponse, HttpClient, BrowserClient, NODE_ID_ATTRIBUTE, sessionStateOf, readRecipeSource, parseInputRecipe, parseOutputRecipe, calloutLabel, bindRecipeSet, memorySink, createCrawler, traceLine, UnknownHookError, rowsOfCells, parseXml, marginRows, findDeckTables, findGridTables, analyzeTables, parseRegion, regionText, deckRegionText, isDeckDocument, resolveMissingPolicy, isWorkbookDocument, RecipeBindingError, RecipeValidationError, countMatches, matchesOf, tryParseJson, isPdfDocument, BrowserProfiles } from '@opencraw/core';
6
+ import { BODY_KINDS, videoIdOf, formatOfResponse, HttpClient, BrowserClient, NODE_ID_ATTRIBUTE, sessionStateOf, readRecipeSource, parseInputRecipe, parseOutputRecipe, calloutLabel, bindRecipeSet, memorySink, createCrawler, traceLine, UnknownHookError, rowsOfCells, parseXml, marginRows, findDeckTables, findGridTables, analyzeTables, parseRegion, regionText, deckRegionText, isDeckDocument, resolveMissingPolicy, isWorkbookDocument, RecipeBindingError, RecipeValidationError, countMatches, matchesOf, tryParseJson, isPdfDocument, BrowserProfiles } from '@opencraw/core';
7
7
  import { randomBytes, randomUUID, createHash } from 'node:crypto';
8
8
  import { execFile } from 'node:child_process';
9
9
  import { mkdir, writeFile, chmod, rm, readFile, rename, stat } from 'node:fs/promises';
@@ -679,7 +679,7 @@ const sampleRunViewSchema = z.object({
679
679
  * browser); `json`, `pdf`, `csv`, `xlsx`, `markdown`, `xml`... are documents (read with a request); `unknown` when it could not be fetched.
680
680
  */
681
681
  const detectUrlViewSchema = z.object({
682
- kind: z.enum(['html', 'json', 'jsonl', 'text', 'pdf', 'csv', 'xlsx', 'pptx', 'yaml', 'markdown', 'xml', 'docx', 'unknown'])
682
+ kind: z.enum(['html', 'json', 'jsonl', 'text', 'pdf', 'csv', 'xlsx', 'pptx', 'yaml', 'markdown', 'xml', 'docx', 'youtube', 'unknown'])
683
683
  });
684
684
 
685
685
  /** What `fetch-start-page` answers with. */
@@ -1202,12 +1202,14 @@ const TIMEOUT_MS = 20_000;
1202
1202
  * What an address returns: the format the engine reads its response as (content type, then what the first bytes
1203
1203
  * show, then the file extension in the address), and, for an API that serves JSON as `text/plain` (common), JSON when
1204
1204
  * the text starts like an object or an array. Only the start of the response is read: a large file is not downloaded.
1205
- * An address that cannot be fetched is `unknown`; the recipe started from it then reports why on its first snapshot.
1205
+ * The address of a YouTube video is `youtube` without being fetched. An address that cannot be fetched is `unknown`; the recipe started from it then reports why on its first snapshot.
1206
1206
  *
1207
1207
  * @param url - The address.
1208
1208
  * @returns The kind: `html` is a page to open in a browser, anything else a document to read.
1209
1209
  */
1210
1210
  async function detectUrlKind(url) {
1211
+ // A video's address is read as a video (its details and transcript), not fetched as the page it opens in a browser.
1212
+ if (/^https?:/i.test(url.trim()) && videoIdOf(url) !== undefined) return 'youtube';
1211
1213
  const controller = new AbortController();
1212
1214
  const timer = setTimeout(() => {
1213
1215
  controller.abort();
@@ -1,10 +1,10 @@
1
1
  /** What an address returns, in the engine's own words (`html` is a page; anything else is a document it reads), or `unknown` when it cannot be fetched. */
2
- export type UrlKind = 'html' | 'json' | 'jsonl' | 'text' | 'pdf' | 'csv' | 'xlsx' | 'pptx' | 'yaml' | 'markdown' | 'xml' | 'docx' | 'unknown';
2
+ export type UrlKind = 'html' | 'json' | 'jsonl' | 'text' | 'pdf' | 'csv' | 'xlsx' | 'pptx' | 'yaml' | 'markdown' | 'xml' | 'docx' | 'youtube' | 'unknown';
3
3
  /**
4
4
  * What an address returns: the format the engine reads its response as (content type, then what the first bytes
5
5
  * show, then the file extension in the address), and, for an API that serves JSON as `text/plain` (common), JSON when
6
6
  * the text starts like an object or an array. Only the start of the response is read: a large file is not downloaded.
7
- * An address that cannot be fetched is `unknown`; the recipe started from it then reports why on its first snapshot.
7
+ * The address of a YouTube video is `youtube` without being fetched. An address that cannot be fetched is `unknown`; the recipe started from it then reports why on its first snapshot.
8
8
  *
9
9
  * @param url - The address.
10
10
  * @returns The kind: `html` is a page to open in a browser, anything else a document to read.
@@ -1,10 +1,10 @@
1
1
  /** What an address returns, in the engine's own words (`html` is a page; anything else is a document it reads), or `unknown` when it cannot be fetched. */
2
- export type UrlKind = 'html' | 'json' | 'jsonl' | 'text' | 'pdf' | 'csv' | 'xlsx' | 'pptx' | 'yaml' | 'markdown' | 'xml' | 'docx' | 'unknown';
2
+ export type UrlKind = 'html' | 'json' | 'jsonl' | 'text' | 'pdf' | 'csv' | 'xlsx' | 'pptx' | 'yaml' | 'markdown' | 'xml' | 'docx' | 'youtube' | 'unknown';
3
3
  /**
4
4
  * What an address returns: the format the engine reads its response as (content type, then what the first bytes
5
5
  * show, then the file extension in the address), and, for an API that serves JSON as `text/plain` (common), JSON when
6
6
  * the text starts like an object or an array. Only the start of the response is read: a large file is not downloaded.
7
- * An address that cannot be fetched is `unknown`; the recipe started from it then reports why on its first snapshot.
7
+ * The address of a YouTube video is `youtube` without being fetched. An address that cannot be fetched is `unknown`; the recipe started from it then reports why on its first snapshot.
8
8
  *
9
9
  * @param url - The address.
10
10
  * @returns The kind: `html` is a page to open in a browser, anything else a document to read.
@@ -18,6 +18,7 @@ export declare const detectUrlViewSchema: z.ZodObject<{
18
18
  markdown: "markdown";
19
19
  xml: "xml";
20
20
  docx: "docx";
21
+ youtube: "youtube";
21
22
  }>;
22
23
  }, z.core.$strip>;
23
24
  export type DetectUrlView = z.infer<typeof detectUrlViewSchema>;
@@ -24,6 +24,7 @@ export declare const snapshotViewSchema: z.ZodObject<{
24
24
  markdown: "markdown";
25
25
  xml: "xml";
26
26
  docx: "docx";
27
+ youtube: "youtube";
27
28
  }>>;
28
29
  notice: z.ZodOptional<z.ZodString>;
29
30
  }, z.core.$strip>;
@@ -18,6 +18,7 @@ export declare const detectUrlViewSchema: z.ZodObject<{
18
18
  xlsx: "xlsx";
19
19
  xml: "xml";
20
20
  yaml: "yaml";
21
+ youtube: "youtube";
21
22
  }>;
22
23
  }, z.core.$strip>;
23
24
  export type DetectUrlView = z.infer<typeof detectUrlViewSchema>;
@@ -24,6 +24,7 @@ export declare const snapshotViewSchema: z.ZodObject<{
24
24
  xlsx: "xlsx";
25
25
  xml: "xml";
26
26
  yaml: "yaml";
27
+ youtube: "youtube";
27
28
  }>>;
28
29
  notice: z.ZodOptional<z.ZodString>;
29
30
  }, z.core.$strip>;