movie-agent 1.0.0
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/LICENSE +21 -0
- package/README.md +464 -0
- package/bin/movie-agent +209 -0
- package/dist/agent.d.ts +89 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +365 -0
- package/dist/agent.js.map +1 -0
- package/dist/cache.d.ts +75 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +133 -0
- package/dist/cache.js.map +1 -0
- package/dist/config.d.ts +17 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +31 -0
- package/dist/config.js.map +1 -0
- package/dist/discover.d.ts +38 -0
- package/dist/discover.d.ts.map +1 -0
- package/dist/discover.js +121 -0
- package/dist/discover.js.map +1 -0
- package/dist/factory.d.ts +87 -0
- package/dist/factory.d.ts.map +1 -0
- package/dist/factory.js +118 -0
- package/dist/factory.js.map +1 -0
- package/dist/filters.d.ts +61 -0
- package/dist/filters.d.ts.map +1 -0
- package/dist/filters.js +97 -0
- package/dist/filters.js.map +1 -0
- package/dist/format.d.ts +33 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +85 -0
- package/dist/format.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/mood.d.ts +7 -0
- package/dist/mood.d.ts.map +1 -0
- package/dist/mood.js +21 -0
- package/dist/mood.js.map +1 -0
- package/dist/providers.d.ts +10 -0
- package/dist/providers.d.ts.map +1 -0
- package/dist/providers.js +70 -0
- package/dist/providers.js.map +1 -0
- package/dist/ranking.d.ts +57 -0
- package/dist/ranking.d.ts.map +1 -0
- package/dist/ranking.js +198 -0
- package/dist/ranking.js.map +1 -0
- package/dist/tmdbApi.d.ts +79 -0
- package/dist/tmdbApi.d.ts.map +1 -0
- package/dist/tmdbApi.js +88 -0
- package/dist/tmdbApi.js.map +1 -0
- package/dist/types.d.ts +99 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/validate.d.ts +13 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +47 -0
- package/dist/validate.js.map +1 -0
- package/package.json +72 -0
package/dist/cache.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Simple in-memory cache with TTL support
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Cache = void 0;
|
|
7
|
+
exports.getCache = getCache;
|
|
8
|
+
exports.resetCache = resetCache;
|
|
9
|
+
exports.generateDiscoverCacheKey = generateDiscoverCacheKey;
|
|
10
|
+
exports.generateProvidersCacheKey = generateProvidersCacheKey;
|
|
11
|
+
class Cache {
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new cache instance
|
|
14
|
+
* @param defaultTtl Default time-to-live in seconds
|
|
15
|
+
*/
|
|
16
|
+
constructor(defaultTtl = 3600) {
|
|
17
|
+
this.store = new Map();
|
|
18
|
+
this.defaultTtl = defaultTtl;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Sets a value in the cache
|
|
22
|
+
* @param key Cache key
|
|
23
|
+
* @param value Value to cache
|
|
24
|
+
* @param ttl Time-to-live in seconds (optional, uses default if not provided)
|
|
25
|
+
*/
|
|
26
|
+
set(key, value, ttl) {
|
|
27
|
+
const effectiveTtl = ttl ?? this.defaultTtl;
|
|
28
|
+
const expiresAt = Date.now() + effectiveTtl * 1000;
|
|
29
|
+
this.store.set(key, { value, expiresAt });
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Gets a value from the cache
|
|
33
|
+
* @param key Cache key
|
|
34
|
+
* @returns Cached value or undefined if not found or expired
|
|
35
|
+
*/
|
|
36
|
+
get(key) {
|
|
37
|
+
const entry = this.store.get(key);
|
|
38
|
+
if (!entry) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
// Check if entry has expired
|
|
42
|
+
if (Date.now() > entry.expiresAt) {
|
|
43
|
+
this.store.delete(key);
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
return entry.value;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Checks if a key exists and is not expired
|
|
50
|
+
* @param key Cache key
|
|
51
|
+
* @returns true if key exists and is not expired
|
|
52
|
+
*/
|
|
53
|
+
has(key) {
|
|
54
|
+
return this.get(key) !== undefined;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Deletes a key from the cache
|
|
58
|
+
* @param key Cache key
|
|
59
|
+
* @returns true if key existed and was deleted
|
|
60
|
+
*/
|
|
61
|
+
delete(key) {
|
|
62
|
+
return this.store.delete(key);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Clears all entries from the cache
|
|
66
|
+
*/
|
|
67
|
+
clear() {
|
|
68
|
+
this.store.clear();
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Gets the number of entries in the cache (including expired ones)
|
|
72
|
+
* @returns Number of entries
|
|
73
|
+
*/
|
|
74
|
+
size() {
|
|
75
|
+
return this.store.size;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Removes all expired entries from the cache
|
|
79
|
+
* @returns Number of entries removed
|
|
80
|
+
*/
|
|
81
|
+
prune() {
|
|
82
|
+
const now = Date.now();
|
|
83
|
+
let removed = 0;
|
|
84
|
+
for (const [key, entry] of this.store.entries()) {
|
|
85
|
+
if (now > entry.expiresAt) {
|
|
86
|
+
this.store.delete(key);
|
|
87
|
+
removed++;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return removed;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.Cache = Cache;
|
|
94
|
+
// Singleton instance for application-wide use
|
|
95
|
+
let cacheInstance = null;
|
|
96
|
+
/**
|
|
97
|
+
* Gets the global cache instance
|
|
98
|
+
* @param ttl Default TTL for the cache (only used on first call)
|
|
99
|
+
* @returns Global cache instance
|
|
100
|
+
*/
|
|
101
|
+
function getCache(ttl) {
|
|
102
|
+
if (!cacheInstance) {
|
|
103
|
+
cacheInstance = new Cache(ttl);
|
|
104
|
+
}
|
|
105
|
+
return cacheInstance;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Resets the global cache instance (useful for testing)
|
|
109
|
+
*/
|
|
110
|
+
function resetCache() {
|
|
111
|
+
cacheInstance = null;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Generates a cache key for discover parameters
|
|
115
|
+
* @param params Discover parameters object
|
|
116
|
+
* @returns Cache key string
|
|
117
|
+
*/
|
|
118
|
+
function generateDiscoverCacheKey(params) {
|
|
119
|
+
// Sort keys to ensure consistent key generation
|
|
120
|
+
const sortedKeys = Object.keys(params).sort();
|
|
121
|
+
const keyParts = sortedKeys.map(key => `${key}=${params[key]}`);
|
|
122
|
+
return `discover:${keyParts.join('&')}`;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Generates a cache key for watch providers
|
|
126
|
+
* @param movieId Movie ID
|
|
127
|
+
* @param region Region code
|
|
128
|
+
* @returns Cache key string
|
|
129
|
+
*/
|
|
130
|
+
function generateProvidersCacheKey(movieId, region) {
|
|
131
|
+
return `providers:${movieId}:${region}`;
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAiHH,4BAKC;AAKD,gCAEC;AAOD,4DAKC;AAQD,8DAKC;AA/ID,MAAa,KAAK;IAIhB;;;OAGG;IACH,YAAY,aAAqB,IAAI;QACnC,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,EAAE,CAAC;QACvB,IAAI,CAAC,UAAU,GAAG,UAAU,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_KEY: string;
|
|
3
|
+
TMDB_BASE_URL: string;
|
|
4
|
+
TMDB_REGION: string;
|
|
5
|
+
CACHE_TTL: number;
|
|
6
|
+
MAX_RECOMMENDATIONS: number;
|
|
7
|
+
MIN_RECOMMENDATIONS: number;
|
|
8
|
+
LLM_PROVIDER: 'gemini' | 'azure';
|
|
9
|
+
GEMINI_API_KEY?: string;
|
|
10
|
+
AZURE_OPENAI_API_KEY?: string;
|
|
11
|
+
AZURE_OPENAI_ENDPOINT?: string;
|
|
12
|
+
AZURE_OPENAI_DEPLOYMENT?: string;
|
|
13
|
+
OPENAI_API_KEY?: string;
|
|
14
|
+
}
|
|
15
|
+
declare const config: Config;
|
|
16
|
+
export default config;
|
|
17
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,MAAM;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,mBAAmB,EAAE,MAAM,CAAC;IAG5B,YAAY,EAAE,QAAQ,GAAG,OAAO,CAAC;IACjC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAkBD,QAAA,MAAM,MAAM,EAAE,MAwBb,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
7
|
+
dotenv_1.default.config();
|
|
8
|
+
function getEnvVar(key, required = false, defaultValue) {
|
|
9
|
+
const value = process.env[key];
|
|
10
|
+
if (required && !value) {
|
|
11
|
+
throw new Error(`Missing required environment variable: ${key}`);
|
|
12
|
+
}
|
|
13
|
+
return value ?? defaultValue;
|
|
14
|
+
}
|
|
15
|
+
const LLM_PROVIDER = getEnvVar('LLM_PROVIDER', false, 'gemini');
|
|
16
|
+
const config = {
|
|
17
|
+
TMDB_API_KEY: getEnvVar('TMDB_API_KEY', false) || '', // Made optional - factory pattern handles this
|
|
18
|
+
TMDB_BASE_URL: getEnvVar('TMDB_BASE_URL', false, 'https://api.themoviedb.org/3'),
|
|
19
|
+
TMDB_REGION: getEnvVar('TMDB_REGION', false, 'CA'),
|
|
20
|
+
CACHE_TTL: parseInt(getEnvVar('CACHE_TTL', false, '86400'), 10),
|
|
21
|
+
MAX_RECOMMENDATIONS: parseInt(getEnvVar('MAX_RECOMMENDATIONS', false, '5'), 10),
|
|
22
|
+
MIN_RECOMMENDATIONS: parseInt(getEnvVar('MIN_RECOMMENDATIONS', false, '3'), 10),
|
|
23
|
+
LLM_PROVIDER,
|
|
24
|
+
GEMINI_API_KEY: getEnvVar('GEMINI_API_KEY', false), // Made optional
|
|
25
|
+
AZURE_OPENAI_API_KEY: getEnvVar('AZURE_OPENAI_API_KEY', false),
|
|
26
|
+
AZURE_OPENAI_ENDPOINT: getEnvVar('AZURE_OPENAI_ENDPOINT', false),
|
|
27
|
+
AZURE_OPENAI_DEPLOYMENT: getEnvVar('AZURE_OPENAI_DEPLOYMENT', false),
|
|
28
|
+
OPENAI_API_KEY: getEnvVar('OPENAI_API_KEY', false),
|
|
29
|
+
};
|
|
30
|
+
exports.default = config;
|
|
31
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0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SAAS,CAAC,uBAAuB,EAAE,KAAK,CAAC;IAChE,uBAAuB,EAAE,SAAS,CAAC,yBAAyB,EAAE,KAAK,CAAC;IACpE,cAAc,EAAE,SAAS,CAAC,gBAAgB,EAAE,KAAK,CAAC;CACnD,CAAC;AAEF,kBAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import TmdbApiClient, { DiscoverMoviesParams, DiscoverMoviesResponse } from './tmdbApi';
|
|
2
|
+
/**
|
|
3
|
+
* Input for building discover parameters.
|
|
4
|
+
*/
|
|
5
|
+
export interface DiscoverInput {
|
|
6
|
+
/** Optional mood to map to genres */
|
|
7
|
+
mood?: string;
|
|
8
|
+
/** Explicit genre names (e.g., ["Action", "Comedy"]) */
|
|
9
|
+
genres?: string[];
|
|
10
|
+
/** Specific release year */
|
|
11
|
+
year?: number;
|
|
12
|
+
/** Minimum release year */
|
|
13
|
+
yearMin?: number;
|
|
14
|
+
/** Maximum release year */
|
|
15
|
+
yearMax?: number;
|
|
16
|
+
/** Minimum runtime in minutes */
|
|
17
|
+
runtimeMin?: number;
|
|
18
|
+
/** Maximum runtime in minutes */
|
|
19
|
+
runtimeMax?: number;
|
|
20
|
+
/** Page number for pagination */
|
|
21
|
+
page?: number;
|
|
22
|
+
/** Sort order (e.g., "popularity.desc", "release_date.desc") */
|
|
23
|
+
sortBy?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Builds TMDb discover parameters from user input.
|
|
27
|
+
* @param input - User input with mood, genres, year range, runtime constraints, etc.
|
|
28
|
+
* @returns DiscoverMoviesParams object ready for API call
|
|
29
|
+
*/
|
|
30
|
+
export declare function buildDiscoverParams(input: DiscoverInput): DiscoverMoviesParams;
|
|
31
|
+
/**
|
|
32
|
+
* Discovers movies based on user input.
|
|
33
|
+
* @param input - User input with mood, genres, year range, runtime constraints, etc.
|
|
34
|
+
* @param apiClient - Optional TMDb API client instance (defaults to new instance)
|
|
35
|
+
* @returns Promise resolving to discover movies response
|
|
36
|
+
*/
|
|
37
|
+
export declare function discoverMovies(input: DiscoverInput, apiClient?: TmdbApiClient): Promise<DiscoverMoviesResponse>;
|
|
38
|
+
//# sourceMappingURL=discover.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discover.d.ts","sourceRoot":"","sources":["../src/discover.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,EAAE,EACpB,oBAAoB,EACpB,sBAAsB,EACvB,MAAM,WAAW,CAAC;AAKnB;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,qCAAqC;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wDAAwD;IACxD,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,4BAA4B;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,2BAA2B;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2BAA2B;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iCAAiC;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iCAAiC;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iCAAiC;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gEAAgE;IAChE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AA+CD;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,aAAa,GACnB,oBAAoB,CA6CtB;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,KAAK,EAAE,aAAa,EACpB,SAAS,CAAC,EAAE,aAAa,GACxB,OAAO,CAAC,sBAAsB,CAAC,CAoBjC"}
|
package/dist/discover.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.buildDiscoverParams = buildDiscoverParams;
|
|
7
|
+
exports.discoverMovies = discoverMovies;
|
|
8
|
+
const tmdbApi_1 = __importDefault(require("./tmdbApi"));
|
|
9
|
+
const mood_1 = require("./mood");
|
|
10
|
+
const cache_1 = require("./cache");
|
|
11
|
+
const config_1 = __importDefault(require("./config"));
|
|
12
|
+
/**
|
|
13
|
+
* Maps genre names to genre IDs based on TMDb's genre list.
|
|
14
|
+
* This is a static mapping of common movie genres.
|
|
15
|
+
*/
|
|
16
|
+
const GENRE_NAME_TO_ID = {
|
|
17
|
+
Action: 28,
|
|
18
|
+
Adventure: 12,
|
|
19
|
+
Animation: 16,
|
|
20
|
+
Biography: 99, // Note: Biography is not a standard TMDb genre, using Documentary
|
|
21
|
+
Comedy: 35,
|
|
22
|
+
Crime: 80,
|
|
23
|
+
Documentary: 99,
|
|
24
|
+
Drama: 18,
|
|
25
|
+
Family: 10751,
|
|
26
|
+
Fantasy: 14,
|
|
27
|
+
History: 36,
|
|
28
|
+
Horror: 27,
|
|
29
|
+
Music: 10402,
|
|
30
|
+
Musical: 10402, // Music and Musical map to the same ID
|
|
31
|
+
Mystery: 9648,
|
|
32
|
+
Romance: 10749,
|
|
33
|
+
'Science Fiction': 878,
|
|
34
|
+
Thriller: 53,
|
|
35
|
+
'TV Movie': 10770,
|
|
36
|
+
War: 10752,
|
|
37
|
+
Western: 37,
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Converts genre names to comma-separated genre IDs.
|
|
41
|
+
* @param genreNames - Array of genre names
|
|
42
|
+
* @returns Comma-separated string of genre IDs, or undefined if no valid genres
|
|
43
|
+
*/
|
|
44
|
+
function genreNamesToIds(genreNames) {
|
|
45
|
+
const ids = genreNames
|
|
46
|
+
.map(name => GENRE_NAME_TO_ID[name])
|
|
47
|
+
.filter(id => id !== undefined);
|
|
48
|
+
if (ids.length === 0) {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
return ids.join(',');
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Builds TMDb discover parameters from user input.
|
|
55
|
+
* @param input - User input with mood, genres, year range, runtime constraints, etc.
|
|
56
|
+
* @returns DiscoverMoviesParams object ready for API call
|
|
57
|
+
*/
|
|
58
|
+
function buildDiscoverParams(input) {
|
|
59
|
+
const params = {};
|
|
60
|
+
// Handle genres - prioritize explicit genres over mood
|
|
61
|
+
let genreNames = [];
|
|
62
|
+
if (input.genres && input.genres.length > 0) {
|
|
63
|
+
genreNames = input.genres;
|
|
64
|
+
}
|
|
65
|
+
else if (input.mood) {
|
|
66
|
+
genreNames = (0, mood_1.moodToGenres)(input.mood);
|
|
67
|
+
}
|
|
68
|
+
if (genreNames.length > 0) {
|
|
69
|
+
params.with_genres = genreNamesToIds(genreNames);
|
|
70
|
+
}
|
|
71
|
+
// Handle year - specific year takes precedence over range
|
|
72
|
+
if (input.year) {
|
|
73
|
+
params.year = input.year;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
// Use date range if no specific year
|
|
77
|
+
if (input.yearMin) {
|
|
78
|
+
params['primary_release_date.gte'] = `${input.yearMin}-01-01`;
|
|
79
|
+
}
|
|
80
|
+
if (input.yearMax) {
|
|
81
|
+
params['primary_release_date.lte'] = `${input.yearMax}-12-31`;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// Handle runtime constraints
|
|
85
|
+
if (input.runtimeMin !== undefined) {
|
|
86
|
+
params['with_runtime.gte'] = input.runtimeMin;
|
|
87
|
+
}
|
|
88
|
+
if (input.runtimeMax !== undefined) {
|
|
89
|
+
params['with_runtime.lte'] = input.runtimeMax;
|
|
90
|
+
}
|
|
91
|
+
// Handle pagination
|
|
92
|
+
if (input.page !== undefined) {
|
|
93
|
+
params.page = input.page;
|
|
94
|
+
}
|
|
95
|
+
// Handle sort order (default to popularity descending)
|
|
96
|
+
params.sort_by = input.sortBy ?? 'popularity.desc';
|
|
97
|
+
return params;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Discovers movies based on user input.
|
|
101
|
+
* @param input - User input with mood, genres, year range, runtime constraints, etc.
|
|
102
|
+
* @param apiClient - Optional TMDb API client instance (defaults to new instance)
|
|
103
|
+
* @returns Promise resolving to discover movies response
|
|
104
|
+
*/
|
|
105
|
+
async function discoverMovies(input, apiClient) {
|
|
106
|
+
const client = apiClient ?? new tmdbApi_1.default();
|
|
107
|
+
const params = buildDiscoverParams(input);
|
|
108
|
+
// Check cache first
|
|
109
|
+
const cache = (0, cache_1.getCache)(config_1.default.CACHE_TTL);
|
|
110
|
+
const cacheKey = (0, cache_1.generateDiscoverCacheKey)(params);
|
|
111
|
+
const cachedResult = cache.get(cacheKey);
|
|
112
|
+
if (cachedResult) {
|
|
113
|
+
return cachedResult;
|
|
114
|
+
}
|
|
115
|
+
// Cache miss - fetch from API
|
|
116
|
+
const result = await client.discoverMovies(params);
|
|
117
|
+
// Store in cache
|
|
118
|
+
cache.set(cacheKey, result);
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=discover.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discover.js","sourceRoot":"","sources":["../src/discover.ts"],"names":[],"mappings":";;;;;AAkFA,kDA+CC;AAQD,wCAuBC;AAhKD,wDAGmB;AACnB,iCAAsC;AACtC,mCAA6D;AAC7D,sDAA8B;AA0B9B;;;GAGG;AACH,MAAM,gBAAgB,GAA2B;IAC/C,MAAM,EAAE,EAAE;IACV,SAAS,EAAE,EAAE;IACb,SAAS,EAAE,EAAE;IACb,SAAS,EAAE,EAAE,EAAE,kEAAkE;IACjF,MAAM,EAAE,EAAE;IACV,KAAK,EAAE,EAAE;IACT,WAAW,EAAE,EAAE;IACf,KAAK,EAAE,EAAE;IACT,MAAM,EAAE,KAAK;IACb,OAAO,EAAE,EAAE;IACX,OAAO,EAAE,EAAE;IACX,MAAM,EAAE,EAAE;IACV,KAAK,EAAE,K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yB,QAAQ,CAAC,CAAC;IAEjE,IAAI,YAAY,EAAE,CAAC;QACjB,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,8BAA8B;IAC9B,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IAEnD,iBAAiB;IACjB,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAE5B,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { MovieAgent } from './agent';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration options for creating a MovieAgent instance
|
|
4
|
+
*/
|
|
5
|
+
export interface MovieAgentConfig {
|
|
6
|
+
tmdbApiKey: string;
|
|
7
|
+
tmdbBaseUrl?: string;
|
|
8
|
+
tmdbRegion?: string;
|
|
9
|
+
llmProvider?: 'gemini' | 'azure';
|
|
10
|
+
geminiApiKey?: string;
|
|
11
|
+
azureOpenAiApiKey?: string;
|
|
12
|
+
azureOpenAiEndpoint?: string;
|
|
13
|
+
azureOpenAiDeployment?: string;
|
|
14
|
+
openaiApiKey?: string;
|
|
15
|
+
cacheTtl?: number;
|
|
16
|
+
maxRecommendations?: number;
|
|
17
|
+
minRecommendations?: number;
|
|
18
|
+
debug?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Factory class for creating configured MovieAgent instances
|
|
22
|
+
*
|
|
23
|
+
* This class provides a clean interface for external projects to create
|
|
24
|
+
* MovieAgent instances without needing to manage TMDb API clients or
|
|
25
|
+
* environment variables directly.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { MovieAgentFactory } from 'movie-agent';
|
|
30
|
+
*
|
|
31
|
+
* const agent = MovieAgentFactory.create({
|
|
32
|
+
* tmdbApiKey: process.env.TMDB_API_KEY,
|
|
33
|
+
* tmdbRegion: 'CA',
|
|
34
|
+
* debug: true
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* const recommendations = await agent.getRecommendations({
|
|
38
|
+
* mood: 'excited',
|
|
39
|
+
* genre: 'Action'
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare class MovieAgentFactory {
|
|
44
|
+
/**
|
|
45
|
+
* Creates a configured MovieAgent instance
|
|
46
|
+
*
|
|
47
|
+
* @param config - Configuration options for the MovieAgent
|
|
48
|
+
* @returns A fully configured MovieAgent instance ready to use
|
|
49
|
+
* @throws Error if required configuration is missing
|
|
50
|
+
*/
|
|
51
|
+
static create(config: MovieAgentConfig): MovieAgent;
|
|
52
|
+
/**
|
|
53
|
+
* Creates a MovieAgent instance from environment variables
|
|
54
|
+
*
|
|
55
|
+
* This is a convenience method for projects that use environment variables.
|
|
56
|
+
* It reads from process.env and creates a MovieAgent with the standard
|
|
57
|
+
* environment variable names.
|
|
58
|
+
*
|
|
59
|
+
* Expected environment variables:
|
|
60
|
+
* - TMDB_API_KEY (required)
|
|
61
|
+
* - TMDB_BASE_URL (optional)
|
|
62
|
+
* - TMDB_REGION (optional, defaults to 'CA')
|
|
63
|
+
* - LLM_PROVIDER (optional)
|
|
64
|
+
* - GEMINI_API_KEY (optional)
|
|
65
|
+
* - AZURE_OPENAI_API_KEY (optional)
|
|
66
|
+
* - AZURE_OPENAI_ENDPOINT (optional)
|
|
67
|
+
* - AZURE_OPENAI_DEPLOYMENT (optional)
|
|
68
|
+
* - OPENAI_API_KEY (optional)
|
|
69
|
+
*
|
|
70
|
+
* @param debug - Enable debug logging (default: false)
|
|
71
|
+
* @returns A fully configured MovieAgent instance
|
|
72
|
+
* @throws Error if TMDB_API_KEY is not set in environment
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* import { MovieAgentFactory } from 'movie-agent';
|
|
77
|
+
*
|
|
78
|
+
* // Make sure to load your .env file first
|
|
79
|
+
* import dotenv from 'dotenv';
|
|
80
|
+
* dotenv.config();
|
|
81
|
+
*
|
|
82
|
+
* const agent = MovieAgentFactory.fromEnv(true);
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
static fromEnv(debug?: boolean): MovieAgent;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGrC;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAE/B,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IAGpB,WAAW,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC;IACjC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,YAAY,CAAC,EAAE,MAAM,CAAC;IAGtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAG5B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,iBAAiB;IAC5B;;;;;;OAMG;IACH,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,gBAAgB,GAAG,UAAU;IAwBnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACH,MAAM,CAAC,OAAO,CAAC,KAAK,UAAQ,GAAG,UAAU;CAiC1C"}
|
package/dist/factory.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.MovieAgentFactory = void 0;
|
|
7
|
+
// src/factory.ts
|
|
8
|
+
const agent_1 = require("./agent");
|
|
9
|
+
const tmdbApi_1 = __importDefault(require("./tmdbApi"));
|
|
10
|
+
/**
|
|
11
|
+
* Factory class for creating configured MovieAgent instances
|
|
12
|
+
*
|
|
13
|
+
* This class provides a clean interface for external projects to create
|
|
14
|
+
* MovieAgent instances without needing to manage TMDb API clients or
|
|
15
|
+
* environment variables directly.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { MovieAgentFactory } from 'movie-agent';
|
|
20
|
+
*
|
|
21
|
+
* const agent = MovieAgentFactory.create({
|
|
22
|
+
* tmdbApiKey: process.env.TMDB_API_KEY,
|
|
23
|
+
* tmdbRegion: 'CA',
|
|
24
|
+
* debug: true
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* const recommendations = await agent.getRecommendations({
|
|
28
|
+
* mood: 'excited',
|
|
29
|
+
* genre: 'Action'
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
class MovieAgentFactory {
|
|
34
|
+
/**
|
|
35
|
+
* Creates a configured MovieAgent instance
|
|
36
|
+
*
|
|
37
|
+
* @param config - Configuration options for the MovieAgent
|
|
38
|
+
* @returns A fully configured MovieAgent instance ready to use
|
|
39
|
+
* @throws Error if required configuration is missing
|
|
40
|
+
*/
|
|
41
|
+
static create(config) {
|
|
42
|
+
// Validate required configuration
|
|
43
|
+
if (!config.tmdbApiKey) {
|
|
44
|
+
throw new Error('TMDB API key is required. Please provide tmdbApiKey in the configuration.');
|
|
45
|
+
}
|
|
46
|
+
// Create TMDb API client with provided configuration
|
|
47
|
+
const tmdbClient = new tmdbApi_1.default(config.tmdbBaseUrl || 'https://api.themoviedb.org/3', config.tmdbApiKey, config.tmdbRegion || 'CA');
|
|
48
|
+
// Create logger function if debug is enabled
|
|
49
|
+
const logger = config.debug
|
|
50
|
+
? (message) => console.log(`[MovieAgent] ${message}`)
|
|
51
|
+
: undefined;
|
|
52
|
+
// Create and return MovieAgent instance
|
|
53
|
+
return new agent_1.MovieAgent(tmdbClient, logger);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Creates a MovieAgent instance from environment variables
|
|
57
|
+
*
|
|
58
|
+
* This is a convenience method for projects that use environment variables.
|
|
59
|
+
* It reads from process.env and creates a MovieAgent with the standard
|
|
60
|
+
* environment variable names.
|
|
61
|
+
*
|
|
62
|
+
* Expected environment variables:
|
|
63
|
+
* - TMDB_API_KEY (required)
|
|
64
|
+
* - TMDB_BASE_URL (optional)
|
|
65
|
+
* - TMDB_REGION (optional, defaults to 'CA')
|
|
66
|
+
* - LLM_PROVIDER (optional)
|
|
67
|
+
* - GEMINI_API_KEY (optional)
|
|
68
|
+
* - AZURE_OPENAI_API_KEY (optional)
|
|
69
|
+
* - AZURE_OPENAI_ENDPOINT (optional)
|
|
70
|
+
* - AZURE_OPENAI_DEPLOYMENT (optional)
|
|
71
|
+
* - OPENAI_API_KEY (optional)
|
|
72
|
+
*
|
|
73
|
+
* @param debug - Enable debug logging (default: false)
|
|
74
|
+
* @returns A fully configured MovieAgent instance
|
|
75
|
+
* @throws Error if TMDB_API_KEY is not set in environment
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* import { MovieAgentFactory } from 'movie-agent';
|
|
80
|
+
*
|
|
81
|
+
* // Make sure to load your .env file first
|
|
82
|
+
* import dotenv from 'dotenv';
|
|
83
|
+
* dotenv.config();
|
|
84
|
+
*
|
|
85
|
+
* const agent = MovieAgentFactory.fromEnv(true);
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
static fromEnv(debug = false) {
|
|
89
|
+
const tmdbApiKey = process.env.TMDB_API_KEY;
|
|
90
|
+
if (!tmdbApiKey) {
|
|
91
|
+
throw new Error('TMDB_API_KEY environment variable is required. ' +
|
|
92
|
+
'Please set it in your .env file or environment.');
|
|
93
|
+
}
|
|
94
|
+
return MovieAgentFactory.create({
|
|
95
|
+
tmdbApiKey,
|
|
96
|
+
tmdbBaseUrl: process.env.TMDB_BASE_URL,
|
|
97
|
+
tmdbRegion: process.env.TMDB_REGION,
|
|
98
|
+
llmProvider: process.env.LLM_PROVIDER || undefined,
|
|
99
|
+
geminiApiKey: process.env.GEMINI_API_KEY,
|
|
100
|
+
azureOpenAiApiKey: process.env.AZURE_OPENAI_API_KEY,
|
|
101
|
+
azureOpenAiEndpoint: process.env.AZURE_OPENAI_ENDPOINT,
|
|
102
|
+
azureOpenAiDeployment: process.env.AZURE_OPENAI_DEPLOYMENT,
|
|
103
|
+
openaiApiKey: process.env.OPENAI_API_KEY,
|
|
104
|
+
cacheTtl: process.env.CACHE_TTL
|
|
105
|
+
? parseInt(process.env.CACHE_TTL, 10)
|
|
106
|
+
: undefined,
|
|
107
|
+
maxRecommendations: process.env.MAX_RECOMMENDATIONS
|
|
108
|
+
? parseInt(process.env.MAX_RECOMMENDATIONS, 10)
|
|
109
|
+
: undefined,
|
|
110
|
+
minRecommendations: process.env.MIN_RECOMMENDATIONS
|
|
111
|
+
? parseInt(process.env.MIN_RECOMMENDATIONS, 10)
|
|
112
|
+
: undefined,
|
|
113
|
+
debug,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.MovieAgentFactory = MovieAgentFactory;
|
|
118
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":";;;;;;AAAA,iBAAiB;AACjB,mCAAqC;AACrC,wDAAsC;AA4BtC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAa,iBAAiB;I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GAAG,CAAC,qBAAqB;YACtD,qBAAqB,EAAE,OAAO,CAAC,GAAG,CAAC,uBAAuB;YAC1D,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc;YACxC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS;gBAC7B,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,CAAC;gBACrC,CAAC,CAAC,SAAS;YACb,kBAAkB,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB;gBACjD,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,EAAE,CAAC;gBAC/C,CAAC,CAAC,SAAS;YACb,kBAAkB,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB;gBACjD,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,EAAE,CAAC;gBAC/C,CAAC,CAAC,SAAS;YACb,KAAK;SACN,CAAC,CAAC;IACL,CAAC;CACF;AAlGD,8CAkGC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime constraints for filtering movies by duration
|
|
3
|
+
*/
|
|
4
|
+
export interface RuntimeConstraints {
|
|
5
|
+
min?: number;
|
|
6
|
+
max?: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Year range for filtering movies by release year
|
|
10
|
+
*/
|
|
11
|
+
export interface YearRange {
|
|
12
|
+
from?: number;
|
|
13
|
+
to?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Filter a movie by checking if it's available on any of the user's platforms
|
|
17
|
+
* @param movie The movie object with available platforms
|
|
18
|
+
* @param userPlatforms Array of platform names the user has access to
|
|
19
|
+
* @returns true if the movie is available on at least one of the user's platforms
|
|
20
|
+
*/
|
|
21
|
+
export declare function filterByPlatforms(movie: {
|
|
22
|
+
platforms?: string[];
|
|
23
|
+
}, userPlatforms: string[]): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Filter a movie by runtime constraints
|
|
26
|
+
* @param movie The movie object with runtime information
|
|
27
|
+
* @param constraints Runtime constraints (min and/or max)
|
|
28
|
+
* @returns true if the movie's runtime satisfies the constraints
|
|
29
|
+
*/
|
|
30
|
+
export declare function filterByRuntime(movie: {
|
|
31
|
+
runtime?: number;
|
|
32
|
+
}, constraints: RuntimeConstraints): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Filter a movie by release year
|
|
35
|
+
* @param movie The movie object with release_date
|
|
36
|
+
* @param year Either a specific year (number) or a year range object
|
|
37
|
+
* @returns true if the movie's release year matches the criteria
|
|
38
|
+
*/
|
|
39
|
+
export declare function filterByYear(movie: {
|
|
40
|
+
release_date?: string;
|
|
41
|
+
}, year: number | YearRange): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Options for filtering movies
|
|
44
|
+
*/
|
|
45
|
+
export interface FilterOptions {
|
|
46
|
+
platforms?: string[];
|
|
47
|
+
runtime?: RuntimeConstraints;
|
|
48
|
+
year?: number | YearRange;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Apply multiple filters to an array of movies
|
|
52
|
+
* @param movies Array of movies to filter
|
|
53
|
+
* @param options Filter options to apply
|
|
54
|
+
* @returns Filtered array of movies that pass all specified filters
|
|
55
|
+
*/
|
|
56
|
+
export declare function applyFilters<T extends {
|
|
57
|
+
platforms?: string[];
|
|
58
|
+
runtime?: number;
|
|
59
|
+
release_date?: string;
|
|
60
|
+
}>(movies: T[], options: FilterOptions): T[];
|
|
61
|
+
//# sourceMappingURL=filters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filters.d.ts","sourceRoot":"","sources":["../src/filters.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;GAEG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