@promptbook/cli 0.103.0-47 → 0.103.0-48

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.
Files changed (48) hide show
  1. package/apps/agents-server/TODO.txt +2 -2
  2. package/apps/agents-server/config.ts.todo +5 -279
  3. package/apps/agents-server/src/app/agents/[agentName]/api/chat/route.ts +7 -1
  4. package/apps/agents-server/src/app/agents/[agentName]/book/BookEditorWrapper.tsx +2 -2
  5. package/apps/agents-server/src/app/agents/[agentName]/book+chat/AgentBookAndChatComponent.tsx +2 -4
  6. package/apps/agents-server/src/app/agents/[agentName]/page.tsx +2 -2
  7. package/apps/agents-server/src/app/api/upload/route.ts +0 -4
  8. package/apps/agents-server/src/{supabase/getSupabase.ts → database/$provideSupabase.ts} +11 -7
  9. package/apps/agents-server/src/{supabase/getSupabaseForBrowser.ts → database/$provideSupabaseForBrowser.ts} +9 -5
  10. package/apps/agents-server/src/{supabase/getSupabaseForServer.ts → database/$provideSupabaseForServer.ts} +4 -4
  11. package/apps/agents-server/src/{supabase/getSupabaseForWorker.ts → database/$provideSupabaseForWorker.ts} +5 -4
  12. package/apps/agents-server/src/database/schema.sql +131 -0
  13. package/apps/agents-server/src/database/schema.ts +217 -0
  14. package/apps/agents-server/src/tools/$provideAgentCollectionForServer.ts +3 -3
  15. package/apps/agents-server/src/tools/$provideOpenAiAssistantExecutionToolsForServer.ts +1 -1
  16. package/apps/agents-server/src/utils/cdn/utils/getUserFileCdnKey.ts +2 -1
  17. package/esm/index.es.js +166 -21
  18. package/esm/index.es.js.map +1 -1
  19. package/esm/typings/src/_packages/core.index.d.ts +6 -0
  20. package/esm/typings/src/_packages/types.index.d.ts +2 -0
  21. package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +7 -3
  22. package/esm/typings/src/book-2.0/agent-source/AgentSourceParseResult.d.ts +2 -1
  23. package/esm/typings/src/book-2.0/agent-source/computeAgentHash.d.ts +8 -0
  24. package/esm/typings/src/book-2.0/agent-source/computeAgentHash.test.d.ts +1 -0
  25. package/esm/typings/src/book-2.0/agent-source/createDefaultAgentName.d.ts +8 -0
  26. package/esm/typings/src/book-2.0/agent-source/normalizeAgentName.d.ts +9 -0
  27. package/esm/typings/src/book-2.0/agent-source/normalizeAgentName.test.d.ts +1 -0
  28. package/esm/typings/src/book-2.0/agent-source/parseAgentSourceWithCommitments.d.ts +1 -1
  29. package/esm/typings/src/collection/agent-collection/constructors/agent-collection-in-supabase/AgentsDatabaseSchema.d.ts +57 -32
  30. package/esm/typings/src/llm-providers/_common/utils/assertUniqueModels.d.ts +12 -0
  31. package/esm/typings/src/llm-providers/agent/Agent.d.ts +7 -2
  32. package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +4 -0
  33. package/esm/typings/src/llm-providers/agent/RemoteAgent.d.ts +2 -2
  34. package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +24 -3
  35. package/esm/typings/src/llm-providers/openai/openai-models.test.d.ts +4 -0
  36. package/esm/typings/src/remote-server/startAgentServer.d.ts +1 -1
  37. package/esm/typings/src/remote-server/startRemoteServer.d.ts +1 -2
  38. package/esm/typings/src/transpilers/openai-sdk/register.d.ts +1 -1
  39. package/esm/typings/src/types/typeAliases.d.ts +6 -0
  40. package/esm/typings/src/utils/normalization/normalize-to-kebab-case.d.ts +2 -0
  41. package/esm/typings/src/utils/normalization/normalizeTo_PascalCase.d.ts +3 -0
  42. package/esm/typings/src/utils/normalization/normalizeTo_camelCase.d.ts +2 -0
  43. package/esm/typings/src/utils/normalization/titleToName.d.ts +2 -0
  44. package/esm/typings/src/version.d.ts +1 -1
  45. package/package.json +1 -1
  46. package/umd/index.umd.js +167 -22
  47. package/umd/index.umd.js.map +1 -1
  48. package/apps/agents-server/src/supabase/TODO.txt +0 -1
@@ -0,0 +1,131 @@
1
+
2
+ -- Note: This is primary source of truth for the database schema
3
+ -- In future we want to be compatible with more then Supabase so we keep SQL as main schema definition
4
+ -- To update, search for [💽]
5
+
6
+
7
+
8
+ CREATE TABLE IF NOT EXISTS "EnvironmentVariable" (
9
+ "id" BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
10
+ "key" TEXT NOT NULL,
11
+ "value" TEXT NOT NULL,
12
+ "note" TEXT NULL,
13
+ CONSTRAINT EnvironmentVariable_key_key UNIQUE ("key")
14
+ );
15
+
16
+
17
+ CREATE TABLE IF NOT EXISTS "Agent" (
18
+ "id" BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
19
+ "agentName" TEXT NOT NULL,
20
+
21
+
22
+ "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
23
+ "updatedAt" TIMESTAMP WITH TIME ZONE NULL DEFAULT NULL,
24
+
25
+
26
+ "agentHash" TEXT NOT NULL,
27
+ "agentSource" TEXT NOT NULL,
28
+ "agentProfile" JSONB NOT NULL,
29
+ "promptbookEngineVersion" TEXT NOT NULL,
30
+
31
+ "usage" JSONB NULL,
32
+ "preparedModelRequirements" JSONB NULL,
33
+ "preparedExternals" JSONB NULL
34
+ );
35
+ -- Ensure uniqueness of agentName even on repeated schema application without duplicate constraint creation
36
+ CREATE UNIQUE INDEX IF NOT EXISTS agent_agentname_key ON "Agent" ("agentName");
37
+ COMMENT ON COLUMN "Agent"."agentName" IS 'The unique name of the agent derived from the first line of the `agentSource`, automatically updated on `agentSource` change';
38
+ COMMENT ON COLUMN "Agent"."agentHash" IS 'The hash of the `agentSource`, automatically updated on `agentSource` change';
39
+ COMMENT ON COLUMN "Agent"."agentSource" IS 'The source code of the agent';
40
+ COMMENT ON COLUMN "Agent"."agentProfile" IS 'The profile of the agent generated from the `agentSource`, automatically updated on `agentSource` change <- TODO: [🕛]';
41
+ COMMENT ON COLUMN "Agent"."promptbookEngineVersion" IS 'The version of the Promptbook engine used for last update of the agent';
42
+ COMMENT ON COLUMN "Agent"."usage" IS 'Usage and spending statistics for the agent';
43
+ COMMENT ON COLUMN "Agent"."preparedModelRequirements" IS 'The prepared model requirements for the agent, generated from the `agentSource` but not after every change (only on explicit request), there is `agentHash` to identify the version of the `agentSource` this was prepared from';
44
+ COMMENT ON COLUMN "Agent"."preparedExternals" IS 'The prepared externals for the agent, generated from the `agentSource` but not after every change (only on explicit request), there is `agentHash` to identify the version of the `agentSource` this was prepared from';
45
+
46
+
47
+ CREATE TABLE IF NOT EXISTS "AgentHistory" (
48
+ "id" BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
49
+ "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
50
+
51
+ "agentName" TEXT NOT NULL,
52
+ "agentHash" TEXT NOT NULL,
53
+ "previousAgentHash" TEXT NULL,
54
+ "agentSource" TEXT NOT NULL,
55
+ "promptbookEngineVersion" TEXT NOT NULL
56
+
57
+ );
58
+
59
+ CREATE INDEX IF NOT EXISTS "AgentHistory_agentName_idx" ON "AgentHistory" ("agentName");
60
+ CREATE INDEX IF NOT EXISTS "AgentHistory_agentHash_idx" ON "AgentHistory" ("agentHash");
61
+
62
+
63
+ CREATE TABLE IF NOT EXISTS "ChatHistory" (
64
+ "id" BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
65
+ "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
66
+
67
+ "messageHash" TEXT NOT NULL,
68
+ "previousMessageHash" TEXT NULL,
69
+ "agentName" TEXT NOT NULL,
70
+ "agentHash" TEXT NOT NULL,
71
+ "message" JSONB NOT NULL,
72
+
73
+ -- Telemetry:
74
+ "promptbookEngineVersion" TEXT NULL,
75
+ "url" TEXT NULL,
76
+ "ip" TEXT NULL,
77
+ "userAgent" TEXT NULL,
78
+ "language" TEXT NULL,
79
+ "platform" TEXT NULL
80
+ );
81
+ COMMENT ON COLUMN "ChatHistory"."url" IS 'The URL where the chat was happening';
82
+ COMMENT ON COLUMN "ChatHistory"."ip" IS 'The IP address of the user';
83
+ COMMENT ON COLUMN "ChatHistory"."userAgent" IS 'The user agent (browser) of the user';
84
+ COMMENT ON COLUMN "ChatHistory"."language" IS 'The language (from the browser) of the user';
85
+ COMMENT ON COLUMN "ChatHistory"."platform" IS 'The platform of the user';
86
+
87
+
88
+ CREATE TABLE IF NOT EXISTS "ChatFeedback" (
89
+ "id" BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
90
+ "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
91
+
92
+ "agentName" TEXT NOT NULL,
93
+ "agentHash" TEXT NOT NULL,
94
+ "rating" TEXT NULL,
95
+ "textRating" TEXT NULL,
96
+ "chatThread" TEXT NULL,
97
+ "userNote" TEXT NULL,
98
+ "expectedAnswer" TEXT NULL,
99
+
100
+ -- Telemetry:
101
+ "promptbookEngineVersion" TEXT NULL,
102
+ "url" TEXT NULL,
103
+ "ip" TEXT NULL,
104
+ "userAgent" TEXT NULL,
105
+ "language" TEXT NULL,
106
+ "platform" TEXT NULL
107
+ );
108
+ COMMENT ON COLUMN "ChatFeedback"."url" IS 'The URL where the chat was happening';
109
+ COMMENT ON COLUMN "ChatFeedback"."ip" IS 'The IP address of the user';
110
+ COMMENT ON COLUMN "ChatFeedback"."userAgent" IS 'The user agent (browser) of the user';
111
+ COMMENT ON COLUMN "ChatFeedback"."language" IS 'The language (from the browser) of the user';
112
+ COMMENT ON COLUMN "ChatFeedback"."platform" IS 'The platform of the user';
113
+
114
+
115
+ /*
116
+ CREATE TABLE IF NOT EXISTS "AgentActionHistory" (
117
+ id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
118
+ createdAt TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(),
119
+
120
+ );
121
+ */
122
+
123
+
124
+ /*
125
+ CREATE TABLE IF NOT EXISTS "Xxx" (
126
+ id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL,
127
+ );
128
+ */
129
+
130
+
131
+ -- TODO: !!!! Create propper database migrations
@@ -0,0 +1,217 @@
1
+ /**
2
+ * AUTO-GENERATED TYPES FROM `schema.sql`
3
+ * Source of truth: `schema.sql` *(do not edit table structure here manually)*
4
+ *
5
+ * [💽] Prompt:
6
+ * Re-generate supabase typescript schema from the `./schema.sql`
7
+ */
8
+
9
+ // Json helper (Supabase style)
10
+ export type Json = string | number | boolean | null | { [key: string]: Json | undefined } | Json[];
11
+
12
+ // Public schema database interface (Supabase convention)
13
+ export type AgentsServerDatabase = {
14
+ public: {
15
+ Tables: {
16
+ EnvironmentVariable: {
17
+ Row: {
18
+ id: number;
19
+ key: string;
20
+ value: string;
21
+ note: string | null;
22
+ };
23
+ Insert: {
24
+ id?: number;
25
+ key: string;
26
+ value: string;
27
+ note?: string | null;
28
+ };
29
+ Update: {
30
+ id?: number;
31
+ key?: string;
32
+ value?: string;
33
+ note?: string | null;
34
+ };
35
+ Relationships: [];
36
+ };
37
+ Agent: {
38
+ Row: {
39
+ id: number;
40
+ agentName: string;
41
+ createdAt: string;
42
+ updatedAt: string | null;
43
+ agentHash: string;
44
+ agentSource: string;
45
+ agentProfile: Json;
46
+ promptbookEngineVersion: string;
47
+ usage: Json | null;
48
+ preparedModelRequirements: Json | null;
49
+ preparedExternals: Json | null;
50
+ };
51
+ Insert: {
52
+ id?: number;
53
+ agentName: string;
54
+ createdAt: string;
55
+ updatedAt?: string | null;
56
+ agentHash: string;
57
+ agentSource: string;
58
+ agentProfile: Json;
59
+ promptbookEngineVersion: string;
60
+ usage?: Json | null;
61
+ preparedModelRequirements?: Json | null;
62
+ preparedExternals?: Json | null;
63
+ };
64
+ Update: {
65
+ id?: number;
66
+ agentName?: string;
67
+ createdAt?: string;
68
+ updatedAt?: string | null;
69
+ agentHash?: string;
70
+ agentSource?: string;
71
+ agentProfile?: Json;
72
+ promptbookEngineVersion?: string;
73
+ usage?: Json | null;
74
+ preparedModelRequirements?: Json | null;
75
+ preparedExternals?: Json | null;
76
+ };
77
+ Relationships: [];
78
+ };
79
+ AgentHistory: {
80
+ Row: {
81
+ id: number;
82
+ createdAt: string;
83
+ agentName: string;
84
+ agentHash: string;
85
+ previousAgentHash: string | null;
86
+ agentSource: string;
87
+ promptbookEngineVersion: string;
88
+ };
89
+ Insert: {
90
+ id?: number;
91
+ createdAt: string;
92
+ agentName: string;
93
+ agentHash: string;
94
+ previousAgentHash?: string | null;
95
+ agentSource: string;
96
+ promptbookEngineVersion: string;
97
+ };
98
+ Update: {
99
+ id?: number;
100
+ createdAt?: string;
101
+ agentName?: string;
102
+ agentHash?: string;
103
+ previousAgentHash?: string | null;
104
+ agentSource?: string;
105
+ promptbookEngineVersion?: string;
106
+ };
107
+ Relationships: [];
108
+ };
109
+ ChatHistory: {
110
+ Row: {
111
+ id: number;
112
+ createdAt: string;
113
+ messageHash: string;
114
+ previousMessageHash: string | null;
115
+ agentName: string;
116
+ agentHash: string;
117
+ message: Json;
118
+ promptbookEngineVersion: string | null;
119
+ url: string | null;
120
+ ip: string | null;
121
+ userAgent: string | null;
122
+ language: string | null;
123
+ platform: string | null;
124
+ };
125
+ Insert: {
126
+ id?: number;
127
+ createdAt: string;
128
+ messageHash: string;
129
+ previousMessageHash?: string | null;
130
+ agentName: string;
131
+ agentHash: string;
132
+ message: Json;
133
+ promptbookEngineVersion?: string | null;
134
+ url?: string | null;
135
+ ip?: string | null;
136
+ userAgent?: string | null;
137
+ language?: string | null;
138
+ platform?: string | null;
139
+ };
140
+ Update: {
141
+ id?: number;
142
+ createdAt?: string;
143
+ messageHash?: string;
144
+ previousMessageHash?: string | null;
145
+ agentName?: string;
146
+ agentHash?: string;
147
+ message?: Json;
148
+ promptbookEngineVersion?: string | null;
149
+ url?: string | null;
150
+ ip?: string | null;
151
+ userAgent?: string | null;
152
+ language?: string | null;
153
+ platform?: string | null;
154
+ };
155
+ Relationships: [];
156
+ };
157
+ ChatFeedback: {
158
+ Row: {
159
+ id: number;
160
+ createdAt: string;
161
+ agentName: string;
162
+ agentHash: string;
163
+ rating: string | null;
164
+ textRating: string | null;
165
+ chatThread: string | null;
166
+ userNote: string | null;
167
+ expectedAnswer: string | null;
168
+ promptbookEngineVersion: string | null;
169
+ url: string | null;
170
+ ip: string | null;
171
+ userAgent: string | null;
172
+ language: string | null;
173
+ platform: string | null;
174
+ };
175
+ Insert: {
176
+ id?: number;
177
+ createdAt: string;
178
+ agentName: string;
179
+ agentHash: string;
180
+ rating?: string | null;
181
+ textRating?: string | null;
182
+ chatThread?: string | null;
183
+ userNote?: string | null;
184
+ expectedAnswer?: string | null;
185
+ promptbookEngineVersion?: string | null;
186
+ url?: string | null;
187
+ ip?: string | null;
188
+ userAgent?: string | null;
189
+ language?: string | null;
190
+ platform?: string | null;
191
+ };
192
+ Update: {
193
+ id?: number;
194
+ createdAt?: string;
195
+ agentName?: string;
196
+ agentHash?: string;
197
+ rating?: string | null;
198
+ textRating?: string | null;
199
+ chatThread?: string | null;
200
+ userNote?: string | null;
201
+ expectedAnswer?: string | null;
202
+ promptbookEngineVersion?: string | null;
203
+ url?: string | null;
204
+ ip?: string | null;
205
+ userAgent?: string | null;
206
+ language?: string | null;
207
+ platform?: string | null;
208
+ };
209
+ Relationships: [];
210
+ };
211
+ };
212
+ Views: Record<string, never>;
213
+ Functions: Record<string, never>;
214
+ Enums: Record<string, never>;
215
+ CompositeTypes: Record<string, never>;
216
+ };
217
+ };
@@ -2,11 +2,11 @@
2
2
 
3
3
  import { AgentCollectionInSupabase } from '@promptbook-local/core';
4
4
  import { AgentCollection } from '@promptbook-local/types';
5
- import { getSupabaseForServer } from '../supabase/getSupabaseForServer';
5
+ import { $provideSupabaseForServer } from '../database/$provideSupabaseForServer';
6
6
 
7
7
  /**
8
8
  * Cache of provided agent collection
9
- *
9
+ *
10
10
  * @private internal cache for `$provideAgentCollectionForServer`
11
11
  */
12
12
  let agentCollection: null | AgentCollection = null;
@@ -40,7 +40,7 @@ export async function $provideAgentCollectionForServer(): Promise<AgentCollectio
40
40
  });
41
41
  */
42
42
 
43
- const supabase = getSupabaseForServer();
43
+ const supabase = $provideSupabaseForServer();
44
44
 
45
45
  agentCollection = new AgentCollectionInSupabase(supabase, {
46
46
  isVerbose,
@@ -26,7 +26,7 @@ export async function $provideOpenAiAssistantExecutionToolsForServer(): Promise<
26
26
 
27
27
  executionTools = new OpenAiAssistantExecutionTools({
28
28
  apiKey: process.env.OPENAI_API_KEY,
29
- assistantId: '!!!! null',
29
+ assistantId: 'abstract_assistant', // <- TODO: !!!! In `OpenAiAssistantExecutionTools` Allow to create abstract assistants with `isCreatingNewAssistantsAllowed`
30
30
  isCreatingNewAssistantsAllowed: true,
31
31
  isVerbose,
32
32
  });
@@ -1,7 +1,7 @@
1
- import { titleToName } from '../../../../../../src/utils/normalization/titleToName';
2
1
  import hexEncoder from 'crypto-js/enc-hex';
3
2
  import sha256 from 'crypto-js/sha256';
4
3
  import type { string_uri } from '../../../../../../src/types/typeAliases';
4
+ import { titleToName } from '../../../../../../src/utils/normalization/titleToName';
5
5
  import { nameToSubfolderPath } from './nameToSubfolderPath';
6
6
 
7
7
  /**
@@ -9,6 +9,7 @@ import { nameToSubfolderPath } from './nameToSubfolderPath';
9
9
  */
10
10
  export function getUserFileCdnKey(file: Buffer, originalFilename: string): string_uri {
11
11
  const hash = sha256(hexEncoder.parse(file.toString('hex'))).toString(/* hex */);
12
+ // <- TODO: [🥬] Encapsulate sha256 to some private utility function
12
13
 
13
14
  const originalFilenameParts = originalFilename.split('.');
14
15
  const extension = originalFilenameParts.pop();