Skip to content
This repository was archived by the owner on Oct 14, 2026. It is now read-only.

Commit ecdf2e4

Browse files
author
Tanase Butcaru
committed
feat(utils): add semantic lookup source/entity type registries (LLMO-7445)
1 parent fc75b50 commit ecdf2e4

7 files changed

Lines changed: 127 additions & 1 deletion

File tree

‎packages/spacecat-shared-utils/src/constants.d.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,24 @@
1111
*/
1212

1313
export { OPPORTUNITY_TYPES, DEFAULT_CPC_VALUE } from './index.js';
14+
15+
export const OPPORTUNITY_SEMANTIC_SOURCE_TYPES: Readonly<{
16+
TOPIC: 'topic';
17+
}>;
18+
19+
export const OPPORTUNITY_SEMANTIC_ENTITY_TYPES: Readonly<{
20+
CITED_ANALYSIS: 'cited-analysis';
21+
REDDIT_ANALYSIS: 'reddit-analysis';
22+
YOUTUBE_ANALYSIS: 'youtube-analysis';
23+
}>;
24+
25+
export const SUGGESTION_SEMANTIC_SOURCE_TYPES: Readonly<{
26+
TOPIC: 'topic';
27+
TITLE: 'title';
28+
}>;
29+
30+
export const SUGGESTION_SEMANTIC_ENTITY_TYPES: Readonly<{
31+
CITED_ANALYSIS: 'cited-analysis';
32+
REDDIT_ANALYSIS: 'reddit-analysis';
33+
YOUTUBE_ANALYSIS: 'youtube-analysis';
34+
}>;

‎packages/spacecat-shared-utils/src/constants.js‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,40 @@ export const OPPORTUNITY_TYPES = /** @type {const} */ ({
7777
});
7878

7979
export const DEFAULT_CPC_VALUE = 1.5;
80+
81+
/**
82+
* Kinds of source text in `opportunity_semantic_embedding.source_type`. The semantic lookup writer
83+
* and reader reject any other value; add a kind here before indexing or searching it.
84+
*/
85+
export const OPPORTUNITY_SEMANTIC_SOURCE_TYPES = Object.freeze({
86+
TOPIC: 'topic',
87+
});
88+
89+
/**
90+
* Opportunity types allowed in `opportunity_semantic_embedding.entity_type`. The writer and reader
91+
* reject any other value; add a type here before indexing or filtering by it.
92+
*/
93+
export const OPPORTUNITY_SEMANTIC_ENTITY_TYPES = Object.freeze({
94+
CITED_ANALYSIS: OPPORTUNITY_TYPES.CITED_ANALYSIS,
95+
REDDIT_ANALYSIS: OPPORTUNITY_TYPES.REDDIT_ANALYSIS,
96+
YOUTUBE_ANALYSIS: OPPORTUNITY_TYPES.YOUTUBE_ANALYSIS,
97+
});
98+
99+
/**
100+
* Kinds of source text in `suggestion_semantic_embedding.source_type`: the suggestion's derived
101+
* topics and its title. Same enforcement as `OPPORTUNITY_SEMANTIC_SOURCE_TYPES`.
102+
*/
103+
export const SUGGESTION_SEMANTIC_SOURCE_TYPES = Object.freeze({
104+
TOPIC: 'topic',
105+
TITLE: 'title',
106+
});
107+
108+
/**
109+
* Parent opportunity types allowed in `suggestion_semantic_embedding.entity_type`. Same
110+
* enforcement as `OPPORTUNITY_SEMANTIC_ENTITY_TYPES`.
111+
*/
112+
export const SUGGESTION_SEMANTIC_ENTITY_TYPES = Object.freeze({
113+
CITED_ANALYSIS: OPPORTUNITY_TYPES.CITED_ANALYSIS,
114+
REDDIT_ANALYSIS: OPPORTUNITY_TYPES.REDDIT_ANALYSIS,
115+
YOUTUBE_ANALYSIS: OPPORTUNITY_TYPES.YOUTUBE_ANALYSIS,
116+
});

‎packages/spacecat-shared-utils/src/index.d.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ export { AUTHORING_TYPES, DELIVERY_TYPES } from './aem.js';
1717

1818
export { OPPORTUNITY_TYPES } from './constants.js';
1919

20+
export {
21+
OPPORTUNITY_SEMANTIC_SOURCE_TYPES,
22+
OPPORTUNITY_SEMANTIC_ENTITY_TYPES,
23+
SUGGESTION_SEMANTIC_SOURCE_TYPES,
24+
SUGGESTION_SEMANTIC_ENTITY_TYPES,
25+
} from './constants.js';
26+
2027
export const DEFAULT_CPC_VALUE: number;
2128

2229
/** UTILITY FUNCTIONS */

‎packages/spacecat-shared-utils/src/index.js‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,14 @@ export { getStoredMetrics, storeMetrics, calculateCPCValue } from './metrics-sto
9292

9393
export { s3Wrapper, getObjectFromKey } from './s3.js';
9494

95-
export { OPPORTUNITY_TYPES, DEFAULT_CPC_VALUE } from './constants.js';
95+
export {
96+
OPPORTUNITY_TYPES,
97+
DEFAULT_CPC_VALUE,
98+
OPPORTUNITY_SEMANTIC_SOURCE_TYPES,
99+
OPPORTUNITY_SEMANTIC_ENTITY_TYPES,
100+
SUGGESTION_SEMANTIC_SOURCE_TYPES,
101+
SUGGESTION_SEMANTIC_ENTITY_TYPES,
102+
} from './constants.js';
96103

97104
export { fetch, resetFetchContext, clearFetchCache } from './adobe-fetch.js';
98105
export { tracingFetch, SPACECAT_USER_AGENT } from './tracing-fetch.js';
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2026 Adobe. All rights reserved.
3+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License. You may obtain a copy
5+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
* OF ANY KIND, either express or implied. See the License for the specific language
10+
* governing permissions and limitations under the License.
11+
*/
12+
13+
import { expect } from 'chai';
14+
import {
15+
OPPORTUNITY_SEMANTIC_SOURCE_TYPES,
16+
OPPORTUNITY_SEMANTIC_ENTITY_TYPES,
17+
SUGGESTION_SEMANTIC_SOURCE_TYPES,
18+
SUGGESTION_SEMANTIC_ENTITY_TYPES,
19+
} from '../src/constants.js';
20+
21+
describe('semantic lookup type registries', () => {
22+
it('lists the opportunity source and entity types', () => {
23+
expect(OPPORTUNITY_SEMANTIC_SOURCE_TYPES).to.deep.equal({ TOPIC: 'topic' });
24+
expect(OPPORTUNITY_SEMANTIC_ENTITY_TYPES).to.deep.equal({
25+
CITED_ANALYSIS: 'cited-analysis',
26+
REDDIT_ANALYSIS: 'reddit-analysis',
27+
YOUTUBE_ANALYSIS: 'youtube-analysis',
28+
});
29+
});
30+
31+
it('lists the suggestion source and entity types', () => {
32+
expect(SUGGESTION_SEMANTIC_SOURCE_TYPES).to.deep.equal({ TOPIC: 'topic', TITLE: 'title' });
33+
expect(SUGGESTION_SEMANTIC_ENTITY_TYPES).to.deep.equal({
34+
CITED_ANALYSIS: 'cited-analysis',
35+
REDDIT_ANALYSIS: 'reddit-analysis',
36+
YOUTUBE_ANALYSIS: 'youtube-analysis',
37+
});
38+
});
39+
40+
it('freezes every registry', () => {
41+
[
42+
OPPORTUNITY_SEMANTIC_SOURCE_TYPES,
43+
OPPORTUNITY_SEMANTIC_ENTITY_TYPES,
44+
SUGGESTION_SEMANTIC_SOURCE_TYPES,
45+
SUGGESTION_SEMANTIC_ENTITY_TYPES,
46+
].forEach((registry) => expect(Object.isFrozen(registry)).to.equal(true));
47+
});
48+
});

‎packages/spacecat-shared-utils/test/index.test.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ describe('Index Exports', () => {
110110
'logWrapper',
111111
'OPPORTUNITY_DEPENDENCY_MAP',
112112
'OPPORTUNITY_GRANT_CONFIG',
113+
'OPPORTUNITY_SEMANTIC_ENTITY_TYPES',
114+
'OPPORTUNITY_SEMANTIC_SOURCE_TYPES',
113115
'OPPORTUNITY_TITLES',
114116
'OPPORTUNITY_TYPES',
115117
'prependSchema',
@@ -130,6 +132,8 @@ describe('Index Exports', () => {
130132
'stripTrailingDot',
131133
'stripTrailingSlash',
132134
'stripWWW',
135+
'SUGGESTION_SEMANTIC_ENTITY_TYPES',
136+
'SUGGESTION_SEMANTIC_SOURCE_TYPES',
133137
'TOKEN_GRANT_CONFIG',
134138
'toBoolean',
135139
'filterBySiteScope',

‎packages/spacecat-shared-utils/test/subpaths.test.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ const EXPECTED_SCHEMAS_EXPORTS = [
5757

5858
const EXPECTED_CONSTANTS_EXPORTS = [
5959
'DEFAULT_CPC_VALUE', 'OPPORTUNITY_TYPES',
60+
'OPPORTUNITY_SEMANTIC_SOURCE_TYPES', 'OPPORTUNITY_SEMANTIC_ENTITY_TYPES',
61+
'SUGGESTION_SEMANTIC_SOURCE_TYPES', 'SUGGESTION_SEMANTIC_ENTITY_TYPES',
6062
];
6163

6264
const pkgDir = resolve(dirname(fileURLToPath(import.meta.url)), '..');

0 commit comments

Comments
 (0)