@@ -8,10 +8,7 @@ import {
88 type KnowledgeMcpToolRunner ,
99 projectResult ,
1010} from '@/lib/knowledge/mcp/tool-runner'
11- import { listMyActivity , MAX_ACTIVITY_ACCOUNTS } from '@/lib/sim-search/live/activity'
12- import { activityCursorAccountCount } from '@/lib/sim-search/live/activity-page'
13- import { listLiveSearchAccounts } from '@/lib/sim-search/live/application'
14- import { supportsActivity } from '@/lib/sim-search/live/providers'
11+ import { listMyActivity } from '@/lib/sim-search/live/activity'
1512
1613interface ListMyActivityToolContext {
1714 execute : KnowledgeMcpToolRunner
@@ -20,33 +17,6 @@ interface ListMyActivityToolContext {
2017 request : NextRequest
2118}
2219
23- /**
24- * What one call costs against the rate limit: one operation per account it reads, since each is
25- * a separate provider listing. A lookup that fails charges one, as a call reading nothing would.
26- */
27- async function activityCost (
28- principal : Principal ,
29- organizationId : string ,
30- source : string | undefined ,
31- cursor : string | undefined
32- ) : Promise < number > {
33- /** A continuation reads only the accounts its cursor still names. */
34- const continued = cursor ? activityCursorAccountCount ( cursor ) : undefined
35- if ( continued !== undefined ) return Math . min ( MAX_ACTIVITY_ACCOUNTS , Math . max ( 1 , continued ) )
36- try {
37- const { accounts } = await listLiveSearchAccounts . execute ( {
38- principal,
39- input : { organizationId } ,
40- } )
41- const read = accounts . filter (
42- ( account ) => supportsActivity ( account . provider ) && ( ! source || account . provider === source )
43- ) . length
44- return Math . min ( MAX_ACTIVITY_ACCOUNTS , Math . max ( 1 , read ) )
45- } catch {
46- return 1
47- }
48- }
49-
5020/**
5121 * Registers `list_my_activity`: what the caller did across their connected sources in a window,
5222 * newest first, with a status per source that names the ones to connect.
@@ -64,29 +34,31 @@ export function registerListMyActivityTool(
6434 inputSchema : listMyActivityMcpSchema ,
6535 annotations : KNOWLEDGE_MCP_READ_ONLY ,
6636 } ,
67- async ( input : unknown , extra : { signal : AbortSignal } ) => {
68- const requested = listMyActivityMcpSchema . safeParse ( input )
69- const cost = await activityCost (
70- principal ,
71- organizationId ,
72- requested . data ?. source ,
73- requested . data ?. cursor
74- )
75- return execute (
37+ async ( input : unknown , extra : { signal : AbortSignal } ) =>
38+ execute (
7639 'list_my_activity' ,
7740 knowledgeOperations . listActivity ,
7841 extra . signal ,
79- async ( registry , signal ) => {
42+ async ( registry , signal , charge ) => {
8043 const parsed = listMyActivityMcpSchema . parse ( input )
8144 const result = await listMyActivity . execute ( {
8245 principal,
8346 input : { ...parsed , organizationId, resultSecretRegistry : registry , signal } ,
8447 request,
8548 } )
49+ /**
50+ * Each account read is a separate provider listing, so beyond the one operation the call
51+ * was admitted with, it is charged one per further account this page read.
52+ */
53+ const accountsRead = result . sources . filter (
54+ ( { accountId, status, reason } ) =>
55+ accountId &&
56+ status !== 'unsupported' &&
57+ ! ( status === 'failed' && reason === 'unavailable' )
58+ ) . length
59+ await charge ( accountsRead - 1 )
8660 return projectResult ( result , registry )
87- } ,
88- cost
61+ }
8962 )
90- }
9163 )
9264}
0 commit comments