@zlens/slack 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/NOTICE +5 -0
- package/dist/format.d.ts +19 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +74 -0
- package/dist/format.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/scope.d.ts +22 -0
- package/dist/scope.d.ts.map +1 -0
- package/dist/scope.js +49 -0
- package/dist/scope.js.map +1 -0
- package/dist/server.d.ts +33 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +268 -0
- package/dist/server.js.map +1 -0
- package/dist/signature.d.ts +27 -0
- package/dist/signature.d.ts.map +1 -0
- package/dist/signature.js +33 -0
- package/dist/signature.js.map +1 -0
- package/package.json +47 -3
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/dist/format.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format an `AgentAnswer` as a Slack response body.
|
|
3
|
+
*
|
|
4
|
+
* Returns Block Kit JSON for rich rendering when possible, with a `text`
|
|
5
|
+
* fallback for clients that don't honor blocks. Citations and the
|
|
6
|
+
* Certified/Uncertified badge are always present.
|
|
7
|
+
*/
|
|
8
|
+
import type { AgentAnswer } from '@zlens/agent';
|
|
9
|
+
interface SlackResponse {
|
|
10
|
+
response_type: 'in_channel' | 'ephemeral';
|
|
11
|
+
text: string;
|
|
12
|
+
blocks: Array<Record<string, unknown>>;
|
|
13
|
+
}
|
|
14
|
+
export declare function formatAnswerForSlack(answer: AgentAnswer, options?: {
|
|
15
|
+
question: string;
|
|
16
|
+
ephemeral?: boolean;
|
|
17
|
+
}): SlackResponse;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,UAAU,aAAa;IACrB,aAAa,EAAE,YAAY,GAAG,WAAW,CAAC;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACxC;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,WAAW,EACnB,OAAO,GAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAAqB,GACpE,aAAa,CAuEf"}
|
package/dist/format.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format an `AgentAnswer` as a Slack response body.
|
|
3
|
+
*
|
|
4
|
+
* Returns Block Kit JSON for rich rendering when possible, with a `text`
|
|
5
|
+
* fallback for clients that don't honor blocks. Citations and the
|
|
6
|
+
* Certified/Uncertified badge are always present.
|
|
7
|
+
*/
|
|
8
|
+
export function formatAnswerForSlack(answer, options = { question: '' }) {
|
|
9
|
+
const { question, ephemeral } = options;
|
|
10
|
+
const badge = answer.kind === 'certified'
|
|
11
|
+
? ':white_check_mark: *Certified*'
|
|
12
|
+
: answer.kind === 'uncertified'
|
|
13
|
+
? ':warning: *AI-generated · uncertified*'
|
|
14
|
+
: ':grey_question: *No answer*';
|
|
15
|
+
const blocks = [
|
|
16
|
+
{
|
|
17
|
+
type: 'section',
|
|
18
|
+
text: { type: 'mrkdwn', text: `${badge} — _${question}_` },
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
type: 'section',
|
|
22
|
+
text: { type: 'mrkdwn', text: answer.text || '_(no body)_' },
|
|
23
|
+
},
|
|
24
|
+
];
|
|
25
|
+
if (answer.proposedSql) {
|
|
26
|
+
blocks.push({
|
|
27
|
+
type: 'section',
|
|
28
|
+
text: { type: 'mrkdwn', text: '*Proposed SQL* (review before saving):' },
|
|
29
|
+
});
|
|
30
|
+
blocks.push({
|
|
31
|
+
type: 'rich_text',
|
|
32
|
+
elements: [
|
|
33
|
+
{
|
|
34
|
+
type: 'rich_text_preformatted',
|
|
35
|
+
elements: [{ type: 'text', text: answer.proposedSql }],
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
if (answer.citations.length > 0) {
|
|
41
|
+
const cite = answer.citations
|
|
42
|
+
.map((c) => `• \`${c.kind}:${c.name}\`${c.gitSha ? ` _(${c.gitSha.slice(0, 8)})_` : ''}`)
|
|
43
|
+
.join('\n');
|
|
44
|
+
blocks.push({
|
|
45
|
+
type: 'section',
|
|
46
|
+
text: { type: 'mrkdwn', text: `*Citations*\n${cite}` },
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
// Feedback action row
|
|
50
|
+
blocks.push({
|
|
51
|
+
type: 'actions',
|
|
52
|
+
block_id: 'dql_feedback',
|
|
53
|
+
elements: [
|
|
54
|
+
{
|
|
55
|
+
type: 'button',
|
|
56
|
+
text: { type: 'plain_text', text: ':+1: Helpful' },
|
|
57
|
+
value: JSON.stringify({ rating: 'up', question, blockId: answer.block?.nodeId }),
|
|
58
|
+
action_id: 'feedback_up',
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
type: 'button',
|
|
62
|
+
text: { type: 'plain_text', text: ':-1: Not helpful' },
|
|
63
|
+
value: JSON.stringify({ rating: 'down', question, blockId: answer.block?.nodeId }),
|
|
64
|
+
action_id: 'feedback_down',
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
});
|
|
68
|
+
return {
|
|
69
|
+
response_type: ephemeral ? 'ephemeral' : 'in_channel',
|
|
70
|
+
text: `${badge} ${answer.text}`.slice(0, 3000),
|
|
71
|
+
blocks,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAUH,MAAM,UAAU,oBAAoB,CAClC,MAAmB,EACnB,UAAqD,EAAE,QAAQ,EAAE,EAAE,EAAE;IAErE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IACxC,MAAM,KAAK,GACT,MAAM,CAAC,IAAI,KAAK,WAAW;QACzB,CAAC,CAAC,gCAAgC;QAClC,CAAC,CAAC,MAAM,CAAC,IAAI,KAAK,aAAa;YAC7B,CAAC,CAAC,wCAAwC;YAC1C,CAAC,CAAC,6BAA6B,CAAC;IAEtC,MAAM,MAAM,GAAmC;QAC7C;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,KAAK,OAAO,QAAQ,GAAG,EAAE;SAC3D;QACD;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,aAAa,EAAE;SAC7D;KACF,CAAC;IAEF,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;QACvB,MAAM,CAAC,IAAI,CAAC;YACV,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ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aACzB;YACD;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,kBAAkB,EAAE;gBACtD,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC;gBAClF,SAAS,EAAE,eAAe;aAC3B;SACF;KACF,CAAC,CAAC;IAEH,OAAO;QACL,aAAa,EAAE,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,YAAY;QACrD,IAAI,EAAE,GAAG,KAAK,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC;QAC9C,MAAM;KACP,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { startSlackServer } from './server.js';
|
|
2
|
+
export type { SlackServerOptions, RunningSlackServer } from './server.js';
|
|
3
|
+
export { verifySlackSignature } from './signature.js';
|
|
4
|
+
export { formatAnswerForSlack } from './format.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/scope.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SLACK IS A THIN TRANSPORT TO THE RUNTIME, WITH A SCOPE. A question may name
|
|
3
|
+
* its domain up front (`in growth: how many leads`, or `--domain growth how
|
|
4
|
+
* many leads`), a channel may default to one (`ZLENS_SLACK_DOMAIN_DEFAULTS`, a
|
|
5
|
+
* JSON map of channel id to domain), and the runtime resolves the envelope —
|
|
6
|
+
* the bot never does. The conversation is the channel: follow-ups in one
|
|
7
|
+
* channel reach the same thread the notebook would.
|
|
8
|
+
*/
|
|
9
|
+
export interface SlackAskScope {
|
|
10
|
+
question: string;
|
|
11
|
+
domain?: string;
|
|
12
|
+
purpose?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function parseSlackAskScope(text: string, options?: {
|
|
15
|
+
channelId?: string;
|
|
16
|
+
defaults?: Record<string, string>;
|
|
17
|
+
}): SlackAskScope;
|
|
18
|
+
/** The channel defaults, from a JSON map in the environment; malformed input is no default at all. */
|
|
19
|
+
export declare function slackDomainDefaults(raw: string | undefined): Record<string, string>;
|
|
20
|
+
/** One conversation per Slack channel. */
|
|
21
|
+
export declare function slackThreadId(channelId: string | undefined): string | undefined;
|
|
22
|
+
//# sourceMappingURL=scope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../src/scope.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAKD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAO,GAAG,aAAa,CAYvI;AAED,sGAAsG;AACtG,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CASnF;AAED,0CAA0C;AAC1C,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAE/E"}
|
package/dist/scope.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SLACK IS A THIN TRANSPORT TO THE RUNTIME, WITH A SCOPE. A question may name
|
|
3
|
+
* its domain up front (`in growth: how many leads`, or `--domain growth how
|
|
4
|
+
* many leads`), a channel may default to one (`ZLENS_SLACK_DOMAIN_DEFAULTS`, a
|
|
5
|
+
* JSON map of channel id to domain), and the runtime resolves the envelope —
|
|
6
|
+
* the bot never does. The conversation is the channel: follow-ups in one
|
|
7
|
+
* channel reach the same thread the notebook would.
|
|
8
|
+
*/
|
|
9
|
+
const LEADING_IN = /^in\s+([A-Za-z0-9_][A-Za-z0-9_.-]*)\s*:\s*([\s\S]+)$/i;
|
|
10
|
+
const FLAG = /(?:^|\s)--(domain|purpose)(?:=|\s+)([A-Za-z0-9_][A-Za-z0-9_.-]*)/gi;
|
|
11
|
+
export function parseSlackAskScope(text, options = {}) {
|
|
12
|
+
let question = text.trim();
|
|
13
|
+
let domain;
|
|
14
|
+
let purpose;
|
|
15
|
+
const leading = LEADING_IN.exec(question);
|
|
16
|
+
if (leading) {
|
|
17
|
+
domain = leading[1];
|
|
18
|
+
question = leading[2].trim();
|
|
19
|
+
}
|
|
20
|
+
question = question.replace(FLAG, (_match, flag, value) => {
|
|
21
|
+
if (flag.toLowerCase() === 'domain')
|
|
22
|
+
domain = value;
|
|
23
|
+
else
|
|
24
|
+
purpose = value;
|
|
25
|
+
return ' ';
|
|
26
|
+
}).replace(/\s+/g, ' ').trim();
|
|
27
|
+
if (!domain && options.channelId && options.defaults?.[options.channelId])
|
|
28
|
+
domain = options.defaults[options.channelId];
|
|
29
|
+
return { question, ...(domain ? { domain } : {}), ...(purpose ? { purpose } : {}) };
|
|
30
|
+
}
|
|
31
|
+
/** The channel defaults, from a JSON map in the environment; malformed input is no default at all. */
|
|
32
|
+
export function slackDomainDefaults(raw) {
|
|
33
|
+
if (!raw?.trim())
|
|
34
|
+
return {};
|
|
35
|
+
try {
|
|
36
|
+
const parsed = JSON.parse(raw);
|
|
37
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
38
|
+
return {};
|
|
39
|
+
return Object.fromEntries(Object.entries(parsed).filter(([, value]) => typeof value === 'string' && value.trim()).map(([key, value]) => [key, value.trim()]));
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return {};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** One conversation per Slack channel. */
|
|
46
|
+
export function slackThreadId(channelId) {
|
|
47
|
+
return channelId ? `slack:${channelId}` : undefined;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=scope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../src/scope.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH,MAAM,UAAU,GAAG,uDAAuD,CAAC;AAC3E,MAAM,IAAI,GAAG,oEAAoE,CAAC;AAElF,MAAM,UAAU,kBAAkB,CAAC,IAAY,EAAE,UAAqE,EAAE;IACtH,IAAI,QAAQ,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IAC3B,IAAI,MAA0B,CAAC;IAC/B,IAAI,OAA2B,CAAC;IAChC,MAAM,OAAO,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC1C,IAAI,OAAO,EAAE,CAAC;QAAC,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C,OAAO,CAAC,MAAiC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,EAAG,KAAgB,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IACvM,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED,0CAA0C;AAC1C,MAAM,UAAU,aAAa,CAAC,SAA6B;IACzD,OAAO,SAAS,CAAC,CAAC,CAAC,SAAS,SAAS,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AACtD,CAAC"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slack slash-command HTTP server.
|
|
3
|
+
*
|
|
4
|
+
* Listens on `127.0.0.1:<port>` and exposes:
|
|
5
|
+
* POST /slack/commands — slash command webhook (`/dql ask ...`, `/dql block ...`)
|
|
6
|
+
* POST /slack/actions — Block Kit interactivity (feedback button clicks)
|
|
7
|
+
*
|
|
8
|
+
* The server is intentionally minimal — no Express/Fastify dep. Slack expects
|
|
9
|
+
* a 200 within 3 seconds, so heavy work is offloaded behind a 200 ack via
|
|
10
|
+
* `response_url` (Slack delivers a one-shot URL with each command).
|
|
11
|
+
*
|
|
12
|
+
* Auth model: bot token (env `SLACK_BOT_TOKEN`) + signing secret
|
|
13
|
+
* (`SLACK_SIGNING_SECRET`). Real OAuth installation can be layered later.
|
|
14
|
+
*/
|
|
15
|
+
import { type ProviderName } from '@zlens/agent';
|
|
16
|
+
export interface SlackServerOptions {
|
|
17
|
+
/** Project root for the agent KG + Skills. */
|
|
18
|
+
projectRoot: string;
|
|
19
|
+
/** Slack signing secret. Required for production; tests can pass any string. */
|
|
20
|
+
signingSecret: string;
|
|
21
|
+
/** TCP port to bind. */
|
|
22
|
+
port?: number;
|
|
23
|
+
/** Optional override for the agent provider (claude/openai/gemini/ollama). */
|
|
24
|
+
provider?: ProviderName;
|
|
25
|
+
/** Skip signature verification (dev only). */
|
|
26
|
+
skipVerification?: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface RunningSlackServer {
|
|
29
|
+
port: number;
|
|
30
|
+
close(): Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
export declare function startSlackServer(opts: SlackServerOptions): Promise<RunningSlackServer>;
|
|
33
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,EAKL,KAAK,YAAY,EAClB,MAAM,cAAc,CAAC;AAMtB,MAAM,WAAW,kBAAkB;IACjC,8CAA8C;IAC9C,WAAW,EAAE,MAAM,CAAC;IACpB,gFAAgF;IAChF,aAAa,EAAE,MAAM,CAAC;IACtB,wBAAwB;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,8CAA8C;IAC9C,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA2B5F"}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slack slash-command HTTP server.
|
|
3
|
+
*
|
|
4
|
+
* Listens on `127.0.0.1:<port>` and exposes:
|
|
5
|
+
* POST /slack/commands — slash command webhook (`/dql ask ...`, `/dql block ...`)
|
|
6
|
+
* POST /slack/actions — Block Kit interactivity (feedback button clicks)
|
|
7
|
+
*
|
|
8
|
+
* The server is intentionally minimal — no Express/Fastify dep. Slack expects
|
|
9
|
+
* a 200 within 3 seconds, so heavy work is offloaded behind a 200 ack via
|
|
10
|
+
* `response_url` (Slack delivers a one-shot URL with each command).
|
|
11
|
+
*
|
|
12
|
+
* Auth model: bot token (env `SLACK_BOT_TOKEN`) + signing secret
|
|
13
|
+
* (`SLACK_SIGNING_SECRET`). Real OAuth installation can be layered later.
|
|
14
|
+
*/
|
|
15
|
+
import { createServer } from 'node:http';
|
|
16
|
+
import { URL } from 'node:url';
|
|
17
|
+
import { KGStore, defaultKgPath, pickProvider, } from '@zlens/agent';
|
|
18
|
+
import { verifySlackSignature } from './signature.js';
|
|
19
|
+
import { formatAnswerForSlack } from './format.js';
|
|
20
|
+
import { parseSlackAskScope, slackDomainDefaults, slackThreadId } from './scope.js';
|
|
21
|
+
import { readEnv } from '@zlens/core';
|
|
22
|
+
export async function startSlackServer(opts) {
|
|
23
|
+
const port = opts.port ?? 3479;
|
|
24
|
+
const kgPath = defaultKgPath(opts.projectRoot);
|
|
25
|
+
const provider = await pickProvider(opts.provider);
|
|
26
|
+
const server = createServer((req, res) => {
|
|
27
|
+
void handleRequest(req, res, opts, kgPath, provider).catch((err) => {
|
|
28
|
+
if (!res.headersSent) {
|
|
29
|
+
res.writeHead(500, { 'content-type': 'application/json' });
|
|
30
|
+
}
|
|
31
|
+
res.end(JSON.stringify({ error: err.message }));
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
await new Promise((resolve, reject) => {
|
|
35
|
+
server.once('error', reject);
|
|
36
|
+
server.listen(port, '127.0.0.1', () => resolve());
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
port,
|
|
40
|
+
close: () => new Promise((resolve, reject) => {
|
|
41
|
+
server.close((err) => (err ? reject(err) : resolve()));
|
|
42
|
+
}),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
async function handleRequest(req, res, opts, kgPath, provider) {
|
|
46
|
+
const url = new URL(req.url ?? '/', 'http://localhost');
|
|
47
|
+
if (req.method === 'GET' && url.pathname === '/health') {
|
|
48
|
+
res.writeHead(200, { 'content-type': 'application/json' });
|
|
49
|
+
res.end(JSON.stringify({ status: 'ok' }));
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (req.method !== 'POST') {
|
|
53
|
+
res.writeHead(405, { 'content-type': 'text/plain' });
|
|
54
|
+
res.end('Method not allowed');
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const rawBody = await readRaw(req);
|
|
58
|
+
if (!opts.skipVerification) {
|
|
59
|
+
const ts = headerOf(req, 'x-slack-request-timestamp') ?? '';
|
|
60
|
+
const sig = headerOf(req, 'x-slack-signature') ?? '';
|
|
61
|
+
const ok = verifySlackSignature({
|
|
62
|
+
signingSecret: opts.signingSecret,
|
|
63
|
+
timestamp: ts,
|
|
64
|
+
signature: sig,
|
|
65
|
+
body: rawBody,
|
|
66
|
+
});
|
|
67
|
+
if (!ok) {
|
|
68
|
+
res.writeHead(401, { 'content-type': 'text/plain' });
|
|
69
|
+
res.end('Bad signature');
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (url.pathname === '/slack/commands') {
|
|
74
|
+
return handleSlashCommand(rawBody, res, opts, kgPath, provider);
|
|
75
|
+
}
|
|
76
|
+
if (url.pathname === '/slack/actions') {
|
|
77
|
+
return handleAction(rawBody, res, kgPath);
|
|
78
|
+
}
|
|
79
|
+
res.writeHead(404, { 'content-type': 'text/plain' });
|
|
80
|
+
res.end('Not found');
|
|
81
|
+
}
|
|
82
|
+
async function handleSlashCommand(rawBody, res, opts, kgPath, provider) {
|
|
83
|
+
const params = new URLSearchParams(rawBody);
|
|
84
|
+
const command = params.get('command') ?? '';
|
|
85
|
+
const text = (params.get('text') ?? '').trim();
|
|
86
|
+
const userId = params.get('user_id') ?? '';
|
|
87
|
+
const userName = params.get('user_name') ?? userId;
|
|
88
|
+
const channelId = params.get('channel_id') ?? undefined;
|
|
89
|
+
const responseUrl = params.get('response_url') ?? '';
|
|
90
|
+
// Parse subcommand: `ask <question>` | `block <id>` | `<question>` (default = ask)
|
|
91
|
+
let sub = 'ask';
|
|
92
|
+
let arg = text;
|
|
93
|
+
const m = text.match(/^(ask|block|lineage)\s+([\s\S]+)$/i);
|
|
94
|
+
if (m) {
|
|
95
|
+
sub = m[1].toLowerCase();
|
|
96
|
+
arg = m[2];
|
|
97
|
+
}
|
|
98
|
+
// Acknowledge immediately so Slack doesn't time out.
|
|
99
|
+
res.writeHead(200, { 'content-type': 'application/json' });
|
|
100
|
+
res.end(JSON.stringify({
|
|
101
|
+
response_type: 'ephemeral',
|
|
102
|
+
text: `Working on it… (${sub})`,
|
|
103
|
+
}));
|
|
104
|
+
try {
|
|
105
|
+
const reply = await runDispatch(sub, arg, userName, kgPath, provider, channelId);
|
|
106
|
+
if (responseUrl) {
|
|
107
|
+
await postBack(responseUrl, reply);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
if (responseUrl) {
|
|
112
|
+
await postBack(responseUrl, {
|
|
113
|
+
response_type: 'ephemeral',
|
|
114
|
+
text: `Error: ${err.message}`,
|
|
115
|
+
blocks: [],
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
void command; // command name is logged for telemetry in real deploys
|
|
120
|
+
}
|
|
121
|
+
async function runDispatch(sub, arg, userName, kgPath, provider, channelId) {
|
|
122
|
+
if (sub === 'block') {
|
|
123
|
+
const kg = new KGStore(kgPath);
|
|
124
|
+
try {
|
|
125
|
+
const node = kg.getNode(`block:${arg}`) ?? kg.getNode(arg);
|
|
126
|
+
if (!node) {
|
|
127
|
+
return formatAnswerForSlack({ kind: 'no_answer', text: `Block "${arg}" not found in the KG.`, citations: [], considered: [] }, { question: `block ${arg}` });
|
|
128
|
+
}
|
|
129
|
+
return formatAnswerForSlack({
|
|
130
|
+
kind: node.status === 'certified' ? 'certified' : 'uncertified',
|
|
131
|
+
text: node.description ?? node.llmContext ?? '_(no description)_',
|
|
132
|
+
block: node,
|
|
133
|
+
citations: [{ nodeId: node.nodeId, kind: node.kind, name: node.name, gitSha: node.gitSha }],
|
|
134
|
+
considered: [],
|
|
135
|
+
}, { question: `block ${arg}` });
|
|
136
|
+
}
|
|
137
|
+
finally {
|
|
138
|
+
kg.close();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (sub === 'lineage') {
|
|
142
|
+
return formatAnswerForSlack({
|
|
143
|
+
kind: 'no_answer',
|
|
144
|
+
text: `Lineage rendering in Slack is coming soon. For now run \`zlens lineage --block ${arg}\` from the CLI.`,
|
|
145
|
+
citations: [],
|
|
146
|
+
considered: [],
|
|
147
|
+
}, { question: `lineage ${arg}` });
|
|
148
|
+
}
|
|
149
|
+
// Default: ask. The running ZLens runtime owns the answer (routing, the V2
|
|
150
|
+
// lane, the gates, trust); the bot is a thin transport to it, exactly as the
|
|
151
|
+
// MCP server is.
|
|
152
|
+
const scope = parseSlackAskScope(arg, { channelId, defaults: slackDomainDefaults(readEnv('ZLENS_SLACK_DOMAIN_DEFAULTS')) });
|
|
153
|
+
const result = await askRuntime(scope.question, userName, {
|
|
154
|
+
...(scope.domain ? { domain: scope.domain } : {}),
|
|
155
|
+
...(scope.purpose ? { purpose: scope.purpose } : {}),
|
|
156
|
+
threadId: slackThreadId(channelId),
|
|
157
|
+
});
|
|
158
|
+
return formatAnswerForSlack(result, { question: scope.question });
|
|
159
|
+
}
|
|
160
|
+
/** POST one question to the local runtime and adapt the run for the formatter. */
|
|
161
|
+
async function askRuntime(question, userName, scope = {}) {
|
|
162
|
+
const workspaceContext = { ...(scope.domain ? { domain: scope.domain } : {}), ...(scope.purpose ? { purpose: scope.purpose } : {}) };
|
|
163
|
+
const base = (readEnv('ZLENS_RUNTIME_URL') ?? 'http://127.0.0.1:3474').replace(/\/$/, '');
|
|
164
|
+
let response;
|
|
165
|
+
try {
|
|
166
|
+
response = await fetch(`${base}/api/agent-runs`, {
|
|
167
|
+
method: 'POST',
|
|
168
|
+
headers: { 'Content-Type': 'application/json' },
|
|
169
|
+
body: JSON.stringify({
|
|
170
|
+
question, requestedMode: 'auto', userId: userName,
|
|
171
|
+
...(scope.threadId ? { threadId: scope.threadId } : {}),
|
|
172
|
+
...(Object.keys(workspaceContext).length ? { workspaceContext } : {}),
|
|
173
|
+
}),
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
return {
|
|
178
|
+
kind: 'no_answer',
|
|
179
|
+
text: `The ZLens runtime at ${base} is not reachable (${error.message}). Start it with \`zlens serve\` or set ZLENS_RUNTIME_URL.`,
|
|
180
|
+
citations: [],
|
|
181
|
+
considered: [],
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
if (!response.ok) {
|
|
185
|
+
return { kind: 'no_answer', text: `ZLens runtime returned ${response.status}.`, citations: [], considered: [] };
|
|
186
|
+
}
|
|
187
|
+
const payload = (await response.json().catch(() => ({})));
|
|
188
|
+
const run = payload.run;
|
|
189
|
+
if (!run)
|
|
190
|
+
return { kind: 'no_answer', text: 'The runtime returned no run.', citations: [], considered: [] };
|
|
191
|
+
const proposedSql = run.artifacts?.map((artifact) => artifact.payload?.proposedSql ?? artifact.payload?.sql).find(Boolean);
|
|
192
|
+
const kind = run.status === 'completed'
|
|
193
|
+
? (run.trustState === 'certified' ? 'certified' : 'uncertified')
|
|
194
|
+
: run.status === 'needs_review'
|
|
195
|
+
? 'uncertified'
|
|
196
|
+
: 'no_answer';
|
|
197
|
+
return {
|
|
198
|
+
kind,
|
|
199
|
+
text: run.answer ?? run.summary ?? '',
|
|
200
|
+
citations: [],
|
|
201
|
+
considered: [],
|
|
202
|
+
...(proposedSql ? { proposedSql } : {}),
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
async function handleAction(rawBody, res, kgPath) {
|
|
206
|
+
// Slack sends `payload=<json>` for interactivity events.
|
|
207
|
+
const params = new URLSearchParams(rawBody);
|
|
208
|
+
const raw = params.get('payload') ?? '{}';
|
|
209
|
+
let payload;
|
|
210
|
+
try {
|
|
211
|
+
payload = JSON.parse(raw);
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
res.writeHead(400, { 'content-type': 'text/plain' });
|
|
215
|
+
res.end('Bad payload');
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const action = payload.actions?.[0];
|
|
219
|
+
if (action && (action.action_id === 'feedback_up' || action.action_id === 'feedback_down')) {
|
|
220
|
+
try {
|
|
221
|
+
const value = JSON.parse(action.value);
|
|
222
|
+
const kg = new KGStore(kgPath);
|
|
223
|
+
try {
|
|
224
|
+
kg.recordFeedback({
|
|
225
|
+
id: `slack_${Date.now().toString(36)}`,
|
|
226
|
+
ts: new Date().toISOString(),
|
|
227
|
+
user: payload.user?.username ?? payload.user?.id ?? 'slack',
|
|
228
|
+
question: value.question,
|
|
229
|
+
answerKind: value.blockId?.startsWith('block:') ? 'certified' : 'uncertified',
|
|
230
|
+
blockId: value.blockId,
|
|
231
|
+
rating: value.rating,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
finally {
|
|
235
|
+
kg.close();
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
catch {
|
|
239
|
+
// swallow — Slack doesn't need to know
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
res.writeHead(200, { 'content-type': 'text/plain' });
|
|
243
|
+
res.end('');
|
|
244
|
+
}
|
|
245
|
+
async function postBack(url, body) {
|
|
246
|
+
await fetch(url, {
|
|
247
|
+
method: 'POST',
|
|
248
|
+
headers: { 'content-type': 'application/json' },
|
|
249
|
+
body: JSON.stringify(body),
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
function readRaw(req) {
|
|
253
|
+
return new Promise((resolve, reject) => {
|
|
254
|
+
const chunks = [];
|
|
255
|
+
req.on('data', (c) => chunks.push(new Uint8Array(c)));
|
|
256
|
+
req.on('end', () => resolve(Buffer.concat(chunks).toString('utf-8')));
|
|
257
|
+
req.on('error', reject);
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
function headerOf(req, name) {
|
|
261
|
+
const v = req.headers[name];
|
|
262
|
+
if (typeof v === 'string')
|
|
263
|
+
return v;
|
|
264
|
+
if (Array.isArray(v))
|
|
265
|
+
return v[0] ?? null;
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,YAAY,EAA6C,MAAM,WAAW,CAAC;AACpF,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EACL,OAAO,EACP,aAAa,EACb,YAAY,GAGb,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACpF,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAoBtC,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,IAAwB;IAC7D,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC;IAE/B,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC/C,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAEnD,MAAM,MAAM,GAAG,YAAY,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QACvC,KAAK,aAAa,CAAC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L,CAAC;AAED,SAAS,OAAO,CAAC,GAAoB;IACnC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,MAAM,GAAiB,EAAE,CAAC;QAChC,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC9D,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACtE,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,QAAQ,CAAC,GAAoB,EAAE,IAAY;IAClD,MAAM,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,IAAI,OAAO,CAAC,KAAK,QAAQ;QAAE,OAAO,CAAC,CAAC;IACpC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QAAE,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;IAC1C,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slack request signature verification (https://api.slack.com/authentication/verifying-requests-from-slack).
|
|
3
|
+
*
|
|
4
|
+
* Slack signs each request with HMAC-SHA256 over `v0:<timestamp>:<rawBody>`
|
|
5
|
+
* using your app's signing secret. The signature lives in
|
|
6
|
+
* `x-slack-signature` and the timestamp in `x-slack-request-timestamp`.
|
|
7
|
+
*
|
|
8
|
+
* The verifier:
|
|
9
|
+
* - rejects requests older than 5 minutes (replay-prevention),
|
|
10
|
+
* - computes the HMAC and compares with the supplied digest,
|
|
11
|
+
* - returns `true` only if both pass.
|
|
12
|
+
*/
|
|
13
|
+
export interface VerifyOptions {
|
|
14
|
+
signingSecret: string;
|
|
15
|
+
/** ISO-8601 or unix-epoch seconds (Slack uses epoch seconds). */
|
|
16
|
+
timestamp: string;
|
|
17
|
+
/** Raw bytes (or string) of the POST body — NOT the parsed form. */
|
|
18
|
+
body: string;
|
|
19
|
+
/** Header value `x-slack-signature` (e.g. "v0=abc..."). */
|
|
20
|
+
signature: string;
|
|
21
|
+
/** Allowed clock skew in seconds. Default 300. */
|
|
22
|
+
toleranceSeconds?: number;
|
|
23
|
+
/** Override "now" for tests. */
|
|
24
|
+
now?: number;
|
|
25
|
+
}
|
|
26
|
+
export declare function verifySlackSignature(opts: VerifyOptions): boolean;
|
|
27
|
+
//# sourceMappingURL=signature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signature.d.ts","sourceRoot":"","sources":["../src/signature.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,MAAM,WAAW,aAAa;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,iEAAiE;IACjE,SAAS,EAAE,MAAM,CAAC;IAClB,oEAAoE;IACpE,IAAI,EAAE,MAAM,CAAC;IACb,2DAA2D;IAC3D,SAAS,EAAE,MAAM,CAAC;IAClB,kDAAkD;IAClD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gCAAgC;IAChC,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAkBjE"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slack request signature verification (https://api.slack.com/authentication/verifying-requests-from-slack).
|
|
3
|
+
*
|
|
4
|
+
* Slack signs each request with HMAC-SHA256 over `v0:<timestamp>:<rawBody>`
|
|
5
|
+
* using your app's signing secret. The signature lives in
|
|
6
|
+
* `x-slack-signature` and the timestamp in `x-slack-request-timestamp`.
|
|
7
|
+
*
|
|
8
|
+
* The verifier:
|
|
9
|
+
* - rejects requests older than 5 minutes (replay-prevention),
|
|
10
|
+
* - computes the HMAC and compares with the supplied digest,
|
|
11
|
+
* - returns `true` only if both pass.
|
|
12
|
+
*/
|
|
13
|
+
import { createHmac, timingSafeEqual } from 'node:crypto';
|
|
14
|
+
export function verifySlackSignature(opts) {
|
|
15
|
+
const { signingSecret, timestamp, body, signature, toleranceSeconds = 300 } = opts;
|
|
16
|
+
const ts = Number.parseInt(timestamp, 10);
|
|
17
|
+
if (!Number.isFinite(ts))
|
|
18
|
+
return false;
|
|
19
|
+
const now = opts.now ?? Math.floor(Date.now() / 1000);
|
|
20
|
+
if (Math.abs(now - ts) > toleranceSeconds)
|
|
21
|
+
return false;
|
|
22
|
+
const base = `v0:${timestamp}:${body}`;
|
|
23
|
+
const computed = `v0=${createHmac('sha256', signingSecret).update(base).digest('hex')}`;
|
|
24
|
+
if (computed.length !== signature.length)
|
|
25
|
+
return false;
|
|
26
|
+
try {
|
|
27
|
+
return timingSafeEqual(new Uint8Array(Buffer.from(computed)), new Uint8Array(Buffer.from(signature)));
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=signature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signature.js","sourceRoot":"","sources":["../src/signature.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAgB1D,MAAM,UAAU,oBAAoB,CAAC,IAAmB;IACtD,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,gBAAgB,GAAG,GAAG,EAAE,GAAG,IAAI,CAAC;IACnF,MAAM,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IAC1C,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;QAAE,OAAO,KAAK,CAAC;IACvC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IACtD,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,gBAAgB;QAAE,OAAO,KAAK,CAAC;IAExD,MAAM,IAAI,GAAG,MAAM,SAAS,IAAI,IAAI,EAAE,CAAC;IACvC,MAAM,QAAQ,GAAG,MAAM,UAAU,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;IACxF,IAAI,QAAQ,CAAC,MAAM,KAAK,SAAS,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IACvD,IAAI,CAAC;QACH,OAAO,eAAe,CACpB,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EACrC,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CACvC,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zlens/slack",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "ZLens Slack front-end: slash-command bot that answers via the block-first agent loop",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"LICENSE",
|
|
18
|
+
"NOTICE"
|
|
19
|
+
],
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/duckcode-ai-labs/zlens.git",
|
|
23
|
+
"directory": "packages/dql-slack"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://github.com/duckcode-ai-labs/zlens",
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/duckcode-ai-labs/zlens/issues"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@zlens/agent": "0.1.0",
|
|
34
|
+
"@zlens/core": "0.1.0",
|
|
35
|
+
"@zlens/project": "0.1.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/node": "^22.0.0",
|
|
39
|
+
"typescript": "^5.7.0",
|
|
40
|
+
"vitest": "^3.0.0"
|
|
41
|
+
},
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=20"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "rm -rf dist tsconfig.tsbuildinfo && tsc -b",
|
|
47
|
+
"test": "vitest run --passWithNoTests",
|
|
48
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo"
|
|
49
|
+
}
|
|
6
50
|
}
|
package/README.md
DELETED