@sentry/junior 0.257.0 → 0.259.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{actor-BTtLaeWy.js → actor-tlxzqaRe.js} +3 -6
- package/dist/adapter-Bn0gFVSF.js +270 -0
- package/dist/{admin-DgIkm6Vy.js → admin-C8xz2f10.js} +2 -3
- package/dist/{agent-hooks-BjtTzvru.js → agent-hooks-B00FaKdP.js} +70 -109
- package/dist/{agent-invocations-Bdu3ROfo.js → agent-invocations-Qfz7dWgU.js} +6 -12
- package/dist/{agent-runner-D7OboVb3.js → agent-runner-CPSd7rKm.js} +324 -742
- package/dist/api/schema.d.ts +442 -447
- package/dist/api/schema.js +6 -6
- package/dist/api.d.ts +2 -12
- package/dist/api.js +165 -158
- package/dist/{app-BsU5QNBd.d.ts → app-Bbxrehjf.d.ts} +25 -45
- package/dist/app.d.ts +3 -3
- package/dist/app.js +206 -321
- package/dist/{assistant-reply-CbTPebzL.js → assistant-reply-CqthTerd.js} +3 -5
- package/dist/{automation-CHdlHVZP.js → automation-DWBFBenG.js} +6 -11
- package/dist/{briefs-oLOldnDM.js → briefs-DNYbQ9cD.js} +8 -11
- package/dist/{cadence-D00SCzT1.js → cadence-R7Em4RjE.js} +1 -2
- package/dist/{catalog-runtime-CZzhGQ7F.js → catalog-runtime-B8SuFPGb.js} +3 -4
- package/dist/cli/chat.d.ts +2 -4
- package/dist/cli/chat.js +22 -24
- package/dist/cli/check.d.ts +1 -3
- package/dist/cli/check.js +4 -5
- package/dist/cli/env.d.ts +1 -3
- package/dist/cli/env.js +1 -2
- package/dist/cli/init.d.ts +1 -3
- package/dist/cli/init.js +3 -3
- package/dist/cli/main.d.ts +1 -3
- package/dist/cli/main.js +8 -5
- package/dist/cli/plugins.d.ts +2 -4
- package/dist/cli/plugins.js +7 -8
- package/dist/cli/run.d.ts +3 -3
- package/dist/cli/run.js +3 -3
- package/dist/cli/snapshot-create.d.ts +1 -3
- package/dist/cli/snapshot-create.js +5 -5
- package/dist/cli/upgrade.d.ts +3 -6
- package/dist/cli/upgrade.js +11 -17
- package/dist/{client-D8HnkOQX.js → client-BZdxgKyL.js} +64 -18
- package/dist/{config-CJRnWK9H.js → config-Deqpfpg9.js} +21 -15
- package/dist/{connections-ClYrKzpX.js → connections-9gJkfS85.js} +179 -20
- package/dist/{conversation-CKNLYBJt.js → conversation-DjN3mlog.js} +8 -15
- package/dist/{conversation-privacy-C8b1nphZ.js → conversation-privacy-CFhNKxp-.js} +2 -3
- package/dist/{conversation-work-C6y3T5Hx.js → conversation-work-BaT_T6EB.js} +1 -2
- package/dist/{credential-sync-BXfohNmJ.js → credential-sync-BABGymK3.js} +23 -190
- package/dist/{db-Ca9Nt5ci.d.ts → db-BnRqQ7G5.d.ts} +1 -1
- package/dist/{executor-Do0THDRR.js → executor-Bb3eQb8q.js} +30 -52
- package/dist/{experimental-CQIvMUO7.js → experimental-BNK1l1jv.js} +2 -4
- package/dist/{history-9pO1Zd4Y.js → history-AY8rs-FR.js} +5 -9
- package/dist/{history-DvqWZlYX.d.ts → history-BgI33Kie.d.ts} +12 -20
- package/dist/{images-BN_BiBXF.js → images-BbSdVHC6.js} +5 -6
- package/dist/instrumentation.d.ts +1 -3
- package/dist/instrumentation.js +6 -8
- package/dist/{job-queue-B6SV9uVa.js → job-queue-vdGU-5ge.js} +6 -12
- package/dist/{logging-CWxiIuCF.js → logging-BStXN56b.js} +7 -12
- package/dist/{message-TUOdbSBW.js → message-DRf6m4uO.js} +5 -6
- package/dist/{model-profile-BwU8mqwD.js → model-profile-Bg8EoCKD.js} +2 -4
- package/dist/nitro.d.ts +3 -5
- package/dist/nitro.js +12 -17
- package/dist/{oauth-authorization-BA4Dt6a7.js → oauth-authorization-djQn5Nhy.js} +2 -4
- package/dist/{oauth-callback-server-Dj5UJODo.js → oauth-callback-server-JmOgLcGl.js} +3 -4
- package/dist/{oauth-relay-CdCnu80W.js → oauth-relay-CTygMkNx.js} +2 -3
- package/dist/{package-discovery-BVvSnQBB.js → package-discovery-DJBompdd.js} +17 -21
- package/dist/{pending-auth-s_QFribU.js → pending-auth-rG5U_QS1.js} +92 -83
- package/dist/{plugin-module-CVvEUSMH.js → plugin-module-Cf5gVPWP.js} +1 -2
- package/dist/{plugins-CjfUP5gJ.d.ts → plugins-B_0Cr0MO.d.ts} +5 -5
- package/dist/{plugins-egKWjgue.js → plugins-DOm9Y6qI.js} +2 -3
- package/dist/{private-trace-result-BLvBjy_e.js → private-trace-result-CE7_lEdq.js} +1 -2
- package/dist/{profile-h-72wM78.js → profile-qBM6B_-V.js} +14 -295
- package/dist/{prompt-DyoEj9c2.js → prompt-xgpyMtg7.js} +5 -9
- package/dist/{queue-B5SnqRln.d.ts → queue-C37RbDVc.d.ts} +0 -2
- package/dist/{registry-sLTr-sV9.js → registry-B_M_x_iS.js} +56 -30
- package/dist/{resolve-ncQPZROQ.js → resolve-BzpuLh8c.js} +8 -12
- package/dist/{result-C883vngT.js → result-DEZH_AnZ.js} +13 -17
- package/dist/{rolldown-runtime-B4FMCO8f.js → rolldown-runtime-nwUcYXjP.js} +1 -2
- package/dist/{runner-CzYImdOF.js → runner-BqQlG10t.js} +12 -13
- package/dist/{sandbox-egress-signals-CZbMINHI.js → sandbox-egress-signals-DCq3WLs5.js} +2 -3
- package/dist/{schema-Dy69D4Ge.js → schema-CF9HqNRY.js} +30 -27
- package/dist/{sentry-CgWZM_kV.js → sentry-BBUlHih9.js} +2 -3
- package/dist/service-account-BqTBkyD7.js +120 -0
- package/dist/service-account-BzhW7kXu.js +661 -0
- package/dist/{session-stop-CQjKd4a2.js → session-stop-CV65ZlU3.js} +23 -33
- package/dist/{skills-C22SLruK.js → skills-CiWS5_Ub.js} +9 -9
- package/dist/{spawn-DY9CLXDL.js → spawn-BSAQ7UQZ.js} +4 -5
- package/dist/{store-DXFIQy-G.js → store-B1GES4gC.js} +13 -15
- package/dist/{store-DoewL5mG.d.ts → store-CG0VJyye.d.ts} +0 -14
- package/dist/{task-queue-B17vV0La.js → task-queue-BAeGEMjJ.js} +5 -7
- package/dist/{task-runner-DUjvzYXj.js → task-runner-BlGhcQPi.js} +22 -26
- package/dist/{tasks-D_WIJtvO.js → tasks-DieKX3d4.js} +63 -78
- package/dist/{thread-state-Ch4yuCqG.js → thread-state-DpSWS4Rr.js} +13 -19
- package/dist/{turn-failure-response-C5nBKC4S.js → turn-failure-response-DQljogGJ.js} +16 -22
- package/dist/{turn-lifecycle-CO-ylUmV.js → turn-lifecycle-BLgrkV_L.js} +2 -3
- package/dist/{turn-session-routing-B3LWooK5.js → turn-session-routing-BlajheOU.js} +2 -3
- package/dist/{validation-CXYxaNYx.js → validation-23d7K9tX.js} +3 -4
- package/dist/vercel.d.ts +1 -3
- package/dist/vercel.js +1 -2
- package/dist/{version-BcdZy2zg.js → version-B_XumRx-.js} +3 -5
- package/dist/{version-CnXZ614E.d.ts → version-Cc2OFd9G.d.ts} +0 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -2
- package/dist/{viewer-DSZXygMU.js → viewer-B2_ABsYi.js} +26 -57
- package/dist/{web-input-B9Bv0_lR.js → web-input-BZDyxpzR.js} +101 -158
- package/dist/{web-message-id-xPI_EFSC.js → web-message-id-CJSUiksE.js} +3 -6
- package/dist/{work-nAfDSUFP.js → work-D3QKiV0O.js} +14 -16
- package/dist/{worker-vGXZ6XFT.js → worker-C8mUjYf9.js} +7 -8
- package/package.json +10 -9
|
@@ -1,39 +1,40 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { R as normalizeIdentityEmail, S as summarizeMessageText, T as withSpan, V as toOptionalString, _ as serializeGenAiAttribute, a as extractGenAiUsageSummary, b as setSpanStatus, c as getLogContextAttributesForSpan, d as logError, f as logException, h as normalizeGenAiFinishReason, i as extractGenAiUsageAttributes, l as getTracePropagationHeaders, m as logWarn, p as logInfo, u as logAudit, w as withLogContext, x as setTags, y as setSpanAttributes, z as isRecord$4 } from "./logging-
|
|
3
|
-
import { m as startInactiveSpan, v as withActiveSpan } from "./sentry-
|
|
4
|
-
import { a as toCanonicalInputMessage, c as toGenAiPayloadMetadata, i as runWithConversationPrivacy, l as toGenAiPayloadTraceAttributes, o as toCanonicalOutputMessage, r as resolveConversationPrivacy, s as toGenAiMessagesTraceAttributes, t as canExposeConversationPayload } from "./conversation-privacy-
|
|
5
|
-
import { n as botConfig, v as normalizeSlackEmojiName } from "./config-
|
|
6
|
-
import { a as formatModelProfiles, c as profileConfig, i as formatModelProfile, l as TURN_REASONING_LEVELS, n as ModelProfileNotConfiguredError, o as modelIdForProfile, s as modelProfileSchema } from "./model-profile-
|
|
7
|
-
import { a as isUserActor, d as parseSlackTeamId, f as parseSlackUserId, g as parseSlackMessageTs, l as parseSlackChannelId, u as parseSlackChannelReferenceId } from "./actor-
|
|
8
|
-
import {
|
|
9
|
-
import { a as juniorAgentInvocations, c as juniorIdentities, d as juniorDestinations, i as juniorAgentBindings, n as AGENT_INVOCATION_PARENT_MAILBOX_STATUSES, s as juniorConversations, t as AGENT_INVOCATION_MAILBOX_STATUSES } from "./agent-invocations-
|
|
10
|
-
import { _ as juniorConversationAnnotations, a as juniorAutomationRuns, b as juniorAttachments, c as juniorStats, f as juniorConversationBriefs, x as juniorArtifacts } from "./executor-
|
|
11
|
-
import { d as contextProvenance, f as instructionActors, m as sameActorIdentity, p as instructionProvenanceFor, t as KNOWN_CONVERSATION_EVENT_TYPES, u as agentInstructionProvenance } from "./history-
|
|
12
|
-
import { a as listReferenceFiles, c as soulPathCandidates, l as worldPathCandidates } from "./package-discovery-
|
|
13
|
-
import { _ as CredentialUnavailableError, a as resolveAuthTokenPlaceholder, c as fetchWithBoundedOAuthErrorBodies, d as actorLogContext, f as credentialContextForActor, g as credentialUserSubjectId, i as resolvePluginHeaderEnvRefs, l as getOAuthProviderErrorAttributes, o as resolvePluginCommandEnv, p as credentialContextSchema, s as OAuthProviderError } from "./registry-
|
|
14
|
-
import { n as pluginCatalogRuntime } from "./catalog-runtime-
|
|
15
|
-
import { a as parseSkillInvocation, i as parseSkillFile, n as findSkillByName, r as loadSkillsByName, t as discoverSkills } from "./skills-
|
|
16
|
-
import { A as escapeSlackMrkdwnText, B as postSlackMessage, Ct as ToolInputError, Dt as loadConversationProjection, Et as loadConnectedMcpProviders, G as continuableMessages, H as uploadFilesToConversation, Ht as recordTurnRoute, I as addReactionToMessage, K as loadTurnCheckpoint, L as getSlackMessagePermalink, Lt as recordAuthorizationRequested, Mt as openConversationProjection, Nt as recordAgentsInstructionsUpdated, O as automationRevision, Ot as loadLastModelProfile, P as slackMention, Pt as recordAttachmentsDelivered, R as openSlackDirectMessage, Rt as recordGuardianActionReviewed, St as TURN_CONTEXT_TAG, Vt as recordToolExecutionStarted, Xt as fallbackShortTitle, Zt as resolveTaskTitle, _t as isToolResultMessage, a as saveScheduledAutomation, bt as stripRuntimeTurnContext, ct as extractAssistantText, d as createEventAutomation, dn as getAgentContextInputLimitTokens, dt as getUserMessageInstructionText, f as deleteEventAutomation, fn as historyItemFromPiMessage, ft as hasRuntimeTurnContext, g as listEventAutomationsForTeam, gt as isToolResultError, ht as isContinuablePiBoundary, i as readScheduledAutomation, it as TurnToolCallLimitExceededError, j as formatSlackLink, jt as loadTurnRoute, ln as estimateTextTokens, lt as getPiMessageRole, m as getEventAutomation, mt as isAssistantMessage, n as listScheduledAutomationsForTeam, nt as TurnBudgetExceededError, ot as createTurnLimitGate, pn as piMessageFromHistoryItem, q as saveTurnCheckpoint, rt as TurnSliceLimitExceededError, st as isTurnExecutionLimitExceededError, t as createScheduledAutomation, tt as TURN_LIMIT_DISABLED_REASON, un as getAgentContextCompactionTriggerTokens, ut as getTerminalAssistantMessages, v as saveEventAutomation, vt as normalizeToolNameFromResult, xt as trimTrailingAssistantMessages, y as setEventAutomationStatus, yt as retainRuntimeTurnContext, z as postSlackEphemeralMessage, zt as recordMcpProviderConnected } from "./tasks-
|
|
17
|
-
import { A as getWorkspaceSnapshotBuilder, B as STOP_WATCHING_TOOL_NAME, Bt as getFilePermalink, C as WorkspaceValidationError, D as setWorkspaceSnapshotBuild, Dt as matchSlackAttachments, E as setWorkspaceSnapshot, F as isSlackMessageTurn, Ft as defaultTimezone, G as createWatch, Gt as normalizeSlackConversationId, H as cancelWatch, Ht as getSlackClient, I as slackMessageTurnDisabledReason, It as resolveUserTimezone, J as getWatch, K as deliverWatch, L as RESOURCE_SUBSCRIPTION_DEFAULT_TTL_MS, M as workspaceRepoCheckoutPath, Mt as createPluginAnnotations, N as resolveChannelCapabilities, O as SANDBOX_RUNTIME, P as getSlackToolContext, R as RESOURCE_SUBSCRIPTION_MAX_TTL_MS, Rt as SlackActionError, S as updateWorkspace, T as loadSnapshotsForProfile, Ut as isConversationScopedChannel, V as cancelSubscriptions, W as createTimerWatch, Wt as isDmChannel$1, Xt as JUNIOR_NATIVE_EVENT_NAMESPACE, Y as listWatches, _ as deleteWorkspace, at as getDashboardConversationLink, b as listWorkspaces, c as getPluginTools, en as conversationNoteEvent, ft as createPluginLogger, g as createWorkspace, j as tryWorkspaceRepoCheckoutPath, jt as saveObjectAnnotations, k as deleteWorkspaceSnapshotBuilders, l as getPluginUserPromptContributions, q as findMatchingWatches, qt as withSlackRetries, r as createPluginHookRunner, s as getPluginSystemPromptContributions, st as getDashboardTaskLink, u as getPlugins, v as getWorkspace, w as invalidateReadySnapshot, y as getWorkspaceByName, z as RESOURCE_WATCH_TOOL_SOURCE, zt as downloadPrivateSlackFile } from "./agent-hooks-
|
|
18
|
-
import { B as briefLinkSchema, H as conversationBriefSchema, J as removedCardSchema, L as detectImageMediaType, R as isVisionImageMediaType, V as briefOutcomeStatusSchema } from "./conversation-
|
|
19
|
-
import {
|
|
20
|
-
import { n as canReusePendingAuthLink, t as abandonReplacedPendingAuth } from "./pending-auth-
|
|
21
|
-
import { c as isTurnInputCommitLostError, i as TurnInputCommitLostError, r as CooperativeTurnYieldError, t as authorizationId } from "./oauth-authorization-
|
|
22
|
-
import { a as isNoReplyMarker, i as NO_REPLY_MARKER, n as getAssistantReplyText, r as sanitizeAssistantText, t as decideReply } from "./assistant-reply-
|
|
23
|
-
import { C as pluginSupportsEvent, D as requireEventIdentifier, E as registeredResourceTypeSchema, L as readAutomationResult, N as FINISH_AUTOMATION_RUN_TOOL_NAME, O as requireSupportedEventMatch, P as automationResultSchema, R as remindMissingAutomationResult, S as hasEventCatalogEntries, T as registeredEventTypeSchema, _ as workspaceSnapshotFinishedEvent, d as requireSlackChannelMessageScope, g as WORKSPACE_SNAPSHOT_READY_EVENT, h as WORKSPACE_SNAPSHOT_FAILED_EVENT, l as getEventCatalog, n as markConversationsStopped, o as enqueueEventNotification, t as getConversationStoppedAtMs, v as workspaceSnapshotWatch, w as registeredEventMatchSchema, x as eventNamespaceSchema, y as automationEventCatalog } from "./session-stop-
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import { a as
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
1
|
+
import { S as resolveGatewayCredential, _ as getProviderErrorAttributes, a as completeText, b as MISSING_GATEWAY_CREDENTIALS_ERROR, c as COMPACTION_SUMMARY_PREFIX, d as renderCurrentInstruction, f as unwrapCurrentInstruction, g as findProviderError, h as createProviderError, i as completeObject, l as hasCompactedConversationContext, m as ProviderError, n as GEN_AI_SERVER_ADDRESS, p as escapeXml, s as resolveGatewayModel, t as GEN_AI_PROVIDER_NAME, u as isCompactionSummaryText, x as getGatewayApiKey, y as isProviderRetryError } from "./client-BZdxgKyL.js";
|
|
2
|
+
import { R as normalizeIdentityEmail, S as summarizeMessageText, T as withSpan, V as toOptionalString, _ as serializeGenAiAttribute, a as extractGenAiUsageSummary, b as setSpanStatus, c as getLogContextAttributesForSpan, d as logError, f as logException, h as normalizeGenAiFinishReason, i as extractGenAiUsageAttributes, l as getTracePropagationHeaders, m as logWarn, p as logInfo, u as logAudit, w as withLogContext, x as setTags, y as setSpanAttributes, z as isRecord$4 } from "./logging-BStXN56b.js";
|
|
3
|
+
import { m as startInactiveSpan, v as withActiveSpan } from "./sentry-BBUlHih9.js";
|
|
4
|
+
import { a as toCanonicalInputMessage, c as toGenAiPayloadMetadata, i as runWithConversationPrivacy, l as toGenAiPayloadTraceAttributes, o as toCanonicalOutputMessage, r as resolveConversationPrivacy, s as toGenAiMessagesTraceAttributes, t as canExposeConversationPayload } from "./conversation-privacy-CFhNKxp-.js";
|
|
5
|
+
import { n as botConfig, v as normalizeSlackEmojiName } from "./config-Deqpfpg9.js";
|
|
6
|
+
import { a as formatModelProfiles, c as profileConfig, i as formatModelProfile, l as TURN_REASONING_LEVELS, n as ModelProfileNotConfiguredError, o as modelIdForProfile, s as modelProfileSchema } from "./model-profile-Bg8EoCKD.js";
|
|
7
|
+
import { a as isUserActor, d as parseSlackTeamId, f as parseSlackUserId, g as parseSlackMessageTs, l as parseSlackChannelId, u as parseSlackChannelReferenceId } from "./actor-tlxzqaRe.js";
|
|
8
|
+
import { C as addAgentTurnUsage, D as hasAgentTurnUsage, R as parseDestination, c as getConversationEventStore, d as getDb, f as getSqlExecutor, l as getConversationMessageSearchStore, r as readActorIdentity, u as getConversationStore, w as agentTurnCostUsd } from "./viewer-B2_ABsYi.js";
|
|
9
|
+
import { a as juniorAgentInvocations, c as juniorIdentities, d as juniorDestinations, i as juniorAgentBindings, n as AGENT_INVOCATION_PARENT_MAILBOX_STATUSES, s as juniorConversations, t as AGENT_INVOCATION_MAILBOX_STATUSES } from "./agent-invocations-Qfz7dWgU.js";
|
|
10
|
+
import { _ as juniorConversationAnnotations, a as juniorAutomationRuns, b as juniorAttachments, c as juniorStats, f as juniorConversationBriefs, x as juniorArtifacts } from "./executor-Bb3eQb8q.js";
|
|
11
|
+
import { d as contextProvenance, f as instructionActors, m as sameActorIdentity, p as instructionProvenanceFor, t as KNOWN_CONVERSATION_EVENT_TYPES, u as agentInstructionProvenance } from "./history-AY8rs-FR.js";
|
|
12
|
+
import { a as listReferenceFiles, c as soulPathCandidates, l as worldPathCandidates } from "./package-discovery-DJBompdd.js";
|
|
13
|
+
import { _ as CredentialUnavailableError, a as resolveAuthTokenPlaceholder, c as fetchWithBoundedOAuthErrorBodies, d as actorLogContext, f as credentialContextForActor, g as credentialUserSubjectId, i as resolvePluginHeaderEnvRefs, l as getOAuthProviderErrorAttributes, o as resolvePluginCommandEnv, p as credentialContextSchema, s as OAuthProviderError } from "./registry-B_M_x_iS.js";
|
|
14
|
+
import { n as pluginCatalogRuntime } from "./catalog-runtime-B8SuFPGb.js";
|
|
15
|
+
import { a as parseSkillInvocation, i as parseSkillFile, n as findSkillByName, r as loadSkillsByName, t as discoverSkills } from "./skills-CiWS5_Ub.js";
|
|
16
|
+
import { A as escapeSlackMrkdwnText, B as postSlackMessage, Ct as ToolInputError, Dt as loadConversationProjection, Et as loadConnectedMcpProviders, G as continuableMessages, H as uploadFilesToConversation, Ht as recordTurnRoute, I as addReactionToMessage, K as loadTurnCheckpoint, L as getSlackMessagePermalink, Lt as recordAuthorizationRequested, Mt as openConversationProjection, Nt as recordAgentsInstructionsUpdated, O as automationRevision, Ot as loadLastModelProfile, P as slackMention, Pt as recordAttachmentsDelivered, R as openSlackDirectMessage, Rt as recordGuardianActionReviewed, St as TURN_CONTEXT_TAG, Vt as recordToolExecutionStarted, Xt as fallbackShortTitle, Zt as resolveTaskTitle, _t as isToolResultMessage, a as saveScheduledAutomation, bt as stripRuntimeTurnContext, ct as extractAssistantText, d as createEventAutomation, dn as getAgentContextInputLimitTokens, dt as getUserMessageInstructionText, f as deleteEventAutomation, fn as historyItemFromPiMessage, ft as hasRuntimeTurnContext, g as listEventAutomationsForTeam, gt as isToolResultError, ht as isContinuablePiBoundary, i as readScheduledAutomation, it as TurnToolCallLimitExceededError, j as formatSlackLink, jt as loadTurnRoute, ln as estimateTextTokens, lt as getPiMessageRole, m as getEventAutomation, mt as isAssistantMessage, n as listScheduledAutomationsForTeam, nt as TurnBudgetExceededError, ot as createTurnLimitGate, pn as piMessageFromHistoryItem, q as saveTurnCheckpoint, rt as TurnSliceLimitExceededError, st as isTurnExecutionLimitExceededError, t as createScheduledAutomation, tt as TURN_LIMIT_DISABLED_REASON, un as getAgentContextCompactionTriggerTokens, ut as getTerminalAssistantMessages, v as saveEventAutomation, vt as normalizeToolNameFromResult, xt as trimTrailingAssistantMessages, y as setEventAutomationStatus, yt as retainRuntimeTurnContext, z as postSlackEphemeralMessage, zt as recordMcpProviderConnected } from "./tasks-DieKX3d4.js";
|
|
17
|
+
import { A as getWorkspaceSnapshotBuilder, B as STOP_WATCHING_TOOL_NAME, Bt as getFilePermalink, C as WorkspaceValidationError, D as setWorkspaceSnapshotBuild, Dt as matchSlackAttachments, E as setWorkspaceSnapshot, F as isSlackMessageTurn, Ft as defaultTimezone, G as createWatch, Gt as normalizeSlackConversationId, H as cancelWatch, Ht as getSlackClient, I as slackMessageTurnDisabledReason, It as resolveUserTimezone, J as getWatch, K as deliverWatch, L as RESOURCE_SUBSCRIPTION_DEFAULT_TTL_MS, M as workspaceRepoCheckoutPath, Mt as createPluginAnnotations, N as resolveChannelCapabilities, O as SANDBOX_RUNTIME, P as getSlackToolContext, R as RESOURCE_SUBSCRIPTION_MAX_TTL_MS, Rt as SlackActionError, S as updateWorkspace, T as loadSnapshotsForProfile, Ut as isConversationScopedChannel, V as cancelSubscriptions, W as createTimerWatch, Wt as isDmChannel$1, Xt as JUNIOR_NATIVE_EVENT_NAMESPACE, Y as listWatches, _ as deleteWorkspace, at as getDashboardConversationLink, b as listWorkspaces, c as getPluginTools, en as conversationNoteEvent, ft as createPluginLogger, g as createWorkspace, j as tryWorkspaceRepoCheckoutPath, jt as saveObjectAnnotations, k as deleteWorkspaceSnapshotBuilders, l as getPluginUserPromptContributions, q as findMatchingWatches, qt as withSlackRetries, r as createPluginHookRunner, s as getPluginSystemPromptContributions, st as getDashboardTaskLink, u as getPlugins, v as getWorkspace, w as invalidateReadySnapshot, y as getWorkspaceByName, z as RESOURCE_WATCH_TOOL_SOURCE, zt as downloadPrivateSlackFile } from "./agent-hooks-B00FaKdP.js";
|
|
18
|
+
import { B as briefLinkSchema, H as conversationBriefSchema, J as removedCardSchema, L as detectImageMediaType, R as isVisionImageMediaType, V as briefOutcomeStatusSchema } from "./conversation-DjN3mlog.js";
|
|
19
|
+
import { C as SANDBOX_DATA_ROOT, D as sandboxSkillDir, E as SANDBOX_WORKSPACE_ROOT, O as sandboxSkillFile, S as sleep, T as SANDBOX_SKILLS_ROOT, _ as workspaceSnapshotNotReadyUserMessage, a as isAbortError, b as buildNonInteractiveShellScript, c as isSandboxCommandStreamInterruptedError, d as isSnapshottingError, f as throwSandboxOperationError, g as isWorkspaceSnapshotNotReadyError, h as getWorkspaceSnapshotNotReadyError, i as ensureDockerDaemon, k as sandboxSkillPathResolution, l as isSandboxMissingError, m as WorkspaceSnapshotNotReadyError, n as hash, o as isAlreadyExistsError, p as wrapSandboxSetupError, r as isStale, s as isSandboxApiTransientError, t as create, u as isSandboxUnavailableError, v as getVercelSandboxCredentials, w as SANDBOX_REPOS_ROOT, x as runNonInteractiveCommand, y as buildCommandScript } from "./profile-qBM6B_-V.js";
|
|
20
|
+
import { n as canReusePendingAuthLink, t as abandonReplacedPendingAuth } from "./pending-auth-rG5U_QS1.js";
|
|
21
|
+
import { c as isTurnInputCommitLostError, i as TurnInputCommitLostError, r as CooperativeTurnYieldError, t as authorizationId } from "./oauth-authorization-djQn5Nhy.js";
|
|
22
|
+
import { a as isNoReplyMarker, i as NO_REPLY_MARKER, n as getAssistantReplyText, r as sanitizeAssistantText, t as decideReply } from "./assistant-reply-CqthTerd.js";
|
|
23
|
+
import { C as pluginSupportsEvent, D as requireEventIdentifier, E as registeredResourceTypeSchema, L as readAutomationResult, N as FINISH_AUTOMATION_RUN_TOOL_NAME, O as requireSupportedEventMatch, P as automationResultSchema, R as remindMissingAutomationResult, S as hasEventCatalogEntries, T as registeredEventTypeSchema, _ as workspaceSnapshotFinishedEvent, d as requireSlackChannelMessageScope, g as WORKSPACE_SNAPSHOT_READY_EVENT, h as WORKSPACE_SNAPSHOT_FAILED_EVENT, l as getEventCatalog, n as markConversationsStopped, o as enqueueEventNotification, t as getConversationStoppedAtMs, v as workspaceSnapshotWatch, w as registeredEventMatchSchema, x as eventNamespaceSchema, y as automationEventCatalog } from "./session-stop-CV65ZlU3.js";
|
|
24
|
+
import { a as acquireActiveLock, o as fenceLock, r as getStateAdapter, s as withLock } from "./adapter-Bn0gFVSF.js";
|
|
25
|
+
import { i as isValidTimeZone, r as getZonedDateTimeParts } from "./cadence-R7Em4RjE.js";
|
|
26
|
+
import { a as createSandboxSession, c as postinstall, d as getSandboxResources, i as bindSandboxFileSystem, l as setSnapshotSpanAttributes, n as isMissingError, o as stopSession, r as resolve$1, s as dependencies } from "./resolve-BzpuLh8c.js";
|
|
27
|
+
import { a as getVercelConversationWorkQueue, f as getTurnRequestDeadline, n as sendNextWorkspaceSnapshotJob, r as sendWorkspaceSnapshotJob } from "./job-queue-vdGU-5ge.js";
|
|
28
|
+
import { E as stopConversationWork } from "./store-B1GES4gC.js";
|
|
29
|
+
import { _ as getMcpProviderErrorAttributes, a as serviceAccountOnly, c as createMcpServiceAccountClientProvider, d as PluginMcpClient, f as McpProviderError, g as getMcpAwareTelemetryMessage, h as getMcpAwareErrorType, i as serviceAccountAllows, l as getMcpServiceAccountCredentials, m as McpToolError, p as McpServiceAccountRequiredError, u as McpAuthorizationRequiredError, v as toMcpProviderError } from "./service-account-BzhW7kXu.js";
|
|
30
|
+
import { F as taskOutcomeInputSchema, M as compileScheduleIntent, N as scheduleIntentSchema, O as automationInstructionToolSchema, T as SCHEDULED_AUTOMATION_SYSTEM_ACTOR, j as ScheduleIntentError, k as automationTitleSchema } from "./automation-DWBFBenG.js";
|
|
31
|
+
import { r as isExperimentalFeatureEnabled } from "./experimental-BNK1l1jv.js";
|
|
32
|
+
import { n as privateTraceResultAttributes } from "./private-trace-result-CE7_lEdq.js";
|
|
31
33
|
import { streamSimple } from "@earendil-works/pi-ai/compat";
|
|
32
34
|
import { createGatewayProvider } from "@ai-sdk/gateway";
|
|
33
35
|
import { generateText } from "ai";
|
|
34
36
|
import path from "node:path";
|
|
35
37
|
import { isDeepStrictEqual } from "node:util";
|
|
36
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
37
38
|
import { z } from "zod";
|
|
38
39
|
import { createHash, createHmac, randomBytes, randomUUID, timingSafeEqual } from "node:crypto";
|
|
39
40
|
import { and, asc, count, countDistinct, desc, eq, gt, gte, inArray, isNotNull, isNull, lt, lte, ne, notExists, or, sql } from "drizzle-orm";
|
|
@@ -47,9 +48,7 @@ import { Kind } from "@sinclair/typebox";
|
|
|
47
48
|
import { Sandbox } from "@vercel/sandbox";
|
|
48
49
|
import { Bash, defineCommand } from "just-bash";
|
|
49
50
|
import { structuredPatch } from "diff";
|
|
50
|
-
import {
|
|
51
|
-
import { UnauthorizedError } from "@modelcontextprotocol/sdk/client/auth.js";
|
|
52
|
-
import { StreamableHTTPClientTransport, StreamableHTTPError } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
51
|
+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
53
52
|
import dns from "node:dns/promises";
|
|
54
53
|
import http from "node:http";
|
|
55
54
|
import https from "node:https";
|
|
@@ -57,7 +56,7 @@ import net from "node:net";
|
|
|
57
56
|
import { NodeHtmlMarkdown } from "node-html-markdown";
|
|
58
57
|
import { Value } from "@sinclair/typebox/value";
|
|
59
58
|
import { SignJWT, importPKCS8 } from "jose";
|
|
60
|
-
|
|
59
|
+
// src/chat/configuration/defaults.ts
|
|
61
60
|
let installDefaults = {};
|
|
62
61
|
function cloneDefaults(defaults) {
|
|
63
62
|
return structuredClone(defaults);
|
|
@@ -78,8 +77,7 @@ function setConfigDefaults(defaults) {
|
|
|
78
77
|
function getConfigDefaults() {
|
|
79
78
|
return cloneDefaults(installDefaults);
|
|
80
79
|
}
|
|
81
|
-
|
|
82
|
-
//#region src/chat/sandbox/skill-sandbox.ts
|
|
80
|
+
// src/chat/sandbox/skill-sandbox.ts
|
|
83
81
|
const MAX_SKILL_FILE_BYTES = 262144;
|
|
84
82
|
const DEFAULT_MAX_SKILL_FILE_CHARS = 2e4;
|
|
85
83
|
const DEFAULT_MAX_SKILL_LIST_ENTRIES = 200;
|
|
@@ -219,12 +217,12 @@ var SkillSandbox = class {
|
|
|
219
217
|
}
|
|
220
218
|
const active = this.getActiveSkill();
|
|
221
219
|
if (active) return active;
|
|
222
|
-
|
|
220
|
+
const [onlySkill, ...otherSkills] = this.loadedSkills.values();
|
|
221
|
+
if (onlySkill && otherSkills.length === 0) return onlySkill;
|
|
223
222
|
throw new Error("No active skill is loaded. Call loadSkill first or pass skill_name explicitly.");
|
|
224
223
|
}
|
|
225
224
|
};
|
|
226
|
-
|
|
227
|
-
//#region src/chat/tools/sandbox/file-utils.ts
|
|
225
|
+
// src/chat/tools/sandbox/file-utils.ts
|
|
228
226
|
const MAX_TEXT_CHARS = 6e4;
|
|
229
227
|
const RIPGREP_EXCLUDED_GLOBS = ["!**/.git/**", "!**/node_modules/**"];
|
|
230
228
|
const DEFAULT_SEARCH_COMMAND_TIMEOUT_MS = 3e4;
|
|
@@ -269,7 +267,7 @@ function escapeRegExp(value) {
|
|
|
269
267
|
function globToRegExp(pattern) {
|
|
270
268
|
let source = "";
|
|
271
269
|
for (let index = 0; index < pattern.length; index += 1) {
|
|
272
|
-
const char = pattern
|
|
270
|
+
const char = pattern.charAt(index);
|
|
273
271
|
const next = pattern[index + 1];
|
|
274
272
|
if (char === "*" && next === "*") {
|
|
275
273
|
if (pattern[index + 2] === "/") {
|
|
@@ -390,8 +388,7 @@ async function collectFiles(params) {
|
|
|
390
388
|
missingRoot: missingPath === params.root
|
|
391
389
|
};
|
|
392
390
|
}
|
|
393
|
-
|
|
394
|
-
//#region src/chat/repository-instructions.ts
|
|
391
|
+
// src/chat/repository-instructions.ts
|
|
395
392
|
const AGENTS_FILENAME = "AGENTS.md";
|
|
396
393
|
const MAX_REPOSITORY_INSTRUCTIONS_BYTES = 32768;
|
|
397
394
|
/** Repository skill directories, in priority order, relative to the Git root. */
|
|
@@ -649,8 +646,7 @@ function findVisibleAgentsInstructions(messages) {
|
|
|
649
646
|
}
|
|
650
647
|
}
|
|
651
648
|
}
|
|
652
|
-
|
|
653
|
-
//#region src/chat/agent/repository-context.ts
|
|
649
|
+
// src/chat/agent/repository-context.ts
|
|
654
650
|
function findRestoredInstructions(messages, provenance) {
|
|
655
651
|
const restoredContext = messages?.map((message, index) => ({
|
|
656
652
|
message,
|
|
@@ -691,8 +687,7 @@ function createRepositoryInstructionsContext(options) {
|
|
|
691
687
|
};
|
|
692
688
|
} };
|
|
693
689
|
}
|
|
694
|
-
|
|
695
|
-
//#region src/chat/pi/traced-stream.ts
|
|
690
|
+
// src/chat/pi/traced-stream.ts
|
|
696
691
|
function attributeModeForPrivacy(conversationPrivacy) {
|
|
697
692
|
return conversationPrivacy === "public" ? "content" : "metadata";
|
|
698
693
|
}
|
|
@@ -800,13 +795,11 @@ function createTracedStreamFn(baseOrOptions = streamSimple) {
|
|
|
800
795
|
}
|
|
801
796
|
};
|
|
802
797
|
}
|
|
803
|
-
|
|
804
|
-
//#region src/chat/runtime/dev-agent-trace.ts
|
|
798
|
+
// src/chat/runtime/dev-agent-trace.ts
|
|
805
799
|
function shouldEmitDevAgentTrace() {
|
|
806
800
|
return process.env.NODE_ENV === "development";
|
|
807
801
|
}
|
|
808
|
-
|
|
809
|
-
//#region src/chat/agent-invocations/blocked-report.ts
|
|
802
|
+
// src/chat/agent-invocations/blocked-report.ts
|
|
810
803
|
/** Blocked report of a child agent. See "Blocked Reports" in README.md. */
|
|
811
804
|
/** Model-facing tool that ends a child agent run as blocked. */
|
|
812
805
|
const REPORT_BLOCKED_TOOL_NAME = "reportBlocked";
|
|
@@ -825,8 +818,7 @@ function readBlockedReport(messages) {
|
|
|
825
818
|
if (parsed.success) return parsed.data;
|
|
826
819
|
}
|
|
827
820
|
}
|
|
828
|
-
|
|
829
|
-
//#region src/chat/services/turn-result.ts
|
|
821
|
+
// src/chat/services/turn-result.ts
|
|
830
822
|
/** Process raw agent messages into a structured AgentRunResult. */
|
|
831
823
|
function buildTurnResult(input) {
|
|
832
824
|
if (input.requireAutomationResult) return buildAutomationTurnResult(input);
|
|
@@ -939,8 +931,7 @@ function buildAutomationTurnResult(input) {
|
|
|
939
931
|
})
|
|
940
932
|
};
|
|
941
933
|
}
|
|
942
|
-
|
|
943
|
-
//#region src/chat/services/provider-retry.ts
|
|
934
|
+
// src/chat/services/provider-retry.ts
|
|
944
935
|
const PROVIDER_RETRY_DELAYS_MS = [
|
|
945
936
|
2e3,
|
|
946
937
|
4e3,
|
|
@@ -965,8 +956,7 @@ function nextProviderRetry(args) {
|
|
|
965
956
|
providerError
|
|
966
957
|
};
|
|
967
958
|
}
|
|
968
|
-
|
|
969
|
-
//#region src/chat/services/empty-output-continuation.ts
|
|
959
|
+
// src/chat/services/empty-output-continuation.ts
|
|
970
960
|
/**
|
|
971
961
|
* Decide whether empty assistant output gets one continuation after a
|
|
972
962
|
* history replacement.
|
|
@@ -987,8 +977,7 @@ function nextEmptyOutputContinuation(args) {
|
|
|
987
977
|
messages
|
|
988
978
|
} : { kind: "exhausted" };
|
|
989
979
|
}
|
|
990
|
-
|
|
991
|
-
//#region src/chat/agent/retry-usage.ts
|
|
980
|
+
// src/chat/agent/retry-usage.ts
|
|
992
981
|
/**
|
|
993
982
|
* Return usage discarded when a retry keeps an exact prefix of agent history.
|
|
994
983
|
*
|
|
@@ -999,8 +988,7 @@ function getDiscardedRetryUsage(messages, retryMessages) {
|
|
|
999
988
|
const usage = extractGenAiUsageSummary(...messages.slice(retryMessages.length).filter(isAssistantMessage));
|
|
1000
989
|
return hasAgentTurnUsage(usage) ? usage : void 0;
|
|
1001
990
|
}
|
|
1002
|
-
|
|
1003
|
-
//#region src/chat/tool-support/structured-result.ts
|
|
991
|
+
// src/chat/tool-support/structured-result.ts
|
|
1004
992
|
const juniorToolContinuationSchema = z.object({
|
|
1005
993
|
arguments: z.record(z.string(), z.unknown()),
|
|
1006
994
|
reason: z.string().min(1).optional()
|
|
@@ -1042,8 +1030,7 @@ function makeStructuredToolOutput(details, options = {}) {
|
|
|
1042
1030
|
details
|
|
1043
1031
|
};
|
|
1044
1032
|
}
|
|
1045
|
-
|
|
1046
|
-
//#region src/chat/tool-support/timed-out-tool-result.ts
|
|
1033
|
+
// src/chat/tool-support/timed-out-tool-result.ts
|
|
1047
1034
|
/**
|
|
1048
1035
|
* Project a host-preempted tool attempt onto the normal tool-result shape.
|
|
1049
1036
|
*
|
|
@@ -1068,8 +1055,7 @@ function projectTimedOutToolResult(result) {
|
|
|
1068
1055
|
isError: false
|
|
1069
1056
|
};
|
|
1070
1057
|
}
|
|
1071
|
-
|
|
1072
|
-
//#region src/chat/services/turn-router.ts
|
|
1058
|
+
// src/chat/services/turn-router.ts
|
|
1073
1059
|
const CLASSIFIER_CONFIDENCE_THRESHOLD = .75;
|
|
1074
1060
|
const MAX_ROUTER_CONTEXT_CHARS = 8e3;
|
|
1075
1061
|
const ROUTER_CONTEXT_HEAD_CHARS = 3e3;
|
|
@@ -1304,8 +1290,7 @@ function toPiReasoningLevel(level) {
|
|
|
1304
1290
|
case "xhigh": return "xhigh";
|
|
1305
1291
|
}
|
|
1306
1292
|
}
|
|
1307
|
-
|
|
1308
|
-
//#region src/chat/services/auth-pause.ts
|
|
1293
|
+
// src/chat/services/auth-pause.ts
|
|
1309
1294
|
/**
|
|
1310
1295
|
* Runtime-owned signal that the current turn must park until the user
|
|
1311
1296
|
* completes an external authorization step.
|
|
@@ -1344,8 +1329,7 @@ var AuthorizationFlowDisabledError = class extends Error {
|
|
|
1344
1329
|
this.provider = provider;
|
|
1345
1330
|
}
|
|
1346
1331
|
};
|
|
1347
|
-
|
|
1348
|
-
//#region src/chat/tools/definition.ts
|
|
1332
|
+
// src/chat/tools/definition.ts
|
|
1349
1333
|
/** Distinguish legacy TypeBox schemas from JSON Schema projected from Zod. */
|
|
1350
1334
|
function isTypeBoxInputSchema(schema) {
|
|
1351
1335
|
return typeof schema === "object" && schema !== null && Kind in schema;
|
|
@@ -1367,8 +1351,7 @@ function disableTools(tools, reason) {
|
|
|
1367
1351
|
disabledReason: reason
|
|
1368
1352
|
}]));
|
|
1369
1353
|
}
|
|
1370
|
-
|
|
1371
|
-
//#region src/chat/agent/types.ts
|
|
1354
|
+
// src/chat/agent/types.ts
|
|
1372
1355
|
/** Resume the agent turn after a transient or ambiguous delivery failure. */
|
|
1373
1356
|
var RetryableDeliveryError = class extends Error {
|
|
1374
1357
|
constructor(cause) {
|
|
@@ -1434,8 +1417,7 @@ function surfaceFromRun(run) {
|
|
|
1434
1417
|
if (run.source.kind === "web") return "api";
|
|
1435
1418
|
return "internal";
|
|
1436
1419
|
}
|
|
1437
|
-
|
|
1438
|
-
//#region src/chat/tool-support/action-review-history.ts
|
|
1420
|
+
// src/chat/tool-support/action-review-history.ts
|
|
1439
1421
|
const MAX_VISIBLE_HISTORY_CHARS = 12e3;
|
|
1440
1422
|
const priorRejectionSchema = z.object({
|
|
1441
1423
|
decision: z.enum(["ask", "deny"]),
|
|
@@ -1537,8 +1519,7 @@ function restoreToolActionRejections(messages) {
|
|
|
1537
1519
|
}
|
|
1538
1520
|
return priorRejections;
|
|
1539
1521
|
}
|
|
1540
|
-
|
|
1541
|
-
//#region src/chat/agent/action-confirmation-retry.ts
|
|
1522
|
+
// src/chat/agent/action-confirmation-retry.ts
|
|
1542
1523
|
const RUN_ENDING_TOOL_NAMES = /* @__PURE__ */ new Set([FINISH_AUTOMATION_RUN_TOOL_NAME, REPORT_BLOCKED_TOOL_NAME]);
|
|
1543
1524
|
function endsRun(message) {
|
|
1544
1525
|
return isToolResultMessage(message) && !isToolResultError(message) && RUN_ENDING_TOOL_NAMES.has(normalizeToolNameFromResult(message) ?? "");
|
|
@@ -1567,8 +1548,7 @@ function actionConfirmationRetryMessages(messages) {
|
|
|
1567
1548
|
if (getPiMessageRole(retryMessages.at(-1)) !== "toolResult") return;
|
|
1568
1549
|
return retryMessages;
|
|
1569
1550
|
}
|
|
1570
|
-
|
|
1571
|
-
//#region src/chat/tool-support/action-review.ts
|
|
1551
|
+
// src/chat/tool-support/action-review.ts
|
|
1572
1552
|
/**
|
|
1573
1553
|
* Owns the execution gate for reviewable tool actions.
|
|
1574
1554
|
*
|
|
@@ -1843,8 +1823,7 @@ async function reviewToolAction(toolCallId, toolName, tool, input, review, signa
|
|
|
1843
1823
|
if (!review) throw new ToolActionReviewUnavailableError();
|
|
1844
1824
|
return review.review(toolCallId, toolName, tool, input, signal);
|
|
1845
1825
|
}
|
|
1846
|
-
|
|
1847
|
-
//#region src/chat/agent/skills.ts
|
|
1826
|
+
// src/chat/agent/skills.ts
|
|
1848
1827
|
/** Run-scoped skill discovery and explicit invocation. */
|
|
1849
1828
|
let startupDiscoveryLogged = false;
|
|
1850
1829
|
/** Upsert a skill into the active skills list by name. */
|
|
@@ -1894,8 +1873,7 @@ async function loadRunSkill(args) {
|
|
|
1894
1873
|
if (loadedSkill) upsertActiveSkill(args.activeSkills, loadedSkill);
|
|
1895
1874
|
return loadedSkill;
|
|
1896
1875
|
}
|
|
1897
|
-
|
|
1898
|
-
//#region src/chat/prompt.ts
|
|
1876
|
+
// src/chat/prompt.ts
|
|
1899
1877
|
/**
|
|
1900
1878
|
* Prompt assembly.
|
|
1901
1879
|
*
|
|
@@ -2378,8 +2356,7 @@ function buildTurnContextPrompt(params) {
|
|
|
2378
2356
|
`</${TURN_CONTEXT_TAG}>`
|
|
2379
2357
|
].filter((section) => Boolean(section)).join("\n\n");
|
|
2380
2358
|
}
|
|
2381
|
-
|
|
2382
|
-
//#region src/chat/conversations/notes.ts
|
|
2359
|
+
// src/chat/conversations/notes.ts
|
|
2383
2360
|
/**
|
|
2384
2361
|
* Conversation notes: short facts that core attaches to a Conversation without
|
|
2385
2362
|
* starting a Turn. The next Turn shows them to the model in its runtime turn
|
|
@@ -2436,8 +2413,7 @@ async function loadTurnConversationNotes(input) {
|
|
|
2436
2413
|
}
|
|
2437
2414
|
return newestFirst.reverse();
|
|
2438
2415
|
}
|
|
2439
|
-
|
|
2440
|
-
//#region src/chat/agent/prompt.ts
|
|
2416
|
+
// src/chat/agent/prompt.ts
|
|
2441
2417
|
/**
|
|
2442
2418
|
* Per-run prompt assembly.
|
|
2443
2419
|
*
|
|
@@ -2812,8 +2788,7 @@ async function assemblePrompt(args) {
|
|
|
2812
2788
|
userContentParts
|
|
2813
2789
|
};
|
|
2814
2790
|
}
|
|
2815
|
-
|
|
2816
|
-
//#region src/chat/capabilities/router.ts
|
|
2791
|
+
// src/chat/capabilities/router.ts
|
|
2817
2792
|
var ProviderCredentialRouter = class {
|
|
2818
2793
|
brokersByProvider;
|
|
2819
2794
|
constructor(input) {
|
|
@@ -2828,11 +2803,9 @@ var ProviderCredentialRouter = class {
|
|
|
2828
2803
|
});
|
|
2829
2804
|
}
|
|
2830
2805
|
};
|
|
2831
|
-
|
|
2832
|
-
//#region src/chat/credentials/user-token-store.ts
|
|
2806
|
+
// src/chat/credentials/user-token-store.ts
|
|
2833
2807
|
const storedTokensSchema = pluginStoredTokensSchema;
|
|
2834
|
-
|
|
2835
|
-
//#region src/chat/credentials/state-adapter-token-store.ts
|
|
2808
|
+
// src/chat/credentials/state-adapter-token-store.ts
|
|
2836
2809
|
const KEY_PREFIX = "oauth-token";
|
|
2837
2810
|
const BUFFER_MS = 864e5;
|
|
2838
2811
|
const LONG_LIVED_TTL_MS = 31536e6;
|
|
@@ -2878,8 +2851,7 @@ var StateAdapterTokenStore = class {
|
|
|
2878
2851
|
}
|
|
2879
2852
|
}
|
|
2880
2853
|
};
|
|
2881
|
-
|
|
2882
|
-
//#region src/chat/capabilities/factory.ts
|
|
2854
|
+
// src/chat/capabilities/factory.ts
|
|
2883
2855
|
const sandboxEgressRouters = /* @__PURE__ */ new WeakMap();
|
|
2884
2856
|
/** Create the user token store used by OAuth-backed credential brokers. */
|
|
2885
2857
|
function createUserTokenStore() {
|
|
@@ -2907,8 +2879,7 @@ function getSandboxEgressRouter() {
|
|
|
2907
2879
|
async function issueProviderCredentialLease(input) {
|
|
2908
2880
|
return await getSandboxEgressRouter().issue(input);
|
|
2909
2881
|
}
|
|
2910
|
-
|
|
2911
|
-
//#region src/chat/capabilities/jr-rpc-command.ts
|
|
2882
|
+
// src/chat/capabilities/jr-rpc-command.ts
|
|
2912
2883
|
function commandResult(input) {
|
|
2913
2884
|
let stdout = "";
|
|
2914
2885
|
if (typeof input.stdout === "string") stdout = input.stdout;
|
|
@@ -2941,7 +2912,7 @@ function parsePrefixFlag(extras) {
|
|
|
2941
2912
|
...prefix ? { prefix } : void 0
|
|
2942
2913
|
};
|
|
2943
2914
|
}
|
|
2944
|
-
if (extras.length === 1 && extras[0]
|
|
2915
|
+
if (extras.length === 1 && extras[0]?.startsWith("--prefix=")) {
|
|
2945
2916
|
const prefix = extras[0].slice(9).trim();
|
|
2946
2917
|
return {
|
|
2947
2918
|
ok: true,
|
|
@@ -3163,8 +3134,7 @@ async function maybeExecuteJrRpcCustomCommand(command, deps) {
|
|
|
3163
3134
|
}
|
|
3164
3135
|
};
|
|
3165
3136
|
}
|
|
3166
|
-
|
|
3167
|
-
//#region src/chat/sandbox/command-result.ts
|
|
3137
|
+
// src/chat/sandbox/command-result.ts
|
|
3168
3138
|
/** Format one shell command outcome as Junior's structured tool result. */
|
|
3169
3139
|
function formatSandboxCommandResult(params) {
|
|
3170
3140
|
return makeStructuredToolOutput({
|
|
@@ -3184,8 +3154,7 @@ function formatSandboxCommandResult(params) {
|
|
|
3184
3154
|
...params.permission_denied ? { permission_denied: params.permission_denied } : void 0
|
|
3185
3155
|
});
|
|
3186
3156
|
}
|
|
3187
|
-
|
|
3188
|
-
//#region src/chat/slack/oauth-authorization-message.ts
|
|
3157
|
+
// src/chat/slack/oauth-authorization-message.ts
|
|
3189
3158
|
const ACCOUNT_SCOPE_NOTE = "This connects only your account. Junior sees only what you can see.";
|
|
3190
3159
|
/** Present private OAuth authorization with a clear action and text fallback. */
|
|
3191
3160
|
function buildSlackOAuthAuthorizationMessage(args) {
|
|
@@ -3210,8 +3179,7 @@ function buildSlackOAuthAuthorizationMessage(args) {
|
|
|
3210
3179
|
}]
|
|
3211
3180
|
};
|
|
3212
3181
|
}
|
|
3213
|
-
|
|
3214
|
-
//#region src/chat/oauth-flow.ts
|
|
3182
|
+
// src/chat/oauth-flow.ts
|
|
3215
3183
|
const OAUTH_STATE_TTL_MS = 6e5;
|
|
3216
3184
|
function optionalString(value) {
|
|
3217
3185
|
return typeof value === "string" ? value : void 0;
|
|
@@ -3377,8 +3345,7 @@ async function startOAuthFlow(provider, input) {
|
|
|
3377
3345
|
})
|
|
3378
3346
|
};
|
|
3379
3347
|
}
|
|
3380
|
-
|
|
3381
|
-
//#region src/chat/sandbox/egress/schemas.ts
|
|
3348
|
+
// src/chat/sandbox/egress/schemas.ts
|
|
3382
3349
|
const finiteNumberSchema = z.number().refine(Number.isFinite);
|
|
3383
3350
|
const httpStatusSchema = z.number().int().min(100).max(599);
|
|
3384
3351
|
const providerNameSchema = z.string().regex(/^[a-z][a-z0-9-]*$/);
|
|
@@ -3441,8 +3408,7 @@ function parseSandboxEgressPermissionDeniedSignal(value) {
|
|
|
3441
3408
|
const result = sandboxEgressPermissionDeniedSignalSchema.safeParse(value);
|
|
3442
3409
|
return result.success ? result.data : void 0;
|
|
3443
3410
|
}
|
|
3444
|
-
|
|
3445
|
-
//#region src/chat/sandbox/egress/session.ts
|
|
3411
|
+
// src/chat/sandbox/egress/session.ts
|
|
3446
3412
|
const SANDBOX_EGRESS_PROXY_PATH = "/api/internal/sandbox-egress";
|
|
3447
3413
|
const SANDBOX_EGRESS_TOKEN_VERSION = "v1";
|
|
3448
3414
|
const SANDBOX_EGRESS_HMAC_CONTEXT = "junior.sandbox_egress.v1";
|
|
@@ -3650,8 +3616,7 @@ async function consumeSandboxEgressPermissionDeniedSignal(egressId) {
|
|
|
3650
3616
|
await Promise.all([state.delete(permissionSignalKey(egressId, "read")), state.delete(permissionSignalKey(egressId, "write"))]);
|
|
3651
3617
|
return signal;
|
|
3652
3618
|
}
|
|
3653
|
-
|
|
3654
|
-
//#region src/chat/sandbox/egress/tracing.ts
|
|
3619
|
+
// src/chat/sandbox/egress/tracing.ts
|
|
3655
3620
|
function isValidDomainPattern(domain) {
|
|
3656
3621
|
if (domain.includes("*")) return domain.startsWith("*.") && domain.indexOf("*", 1) === -1;
|
|
3657
3622
|
return true;
|
|
@@ -3679,8 +3644,7 @@ function shouldPropagateSandboxEgressTrace(host, config = {}) {
|
|
|
3679
3644
|
return domain === normalizedHost;
|
|
3680
3645
|
});
|
|
3681
3646
|
}
|
|
3682
|
-
|
|
3683
|
-
//#region src/chat/sandbox/egress/policy.ts
|
|
3647
|
+
// src/chat/sandbox/egress/policy.ts
|
|
3684
3648
|
/** Return whether an outbound host is covered by a provider domain rule. */
|
|
3685
3649
|
function matchesSandboxEgressDomain(host, domain) {
|
|
3686
3650
|
return host.toLowerCase() === domain.toLowerCase();
|
|
@@ -3749,8 +3713,7 @@ async function resolveSandboxCommandEnvironment() {
|
|
|
3749
3713
|
}
|
|
3750
3714
|
return env;
|
|
3751
3715
|
}
|
|
3752
|
-
|
|
3753
|
-
//#region src/chat/sandbox/prepare-workspace.ts
|
|
3716
|
+
// src/chat/sandbox/prepare-workspace.ts
|
|
3754
3717
|
const WORKSPACE_SETUP_FAILURE_OUTPUT_MAX_CHARS = 7e3;
|
|
3755
3718
|
const WORKSPACE_SETUP_FAILURE_TRUNCATION_MARKER = "[earlier setup output truncated]\n";
|
|
3756
3719
|
const WORKSPACE_SETUP_NODE_OPTIONS = "--max-old-space-size=4096";
|
|
@@ -3830,8 +3793,7 @@ async function prepareWorkspaceSnapshot(params) {
|
|
|
3830
3793
|
});
|
|
3831
3794
|
if (result.exitCode !== 0) throw new Error(`Workspace setup failed: ${workspaceSetupFailureDetail(result)}`);
|
|
3832
3795
|
}
|
|
3833
|
-
|
|
3834
|
-
//#region src/chat/events/people.ts
|
|
3796
|
+
// src/chat/events/people.ts
|
|
3835
3797
|
const linkedSlackIdentity$1 = alias(juniorIdentities, "event_people_slack");
|
|
3836
3798
|
function personKey(person) {
|
|
3837
3799
|
return "email" in person ? `email:${normalizeIdentityEmail(person.email)}` : `${person.provider}:${person.handle.toLowerCase()}`;
|
|
@@ -3876,8 +3838,7 @@ async function resolveEventPeopleMentions(people, slackTeamId) {
|
|
|
3876
3838
|
}
|
|
3877
3839
|
return mentions;
|
|
3878
3840
|
}
|
|
3879
|
-
|
|
3880
|
-
//#region src/chat/events/ingest.ts
|
|
3841
|
+
// src/chat/events/ingest.ts
|
|
3881
3842
|
/** Match a normalized event and enqueue notifications into conversations. */
|
|
3882
3843
|
async function ingestEvent(input, options) {
|
|
3883
3844
|
const event = eventSchema.parse(input);
|
|
@@ -3929,8 +3890,7 @@ async function ingestEvent(input, options) {
|
|
|
3929
3890
|
if (errors.length > 0) throw new AggregateError(errors, "Failed to deliver one or more watches");
|
|
3930
3891
|
return { enqueued };
|
|
3931
3892
|
}
|
|
3932
|
-
|
|
3933
|
-
//#region src/chat/sandbox/snapshot/workspace.ts
|
|
3893
|
+
// src/chat/sandbox/snapshot/workspace.ts
|
|
3934
3894
|
const BUILD_TIMEOUT_MS = 36e5;
|
|
3935
3895
|
const BUILD_TIMEOUT_ERROR = "Workspace snapshot build timed out after 1 hour";
|
|
3936
3896
|
const BUILD_LOCK_TTL_MS = 12e4;
|
|
@@ -4312,8 +4272,7 @@ async function resolveWorkspaceSnapshot(params) {
|
|
|
4312
4272
|
await sleep(WAIT_POLL_MS, params.signal);
|
|
4313
4273
|
}
|
|
4314
4274
|
}
|
|
4315
|
-
|
|
4316
|
-
//#region src/chat/sandbox/snapshot/job-runner.ts
|
|
4275
|
+
// src/chat/sandbox/snapshot/job-runner.ts
|
|
4317
4276
|
/** Build Workspace snapshots in a background job. */
|
|
4318
4277
|
const SNAPSHOT_BUILD_SYSTEM_ACTOR = {
|
|
4319
4278
|
platform: "system",
|
|
@@ -4437,8 +4396,7 @@ async function ensureWorkspaceSnapshotBuild(input) {
|
|
|
4437
4396
|
else await sendWorkspaceSnapshotJob(message);
|
|
4438
4397
|
return "building";
|
|
4439
4398
|
}
|
|
4440
|
-
|
|
4441
|
-
//#region src/chat/sandbox/skill-sync.ts
|
|
4399
|
+
// src/chat/sandbox/skill-sync.ts
|
|
4442
4400
|
const DIRECTORY_CREATE_CONCURRENCY = 8;
|
|
4443
4401
|
function toPosixRelative(base, absolute) {
|
|
4444
4402
|
return path.relative(base, absolute).split(path.sep).join("/");
|
|
@@ -4567,8 +4525,7 @@ async function syncSkillsToSandbox(params) {
|
|
|
4567
4525
|
});
|
|
4568
4526
|
});
|
|
4569
4527
|
}
|
|
4570
|
-
|
|
4571
|
-
//#region src/chat/sandbox/session.ts
|
|
4528
|
+
// src/chat/sandbox/session.ts
|
|
4572
4529
|
const DEFAULT_MAX_OUTPUT_LENGTH = 3e4;
|
|
4573
4530
|
const DEFAULT_BASH_COMMAND_TIMEOUT_MS = 3e5;
|
|
4574
4531
|
const SANDBOX_RUNTIME_BIN_DIR = `${SANDBOX_WORKSPACE_ROOT}/.junior/bin`;
|
|
@@ -5158,8 +5115,7 @@ function createSandboxRuntime(options) {
|
|
|
5158
5115
|
}
|
|
5159
5116
|
};
|
|
5160
5117
|
}
|
|
5161
|
-
|
|
5162
|
-
//#region src/chat/tools/sandbox/text-edits.ts
|
|
5118
|
+
// src/chat/tools/sandbox/text-edits.ts
|
|
5163
5119
|
const MAX_DIFF_LINE_CHARS = 4e3;
|
|
5164
5120
|
/** Preserve a text artifact's dominant line-ending style across rewrites. */
|
|
5165
5121
|
function detectLineEnding(value) {
|
|
@@ -5279,8 +5235,7 @@ function validateAndApplyTextEdits(content, edits, targetName) {
|
|
|
5279
5235
|
};
|
|
5280
5236
|
});
|
|
5281
5237
|
const matchedEdits = [];
|
|
5282
|
-
for (
|
|
5283
|
-
const edit = normalizedEdits[index];
|
|
5238
|
+
for (const [index, edit] of normalizedEdits.entries()) {
|
|
5284
5239
|
const matchIndex = content.indexOf(edit.oldText);
|
|
5285
5240
|
if (matchIndex === -1) throw new ToolInputError(`Could not find edits[${index}] in ${targetName}. oldText must match exactly including whitespace and newlines.`);
|
|
5286
5241
|
const occurrences = countOccurrences(content, edit.oldText);
|
|
@@ -5293,24 +5248,20 @@ function validateAndApplyTextEdits(content, edits, targetName) {
|
|
|
5293
5248
|
});
|
|
5294
5249
|
}
|
|
5295
5250
|
matchedEdits.sort((a, b) => a.matchIndex - b.matchIndex);
|
|
5296
|
-
for (
|
|
5251
|
+
for (const [index, current] of matchedEdits.entries()) {
|
|
5297
5252
|
const previous = matchedEdits[index - 1];
|
|
5298
|
-
|
|
5253
|
+
if (!previous) continue;
|
|
5299
5254
|
if (previous.matchIndex + previous.matchLength > current.matchIndex) throw new ToolInputError(`edits[${previous.editIndex}] and edits[${current.editIndex}] overlap in ${targetName}. Merge overlapping replacements into one edit.`);
|
|
5300
5255
|
}
|
|
5301
5256
|
let newContent = content;
|
|
5302
|
-
for (
|
|
5303
|
-
const edit = matchedEdits[index];
|
|
5304
|
-
newContent = newContent.slice(0, edit.matchIndex) + edit.newText + newContent.slice(edit.matchIndex + edit.matchLength);
|
|
5305
|
-
}
|
|
5257
|
+
for (const edit of [...matchedEdits].reverse()) newContent = newContent.slice(0, edit.matchIndex) + edit.newText + newContent.slice(edit.matchIndex + edit.matchLength);
|
|
5306
5258
|
if (newContent === content) throw new ToolInputError(`No changes made to ${targetName}.`);
|
|
5307
5259
|
return {
|
|
5308
5260
|
baseContent: content,
|
|
5309
5261
|
newContent
|
|
5310
5262
|
};
|
|
5311
5263
|
}
|
|
5312
|
-
|
|
5313
|
-
//#region src/chat/tool-support/zod-tool.ts
|
|
5264
|
+
// src/chat/tool-support/zod-tool.ts
|
|
5314
5265
|
function isContentOnlyToolResult(value) {
|
|
5315
5266
|
return value !== null && typeof value === "object" && Array.isArray(value.content) && !("details" in value);
|
|
5316
5267
|
}
|
|
@@ -5367,8 +5318,7 @@ function zodTool(definition) {
|
|
|
5367
5318
|
} } : void 0
|
|
5368
5319
|
};
|
|
5369
5320
|
}
|
|
5370
|
-
|
|
5371
|
-
//#region src/chat/tools/sandbox/edit-file.ts
|
|
5321
|
+
// src/chat/tools/sandbox/edit-file.ts
|
|
5372
5322
|
/** Accept common edit argument variants before Pi validates the canonical schema. */
|
|
5373
5323
|
function prepareEditFileArguments(input) {
|
|
5374
5324
|
return prepareTextReplacementArguments(input);
|
|
@@ -5423,8 +5373,7 @@ function createEditFileTool() {
|
|
|
5423
5373
|
}
|
|
5424
5374
|
});
|
|
5425
5375
|
}
|
|
5426
|
-
|
|
5427
|
-
//#region src/chat/tools/sandbox/find-files.ts
|
|
5376
|
+
// src/chat/tools/sandbox/find-files.ts
|
|
5428
5377
|
const DEFAULT_FIND_LIMIT = 100;
|
|
5429
5378
|
/** Find workspace files with structured limits instead of ad hoc shell output. */
|
|
5430
5379
|
async function findFiles(params) {
|
|
@@ -5571,8 +5520,7 @@ function createFindFilesTool() {
|
|
|
5571
5520
|
}
|
|
5572
5521
|
});
|
|
5573
5522
|
}
|
|
5574
|
-
|
|
5575
|
-
//#region src/chat/tools/sandbox/grep.ts
|
|
5523
|
+
// src/chat/tools/sandbox/grep.ts
|
|
5576
5524
|
const DEFAULT_GREP_LIMIT = 100;
|
|
5577
5525
|
const MAX_GREP_LINE_CHARS = 500;
|
|
5578
5526
|
const booleanInput$2 = (description) => z.preprocess((value) => value === "true" ? true : value === "false" ? false : value, z.boolean()).describe(description);
|
|
@@ -5645,10 +5593,10 @@ async function grepFiles(params) {
|
|
|
5645
5593
|
const lines = normalizeToLf$1(content).split("\n");
|
|
5646
5594
|
const relativePath = files.length === 1 && filePath === root ? path.posix.basename(filePath) : path.posix.relative(root, filePath);
|
|
5647
5595
|
const matchedLines = [];
|
|
5648
|
-
for (
|
|
5596
|
+
for (const [lineIndex, line] of lines.entries()) {
|
|
5649
5597
|
if (!lineMatches({
|
|
5650
5598
|
ignoreCase: params.ignoreCase,
|
|
5651
|
-
line
|
|
5599
|
+
line,
|
|
5652
5600
|
literal: params.literal,
|
|
5653
5601
|
pattern: params.pattern,
|
|
5654
5602
|
regex
|
|
@@ -5668,7 +5616,7 @@ async function grepFiles(params) {
|
|
|
5668
5616
|
for (let current = start; current <= end; current += 1) {
|
|
5669
5617
|
if (emittedLines.has(current)) continue;
|
|
5670
5618
|
emittedLines.add(current);
|
|
5671
|
-
const truncated = truncateGrepLine(lines[current]);
|
|
5619
|
+
const truncated = truncateGrepLine(lines[current] ?? "");
|
|
5672
5620
|
lineTruncated ||= truncated.truncated;
|
|
5673
5621
|
const separator = matchedLineSet.has(current) ? ":" : "-";
|
|
5674
5622
|
output.push(`${relativePath}${separator}${current + 1}${separator} ${truncated.line}`);
|
|
@@ -5850,8 +5798,7 @@ function createGrepTool() {
|
|
|
5850
5798
|
}
|
|
5851
5799
|
});
|
|
5852
5800
|
}
|
|
5853
|
-
|
|
5854
|
-
//#region src/chat/tools/sandbox/list-dir.ts
|
|
5801
|
+
// src/chat/tools/sandbox/list-dir.ts
|
|
5855
5802
|
const DEFAULT_LIST_LIMIT = 500;
|
|
5856
5803
|
/** List workspace directories without forcing the model through shell output. */
|
|
5857
5804
|
async function listDir(params) {
|
|
@@ -5926,8 +5873,7 @@ function createListDirTool() {
|
|
|
5926
5873
|
}
|
|
5927
5874
|
});
|
|
5928
5875
|
}
|
|
5929
|
-
|
|
5930
|
-
//#region src/chat/tool-support/text-range-result.ts
|
|
5876
|
+
// src/chat/tool-support/text-range-result.ts
|
|
5931
5877
|
const DEFAULT_READ_LIMIT = 1e3;
|
|
5932
5878
|
const MAX_READ_CHARS = 6e4;
|
|
5933
5879
|
function positiveInteger(value) {
|
|
@@ -6001,8 +5947,7 @@ function sliceFileContent(params) {
|
|
|
6001
5947
|
function missingFileResult(path) {
|
|
6002
5948
|
throw new ToolInputError(`File not found: ${path}`);
|
|
6003
5949
|
}
|
|
6004
|
-
|
|
6005
|
-
//#region src/chat/tools/sandbox/read-file.ts
|
|
5950
|
+
// src/chat/tools/sandbox/read-file.ts
|
|
6006
5951
|
/** Create the sandbox read tool definition exposed to the agent. */
|
|
6007
5952
|
function createReadFileTool() {
|
|
6008
5953
|
return zodTool({
|
|
@@ -6024,8 +5969,7 @@ function createReadFileTool() {
|
|
|
6024
5969
|
}
|
|
6025
5970
|
});
|
|
6026
5971
|
}
|
|
6027
|
-
|
|
6028
|
-
//#region src/chat/sandbox/sandbox.ts
|
|
5972
|
+
// src/chat/sandbox/sandbox.ts
|
|
6029
5973
|
/** Create the safe expected tool error for an unavailable sandbox operation. */
|
|
6030
5974
|
function createSandboxUnavailableToolError(operation, cause) {
|
|
6031
5975
|
return new ToolInputError(`The temporary sandbox became unavailable during ${operation}, so the operation did not complete reliably. The next sandbox operation will use a fresh session. It may have produced side effects; retry only if it is safe.`, { cause });
|
|
@@ -6436,8 +6380,7 @@ function createSandbox(options) {
|
|
|
6436
6380
|
}
|
|
6437
6381
|
};
|
|
6438
6382
|
}
|
|
6439
|
-
|
|
6440
|
-
//#region src/chat/tools/sandbox/file-uploads.ts
|
|
6383
|
+
// src/chat/tools/sandbox/file-uploads.ts
|
|
6441
6384
|
/** Maximum single file size accepted by model-facing upload tools. */
|
|
6442
6385
|
const MAX_SANDBOX_FILE_UPLOAD_BYTES = 10485760;
|
|
6443
6386
|
/** Sandbox directory for generated files that later tools can consume. */
|
|
@@ -6539,8 +6482,7 @@ async function readSandboxFileUpload(workspace, input) {
|
|
|
6539
6482
|
path: targetPath
|
|
6540
6483
|
};
|
|
6541
6484
|
}
|
|
6542
|
-
|
|
6543
|
-
//#region src/chat/tools/sandbox/generated-artifacts.ts
|
|
6485
|
+
// src/chat/tools/sandbox/generated-artifacts.ts
|
|
6544
6486
|
async function fileUploadDataToBuffer(data) {
|
|
6545
6487
|
if (Buffer.isBuffer(data)) return data;
|
|
6546
6488
|
if (data instanceof ArrayBuffer) return Buffer.from(data);
|
|
@@ -6572,8 +6514,7 @@ async function writeSandboxGeneratedArtifacts(workspace, files) {
|
|
|
6572
6514
|
})));
|
|
6573
6515
|
return artifacts.map((artifact) => artifact.ref);
|
|
6574
6516
|
}
|
|
6575
|
-
|
|
6576
|
-
//#region src/chat/tool-support/normalize-result.ts
|
|
6517
|
+
// src/chat/tool-support/normalize-result.ts
|
|
6577
6518
|
function isToolContent(value) {
|
|
6578
6519
|
return Array.isArray(value) && value.every((part) => {
|
|
6579
6520
|
if (!part || typeof part !== "object") return false;
|
|
@@ -6714,8 +6655,7 @@ function normalizeToolResult(result, options = {}) {
|
|
|
6714
6655
|
details: normalized.details
|
|
6715
6656
|
};
|
|
6716
6657
|
}
|
|
6717
|
-
|
|
6718
|
-
//#region src/chat/agent/sandbox.ts
|
|
6658
|
+
// src/chat/agent/sandbox.ts
|
|
6719
6659
|
function record(value) {
|
|
6720
6660
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
6721
6661
|
}
|
|
@@ -6824,284 +6764,7 @@ function createAgentSandbox(options) {
|
|
|
6824
6764
|
}
|
|
6825
6765
|
};
|
|
6826
6766
|
}
|
|
6827
|
-
|
|
6828
|
-
//#region src/chat/mcp/errors.ts
|
|
6829
|
-
/** Safe failure at an MCP network or OAuth boundary. */
|
|
6830
|
-
var McpProviderError = class extends Error {
|
|
6831
|
-
phase;
|
|
6832
|
-
provider;
|
|
6833
|
-
missingSession;
|
|
6834
|
-
resourceHost;
|
|
6835
|
-
status;
|
|
6836
|
-
constructor(details) {
|
|
6837
|
-
super(`MCP provider ${details.phase.replace("_", " ")} failed`);
|
|
6838
|
-
this.name = "McpProviderError";
|
|
6839
|
-
this.phase = details.phase;
|
|
6840
|
-
this.provider = details.provider;
|
|
6841
|
-
this.missingSession = details.missingSession;
|
|
6842
|
-
this.resourceHost = details.resourceHost;
|
|
6843
|
-
this.status = details.status;
|
|
6844
|
-
}
|
|
6845
|
-
};
|
|
6846
|
-
function providerStatus(error) {
|
|
6847
|
-
if (!error || typeof error !== "object") return;
|
|
6848
|
-
const value = error;
|
|
6849
|
-
const status = typeof value.status === "number" ? value.status : typeof value.code === "number" ? value.code : void 0;
|
|
6850
|
-
return status !== void 0 && status >= 100 && status <= 599 ? status : void 0;
|
|
6851
|
-
}
|
|
6852
|
-
/** Replace an external MCP failure without retaining its provider-controlled cause. */
|
|
6853
|
-
function toMcpProviderError(error, details) {
|
|
6854
|
-
if (error instanceof McpProviderError) return error;
|
|
6855
|
-
return new McpProviderError({
|
|
6856
|
-
...details,
|
|
6857
|
-
status: details.status ?? providerStatus(error)
|
|
6858
|
-
});
|
|
6859
|
-
}
|
|
6860
|
-
/** Return safe MCP provider fields for logs and spans. */
|
|
6861
|
-
function getMcpProviderErrorAttributes(error) {
|
|
6862
|
-
if (!(error instanceof McpProviderError)) return {};
|
|
6863
|
-
return {
|
|
6864
|
-
"app.credential.provider": error.provider,
|
|
6865
|
-
"app.mcp.error.phase": error.phase,
|
|
6866
|
-
...error.status !== void 0 ? { "http.response.status_code": error.status } : void 0,
|
|
6867
|
-
...error.resourceHost ? { "server.address": error.resourceHost } : void 0
|
|
6868
|
-
};
|
|
6869
|
-
}
|
|
6870
|
-
/** Thrown when an MCP failure should be returned as a model-visible tool error. */
|
|
6871
|
-
var McpToolError = class extends Error {
|
|
6872
|
-
constructor(message) {
|
|
6873
|
-
super(message);
|
|
6874
|
-
this.name = "McpToolError";
|
|
6875
|
-
}
|
|
6876
|
-
};
|
|
6877
|
-
/** Return the OpenTelemetry error.type value for MCP-aware tool failures. */
|
|
6878
|
-
function getMcpAwareErrorType(error, fallback) {
|
|
6879
|
-
if (error instanceof McpToolError) return "tool_error";
|
|
6880
|
-
if (error instanceof McpProviderError) return "mcp_provider_error";
|
|
6881
|
-
return error instanceof Error ? error.name : fallback;
|
|
6882
|
-
}
|
|
6883
|
-
/** Return the display-safe error message for MCP-aware tool failures. */
|
|
6884
|
-
function getMcpAwareErrorMessage(error) {
|
|
6885
|
-
return error instanceof Error ? error.message : String(error);
|
|
6886
|
-
}
|
|
6887
|
-
/** Return an error message safe for logs and span attributes. */
|
|
6888
|
-
function getMcpAwareTelemetryMessage(error, _privacy) {
|
|
6889
|
-
if (error instanceof McpToolError) return "MCP tool call failed";
|
|
6890
|
-
if (error instanceof McpProviderError) return error.message;
|
|
6891
|
-
return getMcpAwareErrorMessage(error);
|
|
6892
|
-
}
|
|
6893
|
-
//#endregion
|
|
6894
|
-
//#region src/chat/mcp/client.ts
|
|
6895
|
-
const MCP_CLIENT_INFO = {
|
|
6896
|
-
name: "junior-mcp-client",
|
|
6897
|
-
version: "1.0.0"
|
|
6898
|
-
};
|
|
6899
|
-
const MCP_TOOLS_CALL_METHOD = "tools/call";
|
|
6900
|
-
function getDefaultPort(url) {
|
|
6901
|
-
if (url.protocol === "https:") return 443;
|
|
6902
|
-
if (url.protocol === "http:") return 80;
|
|
6903
|
-
}
|
|
6904
|
-
function getMcpNetworkAttributes(url) {
|
|
6905
|
-
const port = url.port ? Number(url.port) : getDefaultPort(url);
|
|
6906
|
-
return {
|
|
6907
|
-
"server.address": url.hostname,
|
|
6908
|
-
...port !== void 0 ? { "server.port": port } : void 0,
|
|
6909
|
-
...url.protocol === "http:" || url.protocol === "https:" ? {
|
|
6910
|
-
"network.protocol.name": "http",
|
|
6911
|
-
"network.transport": "tcp"
|
|
6912
|
-
} : void 0
|
|
6913
|
-
};
|
|
6914
|
-
}
|
|
6915
|
-
var McpAuthorizationRequiredError = class extends Error {
|
|
6916
|
-
provider;
|
|
6917
|
-
constructor(provider, message) {
|
|
6918
|
-
super(message);
|
|
6919
|
-
this.name = "McpAuthorizationRequiredError";
|
|
6920
|
-
this.provider = provider;
|
|
6921
|
-
}
|
|
6922
|
-
};
|
|
6923
|
-
function isMissingSessionError(error) {
|
|
6924
|
-
return error instanceof StreamableHTTPError && (error.code === 404 || /Session not found/i.test(error.message));
|
|
6925
|
-
}
|
|
6926
|
-
var PluginMcpClient = class {
|
|
6927
|
-
plugin;
|
|
6928
|
-
options;
|
|
6929
|
-
client;
|
|
6930
|
-
clientPromise;
|
|
6931
|
-
lastAttemptedTransportSessionId;
|
|
6932
|
-
providerStatusStore = new AsyncLocalStorage();
|
|
6933
|
-
transport;
|
|
6934
|
-
listedTools;
|
|
6935
|
-
resourceHost;
|
|
6936
|
-
constructor(plugin, options = {}) {
|
|
6937
|
-
this.plugin = plugin;
|
|
6938
|
-
this.options = options;
|
|
6939
|
-
const url = plugin.manifest.mcp?.url;
|
|
6940
|
-
this.resourceHost = url ? new URL(url).hostname : void 0;
|
|
6941
|
-
}
|
|
6942
|
-
async listTools() {
|
|
6943
|
-
if (this.listedTools) return [...this.listedTools];
|
|
6944
|
-
return await this.withSessionRecovery(async () => {
|
|
6945
|
-
const client = await this.getClient();
|
|
6946
|
-
const discovered = [];
|
|
6947
|
-
const seen = /* @__PURE__ */ new Set();
|
|
6948
|
-
let cursor;
|
|
6949
|
-
do {
|
|
6950
|
-
const result = await this.wrapAuth(() => client.listTools(cursor ? { cursor } : void 0), "list_tools");
|
|
6951
|
-
await this.syncTransportSessionId();
|
|
6952
|
-
for (const tool of result.tools) {
|
|
6953
|
-
if (seen.has(tool.name)) continue;
|
|
6954
|
-
seen.add(tool.name);
|
|
6955
|
-
discovered.push(tool);
|
|
6956
|
-
}
|
|
6957
|
-
cursor = result.nextCursor;
|
|
6958
|
-
} while (cursor);
|
|
6959
|
-
this.listedTools = discovered.sort((left, right) => left.name.localeCompare(right.name));
|
|
6960
|
-
return [...this.listedTools];
|
|
6961
|
-
});
|
|
6962
|
-
}
|
|
6963
|
-
async callTool(name, args, signal) {
|
|
6964
|
-
return await this.withSessionRecovery(async () => {
|
|
6965
|
-
const client = await this.getClient();
|
|
6966
|
-
const mcp = this.plugin.manifest.mcp;
|
|
6967
|
-
if (mcp) {
|
|
6968
|
-
const url = new URL(mcp.url);
|
|
6969
|
-
setSpanAttributes({
|
|
6970
|
-
"mcp.method.name": MCP_TOOLS_CALL_METHOD,
|
|
6971
|
-
"gen_ai.operation.name": "execute_tool",
|
|
6972
|
-
...this.transport?.sessionId ? { "mcp.session.id": this.transport.sessionId } : void 0,
|
|
6973
|
-
...this.transport?.protocolVersion ? { "mcp.protocol.version": this.transport.protocolVersion } : void 0,
|
|
6974
|
-
...getMcpNetworkAttributes(url)
|
|
6975
|
-
});
|
|
6976
|
-
}
|
|
6977
|
-
const result = await this.wrapAuth(() => client.callTool({
|
|
6978
|
-
name,
|
|
6979
|
-
arguments: args ?? {}
|
|
6980
|
-
}, void 0, signal ? { signal } : void 0), "call_tool");
|
|
6981
|
-
await this.syncTransportSessionId();
|
|
6982
|
-
return result;
|
|
6983
|
-
});
|
|
6984
|
-
}
|
|
6985
|
-
async close() {
|
|
6986
|
-
await this.disposeClient();
|
|
6987
|
-
}
|
|
6988
|
-
async withSessionRecovery(operation) {
|
|
6989
|
-
try {
|
|
6990
|
-
return await operation();
|
|
6991
|
-
} catch (error) {
|
|
6992
|
-
await this.syncTransportSessionId();
|
|
6993
|
-
if (!await this.shouldResetMissingSession(error)) throw error;
|
|
6994
|
-
await this.clearStoredTransportSessionId();
|
|
6995
|
-
await this.cleanupClientAfterFailure();
|
|
6996
|
-
return await operation();
|
|
6997
|
-
}
|
|
6998
|
-
}
|
|
6999
|
-
async getClient() {
|
|
7000
|
-
if (this.client) return this.client;
|
|
7001
|
-
if (this.clientPromise) return await this.clientPromise;
|
|
7002
|
-
const clientPromise = this.connectClient();
|
|
7003
|
-
this.clientPromise = clientPromise;
|
|
7004
|
-
try {
|
|
7005
|
-
return await clientPromise;
|
|
7006
|
-
} finally {
|
|
7007
|
-
if (this.clientPromise === clientPromise) this.clientPromise = void 0;
|
|
7008
|
-
}
|
|
7009
|
-
}
|
|
7010
|
-
async connectClient() {
|
|
7011
|
-
const mcp = this.plugin.manifest.mcp;
|
|
7012
|
-
if (!mcp) throw new Error(`Plugin "${this.plugin.manifest.name}" does not declare MCP config`);
|
|
7013
|
-
const headers = mcp.headers ? resolvePluginHeaderEnvRefs(this.plugin.manifest.name, mcp.headers, "MCP header") : void 0;
|
|
7014
|
-
const sessionId = await this.getStoredTransportSessionId();
|
|
7015
|
-
this.lastAttemptedTransportSessionId = sessionId;
|
|
7016
|
-
const transport = new StreamableHTTPClientTransport(new URL(mcp.url), {
|
|
7017
|
-
...headers ? { requestInit: { headers } } : void 0,
|
|
7018
|
-
fetch: fetchWithBoundedOAuthErrorBodies(this.options.fetch, (status) => {
|
|
7019
|
-
const store = this.providerStatusStore.getStore();
|
|
7020
|
-
if (store) store.status = status;
|
|
7021
|
-
}),
|
|
7022
|
-
...this.options.authProvider ? { authProvider: this.options.authProvider } : void 0,
|
|
7023
|
-
...sessionId ? { sessionId } : void 0
|
|
7024
|
-
});
|
|
7025
|
-
const client = new Client(MCP_CLIENT_INFO, { capabilities: {} });
|
|
7026
|
-
this.transport = transport;
|
|
7027
|
-
try {
|
|
7028
|
-
await this.wrapAuth(() => client.connect(transport), "connect");
|
|
7029
|
-
this.client = client;
|
|
7030
|
-
await this.syncTransportSessionId();
|
|
7031
|
-
return client;
|
|
7032
|
-
} catch (error) {
|
|
7033
|
-
await this.syncTransportSessionId();
|
|
7034
|
-
await this.cleanupClientAfterFailure();
|
|
7035
|
-
throw error;
|
|
7036
|
-
}
|
|
7037
|
-
}
|
|
7038
|
-
async wrapAuth(operation, phase) {
|
|
7039
|
-
const store = {};
|
|
7040
|
-
return await this.providerStatusStore.run(store, async () => {
|
|
7041
|
-
try {
|
|
7042
|
-
return await operation();
|
|
7043
|
-
} catch (error) {
|
|
7044
|
-
if (error instanceof McpAuthorizationRequiredError) throw error;
|
|
7045
|
-
if (error instanceof UnauthorizedError) throw new McpAuthorizationRequiredError(this.plugin.manifest.name, `MCP authorization required for plugin "${this.plugin.manifest.name}"`);
|
|
7046
|
-
throw toMcpProviderError(error, {
|
|
7047
|
-
phase,
|
|
7048
|
-
provider: this.plugin.manifest.name,
|
|
7049
|
-
missingSession: isMissingSessionError(error) || void 0,
|
|
7050
|
-
resourceHost: this.resourceHost,
|
|
7051
|
-
status: store.status
|
|
7052
|
-
});
|
|
7053
|
-
}
|
|
7054
|
-
});
|
|
7055
|
-
}
|
|
7056
|
-
async shouldResetMissingSession(error) {
|
|
7057
|
-
if (!(error instanceof McpProviderError && error.missingSession || isMissingSessionError(error))) return false;
|
|
7058
|
-
return Boolean(this.transport?.sessionId ?? this.lastAttemptedTransportSessionId ?? await this.getStoredTransportSessionId());
|
|
7059
|
-
}
|
|
7060
|
-
resetClientState() {
|
|
7061
|
-
const transport = this.transport;
|
|
7062
|
-
this.listedTools = void 0;
|
|
7063
|
-
this.transport = void 0;
|
|
7064
|
-
this.client = void 0;
|
|
7065
|
-
this.clientPromise = void 0;
|
|
7066
|
-
return transport;
|
|
7067
|
-
}
|
|
7068
|
-
async cleanupClientAfterFailure() {
|
|
7069
|
-
const transport = this.resetClientState();
|
|
7070
|
-
if (!transport) return;
|
|
7071
|
-
try {
|
|
7072
|
-
await transport.close();
|
|
7073
|
-
} catch {}
|
|
7074
|
-
}
|
|
7075
|
-
async disposeClient() {
|
|
7076
|
-
const transport = this.resetClientState();
|
|
7077
|
-
if (transport) try {
|
|
7078
|
-
await transport.close();
|
|
7079
|
-
} catch (error) {
|
|
7080
|
-
throw toMcpProviderError(error, {
|
|
7081
|
-
phase: "close",
|
|
7082
|
-
provider: this.plugin.manifest.name,
|
|
7083
|
-
resourceHost: this.resourceHost
|
|
7084
|
-
});
|
|
7085
|
-
}
|
|
7086
|
-
}
|
|
7087
|
-
async getStoredTransportSessionId() {
|
|
7088
|
-
return await this.options.authProvider?.getMcpServerSessionId?.();
|
|
7089
|
-
}
|
|
7090
|
-
async clearStoredTransportSessionId() {
|
|
7091
|
-
const provider = this.options.authProvider;
|
|
7092
|
-
this.lastAttemptedTransportSessionId = void 0;
|
|
7093
|
-
await provider?.saveMcpServerSessionId?.(void 0);
|
|
7094
|
-
}
|
|
7095
|
-
async syncTransportSessionId() {
|
|
7096
|
-
const provider = this.options.authProvider;
|
|
7097
|
-
const sessionId = this.transport?.sessionId;
|
|
7098
|
-
if (!provider?.saveMcpServerSessionId || !sessionId) return;
|
|
7099
|
-
this.lastAttemptedTransportSessionId = sessionId;
|
|
7100
|
-
await provider.saveMcpServerSessionId(sessionId);
|
|
7101
|
-
}
|
|
7102
|
-
};
|
|
7103
|
-
//#endregion
|
|
7104
|
-
//#region src/chat/mcp/tool-manager.ts
|
|
6767
|
+
// src/chat/mcp/tool-manager.ts
|
|
7105
6768
|
const MAX_TOOL_RESULT_TOKENS = 1e4;
|
|
7106
6769
|
const MAX_TOOL_RESULT_BYTES = 32768;
|
|
7107
6770
|
const CHARS_PER_ESTIMATED_TOKEN = 4;
|
|
@@ -7233,13 +6896,16 @@ function extractMcpErrorMessage(result) {
|
|
|
7233
6896
|
return "MCP tool call failed";
|
|
7234
6897
|
}
|
|
7235
6898
|
var McpToolManager = class {
|
|
7236
|
-
options;
|
|
7237
6899
|
pluginsByProvider = /* @__PURE__ */ new Map();
|
|
7238
6900
|
activeProviders = /* @__PURE__ */ new Set();
|
|
7239
6901
|
authorizationPendingProviders = /* @__PURE__ */ new Set();
|
|
7240
6902
|
clientsByProvider = /* @__PURE__ */ new Map();
|
|
6903
|
+
/** Actor clients for tools that a provider's service account may not call. */
|
|
6904
|
+
actorClientsByProvider = /* @__PURE__ */ new Map();
|
|
6905
|
+
serviceAccountProviders = /* @__PURE__ */ new Set();
|
|
7241
6906
|
clientPromisesByProvider = /* @__PURE__ */ new Map();
|
|
7242
6907
|
toolsByProvider = /* @__PURE__ */ new Map();
|
|
6908
|
+
options;
|
|
7243
6909
|
constructor(plugins, options = {}) {
|
|
7244
6910
|
this.options = options;
|
|
7245
6911
|
for (const plugin of plugins) if (plugin.manifest.mcp) this.pluginsByProvider.set(plugin.manifest.name, plugin);
|
|
@@ -7262,8 +6928,9 @@ var McpToolManager = class {
|
|
|
7262
6928
|
if (!plugin?.manifest.mcp) return false;
|
|
7263
6929
|
try {
|
|
7264
6930
|
const client = await this.getClient(plugin);
|
|
7265
|
-
const
|
|
7266
|
-
this.assertWrappedToolsAvailable(plugin,
|
|
6931
|
+
const listedTools = this.filterListedTools(plugin, await client.listTools());
|
|
6932
|
+
this.assertWrappedToolsAvailable(plugin, listedTools);
|
|
6933
|
+
const tools = this.filterServiceAccountOnlyTools(plugin, listedTools);
|
|
7267
6934
|
this.toolsByProvider.set(provider, tools.map((tool) => this.toManagedTool(plugin, client, tool)));
|
|
7268
6935
|
this.activeProviders.add(provider);
|
|
7269
6936
|
return true;
|
|
@@ -7274,12 +6941,14 @@ var McpToolManager = class {
|
|
|
7274
6941
|
}
|
|
7275
6942
|
async close() {
|
|
7276
6943
|
let firstError;
|
|
7277
|
-
for (const client of this.clientsByProvider.values()) try {
|
|
6944
|
+
for (const client of [...this.clientsByProvider.values(), ...this.actorClientsByProvider.values()]) try {
|
|
7278
6945
|
await client.close();
|
|
7279
6946
|
} catch (error) {
|
|
7280
6947
|
firstError ??= error;
|
|
7281
6948
|
}
|
|
7282
6949
|
this.clientsByProvider.clear();
|
|
6950
|
+
this.actorClientsByProvider.clear();
|
|
6951
|
+
this.serviceAccountProviders.clear();
|
|
7283
6952
|
this.toolsByProvider.clear();
|
|
7284
6953
|
this.activeProviders.clear();
|
|
7285
6954
|
this.authorizationPendingProviders.clear();
|
|
@@ -7305,6 +6974,14 @@ var McpToolManager = class {
|
|
|
7305
6974
|
const missingTools = wrappedTools.filter((toolName) => !availableToolNames.has(toolName));
|
|
7306
6975
|
if (missingTools.length > 0) throw new Error(`Plugin ${plugin.manifest.name} MCP discovery missing wrapped tools: ${missingTools.join(", ")}`);
|
|
7307
6976
|
}
|
|
6977
|
+
/**
|
|
6978
|
+
* Hide tools that the service account does not list when no Actor
|
|
6979
|
+
* connection exists to call them.
|
|
6980
|
+
*/
|
|
6981
|
+
filterServiceAccountOnlyTools(plugin, tools) {
|
|
6982
|
+
if (!serviceAccountOnly(plugin.manifest)) return tools;
|
|
6983
|
+
return tools.filter((tool) => serviceAccountAllows(plugin.manifest, { tool: tool.name }));
|
|
6984
|
+
}
|
|
7308
6985
|
async getClient(plugin) {
|
|
7309
6986
|
const existing = this.clientsByProvider.get(plugin.manifest.name);
|
|
7310
6987
|
if (existing) return existing;
|
|
@@ -7319,13 +6996,30 @@ var McpToolManager = class {
|
|
|
7319
6996
|
}
|
|
7320
6997
|
}
|
|
7321
6998
|
async createClient(plugin) {
|
|
7322
|
-
const
|
|
7323
|
-
|
|
6999
|
+
const serviceAccount = await this.options.serviceAccountProviderFactory?.(plugin);
|
|
7000
|
+
if (serviceAccount) this.serviceAccountProviders.add(plugin.manifest.name);
|
|
7001
|
+
const client = await this.newClient(plugin, serviceAccount);
|
|
7002
|
+
this.clientsByProvider.set(plugin.manifest.name, client);
|
|
7003
|
+
return client;
|
|
7004
|
+
}
|
|
7005
|
+
async newClient(plugin, serviceAccount) {
|
|
7006
|
+
if (!serviceAccount && serviceAccountOnly(plugin.manifest)) throw new McpServiceAccountRequiredError(plugin.manifest.name, plugin.manifest.displayName);
|
|
7007
|
+
const authProvider = serviceAccount ?? await this.options.authProviderFactory?.(plugin);
|
|
7008
|
+
return new PluginMcpClient(plugin, {
|
|
7324
7009
|
...authProvider ? { authProvider } : void 0,
|
|
7325
7010
|
...this.options.fetch ? { fetch: this.options.fetch } : void 0
|
|
7326
7011
|
});
|
|
7327
|
-
|
|
7328
|
-
|
|
7012
|
+
}
|
|
7013
|
+
/** Pick the client for one call: the service account for its tools, else the actor. */
|
|
7014
|
+
async clientForTool(plugin, client, toolName) {
|
|
7015
|
+
const provider = plugin.manifest.name;
|
|
7016
|
+
if (!this.serviceAccountProviders.has(provider) || serviceAccountAllows(plugin.manifest, { tool: toolName })) return client;
|
|
7017
|
+
if (serviceAccountOnly(plugin.manifest)) throw new McpToolError(`${plugin.manifest.displayName} tool ${toolName} is not available: Junior's shared ${plugin.manifest.displayName} account cannot use it`);
|
|
7018
|
+
const existing = this.actorClientsByProvider.get(provider);
|
|
7019
|
+
if (existing) return existing;
|
|
7020
|
+
const actorClient = await this.newClient(plugin);
|
|
7021
|
+
this.actorClientsByProvider.set(provider, actorClient);
|
|
7022
|
+
return actorClient;
|
|
7329
7023
|
}
|
|
7330
7024
|
toManagedTool(plugin, client, tool) {
|
|
7331
7025
|
const outputSchema = toOptionalRecord(tool.outputSchema);
|
|
@@ -7361,7 +7055,7 @@ var McpToolManager = class {
|
|
|
7361
7055
|
const argumentAttribute = serializeMcpPayload(resolvedArgs, conversationPrivacy, { privateMetadata: true });
|
|
7362
7056
|
return await withSpan(`execute_tool ${managedToolName}`, "gen_ai.execute_tool", {}, async () => {
|
|
7363
7057
|
try {
|
|
7364
|
-
const result = await client.callTool(tool.name, resolvedArgs, options?.signal);
|
|
7058
|
+
const result = await (await this.clientForTool(plugin, client, tool.name)).callTool(tool.name, resolvedArgs, options?.signal);
|
|
7365
7059
|
if ("isError" in result && result.isError) throw new McpToolError(extractMcpErrorMessage(result));
|
|
7366
7060
|
const resultAttribute = serializeMcpPayload(result, conversationPrivacy, { privateMetadata: true });
|
|
7367
7061
|
if (resultAttribute) setSpanAttributes({ "gen_ai.tool.call.result": resultAttribute });
|
|
@@ -7415,13 +7109,23 @@ var McpToolManager = class {
|
|
|
7415
7109
|
};
|
|
7416
7110
|
}
|
|
7417
7111
|
async handleAuthorizationRequired(provider, error, context) {
|
|
7112
|
+
const plugin = this.pluginsByProvider.get(provider);
|
|
7113
|
+
if (plugin && serviceAccountOnly(plugin.manifest)) {
|
|
7114
|
+
this.forgetProvider(provider);
|
|
7115
|
+
throw new McpServiceAccountRequiredError(provider, plugin.manifest.displayName);
|
|
7116
|
+
}
|
|
7418
7117
|
if (!this.options.onAuthorizationRequired) return false;
|
|
7419
7118
|
if (!(await this.options.onAuthorizationRequired(provider, error, context) === true)) return false;
|
|
7420
7119
|
this.authorizationPendingProviders.add(provider);
|
|
7120
|
+
this.forgetProvider(provider);
|
|
7121
|
+
return true;
|
|
7122
|
+
}
|
|
7123
|
+
forgetProvider(provider) {
|
|
7421
7124
|
this.clientsByProvider.delete(provider);
|
|
7125
|
+
this.actorClientsByProvider.delete(provider);
|
|
7126
|
+
this.serviceAccountProviders.delete(provider);
|
|
7422
7127
|
this.toolsByProvider.delete(provider);
|
|
7423
7128
|
this.activeProviders.delete(provider);
|
|
7424
|
-
return true;
|
|
7425
7129
|
}
|
|
7426
7130
|
/** Return all active ManagedMcpTool objects, optionally filtered by provider. */
|
|
7427
7131
|
getResolvedActiveTools(options = {}) {
|
|
@@ -7479,8 +7183,7 @@ function serializeMcpPayload(payload, privacy, options = {}) {
|
|
|
7479
7183
|
if (privacy !== "private") return serializeGenAiAttribute(payload);
|
|
7480
7184
|
return options.privateMetadata ? serializeGenAiAttribute(toGenAiPayloadMetadata(payload)) : void 0;
|
|
7481
7185
|
}
|
|
7482
|
-
|
|
7483
|
-
//#region src/chat/tools/sandbox/bash.ts
|
|
7186
|
+
// src/chat/tools/sandbox/bash.ts
|
|
7484
7187
|
/** Create the sandbox shell tool definition exposed to the agent. */
|
|
7485
7188
|
function createBashTool() {
|
|
7486
7189
|
return zodTool({
|
|
@@ -7503,8 +7206,7 @@ function createBashTool() {
|
|
|
7503
7206
|
}
|
|
7504
7207
|
});
|
|
7505
7208
|
}
|
|
7506
|
-
|
|
7507
|
-
//#region src/chat/tools/sandbox/image-files.ts
|
|
7209
|
+
// src/chat/tools/sandbox/image-files.ts
|
|
7508
7210
|
/**
|
|
7509
7211
|
* Read a sandbox image for a model request. The file signature, not the file
|
|
7510
7212
|
* name, sets the MIME type.
|
|
@@ -7522,8 +7224,7 @@ async function readSandboxImage(path, readFile, maxBytes) {
|
|
|
7522
7224
|
mimeType
|
|
7523
7225
|
};
|
|
7524
7226
|
}
|
|
7525
|
-
|
|
7526
|
-
//#region src/chat/tools/web/image-generate.ts
|
|
7227
|
+
// src/chat/tools/web/image-generate.ts
|
|
7527
7228
|
const MAX_REQUEST_IMAGE_BYTES = 3145728;
|
|
7528
7229
|
const MAX_SOURCE_IMAGE_BYTES = 26214400;
|
|
7529
7230
|
const RESIZE_LONGEST_EDGES = [
|
|
@@ -7762,8 +7463,7 @@ function createImageGenerateTool(hooks, options, deps = {}) {
|
|
|
7762
7463
|
}
|
|
7763
7464
|
});
|
|
7764
7465
|
}
|
|
7765
|
-
|
|
7766
|
-
//#region src/chat/mcp/tool-name.ts
|
|
7466
|
+
// src/chat/mcp/tool-name.ts
|
|
7767
7467
|
/** Extract the provider from canonical `mcp__<provider>__<tool>` names. */
|
|
7768
7468
|
function parseMcpProviderFromToolName(toolName) {
|
|
7769
7469
|
if (!toolName.startsWith("mcp__")) return void 0;
|
|
@@ -7771,8 +7471,7 @@ function parseMcpProviderFromToolName(toolName) {
|
|
|
7771
7471
|
const delimiterIndex = afterPrefix.indexOf("__");
|
|
7772
7472
|
return delimiterIndex > 0 ? afterPrefix.slice(0, delimiterIndex) : void 0;
|
|
7773
7473
|
}
|
|
7774
|
-
|
|
7775
|
-
//#region src/chat/tools/skill/call-mcp-tool.ts
|
|
7474
|
+
// src/chat/tools/skill/call-mcp-tool.ts
|
|
7776
7475
|
function resolveMcpArguments(input) {
|
|
7777
7476
|
const extraKeys = Object.keys(input).filter((key) => key !== "tool_name" && key !== "arguments" && key !== "intent");
|
|
7778
7477
|
if (extraKeys.length > 0) throw new ToolInputError(`callMcpTool MCP arguments must be nested under arguments, not top-level fields: ${extraKeys.join(", ")}`);
|
|
@@ -7852,8 +7551,7 @@ function createCallMcpToolTool(mcpToolManager) {
|
|
|
7852
7551
|
}
|
|
7853
7552
|
});
|
|
7854
7553
|
}
|
|
7855
|
-
|
|
7856
|
-
//#region src/chat/tools/skill/load-skill.ts
|
|
7554
|
+
// src/chat/tools/skill/load-skill.ts
|
|
7857
7555
|
function toLoadedSkill(result, availableSkills) {
|
|
7858
7556
|
if (typeof result.skill_name !== "string" || typeof result.description !== "string" || typeof result.skill_dir !== "string" || typeof result.instructions !== "string") return null;
|
|
7859
7557
|
const metadata = availableSkills.find((skill) => skill.name === result.skill_name) ?? null;
|
|
@@ -7904,8 +7602,7 @@ function createLoadSkillTool(availableSkills, options) {
|
|
|
7904
7602
|
}
|
|
7905
7603
|
});
|
|
7906
7604
|
}
|
|
7907
|
-
|
|
7908
|
-
//#region src/chat/tool-support/skill/mcp-tool-summary.ts
|
|
7605
|
+
// src/chat/tool-support/skill/mcp-tool-summary.ts
|
|
7909
7606
|
/** Convert a managed MCP tool descriptor into agent-visible search output. */
|
|
7910
7607
|
function toExposedToolSummary(toolDef) {
|
|
7911
7608
|
return {
|
|
@@ -7928,8 +7625,7 @@ function toActiveMcpCatalogSummaries(toolDefs) {
|
|
|
7928
7625
|
available_tool_count: availableToolCount
|
|
7929
7626
|
})).sort((left, right) => left.provider.localeCompare(right.provider));
|
|
7930
7627
|
}
|
|
7931
|
-
|
|
7932
|
-
//#region src/chat/tools/skill/search-mcp-tools.ts
|
|
7628
|
+
// src/chat/tools/skill/search-mcp-tools.ts
|
|
7933
7629
|
const DEFAULT_MAX_RESULTS$1 = 5;
|
|
7934
7630
|
const MAX_RESULTS$2 = 20;
|
|
7935
7631
|
const providerSummarySchema = z.object({
|
|
@@ -8078,8 +7774,7 @@ function createSearchMcpToolsTool(mcpToolManager) {
|
|
|
8078
7774
|
}
|
|
8079
7775
|
});
|
|
8080
7776
|
}
|
|
8081
|
-
|
|
8082
|
-
//#region src/chat/tools/sandbox/view-image.ts
|
|
7777
|
+
// src/chat/tools/sandbox/view-image.ts
|
|
8083
7778
|
const MAX_VIEW_IMAGE_BYTES = 5242880;
|
|
8084
7779
|
const viewImageInputSchema = z.object({ path: z.string().min(1).describe("Path to an image file in the sandbox workspace.") }).strict();
|
|
8085
7780
|
/** Create a tool that loads a sandbox image into the active model context. */
|
|
@@ -8105,8 +7800,7 @@ function createViewImageTool(sandbox, supportsImageInput, deps = {}) {
|
|
|
8105
7800
|
}
|
|
8106
7801
|
});
|
|
8107
7802
|
}
|
|
8108
|
-
|
|
8109
|
-
//#region src/chat/tools/runtime/report-progress.ts
|
|
7803
|
+
// src/chat/tools/runtime/report-progress.ts
|
|
8110
7804
|
/** Create the internal tool the model uses for sparse progress updates. */
|
|
8111
7805
|
function createReportProgressTool() {
|
|
8112
7806
|
return zodTool({
|
|
@@ -8122,8 +7816,7 @@ function createReportProgressTool() {
|
|
|
8122
7816
|
execute: async () => ({})
|
|
8123
7817
|
});
|
|
8124
7818
|
}
|
|
8125
|
-
|
|
8126
|
-
//#region src/chat/tools/runtime/update-plan.ts
|
|
7819
|
+
// src/chat/tools/runtime/update-plan.ts
|
|
8127
7820
|
const planItemSchema = z.object({
|
|
8128
7821
|
step: z.string().describe("Task step text."),
|
|
8129
7822
|
status: z.enum([
|
|
@@ -8157,8 +7850,7 @@ function createUpdatePlanTool() {
|
|
|
8157
7850
|
}] })
|
|
8158
7851
|
});
|
|
8159
7852
|
}
|
|
8160
|
-
|
|
8161
|
-
//#region src/chat/conversations/sql/subtree.ts
|
|
7853
|
+
// src/chat/conversations/sql/subtree.ts
|
|
8162
7854
|
/** Columns of the `conversation_subtree` table that `conversationSubtree` returns. */
|
|
8163
7855
|
const conversationSubtreeColumns = {
|
|
8164
7856
|
conversationId: sql`conversation_subtree.conversation_id`,
|
|
@@ -8190,8 +7882,7 @@ function conversationSubtree(conversationIds) {
|
|
|
8190
7882
|
select scope_conversation_id, conversation_id from tree
|
|
8191
7883
|
) conversation_subtree`;
|
|
8192
7884
|
}
|
|
8193
|
-
|
|
8194
|
-
//#region src/chat/agent-invocations/types.ts
|
|
7885
|
+
// src/chat/agent-invocations/types.ts
|
|
8195
7886
|
const exactStringSchema = z.string().min(1).refine((value) => value === value.trim());
|
|
8196
7887
|
const agentNameSchema = exactStringSchema.max(64);
|
|
8197
7888
|
/** `messageAgent` target for the parent of a child agent. */
|
|
@@ -8263,8 +7954,7 @@ const CHILD_AGENT_RESULTS = [
|
|
|
8263
7954
|
"blocked",
|
|
8264
7955
|
"failed"
|
|
8265
7956
|
];
|
|
8266
|
-
|
|
8267
|
-
//#region src/chat/agent-invocations/errors.ts
|
|
7957
|
+
// src/chat/agent-invocations/errors.ts
|
|
8268
7958
|
/** A child agent already uses this name in the parent Conversation. */
|
|
8269
7959
|
var AgentNameInUseError = class extends Error {
|
|
8270
7960
|
constructor(name) {
|
|
@@ -8293,8 +7983,7 @@ var AgentMessageTargetError = class extends Error {
|
|
|
8293
7983
|
this.name = "AgentMessageTargetError";
|
|
8294
7984
|
}
|
|
8295
7985
|
};
|
|
8296
|
-
|
|
8297
|
-
//#region src/chat/agent-invocations/store.ts
|
|
7986
|
+
// src/chat/agent-invocations/store.ts
|
|
8298
7987
|
const CREATE_LOCK_PREFIX = "junior:agent_invocation:create";
|
|
8299
7988
|
/**
|
|
8300
7989
|
* Return the SQL lock that one parent Conversation takes to start, message,
|
|
@@ -8720,8 +8409,7 @@ async function markAgentInvocationSteered(invocationId, nowMs = Date.now()) {
|
|
|
8720
8409
|
function isTerminalAgentInvocation(invocation) {
|
|
8721
8410
|
return TERMINAL_AGENT_INVOCATION_STATUSES.includes(invocation.status);
|
|
8722
8411
|
}
|
|
8723
|
-
|
|
8724
|
-
//#region src/chat/agent-invocations/list.ts
|
|
8412
|
+
// src/chat/agent-invocations/list.ts
|
|
8725
8413
|
function isChildAgentResult(status) {
|
|
8726
8414
|
return CHILD_AGENT_RESULTS.includes(status);
|
|
8727
8415
|
}
|
|
@@ -8813,8 +8501,7 @@ async function listAgentRelatives(input) {
|
|
|
8813
8501
|
siblings: family.filter((agent) => agent.childConversationId !== conversationId)
|
|
8814
8502
|
};
|
|
8815
8503
|
}
|
|
8816
|
-
|
|
8817
|
-
//#region src/chat/tools/runtime/list-agents.ts
|
|
8504
|
+
// src/chat/tools/runtime/list-agents.ts
|
|
8818
8505
|
const TASK_MAX_LENGTH = 1e3;
|
|
8819
8506
|
const ERROR_MAX_LENGTH = 500;
|
|
8820
8507
|
/** How a listed agent relates to the conversation that lists it. */
|
|
@@ -8909,8 +8596,7 @@ function createListAgentsTool(context) {
|
|
|
8909
8596
|
}
|
|
8910
8597
|
});
|
|
8911
8598
|
}
|
|
8912
|
-
|
|
8913
|
-
//#region src/chat/tools/runtime/message-agent.ts
|
|
8599
|
+
// src/chat/tools/runtime/message-agent.ts
|
|
8914
8600
|
/** Bound the text of one message so a loop cannot fill a mailbox quickly. */
|
|
8915
8601
|
const MESSAGE_AGENT_TEXT_MAX_LENGTH = 8e3;
|
|
8916
8602
|
const messageAgentOutputSchema = juniorToolOutputSchema.extend({
|
|
@@ -8956,8 +8642,7 @@ function createMessageAgentTool(messageAgent) {
|
|
|
8956
8642
|
}
|
|
8957
8643
|
});
|
|
8958
8644
|
}
|
|
8959
|
-
|
|
8960
|
-
//#region src/chat/tools/runtime/spawn-agent.ts
|
|
8645
|
+
// src/chat/tools/runtime/spawn-agent.ts
|
|
8961
8646
|
const spawnAgentOutputSchema = juniorToolOutputSchema.extend({ conversation_id: z.string().min(1).describe("Child conversation ID. Pass it to searchConversationEvents to read the child's history.") });
|
|
8962
8647
|
/** Create the asynchronous child-agent tool for one parent run. */
|
|
8963
8648
|
function createSpawnAgentTool(spawnAgent, profileControl) {
|
|
@@ -9014,8 +8699,7 @@ function createSpawnAgentTool(spawnAgent, profileControl) {
|
|
|
9014
8699
|
}
|
|
9015
8700
|
});
|
|
9016
8701
|
}
|
|
9017
|
-
|
|
9018
|
-
//#region src/chat/agent-invocations/markers.ts
|
|
8702
|
+
// src/chat/agent-invocations/markers.ts
|
|
9019
8703
|
/**
|
|
9020
8704
|
* Dashboard records for agent invocations. The parent Conversation gets one
|
|
9021
8705
|
* `subagent_started` and one `subagent_ended` event for each agent invocation.
|
|
@@ -9098,8 +8782,7 @@ async function recordSubagentEnded(invocation) {
|
|
|
9098
8782
|
createdAtMs: invocation.terminalAtMs
|
|
9099
8783
|
}]);
|
|
9100
8784
|
}
|
|
9101
|
-
|
|
9102
|
-
//#region src/chat/agent-invocations/stop.ts
|
|
8785
|
+
// src/chat/agent-invocations/stop.ts
|
|
9103
8786
|
/**
|
|
9104
8787
|
* Stop one child agent of a parent Conversation and every child agent below
|
|
9105
8788
|
* it. The parent gets no result. SQL stops the work first. Then each
|
|
@@ -9208,8 +8891,7 @@ async function stopLockedAgentInvocationTree(conversationId, nowMs) {
|
|
|
9208
8891
|
stopped: stopped.map(invocationFromRow).filter(isTerminalAgentInvocation)
|
|
9209
8892
|
};
|
|
9210
8893
|
}
|
|
9211
|
-
|
|
9212
|
-
//#region src/chat/tools/runtime/stop-agent.ts
|
|
8894
|
+
// src/chat/tools/runtime/stop-agent.ts
|
|
9213
8895
|
const stopAgentOutputSchema = juniorToolOutputSchema.extend({
|
|
9214
8896
|
conversation_id: z.string().min(1).describe("Stopped child conversation ID"),
|
|
9215
8897
|
stopped: z.boolean().describe("True when work was stopped. False when the child agent had already stopped.")
|
|
@@ -9239,8 +8921,7 @@ function createStopAgentTool(conversationId) {
|
|
|
9239
8921
|
}
|
|
9240
8922
|
});
|
|
9241
8923
|
}
|
|
9242
|
-
|
|
9243
|
-
//#region src/chat/tools/runtime/finish-automation-run.ts
|
|
8924
|
+
// src/chat/tools/runtime/finish-automation-run.ts
|
|
9244
8925
|
const RESULT_GUIDANCE = ["Use `no_action` when the run worked and nothing should be posted, such as when a condition in the instruction is not met, or when a temporary failure stopped the work.", "Use `misconfigured` when the run cannot do its job until its creator changes the automation: a provider, tool, account, or access that the job needs is missing, a target no longer exists, or the instruction cannot be done. Do not use it for a temporary failure or a condition that is not met."].join(" ");
|
|
9245
8926
|
/** Create the tool that ends one Automation run with a declared result. */
|
|
9246
8927
|
function createFinishAutomationRunTool(options) {
|
|
@@ -9277,8 +8958,7 @@ function createFinishAutomationRunTool(options) {
|
|
|
9277
8958
|
}
|
|
9278
8959
|
});
|
|
9279
8960
|
}
|
|
9280
|
-
|
|
9281
|
-
//#region src/chat/tools/runtime/report-blocked.ts
|
|
8961
|
+
// src/chat/tools/runtime/report-blocked.ts
|
|
9282
8962
|
/** Create the tool that ends a child agent run as blocked. */
|
|
9283
8963
|
function createReportBlockedTool() {
|
|
9284
8964
|
return zodTool({
|
|
@@ -9294,8 +8974,7 @@ function createReportBlockedTool() {
|
|
|
9294
8974
|
execute: async (input) => ({ missing: input.missing })
|
|
9295
8975
|
});
|
|
9296
8976
|
}
|
|
9297
|
-
|
|
9298
|
-
//#region src/chat/events/owned-watches.ts
|
|
8977
|
+
// src/chat/events/owned-watches.ts
|
|
9299
8978
|
/**
|
|
9300
8979
|
* Watch ownership for the watch tools. A Conversation owns its own watches and
|
|
9301
8980
|
* the watches of every child agent below it, at any depth. A child agent still
|
|
@@ -9341,8 +9020,7 @@ async function stopOwnedWatch(input) {
|
|
|
9341
9020
|
});
|
|
9342
9021
|
return stopped;
|
|
9343
9022
|
}
|
|
9344
|
-
|
|
9345
|
-
//#region src/chat/tools/list-watches.ts
|
|
9023
|
+
// src/chat/tools/list-watches.ts
|
|
9346
9024
|
const listedResourceWatchSchema = z.object({
|
|
9347
9025
|
id: z.string().min(1),
|
|
9348
9026
|
label: z.string().min(1),
|
|
@@ -9395,8 +9073,7 @@ function createListWatchesTool(context) {
|
|
|
9395
9073
|
}
|
|
9396
9074
|
});
|
|
9397
9075
|
}
|
|
9398
|
-
|
|
9399
|
-
//#region src/chat/tools/search-event-types.ts
|
|
9076
|
+
// src/chat/tools/search-event-types.ts
|
|
9400
9077
|
const DEFAULT_SEARCH_RESULTS = 10;
|
|
9401
9078
|
const MAX_SEARCH_RESULTS = 20;
|
|
9402
9079
|
const searchedResourceTypeSchema = z.object({
|
|
@@ -9476,8 +9153,7 @@ function createSearchEventTypesTool(catalog) {
|
|
|
9476
9153
|
}
|
|
9477
9154
|
});
|
|
9478
9155
|
}
|
|
9479
|
-
|
|
9480
|
-
//#region src/chat/tools/stop-watches.ts
|
|
9156
|
+
// src/chat/tools/stop-watches.ts
|
|
9481
9157
|
const resultDataSchema$1 = z.object({
|
|
9482
9158
|
watching_status: z.literal("stopped"),
|
|
9483
9159
|
stoppedIds: z.array(z.string().min(1))
|
|
@@ -9533,8 +9209,7 @@ function createStopWatchingResourcesTool(context) {
|
|
|
9533
9209
|
}
|
|
9534
9210
|
});
|
|
9535
9211
|
}
|
|
9536
|
-
|
|
9537
|
-
//#region src/chat/tools/watch-timer.ts
|
|
9212
|
+
// src/chat/tools/watch-timer.ts
|
|
9538
9213
|
/** Create one heartbeat-backed Watch in the current Conversation. */
|
|
9539
9214
|
function createWatchTimerTool(context) {
|
|
9540
9215
|
return zodTool({
|
|
@@ -9569,8 +9244,7 @@ function createWatchTimerTool(context) {
|
|
|
9569
9244
|
}
|
|
9570
9245
|
});
|
|
9571
9246
|
}
|
|
9572
|
-
|
|
9573
|
-
//#region src/chat/tools/watch-events.ts
|
|
9247
|
+
// src/chat/tools/watch-events.ts
|
|
9574
9248
|
function inputSchema(catalog) {
|
|
9575
9249
|
return z.object({
|
|
9576
9250
|
identifier: z.string().trim().min(1).describe("Plugin-defined resource identifier."),
|
|
@@ -9675,8 +9349,7 @@ function createWatchEventsTool(context, catalog) {
|
|
|
9675
9349
|
}
|
|
9676
9350
|
});
|
|
9677
9351
|
}
|
|
9678
|
-
|
|
9679
|
-
//#region src/chat/tools/events.ts
|
|
9352
|
+
// src/chat/tools/events.ts
|
|
9680
9353
|
/** Build the complete resource-watch tool set for this runtime context. */
|
|
9681
9354
|
function createEventTools(context, catalog) {
|
|
9682
9355
|
const enabled = hasEventCatalogEntries(catalog);
|
|
@@ -9690,8 +9363,7 @@ function createEventTools(context, catalog) {
|
|
|
9690
9363
|
stopWatchingResources: createStopWatchingResourcesTool(context)
|
|
9691
9364
|
};
|
|
9692
9365
|
}
|
|
9693
|
-
|
|
9694
|
-
//#region src/chat/automations/requester-mention.ts
|
|
9366
|
+
// src/chat/automations/requester-mention.ts
|
|
9695
9367
|
function namesPerson(text, name) {
|
|
9696
9368
|
const escaped = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
9697
9369
|
return new RegExp(`(?<![\\p{L}\\p{N}])${escaped}(?![\\p{L}\\p{N}])`, "iu").test(text);
|
|
@@ -9708,8 +9380,7 @@ function requireRequesterMention(instruction, actor) {
|
|
|
9708
9380
|
if (instruction.includes(mention)) return;
|
|
9709
9381
|
if (namesPerson(instruction, actor.fullName)) throw new ToolInputError(`The instruction names ${actor.fullName} without a Slack mention. Write ${mention} for this person.`);
|
|
9710
9382
|
}
|
|
9711
|
-
|
|
9712
|
-
//#region src/chat/task-outcomes.ts
|
|
9383
|
+
// src/chat/task-outcomes.ts
|
|
9713
9384
|
/** Resolve explicit message outcomes to the Slack Destinations stored on an Automation. */
|
|
9714
9385
|
async function resolveTaskOutcomes(outcomes, currentDestination, creatorSlackUserId) {
|
|
9715
9386
|
if (outcomes === void 0) return [];
|
|
@@ -9751,8 +9422,7 @@ function moveTaskOutcomes(outcomes, currentDestination, nextDestination) {
|
|
|
9751
9422
|
destination: nextDestination
|
|
9752
9423
|
} : outcome);
|
|
9753
9424
|
}
|
|
9754
|
-
|
|
9755
|
-
//#region src/chat/event-automations/tool-support.ts
|
|
9425
|
+
// src/chat/event-automations/tool-support.ts
|
|
9756
9426
|
const compactEventAutomationResultSchema = z.object({
|
|
9757
9427
|
id: z.string().min(1),
|
|
9758
9428
|
status: z.enum([
|
|
@@ -9915,8 +9585,7 @@ async function eventAutomationToolResult(conversationId, task, catalog, requeste
|
|
|
9915
9585
|
}])
|
|
9916
9586
|
};
|
|
9917
9587
|
}
|
|
9918
|
-
|
|
9919
|
-
//#region src/chat/tools/create-event-automation.ts
|
|
9588
|
+
// src/chat/tools/create-event-automation.ts
|
|
9920
9589
|
/** Build a retry-stable automation id scoped to actor, destination, and tool call. */
|
|
9921
9590
|
function buildEventAutomationId(args) {
|
|
9922
9591
|
const toolCallId = args.toolCallId?.trim();
|
|
@@ -10008,8 +9677,7 @@ function createEventAutomationTool(context, catalog) {
|
|
|
10008
9677
|
}
|
|
10009
9678
|
});
|
|
10010
9679
|
}
|
|
10011
|
-
|
|
10012
|
-
//#region src/chat/tools/delete-event-automation.ts
|
|
9680
|
+
// src/chat/tools/delete-event-automation.ts
|
|
10013
9681
|
/** Create the core tool that deletes an event automation. */
|
|
10014
9682
|
function createDeleteEventAutomationTool(context, catalog) {
|
|
10015
9683
|
return zodTool({
|
|
@@ -10044,8 +9712,7 @@ function createDeleteEventAutomationTool(context, catalog) {
|
|
|
10044
9712
|
}
|
|
10045
9713
|
});
|
|
10046
9714
|
}
|
|
10047
|
-
|
|
10048
|
-
//#region src/chat/tools/list-event-automations.ts
|
|
9715
|
+
// src/chat/tools/list-event-automations.ts
|
|
10049
9716
|
const MAX_LISTED_EVENT_AUTOMATIONS = 50;
|
|
10050
9717
|
/** Create the core tool that lists event automations for this destination. */
|
|
10051
9718
|
function createListEventAutomationsTool(context, catalog) {
|
|
@@ -10070,8 +9737,7 @@ function createListEventAutomationsTool(context, catalog) {
|
|
|
10070
9737
|
}
|
|
10071
9738
|
});
|
|
10072
9739
|
}
|
|
10073
|
-
|
|
10074
|
-
//#region src/chat/automations/edit-rules.ts
|
|
9740
|
+
// src/chat/automations/edit-rules.ts
|
|
10075
9741
|
/** Shared edit rules. Transport access checks run before these rules. */
|
|
10076
9742
|
var AutomationEditError = class extends ToolInputError {
|
|
10077
9743
|
field;
|
|
@@ -10106,8 +9772,7 @@ async function editAutomationFields(current, input, isCreator, changesExecution)
|
|
|
10106
9772
|
outcomes
|
|
10107
9773
|
};
|
|
10108
9774
|
}
|
|
10109
|
-
|
|
10110
|
-
//#region src/chat/event-automations/edit.ts
|
|
9775
|
+
// src/chat/event-automations/edit.ts
|
|
10111
9776
|
function changesEventAutomationTrigger(current, next) {
|
|
10112
9777
|
const currentEvents = [...current.events].sort();
|
|
10113
9778
|
const nextEvents = [...next.events].sort();
|
|
@@ -10147,8 +9812,7 @@ async function editEventAutomation(current, input, isCreator, catalog) {
|
|
|
10147
9812
|
throw error;
|
|
10148
9813
|
}
|
|
10149
9814
|
}
|
|
10150
|
-
|
|
10151
|
-
//#region src/chat/tools/update-event-automation.ts
|
|
9815
|
+
// src/chat/tools/update-event-automation.ts
|
|
10152
9816
|
/** Create the core tool that updates an event automation. */
|
|
10153
9817
|
function createUpdateEventAutomationTool(context, catalog) {
|
|
10154
9818
|
return zodTool({
|
|
@@ -10212,8 +9876,7 @@ function createUpdateEventAutomationTool(context, catalog) {
|
|
|
10212
9876
|
}
|
|
10213
9877
|
});
|
|
10214
9878
|
}
|
|
10215
|
-
|
|
10216
|
-
//#region src/chat/tools/event-automations.ts
|
|
9879
|
+
// src/chat/tools/event-automations.ts
|
|
10217
9880
|
/** Build event automation tools for a Conversation with a Slack Location. */
|
|
10218
9881
|
function createEventAutomationTools(context, catalog) {
|
|
10219
9882
|
if (!getSlackToolContext(context)) return {};
|
|
@@ -10224,8 +9887,7 @@ function createEventAutomationTools(context, catalog) {
|
|
|
10224
9887
|
deleteEventAutomation: createDeleteEventAutomationTool(context, catalog)
|
|
10225
9888
|
}, slackMessageTurnDisabledReason(context));
|
|
10226
9889
|
}
|
|
10227
|
-
|
|
10228
|
-
//#region src/chat/scheduled-automations/telemetry.ts
|
|
9890
|
+
// src/chat/scheduled-automations/telemetry.ts
|
|
10229
9891
|
/** Safe structured telemetry attributes for scheduled-automation lifecycle events. */
|
|
10230
9892
|
/** Correlation attributes shared by scheduled-automation create and run events. */
|
|
10231
9893
|
function scheduledAutomationAttributes(task, extras = {}) {
|
|
@@ -10260,8 +9922,7 @@ function scheduledAutomationRunAttributes(task, run, extras = {}) {
|
|
|
10260
9922
|
function logScheduledAutomationRunSkipped(task, run, extras = {}) {
|
|
10261
9923
|
logInfo("scheduled_automation.run.skipped", scheduledAutomationRunAttributes(task, run, extras));
|
|
10262
9924
|
}
|
|
10263
|
-
|
|
10264
|
-
//#region src/chat/scheduled-automations/identity.ts
|
|
9925
|
+
// src/chat/scheduled-automations/identity.ts
|
|
10265
9926
|
const SLACK_USER_ID_PATTERN = /^[UW][A-Z0-9]{5,}$/;
|
|
10266
9927
|
function clean(value) {
|
|
10267
9928
|
const normalized = value?.trim();
|
|
@@ -10288,8 +9949,7 @@ function sanitizeScheduledAutomationPrincipal(principal) {
|
|
|
10288
9949
|
...userName ? { userName } : void 0
|
|
10289
9950
|
};
|
|
10290
9951
|
}
|
|
10291
|
-
|
|
10292
|
-
//#region src/chat/scheduled-automations/tool-support.ts
|
|
9952
|
+
// src/chat/scheduled-automations/tool-support.ts
|
|
10293
9953
|
const TASK_ID_PREFIX = "sched";
|
|
10294
9954
|
const compactTaskResultSchema = z.object({
|
|
10295
9955
|
id: z.string(),
|
|
@@ -10507,8 +10167,7 @@ function buildTaskId(args) {
|
|
|
10507
10167
|
function normalizeStatus(value) {
|
|
10508
10168
|
if (value === "active" || value === "blocked") return value;
|
|
10509
10169
|
}
|
|
10510
|
-
|
|
10511
|
-
//#region src/chat/scheduled-automations/tools/create.ts
|
|
10170
|
+
// src/chat/scheduled-automations/tools/create.ts
|
|
10512
10171
|
/** Create a tool that stores a scheduled automation for the active Slack context. */
|
|
10513
10172
|
function createSlackScheduleCreateAutomationTool(context) {
|
|
10514
10173
|
return zodTool({
|
|
@@ -10606,8 +10265,7 @@ function createSlackScheduleCreateAutomationTool(context) {
|
|
|
10606
10265
|
}
|
|
10607
10266
|
});
|
|
10608
10267
|
}
|
|
10609
|
-
|
|
10610
|
-
//#region src/chat/scheduled-automations/tools/delete.ts
|
|
10268
|
+
// src/chat/scheduled-automations/tools/delete.ts
|
|
10611
10269
|
/** Create a tool that removes a scheduled automation from the active Slack conversation. */
|
|
10612
10270
|
function createSlackScheduleDeleteAutomationTool(context) {
|
|
10613
10271
|
return zodTool({
|
|
@@ -10650,8 +10308,7 @@ function createSlackScheduleDeleteAutomationTool(context) {
|
|
|
10650
10308
|
}
|
|
10651
10309
|
});
|
|
10652
10310
|
}
|
|
10653
|
-
|
|
10654
|
-
//#region src/chat/slack/id-param.ts
|
|
10311
|
+
// src/chat/slack/id-param.ts
|
|
10655
10312
|
/** Define a model-facing Slack channel ID parameter. */
|
|
10656
10313
|
function slackChannelIdParam(description) {
|
|
10657
10314
|
return z.string().min(1).describe(description);
|
|
@@ -10684,8 +10341,7 @@ function parseRequiredSlackUserIdParam(field, value) {
|
|
|
10684
10341
|
error: `Invalid \`${field}\` Slack user ID. Use a Slack user ID like \`U123\` or \`W123\`.`
|
|
10685
10342
|
};
|
|
10686
10343
|
}
|
|
10687
|
-
|
|
10688
|
-
//#region src/chat/scheduled-automations/tools/list.ts
|
|
10344
|
+
// src/chat/scheduled-automations/tools/list.ts
|
|
10689
10345
|
function taskMatchesQuery(task, query) {
|
|
10690
10346
|
const normalized = query.toLowerCase();
|
|
10691
10347
|
return [
|
|
@@ -10740,8 +10396,7 @@ function createSlackScheduleListAutomationsTool(context) {
|
|
|
10740
10396
|
}
|
|
10741
10397
|
});
|
|
10742
10398
|
}
|
|
10743
|
-
|
|
10744
|
-
//#region src/chat/scheduled-automations/tools/run-now.ts
|
|
10399
|
+
// src/chat/scheduled-automations/tools/run-now.ts
|
|
10745
10400
|
/** Create a tool that marks an existing scheduled automation due immediately. */
|
|
10746
10401
|
function createSlackScheduleRunAutomationNowTool(context) {
|
|
10747
10402
|
return zodTool({
|
|
@@ -10773,8 +10428,7 @@ function createSlackScheduleRunAutomationNowTool(context) {
|
|
|
10773
10428
|
}
|
|
10774
10429
|
});
|
|
10775
10430
|
}
|
|
10776
|
-
|
|
10777
|
-
//#region src/chat/scheduled-automations/edit.ts
|
|
10431
|
+
// src/chat/scheduled-automations/edit.ts
|
|
10778
10432
|
/** Build an edit without restarting completed work or changing creator identity. */
|
|
10779
10433
|
async function editScheduledAutomation(current, input, isCreator, nowMs) {
|
|
10780
10434
|
if (current.status === "completed" || current.status === "deleted") throw new AutomationEditError("Completed scheduled automations cannot be updated. Create a new automation instead.");
|
|
@@ -10807,8 +10461,7 @@ async function editScheduledAutomation(current, input, isCreator, nowMs) {
|
|
|
10807
10461
|
status
|
|
10808
10462
|
};
|
|
10809
10463
|
}
|
|
10810
|
-
|
|
10811
|
-
//#region src/chat/scheduled-automations/tools/update.ts
|
|
10464
|
+
// src/chat/scheduled-automations/tools/update.ts
|
|
10812
10465
|
/** Create a tool that edits a scheduled automation, including moving it here. */
|
|
10813
10466
|
function createSlackScheduleUpdateAutomationTool(context) {
|
|
10814
10467
|
return zodTool({
|
|
@@ -10878,8 +10531,7 @@ function createSlackScheduleUpdateAutomationTool(context) {
|
|
|
10878
10531
|
}
|
|
10879
10532
|
});
|
|
10880
10533
|
}
|
|
10881
|
-
|
|
10882
|
-
//#region src/chat/tools/scheduled-automations.ts
|
|
10534
|
+
// src/chat/tools/scheduled-automations.ts
|
|
10883
10535
|
function scheduledAutomationToolContext(context) {
|
|
10884
10536
|
const slackMessageTurn = isSlackMessageTurn(context) ? {
|
|
10885
10537
|
actor: context.actor,
|
|
@@ -10904,8 +10556,7 @@ function createScheduledAutomationTools(context) {
|
|
|
10904
10556
|
slackScheduleRunAutomationNow: createSlackScheduleRunAutomationNowTool(taskContext)
|
|
10905
10557
|
}, slackMessageTurnDisabledReason(context));
|
|
10906
10558
|
}
|
|
10907
|
-
|
|
10908
|
-
//#region src/chat/slack/channel.ts
|
|
10559
|
+
// src/chat/slack/channel.ts
|
|
10909
10560
|
const replySubtypeSchema = z.object({ subtype: z.string().optional() });
|
|
10910
10561
|
/** List channel history using Slack-native, pre-validated timestamp bounds. */
|
|
10911
10562
|
async function listChannelMessages(input) {
|
|
@@ -10994,8 +10645,7 @@ async function joinPublicChannel(channelId) {
|
|
|
10994
10645
|
idempotent: true
|
|
10995
10646
|
});
|
|
10996
10647
|
}
|
|
10997
|
-
|
|
10998
|
-
//#region src/chat/slack/tool-support/channel-access.ts
|
|
10648
|
+
// src/chat/slack/tool-support/channel-access.ts
|
|
10999
10649
|
const DENIED_PRIVATE = "Cannot read this Slack conversation because it is private. Only the current conversation or public channels are readable.";
|
|
11000
10650
|
const DENIED_NOT_FOUND = "Cannot read this Slack conversation because the channel was not found or the bot cannot see it.";
|
|
11001
10651
|
const DENIED_NOT_IN_CHANNEL = "Cannot read this Slack conversation because the bot is not in the channel.";
|
|
@@ -11118,8 +10768,7 @@ async function resolveOptionalSlackChannelRef(input) {
|
|
|
11118
10768
|
if (input.defaultChannelId) return { channelId: input.defaultChannelId };
|
|
11119
10769
|
throw new ToolInputError("Provide `channel_id`, or use this tool in an active Slack channel context.");
|
|
11120
10770
|
}
|
|
11121
|
-
|
|
11122
|
-
//#region src/chat/slack/tools/channel-join.ts
|
|
10771
|
+
// src/chat/slack/tools/channel-join.ts
|
|
11123
10772
|
/** Create a tool that joins one public Slack channel. */
|
|
11124
10773
|
function createSlackChannelJoinTool(context) {
|
|
11125
10774
|
return zodTool({
|
|
@@ -11168,8 +10817,7 @@ function createSlackChannelJoinTool(context) {
|
|
|
11168
10817
|
}
|
|
11169
10818
|
});
|
|
11170
10819
|
}
|
|
11171
|
-
|
|
11172
|
-
//#region src/chat/slack/context.ts
|
|
10820
|
+
// src/chat/slack/context.ts
|
|
11173
10821
|
function toTrimmedSlackString(value) {
|
|
11174
10822
|
return toOptionalString(value)?.trim() || void 0;
|
|
11175
10823
|
}
|
|
@@ -11235,8 +10883,7 @@ function resolveSlackChannelIdFromMessage(message) {
|
|
|
11235
10883
|
}
|
|
11236
10884
|
return resolveSlackChannelIdFromThreadId(toTrimmedSlackString(message.threadId));
|
|
11237
10885
|
}
|
|
11238
|
-
|
|
11239
|
-
//#region src/chat/slack/timestamp-param.ts
|
|
10886
|
+
// src/chat/slack/timestamp-param.ts
|
|
11240
10887
|
/** Define a model-facing Slack timestamp, normalizing numeric model args to strings. */
|
|
11241
10888
|
function slackTimestampParam(description) {
|
|
11242
10889
|
return z.preprocess((value) => typeof value === "number" && Number.isFinite(value) ? String(value) : value, z.string().min(1)).describe(description);
|
|
@@ -11269,8 +10916,7 @@ function parseRequiredSlackTimestampParam(field, value) {
|
|
|
11269
10916
|
error: `Invalid \`${field}\` Slack timestamp. Use a numeric Slack ts like \`1712345678.123456\`.`
|
|
11270
10917
|
};
|
|
11271
10918
|
}
|
|
11272
|
-
|
|
11273
|
-
//#region src/chat/slack/tools/channel-list-messages.ts
|
|
10919
|
+
// src/chat/slack/tools/channel-list-messages.ts
|
|
11274
10920
|
const booleanInput$1 = (description) => z.preprocess((value) => value === "true" ? true : value === "false" ? false : value, z.boolean()).describe(description);
|
|
11275
10921
|
/**
|
|
11276
10922
|
* Accept numeric Slack ts bounds and recover matching
|
|
@@ -11384,8 +11030,7 @@ function createSlackChannelListMessagesTool(context) {
|
|
|
11384
11030
|
}
|
|
11385
11031
|
});
|
|
11386
11032
|
}
|
|
11387
|
-
|
|
11388
|
-
//#region src/chat/slack/tools/conversation-brief-search.ts
|
|
11033
|
+
// src/chat/slack/tools/conversation-brief-search.ts
|
|
11389
11034
|
/** Create Slack-owned filtering and match details for Brief search. */
|
|
11390
11035
|
function createSlackConversationBriefSearchPort(teamId) {
|
|
11391
11036
|
return {
|
|
@@ -11412,15 +11057,13 @@ function createSlackConversationBriefSearchPort(teamId) {
|
|
|
11412
11057
|
}
|
|
11413
11058
|
};
|
|
11414
11059
|
}
|
|
11415
|
-
|
|
11416
|
-
//#region src/chat/conversations/tool-source.ts
|
|
11060
|
+
// src/chat/conversations/tool-source.ts
|
|
11417
11061
|
/** Deferred tool catalog source for retained Junior conversations. */
|
|
11418
11062
|
const CONVERSATIONS_TOOL_SOURCE = {
|
|
11419
11063
|
id: "conversations",
|
|
11420
11064
|
description: "Search messages and events in retained Junior conversations."
|
|
11421
11065
|
};
|
|
11422
|
-
|
|
11423
|
-
//#region src/chat/slack/tools/conversation-message-search.ts
|
|
11066
|
+
// src/chat/slack/tools/conversation-message-search.ts
|
|
11424
11067
|
const DEFAULT_LIMIT$3 = 20;
|
|
11425
11068
|
const MAX_LIMIT$2 = 50;
|
|
11426
11069
|
const conversationMessageSearchOutputSchema = juniorToolOutputSchema.extend({
|
|
@@ -11534,8 +11177,7 @@ function createSlackConversationMessageSearchTool(scope, currentConversationId)
|
|
|
11534
11177
|
}
|
|
11535
11178
|
});
|
|
11536
11179
|
}
|
|
11537
|
-
|
|
11538
|
-
//#region src/chat/slack/tools/public-search.ts
|
|
11180
|
+
// src/chat/slack/tools/public-search.ts
|
|
11539
11181
|
const DEFAULT_LIMIT$2 = 10;
|
|
11540
11182
|
const DEFAULT_CONTENT_TYPES = ["messages"];
|
|
11541
11183
|
const CONTENT_TYPES = [
|
|
@@ -11833,8 +11475,7 @@ function createSlackPublicSearchTool(actionToken) {
|
|
|
11833
11475
|
}
|
|
11834
11476
|
});
|
|
11835
11477
|
}
|
|
11836
|
-
|
|
11837
|
-
//#region src/chat/tools/idempotency.ts
|
|
11478
|
+
// src/chat/tools/idempotency.ts
|
|
11838
11479
|
function stableSerialize(value) {
|
|
11839
11480
|
if (Array.isArray(value)) return `[${value.map((entry) => stableSerialize(entry)).join(",")}]`;
|
|
11840
11481
|
if (value && typeof value === "object") return `{${Object.entries(value).sort((a, b) => a[0].localeCompare(b[0])).map(([key, entry]) => `${JSON.stringify(key)}:${stableSerialize(entry)}`).join(",")}}`;
|
|
@@ -11844,8 +11485,7 @@ function stableSerialize(value) {
|
|
|
11844
11485
|
function createOperationKey(toolName, input) {
|
|
11845
11486
|
return `${toolName}:${stableSerialize(input)}`;
|
|
11846
11487
|
}
|
|
11847
|
-
|
|
11848
|
-
//#region src/chat/slack/tools/message-add-reaction.ts
|
|
11488
|
+
// src/chat/slack/tools/message-add-reaction.ts
|
|
11849
11489
|
/** Create the tool that reacts to the current inbound Slack message. */
|
|
11850
11490
|
function createSlackMessageAddReactionTool(context, state) {
|
|
11851
11491
|
return zodTool({
|
|
@@ -11890,8 +11530,7 @@ function createSlackMessageAddReactionTool(context, state) {
|
|
|
11890
11530
|
}
|
|
11891
11531
|
});
|
|
11892
11532
|
}
|
|
11893
|
-
|
|
11894
|
-
//#region src/chat/attachments/store.ts
|
|
11533
|
+
// src/chat/attachments/store.ts
|
|
11895
11534
|
const DAY_MS = 864e5;
|
|
11896
11535
|
const ATTACHMENT_GC_BATCH_LIMIT = 200;
|
|
11897
11536
|
/** Time that Junior keeps attachment bytes after the file is stored. */
|
|
@@ -12182,8 +11821,7 @@ async function collectAttachmentGarbage(args) {
|
|
|
12182
11821
|
if (stillEligible.length === 0) return { deleted: 0 };
|
|
12183
11822
|
return { deleted: (await args.db.db().delete(juniorAttachments).where(inArray(juniorAttachments.id, stillEligible.map((row) => row.id))).returning({ id: juniorAttachments.id })).length };
|
|
12184
11823
|
}
|
|
12185
|
-
|
|
12186
|
-
//#region src/chat/tools/send-files.ts
|
|
11824
|
+
// src/chat/tools/send-files.ts
|
|
12187
11825
|
const sendFilesResultSchema = juniorToolOutputSchema.extend({
|
|
12188
11826
|
deduplicated: z.boolean().optional(),
|
|
12189
11827
|
attachment_refs: z.array(z.object({
|
|
@@ -12267,8 +11905,7 @@ function createSendFilesTool(state, materializeFile, output) {
|
|
|
12267
11905
|
}
|
|
12268
11906
|
});
|
|
12269
11907
|
}
|
|
12270
|
-
|
|
12271
|
-
//#region src/chat/slack/tools/send-files.ts
|
|
11908
|
+
// src/chat/slack/tools/send-files.ts
|
|
12272
11909
|
/** Deliver files to the active Slack Location and retain Conversation attachments. */
|
|
12273
11910
|
function createSlackSendFilesTool(context, state, materializeFile, attachments) {
|
|
12274
11911
|
const channelId = context.locationChannelId;
|
|
@@ -12291,8 +11928,7 @@ function createSlackSendFilesTool(context, state, materializeFile, attachments)
|
|
|
12291
11928
|
}
|
|
12292
11929
|
});
|
|
12293
11930
|
}
|
|
12294
|
-
|
|
12295
|
-
//#region src/chat/slack/canvas-references.ts
|
|
11931
|
+
// src/chat/slack/canvas-references.ts
|
|
12296
11932
|
const SLACK_FILE_ID_PATTERN = /^F[A-Z0-9]{4,}$/i;
|
|
12297
11933
|
const SLACK_CANVAS_PATH_PATTERN = /^\/(?:docs|canvas|files)\/(?:T[A-Z0-9]+\/)?(?:U[A-Z0-9]+\/)?(F[A-Z0-9]{4,})(?:\/|$)/i;
|
|
12298
11934
|
function isSlackHost(hostname) {
|
|
@@ -12316,8 +11952,7 @@ function extractCanvasId(input) {
|
|
|
12316
11952
|
return;
|
|
12317
11953
|
}
|
|
12318
11954
|
}
|
|
12319
|
-
|
|
12320
|
-
//#region src/chat/slack/tool-support/canvas/markdown.ts
|
|
11955
|
+
// src/chat/slack/tool-support/canvas/markdown.ts
|
|
12321
11956
|
function getListType(marker) {
|
|
12322
11957
|
return /^\d/.test(marker) ? "numbered" : "bullet";
|
|
12323
11958
|
}
|
|
@@ -12445,8 +12080,7 @@ function normalizeCanvasMarkdown(markdown) {
|
|
|
12445
12080
|
unwrappedBlockquoteCount
|
|
12446
12081
|
};
|
|
12447
12082
|
}
|
|
12448
|
-
|
|
12449
|
-
//#region src/chat/slack/tool-support/canvas/api.ts
|
|
12083
|
+
// src/chat/slack/tool-support/canvas/api.ts
|
|
12450
12084
|
/**
|
|
12451
12085
|
* Create a standalone Slack canvas owned by the bot and best-effort grant write
|
|
12452
12086
|
* access to the active channel. Standalone canvases (`canvases.create`) are not
|
|
@@ -12575,8 +12209,7 @@ async function readCanvas(canvasIdOrUrl) {
|
|
|
12575
12209
|
byteLength: buffer.byteLength
|
|
12576
12210
|
};
|
|
12577
12211
|
}
|
|
12578
|
-
|
|
12579
|
-
//#region src/chat/slack/tools/canvas/create.ts
|
|
12212
|
+
// src/chat/slack/tools/canvas/create.ts
|
|
12580
12213
|
/** Create a tool that provisions a new Slack canvas in the active channel. */
|
|
12581
12214
|
function createSlackCanvasCreateTool(context, state) {
|
|
12582
12215
|
return zodTool({
|
|
@@ -12627,8 +12260,7 @@ function createSlackCanvasCreateTool(context, state) {
|
|
|
12627
12260
|
}
|
|
12628
12261
|
});
|
|
12629
12262
|
}
|
|
12630
|
-
|
|
12631
|
-
//#region src/chat/slack/tool-support/canvas/context.ts
|
|
12263
|
+
// src/chat/slack/tool-support/canvas/context.ts
|
|
12632
12264
|
/** Model-facing Slack canvas ID or docs URL parameter. */
|
|
12633
12265
|
const slackCanvasRefParam = z.string().min(1).describe("Slack canvas/file ID or canvas/docs URL.");
|
|
12634
12266
|
/** Resolve model-provided canvas references before Slack API calls. */
|
|
@@ -12643,8 +12275,7 @@ function resolveCanvasTarget(canvas) {
|
|
|
12643
12275
|
canvasId
|
|
12644
12276
|
};
|
|
12645
12277
|
}
|
|
12646
|
-
|
|
12647
|
-
//#region src/chat/slack/tools/canvas/edit.ts
|
|
12278
|
+
// src/chat/slack/tools/canvas/edit.ts
|
|
12648
12279
|
function prepareCanvasEditArguments(input) {
|
|
12649
12280
|
return prepareTextReplacementArguments(input);
|
|
12650
12281
|
}
|
|
@@ -12714,8 +12345,7 @@ function createSlackCanvasEditTool(state) {
|
|
|
12714
12345
|
}
|
|
12715
12346
|
});
|
|
12716
12347
|
}
|
|
12717
|
-
|
|
12718
|
-
//#region src/chat/slack/tools/canvas/read.ts
|
|
12348
|
+
// src/chat/slack/tools/canvas/read.ts
|
|
12719
12349
|
const slackCanvasReadOutputSchema = juniorToolOutputSchema.extend({
|
|
12720
12350
|
canvas_id: z.string().optional(),
|
|
12721
12351
|
title: z.string().optional(),
|
|
@@ -12777,8 +12407,7 @@ function createSlackCanvasReadTool() {
|
|
|
12777
12407
|
}
|
|
12778
12408
|
});
|
|
12779
12409
|
}
|
|
12780
|
-
|
|
12781
|
-
//#region src/chat/slack/tools/canvas/write.ts
|
|
12410
|
+
// src/chat/slack/tools/canvas/write.ts
|
|
12782
12411
|
/** Create a tool that deliberately replaces a Slack canvas body. */
|
|
12783
12412
|
function createSlackCanvasWriteTool(state) {
|
|
12784
12413
|
return zodTool({
|
|
@@ -12821,8 +12450,7 @@ function createSlackCanvasWriteTool(state) {
|
|
|
12821
12450
|
}
|
|
12822
12451
|
});
|
|
12823
12452
|
}
|
|
12824
|
-
|
|
12825
|
-
//#region src/chat/slack/tool-support/list/api.ts
|
|
12453
|
+
// src/chat/slack/tool-support/list/api.ts
|
|
12826
12454
|
function normalizeKey(value) {
|
|
12827
12455
|
return (value ?? "").toLowerCase().replace(/[^a-z0-9]+/g, "_");
|
|
12828
12456
|
}
|
|
@@ -12981,14 +12609,12 @@ async function updateListItem(input) {
|
|
|
12981
12609
|
cells
|
|
12982
12610
|
}), 3, { action: "slackLists.items.update" });
|
|
12983
12611
|
}
|
|
12984
|
-
|
|
12985
|
-
//#region src/chat/slack/tool-support/list/params.ts
|
|
12612
|
+
// src/chat/slack/tool-support/list/params.ts
|
|
12986
12613
|
/** Model-facing Slack list ID parameter. */
|
|
12987
12614
|
const slackListIdParam = z.string().min(1).describe("Slack list ID.");
|
|
12988
12615
|
/** Model-facing Slack list item ID parameter. */
|
|
12989
12616
|
const slackListItemIdParam = z.string().min(1).describe("Slack list item ID.");
|
|
12990
|
-
|
|
12991
|
-
//#region src/chat/slack/tools/list/add-items.ts
|
|
12617
|
+
// src/chat/slack/tools/list/add-items.ts
|
|
12992
12618
|
/** Create a tool that appends items to an explicit Slack list. */
|
|
12993
12619
|
function createSlackListAddItemsTool(state) {
|
|
12994
12620
|
return zodTool({
|
|
@@ -13036,8 +12662,7 @@ function createSlackListAddItemsTool(state) {
|
|
|
13036
12662
|
}
|
|
13037
12663
|
});
|
|
13038
12664
|
}
|
|
13039
|
-
|
|
13040
|
-
//#region src/chat/slack/tools/list/create.ts
|
|
12665
|
+
// src/chat/slack/tools/list/create.ts
|
|
13041
12666
|
/** Create a tool that provisions a new Slack todo list. */
|
|
13042
12667
|
function createSlackListCreateTool(state) {
|
|
13043
12668
|
return zodTool({
|
|
@@ -13068,8 +12693,7 @@ function createSlackListCreateTool(state) {
|
|
|
13068
12693
|
}
|
|
13069
12694
|
});
|
|
13070
12695
|
}
|
|
13071
|
-
|
|
13072
|
-
//#region src/chat/slack/tools/list/get-items.ts
|
|
12696
|
+
// src/chat/slack/tools/list/get-items.ts
|
|
13073
12697
|
/** Create a tool that reads items from an explicit Slack list. */
|
|
13074
12698
|
function createSlackListGetItemsTool() {
|
|
13075
12699
|
return zodTool({
|
|
@@ -13096,8 +12720,7 @@ function createSlackListGetItemsTool() {
|
|
|
13096
12720
|
}
|
|
13097
12721
|
});
|
|
13098
12722
|
}
|
|
13099
|
-
|
|
13100
|
-
//#region src/chat/slack/tools/list/update-item.ts
|
|
12723
|
+
// src/chat/slack/tools/list/update-item.ts
|
|
13101
12724
|
const booleanInput = (description) => z.preprocess((value) => value === "true" ? true : value === "false" ? false : value, z.boolean()).describe(description);
|
|
13102
12725
|
const updateListItemInputSchema = z.union([z.object({
|
|
13103
12726
|
list_id: slackListIdParam,
|
|
@@ -13152,8 +12775,7 @@ function createSlackListUpdateItemTool(state) {
|
|
|
13152
12775
|
}
|
|
13153
12776
|
});
|
|
13154
12777
|
}
|
|
13155
|
-
|
|
13156
|
-
//#region src/chat/slack/tool-support/slack-message-url.ts
|
|
12778
|
+
// src/chat/slack/tool-support/slack-message-url.ts
|
|
13157
12779
|
/** Parse Slack archive URLs into structured message references. */
|
|
13158
12780
|
const SLACK_HOST_PATTERN = /^[a-z0-9-]+\.slack(?:-gov)?\.com$/;
|
|
13159
12781
|
const ARCHIVE_PATH_PATTERN = /^\/archives\/([CDG][A-Z0-9]+)\/p(\d{10})(\d{6})$/;
|
|
@@ -13228,8 +12850,7 @@ function parseSlackMessageReference(input) {
|
|
|
13228
12850
|
}
|
|
13229
12851
|
};
|
|
13230
12852
|
}
|
|
13231
|
-
|
|
13232
|
-
//#region src/chat/slack/message/blocks.ts
|
|
12853
|
+
// src/chat/slack/message/blocks.ts
|
|
13233
12854
|
const MAX_BLOCKS = 50;
|
|
13234
12855
|
const MAX_CHILDREN = 50;
|
|
13235
12856
|
const MAX_DEPTH = 16;
|
|
@@ -13310,8 +12931,7 @@ function renderBlockText(value) {
|
|
|
13310
12931
|
const budget = { remainingNodes: MAX_NODES };
|
|
13311
12932
|
return value.slice(0, MAX_BLOCKS).flatMap((block) => parseElement(block, budget, 0)).join("\n");
|
|
13312
12933
|
}
|
|
13313
|
-
|
|
13314
|
-
//#region src/chat/slack/message/attachments.ts
|
|
12934
|
+
// src/chat/slack/message/attachments.ts
|
|
13315
12935
|
const MAX_ATTACHMENTS = 10;
|
|
13316
12936
|
const MAX_FIELDS_PER_ATTACHMENT = 20;
|
|
13317
12937
|
const MAX_FIELD_CHARS = 1e3;
|
|
@@ -13414,8 +13034,7 @@ function renderAttachment(raw) {
|
|
|
13414
13034
|
function renderAttachmentText(input) {
|
|
13415
13035
|
return getAttachmentPayload(input).slice(0, MAX_ATTACHMENTS).map(renderAttachment).filter((line) => line.length > 0).map((line) => `[attachment] ${line}`).join("\n").slice(0, MAX_ATTACHMENT_TEXT_CHARS);
|
|
13416
13036
|
}
|
|
13417
|
-
|
|
13418
|
-
//#region src/chat/slack/tools/thread-read.ts
|
|
13037
|
+
// src/chat/slack/tools/thread-read.ts
|
|
13419
13038
|
const MAX_THREAD_READ_CHARS = 4e4;
|
|
13420
13039
|
/**
|
|
13421
13040
|
* Combine top-level `files` with files nested inside `attachments`
|
|
@@ -13611,8 +13230,7 @@ function createSlackThreadReadTool(context, attachmentDeps) {
|
|
|
13611
13230
|
}
|
|
13612
13231
|
});
|
|
13613
13232
|
}
|
|
13614
|
-
|
|
13615
|
-
//#region src/chat/slack/users.ts
|
|
13233
|
+
// src/chat/slack/users.ts
|
|
13616
13234
|
const profileFieldsSchema = z.object({ fields: z.record(z.string(), z.object({
|
|
13617
13235
|
value: z.string().optional(),
|
|
13618
13236
|
alt: z.string().optional(),
|
|
@@ -13765,8 +13383,7 @@ async function searchSlackUsers(options) {
|
|
|
13765
13383
|
truncated: listed.truncated
|
|
13766
13384
|
};
|
|
13767
13385
|
}
|
|
13768
|
-
|
|
13769
|
-
//#region src/chat/tools/user-lookup.ts
|
|
13386
|
+
// src/chat/tools/user-lookup.ts
|
|
13770
13387
|
const linkedSlackIdentity = alias(juniorIdentities, "user_lookup_slack_identity");
|
|
13771
13388
|
function explicitUserLookupError(error) {
|
|
13772
13389
|
if (error.apiError === "user_not_found" || error.code === "not_found") return "No Slack user found for the supplied user ID.";
|
|
@@ -13899,8 +13516,7 @@ function createUserLookupTool(teamId, providers) {
|
|
|
13899
13516
|
}
|
|
13900
13517
|
});
|
|
13901
13518
|
}
|
|
13902
|
-
|
|
13903
|
-
//#region src/chat/tools/system-time.ts
|
|
13519
|
+
// src/chat/tools/system-time.ts
|
|
13904
13520
|
const systemTimeInputSchema = z.object({ timezone: z.string().trim().min(1).optional().describe("Optional IANA timezone, for example America/Los_Angeles. When set, iso_local and timezone_offset_minutes are for that zone.") });
|
|
13905
13521
|
const systemTimeOutputSchema = juniorToolOutputSchema.extend({
|
|
13906
13522
|
unix_ms: z.number(),
|
|
@@ -13971,8 +13587,7 @@ function getTimeZoneOffsetMinutes(timestampMs, timezone) {
|
|
|
13971
13587
|
const asUtcMs = Date.UTC(parts.year, parts.month - 1, parts.day, parts.hour, parts.minute, parts.second);
|
|
13972
13588
|
return Math.round((timestampMs - asUtcMs) / 6e4);
|
|
13973
13589
|
}
|
|
13974
|
-
|
|
13975
|
-
//#region src/chat/tools/operator-sql.ts
|
|
13590
|
+
// src/chat/tools/operator-sql.ts
|
|
13976
13591
|
/** Deferred tool catalog source for operator tools. */
|
|
13977
13592
|
const OPERATOR_TOOL_SOURCE = {
|
|
13978
13593
|
id: "operator",
|
|
@@ -14052,8 +13667,7 @@ function createOperatorTools(context) {
|
|
|
14052
13667
|
}
|
|
14053
13668
|
}) };
|
|
14054
13669
|
}
|
|
14055
|
-
|
|
14056
|
-
//#region src/chat/artifacts/store.ts
|
|
13670
|
+
// src/chat/artifacts/store.ts
|
|
14057
13671
|
const MAX_IMAGE_BYTES = 10485760;
|
|
14058
13672
|
const IMAGE_EXTENSIONS = {
|
|
14059
13673
|
"image/gif": "gif",
|
|
@@ -14194,8 +13808,7 @@ function unpublishedArtifactHeaders() {
|
|
|
14194
13808
|
"x-content-type-options": "nosniff"
|
|
14195
13809
|
});
|
|
14196
13810
|
}
|
|
14197
|
-
|
|
14198
|
-
//#region src/chat/tools/publish-image.ts
|
|
13811
|
+
// src/chat/tools/publish-image.ts
|
|
14199
13812
|
const outputSchema$1 = juniorToolOutputSchema.extend({
|
|
14200
13813
|
bytes: z.number().int().positive(),
|
|
14201
13814
|
content_type: z.string().min(1),
|
|
@@ -14239,8 +13852,7 @@ function createPublishImageTool(args) {
|
|
|
14239
13852
|
}
|
|
14240
13853
|
});
|
|
14241
13854
|
}
|
|
14242
|
-
|
|
14243
|
-
//#region src/chat/tools/unpublish-image.ts
|
|
13855
|
+
// src/chat/tools/unpublish-image.ts
|
|
14244
13856
|
const outputSchema = juniorToolOutputSchema.extend({
|
|
14245
13857
|
filename: z.string().min(1),
|
|
14246
13858
|
unpublished: z.literal(true)
|
|
@@ -14272,8 +13884,7 @@ function createUnpublishImageTool(args) {
|
|
|
14272
13884
|
}
|
|
14273
13885
|
});
|
|
14274
13886
|
}
|
|
14275
|
-
|
|
14276
|
-
//#region src/chat/tools/load-attachment.ts
|
|
13887
|
+
// src/chat/tools/load-attachment.ts
|
|
14277
13888
|
const ATTACHMENT_DIR = ".junior/attachments";
|
|
14278
13889
|
async function readStream(stream) {
|
|
14279
13890
|
const chunks = [];
|
|
@@ -14328,8 +13939,7 @@ function createLoadAttachmentTool(args) {
|
|
|
14328
13939
|
}
|
|
14329
13940
|
});
|
|
14330
13941
|
}
|
|
14331
|
-
|
|
14332
|
-
//#region src/chat/tools/search-conversation-events.ts
|
|
13942
|
+
// src/chat/tools/search-conversation-events.ts
|
|
14333
13943
|
const DEFAULT_LIMIT$1 = 25;
|
|
14334
13944
|
const MAX_LIMIT$1 = 100;
|
|
14335
13945
|
const MAX_EVENT_DATA_BYTES = 4e3;
|
|
@@ -14539,8 +14149,7 @@ function stripReplacementHistoryField(value) {
|
|
|
14539
14149
|
replacement_history_count: Array.isArray(replacementHistory) ? replacementHistory.length : 0
|
|
14540
14150
|
};
|
|
14541
14151
|
}
|
|
14542
|
-
|
|
14543
|
-
//#region src/chat/briefs/search.ts
|
|
14152
|
+
// src/chat/briefs/search.ts
|
|
14544
14153
|
/** Search the latest Brief of each public root Conversation in one scope. */
|
|
14545
14154
|
async function searchConversationBriefs(db, args) {
|
|
14546
14155
|
const query = args.filters.query?.trim() || void 0;
|
|
@@ -14604,8 +14213,7 @@ async function searchConversationBriefs(db, args) {
|
|
|
14604
14213
|
};
|
|
14605
14214
|
});
|
|
14606
14215
|
}
|
|
14607
|
-
|
|
14608
|
-
//#region src/chat/tools/search-conversation-briefs.ts
|
|
14216
|
+
// src/chat/tools/search-conversation-briefs.ts
|
|
14609
14217
|
const DEFAULT_LIMIT = 10;
|
|
14610
14218
|
const MAX_LIMIT = 25;
|
|
14611
14219
|
const conversationBriefSearchOutputSchema = juniorToolOutputSchema.extend({
|
|
@@ -14716,8 +14324,7 @@ function createSearchConversationBriefsTool(scope, currentConversationId, provid
|
|
|
14716
14324
|
}
|
|
14717
14325
|
});
|
|
14718
14326
|
}
|
|
14719
|
-
|
|
14720
|
-
//#region src/chat/tools/handoff/tool.ts
|
|
14327
|
+
// src/chat/tools/handoff/tool.ts
|
|
14721
14328
|
const HANDOFF_TOOL_NAME = "handoff";
|
|
14722
14329
|
function formatHandoffProfiles(handoff) {
|
|
14723
14330
|
return handoff.profiles.map((profile) => `- ${formatModelProfile(profile.name, profile.description)}`).join("\n");
|
|
@@ -14758,8 +14365,7 @@ function createHandoffTool(handoff) {
|
|
|
14758
14365
|
}
|
|
14759
14366
|
});
|
|
14760
14367
|
}
|
|
14761
|
-
|
|
14762
|
-
//#region src/chat/plugins/credential-hooks.ts
|
|
14368
|
+
// src/chat/plugins/credential-hooks.ts
|
|
14763
14369
|
function parseSchema(schema, value, message) {
|
|
14764
14370
|
const result = schema.safeParse(value);
|
|
14765
14371
|
if (!result.success) throw new Error(message);
|
|
@@ -14887,31 +14493,30 @@ async function issuePluginCredential(input) {
|
|
|
14887
14493
|
}
|
|
14888
14494
|
}), plugin.manifest.name);
|
|
14889
14495
|
}
|
|
14890
|
-
|
|
14891
|
-
//#region src/chat/tools/web/constants.ts
|
|
14496
|
+
// src/chat/tools/web/constants.ts
|
|
14892
14497
|
const USER_AGENT = "junior-bot/0.1";
|
|
14893
14498
|
const FETCH_TIMEOUT_MS = 8e3;
|
|
14894
14499
|
const DEFAULT_MAX_CHARS = 6e3;
|
|
14895
14500
|
const MAX_FETCH_CHARS = 12e3;
|
|
14896
14501
|
const MAX_FETCH_BYTES = 1e6;
|
|
14897
|
-
|
|
14898
|
-
//#region src/chat/tools/web/network.ts
|
|
14502
|
+
// src/chat/tools/web/network.ts
|
|
14899
14503
|
function isPrivateIpv4(ip) {
|
|
14900
14504
|
const parts = ip.split(".").map((chunk) => Number.parseInt(chunk, 10));
|
|
14901
|
-
|
|
14902
|
-
if (parts
|
|
14903
|
-
if (
|
|
14904
|
-
if (
|
|
14905
|
-
if (
|
|
14906
|
-
if (
|
|
14505
|
+
const [first, second] = parts;
|
|
14506
|
+
if (parts.length !== 4 || first === void 0 || second === void 0 || parts.some((n) => Number.isNaN(n) || n < 0 || n > 255)) return true;
|
|
14507
|
+
if (first === 10 || first === 127) return true;
|
|
14508
|
+
if (first === 169 && second === 254) return true;
|
|
14509
|
+
if (first === 172 && second >= 16 && second <= 31) return true;
|
|
14510
|
+
if (first === 192 && second === 168) return true;
|
|
14511
|
+
if (first === 0) return true;
|
|
14907
14512
|
return false;
|
|
14908
14513
|
}
|
|
14909
14514
|
function parseMappedIpv4FromIpv6(mapped) {
|
|
14910
14515
|
if (net.isIP(mapped) === 4) return mapped;
|
|
14911
|
-
const
|
|
14912
|
-
if (!
|
|
14913
|
-
const high = Number.parseInt(
|
|
14914
|
-
const low = Number.parseInt(
|
|
14516
|
+
const [, highHex, lowHex] = mapped.match(/^([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i) ?? [];
|
|
14517
|
+
if (!highHex || !lowHex) return;
|
|
14518
|
+
const high = Number.parseInt(highHex, 16);
|
|
14519
|
+
const low = Number.parseInt(lowHex, 16);
|
|
14915
14520
|
return `${high >> 8 & 255}.${high & 255}.${low >> 8 & 255}.${low & 255}`;
|
|
14916
14521
|
}
|
|
14917
14522
|
function isPrivateIpv6(ip) {
|
|
@@ -14937,7 +14542,6 @@ async function resolvePublicHostname(hostname) {
|
|
|
14937
14542
|
all: true,
|
|
14938
14543
|
verbatim: true
|
|
14939
14544
|
});
|
|
14940
|
-
if (records.length === 0) throw new ToolInputError("Could not resolve hostname");
|
|
14941
14545
|
const deduped = /* @__PURE__ */ new Map();
|
|
14942
14546
|
for (const record of records) {
|
|
14943
14547
|
const family = record.family === 6 ? 6 : 4;
|
|
@@ -14948,7 +14552,9 @@ async function resolvePublicHostname(hostname) {
|
|
|
14948
14552
|
family
|
|
14949
14553
|
});
|
|
14950
14554
|
}
|
|
14951
|
-
|
|
14555
|
+
const [first, ...rest] = deduped.values();
|
|
14556
|
+
if (!first) throw new ToolInputError("Could not resolve hostname");
|
|
14557
|
+
return [first, ...rest];
|
|
14952
14558
|
}
|
|
14953
14559
|
async function resolvePinnedAddresses(url) {
|
|
14954
14560
|
const hostname = normalizeHostname(url.hostname);
|
|
@@ -14956,7 +14562,7 @@ async function resolvePinnedAddresses(url) {
|
|
|
14956
14562
|
return resolvePublicHostname(hostname);
|
|
14957
14563
|
}
|
|
14958
14564
|
function createPinnedLookup(resolved) {
|
|
14959
|
-
const fallback = resolved
|
|
14565
|
+
const [fallback] = resolved;
|
|
14960
14566
|
return (_hostname, options, callback) => {
|
|
14961
14567
|
if (options?.all) {
|
|
14962
14568
|
callback(null, resolved.map((entry) => ({
|
|
@@ -15003,7 +14609,7 @@ async function fetchWithPinnedLookup(url, resolved, signal) {
|
|
|
15003
14609
|
signal.removeEventListener("abort", onAbort);
|
|
15004
14610
|
const headers = new Headers();
|
|
15005
14611
|
const rawHeaders = response.rawHeaders;
|
|
15006
|
-
for (let i = 0; i < rawHeaders.length; i += 2) headers.append(rawHeaders[i], rawHeaders[i + 1]);
|
|
14612
|
+
for (let i = 0; i + 1 < rawHeaders.length; i += 2) headers.append(rawHeaders[i] ?? "", rawHeaders[i + 1] ?? "");
|
|
15007
14613
|
const rawStatus = response.statusCode ?? 500;
|
|
15008
14614
|
const status = rawStatus >= 200 && rawStatus <= 599 ? rawStatus : 502;
|
|
15009
14615
|
resolve(new Response(Buffer.concat(chunks), {
|
|
@@ -15078,8 +14684,7 @@ async function readResponseBody(response, maxBytes) {
|
|
|
15078
14684
|
}
|
|
15079
14685
|
return new TextDecoder().decode(Buffer.concat(chunks));
|
|
15080
14686
|
}
|
|
15081
|
-
|
|
15082
|
-
//#region src/chat/tools/web/fetch-content.ts
|
|
14687
|
+
// src/chat/tools/web/fetch-content.ts
|
|
15083
14688
|
const htmlToMarkdownConverter = new NodeHtmlMarkdown({
|
|
15084
14689
|
bulletMarker: "-",
|
|
15085
14690
|
codeBlockStyle: "fenced",
|
|
@@ -15122,7 +14727,7 @@ function decodeHtmlEntities(value) {
|
|
|
15122
14727
|
}
|
|
15123
14728
|
function extractTitle(html) {
|
|
15124
14729
|
const match = html.match(/<title\b[^>]*>([\s\S]*?)<\/title>/i);
|
|
15125
|
-
const title = match ? normalizeWhitespace(decodeHtmlEntities(match[1])) : "";
|
|
14730
|
+
const title = match?.[1] !== void 0 ? normalizeWhitespace(decodeHtmlEntities(match[1])) : "";
|
|
15126
14731
|
return title.length > 0 ? title : void 0;
|
|
15127
14732
|
}
|
|
15128
14733
|
function escapeRegex(value) {
|
|
@@ -15220,8 +14825,7 @@ async function extractWebFetchResponse(url, response, maxChars = DEFAULT_MAX_CHA
|
|
|
15220
14825
|
truncated: extracted.truncated
|
|
15221
14826
|
};
|
|
15222
14827
|
}
|
|
15223
|
-
|
|
15224
|
-
//#region src/chat/tools/web/fetch-tool.ts
|
|
14828
|
+
// src/chat/tools/web/fetch-tool.ts
|
|
15225
14829
|
function extensionForMediaType(mediaType) {
|
|
15226
14830
|
if (mediaType === "image/png") return "png";
|
|
15227
14831
|
if (mediaType === "image/jpeg") return "jpg";
|
|
@@ -15279,8 +14883,7 @@ function createWebFetchTool(hooks, options = {}) {
|
|
|
15279
14883
|
}
|
|
15280
14884
|
});
|
|
15281
14885
|
}
|
|
15282
|
-
|
|
15283
|
-
//#region src/chat/tools/web/search.ts
|
|
14886
|
+
// src/chat/tools/web/search.ts
|
|
15284
14887
|
const SEARCH_TIMEOUT_MS = 6e4;
|
|
15285
14888
|
const MAX_RESULTS$1 = 5;
|
|
15286
14889
|
const SEARCH_TOOL_NAME = "parallelSearch";
|
|
@@ -15352,8 +14955,7 @@ function createWebSearchTool(modelId, override) {
|
|
|
15352
14955
|
}
|
|
15353
14956
|
});
|
|
15354
14957
|
}
|
|
15355
|
-
|
|
15356
|
-
//#region src/chat/tools/sandbox/write-file.ts
|
|
14958
|
+
// src/chat/tools/sandbox/write-file.ts
|
|
15357
14959
|
/** Create the sandbox full-file write tool definition exposed to the agent. */
|
|
15358
14960
|
function createWriteFileTool() {
|
|
15359
14961
|
return zodTool({
|
|
@@ -15375,8 +14977,7 @@ function createWriteFileTool() {
|
|
|
15375
14977
|
}
|
|
15376
14978
|
});
|
|
15377
14979
|
}
|
|
15378
|
-
|
|
15379
|
-
//#region src/stats.ts
|
|
14980
|
+
// src/stats.ts
|
|
15380
14981
|
function utcDate(nowMs) {
|
|
15381
14982
|
return new Date(nowMs).toISOString().slice(0, 10);
|
|
15382
14983
|
}
|
|
@@ -15401,8 +15002,7 @@ async function incrementStat(key, options = {}) {
|
|
|
15401
15002
|
async function readStats(start, end) {
|
|
15402
15003
|
return await getDb().select().from(juniorStats).where(and(gte(juniorStats.date, start), lte(juniorStats.date, end))).orderBy(asc(juniorStats.date), asc(juniorStats.namespace), asc(juniorStats.metric), asc(juniorStats.name));
|
|
15403
15004
|
}
|
|
15404
|
-
|
|
15405
|
-
//#region src/chat/workspaces/tools.ts
|
|
15005
|
+
// src/chat/workspaces/tools.ts
|
|
15406
15006
|
/** Record optional reporting without changing the switchWorkspace outcome. */
|
|
15407
15007
|
async function tryRecordWorkspaceSwitchStat(workspace) {
|
|
15408
15008
|
if (!process.env.DATABASE_URL) return;
|
|
@@ -15677,8 +15277,7 @@ function createWorkspaceTools(context) {
|
|
|
15677
15277
|
})
|
|
15678
15278
|
};
|
|
15679
15279
|
}
|
|
15680
|
-
|
|
15681
|
-
//#region src/chat/tools/index.ts
|
|
15280
|
+
// src/chat/tools/index.ts
|
|
15682
15281
|
function createToolState() {
|
|
15683
15282
|
const operationResultCache = /* @__PURE__ */ new Map();
|
|
15684
15283
|
return {
|
|
@@ -15811,8 +15410,7 @@ function createTools(availableSkills, hooks = {}, context, options = {}) {
|
|
|
15811
15410
|
}
|
|
15812
15411
|
return tools;
|
|
15813
15412
|
}
|
|
15814
|
-
|
|
15815
|
-
//#region src/chat/runtime/report-progress.ts
|
|
15413
|
+
// src/chat/runtime/report-progress.ts
|
|
15816
15414
|
function isActivePlanItem(value) {
|
|
15817
15415
|
if (!value || typeof value !== "object") return false;
|
|
15818
15416
|
const item = value;
|
|
@@ -15853,8 +15451,7 @@ function latestProgressStatus(messages) {
|
|
|
15853
15451
|
}
|
|
15854
15452
|
}
|
|
15855
15453
|
}
|
|
15856
|
-
|
|
15857
|
-
//#region src/chat/tool-support/catalog-tool-call.ts
|
|
15454
|
+
// src/chat/tool-support/catalog-tool-call.ts
|
|
15858
15455
|
function schemaErrorText(schema, value) {
|
|
15859
15456
|
const firstError = [...Value.Errors(schema, value)][0];
|
|
15860
15457
|
if (!firstError) return "invalid arguments";
|
|
@@ -15892,8 +15489,7 @@ function prepareCatalogToolCall(call) {
|
|
|
15892
15489
|
toolName: call.toolName
|
|
15893
15490
|
};
|
|
15894
15491
|
}
|
|
15895
|
-
|
|
15896
|
-
//#region src/chat/tools/execution/build-sandbox-input.ts
|
|
15492
|
+
// src/chat/tools/execution/build-sandbox-input.ts
|
|
15897
15493
|
/** Normalize LLM tool params into the shape expected by the sandbox executor. */
|
|
15898
15494
|
function buildSandboxInput(toolName, params) {
|
|
15899
15495
|
const optionalNumber = (value) => typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
@@ -15936,8 +15532,7 @@ function buildSandboxInput(toolName, params) {
|
|
|
15936
15532
|
};
|
|
15937
15533
|
return params;
|
|
15938
15534
|
}
|
|
15939
|
-
|
|
15940
|
-
//#region src/chat/services/plugin-auth-orchestration.ts
|
|
15535
|
+
// src/chat/services/plugin-auth-orchestration.ts
|
|
15941
15536
|
var PluginAuthorizationPauseError = class extends AuthorizationPauseError {
|
|
15942
15537
|
constructor(provider, providerDisplayName, disposition, requestText) {
|
|
15943
15538
|
super("plugin", provider, providerDisplayName, disposition, requestText);
|
|
@@ -16050,8 +15645,7 @@ function createPluginAuthOrchestration(input) {
|
|
|
16050
15645
|
getPendingPause: () => pendingPause
|
|
16051
15646
|
};
|
|
16052
15647
|
}
|
|
16053
|
-
|
|
16054
|
-
//#region src/chat/tools/execution/tool-error-handler.ts
|
|
15648
|
+
// src/chat/tools/execution/tool-error-handler.ts
|
|
16055
15649
|
function isPluginToolInputError(error) {
|
|
16056
15650
|
return error instanceof PluginToolInputError || error instanceof Error && error.name === "PluginToolInputError";
|
|
16057
15651
|
}
|
|
@@ -16112,8 +15706,7 @@ function handleToolExecutionError(error, toolName, toolCallId, shouldTrace, conv
|
|
|
16112
15706
|
});
|
|
16113
15707
|
throw error;
|
|
16114
15708
|
}
|
|
16115
|
-
|
|
16116
|
-
//#region src/chat/tools/execute-tool.ts
|
|
15709
|
+
// src/chat/tools/execute-tool.ts
|
|
16117
15710
|
const EXECUTE_TOOL_NAME = "executeTool";
|
|
16118
15711
|
/** Create the model-visible dispatcher schema for catalog tools. */
|
|
16119
15712
|
function createExecuteToolTool() {
|
|
@@ -16136,8 +15729,7 @@ function createExecuteToolTool() {
|
|
|
16136
15729
|
}
|
|
16137
15730
|
});
|
|
16138
15731
|
}
|
|
16139
|
-
|
|
16140
|
-
//#region src/chat/tool-exposure.ts
|
|
15732
|
+
// src/chat/tool-exposure.ts
|
|
16141
15733
|
/** Return the runtime exposure for a tool, preserving direct compatibility. */
|
|
16142
15734
|
function effectiveToolExposure(definition) {
|
|
16143
15735
|
return definition.exposure ?? "direct";
|
|
@@ -16164,8 +15756,7 @@ function planToolExposure(tools) {
|
|
|
16164
15756
|
excludedTools
|
|
16165
15757
|
};
|
|
16166
15758
|
}
|
|
16167
|
-
|
|
16168
|
-
//#region src/chat/tools/search-tools.ts
|
|
15759
|
+
// src/chat/tools/search-tools.ts
|
|
16169
15760
|
const SEARCH_TOOLS_NAME = "searchTools";
|
|
16170
15761
|
const DEFAULT_MAX_RESULTS = 5;
|
|
16171
15762
|
const MAX_RESULTS = 20;
|
|
@@ -16422,8 +16013,7 @@ function createSearchToolsTool(catalogTools) {
|
|
|
16422
16013
|
}
|
|
16423
16014
|
});
|
|
16424
16015
|
}
|
|
16425
|
-
|
|
16426
|
-
//#region src/chat/tool-support/pi-tool-adapter.ts
|
|
16016
|
+
// src/chat/tool-support/pi-tool-adapter.ts
|
|
16427
16017
|
/**
|
|
16428
16018
|
* How long a preempted tool may take to return its own aborted result. Keep it
|
|
16429
16019
|
* below the agent's abort settle grace, so the parked turn sees the result.
|
|
@@ -16655,8 +16245,7 @@ function createPiAgentTools(tools, sandbox, spanContext, onStatus, sandboxTools,
|
|
|
16655
16245
|
}
|
|
16656
16246
|
}));
|
|
16657
16247
|
}
|
|
16658
|
-
|
|
16659
|
-
//#region src/chat/mcp/jwt-bearer-provider.ts
|
|
16248
|
+
// src/chat/mcp/jwt-bearer-provider.ts
|
|
16660
16249
|
/**
|
|
16661
16250
|
* Non-interactive MCP auth for bot plugins.
|
|
16662
16251
|
*
|
|
@@ -16724,8 +16313,7 @@ function createJwtBearerMcpClientProvider(subject, mcpUrl, auth) {
|
|
|
16724
16313
|
}
|
|
16725
16314
|
};
|
|
16726
16315
|
}
|
|
16727
|
-
|
|
16728
|
-
//#region src/chat/mcp/auth-store.ts
|
|
16316
|
+
// src/chat/mcp/auth-store.ts
|
|
16729
16317
|
const MCP_AUTH_SESSION_PREFIX = "junior:mcp_oauth_attempt:v2";
|
|
16730
16318
|
const MCP_AUTH_CREDENTIALS_PREFIX = "junior:mcp_auth_credentials";
|
|
16731
16319
|
const MCP_AUTH_SESSION_INDEX_PREFIX = "junior:mcp_oauth_attempt_index:v2";
|
|
@@ -16890,8 +16478,7 @@ async function putMcpServerSessionId(userId, provider, sessionId, ttlMs = MCP_SE
|
|
|
16890
16478
|
async function deleteMcpServerSessionId(userId, provider) {
|
|
16891
16479
|
await (await getConnectedStateAdapter()).delete(serverSessionKey(userId, provider));
|
|
16892
16480
|
}
|
|
16893
|
-
|
|
16894
|
-
//#region src/chat/mcp/oauth-provider.ts
|
|
16481
|
+
// src/chat/mcp/oauth-provider.ts
|
|
16895
16482
|
function createClientMetadata(callbackUrl) {
|
|
16896
16483
|
return {
|
|
16897
16484
|
client_name: "Junior MCP Client",
|
|
@@ -16912,12 +16499,12 @@ function requireEnv(name) {
|
|
|
16912
16499
|
return value;
|
|
16913
16500
|
}
|
|
16914
16501
|
var StateBackedMcpOAuthClientProvider = class {
|
|
16502
|
+
clientMetadata;
|
|
16915
16503
|
authSessionId;
|
|
16916
16504
|
callbackUrl;
|
|
16917
16505
|
sessionContext;
|
|
16918
16506
|
runCredentialMutation;
|
|
16919
16507
|
oauthClient;
|
|
16920
|
-
clientMetadata;
|
|
16921
16508
|
constructor(authSessionId, callbackUrl, sessionContext, runCredentialMutation, oauthClient) {
|
|
16922
16509
|
this.authSessionId = authSessionId;
|
|
16923
16510
|
this.callbackUrl = callbackUrl;
|
|
@@ -17050,8 +16637,7 @@ var StateBackedMcpOAuthClientProvider = class {
|
|
|
17050
16637
|
return session;
|
|
17051
16638
|
}
|
|
17052
16639
|
};
|
|
17053
|
-
|
|
17054
|
-
//#region src/chat/mcp/oauth.ts
|
|
16640
|
+
// src/chat/mcp/oauth.ts
|
|
17055
16641
|
function getMcpOAuthCallbackPath(provider) {
|
|
17056
16642
|
return `/api/oauth/callback/mcp/${provider}`;
|
|
17057
16643
|
}
|
|
@@ -17123,8 +16709,7 @@ async function finalizeMcpAuthorization(provider, authSessionId, authorizationCo
|
|
|
17123
16709
|
if (!nextSession) throw new Error(`Unknown MCP auth session: ${authSessionId}`);
|
|
17124
16710
|
return nextSession;
|
|
17125
16711
|
}
|
|
17126
|
-
|
|
17127
|
-
//#region src/chat/services/auth-pause-response.ts
|
|
16712
|
+
// src/chat/services/auth-pause-response.ts
|
|
17128
16713
|
const MAX_AUTH_REQUEST_LENGTH = 200;
|
|
17129
16714
|
function formatAuthRequest(requestText) {
|
|
17130
16715
|
const normalized = requestText.replace(/\s+/g, " ").trim();
|
|
@@ -17144,8 +16729,7 @@ function buildAuthPauseResponse(slackUserId, providerDisplayName, requestText) {
|
|
|
17144
16729
|
const notice = `${mention}I need access to your ${providerDisplayName} account to continue. I sent you a private link.`;
|
|
17145
16730
|
return request ? `${notice}\n\n*Why:* ${request}` : notice;
|
|
17146
16731
|
}
|
|
17147
|
-
|
|
17148
|
-
//#region src/chat/services/mcp-auth-orchestration.ts
|
|
16732
|
+
// src/chat/services/mcp-auth-orchestration.ts
|
|
17149
16733
|
var McpAuthorizationPauseError = class extends AuthorizationPauseError {
|
|
17150
16734
|
constructor(provider, providerDisplayName, disposition, requestText) {
|
|
17151
16735
|
super("mcp", provider, providerDisplayName, disposition, requestText);
|
|
@@ -17181,6 +16765,13 @@ function createMcpAuthOrchestration(input) {
|
|
|
17181
16765
|
authSessionIdsByProvider.set(plugin.manifest.name, provider.authSessionId);
|
|
17182
16766
|
return provider;
|
|
17183
16767
|
};
|
|
16768
|
+
const serviceAccountProviderFactory = async (plugin) => {
|
|
16769
|
+
const provider = plugin.manifest.name;
|
|
16770
|
+
if (!plugin.manifest.accounts?.serviceAccount) return;
|
|
16771
|
+
if (!serviceAccountOnly(plugin.manifest) && input.actorId && (await getMcpStoredOAuthCredentials(input.actorId, provider))?.tokens) return;
|
|
16772
|
+
const credentials = await getMcpServiceAccountCredentials(provider);
|
|
16773
|
+
return credentials ? createMcpServiceAccountClientProvider(provider, credentials) : void 0;
|
|
16774
|
+
};
|
|
17184
16775
|
const onAuthorizationRequired = async (provider, context) => {
|
|
17185
16776
|
if (botAuthProviders.has(provider)) return false;
|
|
17186
16777
|
if (pendingPause) return true;
|
|
@@ -17261,12 +16852,12 @@ function createMcpAuthOrchestration(input) {
|
|
|
17261
16852
|
};
|
|
17262
16853
|
return {
|
|
17263
16854
|
authProviderFactory,
|
|
16855
|
+
serviceAccountProviderFactory,
|
|
17264
16856
|
onAuthorizationRequired,
|
|
17265
16857
|
getPendingPause: () => pendingPause
|
|
17266
16858
|
};
|
|
17267
16859
|
}
|
|
17268
|
-
|
|
17269
|
-
//#region src/chat/sandbox/egress/credentials.ts
|
|
16860
|
+
// src/chat/sandbox/egress/credentials.ts
|
|
17270
16861
|
const HTTP_READ_METHODS = /* @__PURE__ */ new Set([
|
|
17271
16862
|
"GET",
|
|
17272
16863
|
"HEAD",
|
|
@@ -17438,8 +17029,7 @@ async function sandboxEgressCredentialLease(provider, selection, context) {
|
|
|
17438
17029
|
function hasSandboxEgressLeaseTransformForHost(lease, host) {
|
|
17439
17030
|
return lease.headerTransforms.some((transform) => matchesSandboxEgressDomain(host, transform.domain));
|
|
17440
17031
|
}
|
|
17441
|
-
|
|
17442
|
-
//#region src/chat/egress/credentialed.ts
|
|
17032
|
+
// src/chat/egress/credentialed.ts
|
|
17443
17033
|
const HOP_BY_HOP_HEADERS = /* @__PURE__ */ new Set([
|
|
17444
17034
|
"connection",
|
|
17445
17035
|
"host",
|
|
@@ -17566,7 +17156,7 @@ function logSandboxEgressUpstreamRequest(input) {
|
|
|
17566
17156
|
});
|
|
17567
17157
|
}
|
|
17568
17158
|
async function requestBodyBytes(request) {
|
|
17569
|
-
if (request.method === "GET" || request.method === "HEAD" || request.body === null) return;
|
|
17159
|
+
if (request.method === "GET" || request.method === "HEAD" || request.method === "OPTIONS" || request.body === null) return;
|
|
17570
17160
|
return await request.arrayBuffer();
|
|
17571
17161
|
}
|
|
17572
17162
|
/**
|
|
@@ -17986,8 +17576,7 @@ async function executeCredentialedEgressRequest(input) {
|
|
|
17986
17576
|
});
|
|
17987
17577
|
}
|
|
17988
17578
|
}
|
|
17989
|
-
|
|
17990
|
-
//#region src/chat/egress/plugin.ts
|
|
17579
|
+
// src/chat/egress/plugin.ts
|
|
17991
17580
|
function credentialContextForPluginEgress(credentialContext) {
|
|
17992
17581
|
return {
|
|
17993
17582
|
credentials: credentialContext,
|
|
@@ -18030,8 +17619,7 @@ function createPluginEgress(deps) {
|
|
|
18030
17619
|
});
|
|
18031
17620
|
} };
|
|
18032
17621
|
}
|
|
18033
|
-
|
|
18034
|
-
//#region src/chat/services/guardian-action-policy.ts
|
|
17622
|
+
// src/chat/services/guardian-action-policy.ts
|
|
18035
17623
|
/**
|
|
18036
17624
|
* The only reasons that Guardian can block an action. Keep each rule broad
|
|
18037
17625
|
* and free of tool or provider names. The model sees them in this order.
|
|
@@ -18157,8 +17745,7 @@ ${renderRules("deny")}
|
|
|
18157
17745
|
- Rate risk and user authorization first.
|
|
18158
17746
|
- Then set the rule to the id of the one rule that the action clearly matches. When a hard rule and a confirmation rule both match, name the hard rule. When no definition clearly fits, use \`none\`. Do not name a rule only to express general doubt.
|
|
18159
17747
|
- Keep the reason to one concise, specific sentence. For a confirmation rule, name the exact action, target, and material side effects the user must confirm. For a hard rule, name the risk. For \`none\`, say why the action is ordinary.`;
|
|
18160
|
-
|
|
18161
|
-
//#region src/chat/services/guardian-action-review.ts
|
|
17748
|
+
// src/chat/services/guardian-action-review.ts
|
|
18162
17749
|
const guardianAssessmentSchema = z.object({
|
|
18163
17750
|
riskLevel: z.enum([
|
|
18164
17751
|
"low",
|
|
@@ -18292,8 +17879,7 @@ function createGuardianActionReviewer(options) {
|
|
|
18292
17879
|
};
|
|
18293
17880
|
} };
|
|
18294
17881
|
}
|
|
18295
|
-
|
|
18296
|
-
//#region src/chat/tool-support/action-review-evidence.ts
|
|
17882
|
+
// src/chat/tool-support/action-review-evidence.ts
|
|
18297
17883
|
const MAX_MESSAGE_TRANSCRIPT_TOKENS = 1e4;
|
|
18298
17884
|
const MAX_TOOL_TRANSCRIPT_TOKENS = 1e4;
|
|
18299
17885
|
const MAX_MESSAGE_ENTRY_TOKENS = 2e3;
|
|
@@ -18437,8 +18023,7 @@ function buildToolActionEvidence(messages, options = {}) {
|
|
|
18437
18023
|
omittedEntries: included.filter((value) => !value).length
|
|
18438
18024
|
};
|
|
18439
18025
|
}
|
|
18440
|
-
|
|
18441
|
-
//#region src/chat/agent-invocations/root-conversation.ts
|
|
18026
|
+
// src/chat/agent-invocations/root-conversation.ts
|
|
18442
18027
|
/** Most root messages that Guardian reads, newest first. Codex uses 16. */
|
|
18443
18028
|
const MAX_ROOT_MESSAGES = 16;
|
|
18444
18029
|
/** Most characters of one root message. */
|
|
@@ -18590,8 +18175,7 @@ async function readRootConversation(args) {
|
|
|
18590
18175
|
truncated: hasOlder || orphanEdits || messages.length < all.length
|
|
18591
18176
|
};
|
|
18592
18177
|
}
|
|
18593
|
-
|
|
18594
|
-
//#region src/chat/agent/tools.ts
|
|
18178
|
+
// src/chat/agent/tools.ts
|
|
18595
18179
|
/** Record optional reporting without changing the loadSkill outcome. */
|
|
18596
18180
|
async function tryRecordSkillLoadStat(skill) {
|
|
18597
18181
|
if (!process.env.DATABASE_URL) return;
|
|
@@ -18709,6 +18293,7 @@ async function wireAgentTools(args) {
|
|
|
18709
18293
|
});
|
|
18710
18294
|
const mcpToolManager = new McpToolManager(pluginCatalogRuntime.getMcpProviders(), {
|
|
18711
18295
|
authProviderFactory: mcpAuth.authProviderFactory,
|
|
18296
|
+
serviceAccountProviderFactory: mcpAuth.serviceAccountProviderFactory,
|
|
18712
18297
|
onAuthorizationRequired: (provider, _error, context) => mcpAuth.onAuthorizationRequired(provider, context),
|
|
18713
18298
|
onToolSuccess: async (input) => {
|
|
18714
18299
|
return await pluginHooks.afterMcpTool({
|
|
@@ -18827,7 +18412,11 @@ async function wireAgentTools(args) {
|
|
|
18827
18412
|
const pendingMcpProvider = args.state.pendingAuth?.kind === "mcp" ? args.state.pendingAuth.provider : void 0;
|
|
18828
18413
|
if (credentialUserId) for (const provider of args.connectedMcpProviders) {
|
|
18829
18414
|
if (provider === pendingMcpProvider) continue;
|
|
18830
|
-
|
|
18415
|
+
try {
|
|
18416
|
+
if (await mcpToolManager.activateProvider(provider)) await args.recordConnectedMcpProvider(provider);
|
|
18417
|
+
} catch (error) {
|
|
18418
|
+
if (!(error instanceof McpServiceAccountRequiredError)) throw error;
|
|
18419
|
+
}
|
|
18831
18420
|
if (mcpAuth.getPendingPause()) {
|
|
18832
18421
|
args.resume.captureHistoryBeforePrompt(args.preAgentPromptMessages());
|
|
18833
18422
|
throw mcpAuth.getPendingPause();
|
|
@@ -18890,8 +18479,7 @@ async function wireAgentTools(args) {
|
|
|
18890
18479
|
toolRuntimeContext
|
|
18891
18480
|
};
|
|
18892
18481
|
}
|
|
18893
|
-
|
|
18894
|
-
//#region src/chat/agent/resume.ts
|
|
18482
|
+
// src/chat/agent/resume.ts
|
|
18895
18483
|
function extractSliceUsage(messages, beforeMessageCount) {
|
|
18896
18484
|
const usage = extractGenAiUsageSummary(...messages.slice(beforeMessageCount).filter(isAssistantMessage));
|
|
18897
18485
|
return hasAgentTurnUsage(usage) ? usage : void 0;
|
|
@@ -19107,8 +18695,7 @@ function createResumeState(args) {
|
|
|
19107
18695
|
}
|
|
19108
18696
|
};
|
|
19109
18697
|
}
|
|
19110
|
-
|
|
19111
|
-
//#region src/chat/services/plan-continuation.ts
|
|
18698
|
+
// src/chat/services/plan-continuation.ts
|
|
19112
18699
|
const OPEN_PLAN_TAG = "open-plan";
|
|
19113
18700
|
function openItems(input) {
|
|
19114
18701
|
const plan = input && typeof input === "object" ? input.plan : void 0;
|
|
@@ -19172,8 +18759,7 @@ function appendOpenPlan(continuation, messages) {
|
|
|
19172
18759
|
const plan = latestOpenPlanItems(messages);
|
|
19173
18760
|
return plan.length === 0 ? continuation : `${continuation}\n\n<${OPEN_PLAN_TAG}>\n${JSON.stringify(plan)}\n</${OPEN_PLAN_TAG}>`;
|
|
19174
18761
|
}
|
|
19175
|
-
|
|
19176
|
-
//#region src/chat/services/context-compaction.ts
|
|
18762
|
+
// src/chat/services/context-compaction.ts
|
|
19177
18763
|
const RETAINED_USER_MESSAGE_TOKENS = 2e4;
|
|
19178
18764
|
const MAX_SUMMARY_CHARS = 6e3;
|
|
19179
18765
|
/** Raised when Junior cannot compact history below the active model's hard ceiling. */
|
|
@@ -19604,8 +19190,7 @@ async function compactActiveContextIfNeeded(args, deps) {
|
|
|
19604
19190
|
piMessages: messages
|
|
19605
19191
|
};
|
|
19606
19192
|
}
|
|
19607
|
-
|
|
19608
|
-
//#region src/chat/agent/handoff.ts
|
|
19193
|
+
// src/chat/agent/handoff.ts
|
|
19609
19194
|
/** Tools that must be the only tool call in their assistant message. */
|
|
19610
19195
|
const EXCLUSIVE_TOOL_NAMES = [
|
|
19611
19196
|
HANDOFF_TOOL_NAME,
|
|
@@ -19724,8 +19309,7 @@ function applyHandoff(args) {
|
|
|
19724
19309
|
thinkingLevel: args.pending.thinkingLevel
|
|
19725
19310
|
};
|
|
19726
19311
|
}
|
|
19727
|
-
|
|
19728
|
-
//#region src/chat/agent/index.ts
|
|
19312
|
+
// src/chat/agent/index.ts
|
|
19729
19313
|
/**
|
|
19730
19314
|
* Agent executor.
|
|
19731
19315
|
*
|
|
@@ -20720,8 +20304,7 @@ async function executeAgentRunInPrivacyContext(run, conversationPrivacy, runLogC
|
|
|
20720
20304
|
await closeTools?.();
|
|
20721
20305
|
}
|
|
20722
20306
|
}
|
|
20723
|
-
|
|
20724
|
-
//#region src/chat/runtime/agent-runner.ts
|
|
20307
|
+
// src/chat/runtime/agent-runner.ts
|
|
20725
20308
|
/** Compose the agent executor with stable host dependencies. */
|
|
20726
20309
|
function createAgentRunner(execute, options) {
|
|
20727
20310
|
const attachmentStorage = options?.attachmentStorage;
|
|
@@ -20747,7 +20330,7 @@ function createAgentRunner(execute, options) {
|
|
|
20747
20330
|
} } : void 0
|
|
20748
20331
|
};
|
|
20749
20332
|
if (run.instruction.storedAttachments?.length) {
|
|
20750
|
-
const { loadInputImages } = await import("./images-
|
|
20333
|
+
const { loadInputImages } = await import("./images-BbSdVHC6.js").then((n) => n.n);
|
|
20751
20334
|
const storage = nextRun.environment?.attachmentStorage;
|
|
20752
20335
|
if (!storage) throw new Error("Attachment storage is unavailable.");
|
|
20753
20336
|
nextRun.instruction = {
|
|
@@ -20762,5 +20345,4 @@ function createAgentRunner(execute, options) {
|
|
|
20762
20345
|
return await execute(nextRun, streamFn);
|
|
20763
20346
|
} };
|
|
20764
20347
|
}
|
|
20765
|
-
|
|
20766
|
-
export { getAgentInvocation as $, resolveSlackChannelIdFromMessage as A, consumeSandboxEgressPermissionDeniedSignal as At, effectiveTaskOutcomes as B, withoutSavedSteeringMessages as Bt, renderBlockText as C, ingestEvent as Ct, storeAttachment as D, SANDBOX_EGRESS_PROXY_PATH as Dt, requestAttachmentDeletion as E, shouldPropagateSandboxEgressTrace as Et, logScheduledAutomationRunSkipped as F, parseOAuthStatePayload as Ft, recordSubagentStarted as G, readBlockedReport as Gt, stopChildAgentsOf as H, actorFromRun as Ht, scheduledAutomationRunAttributes as I, resolveBaseUrl as It, createAgentInvocation as J, setConfigDefaults as Jt, listChildAgents as K, shouldEmitDevAgentTrace as Kt, editEventAutomation as L, startOAuthFlow as Lt, getConversationInfo as M, sandboxEgressSignalsResponseSchema as Mt, listThreadReplies as N, deliverPrivateMessage as Nt, parseSlackThreadId as O, clearSandboxEgressSignals as Ot, editScheduledAutomation as P, formatProviderLabel as Pt, getActiveAgentInvocationForConversation as Q, AutomationEditError as R, createUserTokenStore as Rt, renderAttachmentText as S, processWorkspaceSnapshotJob as St, readLiveAttachment as T, normalizeSandboxEgressTracePropagationDomains as Tt, stopConversationSession as U, toolInvocationDestination as Ut, resolveTaskOutcomes as V, RetryableDeliveryError as Vt, recordSubagentEnded as W, AuthorizationFlowDisabledError as Wt, createAgentInvocationFromLatest as X, createAgentInvocationForMessage as Y, findChildAgentConversationId as Z, resolvePluginOAuthAccount as _, AgentMessageTargetError as _t, buildAuthPauseResponse as a, getAgentInvocationTurnId as at, unpublishedArtifactHeaders as b, conversationSubtreeColumns as bt, deleteMcpAuthSessionsForUserProvider as c, isTerminalAgentInvocation as ct, getMcpAuthSession as d, markAgentInvocationMailboxAppended as dt, getAgentInvocationIdForEvents as et, getMcpStoredOAuthCredentials as f, markAgentInvocationParentMailboxAppended as ft, readStats as g, reportReplacedAgentInvocation as gt, latestProgressStatus as h, markAgentInvocationSteered as ht, executeCredentialedEgressRequest as i, getAgentInvocationResultMessageId as it, resolveSlackChannelIdFromThreadId as j, parseSandboxEgressCredentialToken as jt, readSlackRawMessageContext as k, consumeSandboxEgressAuthRequiredSignal as kt, deleteMcpServerSessionId as l, listPendingAgentInvocationMailboxAppends as lt, PluginCredentialFailureError as m, markAgentInvocationRunning as mt, executeAgentRun as n, getAgentInvocationIdForResult as nt, finalizeMcpAuthorization as o, getChildAgentLabel as ot, putMcpStoredOAuthCredentials as p, markAgentInvocationPaused as pt, completeAgentInvocation as q, getConfigDefaults as qt, createContextCompactor as r, getAgentInvocationMessageId as rt, deleteMcpAuthSession as s, getLatestAgentInvocationForConversation as st, createAgentRunner as t, getAgentInvocationIdForMessage as tt, deleteMcpStoredOAuthCredentials as u, listPendingAgentInvocationResults as ut, publicArtifactHeaders as v, PARENT_AGENT_TARGET as vt, collectAttachmentGarbage as w, resolveSandboxEgressProviderForHost as wt, lookupSlackUserProfile as x, getMcpProviderErrorAttributes as xt, readPublicArtifact as y, conversationSubtree as yt, eventAutomationTriggerAvailable as z, buildSteeringPiMessage as zt };
|
|
20348
|
+
export { getAgentInvocation as $, resolveSlackChannelIdFromMessage as A, parseSandboxEgressCredentialToken as At, effectiveTaskOutcomes as B, actorFromRun as Bt, renderBlockText as C, resolveSandboxEgressProviderForHost as Ct, storeAttachment as D, clearSandboxEgressSignals as Dt, requestAttachmentDeletion as E, SANDBOX_EGRESS_PROXY_PATH as Et, logScheduledAutomationRunSkipped as F, startOAuthFlow as Ft, recordSubagentStarted as G, getConfigDefaults as Gt, stopChildAgentsOf as H, AuthorizationFlowDisabledError as Ht, scheduledAutomationRunAttributes as I, createUserTokenStore as It, createAgentInvocation as J, listChildAgents as K, setConfigDefaults as Kt, editEventAutomation as L, buildSteeringPiMessage as Lt, getConversationInfo as M, formatProviderLabel as Mt, listThreadReplies as N, parseOAuthStatePayload as Nt, parseSlackThreadId as O, consumeSandboxEgressAuthRequiredSignal as Ot, editScheduledAutomation as P, resolveBaseUrl as Pt, getActiveAgentInvocationForConversation as Q, AutomationEditError as R, withoutSavedSteeringMessages as Rt, renderAttachmentText as S, ingestEvent as St, readLiveAttachment as T, shouldPropagateSandboxEgressTrace as Tt, stopConversationSession as U, readBlockedReport as Ut, resolveTaskOutcomes as V, toolInvocationDestination as Vt, recordSubagentEnded as W, shouldEmitDevAgentTrace as Wt, createAgentInvocationFromLatest as X, createAgentInvocationForMessage as Y, findChildAgentConversationId as Z, resolvePluginOAuthAccount as _, AgentMessageTargetError as _t, buildAuthPauseResponse as a, getAgentInvocationTurnId as at, unpublishedArtifactHeaders as b, conversationSubtreeColumns as bt, deleteMcpAuthSessionsForUserProvider as c, isTerminalAgentInvocation as ct, getMcpAuthSession as d, markAgentInvocationMailboxAppended as dt, getAgentInvocationIdForEvents as et, getMcpStoredOAuthCredentials as f, markAgentInvocationParentMailboxAppended as ft, readStats as g, reportReplacedAgentInvocation as gt, latestProgressStatus as h, markAgentInvocationSteered as ht, executeCredentialedEgressRequest as i, getAgentInvocationResultMessageId as it, resolveSlackChannelIdFromThreadId as j, sandboxEgressSignalsResponseSchema as jt, readSlackRawMessageContext as k, consumeSandboxEgressPermissionDeniedSignal as kt, deleteMcpServerSessionId as l, listPendingAgentInvocationMailboxAppends as lt, PluginCredentialFailureError as m, markAgentInvocationRunning as mt, executeAgentRun as n, getAgentInvocationIdForResult as nt, finalizeMcpAuthorization as o, getChildAgentLabel as ot, putMcpStoredOAuthCredentials as p, markAgentInvocationPaused as pt, completeAgentInvocation as q, createContextCompactor as r, getAgentInvocationMessageId as rt, deleteMcpAuthSession as s, getLatestAgentInvocationForConversation as st, createAgentRunner as t, getAgentInvocationIdForMessage as tt, deleteMcpStoredOAuthCredentials as u, listPendingAgentInvocationResults as ut, publicArtifactHeaders as v, PARENT_AGENT_TARGET as vt, collectAttachmentGarbage as w, normalizeSandboxEgressTracePropagationDomains as wt, lookupSlackUserProfile as x, processWorkspaceSnapshotJob as xt, readPublicArtifact as y, conversationSubtree as yt, eventAutomationTriggerAvailable as z, RetryableDeliveryError as zt };
|