Skip to content

Commit c389458

Browse files
committed
feat(HNT-2086): add crawl domain message and event types
1 parent ad867ca commit c389458

5 files changed

Lines changed: 86 additions & 1 deletion

File tree

packages/crawl-common/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ export type {
1212
export type {
1313
CorpusItem,
1414
CrawlArticleMessage,
15+
DiscoveryContext,
16+
CrawlArticleDiscoveryMessage,
1517
ArticleAuthor,
1618
ArticleBreadcrumb,
1719
ArticleEvent,
20+
ArticleDiscoveryEvent,
21+
LiveArticle,
22+
PublisherList,
1823
} from './types/index.js';

packages/crawl-common/src/types/events.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,24 @@ export interface ArticleEvent {
2626
breadcrumbs?: ArticleBreadcrumb[];
2727
language?: string;
2828
}
29+
30+
/**
31+
* Event published to the article-discoveries Pub/Sub topic and
32+
* written to the crawl.article_discoveries BigQuery table via a
33+
* BigQuery subscription. One event per discovered article and
34+
* context, so topic and surface_id come from the context the
35+
* page was crawled for, while source_url is that page.
36+
*/
37+
export interface ArticleDiscoveryEvent {
38+
url: string;
39+
source_url: string;
40+
crawled_at: string;
41+
published_at?: string;
42+
headline?: string;
43+
authors?: ArticleAuthor[];
44+
summary?: string;
45+
language?: string;
46+
topic?: string;
47+
page_position?: number;
48+
surface_id: string;
49+
}
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
export type { CorpusItem, CrawlArticleMessage } from './messages.js';
1+
export type {
2+
CorpusItem,
3+
CrawlArticleMessage,
4+
DiscoveryContext,
5+
CrawlArticleDiscoveryMessage,
6+
LiveArticle,
7+
PublisherList,
8+
} from './messages.js';
29
export type {
310
ArticleAuthor,
411
ArticleBreadcrumb,
512
ArticleEvent,
13+
ArticleDiscoveryEvent,
614
} from './events.js';

packages/crawl-common/src/types/messages.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,53 @@ export interface CrawlArticleMessage {
2727
source_url: string;
2828
crawl_id: string;
2929
enqueued_at: string;
30+
// Refresh window for this article, set by the producer: discovery uses
31+
// the article fetch TTL, the agent uses the live-article interval. The
32+
// worker gates re-fetch and writes its fetch claim against this value.
33+
// Optional so a rolling deploy does not reject messages enqueued before
34+
// the field existed; the worker falls back to the configured fetch TTL.
35+
refresh_interval_minutes?: number;
3036
corpus_item?: CorpusItem;
3137
}
38+
39+
/**
40+
* Surface and topic a discovered page is crawled for. A page
41+
* can be crawled for several surfaces, so each discovery job
42+
* carries one context per (surface, topic) pair.
43+
*/
44+
export interface DiscoveryContext {
45+
surface_id: string;
46+
topic: string;
47+
}
48+
49+
/**
50+
* Pub/Sub message consumed from the crawl-article-discovery
51+
* subscription. Tells the discovery worker which page to crawl,
52+
* how recently it may have been crawled, and the contexts to
53+
* attribute discovered articles to.
54+
*/
55+
export interface CrawlArticleDiscoveryMessage {
56+
url: string;
57+
interval_minutes: number;
58+
contexts: DiscoveryContext[];
59+
}
60+
61+
/**
62+
* A live (curated) article in the agent's publisher list. The agent
63+
* enqueues a crawl-article job carrying this corpus_item so the
64+
* worker can re-extract and sync editorial metadata.
65+
*/
66+
export interface LiveArticle {
67+
url: string;
68+
corpus_item: CorpusItem;
69+
}
70+
71+
/**
72+
* The agent's publisher list, loaded from JSON. pages drive
73+
* discovery crawls; live_articles are re-crawled directly to keep
74+
* curated metadata fresh. Phase 5 replaces this with the Corpus API.
75+
*/
76+
export interface PublisherList {
77+
pages: CrawlArticleDiscoveryMessage[];
78+
live_articles: LiveArticle[];
79+
}

packages/crawl-common/vitest.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@ export default defineConfig({
44
test: {
55
globals: true,
66
include: ['src/**/*.spec.ts', 'src/**/*.integration.ts'],
7+
// Emulator/container integration tests need headroom over the 5s
8+
// default, especially when packages run in parallel.
9+
testTimeout: 30_000,
710
},
811
});

0 commit comments

Comments
 (0)