@owlmeans/bot 0.0.0-stage → 0.1.18-rc.2

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.
Files changed (99) hide show
  1. package/README.md +85 -2
  2. package/agent-meta/manifest.json +16 -0
  3. package/agent-meta/skills/bot/SKILL.md +187 -0
  4. package/build/consts.d.ts +132 -0
  5. package/build/consts.d.ts.map +1 -0
  6. package/build/consts.js +197 -0
  7. package/build/consts.js.map +1 -0
  8. package/build/consts.local.d.ts +13 -0
  9. package/build/consts.local.d.ts.map +1 -0
  10. package/build/consts.local.js +13 -0
  11. package/build/consts.local.js.map +1 -0
  12. package/build/errors.d.ts +43 -0
  13. package/build/errors.d.ts.map +1 -0
  14. package/build/errors.js +66 -0
  15. package/build/errors.js.map +1 -0
  16. package/build/helpers/command/types.d.ts +14 -0
  17. package/build/helpers/command/types.d.ts.map +1 -0
  18. package/build/helpers/command/types.js +2 -0
  19. package/build/helpers/command/types.js.map +1 -0
  20. package/build/helpers/command.d.ts +4 -0
  21. package/build/helpers/command.d.ts.map +1 -0
  22. package/build/helpers/command.js +21 -0
  23. package/build/helpers/command.js.map +1 -0
  24. package/build/helpers/index.d.ts +7 -0
  25. package/build/helpers/index.d.ts.map +1 -0
  26. package/build/helpers/index.js +4 -0
  27. package/build/helpers/index.js.map +1 -0
  28. package/build/helpers/platform/types.d.ts +12 -0
  29. package/build/helpers/platform/types.d.ts.map +1 -0
  30. package/build/helpers/platform/types.js +2 -0
  31. package/build/helpers/platform/types.js.map +1 -0
  32. package/build/helpers/platform.d.ts +4 -0
  33. package/build/helpers/platform.d.ts.map +1 -0
  34. package/build/helpers/platform.js +17 -0
  35. package/build/helpers/platform.js.map +1 -0
  36. package/build/helpers/rule/types.d.ts +26 -0
  37. package/build/helpers/rule/types.d.ts.map +1 -0
  38. package/build/helpers/rule/types.js +2 -0
  39. package/build/helpers/rule/types.js.map +1 -0
  40. package/build/helpers/rule.d.ts +4 -0
  41. package/build/helpers/rule.d.ts.map +1 -0
  42. package/build/helpers/rule.js +71 -0
  43. package/build/helpers/rule.js.map +1 -0
  44. package/build/index.d.ts +8 -0
  45. package/build/index.d.ts.map +1 -0
  46. package/build/index.js +6 -0
  47. package/build/index.js.map +1 -0
  48. package/build/protocols/types.d.ts +115 -0
  49. package/build/protocols/types.d.ts.map +1 -0
  50. package/build/protocols/types.js +2 -0
  51. package/build/protocols/types.js.map +1 -0
  52. package/build/protocols.d.ts +21 -0
  53. package/build/protocols.d.ts.map +1 -0
  54. package/build/protocols.js +70 -0
  55. package/build/protocols.js.map +1 -0
  56. package/build/schemas.d.ts +17 -0
  57. package/build/schemas.d.ts.map +1 -0
  58. package/build/schemas.js +140 -0
  59. package/build/schemas.js.map +1 -0
  60. package/build/types.d.ts +215 -0
  61. package/build/types.d.ts.map +1 -0
  62. package/build/types.js +2 -0
  63. package/build/types.js.map +1 -0
  64. package/build/utils/aliases/types.d.ts +30 -0
  65. package/build/utils/aliases/types.d.ts.map +1 -0
  66. package/build/utils/aliases/types.js +2 -0
  67. package/build/utils/aliases/types.js.map +1 -0
  68. package/build/utils/aliases.d.ts +4 -0
  69. package/build/utils/aliases.d.ts.map +1 -0
  70. package/build/utils/aliases.js +26 -0
  71. package/build/utils/aliases.js.map +1 -0
  72. package/package.json +42 -4
  73. package/src/consts.local.ts +14 -0
  74. package/src/consts.ts +214 -0
  75. package/src/errors.ts +78 -0
  76. package/src/helpers/command/types.ts +14 -0
  77. package/src/helpers/command.ts +26 -0
  78. package/src/helpers/index.ts +6 -0
  79. package/src/helpers/platform/types.ts +12 -0
  80. package/src/helpers/platform.ts +23 -0
  81. package/src/helpers/rule/types.ts +26 -0
  82. package/src/helpers/rule.ts +89 -0
  83. package/src/index.ts +7 -0
  84. package/src/protocols/types.ts +107 -0
  85. package/src/protocols.ts +121 -0
  86. package/src/schemas.ts +159 -0
  87. package/src/types.ts +228 -0
  88. package/src/utils/aliases/types.ts +25 -0
  89. package/src/utils/aliases.ts +30 -0
  90. package/tests/command.spec.ts +23 -0
  91. package/tests/context.ts +13 -0
  92. package/tests/errors.spec.ts +41 -0
  93. package/tests/platforms.spec.ts +60 -0
  94. package/tests/protocols.spec.ts +80 -0
  95. package/tests/rule.spec.ts +129 -0
  96. package/tests/schemas.spec.ts +102 -0
  97. package/tests/tsconfig.json +12 -0
  98. package/tests/update.spec.ts +38 -0
  99. package/tsconfig.json +8 -0
@@ -0,0 +1,70 @@
1
+ import { contract, openProtocol, protocol, typed } from '@owlmeans/entrypoint';
2
+ import { backend, route, RouteMethod } from '@owlmeans/route';
3
+ import { BotActivityQuerySchema, BotChallengeQuerySchema, BotConnectionInputSchema, BotHookParamsSchema, BotIdParamsSchema, BotRuleInputSchema, BotRuleListQuerySchema, BotSimulateInputSchema, } from './schemas.js';
4
+ import { botAliasUtils } from './utils/aliases.js';
5
+ const mountOf = (base) => ({
6
+ ...(base.parent != null ? { parent: base.parent } : {}),
7
+ ...(base.service != null ? { service: base.service } : {}),
8
+ });
9
+ /**
10
+ * Declare one managing surface of the bot — connections, rules, activity — as an immutable tree a
11
+ * server binds and a client calls.
12
+ *
13
+ * Every leaf hangs under ONE base that carries the guards and the gate, so they cannot drift apart;
14
+ * aliases derive from `opts.base.alias` (`<alias>:connection:list` …). A target declares one tree per
15
+ * area that runs bots (`api:bot:operator`, `api:bot:member`) — the same leaves, another gate.
16
+ */
17
+ export const makeBotProtocols = (opts) => {
18
+ const aliases = botAliasUtils.botAliases(opts.base.alias);
19
+ const base = openProtocol(route(aliases.base, opts.base.path, backend(mountOf(opts.base))), {
20
+ ...(opts.guards != null ? { guards: opts.guards } : {}),
21
+ ...(opts.gates != null ? { gate: opts.gates } : {}),
22
+ });
23
+ const leaf = (alias, path, method) => route(alias, path, backend({ parent: base }, method));
24
+ return Object.freeze({
25
+ base,
26
+ connection: Object.freeze({
27
+ list: protocol(leaf(aliases.connection.list, '/connections', RouteMethod.GET), contract(typed())),
28
+ save: protocol(leaf(aliases.connection.save, '/connections', RouteMethod.POST), contract.request({ body: typed(BotConnectionInputSchema) }, typed())),
29
+ verify: protocol(leaf(aliases.connection.verify, '/connections/:id/verify', RouteMethod.POST), contract.request({ params: typed(BotIdParamsSchema) }, typed())),
30
+ remove: protocol(leaf(aliases.connection.remove, '/connections/:id', RouteMethod.DELETE), contract.request({ params: typed(BotIdParamsSchema) }, typed())),
31
+ simulate: protocol(leaf(aliases.connection.simulate, '/connections/:id/simulate', RouteMethod.POST), contract.request({
32
+ params: typed(BotIdParamsSchema),
33
+ body: typed(BotSimulateInputSchema),
34
+ }, typed())),
35
+ }),
36
+ rule: Object.freeze({
37
+ list: protocol(leaf(aliases.rule.list, '/rules', RouteMethod.GET), contract.request({ query: typed(BotRuleListQuerySchema) }, typed())),
38
+ save: protocol(leaf(aliases.rule.save, '/rules', RouteMethod.POST), contract.request({ body: typed(BotRuleInputSchema) }, typed())),
39
+ remove: protocol(leaf(aliases.rule.remove, '/rules/:id', RouteMethod.DELETE), contract.request({ params: typed(BotIdParamsSchema) }, typed())),
40
+ }),
41
+ activity: Object.freeze({
42
+ list: protocol(leaf(aliases.activity.list, '/activity', RouteMethod.GET), contract.request({ query: typed(BotActivityQuerySchema) }, typed())),
43
+ }),
44
+ });
45
+ };
46
+ /**
47
+ * Declare the platforms' inbound surface: `receive` (POST) and `challenge` (GET) at
48
+ * `/:platform/:connection` under the base.
49
+ *
50
+ * NO guard and no gate, by design: the caller is the platform, and it proves itself by signing the
51
+ * request (Telegram's secret token, WhatsApp's app-secret HMAC, Slack's signing secret), which the
52
+ * server verifies against the connection's credentials. The body carries no schema — the signature
53
+ * covers the raw bytes, and the payload is the platform's own.
54
+ */
55
+ export const makeBotHookProtocols = (opts) => {
56
+ const aliases = botAliasUtils.botHookAliases(opts.base.alias);
57
+ const base = openProtocol(route(aliases.base, opts.base.path, backend(mountOf(opts.base))));
58
+ return Object.freeze({
59
+ base,
60
+ receive: protocol(route(aliases.receive, '/:platform/:connection', backend({ parent: base }, RouteMethod.POST)), contract.request({
61
+ params: typed(BotHookParamsSchema),
62
+ body: typed(),
63
+ }, typed())),
64
+ challenge: protocol(route(aliases.challenge, '/:platform/:connection', backend({ parent: base }, RouteMethod.GET)), contract.request({
65
+ params: typed(BotHookParamsSchema),
66
+ query: typed(BotChallengeQuerySchema),
67
+ }, typed())),
68
+ });
69
+ };
70
+ //# sourceMappingURL=protocols.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocols.js","sourceRoot":"","sources":["../src/protocols.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAC9E,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAqB,MAAM,iBAAiB,CAAA;AAChF,OAAO,EACL,sBAAsB,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,iBAAiB,EACjH,kBAAkB,EAAE,sBAAsB,EAAE,sBAAsB,GACnE,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AASlD,MAAM,OAAO,GAAG,CAAC,IAAoB,EAAyB,EAAE,CAAC,CAAC;IAChE,GAAG,CAAC,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACvD,GAAG,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;CAC3D,CAAC,CAAA;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAAwB,EAAgB,EAAE;IACzE,MAAM,OAAO,GAAG,aAAa,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACzD,MAAM,I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O,CAAC,SAAS,EAAE,wBAAwB,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,EAC9F,QAAQ,CAAC,OAAO,CAAC;YACf,MAAM,EAAE,KAAK,CAAgB,mBAAmB,CAAC;YACjD,KAAK,EAAE,KAAK,CAAoB,uBAAuB,CAAC;SACzD,EAAE,KAAK,EAAU,CAAC,CACpB;KACF,CAAC,CAAA;AACJ,CAAC,CAAA"}
@@ -0,0 +1,17 @@
1
+ import type { JSONSchemaType } from 'ajv';
2
+ import type { BotActivityQuery, BotChallengeQuery, BotHookParams, BotIdParams, BotRuleListQuery } from './protocols/types.js';
3
+ import type { BotConnectionInput, BotRuleInput, BotSimulateInput } from './types.js';
4
+ export declare const BotIdParamsSchema: JSONSchemaType<BotIdParams>;
5
+ export declare const BotConnectionInputSchema: JSONSchemaType<BotConnectionInput>;
6
+ export declare const BotRuleInputSchema: JSONSchemaType<BotRuleInput>;
7
+ export declare const BotSimulateInputSchema: JSONSchemaType<BotSimulateInput>;
8
+ export declare const BotRuleListQuerySchema: JSONSchemaType<BotRuleListQuery>;
9
+ /** A query string arrives as text: the server coerces `limit` before this checks it. */
10
+ export declare const BotActivityQuerySchema: JSONSchemaType<BotActivityQuery>;
11
+ export declare const BotHookParamsSchema: JSONSchemaType<BotHookParams>;
12
+ /**
13
+ * The handshake query. Open (`additionalProperties: true`): a platform adds keys at will, and a
14
+ * stripping validator must never drop the one the server reads.
15
+ */
16
+ export declare const BotChallengeQuerySchema: JSONSchemaType<BotChallengeQuery>;
17
+ //# sourceMappingURL=schemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,KAAK,CAAA;AAOzC,OAAO,KAAK,EACV,gBAAgB,EAAE,iBAAiB,EAAE,aAAa,EAAE,WAAW,EAAE,gBAAgB,EAClF,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EAAE,kBAAkB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAcpF,eAAO,MAAM,iBAAiB,6BAK5B,CAAA;AAEF,eAAO,MAAM,wBAAwB,oCAoBnC,CAAA;AAEF,eAAO,MAAM,kBAAkB,8BAqB7B,CAAA;AAEF,eAAO,MAAM,sBAAsB,kCAuCjC,CAAA;AAEF,eAAO,MAAM,sBAAsB,kCAKjC,CAAA;AAEF,wFAAwF;AACxF,eAAO,MAAM,sBAAsB,kCAQjC,CAAA;AAEF,eAAO,MAAM,mBAAmB,+BAQ9B,CAAA;AAEF;;;GAGG;AACH,eAAO,MAAM,uBAAuB,mCASlC,CAAA"}
@@ -0,0 +1,140 @@
1
+ import { BOT_ACTIVITY_LIMIT_MAX, BOT_CREDENTIAL_KEY_PATTERN, BOT_CREDENTIAL_MAX, BOT_CREDENTIALS_MAX, BOT_ID_MAX, BOT_ID_PATTERN, BOT_INSTRUCTION_MAX, BOT_KEYWORD_MAX, BOT_KEYWORDS_MAX, BOT_LABEL_MAX, BOT_NAME_MAX, BOT_REPLY_MAX, BOT_RULE_NAME_MAX, BOT_TEXT_MAX, BotChatKind, BotMatchMode, BotPlatform, BotRuleAction, BotTransport, } from './consts.js';
2
+ /**
3
+ * Hand-written request schemas, cast: an optional key is OPTIONAL, never `null` — the wire matches the
4
+ * TypeScript type exactly. The only nullable is a rule's `connection`, whose `null` means "every
5
+ * connection of the scope". `additionalProperties: false` everywhere a client writes.
6
+ */
7
+ const cast = (schema) => schema;
8
+ const Id = { type: 'string', minLength: 1, maxLength: BOT_ID_MAX, pattern: BOT_ID_PATTERN };
9
+ const Name = { type: 'string', maxLength: BOT_NAME_MAX };
10
+ /** A platform's own id (a chat, a user, a message) — no pattern: Telegram chat ids are negative numbers. */
11
+ const PlatformId = { type: 'string', minLength: 1, maxLength: BOT_ID_MAX };
12
+ export const BotIdParamsSchema = cast({
13
+ type: 'object',
14
+ properties: { id: Id },
15
+ required: ['id'],
16
+ additionalProperties: false,
17
+ });
18
+ export const BotConnectionInputSchema = cast({
19
+ type: 'object',
20
+ properties: {
21
+ id: Id,
22
+ platform: { type: 'string', enum: Object.values(BotPlatform) },
23
+ label: { type: 'string', minLength: 1, maxLength: BOT_LABEL_MAX },
24
+ transport: { type: 'string', enum: Object.values(BotTransport) },
25
+ enabled: { type: 'boolean' },
26
+ // Write-only. An omitted key keeps its stored value; an empty string is spellable so an optional
27
+ // credential can be cleared.
28
+ credentials: {
29
+ type: 'object',
30
+ propertyNames: { pattern: BOT_CREDENTIAL_KEY_PATTERN },
31
+ additionalProperties: { type: 'string', maxLength: BOT_CREDENTIAL_MAX },
32
+ maxProperties: BOT_CREDENTIALS_MAX,
33
+ required: [],
34
+ },
35
+ },
36
+ required: ['platform', 'label'],
37
+ additionalProperties: false,
38
+ });
39
+ export const BotRuleInputSchema = cast({
40
+ type: 'object',
41
+ properties: {
42
+ id: Id,
43
+ connection: { ...Id, nullable: true },
44
+ name: { type: 'string', minLength: 1, maxLength: BOT_RULE_NAME_MAX },
45
+ keywords: {
46
+ type: 'array',
47
+ items: { type: 'string', minLength: 1, maxLength: BOT_KEYWORD_MAX },
48
+ minItems: 1,
49
+ maxItems: BOT_KEYWORDS_MAX,
50
+ },
51
+ mode: { type: 'string', enum: Object.values(BotMatchMode) },
52
+ action: { type: 'string', enum: Object.values(BotRuleAction) },
53
+ reply: { type: 'string', maxLength: BOT_REPLY_MAX },
54
+ instruction: { type: 'string', maxLength: BOT_INSTRUCTION_MAX },
55
+ enabled: { type: 'boolean' },
56
+ order: { type: 'number' },
57
+ },
58
+ required: ['name', 'keywords', 'action'],
59
+ additionalProperties: false,
60
+ });
61
+ export const BotSimulateInputSchema = cast({
62
+ type: 'object',
63
+ properties: {
64
+ text: { type: 'string', minLength: 1, maxLength: BOT_TEXT_MAX },
65
+ chat: {
66
+ type: 'object',
67
+ properties: {
68
+ id: PlatformId,
69
+ kind: { type: 'string', enum: Object.values(BotChatKind) },
70
+ title: Name,
71
+ thread: PlatformId,
72
+ space: PlatformId,
73
+ },
74
+ required: [],
75
+ additionalProperties: false,
76
+ },
77
+ sender: {
78
+ type: 'object',
79
+ properties: {
80
+ id: PlatformId,
81
+ name: Name,
82
+ username: Name,
83
+ bot: { type: 'boolean' },
84
+ },
85
+ required: [],
86
+ additionalProperties: false,
87
+ },
88
+ replyTo: {
89
+ type: 'object',
90
+ properties: {
91
+ id: PlatformId,
92
+ text: { type: 'string', maxLength: BOT_TEXT_MAX },
93
+ },
94
+ required: ['id'],
95
+ additionalProperties: false,
96
+ },
97
+ },
98
+ required: ['text'],
99
+ additionalProperties: false,
100
+ });
101
+ export const BotRuleListQuerySchema = cast({
102
+ type: 'object',
103
+ properties: { connection: Id },
104
+ required: [],
105
+ additionalProperties: false,
106
+ });
107
+ /** A query string arrives as text: the server coerces `limit` before this checks it. */
108
+ export const BotActivityQuerySchema = cast({
109
+ type: 'object',
110
+ properties: {
111
+ connection: Id,
112
+ limit: { type: 'integer', minimum: 1, maximum: BOT_ACTIVITY_LIMIT_MAX },
113
+ },
114
+ required: [],
115
+ additionalProperties: false,
116
+ });
117
+ export const BotHookParamsSchema = cast({
118
+ type: 'object',
119
+ properties: {
120
+ platform: { type: 'string', enum: Object.values(BotPlatform) },
121
+ connection: Id,
122
+ },
123
+ required: ['platform', 'connection'],
124
+ additionalProperties: false,
125
+ });
126
+ /**
127
+ * The handshake query. Open (`additionalProperties: true`): a platform adds keys at will, and a
128
+ * stripping validator must never drop the one the server reads.
129
+ */
130
+ export const BotChallengeQuerySchema = cast({
131
+ type: 'object',
132
+ properties: {
133
+ 'hub.mode': { type: 'string', maxLength: BOT_NAME_MAX },
134
+ 'hub.verify_token': { type: 'string', maxLength: BOT_CREDENTIAL_MAX },
135
+ 'hub.challenge': { type: 'string', maxLength: BOT_CREDENTIAL_MAX },
136
+ },
137
+ required: [],
138
+ additionalProperties: true,
139
+ });
140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EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,EAAE;QACvD,kBAAkB,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,kBAAkB,EAAE;QACrE,eAAe,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,kBAAkB,EAAE;KACnE;IACD,QAAQ,EAAE,EAAE;IACZ,oBAAoB,EAAE,IAAI;CAC3B,CAAC,CAAA"}
@@ -0,0 +1,215 @@
1
+ import type { BotActionKind, BotChatKind, BotConnectionStatus, BotMatchMode, BotPlatform, BotReceiveMode, BotRuleAction, BotTransport, BotUpdateKind } from './consts.js';
2
+ /** One credential a platform needs — what the panel draws an input for. */
3
+ export interface BotCredentialField {
4
+ key: string;
5
+ /** Never shown back once saved; the connection only says the key holds a value. */
6
+ secret: boolean;
7
+ /** The connection cannot be verified without it. */
8
+ required: boolean;
9
+ /**
10
+ * The server creates it on save and nobody types it (WhatsApp's verify token); the connection's
11
+ * `setup` steps carry it for pasting into the platform console.
12
+ */
13
+ generated?: boolean;
14
+ /** Optional credential only: the platform calls it adds when set (Slack's admin `userToken`: `delete`). */
15
+ enables?: BotActionKind[];
16
+ }
17
+ /** What a platform needs and can do. One per platform, in `BOT_PLATFORMS`. */
18
+ export interface BotPlatformDescriptor {
19
+ platform: BotPlatform;
20
+ title: string;
21
+ credentials: BotCredentialField[];
22
+ /** The receive modes the platform offers, preferred first. */
23
+ receive: BotReceiveMode[];
24
+ /** The platform calls the required credentials allow; `note` is never listed. */
25
+ actions: BotActionKind[];
26
+ /** `auto`: the server registers the hook itself; `manual`: a person pastes `setup` into the console. */
27
+ setup: 'auto' | 'manual';
28
+ /** Where a person learns to create the bot and its credentials. */
29
+ docs: string;
30
+ }
31
+ /** A connection as any client sees it — never a credential. */
32
+ export interface BotConnection {
33
+ id: string;
34
+ /** The organization (or application) key the connection belongs to — the server's, never the wire's. */
35
+ scope: string;
36
+ platform: BotPlatform;
37
+ label: string;
38
+ transport: BotTransport;
39
+ status: BotConnectionStatus;
40
+ enabled: boolean;
41
+ /** The receive mode in effect. */
42
+ receive: BotReceiveMode;
43
+ /** Who the bot is on the platform, as verification answered. */
44
+ identity?: {
45
+ id: string;
46
+ username?: string;
47
+ name?: string;
48
+ };
49
+ /** The address the platform posts to, for webhook platforms. */
50
+ hookUrl?: string;
51
+ /** Manual steps: the URL / verify token to paste in the platform console. */
52
+ setup?: string[];
53
+ /** Which credential keys hold a value. */
54
+ credentialsSet: string[];
55
+ lastError?: string;
56
+ lastEventAt?: string;
57
+ createdAt: string;
58
+ updatedAt: string;
59
+ }
60
+ /**
61
+ * A connection as a client writes it. `credentials` is write-only: an omitted key keeps its stored
62
+ * value.
63
+ */
64
+ export interface BotConnectionInput {
65
+ id?: string;
66
+ platform: BotPlatform;
67
+ label: string;
68
+ transport?: BotTransport;
69
+ enabled?: boolean;
70
+ credentials?: Record<string, string>;
71
+ }
72
+ /** A chat; `space` is the Discord guild or the Slack team. */
73
+ export interface BotChatRef {
74
+ id: string;
75
+ kind: BotChatKind;
76
+ title?: string;
77
+ thread?: string;
78
+ space?: string;
79
+ }
80
+ export interface BotSenderRef {
81
+ id: string;
82
+ name?: string;
83
+ username?: string;
84
+ bot?: boolean;
85
+ }
86
+ /**
87
+ * Enough to act on one message. `space` (the Discord guild / Slack team) is carried so a reference
88
+ * alone suffices where the platform addresses a member through it (a Discord timeout needs the guild).
89
+ */
90
+ export interface BotMessageRef {
91
+ chat: string;
92
+ id: string;
93
+ thread?: string;
94
+ space?: string;
95
+ }
96
+ /** The message an update carries. */
97
+ export interface BotReplyTarget extends BotMessageRef {
98
+ text?: string;
99
+ sender?: BotSenderRef;
100
+ }
101
+ export interface BotMessage {
102
+ ref: BotMessageRef;
103
+ text: string;
104
+ date: string;
105
+ replyTo?: BotReplyTarget;
106
+ }
107
+ /** A `/command`, its bot address stripped and its name lower-cased. */
108
+ export interface BotCommand {
109
+ name: string;
110
+ args: string;
111
+ }
112
+ /** A keyword group: the keywords and what the bot does with a message that matches them. */
113
+ export interface BotRule {
114
+ id: string;
115
+ scope: string;
116
+ /** One connection only; `null` or absent applies to every connection of the scope. */
117
+ connection?: string | null;
118
+ name: string;
119
+ keywords: string[];
120
+ mode: BotMatchMode;
121
+ action: BotRuleAction;
122
+ /** The fixed text of `reply` / `warn` (and the confirmation of `record`). */
123
+ reply?: string;
124
+ /** What the product's agent is told for this group. */
125
+ instruction?: string;
126
+ enabled: boolean;
127
+ order: number;
128
+ createdAt: string;
129
+ updatedAt: string;
130
+ }
131
+ export interface BotRuleInput {
132
+ id?: string;
133
+ connection?: string | null;
134
+ name: string;
135
+ keywords: string[];
136
+ mode?: BotMatchMode;
137
+ action: BotRuleAction;
138
+ reply?: string;
139
+ instruction?: string;
140
+ enabled?: boolean;
141
+ order?: number;
142
+ }
143
+ /** A rule a message matched, with the rule's keywords (as stored) that matched it. */
144
+ export interface BotMatch {
145
+ rule: BotRule;
146
+ keywords: string[];
147
+ }
148
+ /** A normalized inbound update, as a handler receives it. */
149
+ export interface BotUpdate {
150
+ id: string;
151
+ connection: string;
152
+ scope: string;
153
+ platform: BotPlatform;
154
+ kind: BotUpdateKind;
155
+ chat: BotChatRef;
156
+ sender?: BotSenderRef;
157
+ message?: BotMessage;
158
+ command?: BotCommand;
159
+ /** A direct message, a mention of the bot, or a reply to it. */
160
+ addressed: boolean;
161
+ /** Enabled rules of the scope (and connection) the text matches, by order. */
162
+ matches: BotMatch[];
163
+ receivedAt: string;
164
+ raw?: unknown;
165
+ }
166
+ /** Whom an activity acted on. */
167
+ export interface BotActivityTarget {
168
+ chat: string;
169
+ message?: string;
170
+ user?: string;
171
+ }
172
+ /** One thing the bot did — or tried to do — recorded whether it succeeded or not. */
173
+ export interface BotActivity {
174
+ id: string;
175
+ scope: string;
176
+ connection: string;
177
+ platform: BotPlatform;
178
+ /** The update it answered. */
179
+ update?: string;
180
+ action: BotActionKind;
181
+ target?: BotActivityTarget;
182
+ text?: string;
183
+ /** The rule it followed. */
184
+ rule?: string;
185
+ ok: boolean;
186
+ /** Why it failed, as a short sentence a person reads. */
187
+ error?: string;
188
+ /**
189
+ * The machine marker of the failure (`bot:<marker>:<detail>`) — what code compares and what a
190
+ * translating view keys its copy on; never shown as is.
191
+ */
192
+ code?: string;
193
+ transport: BotTransport;
194
+ at: string;
195
+ }
196
+ /** A message fed to a MOCK connection through the platform's own path. */
197
+ export interface BotSimulateInput {
198
+ text: string;
199
+ chat?: Partial<BotChatRef>;
200
+ sender?: Partial<BotSenderRef>;
201
+ replyTo?: {
202
+ id: string;
203
+ text?: string;
204
+ };
205
+ }
206
+ export interface BotSimulateResult {
207
+ /** The id of the update the simulated message became. */
208
+ update: string;
209
+ /**
210
+ * `true` when the simulated payload's dedupe key was already in the inbox: `update` is that
211
+ * existing row and nothing new is dispatched. `false` (or absent) for a new row.
212
+ */
213
+ duplicate?: boolean;
214
+ }
215
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EAAE,WAAW,EAAE,mBAAmB,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EACzG,YAAY,EAAE,aAAa,EAC5B,MAAM,aAAa,CAAA;AAEpB,2EAA2E;AAC3E,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,CAAA;IACX,mFAAmF;IACnF,MAAM,EAAE,OAAO,CAAA;IACf,oDAAoD;IACpD,QAAQ,EAAE,OAAO,CAAA;IACjB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,2GAA2G;IAC3G,OAAO,CAAC,EAAE,aAAa,EAAE,CAAA;CAC1B;AAED,8EAA8E;AAC9E,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,WAAW,CAAA;IACrB,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,kBAAkB,EAAE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ceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,30 @@
1
+ /** The aliases one managing tree answers under — every one derived from the mount's base alias. */
2
+ export interface BotAliases {
3
+ readonly base: string;
4
+ readonly connection: {
5
+ readonly list: string;
6
+ readonly save: string;
7
+ readonly verify: string;
8
+ readonly remove: string;
9
+ readonly simulate: string;
10
+ };
11
+ readonly rule: {
12
+ readonly list: string;
13
+ readonly save: string;
14
+ readonly remove: string;
15
+ };
16
+ readonly activity: {
17
+ readonly list: string;
18
+ };
19
+ }
20
+ export interface BotHookAliases {
21
+ readonly base: string;
22
+ readonly receive: string;
23
+ readonly challenge: string;
24
+ }
25
+ export interface BotAliasUtils {
26
+ /** Two mounts in one deployment are two base aliases, never two copies of a table. */
27
+ botAliases: (base: string) => BotAliases;
28
+ botHookAliases: (base: string) => BotHookAliases;
29
+ }
30
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/utils/aliases/types.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,UAAU,EAAE;QACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;QACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;QACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;QACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;QACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;KAC1B,CAAA;IACD,QAAQ,CAAC,IAAI,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAA;IACxF,QAAQ,CAAC,QAAQ,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;CAC7C;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAC3B;AAED,MAAM,WAAW,aAAa;IAC5B,sFAAsF;IACtF,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,UAAU,CAAA;IACxC,cAAc,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,cAAc,CAAA;CACjD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/utils/aliases/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import type { BotAliasUtils } from './aliases/types.js';
2
+ export declare const createBotAliasUtils: () => BotAliasUtils;
3
+ export declare const botAliasUtils: BotAliasUtils;
4
+ //# sourceMappingURL=aliases.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aliases.d.ts","sourceRoot":"","sources":["../../src/utils/aliases.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,aAAa,EAAkB,MAAM,oBAAoB,CAAA;AAEnF,eAAO,MAAM,mBAAmB,QAAO,aAyBtC,CAAA;AAED,eAAO,MAAM,aAAa,eAAwB,CAAA"}
@@ -0,0 +1,26 @@
1
+ export const createBotAliasUtils = () => {
2
+ const botAliases = (base) => Object.freeze({
3
+ base,
4
+ connection: Object.freeze({
5
+ list: `${base}:connection:list`,
6
+ save: `${base}:connection:save`,
7
+ verify: `${base}:connection:verify`,
8
+ remove: `${base}:connection:remove`,
9
+ simulate: `${base}:connection:simulate`,
10
+ }),
11
+ rule: Object.freeze({
12
+ list: `${base}:rule:list`,
13
+ save: `${base}:rule:save`,
14
+ remove: `${base}:rule:remove`,
15
+ }),
16
+ activity: Object.freeze({ list: `${base}:activity:list` }),
17
+ });
18
+ const botHookAliases = (base) => Object.freeze({
19
+ base,
20
+ receive: `${base}:receive`,
21
+ challenge: `${base}:challenge`,
22
+ });
23
+ return { botAliases, botHookAliases };
24
+ };
25
+ export const botAliasUtils = createBotAliasUtils();
26
+ //# sourceMappingURL=aliases.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aliases.js","sourceRoot":"","sources":["../../src/utils/aliases.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAkB,EAAE;IACrD,MAAM,UAAU,GAAG,CAAC,IAAY,EAAc,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC;QAC7D,IAAI;QACJ,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC;YACxB,IAAI,EAAE,GAAG,IAAI,kBAAkB;YAC/B,IAAI,EAAE,GAAG,IAAI,kBAAkB;YAC/B,MAAM,EAAE,GAAG,IAAI,oBAAoB;YACnC,MAAM,EAAE,GAAG,IAAI,oBAAoB;YACnC,QAAQ,EAAE,GAAG,IAAI,sBAAsB;SACxC,CAAC;QACF,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC;YAClB,IAAI,EAAE,GAAG,IAAI,YAAY;YACzB,IAAI,EAAE,GAAG,IAAI,YAAY;YACzB,MAAM,EAAE,GAAG,IAAI,cAAc;SAC9B,CAAC;QACF,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,GAAG,IAAI,gBAAgB,EAAE,CAAC;KAC3D,CAAC,CAAA;IAEF,MAAM,cAAc,GAAG,CAAC,IAAY,EAAkB,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC;QACrE,IAAI;QACJ,OAAO,EAAE,GAAG,IAAI,UAAU;QAC1B,SAAS,EAAE,GAAG,IAAI,YAAY;KAC/B,CAAC,CAAA;IAEF,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,CAAA;AACvC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,mBAAmB,EAAE,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,44 @@
1
1
  {
2
2
  "name": "@owlmeans/bot",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.18-rc.2",
4
+ "license": "MIT",
5
+ "description": "Runtime-free, browser-safe contract of OwlMeans chat bots — platforms (Telegram, WhatsApp, Discord, Slack) and their descriptors, connections, keyword rules, normalized updates and activity, the Unicode-aware rule matcher and command parser, the operator/member and hook protocol trees with their AJV schemas, and the bot error family.",
6
+ "type": "module",
7
+ "scripts": {
8
+ "build": "tsc -b",
9
+ "dev": "sleep 2 && nodemon -e ts,tsx,json --watch src --exec \"tsc -p ./tsconfig.json\"",
10
+ "watch": "tsc -b -w --preserveWatchOutput --pretty",
11
+ "test": "bun test ./tests"
12
+ },
13
+ "main": "build/index.js",
14
+ "module": "build/index.js",
15
+ "types": "build/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "import": "./build/index.js",
19
+ "require": "./build/index.js",
20
+ "default": "./build/index.js",
21
+ "module": "./build/index.js",
22
+ "types": "./build/index.d.ts"
23
+ }
24
+ },
25
+ "dependencies": {
26
+ "@owlmeans/context": "^0.1.18-rc.35",
27
+ "@owlmeans/entrypoint": "^0.1.18-rc.42",
28
+ "@owlmeans/error": "^0.1.18-rc.39",
29
+ "@owlmeans/route": "^0.1.18-rc.36"
30
+ },
31
+ "peerDependencies": {
32
+ "ajv": "*"
33
+ },
34
+ "devDependencies": {
35
+ "@owlmeans/dep-config": "workspace:*",
36
+ "@types/bun": "^1.4.2",
37
+ "ajv": "^8.20.0",
38
+ "nodemon": "^3.1.14",
39
+ "typescript": "^7.0.2"
40
+ },
41
+ "publishConfig": {
42
+ "access": "public"
43
+ }
44
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * One token of `word` matching: letters, combining marks, digits and `_`. Marks are part of the word
3
+ * (Devanagari vowel signs, a decomposed accent left after folding), so a word never splits on one.
4
+ */
5
+ export const BOT_TOKEN_PATTERN = /[\p{L}\p{M}\p{N}_]+/gu
6
+
7
+ /** Any whitespace run — collapsed to one space before a `contains` comparison and in a stored keyword. */
8
+ export const BOT_SPACE_PATTERN = /\s+/gu
9
+
10
+ /**
11
+ * A `/command`, optionally addressed `@ToBot`, ending at whitespace or at the end of the text, then
12
+ * its arguments.
13
+ */
14
+ export const BOT_COMMAND_PATTERN = /^\/([\p{L}\p{N}_-]{1,64})(?:@([\p{L}\p{N}_.]{1,64}))?(?:\s+([\s\S]*))?$/u