@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
|
@@ -0,0 +1,307 @@
|
|
|
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 { externalToolRef, parseExternalToolRef } from "./refs.js";
|
|
9
|
+
//#region src/agent/external-tools/composio-provider.ts
|
|
10
|
+
init_session_key();
|
|
11
|
+
const CONNECT_ACTION = "$connect";
|
|
12
|
+
const CONNECTION_ARGUMENT = "xopcConnectionId";
|
|
13
|
+
function textResult(value) {
|
|
14
|
+
return {
|
|
15
|
+
content: [{
|
|
16
|
+
type: "text",
|
|
17
|
+
text: typeof value === "string" ? value : JSON.stringify(value, null, 2)
|
|
18
|
+
}],
|
|
19
|
+
details: {}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function connectorPrincipalForSession(sessionKey) {
|
|
23
|
+
const parsed = parseSessionKey(sessionKey);
|
|
24
|
+
if (!parsed || parsed.source === "cli" || parsed.source === "webchat") return {
|
|
25
|
+
principalId: "local-owner",
|
|
26
|
+
agentId: parsed?.agentId,
|
|
27
|
+
isLocalOwner: true
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
principalId: `channel:${parsed.source}:${parsed.accountId}:${parsed.peerKind}:${parsed.peerId}`,
|
|
31
|
+
agentId: parsed.agentId,
|
|
32
|
+
isLocalOwner: false
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function installedConfigToolkits(config) {
|
|
36
|
+
return Object.values(config?.connectors?.instances ?? {}).flatMap((record) => {
|
|
37
|
+
if (!record || typeof record !== "object" || Array.isArray(record)) return [];
|
|
38
|
+
const row = record;
|
|
39
|
+
const marker = row.xopcConnector;
|
|
40
|
+
const markerRecord = marker && typeof marker === "object" && !Array.isArray(marker) ? marker : void 0;
|
|
41
|
+
if (markerRecord?.enabled === false) return [];
|
|
42
|
+
const runtime = row.runtime;
|
|
43
|
+
if (typeof markerRecord?.connectorId !== "string" || !runtime || typeof runtime !== "object" || Array.isArray(runtime) || runtime.type !== "composio" || runtime.role !== "toolkit" || typeof runtime.toolkit !== "string") return [];
|
|
44
|
+
return [{
|
|
45
|
+
connectorId: markerRecord.connectorId,
|
|
46
|
+
toolkit: runtime.toolkit
|
|
47
|
+
}];
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function composioToolkitFromConnectorId(connectorId) {
|
|
51
|
+
const definition = getConnectorDefinition(connectorId);
|
|
52
|
+
return definition?.runtime.type === "composio" && definition.runtime.role === "toolkit" ? definition.runtime.toolkit : void 0;
|
|
53
|
+
}
|
|
54
|
+
function toolkitFromInstallation(installation) {
|
|
55
|
+
const toolkit = composioToolkitFromConnectorId(installation.connectorId);
|
|
56
|
+
if (!toolkit) throw new Error(`Connector installation is not a Composio toolkit: ${installation.connectorId}`);
|
|
57
|
+
return toolkit;
|
|
58
|
+
}
|
|
59
|
+
function syncLocalOwnerInstallations(config) {
|
|
60
|
+
for (const { connectorId, toolkit } of installedConfigToolkits(config)) {
|
|
61
|
+
const id = `${connectorId}-local-owner`;
|
|
62
|
+
const existing = getConnectorInstallation(id);
|
|
63
|
+
upsertConnectorInstallation({
|
|
64
|
+
id,
|
|
65
|
+
connectorId,
|
|
66
|
+
principalId: "local-owner",
|
|
67
|
+
enabled: true,
|
|
68
|
+
allowedAgentIds: existing?.allowedAgentIds ?? [],
|
|
69
|
+
maxScope: getComposioToolkitScope(config, toolkit),
|
|
70
|
+
confirmationPolicy: existing?.confirmationPolicy ?? "writes",
|
|
71
|
+
selectedConnectionIds: existing?.selectedConnectionIds ?? [],
|
|
72
|
+
createdAt: existing?.createdAt
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function toolkitForAction(actionId, candidates) {
|
|
77
|
+
const normalizedAction = actionId.trim().toUpperCase();
|
|
78
|
+
return [...candidates].sort((left, right) => right.length - left.length).find((toolkit) => normalizedAction === toolkit.toUpperCase() || normalizedAction.startsWith(`${toolkit.toUpperCase()}_`));
|
|
79
|
+
}
|
|
80
|
+
function contractFromSearch(connectorId, toolkit, actionId, value) {
|
|
81
|
+
const row = value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
82
|
+
const risk = scopeForComposioAction(actionId);
|
|
83
|
+
return {
|
|
84
|
+
connectorId,
|
|
85
|
+
actionId,
|
|
86
|
+
toolkit,
|
|
87
|
+
scope: risk.scope,
|
|
88
|
+
curated: risk.curated,
|
|
89
|
+
inputSchema: row.inputSchema,
|
|
90
|
+
cachedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function schemaSummary(value, fallback) {
|
|
94
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return fallback;
|
|
95
|
+
const row = value;
|
|
96
|
+
for (const candidate of [
|
|
97
|
+
row.description,
|
|
98
|
+
row.title,
|
|
99
|
+
row.name
|
|
100
|
+
]) if (typeof candidate === "string" && candidate.trim()) return candidate.trim();
|
|
101
|
+
return fallback;
|
|
102
|
+
}
|
|
103
|
+
function actionInputSchema(action) {
|
|
104
|
+
const schema = action.inputSchema && typeof action.inputSchema === "object" && !Array.isArray(action.inputSchema) ? action.inputSchema : { type: "object" };
|
|
105
|
+
const properties = schema.properties && typeof schema.properties === "object" && !Array.isArray(schema.properties) ? schema.properties : {};
|
|
106
|
+
return {
|
|
107
|
+
...schema,
|
|
108
|
+
type: "object",
|
|
109
|
+
properties: {
|
|
110
|
+
...properties,
|
|
111
|
+
[CONNECTION_ARGUMENT]: {
|
|
112
|
+
type: "string",
|
|
113
|
+
description: "Optional local connection id when more than one account is connected."
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
var ComposioToolProvider = class {
|
|
119
|
+
source = "composio";
|
|
120
|
+
adapter;
|
|
121
|
+
constructor(deps) {
|
|
122
|
+
this.deps = deps;
|
|
123
|
+
this.adapter = deps.adapter ?? new ComposioSessionsAdapter();
|
|
124
|
+
}
|
|
125
|
+
async search(query) {
|
|
126
|
+
const available = this.availableInstallations();
|
|
127
|
+
const toolkits = available.installations.map(toolkitFromInstallation);
|
|
128
|
+
if (toolkits.length === 0) return [];
|
|
129
|
+
const result = await (await this.adapter.createSession({
|
|
130
|
+
principalId: available.principalId,
|
|
131
|
+
toolkits
|
|
132
|
+
})).search({
|
|
133
|
+
query,
|
|
134
|
+
toolkits
|
|
135
|
+
});
|
|
136
|
+
const schemas = result && typeof result === "object" && !Array.isArray(result) ? result.toolSchemas : void 0;
|
|
137
|
+
const hits = available.installations.map((installation) => {
|
|
138
|
+
const toolkit = toolkitFromInstallation(installation);
|
|
139
|
+
return {
|
|
140
|
+
toolRef: externalToolRef(this.source, installation.id, CONNECT_ACTION),
|
|
141
|
+
source: this.source,
|
|
142
|
+
namespace: toolkit,
|
|
143
|
+
title: `Connect ${toolkit}`,
|
|
144
|
+
summary: `Authorize an account for the installed ${toolkit} app.`
|
|
145
|
+
};
|
|
146
|
+
});
|
|
147
|
+
if (!schemas || typeof schemas !== "object" || Array.isArray(schemas)) return hits;
|
|
148
|
+
for (const [actionId, schema] of Object.entries(schemas)) {
|
|
149
|
+
const toolkit = toolkitForAction(actionId, toolkits);
|
|
150
|
+
if (!toolkit || !isComposioActionAllowedByCatalog(actionId)) continue;
|
|
151
|
+
const installation = available.installations.find((candidate) => toolkitFromInstallation(candidate) === toolkit);
|
|
152
|
+
if (!installation) continue;
|
|
153
|
+
upsertConnectorActionMetadata(contractFromSearch(installation.connectorId, toolkit, actionId, schema));
|
|
154
|
+
hits.push({
|
|
155
|
+
toolRef: externalToolRef(this.source, installation.id, actionId),
|
|
156
|
+
source: this.source,
|
|
157
|
+
namespace: toolkit,
|
|
158
|
+
title: actionId,
|
|
159
|
+
summary: schemaSummary(schema, `Run ${actionId} in ${toolkit}.`)
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
return hits;
|
|
163
|
+
}
|
|
164
|
+
async describe(toolRef) {
|
|
165
|
+
const resolved = this.resolve(toolRef);
|
|
166
|
+
if (!resolved) return void 0;
|
|
167
|
+
const toolkit = toolkitFromInstallation(resolved.installation);
|
|
168
|
+
if (resolved.actionId === CONNECT_ACTION) {
|
|
169
|
+
const summary = `Authorize an account for the installed ${toolkit} app.`;
|
|
170
|
+
return {
|
|
171
|
+
toolRef,
|
|
172
|
+
source: this.source,
|
|
173
|
+
namespace: toolkit,
|
|
174
|
+
title: `Connect ${toolkit}`,
|
|
175
|
+
summary,
|
|
176
|
+
description: `${summary} Never claim the connection succeeded until it is checked again.`,
|
|
177
|
+
inputSchema: {
|
|
178
|
+
type: "object",
|
|
179
|
+
properties: { alias: {
|
|
180
|
+
type: "string",
|
|
181
|
+
description: "Optional account label."
|
|
182
|
+
} },
|
|
183
|
+
additionalProperties: false
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
const action = listConnectorActionMetadata(resolved.installation.connectorId).find((candidate) => candidate.actionId === resolved.actionId);
|
|
188
|
+
if (!action?.inputSchema || !isComposioActionAllowedByCatalog(action.actionId)) return void 0;
|
|
189
|
+
const summary = `Run ${action.actionId} in ${toolkit}.`;
|
|
190
|
+
return {
|
|
191
|
+
toolRef,
|
|
192
|
+
source: this.source,
|
|
193
|
+
namespace: toolkit,
|
|
194
|
+
title: action.actionId,
|
|
195
|
+
summary,
|
|
196
|
+
description: summary,
|
|
197
|
+
inputSchema: actionInputSchema(action)
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
async execute(toolRef, args, approvalId, _context) {
|
|
201
|
+
const available = this.availableInstallations();
|
|
202
|
+
const resolved = this.resolve(toolRef, available.installations);
|
|
203
|
+
if (!resolved) return textResult("This connected app tool is not allowed for this user and agent.");
|
|
204
|
+
let executionArgs = args;
|
|
205
|
+
if (this.deps.hookRunner) {
|
|
206
|
+
const hook = await this.deps.hookRunner.runBeforeToolCall(toolRef, args, { sessionKey: available.context?.sessionKey });
|
|
207
|
+
if (!hook.allowed) throw new Error(hook.reason ?? "Connected app tool call blocked by policy hook.");
|
|
208
|
+
executionArgs = hook.params ?? args;
|
|
209
|
+
}
|
|
210
|
+
const toolkit = toolkitFromInstallation(resolved.installation);
|
|
211
|
+
if (resolved.actionId === CONNECT_ACTION) {
|
|
212
|
+
const authorization = await this.adapter.authorize({
|
|
213
|
+
principalId: available.principalId,
|
|
214
|
+
toolkit,
|
|
215
|
+
installationId: resolved.installation.id,
|
|
216
|
+
alias: typeof executionArgs.alias === "string" ? executionArgs.alias : void 0
|
|
217
|
+
});
|
|
218
|
+
return textResult({
|
|
219
|
+
status: authorization.status,
|
|
220
|
+
toolkit,
|
|
221
|
+
authorizationUrl: authorization.connectUrl,
|
|
222
|
+
connectionId: authorization.connectionId,
|
|
223
|
+
instruction: "Ask the user to open the authorization URL. Check the connection again after they finish."
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
const action = listConnectorActionMetadata(resolved.installation.connectorId).find((candidate) => candidate.actionId === resolved.actionId);
|
|
227
|
+
if (!action?.inputSchema || !isComposioActionAllowedByCatalog(resolved.actionId)) return textResult("The exact action contract is unavailable. Search and describe the tool again.");
|
|
228
|
+
await this.adapter.syncConnections({ principalId: available.principalId }).catch(() => []);
|
|
229
|
+
const connections = listConnectorConnections({
|
|
230
|
+
principalId: available.principalId,
|
|
231
|
+
connectorId: resolved.installation.connectorId
|
|
232
|
+
}).filter((connection) => connection.status === "active");
|
|
233
|
+
const requestedConnection = typeof executionArgs[CONNECTION_ARGUMENT] === "string" ? executionArgs[CONNECTION_ARGUMENT] : void 0;
|
|
234
|
+
const connection = requestedConnection ? connections.find((candidate) => candidate.id === requestedConnection) : connections.find((candidate) => candidate.isDefault) ?? connections[0];
|
|
235
|
+
const actionArgs = { ...executionArgs };
|
|
236
|
+
delete actionArgs[CONNECTION_ARGUMENT];
|
|
237
|
+
const argsHash = connectorArgumentsHash(actionArgs);
|
|
238
|
+
let confirmed = false;
|
|
239
|
+
if (approvalId) {
|
|
240
|
+
const pending = getConnectorApproval(approvalId);
|
|
241
|
+
if (!pending || pending.principalId !== available.principalId || pending.connectorId !== resolved.installation.connectorId || pending.actionId !== action.actionId || pending.sessionKey !== available.context?.sessionKey) return textResult("The connector approval is invalid for this session or action.");
|
|
242
|
+
confirmed = Boolean(consumeConnectorApproval(approvalId, argsHash));
|
|
243
|
+
if (!confirmed) return textResult("The connector approval is not approved, has expired, or was already used.");
|
|
244
|
+
}
|
|
245
|
+
const result = await this.adapter.executeWithPolicy({
|
|
246
|
+
context: {
|
|
247
|
+
principalId: available.principalId,
|
|
248
|
+
toolkits: [toolkit]
|
|
249
|
+
},
|
|
250
|
+
installation: resolved.installation,
|
|
251
|
+
connection,
|
|
252
|
+
action,
|
|
253
|
+
args: actionArgs,
|
|
254
|
+
agentId: available.agentId,
|
|
255
|
+
sessionKey: available.context?.sessionKey,
|
|
256
|
+
confirmed
|
|
257
|
+
});
|
|
258
|
+
if (result.decision === "confirmation_required") {
|
|
259
|
+
const approval = createConnectorApproval({
|
|
260
|
+
principalId: available.principalId,
|
|
261
|
+
connectorId: resolved.installation.connectorId,
|
|
262
|
+
connectionId: connection?.id,
|
|
263
|
+
agentId: available.agentId,
|
|
264
|
+
sessionKey: available.context?.sessionKey,
|
|
265
|
+
actionId: action.actionId,
|
|
266
|
+
scope: action.scope,
|
|
267
|
+
argumentsHash: argsHash,
|
|
268
|
+
argumentsPreview: connectorArgumentsPreview(actionArgs),
|
|
269
|
+
expiresAt: new Date(Date.now() + 10 * 6e4).toISOString()
|
|
270
|
+
});
|
|
271
|
+
return textResult({
|
|
272
|
+
status: "confirmation_required",
|
|
273
|
+
approvalId: approval.id,
|
|
274
|
+
actionId: approval.actionId,
|
|
275
|
+
scope: approval.scope,
|
|
276
|
+
argumentsPreview: approval.argumentsPreview,
|
|
277
|
+
expiresAt: approval.expiresAt,
|
|
278
|
+
instruction: "Ask the user to approve this exact action in xopc, then retry with the approvalId and unchanged arguments."
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
return textResult(result.decision === "allowed" ? result.result : result.reason);
|
|
282
|
+
}
|
|
283
|
+
availableInstallations() {
|
|
284
|
+
const context = this.deps.getCurrentContext();
|
|
285
|
+
const principal = connectorPrincipalForSession(context?.sessionKey);
|
|
286
|
+
if (principal.isLocalOwner) syncLocalOwnerInstallations(this.deps.getConfig());
|
|
287
|
+
const agentId = this.deps.agentId ?? principal.agentId;
|
|
288
|
+
const installations = listConnectorInstallations(principal.principalId).filter((installation) => installation.enabled && composioToolkitFromConnectorId(installation.connectorId) !== void 0 && (installation.allowedAgentIds.length === 0 || Boolean(agentId && installation.allowedAgentIds.includes(agentId))));
|
|
289
|
+
return {
|
|
290
|
+
principalId: principal.principalId,
|
|
291
|
+
agentId,
|
|
292
|
+
context,
|
|
293
|
+
installations
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
resolve(toolRef, installations = this.availableInstallations().installations) {
|
|
297
|
+
const parsed = parseExternalToolRef(toolRef, this.source);
|
|
298
|
+
if (!parsed) return void 0;
|
|
299
|
+
const installation = installations.find((candidate) => candidate.id === parsed.namespace);
|
|
300
|
+
return installation ? {
|
|
301
|
+
installation,
|
|
302
|
+
actionId: parsed.toolName
|
|
303
|
+
} : void 0;
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
//#endregion
|
|
307
|
+
export { ComposioToolProvider };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ExtensionHookRunner } from '../../extensions/index.js';
|
|
2
|
+
import type { ExtensionRegistry } from '../../extensions/types/index.js';
|
|
3
|
+
import { type ToolExecutorConfig } from '../tools/executor.js';
|
|
4
|
+
import type { ExternalToolDescriptor, ExternalToolExecutionContext, ExternalToolProvider, ExternalToolSearchHit } from './types.js';
|
|
5
|
+
export interface ExtensionToolProviderDeps {
|
|
6
|
+
registry?: ExtensionRegistry;
|
|
7
|
+
disabledTools?: Set<string>;
|
|
8
|
+
getSessionKey: () => string | undefined;
|
|
9
|
+
hookRunner?: ExtensionHookRunner;
|
|
10
|
+
toolExecutorConfig?: Partial<ToolExecutorConfig>;
|
|
11
|
+
}
|
|
12
|
+
export declare class ExtensionToolProvider implements ExternalToolProvider {
|
|
13
|
+
private readonly deps;
|
|
14
|
+
readonly source: "extension";
|
|
15
|
+
constructor(deps: ExtensionToolProviderDeps);
|
|
16
|
+
search(_query: string): Promise<ExternalToolSearchHit[]>;
|
|
17
|
+
describe(toolRef: string): Promise<ExternalToolDescriptor | undefined>;
|
|
18
|
+
execute(toolRef: string, args: Record<string, unknown>, _approvalId: string | undefined, context: ExternalToolExecutionContext): Promise<import("@earendil-works/pi-agent-core").AgentToolResult<any>>;
|
|
19
|
+
private resolve;
|
|
20
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { externalToolRef, parseExternalToolRef } from "./refs.js";
|
|
2
|
+
import { executeToolWithProtection } from "../tools/executor.js";
|
|
3
|
+
//#region src/agent/external-tools/extension-provider.ts
|
|
4
|
+
function toolSummary(tool) {
|
|
5
|
+
return tool.description || tool.label || tool.name;
|
|
6
|
+
}
|
|
7
|
+
var ExtensionToolProvider = class {
|
|
8
|
+
source = "extension";
|
|
9
|
+
constructor(deps) {
|
|
10
|
+
this.deps = deps;
|
|
11
|
+
}
|
|
12
|
+
async search(_query) {
|
|
13
|
+
if (!this.deps.registry) return [];
|
|
14
|
+
return this.deps.registry.getAllTools().filter((tool) => !this.deps.disabledTools?.has(tool.name)).flatMap((tool) => {
|
|
15
|
+
const extensionId = this.deps.registry.getToolExtensionId(tool.name);
|
|
16
|
+
if (!extensionId) return [];
|
|
17
|
+
return [{
|
|
18
|
+
toolRef: externalToolRef(this.source, extensionId, tool.name),
|
|
19
|
+
source: this.source,
|
|
20
|
+
namespace: extensionId,
|
|
21
|
+
title: tool.label || tool.name,
|
|
22
|
+
summary: toolSummary(tool)
|
|
23
|
+
}];
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
async describe(toolRef) {
|
|
27
|
+
const resolved = this.resolve(toolRef);
|
|
28
|
+
if (!resolved) return void 0;
|
|
29
|
+
const { extensionId, tool } = resolved;
|
|
30
|
+
const summary = toolSummary(tool);
|
|
31
|
+
return {
|
|
32
|
+
toolRef,
|
|
33
|
+
source: this.source,
|
|
34
|
+
namespace: extensionId,
|
|
35
|
+
title: tool.label || tool.name,
|
|
36
|
+
summary,
|
|
37
|
+
description: summary,
|
|
38
|
+
inputSchema: tool.parameters
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
async execute(toolRef, args, _approvalId, context) {
|
|
42
|
+
const resolved = this.resolve(toolRef);
|
|
43
|
+
if (!resolved) throw new Error(`Extension tool is unavailable: ${toolRef}`);
|
|
44
|
+
let executionArgs = args;
|
|
45
|
+
if (this.deps.hookRunner) {
|
|
46
|
+
const hook = await this.deps.hookRunner.runBeforeToolCall(resolved.tool.name, args, {
|
|
47
|
+
extensionId: resolved.extensionId,
|
|
48
|
+
sessionKey: this.deps.getSessionKey()
|
|
49
|
+
});
|
|
50
|
+
if (!hook.allowed) throw new Error(hook.reason ?? "Extension tool call blocked by policy hook.");
|
|
51
|
+
executionArgs = hook.params ?? args;
|
|
52
|
+
}
|
|
53
|
+
return executeToolWithProtection(resolved.tool, context.toolCallId, executionArgs, context.signal, context.onUpdate, this.deps.toolExecutorConfig);
|
|
54
|
+
}
|
|
55
|
+
resolve(toolRef) {
|
|
56
|
+
if (!this.deps.registry) return void 0;
|
|
57
|
+
const parsed = parseExternalToolRef(toolRef, this.source);
|
|
58
|
+
if (!parsed || this.deps.disabledTools?.has(parsed.toolName)) return void 0;
|
|
59
|
+
const tool = this.deps.registry.getTool(parsed.toolName);
|
|
60
|
+
if (!tool || this.deps.registry.getToolExtensionId(parsed.toolName) !== parsed.namespace) return;
|
|
61
|
+
return {
|
|
62
|
+
extensionId: parsed.namespace,
|
|
63
|
+
tool
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
//#endregion
|
|
68
|
+
export { ExtensionToolProvider };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AgentTool } from '@earendil-works/pi-agent-core';
|
|
2
|
+
import { type ExternalToolProvider } from './types.js';
|
|
3
|
+
export declare const EXTERNAL_TOOL_NAMES: {
|
|
4
|
+
readonly search: "xopc_tool_search";
|
|
5
|
+
readonly describe: "xopc_tool_describe";
|
|
6
|
+
readonly execute: "xopc_tool_execute";
|
|
7
|
+
};
|
|
8
|
+
export declare function createExternalToolGatewayTools(providers: ExternalToolProvider[]): AgentTool[];
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { ExternalToolService } from "./service.js";
|
|
2
|
+
import { EXTERNAL_TOOL_SOURCES } from "./types.js";
|
|
3
|
+
import { Type } from "@sinclair/typebox";
|
|
4
|
+
//#region src/agent/external-tools/gateway-tools.ts
|
|
5
|
+
const EXTERNAL_TOOL_NAMES = {
|
|
6
|
+
search: "xopc_tool_search",
|
|
7
|
+
describe: "xopc_tool_describe",
|
|
8
|
+
execute: "xopc_tool_execute"
|
|
9
|
+
};
|
|
10
|
+
const ToolSearchSchema = Type.Object({
|
|
11
|
+
query: Type.String({ description: "Describe the capability or task you need." }),
|
|
12
|
+
sources: Type.Optional(Type.Array(Type.Union(EXTERNAL_TOOL_SOURCES.map((source) => Type.Literal(source))), {
|
|
13
|
+
maxItems: EXTERNAL_TOOL_SOURCES.length,
|
|
14
|
+
description: "Optional external tool sources to search."
|
|
15
|
+
})),
|
|
16
|
+
limit: Type.Optional(Type.Integer({
|
|
17
|
+
minimum: 1,
|
|
18
|
+
maximum: 20
|
|
19
|
+
}))
|
|
20
|
+
});
|
|
21
|
+
const ToolDescribeSchema = Type.Object({ toolRefs: Type.Array(Type.String(), {
|
|
22
|
+
minItems: 1,
|
|
23
|
+
maxItems: 3,
|
|
24
|
+
description: "Exact tool references returned by xopc_tool_search."
|
|
25
|
+
}) });
|
|
26
|
+
const ToolExecuteSchema = Type.Object({
|
|
27
|
+
toolRef: Type.String({ description: "Exact tool reference returned by xopc_tool_search." }),
|
|
28
|
+
revision: Type.String({ description: "Exact contract revision returned by xopc_tool_describe." }),
|
|
29
|
+
arguments: Type.Optional(Type.Record(Type.String(), Type.Unknown())),
|
|
30
|
+
approvalId: Type.Optional(Type.String({ description: "One-time approval id when execution requested confirmation." }))
|
|
31
|
+
});
|
|
32
|
+
function textResult(value, details = {}) {
|
|
33
|
+
return {
|
|
34
|
+
content: [{
|
|
35
|
+
type: "text",
|
|
36
|
+
text: JSON.stringify(value, null, 2)
|
|
37
|
+
}],
|
|
38
|
+
details
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function createExternalToolGatewayTools(providers) {
|
|
42
|
+
const service = new ExternalToolService(providers);
|
|
43
|
+
return [
|
|
44
|
+
{
|
|
45
|
+
name: EXTERNAL_TOOL_NAMES.search,
|
|
46
|
+
label: "🔎 External Tool Search",
|
|
47
|
+
description: "Search MCP, connected-app, extension, and remote-memory tools. Use concise English capability keywords. Returns compact references only; call xopc_tool_describe before execution.",
|
|
48
|
+
parameters: ToolSearchSchema,
|
|
49
|
+
async execute(_toolCallId, params) {
|
|
50
|
+
return textResult(await service.search(params));
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: EXTERNAL_TOOL_NAMES.describe,
|
|
55
|
+
label: "📋 External Tool Contract",
|
|
56
|
+
description: "Load exact contracts for up to three external tools returned by xopc_tool_search.",
|
|
57
|
+
parameters: ToolDescribeSchema,
|
|
58
|
+
async execute(_toolCallId, params) {
|
|
59
|
+
return textResult(await service.describe(params.toolRefs));
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: EXTERNAL_TOOL_NAMES.execute,
|
|
64
|
+
label: "▶️ External Tool Execute",
|
|
65
|
+
description: "Execute one external tool using its exact reference, contract revision, and validated arguments.",
|
|
66
|
+
parameters: ToolExecuteSchema,
|
|
67
|
+
async execute(toolCallId, params, signal, onUpdate) {
|
|
68
|
+
const result = await service.execute({
|
|
69
|
+
...params,
|
|
70
|
+
context: {
|
|
71
|
+
toolCallId,
|
|
72
|
+
signal,
|
|
73
|
+
onUpdate
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
return {
|
|
77
|
+
...result,
|
|
78
|
+
details: {
|
|
79
|
+
...result.details ?? {},
|
|
80
|
+
delegatedToolRef: params.toolRef,
|
|
81
|
+
delegatedToolRevision: params.revision
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
];
|
|
87
|
+
}
|
|
88
|
+
//#endregion
|
|
89
|
+
export { EXTERNAL_TOOL_NAMES, createExternalToolGatewayTools };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Config } from '../../config/schema.js';
|
|
2
|
+
import type { ExtensionHookRunner } from '../../extensions/index.js';
|
|
3
|
+
import type { ExtensionRegistry } from '../../extensions/types/index.js';
|
|
4
|
+
import type { MemoryManager } from '../memory/manager.js';
|
|
5
|
+
import type { ToolExecutorConfig } from '../tools/executor.js';
|
|
6
|
+
export interface DefaultExternalToolGatewayDeps {
|
|
7
|
+
workspace: string;
|
|
8
|
+
getConfig: () => Config | undefined;
|
|
9
|
+
getCurrentContext: () => {
|
|
10
|
+
channel: string;
|
|
11
|
+
chatId: string;
|
|
12
|
+
sessionKey: string;
|
|
13
|
+
} | null;
|
|
14
|
+
agentId?: string;
|
|
15
|
+
extensionRegistry?: ExtensionRegistry;
|
|
16
|
+
disabledTools?: Set<string>;
|
|
17
|
+
hookRunner?: ExtensionHookRunner;
|
|
18
|
+
toolExecutorConfig?: Partial<ToolExecutorConfig>;
|
|
19
|
+
getMemoryManager?: () => MemoryManager;
|
|
20
|
+
}
|
|
21
|
+
export declare function createDefaultExternalToolGatewayTools(deps: DefaultExternalToolGatewayDeps): import("@earendil-works/pi-agent-core").AgentTool<import("typebox").TSchema, any>[];
|
|
22
|
+
export { ExternalToolService } from './service.js';
|
|
23
|
+
export { EXTERNAL_TOOL_NAMES } from './gateway-tools.js';
|
|
24
|
+
export type * from './types.js';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ComposioToolProvider } from "./composio-provider.js";
|
|
2
|
+
import { ExtensionToolProvider } from "./extension-provider.js";
|
|
3
|
+
import { ExternalToolService } from "./service.js";
|
|
4
|
+
import { EXTERNAL_TOOL_NAMES, createExternalToolGatewayTools } from "./gateway-tools.js";
|
|
5
|
+
import { McpToolProvider } from "./mcp-provider.js";
|
|
6
|
+
import { MemoryToolProvider } from "./memory-provider.js";
|
|
7
|
+
//#region src/agent/external-tools/index.ts
|
|
8
|
+
function createDefaultExternalToolGatewayTools(deps) {
|
|
9
|
+
return createExternalToolGatewayTools([
|
|
10
|
+
new McpToolProvider({
|
|
11
|
+
workspace: deps.workspace,
|
|
12
|
+
getConfig: deps.getConfig,
|
|
13
|
+
getSessionKey: () => deps.getCurrentContext()?.sessionKey,
|
|
14
|
+
agentId: deps.agentId,
|
|
15
|
+
hookRunner: deps.hookRunner
|
|
16
|
+
}),
|
|
17
|
+
new ComposioToolProvider({
|
|
18
|
+
getConfig: deps.getConfig,
|
|
19
|
+
getCurrentContext: deps.getCurrentContext,
|
|
20
|
+
agentId: deps.agentId,
|
|
21
|
+
hookRunner: deps.hookRunner
|
|
22
|
+
}),
|
|
23
|
+
new ExtensionToolProvider({
|
|
24
|
+
registry: deps.extensionRegistry,
|
|
25
|
+
disabledTools: deps.disabledTools,
|
|
26
|
+
getSessionKey: () => deps.getCurrentContext()?.sessionKey,
|
|
27
|
+
hookRunner: deps.hookRunner,
|
|
28
|
+
toolExecutorConfig: deps.toolExecutorConfig
|
|
29
|
+
}),
|
|
30
|
+
new MemoryToolProvider({
|
|
31
|
+
getMemoryManager: deps.getMemoryManager,
|
|
32
|
+
disabledTools: deps.disabledTools,
|
|
33
|
+
getSessionKey: () => deps.getCurrentContext()?.sessionKey,
|
|
34
|
+
hookRunner: deps.hookRunner,
|
|
35
|
+
toolExecutorConfig: deps.toolExecutorConfig
|
|
36
|
+
})
|
|
37
|
+
]);
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
export { EXTERNAL_TOOL_NAMES, ExternalToolService, createDefaultExternalToolGatewayTools };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { AgentToolResult } from '@earendil-works/pi-agent-core';
|
|
2
|
+
import type { Config } from '../../config/schema.js';
|
|
3
|
+
import type { ExtensionHookRunner } from '../../extensions/index.js';
|
|
4
|
+
import type { SessionMcpRuntime } from '../mcp/bundle-mcp-types.js';
|
|
5
|
+
import type { ExternalToolDescriptor, ExternalToolExecutionContext, ExternalToolProvider, ExternalToolSearchHit } from './types.js';
|
|
6
|
+
export interface McpToolProviderDeps {
|
|
7
|
+
workspace: string;
|
|
8
|
+
getConfig: () => Config | undefined;
|
|
9
|
+
getSessionKey: () => string | undefined;
|
|
10
|
+
agentId?: string;
|
|
11
|
+
hookRunner?: ExtensionHookRunner;
|
|
12
|
+
getRuntime?: (params: {
|
|
13
|
+
sessionId: string;
|
|
14
|
+
sessionKey?: string;
|
|
15
|
+
workspaceDir: string;
|
|
16
|
+
cfg?: Config;
|
|
17
|
+
}) => Promise<SessionMcpRuntime>;
|
|
18
|
+
}
|
|
19
|
+
export declare class McpToolProvider implements ExternalToolProvider {
|
|
20
|
+
private readonly deps;
|
|
21
|
+
readonly source: "mcp";
|
|
22
|
+
constructor(deps: McpToolProviderDeps);
|
|
23
|
+
search(_query: string): Promise<ExternalToolSearchHit[]>;
|
|
24
|
+
describe(toolRef: string): Promise<ExternalToolDescriptor | undefined>;
|
|
25
|
+
execute(toolRef: string, args: Record<string, unknown>, _approvalId: string | undefined, context: ExternalToolExecutionContext): Promise<AgentToolResult<Record<string, unknown>>>;
|
|
26
|
+
private resolve;
|
|
27
|
+
private isAllowed;
|
|
28
|
+
private withRuntime;
|
|
29
|
+
}
|