Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/browser-scraper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"type": "module",
"scripts": {
"dev": "wrangler dev",
"dev": "wrangler dev --port 8788 --inspector-port 9230",
"deploy": "wrangler deploy",
"typecheck": "tsc",
"lint": "eslint .",
Expand Down
8 changes: 8 additions & 0 deletions apps/operator/migrations/0006_unknown_the_santerians.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CREATE TABLE `pending_conversations` (
`chat_id` integer PRIMARY KEY NOT NULL,
`messages_json` text NOT NULL,
`pending_tool_call_id` text NOT NULL,
`options_json` text NOT NULL,
`token` text NOT NULL,
`expires_at` text NOT NULL
);
283 changes: 283 additions & 0 deletions apps/operator/migrations/meta/0006_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,283 @@
{
"version": "6",
"dialect": "sqlite",
"id": "8e57a58d-9d91-45b3-8f6c-5defe7f366c0",
"prevId": "b69943e8-9429-48a9-b896-82adc44bd6d7",
"tables": {
"pending_actions": {
"name": "pending_actions",
"columns": {
"chat_id": {
"name": "chat_id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"action_type": {
"name": "action_type",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"payload": {
"name": "payload",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"expires_at": {
"name": "expires_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"token": {
"name": "token",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"pending_conversations": {
"name": "pending_conversations",
"columns": {
"chat_id": {
"name": "chat_id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"messages_json": {
"name": "messages_json",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"pending_tool_call_id": {
"name": "pending_tool_call_id",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"options_json": {
"name": "options_json",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"token": {
"name": "token",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"expires_at": {
"name": "expires_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"schedules": {
"name": "schedules",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"chat_id": {
"name": "chat_id",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"schedule_type": {
"name": "schedule_type",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"hour": {
"name": "hour",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"minute": {
"name": "minute",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": 0
},
"day_of_week": {
"name": "day_of_week",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"day_of_month": {
"name": "day_of_month",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"timezone": {
"name": "timezone",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'UTC'"
},
"fixed_message": {
"name": "fixed_message",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"message_prompt": {
"name": "message_prompt",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"source_url": {
"name": "source_url",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"keywords": {
"name": "keywords",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"state_json": {
"name": "state_json",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"active": {
"name": "active",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": true
},
"use_browser": {
"name": "use_browser",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": false
},
"next_run_at": {
"name": "next_run_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"claimed_at": {
"name": "claimed_at",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"retry_count": {
"name": "retry_count",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": 0
},
"created_at": {
"name": "created_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {
"idx_schedules_next_run": {
"name": "idx_schedules_next_run",
"columns": ["active", "next_run_at"],
"isUnique": false
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
}
},
"views": {},
"enums": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
},
"internal": {
"indexes": {}
}
}
7 changes: 7 additions & 0 deletions apps/operator/migrations/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@
"when": 1777491867371,
"tag": "0005_nervous_scorpion",
"breakpoints": true
},
{
"idx": 6,
"version": "6",
"when": 1777705134403,
"tag": "0006_unknown_the_santerians",
"breakpoints": true
}
]
}
11 changes: 10 additions & 1 deletion apps/operator/src/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,13 @@ const pendingActions = sqliteTable("pending_actions", {
token: text("token"),
});

export { pendingActions, schedules };
const pendingConversations = sqliteTable("pending_conversations", {
chatId: int("chat_id").primaryKey(),
messagesJson: text("messages_json").notNull(),
pendingToolCallId: text("pending_tool_call_id").notNull(),
optionsJson: text("options_json").notNull(),
token: text("token").notNull(),
expiresAt: text("expires_at").notNull(),
});

export { pendingActions, pendingConversations, schedules };
47 changes: 47 additions & 0 deletions apps/operator/src/modules/telegram/callback-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
type ParsedCallback =
| { action: "confirm" | "cancel"; token: string }
| { action: "answer"; token: string; optionIndex: number };

const parseCallbackData = (
data: string | undefined
): ParsedCallback | undefined => {
if (!data) {
return undefined;
}
if (data.startsWith("q:")) {
const rest = data.slice(2);
const colon = rest.indexOf(":");
if (colon === -1) {
return undefined;
}
const token = rest.slice(0, colon);
const indexStr = rest.slice(colon + 1);
if (!token || !/^\d+$/.test(indexStr)) {
return undefined;
}
return {
action: "answer",
token,
optionIndex: Number.parseInt(indexStr, 10),
};
}
const colon = data.indexOf(":");
if (colon === -1) {
return undefined;
}
const prefix = data.slice(0, colon);
const token = data.slice(colon + 1);
if (!token) {
return undefined;
}
if (prefix === "c") {
return { action: "confirm", token };
}
if (prefix === "x") {
return { action: "cancel", token };
}
return undefined;
};

export { parseCallbackData };
export type { ParsedCallback };
Loading
Loading