aboutsummaryrefslogtreecommitdiff
path: root/packages/validation
diff options
context:
space:
mode:
authorMahesh Sanikommu <[email protected]>2025-08-21 08:40:44 -0700
committerGitHub <[email protected]>2025-08-21 08:40:44 -0700
commit9e1e392a2b923c9d00e12c0fd27586d9d5b29daf (patch)
tree8b10459076bdfb4a2882acd4cccdc3e7dea1e838 /packages/validation
parentMerge pull request #368 from supermemoryai/mahesh/doc-update (diff)
downloadsupermemory-9e1e392a2b923c9d00e12c0fd27586d9d5b29daf.tar.xz
supermemory-9e1e392a2b923c9d00e12c0fd27586d9d5b29daf.zip
Enhanced Text Editor and format fixes with biome (#371)
Diffstat (limited to 'packages/validation')
-rw-r--r--packages/validation/api.ts270
-rw-r--r--packages/validation/package.json10
-rw-r--r--packages/validation/schemas.ts83
3 files changed, 181 insertions, 182 deletions
diff --git a/packages/validation/api.ts b/packages/validation/api.ts
index 060c3d69..91ac5e09 100644
--- a/packages/validation/api.ts
+++ b/packages/validation/api.ts
@@ -1,11 +1,11 @@
import { z } from "zod"
import "zod-openapi/extend"
import {
+ MetadataSchema as BaseMetadataSchema,
DocumentSchema,
MemoryEntrySchema,
OrganizationSettingsSchema,
RequestTypeEnum,
- MetadataSchema as BaseMetadataSchema,
} from "./schemas"
export const MetadataSchema = BaseMetadataSchema
@@ -47,90 +47,96 @@ const exampleMemory = {
url: "https://example.com/article",
} as const
-export const MemorySchema = z.object({
- id: z.string().openapi({
- description: "Unique identifier of the memory.",
- example: "acxV5LHMEsG2hMSNb4umbn",
- }),
- customId: z.string().nullable().optional().openapi({
- description:
- "Optional custom ID of the memory. This could be an ID from your database that will uniquely identify this memory.",
- example: "mem_abc123",
- }),
- connectionId: z.string().nullable().optional().openapi({
- description:
- "Optional ID of connection the memory was created from. This is useful for identifying the source of the memory.",
- example: "conn_123",
- }),
- content: z.string().nullable().optional().openapi({
- description:
- "The content to extract and process into a memory. This can be a URL to a website, a PDF, an image, or a video. \n\nPlaintext: Any plaintext format\n\nURL: A URL to a website, PDF, image, or video\n\nWe automatically detect the content type from the url's response format.",
- examples: [
- "This is a detailed article about machine learning concepts...",
- "https://example.com/article",
- "https://youtube.com/watch?v=abc123",
- "https://example.com/audio.mp3",
- "https://aws-s3.com/bucket/file.pdf",
- "https://example.com/image.jpg",
- ],
- }),
- metadata: MetadataSchema.nullable().optional().openapi({
- description:
- "Optional metadata for the memory. This is used to store additional information about the memory. You can use this to store any additional information you need about the memory. Metadata can be filtered through. Keys must be strings and are case sensitive. Values can be strings, numbers, or booleans. You cannot nest objects.",
- example: exampleMetadata,
- }),
- source: z.string().nullable().optional().openapi({
- description: "Source of the memory",
- example: "web",
- }),
- status: DocumentSchema.shape.status.openapi({
- description: "Status of the memory",
- example: "done",
- }),
- summary: z.string().nullable().optional().openapi({
- description: "Summary of the memory content",
- example:
- "A comprehensive guide to understanding the basics of machine learning and its applications.",
- }),
- title: z.string().nullable().optional().openapi({
- description: "Title of the memory",
- example: "Introduction to Machine Learning",
- }),
- type: DocumentSchema.shape.type.openapi({
- description: "Type of the memory",
- example: "text",
- }),
- url: z.string().nullable().optional().openapi({
- description: "URL of the memory",
- example: "https://example.com/article",
- }),
- createdAt: z.string().openapi({
- description: "Creation timestamp",
- example: new Date().toISOString(),
- format: "date-time",
- }),
- updatedAt: z.string().openapi({
- description: "Last update timestamp",
- example: new Date().toISOString(),
- format: "date-time",
- }),
- containerTags: z
- .array(z.string())
- .optional()
- .readonly()
- .openapi({
+export const MemorySchema = z
+ .object({
+ id: z.string().openapi({
+ description: "Unique identifier of the memory.",
+ example: "acxV5LHMEsG2hMSNb4umbn",
+ }),
+ customId: z.string().nullable().optional().openapi({
description:
- "Optional tags this memory should be containerized by. This can be an ID for your user, a project ID, or any other identifier you wish to use to group memories.",
- example: ["user_123", "project_123"] as const,
+ "Optional custom ID of the memory. This could be an ID from your database that will uniquely identify this memory.",
+ example: "mem_abc123",
}),
- chunkCount: z.number().default(0).openapi({
- description: "Number of chunks in the memory",
- example: 10,
- }),
-}).openapi({
- description: "Memory object",
- example: exampleMemory,
-})
+ connectionId: z.string().nullable().optional().openapi({
+ description:
+ "Optional ID of connection the memory was created from. This is useful for identifying the source of the memory.",
+ example: "conn_123",
+ }),
+ content: z
+ .string()
+ .nullable()
+ .optional()
+ .openapi({
+ description:
+ "The content to extract and process into a memory. This can be a URL to a website, a PDF, an image, or a video. \n\nPlaintext: Any plaintext format\n\nURL: A URL to a website, PDF, image, or video\n\nWe automatically detect the content type from the url's response format.",
+ examples: [
+ "This is a detailed article about machine learning concepts...",
+ "https://example.com/article",
+ "https://youtube.com/watch?v=abc123",
+ "https://example.com/audio.mp3",
+ "https://aws-s3.com/bucket/file.pdf",
+ "https://example.com/image.jpg",
+ ],
+ }),
+ metadata: MetadataSchema.nullable().optional().openapi({
+ description:
+ "Optional metadata for the memory. This is used to store additional information about the memory. You can use this to store any additional information you need about the memory. Metadata can be filtered through. Keys must be strings and are case sensitive. Values can be strings, numbers, or booleans. You cannot nest objects.",
+ example: exampleMetadata,
+ }),
+ source: z.string().nullable().optional().openapi({
+ description: "Source of the memory",
+ example: "web",
+ }),
+ status: DocumentSchema.shape.status.openapi({
+ description: "Status of the memory",
+ example: "done",
+ }),
+ summary: z.string().nullable().optional().openapi({
+ description: "Summary of the memory content",
+ example:
+ "A comprehensive guide to understanding the basics of machine learning and its applications.",
+ }),
+ title: z.string().nullable().optional().openapi({
+ description: "Title of the memory",
+ example: "Introduction to Machine Learning",
+ }),
+ type: DocumentSchema.shape.type.openapi({
+ description: "Type of the memory",
+ example: "text",
+ }),
+ url: z.string().nullable().optional().openapi({
+ description: "URL of the memory",
+ example: "https://example.com/article",
+ }),
+ createdAt: z.string().openapi({
+ description: "Creation timestamp",
+ example: new Date().toISOString(),
+ format: "date-time",
+ }),
+ updatedAt: z.string().openapi({
+ description: "Last update timestamp",
+ example: new Date().toISOString(),
+ format: "date-time",
+ }),
+ containerTags: z
+ .array(z.string())
+ .optional()
+ .readonly()
+ .openapi({
+ description:
+ "Optional tags this memory should be containerized by. This can be an ID for your user, a project ID, or any other identifier you wish to use to group memories.",
+ example: ["user_123", "project_123"] as const,
+ }),
+ chunkCount: z.number().default(0).openapi({
+ description: "Number of chunks in the memory",
+ example: 10,
+ }),
+ })
+ .openapi({
+ description: "Memory object",
+ example: exampleMemory,
+ })
export const MemoryUpdateSchema = z.object({
containerTags: z
@@ -698,7 +704,8 @@ export const MemorySearchResult = z.object({
.array(
z.object({
relation: z.enum(["updates", "extends", "derives"]).openapi({
- description: "Relation type between this memory and its parent/child",
+ description:
+ "Relation type between this memory and its parent/child",
example: "updates",
}),
version: z.number().nullable().optional().openapi({
@@ -725,7 +732,8 @@ export const MemorySearchResult = z.object({
.array(
z.object({
relation: z.enum(["updates", "extends", "derives"]).openapi({
- description: "Relation type between this memory and its parent/child",
+ description:
+ "Relation type between this memory and its parent/child",
example: "extends",
}),
version: z.number().nullable().optional().openapi({
@@ -1027,48 +1035,48 @@ export const AnalyticsMemoryResponseSchema = z.object({
totalMemories: z.number(),
})
-export const MemoryEntryAPISchema = MemoryEntrySchema
- .extend({
- sourceAddedAt: z.date().nullable(), // From join relationship
- sourceRelevanceScore: z.number().nullable(), // From join relationship
- sourceMetadata: z.record(z.unknown()).nullable(), // From join relationship
- spaceContainerTag: z.string().nullable(), // From join relationship
+export const MemoryEntryAPISchema = MemoryEntrySchema.extend({
+ sourceAddedAt: z.date().nullable(), // From join relationship
+ sourceRelevanceScore: z.number().nullable(), // From join relationship
+ sourceMetadata: z.record(z.unknown()).nullable(), // From join relationship
+ spaceContainerTag: z.string().nullable(), // From join relationship
+}).openapi({
+ description: "Memory entry with source relationship data",
+})
+
+// Extended document schema with memory entries
+export const DocumentWithMemoriesSchema = z
+ .object({
+ id: DocumentSchema.shape.id,
+ customId: DocumentSchema.shape.customId,
+ contentHash: DocumentSchema.shape.contentHash,
+ orgId: DocumentSchema.shape.orgId,
+ userId: DocumentSchema.shape.userId,
+ connectionId: DocumentSchema.shape.connectionId,
+ title: DocumentSchema.shape.title,
+ content: DocumentSchema.shape.content,
+ summary: DocumentSchema.shape.summary,
+ url: DocumentSchema.shape.url,
+ source: DocumentSchema.shape.source,
+ type: DocumentSchema.shape.type,
+ status: DocumentSchema.shape.status,
+ metadata: DocumentSchema.shape.metadata,
+ processingMetadata: DocumentSchema.shape.processingMetadata,
+ raw: DocumentSchema.shape.raw,
+ tokenCount: DocumentSchema.shape.tokenCount,
+ wordCount: DocumentSchema.shape.wordCount,
+ chunkCount: DocumentSchema.shape.chunkCount,
+ averageChunkSize: DocumentSchema.shape.averageChunkSize,
+ summaryEmbedding: DocumentSchema.shape.summaryEmbedding,
+ summaryEmbeddingModel: DocumentSchema.shape.summaryEmbeddingModel,
+ createdAt: DocumentSchema.shape.createdAt,
+ updatedAt: DocumentSchema.shape.updatedAt,
+ memoryEntries: z.array(MemoryEntryAPISchema),
})
.openapi({
- description: "Memory entry with source relationship data",
+ description: "Document with associated memory entries",
})
-// Extended document schema with memory entries
-export const DocumentWithMemoriesSchema = z.object({
- id: DocumentSchema.shape.id,
- customId: DocumentSchema.shape.customId,
- contentHash: DocumentSchema.shape.contentHash,
- orgId: DocumentSchema.shape.orgId,
- userId: DocumentSchema.shape.userId,
- connectionId: DocumentSchema.shape.connectionId,
- title: DocumentSchema.shape.title,
- content: DocumentSchema.shape.content,
- summary: DocumentSchema.shape.summary,
- url: DocumentSchema.shape.url,
- source: DocumentSchema.shape.source,
- type: DocumentSchema.shape.type,
- status: DocumentSchema.shape.status,
- metadata: DocumentSchema.shape.metadata,
- processingMetadata: DocumentSchema.shape.processingMetadata,
- raw: DocumentSchema.shape.raw,
- tokenCount: DocumentSchema.shape.tokenCount,
- wordCount: DocumentSchema.shape.wordCount,
- chunkCount: DocumentSchema.shape.chunkCount,
- averageChunkSize: DocumentSchema.shape.averageChunkSize,
- summaryEmbedding: DocumentSchema.shape.summaryEmbedding,
- summaryEmbeddingModel: DocumentSchema.shape.summaryEmbeddingModel,
- createdAt: DocumentSchema.shape.createdAt,
- updatedAt: DocumentSchema.shape.updatedAt,
- memoryEntries: z.array(MemoryEntryAPISchema),
-}).openapi({
- description: "Document with associated memory entries",
-})
-
export const DocumentsWithMemoriesResponseSchema = z
.object({
documents: z.array(DocumentWithMemoriesSchema),
@@ -1212,14 +1220,14 @@ export const ProjectSchema = z
format: "date-time",
}),
updatedAt: z.string().openapi({
- description: "Last update timestamp",
- example: new Date().toISOString(),
- format: "date-time",
- }),
- isExperimental: z.boolean().openapi({
- description: "Whether the project (space) is in experimental mode",
- example: false,
- }),
+ description: "Last update timestamp",
+ example: new Date().toISOString(),
+ format: "date-time",
+ }),
+ isExperimental: z.boolean().openapi({
+ description: "Whether the project (space) is in experimental mode",
+ example: false,
+ }),
documentCount: z.number().optional().openapi({
description: "Number of documents in this project",
example: 42,
diff --git a/packages/validation/package.json b/packages/validation/package.json
index e217993d..ea9f5fc1 100644
--- a/packages/validation/package.json
+++ b/packages/validation/package.json
@@ -1,6 +1,6 @@
{
- "name": "@repo/validation",
- "version": "0.0.0",
- "private": true,
- "type": "module"
-} \ No newline at end of file
+ "name": "@repo/validation",
+ "version": "0.0.0",
+ "private": true,
+ "type": "module"
+}
diff --git a/packages/validation/schemas.ts b/packages/validation/schemas.ts
index 1cd2701c..92524164 100644
--- a/packages/validation/schemas.ts
+++ b/packages/validation/schemas.ts
@@ -10,7 +10,7 @@ export type Visibility = z.infer<typeof VisibilityEnum>
export const DocumentTypeEnum = z.enum([
"text",
- "pdf",
+ "pdf",
"tweet",
"google_doc",
"google_slide",
@@ -26,7 +26,7 @@ export type DocumentType = z.infer<typeof DocumentTypeEnum>
export const DocumentStatusEnum = z.enum([
"unknown",
"queued",
- "extracting",
+ "extracting",
"chunking",
"embedding",
"indexing",
@@ -125,7 +125,7 @@ export type Chunk = z.infer<typeof ChunkSchema>
export const ConnectionProviderEnum = z.enum([
"notion",
- "google-drive",
+ "google-drive",
"onedrive",
])
export type ConnectionProvider = z.infer<typeof ConnectionProviderEnum>
@@ -153,22 +153,22 @@ export const ConnectionSchema = z.object({
email: z.string().nullable().optional(),
documentLimit: z.number().default(10000),
containerTags: z.array(z.string()).nullable().optional(),
-
+
// Token management
accessToken: z.string().nullable().optional(),
refreshToken: z.string().nullable().optional(),
expiresAt: z.coerce.date().nullable().optional(),
-
+
// Provider-specific metadata
metadata: z.record(z.unknown()),
-
+
createdAt: z.coerce.date(),
})
export type Connection = z.infer<typeof ConnectionSchema>
export const RequestTypeEnum = z.enum([
"add",
- "search",
+ "search",
"fast_search",
"request",
"update",
@@ -186,31 +186,31 @@ export const ApiRequestSchema = z.object({
keyId: z.string().nullable().optional(),
statusCode: z.number(),
duration: z.number().nullable().optional(), // duration in ms
-
+
// Request/Response data
input: z.record(z.unknown()).nullable().optional(),
output: z.record(z.unknown()).nullable().optional(),
-
+
// Token usage tracking
originalTokens: z.number().nullable().optional(),
finalTokens: z.number().nullable().optional(),
tokensSaved: z.number().nullable().optional(), // computed field
-
+
// Cost tracking
costSavedUSD: z.number().nullable().optional(),
-
+
// Chat specific fields
model: z.string().nullable().optional(),
provider: z.string().nullable().optional(),
conversationId: z.string().nullable().optional(),
-
+
// Flags
contextModified: z.boolean().default(false),
-
+
// Metadata
metadata: MetadataSchema.nullable().optional(),
origin: z.string().default("api"),
-
+
createdAt: z.coerce.date(),
})
export type ApiRequest = z.infer<typeof ApiRequestSchema>
@@ -224,23 +224,19 @@ export const SpaceSchema = z.object({
containerTag: z.string().nullable().optional(),
visibility: VisibilityEnum.default("private"),
isExperimental: z.boolean().default(false),
-
+
// Content indexing
contentTextIndex: z.record(z.unknown()).default({}), // KnowledgeBase type
indexSize: z.number().nullable().optional(),
-
+
metadata: MetadataSchema.nullable().optional(),
-
+
createdAt: z.coerce.date(),
updatedAt: z.coerce.date(),
})
export type Space = z.infer<typeof SpaceSchema>
-export const MemoryRelationEnum = z.enum([
- "updates",
- "extends",
- "derives",
-])
+export const MemoryRelationEnum = z.enum(["updates", "extends", "derives"])
export type MemoryRelation = z.infer<typeof MemoryRelationEnum>
export const MemoryEntrySchema = z.object({
@@ -249,33 +245,33 @@ export const MemoryEntrySchema = z.object({
spaceId: z.string(),
orgId: z.string(),
userId: z.string().nullable().optional(),
-
+
// Version control
version: z.number().default(1),
isLatest: z.boolean().default(true),
parentMemoryId: z.string().nullable().optional(),
rootMemoryId: z.string().nullable().optional(),
-
+
// Memory relationships
memoryRelations: z.record(MemoryRelationEnum).default({}),
-
+
// Source tracking
sourceCount: z.number().default(1),
-
+
// Status flags
isInference: z.boolean().default(false),
isForgotten: z.boolean().default(false),
forgetAfter: z.coerce.date().nullable().optional(),
forgetReason: z.string().nullable().optional(),
-
+
// Embeddings
memoryEmbedding: z.array(z.number()).nullable().optional(),
memoryEmbeddingModel: z.string().nullable().optional(),
memoryEmbeddingNew: z.array(z.number()).nullable().optional(),
memoryEmbeddingNewModel: z.string().nullable().optional(),
-
+
metadata: z.record(z.unknown()).nullable().optional(),
-
+
createdAt: z.coerce.date(),
updatedAt: z.coerce.date(),
})
@@ -296,12 +292,7 @@ export const MemoryDocumentSourceSchema = z.object({
})
export type MemoryDocumentSource = z.infer<typeof MemoryDocumentSourceSchema>
-export const SpaceRoleEnum = z.enum([
- "owner",
- "admin",
- "editor",
- "viewer",
-])
+export const SpaceRoleEnum = z.enum(["owner", "admin", "editor", "viewer"])
export type SpaceRole = z.infer<typeof SpaceRoleEnum>
export const SpacesToMembersSchema = z.object({
@@ -317,28 +308,28 @@ export type SpacesToMembers = z.infer<typeof SpacesToMembersSchema>
export const OrganizationSettingsSchema = z.object({
id: z.string(),
orgId: z.string(),
-
+
// LLM Filtering
shouldLLMFilter: z.boolean().default(false),
filterPrompt: z.string().nullable().optional(),
includeItems: z.array(z.string()).nullable().optional(),
excludeItems: z.array(z.string()).nullable().optional(),
-
+
// Google Drive custom keys
googleDriveCustomKeyEnabled: z.boolean().default(false),
googleDriveClientId: z.string().nullable().optional(),
googleDriveClientSecret: z.string().nullable().optional(),
-
+
// Notion custom keys
notionCustomKeyEnabled: z.boolean().default(false),
notionClientId: z.string().nullable().optional(),
notionClientSecret: z.string().nullable().optional(),
-
+
// OneDrive custom keys
onedriveCustomKeyEnabled: z.boolean().default(false),
onedriveClientId: z.string().nullable().optional(),
onedriveClientSecret: z.string().nullable().optional(),
-
+
updatedAt: z.coerce.date(),
})
export type OrganizationSettings = z.infer<typeof OrganizationSettingsSchema>
@@ -347,7 +338,7 @@ export const schemas = {
// Base types
MetadataSchema,
VisibilityEnum,
-
+
// Content
DocumentTypeEnum,
DocumentStatusEnum,
@@ -356,16 +347,16 @@ export const schemas = {
DocumentSchema,
ChunkTypeEnum,
ChunkSchema,
-
+
// Connections
ConnectionProviderEnum,
ConnectionStateSchema,
ConnectionSchema,
-
+
// Analytics
RequestTypeEnum,
ApiRequestSchema,
-
+
// Spaces and Memory
SpaceSchema,
MemoryRelationEnum,
@@ -374,7 +365,7 @@ export const schemas = {
MemoryDocumentSourceSchema,
SpaceRoleEnum,
SpacesToMembersSchema,
-
+
// Auth
OrganizationSettingsSchema,
-} as const \ No newline at end of file
+} as const