-
Notifications
You must be signed in to change notification settings - Fork 4
Support bearer/query API keys (toggle), normalize/deduplicate memory imports, and use auth key for rate-limiting #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import crypto from 'crypto'; | ||
| import { scrubCredentials } from './scrub.js'; | ||
| import { validateMemoryInput } from '../middleware/validate.js'; | ||
|
|
||
| export function buildDedupExtraFilter(clientId, type) { | ||
| return { | ||
| active: true, | ||
| client_id: clientId || 'global', | ||
| type, | ||
| }; | ||
| } | ||
|
|
||
| export function normalizeMemoryRecord(record = {}, options = {}) { | ||
| const { | ||
| defaultType, | ||
| defaultSourceAgent, | ||
| } = options; | ||
|
|
||
| const rawContent = record.content || record.text || ''; | ||
| const normalized = { | ||
| ...record, | ||
| type: record.type || defaultType, | ||
| content: scrubCredentials(rawContent), | ||
| source_agent: record.source_agent || defaultSourceAgent, | ||
| client_id: record.client_id || 'global', | ||
| category: record.category || 'episodic', | ||
| importance: record.importance || 'medium', | ||
| knowledge_category: record.knowledge_category || 'general', | ||
| }; | ||
|
|
||
| const validationError = validateMemoryInput({ | ||
| type: normalized.type, | ||
| content: normalized.content, | ||
| source_agent: normalized.source_agent, | ||
| importance: normalized.importance, | ||
|
Comment on lines
+31
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This new centralized validation path does not pass Useful? React with 👍 / 👎. |
||
| client_id: normalized.client_id, | ||
| key: normalized.key, | ||
| subject: normalized.subject, | ||
| status_value: normalized.status_value, | ||
| }); | ||
|
|
||
| if (validationError) { | ||
| return { error: validationError }; | ||
| } | ||
|
|
||
| return { | ||
| normalized, | ||
| contentHash: crypto.createHash('sha256').update(normalized.content).digest('hex').slice(0, 16), | ||
| }; | ||
| } | ||
|
|
||
| export function normalizeImportRecord(record = {}) { | ||
| return normalizeMemoryRecord(record, { | ||
| defaultType: 'event', | ||
| defaultSourceAgent: 'import', | ||
| }); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bearer scheme matching is currently case-sensitive (
startsWith('Bearer ')), but HTTP auth schemes are case-insensitive, so valid headers likeauthorization: bearer <token>are rejected with 401. Since this commit introduces Bearer-token support, this causes legitimate clients/proxies using lowercase schemes to fail authentication unexpectedly.Useful? React with 👍 / 👎.