curriculum-api 0.1.0 → 0.2.0
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/{admin-U7LVEF3Y.js → admin-LLA7YFBM.js} +1357 -438
- package/dist/chunk-2BZOKT6H.js +877 -0
- package/dist/{chunk-RL62MWPL.js → chunk-IM5Z67ZH.js} +79 -40
- package/dist/cli.js +19 -5
- package/dist/index.d.ts +20 -2
- package/dist/index.js +1129 -131
- package/drizzle/0003_zippy_frank_castle.sql +1 -0
- package/drizzle/0004_woozy_bloodaxe.sql +2 -0
- package/drizzle/0005_little_kronos.sql +8 -0
- package/drizzle/0006_drop_master_cv.sql +3 -0
- package/drizzle/0007_graceful_karma.sql +5 -0
- package/drizzle/meta/0003_snapshot.json +556 -0
- package/drizzle/meta/0004_snapshot.json +549 -0
- package/drizzle/meta/0005_snapshot.json +595 -0
- package/drizzle/meta/0006_snapshot.json +589 -0
- package/drizzle/meta/0007_snapshot.json +621 -0
- package/drizzle/meta/_journal.json +35 -0
- package/package.json +10 -3
- package/dist/chunk-N6XNQ5R5.js +0 -463
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
// src/db/migrate.ts
|
|
2
2
|
import { existsSync } from "fs";
|
|
3
3
|
import { fileURLToPath } from "url";
|
|
4
|
-
import {
|
|
5
|
-
import { drizzle as drizzle2 } from "drizzle-orm/neon-http";
|
|
6
|
-
import { migrate as runMigrations } from "drizzle-orm/neon-http/migrator";
|
|
4
|
+
import { migrate as runMigrations } from "drizzle-orm/node-postgres/migrator";
|
|
7
5
|
|
|
8
6
|
// src/db/client.ts
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
neonConfig.fetchEndpoint = fetchEndpointFor;
|
|
7
|
+
import { drizzle } from "drizzle-orm/node-postgres";
|
|
8
|
+
import { Pool } from "pg";
|
|
9
|
+
var POOL_MAX = 5;
|
|
10
|
+
var CONNECT_TIMEOUT_MS = 5e3;
|
|
11
|
+
var QUERY_TIMEOUT_MS = 3e4;
|
|
16
12
|
function createDb(url) {
|
|
17
|
-
|
|
13
|
+
const pool = new Pool({
|
|
14
|
+
connectionString: url,
|
|
15
|
+
max: POOL_MAX,
|
|
16
|
+
connectionTimeoutMillis: CONNECT_TIMEOUT_MS,
|
|
17
|
+
query_timeout: QUERY_TIMEOUT_MS
|
|
18
|
+
});
|
|
19
|
+
pool.on("error", (error) => console.error("postgres pool error:", error.message));
|
|
20
|
+
return drizzle(pool, { casing: "snake_case" });
|
|
21
|
+
}
|
|
22
|
+
async function closeDb(db) {
|
|
23
|
+
await db.$client.end();
|
|
18
24
|
}
|
|
19
25
|
|
|
20
26
|
// src/db/migrate.ts
|
|
@@ -26,12 +32,16 @@ function migrationsFolder() {
|
|
|
26
32
|
throw new Error("drizzle migrations folder not found");
|
|
27
33
|
}
|
|
28
34
|
async function migrate(databaseUrl) {
|
|
29
|
-
const db =
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
const db = createDb(databaseUrl);
|
|
36
|
+
try {
|
|
37
|
+
await runMigrations(db, {
|
|
38
|
+
migrationsFolder: migrationsFolder(),
|
|
39
|
+
migrationsSchema: "curriculum_api",
|
|
40
|
+
migrationsTable: "__drizzle_migrations"
|
|
41
|
+
});
|
|
42
|
+
} finally {
|
|
43
|
+
await closeDb(db);
|
|
44
|
+
}
|
|
35
45
|
}
|
|
36
46
|
|
|
37
47
|
// src/llm/default-prompts.ts
|
|
@@ -61,6 +71,7 @@ ${SHARED_RULES}
|
|
|
61
71
|
- Never copy the job description's phrasing ("strong experience with", "hands-on..."); it states what the employer wants, not what the candidate did.
|
|
62
72
|
- Never introduce a skill, tool, employer, job title, date, certification or metric that is absent from the CV, even if the job description asks for it. A requirement the CV does not evidence stays out of the resume.
|
|
63
73
|
- Keep every role of the CV with its employer, title and dates. Never drop or merge a role; to save space, compress its bullets.
|
|
74
|
+
- Keep every education, certification, course, skill group and language of the CV, ordered by relevance to the job (the ones the job asks for first). Only projects, publications and honours may be left out.
|
|
64
75
|
- Output markdown only: no preamble, closing remarks, tables, emoji, or meta-commentary about your reasoning or missing information.
|
|
65
76
|
- Never emit control tokens such as "</s>", "<eos>" or "<|endoftext|>".
|
|
66
77
|
- Leave out contact details; they are added separately when the resume is printed.`;
|
|
@@ -73,6 +84,7 @@ import {
|
|
|
73
84
|
date,
|
|
74
85
|
index,
|
|
75
86
|
integer,
|
|
87
|
+
jsonb,
|
|
76
88
|
pgSchema,
|
|
77
89
|
primaryKey,
|
|
78
90
|
text,
|
|
@@ -86,7 +98,7 @@ var profile = curriculum.table(
|
|
|
86
98
|
id: integer().primaryKey().default(1),
|
|
87
99
|
fullName: text().notNull(),
|
|
88
100
|
headline: text().notNull(),
|
|
89
|
-
|
|
101
|
+
summary: text().notNull().default(""),
|
|
90
102
|
publicSystemPrompt: text().notNull(),
|
|
91
103
|
recruiterSystemPrompt: text().notNull(),
|
|
92
104
|
tailorSystemPrompt: text().notNull(),
|
|
@@ -94,6 +106,15 @@ var profile = curriculum.table(
|
|
|
94
106
|
},
|
|
95
107
|
(t) => [check("profile_singleton", sql`${t.id} = 1`)]
|
|
96
108
|
);
|
|
109
|
+
var careerLibrary = curriculum.table(
|
|
110
|
+
"career_library",
|
|
111
|
+
{
|
|
112
|
+
id: integer().primaryKey().default(1),
|
|
113
|
+
document: jsonb().notNull().default(sql`'{"version":1,"items":[]}'::jsonb`),
|
|
114
|
+
updatedAt: timestamp({ withTimezone: true }).notNull().defaultNow()
|
|
115
|
+
},
|
|
116
|
+
(t) => [check("career_library_singleton", sql`${t.id} = 1`)]
|
|
117
|
+
);
|
|
97
118
|
var settings = curriculum.table("settings", {
|
|
98
119
|
key: text().primaryKey(),
|
|
99
120
|
value: text().notNull()
|
|
@@ -112,18 +133,29 @@ var personalInfo = curriculum.table(
|
|
|
112
133
|
check("personal_info_visibility", sql`${t.visibility} in ('public', 'recruiter', 'print')`)
|
|
113
134
|
]
|
|
114
135
|
);
|
|
115
|
-
var tailoredResumes = curriculum.table(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
136
|
+
var tailoredResumes = curriculum.table(
|
|
137
|
+
"tailored_resumes",
|
|
138
|
+
{
|
|
139
|
+
id: uuid().primaryKey().default(sql`gen_random_uuid()`),
|
|
140
|
+
title: text().notNull(),
|
|
141
|
+
company: text(),
|
|
142
|
+
jobDescription: text().notNull(),
|
|
143
|
+
customInstructions: text().notNull().default(""),
|
|
144
|
+
headerFields: text().array(),
|
|
145
|
+
model: text(),
|
|
146
|
+
/** The Resume Document; NULL until the first successful generation. Parsed by the service. */
|
|
147
|
+
structured: jsonb(),
|
|
148
|
+
createdAt: timestamp({ withTimezone: true }).notNull().defaultNow(),
|
|
149
|
+
updatedAt: timestamp({ withTimezone: true }).notNull().defaultNow(),
|
|
150
|
+
/** Fit of the Career Library to the job, 0-100; NULL until the first successful generation. */
|
|
151
|
+
score: integer(),
|
|
152
|
+
scoreRationale: text().notNull().default(""),
|
|
153
|
+
missingSkills: text().array().notNull().default(sql`'{}'::text[]`),
|
|
154
|
+
/** Array of `{ what, reason }`, parsed by the service. */
|
|
155
|
+
omissions: jsonb().notNull().default(sql`'[]'::jsonb`)
|
|
156
|
+
},
|
|
157
|
+
(t) => [check("tailored_resumes_score", sql`${t.score} between 0 and 100`)]
|
|
158
|
+
);
|
|
127
159
|
var recruiterChats = curriculum.table(
|
|
128
160
|
"recruiter_chats",
|
|
129
161
|
{
|
|
@@ -179,21 +211,28 @@ var adminLoginAttempts = curriculum.table(
|
|
|
179
211
|
// src/db/seed.ts
|
|
180
212
|
async function seed(databaseUrl) {
|
|
181
213
|
const db = createDb(databaseUrl);
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
214
|
+
try {
|
|
215
|
+
const inserted = await db.insert(profile).values({
|
|
216
|
+
id: 1,
|
|
217
|
+
fullName: "",
|
|
218
|
+
headline: "",
|
|
219
|
+
summary: "",
|
|
220
|
+
publicSystemPrompt: DEFAULT_PUBLIC_SYSTEM_PROMPT,
|
|
221
|
+
recruiterSystemPrompt: DEFAULT_RECRUITER_SYSTEM_PROMPT,
|
|
222
|
+
tailorSystemPrompt: DEFAULT_TAILOR_SYSTEM_PROMPT
|
|
223
|
+
}).onConflictDoNothing({ target: profile.id }).returning({ id: profile.id });
|
|
224
|
+
await db.insert(careerLibrary).values({ id: 1 }).onConflictDoNothing({ target: careerLibrary.id });
|
|
225
|
+
return inserted.length > 0 ? "created" : "exists";
|
|
226
|
+
} finally {
|
|
227
|
+
await closeDb(db);
|
|
228
|
+
}
|
|
192
229
|
}
|
|
193
230
|
|
|
194
231
|
export {
|
|
195
232
|
createDb,
|
|
233
|
+
closeDb,
|
|
196
234
|
profile,
|
|
235
|
+
careerLibrary,
|
|
197
236
|
settings,
|
|
198
237
|
personalInfo,
|
|
199
238
|
tailoredResumes,
|
package/dist/cli.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
adminLoginAttempts,
|
|
4
|
+
closeDb,
|
|
4
5
|
createDb,
|
|
5
6
|
migrate,
|
|
6
7
|
publicUsage,
|
|
7
8
|
seed
|
|
8
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-IM5Z67ZH.js";
|
|
9
10
|
|
|
10
11
|
// src/cli.ts
|
|
11
12
|
import { realpathSync } from "fs";
|
|
@@ -16,9 +17,13 @@ import bcrypt from "bcryptjs";
|
|
|
16
17
|
import { lt, sql } from "drizzle-orm";
|
|
17
18
|
async function cleanup(databaseUrl, days = 30) {
|
|
18
19
|
const db = createDb(databaseUrl);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
try {
|
|
21
|
+
const usage = await db.delete(publicUsage).where(lt(publicUsage.day, sql`(current_date - ${days}::int)`)).returning({ ipHash: publicUsage.ipHash });
|
|
22
|
+
const attempts = await db.delete(adminLoginAttempts).where(lt(adminLoginAttempts.windowStart, sql`(now() - make_interval(days => ${days}::int))`)).returning({ ipHash: adminLoginAttempts.ipHash });
|
|
23
|
+
return { publicUsage: usage.length, loginAttempts: attempts.length };
|
|
24
|
+
} finally {
|
|
25
|
+
await closeDb(db);
|
|
26
|
+
}
|
|
22
27
|
}
|
|
23
28
|
|
|
24
29
|
// src/cli.ts
|
|
@@ -30,6 +35,14 @@ Commands:
|
|
|
30
35
|
hash-password read a password from stdin and print its bcrypt hash
|
|
31
36
|
cleanup delete public_usage and admin_login_attempts rows older than 30 days (needs DATABASE_URL)`;
|
|
32
37
|
var BCRYPT_COST = 12;
|
|
38
|
+
function hostOf(url) {
|
|
39
|
+
try {
|
|
40
|
+
const { host, pathname } = new URL(url);
|
|
41
|
+
return `${host}${pathname}`;
|
|
42
|
+
} catch {
|
|
43
|
+
return "(unparseable url)";
|
|
44
|
+
}
|
|
45
|
+
}
|
|
33
46
|
async function runCli(argv, io) {
|
|
34
47
|
const [command] = argv;
|
|
35
48
|
const databaseUrl = (preferred) => {
|
|
@@ -42,7 +55,7 @@ async function runCli(argv, io) {
|
|
|
42
55
|
const url = databaseUrl(io.env.DATABASE_URL_UNPOOLED);
|
|
43
56
|
if (!url) return 1;
|
|
44
57
|
await migrate(url);
|
|
45
|
-
io.out(
|
|
58
|
+
io.out(`migrations applied to ${hostOf(url)}`);
|
|
46
59
|
return 0;
|
|
47
60
|
}
|
|
48
61
|
case "seed": {
|
|
@@ -102,5 +115,6 @@ if (isMain()) {
|
|
|
102
115
|
);
|
|
103
116
|
}
|
|
104
117
|
export {
|
|
118
|
+
hostOf,
|
|
105
119
|
runCli
|
|
106
120
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -21,8 +21,17 @@ interface CurriculumApiConfig {
|
|
|
21
21
|
public?: string;
|
|
22
22
|
tailor?: string;
|
|
23
23
|
recruiter?: string;
|
|
24
|
+
import?: string;
|
|
24
25
|
};
|
|
25
26
|
limits?: Partial<Limits>;
|
|
27
|
+
/** Sampling temperature per area, 0..2; the settings table overrides them. */
|
|
28
|
+
temperatures?: Partial<Temperatures>;
|
|
29
|
+
}
|
|
30
|
+
interface Temperatures {
|
|
31
|
+
public: number;
|
|
32
|
+
tailor: number;
|
|
33
|
+
recruiter: number;
|
|
34
|
+
import: number;
|
|
26
35
|
}
|
|
27
36
|
interface Limits {
|
|
28
37
|
publicQuestionsPerIpPerDay: number;
|
|
@@ -47,16 +56,19 @@ interface ResolvedConfig {
|
|
|
47
56
|
public?: string;
|
|
48
57
|
tailor?: string;
|
|
49
58
|
recruiter?: string;
|
|
59
|
+
import?: string;
|
|
50
60
|
};
|
|
51
61
|
limits: Limits;
|
|
62
|
+
temperatures: Temperatures;
|
|
52
63
|
}
|
|
53
64
|
|
|
54
65
|
/** Validates the config and builds the app. Performs no I/O. */
|
|
55
66
|
declare function createApp(config: CurriculumApiConfig): Hono;
|
|
56
67
|
|
|
68
|
+
/** Pass the unpooled (direct) connection string when there is one: DDL does not belong behind PgBouncer. */
|
|
57
69
|
declare function migrate(databaseUrl: string): Promise<void>;
|
|
58
70
|
|
|
59
|
-
/** Creates the profile row
|
|
71
|
+
/** Creates the profile row and the empty career library with the default prompts; leaves an existing row alone. */
|
|
60
72
|
declare function seed(databaseUrl: string): Promise<"created" | "exists">;
|
|
61
73
|
|
|
62
74
|
/** Domain errors carry their HTTP status so the API and admin handlers share one mapping. */
|
|
@@ -128,6 +140,12 @@ declare class DecryptionError extends DomainError {
|
|
|
128
140
|
readonly status = 500;
|
|
129
141
|
constructor(message?: string);
|
|
130
142
|
}
|
|
143
|
+
/** The model answered, but its reply did not parse against the requested schema. */
|
|
144
|
+
declare class LlmOutputInvalidError extends DomainError {
|
|
145
|
+
readonly code = "llm_output_invalid";
|
|
146
|
+
readonly status = 502;
|
|
147
|
+
constructor(message?: string);
|
|
148
|
+
}
|
|
131
149
|
|
|
132
|
-
export { CaptchaFailedError, ChatExpiredError, ChatRevokedError, ConfigError, DecryptionError, DomainError, ForbiddenError, LimitReachedError, LlmUnavailableError, NotFoundError, PiiLeakError, UnauthorizedError, ValidationError, createApp, migrate, seed };
|
|
150
|
+
export { CaptchaFailedError, ChatExpiredError, ChatRevokedError, ConfigError, DecryptionError, DomainError, ForbiddenError, LimitReachedError, LlmOutputInvalidError, LlmUnavailableError, NotFoundError, PiiLeakError, UnauthorizedError, ValidationError, createApp, migrate, seed };
|
|
133
151
|
export type { CurriculumApiConfig, Limits, ResolvedConfig };
|