Repository navigation
🏗️ feat(prompts): add source identity to prompt groups - #16891
AtefBellaaj wants to merge 1 commit into
Conversation
|
@codex review Please review head |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: edecafb7ba
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| source: TPromptGroupSource; | ||
| sourcePromptName?: string; | ||
| sourceProjectId?: string; | ||
| sourceDestination?: string; |
There was a problem hiding this comment.
Exclude immutable source fields from the update payload
When a typed client calls updatePromptGroup, TUpdatePromptGroupPayload = Partial<TPromptGroup> now permits all four provenance fields added here, but packages/api/src/prompts/schemas.ts uses a strict update schema that rejects each of them. Thus the public client contract accepts requests that invariably receive an invalid-request response; omit these immutable fields from the update payload type or define the payload from the fields the endpoint actually accepts.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in b0dc9fb. TUpdatePromptGroupPayload is now Partial<Omit<TPromptGroup, 'source' | 'sourcePromptName' | 'sourceProjectId' | 'sourceDestination'>>, so the typed client contract matches the strict update schema. tsc --noEmit is clean in data-provider, api and client; the only caller (PromptForm.tsx) already passes specific fields. packages/api src/prompts: 125 tests pass.
edecafb to
b0dc9fb
Compare
|
@codex review Please review head |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
b0dc9fb to
8649d12
Compare
|
@codex review Please review head |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
8649d12 to
3c2a54d
Compare
137b801 to
7f587fd
Compare
3e96977 to
00f8d83
Compare
be6a058 to
42af5a6
Compare
42af5a6 to
c1e1748
Compare
c1e1748 to
8a7fe3e
Compare
8a7fe3e to
fecabe8
Compare
504bd04 to
1546660
Compare
Add source, sourcePromptName, sourceProjectId and sourceDestination to PromptGroup. productionId is required only for native groups. A unique partial index on the source identity covers only groups that have sourcePromptName, so native groups need no migration. The create path drops client-supplied source fields, and the native create upsert does not match langfuse groups. Records map a missing source to native.
1546660 to
1019558
Compare
Summary
A PromptGroup has no record of where it came from, so later work that routes prompt operations by source, or that syncs prompts from an external catalog such as Langfuse, has nothing to key on. This PR adds the source fields to PromptGroup and stops a client from setting them. Existing native prompts keep working without a migration.
Stacked on #16854 (
atef/ai-2271-langfuse-prompt-test). No UI change.How it works
The schema stores flat, typed scalar fields rather than a subdocument or a Mixed blob, so each one maps to one column on FerretDB/PostgreSQL.
sourcedefaults tonative, andtoPromptGroupRecordmaps a stored group withoutsourcetonative, which is the only place the default applies.productionId: { type: Schema.Types.ObjectId, ref: 'Prompt', - required: true, + required: function (this: IPromptGroupDocument) { + return (this.source ?? 'native') === 'native'; + }, }, +source: { type: String, enum: ['native', 'langfuse'], default: 'native' }, +sourcePromptName: { + type: String, + required: function (this: IPromptGroupDocument) { + return this.source === 'langfuse'; + }, +}, +// sourceProjectId and sourceDestination: same shape ... +promptGroupSchema.index( + { tenantId: 1, sourceDestination: 1, sourceProjectId: 1, sourcePromptName: 1 }, + { unique: true, partialFilterExpression: { sourcePromptName: { $exists: true } } }, +);Write paths:
createPromptGroupinpackages/api/src/prompts/service.tsremovessource,sourcePromptName,sourceProjectIdandsourceDestinationfrom the clientgroup, so a client create always produces a native group. The native create upsert filter also hassource: { $ne: 'langfuse' }, becauseproductionId: nullalone also matches a group with noproductionId.updatePromptGroupSchemais.strict()and already rejects these keys. A test covers this.getAllPromptGroups,getPromptGroupsandgetListPromptGroupsByAccessselect the four fields.PromptGroupRecordandTPromptGroupdeclaresourceas required.Type of change
Testing
Tested environments/configuration: mongodb-memory-server (Jest).
Automated tests:
packages/data-schemas:npx jest src/methods/prompt(57 pass). These tests cover native groups rejected withoutproductionId, langfuse groups saved without it, langfuse groups rejected without identity fields, duplicate identity rejected in one tenant and accepted across tenants, duplicate native names accepted, the source fields in all three list methods, and a native create that does not merge into a langfuse group with the same name.packages/api:npx jest src/prompts(125 pass), including the newrecords.spec.ts(missingsourcemaps tonative), the create guard (raw stored document is native, without identity fields) and the strict update schema.api:npx jest server/routes/prompts.test.js(55 pass).npx tsc --noEmitpasses inpackages/data-schemas,packages/api,packages/data-providerandclient. Prettier, eslint and sort-imports pass on the changed files.Screenshots / recordings
No user-facing change.
Risk / compatibility
source; they validate as native (productionIdstays required for them) and read asnative. No data migration.sourcePromptName. No existing document has it, so the autoIndex build at startup is empty and cannot fail on duplicates. It uses the same$existspartial filter form as existing indexes, so it works on FerretDB and DocumentDB. No new aggregate stages or Mongo-only operators.groupreach the upsert as before.Checklist
🤖 Generated with Claude Code