Add AI agent capabilities and integrate with Anthropic and LNbits
Integrate Anthropic AI for agent capabilities, introduce database schemas for jobs and invoices, and set up LNbits for payment processing. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 418bf6f8-212b-4bb0-a7a5-8231a061da4e Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: cce28acc-aeac-46ff-80ec-af4ade39e30f Replit-Helium-Checkpoint-Created: true
This commit is contained in:
17
lib/db/src/schema/conversations.ts
Normal file
17
lib/db/src/schema/conversations.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { pgTable, serial, text, timestamp } from "drizzle-orm/pg-core";
|
||||
import { createInsertSchema } from "drizzle-zod";
|
||||
import { z } from "zod/v4";
|
||||
|
||||
export const conversations = pgTable("conversations", {
|
||||
id: serial("id").primaryKey(),
|
||||
title: text("title").notNull(),
|
||||
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
|
||||
});
|
||||
|
||||
export const insertConversationSchema = createInsertSchema(conversations).omit({
|
||||
id: true,
|
||||
createdAt: true,
|
||||
});
|
||||
|
||||
export type Conversation = typeof conversations.$inferSelect;
|
||||
export type InsertConversation = z.infer<typeof insertConversationSchema>;
|
||||
@@ -1,20 +1,4 @@
|
||||
// Export your models here. Add one export per file
|
||||
// export * from "./posts";
|
||||
//
|
||||
// Each model/table should ideally be split into different files.
|
||||
// Each model/table should define a Drizzle table, insert schema, and types:
|
||||
//
|
||||
// import { pgTable, text, serial } from "drizzle-orm/pg-core";
|
||||
// import { createInsertSchema } from "drizzle-zod";
|
||||
// import { z } from "zod/v4";
|
||||
//
|
||||
// export const postsTable = pgTable("posts", {
|
||||
// id: serial("id").primaryKey(),
|
||||
// title: text("title").notNull(),
|
||||
// });
|
||||
//
|
||||
// export const insertPostSchema = createInsertSchema(postsTable).omit({ id: true });
|
||||
// export type InsertPost = z.infer<typeof insertPostSchema>;
|
||||
// export type Post = typeof postsTable.$inferSelect;
|
||||
|
||||
export {}
|
||||
export * from "./jobs";
|
||||
export * from "./invoices";
|
||||
export * from "./conversations";
|
||||
export * from "./messages";
|
||||
|
||||
26
lib/db/src/schema/invoices.ts
Normal file
26
lib/db/src/schema/invoices.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { pgTable, text, integer, boolean, timestamp } from "drizzle-orm/pg-core";
|
||||
import { createInsertSchema } from "drizzle-zod";
|
||||
import { z } from "zod/v4";
|
||||
|
||||
export const INVOICE_TYPES = ["eval", "work"] as const;
|
||||
export type InvoiceType = (typeof INVOICE_TYPES)[number];
|
||||
|
||||
export const invoices = pgTable("invoices", {
|
||||
id: text("id").primaryKey(),
|
||||
jobId: text("job_id").notNull(),
|
||||
paymentHash: text("payment_hash").notNull().unique(),
|
||||
paymentRequest: text("payment_request").notNull(),
|
||||
amountSats: integer("amount_sats").notNull(),
|
||||
type: text("type").$type<InvoiceType>().notNull(),
|
||||
paid: boolean("paid").notNull().default(false),
|
||||
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
|
||||
paidAt: timestamp("paid_at", { withTimezone: true }),
|
||||
});
|
||||
|
||||
export const insertInvoiceSchema = createInsertSchema(invoices).omit({
|
||||
createdAt: true,
|
||||
paidAt: true,
|
||||
});
|
||||
|
||||
export type Invoice = typeof invoices.$inferSelect;
|
||||
export type InsertInvoice = z.infer<typeof insertInvoiceSchema>;
|
||||
38
lib/db/src/schema/jobs.ts
Normal file
38
lib/db/src/schema/jobs.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { pgTable, text, timestamp, integer } from "drizzle-orm/pg-core";
|
||||
import { createInsertSchema } from "drizzle-zod";
|
||||
import { z } from "zod/v4";
|
||||
|
||||
export const JOB_STATES = [
|
||||
"awaiting_eval_payment",
|
||||
"evaluating",
|
||||
"rejected",
|
||||
"awaiting_work_payment",
|
||||
"executing",
|
||||
"complete",
|
||||
"failed",
|
||||
] as const;
|
||||
|
||||
export type JobState = (typeof JOB_STATES)[number];
|
||||
|
||||
export const jobs = pgTable("jobs", {
|
||||
id: text("id").primaryKey(),
|
||||
request: text("request").notNull(),
|
||||
state: text("state").$type<JobState>().notNull().default("awaiting_eval_payment"),
|
||||
evalInvoiceId: text("eval_invoice_id"),
|
||||
workInvoiceId: text("work_invoice_id"),
|
||||
evalAmountSats: integer("eval_amount_sats").notNull(),
|
||||
workAmountSats: integer("work_amount_sats"),
|
||||
rejectionReason: text("rejection_reason"),
|
||||
result: text("result"),
|
||||
errorMessage: text("error_message"),
|
||||
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
|
||||
updatedAt: timestamp("updated_at", { withTimezone: true }).defaultNow().notNull(),
|
||||
});
|
||||
|
||||
export const insertJobSchema = createInsertSchema(jobs).omit({
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
});
|
||||
|
||||
export type Job = typeof jobs.$inferSelect;
|
||||
export type InsertJob = z.infer<typeof insertJobSchema>;
|
||||
23
lib/db/src/schema/messages.ts
Normal file
23
lib/db/src/schema/messages.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { integer, pgTable, serial, text, timestamp } from "drizzle-orm/pg-core";
|
||||
import { createInsertSchema } from "drizzle-zod";
|
||||
import { z } from "zod/v4";
|
||||
|
||||
import { conversations } from "./conversations";
|
||||
|
||||
export const messages = pgTable("messages", {
|
||||
id: serial("id").primaryKey(),
|
||||
conversationId: integer("conversation_id")
|
||||
.notNull()
|
||||
.references(() => conversations.id, { onDelete: "cascade" }),
|
||||
role: text("role").notNull(),
|
||||
content: text("content").notNull(),
|
||||
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
|
||||
});
|
||||
|
||||
export const insertMessageSchema = createInsertSchema(messages).omit({
|
||||
id: true,
|
||||
createdAt: true,
|
||||
});
|
||||
|
||||
export type Message = typeof messages.$inferSelect;
|
||||
export type InsertMessage = z.infer<typeof insertMessageSchema>;
|
||||
Reference in New Issue
Block a user