@iconicompany/iagent-contracts 0.0.0-stage → 0.3.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/README.md +12 -2
- package/package.json +29 -4
- package/src/index.ts +1 -0
- package/src/outbound.ts +223 -0
package/README.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @iconicompany/iagent-contracts
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Контракты процессов очереди исходящих iagent (`iagent-outbound`) для соседей: импортируйте их вместо копии типов.
|
|
4
|
+
Пакет только для Bun — экспорт идёт исходниками `.ts`.
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
import { deliverMessage } from "@iconicompany/iagent-contracts";
|
|
8
|
+
import { startContract } from "@iworkflow/core/contract";
|
|
9
|
+
|
|
10
|
+
const handle = await startContract(client, deliverMessage, input, { id: "italent:offer:42" }); // ключ задаёт вызывающий
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Каталог (JSON Schema и страница с диаграммой) — `docs/contracts/` репозитория iagent; `bun run test` сверяет его с кодом.
|
package/package.json
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iconicompany/iagent-contracts",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Контракты процессов очереди исходящих iagent для соседей: схемы входа и исходов",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "UNLICENSED",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"src",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"exports": {
|
|
15
|
+
".": "./src/index.ts"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"contracts": "iworkflow-contracts src/index.ts --out ../../docs/contracts",
|
|
19
|
+
"test": "bun test",
|
|
20
|
+
"type-check": "tsc --noEmit"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@iworkflow/core": "0.16.4",
|
|
24
|
+
"@sinclair/typebox": "^0.34.0",
|
|
25
|
+
"@types/bun": "1.4.0"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@iworkflow/core": "^0.16.0",
|
|
29
|
+
"@sinclair/typebox": "^0.34.0"
|
|
30
|
+
}
|
|
31
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { botDialog, deliverMessage, eraseIagentPersonalData, findTelegram, sendDeletionConfirmationEmail, sendErasureConfirmation } from "./outbound";
|
package/src/outbound.ts
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
// Контракты очереди исходящих iagent: вход и итог процессов, которые запускают соседи (AC-GW-CONTRACT-01).
|
|
2
|
+
// Типы шлюза сверяются с этими схемами тестом packages/gateway/test/outbound-contract.test.ts.
|
|
3
|
+
import { Type as T } from "@sinclair/typebox";
|
|
4
|
+
import { defineWorkflowContract } from "@iworkflow/core/contract";
|
|
5
|
+
|
|
6
|
+
const QUEUE = "iagent-outbound";
|
|
7
|
+
|
|
8
|
+
const contact = T.Object(
|
|
9
|
+
{ firstName: T.String(), lastName: T.Optional(T.String()), note: T.Optional(T.String()) },
|
|
10
|
+
{ description: "Как человек записан контактом аккаунта" },
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
const recipient = T.Object(
|
|
14
|
+
{
|
|
15
|
+
userRef: T.Optional(T.String({ description: "Сквозной users.uid продукта" })),
|
|
16
|
+
transport: T.Optional(T.String()),
|
|
17
|
+
accountId: T.Optional(T.String()),
|
|
18
|
+
chatId: T.Optional(T.String()),
|
|
19
|
+
username: T.Optional(T.String({ description: "Имя в мессенджере, без собачки" })),
|
|
20
|
+
email: T.Optional(T.String()),
|
|
21
|
+
phone: T.Optional(T.String({ description: "Телефон в E.164: учётку Telegram очередь ищет по нему" })),
|
|
22
|
+
contact: T.Optional(contact),
|
|
23
|
+
maxChatId: T.Optional(T.String()),
|
|
24
|
+
negotiationId: T.Optional(T.String()),
|
|
25
|
+
hhChatId: T.Optional(T.String()),
|
|
26
|
+
resumeHash: T.Optional(T.String()),
|
|
27
|
+
},
|
|
28
|
+
{ description: "Кому: любой набор известных шлюзу адресов человека" },
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const button = T.Object({ text: T.String(), url: T.Optional(T.String()), callbackData: T.Optional(T.String()) });
|
|
32
|
+
|
|
33
|
+
const deliverInput = T.Object({
|
|
34
|
+
recipient,
|
|
35
|
+
text: T.String(),
|
|
36
|
+
buttons: T.Optional(T.Array(T.Array(button))),
|
|
37
|
+
format: T.Optional(T.Union([T.Literal("plain"), T.Literal("markdown"), T.Literal("html")])),
|
|
38
|
+
channels: T.Optional(T.Array(T.String(), { description: "Ограничить каналы; не задано — все, что знают человека" })),
|
|
39
|
+
email: T.Optional(
|
|
40
|
+
T.Object({ subject: T.Optional(T.String()), headers: T.Optional(T.Record(T.String(), T.String())), html: T.Optional(T.String()) }),
|
|
41
|
+
),
|
|
42
|
+
client: T.String({ description: "Кто поставил сообщение: попадает в журнал шлюза" }),
|
|
43
|
+
askToAddContact: T.Optional(T.Boolean({ description: "Невзаимному — просьба добавить в контакты" })),
|
|
44
|
+
linkBlock: T.Optional(T.String({ description: "Ссылка отдельным блоком" })),
|
|
45
|
+
linkFallback: T.Optional(T.String({ description: "Заглушка вместо ссылки невзаимному" })),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const delivery = T.Object({
|
|
49
|
+
channel: T.String(),
|
|
50
|
+
transportId: T.Optional(T.String()),
|
|
51
|
+
senderType: T.Optional(T.Union([T.Literal("bot"), T.Literal("account")])),
|
|
52
|
+
ok: T.Boolean(),
|
|
53
|
+
messageId: T.Optional(T.String()),
|
|
54
|
+
recipientId: T.Optional(T.String()),
|
|
55
|
+
intendedFor: T.Optional(T.Union([T.String(), T.Null()])),
|
|
56
|
+
redirected: T.Boolean(),
|
|
57
|
+
message: T.String(),
|
|
58
|
+
retryAfterSeconds: T.Optional(T.Number()),
|
|
59
|
+
failure: T.Optional(
|
|
60
|
+
T.Union([T.Literal("flood-wait"), T.Literal("peer-flood"), T.Literal("busy"), T.Literal("daily-cap"), T.Literal("error")]),
|
|
61
|
+
),
|
|
62
|
+
telegram: T.Optional(
|
|
63
|
+
T.Object({ telegramId: T.String(), username: T.Optional(T.String()), mutualContact: T.Union([T.Boolean(), T.Null()]) }),
|
|
64
|
+
),
|
|
65
|
+
contactStatus: T.Optional(T.Union([T.Literal("mutual"), T.Literal("contact"), T.Literal("none"), T.Null()])),
|
|
66
|
+
linkIncluded: T.Optional(T.Boolean()),
|
|
67
|
+
retryable: T.Optional(T.Boolean({ description: "Только у недоставленного: false — повтор не поможет (адресат недостижим, канала нет, подавлен, учётки Telegram с телефоном нет); true — можно поставить новую доставку позже" })),
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const telegramMatch = T.Object({
|
|
71
|
+
phone: T.String(),
|
|
72
|
+
found: T.Boolean({ description: "false — учётки с этим телефоном нет" }),
|
|
73
|
+
telegramId: T.Optional(T.String()),
|
|
74
|
+
username: T.Optional(T.String()),
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
export const deliverMessage = defineWorkflowContract({
|
|
78
|
+
name: "deliverMessage",
|
|
79
|
+
taskQueue: QUEUE,
|
|
80
|
+
description: "Доставка сообщения человеку по известным каналам: темп, тихие часы и срок 5 ч рабочего окна держит шлюз.",
|
|
81
|
+
workflowId: { by: "caller", description: "Ключ доставки вызывающего: italent:offer:<id>, italent:agency-lead:<senderId>" },
|
|
82
|
+
input: deliverInput,
|
|
83
|
+
outcomes: {
|
|
84
|
+
result: T.Object(
|
|
85
|
+
{
|
|
86
|
+
ok: T.Boolean({ description: "true — хотя бы один канал принял" }),
|
|
87
|
+
message: T.String(),
|
|
88
|
+
ids: T.Array(T.Number(), { description: "Строки ленты шлюза" }),
|
|
89
|
+
deliveries: T.Array(delivery),
|
|
90
|
+
telegram: T.Optional(telegramMatch),
|
|
91
|
+
},
|
|
92
|
+
{ description: "Итог по каналам" },
|
|
93
|
+
),
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
export const findTelegram = defineWorkflowContract({
|
|
98
|
+
name: "findTelegram",
|
|
99
|
+
taskQueue: QUEUE,
|
|
100
|
+
description: "Поиск учётки Telegram по телефону; найденного можно сохранить контактом аккаунта.",
|
|
101
|
+
workflowId: { by: "caller", description: "Ключ вызывающего" },
|
|
102
|
+
input: T.Object({ phone: T.String(), client: T.String(), contact: T.Optional(contact) }),
|
|
103
|
+
outcomes: { result: telegramMatch },
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const subject = T.Object({
|
|
107
|
+
email: T.Optional(T.String()),
|
|
108
|
+
zitadelUserId: T.Optional(T.String()),
|
|
109
|
+
userRef: T.Optional(T.String({ description: "users.uid продукта, не id ZITADEL" })),
|
|
110
|
+
italentUserIds: T.Optional(T.Array(T.Number())),
|
|
111
|
+
specialistIds: T.Optional(T.Array(T.Number())),
|
|
112
|
+
externalIds: T.Optional(T.Array(T.String())),
|
|
113
|
+
offerIds: T.Optional(T.Array(T.Number())),
|
|
114
|
+
telegramUsernames: T.Optional(T.Array(T.String())),
|
|
115
|
+
phones: T.Optional(T.Array(T.String())),
|
|
116
|
+
hhChatIds: T.Optional(T.Array(T.String())),
|
|
117
|
+
telegramIds: T.Optional(T.Array(T.String())),
|
|
118
|
+
});
|
|
119
|
+
const phase = T.Union([T.Literal("prepare"), T.Literal("erase"), T.Literal("verify")]);
|
|
120
|
+
|
|
121
|
+
export const eraseIagentPersonalData = defineWorkflowContract({
|
|
122
|
+
name: "eraseIagentPersonalData",
|
|
123
|
+
taskQueue: QUEUE,
|
|
124
|
+
description: "Шаг прекращения обработки персональных данных в шлюзе: подготовка, удаление, проверка.",
|
|
125
|
+
workflowId: { by: "caller", description: "Ключ вызывающего на запрос и шаг" },
|
|
126
|
+
input: T.Object({ requestId: T.String(), phase, subject }),
|
|
127
|
+
outcomes: {
|
|
128
|
+
result: T.Object({
|
|
129
|
+
project: T.Literal("iagent"),
|
|
130
|
+
phase,
|
|
131
|
+
subject,
|
|
132
|
+
counts: T.Record(T.String(), T.Number()),
|
|
133
|
+
verified: T.Boolean(),
|
|
134
|
+
limitations: T.Array(T.String()),
|
|
135
|
+
}),
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const confirmationInput = T.Object({
|
|
140
|
+
requestId: T.String(),
|
|
141
|
+
email: T.Optional(T.String({ description: "Обязателен без recipient" })),
|
|
142
|
+
text: T.Optional(T.String()),
|
|
143
|
+
recipient: T.Optional(
|
|
144
|
+
T.Union([
|
|
145
|
+
T.Object({ transport: T.Literal("headhunter"), hhChatId: T.String({ pattern: "^\\d+$" }) }),
|
|
146
|
+
T.Object({ transport: T.Literal("telegram"), chatId: T.String({ pattern: "^-?\\d+$" }) }),
|
|
147
|
+
]),
|
|
148
|
+
),
|
|
149
|
+
});
|
|
150
|
+
const confirmationResult = T.Object({
|
|
151
|
+
sent: T.Boolean({ description: "true — канал принял сообщение; не доказательство прочтения" }),
|
|
152
|
+
alreadySent: T.Optional(T.Boolean()),
|
|
153
|
+
}, { description: "Отказ (неверный вход, ключ не erase-confirmation:<requestId>, канал не принял) — сбой процесса без повтора, не исход" });
|
|
154
|
+
|
|
155
|
+
export const sendDeletionConfirmationEmail = defineWorkflowContract({
|
|
156
|
+
name: "sendDeletionConfirmationEmail",
|
|
157
|
+
taskQueue: QUEUE,
|
|
158
|
+
description: "Подтверждение прекращения обработки персональных данных: письмом или туда, откуда пришёл отзыв.",
|
|
159
|
+
workflowId: { by: "caller", description: "erase-confirmation:<requestId>, повтор — с суффиксом :retry-<n>" },
|
|
160
|
+
input: confirmationInput,
|
|
161
|
+
outcomes: { result: confirmationResult },
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
export const sendErasureConfirmation = defineWorkflowContract({
|
|
165
|
+
name: "sendErasureConfirmation",
|
|
166
|
+
taskQueue: QUEUE,
|
|
167
|
+
description: "То же подтверждение под новым именем процесса.",
|
|
168
|
+
workflowId: { by: "caller", description: "erase-confirmation:<requestId>, повтор — с суффиксом :retry-<n>" },
|
|
169
|
+
input: confirmationInput,
|
|
170
|
+
outcomes: { result: confirmationResult },
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
const botAnswer = T.Union(
|
|
174
|
+
[
|
|
175
|
+
T.Object({ text: T.String({ description: "Ответ текстом" }) }),
|
|
176
|
+
T.Object({ button: T.String({ description: "Нажать кнопку под вопросом по её тексту" }) }),
|
|
177
|
+
T.Object({ document: T.Object({ filename: T.String(), dataBase64: T.String() }) }),
|
|
178
|
+
T.Object({ done: T.Literal(true) }),
|
|
179
|
+
],
|
|
180
|
+
{ description: "Ответ на вопрос бота или конец диалога" },
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
export const botDialog = defineWorkflowContract({
|
|
184
|
+
name: "botDialog",
|
|
185
|
+
taskQueue: QUEUE,
|
|
186
|
+
description: "Диалог учёткой Telegram с ботом по сценарию: /start, ответ на каждый вопрос по ключу, итог.",
|
|
187
|
+
workflowId: { by: "caller", description: "Ключ вызывающего: второй запуск с ним диалога не начнёт" },
|
|
188
|
+
input: T.Object({
|
|
189
|
+
bot: T.String({ description: "Имя бота, с собачкой или без" }),
|
|
190
|
+
start: T.Optional(T.String({ description: "Параметр /start из ссылки ?start=" })),
|
|
191
|
+
channel: T.Optional(T.String({ description: "Канал шлюза (учётка); не задан — вторая учётка, если есть" })),
|
|
192
|
+
stepTimeoutSec: T.Optional(T.Integer({ description: "Сколько ждать сообщения бота, с; по умолчанию 120" })),
|
|
193
|
+
steps: T.Array(
|
|
194
|
+
T.Object({
|
|
195
|
+
id: T.String(),
|
|
196
|
+
keywords: T.Array(T.String(), { description: "Шаг — первый, чьё слово входит в текст бота без регистра" }),
|
|
197
|
+
answer: botAnswer,
|
|
198
|
+
}),
|
|
199
|
+
),
|
|
200
|
+
}),
|
|
201
|
+
outcomes: {
|
|
202
|
+
result: T.Union([
|
|
203
|
+
T.Object({ ok: T.Literal(true), receipt: T.String({ description: "Последнее сообщение бота" }) }),
|
|
204
|
+
T.Object({
|
|
205
|
+
ok: T.Literal(false),
|
|
206
|
+
reason: T.Union([
|
|
207
|
+
T.Literal("invalid"),
|
|
208
|
+
T.Literal("no-channel"),
|
|
209
|
+
T.Literal("busy"),
|
|
210
|
+
T.Literal("gateway-error"),
|
|
211
|
+
T.Literal("unknown-question"),
|
|
212
|
+
T.Literal("timeout"),
|
|
213
|
+
T.Literal("button-missing"),
|
|
214
|
+
T.Literal("loop"),
|
|
215
|
+
T.Literal("send-failed"),
|
|
216
|
+
]),
|
|
217
|
+
message: T.Optional(T.String()),
|
|
218
|
+
question: T.Optional(T.String({ description: "Вопрос бота, на котором остановились" })),
|
|
219
|
+
stepId: T.Optional(T.String()),
|
|
220
|
+
}),
|
|
221
|
+
]),
|
|
222
|
+
},
|
|
223
|
+
});
|