@decocms/mesh-sdk 1.2.1 → 1.2.3

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.
@@ -1,4 +1,10 @@
1
1
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2
+ import {
3
+ ErrorCode,
4
+ McpError,
5
+ type ListResourcesResult,
6
+ type ReadResourceResult,
7
+ } from "@modelcontextprotocol/sdk/types.js";
2
8
  import {
3
9
  useQuery,
4
10
  useSuspenseQuery,
@@ -7,10 +13,6 @@ import {
7
13
  type UseSuspenseQueryOptions,
8
14
  type UseSuspenseQueryResult,
9
15
  } from "@tanstack/react-query";
10
- import type {
11
- ListResourcesResult,
12
- ReadResourceResult,
13
- } from "@modelcontextprotocol/sdk/types.js";
14
16
  import { KEYS } from "../lib/query-keys";
15
17
 
16
18
  /**
@@ -24,7 +26,15 @@ export async function listResources(
24
26
  if (!capabilities?.resources) {
25
27
  return { resources: [] };
26
28
  }
27
- return await client.listResources();
29
+
30
+ try {
31
+ return await client.listResources();
32
+ } catch (error) {
33
+ if (error instanceof McpError && error.code === ErrorCode.MethodNotFound) {
34
+ return { resources: [] };
35
+ }
36
+ throw error;
37
+ }
28
38
  }
29
39
 
30
40
  /**
@@ -5,17 +5,28 @@
5
5
  * These hooks offer a reactive interface for accessing and manipulating virtual MCPs.
6
6
  */
7
7
 
8
+ import { useQuery } from "@tanstack/react-query";
9
+ import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
8
10
  import type { VirtualMCPEntity } from "../types/virtual-mcp";
9
11
  import { useProjectContext } from "../context";
10
12
  import {
13
+ collectionItemQueryOptions,
11
14
  useCollectionActions,
12
15
  useCollectionItem,
13
16
  useCollectionList,
14
17
  type CollectionFilter,
15
18
  type UseCollectionListOptions,
16
19
  } from "./use-collections";
20
+ import type { Client } from "@modelcontextprotocol/sdk/client/index.js";
17
21
  import { useMCPClient } from "./use-mcp-client";
18
22
  import { SELF_MCP_ALIAS_ID } from "../lib/constants";
23
+ import { KEYS } from "../lib/query-keys";
24
+
25
+ export interface VirtualMCPLastUsed {
26
+ id: string;
27
+ last_used_at?: string;
28
+ last_used_by?: string;
29
+ }
19
30
 
20
31
  /**
21
32
  * Filter definition for virtual MCPs (matches @deco/ui Filter shape)
@@ -38,6 +49,7 @@ export function useVirtualMCPs(options: UseVirtualMCPsOptions = {}) {
38
49
  const client = useMCPClient({
39
50
  connectionId: SELF_MCP_ALIAS_ID,
40
51
  orgId: org.id,
52
+ orgSlug: org.slug,
41
53
  });
42
54
 
43
55
  return useCollectionList<VirtualMCPEntity>(
@@ -48,6 +60,23 @@ export function useVirtualMCPs(options: UseVirtualMCPsOptions = {}) {
48
60
  );
49
61
  }
50
62
 
63
+ /**
64
+ * Query options for a single virtual MCP — shared with parallel-prefetch
65
+ * batches so they warm the exact cache entry useVirtualMCP reads.
66
+ */
67
+ export function virtualMcpItemQueryOptions(
68
+ orgId: string,
69
+ virtualMcpId: string | null | undefined,
70
+ client: Client,
71
+ ) {
72
+ return collectionItemQueryOptions<VirtualMCPEntity>(
73
+ orgId,
74
+ "VIRTUAL_MCP",
75
+ virtualMcpId ?? undefined,
76
+ client,
77
+ );
78
+ }
79
+
51
80
  /**
52
81
  * Hook to get a single virtual MCP by ID
53
82
  *
@@ -61,6 +90,7 @@ export function useVirtualMCP(
61
90
  const client = useMCPClient({
62
91
  connectionId: SELF_MCP_ALIAS_ID,
63
92
  orgId: org.id,
93
+ orgSlug: org.slug,
64
94
  });
65
95
 
66
96
  // If null/undefined, return null (use default virtual MCP)
@@ -75,6 +105,39 @@ export function useVirtualMCP(
75
105
  return dbVirtualMCP;
76
106
  }
77
107
 
108
+ /**
109
+ * Hook to fetch last-used info (most recent thread timestamp + user) for a set
110
+ * of virtual MCPs. Backed by VIRTUAL_MCP_LAST_USED_LIST so the data isn't
111
+ * loaded on the agent fetch hot path.
112
+ */
113
+ export function useVirtualMCPsLastUsed(ids: string[]) {
114
+ const { org } = useProjectContext();
115
+ const client = useMCPClient({
116
+ connectionId: SELF_MCP_ALIAS_ID,
117
+ orgId: org.id,
118
+ orgSlug: org.slug,
119
+ });
120
+ const sortedIds = [...ids].sort();
121
+
122
+ return useQuery<Map<string, VirtualMCPLastUsed>>({
123
+ queryKey: KEYS.virtualMcpLastUsed(org.id, sortedIds),
124
+ enabled: sortedIds.length > 0,
125
+ staleTime: 30_000,
126
+ queryFn: async () => {
127
+ const result = (await client.callTool({
128
+ name: "VIRTUAL_MCP_LAST_USED_LIST",
129
+ arguments: { ids: sortedIds },
130
+ })) as CallToolResult;
131
+ const payload = (result.structuredContent ?? { items: [] }) as {
132
+ items: VirtualMCPLastUsed[];
133
+ };
134
+ const map = new Map<string, VirtualMCPLastUsed>();
135
+ for (const item of payload.items) map.set(item.id, item);
136
+ return map;
137
+ },
138
+ });
139
+ }
140
+
78
141
  /**
79
142
  * Hook to get virtual MCP mutation actions (create, update, delete)
80
143
  *
@@ -85,6 +148,7 @@ export function useVirtualMCPActions() {
85
148
  const client = useMCPClient({
86
149
  connectionId: SELF_MCP_ALIAS_ID,
87
150
  orgId: org.id,
151
+ orgSlug: org.slug,
88
152
  });
89
153
 
90
154
  return useCollectionActions<VirtualMCPEntity>(org.id, "VIRTUAL_MCP", client);
package/src/index.ts CHANGED
@@ -2,11 +2,15 @@
2
2
  export {
3
3
  ProjectContextProvider,
4
4
  useProjectContext,
5
+ useOrg,
6
+ useCurrentProject,
5
7
  Locator,
6
- ORG_ADMIN_PROJECT_SLUG,
7
8
  type ProjectContextProviderProps,
8
9
  type ProjectLocator,
9
10
  type LocatorStructured,
11
+ type OrganizationData,
12
+ type ProjectData,
13
+ type ProjectUI,
10
14
  } from "./context";
11
15
 
12
16
  // Hooks
@@ -15,9 +19,14 @@ export {
15
19
  useCollectionItem,
16
20
  useCollectionList,
17
21
  useCollectionActions,
22
+ buildWhereExpression,
23
+ buildOrderByExpression,
24
+ buildCollectionQueryKey,
25
+ EMPTY_COLLECTION_LIST_RESULT,
18
26
  type CollectionEntity,
19
27
  type CollectionFilter,
20
28
  type UseCollectionListOptions,
29
+ type CollectionQueryKey,
21
30
  // Connection hooks
22
31
  useConnections,
23
32
  useConnection,
@@ -27,8 +36,10 @@ export {
27
36
  // MCP client hook and factory
28
37
  createMCPClient,
29
38
  useMCPClient,
39
+ useMCPClientOptional,
30
40
  type CreateMcpClientOptions,
31
41
  type UseMcpClientOptions,
42
+ type UseMcpClientOptionalOptions,
32
43
  // MCP tools hooks
33
44
  useMCPToolsList,
34
45
  useMCPToolsListQuery,
@@ -61,13 +72,27 @@ export {
61
72
  // Virtual MCP hooks
62
73
  useVirtualMCPs,
63
74
  useVirtualMCP,
75
+ virtualMcpItemQueryOptions,
64
76
  useVirtualMCPActions,
77
+ useVirtualMCPsLastUsed,
65
78
  type VirtualMCPFilter,
66
79
  type UseVirtualMCPsOptions,
80
+ type VirtualMCPLastUsed,
67
81
  } from "./hooks";
68
82
 
69
83
  // Types
70
84
  export {
85
+ // AI Provider types
86
+ PROVIDER_IDS,
87
+ MODEL_CAPABILITIES,
88
+ type ProviderId,
89
+ type ModelCapability,
90
+ type AiProviderModel,
91
+ type AiProviderModelLimits,
92
+ type AiProviderModelCosts,
93
+ type AiProviderKey,
94
+ type AiProviderInfo,
95
+ // Connection types
71
96
  ConnectionEntitySchema,
72
97
  ConnectionCreateDataSchema,
73
98
  ConnectionUpdateDataSchema,
@@ -86,24 +111,87 @@ export {
86
111
  VirtualMCPEntitySchema,
87
112
  VirtualMCPCreateDataSchema,
88
113
  VirtualMCPUpdateDataSchema,
114
+ VirtualMcpUILayoutSchema,
115
+ VirtualMcpUILayoutTabSchema,
89
116
  type VirtualMCPEntity,
90
117
  type VirtualMCPCreateData,
91
118
  type VirtualMCPUpdateData,
92
119
  type VirtualMCPConnection,
93
- type ToolSelectionMode,
120
+ type VirtualMcpUILayout,
121
+ type VirtualMcpUILayoutTab,
122
+ type VirtualMcpHomeTile,
123
+ getHomeTiles,
124
+ SandboxMapSchema,
125
+ type SandboxMap,
126
+ SandboxRecordSchema,
127
+ type SandboxRecord,
128
+ type RuntimeMetadata,
129
+ type RuntimeEnvEntry,
130
+ ENV_VAR_KEY_RE,
131
+ parseSandboxRecord,
132
+ parseBranchMap,
133
+ normalizeSandboxMap,
134
+ type SandboxProviderKind,
135
+ type GithubRepo,
136
+ // Decopilot event types
137
+ THREAD_STATUSES,
138
+ THREAD_DISPLAY_STATUSES,
139
+ DECOPILOT_EVENTS,
140
+ ALL_DECOPILOT_EVENT_TYPES,
141
+ createDecopilotStepEvent,
142
+ createDecopilotFinishEvent,
143
+ createDecopilotThreadStatusEvent,
144
+ type ThreadStatus,
145
+ type ThreadDisplayStatus,
146
+ type DecopilotEventType,
147
+ type DecopilotStepEvent,
148
+ type DecopilotFinishEvent,
149
+ type DecopilotThreadStatusEvent,
150
+ type DecopilotSSEEvent,
151
+ type DecopilotEventMap,
94
152
  } from "./types";
95
153
 
96
154
  // Streamable HTTP transport
97
155
  export { StreamableHTTPClientTransport } from "./lib/streamable-http-client-transport";
98
156
 
157
+ // Bridge transport
158
+ export {
159
+ createBridgeTransportPair,
160
+ BridgeClientTransport,
161
+ BridgeServerTransport,
162
+ type BridgeTransportPair,
163
+ } from "./lib/bridge-transport";
164
+
165
+ // Server-client bridge
166
+ export {
167
+ createServerFromClient,
168
+ type ServerFromClientOptions,
169
+ } from "./lib/server-client-bridge";
170
+
99
171
  // Query keys
100
172
  export { KEYS } from "./lib/query-keys";
101
173
 
174
+ // Default model selection
175
+ export {
176
+ DEFAULT_MODEL_PREFERENCES,
177
+ FAST_MODEL_PREFERENCES,
178
+ SMART_MODEL_PREFERENCES,
179
+ THINKING_MODEL_PREFERENCES,
180
+ IMAGE_MODEL_PREFERENCES,
181
+ WEB_RESEARCH_MODEL_PREFERENCES,
182
+ selectDefaultModel,
183
+ getFastModel,
184
+ pickSimpleModeDefaults,
185
+ type SimpleModeModelSlot,
186
+ type SimpleModeDefaults,
187
+ } from "./lib/default-model";
188
+
102
189
  // MCP OAuth utilities
103
190
  export {
104
191
  authenticateMcp,
105
192
  handleOAuthCallback,
106
193
  isConnectionAuthenticated,
194
+ setOAuthRedirectOrigin,
107
195
  type McpOAuthProviderOptions,
108
196
  type OAuthTokenInfo,
109
197
  type AuthenticateMcpResult,
@@ -111,18 +199,45 @@ export {
111
199
  type OAuthWindowMode,
112
200
  } from "./lib/mcp-oauth";
113
201
 
202
+ // Usage utilities
203
+ export {
204
+ getCostFromUsage,
205
+ emptyUsageStats,
206
+ addUsage,
207
+ calculateUsageStats,
208
+ sanitizeProviderMetadata,
209
+ type UsageData,
210
+ type UsageStats,
211
+ } from "./lib/usage";
212
+
114
213
  // Constants and well-known MCP definitions
115
214
  export {
116
215
  // Frontend self MCP ID
117
216
  SELF_MCP_ALIAS_ID,
217
+ // Frontend dev-assets MCP ID
218
+ DEV_ASSETS_MCP_ALIAS_ID,
118
219
  // Org-scoped MCP ID generators
119
220
  WellKnownOrgMCPId,
120
221
  // Connection factory functions
121
222
  getWellKnownRegistryConnection,
122
223
  getWellKnownCommunityRegistryConnection,
123
224
  getWellKnownSelfConnection,
124
- getWellKnownOpenRouterConnection,
225
+ getWellKnownDevAssetsConnection,
125
226
  getWellKnownMcpStudioConnection,
126
227
  // Virtual MCP factory functions
127
- getWellKnownDecopilotAgent,
228
+ getWellKnownDecopilotVirtualMCP,
229
+ getWellKnownDecopilotConnection,
230
+ // Decopilot utilities
231
+ isDecopilot,
232
+ getDecopilotId,
233
+ // Site Diagnostics utilities
234
+ isSiteDiagnostics,
235
+ getSiteDiagnosticsId,
236
+ // Brand-Context Setup utilities
237
+ isBrandContextSetup,
238
+ getBrandContextSetupId,
239
+ getWellKnownBrandContextSetupVirtualMCP,
240
+ // Studio Pack utilities
241
+ StudioPackAgentId,
242
+ isStudioPackAgent,
128
243
  } from "./lib/constants";