@ykurilov/agent-chat-background 0.110.0 → 0.111.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.
@@ -0,0 +1,241 @@
1
+ {
2
+ "id": "97b6b40b-41ff-4bd1-9a54-e159a1071f78",
3
+ "prevId": "91b4552b-82f6-4ece-a401-81d8c9873358",
4
+ "version": "7",
5
+ "dialect": "postgresql",
6
+ "tables": {
7
+ "agent_chat.background_tasks": {
8
+ "name": "background_tasks",
9
+ "schema": "agent_chat",
10
+ "columns": {
11
+ "id": {
12
+ "name": "id",
13
+ "type": "text",
14
+ "primaryKey": true,
15
+ "notNull": true
16
+ },
17
+ "owner_id": {
18
+ "name": "owner_id",
19
+ "type": "text",
20
+ "primaryKey": false,
21
+ "notNull": true
22
+ },
23
+ "chat_id": {
24
+ "name": "chat_id",
25
+ "type": "text",
26
+ "primaryKey": false,
27
+ "notNull": true
28
+ },
29
+ "message_id": {
30
+ "name": "message_id",
31
+ "type": "text",
32
+ "primaryKey": false,
33
+ "notNull": true
34
+ },
35
+ "tool_call_id": {
36
+ "name": "tool_call_id",
37
+ "type": "text",
38
+ "primaryKey": false,
39
+ "notNull": true
40
+ },
41
+ "channel": {
42
+ "name": "channel",
43
+ "type": "text",
44
+ "primaryKey": false,
45
+ "notNull": true
46
+ },
47
+ "kind": {
48
+ "name": "kind",
49
+ "type": "text",
50
+ "primaryKey": false,
51
+ "notNull": true
52
+ },
53
+ "name": {
54
+ "name": "name",
55
+ "type": "text",
56
+ "primaryKey": false,
57
+ "notNull": true
58
+ },
59
+ "input": {
60
+ "name": "input",
61
+ "type": "jsonb",
62
+ "primaryKey": false,
63
+ "notNull": false
64
+ },
65
+ "title": {
66
+ "name": "title",
67
+ "type": "text",
68
+ "primaryKey": false,
69
+ "notNull": true
70
+ },
71
+ "started_by": {
72
+ "name": "started_by",
73
+ "type": "text",
74
+ "primaryKey": false,
75
+ "notNull": false
76
+ },
77
+ "status": {
78
+ "name": "status",
79
+ "type": "text",
80
+ "primaryKey": false,
81
+ "notNull": true
82
+ },
83
+ "helper_messages": {
84
+ "name": "helper_messages",
85
+ "type": "jsonb",
86
+ "primaryKey": false,
87
+ "notNull": false
88
+ },
89
+ "progress": {
90
+ "name": "progress",
91
+ "type": "jsonb",
92
+ "primaryKey": false,
93
+ "notNull": false
94
+ },
95
+ "result": {
96
+ "name": "result",
97
+ "type": "jsonb",
98
+ "primaryKey": false,
99
+ "notNull": false
100
+ },
101
+ "error": {
102
+ "name": "error",
103
+ "type": "text",
104
+ "primaryKey": false,
105
+ "notNull": false
106
+ },
107
+ "lease_owner": {
108
+ "name": "lease_owner",
109
+ "type": "text",
110
+ "primaryKey": false,
111
+ "notNull": false
112
+ },
113
+ "lease_until": {
114
+ "name": "lease_until",
115
+ "type": "timestamp (3) with time zone",
116
+ "primaryKey": false,
117
+ "notNull": false
118
+ },
119
+ "attempt": {
120
+ "name": "attempt",
121
+ "type": "integer",
122
+ "primaryKey": false,
123
+ "notNull": true,
124
+ "default": 0
125
+ },
126
+ "created_at": {
127
+ "name": "created_at",
128
+ "type": "timestamp (3) with time zone",
129
+ "primaryKey": false,
130
+ "notNull": true
131
+ },
132
+ "started_at": {
133
+ "name": "started_at",
134
+ "type": "timestamp (3) with time zone",
135
+ "primaryKey": false,
136
+ "notNull": false
137
+ },
138
+ "finished_at": {
139
+ "name": "finished_at",
140
+ "type": "timestamp (3) with time zone",
141
+ "primaryKey": false,
142
+ "notNull": false
143
+ },
144
+ "delivered_at": {
145
+ "name": "delivered_at",
146
+ "type": "timestamp (3) with time zone",
147
+ "primaryKey": false,
148
+ "notNull": false
149
+ },
150
+ "delivery_key": {
151
+ "name": "delivery_key",
152
+ "type": "text",
153
+ "primaryKey": false,
154
+ "notNull": false
155
+ }
156
+ },
157
+ "indexes": {
158
+ "background_tasks_status_lease_idx": {
159
+ "name": "background_tasks_status_lease_idx",
160
+ "columns": [
161
+ {
162
+ "expression": "status",
163
+ "isExpression": false,
164
+ "asc": true,
165
+ "nulls": "last"
166
+ },
167
+ {
168
+ "expression": "lease_until",
169
+ "isExpression": false,
170
+ "asc": true,
171
+ "nulls": "last"
172
+ }
173
+ ],
174
+ "isUnique": false,
175
+ "concurrently": false,
176
+ "method": "btree",
177
+ "with": {}
178
+ },
179
+ "background_tasks_owner_status_idx": {
180
+ "name": "background_tasks_owner_status_idx",
181
+ "columns": [
182
+ {
183
+ "expression": "owner_id",
184
+ "isExpression": false,
185
+ "asc": true,
186
+ "nulls": "last"
187
+ },
188
+ {
189
+ "expression": "status",
190
+ "isExpression": false,
191
+ "asc": true,
192
+ "nulls": "last"
193
+ }
194
+ ],
195
+ "isUnique": false,
196
+ "concurrently": false,
197
+ "method": "btree",
198
+ "with": {}
199
+ },
200
+ "background_tasks_chat_delivered_idx": {
201
+ "name": "background_tasks_chat_delivered_idx",
202
+ "columns": [
203
+ {
204
+ "expression": "chat_id",
205
+ "isExpression": false,
206
+ "asc": true,
207
+ "nulls": "last"
208
+ },
209
+ {
210
+ "expression": "delivered_at",
211
+ "isExpression": false,
212
+ "asc": true,
213
+ "nulls": "last"
214
+ }
215
+ ],
216
+ "isUnique": false,
217
+ "concurrently": false,
218
+ "method": "btree",
219
+ "with": {}
220
+ }
221
+ },
222
+ "foreignKeys": {},
223
+ "compositePrimaryKeys": {},
224
+ "uniqueConstraints": {},
225
+ "policies": {},
226
+ "checkConstraints": {},
227
+ "isRLSEnabled": false
228
+ }
229
+ },
230
+ "enums": {},
231
+ "schemas": {},
232
+ "sequences": {},
233
+ "roles": {},
234
+ "policies": {},
235
+ "views": {},
236
+ "_meta": {
237
+ "columns": {},
238
+ "schemas": {},
239
+ "tables": {}
240
+ }
241
+ }
@@ -15,6 +15,13 @@
15
15
  "when": 1791184440303,
16
16
  "tag": "0001_delivery_key",
17
17
  "breakpoints": true
18
+ },
19
+ {
20
+ "idx": 2,
21
+ "version": "7",
22
+ "when": 1794821625698,
23
+ "tag": "0002_started_by",
24
+ "breakpoints": true
18
25
  }
19
26
  ]
20
27
  }
@@ -0,0 +1 @@
1
+ ALTER TABLE `background_tasks` ADD `started_by` text;
@@ -0,0 +1,222 @@
1
+ {
2
+ "version": "6",
3
+ "dialect": "sqlite",
4
+ "id": "5a8b7790-dafb-4681-88c1-67af06f23281",
5
+ "prevId": "4df81cfc-b736-412a-add4-01a32c9129b4",
6
+ "tables": {
7
+ "background_tasks": {
8
+ "name": "background_tasks",
9
+ "columns": {
10
+ "id": {
11
+ "name": "id",
12
+ "type": "text",
13
+ "primaryKey": true,
14
+ "notNull": true,
15
+ "autoincrement": false
16
+ },
17
+ "owner_id": {
18
+ "name": "owner_id",
19
+ "type": "text",
20
+ "primaryKey": false,
21
+ "notNull": true,
22
+ "autoincrement": false
23
+ },
24
+ "chat_id": {
25
+ "name": "chat_id",
26
+ "type": "text",
27
+ "primaryKey": false,
28
+ "notNull": true,
29
+ "autoincrement": false
30
+ },
31
+ "message_id": {
32
+ "name": "message_id",
33
+ "type": "text",
34
+ "primaryKey": false,
35
+ "notNull": true,
36
+ "autoincrement": false
37
+ },
38
+ "tool_call_id": {
39
+ "name": "tool_call_id",
40
+ "type": "text",
41
+ "primaryKey": false,
42
+ "notNull": true,
43
+ "autoincrement": false
44
+ },
45
+ "channel": {
46
+ "name": "channel",
47
+ "type": "text",
48
+ "primaryKey": false,
49
+ "notNull": true,
50
+ "autoincrement": false
51
+ },
52
+ "kind": {
53
+ "name": "kind",
54
+ "type": "text",
55
+ "primaryKey": false,
56
+ "notNull": true,
57
+ "autoincrement": false
58
+ },
59
+ "name": {
60
+ "name": "name",
61
+ "type": "text",
62
+ "primaryKey": false,
63
+ "notNull": true,
64
+ "autoincrement": false
65
+ },
66
+ "input": {
67
+ "name": "input",
68
+ "type": "text",
69
+ "primaryKey": false,
70
+ "notNull": false,
71
+ "autoincrement": false
72
+ },
73
+ "title": {
74
+ "name": "title",
75
+ "type": "text",
76
+ "primaryKey": false,
77
+ "notNull": true,
78
+ "autoincrement": false
79
+ },
80
+ "started_by": {
81
+ "name": "started_by",
82
+ "type": "text",
83
+ "primaryKey": false,
84
+ "notNull": false,
85
+ "autoincrement": false
86
+ },
87
+ "status": {
88
+ "name": "status",
89
+ "type": "text",
90
+ "primaryKey": false,
91
+ "notNull": true,
92
+ "autoincrement": false
93
+ },
94
+ "helper_messages": {
95
+ "name": "helper_messages",
96
+ "type": "text",
97
+ "primaryKey": false,
98
+ "notNull": false,
99
+ "autoincrement": false
100
+ },
101
+ "progress": {
102
+ "name": "progress",
103
+ "type": "text",
104
+ "primaryKey": false,
105
+ "notNull": false,
106
+ "autoincrement": false
107
+ },
108
+ "result": {
109
+ "name": "result",
110
+ "type": "text",
111
+ "primaryKey": false,
112
+ "notNull": false,
113
+ "autoincrement": false
114
+ },
115
+ "error": {
116
+ "name": "error",
117
+ "type": "text",
118
+ "primaryKey": false,
119
+ "notNull": false,
120
+ "autoincrement": false
121
+ },
122
+ "lease_owner": {
123
+ "name": "lease_owner",
124
+ "type": "text",
125
+ "primaryKey": false,
126
+ "notNull": false,
127
+ "autoincrement": false
128
+ },
129
+ "lease_until": {
130
+ "name": "lease_until",
131
+ "type": "integer",
132
+ "primaryKey": false,
133
+ "notNull": false,
134
+ "autoincrement": false
135
+ },
136
+ "attempt": {
137
+ "name": "attempt",
138
+ "type": "integer",
139
+ "primaryKey": false,
140
+ "notNull": true,
141
+ "autoincrement": false,
142
+ "default": 0
143
+ },
144
+ "created_at": {
145
+ "name": "created_at",
146
+ "type": "integer",
147
+ "primaryKey": false,
148
+ "notNull": true,
149
+ "autoincrement": false
150
+ },
151
+ "started_at": {
152
+ "name": "started_at",
153
+ "type": "integer",
154
+ "primaryKey": false,
155
+ "notNull": false,
156
+ "autoincrement": false
157
+ },
158
+ "finished_at": {
159
+ "name": "finished_at",
160
+ "type": "integer",
161
+ "primaryKey": false,
162
+ "notNull": false,
163
+ "autoincrement": false
164
+ },
165
+ "delivered_at": {
166
+ "name": "delivered_at",
167
+ "type": "integer",
168
+ "primaryKey": false,
169
+ "notNull": false,
170
+ "autoincrement": false
171
+ },
172
+ "delivery_key": {
173
+ "name": "delivery_key",
174
+ "type": "text",
175
+ "primaryKey": false,
176
+ "notNull": false,
177
+ "autoincrement": false
178
+ }
179
+ },
180
+ "indexes": {
181
+ "background_tasks_status_lease_idx": {
182
+ "name": "background_tasks_status_lease_idx",
183
+ "columns": [
184
+ "status",
185
+ "lease_until"
186
+ ],
187
+ "isUnique": false
188
+ },
189
+ "background_tasks_owner_status_idx": {
190
+ "name": "background_tasks_owner_status_idx",
191
+ "columns": [
192
+ "owner_id",
193
+ "status"
194
+ ],
195
+ "isUnique": false
196
+ },
197
+ "background_tasks_chat_delivered_idx": {
198
+ "name": "background_tasks_chat_delivered_idx",
199
+ "columns": [
200
+ "chat_id",
201
+ "delivered_at"
202
+ ],
203
+ "isUnique": false
204
+ }
205
+ },
206
+ "foreignKeys": {},
207
+ "compositePrimaryKeys": {},
208
+ "uniqueConstraints": {},
209
+ "checkConstraints": {}
210
+ }
211
+ },
212
+ "views": {},
213
+ "enums": {},
214
+ "_meta": {
215
+ "schemas": {},
216
+ "tables": {},
217
+ "columns": {}
218
+ },
219
+ "internal": {
220
+ "indexes": {}
221
+ }
222
+ }
@@ -15,6 +15,13 @@
15
15
  "when": 1791184440017,
16
16
  "tag": "0001_delivery_key",
17
17
  "breakpoints": true
18
+ },
19
+ {
20
+ "idx": 2,
21
+ "version": "6",
22
+ "when": 1794821625206,
23
+ "tag": "0002_started_by",
24
+ "breakpoints": true
18
25
  }
19
26
  ]
20
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ykurilov/agent-chat-background",
3
- "version": "0.110.0",
3
+ "version": "0.111.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -47,7 +47,7 @@
47
47
  "dependencies": {
48
48
  "ai": "7.0.122",
49
49
  "drizzle-orm": "^0.45.3",
50
- "@ykurilov/agent-chat-core": "0.110.0"
50
+ "@ykurilov/agent-chat-core": "0.111.0"
51
51
  },
52
52
  "peerDependencies": {
53
53
  "better-sqlite3": "^13.0.3",
@@ -68,7 +68,7 @@
68
68
  "better-sqlite3": "^13.0.3",
69
69
  "drizzle-kit": "^0.31.11",
70
70
  "pg": "^8.23.0",
71
- "@ykurilov/agent-chat-server": "0.110.0"
71
+ "@ykurilov/agent-chat-server": "0.111.0"
72
72
  },
73
73
  "scripts": {
74
74
  "build": "node ../../scripts/build-package.mjs",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/store/task-store.ts"],"sourcesContent":["import type { TaskStatus } from \"@ykurilov/agent-chat-core\";\nimport type { TaskCondition, TaskPatch, TaskRecord } from \"../types\";\n\n/**\n * Жизнь задачи в хранилище.\n * - `queued`/`running` — идёт; аренда у копии сервера, которая её ведёт.\n * - `awaiting_approval` и законченные — ждут доставки служебного сообщения; аренда у копии, которая доставляет.\n * - `delivered_at` стоит — чату всё сообщено, аренды нет, задача никому не нужна до следующего события.\n * Поэтому «задаче нужна копия сервера» — ровно `delivered_at IS NULL`.\n */\nexport const RUNNING_STATUSES = [\"queued\", \"running\"] as const satisfies readonly TaskStatus[];\nexport const FINISHED_STATUSES = [\"done\", \"failed\", \"canceled\", \"interrupted\", \"timed_out\"] as const satisfies readonly TaskStatus[];\n/** О чём чат получает служебное сообщение. */\nexport const NOTICE_STATUSES = [...FINISHED_STATUSES, \"awaiting_approval\"] as const satisfies readonly TaskStatus[];\n\nexport const isRunningStatus = (status: TaskStatus): boolean => (RUNNING_STATUSES as readonly TaskStatus[]).includes(status);\nexport const isFinishedStatus = (status: TaskStatus): boolean => (FINISHED_STATUSES as readonly TaskStatus[]).includes(status);\n\n/** Поля записи, которые хранилище может не хранить: `null` из базы и `undefined` из правки значат «нет». */\nconst OPTIONAL_FIELDS = [\n \"input\",\n \"helperMessages\",\n \"progress\",\n \"result\",\n \"error\",\n \"leaseOwner\",\n \"leaseUntil\",\n \"startedAt\",\n \"finishedAt\",\n \"deliveredAt\",\n \"deliveryKey\",\n] as const satisfies readonly (keyof TaskRecord)[];\n\n/** Выполнено ли условие записи для задачи. */\nexport function meetsCondition(task: TaskRecord, when: TaskCondition | undefined): boolean {\n if (when?.leaseOwner !== undefined && task.leaseOwner !== when.leaseOwner) return false;\n if (when?.statuses !== undefined && !when.statuses.includes(task.status)) return false;\n if (when?.pendingApprovalId !== undefined && task.progress?.pendingApproval?.approvalId !== when.pendingApprovalId) return false;\n return true;\n}\n\n/** Убирает пустые необязательные поля: запись из любого хранилища выглядит одинаково. */\nexport function withoutEmptyFields(record: TaskRecord): TaskRecord {\n const clean = { ...record } as Record<string, unknown>;\n for (const field of OPTIONAL_FIELDS) {\n if (clean[field] === null || clean[field] === undefined) delete clean[field];\n }\n return clean as unknown as TaskRecord;\n}\n\n/** Правка (или вся запись) как пары «поле — значение»: переданный `undefined` стирает поле (`null` в базе). */\nexport function patchEntries(patch: TaskPatch | TaskRecord): Array<[string, unknown]> {\n return Object.entries(patch).map(([key, value]) => [key, value ?? null]);\n}\n\n/** PostgreSQL не хранит символ NUL ни в тексте, ни в jsonb: убираем его до записи. */\nexport function withoutNul<T>(value: T): T {\n if (value === null || value === undefined) return value;\n if (typeof value === \"string\") return value.replaceAll(\"\\u0000\", \"\") as T;\n if (typeof value !== \"object\") return value;\n return JSON.parse(JSON.stringify(value, (_key, item: unknown) => (typeof item === \"string\" ? item.replaceAll(\"\\u0000\", \"\") : item))) as T;\n}\n"],"mappings":";AAUO,IAAM,mBAAmB,CAAC,UAAU,SAAS;AAC7C,IAAM,oBAAoB,CAAC,QAAQ,UAAU,YAAY,eAAe,WAAW;AAEnF,IAAM,kBAAkB,CAAC,GAAG,mBAAmB,mBAAmB;AAElE,IAAM,kBAAkB,CAAC,WAAiC,iBAA2C,SAAS,MAAM;AACpH,IAAM,mBAAmB,CAAC,WAAiC,kBAA4C,SAAS,MAAM;AAG7H,IAAM,kBAAkB;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAGO,SAAS,eAAe,MAAkB,MAA0C;AACzF,MAAI,MAAM,eAAe,UAAa,KAAK,eAAe,KAAK,WAAY,QAAO;AAClF,MAAI,MAAM,aAAa,UAAa,CAAC,KAAK,SAAS,SAAS,KAAK,MAAM,EAAG,QAAO;AACjF,MAAI,MAAM,sBAAsB,UAAa,KAAK,UAAU,iBAAiB,eAAe,KAAK,kBAAmB,QAAO;AAC3H,SAAO;AACT;AAGO,SAAS,mBAAmB,QAAgC;AACjE,QAAM,QAAQ,EAAE,GAAG,OAAO;AAC1B,aAAW,SAAS,iBAAiB;AACnC,QAAI,MAAM,KAAK,MAAM,QAAQ,MAAM,KAAK,MAAM,OAAW,QAAO,MAAM,KAAK;AAAA,EAC7E;AACA,SAAO;AACT;AAGO,SAAS,aAAa,OAAyD;AACpF,SAAO,OAAO,QAAQ,KAAK,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,KAAK,SAAS,IAAI,CAAC;AACzE;AAGO,SAAS,WAAc,OAAa;AACzC,MAAI,UAAU,QAAQ,UAAU,OAAW,QAAO;AAClD,MAAI,OAAO,UAAU,SAAU,QAAO,MAAM,WAAW,MAAU,EAAE;AACnE,MAAI,OAAO,UAAU,SAAU,QAAO;AACtC,SAAO,KAAK,MAAM,KAAK,UAAU,OAAO,CAAC,MAAM,SAAmB,OAAO,SAAS,WAAW,KAAK,WAAW,MAAU,EAAE,IAAI,IAAK,CAAC;AACrI;","names":[]}