feat(ai): support batch fetching multiple prompts with getMany (#4353) - #4690
feat(ai): support batch fetching multiple prompts with getMany (#4353)#4690vaibhavmashal wants to merge 2 commits into
Conversation
marandaneto
left a comment
There was a problem hiding this comment.
Automated advisory code review.
| ): Promise<Record<string, PromptResult>> { | ||
| const results: Record<string, PromptResult> = {} | ||
|
|
||
| await Promise.all( |
There was a problem hiding this comment.
blocking: getMany still makes one HTTP request per prompt — Promise.all(items.map(... this.get(...))) performs N independent fetches, so this does not deliver the issue's requested single network call. The existing GET /api/environments/{project_id}/llm_prompts/?content=full endpoint is not a substitute: it returns a paginated list of all latest prompts and cannot select exact names, resolve per-item versions or labels, or define partial missing-prompt behavior. A dedicated backend batch API is needed before the SDK can implement this contract; a focused two-prompt test expecting one fetch receives two.
| // Same as loader-globals.ts except includes all additional extension loaders | ||
| import './all-external-dependencies' | ||
| import './lazy-recorder' | ||
| import './external-scripts-loader' |
There was a problem hiding this comment.
blocking: Keep external loading out of no-external bundles — this import, mirrored in module.full.no-external.es.ts, embeds loadExternalDependency into artifacts whose established contract and regression tests require no script loader. After building, the existing entrypoint test fails both Array and Module assertions because these no-external bundles now contain the loader.
| /** | ||
| * Single prompt item or descriptor for batch fetching in Prompts.getMany() | ||
| */ | ||
| export type PromptBatchItem = string | ({ name: string } & GetPromptOptions) |
There was a problem hiding this comment.
blocking: Export the new descriptor type from the package root — PromptBatchItem appears in the public getMany signature, but packages/ai/src/index.ts does not re-export it. The generated declaration therefore causes import type { PromptBatchItem } from '@posthog/ai' to fail with TS2459.
| @@ -0,0 +1,5 @@ | |||
| --- | |||
| "posthog-js": patch | |||
There was a problem hiding this comment.
blocking: Add an @posthog/ai changeset — this changeset only versions posthog-js, so merging the new public getMany API will not version or publish @posthog/ai. changeset status confirms that the PR schedules only the posthog-js patch release.
|
moving this to draft until everything is addressed |
|
Makes total sense @marandaneto — having dedicated backend batch API endpoint support first will definitely be much cleaner and safer for infra load. Happy to keep this in draft and align the client interface once the backend endpoint is ready. |
Summary
Closes #4353
Adds \getMany()\ to @posthog/ai\ \Prompts\ to allow callers to fetch multiple prompts in a single call with concurrent execution, shared client-side caching, and per-item/shared fallback support.
Changes
Verification