@devries-cameron20 / composio Mirror · read-only
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 03:37 UTC

next
ts 25 lines 1.03 KB
Raw
1 import { readFile } from 'node:fs/promises';
2 import { join } from 'node:path';
3 import { z } from 'zod';
4
5 export const contentFreshnessSchema = z.object({
6 version: z.literal(1),
7 pages: z.record(z.string(), z.iso.datetime({ offset: true })),
8 });
9
10 export type ContentFreshnessManifest = z.infer<typeof contentFreshnessSchema>;
11
12 /** Read only the persisted build artifact: deployed functions never need Git. */
13 export function createPageLastUpdatedReader(manifestPath: string) {
14 let manifest: Promise<ContentFreshnessManifest | null> | undefined;
15 return async (pathname: string): Promise<string | null> => {
16 manifest ??= readFile(manifestPath, 'utf8').then(
17 text => contentFreshnessSchema.parse(JSON.parse(text)),
18 ).catch(() => null);
19 const data = await manifest;
20 return data && Object.hasOwn(data.pages, pathname) ? data.pages[pathname] ?? null : null;
21 };
22 }
23
24 export const getPageLastUpdated: (pathname: string) => Promise<string | null> =
25 createPageLastUpdatedReader(join(process.cwd(), '.generated/content-freshness.json'));