SPB Git

Repository Public

types.ts 10.5 KB 418 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : SPIDER — Universal Web Intelligence Engine8 * File             : sdk/typescript/src/types.ts9 * Module           : Sdk10 * Repository       : https://git.spboucher.ai/spider11 * Project Website  : Not specified12 * Created          : 2026-12-0413 * Last Modified    : 2026-12-0414 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: contact@spboucher.ai23 * Development      : dev@spboucher.ai24 * Support          : support@spboucher.ai25 * Security/Admin   : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License          : ISC34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243/**44 * Request and response types of the SPIDER API (contract v1).45 *46 * Request types list every option of the contract. `PolicyOptions` has no `respect_robots_txt` and47 * no `stop_on_access_denied`: SPIDER always honours robots.txt and always stops on an access48 * denial, the server refuses any attempt to disable either, and the SDK offers no way to ask.49 * Response types name the documented fields and accept unknown ones.50 */51import type { JOB_STATES } from "./routes.js";5253export type JobStatus = (typeof JOB_STATES)[number];54export type JobKind =55  | "scrape" | "crawl" | "map" | "screenshot" | "deep_capture" | "extract" | "ocr" | "vision" | "batch"56  | "monitor_run";57export type Render = "auto" | "http" | "browser";58export type Profile = "desktop" | "mobile" | "tablet";59export type Format = "markdown" | "json" | "text" | "html" | "links" | "tables" | "structured" | "media";60export type WebhookEventName = "job.finished" | "job.progress" | "change.detected";61export type WatchKind = "content" | "layout" | "fields" | "visual";62export type ExportFormat = "jsonl" | "csv" | "markdown" | "html" | "zip";63export type MonitorAction = "enable" | "disable" | "run-now" | "delete";64export type JsonObject = Record<string, unknown>;6566export interface Budgets {67  max_pages?: number;68  max_depth?: number;69  max_states_per_page?: number;70  max_actions_per_page?: number;71  max_bytes?: number;72  max_duration_s?: number;73  max_urls_per_pattern?: number;74}7576export interface CaptureOptions {77  viewport?: boolean;78  full_page?: boolean;79  tiles?: boolean;80  tile_height?: number;81  tile_width?: number;82  tile_overlap?: number;83  elements?: string[];84  sections?: boolean;85  interactive_states?: boolean;86  profiles?: Profile[];87  engine?: "chromium" | "webkit";88  device_scale_factor?: number;89  locale?: string;90  timezone?: string;91  webp_derivatives?: boolean;92  pdf?: boolean;93}9495export interface ExtractOptions {96  formats?: Format[];97  ocr?: boolean;98  ocr_languages?: string[];99  vision?: "off" | "on_conflict" | "always";100  include_evidence?: boolean;101  /** A JSON Schema of type object; the custom keyword `x-aliases` lists the labels of a field. */102  schema?: JsonObject;103  schema_id?: string;104  rules?: JsonObject;105  connector_id?: string;106}107108/** Scope and politeness. robots.txt compliance and stop-on-access-denial are not options. */109export interface PolicyOptions {110  same_origin_only?: boolean;111  include_subdomains?: boolean;112  allow_domains?: string[];113  exclude_paths?: string[];114  include_paths?: string[];115  min_delay_ms?: number;116}117118export interface WebhookOptions {119  url: string;120  events?: WebhookEventName[];121}122123interface JobBase {124  policy?: PolicyOptions;125  webhook?: WebhookOptions;126  priority?: number;127  metadata?: Record<string, string>;128}129130export interface ScrapeRequest extends JobBase {131  url: string;132  render?: Render;133  capture?: CaptureOptions;134  extract?: ExtractOptions;135  timeout_s?: number;136}137138export interface CrawlRequest extends JobBase {139  /** One of `url`, `urls` or `sitemap` is required. */140  url?: string;141  urls?: string[];142  sitemap?: string;143  strategy?: "bfs" | "dfs" | "priority";144  render?: Render;145  max_depth?: number;146  max_pages?: number;147  max_states_per_page?: number;148  budgets?: Budgets;149  capture?: CaptureOptions;150  extract?: ExtractOptions;151  use_sitemaps?: boolean;152}153154export interface MapRequest extends JobBase {155  url: string;156  budgets?: Budgets;157  use_sitemaps?: boolean;158  render?: "http" | "browser";159}160161export interface ScreenshotRequest extends JobBase {162  url: string;163  capture?: CaptureOptions;164  timeout_s?: number;165}166167export interface DeepCaptureRequest extends JobBase {168  url: string;169  capture?: CaptureOptions;170  budgets?: Budgets;171  extract?: ExtractOptions;172  timeout_s?: number;173}174175export interface ExtractRequest extends JobBase {176  url: string;177  render?: Render;178  /** Needs `schema`, `schema_id` or `connector_id`. */179  extract: ExtractOptions;180}181182export interface OcrRequest {183  artifact_id: string;184  languages?: string[];185  fast?: boolean;186}187188export interface VisionRequest {189  /** 1 to 4 image artifacts. */190  artifact_ids: string[];191  task?: "describe" | "fields";192  schema?: JsonObject;193  model?: string;194}195196export type BatchItem =197  | { kind: "scrape"; request: ScrapeRequest }198  | { kind: "screenshot"; request: ScreenshotRequest }199  | { kind: "extract"; request: ExtractRequest }200  | { kind: "deep_capture"; request: DeepCaptureRequest };201202export interface BatchRequest {203  items: BatchItem[];204}205206export interface MonitorRequest {207  name: string;208  request: ScrapeRequest;209  interval_s?: number;210  watch?: WatchKind[];211  ignore_selectors?: string[];212  cooldown_s?: number;213  enabled?: boolean;214}215216export interface DiffRequest {217  snapshot_a: string;218  snapshot_b: string;219  visual?: boolean;220  ignore_selectors?: string[];221}222223export interface SearchRequest {224  query: string;225  site_id?: string;226  domain?: string;227  since?: string;228  until?: string;229  limit?: number;230  cursor?: string;231}232233// ----------------------------------------------------------------------------- responses234export interface Job {235  job_id: string;236  kind: JobKind;237  status: JobStatus;238  priority: number;239  created_at: string;240  started_at: string | null;241  finished_at: string | null;242  site_id: string | null;243  status_url: string;244  results_url: string;245  events_url: string;246  progress: {247    pages_admitted: number;248    bytes_used: number;249    urls: Record<string, number>;250    budgets_hit: string[];251    skipped: Record<string, number>;252    [key: string]: unknown;253  };254  error: unknown;255  /** Present and true when the submission was answered from an earlier one with the same Idempotency-Key. */256  idempotent_replay?: boolean;257  [key: string]: unknown;258}259260export interface ArtifactRef {261  artifact_id: string;262  kind: string;263  sha256: string;264  mime: string;265  bytes: number;266  width: number | null;267  height: number | null;268  /** Short-lived signed URL; prefer `getArtifact(artifact_id)`. */269  url?: string;270  [key: string]: unknown;271}272273export interface FieldEvidence {274  field: string;275  value: unknown;276  raw: unknown;277  method: string;278  group: string;279  score: number;280  selector: string | null;281  status: string;282  detail: string;283  [key: string]: unknown;284}285286export interface ExtractedRecord {287  record_id: string;288  data: JsonObject;289  /** `valid`, `needs_review`, … Publish only what is `valid`. */290  status: string;291  validation: string[];292  evidence?: FieldEvidence[];293  [key: string]: unknown;294}295296export interface ResultItem {297  snapshot_id: string;298  url: string;299  final_url: string;300  http_status: number | null;301  title: string | null;302  content_hash: string | null;303  captured_at: string;304  meta: JsonObject;305  artifacts: ArtifactRef[];306  content?: { markdown?: string; text?: string; json?: unknown };307  record?: ExtractedRecord;308  [key: string]: unknown;309}310311export interface NotCollected {312  url: string;313  status: string;314  reason: string | null;315  http_status: number | null;316  [key: string]: unknown;317}318319export interface Page<T> {320  items: T[];321  next_cursor: string | null;322  [key: string]: unknown;323}324325export interface ResultsPage extends Page<ResultItem> {326  job_id: string;327  status: JobStatus;328  complete: boolean;329  not_collected: NotCollected[];330}331332export interface SearchHit {333  snapshot_id: string;334  url: string;335  title: string | null;336  host: string;337  captured_at: string;338  score: number;339  excerpt: string;340  [key: string]: unknown;341}342343export interface BatchResponse {344  items: Array<{ index: number; job_id?: string; status?: string; status_url?: string; error?: { code: string; message: string } }>;345  accepted: number;346  rejected: number;347  [key: string]: unknown;348}349350export interface Monitor {351  id: string;352  name: string;353  interval_s: number;354  enabled: boolean;355  [key: string]: unknown;356}357358export interface MonitorSummary {359  schedule_id: string;360  name: string;361  url: string;362  enabled: boolean;363  last_snapshot_id: string | null;364  [key: string]: unknown;365}366367export interface ChangeEvent {368  change_id: string;369  schedule_id: string;370  url: string;371  snapshot_a: string;372  snapshot_b: string;373  kinds: string[];374  summary: JsonObject;375  alerted: boolean;376  created_at: string;377  [key: string]: unknown;378}379380export interface DiffResult {381  kinds: string[];382  text: JsonObject;383  layout: JsonObject;384  fields: { changed: boolean; fields: Record<string, { before: unknown; after: unknown }>; [key: string]: unknown };385  visual: JsonObject | null;386  snapshot_a: string;387  snapshot_b: string;388  [key: string]: unknown;389}390391export interface SiteGraph {392  site_id: string;393  job_id: string;394  nodes: JsonObject[];395  edges: JsonObject[];396  next_cursor: string | null;397  [key: string]: unknown;398}399400export interface Health {401  status: string;402  version: string;403  [key: string]: unknown;404}405406/** One server-sent event of a job; `data` is the decoded JSON payload. */407export interface JobEvent {408  id: string | null;409  type: string;410  data: unknown;411}412413export interface JobResult {414  job: Job;415  results: ResultItem[];416  notCollected: NotCollected[];417}418
Files main
Menu

Theme