@supyagent/sdk 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/prisma.d.ts +5 -63
- package/dist/prisma.js.map +1 -1
- package/package.json +16 -6
package/dist/prisma.d.ts
CHANGED
|
@@ -31,70 +31,12 @@ interface UIMessageLike {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
34
|
+
* Accepts any PrismaClient instance.
|
|
35
|
+
* We use `any` here because Prisma generates unique client types per schema,
|
|
36
|
+
* and a structural interface can't satisfy Prisma's branded enum types
|
|
37
|
+
* (e.g. SortOrder). The implementation only calls standard Prisma methods.
|
|
36
38
|
*/
|
|
37
|
-
|
|
38
|
-
chat: {
|
|
39
|
-
upsert: (args: {
|
|
40
|
-
where: {
|
|
41
|
-
id: string;
|
|
42
|
-
};
|
|
43
|
-
create: {
|
|
44
|
-
id: string;
|
|
45
|
-
title: string;
|
|
46
|
-
};
|
|
47
|
-
update: {
|
|
48
|
-
title?: string;
|
|
49
|
-
};
|
|
50
|
-
}) => Promise<unknown>;
|
|
51
|
-
findMany: (args: {
|
|
52
|
-
orderBy: {
|
|
53
|
-
updatedAt: string;
|
|
54
|
-
};
|
|
55
|
-
select: {
|
|
56
|
-
id: boolean;
|
|
57
|
-
title: boolean;
|
|
58
|
-
createdAt: boolean;
|
|
59
|
-
updatedAt: boolean;
|
|
60
|
-
};
|
|
61
|
-
}) => Promise<ChatSummary[]>;
|
|
62
|
-
delete: (args: {
|
|
63
|
-
where: {
|
|
64
|
-
id: string;
|
|
65
|
-
};
|
|
66
|
-
}) => Promise<unknown>;
|
|
67
|
-
};
|
|
68
|
-
message: {
|
|
69
|
-
count: (args: {
|
|
70
|
-
where: {
|
|
71
|
-
chatId: string;
|
|
72
|
-
};
|
|
73
|
-
}) => Promise<number>;
|
|
74
|
-
createMany: (args: {
|
|
75
|
-
data: Array<{
|
|
76
|
-
id: string;
|
|
77
|
-
chatId: string;
|
|
78
|
-
role: string;
|
|
79
|
-
parts: string;
|
|
80
|
-
metadata: string | null;
|
|
81
|
-
}>;
|
|
82
|
-
}) => Promise<unknown>;
|
|
83
|
-
findMany: (args: {
|
|
84
|
-
where: {
|
|
85
|
-
chatId: string;
|
|
86
|
-
};
|
|
87
|
-
orderBy: {
|
|
88
|
-
createdAt: string;
|
|
89
|
-
};
|
|
90
|
-
}) => Promise<Array<{
|
|
91
|
-
id: string;
|
|
92
|
-
role: string;
|
|
93
|
-
parts: string;
|
|
94
|
-
metadata: string | null;
|
|
95
|
-
}>>;
|
|
96
|
-
};
|
|
97
|
-
}
|
|
39
|
+
type PrismaLike = any;
|
|
98
40
|
/**
|
|
99
41
|
* Create a ChatAdapter backed by Prisma.
|
|
100
42
|
*
|
package/dist/prisma.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/persistence/prisma-adapter.ts"],"sourcesContent":["import type { ChatAdapter, ChatSummary, UIMessageLike } from \"./types.js\";\n\n/**\n *
|
|
1
|
+
{"version":3,"sources":["../src/persistence/prisma-adapter.ts"],"sourcesContent":["import type { ChatAdapter, ChatSummary, UIMessageLike } from \"./types.js\";\n\n/**\n * Accepts any PrismaClient instance.\n * We use `any` here because Prisma generates unique client types per schema,\n * and a structural interface can't satisfy Prisma's branded enum types\n * (e.g. SortOrder). The implementation only calls standard Prisma methods.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype PrismaLike = any;\n\n/**\n * Create a ChatAdapter backed by Prisma.\n *\n * @example\n * ```ts\n * import { createPrismaAdapter } from '@supyagent/sdk/prisma';\n * import { prisma } from '@/lib/prisma';\n *\n * const adapter = createPrismaAdapter(prisma);\n * ```\n */\nexport function createPrismaAdapter(prisma: PrismaLike): ChatAdapter {\n return {\n async saveChat(chatId: string, messages: UIMessageLike[]) {\n // Extract title from first user message\n const firstUserMsg = messages.find((m) => m.role === \"user\");\n const title = extractTitle(firstUserMsg);\n\n // Upsert the chat record\n await prisma.chat.upsert({\n where: { id: chatId },\n create: { id: chatId, title },\n update: { title },\n });\n\n // Append-only: count existing messages, create only new ones\n const existingCount = await prisma.message.count({\n where: { chatId },\n });\n\n const newMessages = messages.slice(existingCount);\n if (newMessages.length > 0) {\n await prisma.message.createMany({\n data: newMessages.map((msg) => ({\n id: msg.id,\n chatId,\n role: msg.role,\n parts: JSON.stringify(msg.parts),\n metadata: msg.metadata ? JSON.stringify(msg.metadata) : null,\n })),\n });\n }\n },\n\n async loadChat(chatId: string) {\n const messages = await prisma.message.findMany({\n where: { chatId },\n orderBy: { createdAt: \"asc\" },\n });\n\n return messages.map((msg: { id: string; role: string; parts: string; metadata: string | null }) => ({\n id: msg.id,\n role: msg.role,\n parts: JSON.parse(msg.parts),\n metadata: msg.metadata ? JSON.parse(msg.metadata) : undefined,\n }));\n },\n\n async listChats() {\n return prisma.chat.findMany({\n orderBy: { updatedAt: \"desc\" },\n select: {\n id: true,\n title: true,\n createdAt: true,\n updatedAt: true,\n },\n });\n },\n\n async deleteChat(chatId: string) {\n await prisma.chat.delete({ where: { id: chatId } });\n },\n };\n}\n\nfunction extractTitle(message?: UIMessageLike): string {\n if (!message) return \"New Chat\";\n const textPart = message.parts.find((p) => p.type === \"text\");\n if (textPart && typeof textPart.text === \"string\") {\n return textPart.text.slice(0, 100);\n }\n return \"New Chat\";\n}\n"],"mappings":";AAsBO,SAAS,oBAAoB,QAAiC;AACnE,SAAO;AAAA,IACL,MAAM,SAAS,QAAgB,UAA2B;AAExD,YAAM,eAAe,SAAS,KAAK,CAAC,MAAM,EAAE,SAAS,MAAM;AAC3D,YAAM,QAAQ,aAAa,YAAY;AAGvC,YAAM,OAAO,KAAK,OAAO;AAAA,QACvB,OAAO,EAAE,IAAI,OAAO;AAAA,QACpB,QAAQ,EAAE,IAAI,QAAQ,MAAM;AAAA,QAC5B,QAAQ,EAAE,MAAM;AAAA,MAClB,CAAC;AAGD,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AAO;AACrB,QAAM,WAAW,QAAQ,MAAM,KAAK,CAAC,MAAM,EAAE,SAAS,MAAM;AAC5D,MAAI,YAAY,OAAO,SAAS,SAAS,UAAU;AACjD,WAAO,SAAS,KAAK,MAAM,GAAG,GAAG;AAAA,EACnC;AACA,SAAO;AACT;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supyagent/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Supyagent SDK — AI SDK tools, persistence, and UI components",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -17,7 +17,9 @@
|
|
|
17
17
|
"types": "./dist/react.d.ts"
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
|
-
"files": [
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
21
23
|
"scripts": {
|
|
22
24
|
"build": "tsup",
|
|
23
25
|
"test": "vitest run",
|
|
@@ -34,10 +36,18 @@
|
|
|
34
36
|
"react-dom": ">=18.0.0"
|
|
35
37
|
},
|
|
36
38
|
"peerDependenciesMeta": {
|
|
37
|
-
"@prisma/client": {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"react
|
|
39
|
+
"@prisma/client": {
|
|
40
|
+
"optional": true
|
|
41
|
+
},
|
|
42
|
+
"lucide-react": {
|
|
43
|
+
"optional": true
|
|
44
|
+
},
|
|
45
|
+
"react": {
|
|
46
|
+
"optional": true
|
|
47
|
+
},
|
|
48
|
+
"react-dom": {
|
|
49
|
+
"optional": true
|
|
50
|
+
}
|
|
41
51
|
},
|
|
42
52
|
"devDependencies": {
|
|
43
53
|
"@testing-library/jest-dom": "^6.6.3",
|