@geminixiang/mikan 1.0.0-beta.20 → 1.0.0-beta.21
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/CHANGELOG.md +34 -0
- package/README.md +18 -11
- package/dist/adapters/buffered-responder.d.ts +60 -0
- package/dist/adapters/buffered-responder.d.ts.map +1 -0
- package/dist/adapters/buffered-responder.js +201 -0
- package/dist/adapters/buffered-responder.js.map +1 -0
- package/dist/adapters/discord/context.d.ts.map +1 -1
- package/dist/adapters/discord/context.js +42 -177
- package/dist/adapters/discord/context.js.map +1 -1
- package/dist/adapters/github/bot.d.ts +14 -76
- package/dist/adapters/github/bot.d.ts.map +1 -1
- package/dist/adapters/github/bot.js +52 -443
- package/dist/adapters/github/bot.js.map +1 -1
- package/dist/adapters/github/client.d.ts +4 -0
- package/dist/adapters/github/client.d.ts.map +1 -1
- package/dist/adapters/github/client.js +5 -0
- package/dist/adapters/github/client.js.map +1 -1
- package/dist/adapters/github/context.d.ts.map +1 -1
- package/dist/adapters/github/context.js +32 -104
- package/dist/adapters/github/context.js.map +1 -1
- package/dist/adapters/github/github-ops.d.ts +90 -0
- package/dist/adapters/github/github-ops.d.ts.map +1 -0
- package/dist/adapters/github/github-ops.js +405 -0
- package/dist/adapters/github/github-ops.js.map +1 -0
- package/dist/adapters/github/repo.d.ts +2 -0
- package/dist/adapters/github/repo.d.ts.map +1 -1
- package/dist/adapters/github/repo.js +5 -0
- package/dist/adapters/github/repo.js.map +1 -1
- package/dist/adapters/github/tools/checks.d.ts.map +1 -1
- package/dist/adapters/github/tools/checks.js +6 -17
- package/dist/adapters/github/tools/checks.js.map +1 -1
- package/dist/adapters/github/tools/issue.d.ts.map +1 -1
- package/dist/adapters/github/tools/issue.js +6 -17
- package/dist/adapters/github/tools/issue.js.map +1 -1
- package/dist/adapters/github/tools/pr.d.ts.map +1 -1
- package/dist/adapters/github/tools/pr.js +6 -17
- package/dist/adapters/github/tools/pr.js.map +1 -1
- package/dist/adapters/github/tools/read.d.ts.map +1 -1
- package/dist/adapters/github/tools/read.js +6 -17
- package/dist/adapters/github/tools/read.js.map +1 -1
- package/dist/adapters/github/tools/review-reply.d.ts.map +1 -1
- package/dist/adapters/github/tools/review-reply.js +6 -17
- package/dist/adapters/github/tools/review-reply.js.map +1 -1
- package/dist/adapters/github/tools/sync.d.ts.map +1 -1
- package/dist/adapters/github/tools/sync.js +6 -17
- package/dist/adapters/github/tools/sync.js.map +1 -1
- package/dist/adapters/slack/bot.js +1 -1
- package/dist/adapters/slack/bot.js.map +1 -1
- package/dist/adapters/telegram/context.d.ts.map +1 -1
- package/dist/adapters/telegram/context.js +33 -151
- package/dist/adapters/telegram/context.js.map +1 -1
- package/dist/agent.d.ts +0 -1
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +28 -32
- package/dist/agent.js.map +1 -1
- package/dist/cli/arg-grammar.d.ts +25 -0
- package/dist/cli/arg-grammar.d.ts.map +1 -0
- package/dist/cli/arg-grammar.js +59 -0
- package/dist/cli/arg-grammar.js.map +1 -0
- package/dist/cli/boot.d.ts +16 -0
- package/dist/cli/boot.d.ts.map +1 -0
- package/dist/cli/boot.js +119 -0
- package/dist/cli/boot.js.map +1 -0
- package/dist/cli/ext.js +9 -11
- package/dist/cli/ext.js.map +1 -1
- package/dist/commands/extensions.js +2 -2
- package/dist/commands/extensions.js.map +1 -1
- package/dist/commands/login.d.ts.map +1 -1
- package/dist/commands/login.js +5 -2
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/model.d.ts.map +1 -1
- package/dist/commands/model.js +8 -8
- package/dist/commands/model.js.map +1 -1
- package/dist/commands/sandbox.d.ts.map +1 -1
- package/dist/commands/sandbox.js +7 -5
- package/dist/commands/sandbox.js.map +1 -1
- package/dist/config.d.ts +0 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +8 -41
- package/dist/config.js.map +1 -1
- package/dist/env-manifest.d.ts +35 -0
- package/dist/env-manifest.d.ts.map +1 -0
- package/dist/env-manifest.js +225 -0
- package/dist/env-manifest.js.map +1 -0
- package/dist/events.d.ts +0 -10
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +9 -82
- package/dist/events.js.map +1 -1
- package/dist/execution-resolver.d.ts +1 -0
- package/dist/execution-resolver.d.ts.map +1 -1
- package/dist/execution-resolver.js +33 -36
- package/dist/execution-resolver.js.map +1 -1
- package/dist/harness/event-format.d.ts +66 -0
- package/dist/harness/event-format.d.ts.map +1 -0
- package/dist/harness/event-format.js +112 -0
- package/dist/harness/event-format.js.map +1 -0
- package/dist/harness/extensions/loader.d.ts +9 -6
- package/dist/harness/extensions/loader.d.ts.map +1 -1
- package/dist/harness/extensions/loader.js +35 -50
- package/dist/harness/extensions/loader.js.map +1 -1
- package/dist/harness/extensions/types.d.ts +10 -14
- package/dist/harness/extensions/types.d.ts.map +1 -1
- package/dist/harness/extensions/types.js.map +1 -1
- package/dist/harness/index.d.ts +1 -0
- package/dist/harness/index.d.ts.map +1 -1
- package/dist/harness/index.js +1 -0
- package/dist/harness/index.js.map +1 -1
- package/dist/harness/runner.d.ts +16 -0
- package/dist/harness/runner.d.ts.map +1 -1
- package/dist/harness/runner.js +27 -1
- package/dist/harness/runner.js.map +1 -1
- package/dist/harness/subagent-runner.d.ts +18 -1
- package/dist/harness/subagent-runner.d.ts.map +1 -1
- package/dist/harness/subagent-runner.js +62 -30
- package/dist/harness/subagent-runner.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/main.js +69 -121
- package/dist/main.js.map +1 -1
- package/dist/observability/instrument.js +6 -4
- package/dist/observability/instrument.js.map +1 -1
- package/dist/observability/sentry.d.ts.map +1 -1
- package/dist/observability/sentry.js +3 -2
- package/dist/observability/sentry.js.map +1 -1
- package/dist/runtime/conversation-runtime.js +13 -3
- package/dist/runtime/conversation-runtime.js.map +1 -1
- package/dist/runtime/types.d.ts +4 -0
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/runtime/types.js.map +1 -1
- package/dist/sandbox/cloudflare.d.ts +1 -0
- package/dist/sandbox/cloudflare.d.ts.map +1 -1
- package/dist/sandbox/cloudflare.js +4 -1
- package/dist/sandbox/cloudflare.js.map +1 -1
- package/dist/sandbox/container.d.ts +1 -0
- package/dist/sandbox/container.d.ts.map +1 -1
- package/dist/sandbox/container.js +4 -1
- package/dist/sandbox/container.js.map +1 -1
- package/dist/sandbox/firecracker.d.ts +1 -0
- package/dist/sandbox/firecracker.d.ts.map +1 -1
- package/dist/sandbox/firecracker.js +4 -1
- package/dist/sandbox/firecracker.js.map +1 -1
- package/dist/sandbox/gondolin-bootstrap.d.ts +26 -0
- package/dist/sandbox/gondolin-bootstrap.d.ts.map +1 -0
- package/dist/sandbox/gondolin-bootstrap.js +27 -0
- package/dist/sandbox/gondolin-bootstrap.js.map +1 -0
- package/dist/sandbox/gondolin-contract.d.ts +125 -0
- package/dist/sandbox/gondolin-contract.d.ts.map +1 -0
- package/dist/sandbox/gondolin-contract.js +155 -0
- package/dist/sandbox/gondolin-contract.js.map +1 -0
- package/dist/sandbox/gondolin-fleet.d.ts +1 -1
- package/dist/sandbox/gondolin-fleet.d.ts.map +1 -1
- package/dist/sandbox/gondolin-fleet.js +1 -1
- package/dist/sandbox/gondolin-fleet.js.map +1 -1
- package/dist/sandbox/gondolin-gateway.d.ts +1 -0
- package/dist/sandbox/gondolin-gateway.d.ts.map +1 -1
- package/dist/sandbox/gondolin-gateway.js +13 -6
- package/dist/sandbox/gondolin-gateway.js.map +1 -1
- package/dist/sandbox/gondolin-inventory.d.ts +2 -16
- package/dist/sandbox/gondolin-inventory.d.ts.map +1 -1
- package/dist/sandbox/gondolin-inventory.js +2 -12
- package/dist/sandbox/gondolin-inventory.js.map +1 -1
- package/dist/sandbox/gondolin-placement.d.ts +0 -2
- package/dist/sandbox/gondolin-placement.d.ts.map +1 -1
- package/dist/sandbox/gondolin-placement.js +0 -6
- package/dist/sandbox/gondolin-placement.js.map +1 -1
- package/dist/sandbox/gondolin-recovery.d.ts +33 -0
- package/dist/sandbox/gondolin-recovery.d.ts.map +1 -0
- package/dist/sandbox/gondolin-recovery.js +39 -0
- package/dist/sandbox/gondolin-recovery.js.map +1 -0
- package/dist/sandbox/gondolin-remote.d.ts +2 -5
- package/dist/sandbox/gondolin-remote.d.ts.map +1 -1
- package/dist/sandbox/gondolin-remote.js +12 -39
- package/dist/sandbox/gondolin-remote.js.map +1 -1
- package/dist/sandbox/gondolin-worker-client.d.ts +8 -12
- package/dist/sandbox/gondolin-worker-client.d.ts.map +1 -1
- package/dist/sandbox/gondolin-worker-client.js +13 -15
- package/dist/sandbox/gondolin-worker-client.js.map +1 -1
- package/dist/sandbox/gondolin-worker.d.ts +2 -40
- package/dist/sandbox/gondolin-worker.d.ts.map +1 -1
- package/dist/sandbox/gondolin-worker.js.map +1 -1
- package/dist/sandbox/gondolin.d.ts +1 -0
- package/dist/sandbox/gondolin.d.ts.map +1 -1
- package/dist/sandbox/gondolin.js +8 -4
- package/dist/sandbox/gondolin.js.map +1 -1
- package/dist/sandbox/host.d.ts +1 -0
- package/dist/sandbox/host.d.ts.map +1 -1
- package/dist/sandbox/host.js +3 -0
- package/dist/sandbox/host.js.map +1 -1
- package/dist/sandbox/index.d.ts +9 -1
- package/dist/sandbox/index.d.ts.map +1 -1
- package/dist/sandbox/index.js +14 -0
- package/dist/sandbox/index.js.map +1 -1
- package/dist/sandbox/types.d.ts +5 -0
- package/dist/sandbox/types.d.ts.map +1 -1
- package/dist/sandbox/types.js.map +1 -1
- package/dist/sandbox/utils.d.ts +1 -0
- package/dist/sandbox/utils.d.ts.map +1 -1
- package/dist/sandbox/utils.js +5 -2
- package/dist/sandbox/utils.js.map +1 -1
- package/dist/sessions/chat-history-sync.d.ts +32 -0
- package/dist/sessions/chat-history-sync.d.ts.map +1 -0
- package/dist/sessions/{agent-memory-file-manager.js → chat-history-sync.js} +24 -83
- package/dist/sessions/chat-history-sync.js.map +1 -0
- package/dist/sessions/conversation-log.d.ts +13 -0
- package/dist/sessions/conversation-log.d.ts.map +1 -0
- package/dist/sessions/conversation-log.js +47 -0
- package/dist/sessions/conversation-log.js.map +1 -0
- package/dist/sessions/rotation.d.ts +2 -0
- package/dist/sessions/rotation.d.ts.map +1 -0
- package/dist/sessions/rotation.js +39 -0
- package/dist/sessions/rotation.js.map +1 -0
- package/dist/sessions/store.d.ts.map +1 -1
- package/dist/sessions/store.js +4 -10
- package/dist/sessions/store.js.map +1 -1
- package/dist/sessions/types.d.ts +2 -2
- package/dist/sessions/types.d.ts.map +1 -1
- package/dist/sessions/types.js.map +1 -1
- package/dist/settings-mutation.d.ts +23 -0
- package/dist/settings-mutation.d.ts.map +1 -0
- package/dist/settings-mutation.js +42 -0
- package/dist/settings-mutation.js.map +1 -0
- package/dist/tools/event.d.ts.map +1 -1
- package/dist/tools/event.js +27 -46
- package/dist/tools/event.js.map +1 -1
- package/dist/tools/host-fn-tool.d.ts +21 -0
- package/dist/tools/host-fn-tool.d.ts.map +1 -0
- package/dist/tools/host-fn-tool.js +32 -0
- package/dist/tools/host-fn-tool.js.map +1 -0
- package/dist/tools/index.d.ts +1 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +1 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/react.d.ts.map +1 -1
- package/dist/tools/react.js +6 -17
- package/dist/tools/react.js.map +1 -1
- package/dist/tools/read.d.ts.map +1 -1
- package/dist/tools/read.js +7 -26
- package/dist/tools/read.js.map +1 -1
- package/dist/tools/sandbox.d.ts.map +1 -1
- package/dist/tools/sandbox.js +5 -2
- package/dist/tools/sandbox.js.map +1 -1
- package/dist/tools/subagent-slots.d.ts +28 -0
- package/dist/tools/subagent-slots.d.ts.map +1 -0
- package/dist/tools/subagent-slots.js +57 -0
- package/dist/tools/subagent-slots.js.map +1 -0
- package/dist/tools/subagent.d.ts +7 -2
- package/dist/tools/subagent.d.ts.map +1 -1
- package/dist/tools/subagent.js +160 -111
- package/dist/tools/subagent.js.map +1 -1
- package/dist/tools/types.d.ts +10 -9
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/types.js.map +1 -1
- package/dist/types.d.ts +5 -24
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/date.d.ts +1 -1
- package/dist/utils/date.js +1 -1
- package/dist/utils/date.js.map +1 -1
- package/dist/vault/disabled.d.ts.map +1 -1
- package/dist/vault/disabled.js +0 -1
- package/dist/vault/disabled.js.map +1 -1
- package/dist/vault/index.d.ts +0 -2
- package/dist/vault/index.d.ts.map +1 -1
- package/dist/vault/index.js +0 -10
- package/dist/vault/index.js.map +1 -1
- package/dist/vault/injection.d.ts +20 -0
- package/dist/vault/injection.d.ts.map +1 -0
- package/dist/vault/injection.js +27 -0
- package/dist/vault/injection.js.map +1 -0
- package/dist/vault/types.d.ts +0 -2
- package/dist/vault/types.d.ts.map +1 -1
- package/dist/vault/types.js.map +1 -1
- package/dist/web/admin/portal.d.ts +3 -3
- package/dist/web/admin/portal.d.ts.map +1 -1
- package/dist/web/admin/portal.js +41 -39
- package/dist/web/admin/portal.js.map +1 -1
- package/dist/web/admin/types.d.ts +3 -0
- package/dist/web/admin/types.d.ts.map +1 -1
- package/dist/web/admin/types.js.map +1 -1
- package/dist/web/agent-events/portal.d.ts.map +1 -1
- package/dist/web/agent-events/portal.js +2 -1
- package/dist/web/agent-events/portal.js.map +1 -1
- package/package.json +1 -1
- package/dist/sessions/agent-memory-file-manager.d.ts +0 -19
- package/dist/sessions/agent-memory-file-manager.d.ts.map +0 -1
- package/dist/sessions/agent-memory-file-manager.js.map +0 -1
- package/dist/vault/routing.d.ts +0 -4
- package/dist/vault/routing.d.ts.map +0 -1
- package/dist/vault/routing.js +0 -6
- package/dist/vault/routing.js.map +0 -1
|
@@ -1,25 +1,10 @@
|
|
|
1
|
-
import * as log from "../../log.js";
|
|
2
1
|
import { resolveChatSessionKey } from "../../sessions/policy.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { formatGithubContinuation
|
|
2
|
+
import { createBufferedResponder, formatMarkdownToolResult } from "../buffered-responder.js";
|
|
3
|
+
import { createChatResponseErrorReporter } from "../shared.js";
|
|
4
|
+
import { formatGithubContinuation } from "./bot.js";
|
|
5
|
+
import { GITHUB_MAX_COMMENT_LENGTH } from "./client.js";
|
|
6
6
|
import { parseGithubConversationId } from "./ids.js";
|
|
7
|
-
function formatToolResult(result) {
|
|
8
|
-
const argsFormatted = formatToolArgs(result.args);
|
|
9
|
-
const duration = (result.durationMs / 1000).toFixed(1);
|
|
10
|
-
let text = `**${result.isError ? "Error" : "Done"} ${result.toolName}**`;
|
|
11
|
-
if (result.label)
|
|
12
|
-
text += `: ${result.label}`;
|
|
13
|
-
text += ` (${duration}s)\n`;
|
|
14
|
-
if (argsFormatted)
|
|
15
|
-
text += `\`\`\`\n${argsFormatted}\n\`\`\`\n`;
|
|
16
|
-
text += `**Result:**\n\`\`\`\n${result.result}\n\`\`\``;
|
|
17
|
-
return text;
|
|
18
|
-
}
|
|
19
7
|
export function createGithubAdapters(event, bot) {
|
|
20
|
-
let commentId = null;
|
|
21
|
-
let accumulatedText = "";
|
|
22
|
-
const responseOperations = new OrderedResponseOperations();
|
|
23
8
|
const conversationId = event.conversationId;
|
|
24
9
|
const ref = parseGithubConversationId(conversationId);
|
|
25
10
|
const message = {
|
|
@@ -76,100 +61,43 @@ export function createGithubAdapters(event, bot) {
|
|
|
76
61
|
showUsageSummary: false,
|
|
77
62
|
},
|
|
78
63
|
};
|
|
64
|
+
let currentResponseId = null;
|
|
79
65
|
const reportResponseError = createChatResponseErrorReporter(() => ({
|
|
80
66
|
platform: "github",
|
|
81
67
|
conversationId,
|
|
82
68
|
messageId: message.id,
|
|
83
69
|
sessionKey: message.sessionKey,
|
|
84
|
-
responseMessageId:
|
|
70
|
+
responseMessageId: currentResponseId === null ? null : Number(currentResponseId),
|
|
85
71
|
conversationKind: message.conversationKind,
|
|
86
72
|
}));
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
function queueGithubResponse(label, operation, work, extra) {
|
|
103
|
-
return responseOperations.run(work, (err) => {
|
|
104
|
-
log.logWarning(`GitHub ${label} error`, err instanceof Error ? err.message : String(err));
|
|
105
|
-
reportResponseError(err, operation, extra());
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
// No appendResponseDelta/finishResponse: GitHub gets the finished response
|
|
109
|
-
// in one comment. Streaming would edit the comment on every flush — API
|
|
110
|
-
// churn and "edited" noise for readers who refresh rather than watch typing.
|
|
111
|
-
const responder = {
|
|
112
|
-
respond: async (text) => {
|
|
113
|
-
await queueGithubResponse("respond", "respond", async () => {
|
|
114
|
-
accumulatedText = accumulatedText ? `${accumulatedText}\n${text}` : text;
|
|
115
|
-
await postSplitResponse(accumulatedText);
|
|
116
|
-
if (commentId !== null) {
|
|
117
|
-
bot.logBotResponse(conversationId, text, String(commentId));
|
|
118
|
-
}
|
|
119
|
-
}, () => ({
|
|
120
|
-
phase: commentId ? "update" : "initial_post",
|
|
121
|
-
textLength: text.length,
|
|
122
|
-
accumulatedLength: accumulatedText.length,
|
|
123
|
-
}));
|
|
124
|
-
},
|
|
125
|
-
replaceResponse: async (text) => {
|
|
126
|
-
await queueGithubResponse("replaceResponse", "replace_response", async () => {
|
|
127
|
-
accumulatedText = text;
|
|
128
|
-
await postSplitResponse(accumulatedText);
|
|
129
|
-
}, () => ({
|
|
130
|
-
textLength: text.length,
|
|
131
|
-
hadExistingResponse: Boolean(commentId),
|
|
132
|
-
}));
|
|
133
|
-
},
|
|
134
|
-
respondDiagnostic: async (text, options) => {
|
|
135
|
-
await queueGithubResponse("respondDiagnostic", "respond_diagnostic", async () => {
|
|
136
|
-
const prefix = options?.style === "error" ? "**Error:** " : "";
|
|
137
|
-
for (const part of splitText(`${prefix}${text}`, GITHUB_MAX_COMMENT_LENGTH, formatGithubContinuation)) {
|
|
138
|
-
await bot.postComment(ref, part);
|
|
139
|
-
}
|
|
140
|
-
}, () => ({ textLength: text.length, style: options?.style }));
|
|
141
|
-
},
|
|
142
|
-
respondToolResult: async (result) => {
|
|
143
|
-
await responder.respondDiagnostic(formatToolResult(result));
|
|
73
|
+
// streaming: false — GitHub gets the finished response in one comment.
|
|
74
|
+
// Streaming would edit the comment on every flush: API churn and "edited"
|
|
75
|
+
// noise for readers who refresh rather than watch typing. There is also no
|
|
76
|
+
// typing indicator or working suffix; progress shows through comment edits.
|
|
77
|
+
const { responder } = createBufferedResponder({
|
|
78
|
+
label: "GitHub",
|
|
79
|
+
maxLength: GITHUB_MAX_COMMENT_LENGTH,
|
|
80
|
+
formatContinuation: formatGithubContinuation,
|
|
81
|
+
errorPrefix: "**Error:** ",
|
|
82
|
+
streaming: false,
|
|
83
|
+
formatToolResult: formatMarkdownToolResult,
|
|
84
|
+
reportError: reportResponseError,
|
|
85
|
+
post: async (text) => {
|
|
86
|
+
currentResponseId = String(await bot.postComment(ref, text));
|
|
87
|
+
return currentResponseId;
|
|
144
88
|
},
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
// feature); leave a pointer instead of failing the run.
|
|
151
|
-
const name = title ?? filePath;
|
|
152
|
-
await queueGithubResponse("uploadFile", "respond_diagnostic", async () => {
|
|
153
|
-
await bot.postComment(ref, `*(file \`${name}\` was produced, but the GitHub adapter cannot attach files to comments)*`);
|
|
154
|
-
}, () => ({ filePath }));
|
|
89
|
+
update: (id, text) => bot.updateMessage(conversationId, id, text),
|
|
90
|
+
postExtra: (text) => bot.postComment(ref, text),
|
|
91
|
+
delete: async (id) => {
|
|
92
|
+
await bot.deleteComment(ref, Number(id));
|
|
93
|
+
currentResponseId = null;
|
|
155
94
|
},
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
try {
|
|
163
|
-
await bot.deleteComment(ref, commentId);
|
|
164
|
-
}
|
|
165
|
-
catch {
|
|
166
|
-
// Ignore errors
|
|
167
|
-
}
|
|
168
|
-
commentId = null;
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
},
|
|
172
|
-
};
|
|
95
|
+
logBotResponse: (text, id) => bot.logBotResponse(conversationId, text, id),
|
|
96
|
+
// The REST API cannot attach files to comments (uploads are a browser
|
|
97
|
+
// feature); leave a pointer instead of failing the run.
|
|
98
|
+
uploadFallbackNote: (name) => `*(file \`${name}\` was produced, but the GitHub adapter cannot attach files to comments)*`,
|
|
99
|
+
react: (emoji) => bot.addReaction(conversationId, event.ts, emoji),
|
|
100
|
+
});
|
|
173
101
|
return { message, responder, platform };
|
|
174
102
|
}
|
|
175
103
|
//# sourceMappingURL=context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/adapters/github/context.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EACL,+BAA+B,EAC/B,cAAc,EACd,SAAS,GAEV,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EACL,wBAAwB,EACxB,yBAAyB,GAE1B,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAGrD,SAAS,gBAAgB,CAAC,MAAsB;IAC9C,MAAM,aAAa,GAAG,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAClD,MAAM,QAAQ,GAAG,CAAC,MAAM,CAAC,UAAU,GAAG,IAAI,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AAC;KACF,CAAC;IAEF,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AAC1C,CAAC","sourcesContent":["import type {\n ChatToolResult,\n ConversationMessage,\n ConversationResponder,\n MessagingInfo,\n} from \"../../adapter.js\";\nimport * as log from \"../../log.js\";\nimport { resolveChatSessionKey } from \"../../sessions/policy.js\";\nimport {\n createChatResponseErrorReporter,\n formatToolArgs,\n splitText,\n type ChatResponseErrorOperation,\n} from \"../shared.js\";\nimport { OrderedResponseOperations } from \"../streaming.js\";\nimport {\n formatGithubContinuation,\n GITHUB_MAX_COMMENT_LENGTH,\n type GithubMessagingBot,\n} from \"./bot.js\";\nimport { parseGithubConversationId } from \"./ids.js\";\nimport type { GithubEvent } from \"./types.js\";\n\nfunction formatToolResult(result: ChatToolResult): string {\n const argsFormatted = formatToolArgs(result.args);\n const duration = (result.durationMs / 1000).toFixed(1);\n let text = `**${result.isError ? \"Error\" : \"Done\"} ${result.toolName}**`;\n if (result.label) text += `: ${result.label}`;\n text += ` (${duration}s)\\n`;\n if (argsFormatted) text += `\\`\\`\\`\\n${argsFormatted}\\n\\`\\`\\`\\n`;\n text += `**Result:**\\n\\`\\`\\`\\n${result.result}\\n\\`\\`\\``;\n return text;\n}\n\nexport function createGithubAdapters(\n event: GithubEvent,\n bot: GithubMessagingBot,\n): {\n message: ConversationMessage;\n responder: ConversationResponder;\n platform: MessagingInfo;\n} {\n let commentId: number | null = null;\n let accumulatedText = \"\";\n const responseOperations = new OrderedResponseOperations();\n\n const conversationId = event.conversationId;\n const ref = parseGithubConversationId(conversationId);\n\n const message: ConversationMessage = {\n id: event.ts,\n sessionKey:\n event.sessionKey ??\n resolveChatSessionKey({\n conversationId,\n conversationKind: event.conversationKind,\n messageId: event.ts,\n persistentTopLevel: true,\n threadTs: event.thread_ts,\n }),\n conversationKind: event.conversationKind,\n userId: event.user,\n userName: event.userName,\n text: event.text,\n attachments: event.attachments,\n threadTs: event.thread_ts,\n };\n\n // The bot's getMessagingInfo() is the single authority for platform info;\n // the conversation-scoped context below is an explicit append, not a fork.\n const baseInfo = bot.getMessagingInfo();\n const platform: MessagingInfo = {\n ...baseInfo,\n formattingGuide:\n `${baseInfo.formattingGuide}\\n\\n` +\n `## Conversation context\\n` +\n `This conversation IS GitHub issue/PR ${ref.owner}/${ref.repo}#${ref.number}: the ` +\n `first message in the history is its title and body, and the following messages are ` +\n `its comments. When the user says \"this issue\", they mean #${ref.number}. Messages ` +\n `tagged [PR review comment rc-<id> …] are inline review threads on a diff line: ` +\n `answer those with the github_review_reply tool (comment_id = that id) so the reply ` +\n `lands in-thread — your normal response posts as a plain PR comment.\\n\\n` +\n `## Repository & pull requests\\n` +\n `The repository is cloned at ./repo — a snapshot from this conversation's first ` +\n `trigger; run github_sync when it may be stale to pull the latest PR head or base ` +\n `branch. If this conversation is a pull request, its head branch is checked out ` +\n `under its real name (run git branch --show-current in ./repo to see it; fork PRs ` +\n `fall back to pr-${ref.number}). You have no git credentials, so git fetch/push ` +\n `fail by design.\\n` +\n `To ship code changes: commit inside ./repo (the git author is preconfigured) on a ` +\n `pi/<name> branch, then call the github_pr tool to push it. When this conversation's ` +\n `checked-out PR head branch is already named pi/<name> — e.g. a PR you opened ` +\n `earlier — commit directly on it and pass that branch to github_pr: the push ` +\n `updates THIS pull request instead of opening a new one. Any other branch opens a ` +\n `new pull request (draft: true for a draft); calling github_pr again with the same ` +\n `branch pushes new commits to its existing PR. Use github_checks to read CI results ` +\n `for your branch (or this PR) — pass a failing check's job id to read its log — and ` +\n `iterate until they pass. You cannot push the default branch or ` +\n `merge — humans review and merge every PR.\\n` +\n `github_read looks up PR/issue metadata this clone cannot show (diff stats, changed ` +\n `files, review state, other issues in this repo); github_issue manages labels, ` +\n `assignees, and close/reopen for triage.`,\n diagnostics: {\n showUsageSummary: false,\n },\n };\n\n const reportResponseError = createChatResponseErrorReporter(() => ({\n platform: \"github\",\n conversationId,\n messageId: message.id,\n sessionKey: message.sessionKey,\n responseMessageId: commentId,\n conversationKind: message.conversationKind,\n }));\n\n async function postOrUpdateResponse(displayText: string): Promise<void> {\n if (commentId !== null) {\n await bot.updateMessage(conversationId, String(commentId), displayText);\n } else {\n commentId = await bot.postComment(ref, displayText);\n }\n }\n\n async function postSplitResponse(text: string): Promise<void> {\n const [displayText, ...extraParts] = splitText(\n text,\n GITHUB_MAX_COMMENT_LENGTH,\n formatGithubContinuation,\n );\n await postOrUpdateResponse(displayText);\n for (const part of extraParts) {\n await bot.postComment(ref, part);\n }\n }\n\n function queueGithubResponse(\n label: string,\n operation: ChatResponseErrorOperation,\n work: () => Promise<void>,\n extra: () => Record<string, unknown>,\n ): Promise<void> {\n return responseOperations.run(work, (err) => {\n log.logWarning(`GitHub ${label} error`, err instanceof Error ? err.message : String(err));\n reportResponseError(err, operation, extra());\n });\n }\n\n // No appendResponseDelta/finishResponse: GitHub gets the finished response\n // in one comment. Streaming would edit the comment on every flush — API\n // churn and \"edited\" noise for readers who refresh rather than watch typing.\n const responder: ConversationResponder = {\n respond: async (text: string) => {\n await queueGithubResponse(\n \"respond\",\n \"respond\",\n async () => {\n accumulatedText = accumulatedText ? `${accumulatedText}\\n${text}` : text;\n await postSplitResponse(accumulatedText);\n if (commentId !== null) {\n bot.logBotResponse(conversationId, text, String(commentId));\n }\n },\n () => ({\n phase: commentId ? \"update\" : \"initial_post\",\n textLength: text.length,\n accumulatedLength: accumulatedText.length,\n }),\n );\n },\n\n replaceResponse: async (text: string) => {\n await queueGithubResponse(\n \"replaceResponse\",\n \"replace_response\",\n async () => {\n accumulatedText = text;\n await postSplitResponse(accumulatedText);\n },\n () => ({\n textLength: text.length,\n hadExistingResponse: Boolean(commentId),\n }),\n );\n },\n\n respondDiagnostic: async (text: string, options?: { style?: \"muted\" | \"error\" }) => {\n await queueGithubResponse(\n \"respondDiagnostic\",\n \"respond_diagnostic\",\n async () => {\n const prefix = options?.style === \"error\" ? \"**Error:** \" : \"\";\n for (const part of splitText(\n `${prefix}${text}`,\n GITHUB_MAX_COMMENT_LENGTH,\n formatGithubContinuation,\n )) {\n await bot.postComment(ref, part);\n }\n },\n () => ({ textLength: text.length, style: options?.style }),\n );\n },\n\n respondToolResult: async (result: ChatToolResult) => {\n await responder.respondDiagnostic(formatToolResult(result));\n },\n\n // GitHub has no typing indicator; progress shows through comment edits.\n setTyping: async () => {},\n\n setWorking: async () => {},\n\n uploadFile: async (filePath: string, title?: string) => {\n // The REST API cannot attach files to comments (uploads are a browser\n // feature); leave a pointer instead of failing the run.\n const name = title ?? filePath;\n await queueGithubResponse(\n \"uploadFile\",\n \"respond_diagnostic\",\n async () => {\n await bot.postComment(\n ref,\n `*(file \\`${name}\\` was produced, but the GitHub adapter cannot attach files to comments)*`,\n );\n },\n () => ({ filePath }),\n );\n },\n\n react: async (emoji: string) => {\n await bot.addReaction(conversationId, event.ts, emoji);\n },\n\n deleteResponse: async () => {\n await responseOperations.run(async () => {\n if (commentId !== null) {\n try {\n await bot.deleteComment(ref, commentId);\n } catch {\n // Ignore errors\n }\n commentId = null;\n }\n });\n },\n };\n\n return { message, responder, platform };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/adapters/github/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AAC7F,OAAO,EAAE,+BAA+B,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,wBAAwB,EAA2B,MAAM,UAAU,CAAC;AAC7E,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAGrD,MAAM,UAAU,oBAAoB,CAClC,KAAkB,EAClB,GAAuB;IAMvB,MAAM,cAAc,GAAG,KAAK,CAAC,cAAc,CAAC;IAC5C,MAAM,GAAG,GAAG,yBAAyB,CAAC,cAA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AAG,CAAC,aAAa,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;YACzC,iBAAiB,GAAG,IAAI,CAAC;QAC3B,CAAC;QACD,cAAc,EAAE,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,cAAc,CAAC,cAAc,EAAE,IAAI,EAAE,EAAE,CAAC;QAC1E,sEAAsE;QACtE,wDAAwD;QACxD,kBAAkB,EAAE,CAAC,IAAI,EAAE,EAAE,CAC3B,YAAY,IAAI,2EAA2E;QAC7F,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC,cAAc,EAAE,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC;KACnE,CAAC,CAAC;IAEH,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AAC1C,CAAC","sourcesContent":["import type { ConversationMessage, ConversationResponder, MessagingInfo } from \"../../adapter.js\";\nimport { resolveChatSessionKey } from \"../../sessions/policy.js\";\nimport { createBufferedResponder, formatMarkdownToolResult } from \"../buffered-responder.js\";\nimport { createChatResponseErrorReporter } from \"../shared.js\";\nimport { formatGithubContinuation, type GithubMessagingBot } from \"./bot.js\";\nimport { GITHUB_MAX_COMMENT_LENGTH } from \"./client.js\";\nimport { parseGithubConversationId } from \"./ids.js\";\nimport type { GithubEvent } from \"./types.js\";\n\nexport function createGithubAdapters(\n event: GithubEvent,\n bot: GithubMessagingBot,\n): {\n message: ConversationMessage;\n responder: ConversationResponder;\n platform: MessagingInfo;\n} {\n const conversationId = event.conversationId;\n const ref = parseGithubConversationId(conversationId);\n\n const message: ConversationMessage = {\n id: event.ts,\n sessionKey:\n event.sessionKey ??\n resolveChatSessionKey({\n conversationId,\n conversationKind: event.conversationKind,\n messageId: event.ts,\n persistentTopLevel: true,\n threadTs: event.thread_ts,\n }),\n conversationKind: event.conversationKind,\n userId: event.user,\n userName: event.userName,\n text: event.text,\n attachments: event.attachments,\n threadTs: event.thread_ts,\n };\n\n // The bot's getMessagingInfo() is the single authority for platform info;\n // the conversation-scoped context below is an explicit append, not a fork.\n const baseInfo = bot.getMessagingInfo();\n const platform: MessagingInfo = {\n ...baseInfo,\n formattingGuide:\n `${baseInfo.formattingGuide}\\n\\n` +\n `## Conversation context\\n` +\n `This conversation IS GitHub issue/PR ${ref.owner}/${ref.repo}#${ref.number}: the ` +\n `first message in the history is its title and body, and the following messages are ` +\n `its comments. When the user says \"this issue\", they mean #${ref.number}. Messages ` +\n `tagged [PR review comment rc-<id> …] are inline review threads on a diff line: ` +\n `answer those with the github_review_reply tool (comment_id = that id) so the reply ` +\n `lands in-thread — your normal response posts as a plain PR comment.\\n\\n` +\n `## Repository & pull requests\\n` +\n `The repository is cloned at ./repo — a snapshot from this conversation's first ` +\n `trigger; run github_sync when it may be stale to pull the latest PR head or base ` +\n `branch. If this conversation is a pull request, its head branch is checked out ` +\n `under its real name (run git branch --show-current in ./repo to see it; fork PRs ` +\n `fall back to pr-${ref.number}). You have no git credentials, so git fetch/push ` +\n `fail by design.\\n` +\n `To ship code changes: commit inside ./repo (the git author is preconfigured) on a ` +\n `pi/<name> branch, then call the github_pr tool to push it. When this conversation's ` +\n `checked-out PR head branch is already named pi/<name> — e.g. a PR you opened ` +\n `earlier — commit directly on it and pass that branch to github_pr: the push ` +\n `updates THIS pull request instead of opening a new one. Any other branch opens a ` +\n `new pull request (draft: true for a draft); calling github_pr again with the same ` +\n `branch pushes new commits to its existing PR. Use github_checks to read CI results ` +\n `for your branch (or this PR) — pass a failing check's job id to read its log — and ` +\n `iterate until they pass. You cannot push the default branch or ` +\n `merge — humans review and merge every PR.\\n` +\n `github_read looks up PR/issue metadata this clone cannot show (diff stats, changed ` +\n `files, review state, other issues in this repo); github_issue manages labels, ` +\n `assignees, and close/reopen for triage.`,\n diagnostics: {\n showUsageSummary: false,\n },\n };\n\n let currentResponseId: string | null = null;\n\n const reportResponseError = createChatResponseErrorReporter(() => ({\n platform: \"github\",\n conversationId,\n messageId: message.id,\n sessionKey: message.sessionKey,\n responseMessageId: currentResponseId === null ? null : Number(currentResponseId),\n conversationKind: message.conversationKind,\n }));\n\n // streaming: false — GitHub gets the finished response in one comment.\n // Streaming would edit the comment on every flush: API churn and \"edited\"\n // noise for readers who refresh rather than watch typing. There is also no\n // typing indicator or working suffix; progress shows through comment edits.\n const { responder } = createBufferedResponder({\n label: \"GitHub\",\n maxLength: GITHUB_MAX_COMMENT_LENGTH,\n formatContinuation: formatGithubContinuation,\n errorPrefix: \"**Error:** \",\n streaming: false,\n formatToolResult: formatMarkdownToolResult,\n reportError: reportResponseError,\n post: async (text) => {\n currentResponseId = String(await bot.postComment(ref, text));\n return currentResponseId;\n },\n update: (id, text) => bot.updateMessage(conversationId, id, text),\n postExtra: (text) => bot.postComment(ref, text),\n delete: async (id) => {\n await bot.deleteComment(ref, Number(id));\n currentResponseId = null;\n },\n logBotResponse: (text, id) => bot.logBotResponse(conversationId, text, id),\n // The REST API cannot attach files to comments (uploads are a browser\n // feature); leave a pointer instead of failing the run.\n uploadFallbackNote: (name) =>\n `*(file \\`${name}\\` was produced, but the GitHub adapter cannot attach files to comments)*`,\n react: (emoji) => bot.addReaction(conversationId, event.ts, emoji),\n });\n\n return { message, responder, platform };\n}\n"]}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { GithubClient } from "./client.js";
|
|
2
|
+
import type { GithubBotConfig, GithubCheckSummary, GithubConversationRef, GithubIssueRequest, GithubPrRequest, GithubPrResult, GithubReadRequest, GithubReadResult, PlatformGithubOps } from "./types.js";
|
|
3
|
+
/** Whether the conversation's issue is a PR, for callers where the triggering
|
|
4
|
+
* item didn't carry that knowledge. Errs toward plain issue. */
|
|
5
|
+
export declare function fetchIsPr(client: GithubClient, ref: GithubConversationRef): Promise<boolean>;
|
|
6
|
+
/**
|
|
7
|
+
* The PR's head branch name when it lives in this repo — that is the name
|
|
8
|
+
* the local checkout should carry, so committing on it and calling
|
|
9
|
+
* github_pr pushes back to the PR itself instead of opening a new one.
|
|
10
|
+
* Fork heads (unpushable with the repo-scoped token) and failed lookups
|
|
11
|
+
* return undefined; callers then fall back to the synthetic pr-<n>.
|
|
12
|
+
*/
|
|
13
|
+
export declare function fetchPrHeadBranch(client: GithubClient, ref: GithubConversationRef): Promise<string | undefined>;
|
|
14
|
+
/**
|
|
15
|
+
* Host-side backend of the github_* tool pack (`PlatformGithubOps`),
|
|
16
|
+
* standalone from the messaging bot: it needs the API client, the
|
|
17
|
+
* conversation working dir, and optional Cloud Build access — not the poll
|
|
18
|
+
* loop, queues, or trigger gate. Tokens are minted per call, scoped to the
|
|
19
|
+
* conversation's repo, and never enter the sandbox.
|
|
20
|
+
*/
|
|
21
|
+
export declare class GithubOps implements PlatformGithubOps {
|
|
22
|
+
private readonly client;
|
|
23
|
+
private readonly config;
|
|
24
|
+
/** Cloud Build ids seen in getChecks summaries → their GCP project. */
|
|
25
|
+
private buildRef;
|
|
26
|
+
constructor(client: GithubClient, config: {
|
|
27
|
+
workingDir: string;
|
|
28
|
+
cloudBuild?: GithubBotConfig["cloudBuild"];
|
|
29
|
+
});
|
|
30
|
+
private repoDir;
|
|
31
|
+
/**
|
|
32
|
+
* Backs the `github_pr` tool: push a `pi/*` branch the agent prepared in
|
|
33
|
+
* the conversation's clone, then open a pull request as the App. The write
|
|
34
|
+
* token is minted per call, scoped to this one repo, and never enters the
|
|
35
|
+
* sandbox.
|
|
36
|
+
*/
|
|
37
|
+
pushAndCreatePr(conversationId: string, request: GithubPrRequest): Promise<GithubPrResult>;
|
|
38
|
+
/**
|
|
39
|
+
* Backs the `github_checks` tool: CI check runs for a branch the agent
|
|
40
|
+
* pushed, or for the conversation's PR head when no branch is given.
|
|
41
|
+
*/
|
|
42
|
+
getChecks(conversationId: string, branch?: string): Promise<GithubCheckSummary[]>;
|
|
43
|
+
private rememberBuild;
|
|
44
|
+
/**
|
|
45
|
+
* Backs the Cloud Build log mode of `github_checks`. GCP credentials stay
|
|
46
|
+
* host-side (ADC via GOOGLE_APPLICATION_CREDENTIALS — e.g. a Workload
|
|
47
|
+
* Identity Federation external_account file); the build must have appeared
|
|
48
|
+
* in a github_checks summary first, which is also where its project is
|
|
49
|
+
* learned. Unreadable logs degrade to the console url, never a dead end.
|
|
50
|
+
*/
|
|
51
|
+
getBuildLog(conversationId: string, buildId: string): Promise<string>;
|
|
52
|
+
/**
|
|
53
|
+
* Backs the `github_sync` tool: refresh the conversation's ./repo clone
|
|
54
|
+
* from origin with an ephemeral read token. Fetch-only when moving the
|
|
55
|
+
* checkout could lose agent work; the formatted report tells the agent
|
|
56
|
+
* what happened and what to do next.
|
|
57
|
+
*/
|
|
58
|
+
syncRepo(conversationId: string, branch?: string): Promise<string>;
|
|
59
|
+
/**
|
|
60
|
+
* Backs the `github_read` tool: PR/issue metadata the ./repo clone cannot
|
|
61
|
+
* provide (diff stats, review state, other issues in the repo). Owner/repo
|
|
62
|
+
* always come from the conversation id, so reads never leave this repo.
|
|
63
|
+
*/
|
|
64
|
+
readGithub(conversationId: string, request: GithubReadRequest): Promise<GithubReadResult>;
|
|
65
|
+
/**
|
|
66
|
+
* Backs the `github_issue` tool: labels, assignees, and open/closed state
|
|
67
|
+
* on any issue of this conversation's repo (triage). Same-repo by
|
|
68
|
+
* construction — owner/repo come from the conversation id; the action enum
|
|
69
|
+
* is closed, so lock/delete/transfer cannot be expressed at all.
|
|
70
|
+
*/
|
|
71
|
+
manageIssue(conversationId: string, request: GithubIssueRequest): Promise<string>;
|
|
72
|
+
/**
|
|
73
|
+
* Backs the `github_review_reply` tool: answer inside one inline review
|
|
74
|
+
* thread of this conversation's PR. The comment id comes from an
|
|
75
|
+
* `[PR review comment rc-<id> …]` message; GitHub validates it belongs to
|
|
76
|
+
* this PR (404 otherwise, translated into agent-actionable guidance).
|
|
77
|
+
*/
|
|
78
|
+
replyToReviewThread(conversationId: string, commentId: number, body: string): Promise<{
|
|
79
|
+
url: string;
|
|
80
|
+
}>;
|
|
81
|
+
/**
|
|
82
|
+
* Backs the log mode of `github_checks`: the tail of one CI job's log so
|
|
83
|
+
* the agent can diagnose a failing check without sandbox credentials. Only
|
|
84
|
+
* GitHub Actions checks have logs on GitHub — external CI apps (e.g. Cloud
|
|
85
|
+
* Build) keep theirs on their own service, so a 404 here is translated
|
|
86
|
+
* into guidance instead of a dead end.
|
|
87
|
+
*/
|
|
88
|
+
getJobLog(conversationId: string, jobId: number): Promise<string>;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=github-ops.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github-ops.d.ts","sourceRoot":"","sources":["../../../src/adapters/github/github-ops.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,YAAY,EAA0C,MAAM,aAAa,CAAC;AAUnG,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EAClB,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAWpB;iEACiE;AACjE,wBAAsB,SAAS,CAC7B,MAAM,EAAE,YAAY,EACpB,GAAG,EAAE,qBAAqB,GACzB,OAAO,CAAC,OAAO,CAAC,CAOlB;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,YAAY,EACpB,GAAG,EAAE,qBAAqB,GACzB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAS7B;AAED;;;;;;GAMG;AACH,qBAAa,SAAU,YAAW,iBAAiB;IAK/C,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;IALzB,uEAAuE;IACvE,OAAO,CAAC,QAAQ,CAA0C;IAE1D,YACmB,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE;QACvB,UAAU,EAAE,MAAM,CAAC;QACnB,UAAU,CAAC,EAAE,eAAe,CAAC,YAAY,CAAC,CAAC;KAC5C,EACC;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