@cursor/july 0.1.95 → 0.1.96
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/AGENTS.md +3 -4
- package/dist/channels/deployments/types.d.ts +1 -1
- package/dist/channels/deployments/types.d.ts.map +1 -1
- package/dist/channels/deployments/types.js +1 -0
- package/dist/channels/origin/api.d.ts +59 -13
- package/dist/channels/origin/api.d.ts.map +1 -1
- package/dist/channels/origin/api.js +168 -27
- package/dist/channels/origin/binding.d.ts +2 -2
- package/dist/channels/origin/checks.d.ts +6 -6
- package/dist/channels/origin/checks.js +6 -6
- package/dist/channels/origin/cursor-account.d.ts +5 -3
- package/dist/channels/origin/cursor-account.d.ts.map +1 -1
- package/dist/channels/origin/cursor-account.js +5 -3
- package/dist/channels/slack/api.d.ts +9 -0
- package/dist/channels/slack/api.d.ts.map +1 -1
- package/dist/channels/slack/api.js +36 -5
- package/dist/channels/slack/defaults.d.ts.map +1 -1
- package/dist/channels/slack/defaults.js +17 -46
- package/dist/channels/slack/dispatch.d.ts +7 -1
- package/dist/channels/slack/dispatch.d.ts.map +1 -1
- package/dist/channels/slack/dispatch.js +47 -23
- package/dist/channels/slack/inbound.d.ts +8 -0
- package/dist/channels/slack/inbound.d.ts.map +1 -1
- package/dist/channels/slack/inbound.js +32 -0
- package/dist/channels/slack/live-delivery.d.ts +26 -29
- package/dist/channels/slack/live-delivery.d.ts.map +1 -1
- package/dist/channels/slack/live-delivery.js +172 -73
- package/dist/channels/slack/manifest.d.ts.map +1 -1
- package/dist/channels/slack/manifest.js +5 -1
- package/dist/channels/slack/nudge-carrier.d.ts +2 -0
- package/dist/channels/slack/nudge-carrier.d.ts.map +1 -1
- package/dist/channels/slack/nudge-carrier.js +48 -1
- package/dist/channels/slack/slack-channel.d.ts.map +1 -1
- package/dist/channels/slack/slack-channel.js +2 -2
- package/dist/docs/404.html +2 -2
- package/dist/docs/ab.html +4 -4
- package/dist/docs/assets/{app.BBj0klBO.js → app.jXleCmOc.js} +1 -1
- package/dist/docs/assets/chunks/@localSearchIndexroot.DFoGuETX.js +1 -0
- package/dist/docs/assets/chunks/{VPLocalSearchBox.CUEXpL78.js → VPLocalSearchBox.8LhyglIT.js} +1 -1
- package/dist/docs/assets/chunks/{theme.DabmQnia.js → theme.9ged-pr2.js} +2 -2
- package/dist/docs/assets/index.md.CI93Ltlb.js +5 -0
- package/dist/docs/assets/{index.md.BoHaMdeZ.lean.js → index.md.CI93Ltlb.lean.js} +1 -1
- package/dist/docs/assets/{reference_cli.md.BsMOxDvh.js → reference_cli.md.CCnG-nJx.js} +2 -1
- package/dist/docs/assets/templates_code-wiki.md.CDYZIBFN.js +2 -0
- package/dist/docs/assets/templates_code-wiki.md.CDYZIBFN.lean.js +1 -0
- package/dist/docs/building-with-agents.html +4 -4
- package/dist/docs/concepts.html +4 -4
- package/dist/docs/deployment.html +4 -4
- package/dist/docs/evals.html +4 -4
- package/dist/docs/guides/agent-to-agent.html +4 -4
- package/dist/docs/guides/cloud-runtime.html +4 -4
- package/dist/docs/guides/convert-automation.html +4 -4
- package/dist/docs/guides/github.html +4 -4
- package/dist/docs/guides/human-in-the-loop.html +4 -4
- package/dist/docs/guides/mcp-oauth.html +4 -4
- package/dist/docs/guides/opentelemetry.html +4 -4
- package/dist/docs/guides/slack.html +4 -4
- package/dist/docs/guides/webhooks.html +4 -4
- package/dist/docs/hashmap.json +1 -1
- package/dist/docs/hillclimbing.html +4 -4
- package/dist/docs/index.html +6 -6
- package/dist/docs/index.md +3 -1
- package/dist/docs/llms-full.txt +102 -3
- package/dist/docs/llms.txt +1 -0
- package/dist/docs/quickstart.html +4 -4
- package/dist/docs/reference/agent-config.html +4 -4
- package/dist/docs/reference/artifacts.html +4 -4
- package/dist/docs/reference/channels.html +4 -4
- package/dist/docs/reference/cli.html +7 -6
- package/dist/docs/reference/cli.md +3 -2
- package/dist/docs/reference/connections.html +4 -4
- package/dist/docs/reference/hooks.html +4 -4
- package/dist/docs/reference/http-api.html +4 -4
- package/dist/docs/reference/instructions.html +4 -4
- package/dist/docs/reference/playground.html +4 -4
- package/dist/docs/reference/project-layout.html +4 -4
- package/dist/docs/reference/prompt.html +4 -4
- package/dist/docs/reference/schedules.html +4 -4
- package/dist/docs/reference/sessions.html +4 -4
- package/dist/docs/reference/skills.html +4 -4
- package/dist/docs/reference/subagents.html +4 -4
- package/dist/docs/reference/tools.html +4 -4
- package/dist/docs/scaffolding-agents.html +4 -4
- package/dist/docs/storage.html +4 -4
- package/dist/docs/templates/agentic-owners.html +4 -4
- package/dist/docs/templates/code-wiki.html +28 -0
- package/dist/docs/templates/code-wiki.md +91 -0
- package/dist/docs/templates/demo.html +5 -5
- package/dist/docs/templates/pr-autofixer.html +4 -4
- package/dist/docs/templates/security-help.html +4 -4
- package/dist/docs/templates/security-reviewer.html +5 -5
- package/dist/docs/templates/triage.html +4 -4
- package/dist/docs/troubleshooting.html +4 -4
- package/dist/files-backends/cursor-hosted.d.ts +26 -4
- package/dist/files-backends/cursor-hosted.d.ts.map +1 -1
- package/dist/files-backends/cursor-hosted.js +32 -4
- package/dist/internal/advertise-tools.d.ts +2 -0
- package/dist/internal/advertise-tools.d.ts.map +1 -1
- package/dist/internal/advertise-tools.js +15 -1
- package/dist/internal/bounded.d.ts +7 -0
- package/dist/internal/bounded.d.ts.map +1 -0
- package/dist/internal/bounded.js +32 -0
- package/dist/internal/cli-deploy.d.ts.map +1 -1
- package/dist/internal/cli-deploy.js +7 -1
- package/dist/internal/conversation-mirror.d.ts +11 -8
- package/dist/internal/conversation-mirror.d.ts.map +1 -1
- package/dist/internal/conversation-mirror.js +116 -55
- package/dist/internal/cursor/backend-client.d.ts.map +1 -1
- package/dist/internal/cursor/backend-client.js +22 -48
- package/dist/internal/cursor/session-token.d.ts +45 -0
- package/dist/internal/cursor/session-token.d.ts.map +1 -0
- package/dist/internal/cursor/session-token.js +99 -0
- package/dist/internal/cursor-agent-template.d.ts +1 -1
- package/dist/internal/cursor-agent-template.d.ts.map +1 -1
- package/dist/internal/cursor-agent-template.js +1 -0
- package/dist/internal/framework-file-storage.d.ts +61 -0
- package/dist/internal/framework-file-storage.d.ts.map +1 -0
- package/dist/internal/framework-file-storage.js +204 -0
- package/dist/internal/framework-storage-selection.d.ts +11 -5
- package/dist/internal/framework-storage-selection.d.ts.map +1 -1
- package/dist/internal/framework-storage-selection.js +38 -11
- package/dist/internal/hosted-delivery.d.ts +7 -0
- package/dist/internal/hosted-delivery.d.ts.map +1 -1
- package/dist/internal/hosted-delivery.js +4 -0
- package/dist/internal/init-project.d.ts.map +1 -1
- package/dist/internal/init-project.js +2 -0
- package/dist/internal/install-cursor-skills.d.ts.map +1 -1
- package/dist/internal/install-cursor-skills.js +1 -3
- package/dist/internal/managed-delivery.d.ts +80 -0
- package/dist/internal/managed-delivery.d.ts.map +1 -0
- package/dist/internal/managed-delivery.js +86 -0
- package/dist/internal/runtime-dispatch-runner.d.ts +5 -1
- package/dist/internal/runtime-dispatch-runner.d.ts.map +1 -1
- package/dist/internal/runtime-dispatch-runner.js +7 -0
- package/dist/internal/sdk-runner.d.ts +11 -0
- package/dist/internal/sdk-runner.d.ts.map +1 -1
- package/dist/internal/sdk-runner.js +39 -8
- package/dist/internal/server.js +1 -0
- package/dist/internal/session-engine.d.ts +13 -0
- package/dist/internal/session-engine.d.ts.map +1 -1
- package/dist/internal/session-engine.js +62 -3
- package/dist/internal/steering.d.ts +15 -0
- package/dist/internal/steering.d.ts.map +1 -0
- package/dist/internal/steering.js +18 -0
- package/dist/playground/assets/index-B1DDvBeC.css +1 -0
- package/dist/playground/assets/{index-CZA1uEWA.js → index-Cx9CclK_.js} +51 -51
- package/dist/playground/index.html +2 -2
- package/dist/storage-backends/cursor-hosted.d.ts +8 -5
- package/dist/storage-backends/cursor-hosted.d.ts.map +1 -1
- package/dist/storage-backends/cursor-hosted.js +4 -3
- package/dist/types.d.ts +2 -1
- package/dist/types.d.ts.map +1 -1
- package/docs/README.md +3 -1
- package/docs/reference/cli.md +3 -2
- package/docs/templates/code-wiki.md +96 -0
- package/package.json +2 -2
- package/skills/ab/SKILL.md +13 -97
- package/skills/create-agent/SKILL.md +123 -223
- package/skills/debug/SKILL.md +34 -68
- package/skills/evals/SKILL.md +55 -180
- package/skills/framework-map/SKILL.md +83 -145
- package/skills/github/SKILL.md +53 -111
- package/skills/hillclimb/SKILL.md +40 -163
- package/skills/mcp-auth/SKILL.md +48 -107
- package/skills/otel/SKILL.md +22 -68
- package/skills/setup-slack/SKILL.md +77 -208
- package/src/channels/deployments/types.ts +1 -0
- package/src/channels/origin/api.ts +242 -30
- package/src/channels/origin/binding.ts +2 -2
- package/src/channels/origin/checks.ts +6 -6
- package/src/channels/origin/cursor-account.ts +5 -3
- package/src/channels/slack/api.ts +41 -5
- package/src/channels/slack/defaults.ts +15 -49
- package/src/channels/slack/dispatch.ts +56 -22
- package/src/channels/slack/inbound.ts +43 -0
- package/src/channels/slack/live-delivery.ts +235 -114
- package/src/channels/slack/manifest.ts +5 -1
- package/src/channels/slack/nudge-carrier.ts +48 -1
- package/src/channels/slack/slack-channel.ts +2 -0
- package/src/files-backends/cursor-hosted.ts +40 -7
- package/src/internal/advertise-tools.ts +18 -2
- package/src/internal/bounded.ts +28 -0
- package/src/internal/cli-deploy.ts +12 -0
- package/src/internal/conversation-mirror.ts +145 -69
- package/src/internal/cursor/backend-client.ts +34 -58
- package/src/internal/cursor/session-token.ts +115 -0
- package/src/internal/cursor-agent-template.ts +1 -0
- package/src/internal/framework-file-storage.ts +222 -0
- package/src/internal/framework-storage-selection.ts +51 -11
- package/src/internal/hosted-delivery.ts +10 -0
- package/src/internal/init-project.ts +2 -0
- package/src/internal/install-cursor-skills.ts +1 -4
- package/src/internal/managed-delivery.ts +125 -0
- package/src/internal/runtime-dispatch-runner.ts +10 -0
- package/src/internal/sdk-runner.ts +56 -8
- package/src/internal/server.ts +2 -0
- package/src/internal/session-engine.ts +64 -4
- package/src/internal/steering.ts +17 -0
- package/src/storage-backends/cursor-hosted.ts +9 -7
- package/src/types.ts +2 -1
- package/templates/code-wiki/README.md +34 -0
- package/templates/code-wiki/agent/agent.ts +8 -0
- package/templates/code-wiki/agent/channels/github.ts +144 -0
- package/templates/code-wiki/agent/instructions.md +39 -0
- package/templates/code-wiki/agent/lib/repos.ts +5 -0
- package/templates/code-wiki/agent/lib/wiki.ts +22 -0
- package/templates/code-wiki/agent/tools/apply_wiki.ts +219 -0
- package/templates/code-wiki/evals/evals.config.ts +5 -0
- package/templates/code-wiki/evals/wiki.eval.ts +132 -0
- package/templates/code-wiki/init.json +25 -0
- package/templates/code-wiki/package.json +18 -0
- package/templates/code-wiki/tsconfig.json +12 -0
- package/dist/docs/assets/chunks/@localSearchIndexroot.oqPawjiD.js +0 -1
- package/dist/docs/assets/index.md.BoHaMdeZ.js +0 -5
- package/dist/internal/deployment-scm-event-stream.d.ts +0 -116
- package/dist/internal/deployment-scm-event-stream.d.ts.map +0 -1
- package/dist/internal/deployment-scm-event-stream.js +0 -474
- package/dist/playground/assets/index-CF7hUDnQ.css +0 -1
- package/src/internal/deployment-scm-event-stream.ts +0 -593
- /package/dist/docs/assets/{reference_cli.md.BsMOxDvh.lean.js → reference_cli.md.CCnG-nJx.lean.js} +0 -0
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
normalizeIdentity,
|
|
10
10
|
} from "../../internal/continuation-identity.js";
|
|
11
11
|
import { routeLocalIngressContinuation } from "../../internal/local-ingress.js";
|
|
12
|
+
import { steeringEnabled } from "../../internal/steering.js";
|
|
12
13
|
import type {
|
|
13
14
|
ArtifactsApi,
|
|
14
15
|
HostContext,
|
|
@@ -16,7 +17,11 @@ import type {
|
|
|
16
17
|
SendMessageFn,
|
|
17
18
|
} from "../../types.js";
|
|
18
19
|
import { buildSlackBinding, slackContinuationKey } from "./api.js";
|
|
19
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
firstLineTitle,
|
|
22
|
+
maybeSetSuggestedPrompts,
|
|
23
|
+
maybeSetThreadTitle,
|
|
24
|
+
} from "./assistant.js";
|
|
20
25
|
import {
|
|
21
26
|
appendSlackAttachmentAnnotations,
|
|
22
27
|
prepareSlackAttachments,
|
|
@@ -33,6 +38,7 @@ import { isExternalSlackSender } from "./external-policy.js";
|
|
|
33
38
|
import {
|
|
34
39
|
formatSlackContextBlock,
|
|
35
40
|
parseAppMentionEvent,
|
|
41
|
+
parseAssistantThreadStarted,
|
|
36
42
|
parseChannelMessageEvent,
|
|
37
43
|
parseDirectMessageEvent,
|
|
38
44
|
parseReactionAddedEvent,
|
|
@@ -51,6 +57,7 @@ import type {
|
|
|
51
57
|
SlackDispatchDecision,
|
|
52
58
|
SlackMessage,
|
|
53
59
|
SlackMessageHandler,
|
|
60
|
+
SlackSuggestedPrompt,
|
|
54
61
|
} from "./types.js";
|
|
55
62
|
|
|
56
63
|
const FOLLOWUP_TYPING = "Saw your follow-up…";
|
|
@@ -167,6 +174,12 @@ export interface SlackInboundDispatchDeps extends SlackContinuationProbes {
|
|
|
167
174
|
* `false` to admit them (or when an upstream gate already refused them).
|
|
168
175
|
*/
|
|
169
176
|
blockExternals?: boolean;
|
|
177
|
+
/**
|
|
178
|
+
* Suggested prompts written on `assistant_thread_started` so the
|
|
179
|
+
* assistant pane is not blank before the first user message.
|
|
180
|
+
*/
|
|
181
|
+
suggestedPrompts?: SlackSuggestedPrompt[];
|
|
182
|
+
suggestedPromptsTitle?: string;
|
|
170
183
|
}
|
|
171
184
|
|
|
172
185
|
function triggeringMergeMessage(
|
|
@@ -529,27 +542,24 @@ export async function dispatchInboundMessage(args: {
|
|
|
529
542
|
continuation,
|
|
530
543
|
event_id: args.eventId,
|
|
531
544
|
});
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
:
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
continuation,
|
|
551
|
-
event_id: args.eventId,
|
|
552
|
-
});
|
|
545
|
+
if (!steeringEnabled()) {
|
|
546
|
+
try {
|
|
547
|
+
await args.host.slackNudges?.append({
|
|
548
|
+
continuationKey: continuation,
|
|
549
|
+
sourceTs: message.ts,
|
|
550
|
+
text: media.userText,
|
|
551
|
+
author: message.author?.userName,
|
|
552
|
+
});
|
|
553
|
+
} catch (nudgeError) {
|
|
554
|
+
log.warn("nudge append failed", {
|
|
555
|
+
error:
|
|
556
|
+
nudgeError instanceof Error
|
|
557
|
+
? nudgeError.message
|
|
558
|
+
: String(nudgeError),
|
|
559
|
+
continuation,
|
|
560
|
+
event_id: args.eventId,
|
|
561
|
+
});
|
|
562
|
+
}
|
|
553
563
|
}
|
|
554
564
|
try {
|
|
555
565
|
if (args.followUpStatus !== false) {
|
|
@@ -750,6 +760,30 @@ export function dispatchInboundFromEventBody(
|
|
|
750
760
|
return true;
|
|
751
761
|
}
|
|
752
762
|
|
|
763
|
+
const assistantThread = parseAssistantThreadStarted(body);
|
|
764
|
+
if (assistantThread !== null) {
|
|
765
|
+
const prompts = deps.suggestedPrompts ?? [];
|
|
766
|
+
log.info("assistant thread started", {
|
|
767
|
+
channel: assistantThread.channelId,
|
|
768
|
+
thread_ts: assistantThread.threadTs,
|
|
769
|
+
user: assistantThread.userId,
|
|
770
|
+
event_id: eventId,
|
|
771
|
+
});
|
|
772
|
+
if (prompts.length > 0) {
|
|
773
|
+
deps.waitUntil(
|
|
774
|
+
maybeSetSuggestedPrompts({
|
|
775
|
+
botToken: deps.credentials?.botToken,
|
|
776
|
+
channelId: assistantThread.channelId,
|
|
777
|
+
threadTs: assistantThread.threadTs,
|
|
778
|
+
prompts,
|
|
779
|
+
title: deps.suggestedPromptsTitle,
|
|
780
|
+
log,
|
|
781
|
+
})
|
|
782
|
+
);
|
|
783
|
+
}
|
|
784
|
+
return true;
|
|
785
|
+
}
|
|
786
|
+
|
|
753
787
|
if (deps.channelWatch !== undefined) {
|
|
754
788
|
// Parse keeps bot-authored posts; the watcher enforces the per-channel
|
|
755
789
|
// policy (includeBotPosts, own-post loop safety) with skip logging.
|
|
@@ -121,6 +121,49 @@ export function parseAppMentionEvent(
|
|
|
121
121
|
return delegation === undefined ? message : { ...message, delegation };
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
export interface SlackAssistantThreadStarted {
|
|
125
|
+
channelId: string;
|
|
126
|
+
threadTs: string;
|
|
127
|
+
userId?: string;
|
|
128
|
+
teamId?: string;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Slack fires this when a user opens the assistant pane. No model turn. */
|
|
132
|
+
export function parseAssistantThreadStarted(
|
|
133
|
+
body: unknown
|
|
134
|
+
): SlackAssistantThreadStarted | null {
|
|
135
|
+
const root = asRecord(body);
|
|
136
|
+
if (root === null || root.type !== "event_callback") {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
const event = asRecord(root.event);
|
|
140
|
+
if (event === null || event.type !== "assistant_thread_started") {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
const thread = asRecord(event.assistant_thread);
|
|
144
|
+
if (thread === null) {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
const channelId = asString(thread.channel_id);
|
|
148
|
+
const threadTs = asString(thread.thread_ts);
|
|
149
|
+
if (
|
|
150
|
+
channelId === undefined ||
|
|
151
|
+
channelId === "" ||
|
|
152
|
+
threadTs === undefined ||
|
|
153
|
+
threadTs === ""
|
|
154
|
+
) {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
const userId = asString(thread.user_id);
|
|
158
|
+
const teamId = asString(root.team_id) ?? asString(event.team_id);
|
|
159
|
+
return {
|
|
160
|
+
channelId,
|
|
161
|
+
threadTs,
|
|
162
|
+
userId: userId === undefined || userId === "" ? undefined : userId,
|
|
163
|
+
teamId: teamId === undefined || teamId === "" ? undefined : teamId,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
124
167
|
/**
|
|
125
168
|
* Parse DM / IM messages. More generous than a strict channel_type check:
|
|
126
169
|
* accepts `channel_type === "im"` or channel ids starting with `D`, and
|
|
@@ -4,12 +4,16 @@
|
|
|
4
4
|
* Cursor-account channels do not use this path — they reply with a single
|
|
5
5
|
* final `chat.postMessage` and put thinking on `assistant.threads.setStatus`
|
|
6
6
|
* (no message edits).
|
|
7
|
+
*
|
|
8
|
+
* Assistant-pane threads only render stream APIs. Start lazily with the
|
|
9
|
+
* first real markdown/chunks plus recipient ids — empty startStream is
|
|
10
|
+
* rejected or never attaches.
|
|
7
11
|
*/
|
|
8
12
|
|
|
9
13
|
import type { ChannelEventContext } from "../../types.js";
|
|
10
14
|
import { appendChatStream, startChatStream, stopChatStream } from "./api.js";
|
|
11
15
|
import type { SlackLog } from "./log.js";
|
|
12
|
-
import { computeStreamAppend } from "./stream.js";
|
|
16
|
+
import { computeStreamAppend, type StreamTaskChunk } from "./stream.js";
|
|
13
17
|
import type { SlackBotToken, SlackChannelState } from "./types.js";
|
|
14
18
|
|
|
15
19
|
type SlackChannel = ChannelEventContext<SlackChannelState>;
|
|
@@ -19,96 +23,195 @@ export interface LiveDeliveryDeps {
|
|
|
19
23
|
getLog: () => SlackLog;
|
|
20
24
|
}
|
|
21
25
|
|
|
26
|
+
type OpenArgs = {
|
|
27
|
+
channel: SlackChannel;
|
|
28
|
+
channelId: string;
|
|
29
|
+
threadTs: string;
|
|
30
|
+
sessionId: string;
|
|
31
|
+
markdown_text?: string;
|
|
32
|
+
chunks?: StreamTaskChunk[];
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
type StreamArgs = {
|
|
36
|
+
channel: SlackChannel;
|
|
37
|
+
channelId: string;
|
|
38
|
+
sessionId: string;
|
|
39
|
+
};
|
|
40
|
+
|
|
22
41
|
/**
|
|
23
42
|
* How the default handlers deliver an in-progress reply. Methods write live
|
|
24
43
|
* delivery state (`streamTs`, `streamChannelId`, `lastPostedText`,
|
|
25
44
|
* `streamingUnavailable`) on `channel.state` directly.
|
|
26
45
|
*/
|
|
27
46
|
export interface LiveDeliveryStrategy {
|
|
28
|
-
/** True when tool-call thinking steps can be appended to the live message. */
|
|
29
47
|
readonly inlineToolSteps: boolean;
|
|
30
|
-
/** Open the live message
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}): Promise<void>;
|
|
37
|
-
/** Push the latest cumulative text to the live message (throttled). */
|
|
38
|
-
append(args: {
|
|
39
|
-
channel: SlackChannel;
|
|
40
|
-
channelId: string;
|
|
41
|
-
streamTs: string;
|
|
42
|
-
text: string;
|
|
43
|
-
sessionId: string;
|
|
44
|
-
}): Promise<void>;
|
|
48
|
+
/** Open the live message with the first real markdown or task chunks. */
|
|
49
|
+
open(args: OpenArgs): Promise<boolean>;
|
|
50
|
+
append(args: StreamArgs & { text: string }): Promise<void>;
|
|
51
|
+
appendChunks(
|
|
52
|
+
args: StreamArgs & { chunks: StreamTaskChunk[] }
|
|
53
|
+
): Promise<boolean>;
|
|
45
54
|
/**
|
|
46
55
|
* Flush the final reply text. `delivered` is false only when the caller must
|
|
47
56
|
* post the full reply as a fresh message (finalize failed on partial text).
|
|
48
57
|
*/
|
|
49
|
-
finalize(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
text: string;
|
|
54
|
-
sessionId: string;
|
|
55
|
-
}): Promise<{ delivered: boolean }>;
|
|
56
|
-
/** Close the live message when the turn produced no final text. */
|
|
57
|
-
finalizeEmpty(args: {
|
|
58
|
-
channel: SlackChannel;
|
|
59
|
-
channelId: string;
|
|
60
|
-
streamTs: string;
|
|
61
|
-
}): Promise<void>;
|
|
62
|
-
/** Best-effort remove a live message left open after the turn ended. */
|
|
58
|
+
finalize(
|
|
59
|
+
args: StreamArgs & { text: string }
|
|
60
|
+
): Promise<{ delivered: boolean }>;
|
|
61
|
+
finalizeEmpty(args: { channel: SlackChannel }): Promise<void>;
|
|
63
62
|
cleanupOrphan(args: { channel: SlackChannel }): Promise<void>;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
63
|
+
fail(
|
|
64
|
+
args: StreamArgs & { errorText: string }
|
|
65
|
+
): Promise<{ delivered: boolean }>;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function streamRecipients(channel: SlackChannel): {
|
|
69
|
+
recipient_user_id: string | undefined;
|
|
70
|
+
recipient_team_id: string | undefined;
|
|
71
|
+
} {
|
|
72
|
+
const user = channel.state.triggeringUserId;
|
|
73
|
+
const team = channel.state.teamId;
|
|
74
|
+
return {
|
|
75
|
+
recipient_user_id: user === null || user === "" ? undefined : user,
|
|
76
|
+
recipient_team_id: team === null || team === "" ? undefined : team,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function activeStreamTs(channel: SlackChannel): string | null {
|
|
81
|
+
const ts = channel.state.streamTs;
|
|
82
|
+
return ts === null || ts === "" ? null : ts;
|
|
72
83
|
}
|
|
73
84
|
|
|
74
85
|
export function createStreamDeliveryStrategy(
|
|
75
86
|
deps: LiveDeliveryDeps
|
|
76
87
|
): LiveDeliveryStrategy {
|
|
77
88
|
const { botToken, getLog } = deps;
|
|
78
|
-
return {
|
|
79
|
-
inlineToolSteps: true,
|
|
80
89
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
90
|
+
const open: LiveDeliveryStrategy["open"] = async ({
|
|
91
|
+
channel,
|
|
92
|
+
channelId,
|
|
93
|
+
threadTs,
|
|
94
|
+
sessionId,
|
|
95
|
+
markdown_text,
|
|
96
|
+
chunks,
|
|
97
|
+
}) => {
|
|
98
|
+
if (activeStreamTs(channel) !== null) {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
const hasMarkdown = markdown_text !== undefined && markdown_text !== "";
|
|
102
|
+
const hasChunks = chunks !== undefined && chunks.length > 0;
|
|
103
|
+
if (!hasMarkdown && !hasChunks) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
const log = getLog();
|
|
107
|
+
const started = await startChatStream({
|
|
108
|
+
botToken,
|
|
109
|
+
channel: channelId,
|
|
110
|
+
thread_ts: threadTs,
|
|
111
|
+
markdown_text: hasMarkdown ? markdown_text : undefined,
|
|
112
|
+
chunks: hasChunks ? chunks : undefined,
|
|
113
|
+
...streamRecipients(channel),
|
|
114
|
+
});
|
|
115
|
+
if (!started.ok) {
|
|
116
|
+
log.warn("chat.startStream unavailable", {
|
|
117
|
+
error: started.error,
|
|
85
118
|
channel: channelId,
|
|
86
119
|
thread_ts: threadTs,
|
|
87
|
-
markdown_text: "",
|
|
88
|
-
});
|
|
89
|
-
if (!started.ok) {
|
|
90
|
-
log.warn("chat.startStream unavailable", {
|
|
91
|
-
error: started.error,
|
|
92
|
-
channel: channelId,
|
|
93
|
-
thread_ts: threadTs,
|
|
94
|
-
session: sessionId,
|
|
95
|
-
});
|
|
96
|
-
if (started.unsupported === true) {
|
|
97
|
-
channel.state.streamingUnavailable = true;
|
|
98
|
-
}
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
channel.state.streamTs = started.ts;
|
|
102
|
-
channel.state.streamChannelId = started.channel;
|
|
103
|
-
channel.state.lastPostedText = "";
|
|
104
|
-
log.info("chat.startStream ok", {
|
|
105
|
-
channel: started.channel,
|
|
106
|
-
stream_ts: started.ts,
|
|
107
120
|
session: sessionId,
|
|
108
121
|
});
|
|
109
|
-
|
|
122
|
+
if (started.unsupported === true) {
|
|
123
|
+
channel.state.streamingUnavailable = true;
|
|
124
|
+
}
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
channel.state.streamTs = started.ts;
|
|
128
|
+
channel.state.streamChannelId = started.channel;
|
|
129
|
+
channel.state.lastPostedText = hasMarkdown ? (markdown_text ?? "") : "";
|
|
130
|
+
log.info("chat.startStream ok", {
|
|
131
|
+
channel: started.channel,
|
|
132
|
+
stream_ts: started.ts,
|
|
133
|
+
session: sessionId,
|
|
134
|
+
});
|
|
135
|
+
return true;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const ensureOpen = async (
|
|
139
|
+
args: StreamArgs & {
|
|
140
|
+
markdown_text?: string;
|
|
141
|
+
chunks?: StreamTaskChunk[];
|
|
142
|
+
}
|
|
143
|
+
): Promise<string | null> => {
|
|
144
|
+
const existing = activeStreamTs(args.channel);
|
|
145
|
+
if (existing !== null) {
|
|
146
|
+
return existing;
|
|
147
|
+
}
|
|
148
|
+
const threadTs = args.channel.state.threadTs;
|
|
149
|
+
if (threadTs === null || threadTs === "") {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
const opened = await open({
|
|
153
|
+
channel: args.channel,
|
|
154
|
+
channelId: args.channelId,
|
|
155
|
+
threadTs,
|
|
156
|
+
sessionId: args.sessionId,
|
|
157
|
+
markdown_text: args.markdown_text,
|
|
158
|
+
chunks: args.chunks,
|
|
159
|
+
});
|
|
160
|
+
return opened ? activeStreamTs(args.channel) : null;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const stopWithSuffix = async (args: {
|
|
164
|
+
channel: SlackChannel;
|
|
165
|
+
channelId: string;
|
|
166
|
+
ts: string;
|
|
167
|
+
text: string;
|
|
168
|
+
}): Promise<{ ok: boolean; error?: string }> => {
|
|
169
|
+
const appendText = computeStreamAppend(
|
|
170
|
+
args.channel.state.lastPostedText,
|
|
171
|
+
args.text
|
|
172
|
+
);
|
|
173
|
+
const stopped = await stopChatStream({
|
|
174
|
+
botToken,
|
|
175
|
+
channel: args.channelId,
|
|
176
|
+
ts: args.ts,
|
|
177
|
+
markdown_text: appendText === "" ? undefined : appendText,
|
|
178
|
+
});
|
|
179
|
+
args.channel.state.streamTs = null;
|
|
180
|
+
if (stopped.ok) {
|
|
181
|
+
args.channel.state.lastPostedText = args.text;
|
|
182
|
+
args.channel.state.lastBotMessageTs = args.ts;
|
|
183
|
+
return { ok: true };
|
|
184
|
+
}
|
|
185
|
+
if (stopped.unsupported === true) {
|
|
186
|
+
args.channel.state.streamingUnavailable = true;
|
|
187
|
+
}
|
|
188
|
+
return { ok: false, error: stopped.error };
|
|
189
|
+
};
|
|
110
190
|
|
|
111
|
-
|
|
191
|
+
const closeOrphan = async (channel: SlackChannel): Promise<void> => {
|
|
192
|
+
const orphanTs = activeStreamTs(channel);
|
|
193
|
+
const channelId = channel.state.streamChannelId ?? channel.state.channelId;
|
|
194
|
+
if (orphanTs === null || channelId === null || channelId === "") {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
await stopChatStream({ botToken, channel: channelId, ts: orphanTs });
|
|
198
|
+
channel.state.streamTs = null;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
return {
|
|
202
|
+
inlineToolSteps: true,
|
|
203
|
+
open,
|
|
204
|
+
|
|
205
|
+
async append({ channel, channelId, text, sessionId }) {
|
|
206
|
+
const ts = await ensureOpen({
|
|
207
|
+
channel,
|
|
208
|
+
channelId,
|
|
209
|
+
sessionId,
|
|
210
|
+
markdown_text: text,
|
|
211
|
+
});
|
|
212
|
+
if (ts === null) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
112
215
|
const appendText = computeStreamAppend(
|
|
113
216
|
channel.state.lastPostedText,
|
|
114
217
|
text
|
|
@@ -119,14 +222,14 @@ export function createStreamDeliveryStrategy(
|
|
|
119
222
|
const result = await appendChatStream({
|
|
120
223
|
botToken,
|
|
121
224
|
channel: channelId,
|
|
122
|
-
ts
|
|
225
|
+
ts,
|
|
123
226
|
markdown_text: appendText,
|
|
124
227
|
});
|
|
125
228
|
if (!result.ok) {
|
|
126
229
|
getLog().warn("appendStream failed", {
|
|
127
230
|
error: result.error,
|
|
128
231
|
channel: channelId,
|
|
129
|
-
stream_ts:
|
|
232
|
+
stream_ts: ts,
|
|
130
233
|
session: sessionId,
|
|
131
234
|
});
|
|
132
235
|
if (result.unsupported === true) {
|
|
@@ -137,26 +240,50 @@ export function createStreamDeliveryStrategy(
|
|
|
137
240
|
channel.state.lastPostedText = text;
|
|
138
241
|
},
|
|
139
242
|
|
|
140
|
-
async
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
243
|
+
async appendChunks({ channel, channelId, chunks, sessionId }) {
|
|
244
|
+
const hadStream = activeStreamTs(channel) !== null;
|
|
245
|
+
const ts = await ensureOpen({
|
|
246
|
+
channel,
|
|
247
|
+
channelId,
|
|
248
|
+
sessionId,
|
|
249
|
+
chunks,
|
|
250
|
+
});
|
|
251
|
+
if (ts === null) {
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
if (!hadStream) {
|
|
255
|
+
return true;
|
|
256
|
+
}
|
|
257
|
+
const result = await appendChatStream({
|
|
148
258
|
botToken,
|
|
149
259
|
channel: channelId,
|
|
150
|
-
ts
|
|
151
|
-
|
|
260
|
+
ts,
|
|
261
|
+
chunks,
|
|
262
|
+
});
|
|
263
|
+
return result.ok;
|
|
264
|
+
},
|
|
265
|
+
|
|
266
|
+
async finalize({ channel, channelId, text, sessionId }) {
|
|
267
|
+
const log = getLog();
|
|
268
|
+
const ts = await ensureOpen({
|
|
269
|
+
channel,
|
|
270
|
+
channelId,
|
|
271
|
+
sessionId,
|
|
272
|
+
markdown_text: text,
|
|
273
|
+
});
|
|
274
|
+
if (ts === null) {
|
|
275
|
+
return { delivered: false };
|
|
276
|
+
}
|
|
277
|
+
const stopped = await stopWithSuffix({
|
|
278
|
+
channel,
|
|
279
|
+
channelId,
|
|
280
|
+
ts,
|
|
281
|
+
text,
|
|
152
282
|
});
|
|
153
283
|
if (stopped.ok) {
|
|
154
|
-
channel.state.streamTs = null;
|
|
155
|
-
channel.state.lastPostedText = text;
|
|
156
|
-
channel.state.lastBotMessageTs = streamTs;
|
|
157
284
|
log.info("reply delivered via stream", {
|
|
158
285
|
channel: channelId,
|
|
159
|
-
stream_ts:
|
|
286
|
+
stream_ts: ts,
|
|
160
287
|
session: sessionId,
|
|
161
288
|
chars: text.length,
|
|
162
289
|
});
|
|
@@ -165,52 +292,46 @@ export function createStreamDeliveryStrategy(
|
|
|
165
292
|
log.warn("chat.stopStream failed; falling back to postMessage", {
|
|
166
293
|
error: stopped.error,
|
|
167
294
|
channel: channelId,
|
|
168
|
-
stream_ts:
|
|
295
|
+
stream_ts: ts,
|
|
169
296
|
session: sessionId,
|
|
170
297
|
});
|
|
171
|
-
if (stopped.unsupported === true) {
|
|
172
|
-
channel.state.streamingUnavailable = true;
|
|
173
|
-
}
|
|
174
|
-
channel.state.streamTs = null;
|
|
175
|
-
// If we already streamed content, do not post the full reply again.
|
|
176
298
|
const alreadyStreamed =
|
|
177
299
|
typeof channel.state.lastPostedText === "string" &&
|
|
178
300
|
channel.state.lastPostedText.length > 0;
|
|
179
301
|
return { delivered: alreadyStreamed };
|
|
180
302
|
},
|
|
181
303
|
|
|
182
|
-
async finalizeEmpty({
|
|
183
|
-
await
|
|
304
|
+
async finalizeEmpty({ channel }) {
|
|
305
|
+
await closeOrphan(channel);
|
|
184
306
|
},
|
|
185
307
|
|
|
186
308
|
async cleanupOrphan({ channel }) {
|
|
187
|
-
|
|
188
|
-
// turn ended without a final assistant message, close it here so
|
|
189
|
-
// Slack does not leave the live reply in a streaming state.
|
|
190
|
-
const streamTs = channel.state.streamTs;
|
|
191
|
-
const channelId =
|
|
192
|
-
channel.state.streamChannelId ?? channel.state.channelId;
|
|
193
|
-
if (
|
|
194
|
-
streamTs === null ||
|
|
195
|
-
streamTs === "" ||
|
|
196
|
-
channelId === null ||
|
|
197
|
-
channelId === ""
|
|
198
|
-
) {
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
await stopChatStream({ botToken, channel: channelId, ts: streamTs });
|
|
202
|
-
channel.state.streamTs = null;
|
|
309
|
+
await closeOrphan(channel);
|
|
203
310
|
},
|
|
204
311
|
|
|
205
|
-
async fail({ channel, channelId,
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
312
|
+
async fail({ channel, channelId, errorText, sessionId }) {
|
|
313
|
+
const ts = await ensureOpen({
|
|
314
|
+
channel,
|
|
315
|
+
channelId,
|
|
316
|
+
sessionId,
|
|
210
317
|
markdown_text: errorText,
|
|
211
318
|
});
|
|
212
|
-
|
|
213
|
-
|
|
319
|
+
if (ts === null) {
|
|
320
|
+
return { delivered: false };
|
|
321
|
+
}
|
|
322
|
+
const stopped = await stopWithSuffix({
|
|
323
|
+
channel,
|
|
324
|
+
channelId,
|
|
325
|
+
ts,
|
|
326
|
+
text: errorText,
|
|
327
|
+
});
|
|
328
|
+
if (stopped.ok) {
|
|
329
|
+
return { delivered: true };
|
|
330
|
+
}
|
|
331
|
+
const alreadyStreamed =
|
|
332
|
+
typeof channel.state.lastPostedText === "string" &&
|
|
333
|
+
channel.state.lastPostedText.length > 0;
|
|
334
|
+
return { delivered: alreadyStreamed };
|
|
214
335
|
},
|
|
215
336
|
};
|
|
216
337
|
}
|
|
@@ -81,7 +81,11 @@ const BOT_SCOPES = [
|
|
|
81
81
|
"users:read",
|
|
82
82
|
] as const;
|
|
83
83
|
|
|
84
|
-
const BOT_EVENTS = [
|
|
84
|
+
const BOT_EVENTS = [
|
|
85
|
+
"app_mention",
|
|
86
|
+
"message.im",
|
|
87
|
+
"assistant_thread_started",
|
|
88
|
+
] as const;
|
|
85
89
|
|
|
86
90
|
/** Slack's display_information.description bound. */
|
|
87
91
|
const MAX_DESCRIPTION_LENGTH = 140;
|