managed-deepagents 0.4.0-dev.67 → 0.4.0-dev.69
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 +1 -1
- package/dist/channels/assistant-text.d.ts +7 -0
- package/dist/channels/assistant-text.d.ts.map +1 -0
- package/dist/channels/assistant-text.js +28 -0
- package/dist/channels/assistant-text.js.map +1 -0
- package/dist/channels/binding.d.ts +34 -0
- package/dist/channels/binding.d.ts.map +1 -0
- package/dist/channels/binding.js +67 -0
- package/dist/channels/binding.js.map +1 -0
- package/dist/channels/errors.d.ts +11 -0
- package/dist/channels/errors.d.ts.map +1 -0
- package/dist/channels/errors.js +25 -0
- package/dist/channels/errors.js.map +1 -0
- package/dist/channels/index.d.ts +19 -0
- package/dist/channels/index.d.ts.map +1 -0
- package/dist/channels/index.js +14 -0
- package/dist/channels/index.js.map +1 -0
- package/dist/channels/runtime.d.ts +40 -0
- package/dist/channels/runtime.d.ts.map +1 -0
- package/dist/channels/runtime.js +76 -0
- package/dist/channels/runtime.js.map +1 -0
- package/dist/channels/schedule-delivery.d.ts +67 -0
- package/dist/channels/schedule-delivery.d.ts.map +1 -0
- package/dist/channels/schedule-delivery.js +193 -0
- package/dist/channels/schedule-delivery.js.map +1 -0
- package/dist/channels/slack/define.d.ts +87 -0
- package/dist/channels/slack/define.d.ts.map +1 -0
- package/dist/channels/slack/define.js +141 -0
- package/dist/channels/slack/define.js.map +1 -0
- package/dist/channels/slack/http.d.ts +86 -0
- package/dist/channels/slack/http.d.ts.map +1 -0
- package/dist/channels/slack/http.js +441 -0
- package/dist/channels/slack/http.js.map +1 -0
- package/dist/channels/slack/index.d.ts +18 -0
- package/dist/channels/slack/index.d.ts.map +1 -0
- package/dist/channels/slack/index.js +13 -0
- package/dist/channels/slack/index.js.map +1 -0
- package/dist/channels/slack/normalize.d.ts +62 -0
- package/dist/channels/slack/normalize.d.ts.map +1 -0
- package/dist/channels/slack/normalize.js +320 -0
- package/dist/channels/slack/normalize.js.map +1 -0
- package/dist/channels/slack/source-thread.d.ts +34 -0
- package/dist/channels/slack/source-thread.d.ts.map +1 -0
- package/dist/channels/slack/source-thread.js +92 -0
- package/dist/channels/slack/source-thread.js.map +1 -0
- package/dist/channels/slack/transport.d.ts +48 -0
- package/dist/channels/slack/transport.d.ts.map +1 -0
- package/dist/channels/slack/transport.js +178 -0
- package/dist/channels/slack/transport.js.map +1 -0
- package/dist/channels/store.d.ts +51 -0
- package/dist/channels/store.d.ts.map +1 -0
- package/dist/channels/store.js +76 -0
- package/dist/channels/store.js.map +1 -0
- package/dist/channels/types.d.ts +116 -0
- package/dist/channels/types.d.ts.map +1 -0
- package/dist/channels/types.js +24 -0
- package/dist/channels/types.js.map +1 -0
- package/dist/identity/links.d.ts +62 -0
- package/dist/identity/links.d.ts.map +1 -0
- package/dist/identity/links.js +176 -0
- package/dist/identity/links.js.map +1 -0
- package/dist/identity/slack-connect-http.d.ts +21 -0
- package/dist/identity/slack-connect-http.d.ts.map +1 -0
- package/dist/identity/slack-connect-http.js +129 -0
- package/dist/identity/slack-connect-http.js.map +1 -0
- package/dist/identity/slack-oauth.d.ts +60 -0
- package/dist/identity/slack-oauth.d.ts.map +1 -0
- package/dist/identity/slack-oauth.js +193 -0
- package/dist/identity/slack-oauth.js.map +1 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/runtime/auth.d.ts +40 -0
- package/dist/runtime/auth.d.ts.map +1 -1
- package/dist/runtime/auth.js +123 -9
- package/dist/runtime/auth.js.map +1 -1
- package/dist/runtime/cors.d.ts +28 -0
- package/dist/runtime/cors.d.ts.map +1 -0
- package/dist/runtime/cors.js +92 -0
- package/dist/runtime/cors.js.map +1 -0
- package/dist/runtime/identity-http.d.ts +6 -0
- package/dist/runtime/identity-http.d.ts.map +1 -1
- package/dist/runtime/identity-http.js +90 -2
- package/dist/runtime/identity-http.js.map +1 -1
- package/dist/runtime/identity-runtime.d.ts +41 -1
- package/dist/runtime/identity-runtime.d.ts.map +1 -1
- package/dist/runtime/identity-runtime.js +142 -2
- package/dist/runtime/identity-runtime.js.map +1 -1
- package/dist/runtime/index.d.ts +3 -5
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +76 -209
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/langsmith-connector.d.ts.map +1 -1
- package/dist/runtime/langsmith-connector.js +4 -3
- package/dist/runtime/langsmith-connector.js.map +1 -1
- package/dist/runtime/managed-tools.d.ts +6 -0
- package/dist/runtime/managed-tools.d.ts.map +1 -1
- package/dist/runtime/managed-tools.js +10 -0
- package/dist/runtime/managed-tools.js.map +1 -1
- package/dist/runtime/memory/context-io.d.ts +5 -0
- package/dist/runtime/memory/context-io.d.ts.map +1 -0
- package/dist/runtime/memory/context-io.js +28 -0
- package/dist/runtime/memory/context-io.js.map +1 -0
- package/dist/runtime/memory/index.d.ts +8 -0
- package/dist/runtime/memory/index.d.ts.map +1 -0
- package/dist/runtime/memory/index.js +6 -0
- package/dist/runtime/memory/index.js.map +1 -0
- package/dist/runtime/memory/mounts.d.ts +38 -0
- package/dist/runtime/memory/mounts.d.ts.map +1 -0
- package/dist/runtime/memory/mounts.js +185 -0
- package/dist/runtime/memory/mounts.js.map +1 -0
- package/dist/runtime/memory/paths.d.ts +10 -0
- package/dist/runtime/memory/paths.d.ts.map +1 -0
- package/dist/runtime/memory/paths.js +50 -0
- package/dist/runtime/memory/paths.js.map +1 -0
- package/dist/runtime/memory/seed.d.ts +30 -0
- package/dist/runtime/memory/seed.d.ts.map +1 -0
- package/dist/runtime/memory/seed.js +185 -0
- package/dist/runtime/memory/seed.js.map +1 -0
- package/dist/runtime/memory/user-repo.d.ts +19 -0
- package/dist/runtime/memory/user-repo.d.ts.map +1 -0
- package/dist/runtime/memory/user-repo.js +57 -0
- package/dist/runtime/memory/user-repo.js.map +1 -0
- package/dist/runtime/types.d.ts +11 -2
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/schedules.d.ts +6 -3
- package/dist/schedules.d.ts.map +1 -1
- package/dist/schedules.js +22 -0
- package/dist/schedules.js.map +1 -1
- package/dist/types.d.ts +5 -12
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +15 -10
- package/dist/evals-run.d.ts +0 -3
- package/dist/evals-run.d.ts.map +0 -1
- package/dist/evals-run.js +0 -14
- package/dist/evals-run.js.map +0 -1
- package/dist/evals.d.ts +0 -238
- package/dist/evals.d.ts.map +0 -1
- package/dist/evals.js +0 -291
- package/dist/evals.js.map +0 -1
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schedule `deliverTo` auto-post after a cron-triggered agent run.
|
|
3
|
+
*
|
|
4
|
+
* Reads `configurable.mda_schedule.deliver_to` (compiled from defineSchedule)
|
|
5
|
+
* and posts the final assistant text to Slack when configured.
|
|
6
|
+
*
|
|
7
|
+
* Delivery only runs for managed cron invocations: compiled crons stamp both
|
|
8
|
+
* `metadata.mda_managed` / `metadata.mda_schedule` and
|
|
9
|
+
* `configurable.mda_schedule.name`. Ordinary HTTP invokes cannot forge that
|
|
10
|
+
* pair (and `mda_schedule` is a reserved configurable key).
|
|
11
|
+
*/
|
|
12
|
+
import { getConfig } from "@langchain/langgraph";
|
|
13
|
+
import { extractAssistantText } from "./assistant-text.js";
|
|
14
|
+
import { SLACK_BOT_TOKEN_ENV } from "./binding.js";
|
|
15
|
+
import { createSlackWebApiTransport } from "./slack/transport.js";
|
|
16
|
+
let scheduleMetadataForTests;
|
|
17
|
+
/** Override LangGraph run metadata resolution. Test-only. */
|
|
18
|
+
export function setScheduleMetadataForTests(loader) {
|
|
19
|
+
scheduleMetadataForTests = loader;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Read and normalize `configurable.mda_schedule.deliver_to` from a cron run.
|
|
23
|
+
* Accepts camelCase (TS compile) and snake_case (Python compile) shapes.
|
|
24
|
+
*/
|
|
25
|
+
export function readScheduleDeliverTo(configurable) {
|
|
26
|
+
const schedule = configurable?.mda_schedule;
|
|
27
|
+
if (!schedule || typeof schedule !== "object" || Array.isArray(schedule)) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
const record = schedule;
|
|
31
|
+
const raw = record.deliver_to ?? record.deliverTo;
|
|
32
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
const target = raw;
|
|
36
|
+
const channel = typeof target.channel === "string" ? target.channel.trim() : "";
|
|
37
|
+
if (!channel)
|
|
38
|
+
return undefined;
|
|
39
|
+
const toRaw = target.to;
|
|
40
|
+
if (!toRaw || typeof toRaw !== "object" || Array.isArray(toRaw)) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
const to = toRaw;
|
|
44
|
+
const destType = typeof to.type === "string" ? to.type : "";
|
|
45
|
+
const conversationId = (typeof to.conversationId === "string" && to.conversationId) ||
|
|
46
|
+
(typeof to.conversation_id === "string" && to.conversation_id) ||
|
|
47
|
+
"";
|
|
48
|
+
if (!conversationId.trim())
|
|
49
|
+
return undefined;
|
|
50
|
+
let normalizedTo;
|
|
51
|
+
if (destType === "provider_conversation") {
|
|
52
|
+
normalizedTo = {
|
|
53
|
+
type: "provider_conversation",
|
|
54
|
+
conversationId: conversationId.trim(),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
else if (destType === "provider_thread") {
|
|
58
|
+
const threadId = (typeof to.threadId === "string" && to.threadId) ||
|
|
59
|
+
(typeof to.thread_id === "string" && to.thread_id) ||
|
|
60
|
+
"";
|
|
61
|
+
if (!threadId.trim())
|
|
62
|
+
return undefined;
|
|
63
|
+
normalizedTo = {
|
|
64
|
+
type: "provider_thread",
|
|
65
|
+
conversationId: conversationId.trim(),
|
|
66
|
+
threadId: threadId.trim(),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
const autoPostRaw = target.autoPost ?? target.auto_post;
|
|
73
|
+
const autoPost = autoPostRaw === undefined ? true : Boolean(autoPostRaw);
|
|
74
|
+
return { channel, to: normalizedTo, autoPost };
|
|
75
|
+
}
|
|
76
|
+
/** Map a deliverTo destination onto a runtime channel address. */
|
|
77
|
+
export function addressFromDeliverTo(to) {
|
|
78
|
+
if (to.type === "provider_thread") {
|
|
79
|
+
return { conversationId: to.conversationId, threadId: to.threadId };
|
|
80
|
+
}
|
|
81
|
+
return { conversationId: to.conversationId };
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Post schedule result text to the configured channel. Soft-fails (logs) on
|
|
85
|
+
* missing token / provider errors so cron runs are not marked failed.
|
|
86
|
+
*/
|
|
87
|
+
export async function deliverScheduleResult(input) {
|
|
88
|
+
const text = input.replyText.trim();
|
|
89
|
+
if (!text || !input.deliverTo.autoPost) {
|
|
90
|
+
return "skipped";
|
|
91
|
+
}
|
|
92
|
+
// Phase 1: Slack only (channel id is file-derived name, typically "slack").
|
|
93
|
+
if (input.deliverTo.channel !== "slack") {
|
|
94
|
+
console.error(`[mda] schedule deliverTo channel "${input.deliverTo.channel}" is not supported yet`);
|
|
95
|
+
return "failed";
|
|
96
|
+
}
|
|
97
|
+
const address = addressFromDeliverTo(input.deliverTo.to);
|
|
98
|
+
if (input.post) {
|
|
99
|
+
try {
|
|
100
|
+
await input.post({
|
|
101
|
+
text,
|
|
102
|
+
conversationId: address.conversationId,
|
|
103
|
+
...(address.threadId ? { threadId: address.threadId } : {}),
|
|
104
|
+
});
|
|
105
|
+
return "posted";
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
console.error("[mda] schedule Slack delivery failed:", error);
|
|
109
|
+
return "failed";
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const botToken = input.botToken ?? process.env[SLACK_BOT_TOKEN_ENV] ?? "";
|
|
113
|
+
if (!botToken.trim()) {
|
|
114
|
+
console.error("[mda] schedule deliverTo requires SLACK_BOT_TOKEN; skipping auto-post");
|
|
115
|
+
return "failed";
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
const transport = createSlackWebApiTransport({ botToken });
|
|
119
|
+
await transport.post({
|
|
120
|
+
text,
|
|
121
|
+
conversationId: address.conversationId,
|
|
122
|
+
...(address.threadId ? { threadId: address.threadId } : {}),
|
|
123
|
+
});
|
|
124
|
+
return "posted";
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
console.error("[mda] schedule Slack delivery failed:", error);
|
|
128
|
+
return "failed";
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* True when this run is a managed cron fire (not a caller-forged HTTP invoke).
|
|
133
|
+
*/
|
|
134
|
+
export function isTrustedScheduleDeliveryRun(configurable) {
|
|
135
|
+
const schedule = configurable?.mda_schedule;
|
|
136
|
+
if (!schedule || typeof schedule !== "object" || Array.isArray(schedule)) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
const name = schedule.name;
|
|
140
|
+
if (typeof name !== "string" || !name.trim()) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
const metadata = resolveScheduleMetadata();
|
|
144
|
+
return (metadata?.mda_managed === true && metadata.mda_schedule === name.trim());
|
|
145
|
+
}
|
|
146
|
+
function resolveScheduleMetadata() {
|
|
147
|
+
if (scheduleMetadataForTests) {
|
|
148
|
+
return scheduleMetadataForTests();
|
|
149
|
+
}
|
|
150
|
+
try {
|
|
151
|
+
const metadata = getConfig().metadata;
|
|
152
|
+
if (metadata && typeof metadata === "object" && !Array.isArray(metadata)) {
|
|
153
|
+
return metadata;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
// Outside a runnable context (unit tests without the override).
|
|
158
|
+
}
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Always-on middleware that auto-posts schedule results when `deliver_to` is set
|
|
163
|
+
* on a trusted managed cron run.
|
|
164
|
+
*/
|
|
165
|
+
export function createScheduleDeliveryMiddleware(options) {
|
|
166
|
+
const deliver = options?.deliver ?? deliverScheduleResult;
|
|
167
|
+
return {
|
|
168
|
+
name: "mda-schedule-delivery",
|
|
169
|
+
async afterAgent(state, runtime) {
|
|
170
|
+
const configurable = runtime?.configurable &&
|
|
171
|
+
typeof runtime.configurable === "object" &&
|
|
172
|
+
!Array.isArray(runtime.configurable)
|
|
173
|
+
? runtime.configurable
|
|
174
|
+
: undefined;
|
|
175
|
+
if (!isTrustedScheduleDeliveryRun(configurable)) {
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
178
|
+
const deliverTo = readScheduleDeliverTo(configurable);
|
|
179
|
+
if (!deliverTo)
|
|
180
|
+
return undefined;
|
|
181
|
+
const messages = state &&
|
|
182
|
+
typeof state === "object" &&
|
|
183
|
+
!Array.isArray(state) &&
|
|
184
|
+
"messages" in state
|
|
185
|
+
? state.messages
|
|
186
|
+
: undefined;
|
|
187
|
+
const replyText = extractAssistantText({ messages });
|
|
188
|
+
await deliver({ deliverTo, replyText });
|
|
189
|
+
return undefined;
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=schedule-delivery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schedule-delivery.js","sourceRoot":"","sources":["../../src/channels/schedule-delivery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAIjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAGlE,IAAI,wBAES,CAAC;A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;gBACzB,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;gBACrB,UAAU,IAAI,KAAK;gBACjB,CAAC,CAAE,KAAgC,CAAC,QAAQ;gBAC5C,CAAC,CAAC,SAAS,CAAC;YAChB,MAAM,SAAS,GAAG,oBAAoB,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;YACrD,MAAM,OAAO,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,CAAC;YACxC,OAAO,SAAS,CAAC;QACnB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `defineSlackChannel` — declarative Slack channel authoring surface.
|
|
3
|
+
*
|
|
4
|
+
* Returns a validated declaration. Provider HTTP, OAuth, and Web API clients
|
|
5
|
+
* remain managed implementation details.
|
|
6
|
+
*/
|
|
7
|
+
import type { ChannelProvider, JsonValue } from "../types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Managed Slack triggers.
|
|
10
|
+
* Later phases may enable `slash_command` / `interaction`.
|
|
11
|
+
*/
|
|
12
|
+
export type SlackChannelTrigger = "app_mention" | "direct_message" | "thread_reply";
|
|
13
|
+
export type SlackMentionBehavior = "strip" | "preserve";
|
|
14
|
+
export type SlackConversationMapping = "thread" | "conversation" | "message";
|
|
15
|
+
export interface SlackChannelFilters {
|
|
16
|
+
includeConversations?: readonly string[];
|
|
17
|
+
excludeConversations?: readonly string[];
|
|
18
|
+
/** Fully-qualified mapped actor IDs such as `slack:T123:U456`. */
|
|
19
|
+
includeActors?: readonly string[];
|
|
20
|
+
excludeActors?: readonly string[];
|
|
21
|
+
/**
|
|
22
|
+
* Slack Connect shared conversations. Phase 1 rejects `true`.
|
|
23
|
+
* @default false
|
|
24
|
+
*/
|
|
25
|
+
allowSharedConversations?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface SlackConversationPolicy {
|
|
28
|
+
/** @default "thread" */
|
|
29
|
+
appMention?: SlackConversationMapping;
|
|
30
|
+
/** @default "conversation" */
|
|
31
|
+
directMessage?: SlackConversationMapping;
|
|
32
|
+
}
|
|
33
|
+
export interface SlackChannelConfig {
|
|
34
|
+
on: readonly SlackChannelTrigger[];
|
|
35
|
+
/** @default true */
|
|
36
|
+
autoReply?: boolean;
|
|
37
|
+
/** @default "strip" */
|
|
38
|
+
mentionBehavior?: SlackMentionBehavior;
|
|
39
|
+
filters?: SlackChannelFilters;
|
|
40
|
+
conversation?: SlackConversationPolicy;
|
|
41
|
+
}
|
|
42
|
+
/** Object exported from `channels/*.ts`. */
|
|
43
|
+
export interface SlackChannelDefinition {
|
|
44
|
+
readonly kind: "channel";
|
|
45
|
+
readonly provider: ChannelProvider;
|
|
46
|
+
readonly config: RequiredSlackChannelConfig;
|
|
47
|
+
}
|
|
48
|
+
/** Normalized config with defaults applied. */
|
|
49
|
+
export interface RequiredSlackChannelConfig {
|
|
50
|
+
on: readonly SlackChannelTrigger[];
|
|
51
|
+
autoReply: boolean;
|
|
52
|
+
mentionBehavior: SlackMentionBehavior;
|
|
53
|
+
filters: {
|
|
54
|
+
includeConversations?: readonly string[];
|
|
55
|
+
excludeConversations?: readonly string[];
|
|
56
|
+
includeActors?: readonly string[];
|
|
57
|
+
excludeActors?: readonly string[];
|
|
58
|
+
allowSharedConversations: boolean;
|
|
59
|
+
};
|
|
60
|
+
conversation: {
|
|
61
|
+
appMention: SlackConversationMapping;
|
|
62
|
+
directMessage: SlackConversationMapping;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/** Provider-neutral channel manifest emitted at compile/deploy time. */
|
|
66
|
+
export interface ChannelManifest {
|
|
67
|
+
name: string;
|
|
68
|
+
provider: ChannelProvider;
|
|
69
|
+
triggers: readonly SlackChannelTrigger[];
|
|
70
|
+
autoReply: boolean;
|
|
71
|
+
mentionBehavior: SlackMentionBehavior;
|
|
72
|
+
filters: RequiredSlackChannelConfig["filters"];
|
|
73
|
+
conversation: RequiredSlackChannelConfig["conversation"];
|
|
74
|
+
requiredScopes: readonly string[];
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Declare a managed Slack channel. Files under `channels/*.ts` export a named
|
|
78
|
+
* `channel` created with this helper.
|
|
79
|
+
*/
|
|
80
|
+
export declare function defineSlackChannel(config: SlackChannelConfig): SlackChannelDefinition;
|
|
81
|
+
/** Derive Slack OAuth scopes from enabled channel triggers. */
|
|
82
|
+
export declare function requiredSlackScopes(config: Pick<RequiredSlackChannelConfig, "on">): string[];
|
|
83
|
+
/** Build the compile/deploy channel manifest for a file-derived name. */
|
|
84
|
+
export declare function toChannelManifest(name: string, definition: SlackChannelDefinition): ChannelManifest;
|
|
85
|
+
/** @internal — re-export for manifest JSON typing. */
|
|
86
|
+
export type SlackChannelJsonValue = JsonValue;
|
|
87
|
+
//# sourceMappingURL=define.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define.d.ts","sourceRoot":"","sources":["../../../src/channels/slack/define.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE9D;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAC3B,aAAa,GACb,gBAAgB,GAChB,cAAc,CAAC;AAEnB,MAAM,MAAM,oBAAoB,GAAG,OAAO,GAAG,UAAU,CAAC;AAExD,MAAM,MAAM,wBAAwB,GAAG,QAAQ,GAAG,cAAc,GAAG,SAAS,CAAC;AAE7E,MAAM,WAAW,mBAAmB;IAClC,oBAAoB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACzC,oBAAoB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACzC,kEAAkE;IAClE,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,aAAa,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC;;;OAGG;IACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACpC;AAED,MAAM,W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AE,OAAO,CAAC;IACnB,eAAe,EAAE,oBAAoB,CAAC;IACtC,OAAO,EAAE,0BAA0B,CAAC,SAAS,CAAC,CAAC;IAC/C,YAAY,EAAE,0BAA0B,CAAC,cAAc,CAAC,CAAC;IACzD,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC;AAUD;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,kBAAkB,GACzB,sBAAsB,CAOxB;AAED,+DAA+D;AAC/D,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,IAAI,CAAC,0BAA0B,EAAE,IAAI,CAAC,GAC7C,MAAM,EAAE,CAeV;AAED,yEAAyE;AACzE,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,sBAAsB,GACjC,eAAe,CAWjB;AAwHD,sDAAsD;AACtD,MAAM,MAAM,qBAAqB,GAAG,SAAS,CAAC"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `defineSlackChannel` — declarative Slack channel authoring surface.
|
|
3
|
+
*
|
|
4
|
+
* Returns a validated declaration. Provider HTTP, OAuth, and Web API clients
|
|
5
|
+
* remain managed implementation details.
|
|
6
|
+
*/
|
|
7
|
+
const SUPPORTED_TRIGGERS = new Set([
|
|
8
|
+
"app_mention",
|
|
9
|
+
"direct_message",
|
|
10
|
+
"thread_reply",
|
|
11
|
+
]);
|
|
12
|
+
const MENTION_BEHAVIORS = new Set(["strip", "preserve"]);
|
|
13
|
+
const MAPPINGS = new Set(["thread", "conversation", "message"]);
|
|
14
|
+
/**
|
|
15
|
+
* Declare a managed Slack channel. Files under `channels/*.ts` export a named
|
|
16
|
+
* `channel` created with this helper.
|
|
17
|
+
*/
|
|
18
|
+
export function defineSlackChannel(config) {
|
|
19
|
+
const normalized = validateAndNormalize(config);
|
|
20
|
+
return {
|
|
21
|
+
kind: "channel",
|
|
22
|
+
provider: "slack",
|
|
23
|
+
config: normalized,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** Derive Slack OAuth scopes from enabled channel triggers. */
|
|
27
|
+
export function requiredSlackScopes(config) {
|
|
28
|
+
const scopes = new Set(["chat:write"]);
|
|
29
|
+
for (const trigger of config.on) {
|
|
30
|
+
if (trigger === "app_mention") {
|
|
31
|
+
scopes.add("app_mentions:read");
|
|
32
|
+
}
|
|
33
|
+
if (trigger === "direct_message") {
|
|
34
|
+
scopes.add("im:history");
|
|
35
|
+
}
|
|
36
|
+
if (trigger === "thread_reply") {
|
|
37
|
+
scopes.add("channels:history");
|
|
38
|
+
scopes.add("groups:history");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return [...scopes].sort();
|
|
42
|
+
}
|
|
43
|
+
/** Build the compile/deploy channel manifest for a file-derived name. */
|
|
44
|
+
export function toChannelManifest(name, definition) {
|
|
45
|
+
return {
|
|
46
|
+
name,
|
|
47
|
+
provider: definition.provider,
|
|
48
|
+
triggers: definition.config.on,
|
|
49
|
+
autoReply: definition.config.autoReply,
|
|
50
|
+
mentionBehavior: definition.config.mentionBehavior,
|
|
51
|
+
filters: definition.config.filters,
|
|
52
|
+
conversation: definition.config.conversation,
|
|
53
|
+
requiredScopes: requiredSlackScopes(definition.config),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function validateAndNormalize(config) {
|
|
57
|
+
if (config === null || typeof config !== "object") {
|
|
58
|
+
throw new Error("defineSlackChannel(...) requires a configuration object.");
|
|
59
|
+
}
|
|
60
|
+
if (!Array.isArray(config.on) || config.on.length === 0) {
|
|
61
|
+
throw new Error('defineSlackChannel(...) requires a non-empty `on` array of "app_mention", "direct_message", and/or "thread_reply".');
|
|
62
|
+
}
|
|
63
|
+
for (const trigger of config.on) {
|
|
64
|
+
if (!SUPPORTED_TRIGGERS.has(trigger)) {
|
|
65
|
+
throw new Error(`defineSlackChannel(...) does not support trigger "${String(trigger)}".`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const uniqueTriggers = [...new Set(config.on)];
|
|
69
|
+
const autoReply = config.autoReply ?? true;
|
|
70
|
+
if (typeof autoReply !== "boolean") {
|
|
71
|
+
throw new Error("defineSlackChannel(...) requires `autoReply` to be a boolean.");
|
|
72
|
+
}
|
|
73
|
+
const mentionBehavior = config.mentionBehavior ?? "strip";
|
|
74
|
+
if (!MENTION_BEHAVIORS.has(mentionBehavior)) {
|
|
75
|
+
throw new Error('defineSlackChannel(...) requires `mentionBehavior` to be "strip" or "preserve".');
|
|
76
|
+
}
|
|
77
|
+
const filters = normalizeFilters(config.filters);
|
|
78
|
+
const conversation = {
|
|
79
|
+
appMention: config.conversation?.appMention ?? "thread",
|
|
80
|
+
directMessage: config.conversation?.directMessage ?? "conversation",
|
|
81
|
+
};
|
|
82
|
+
if (!MAPPINGS.has(conversation.appMention)) {
|
|
83
|
+
throw new Error('defineSlackChannel(...) requires `conversation.appMention` to be "thread", "conversation", or "message".');
|
|
84
|
+
}
|
|
85
|
+
if (!MAPPINGS.has(conversation.directMessage)) {
|
|
86
|
+
throw new Error('defineSlackChannel(...) requires `conversation.directMessage` to be "thread", "conversation", or "message".');
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
on: uniqueTriggers,
|
|
90
|
+
autoReply,
|
|
91
|
+
mentionBehavior,
|
|
92
|
+
filters,
|
|
93
|
+
conversation,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function normalizeFilters(filters) {
|
|
97
|
+
if (filters === undefined) {
|
|
98
|
+
return { allowSharedConversations: false };
|
|
99
|
+
}
|
|
100
|
+
if (filters === null || typeof filters !== "object") {
|
|
101
|
+
throw new Error("defineSlackChannel(...) requires `filters` to be an object.");
|
|
102
|
+
}
|
|
103
|
+
const allowShared = filters.allowSharedConversations ?? false;
|
|
104
|
+
if (typeof allowShared !== "boolean") {
|
|
105
|
+
throw new Error("defineSlackChannel(...) requires `filters.allowSharedConversations` to be a boolean.");
|
|
106
|
+
}
|
|
107
|
+
// Phase 1 rejects Slack Connect.
|
|
108
|
+
if (allowShared) {
|
|
109
|
+
throw new Error("defineSlackChannel(...) rejects `filters.allowSharedConversations: true` in Phase 1.");
|
|
110
|
+
}
|
|
111
|
+
for (const key of [
|
|
112
|
+
"includeConversations",
|
|
113
|
+
"excludeConversations",
|
|
114
|
+
"includeActors",
|
|
115
|
+
"excludeActors",
|
|
116
|
+
]) {
|
|
117
|
+
const value = filters[key];
|
|
118
|
+
if (value === undefined)
|
|
119
|
+
continue;
|
|
120
|
+
if (!Array.isArray(value) ||
|
|
121
|
+
value.some((entry) => typeof entry !== "string" || entry.trim().length === 0)) {
|
|
122
|
+
throw new Error(`defineSlackChannel(...) requires \`filters.${key}\` to be an array of non-empty strings.`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
...(filters.includeConversations
|
|
127
|
+
? { includeConversations: [...filters.includeConversations] }
|
|
128
|
+
: {}),
|
|
129
|
+
...(filters.excludeConversations
|
|
130
|
+
? { excludeConversations: [...filters.excludeConversations] }
|
|
131
|
+
: {}),
|
|
132
|
+
...(filters.includeActors
|
|
133
|
+
? { includeActors: [...filters.includeActors] }
|
|
134
|
+
: {}),
|
|
135
|
+
...(filters.excludeActors
|
|
136
|
+
? { excludeActors: [...filters.excludeActors] }
|
|
137
|
+
: {}),
|
|
138
|
+
allowSharedConversations: false,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=define.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define.js","sourceRoot":"","sources":["../../../src/channels/slack/define.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAoFH,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAS;IACzC,aAAa;IACb,gBAAgB;IAChB,cAAc;CACf,CAAC,CAAC;AACH,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;AACzD,MAAM,QAAQ,GAAG,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KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;QAC3B,IAAI,KAAK,KAAK,SAAS;YAAE,SAAS;QAClC,IACE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;YACrB,KAAK,CAAC,IAAI,CACR,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,CAClE,EACD,CAAC;YACD,MAAM,IAAI,KAAK,CACb,8CAA8C,GAAG,yCAAyC,CAC3F,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO;QACL,GAAG,CAAC,OAAO,CAAC,oBAAoB;YAC9B,CAAC,CAAC,EAAE,oBAAoB,EAAE,CAAC,GAAG,OAAO,CAAC,oBAAoB,CAAC,EAAE;YAC7D,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,CAAC,OAAO,CAAC,oBAAoB;YAC9B,CAAC,CAAC,EAAE,oBAAoB,EAAE,CAAC,GAAG,OAAO,CAAC,oBAAoB,CAAC,EAAE;YAC7D,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,CAAC,OAAO,CAAC,aAAa;YACvB,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC,EAAE;YAC/C,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,CAAC,OAAO,CAAC,aAAa;YACvB,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,GAAG,OAAO,CAAC,aAAa,CAAC,EAAE;YAC/C,CAAC,CAAC,EAAE,CAAC;QACP,wBAAwB,EAAE,KAAK;KAChC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Managed Slack Events HTTP handler + agent runner.
|
|
3
|
+
*
|
|
4
|
+
* Verifies Slack signatures, normalizes Phase 1 events, acknowledges within the
|
|
5
|
+
* Slack 3s window, then invokes the graph over a trusted loopback and posts an
|
|
6
|
+
* auto-reply when needed.
|
|
7
|
+
*/
|
|
8
|
+
import { InMemoryChannelStore } from "../store.js";
|
|
9
|
+
import { type ChannelBinding } from "../binding.js";
|
|
10
|
+
import type { RequiredSlackChannelConfig } from "./define.js";
|
|
11
|
+
import { type SlackInstallationContext } from "./normalize.js";
|
|
12
|
+
import { type IdentityLinkStore } from "../../identity/links.js";
|
|
13
|
+
/** Env vars for Phase 1 single-workspace Slack install. */
|
|
14
|
+
export declare const SLACK_SIGNING_SECRET_ENV = "SLACK_SIGNING_SECRET";
|
|
15
|
+
export declare const SLACK_API_APP_ID_ENV = "SLACK_API_APP_ID";
|
|
16
|
+
export declare const SLACK_TEAM_ID_ENV = "SLACK_TEAM_ID";
|
|
17
|
+
export declare const SLACK_BOT_USER_ID_ENV = "SLACK_BOT_USER_ID";
|
|
18
|
+
/** Inputs for the `thread_reply` involvement probe (after identity remap). */
|
|
19
|
+
export interface SourceThreadExistsInput {
|
|
20
|
+
sourceThreadKey: string;
|
|
21
|
+
actorId: string;
|
|
22
|
+
tenantId?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface SlackChannelHttpConfig {
|
|
25
|
+
name: string;
|
|
26
|
+
config: RequiredSlackChannelConfig;
|
|
27
|
+
/** Override store (tests). */
|
|
28
|
+
store?: InMemoryChannelStore;
|
|
29
|
+
/** Override background scheduling (tests can run inline). */
|
|
30
|
+
schedule?: (work: () => Promise<void>) => void;
|
|
31
|
+
/** Override agent invoke (tests). */
|
|
32
|
+
invokeAgent?: typeof invokeChannelAgent;
|
|
33
|
+
/** Override installation/env resolution (tests). */
|
|
34
|
+
installation?: SlackInstallationContext;
|
|
35
|
+
signingSecret?: string;
|
|
36
|
+
botToken?: string;
|
|
37
|
+
deploymentId?: string;
|
|
38
|
+
assistantId?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Pre-read raw body. Prefer this when the HTTP framework may have already
|
|
41
|
+
* consumed `request` (the Hono mount passes `await c.req.text()`).
|
|
42
|
+
*/
|
|
43
|
+
rawBody?: string | Uint8Array;
|
|
44
|
+
/** Override identity link store (tests). */
|
|
45
|
+
linkStore?: IdentityLinkStore;
|
|
46
|
+
/**
|
|
47
|
+
* Override involvement check for `thread_reply` (tests). Defaults to probing
|
|
48
|
+
* whether an MDA thread already exists for the source-thread key under the
|
|
49
|
+
* resolved (post-link) actor.
|
|
50
|
+
*/
|
|
51
|
+
sourceThreadExists?: (input: SourceThreadExistsInput) => Promise<boolean>;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Handle `POST /channels/{name}/events` for a Slack Events API request.
|
|
55
|
+
*
|
|
56
|
+
* Always verifies the signature against the raw body before parsing JSON.
|
|
57
|
+
*/
|
|
58
|
+
export declare function handleSlackEventsRequest(request: Request, channel: SlackChannelHttpConfig): Promise<Response>;
|
|
59
|
+
export interface InvokeChannelAgentInput {
|
|
60
|
+
actorId: string;
|
|
61
|
+
tenantId?: string;
|
|
62
|
+
sourceThreadKey: string;
|
|
63
|
+
binding: ChannelBinding;
|
|
64
|
+
text: string;
|
|
65
|
+
assistantId: string;
|
|
66
|
+
}
|
|
67
|
+
export interface InvokeChannelAgentResult {
|
|
68
|
+
replyText: string;
|
|
69
|
+
runId?: string;
|
|
70
|
+
threadId: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* True when an MDA thread already exists for this Slack source-thread key.
|
|
74
|
+
* Used to gate `thread_reply` so unrelated channel threads are ignored.
|
|
75
|
+
*
|
|
76
|
+
* Call with the **resolved** actor (post Connect-with-Slack remap) so
|
|
77
|
+
* `threads: "actor"` ownership matches the thread created on the first run.
|
|
78
|
+
*/
|
|
79
|
+
export declare function channelSourceThreadExists(input: SourceThreadExistsInput): Promise<boolean>;
|
|
80
|
+
/**
|
|
81
|
+
* Invoke the managed graph over a trusted loopback with channel identity stamped.
|
|
82
|
+
*/
|
|
83
|
+
export declare function invokeChannelAgent(input: InvokeChannelAgentInput): Promise<InvokeChannelAgentResult>;
|
|
84
|
+
/** Deterministic LangGraph thread id from the Slack source-thread key. */
|
|
85
|
+
export declare function stableThreadId(sourceThreadKey: string): string;
|
|
86
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/channels/slack/http.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAGL,KAAK,cAAc,EAEpB,MAAM,eAAe,CAAC;AAGvB,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAGL,KAAK,wBAAwB,EAC9B,MAAM,gBAAgB,CAAC;AAQxB,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,yBAAyB,CAAC;AAcjC,2DAA2D;AAC3D,eAAO,MAAM,wBAAwB,yBAAyB,CAAC;AAC/D,eAAO,MAAM,oBAAoB,qBAAqB,CAAC;AACvD,eAAO,MAAM,iBAAiB,kBAAkB,CAAC;AACjD,eAAO,MAAM,qBAAqB,sBAAsB,CAAC;AAiBzD,8EAA8E;AAC9E,MAAM,WAAW,uBAAuB;IACtC,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,0BAA0B,CAAC;IACnC,8BAA8B;IAC9B,KAAK,CAAC,EAAE,oBAAoB,CAAC;IAC7B,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;IAC/C,qCAAqC;IACrC,WAAW,CAAC,EAAE,OAAO,kBAAkB,CAAC;IACxC,oDAAoD;IACpD,YAAY,CAAC,EAAE,wBAAwB,CAAC;IACxC,aAAa,CAAC,EAAE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