@xopcai/xopc 0.0.187 → 0.0.188
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/browser-ext/manifest.json +1 -1
- package/dist/extensions/demo-memory/src/index.js +1 -0
- package/dist/extensions/feishu/src/streaming/streaming-adapter.js +1 -3
- package/dist/extensions/telegram/src/adapters/streaming-adapter.js +0 -2
- package/dist/extensions/telegram/src/draft-stream.d.ts +0 -4
- package/dist/extensions/telegram/src/draft-stream.js +1 -53
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/gateway/static/root/assets/{activity-store-WlR2zEvA.js → activity-store--QoUGhiS.js} +1 -1
- package/dist/gateway/static/root/assets/{agent-avatar-dicebear-RedDszrG.js → agent-avatar-dicebear-B0yweLNQ.js} +1 -1
- package/dist/gateway/static/root/assets/{agents-Df9mTa-K.js → agents-C6OV-gMm.js} +1 -1
- package/dist/gateway/static/root/assets/{api-tVOllncq.js → api-5laWqfiE.js} +1 -1
- package/dist/gateway/static/root/assets/{app-management-settings-panel-C9hKBzaF.js → app-management-settings-panel-BXJ8Jiv_.js} +1 -1
- package/dist/gateway/static/root/assets/{appearance-settings-5cQvq7hd.js → appearance-settings-DG9n9D1M.js} +1 -1
- package/dist/gateway/static/root/assets/{apps-page-Bd3tN-k2.js → apps-page-Ci14lDeO.js} +1 -1
- package/dist/gateway/static/root/assets/{archive-plugin-Ct-shK4n.js → archive-plugin-Ceh5qrZf.js} +1 -1
- package/dist/gateway/static/root/assets/{attachment-load-CpPj3m-q.js → attachment-load-jFW7uYf7.js} +1 -1
- package/dist/gateway/static/root/assets/automations-page-Q1xmb4Rh.js +6 -0
- package/dist/gateway/static/root/assets/{binary-plugins-BpSXZBle.js → binary-plugins-XDlkI1r4.js} +1 -1
- package/dist/gateway/static/root/assets/{block-editor-B8hR2tXc.js → block-editor-kyKc2IhE.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-settings-page-jb5Hf-hm.js → browser-settings-page-DbowrHXD.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-workflow-inputs-D_LAXUrh.js → browser-workflow-inputs-BJa5Iz_v.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-workflows-page-CPAs7-6s.js → browser-workflows-page-CTQQOsn5.js} +1 -1
- package/dist/gateway/static/root/assets/{capabilities-settings-panel-BjUe4raq.js → capabilities-settings-panel-DoZPFdKF.js} +1 -1
- package/dist/gateway/static/root/assets/{capability-presets-api-CKklVY2p.js → capability-presets-api-Dn-7MMEo.js} +1 -1
- package/dist/gateway/static/root/assets/{capability-presets-settings-panel-DiWIMYRr.js → capability-presets-settings-panel-Bt8Hnx0h.js} +1 -1
- package/dist/gateway/static/root/assets/{channel-recipient-api-WWN-nbFL.js → channel-recipient-api-BgIkWq01.js} +1 -1
- package/dist/gateway/static/root/assets/{channels-settings-D8IkjMuX.js → channels-settings-Bpsebsru.js} +1 -1
- package/dist/gateway/static/root/assets/channels-status-swr-DFmdYRE5.js +1 -0
- package/dist/gateway/static/root/assets/{connector-logo-CdNkVFdB.js → connector-logo-TRr9ybf6.js} +1 -1
- package/dist/gateway/static/root/assets/{connectors-page-BT2ahw52.js → connectors-page-Tg5kl22i.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-Bm_IEAf3.js → desktop-pet-CSwd00CV.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-settings-C0Ve04-G.js → desktop-pet-settings-CuNQvHGu.js} +1 -1
- package/dist/gateway/static/root/assets/{directory-picker-path-field-B2cvhvAI.js → directory-picker-path-field-ct0n5Rje.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-debug-page-DNashgGu.js → extension-debug-page-BeRBuMUU.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-Bvo-5htX.js → extension-page-DbK-Cwao.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-BBESdISV.js → extension-settings-page-C9ag5tb5.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-config-api-ClQvokMo.js → gateway-config-api-CC7EvEFp.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-settings-CIRs2QVy.js → gateway-settings-9g8uIry9.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-startup-retry-CntXJF6W.js → gateway-startup-retry-B2DmdlwO.js} +1 -1
- package/dist/gateway/static/root/assets/{heartbeat-settings-CWKcZuvc.js → heartbeat-settings-fl1oC_-5.js} +1 -1
- package/dist/gateway/static/root/assets/{home-page-C59f8UJw.js → home-page-Bao9jq_z.js} +1 -1
- package/dist/gateway/static/root/assets/{image-generation-api-DjSAQwGy.js → image-generation-api-GMTaS6eI.js} +1 -1
- package/dist/gateway/static/root/assets/index-Cl5n1f_U.css +1 -0
- package/dist/gateway/static/root/assets/index-OJgiMh07.js +223 -0
- package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-ahKHpjoW.js → keyboard-shortcuts-settings-DhGYddbI.js} +1 -1
- package/dist/gateway/static/root/assets/{local-app-workbench-page-DRB4UQBE.js → local-app-workbench-page-B69NvtvH.js} +1 -1
- package/dist/gateway/static/root/assets/{local-apps-page-B6GKdgza.js → local-apps-page-CmnrBmWi.js} +1 -1
- package/dist/gateway/static/root/assets/{locale-store-Bff30u5V.js → locale-store-D6hs74o5.js} +1 -1
- package/dist/gateway/static/root/assets/{logs-page-CNp4XiBN.js → logs-page-Cq3cABqg.js} +1 -1
- package/dist/gateway/static/root/assets/{markdown-split-BeNMJm_i.js → markdown-split-CZaBPOVn.js} +1 -1
- package/dist/gateway/static/root/assets/{media-plugins-Bdzrj_-6.js → media-plugins-CiKvSgCv.js} +1 -1
- package/dist/gateway/static/root/assets/messages-D02NNLCZ.js +3 -0
- package/dist/gateway/static/root/assets/{notes-page-MYIi-9S9.js → notes-page-Bisbzqlz.js} +1 -1
- package/dist/gateway/static/root/assets/{notes-workbench-DqSkeDXX.js → notes-workbench-BOZfJFhE.js} +2 -2
- package/dist/gateway/static/root/assets/{page-tabs-3t88bbGx.js → page-tabs-BxlwhAbH.js} +1 -1
- package/dist/gateway/static/root/assets/{preview-open-alternatives-Cf_BWbeE.js → preview-open-alternatives-RM8wXxfT.js} +1 -1
- package/dist/gateway/static/root/assets/{product-open-page-CKq73c98.js → product-open-page-DdBlibek.js} +1 -1
- package/dist/gateway/static/root/assets/{project-detail-page-BrbHs4Wp.js → project-detail-page-TSKFb2tN.js} +1 -1
- package/dist/gateway/static/root/assets/{projects-page-B80rtkj6.js → projects-page-BokeBrTT.js} +1 -1
- package/dist/gateway/static/root/assets/{remote-access-hub-_Q3GEznb.js → remote-access-hub-C56anxCX.js} +1 -1
- package/dist/gateway/static/root/assets/{schema-form-NqOm-OG1.js → schema-form-BDKbpmXv.js} +1 -1
- package/dist/gateway/static/root/assets/{sessions-page-55dJOUVg.js → sessions-page-C7TQADrD.js} +1 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-BDOPKeAX.js +1 -0
- package/dist/gateway/static/root/assets/{settings-form-section-DYAS8p8z.js → settings-form-section-zxo5ZGOu.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-loading-skeleton-DZFhxihA.js → settings-loading-skeleton-DgIp8_S6.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-page-BSIiMLi-.js → settings-page-BUPSIa9P.js} +1 -1
- package/dist/gateway/static/root/assets/{settings-page-layout-DfFfkdED.js → settings-page-layout-97LmwrzC.js} +1 -1
- package/dist/gateway/static/root/assets/{setup-status-panel-q_yE6-H1.js → setup-status-panel-BRg766eW.js} +1 -1
- package/dist/gateway/static/root/assets/{share-preview-page-CYtrQaZN.js → share-preview-page-BH7i3g1S.js} +1 -1
- package/dist/gateway/static/root/assets/{shares-settings-gYkRX9Ik.js → shares-settings-DhEAviQ_.js} +1 -1
- package/dist/gateway/static/root/assets/skill-reload-api-Ct7AV8ls.js +1 -0
- package/dist/gateway/static/root/assets/{skills-page-GZHKDFSb.js → skills-page-DoVuprZm.js} +1 -1
- package/dist/gateway/static/root/assets/{skills-page.utils-BBXirAjc.js → skills-page.utils-s-a5WV9j.js} +1 -1
- package/dist/gateway/static/root/assets/{system-settings-panel-DLf5YvFl.js → system-settings-panel-BxjeMT5k.js} +1 -1
- package/dist/gateway/static/root/assets/{task-detail-page-DFGkuYfl.js → task-detail-page-BahycnfW.js} +1 -1
- package/dist/gateway/static/root/assets/{theme-store-y7e_tvYi.js → theme-store-BRxdsmic.js} +1 -1
- package/dist/gateway/static/root/assets/{time-picker-5sHEZ5w5.js → time-picker-BGk_Tbsj.js} +1 -1
- package/dist/gateway/static/root/assets/{typed-models-lib-DR12j_dr.js → typed-models-lib-39MjwPSq.js} +1 -1
- package/dist/gateway/static/root/assets/{use-save-bar-registration-BsvcJgZl.js → use-save-bar-registration-5aVSjTjO.js} +1 -1
- package/dist/gateway/static/root/assets/{user-context-page-q5dr8JFG.js → user-context-page-B9K41qmy.js} +1 -1
- package/dist/gateway/static/root/assets/{voice-api-key-field-DKADXFWD.js → voice-api-key-field-XU-7sBSg.js} +1 -1
- package/dist/gateway/static/root/assets/{work-discovery-overlay-BC1nExf8.js → work-discovery-overlay-CJqu8UHq.js} +1 -1
- package/dist/gateway/static/root/assets/{work-discovery-page-fNvSg40M.js → work-discovery-page-BBVnRHju.js} +1 -1
- package/dist/gateway/static/root/assets/{workflow-run-setup-panel-C8X5W-8k.js → workflow-run-setup-panel-DXtg8Qxl.js} +1 -1
- package/dist/gateway/static/root/assets/{workflows-page-YJBKmPYK.js → workflows-page-Bs_tYfst.js} +1 -1
- package/dist/gateway/static/root/index.html +7 -7
- package/dist/package.js +1 -1
- package/dist/packages/gateway-contract/src/tool-activity.js +223 -0
- package/dist/src/agent/agent-manager.js +2 -8
- package/dist/src/agent/code-intelligence/binary.js +1 -1
- package/dist/src/agent/embedded/run-for-session.d.ts +0 -2
- package/dist/src/agent/embedded/run-for-session.js +99 -112
- package/dist/src/agent/external-tools/composio-provider.d.ts +29 -0
- package/dist/src/agent/external-tools/composio-provider.js +307 -0
- package/dist/src/agent/external-tools/extension-provider.d.ts +20 -0
- package/dist/src/agent/external-tools/extension-provider.js +68 -0
- package/dist/src/agent/external-tools/gateway-tools.d.ts +8 -0
- package/dist/src/agent/external-tools/gateway-tools.js +89 -0
- package/dist/src/agent/external-tools/index.d.ts +24 -0
- package/dist/src/agent/external-tools/index.js +40 -0
- package/dist/src/agent/external-tools/mcp-provider.d.ts +29 -0
- package/dist/src/agent/external-tools/mcp-provider.js +118 -0
- package/dist/src/agent/external-tools/memory-provider.d.ts +21 -0
- package/dist/src/agent/external-tools/memory-provider.js +56 -0
- package/dist/src/agent/external-tools/refs.d.ts +5 -0
- package/dist/src/agent/external-tools/refs.js +18 -0
- package/dist/src/agent/external-tools/service.d.ts +26 -0
- package/dist/src/agent/external-tools/service.js +117 -0
- package/dist/src/agent/external-tools/types.d.ts +28 -0
- package/dist/src/agent/external-tools/types.js +9 -0
- package/dist/src/agent/inbound/inbound-loop.d.ts +0 -2
- package/dist/src/agent/inbound/inbound-loop.js +0 -3
- package/dist/src/agent/mcp/{bundle-mcp-materialize.d.ts → bundle-mcp-gateway.d.ts} +1 -19
- package/dist/src/agent/mcp/bundle-mcp-gateway.js +60 -0
- package/dist/src/agent/mcp/bundle-mcp-names.d.ts +0 -8
- package/dist/src/agent/mcp/bundle-mcp-names.js +2 -29
- package/dist/src/agent/mcp/bundle-mcp-policy.d.ts +4 -7
- package/dist/src/agent/mcp/bundle-mcp-policy.js +6 -20
- package/dist/src/agent/mcp/bundle-mcp-runtime.js +2 -2
- package/dist/src/agent/mcp/bundle-mcp-tools.d.ts +1 -2
- package/dist/src/agent/mcp/bundle-mcp-tools.js +1 -2
- package/dist/src/agent/mcp/bundle-mcp-types.d.ts +0 -5
- package/dist/src/agent/mcp/index.d.ts +0 -2
- package/dist/src/agent/mcp/index.js +2 -5
- package/dist/src/agent/mcp/mcp-stdio-transport.js +1 -1
- package/dist/src/agent/mcp/mcp-transport.js +1 -1
- package/dist/src/agent/memory/context/planner.d.ts +1 -0
- package/dist/src/agent/memory/context/planner.js +22 -7
- package/dist/src/agent/memory/manager.d.ts +4 -1
- package/dist/src/agent/memory/manager.js +5 -2
- package/dist/src/agent/memory/types.d.ts +2 -0
- package/dist/src/agent/messaging/stream-manager.d.ts +2 -14
- package/dist/src/agent/messaging/stream-manager.js +0 -12
- package/dist/src/agent/orchestration/agent-event-handler.d.ts +1 -3
- package/dist/src/agent/orchestration/agent-event-handler.js +0 -36
- package/dist/src/agent/orchestration/agent-orchestrator.d.ts +0 -5
- package/dist/src/agent/orchestration/agent-orchestrator.js +0 -5
- package/dist/src/agent/prompt/sections/behavior.js +6 -4
- package/dist/src/agent/service.d.ts +0 -3
- package/dist/src/agent/service.js +0 -28
- package/dist/src/agent/service.types.d.ts +0 -3
- package/dist/src/agent/skills/hub-pull.js +1 -1
- package/dist/src/agent/starter-agents.js +2 -2
- package/dist/src/agent/tools/delegate-tool.js +5 -1
- package/dist/src/agent/tools/executor.js +1 -1
- package/dist/src/agent/tools/factory.d.ts +2 -1
- package/dist/src/agent/tools/factory.js +16 -22
- package/dist/src/agent/tools/index.d.ts +0 -1
- package/dist/src/agent/tools/index.js +1 -2
- package/dist/src/agent/workflow/workflow-child-tools.js +7 -1
- package/dist/src/browser/providers/cloakbrowser.js +1 -1
- package/dist/src/channels/channel-domain.d.ts +0 -4
- package/dist/src/channels/plugin-types.d.ts +0 -2
- package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
- package/dist/src/cli/commands/extension-marketplace.js +1 -1
- package/dist/src/connectors/health.js +1 -1
- package/dist/src/extensions/extension-registry-impl.d.ts +3 -1
- package/dist/src/extensions/extension-registry-impl.js +7 -1
- package/dist/src/extensions/loader.js +1 -1
- package/dist/src/extensions/types/core.d.ts +2 -1
- package/dist/src/extensions/update.js +1 -1
- package/dist/src/gateway/agent-builtin-tools.d.ts +1 -1
- package/dist/src/gateway/agent-builtin-tools.js +5 -2
- package/dist/src/gateway/chat-stream/mapper.js +16 -1
- package/dist/src/gateway/chat-stream/protocol.d.ts +4 -0
- package/dist/src/gateway/file-reference-errors.d.ts +6 -0
- package/dist/src/gateway/file-reference-errors.js +21 -0
- package/dist/src/gateway/heartbeat/service.js +1 -1
- package/dist/src/gateway/hono/lib/config-payload.js +1 -1
- package/dist/src/gateway/hono/routes/auth-registry-extensions.js +1 -1
- package/dist/src/gateway/hono/routes/config-patch/misc.js +1 -1
- package/dist/src/gateway/hono/routes/mcp.js +1 -1
- package/dist/src/gateway/hono/routes/projects.js +34 -13
- package/dist/src/gateway/hono/routes/workflows.js +1 -1
- package/dist/src/gateway/hono/routes/workspace.js +34 -13
- package/dist/src/gateway/hono/routes/you.js +3 -3
- package/dist/src/gateway/service/config-coordinator.js +1 -1
- package/dist/src/gateway/service/run-gateway-agent.js +4 -1
- package/dist/src/gateway/service.js +6 -6
- package/dist/src/heartbeat/index.js +1 -1
- package/dist/src/infra/update-runner.js +1 -1
- package/dist/src/share/share-zip.js +1 -1
- package/dist/src/storage/sqlite/memory-records-repository.js +3 -1
- package/dist/src/storage/sqlite/migrations/108_repair_user_memory_provider.sql +18 -0
- package/dist/src/storage/sqlite/migrations/runner.d.ts +1 -1
- package/dist/src/storage/sqlite/migrations/runner.js +3 -3
- package/dist/src/storage/sqlite/migrations/runner.ts +1 -1
- package/dist/src/storage/sqlite/schema.js +1 -1
- package/dist/src/tui/tool-summary.d.ts +1 -2
- package/dist/src/tui/tool-summary.js +2 -18
- package/dist/src/tunnel/frpc-binary.js +1 -1
- package/dist/src/user-context/projection.d.ts +1 -0
- package/dist/src/user-context/projection.js +2 -1
- package/dist/src/voice/local/model-files.js +1 -1
- package/dist/src/work-discovery/service.js +1 -1
- package/package.json +1 -1
- package/dist/gateway/static/root/assets/automations-page-w6K9GZQ7.js +0 -6
- package/dist/gateway/static/root/assets/channels-status-swr-CySs1GQX.js +0 -1
- package/dist/gateway/static/root/assets/index-D-YfWVyS.css +0 -1
- package/dist/gateway/static/root/assets/index-vi5KlR5_.js +0 -222
- package/dist/gateway/static/root/assets/messages-CPxz48hr.js +0 -3
- package/dist/gateway/static/root/assets/settings-advanced-gate-CSFCZj14.js +0 -1
- package/dist/gateway/static/root/assets/skill-reload-api-BoNBMKW6.js +0 -1
- package/dist/src/agent/feedback/feedback-coordinator.d.ts +0 -73
- package/dist/src/agent/feedback/feedback-coordinator.js +0 -156
- package/dist/src/agent/feedback/index.d.ts +0 -4
- package/dist/src/agent/feedback/index.js +0 -2
- package/dist/src/agent/lifecycle/progress.d.ts +0 -90
- package/dist/src/agent/lifecycle/progress.js +0 -339
- package/dist/src/agent/mcp/bundle-mcp-materialize.js +0 -183
- package/dist/src/agent/mcp/mcp-tool-meta.d.ts +0 -8
- package/dist/src/agent/mcp/mcp-tool-meta.js +0 -13
- package/dist/src/agent/mcp/resolve-embedded-mcp-tools.d.ts +0 -14
- package/dist/src/agent/mcp/resolve-embedded-mcp-tools.js +0 -48
- package/dist/src/agent/tools/composio-tool.d.ts +0 -21
- package/dist/src/agent/tools/composio-tool.js +0 -261
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import { createLogger } from "../../utils/logger/index.js";
|
|
2
|
-
import { init_logger } from "../../utils/logger.js";
|
|
3
|
-
import { init_string_coerce, normalizeLowercaseStringOrEmpty, normalizeOptionalString } from "../../utils/string-coerce.js";
|
|
4
|
-
import { buildSafeToolName, normalizeReservedToolNames } from "./bundle-mcp-names.js";
|
|
5
|
-
import { setPluginToolMeta } from "./mcp-tool-meta.js";
|
|
6
|
-
import crypto from "node:crypto";
|
|
7
|
-
//#region src/agent/mcp/bundle-mcp-materialize.ts
|
|
8
|
-
init_logger();
|
|
9
|
-
init_string_coerce();
|
|
10
|
-
const log = createLogger("Mcp:Bundle");
|
|
11
|
-
function readMaterializedToolDescription(tool) {
|
|
12
|
-
const raw = tool;
|
|
13
|
-
return normalizeOptionalString(raw.description) ?? normalizeOptionalString(raw.label) ?? tool.name;
|
|
14
|
-
}
|
|
15
|
-
function mapBundleMcpToolsForGateway(tools, serverId) {
|
|
16
|
-
const prefix = `${serverId.trim()}__`;
|
|
17
|
-
return tools.filter((tool) => tool.name.startsWith(prefix)).map((tool) => ({
|
|
18
|
-
name: tool.name,
|
|
19
|
-
shortName: tool.name.slice(prefix.length),
|
|
20
|
-
description: readMaterializedToolDescription(tool)
|
|
21
|
-
}));
|
|
22
|
-
}
|
|
23
|
-
async function listBundleMcpServerToolsForGateway(params) {
|
|
24
|
-
const runtime = await createBundleMcpToolRuntime({
|
|
25
|
-
workspaceDir: params.workspaceDir,
|
|
26
|
-
cfg: params.cfg
|
|
27
|
-
});
|
|
28
|
-
try {
|
|
29
|
-
return mapBundleMcpToolsForGateway(runtime.tools, params.serverId);
|
|
30
|
-
} finally {
|
|
31
|
-
await runtime.dispose();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function mapBundleMcpResourcesForGateway(resources, serverId) {
|
|
35
|
-
return resources.filter((resource) => resource.serverName === serverId).map((resource) => ({
|
|
36
|
-
uri: resource.uri,
|
|
37
|
-
name: resource.name,
|
|
38
|
-
title: resource.title,
|
|
39
|
-
description: resource.description,
|
|
40
|
-
mimeType: resource.mimeType
|
|
41
|
-
}));
|
|
42
|
-
}
|
|
43
|
-
function mapBundleMcpPromptsForGateway(prompts, serverId) {
|
|
44
|
-
return prompts.filter((prompt) => prompt.serverName === serverId).map((prompt) => ({
|
|
45
|
-
name: prompt.name,
|
|
46
|
-
title: prompt.title,
|
|
47
|
-
description: prompt.description,
|
|
48
|
-
argumentCount: prompt.argumentCount
|
|
49
|
-
}));
|
|
50
|
-
}
|
|
51
|
-
async function listBundleMcpServerCapabilitiesForGateway(params) {
|
|
52
|
-
const createRuntime = (await import("./bundle-mcp-runtime.js")).createSessionMcpRuntime;
|
|
53
|
-
const runtime = createRuntime({
|
|
54
|
-
sessionId: `bundle-mcp:${crypto.randomUUID()}`,
|
|
55
|
-
workspaceDir: params.workspaceDir,
|
|
56
|
-
cfg: params.cfg
|
|
57
|
-
});
|
|
58
|
-
try {
|
|
59
|
-
const catalog = await runtime.getCatalog();
|
|
60
|
-
const tools = mapBundleMcpToolsForGateway(await materializeBundleMcpToolsForRun({ runtime }).then(async (toolRuntime) => {
|
|
61
|
-
try {
|
|
62
|
-
return toolRuntime.tools;
|
|
63
|
-
} finally {
|
|
64
|
-
await toolRuntime.dispose();
|
|
65
|
-
}
|
|
66
|
-
}), params.serverId);
|
|
67
|
-
const resources = mapBundleMcpResourcesForGateway(catalog.resources, params.serverId);
|
|
68
|
-
const prompts = mapBundleMcpPromptsForGateway(catalog.prompts, params.serverId);
|
|
69
|
-
return {
|
|
70
|
-
serverId: params.serverId,
|
|
71
|
-
toolCount: tools.length,
|
|
72
|
-
resourceCount: resources.length,
|
|
73
|
-
promptCount: prompts.length,
|
|
74
|
-
tools,
|
|
75
|
-
resources,
|
|
76
|
-
prompts
|
|
77
|
-
};
|
|
78
|
-
} finally {
|
|
79
|
-
await runtime.dispose();
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
function toAgentToolResult(params) {
|
|
83
|
-
const content = Array.isArray(params.result.content) ? params.result.content : [];
|
|
84
|
-
const normalizedContent = content.length > 0 ? content : params.result.structuredContent !== void 0 ? [{
|
|
85
|
-
type: "text",
|
|
86
|
-
text: JSON.stringify(params.result.structuredContent, null, 2)
|
|
87
|
-
}] : [{
|
|
88
|
-
type: "text",
|
|
89
|
-
text: JSON.stringify({
|
|
90
|
-
status: params.result.isError === true ? "error" : "ok",
|
|
91
|
-
server: params.serverName,
|
|
92
|
-
tool: params.toolName
|
|
93
|
-
}, null, 2)
|
|
94
|
-
}];
|
|
95
|
-
const details = {
|
|
96
|
-
mcpServer: params.serverName,
|
|
97
|
-
mcpTool: params.toolName
|
|
98
|
-
};
|
|
99
|
-
if (params.result.structuredContent !== void 0) details.structuredContent = params.result.structuredContent;
|
|
100
|
-
if (params.result.isError === true) details.status = "error";
|
|
101
|
-
return {
|
|
102
|
-
content: normalizedContent,
|
|
103
|
-
details
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
async function materializeBundleMcpToolsForRun(params) {
|
|
107
|
-
let disposed = false;
|
|
108
|
-
const releaseLease = params.runtime.acquireLease?.();
|
|
109
|
-
params.runtime.markUsed();
|
|
110
|
-
let catalog;
|
|
111
|
-
try {
|
|
112
|
-
catalog = await params.runtime.getCatalog();
|
|
113
|
-
} catch (error) {
|
|
114
|
-
releaseLease?.();
|
|
115
|
-
throw error;
|
|
116
|
-
}
|
|
117
|
-
const reservedNames = normalizeReservedToolNames(params.reservedToolNames);
|
|
118
|
-
const tools = [];
|
|
119
|
-
const sortedCatalogTools = [...catalog.tools].toSorted((a, b) => {
|
|
120
|
-
const serverOrder = a.safeServerName.localeCompare(b.safeServerName);
|
|
121
|
-
if (serverOrder !== 0) return serverOrder;
|
|
122
|
-
const toolOrder = a.toolName.localeCompare(b.toolName);
|
|
123
|
-
if (toolOrder !== 0) return toolOrder;
|
|
124
|
-
return a.serverName.localeCompare(b.serverName);
|
|
125
|
-
});
|
|
126
|
-
for (const tool of sortedCatalogTools) {
|
|
127
|
-
const originalName = tool.toolName.trim();
|
|
128
|
-
if (!originalName) continue;
|
|
129
|
-
const safeToolName = buildSafeToolName({
|
|
130
|
-
serverName: tool.safeServerName,
|
|
131
|
-
toolName: originalName,
|
|
132
|
-
reservedNames
|
|
133
|
-
});
|
|
134
|
-
if (safeToolName !== `${tool.safeServerName}__${originalName}`) log.warn(`bundle-mcp: tool "${tool.toolName}" from server "${tool.serverName}" registered as "${safeToolName}" to keep the tool name provider-safe.`);
|
|
135
|
-
reservedNames.add(normalizeLowercaseStringOrEmpty(safeToolName));
|
|
136
|
-
const agentTool = {
|
|
137
|
-
name: safeToolName,
|
|
138
|
-
label: tool.title ?? tool.toolName,
|
|
139
|
-
description: tool.description || tool.title || tool.fallbackDescription,
|
|
140
|
-
parameters: tool.inputSchema,
|
|
141
|
-
execute: async (_toolCallId, input, signal) => {
|
|
142
|
-
params.runtime.markUsed();
|
|
143
|
-
const result = await params.runtime.callTool(tool.serverName, tool.toolName, input, signal);
|
|
144
|
-
return toAgentToolResult({
|
|
145
|
-
serverName: tool.serverName,
|
|
146
|
-
toolName: tool.toolName,
|
|
147
|
-
result
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
setPluginToolMeta(agentTool, {
|
|
152
|
-
pluginId: "bundle-mcp",
|
|
153
|
-
optional: false
|
|
154
|
-
});
|
|
155
|
-
tools.push(agentTool);
|
|
156
|
-
}
|
|
157
|
-
tools.sort((a, b) => a.name.localeCompare(b.name));
|
|
158
|
-
return {
|
|
159
|
-
tools,
|
|
160
|
-
dispose: async () => {
|
|
161
|
-
if (disposed) return;
|
|
162
|
-
disposed = true;
|
|
163
|
-
releaseLease?.();
|
|
164
|
-
await params.disposeRuntime?.();
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
async function createBundleMcpToolRuntime(params) {
|
|
169
|
-
const runtime = (params.createRuntime ?? (await import("./bundle-mcp-runtime.js")).createSessionMcpRuntime)({
|
|
170
|
-
sessionId: `bundle-mcp:${crypto.randomUUID()}`,
|
|
171
|
-
workspaceDir: params.workspaceDir,
|
|
172
|
-
cfg: params.cfg
|
|
173
|
-
});
|
|
174
|
-
return await materializeBundleMcpToolsForRun({
|
|
175
|
-
runtime,
|
|
176
|
-
reservedToolNames: params.reservedToolNames,
|
|
177
|
-
disposeRuntime: async () => {
|
|
178
|
-
await runtime.dispose();
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
//#endregion
|
|
183
|
-
export { createBundleMcpToolRuntime, listBundleMcpServerCapabilitiesForGateway, listBundleMcpServerToolsForGateway, mapBundleMcpToolsForGateway, materializeBundleMcpToolsForRun };
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { AgentTool } from '@earendil-works/pi-agent-core';
|
|
2
|
-
export type McpToolMeta = {
|
|
3
|
-
pluginId: string;
|
|
4
|
-
optional?: boolean;
|
|
5
|
-
};
|
|
6
|
-
export declare function setPluginToolMeta(tool: AgentTool, meta: McpToolMeta): void;
|
|
7
|
-
export declare function getPluginToolMeta(tool: AgentTool): McpToolMeta | undefined;
|
|
8
|
-
export declare function isBundleMcpTool(tool: AgentTool): boolean;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
//#region src/agent/mcp/mcp-tool-meta.ts
|
|
2
|
-
const MCP_TOOL_META = Symbol.for("xopc.mcpToolMeta");
|
|
3
|
-
function setPluginToolMeta(tool, meta) {
|
|
4
|
-
tool[MCP_TOOL_META] = meta;
|
|
5
|
-
}
|
|
6
|
-
function getPluginToolMeta(tool) {
|
|
7
|
-
return tool[MCP_TOOL_META];
|
|
8
|
-
}
|
|
9
|
-
function isBundleMcpTool(tool) {
|
|
10
|
-
return getPluginToolMeta(tool)?.pluginId === "bundle-mcp";
|
|
11
|
-
}
|
|
12
|
-
//#endregion
|
|
13
|
-
export { getPluginToolMeta, isBundleMcpTool, setPluginToolMeta };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { AgentTool } from '@earendil-works/pi-agent-core';
|
|
2
|
-
import type { Config } from '../../config/schema.js';
|
|
3
|
-
export type ResolvedEmbeddedMcpTools = {
|
|
4
|
-
tools: AgentTool[];
|
|
5
|
-
dispose: () => Promise<void>;
|
|
6
|
-
};
|
|
7
|
-
export declare function resolveEmbeddedMcpToolsForTurn(params: {
|
|
8
|
-
sessionKey: string;
|
|
9
|
-
workspaceDir: string;
|
|
10
|
-
cfg?: Config;
|
|
11
|
-
baseTools: AgentTool[];
|
|
12
|
-
cleanupOnTurnEnd?: boolean;
|
|
13
|
-
}): Promise<ResolvedEmbeddedMcpTools>;
|
|
14
|
-
export declare function mergeTurnTools(baseTools: AgentTool[], mcpTools: AgentTool[]): AgentTool[];
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { resolveEffectiveAgentProfileForSession } from "../../config/agent-profile.js";
|
|
2
|
-
import { isMcpToolDenied, shouldCreateBundleMcpRuntimeForAttempt } from "./bundle-mcp-policy.js";
|
|
3
|
-
import { getOrCreateSessionMcpRuntime } from "./bundle-mcp-runtime.js";
|
|
4
|
-
import { materializeBundleMcpToolsForRun } from "./bundle-mcp-materialize.js";
|
|
5
|
-
import "./bundle-mcp-tools.js";
|
|
6
|
-
//#region src/agent/mcp/resolve-embedded-mcp-tools.ts
|
|
7
|
-
async function resolveEmbeddedMcpToolsForTurn(params) {
|
|
8
|
-
const profile = params.cfg ? resolveEffectiveAgentProfileForSession(params.cfg, params.sessionKey) : void 0;
|
|
9
|
-
const disabledTools = profile?.tools.denied;
|
|
10
|
-
if (!shouldCreateBundleMcpRuntimeForAttempt(params.cfg)) return {
|
|
11
|
-
tools: [],
|
|
12
|
-
dispose: async () => {}
|
|
13
|
-
};
|
|
14
|
-
const reserved = new Set(params.baseTools.map((t) => t.name));
|
|
15
|
-
const runtime = await getOrCreateSessionMcpRuntime({
|
|
16
|
-
sessionId: params.sessionKey,
|
|
17
|
-
sessionKey: params.sessionKey,
|
|
18
|
-
workspaceDir: params.workspaceDir,
|
|
19
|
-
cfg: params.cfg
|
|
20
|
-
});
|
|
21
|
-
let materialized;
|
|
22
|
-
try {
|
|
23
|
-
materialized = await materializeBundleMcpToolsForRun({
|
|
24
|
-
runtime,
|
|
25
|
-
reservedToolNames: reserved,
|
|
26
|
-
disposeRuntime: params.cleanupOnTurnEnd ? async () => {
|
|
27
|
-
await runtime.dispose();
|
|
28
|
-
} : void 0
|
|
29
|
-
});
|
|
30
|
-
} catch (error) {
|
|
31
|
-
await runtime.dispose().catch(() => {});
|
|
32
|
-
throw error;
|
|
33
|
-
}
|
|
34
|
-
return {
|
|
35
|
-
tools: materialized.tools.filter((tool) => {
|
|
36
|
-
if (disabledTools?.has(tool.name)) return false;
|
|
37
|
-
if (isMcpToolDenied(tool.name, profile?.manifest.tools.mcp)) return false;
|
|
38
|
-
return true;
|
|
39
|
-
}),
|
|
40
|
-
dispose: materialized.dispose
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
function mergeTurnTools(baseTools, mcpTools) {
|
|
44
|
-
if (mcpTools.length === 0) return baseTools;
|
|
45
|
-
return [...baseTools, ...mcpTools];
|
|
46
|
-
}
|
|
47
|
-
//#endregion
|
|
48
|
-
export { mergeTurnTools, resolveEmbeddedMcpToolsForTurn };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { AgentTool } from '@earendil-works/pi-agent-core';
|
|
2
|
-
import type { Config } from '../../config/schema.js';
|
|
3
|
-
import { ComposioSessionsAdapter } from '../../connectors/composio-sessions.js';
|
|
4
|
-
type CurrentContext = {
|
|
5
|
-
channel: string;
|
|
6
|
-
chatId: string;
|
|
7
|
-
sessionKey: string;
|
|
8
|
-
} | null;
|
|
9
|
-
export type ComposioToolDeps = {
|
|
10
|
-
getConfig: () => Config | undefined;
|
|
11
|
-
getCurrentContext: () => CurrentContext;
|
|
12
|
-
agentId?: string;
|
|
13
|
-
adapter?: ComposioSessionsAdapter;
|
|
14
|
-
};
|
|
15
|
-
export declare function connectorPrincipalForSession(sessionKey: string | undefined): {
|
|
16
|
-
principalId: string;
|
|
17
|
-
agentId?: string;
|
|
18
|
-
isLocalOwner: boolean;
|
|
19
|
-
};
|
|
20
|
-
export declare function createComposioTools(deps: ComposioToolDeps): AgentTool[];
|
|
21
|
-
export {};
|
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
import { consumeConnectorApproval, createConnectorApproval, getConnectorApproval, getConnectorInstallation, listConnectorActionMetadata, listConnectorConnections, listConnectorInstallations, upsertConnectorActionMetadata, upsertConnectorInstallation } from "../../storage/sqlite/connector-repository.js";
|
|
2
|
-
import "../../storage/sqlite/index.js";
|
|
3
|
-
import { init_session_key, parseSessionKey } from "../../routing/session-key.js";
|
|
4
|
-
import { connectorArgumentsHash, connectorArgumentsPreview } from "../../connectors/approval.js";
|
|
5
|
-
import { ComposioSessionsAdapter } from "../../connectors/composio-sessions.js";
|
|
6
|
-
import { getComposioToolkitScope, isComposioActionAllowedByCatalog, scopeForComposioAction } from "../../connectors/composio.js";
|
|
7
|
-
import { getConnectorDefinition } from "../../connectors/catalog.js";
|
|
8
|
-
import { Type } from "@sinclair/typebox";
|
|
9
|
-
//#region src/agent/tools/composio-tool.ts
|
|
10
|
-
init_session_key();
|
|
11
|
-
const ComposioSearchSchema = Type.Object({
|
|
12
|
-
query: Type.String({ description: "Describe the task or information you need from connected apps." }),
|
|
13
|
-
toolkits: Type.Optional(Type.Array(Type.String(), {
|
|
14
|
-
maxItems: 8,
|
|
15
|
-
description: "Optional installed app slugs to search."
|
|
16
|
-
}))
|
|
17
|
-
});
|
|
18
|
-
const ComposioConnectSchema = Type.Object({
|
|
19
|
-
toolkit: Type.String({ description: "Installed Composio app slug, for example gmail or notion." }),
|
|
20
|
-
alias: Type.Optional(Type.String({ description: "Optional account label such as Personal or Work." }))
|
|
21
|
-
});
|
|
22
|
-
const ComposioExecuteSchema = Type.Object({
|
|
23
|
-
actionId: Type.String({ description: "Exact action slug returned by composio_search." }),
|
|
24
|
-
arguments: Type.Optional(Type.Record(Type.String(), Type.Unknown(), { description: "Arguments matching the exact contract returned by composio_search." })),
|
|
25
|
-
connectionId: Type.Optional(Type.String({ description: "Local connection id when more than one account is connected." })),
|
|
26
|
-
approvalId: Type.Optional(Type.String({ description: "Approval id after the user explicitly approves a pending write/admin action." }))
|
|
27
|
-
});
|
|
28
|
-
function textResult(value) {
|
|
29
|
-
return {
|
|
30
|
-
content: [{
|
|
31
|
-
type: "text",
|
|
32
|
-
text: typeof value === "string" ? value : JSON.stringify(value, null, 2)
|
|
33
|
-
}],
|
|
34
|
-
details: {}
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
function connectorPrincipalForSession(sessionKey) {
|
|
38
|
-
const parsed = parseSessionKey(sessionKey);
|
|
39
|
-
if (!parsed || parsed.source === "cli" || parsed.source === "webchat") return {
|
|
40
|
-
principalId: "local-owner",
|
|
41
|
-
agentId: parsed?.agentId,
|
|
42
|
-
isLocalOwner: true
|
|
43
|
-
};
|
|
44
|
-
return {
|
|
45
|
-
principalId: `channel:${parsed.source}:${parsed.accountId}:${parsed.peerKind}:${parsed.peerId}`,
|
|
46
|
-
agentId: parsed.agentId,
|
|
47
|
-
isLocalOwner: false
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
function installedConfigToolkits(config) {
|
|
51
|
-
return Object.entries(config?.connectors?.instances ?? {}).flatMap(([_instanceId, record]) => {
|
|
52
|
-
if (!record || typeof record !== "object" || Array.isArray(record)) return [];
|
|
53
|
-
const row = record;
|
|
54
|
-
const marker = row.xopcConnector;
|
|
55
|
-
if (marker && typeof marker === "object" && !Array.isArray(marker) && marker.enabled === false) return [];
|
|
56
|
-
const connectorId = marker && typeof marker === "object" && !Array.isArray(marker) ? marker.connectorId : void 0;
|
|
57
|
-
const runtime = row.runtime;
|
|
58
|
-
if (typeof connectorId !== "string" || !runtime || typeof runtime !== "object" || Array.isArray(runtime) || runtime.type !== "composio" || runtime.role !== "toolkit" || typeof runtime.toolkit !== "string") return [];
|
|
59
|
-
return [{
|
|
60
|
-
connectorId,
|
|
61
|
-
toolkit: runtime.toolkit
|
|
62
|
-
}];
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
function syncLocalOwnerInstallations(config) {
|
|
66
|
-
for (const { connectorId, toolkit } of installedConfigToolkits(config)) {
|
|
67
|
-
const id = `${connectorId}-local-owner`;
|
|
68
|
-
const existing = getConnectorInstallation(id);
|
|
69
|
-
upsertConnectorInstallation({
|
|
70
|
-
id,
|
|
71
|
-
connectorId,
|
|
72
|
-
principalId: "local-owner",
|
|
73
|
-
enabled: true,
|
|
74
|
-
allowedAgentIds: existing?.allowedAgentIds ?? [],
|
|
75
|
-
maxScope: getComposioToolkitScope(config, toolkit),
|
|
76
|
-
confirmationPolicy: existing?.confirmationPolicy ?? "writes",
|
|
77
|
-
selectedConnectionIds: existing?.selectedConnectionIds ?? [],
|
|
78
|
-
createdAt: existing?.createdAt
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
function availableInstallations(deps) {
|
|
83
|
-
const context = deps.getCurrentContext();
|
|
84
|
-
const principal = connectorPrincipalForSession(context?.sessionKey);
|
|
85
|
-
if (principal.isLocalOwner) syncLocalOwnerInstallations(deps.getConfig());
|
|
86
|
-
const agentId = deps.agentId ?? principal.agentId;
|
|
87
|
-
const installations = listConnectorInstallations(principal.principalId).filter((installation) => installation.enabled && composioToolkitFromConnectorId(installation.connectorId) !== void 0 && (installation.allowedAgentIds.length === 0 || Boolean(agentId && installation.allowedAgentIds.includes(agentId))));
|
|
88
|
-
return {
|
|
89
|
-
principalId: principal.principalId,
|
|
90
|
-
agentId,
|
|
91
|
-
context,
|
|
92
|
-
installations
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
function composioToolkitFromConnectorId(connectorId) {
|
|
96
|
-
const definition = getConnectorDefinition(connectorId);
|
|
97
|
-
return definition?.runtime.type === "composio" && definition.runtime.role === "toolkit" ? definition.runtime.toolkit : void 0;
|
|
98
|
-
}
|
|
99
|
-
function toolkitFromInstallation(installation) {
|
|
100
|
-
const toolkit = composioToolkitFromConnectorId(installation.connectorId);
|
|
101
|
-
if (!toolkit) throw new Error(`Connector installation is not a Composio toolkit: ${installation.connectorId}`);
|
|
102
|
-
return toolkit;
|
|
103
|
-
}
|
|
104
|
-
function toolkitForAction(actionId, candidates) {
|
|
105
|
-
const normalizedAction = actionId.trim().toUpperCase();
|
|
106
|
-
return [...candidates].sort((left, right) => right.length - left.length).find((toolkit) => normalizedAction === toolkit.toUpperCase() || normalizedAction.startsWith(`${toolkit.toUpperCase()}_`));
|
|
107
|
-
}
|
|
108
|
-
function contractFromSearch(connectorId, toolkit, actionId, value) {
|
|
109
|
-
const row = value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
110
|
-
const risk = scopeForComposioAction(actionId);
|
|
111
|
-
return {
|
|
112
|
-
connectorId,
|
|
113
|
-
actionId,
|
|
114
|
-
toolkit,
|
|
115
|
-
scope: risk.scope,
|
|
116
|
-
curated: risk.curated,
|
|
117
|
-
inputSchema: row.inputSchema,
|
|
118
|
-
cachedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
function createComposioTools(deps) {
|
|
122
|
-
if (installedConfigToolkits(deps.getConfig()).length === 0) return [];
|
|
123
|
-
const adapter = deps.adapter ?? new ComposioSessionsAdapter();
|
|
124
|
-
return [
|
|
125
|
-
{
|
|
126
|
-
name: "composio_search",
|
|
127
|
-
label: "🔎 Connected Apps Search",
|
|
128
|
-
description: "Discover exact actions and argument contracts for the connected apps allowed in this session. Call this before composio_execute.",
|
|
129
|
-
parameters: ComposioSearchSchema,
|
|
130
|
-
async execute(_toolCallId, params) {
|
|
131
|
-
const available = availableInstallations(deps);
|
|
132
|
-
const installedToolkits = available.installations.map(toolkitFromInstallation);
|
|
133
|
-
const requested = params.toolkits?.length ? params.toolkits.map((toolkit) => toolkit.toLowerCase()).filter((toolkit) => installedToolkits.includes(toolkit)) : installedToolkits;
|
|
134
|
-
if (requested.length === 0) return textResult("No connected apps are allowed for this user and agent.");
|
|
135
|
-
const result = await (await adapter.createSession({
|
|
136
|
-
principalId: available.principalId,
|
|
137
|
-
toolkits: requested
|
|
138
|
-
})).search({
|
|
139
|
-
query: params.query,
|
|
140
|
-
toolkits: requested
|
|
141
|
-
});
|
|
142
|
-
let visibleResult = result;
|
|
143
|
-
if (result && typeof result === "object" && !Array.isArray(result)) {
|
|
144
|
-
const schemas = result.toolSchemas;
|
|
145
|
-
if (schemas && typeof schemas === "object" && !Array.isArray(schemas)) {
|
|
146
|
-
const visibleSchemas = {};
|
|
147
|
-
for (const [actionId, schema] of Object.entries(schemas)) {
|
|
148
|
-
const toolkit = toolkitForAction(actionId, requested);
|
|
149
|
-
if (toolkit && requested.includes(toolkit)) {
|
|
150
|
-
if (!isComposioActionAllowedByCatalog(actionId)) continue;
|
|
151
|
-
visibleSchemas[actionId] = schema;
|
|
152
|
-
const installation = available.installations.find((candidate) => toolkitFromInstallation(candidate) === toolkit);
|
|
153
|
-
if (installation) upsertConnectorActionMetadata(contractFromSearch(installation.connectorId, toolkit, actionId, schema));
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
visibleResult = {
|
|
157
|
-
...result,
|
|
158
|
-
toolSchemas: visibleSchemas
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return textResult(visibleResult);
|
|
163
|
-
}
|
|
164
|
-
},
|
|
165
|
-
{
|
|
166
|
-
name: "composio_connect",
|
|
167
|
-
label: "🔐 Connect App Account",
|
|
168
|
-
description: "Create an authorization link for an installed app. Never claims the connection succeeded until it is checked again.",
|
|
169
|
-
parameters: ComposioConnectSchema,
|
|
170
|
-
async execute(_toolCallId, params) {
|
|
171
|
-
const available = availableInstallations(deps);
|
|
172
|
-
const toolkit = params.toolkit.trim().toLowerCase();
|
|
173
|
-
const installation = available.installations.find((candidate) => toolkitFromInstallation(candidate) === toolkit);
|
|
174
|
-
if (!installation) return textResult("This app is not installed or is not allowed for this user and agent.");
|
|
175
|
-
const authorization = await adapter.authorize({
|
|
176
|
-
principalId: available.principalId,
|
|
177
|
-
toolkit,
|
|
178
|
-
installationId: installation.id,
|
|
179
|
-
alias: params.alias
|
|
180
|
-
});
|
|
181
|
-
return textResult({
|
|
182
|
-
status: authorization.status,
|
|
183
|
-
toolkit,
|
|
184
|
-
authorizationUrl: authorization.connectUrl,
|
|
185
|
-
connectionId: authorization.connectionId,
|
|
186
|
-
instruction: "Ask the user to open the authorization URL. Check the connection again after they finish."
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
},
|
|
190
|
-
{
|
|
191
|
-
name: "composio_execute",
|
|
192
|
-
label: "🔌 Connected App Action",
|
|
193
|
-
description: "Execute an exact action returned by composio_search. Write and admin actions require a user-approved approvalId.",
|
|
194
|
-
parameters: ComposioExecuteSchema,
|
|
195
|
-
async execute(_toolCallId, params) {
|
|
196
|
-
const available = availableInstallations(deps);
|
|
197
|
-
const toolkit = toolkitForAction(params.actionId, available.installations.map(toolkitFromInstallation));
|
|
198
|
-
if (!toolkit) return textResult("Unknown toolkit for this action. Call composio_search first.");
|
|
199
|
-
const installation = available.installations.find((candidate) => toolkitFromInstallation(candidate) === toolkit);
|
|
200
|
-
if (!installation) return textResult("This app is not allowed for this user and agent.");
|
|
201
|
-
if (!isComposioActionAllowedByCatalog(params.actionId)) return textResult("This action is not in the connector curated action catalog.");
|
|
202
|
-
const action = listConnectorActionMetadata(installation.connectorId).find((candidate) => candidate.actionId === params.actionId);
|
|
203
|
-
if (!action?.inputSchema) return textResult("The exact action contract is not cached. Call composio_search for this task before executing.");
|
|
204
|
-
await adapter.syncConnections({ principalId: available.principalId }).catch(() => []);
|
|
205
|
-
const connections = listConnectorConnections({
|
|
206
|
-
principalId: available.principalId,
|
|
207
|
-
connectorId: installation.connectorId
|
|
208
|
-
}).filter((connection) => connection.status === "active");
|
|
209
|
-
const connection = params.connectionId ? connections.find((candidate) => candidate.id === params.connectionId) : connections.find((candidate) => candidate.isDefault) ?? connections[0];
|
|
210
|
-
const args = params.arguments ?? {};
|
|
211
|
-
const argsHash = connectorArgumentsHash(args);
|
|
212
|
-
let confirmed = false;
|
|
213
|
-
if (params.approvalId) {
|
|
214
|
-
const pending = getConnectorApproval(params.approvalId);
|
|
215
|
-
if (!pending || pending.principalId !== available.principalId || pending.connectorId !== installation.connectorId || pending.actionId !== action.actionId || pending.sessionKey !== available.context?.sessionKey) return textResult("The connector approval is invalid for this session or action.");
|
|
216
|
-
confirmed = Boolean(consumeConnectorApproval(params.approvalId, argsHash));
|
|
217
|
-
if (!confirmed) return textResult("The connector approval is not approved, has expired, or was already used.");
|
|
218
|
-
}
|
|
219
|
-
const result = await adapter.executeWithPolicy({
|
|
220
|
-
context: {
|
|
221
|
-
principalId: available.principalId,
|
|
222
|
-
toolkits: [toolkit]
|
|
223
|
-
},
|
|
224
|
-
installation,
|
|
225
|
-
connection,
|
|
226
|
-
action,
|
|
227
|
-
args,
|
|
228
|
-
agentId: available.agentId,
|
|
229
|
-
sessionKey: available.context?.sessionKey,
|
|
230
|
-
confirmed
|
|
231
|
-
});
|
|
232
|
-
if (result.decision === "confirmation_required") {
|
|
233
|
-
const approval = createConnectorApproval({
|
|
234
|
-
principalId: available.principalId,
|
|
235
|
-
connectorId: installation.connectorId,
|
|
236
|
-
connectionId: connection?.id,
|
|
237
|
-
agentId: available.agentId,
|
|
238
|
-
sessionKey: available.context?.sessionKey,
|
|
239
|
-
actionId: action.actionId,
|
|
240
|
-
scope: action.scope,
|
|
241
|
-
argumentsHash: argsHash,
|
|
242
|
-
argumentsPreview: connectorArgumentsPreview(args),
|
|
243
|
-
expiresAt: new Date(Date.now() + 10 * 6e4).toISOString()
|
|
244
|
-
});
|
|
245
|
-
return textResult({
|
|
246
|
-
status: "confirmation_required",
|
|
247
|
-
approvalId: approval.id,
|
|
248
|
-
actionId: approval.actionId,
|
|
249
|
-
scope: approval.scope,
|
|
250
|
-
argumentsPreview: approval.argumentsPreview,
|
|
251
|
-
expiresAt: approval.expiresAt,
|
|
252
|
-
instruction: "Ask the user to approve this exact action in xopc, then retry with the approvalId and unchanged arguments."
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
return textResult(result.decision === "allowed" ? result.result : result.reason);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
];
|
|
259
|
-
}
|
|
260
|
-
//#endregion
|
|
261
|
-
export { connectorPrincipalForSession, createComposioTools };
|